Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- *
- * @ This file is created by http://DeZender.Net
- * @ deZender (PHP5 Decoder for ionCube Encoder)
- *
- * @ Version : 3.5.0.0
- * @ Author : DeZender
- * @ Release on : 22.06.2018
- * @ Official site : http://DeZender.Net
- *
- */
- namespace SR\Utils;
- class Scheduled extends Events
- {
- private static $instance = null;
- public function __construct()
- {
- parent::__construct();
- add_filter('cron_schedules', array($this, 'cronSchedules'));
- add_action('sr_event', array($this, 'event'), 10, 1);
- add_action('sr_event_update', array($this, 'update'));
- add_action('sr_statistic', array($this, 'statistic'));
- add_action('sr_analytics', array($this, 'analytics'));
- add_action('sr_cleaner', array($this, 'cleaner'));
- add_action('sr_welcome', array($this, 'welcome'));
- add_action('sr_notify', array($this, 'notify'));
- add_action('sr_logs', array($this, 'logs'), 10, 2);
- add_action('sr_migrate', array($this, 'migrate'), 10, 1);
- }
- public static function init()
- {
- if (self::$instance == null) {
- self::$instance = new self();
- }
- return self::$instance;
- }
- public function setErrorHandler($type, $message, $file, $line)
- {
- if (!(error_reporting() & $type)) {
- return false;
- }
- $prefix = plugin_dir_path(__DIR__);
- $message = sprintf('%s, called in %s on line %s', $message, $file, $line);
- $message = str_replace($prefix, '/', $message);
- throw new \SR\Exceptions\Exception($message);
- }
- public function cronSchedules($schedules)
- {
- $schedules['weekly'] = array('interval' => 604800, 'display' => __('Once Weekly'));
- return $schedules;
- }
- public function update()
- {
- $settings = \SR\Settings\Settings::init()->getAll();
- foreach ($settings as $social => $value) {
- $socialId = \SR\Constants\Event::getSocialIdByName($social);
- if ($socialId === null || !isset($value['scope'])) {
- continue;
- }
- $events = \SR\Helpers\Event::getEventsBySocialId($socialId);
- foreach ($value['scope'] as $action => $enabled) {
- if (!$enabled) {
- continue;
- }
- $actionId = \SR\Constants\Event::getActionIdByName($action);
- $fined = Underscore::filter(
- $events,
- function($event) use ($actionId) {
- return !$event['is_force'] && $event['action_id'] == $actionId;
- }
- );
- $finedCount = count($fined);
- if (1 < $finedCount) {
- $latest = Underscore::initial($fined);
- if ($finedCount == 2) {
- $latest = array($latest);
- }
- Underscore::each(
- $latest,
- function($event) {
- \SR\Helpers\Event::remove($event['id']);
- }
- );
- }
- if (!$fined) {
- \SR\Helpers\Event::create(array('social_id' => $socialId, 'action_id' => $actionId));
- }
- }
- }
- $events = \SR\Helpers\Event::get();
- $time = time();
- Underscore::each(
- $events,
- function($event) use ($time) {
- $scheduled = wp_next_scheduled('sr_event', array($event['id']));
- if (!$scheduled) {
- if ($event['time'] < $time) {
- $event['time'] = $time + 10;
- }
- wp_schedule_single_event($event['time'], 'sr_event', array($event['id']));
- }
- }
- );
- }
- public function migrate()
- {
- wp_schedule_single_event(time() + 30, 'sr_migrate');
- global $wpdb;
- $tSpinners = (string) $wpdb->base_prefix . 'sr_migrate_spinners';
- $tObjects = (string) $wpdb->base_prefix . 'sr_migrate_objects';
- $tMedia = (string) $wpdb->base_prefix . 'sr_migrate_media';
- $tEvents = (string) $wpdb->base_prefix . 'sr_migrate_events';
- $spinners = $wpdb->query("SHOW TABLES LIKE '" . $tSpinners . "'");
- if ($spinners == 1) {
- $spinners = $wpdb->get_results('SELECT * FROM ' . $tSpinners . ' LIMIT 20', ARRAY_A);
- Underscore::each(
- $spinners,
- function($spinner) use ($wpdb, $tSpinners) {
- $typeId = 0;
- if ($spinner['type'] == 'comment') {
- $typeId = 1;
- }
- if ($spinner['type'] == '$type') {
- $typeId = 2;
- }
- $data = array('type_id' => $typeId, 'template' => $spinner['content']);
- $isAdded = \SR\Helpers\Spinner::add(array($data));
- if ($isAdded) {
- $wpdb->delete($tSpinners, array('id' => $spinner['id']), array('%d'));
- }
- }
- );
- if (count($spinners) < 10) {
- $count = $wpdb->get_var('SELECT COUNT(*) FROM ' . $tSpinners);
- if ($count == 0) {
- $wpdb->query('DROP TABLE ' . $tSpinners);
- }
- ......................................................................................
- ..............................................................
- ...............................
Advertisement
Add Comment
Please, Sign In to add comment