/** * * @param array $args */ public static function initialize($args) { // Traitement de l'url if (!empty($args['url'])) { $url = explode('/', $args['url']); } // On traite le controleur if (!empty($url[0])) { self::$_controllerName = str_replace(' ', '', ucwords(strtolower(str_replace('_', ' ', $url[0])))) . CONTROLLER_SUFFIX; self::$_controllerFileName = str_replace(' ', '', ucwords(strtolower(str_replace('_', ' ', $url[0])))) . CONTROLLER_SUFFIX . PHP_EXT; } else { include 'Config.php'; self::$_controllerName = $settings['DefaultController']; self::$_controllerFileName = $settings['DefaultController'] . PHP_EXT; } // On traite la méthode if (!empty($url[1])) { self::$_methodName = lcfirst(str_replace(' ', '', ucwords(strtolower(str_replace('_', ' ', $url[1]))))); } else { include 'Config.php'; self::$_methodName = $settings['DefaultMethod']; } // On traite les variables passé par url if (sizeof($args) > 1) { unset($args['url']); foreach ($args as $k => $v) { self::$_args[$k] = $v; } } }
/** * set access privileges */ function init() { $this->acl->allow("administrator", $this->name, "*"); if (!$this->acl->isAllowed($this->session->get("role"), $this->name, $this->action)) { $this->redirect(AppRouter::getRewrittedUrl("/admin/main/logIn")); } }
public static function realImgSrc($imgSrc, $type = "main", $size = "normal", $title = '') { if ($imgSrc) { $path = "/uploads/images_thumbs/" . UploadedFile::fileNameToPath($imgSrc); } else { $imgSrc = "DefaultMainPhoto.jpg"; $path = "/templates/arfooo/images/"; } switch ($size) { case "small": $imgSrc = "s" . $imgSrc; break; case "medium": $imgSrc = "m" . $imgSrc; break; case "nano": $imgSrc = "n" . $imgSrc; break; } if ($title) { $path .= NameTool::strToAscii($title) . '-'; } $imgSrc = $path . $imgSrc; return AppRouter::getResourceUrl($imgSrc); }
protected function parseItem($email) { $text = $this->data['text']; $verification = $this->verification->addVerification(null, "newsletterEmailDel", $email); $unsubscribeLink = Config::get("siteRootUrl") . AppRouter::getRewrittedUrl("/newsletter/confirmNewsletterEmailDel/" . $verification->code, false); $text .= str_replace("[unsubscribe link]", $unsubscribeLink, $this->data['newsletterFooterDescription']); $this->mailer->sendEmail($email, $this->data['subject'], $text, $this->data['fromEmail']); if ($this->parsedItems < $this->totalItems) { sleep($this->timeDelay); } }
function indexAction() { // add static links $urlRewriting = Config::get('urlRewriting'); $siteRootUrl = Config::get('siteRootUrl'); $siteMapGenerator = new SiteMapGenerator(); $siteMapGenerator->setSavePath(CODE_ROOT_DIR); $siteMapGenerator->addLink($siteRootUrl, '', 'always', '1.0'); if (Config::get("newsEnabled")) { $siteMapGenerator->addLink($siteRootUrl . AppRouter::getRewrittedUrl('/site/news', false), '', 'always', '1.0'); } if (Config::get("rssNewsEnabled")) { $siteMapGenerator->addLink($siteRootUrl . AppRouter::getRewrittedUrl('/rss/news', false), '', 'always', '0.8'); } if (Config::get("notationsEnabled")) { $siteMapGenerator->addLink($siteRootUrl . AppRouter::getRewrittedUrl('/site/topNotes', false), '', '', '0.8'); } if (Config::get("hitsEnabled")) { $siteMapGenerator->addLink($siteRootUrl . AppRouter::getRewrittedUrl('/site/topHits', false), '', '', '0.8'); } if (Config::get("topReferrersEnabled")) { $siteMapGenerator->addLink($siteRootUrl . AppRouter::getRewrittedUrl('/site/topReferrers', false), '', '', '0.8'); } if (Config::get("topRankEnabled")) { $siteMapGenerator->addLink($siteRootUrl . AppRouter::getRewrittedUrl('/site/topRank', false), '', '', '0.8'); } if (Config::get("allCategoriesPageEnabled")) { $siteMapGenerator->addLink($siteRootUrl . AppRouter::getRewrittedUrl('/category/showAll', false), '', 'weekly', '1.0'); } if (Config::get("contactPageEnabled")) { $siteMapGenerator->addLink($siteRootUrl . AppRouter::getRewrittedUrl('/contact', false), '', '', '1.0'); } // add all sites links $step = 1000; $maxSiteId = $this->site->get("MAX(siteId)"); for ($startId = 0; $startId <= $maxSiteId; $startId += $step) { $c = new Criteria(); $c->add("siteId", $startId, ">="); $c->add("siteId", $startId + $step, "<"); $c->add("status", 'validated'); $sites = $this->site->findAll($c, "siteId, siteTitle, creationDate, categoryId"); $this->site->attachParents($sites); foreach ($sites as $site) { $siteMapGenerator->addLink(AppRouter::getObjectUrl($site, "siteDetails", true), date("Y-m-d", strtotime($site['creationDate'])), '', '1.0'); } } // add all categories links $categories = $this->category->findAll(null, "categoryId, name, urlName"); foreach ($categories as $category) { $siteMapGenerator->addLink(AppRouter::getObjectUrl($category, "category", true), "", '', '1.0'); } $siteMapGenerator->endSiteMap(); }
function saveReferrerAction() { $refererUrl = Request::getInstance()->getRefererUrl(); if ($refererUrl) { $refererHost = AppRouter::getHostNameFromUrl($refererUrl); $directoryHost = AppRouter::getHostNameFromUrl(Config::get('siteRootUrl')); if ($refererHost && $refererHost != $directoryHost) { $this->otherReferrerSite->saveReferrer($refererUrl); $this->searchTag->handleSearchEngineReferrer($refererUrl); } } $this->autoRender = false; }
function replaceTags($message, $site = null) { $replacements = array("[name of directory]" => Config::get("siteTitle"), "[url of your directory]" => Config::get("siteRootUrl")); if ($site) { $this->site->attachParents($site); $detailsUrl = AppRouter::getObjectUrl($site, "siteDetails", true); $category = $this->category->findByPk($site->categoryId, "name"); $siteDescription = utf8_strlen($site->description) > 100 ? utf8_substr($site->description, 0, 100) : $site->description; $replacements += array("[site name]" => $site->siteTitle, "[name of the category]" => $category->name, "[url site details]" => $detailsUrl, "[url site]" => $site->url, "[description of the site]" => $siteDescription, "[site type]" => $site->siteType == "basic" ? _t("Free") : _t("Privilege")); } $message = strtr($message, $replacements); return $message; }
function init() { $this->acl->allow("administrator", $this->name, "*"); $this->acl->allow("guest", $this->name, "start"); $this->acl->allow("guest", $this->name, "nextStart"); if (!$this->acl->isAllowed($this->session->get("role"), $this->name, $this->action)) { $this->redirect(AppRouter::getRewrittedUrl("/admin/main/logIn")); } if (in_array($this->request->taskId, array("newsletter", "siteHttpCode", "siteBacklink", "siteThumb", "siteDuplicateContent"))) { $className = ucfirst($this->request->taskId) . "BackgroundTask"; $this->backgroundTask = new $className(); } $this->viewClass = "JsonView"; }
function saveRefferingFromNotRegisteredSite($referrerUrl) { $hostName = AppRouter::getHostNameFromUrl($referrerUrl); if (empty($hostName)) { return; } $c = new Criteria(); $c->add("url", $hostName); if ($this->getCount($c)) { $this->update(array("_ReferrerTimes" => "ReferrerTimes + 1"), $c); } else { $record = new OtherReferrerSiteRecord(); $record->url = $hostName; $record->referrerTimes = 1; $record->save(); } }
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(); } }
function saveSiteAction() { $this->viewClass = "JsonView"; $edit = !empty($this->request->siteId); $validationOptions = array("admin" => true, "forceCategoryDuplicate" => true, "forcePossibleTender" => true); if ($this->request->url == "http://") { $this->request->url = ""; } if ($edit) { $site = $this->site->findByPk($this->request->siteId); if ($site->status != "validated" && $this->request->status == "validated") { $site->_creationDate = "NOW()"; } $package = $site->packageId ? $this->package->findByPk($site->packageId) : null; $errorMessage = $this->siteValidator->validate($this->request, $site, $validationOptions + array("package" => $package)); } else { $site = new SiteRecord(); $this->request->webmasterEmail = $this->session->get("email"); $errorMessage = $this->siteValidator->validate($this->request, null, $validationOptions); } if ($errorMessage) { $status = "error"; $this->set("status", $status); $this->set("message", _t($errorMessage)); return; } $fields = array("categoryId", "webmasterName", "webmasterEmail", "webmasterId", "siteTitle", "url", "rssTitle", "rssFeedOfSite", "description", "returnBond", "status", "problemExists", "priority", "visitsCount", "referrerTimes"); if (Config::get("countryFlagsEnabled")) { array_push($fields, "countryCode"); } if (Config::get("companyInfoEnabled")) { array_push($fields, "address", "zipCode", "city", "country", "phoneNumber", "faxNumber"); } if (isset($this->request->proposalForCategory)) { array_push($fields, 'proposalForCategory'); } if (isset($this->request->proposalForKeywords)) { array_push($fields, 'proposalForKeywords'); } if (isset($this->request->descriptionDisplayMethod)) { array_push($fields, 'descriptionDisplayMethod'); } $site->fromArray($this->request->getArray($fields)); $site->searchPartnership = empty($this->request->searchPartnership) ? 0 : 1; $site->save(); // store keywords, admin has no limit here if (!empty($this->request->keywords)) { $this->keywordsOfSite->storeKeywords($site->siteId, $this->request->keywords, 1000); } // save additional categories if (!empty($this->request->additionalCategoryIds)) { $c = new Criteria(); $c->add('siteId', $site->siteId); $this->siteAdditionalCategory->del($c); foreach ($this->request->additionalCategoryIds as $categoryId) { $additionalCategory = new SiteAdditionalCategoryRecord(array('siteId' => $site->siteId, 'categoryId' => $categoryId)); $additionalCategory->save(); } $this->site->updateStats(); } if (!empty($this->request->tempId)) { $c = new Criteria(); $c->add("tempId", $this->request->tempId); $this->photo->update(array("itemId" => $site->siteId, "_tempId" => "NULL"), $c); $site->updatePhotos(); } $this->extraField->saveExtraFieldsValues($site, $this->request); $site->updateSuffix(); $this->set("status", "ok"); $this->set("message", _t("The site was successfully submitted.")); $this->set("redirectUrl", AppRouter::getRewrittedUrl("/admin/category/index/" . $site->categoryId)); }
public static function setParameters(array $params) { self::$params = $params; return; }
function indexAction() { $this->redirect(AppRouter::getRewrittedUrl("/moderation/site/waiting")); }
function getThumbnailSrc($canBeOverwrittenByGalleryImage = true) { if ($canBeOverwrittenByGalleryImage && (empty($this->url) || Config::get("firstGalleryImageForThumbEnabled") && $this->firstGalleryImageSrc)) { if ($this->firstGalleryImageSrc) { return AppRouter::getResourceUrl("/uploads/images_thumbs/" . UploadedFile::fileNameToPath($this->firstGalleryImageSrc) . 's' . $this->firstGalleryImageSrc); } else { return $this->getDefaultImageSrc(); } } $siteId = $this->siteId; if ($this->imageSrc) { return AppRouter::getResourceUrl("/uploads/images_thumbs/" . $this->imageSrc); } else { if (empty($this->url)) { return $this->getDefaultImageSrc(); } else { if (Config::get('cacheSiteImagesEnabled') == 1) { $fileName = $siteId . '.jpg'; $filePath = Config::get("SITES_THUMBS_PATH") . $fileName; if (file_exists($filePath)) { return AppRouter::getResourceUrl("/uploads/images_thumbs/" . $fileName); } else { return AppRouter::getRewrittedUrl("/site/getThumb/" . $siteId); } } else { if (Config::get("thumbsGeneratorUrl")) { return $this->getThumbGeneratorSiteUrl(); } else { return $this->getDefaultImageSrc(); } } } } }
/** * Create module link to navigate between actions in controller * @param string $action Action name in controller * @return string full url to action */ protected function moduleLink($action = "", $absolute = true) { $url = ""; if ($this->localDir) { $url .= "/" . rtrim($this->localDir, "/") . ""; } $url = $url . "/" . $this->niceName; if ($action) { $url .= "/" . $action; } $url = AppRouter::getRewrittedUrl($url, $absolute); if ($url[0] != "/" && $absolute) { $url .= "/" . $url; } return $url; }
public function processPaymentAction() { if (empty($this->request->processorId) || empty($this->request->packageId)) { $this->redirect($this->moduleLink("selectPaymentOptions")); } $processorId = $this->request->processorId; $package = $this->package->findByPk($this->request->packageId); $paymentProcessor = $this->factoryPaymentProcessor($processorId); if (empty($paymentProcessor) || empty($package)) { $this->return404(); } if (!$paymentProcessor->setProduct($package)) { $this->return404(); } $processPaymentSuccesfully = $paymentProcessor->processPayment(); if ($processorId == "PayPal") { $notifyUrl = Config::get("siteRootUrl") . $this->moduleLink("ipn", false); $returnUrl = Config::get("siteRootUrl") . AppRouter::getRewrittedUrl("/webmaster/loading", false); $cancelReturnUrl = Config::get("siteRootUrl") . AppRouter::getRewrittedUrl("/webmaster/submitWebsite/premium", false); $paymentProcessor->setNotifyUrl($notifyUrl); $paymentProcessor->setReturnUrl($returnUrl); $paymentProcessor->setCancelReturnUrl($cancelReturnUrl); $this->set("paymentOptions", $paymentProcessor->getPaymentOptions()); } if ($processorId == "Allopass") { $this->viewClass = "JsonView"; if (!$processPaymentSuccesfully) { //set status to js part about that something is wrong with site data $this->set("status", "error"); //set error message what is wrong $this->set("message", _t($paymentProcessor->getLastError())); return; } //set status to js part about site proccessing $this->set("status", "ok"); //inform js to redirect $redirectUrl = AppRouter::getRewrittedUrl("/webmaster/submitWebsite/premium"); $this->set("redirectUrl", $redirectUrl); $this->set("message", _t("Allopass was validated sucessfully.")); } }
/** * Generate RSS for specified site */ function siteAction($siteId) { if (!Config::get("rssSitesEnabled")) { $this->return404(); } //get category data $site = $this->site->findByPk($siteId); if (empty($site)) { return $this->return404(); } $this->site->attachParents($site); $rawSiteTitle = $site['siteTitle']; $doc = new XmlGenerator(); $rssNode = $doc->createElement('rss'); $doc->appendChild($rssNode); $rssNode->setAttribute('version', '2.0'); $channelNode = new XmlElement('channel'); $rssNode->appendChild($channelNode); //add channel properties $channelNode->addProperty('title', utf8_htmlspecialchars($rawSiteTitle)); $channelNode->addProperty('link', AppRouter::getObjectUrl($site, "siteDetails", true)); $channelNode->addProperty('description', _t('Site') . ' ' . utf8_htmlspecialchars($rawSiteTitle)); $channelNode->addProperty('language', 'fr-fr'); $channelNode->addProperty('lastBuildDate', date('D, j M Y H:i:s O')); $channelNode->addProperty('generator', 'RSS Generator'); $sites = array($site); $this->appendSites($channelNode, $sites); $this->set("doc", $doc); $this->viewClass = "XmlView"; }
public static function getObjectUrl($object, $type, $absolute = false) { switch ($type) { case "tag": $urlParts = array("/site/tag/%d/%s/%d", $object['tagId'], NameTool::strToAscii($object['tag']), isset($object['page']) ? $object['page'] : 1); break; case "keyword": $urlParts = array("/site/keyword/%d/%s/%d", $object['keywordId'], NameTool::strToAscii($object['keyword']), isset($object['page']) ? $object['page'] : 1); break; case "category": $urlParts = array("/site/category/%d/%s/%d", $object['categoryId'], Config::get("advancedUrlRewritingEnabled") ? $object['urlName'] : NameTool::strToAscii($object['name']), isset($object['page']) ? $object['page'] : 1); break; case "keyword": $urlParts = array("/site/keyword/%d/%s/%d", $object['keywordId'], $object['keyword'], isset($object['page']) ? $object['page'] : 1); break; case "siteDetails": $titleUrl = NameTool::strToAscii($object['siteTitle']); if (Config::get("advancedUrlRewritingEnabled")) { $categoryUrl = ""; $categoryParents = $object['categoryParents']; foreach ($categoryParents as $categoryParent) { if ($categoryUrl) { $categoryUrl .= "\\"; } $categoryUrl .= NameTool::strToAscii($categoryParent['name']); } $urlParts = array("/site/details/%d/%s/%s", $object['siteId'], $categoryUrl, $titleUrl); } else { $urlParts = array("/site/details/%d/%s", $object['siteId'], $titleUrl); } break; } $url = AppRouter::getRewrittedUrl($urlParts); if ($absolute) { $url = Config::get("siteDomainUrl") . $url; } return $url; }
function saveCategoryAction() { $rebuild = false; $edit = !empty($this->request->categoryId); $imageSrc = false; try { $file = new UploadedFile("categoryImage"); $file->addFilter("extension", array("jpg", "gif", "png")); //check and save image if ($file->wasUploaded()) { $file->setSavePath(CODE_ROOT_DIR . 'uploads/images_categories/'); $file->save(); $imageSrc = $file->getSavedFileName(); } } catch (Exception $e) { } if (!$edit && $imageSrc == false) { $imageSrc = 'defaultCategoryImage.gif'; } //create and save new category $fields = $this->request->getArray(array("name", "urlName", "navigationName", "title", "headerDescription", "possibleTender", "description", "metaDescription", "parentCategoryId", "forbidden")); if ($edit) { $category = $this->category->findByPk($this->request->categoryId); //handle categoryParentId change if ($category->parentCategoryId != $this->request->parentCategoryId && $category->changeParent($this->request->parentCategoryId)) { $rebuild = true; } } else { $category = new CategoryRecord(); } $category->fromArray($fields); if ($imageSrc) { if ($edit) { $category->removeImage(); } $category->imageSrc = $imageSrc; } if (empty($category->urlName)) { $category->urlName = $category->name; } $excludeCategoryId = $edit ? $category->categoryId : false; $category->urlName = $this->category->getFreeUrlName($category->urlName, $excludeCategoryId); $category->save(); if (!$edit) { $this->categoryParent->addNode($this->request->parentCategoryId, $category->categoryId); } if ($rebuild) { $this->categoryParent->moveNode($category->categoryId, $category->parentCategoryId); $this->category->updateValidatedSitesCount(); } $redirect = AppRouter::getRewrittedUrl("/admin/category/index/" . $category->parentCategoryId); $this->redirect($redirect); }
/** * 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); } } }
* web applications through scripting. * * see https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS */ if (AppConfig::get('security.cors.enabled', false)) { $continue = cross_origin_resource_sharing(AppConfig::get('security.cors.allowed-origins', []), AppConfig::get('security.cors.allow-credentials', false)); if (!$continue) { die; } unset($continue); } /* * get a router to handle and generate URLs. */ require_once APPDIR . '/router.class.php'; $router = new AppRouter(); $router->decode_url($_SERVER['REQUEST_URI']); /* * Find the controller that registered for the requested URI. Note that here * $_REQUEST['controller'] stand for an alias and not a controller class, hence * the need of the router's logic. */ $controller = $router->find_route(isset($_REQUEST['controller']) ? $_REQUEST['controller'] : NULL, isset($_REQUEST['action']) ? $_REQUEST['action'] : NULL, $_SERVER['REQUEST_METHOD']); if (is_null($controller)) { require_once APPDIR . '/controllers/error.class.php'; $controller = new ErrorController(No2_HTTP::NOT_FOUND); } /* * Execute the requested action in order to be able to render the ressource. */ invoke_it:
<?php # Load everything! require '../config/loader.php'; $slim = new \Slim\Slim(); # Initialize the application. Custom logic goes below here. # Set up RedBean RapidRest::dbInit(); # It's just a configuration-friendly call to R::setup() # Route our request AppRouter::route(); # Add your custom routes to /lib/routes.php $slim->run(); # Run the program
function saveSiteAction() { $this->viewClass = "JsonView"; $edit = !empty($this->request->siteId); $validationOptions = array("admin" => true, "forceCategoryDuplicate" => true, "forcePossibleTender" => true); if ($edit) { $site = $this->site->findByPk($this->request->siteId); if ($site->status != "validated" && $this->request->status == "validated") { $site->_creationDate = "NOW()"; } $package = $site->packageId ? $this->package->findByPk($site->packageId) : null; $errorMessage = $this->siteValidator->validate($this->request, $site, $validationOptions + array("package" => $package)); } else { $site = new SiteRecord(); $this->request->webmasterEmail = $this->session->get("email"); $errorMessage = $this->siteValidator->validate($this->request, null, $validationOptions); } if ($errorMessage) { $status = "error"; $this->set("status", $status); $this->set("message", _t($errorMessage)); return; } $fields = array("categoryId", "webmasterName", "webmasterEmail", "webmasterId", "siteTitle", "url", "rssTitle", "rssFeedOfSite", "description", "returnBond", "status", "problemExists", "priority", "visitsCount", "referrerTimes"); if (Config::get("countryFlagsEnabled")) { array_push($fields, "countryCode"); } if (Config::get("companyInfoEnabled")) { array_push($fields, "address", "zipCode", "city", "country", "phoneNumber", "faxNumber"); } $site->fromArray($this->request->getArray($fields)); $site->save(); // store keywords if (!empty($this->request->keywords)) { $maxKeywordsCountPerSite = $package ? $package->maxKeywordsCountPerSite : Config::get("maxKeywordsCountPerSite"); $this->keywordsOfSite->storeKeywords($site->siteId, $this->request->keywords, $maxKeywordsCountPerSite); } if (!empty($this->request->tempId)) { $c = new Criteria(); $c->add("tempId", $this->request->siteId); $this->photo->update(array("siteId" => $site->siteId, "_tempId" => "NULL"), $c); $site->updatePhotos(); } $this->extraField->saveExtraFieldsValues($site, $this->request); $site->updateSuffix(); $this->set("status", "ok"); $this->set("message", _t("The site was successfully submitted.")); $this->set("redirectUrl", AppRouter::getRewrittedUrl("/moderation/site/waiting")); }
function deleteAction($fieldId) { $extraField = $this->extraField->findByPk($fieldId); if (empty($extraField)) { $this->return404(); } $c = new Criteria(); $c->add("fieldId", $extraField->fieldId); $c->setLimit(1); $categoryId = $this->extraFieldCategory->get("categoryId", $c); $extraField->del(); $url = AppRouter::getRewrittedUrl("/admin/category/edit/" . $categoryId); $this->redirect($url); }
function checkSiteTypeAccess($siteType, $action) { if (!Config::get("inscriptionsOfSitesEnabled")) { $this->redirect($this->moduleLink("submitDisabled")); } if (empty($siteType)) { if (Config::get("availableSiteTypes") == "basic") { $this->redirect($this->moduleLink("{$action}/basic")); } else { $this->redirect($this->moduleLink("chooseSiteType")); } } if (!$this->validSiteType($siteType)) { $this->return404(); } if ($siteType == "premium") { if (Config::get("registrationOfWebmastersEnabled")) { $payment = $this->payment->getUnusedPaidOneByUserId($this->userId); } else { $payment = $this->payment->getUnusedPaidOneByIp($this->request->getIp()); } if (empty($payment)) { $this->redirect(AppRouter::getRewrittedUrl("/payment/selectPaymentOptions")); } else { $package = $this->package->findByPk($payment->packageId); return $package; } } return null; }
function updateImageSrc() { if ($this->imageSrc) { $this->imageSrc = AppRouter::getResourceUrl("/uploads/images_packages/" . $this->imageSrc); } }
function validate($newSite, $oldSite = null, $validationOptions = array()) { $categoryId = intval($newSite->categoryId); $url = !empty($newSite->url) ? $newSite->url : ""; $isAdmin = !empty($validationOptions['admin']); $package = !empty($validationOptions['package']) ? $validationOptions['package'] : null; // required fields validation if (empty($newSite->siteTitle) || !isset($newSite->description)) { return 'Please, fill in the fields title and Description.'; } if (empty($categoryId)) { return 'Please, select a category from the dropdown list.'; } if (Config::get("urlMandatory") && empty($url)) { return 'Please fill URL field'; } if (!empty($url)) { // ensure that site is not registered in this category if ((!$oldSite || $oldSite->categoryId != $categoryId) && !$isAdmin && empty($validationOptions['forceCategoryDuplicate']) && $this->whetherSiteIsRegisteredInCategory($url, $categoryId)) { return 'The site is already registered in this category.'; } // check whether the URL is allowed to be offered if (!preg_match('#^' . Config::get("supportedUrlSchemes") . '://#', $url)) { return 'We do not support this url protocol'; } if (!preg_match('#^' . Config::get("supportedUrlSchemes") . '://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$#i', $url)) { return 'Url is invalid'; } if ($this->getIfHostIsBanned(AppRouter::getHostNameFromUrl($url), 0)) { return 'This site is not allowed to be offered.'; } if ($this->bannedSite->isBanned($url)) { return 'This site is not allowed to be offered.'; } if (!$oldSite && !$isAdmin) { if ((int) $this->getCountOfSiteCopiesInDifferentCategories($url) >= (int) Config::get('maxCategoriesCountPerSite')) { return 'This site is not allowed to be offered more times.'; } if ((int) $this->getCountOfSiteSubpages($url) >= (int) Config::get('maxSubpagesCountPerSite')) { return 'No more subpages of this site can be submitted.'; } } if (Config::get('inscriptionCheckHttpResponseCode') == 1) { $httpClient = new HttpClient(); $httpCode = $httpClient->checkResponseCodeOfSite($url); if ($httpCode != 200) { return 'This site\' HTTP response code is not 200. The site is not accepted.'; } } } if (!$isAdmin) { $minSiteDescriptionLength = $package ? $package['siteDescriptionMinLength'] : Config::get("minSiteDescriptionLength"); $rawDescription = strip_tags($newSite->description); if ($minSiteDescriptionLength && utf8_strlen($rawDescription) < $minSiteDescriptionLength && !$isAdmin) { return _t('Description of site must have minimum') . ' ' . $minSiteDescriptionLength . ' ' . _t('characters length.'); } $siteDescriptionMaxLength = $package ? $package['siteDescriptionMaxLength'] : Config::get('siteDescriptionMaxLength'); if ($siteDescriptionMaxLength && utf8_strlen($rawDescription) > $siteDescriptionMaxLength) { return _t('Description of site must have maximum') . ' ' . $siteDescriptionMaxLength . ' ' . _t('characters length.'); } } if (Config::get('backLinkMandatory') && (!$package || $package['backLinkMandatory']) && empty($newSite->returnBond) && !$isAdmin) { return 'Backlink is mandatory.'; } if (Config::get('countryFlagsEnabled') && empty($newSite->countryCode) && !$isAdmin) { return 'Country is mandatory.'; } $category = $this->category->findByPk($categoryId); if (!$category || !$isAdmin && $category->possibleTender != 1 && empty($validationOptions['forcePossibleTender'])) { return 'Sites cannot be offered for this category.'; } if ($this->bannedEmail->isBanned($newSite->webmasterEmail) && !$isAdmin) { return 'This email is banned.'; } if ($this->bannedIp->isBanned(Request::getInstance()->getIp())) { return 'Your IP is banned.'; } if (Config::get('duplicateContentCheckerEnabled') && !$isAdmin) { $duplicateChecker = new GoogleDuplicateChecker(); $duplicateChecker->setPhrasesToCheckCount(Config::get('duplicateContentCheckerPhrasesToCheckCount'))->setWordsInPhraseCount(Config::get('duplicateContentCheckerWordsInPhraseCount'))->setAllowableDuplicatedPhrasesCount(Config::get('duplicateContentCheckerAllowableDuplicatedPhrasesCount')); if ($duplicateChecker->isDuplicateContent($newSite->description)) { return 'We have detected duplicate content, change your description.'; } } $errorMessage = $this->extraField->validate($newSite); if ($errorMessage) { return $errorMessage; } return ''; }