Пример #1
0
 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);
 }
Пример #2
0
 /**
  * Display form to edit ads on specified site
  */
 function inAction($page)
 {
     //list of sites which can be edited
     $pages = array("news", "topHits", "topNotes", "topRank", "topReferrers", "search", "contact", "error404", "allcategories", "predefineCategory", "predefineSite", "predefineKeyword", "predefineTag", "index");
     if (!in_array($page, $pages)) {
         $this->return404();
     }
     $itemsPerPage = 0;
     //determine siteItems slots count to display on this ads page
     switch ($page) {
         case "news":
             $itemsPerPage = Config::get("maxNewsCount");
             break;
         case "topHits":
             $itemsPerPage = Config::get("maxTopHitsCount");
             break;
         case "topNotes":
             $itemsPerPage = Config::get("maxTopNotesCount");
             break;
         case "topRank":
             $itemsPerPage = Config::get("maxTopRankCount");
             break;
         case "topReferrers":
             $itemsPerPage = Config::get("maxTopReferrersCount");
             break;
         case "search":
             $itemsPerPage = Config::get("sitesPerPageInSearch");
             break;
         case "contact":
         case "allcategories":
         case "error404":
             $itemsPerPage = 0;
             break;
     }
     $this->set("itemsPerPage", $itemsPerPage);
     //get all accessible criterions to choose
     $this->set("adCriterias", $this->adCriteria->getSelectList());
     //set adPage name to js know what is edited
     $this->set("adPage", $page);
     $this->set("adPageDescription", str_replace("_", " ", NameTool::underscore($page)));
     //if non standard page load indyvidual files
     if (in_array($page, array("predefineCategory", "predefineSite", "predefineKeyword", "predefineTag", "index", "keywordLetter"))) {
         if ($page == "predefineKeyword") {
             $this->set("adPage", "predefineKeyword");
             $this->set("adPage2", "predefineLetter");
         }
         $this->viewFile = "pages/" . $page;
     }
 }
Пример #3
0
 public function render($controller)
 {
     $tpl = $this->templateLite;
     $templateName = $this->templateName;
     $tpl->template_dir = Config::get('TEMPLATES_PATH') . $templateName;
     if (!is_dir($tpl->template_dir)) {
         $templateName = Config::get("DEFAULT_TEMPLATE_NAME");
         $tpl->template_dir = Config::get('TEMPLATES_PATH') . $templateName;
     }
     $tpl->compile_dir = CODE_ROOT_DIR . "compiled/" . $controller->localDir . $templateName . "_template" . "/" . Config::get("language");
     if (!is_dir($tpl->compile_dir)) {
         $currentPath = CODE_ROOT_DIR . "compiled/";
         $dirs = explode("/", substr($tpl->compile_dir, strlen($currentPath)));
         foreach ($dirs as $dir) {
             $currentPath .= $dir . "/";
             if (!is_dir($currentPath)) {
                 $oldMask = umask(0);
                 mkdir($currentPath, 0777);
                 umask($oldMask);
             }
         }
     }
     $tpl->assign("setting", Config::getAll());
     $tpl->assign("display", Display::getAll());
     $tpl->assign("templateName", $templateName);
     $tpl->assign("controllerAction", $controller->action);
     $tpl->assign("controllerName", $controller->name);
     $tpl->assign(array_map_recursive("htmlspecialchars", $controller->viewVars));
     $tpl->assign("action", $controller->action);
     $tpl->assign("sessionLifeTime", ini_get('session.gc_maxlifetime'));
     if ($controller->viewFile) {
         $viewFile = NameTool::getTemplateFileName($controller->niceName . "/" . $controller->viewFile);
     } else {
         $viewFile = NameTool::getTemplateFileName($controller->niceName . "/" . $controller->action);
     }
     $tpl->encode_file_name = false;
     return $tpl->fetch($viewFile);
 }
Пример #4
0
 function validate()
 {
     $formFieldName = $this->formFieldName;
     if (empty($_FILES[$formFieldName])) {
         throw new Exception("Uploaded file dosn't exists");
     }
     if ($_FILES[$formFieldName]['size'] == 0 || $_FILES[$formFieldName]['error'] != 0) {
         throw new Exception("Transmission error or file have 0 bytes");
     }
     if (!is_uploaded_file($_FILES[$formFieldName]['tmp_name'])) {
         throw new Exception("This isn't uploaded file");
     }
     $this->fileExtension = preg_match("#\\.([^\\.]*)\$#", $_FILES[$formFieldName]['name'], $m) ? strtolower($m[1]) : "";
     if (in_array($this->fileExtension, array('php', 'php4', 'php5'))) {
         throw new Exception("PHP files can NOT be uploaded");
     }
     if (!empty($this->filters['extension']) && !in_array($this->fileExtension, $this->filters['extension'])) {
         throw new Exception("Wrong file format. We accept only (" . implode(", ", $this->filters['extension']) . ")");
     }
     if (!empty($this->filters['maxSize']) && $_FILES[$formFieldName]['size'] > $this->filters['maxSize']) {
         throw new Exception("Maximum allowable file size is " . NameTool::formatByteSize($this->filters['maxSize']) . " and your file have " . NameTool::formatByteSize($_FILES[$formFieldName]['size']));
     }
 }
Пример #5
0
 function createUrlNames()
 {
     $withParents = Config::get('advancedUrlRewritingParentsEnabled');
     set_time_limit(600);
     $categories = $this->category->findAll(null, "categoryId, parentCategoryId, name, urlName");
     $tree = new NavigationTree();
     foreach ($categories as $category) {
         $tree->addNode($category['categoryId'], $category['parentCategoryId'], array("name" => $category['name'], "urlName" => $category['urlName']));
     }
     $connections = $tree->getAllConnections();
     $urlNames = array("");
     foreach ($connections as $connection) {
         $urlName = NameTool::strToAscii($connection['value']['name']);
         if ($withParents) {
             $urlName = ltrim($urlNames[$connection['depth'] - 1] . "\\" . $urlName, "\\");
             $urlNames[$connection['depth']] = $urlName;
         }
         $urlName = $this->category->getFreeUrlName($urlName, $connection['categoryId']);
         if ($connection['value']['urlName'] && $connection['value']['urlName'] != $urlName && !$this->rewrite->findByPk($connection['value']['urlName'])) {
             $rewrite = new RewriteRecord();
             $rewrite->originalUrl = $connection['value']['urlName'];
             $rewrite->rewrittedUrl = $urlName;
             $rewrite->save();
         }
         $this->category->updateByPk(array("urlName" => $urlName), $connection['categoryId']);
     }
 }
Пример #6
0
 function getFreeUrlName($baseUrlName, $excludeCategoryId = false)
 {
     $baseUrlName = NameTool::strToAscii($baseUrlName, "_\\");
     $lp = 0;
     do {
         $lp++;
         $urlName = $baseUrlName;
         $urlName .= $lp > 1 ? $lp : "";
         if (in_array($urlName, array('admin', 'moderation', 'webmaster'))) {
             $exists = true;
         } else {
             $c = new Criteria();
             $c->add("urlName", $urlName);
             if ($excludeCategoryId) {
                 $c->add("categoryId", $excludeCategoryId, "!=");
             }
             $exists = $this->category->getCount($c);
         }
     } while ($exists);
     return $urlName;
 }
Пример #7
0
 /**
  * Display sites which contain tag
  */
 function tagAction($tagId, $tag, $page = 1)
 {
     $searchTag = $this->searchTag->findByPk($tagId);
     if (empty($searchTag) || NameTool::strToAscii($searchTag->tag) != $tag || $searchTag->banned) {
         return $this->return404();
     }
     //set adPage for ads
     Display::set("adPage", "tag" . $tagId);
     $searchedSites = array();
     //get sites which containt searched phrase
     $searchedSites = $this->siteSearcher->searchValidated(array("phrase" => $searchTag->tag), $page);
     //prepare data for pagination
     $totalPages = ceil($this->siteSearcher->getFoundRowsCount() / Config::get("sitesPerPageInSearch"));
     //set founded sites and paginations data
     $this->set("searchTag", $searchTag);
     $this->set("searchedSites", $searchedSites);
     $this->set("pageNavigation", array("baseLink" => "/site/tag/{$tagId}/" . NameTool::strToAscii($tag) . "/", "totalPages" => $totalPages, "currentPage" => $page, "title" => $tag));
 }
Пример #8
0
 /**
  * Dispatch an HTTP request to a controller/action.
  *
  * @param string $url Optional argument Url with routing informatins
  */
 public function dispatch($url = false, $return = false)
 {
     if (empty($this->router)) {
         $this->setRouter(new Router());
     }
     if (!$url) {
         $url = $this->getUrlParams();
     }
     $url = trim($url, "/");
     $route = $this->router->getRoute($url);
     if ($route['executeDir']) {
         $url = preg_replace("#^" . $route['executeDir'] . "/?#", "", $url);
     }
     $this->lastUrl = $url;
     $params = explode("/", $url);
     $index = 0;
     $route['path'] = $route['executeDir'] ? $route['executeDir'] . "/" : "";
     $this->setExecuteDir($route['executeDir']);
     if ($route['executeDir']) {
         $controllerDir = CODE_ROOT_DIR . $route['path'] . "controllers/";
         Config::set("LANGUAGES_PATH", CODE_ROOT_DIR . $route['path'] . "languages/");
         Config::set('TEMPLATES_PATH', CODE_ROOT_DIR . $route['path'] . "templates/");
     } else {
         $controllerDir = Config::get('CONTROLLERS_PATH');
     }
     $controllerName = empty($params[$index]) ? "" : basename($params[$index]);
     $index++;
     $controllerAction = empty($params[$index]) ? "" : basename($params[$index]);
     if (empty($controllerName) && !empty($controllerAction)) {
         $this->return404();
     }
     if (empty($controllerName)) {
         $controllerName = "Main";
     }
     if (empty($controllerAction)) {
         $controllerAction = "index";
     }
     $controllerActionMethod = $controllerAction . "Action";
     $controllerClassName = NameTool::getControllerClassName($controllerName, $route['executeDir']);
     $controllerFileName = NameTool::getControllerFileName($controllerName);
     $controllerPath = $controllerDir . $controllerFileName;
     if (!isset($controllers[$controllerClassName])) {
         if (!file_exists($controllerPath)) {
             return $this->throwError("Missed controller file: {$controllerPath}");
         }
         require_once $controllerPath;
         if (!class_exists($controllerClassName)) {
             return $this->throwError("Missed controller class" . ": {$controllerClassName}");
         }
         static $controllers = array();
         $controllers[$controllerClassName] = new $controllerClassName($this);
     }
     $controller = $controllers[$controllerClassName];
     $controller->action = $controllerAction;
     $controller->localDir = $route['path'];
     if (!is_callable(array($controller, $controllerActionMethod))) {
         return $this->throwError("Missed action method" . ": {$controllerActionMethod}");
     }
     if (is_callable(array($controller, "init"))) {
         call_user_func_array(array($controller, "init"), array());
     }
     $params = array_slice($params, 2);
     $result = call_user_func_array(array($controller, $controllerActionMethod), $params);
     if ($return || $result !== null) {
         return $result !== null ? $result : $controller->render();
     } else {
         echo $controller->render();
     }
 }
Пример #9
0
 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;
 }