Пример #1
0
 function NS_SNAP_SavePostMetaTags($id)
 {
     global $nxs_snapAvNts, $plgn_NS_SNAutoPoster;
     if (!empty($_POST['nxs_snapPostOptions'])) {
         $NXS_POSTX = $_POST['nxs_snapPostOptions'];
         $NXS_POST = array();
         $NXS_POST = NXS_parseQueryStr($NXS_POSTX);
     } else {
         $NXS_POST = $_POST;
     }
     if (count($NXS_POST) < 1 || !isset($NXS_POST["snapEdIT"]) || empty($NXS_POST["snapEdIT"])) {
         return;
     }
     if (get_magic_quotes_gpc() || !empty($_POST['nxs_mqTest']) && $_POST['nxs_mqTest'] == "\\'") {
         array_walk_recursive($NXS_POST, 'nsx_stripSlashes');
     }
     array_walk_recursive($NXS_POST, 'nsx_fixSlashes');
     if (!isset($plgn_NS_SNAutoPoster)) {
         return;
     }
     $options = $plgn_NS_SNAutoPoster->nxs_options;
     //  echo "| NS_SNAP_SavePostMetaTags - ".$id." |";
     $post = get_post($id);
     if ($post->post_type == 'revision' && $post->post_status == 'inherit' && $post->post_parent != '0') {
         return;
     }
     // prr($NXS_POST);
     if (empty($NXS_POST["useSURL"])) {
         $NXS_POST["useSURL"] = '2';
     }
     delete_post_meta($id, '_snap_forceSURL');
     add_post_meta($id, '_snap_forceSURL', $NXS_POST["useSURL"]);
     delete_post_meta($id, 'snap_MYURL');
     add_post_meta($id, 'snap_MYURL', $NXS_POST["urlToUse"]);
     delete_post_meta($id, 'snapEdIT');
     add_post_meta($id, 'snapEdIT', '1');
     $snap_isAutoPosted = get_post_meta($id, 'snap_isAutoPosted', true);
     if ($snap_isAutoPosted == '1' && $post->post_status == 'future') {
         delete_post_meta($id, 'snap_isAutoPosted');
         add_post_meta($id, 'snap_isAutoPosted', '2');
     }
     foreach ($nxs_snapAvNts as $avNt) {
         // echo "--------------------------------------------";  prr($avNt);
         if (isset($options[$avNt['lcode']]) && count($options[$avNt['lcode']]) > 0 && isset($NXS_POST[$avNt['lcode']]) && count($NXS_POST[$avNt['lcode']]) > 0) {
             $savedMeta = maybe_unserialize(get_post_meta($id, 'snap' . $avNt['code'], true));
             if (is_array($NXS_POST[$avNt['lcode']])) {
                 $ii = 0;
                 foreach ($NXS_POST[$avNt['lcode']] as $pst) {
                     // echo "###########";  prr($pst);
                     if (is_array($pst) && empty($pst['do' . $avNt['code']]) && empty($NXS_POST[$avNt['lcode']][$ii]['do' . $avNt['code']])) {
                         $NXS_POST[$avNt['lcode']][$ii]['do' . $avNt['code']] = 0;
                     }
                     $ii++;
                 }
             }
             $newMeta = $NXS_POST[$avNt['lcode']];
             if (is_array($savedMeta) && is_array($newMeta)) {
                 $newMeta = nxsMergeArraysOV($savedMeta, $newMeta);
             }
             // echo "#####~~~~~~~~~ ".$id."| snap".$avNt['code']; prr($savedMeta); echo "||"; prr($newMeta);// $newMeta = 'AAA';
             delete_post_meta($id, 'snap' . $avNt['code']);
             add_post_meta($id, 'snap' . $avNt['code'], str_replace('\\', '\\\\', serialize($newMeta)));
         }
     }
     //    die();
     // prr($_POST);
 }
Пример #2
0
 function nxs_snapPublishTo($postArr, $type = '', $aj = false)
 {
     global $plgn_NS_SNAutoPoster, $nxs_snapAvNts, $blog_id, $nxs_tpWMPU;
     //  echo " | nxs_doSMAS2 | "; prr($postArr);
     if (!isset($plgn_NS_SNAutoPoster)) {
         return;
     }
     $options = $plgn_NS_SNAutoPoster->nxs_options;
     if (!empty($_POST['nxs_snapPostOptions'])) {
         $NXS_POSTX = $_POST['nxs_snapPostOptions'];
         $NXS_POST = array();
         $NXS_POST = NXS_parseQueryStr($NXS_POSTX);
     } else {
         $NXS_POST = $_POST;
     }
     if (is_object($postArr)) {
         $postID = $postArr->ID;
     } else {
         $postID = $postArr;
         $postArr = get_post($postID);
     }
     $isPost = isset($NXS_POST["snapEdIT"]);
     $post = get_post($postID);
     if ($post->post_status != 'publish') {
         sleep(5);
         $post = get_post($postID);
         $postArr = $post;
         if ($post->post_status != 'publish') {
             nxs_addToLogN('I', 'Cancelled', '', 'Autopost Cancelled - Post is not "Published" Right now - Post ID:(' . $postID . ') - Current Post status -' . $post->post_status);
             return;
         }
     }
     //nxs_addToLogN('BG', 'Post Status Changed', '', '-=## Autopost requested.'.($blog_id>1?'BlogID:'.$blog_id:'').' PostID:('.$postID.') Post Type: '.$post->post_type.' ##=-');
     //$args=array('public'=>true, '_builtin'=>false);  $output = 'names';  $operator = 'and';  $post_types = array(); ## Removed because some post types are not available from WP Cron
     // if (function_exists('get_post_types')) { $post_types=get_post_types($args, $output, $operator);  ## Removed because some post types are not available from WP Cron
     if (isset($options['nxsCPTSeld']) && $options['nxsCPTSeld'] != '') {
         $nxsCPTSeld = unserialize($options['nxsCPTSeld']);
     } else {
         $nxsCPTSeld = array();
     }
     // if ($post->post_type == 'post' || ($options['useForPages']=='1' && $post->post_type == 'page') || (in_array($post->post_type, $post_types) && in_array($post->post_type, $nxsCPTSeld))) {  ## Removed because some post types are not available from WP Cron
     $post_types = array();
     if ($post->post_type == 'post' || $options['useForPages'] == '1' && $post->post_type == 'page' || in_array($post->post_type, $nxsCPTSeld)) {
         if ($isPost && $options['skipSecurity'] != '1' && !current_user_can("make_snap_posts") && !current_user_can("manage_options")) {
             nxs_addToLogN('I', 'Skipped', '', 'Current user can\'t autopost - Post ID:(' . $postID . ')');
             return;
         }
         $postUser = $postArr->post_author;
         if ($options['skipSecurity'] != '1' && !user_can($postUser, "make_snap_posts") && !user_can($postUser, "manage_options")) {
             nxs_addToLogN('I', 'Skipped', '', '', 'User ID ' . $postUser . ' can\'t autopost (see <a target="_blank" href="http://www.nextscripts.com/support-faq/#a17">FAQ #1.7</a>)  - Post ID:(' . $postID . ')');
             return;
         }
         if ($isPost) {
             $plgn_NS_SNAutoPoster->NS_SNAP_SavePostMetaTags($postID);
         }
         if (function_exists('nxs_doSMAS2')) {
             nxs_doSMAS2($postArr, $type, $aj);
             return;
         } else {
             $options = $plgn_NS_SNAutoPoster->nxs_options;
             $ltype = strtolower($type);
             if ($nxs_tpWMPU == 'S') {
                 switch_to_blog(1);
                 $plgn_NS_SNAutoPoster = new NS_SNAutoPoster();
                 $options = $plgn_NS_SNAutoPoster->nxs_options;
                 restore_current_blog();
             }
             if (!isset($options['nxsHTDP']) || $options['nxsHTDP'] == 'S') {
                 if (isset($NXS_POST["snapEdIT"]) && $NXS_POST["snapEdIT"] == '1') {
                     $publtype = 'S';
                     $delay = rand(2, 10);
                 } else {
                     $publtype = 'A';
                 }
             } else {
                 $publtype = 'I';
             }
             nxs_addToLogN('BG', 'Start =- ', '', '------=========#### NEW AUTO-POST REQUEST ' . ($blog_id > 1 ? 'BlogID:' . $blog_id : '') . ' PostID:(' . $postID . ') ' . ($publtype == 'S' ? 'Scheduled +' . $delay : ($publtype == 'A' ? 'Automated' : 'Immediate')) . ' ####=========------');
             $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true);
             if ($snap_isAutoPosted == '1') {
                 nxs_addToLogN('W', 'Skipped', '', 'Already Autoposted - Post ID:(' . $postID . ')');
                 return;
             }
             $snap_isEdIT = get_post_meta($postID, 'snapEdIT', true);
             if ($snap_isEdIT != '1') {
                 $doPost = true;
                 $exclCats = maybe_unserialize($options['exclCats']);
                 $postCats = wp_get_post_categories($postID);
                 foreach ($postCats as $pCat) {
                     if (is_array($exclCats) && in_array($pCat, $exclCats)) {
                         $doPost = false;
                     } else {
                         $doPost = true;
                         break;
                     }
                 }
                 if (!$doPost) {
                     nxs_addToLogN('I', 'Skipped', '', 'Automated Post - Category Excluded - Post ID:(' . $postID . ')');
                     return;
                 }
             }
             foreach ($nxs_snapAvNts as $avNt) {
                 if (isset($options[$avNt['lcode']]) && count($options[$avNt['lcode']]) > 0) {
                     $clName = 'nxs_snapClass' . $avNt['code'];
                     if ($isPost && isset($NXS_POST[$avNt['lcode']])) {
                         $po = $NXS_POST[$avNt['lcode']];
                     } else {
                         $po = get_post_meta($postID, 'snap' . $avNt['code'], true);
                         $po = maybe_unserialize($po);
                     }
                     if (isset($po) && is_array($po)) {
                         $isPostMeta = true;
                     } else {
                         $isPostMeta = false;
                         $po = $options[$avNt['lcode']];
                     }
                     delete_post_meta($postID, 'snap_isAutoPosted');
                     add_post_meta($postID, 'snap_isAutoPosted', '1');
                     $optMt = $options[$avNt['lcode']][0];
                     if ($isPostMeta) {
                         $ntClInst = new $clName();
                         $optMt = $ntClInst->adjMetaOpt($optMt, $po[0]);
                     }
                     if ($snap_isEdIT != '1') {
                         $doPost = true;
                         if ($optMt['catSel'] == '1' && trim($optMt['catSelEd']) != '') {
                             $inclCats = explode(',', $optMt['catSelEd']);
                             foreach ($postCats as $pCat) {
                                 if (!in_array($pCat, $inclCats)) {
                                     $doPost = false;
                                 } else {
                                     $doPost = true;
                                     break;
                                 }
                             }
                             if (!$doPost) {
                                 nxs_addToLogN('I', 'Skipped', $avNt['name'] . ' (' . $optMt['nName'] . ')', '[Automated Post]  - Individual Category Excluded - Post ID:(' . $postID . ')');
                                 continue;
                             }
                         }
                         //## Get tags
                         if (!empty($optMt['tagsSel'])) {
                             $inclTags = explode(',', strtolower($optMt['tagsSel']));
                             $postTags = wp_get_post_tags($postID, array('fields' => 'slugs'));
                             $postCust = array();
                             //## Get all custom post types
                             foreach ($inclTags as $iTag) {
                                 if (strpos($iTag, '|') !== false) {
                                     $dd = explode('|', $itag);
                                     if (empty($postCust[$dd[0]])) {
                                         $postCust[$dd[0]] = wp_get_object_terms($postID, $dd[0], array('fields' => 'slugs'));
                                     }
                                     if (!in_array(strtolower($dd[1]), $postCust[$dd[0]])) {
                                         $doPost = false;
                                     } else {
                                         $doPost = true;
                                         break;
                                     }
                                 } else {
                                     if (!in_array(strtolower($iTag), $postTags)) {
                                         $doPost = false;
                                     } else {
                                         $doPost = true;
                                         break;
                                     }
                                 }
                             }
                             if (!$doPost) {
                                 nxs_addToLogN('I', 'Skipped', $avNt['name'] . ' (' . $optMt['nName'] . ')', '[Automated Post]  - Tag Excluded - Post ID:(' . $postID . ') - Included Tags: ' . $optMt['tagsSel'] . ' | Post Tags: ' . print_r($postTags, true) . " | " . print_r($postCust, true));
                                 continue;
                             }
                         }
                     }
                     if ($optMt['do' . $avNt['code']] == '1') {
                         $optMt['ii'] = 0;
                         if ($publtype == 'A' && ($optMt['nMin'] > 0 || $optMt['nHrs'] > 0 || $optMt['nTime'] != '')) {
                             $publtype = 'S';
                         }
                         if ($publtype == 'S') {
                             if (isset($optMt['nHrs']) && isset($optMt['nMin']) && ($optMt['nHrs'] > 0 || $optMt['nMin'] > 0)) {
                                 $delay = $optMt['nMin'] * 60 + $optMt['nHrs'] * 3600;
                                 nxs_addToLogN('I', 'Delayed', $avNt['name'] . ' (' . $optMt['nName'] . ')', 'Post has been delayed for ' . $delay . ' Seconds (' . ($optMt['nHrs'] > 0 ? $optMt['nHrs'] . ' Hours' : '') . " " . ($optMt['nMin'] > 0 ? $optMt['nMin'] . ' Minutes' : '') . ')');
                             } else {
                                 $delay = rand(2, 10);
                             }
                             $optMt['timeToRun'] = time() + $delay;
                             if ($options['ver'] > 300.33) {
                                 $shName = '_nxs_snap_sh_' . $avNt['code'] . '0_' . $optMt['timeToRun'];
                                 delete_post_meta($postID, $shName);
                                 add_post_meta($postID, $shName, $optMt);
                                 $args = array($postID, $shName);
                             } else {
                                 $args = array($postID, $optMt);
                             }
                             wp_schedule_single_event($optMt['timeToRun'], 'ns_doPublishTo' . $avNt['code'], $args);
                             nxs_addToLogN('BI', 'Scheduled', $avNt['name'] . ' (' . $optMt['nName'] . ') for ' . $optMt['timeToRun'] . "(" . date_i18n('Y-m-d H:i:s', $optMt['timeToRun'] + get_option('gmt_offset') * HOUR_IN_SECONDS) . ")", ' PostID:(' . $postID . ')');
                         } else {
                             $fname = 'nxs_doPublishTo' . $avNt['code'];
                             $fname($postID, $optMt);
                         }
                     } else {
                         nxs_addToLogN('GR', 'Skipped', $avNt['name'] . ' (' . $optMt['nName'] . ')', '-=[Unchecked Account]=- - PostID:' . $postID . '');
                     }
                 }
             }
         }
     } else {
         nxs_addToLogN('I', 'Skipped', '', 'Excluded Post Type: ' . $post->post_type . ' (Post ID: ' . $postID . ')| NOT IN (' . print_r($nxsCPTSeld, true) . ')| ALL (' . print_r($post_types, true) . ')');
         return;
     }
     if ($isS) {
         restore_current_blog();
     }
 }