Guest User

Untitled

a guest
Jun 18th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. <?php
  2. /*
  3. *
  4. * @ This file is created by http://DeZender.Net
  5. * @ deZender (PHP5 Decoder for ionCube Encoder)
  6. *
  7. * @ Version : 3.5.0.0
  8. * @ Author : DeZender
  9. * @ Release on : 22.06.2018
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. namespace SR\Utils;
  15.  
  16. class Scheduled extends Events
  17. {
  18. private static $instance = null;
  19.  
  20. public function __construct()
  21. {
  22. parent::__construct();
  23. add_filter('cron_schedules', array($this, 'cronSchedules'));
  24. add_action('sr_event', array($this, 'event'), 10, 1);
  25. add_action('sr_event_update', array($this, 'update'));
  26. add_action('sr_statistic', array($this, 'statistic'));
  27. add_action('sr_analytics', array($this, 'analytics'));
  28. add_action('sr_cleaner', array($this, 'cleaner'));
  29. add_action('sr_welcome', array($this, 'welcome'));
  30. add_action('sr_notify', array($this, 'notify'));
  31. add_action('sr_logs', array($this, 'logs'), 10, 2);
  32. add_action('sr_migrate', array($this, 'migrate'), 10, 1);
  33. }
  34.  
  35. public static function init()
  36. {
  37. if (self::$instance == null) {
  38. self::$instance = new self();
  39. }
  40.  
  41. return self::$instance;
  42. }
  43.  
  44. public function setErrorHandler($type, $message, $file, $line)
  45. {
  46. if (!(error_reporting() & $type)) {
  47. return false;
  48. }
  49.  
  50. $prefix = plugin_dir_path(__DIR__);
  51. $message = sprintf('%s, called in %s on line %s', $message, $file, $line);
  52. $message = str_replace($prefix, '/', $message);
  53.  
  54. throw new \SR\Exceptions\Exception($message);
  55. }
  56.  
  57. public function cronSchedules($schedules)
  58. {
  59. $schedules['weekly'] = array('interval' => 604800, 'display' => __('Once Weekly'));
  60.  
  61. return $schedules;
  62. }
  63.  
  64. public function update()
  65. {
  66. $settings = \SR\Settings\Settings::init()->getAll();
  67.  
  68. foreach ($settings as $social => $value) {
  69. $socialId = \SR\Constants\Event::getSocialIdByName($social);
  70.  
  71. if ($socialId === null || !isset($value['scope'])) {
  72. continue;
  73. }
  74.  
  75. $events = \SR\Helpers\Event::getEventsBySocialId($socialId);
  76.  
  77. foreach ($value['scope'] as $action => $enabled) {
  78. if (!$enabled) {
  79. continue;
  80. }
  81.  
  82. $actionId = \SR\Constants\Event::getActionIdByName($action);
  83. $fined = Underscore::filter(
  84. $events,
  85. function($event) use ($actionId) {
  86. return !$event['is_force'] && $event['action_id'] == $actionId;
  87. }
  88. );
  89. $finedCount = count($fined);
  90.  
  91. if (1 < $finedCount) {
  92. $latest = Underscore::initial($fined);
  93.  
  94. if ($finedCount == 2) {
  95. $latest = array($latest);
  96. }
  97.  
  98. Underscore::each(
  99. $latest,
  100. function($event) {
  101. \SR\Helpers\Event::remove($event['id']);
  102. }
  103. );
  104. }
  105.  
  106. if (!$fined) {
  107. \SR\Helpers\Event::create(array('social_id' => $socialId, 'action_id' => $actionId));
  108. }
  109. }
  110. }
  111. $events = \SR\Helpers\Event::get();
  112. $time = time();
  113. Underscore::each(
  114. $events,
  115. function($event) use ($time) {
  116. $scheduled = wp_next_scheduled('sr_event', array($event['id']));
  117.  
  118. if (!$scheduled) {
  119. if ($event['time'] < $time) {
  120. $event['time'] = $time + 10;
  121. }
  122.  
  123. wp_schedule_single_event($event['time'], 'sr_event', array($event['id']));
  124. }
  125. }
  126. );
  127. }
  128.  
  129. public function migrate()
  130. {
  131. wp_schedule_single_event(time() + 30, 'sr_migrate');
  132. global $wpdb;
  133. $tSpinners = (string) $wpdb->base_prefix . 'sr_migrate_spinners';
  134. $tObjects = (string) $wpdb->base_prefix . 'sr_migrate_objects';
  135. $tMedia = (string) $wpdb->base_prefix . 'sr_migrate_media';
  136. $tEvents = (string) $wpdb->base_prefix . 'sr_migrate_events';
  137. $spinners = $wpdb->query("SHOW TABLES LIKE '" . $tSpinners . "'");
  138.  
  139. if ($spinners == 1) {
  140. $spinners = $wpdb->get_results('SELECT * FROM ' . $tSpinners . ' LIMIT 20', ARRAY_A);
  141. Underscore::each(
  142. $spinners,
  143. function($spinner) use ($wpdb, $tSpinners) {
  144. $typeId = 0;
  145.  
  146. if ($spinner['type'] == 'comment') {
  147. $typeId = 1;
  148. }
  149.  
  150. if ($spinner['type'] == '$type') {
  151. $typeId = 2;
  152. }
  153.  
  154. $data = array('type_id' => $typeId, 'template' => $spinner['content']);
  155. $isAdded = \SR\Helpers\Spinner::add(array($data));
  156.  
  157. if ($isAdded) {
  158. $wpdb->delete($tSpinners, array('id' => $spinner['id']), array('%d'));
  159. }
  160. }
  161. );
  162.  
  163. if (count($spinners) < 10) {
  164. $count = $wpdb->get_var('SELECT COUNT(*) FROM ' . $tSpinners);
  165.  
  166. if ($count == 0) {
  167. $wpdb->query('DROP TABLE ' . $tSpinners);
  168. }
  169. ......................................................................................
  170. ..............................................................
  171. ...............................
Advertisement
Add Comment
Please, Sign In to add comment