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
<?php
namespace hji\recentsales\tinymce;
use \hji\membership\Membership;
use \hji\ResponsiveIDX\ResponsiveIDX;
class RecentSales
{
function __construct()
{
add_action('admin_init', array($this, 'init'));
add_action('wp_ajax_hji_recent_sales_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['RecentSales'] = \hji\recentsales\RecentSales::$scripts . '/components/tinymce-recent-sales.js';
return $plugin_array;
}
function registerButton($buttons)
{
array_push($buttons, "|", "RecentSales");
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();
}
$markets = Membership::getInstance()->getMarkets();
$markets = (!$markets || empty($markets)) ? array() : $markets;
require_once(Membership::$dir . '/common/utils/View.php');
$view = new \hji\common\utils\View();
$params = array(
'fields' => $this->_getSupportedFields(),
'markets' => $markets
);
echo $view->render(\hji\recentsales\RecentSales::$dir .'/classes/views/tinymce-widget.phtml', $params);
die();
}
private function _getSupportedFields()
{
$fields = \hji\recentsales\widgets\RecentSales::$supportedFields;
$result = array();
foreach($fields as $name)
{
$result[$name]['id'] = $name;
$result[$name]['name'] = $name;
$result[$name]['value'] = false;
}
if (isset($result['radius']))
{
$result['radius']['value'] = 3;
}
if (isset($result['days']))
{
$result['days']['value'] = 60;
}
return $result;
}
}