mirror of
https://github.com/felixfoertsch/wordpress-dev-env.git
synced 2026-04-19 07:48:38 +02:00
Initial commit
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
namespace WCFE\Modules\Profiles\Controller;
|
||||
|
||||
# JSON Responder framework
|
||||
use WPPFW\MVC\Service\JSONEncoder;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class JSONControllerResponder extends JSONEncoder {}
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
namespace WCFE\Modules\Profiles\Controller\Profiles;
|
||||
|
||||
# Imoprts
|
||||
use WPPFW\MVC\Controller\Controller;
|
||||
|
||||
# Config Form
|
||||
use WCFE\Modules\Editor\Model\Forms;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class ProfilesController extends Controller {
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
*/
|
||||
private function _checkPermission()
|
||||
{
|
||||
|
||||
# Check if permitted to take such action
|
||||
if ( ! is_super_admin() )
|
||||
{
|
||||
|
||||
header( 'HTTP/1.0 4.3 Forbidden' );
|
||||
|
||||
die( );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
*/
|
||||
public function editAction()
|
||||
{
|
||||
|
||||
if ( ! $this->_checkPermission() )
|
||||
{
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! isset( $_GET[ 'caller' ] ) )
|
||||
{
|
||||
die( $this->__( 'Invalid Caller!!!' ) );
|
||||
}
|
||||
|
||||
$form = new \WCFE\Modules\Profiles\Model\Forms\ProfileForm();
|
||||
$model =& $this->getModel();
|
||||
$router =& $this->router();
|
||||
|
||||
$result[ 'securityToken' ] = wp_create_nonce();
|
||||
$result[ 'form' ] =& $form;
|
||||
$result[ 'caller' ] = $_GET[ 'caller' ];
|
||||
$result[ 'storageId' ] = isset( $_GET[ 'storageId' ] ) ? $_GET[ 'storageId' ] : null;
|
||||
|
||||
# Query profile to ediot or create new one
|
||||
if ( $_SERVER[ 'REQUEST_METHOD' ] != 'POST' )
|
||||
{
|
||||
|
||||
$result[ 'isNew' ] = ! isset( $_GET[ 'id' ] ) || ! $_GET[ 'id' ];
|
||||
|
||||
if ( isset( $_GET[ 'id' ] ) && $_GET[ 'id' ] )
|
||||
{
|
||||
|
||||
# Query Item
|
||||
if ( ! $profile = $model->getProfile( $_GET[ 'id' ] ) )
|
||||
{
|
||||
|
||||
$model->addError( $this->__( 'Profile doesnt exists!!' ) );
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
# Fill form with queried item
|
||||
$form->setValue( array( $form->getName() => $profile->getArray() ) );
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
# Check post nonce
|
||||
if ( ! isset( $_POST[ 'securityToken' ] ) ||
|
||||
! $_POST[ 'securityToken' ] ||
|
||||
! wp_verify_nonce( $_POST[ 'securityToken' ] ) )
|
||||
{
|
||||
|
||||
$model->addError( $this->__( 'Invalid Access Token' ) );
|
||||
|
||||
$this->redirect( $router->routeAction() ) ;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
# Upate or insert profile
|
||||
$postData = filter_input( INPUT_POST, $form->getName(), FILTER_UNSAFE_RAW, FILTER_REQUIRE_ARRAY );
|
||||
|
||||
$result[ 'isNew' ] = ! isset( $postData[ 'id' ] ) || ! $postData[ 'id' ];
|
||||
|
||||
$form->setValue( array( $form->getName() => $postData ) );
|
||||
|
||||
$profile = new \WCFE\Modules\Profiles\Model\Profile( $form->getValue() );
|
||||
|
||||
if ( $model->validate( $profile ) )
|
||||
{
|
||||
if ( $model->saveProfile( $profile, $result[ 'storageId' ] ) )
|
||||
{
|
||||
|
||||
$result[ 'profile' ] = $profile->getArray();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
*/
|
||||
public function listAction()
|
||||
{
|
||||
if ( ! $this->_checkPermission() )
|
||||
{
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$model =& $this->getModel();
|
||||
$router =& $this->router();
|
||||
|
||||
$result[ 'securityNonce' ] = wp_create_nonce();
|
||||
$result[ 'profiles' ] = $model->getProfiles();
|
||||
|
||||
# Delete
|
||||
if ( $_SERVER[ 'REQUEST_METHOD' ] == 'POST' )
|
||||
{
|
||||
|
||||
if ( ! isset( $_POST[ 'securityNonce'] ) || ! wp_verify_nonce( $_POST[ 'securityNonce'] ) )
|
||||
{
|
||||
$model->addError( $this->__( 'Invalid security Token' ) );
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ( $model->delete( $_POST[ 'id' ] ) )
|
||||
{
|
||||
$this->redirect( $router->routeAction() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
} # End class
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
namespace WCFE\Modules\Profiles\Controller\ProfilesService;
|
||||
|
||||
# Imoprts
|
||||
use WPPFW\MVC\Controller\ServiceController;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class ProfilesServiceController extends ServiceController {
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
*/
|
||||
private function _checkPermission()
|
||||
{
|
||||
|
||||
# Check if permitted to take such action
|
||||
if (
|
||||
( ! isset( $_POST[ 'securityToken' ] ) ) ||
|
||||
|
||||
( ! $_POST[ 'securityToken' ] ) ||
|
||||
|
||||
( ! wp_verify_nonce( $_POST[ 'securityToken' ] ) ) ||
|
||||
|
||||
( ! is_super_admin() ) )
|
||||
{
|
||||
|
||||
header( 'HTTP/1.0 4.3 Forbidden' );
|
||||
|
||||
die( $this->__( 'Access Denies' ) );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
*/
|
||||
public function createProfileVarsTStorageAction()
|
||||
{
|
||||
if ( ! $this->_checkPermission() )
|
||||
{
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$model =& $this->getModel( 'Profiles' );
|
||||
|
||||
$vars = filter_input( INPUT_POST, 'configFileFields', FILTER_UNSAFE_RAW, FILTER_REQUIRE_ARRAY );
|
||||
|
||||
# Exclude form internal fields
|
||||
unset( $vars[ 'Task' ] );
|
||||
unset( $vars[ 'stoken' ] );
|
||||
|
||||
$storageId = $model->createProfileVarsTStorage( $vars );
|
||||
|
||||
return array( 'id' => $storageId );
|
||||
}
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
*/
|
||||
public function deleteProfileAction()
|
||||
{
|
||||
|
||||
if ( ! $this->_checkPermission() )
|
||||
{
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
$model =& $this->getModel( 'Profiles' );
|
||||
$profileId = $_POST[ 'profileId' ];
|
||||
|
||||
return $model->delete( array( $profileId ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
*/
|
||||
public function setProfileVarsAction()
|
||||
{
|
||||
|
||||
if ( ! $this->_checkPermission() )
|
||||
{
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
$model =& $this->getModel( 'Profiles' );
|
||||
|
||||
$profile = new \WCFE\Modules\Profiles\Model\Profile();
|
||||
|
||||
$profile->id = $_POST[ 'profileId' ];
|
||||
$profile->vars = filter_input( INPUT_POST, 'configFileFields', FILTER_UNSAFE_RAW, FILTER_REQUIRE_ARRAY );
|
||||
|
||||
# Exclude form internal fields
|
||||
unset( $profile->vars[ 'Task' ] );
|
||||
unset( $profile->vars[ 'stoken' ] );
|
||||
|
||||
return $model->updateProfileVars( $profile );
|
||||
}
|
||||
|
||||
} # End class
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
# Define namespace
|
||||
namespace WCFE\Modules\Profiles\Model\Forms;
|
||||
|
||||
# Forms framework
|
||||
use WPPFW\Forms;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class ProfileForm extends Forms\Form
|
||||
{
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
# Define form parameters
|
||||
parent::__construct('profileForm', 'stoken');
|
||||
# Add fields
|
||||
$this->addChain( new Forms\Fields\FormStringField( 'name' ) )
|
||||
->addChain( new Forms\Fields\FormStringField( 'description' ) )
|
||||
->addChain( new Forms\Fields\FormStringField( 'id' ) );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
namespace WCFE\Modules\Profiles\Model;
|
||||
|
||||
# Models Framework
|
||||
use WPPFW\MVC\Model\EntityModel;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Profile extends EntityModel
|
||||
{
|
||||
public $description;
|
||||
public $id;
|
||||
public $name;
|
||||
public $vars;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
namespace WCFE\Modules\Profiles\Model;
|
||||
|
||||
# Models Framework
|
||||
use WPPFW\MVC\Model\PluginModel;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class ProfilesModel extends PluginModel {
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $profiles = array();
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $profileVarsTStorage = array();
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @param mixed $vars
|
||||
*/
|
||||
public function createProfileVarsTStorage( $vars )
|
||||
{
|
||||
|
||||
$id = md5( uniqid() );
|
||||
|
||||
# For now we just need single storage
|
||||
$this->profileVarsTStorage = array( $id => $vars );
|
||||
|
||||
return $id;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @param mixed $ids
|
||||
*/
|
||||
public function delete( $ids )
|
||||
{
|
||||
|
||||
$deletedRecords = 0;
|
||||
|
||||
foreach ( $ids as $profileId )
|
||||
{
|
||||
if ( isset( $this->profiles[ $profileId ] ) )
|
||||
{
|
||||
|
||||
unset( $this->profiles[ $profileId ] );
|
||||
|
||||
$deletedRecords ++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->addError( $this->__( '%d profiles deleted', $deletedRecords ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @param mixed $id
|
||||
*/
|
||||
public function getProfile( $id )
|
||||
{
|
||||
|
||||
if ( isset( $this->profiles[ $id ] ) )
|
||||
{
|
||||
$profile = new Profile( $this->profiles[ $id ] );
|
||||
|
||||
return $profile;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
*/
|
||||
public function getProfiles()
|
||||
{
|
||||
|
||||
$profiles = array();
|
||||
|
||||
foreach ( $this->profiles as $profileData )
|
||||
{
|
||||
|
||||
$profiles[] = new Profile( $profileData );
|
||||
}
|
||||
|
||||
return $profiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @param Profile $profile
|
||||
* @param mixed $storageId
|
||||
*/
|
||||
public function saveProfile( Profile & $profile, $storageId )
|
||||
{
|
||||
if ( $profile->id )
|
||||
{
|
||||
if ( ! $currentProfile = $this->getProfile( $profile->id ) )
|
||||
{
|
||||
|
||||
$this->addError( $this->__( 'Profile doesnt exists!!!' ) );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$profile->vars = $currentProfile->vars;
|
||||
|
||||
$this->setMessage( $this->__( 'Profile Updated successfuly' ) );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
# Generate new id
|
||||
$profile->id = sanitize_title( $profile->name );
|
||||
|
||||
# Insert vars too if there is storage Id specifed
|
||||
if ( $storageId )
|
||||
{
|
||||
# Copy vars to profile vars
|
||||
$profile->vars = $this->profileVarsTStorage[ $storageId ];
|
||||
|
||||
# Reset temporary storage
|
||||
$this->profileVarsTStorage = array();
|
||||
}
|
||||
|
||||
$this->setMessage( $this->__( 'Profile Added successfuly' ) );
|
||||
}
|
||||
|
||||
# Update or Insert
|
||||
$this->profiles[ $profile->id ] = $profile->getArray();
|
||||
|
||||
return $profile->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @param Profile $profile
|
||||
*/
|
||||
public function updateProfileVars( Profile & $profile )
|
||||
{
|
||||
if ( ! isset( $this->profiles[ $profile->id ] ) )
|
||||
{
|
||||
|
||||
$this->addError( $this->__( 'Profile doesn\'t exists' ) );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->profiles[ $profile->id ][ 'vars' ] = $profile->vars;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @param Profile $profile
|
||||
*/
|
||||
public function validate( Profile & $profile )
|
||||
{
|
||||
|
||||
# ALways valid when editing, adding new valid only if name doesn't exists
|
||||
return ( $profile->id || ( ! $profile->id && ! isset( $this->profiles[ $profile->id ] ) ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
body
|
||||
{
|
||||
background-color: white;
|
||||
}
|
||||
div#wcfe-profile-edit {
|
||||
|
||||
}
|
||||
|
||||
div#wcfe-profile-edit fieldset {
|
||||
border:none;
|
||||
}
|
||||
|
||||
div#wcfe-profile-edit fieldset ul
|
||||
{
|
||||
list-style-type:none;
|
||||
}
|
||||
|
||||
div#wcfe-profile-edit fieldset ul li
|
||||
{
|
||||
margin-bottom:16px
|
||||
}
|
||||
div#wcfe-profile-edit fieldset ul li label{
|
||||
|
||||
display:inline-block;
|
||||
width: 200px
|
||||
}
|
||||
|
||||
|
||||
#profile-description
|
||||
{
|
||||
width: 420px;
|
||||
height: 219px;
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
namespace WCFE\Modules\Profiles\View\Profile\Media;
|
||||
|
||||
# Script resource
|
||||
use WPPFW\Services\Queue\StyleResource;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class EditCSS extends StyleResource {
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $fileName = 'Edit.css';
|
||||
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
(function( $ )
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
var WCFEEditProfile = new function()
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
var initialize = function()
|
||||
{
|
||||
$( '#wcfe-profile-edit form input[type="submit"]' ).click(
|
||||
|
||||
function()
|
||||
{
|
||||
|
||||
var profileId = $( '#wcfe-profile-edit form input[name="profileForm[id]"]' ).val();
|
||||
|
||||
if ( ! profileId && ! $( '#profile-name' ).val() )
|
||||
{
|
||||
alert( WCFEProfileL10N.msg_profileNameEmpty );
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
// Initialize form script when document lodaed
|
||||
$( initialize );
|
||||
|
||||
};
|
||||
|
||||
|
||||
})( jQuery );
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
namespace WCFE\Modules\Profiles\View\Profile\Media;
|
||||
|
||||
# Script resource
|
||||
use WPPFW\Services\Queue\ScriptResource;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Profile extends ScriptResource {
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $fileName = 'Profile.js';
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
return array
|
||||
(
|
||||
|
||||
'msg_profileNameEmpty' => $this->__( 'Profile name cannot be empty' ),
|
||||
|
||||
|
||||
);
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
# Define namespace
|
||||
namespace WCFE\Modules\Editor\View\Editor\Templates;
|
||||
|
||||
# No direct access
|
||||
defined('ABSPATH') or die( WCFE\NO_DIRECT_ACCESS_MESSAGE );
|
||||
|
||||
$router = $this->router();
|
||||
$result = $this->result();
|
||||
|
||||
$form =& $result[ 'form' ];
|
||||
$securityToken = $result[ 'securityToken' ];
|
||||
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<?php do_action( 'admin_print_scripts' ); ?>
|
||||
<?php do_action( 'admin_print_styles' ); ?>
|
||||
</head>
|
||||
<body>
|
||||
<div id="wcfe-profile-edit" class="wcfe-popup-view">
|
||||
<form action="<?php echo $router->route( new \WPPFW\MVC\MVCViewParams( '', '', 'Edit', '', 'Profile' ) ) ?>&caller=<?php echo $result[ 'caller' ] ?>&storageId=<?php echo $result[ 'storageId' ] ?>" method="post">
|
||||
<fieldset>
|
||||
<ul>
|
||||
<li>
|
||||
<label for="profile-name"><?php $this->_e( 'Name' ) ?></label>
|
||||
<input<?php echo ( ! $result[ 'isNew' ] ? ' readonly="readonly"' : '' ) ?> type="text" id="profile-name" name="profileForm[name]" value="<?php echo $form->get( 'name' )->getValue() ?>" />
|
||||
</li>
|
||||
<li>
|
||||
<label for="profile-description"><?php $this->_e( 'Description' ) ?></label>
|
||||
<textarea id="profile-description" name="profileForm[description]"><?php echo $form->get( 'description' )->getValue() ?></textarea>
|
||||
</li>
|
||||
<li>
|
||||
<input type="submit" name="Save" value="Save" />
|
||||
</li>
|
||||
</ul>
|
||||
</fieldset>
|
||||
<input type="hidden" name="securityToken" value="<?php echo $securityToken ?>" />
|
||||
<input type="hidden" name="profileForm[id]" value="<?php echo $form->get( 'id' )->getValue() ?>" />
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
if ( isset( $result[ 'profile' ] ) ) :
|
||||
$callbackName = $result[ 'isNew' ] ? '_onprofilecreated' : '_onprofileupdated';
|
||||
?>
|
||||
<script type="text/javascript"> window.parent[ '<?php echo $result[ 'caller' ] ?>' ].<?php echo $callbackName ?>( <?php echo json_encode( $result[ 'profile' ] ) ?> );</script>
|
||||
<?php endif; ?>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
namespace WCFE\Modules\Profiles\View\Profile;
|
||||
|
||||
# Imports
|
||||
use WPPFW\MVC\View\TemplateView;
|
||||
|
||||
# Dashboard script queue
|
||||
use WPPFW\Services\Queue\DashboardScriptsQueue;
|
||||
use WPPFW\Services\Queue\DashboardStylesQueue;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class ProfileHTMLView extends TemplateView {
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $actionsRoute = array();
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $extraExtension = '.php';
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @var \WCFE\Libraries\ResStorage
|
||||
*/
|
||||
private $resFactory;
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @var DashboardScriptsQueue
|
||||
*/
|
||||
private $scriptsQueue;
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @var DashboardStylesQueue
|
||||
*/
|
||||
private $stylesQueue;
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
*/
|
||||
protected function initialize() {
|
||||
|
||||
# ENQUEUE SCRIPT and STYLES
|
||||
$this->resFactory = new \WCFE\Libraries\ResStorage(
|
||||
WP_PLUGIN_URL . '/wp-config-file-editor',
|
||||
WP_PLUGIN_DIR . '/wp-config-file-editor'
|
||||
);
|
||||
|
||||
# Scripts and Styles queues
|
||||
$this->scriptsQueue = new DashboardScriptsQueue( $this, 'js', 'localization.php' );
|
||||
$this->stylesQueue = new DashboardStylesQueue();
|
||||
|
||||
# Scripts
|
||||
$this->scriptsQueue->enqueueNamedResource( \WPPFW\Services\Queue\DashboardScriptsQueue::JQUERY );
|
||||
$this->scriptsQueue->enqueueNamedResource( 'jquery-serialize-object' );
|
||||
$this->scriptsQueue->add( $this->resFactory->getRes( 'WCFE\Modules\Profiles\View\Profile\Media\Profile' ), true );
|
||||
|
||||
# Styles
|
||||
|
||||
$this->stylesQueue->add( $this->resFactory->getRes( 'WCFE\Modules\Profiles\View\Profile\Media\EditCSS' ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
body
|
||||
{
|
||||
margin-top: 10px;
|
||||
}
|
||||
table.wcfe-grid-table
|
||||
{
|
||||
width: 100%;
|
||||
background-color: gray;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
table.wcfe-grid-table tr th
|
||||
{
|
||||
background-color: #D9D9DA;
|
||||
}
|
||||
|
||||
table.wcfe-grid-table tr td
|
||||
{
|
||||
background-color: white;
|
||||
text-align: center;
|
||||
}
|
||||
.wcfe-table-grid-column-actions a {
|
||||
font-size: 13px;
|
||||
color: #0B9BD4;
|
||||
font-weight: bold;
|
||||
text-decoration: none;
|
||||
}
|
||||
.wcfe-table-grid-column-actions a:hover {
|
||||
color: #0D5C7B;
|
||||
}
|
||||
#wcfe-profiles-list-menu
|
||||
{
|
||||
width: 80px;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
#wcfe-profiles-list-menu ul li
|
||||
{
|
||||
width: 90px;
|
||||
}
|
||||
|
||||
.active-profile-state {
|
||||
color: red;
|
||||
font-weight: bold;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
namespace WCFE\Modules\Profiles\View\Profiles\Media;
|
||||
|
||||
# Script resource
|
||||
use WPPFW\Services\Queue\StyleResource;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Style extends StyleResource {
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $fileName = 'List.css';
|
||||
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @type T_JS_FUNCTION
|
||||
*/
|
||||
WCFEProfilesList = new function()
|
||||
{
|
||||
|
||||
this._onprofilecreated = function( profile )
|
||||
{
|
||||
window.location.reload();
|
||||
}
|
||||
this._onprofileupdated = function( profile )
|
||||
{
|
||||
window.location.reload();
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
jQuery( function() {
|
||||
|
||||
var $ = jQuery;
|
||||
|
||||
$( '#wcfe-profiles-list-menu' ).menu({ position: { my: "left top", at: "left bottom" },
|
||||
select : function(event)
|
||||
{
|
||||
switch ( event.srcElement.id )
|
||||
{
|
||||
case 'wcfe-profiles-list-menu-delete':
|
||||
|
||||
if ( confirm( WCFEProfilesL10N.confirm_deleteSelected ) )
|
||||
{
|
||||
$( '#wcfe-grid-table-form' ).submit();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'wcfe-profiles-list-menu-create':
|
||||
|
||||
tb_show( WCFEProfilesL10N.title_createProfile, actionsRoute[ 'editProfile' ] + '&caller=WCFEProfilesList&TB_iframe=true' );
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$( '#wcfe-table-grid-selectall' ).change(
|
||||
function()
|
||||
{
|
||||
$( '.wcfe-grid-table input[name="id[]"]' ).prop( 'checked', $( this ).prop( 'checked' ) );
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
// Notify config form window
|
||||
$( '.wcfe-select-profile' ).click(
|
||||
|
||||
function()
|
||||
{
|
||||
|
||||
// Create compatible profile object similar to
|
||||
// the one recivied by server. Aggregat
|
||||
// profile data from greid row
|
||||
|
||||
///////// This is not currently being used however leav it for a while to make ///////
|
||||
//////// sure I don't need it /////////
|
||||
var profile = {};
|
||||
var profileId = this.href.substring( this.href.indexOf( '#' ) + 1 );
|
||||
var profileFields = $( '.wcfe-grid-table #profile-row-' + profileId + ' td span.profile-field' ).each(
|
||||
function( )
|
||||
{
|
||||
|
||||
var jField = $( this );
|
||||
|
||||
// Last word in last class is the field name
|
||||
var fieldName = this.className.split( '-' )[ 2 ];
|
||||
|
||||
profile[ fieldName ] = jField.text();
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
// Callback with selected profile object
|
||||
var callback = window.parent.WCFEEditorForm._onselectprofile;
|
||||
|
||||
callback( profileId );
|
||||
}
|
||||
);
|
||||
|
||||
// Edit Profile
|
||||
$( '.wcfe-edit-profile' ).click(
|
||||
function( event )
|
||||
{
|
||||
|
||||
tb_show( 'Edit Profile', event.target.href + '&caller=WCFEProfilesList&TB_iframe=true' );
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
// Disallow deleteing active profile
|
||||
var gridTable = $( '.wcfe-grid-table' );
|
||||
var profile = window.parent.WCFEEditorForm.profile.getProfile()
|
||||
if ( profile )
|
||||
{
|
||||
var activeProfileCheckbox = gridTable.find( '#profile-row-' + profile.id + ' input[type="checkbox"]');
|
||||
activeProfileCheckbox.parent().append( '<span class="active-profile-state">Active</span>' );
|
||||
activeProfileCheckbox.remove();
|
||||
}
|
||||
|
||||
gridTable.show(); // Its hidding by inline style attribute
|
||||
} );
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
namespace WCFE\Modules\Profiles\View\Profiles\Media;
|
||||
|
||||
# Script resource
|
||||
use WPPFW\Services\Queue\ScriptResource;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Profiles extends ScriptResource
|
||||
{
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $fileName = 'Profiles.js';
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
return array
|
||||
(
|
||||
|
||||
'confirm_deleteSelected' => $this->__( 'Would you like to delete selected profiles?' ),
|
||||
'title_createProfile' => $this->__( 'Create Profile' ),
|
||||
|
||||
|
||||
);
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
# Define namespace
|
||||
namespace WCFE\Modules\Editor\View\Editor\Templates;
|
||||
|
||||
# No direct access
|
||||
defined('ABSPATH') or die( WCFE\NO_DIRECT_ACCESS_MESSAGE );
|
||||
|
||||
$result = $this->result();
|
||||
$router = $this->router();
|
||||
$profiles = $result[ 'profiles' ];
|
||||
$securityNonce = $result[ 'securityNonce' ];
|
||||
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<?php do_action( 'admin_print_scripts' ); ?>
|
||||
<?php do_action( 'admin_print_styles' ); ?>
|
||||
</head>
|
||||
<body>
|
||||
<div id="wcfe-profiles-list" class="wcfe-popup-view">
|
||||
<ul id="wcfe-profiles-list-menu">
|
||||
<li><?php $this->_e( 'Actions' ) ?>
|
||||
<ul>
|
||||
<li id="wcfe-profiles-list-menu-delete"><?php $this->_e( 'Delete' ) ?></li>
|
||||
<li id="wcfe-profiles-list-menu-create"><?php $this->_e( 'Create' ) ?></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<form id="wcfe-grid-table-form" action="<?php echo $router->routeAction() ?>" method="post">
|
||||
<table class="wcfe-grid-table" style="display: none;" cellpadding="4" cellspacing="2">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php $this->_e( 'Name' ) ?></th>
|
||||
<th><?php $this->_e( 'escription' ) ?></th>
|
||||
<th><?php $this->_e( 'ID' ) ?></th>
|
||||
<th><input type="checkbox" id="wcfe-table-grid-selectall" /></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ( $profiles as $profile ) : ?>
|
||||
<tr id="profile-row-<?php echo $profile->id ?>">
|
||||
<td>
|
||||
<span class="profile-field profile-name"><?php echo $profile->name ?></span>
|
||||
<div class="wcfe-table-grid-column-actions">
|
||||
<a class="wcfe-edit-profile" href="<?php echo $router->route( new \WPPFW\MVC\MVCViewParams( '', '', 'Edit', '', 'Profile' ) ) ?>&id=<?php echo $profile->id ?>"><?php $this->_e( 'Edit' ) ?></a> |
|
||||
<a class="wcfe-select-profile" href="#<?php echo $profile->id ?>"><?php $this->_e( 'Load' ) ?></a>
|
||||
</div>
|
||||
</td>
|
||||
<td><span class="profile-field profile-description"><?php echo $profile->description ?></span></td>
|
||||
<td><span class="profile-field profile-id"><?php echo $profile->id ?></span></td>
|
||||
<td><input type="checkbox" name="id[]" value="<?php echo $profile->id ?>" /></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<input type="hidden" name="securityNonce" value="<?php echo $result[ 'securityNonce' ] ?>" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">var actionsRoute = <?php echo json_encode( $this->actionsRoute ) ?>;</script>
|
||||
<?php do_action( 'admin_print_footer_scripts' ) ?>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
namespace WCFE\Modules\Profiles\View\Profiles;
|
||||
|
||||
# Imports
|
||||
use WPPFW\MVC\View\TemplateView;
|
||||
|
||||
# Dashboard script queue
|
||||
use WPPFW\Services\Queue\DashboardScriptsQueue;
|
||||
use WPPFW\Services\Queue\DashboardStylesQueue;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class ProfilesHTMLView extends TemplateView {
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $actionsRoute = array();
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $extraExtension = '.php';
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @var \WCFE\Libraries\ResStorage
|
||||
*/
|
||||
private $resFactory;
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @var DashboardScriptsQueue
|
||||
*/
|
||||
private $scriptsQueue;
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @var DashboardStylesQueue
|
||||
*/
|
||||
private $stylesQueue;
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
*/
|
||||
protected function initialize() {
|
||||
|
||||
# ENQUEUE SCRIPT and STYLES
|
||||
$this->resFactory = new \WCFE\Libraries\ResStorage(
|
||||
WP_PLUGIN_URL . '/wp-config-file-editor',
|
||||
WP_PLUGIN_DIR . '/wp-config-file-editor'
|
||||
);
|
||||
|
||||
# Scripts and Styles queues
|
||||
$this->scriptsQueue = new DashboardScriptsQueue( $this, 'js', 'localization.php' );
|
||||
$this->stylesQueue = new DashboardStylesQueue();
|
||||
|
||||
# Scripts
|
||||
$this->scriptsQueue->enqueueNamedResource( \WPPFW\Services\Queue\DashboardScriptsQueue::JQUERY );
|
||||
|
||||
$this->scriptsQueue->enqueueNamedResource( DashboardScriptsQueue::THICK_BOX );
|
||||
|
||||
$this->scriptsQueue->add( $this->resFactory->getRes( 'WCFE\Libraries\JavaScript\jQueryMenu' ) );
|
||||
|
||||
$this->scriptsQueue->add( $this->resFactory->getRes( 'WCFE\Modules\Profiles\View\Profiles\Media\Profiles' ), true );
|
||||
|
||||
|
||||
# Styles
|
||||
$this->stylesQueue->enqueueNamedResource( DashboardStylesQueue::THICK_BOX );
|
||||
|
||||
$this->stylesQueue->add( $this->resFactory->getRes( 'WCFE\Libraries\CSS\jQuery\Theme\Theme' ) );
|
||||
|
||||
$this->stylesQueue->add( $this->resFactory->getRes( 'WCFE\Modules\Profiles\View\Profiles\Media\Style' ) );
|
||||
|
||||
# Actions route
|
||||
$this->setActionsRoute(
|
||||
'Profiles', 'profilesView', array
|
||||
(
|
||||
'editProfile' => array( 'action' => 'Edit', 'view' => 'Profile' )
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* put your comment there...
|
||||
*
|
||||
* @param mixed $moduleName
|
||||
* @param mixed $serviceObjectName
|
||||
* @param mixed $actionsList
|
||||
* @return EditorHTMLView
|
||||
*/
|
||||
private function & setActionsRoute( $moduleName, $serviceObjectName, $actionsList )
|
||||
{
|
||||
|
||||
$args = func_get_args();
|
||||
|
||||
for ( $argIndex = 0; $argIndex < count( $args ); $argIndex += 3 )
|
||||
{
|
||||
|
||||
$serviceRouter = $this->router()->findRouter( $args[ $argIndex ], $args[ $argIndex + 1 ] );
|
||||
|
||||
foreach ( ( $args[ $argIndex + 2 ] ) as $key => $route )
|
||||
{
|
||||
|
||||
$route = array_merge( array( 'action' => '', 'controller' => '', 'module' => '', 'view' => '', 'format' => '' ), $route );
|
||||
|
||||
$this->actionsRoute[ $key ] = (string) $serviceRouter->route
|
||||
(
|
||||
new \WPPFW\MVC\MVCViewParams
|
||||
(
|
||||
$route[ 'module' ],
|
||||
$route[ 'controller' ],
|
||||
$route[ 'action' ],
|
||||
$route[ 'format' ],
|
||||
$route[ 'view' ]
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user