/** * @param WebRequestDictionary $dictonary * @param array $getVars request's $_GET * @param array $postVars request's $_POST * @param array $cookieVars request's $_COOKIE * @param array $filesVars request's $_FILES * @param string|null $baseHost optional base host for request's request url (SiteUrl) * @param string $baseUri optional base uri */ function __construct(WebRequestDictionary $dictonary, array $getVars, array $postVars, array $cookieVars, array $filesVars, $baseHost = null, $baseUri = '/') { Assert::isScalar($baseUri); $this->dictionary = $dictonary->getFields(); $this->httpUrl = SiteUrl::import($dictonary, $baseHost, $baseUri); $this->vars = array(WebRequestPart::GET => $getVars, WebRequestPart::POST => $postVars, WebRequestPart::COOKIE => $cookieVars, WebRequestPart::FILES => $filesVars); $this->allVars = call_user_func_array('array_merge', array($filesVars, $cookieVars, $postVars, $getVars)); }
function compose(SiteUrl $url, array $parameters) { if ($this->requestPart->is(WebRequestPart::GET)) { if (array_key_exists($this->name, $parameters)) { $url->addQueryArgument($this->name, (string) $parameters[$this->name]); } else { if (!$this->isOptional) { if ($this->defaultValue) { $url->addQueryArgument($this->name, $this->defaultValue); } else { // FIXME: use exception Assert::isUnreachable('missing %s parameter', $this->name); } } } } }
function __construct(array $getVars, array $postVars, array $cookieVars, array $filesVars, array $serverVars, array $envVars, $baseHost = null, $baseUri = '/') { Assert::isScalar($baseUri); $this->getVars = $getVars; $this->postVars = $postVars; $this->cookieVars = $cookieVars; $this->filesVars = $filesVars; $this->serverVars = $serverVars; $this->envVars = $envVars; // GPCF $this->allVars = array_replace_recursive($cookieVars, $getVars, $postVars, $filesVars); $this->httpUrl = SiteUrl::import($this->isSecured() ? 'https' : 'http', $this->serverVars['HTTP_HOST'], $this->serverVars['SERVER_PORT'], $this->serverVars['REQUEST_URI'], $baseHost, $baseUri); }
/** * 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 . '筆資料'; }
/** * Is this path within the given path? * * E.g. if the current path is "blog/view/123", this would return true for "blog", * but false for "bl" or "blog/vi". * * @param string $path Path to compare. E.g. "blog/view" * * @return bool */ public function isWithinPath($path) { $path = SiteUrl::normalizePath($path); $current_path = $this->getPath() . '/'; $path = trim($path, '/') . '/'; if ($path === '/') { return true; } return 0 === strpos($current_path, $path); }
/** * 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; }
function compose(SiteUrl $url, array $parameters) { $pathChunks = array(); foreach ($this->chunkRewriters as $chunkRewriter) { $values = $chunkRewriter->getValues(); if (($name = $chunkRewriter->getName()) && 1 != sizeof($values)) { Assert::isTrue(isset($parameters[$name]), '%s expects parameter %s to be specified for pattern `%s`', get_class($this), $name, $this->urlPattern); if (sizeof($values)) { Assert::isTrue(in_array($parameters[$name], $values), '%s expects parameter %s to be in range as defined by pattern `%s`', get_class($this), $name, $this->urlPattern); } $pathChunks[] = $parameters[$name]; } else { $pathChunks[] = reset($values); } } $url->setVirtualPath(join('/', $pathChunks)); }
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>
/** * 初始化数据库redis * * @return void */ private function initDbRedis() { $redis = $this->redis; $tablePre = $this->controller->getTablePre(); // 清空当前数据库 $redis->flushDB(); // 计数器 $redis->hMset($tablePre . 'counter', array('uid' => 0, 'topicid' => 0, 'replyid' => 0, 'bkid' => 0, 'linkid' => 0)); // 创建默认节点 $bkM = new BkModel($this->controller); $bkid = $bkM->createBk(0, '默认节点'); //将默认节点加入首页导航 $bkM->addBk2Index($bkid); // 发表一篇默认帖子 $topicModel = new Topics($this->controller); $topicModel->postTopic(0, $bkid, '你好世界', '你好,这是一个测试帖子'); // 网站配置信息 $redis->hMset($tablePre . 'site_conf', array('sitename' => '流光论坛', 'create_time' => time(), 'notice_on' => 1, 'notice_text' => '流光论坛安装成功', 'open_compress' => 1)); //添加链接 $linksArr = array(array('name' => '关于', 'url' => '/about'), array('name' => 'FAQ', 'url' => '/faq'), array('name' => 'API', 'url' => '/api'), array('name' => '我们的愿景', 'url' => '/mission'), array('name' => 'IP查询', 'url' => '/ip'), array('name' => '工作空间', 'url' => '/workspace'), array('name' => '广告投放', 'url' => '/advertise'), array('name' => '博客', 'url' => '/blog'), array('name' => '上网首页', 'url' => '/start')); $urlM = new SiteUrl($this->controller); foreach ($linksArr as $linkNode) { $urlM->addUrl($linkNode['name'], $linkNode['url']); } }
public function addUrl(SiteUrl $url) { $url->setSite($this); $this->urls->add($url); }
/** * @dataProvider samePathProvider */ public function testGetPathReturnsSamePath($url, $path) { $this->assertSame($path, $this->url->getSitePath($url)->getPath()); }