public static function set_timestamp($value = null)
 {
     if (!$value) {
         $value = $_SERVER['REQUEST_TIME'];
     }
     self::$timestamp = $value;
     theme_options::set_options(self::$iden, self::$timestamp);
 }
Exemplo n.º 2
0
 public static function save_post($post_id)
 {
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return false;
     }
     if (!isset($_POST[__CLASS__ . '-nonce']) || !wp_verify_nonce($_POST[__CLASS__ . '-nonce'], __CLASS__)) {
         return false;
     }
     $opt = self::get_options();
     if (!isset($opt['ids'])) {
         $opt['ids'] = [];
     }
     /**
      * set to recomm
      */
     if (isset($_POST[__CLASS__])) {
         if (!in_array($post_id, $opt['ids'])) {
             $opt['ids'][] = $post_id;
             arsort($opt['ids']);
             $opt['ids'] = array_slice($opt['ids'], 0, 50);
             theme_options::set_options(__CLASS__, $opt);
             self::clear_cache();
         }
     } else {
         $key = array_search($post_id, $opt['ids']);
         if ($key !== false) {
             unset($opt['ids'][$key]);
             $opt['ids'] = array_slice($opt['ids'], 0, 50);
             theme_options::set_options(__CLASS__, $opt);
             self::clear_cache();
         }
     }
 }
Exemplo n.º 3
0
 public static function process()
 {
     theme_features::check_referer();
     $type = isset($_REQUEST['type']) && is_string($_REQUEST['type']) ? $_REQUEST['type'] : false;
     $current_user_id = theme_cache::get_current_user_id();
     switch ($type) {
         /**
          * backend create db table
          */
         case 'create-db':
             if (!theme_cache::current_user_can('manage_options')) {
                 die(___('Sorry, your permission is not enough to create database table.'));
             }
             //die(theme_features::json_format([
             //	'status' => 'error',
             //	'code' => 'invaild_permission',
             //	'msg' => ___('Sorry, your permission is not enough to create database table.'),
             //]));
             if (self::has_table()) {
                 die(___('Sorry, the database table already exists.'));
             }
             //die(theme_features::json_format([
             //	'status' => 'error',
             //	'code' => 'exists_table',
             //	'msg' => ___('Sorry, the database table already exists.'),
             //]));
             self::create_db_table();
             theme_options::set_options(__CLASS__, ['db-version' => self::$db_version]);
             header('location: ' . theme_options::get_url() . '&' . __CLASS__);
             die;
             //die(theme_features::json_format([
             //	'status' => 'success',
             //	'msg' => ___('Database table has been created.'),
             //]));
             /**
              * get-userdata
              */
         //die(theme_features::json_format([
         //	'status' => 'success',
         //	'msg' => ___('Database table has been created.'),
         //]));
         /**
          * get-userdata
          */
         case 'get-userdata':
             /** nonce */
             theme_features::check_nonce();
             /**
              * uid
              */
             $uid = isset($_REQUEST['uid']) && is_numeric($_REQUEST['uid']) ? $_REQUEST['uid'] : false;
             /**
              * get userdata
              */
             $user = self::check_uid($uid);
             /** add user to lists */
             self::add_list($current_user_id, $user->ID);
             die(theme_features::json_format(['status' => 'success', 'name' => esc_html($user->display_name), 'avatar' => get_avatar_url($user->ID), 'msg' => ___('User data loaded, you can send P.M. now.'), 'url' => theme_cache::get_author_posts_url($user->ID)]));
             /**
              * remove user lists
              */
         /**
          * remove user lists
          */
         case 'remove-dialog':
             $receiver_uid = isset($_REQUEST['uid']) && is_numeric($_REQUEST['uid']) ? (int) $_REQUEST['uid'] : false;
             $receiver = self::check_uid($receiver_uid);
             $status = self::remove_list($current_user_id, $receiver->ID);
             if ($status) {
                 die(theme_features::json_format(['status' => 'success', 'code' => 'removed']));
             }
             die(theme_features::json_format(['status' => 'error', 'code' => 'remove_fail']));
             /**
              * send
              */
         /**
          * send
          */
         case 'send':
             /** nonce */
             theme_features::check_nonce();
             $receiver_uid = isset($_REQUEST['uid']) && is_numeric($_REQUEST['uid']) ? $_REQUEST['uid'] : false;
             $receiver = self::check_uid($receiver_uid);
             /** check content */
             $content = isset($_REQUEST['content']) && is_string($_REQUEST['content']) ? trim($_REQUEST['content']) : false;
             if ($content != '') {
                 $content = fliter_script(strip_tags($content, '<a><b><strong><em><i><del>'));
             }
             if (trim($content) == '') {
                 die(theme_features::json_format(['status' => 'error', 'code' => 'empty_content', 'msg' => ___('Sorry, message content is null, please try again.')]));
             }
             /** pass */
             $pm_id = self::insert_pm(['pm_author' => $current_user_id, 'pm_receiver' => $receiver->ID, 'pm_content' => $content]);
             if (!$pm_id) {
                 die(theme_features::json_format(['status' => 'error', 'code' => 'can_not_create_pm', 'msg' => ___('Sorry, system can not create the private message, please try again later.')]));
             }
             /** get pm */
             $pm = self::get_pm($pm_id);
             /** add list for author */
             self::add_list($current_user_id, $pm->pm_receiver);
             /** add list for receiver */
             self::add_list($pm->pm_receiver, $current_user_id);
             die(theme_features::json_format(['status' => 'success', 'pm' => ['pm_receiver' => self::get_niceid($pm->pm_receiver), 'pm_author' => self::get_niceid($pm->pm_author), 'pm_date' => current_time('Y/m/d H:i:s'), 'pm_content' => $pm->pm_content, 'url' => theme_cache::get_author_posts_url($pm->pm_receiver)], 'msg' => ___('Message sent.')]));
             /**
              * latest pm id
              */
         /**
          * latest pm id
          */
         case 'comet':
             /** nonce */
             theme_features::check_nonce();
             $receiver_id = $current_user_id;
             $client_timestamp = isset($_REQUEST['timestamp']) && is_numeric($_REQUEST['timestamp']) ? $_REQUEST['timestamp'] : false;
             /** if not client timestamp, return error */
             if (!$client_timestamp) {
                 die(theme_features::json_format(['status' => 'error', 'code' => 'invaild_timestamp', 'msg' => ___('Sorry, your session is timeout, please refresh page.')]));
             }
             /** set timeout */
             set_time_limit(60);
             /** check new pm for receiver */
             for ($i = 0; $i < self::$comet_timeout; ++$i) {
                 /** have new pm */
                 $timestamp = self::get_timestamp($receiver_id);
                 if ($timestamp <= $client_timestamp) {
                     sleep(1);
                     continue;
                 }
                 /** have new pm, output latest pm */
                 $latest_pm = self::get_pm(self::get_latest_pm_id($receiver_id));
                 /** clear unreads for me */
                 self::clear_unreads($current_user_id);
                 die(theme_features::json_format(['status' => 'success', 'pm' => ['pm_receiver' => self::get_niceid($latest_pm->pm_receiver), 'pm_author' => self::get_niceid($latest_pm->pm_author), 'pm_author_name' => theme_cache::get_the_author_meta('display_name', $latest_pm->pm_author), 'pm_author_avatar' => get_avatar_url($latest_pm->pm_author), 'pm_date' => current_time('Y/m/d H:i:s'), 'pm_content' => $latest_pm->pm_content, 'url' => theme_cache::get_author_posts_url($pm->pm_author)], 'timestamp' => $timestamp]));
             }
             /** timeout msg */
             die(theme_features::json_format(['status' => 'error', 'code' => 'timeout', 'msg' => ___('Timeout')]));
         default:
             die(theme_features::json_format(['status' => 'error', 'code' => 'invaild_type', 'msg' => ___('Sorry, type param is invaild.')]));
     }
 }