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
<?php
namespace hji\homevalue\controllers;
use \hji\membership\Membership;
class HomeValueTinyMCE
{
function __construct()
{
add_action('admin_init', array($this, 'init'));
add_action('wp_ajax_hji_homevalue_tinymce', array($this, 'loadWindow'));
}
function init()
{
if (!current_user_can('edit_posts') && !current_user_can('edit_pages'))
{
return;
}
if (get_user_option('rich_editing') == 'true')
{
add_filter('mce_external_plugins', array($this, 'registerPlugin'));
add_filter('hji_mce_buttons', array($this, 'registerButton'));
}
}
function registerPlugin($plugin_array)
{
$plugin_array['HomeValue'] = \hji\homevalue\HomeValue::$scripts . '/components/tinymce.js';
return $plugin_array;
}
function registerButton($buttons)
{
array_push($buttons, "HomeValue");
return $buttons;
}
function loadWindow()
{
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(\hji\homevalue\HomeValue::$dir . '/classes/views');
$fields = array('fields' => $this->_getSupportedFields());
echo $view->render('home-value-tinymce-widget', $fields);
die();
}
private function _getSupportedFields()
{
$fields = HomeValueWidget::$supportedFields;
$result = array();
foreach($fields as $name)
{
$result[$name]['id'] = $name;
$result[$name]['name'] = $name;
$result[$name]['value'] = false;
}
return $result;
}
}