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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
<?php
namespace hji\recentsales;
use \hji\membership\models\Settings as M_Settings;
new RecentSales();
class RecentSales
{
const NAME = 'HJI Recent Sales';
private $canLoad = false;
private $licenseKey;
public static $slug;
public static $dir;
public static $url;
public static $scripts;
function __construct()
{
add_filter('hji_membership_register_plugin', array($this, 'registerPlugin'));
}
function registerPlugin($plugins)
{
array_push($plugins, array('file' => __FILE__, 'callback' => array($this, 'init')));
return $plugins;
}
function init()
{
self::$slug = basename(dirname(__FILE__));
self::$dir = WP_PLUGIN_DIR . '/' . self::$slug;
self::$url = WP_PLUGIN_URL . '/' . self::$slug;
self::$scripts = self::$url . '/resources/scripts/build';
require_once(self::$dir . '/classes/widgets/RecentSales.php');
add_action('widgets_init', function(){
register_widget('\hji\recentsales\widgets\RecentSales');
});
add_action('wp_enqueue_scripts', array($this, 'loadStyles'));
if (is_admin())
{
add_action('admin_enqueue_scripts', array($this, 'loadAdminScripts'));
add_action('admin_print_footer_scripts', array($this, 'initWidgetsAdminJs'));
}
$this->initPlugin();
}
function initPlugin()
{
$settings = new M_Settings();
$this->licenseKey = $settings->licenseKey;
if (!$this->licenseKey)
{
return;
}
$this->registerRequireJs();
require_once(self::$dir . '/classes/controllers/Shortcodes.php');
new controllers\Shortcodes($this->licenseKey);
require_once(self::$dir . '/classes/tinymce/RecentSales.php');
new tinymce\RecentSales();
}
function registerRequireJs()
{
$requireJS = \hji\membership\Membership::getInstance()->requireJs;
$requireJS->addPath(self::$slug . '/main', self::$scripts . '/main');
$requireJS->addPath(self::$slug, self::$url . '/components');
}
function loadStyles()
{
wp_register_style('hji-recent-sales', self::$url . '/resources/styles/recent-sales.min.css');
wp_enqueue_style('hji-recent-sales');
}
function loadAdminScripts()
{
if (!stristr($_SERVER['REQUEST_URI'], 'widgets.php') &&
!stristr($_SERVER['REQUEST_URI'], 'hji_recent_sales_tinymce'))
return;
$adminJs = self::$scripts . '/components/widgets-admin.js';
wp_register_script('hji-recent-sales', $adminJs, array('jquery'), '1.0', true);
wp_enqueue_script('hji-recent-sales');
wp_register_style('hji-recent-sales', self::$url . '/resources/styles/recent-sales-admin.min.css');
wp_enqueue_style('hji-recent-sales');
}
function initWidgetsAdminJs()
{
if (stristr($_SERVER['REQUEST_URI'], 'widgets.php'))
{
?>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('[id*="_recent-sales-"]').ManageRecentSalesWidget();
});
</script>
<?php
}
if (stristr($_SERVER['REQUEST_URI'], 'hji_recent_sales_tinymce'))
{
?>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('[id*="_recent-sales-"]').ManageRecentSalesWidget({tinymce: true});
});
</script>
<?php
}
}
function addNoticeMembershipRequired()
{
echo '<div id="message" class="error"><p><strong style="color: #f00">ERROR (' . self::NAME . '):</strong> HJI Membership & HJI Responsive IDX plugins are required. If you don\'t have them installed, please contact our support department at <a href="mailto:help@homejunction.com">help@homejunction.com</a> or at (858) 777-9533 Ext. 4.</p></div>';
}
}