Пример #1
0
 function getDirectoryCondition()
 {
     $cache = Cacher::getInstance();
     if (($message = $cache->load("directoryCondition")) === null) {
         $message = $this->customMessage->findByPk("directoryCondition")->toArray();
         $cache->save($message, null, null, array("custommessage"));
     }
     return $message;
 }
Пример #2
0
 function removeAll()
 {
     $c = new Criteria();
     $this->del($c);
     $this->site->update(array("referrerTimes" => 0), $c);
     $todayDate = date("Y-m-d");
     $this->setting->set('topReferrersLastResetDate', $todayDate);
     Cacher::getInstance()->clean("tag", array("setting"));
 }
Пример #3
0
 /**
  * Index page
  */
 function indexAction()
 {
     //set adPage
     Display::set("adPage", "index");
     //set META description
     $this->set("metaDescription", Config::get("siteDescription"));
     $cache = Cacher::getInstance();
     //retrieve predefinied html directoryDescription from db
     if (($message = $cache->load("directoryDescription")) === null) {
         $message = $this->customMessage->findByPk("directoryDescription")->toArray();
         $cache->save($message, null, null, array("custommessage"));
     }
     $this->set("directoryDescription", $message);
 }
Пример #4
0
 function listAction()
 {
     //get category to display set by /site/category
     $parentCategoryId = Display::get("currentCategoryId", 0);
     $cache = Cacher::getInstance();
     $cacheItemName = "categoryMiddleHtml" . $parentCategoryId . Config::get("language") . "Template" . Config::get("templateName");
     //check that cached version exists
     if (($categoriesMiddleHtml = $cache->load($cacheItemName, false)) === null) {
         //retrieve all categories which have this $parentCategoryId alphabetically
         $c = new Criteria();
         $c->addOrder("position, name");
         $c->add("parentCategoryId", $parentCategoryId);
         //create assoctiation array with keys = categoryId and values category data
         $categoriesList = $this->category->getArray($c, "parentCategoryId, name, urlName, imageSrc, validatedSitesCount", null, true);
         //if exists some categories having this parent
         if (!empty($categoriesList)) {
             //get count of category subcategories
             $maxSubcategoriesCount = Config::get("countOfSubcategoriesUnderCategory");
             if ($maxSubcategoriesCount) {
                 //retrieve subcategories which have categories on this page
                 $c = new Criteria();
                 $c->addOrder("position, name");
                 $c->add("parentCategoryId", array_keys($categoriesList), "IN");
                 $subcategories = $this->category->findAll($c);
                 //foreach category create subcategories container
                 foreach ($categoriesList as $key => $category) {
                     $categoriesList[$key]['subcategories'] = array();
                 }
                 //foreach subcategories add it to parent category
                 foreach ($subcategories as $subcategory) {
                     $parentCategory =& $categoriesList[$subcategory['parentCategoryId']];
                     //check that $maxSubcategoriesCount isn't reached
                     if (count($parentCategory['subcategories']) < $maxSubcategoriesCount) {
                         $parentCategory['subcategories'][] = $subcategory;
                     }
                 }
             }
             //create standard array to be able create 2 columns table (much be indexed i, i+1)
             $categoriesList = array_values($categoriesList);
         }
         $this->set("categoriesList", $categoriesList);
         $categoriesMiddleHtml = $this->render();
         //store categories with subcategories on this page to cache
         $cache->save($categoriesMiddleHtml, $cacheItemName, false, array("category", "site"));
     }
     return $categoriesMiddleHtml;
 }
Пример #5
0
 /**
  * Retrieve main settings for application
  * @return array
  */
 public function loadSettings()
 {
     $cache = Cacher::getInstance();
     if (($settings = $cache->load("settings")) === null) {
         $settings = array();
         foreach ($this->setting->findAll(new Criteria(), "`key`, `value`") as $row) {
             $settings[$row['key']] = $row['value'];
         }
         $cache->save($settings, null, null, array("setting"));
     }
     foreach ($settings as $key => $value) {
         Config::set($key, $value);
     }
     $rawUrl = parse_url(Config::get("siteRootUrl"));
     Config::set("siteDomainUrl", "http://" . $rawUrl['host']);
     $errorHandler = ErrorHandler::getInstance();
     if (!Config::get('errorHandlerSaveToFileEnabled')) {
         $errorHandler->setOption('saveToFile', false);
     }
     if (!Config::get('errorHandlerDisplayErrorEnabled')) {
         $errorHandler->setOption('displayError', false);
     }
 }
Пример #6
0
 public function saveCampaignFilters($filters)
 {
     $this->setting->set('campaignFilters', serialize($filters));
     Cacher::getInstance()->clean('all');
 }
Пример #7
0
 /**
  * Clear actions
  */
 function clearAction()
 {
     $cmd = "";
     foreach (array("topHits", "topReferrers", "fileCache", "googleCache", "createUrlNames", "categoryOrder") as $opt) {
         if ($this->request->hasValue($opt)) {
             $cmd = $opt;
         }
     }
     switch ($cmd) {
         case "topHits":
             $this->hit->removeAll();
             break;
         case "topReferrers":
             $this->otherReferrerSite->removeAll();
             break;
         case "fileCache":
             $cache = Cacher::getInstance();
             $cache->clean("all");
             $this->clearDir(CODE_ROOT_DIR . "compiled/");
             break;
         case "googleCache":
             $this->cacheGoogleDetail->removeAll();
             break;
         case "createUrlNames":
             $this->createUrlNames();
             break;
         case "categoryOrder":
             $this->category->resetOrder();
             break;
     }
     $this->redirect($this->moduleLink());
 }
Пример #8
0
 function update($data, Criteria $c)
 {
     parent::update($data, $c);
     $this->updateValidatedSitesCount();
     Cacher::getInstance()->clean("tag", array("category"));
 }
Пример #9
0
 function __construct()
 {
     $this->cache = Cacher::getInstance();
 }
Пример #10
0
 function updateAction()
 {
     $this->setting->set("templateName", $this->request->templateName);
     Cacher::getInstance()->clean("tag", array("setting"));
     $this->redirect($this->moduleLink());
 }
Пример #11
0
 public function start()
 {
     $scriptStartTime = time();
     ignore_user_abort(true);
     set_time_limit(60 * 5);
     $taskCriteria = new Criteria();
     $taskCriteria->add("taskId", $this->taskId);
     $task = $this->task->find($taskCriteria);
     if (empty($task)) {
         return;
     }
     if (!in_array($task->status, array("init", "next"))) {
         return;
     }
     $this->data = unserialize($task->data);
     if ($task->status == "next") {
         $taskData = Cacher::getInstance()->load("taskData" . $this->taskId);
         if (empty($taskData)) {
             return;
         }
         $this->items = $taskData['items'];
         $startIndex = $taskData['startIndex'];
         $this->parsedItems = $startIndex;
     } else {
         $startIndex = 0;
         $this->loadItems();
     }
     $this->totalItems = count($this->items);
     $task->totalItems = $this->totalItems;
     $task->status = "active";
     $task->save();
     $lp = 0;
     $this->beforeParsing();
     $executeNextProcess = false;
     for ($i = $startIndex, $itemsCount = count($this->items); $i < $itemsCount && !$executeNextProcess; $i++) {
         $item = $this->items[$i];
         $this->parseItem($item);
         $task->parsedItems = ++$this->parsedItems;
         $task->save();
         if ($this->parsedItems < $this->totalItems) {
             $taskStatus = $this->task->get("status", $taskCriteria);
             if ($taskStatus == "pause") {
                 do {
                     sleep($this->pauseUpdateStatusInterval);
                     $taskStatus = $this->task->get("status", $taskCriteria);
                 } while ($taskStatus == "pause");
             }
             if ($taskStatus == "stop") {
                 break;
             }
             if (time() - $scriptStartTime > $this->scriptMaxExecutionTime) {
                 $executeNextProcess = true;
                 $taskData = array("items" => $this->items, "startIndex" => $i + 1);
                 Cacher::getInstance()->save($taskData, "taskData" . $this->taskId);
             }
         }
     }
     if ($executeNextProcess) {
         $task->status = "next";
         $task->save();
         $this->fork(AppRouter::getRewrittedUrl("/admin/task/nextStart"));
     } else {
         Cacher::getInstance()->delete("taskData" . $this->taskId);
         $task->status = "finish";
         $task->save();
         $this->afterParsing();
     }
 }
Пример #12
0
 /**
  * Load cache
  *
  * @return array
  */
 protected function loadCache()
 {
     if ($this->_cache === null) {
         $this->_cache = Cacher::getInstance()->get($this->getCacheName());
     }
     return $this->_cache;
 }
Пример #13
0
 /**
  * Save edited customMessage
  */
 function saveEditMessageAction()
 {
     $keyId = $this->request->get("messageId");
     $fields = array("title", "description");
     if (!empty($this->request->userText)) {
         $fields[] = "userText";
     }
     $data = $this->request->getArray($fields);
     $this->customMessage->updateByPk($data, $keyId);
     if (in_array($keyId, array("directoryDescription", "directoryCondition"))) {
         Cacher::getInstance()->delete($keyId);
     }
     $this->redirect($this->moduleLink("email"));
 }
Пример #14
0
 public static function displayAd($params, &$tpl)
 {
     $place = $params['place'];
     $page = Display::get("adPage");
     if (empty($page)) {
         return "";
     }
     if (!self::$adsLoaded) {
         $page = Display::get("adPage");
         $cache = Cacher::getInstance();
         //get Ads ids on current page
         if (($data = $cache->load("adsOnPage" . $page)) === null) {
             $data = Model::factoryInstance("ad")->getAdsOnPage($page);
             $cache->save($data, null, null, array("adCriteria", "ad"));
         }
         self::$adsOnPage = $data;
         //load predefined settings
         if (($data = $cache->load("adsPredefinitions")) === null) {
             $data = Model::factoryInstance("ad")->getAllPredefinitions();
             $cache->save($data, null, null, array("adCriteria", "ad"));
         }
         self::$predefinitions = $data;
         if (preg_match("#^(site|keyword|category|letter|tag)#", $page, $match)) {
             self::$predefinitionTypeName = $match[1];
         }
         //load ads html content
         if (($data = $cache->load("adsAllCriterias")) === null) {
             $data = Model::factoryInstance("adCriteria")->getArray(null, "htmlContent");
             $cache->save($data, null, null, array("adCriteria"));
         }
         self::$adCriterias = $data;
         self::$adsLoaded = true;
         self::$pageIsPredefinied = !empty(self::$adsOnPage['predefine']);
     }
     $htmlContent = "";
     if (!empty(self::$adsOnPage['general']) && !empty(self::$adsOnPage[$place])) {
         $adCriterionId = self::$adsOnPage[$place];
         if (!empty(self::$adCriterias[$adCriterionId])) {
             $htmlContent = self::$adCriterias[$adCriterionId];
         }
     } else {
         if (self::$pageIsPredefinied && (!isset(self::$adsOnPage['general']) || self::$adsOnPage['general'] == 1)) {
             if (!empty(self::$predefinitions[self::$predefinitionTypeName][$place])) {
                 $adCriterionId = self::$predefinitions[self::$predefinitionTypeName][$place];
                 if (!empty(self::$adCriterias[$adCriterionId])) {
                     $htmlContent = self::$adCriterias[$adCriterionId];
                 }
             }
         }
     }
     return $htmlContent;
 }
Пример #15
0
 function updateStats()
 {
     $this->category->updateValidatedSitesCount();
     Cacher::getInstance()->clean("tag", array("site", "category", "keyword"));
 }
Пример #16
0
 function displayTagCloudAction()
 {
     //check is tag cloud was cached before
     $cache = Cacher::getInstance();
     $cacheItemName = "tagCloudHtml" . Config::get("language") . "Template" . Config::get("templateName");
     if (($tagCloudHtml = $cache->load($cacheItemName, false)) === null) {
         //get stats defined in statistic model
         $this->set("tags", $this->searchTag->getTagCloud());
         $this->viewFile = "menuright/tagCloud";
         $tagCloudHtml = $this->render();
         $cache->save($tagCloudHtml, $cacheItemName, false, array("searchTag"));
     }
     return $tagCloudHtml;
 }
Пример #17
0
 public function del()
 {
     parent::del();
     $cache = Cacher::getInstance();
     $cache->clean("tag", array("searchTag"));
 }
Пример #18
0
 /**
  * Save new criterion
  */
 function saveNewCriteriaAction()
 {
     $adcriteria = new AdCriteriaRecord();
     $adcriteria->name = $this->request->name;
     $adcriteria->htmlContent = $this->request->htmlContent;
     $adcriteria->save();
     Cacher::getInstance()->clean("tag", array("adCriteria"));
     $this->redirect($this->moduleLink());
 }
Пример #19
0
 /**
  * Display site details page
  */
 function detailsAction($siteId, $niceUrl)
 {
     //set adPage for ads
     Display::set("adPage", "site" . $siteId);
     $cache = Cacher::getInstance();
     $cacheLifeTime = Config::get("siteDetailsCacheLifeTime");
     if (!Config::get("siteDetailsCacheEnabled") || ($site = $cache->load("siteDetails{$siteId}", true, $cacheLifeTime)) === null) {
         //get site data
         $site = $this->site->getSiteWithDetails($siteId);
         if (empty($site) || $site->status != "validated") {
             return $this->return404();
         }
         $this->site->attachParents($site);
         //check passed siteTitle is url is correct
         $siteDetailsUrl = AppRouter::getObjectUrl($site, "siteDetails");
         if ($siteDetailsUrl != $_SERVER['REQUEST_URI']) {
             $this->redirect($siteDetailsUrl, 301);
         }
         $this->site->attachExtraFields($site);
         $site->photos = $this->photo->getItemPhotos($siteId);
         //get site keywords
         $site->keywords = $site->getKeywords();
         //get google details
         $googleStats = new GoogleStats();
         $results = $googleStats->getGoogleDetailsOfSiteIfCached($site->url);
         //if results exists pass them to template
         if ($results) {
             $site->pageRank = $results['pageRank'];
             $site->backlinksCount = $results['backlinksCount'];
             $site->indexedPagesCount = $results['indexedPagesCount'];
         } else {
             //if no use ajax to reduce site generation time
             $this->set("ajaxGoogleDetails", true);
         }
         if (Config::get("showRandomSitesInDetails")) {
             $site->randomSites = $site->getSimilarSites();
         }
         $site->comments = $this->comment->getSiteValidatedComments($siteId);
         if (Config::get("siteDetailsCacheEnabled")) {
             $cache->save($site, null, null, array("site", "site" . $siteId));
         }
     } else {
         //check passed siteTitle is url is correct
         $siteDetailsUrl = AppRouter::getObjectUrl($site, "siteDetails");
         if ($siteDetailsUrl != $_SERVER['REQUEST_URI']) {
             $this->redirect($siteDetailsUrl, 301);
         }
     }
     //set category id where site is placed to retrieve predefinitions in ads module
     Display::set("adSiteCategoryId", $site->categoryId);
     //set site rss href
     Display::set("siteRssHref", AppRouter::getRewrittedUrl("/rss/site/" . $site->siteId));
     //set META keywords in HEAD section
     $this->set("metaKeywords", implode(", ", array_map(create_function('$a', 'return $a["keyword"];'), $site->keywords)));
     //set META description in HEAD section
     $this->set("metaDescription", utf8_substr(preg_replace("#\r?\n#", "", strip_tags($site->description)), 0, 200));
     //check passed siteTitle is url is correct
     $siteDetailsUrl = AppRouter::getObjectUrl($site, "siteDetails");
     if ($siteDetailsUrl != $_SERVER['REQUEST_URI']) {
         $this->redirect($siteDetailsUrl, 301);
     }
     $this->siteHtml->configureSiteHtmlDisplay($site);
     //set site data
     $this->set("site", $site);
     if (Config::get("googleMapEnabled")) {
         $this->set("googleMap", $site->getGoogleMap());
     }
     if (Config::get("remoteRssParsingEnabled") && !empty($site['rssFeedOfSite'])) {
         define("MAGPIE_OUTPUT_ENCODING", "UTF-8");
         define("MAGPIE_DETECT_ENCODING", true);
         // Define cache's maximum age
         define('MAGPIE_CACHE_AGE', 60 * 60 * 24 * intval(Config::get('magpieRssCacheMaxAgeDays')));
         require_once Config::get('COMPONENTS_PATH') . 'magpierss/rss_fetch.php';
         $rss = @fetch_rss($site['rssFeedOfSite']);
         if (!empty($rss)) {
             $remoteRss = array("items" => array(), "channel" => $rss->channel);
             $items = array_slice($rss->items, 0, Config::get("numberOfItemsForRssParsing"));
             foreach ($items as $item) {
                 if (isset($item['description'])) {
                     // Strip tags from each item's description
                     $item['description'] = strip_tags(html_entity_decode($item['description'], ENT_COMPAT, 'UTF-8'));
                 }
                 if (!isset($item['link']) && isset($item['link_'])) {
                     $item['link'] = $item['link_'];
                 }
                 if (!empty($item['link']) && !empty($item['title'])) {
                     $remoteRss['items'][] = $item;
                 }
             }
             $this->set("remoteRss", $remoteRss);
         }
     }
 }
Пример #20
0
 function update($data, Criteria $c)
 {
     parent::update($data, $c);
     Cacher::getInstance()->clean("tag", array("user"));
 }
Пример #21
0
 function updateRefusedSitesCount($moderatorId, $count)
 {
     $this->updateByPk(array("_refusedSitesCount" => "refusedSitesCount + {$count}"), $moderatorId);
     $cache = Cacher::getInstance();
     $cache->clean("tag", array("refusal"));
 }