예제 #1
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();
     }
 }
예제 #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 (is_object($postArr)) {
         $postID = $postArr->ID;
     } else {
         $postID = $postArr;
     }
     $isPost = isset($_POST["snapEdIT"]);
     if ($isPost) {
         $plgn_NS_SNAutoPoster->NS_SNAP_SavePostMetaTags($postID);
     }
     if (function_exists('nxs_doSMAS2')) {
         nxs_doSMAS2($postArr, $type, $aj);
         return;
     } else {
         if (!isset($plgn_NS_SNAutoPoster)) {
             return;
         }
         $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($_POST["snapEdIT"]) && $_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' ? 'Non Human' : 'Immediate')) . ' ####=========------');
         $post = get_post($postID);
         $args = array('public' => true, '_builtin' => false);
         $output = 'names';
         $operator = 'and';
         $post_types = array();
         if (function_exists('get_post_types')) {
             $post_types = get_post_types($args, $output, $operator);
         }
         $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', '', 'Non-Human Post - Category Excluded - Post ID:(' . $postID . ')');
                 return;
             }
         }
         if ($options['nxsCPTSeld'] != '') {
             $nxsCPTSeld = unserialize($options['nxsCPTSeld']);
         } else {
             $nxsCPTSeld = array_keys($post_types);
         }
         //prr($nxsCPTSeld);
         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)) {
             foreach ($nxs_snapAvNts as $avNt) {
                 if (count($options[$avNt['lcode']]) > 0) {
                     $clName = 'nxs_snapClass' . $avNt['code'];
                     if ($isPost && isset($_POST[$avNt['lcode']])) {
                         $po = $_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'] . ')', '[Non-Human Post]  - Individual Category Excluded - Post ID:(' . $postID . ')');
                                 return;
                             }
                         }
                     }
                     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;
                             $args = array($postID, $optMt);
                             wp_schedule_single_event($optMt['timeToRun'], 'ns_doPublishTo' . $avNt['code'], $args);
                             nxs_addToLogN('BI', 'Scheduled', $avNt['name'] . ' (' . $optMt['nName'] . ')', ' PostID:(' . $postID . ')');
                         } else {
                             $fname = 'nxs_doPublishTo' . $avNt['code'];
                             $fname($postID, $optMt);
                         }
                     } else {
                         nxs_addToLogN('GR', 'Skipped', $avNt['name'] . ' (' . $optMt['nName'] . ')', '-=[Unchecked Account]=- - PostID:' . $postID . '');
                     }
                 }
             }
         }
     }
     if ($isS) {
         restore_current_blog();
     }
 }