1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
<?php
namespace hji\common\factories;
use hji\common\models\PluginJsVars;
use hji\common\models\mcePluginModel;
use hji\membership\Membership;
class mcePluginFactory
{
protected $mcePluginModel;
function __construct(mcePluginModel $mcePluginModel)
{
$this->mcePluginModel = $mcePluginModel;
}
function create()
{
if (current_user_can('edit_posts') && current_user_can('edit_pages'))
{
$this->registerActionHooks();
}
}
protected function registerActionHooks()
{
add_action('wp_ajax_' . $this->mcePluginModel->getAction(), array($this, 'renderMcePopupDialog'));
if (get_user_option('rich_editing') == 'true')
{
add_action('admin_enqueue_scripts', array($this, 'loadScripts'));
add_filter('mce_external_plugins', array($this, 'registerPlugin'));
add_filter('hji_mce_buttons', array($this, 'registerButton'));
}
}
function loadScripts($hook)
{
if ($hook == 'post.php' || $hook == 'post-new.php')
{
$jsVars = new PluginJsVars('tinymcePlugins');
$jsVars->setVar($this->mcePluginModel->getHandle(), $this->mcePluginModel->exportObject());
}
if ($this->isMcePopup())
{
wp_enqueue_script('tinymce_popup', get_option('siteurl') . '/wp-includes/js/tinymce/tiny_mce_popup.js');
wp_enqueue_script('tinymce_form_utils', get_option('siteurl') . '/wp-includes/js/tinymce/utils/form_utils.js');
wp_enqueue_script('hji_tinymce_shortcode', Membership::$url . '/resources/scripts/build/components/tinymceToShortcode.js');
}
}
function isMcePopup()
{
if (isset($_REQUEST['action']) && $_REQUEST['action'] == $this->mcePluginModel->getAction())
{
return true;
}
return false;
}
function registerPlugin($plugin_array)
{
$plugin_array[$this->mcePluginModel->getHandle()] = Membership::$url . '/resources/scripts/build/components/tinymcePlugin.js';
return $plugin_array;
}
function registerButton($buttons)
{
array_push($buttons, "|", $this->mcePluginModel->getHandle());
return $buttons;
}
function renderMcePopupDialog()
{
if (!current_user_can('edit_pages') && !current_user_can('edit_posts'))
{
die(__("You are not allowed to be here"));
}
if (!$_REQUEST['plugin'])
{
die();
}
$view = new \hji\common\utils\Views(Membership::$dir . '/common/views/');
$vars['mcePluginModel'] = $this->mcePluginModel;
echo $view->render('tinymce-page', $vars);
die();
}
}