function xt_cron_autoshare() { global $wpdb; if (!IS_CLOUD) { set_time_limit(0); } $date = gmdate('Y-m-d H', current_time('timestamp')); $shares = $wpdb->get_results('SELECT * FROM ' . XT_TABLE_SHARE_CRON . ' WHERE create_date<=\'' . $date . '\' LIMIT 200'); $deleteKeys = array(); if (!empty($shares)) { foreach ($shares as $share) { $share_key = $share->share_key; $user_id = $share->user_id; $user_name = $share->user_name; $album_id = $share->album_id; $data = array(); if (!empty($share->cache_data)) { $data = maybe_unserialize($share->cache_data); if (!empty($data)) { if (xt_check_share($data['share_key'], $user_id)) { $deleteKeys[] = $share_key; continue; } } } if (empty($data)) { $fetch = array(); if (startsWith($share_key, 'tb')) { //taobao $fetch = xt_share_fetch('http://item.taobao.com/item.htm?id=' . str_replace('tb_', '', $share_key)); } elseif (startWith($share_key, 'pp')) { //paipai $fetch = xt_share_fetch('http://auction1.paipai.com/' . str_replace('pp_', '', $share_key)); } if (!empty($fetch)) { $data = array('share_key' => $fetch['share_key'], 'title' => $fetch['title'], 'pic_url' => $fetch['pic_url'], 'price' => $fetch['price'], 'cid' => $fetch['cid'], 'cache_data' => $fetch['cache_data'], 'content' => '', 'from_type' => $fetch['from_type']); } } if (!empty($data)) { xt_share_share(array('share_key' => $data['share_key'], 'title' => $data['title'], 'pic_url' => $data['pic_url'], 'price' => $data['price'], 'cid' => (int) $data['cid'], 'user_id' => (int) $user_id, 'user_name' => $user_name, 'cache_data' => $data['cache_data'], 'from_type' => $data['from_type'], 'data_type' => 1, 'content' => isset($data['content']) ? trim(strip_tags($data['content'])) : null, 'album_id' => (int) $album_id)); } $deleteKeys[] = $share_key; } if (!empty($deleteKeys)) { $_keys = array(); foreach ($deleteKeys as $deleteKey) { $_keys[] = "'{$deleteKey}'"; } $wpdb->query('DELETE FROM ' . XT_TABLE_SHARE_CRON . ' WHERE share_key in (' . implode(',', $_keys) . ')'); } xt_catalogs_share(true); //reload catalogs and tags do_action('xt_page_updated', 'home'); //clear home cache } }
function xt_ajax_share_add() { //第一步:新增分享 $xt_share_param = $_POST; //第二步:加入专辑 $result = array('code' => 0, 'msg' => '', 'result' => array()); if (!isset($_POST['share_key'])) { $result['code'] = 500; $result['msg'] = '未指定要分享的对象'; } if (!isset($_POST['user_id'])) { $result['code'] = 500; $result['msg'] = '未指定评论人'; } if (!isset($_POST['album_title'])) { $result['code'] = 500; $result['msg'] = '未指定专辑'; } if (!isset($_POST['title'])) { $result['code'] = 500; $result['msg'] = '未指定宝贝名称'; } if (!isset($_POST['from_type'])) { $result['code'] = 500; $result['msg'] = '未指定分享宝贝来源'; } if (!isset($_POST['data_type'])) { $result['code'] = 500; $result['msg'] = '未指定分享宝贝类型'; } $user = wp_get_current_user(); if ($user->exists()) { global $wpdb; if ($user->ID != absint($_POST['user_id'])) { $result['code'] = 500; $result['msg'] = '用户不一致'; } if (empty($user->display_name)) { $user->display_name = $user->user_login; } $user_name = $wpdb->escape($user->display_name); } else { $result['code'] = 500; $result['msg'] = '未登录'; } if ($result['code'] == 0) { $result['result'] = xt_share_share($_POST); } exit(json_encode($result)); }