コード例 #1
0
ファイル: serp.api.class.php プロジェクト: shahadat014/geleyi
 /**
  * Singleton pattern
  *
  * @return pspSeoCheck Singleton instance
  */
 public static function getInstance()
 {
     if (!self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
コード例 #2
0
ファイル: init.php プロジェクト: shahadat014/geleyi
 public function check_reporter()
 {
     @ini_set('max_execution_time', 0);
     @set_time_limit(0);
     // infinte
     global $wpdb;
     $__tasks = array();
     //retrives (url, keyword) pairs which have common keywords!
     $sql = "SELECT a.id, a.focus_keyword, a.search_engine, COUNT(a.id) AS nb FROM " . $wpdb->prefix . "psp_serp_reporter as a WHERE 1=1 and a.publish='Y' GROUP BY a.focus_keyword, a.search_engine HAVING nb>1 ORDER BY a.id ASC;";
     $res = $wpdb->get_results($sql, ARRAY_A);
     // exit if no tasks to be run
     if (count($res) > 0) {
         $__tasks[0] = $res;
     }
     //retrives (url, keyword) pairs which don't have common keywords!
     $sql2 = "SELECT a.url, a.id, a.focus_keyword, a.search_engine, COUNT(a.id) AS nb FROM " . $wpdb->prefix . "psp_serp_reporter as a WHERE 1=1 and a.publish='Y' GROUP BY a.focus_keyword, a.search_engine HAVING nb<=1 ORDER BY a.id ASC;";
     $res2 = $wpdb->get_results($sql2, ARRAY_A);
     // exit if no tasks to be run
     if (count($res2) > 0) {
         $__tasks[1] = $res2;
     }
     require_once $this->the_plugin->cfg['paths']['scripts_dir_path'] . '/serp/serp.api.class.php';
     $serp = pspSERPCheck::getInstance();
     // loop tasks
     foreach ($__tasks as $__k => $__v) {
         foreach ($__v as $key => $value) {
             if ($__k == 0) {
                 //use cache!
                 $sql_url = $wpdb->prepare("SELECT a.id, a.focus_keyword, a.url, a.search_engine FROM " . $wpdb->prefix . "psp_serp_reporter as a WHERE 1=1 and a.publish='Y' and a.focus_keyword=%s and a.search_engine=%s ORDER BY a.id ASC;", $value['focus_keyword'], $value['search_engine']);
                 $res_url = $wpdb->get_results($sql_url, ARRAY_A);
                 if (count($res_url) > 0) {
                     foreach ($res_url as $ku => $vu) {
                         $__spParams = array('engine' => $value['search_engine'], 'keyword' => $value['focus_keyword'], 'link' => $vu['url'], 'dopause' => $this->serp_sleep);
                         $googleScoreInfo = $serp->__get_serp_score($__spParams);
                         if ($googleScoreInfo === false || isset($googleScoreInfo['status']) && $googleScoreInfo['status'] == 'invalid') {
                             $this->googleAccessStatus($vu['id'], array('status' => 'invalid', 'msg' => $googleScoreInfo['msg']));
                         } else {
                             // add to DB or update if is from new day
                             $this->addToReportDB($googleScoreInfo, $value['search_engine']);
                         }
                     }
                 }
             } else {
                 $__spParams = array('engine' => $value['search_engine'], 'keyword' => $value['focus_keyword'], 'link' => $value['url'], 'dopause' => $this->serp_sleep);
                 $googleScoreInfo = $serp->__get_serp_score($__spParams);
                 if ($googleScoreInfo === false || isset($googleScoreInfo['status']) && $googleScoreInfo['status'] == 'invalid') {
                     $this->googleAccessStatus($value['id'], array('status' => 'invalid', 'msg' => $googleScoreInfo['msg']));
                 } else {
                     // add to DB or update if is from new day
                     $this->addToReportDB($googleScoreInfo, $value['search_engine']);
                 }
             }
         }
     }
     //send email!
     $this->cron_reporter_email();
     // return for ajax
     die(json_encode(array('status' => 'valid', 'msg' => '')));
 }