| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* |
| 8 |
*/ |
| 9 |
class CJTBlocksCreateMetaBoxView extends CJTView { |
| 10 |
|
| 11 |
/** |
| 12 |
* put your comment there... |
| 13 |
* |
| 14 |
* @var mixed |
| 15 |
*/ |
| 16 |
protected $block = null; |
| 17 |
|
| 18 |
/** |
| 19 |
* put your comment there... |
| 20 |
* |
| 21 |
* @var mixed |
| 22 |
*/ |
| 23 |
protected $options = null; |
| 24 |
|
| 25 |
/** |
| 26 |
* put your comment there... |
| 27 |
* |
| 28 |
* @var mixed |
| 29 |
*/ |
| 30 |
protected $securityToken = null; |
| 31 |
|
| 32 |
/** |
| 33 |
* put your comment there... |
| 34 |
* |
| 35 |
* @param mixed $viewInfo |
| 36 |
* @return CJTBlockMetaBoxView |
| 37 |
*/ |
| 38 |
public function __construct($viewInfo) { |
| 39 |
parent::__construct($viewInfo); |
| 40 |
// Initialize vars. |
| 41 |
$this->options = (object) array(); |
| 42 |
// Add scripts ands styles actions. |
| 43 |
add_action('admin_print_scripts', array(__CLASS__, 'enqueueScripts')); |
| 44 |
add_action('admin_print_styles', array(__CLASS__, 'enqueueStyles')); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* put your comment there... |
| 49 |
* |
| 50 |
*/ |
| 51 |
public function display() { |
| 52 |
echo $this->getTemplate('create'); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* put your comment there... |
| 57 |
* |
| 58 |
*/ |
| 59 |
public static function enqueueScripts() { |
| 60 |
// Use related scripts. |
| 61 |
self::useScripts(__CLASS__, |
| 62 |
'jquery-ui-menu', |
| 63 |
'views:blocks:create-metabox:public:js:{CJT-}metabox', |
| 64 |
'views:blocks:manager:public:js:{CJT-}blocks', |
| 65 |
'framework:js:ajax:{CJT-}cjt-server', |
| 66 |
'framework:js:ui:{CJT-}jquery.link-progress', |
| 67 |
'framework:js:ajax:{CJT-}scripts-loader', |
| 68 |
'framework:js:ajax:{CJT-}styles-loader', |
| 69 |
'framework:js:wordpress:{CJT-}script-localizer' |
| 70 |
); |
| 71 |
/* |
| 72 |
* Link Thickbox to header instead of footer. |
| 73 |
* media-upload script linked directly after thickbox script. |
| 74 |
* media-upload script override tb_position() function to show |
| 75 |
* thickbox popup forms in fixed position and size! |
| 76 |
* |
| 77 |
* To overcome this problem we need to get a copy from original tb_position() |
| 78 |
* just after thickbox is loaded and just before media-upload is |
| 79 |
* not override tb_position yet. |
| 80 |
* metabox.js now is between thickbox and media-upload, have fun! |
| 81 |
*/ |
| 82 |
$GLOBALS['wp_scripts']->registered['thickbox']->args = 0; |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* put your comment there... |
| 87 |
* |
| 88 |
*/ |
| 89 |
public static function enqueueStyles() { |
| 90 |
// Use related styles. |
| 91 |
self::useStyles(__CLASS__, |
| 92 |
'views:blocks:create-metabox:public:css:{CJT-}metabox' |
| 93 |
); |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* put your comment there... |
| 98 |
* |
| 99 |
*/ |
| 100 |
public function getBlock() { |
| 101 |
return $this->block; |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* put your comment there... |
| 106 |
* |
| 107 |
*/ |
| 108 |
public function getMetaboxName() { |
| 109 |
return $this->getBlock()->name; |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* put your comment there... |
| 114 |
* |
| 115 |
* @param mixed $id |
| 116 |
*/ |
| 117 |
public function getMetaboxId() { |
| 118 |
// Use the same id as regular CJT block. |
| 119 |
$blockView = CJTView::create('blocks/block'); |
| 120 |
// To avoid outputing script and styles for block box Remove scripts and styles actions! |
| 121 |
remove_action('admin_print_scripts', array('CJTBlocksBlockView', 'enqueueScripts')); |
| 122 |
remove_action('admin_print_styles', array('CJTBlocksBlockView', 'enqueueStyles')); |
| 123 |
// Get metabox id. |
| 124 |
$blockView->setBlock($this->getBlock()); |
| 125 |
return $blockView->getMetaboxId(); |
| 126 |
} |
| 127 |
|
| 128 |
/** |
| 129 |
* put your comment there... |
| 130 |
* |
| 131 |
*/ |
| 132 |
public function getOption($name) { |
| 133 |
return isset($this->options->{$name}) ? $this->options->{$name} : null; |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* put your comment there... |
| 138 |
* |
| 139 |
*/ |
| 140 |
public function getSecurityToken() { |
| 141 |
return $this->securityToken; |
| 142 |
} |
| 143 |
/** |
| 144 |
* put your comment there... |
| 145 |
* |
| 146 |
* @param mixed $block |
| 147 |
*/ |
| 148 |
public function setBlock($block) { |
| 149 |
$this->block = $block; |
| 150 |
} |
| 151 |
|
| 152 |
/** |
| 153 |
* put your comment there... |
| 154 |
* |
| 155 |
* @param mixed $name |
| 156 |
* @param mixed $value |
| 157 |
*/ |
| 158 |
public function setOption($name, $value) { |
| 159 |
$this->options->{$name} = $value; |
| 160 |
// Chaining! |
| 161 |
return $this; |
| 162 |
} |
| 163 |
|
| 164 |
/** |
| 165 |
* put your comment there... |
| 166 |
* |
| 167 |
* @param mixed $token |
| 168 |
*/ |
| 169 |
public function setSecurityToken($token) { |
| 170 |
$this->securityToken = $token; |
| 171 |
} |
| 172 |
|
| 173 |
} // End class. |
| 174 |
|
| 175 |
// Hookable!! |
| 176 |
CJTBlocksCreateMetaBoxView::define('CJTBlocksCreateMetaBoxView'); |