/** * Add workflow after adding new support languages. * * @param mixed $params */ public function actionAddWorkflow($model) { $command = Yii::app()->db; if (!is_object($model)) { return $this->result->fail(ERROR_INVALID_DATA, Yii::t('Core.language', 'Invalid model params.')); } //Get the site default's' urls $site = Site::model()->findByPk($model->site_id); $siteDefaultUrls = SiteUrl::model()->findAllByAttributes(array('site_id' => $model->site_id, 'status' => true)); $count = 0; if (count($siteDefaultUrls)) { foreach ($siteDefaultUrls as $siteUrl) { $liveUrl = $siteUrl->url . '/' . str_replace('_', '/', $model->locale_id); //Check exist domain, go here. $liveWf = array('name' => $model->locale_id . '_live', 'url' => $liveUrl, 'locale_id' => $model->locale_id, 'type' => Workflow::TYPE_FINAL, 'site_id' => $model->site_id); if (!$this->isExistWorkflow($site->table_prefix . 'workflow', $liveUrl)) { $count += $this->saveWorkflow($site->table_prefix . 'workflow', $liveWf); } } } //Also add a dev workflow $result = $command->createCommand()->select('url')->from($site->table_prefix . 'workflow')->where('name=:name AND site_id=:siteId', array(':name' => 'dev', ':siteId' => $model->site_id))->queryRow(); if (count($result)) { //If exist a default dev domain , get it. $domain = $result['url']; } else { //Get current dev domain $domain = parse_url(yii::app()->request->getHostInfo(), PHP_URL_HOST); } //Check duplicate here. $devUrl = $domain . '/' . str_replace('_', '/', $model->locale_id); $devWf = array('name' => $model->locale_id . '_dev', 'url' => $devUrl, 'locale_id' => $model->locale_id, 'type' => Workflow::TYPE_INITITAL, 'site_id' => $model->site_id); if (!$this->isExistWorkflow($site->table_prefix . 'workflow', $devUrl)) { $count += $this->saveWorkflow($site->table_prefix . 'workflow', $devWf); } return $this->result = $count; }
/** * */ private function GetSEOState($taskID) { $dataProvider = new CActiveDataProvider(SiteUrl::model(), array('pagination' => false)); echo '資料庫共' . $dataProvider->totalItemCount . '筆資料' . "\r\n"; $i = 0; foreach ($dataProvider->getData() as $record) { $site = $record->site; $id = $record->SiteID; // if($i>=5) // { // break; // } //移除前面的http:// (若有的話) $site = preg_replace('#^https?://#', '', $site); $site = preg_replace('#^http?://#', '', $site); //系統延遲 $pagerank = 0; $now = new DateTime(); try { $pagerank = \SEOstats\Services\Google::getPageRank($site); if (!is_numeric($pagerank)) { $pagerank = null; } } catch (Exception $e) { $pagerank = null; } usleep(rand(1000, 3000)); //下面這行是採用Google API提供之資料 //$googleIds = \SEOstats\Services\Google::getSiteindexTotal($site); //下面這行是採用網頁搜尋結果資料 if ($i % 2 == 1) { usleep(rand(500, 1000)); $googleIds = $this->GetGoogleSearch("site:{$site}"); } else { $googleIds = $this->GetGoogleSearch("site:{$site}"); } sleep(3); if (is_null($googleIds)) { //用另外種管道重抓一次 usleep(rand(5000, 10000)); echo '[log]' . $site . "使用重抓索引資料;/r/n"; $googleIds = \SEOstats\Services\Google::getSiteindexTotal($site); } if ($i % 2 == 1) { usleep(rand(500, 1000)); $googleLinks = $this->GetGoogleSearch("link:{$site}"); } else { $googleLinks = $this->GetGoogleSearch("link:{$site}"); } //如果抓不到資料就換個管道 if (is_null($googleLinks)) { //用另外種管道重抓一次 usleep(rand(5000, 10000)); echo '[log]' . $site . "使用API重抓頁面數資料;/r/n"; $googleLinks = \SEOstats\Services\Google::getBacklinksTotal($site); } usleep(rand(1010, 15020)); //echo("[log]".$now->format( 'Y-m-d H:i:s' )."搜尋".$site."有".$googleLinks.'項結果 '."\r\n"); //取得社群分享數據 $seostats = new \SEOstats\SEOstats(); $seostats->setUrl("http://{$site}"); $fb = Social::getFacebookShares(); //print_r($fb); usleep(rand(4000, 10000)); // //設定抓取的檔案類型 // $fileTypeList = array('pdf', 'doc', 'docx', 'ppt', 'pptx', 'ps', 'eps'); $fileCount = array(); $error_statues = 0; foreach ($fileTypeList as $key => $value) { usleep(rand(5000, 10000)); if ($error_statues == 0) { $fileCount[$value] = $this->GetGoogleSearch("site:{$site}" . ' filetype:' . $value); } if (is_null($fileCount[$value])) { $fileCount[$value] = \SEOstats\Services\Google::getSiteFileTypeTotal($site, $value); //表示系統被Google封鎖了。 if (is_null($fileCount[$value])) { $fileCount[$value] = 0; $error_statues++; } } } usleep(rand(4000, 10000)); //取得網站資訊,包含網站一些設定資訊。 $info = $this->get_url_info($site); $model = new Data(); $model->attributes = array('SiteID' => $id, 'GoogleData' => $googleIds, 'google_backlink' => $googleLinks, 'filetime' => $info['filetime'] = !-1 ? date("Y-m-d H:i:s", $info['filetime']) : null, 'robot' => $this->remoteFileExists("{$site}/robots.txt"), 'sitemap' => $this->remoteFileExists("{$site}/sitemap.xml"), 'Time' => $now->format('Y-m-d H:i:s'), 'Facebook' => $fb['total_count'], 'FB_share_count' => $fb['share_count'], 'FB_like_count' => $fb['like_count'], 'FB_comment_count' => $fb['comment_count'], 'FB_commentsbox_count' => $fb['commentsbox_count'], 'FB_click_count' => $fb['click_count'], 'TwitterShares' => Social::getTwitterShares(), 'LinkedInShares' => Social::getLinkedInShares(), 'pdf' => $fileCount['pdf'], 'doc' => $fileCount['doc'], 'docx' => $fileCount['docx'], 'ppt' => $fileCount['ppt'], 'pptx' => $fileCount['pptx'], 'ps' => $fileCount['ps'], 'eps' => $fileCount['eps'], 'YY' => $now->format('Y'), 'MM' => $now->format('m'), 'DD' => $now->format('d'), 'TaskID' => $taskID, 'google_page_rank' => $pagerank); //Yii::app()->end(); if ($model->save()) { $i++; } else { print "網址: {$site} 出現錯誤"; print_r($model->getErrors()); } usleep(rand(100, 400)); // if($i==3) // { // break; // } } echo '執行完畢,共儲存' . $i . '筆資料'; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return SiteUrl the loaded model * @throws CHttpException */ public function loadModel($id) { $model = SiteUrl::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionDetail($id) { $this->layout = '//layouts/main'; Yii::app()->clientScript->registerCoreScript('jquery'); Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/themes/bootstrap/js/waypoints.min.js'); Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/themes/bootstrap/js/jquery.counterup.min.js'); //Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl .'/themes/bootstrap/js/circles.js'); Yii::app()->getClientScript()->registerCss('Detail', ' .counters span { font-size: 35px; color: #FFBF00; text-align: center; }'); $site_model = SiteUrl::model()->findByPk($id); if ($site_model == null) { throw new CHttpException(404, 'The requested page does not exist.'); } $group_model = Group::model()->findByPk($site_model->groupid); $lastTaskId = Yii::app()->db->createCommand('SELECT TaskID FROM task ORDER BY TaskID DESC LIMIT 1')->queryScalar(); $DataID = Yii::app()->db->createCommand('SELECT DataID FROM data WHERE `TaskID`=' . $lastTaskId . ' AND SiteID=' . $id . ' ORDER BY DataID DESC LIMIT 1')->queryScalar(); $this->render('detail', array('site_model' => $site_model, 'group_model' => $group_model, 'data' => $this->loadModel($DataID))); }
<?php echo Data::model()->count() * 8; ?> </span> <h4>登錄資料筆數</h4> </div> <div class="counters col-md-4 col-sm-4"> <span class="counter"> <?php echo Group::model()->count(); ?> </span> <h4>網站數</h4> </div> <div class="counters col-md-4 col-sm-4"> <span class="counter"> <?php echo SiteUrl::model()->count(); ?> </span> <h4>單位及系所數</h4> </div> </div> <p class="lead"> <?php echo CHtml::link('行政單位排名 <i class="fa fa-university fa-lg"></i>', array('/行政單位排名'), array('class' => 'btn btn-outline-inverse btn-lg')); ?> <?php echo CHtml::link('學術單位排名 <i class="fa fa-graduation-cap fa-lg"></i>', array('/學術單位排名'), array('class' => 'btn btn-outline-inverse btn-lg')); ?> </p>