Ejemplo n.º 1
0
 private function check($route)
 {
     if ($this->api->controller->method) {
         return;
     }
     $route_callback = call_user_func_array(array($this->api->controller, 'route'), func_get_args());
     $api_callback = null;
     if ($route_callback->status) {
         $this->api->controller->method = $this->api_method;
         $args_object = object(array('method' => $this->api_method, 'match' => $route_callback->match));
         if ($this->model_api_name) {
             $model_api_name = "api_" . $this->model_api_name;
             // $api_callback = $this->api->controller->model()->$model_api_name($args_object);
             $this->api->controller->model_api_processor = $object = object(array("method" => $model_api_name, "args" => $args_object));
             // $this->api->controller->api_callback = $api_callback;
         }
         if ($this->view_api_name && !\lib\router::get_storage('api')) {
             $view_api_name = "view_" . $this->view_api_name;
             if ($this->model_api_name) {
                 $args_object->api_callback = $api_callback;
             }
             // $api_callback = $this->api->controller->view()->$view_api_name($args_object);
             $this->api->controller->view_api_processor = $object = object(array("method" => $view_api_name, "args" => $args_object));
         }
     }
 }
Ejemplo n.º 2
0
 public function post_login()
 {
     // get parameters and set to local variables
     $mymobile = utility::post('mobile', 'filter');
     $mypass = utility::post('password');
     // check for mobile exist
     $tmp_result = $this->sql()->tableUsers()->whereUser_mobile($mymobile)->and('user_status', 'active')->select();
     // $tmp_result =  $this->sql()->tableUsers()->select();
     // if exist
     if ($tmp_result->num() == 1) {
         $tmp_result = $tmp_result->assoc();
         $myhashedPassword = $tmp_result['user_pass'];
         // if password is correct. go for login:)
         if (isset($myhashedPassword) && utility::hasher($mypass, $myhashedPassword)) {
             // you can change the code way easily at any time!
             // $qry		= $this->sql()->tableUsers ()
             // 				->setUser_logincounter  ($tmp_result['user_logincounter'] +1)
             // 				->whereId               ($tmp_result['id']);
             // $sql		= $qry->update();
             $myfields = array('id', 'user_displayname', 'user_mobile', 'user_status');
             $this->setLoginSession($tmp_result, $myfields);
             // ======================================================
             // you can manage next event with one of these variables,
             // commit for successfull and rollback for failed
             // if query run without error means commit
             $this->commit(function () {
                 // $this->logger('login');
                 // create code for pass with get to service home page
                 debug::true(T_("Login Successfully"));
                 $referer = \lib\router::urlParser('referer', 'host');
                 /**
                  * temporary: after fix permissions below line must be delete
                  */
                 if ($referer == 'archiver.dev' || $referer == 'irancamera.ir') {
                     $this->redirector()->set_domain()->set_sub_domain('files')->set_url();
                 } elseif (\lib\router::get_storage('CMS')) {
                     $this->redirector()->set_domain()->set_sub_domain(\lib\router::get_storage('CMS'))->set_url();
                 } else {
                     $this->redirector()->set_domain()->set_url();
                 }
             });
             $this->rollback(function () {
                 debug::error(T_("Login failed!"));
             });
         } else {
             debug::error(T_("Mobile or password is incorrect"));
         }
     } elseif ($tmp_result->num() == 0) {
         debug::error(T_("Mobile or password is incorrect"));
     } else {
         debug::error(T_("Please forward this message to administrator"));
     }
     sleep(0.1);
 }
Ejemplo n.º 3
0
 public function __construct($_protocol, $_url, $_title, $_desc)
 {
     $this->siteurl = $_protocol . $_url;
     $this->rssFeed = '<?xml version="1.0" encoding="utf-8"?>' . "\n\n";
     $this->rssFeed .= '<rss version="2.0"' . "\n " . 'xmlns:content="http://purl.org/rss/1.0/modules/content/"' . "\n " . 'xmlns:wfw="http://wellformedweb.org/CommentAPI/"' . "\n " . 'xmlns:dc="http://purl.org/dc/elements/1.1/"' . "\n " . 'xmlns:atom="http://www.w3.org/2005/Atom"' . "\n " . 'xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"' . "\n " . 'xmlns:slash="http://purl.org/rss/1.0/modules/slash/"' . "\n" . '>' . "\n\n";
     $this->rssFeed .= '  <channel>' . "\n\n";
     $this->rssFeed .= '    <title>' . $_title . '</title>' . "\n";
     $this->rssFeed .= '    <link>' . $_protocol . $_url . '</link>' . "\n";
     $this->rssFeed .= '    <description>' . $_desc . '</description>' . "\n";
     $this->rssFeed .= '    <language>' . str_replace('_', '-', \lib\router::get_storage('defaultLanguage')) . '</language>' . "\n";
     $this->rssFeed .= '    <copyright>Copyright (C) ' . date("Y") . ' ' . $_url . '</copyright>' . "\n";
     $this->rssFeed .= '    <generator>' . 'Saloos!' . '</generator>' . "\n";
 }
Ejemplo n.º 4
0
 public function _processor($options = false)
 {
     if (is_array($options)) {
         $options = (object) $options;
     }
     $force_json = gettype($options) == 'object' && isset($options->force_json) && $options->force_json ? true : false;
     $force_stop = gettype($options) == 'object' && isset($options->force_stop) && $options->force_stop ? true : false;
     $not_redirect = gettype($options) == 'object' && isset($options->not_redirect) && $options->not_redirect ? true : false;
     if ($this->transaction && debug::$status) {
         if (isset($this->sql)) {
             $this->sql->commit();
         }
         if (count($this->commit)) {
             call_user_func_array($this->commit[0], array_slice($this->commit, 1));
         }
     } elseif ($this->transaction && !debug::$status) {
         if (isset($this->sql)) {
             $this->sql->rollback();
         }
         if (count($this->rollback)) {
             call_user_func_array($this->rollback[0], array_slice($this->rollback, 1));
         }
     }
     if ($not_redirect) {
         $this->controller()->redirector = false;
     }
     if (\saloos::is_json_accept() || $force_json) {
         header('Content-Type: application/json');
         if (isset($this->controller()->redirector) && $this->controller()->redirector) {
             $_SESSION['debug'][md5(strtok($this->redirector()->redirect(true), '?'))] = debug::compile();
             debug::msg("redirect", $this->redirector()->redirect(true));
         }
         echo debug::compile(true);
     } elseif (!\lib\router::get_storage('api') && strtolower($_SERVER['REQUEST_METHOD']) == "post") {
         $this->redirector();
     }
     if (isset($this->controller()->redirector) && $this->controller()->redirector && !\saloos::is_json_accept()) {
         $_SESSION['debug'][md5(strtok($this->redirector()->redirect(true), '?'))] = debug::compile();
         $this->redirector()->redirect();
     }
     if ($force_stop) {
         exit;
     }
 }
Ejemplo n.º 5
0
 /**
  * return list of posts in custom term like cat or tag
  * @return [type] datarow
  */
 public function sp_postsInTerm($_limit = null)
 {
     $url = $this->url('path');
     if (substr($url, 0, 4) === 'tag/') {
         $url = substr($url, 4, $url);
     }
     if (substr($url, 0, 11) === 'book-index/') {
         preg_match("#^book-index/([^\\/]*)(.*)\$#", $url, $m);
         $url_raw = "book/{$m['1']}";
         if ($m[2] !== '') {
             $qry = $this->sql()->table('posts')->where('post_status', 'publish')->order('id', 'ASC');
             $qry->join('termusages')->on('termusage_id', '#posts.id')->and('termusage_foreign', '#"posts"');
             $qry->join('terms')->on('id', '#termusages.term_id')->and('term_url', $url)->groupby('#posts.id');
         } else {
             $parent_id = $this->sql()->table('posts')->where('post_url', $url_raw)->and('post_status', 'publish')->select()->assoc('id');
             $qry = $this->sql()->table('posts')->where('post_parent', $parent_id)->and('post_status', 'publish')->order('id', 'ASC');
         }
         return $qry->select()->allassoc();
     }
     $qry = $this->sql()->table('posts')->where('post_status', 'publish')->order('id', 'DESC');
     $qry->join('termusages')->on('termusage_id', '#posts.id')->and('termusage_foreign', '#"posts"')->field(false);
     $qry->join('terms')->on('id', '#termusages.term_id')->and('term_url', $url)->groupby('#posts.id')->field(false);
     // hasan :|
     $pagenation = [];
     if ($_limit) {
         $qryCount = clone $qry;
         $qryCount->field("#count(posts.id)");
         $count = $qryCount->select()->num();
         $pagenationPages = ceil($count / $_limit);
         $pagenationCurrent = \lib\router::get_storage("pagenation");
         $pagenationNext = \lib\router::get_storage("pagenation") + 1;
         $pagenationPrev = \lib\router::get_storage("pagenation") - 1;
         if ($pagenationCurrent !== null and $pagenationCurrent < 1 || $pagenationCurrent > $pagenationPages) {
             \lib\error::page(T_("Does not exist!"));
             return;
         }
         $pagenation = ["num_page" => $pagenationPages, "pages" => intval($pagenationPages), "current" => $pagenationCurrent == 0 ? 1 : intval($pagenationCurrent), "next" => $pagenationNext <= $pagenationPages ? $pagenationNext : false, "prev" => $pagenationPrev >= 1 ? $pagenationPrev : false, "count_link" => 7, "current_url" => \lib\router::get_url()];
         $start = \lib\router::get_storage("pagenation") ? (\lib\router::get_storage("pagenation") - 1) * $_limit : 0;
         $qry->limit($start, $_limit);
     }
     return ["pagenation" => $pagenation, "result" => $qry->select()->allassoc()];
 }
Ejemplo n.º 6
0
 /**
  * [__construct description]
  */
 public function __construct()
 {
     parent::__construct();
     if (MyAccount && SubDomain == null) {
         if (AccountService === Domain) {
             $domain = null;
         } else {
             $domain = AccountService . MainTld;
         }
         $param = $this->url('param');
         if ($param) {
             $param = '?' . $param;
         }
         switch ($this->module()) {
             case 'signin':
             case 'login':
                 $this->redirector()->set_domain($domain)->set_url(MyAccount . '/login' . $param)->redirect();
                 break;
             case 'signup':
             case 'register':
                 $this->redirector()->set_domain($domain)->set_url(MyAccount . '/signup' . $param)->redirect();
                 break;
             case 'signout':
             case 'logout':
                 // if(Domain !== MainService)
                 // $this->redirector()->set_domain(MainService.'.'.Tld)->set_url('logout')->redirect();
                 $this->redirector()->set_domain()->set_url(MyAccount . '/logout' . $param)->redirect();
                 break;
                 // case 'favicon.ico':
                 // 	$this->redirector()->set_domain()->set_url('static/images/favicon.png')->redirect();
                 // 	break;
         }
     }
     $myrep = router::get_repository_name();
     // running template base module for homepage
     if (\lib\router::get_storage('CMS') && $myrep === 'content' && method_exists($this, 's_template_finder') && get_class($this) === 'content\\home\\controller') {
         $this->s_template_finder();
     }
     $this->pagnation_config();
     $this->save_ref();
 }
Ejemplo n.º 7
0
 public function _corridor()
 {
     if (method_exists($this, 'corridor')) {
         $this->corridor();
     }
     if (!$this->method) {
         $this->method = 'get';
     }
     $processor_arg = false;
     if (isset($this->model_api_processor)) {
         $name = $this->model_api_processor->method;
         $args = $this->model_api_processor->args;
         $api_callback = call_user_func_array(array($this->model(), $name), array($args));
         $this->api_callback = $api_callback;
     }
     if (saloos::is_json_accept()) {
         $this->display = false;
     }
     if (!\lib\router::get_storage('api') && $this->method == 'get' && $this->display) {
         $this->view();
         if (isset($this->view_api_processor)) {
             $name = $this->view_api_processor->method;
             $args = $this->view_api_processor->args;
             if (isset($this->api_callback)) {
                 $args->api_callback = $api_callback;
             }
             call_user_func_array(array($this->view(), $name), array($args));
         }
         if ($this->display) {
             $this->view()->corridor();
         }
     } elseif (router::get_storage('api') || !$this->display) {
         $mycallback = isset($this->api_callback) ? $this->api_callback : null;
         debug::msg('callback', $mycallback);
         $processor_arg = object(array('force_json' => true));
     }
     if ($this->model) {
         $this->model()->_processor($processor_arg);
     }
 }
Ejemplo n.º 8
0
 /**
  * check saloos language and if needed convert to persian date
  * else show default date
  * @param  [type] $_date [description]
  * @return [type]        [description]
  */
 public static function date($_format, $_stamp = false, $_type = false, $_persianChar = true)
 {
     $result = null;
     if (strlen($_stamp) < 2) {
         $_stamp = false;
     }
     // get target language
     if ($_type === 'default') {
         $_type = substr(\lib\router::get_storage('defaultLanguage'), 0, 2);
     } elseif ($_type === 'current') {
         $_type = substr(\lib\router::get_storage('language'), 0, 2);
     }
     // if need persian use it else use default date function
     if ($_type === true || $_type === 'fa') {
         $result = \lib\utility\jdate::date($_format, $_stamp, $_persianChar);
     } else {
         if ($_stamp) {
             $result = date($_format, $_stamp);
         } else {
             $result = date($_format);
         }
     }
     return $result;
 }
Ejemplo n.º 9
0
 function _route()
 {
     // check permission to access to cp
     if (Tld !== 'dev') {
         parent::_permission('cp');
     }
     // // Restrict unwanted module
     // if(!$this->cpModlueList())
     // 	\lib\error::page(T_("Not found!"));
     $exist = false;
     $mymodule = $this->cpModule('table');
     $cpModule = $this->cpModule('raw');
     // var_dump($this->child());
     $this->display_name = 'content_cp/templates/raw.html';
     switch ($this->child()) {
         case 'dbtables':
             $exist = true;
             echo \lib\utility\dbTables::create();
             break;
         case 'db':
             $exist = true;
             if (\lib\utility::get('upgrade')) {
                 // do upgrade
                 $result = \lib\db::install(true);
             } elseif (\lib\utility::get('backup')) {
                 $result = \lib\db::backup(true);
             }
             echo '<pre>';
             print_r($result);
             echo '</pre>';
             break;
         case 'twigtrans':
             $exist = true;
             $mypath = \lib\utility::get('path');
             $myupdate = \lib\utility::get('update');
             echo \lib\utility\twigTrans::extract($mypath, $myupdate);
             break;
         case 'phpinfo':
             $exist = true;
             phpinfo();
             break;
         case 'server':
             $exist = true;
             if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && !class_exists("COM")) {
                 ob_start();
                 echo "<!DOCTYPE html><meta charset='UTF-8'/><title>Extract text form twig files</title><body style='padding:0 1%;margin:0 1%;direction:ltr;overflow:hidden'>";
                 echo "<h1>" . T_("First you need to enable COM on windows") . "</h1>";
                 echo "<a target='_blank' href='http://www.php.net/manual/en/class.com.php'>" . T_("Read More") . "</a>";
                 break;
             }
             \lib\utility\tools::linfo();
             $this->display_name = 'content_cp/templates/raw-all.html';
             break;
         case 'twitter':
             $a = \lib\utility\socialNetwork::twitter('hello! test #api');
             // var_dump($a);
             break;
         case 'mergefiles':
             $exist = true;
             echo \lib\utility\tools::mergefiles('merged-project.php');
             if (\lib\utility::get('type') === 'all') {
                 echo \lib\utility\tools::mergefiles('merged-saloos-lib.php', core . lib);
                 echo \lib\utility\tools::mergefiles('merged-saloos-cp.php', addons . 'content_cp/');
                 echo \lib\utility\tools::mergefiles('merged-saloos-account.php', addons . 'content_account/');
                 echo \lib\utility\tools::mergefiles('merged-saloos-includes.php', addons . 'includes/');
             }
             break;
         case 'sitemap':
             $exist = true;
             $site_url = \lib\router::get_storage('url_site');
             $sitemap = new \lib\utility\sitemap($site_url, root . 'public_html/', 'sitemap');
             // echo "<pre>";
             // add posts
             foreach ($this->model()->sitemap('posts', 'post') as $row) {
                 $sitemap->addItem($row['post_url'], '0.8', 'daily', $row['post_publishdate']);
             }
             // add pages
             foreach ($this->model()->sitemap('posts', 'page') as $row) {
                 $sitemap->addItem($row['post_url'], '0.6', 'weekly', $row['post_publishdate']);
             }
             // add attachments
             foreach ($this->model()->sitemap('posts', 'attachment') as $row) {
                 $sitemap->addItem($row['post_url'], '0.2', 'weekly', $row['post_publishdate']);
             }
             // add books
             foreach ($this->model()->sitemap('posts', 'book') as $row) {
                 $sitemap->addItem($row['post_url'], '0.6', 'yearly', $row['post_publishdate']);
             }
             // add cats and tags
             foreach ($this->model()->sitemap('terms') as $row) {
                 $sitemap->addItem($row['term_url'], '0.4', 'weekly', $row['date_modified']);
             }
             $sitemap->createSitemapIndex();
             echo "<p class='alert alert-success'>Create sitemap Successfully!</p>";
             // echo "Create Successful";
             break;
         case 'git':
             // declare variables
             $exist = true;
             $rep = null;
             $result = [];
             $location = '../../';
             $name = \lib\utility::get('name');
             $output = null;
             // switch by name of repository
             switch ($name) {
                 case 'saloos':
                     $location .= 'saloos';
                     $rep .= "https://github.com/Ermile/Saloos.git";
                     break;
                 case 'addons':
                     $location .= 'saloos/saloos-addons';
                     $rep .= "https://github.com/Ermile/Saloos-Addons.git";
                     break;
                 default:
                     $exist = false;
                     return;
                     break;
             }
             // change location to address of requested
             chdir($location);
             // start show result
             $output = "<pre>";
             $output .= 'Repository address: ' . getcwd() . '<br/>';
             $output .= 'Remote address:     ' . $rep . '<hr/>';
             $command = 'git pull ' . $rep . ' 2>&1';
             // Print the exec output inside of a pre element
             exec($command, $result);
             if (!$result) {
                 $output .= T_('Not Work!');
             }
             foreach ($result as $line) {
                 $output .= $line . "\n";
             }
             $output .= "</pre>";
             echo $output;
             break;
         case null:
             $mypath = $this->url('path', '_');
             if (is_file(addons . 'content_cp/templates/static_' . $mypath . '.html')) {
                 $this->display_name = 'content_cp/templates/static_' . $mypath . '.html';
             }
             // $this->display_name	= 'content_cp/templates/static_'.$mypath.'.html';
             break;
         default:
             $this->display_name = 'content_cp/templates/static_tools.html';
             return;
             break;
     }
     // $this->get()->ALL();
     if ($exist) {
         $this->model()->_processor(object(array("force_json" => false, "force_stop" => true)));
     }
     return;
 }
Ejemplo n.º 10
0
 public function loadController()
 {
     /**
      * find controller;
      */
     $url_property = router::get_url_property(-1);
     $myrep = router::get_repository_name();
     if (!router::get_controller()) {
         $controller_name = '\\' . $myrep . '\\' . router::get_class() . '\\' . router::get_method() . '\\controller';
         $prv_class = router::get_class();
         // var_dump($controller_name);
         if (!class_exists($controller_name)) {
             if ((!isset($url_property[1]) || $url_property[1] != router::get_method()) && router::get_method() != 'home') {
                 router::add_url_property(router::get_method());
             }
             $prv_method = router::get_method();
             router::set_method('home');
             $controller_name = '\\' . $myrep . '\\' . router::get_class() . '\\' . router::get_method() . '\\controller';
             // var_dump(router::get_url_property(-1));
             // var_dump($controller_name);
             if (!class_exists($controller_name)) {
                 router::set_class($prv_class);
                 $controller_name = '\\' . $myrep . '\\' . router::get_class() . '\\controller';
                 // var_dump(router::get_url_property(-1));
                 // var_dump($controller_name);
                 if (!class_exists($controller_name)) {
                     if ((!isset($url_property[0]) || $url_property[0] != router::get_class()) && router::get_class() != 'home') {
                         router::add_url_property(router::get_class());
                     }
                     router::set_class('home');
                     $controller_name = '\\' . $myrep . '\\' . router::get_class() . '\\' . router::get_method() . '\\controller';
                     // var_dump(router::get_url_property(-1));
                     // var_dump($controller_name);
                     //
                     if (!class_exists($controller_name)) {
                         router::set_class('home');
                         $controller_name = '\\' . $myrep . '\\' . router::get_class() . '\\controller';
                         // var_dump(router::get_url_property(-1));
                         // $controller_name='\account\home\controller';
                         // var_dump($controller_name);
                         if (!class_exists($controller_name)) {
                             \lib\error::page("content not found");
                         }
                     }
                 }
             }
         }
     } else {
         $controller_name = router::get_controller();
     }
     router::set_controller($controller_name);
     if (!class_exists($controller_name)) {
         error::page($controller_name);
     }
     $controller = new $controller_name();
     self::$controller = $controller;
     // running template base module for homepage
     if (\lib\router::get_storage('CMS') && $myrep == 'content' && method_exists($controller, 's_template_finder')) {
         $controller->s_template_finder();
     }
     if (method_exists($controller, '_route')) {
         $controller->_route();
     }
     if (router::get_controller() !== $controller_name) {
         $this->loadController();
         return;
     }
     if (method_exists($controller, 'config')) {
         $controller->config();
     }
     if (method_exists($controller, 'options')) {
         $controller->options();
     }
     if (count(router::get_url_property(-1)) > 0 && $controller->route_check_true === false) {
         error::page('Unavailable');
     }
     $controller->_corridor();
 }
Ejemplo n.º 11
0
 /**
  * this function return the number of post needed with special condition
  * @param  [type] $args argumats can pass from twig
  * @return [type]       the array contain list of posts
  */
 public function posts(...$args)
 {
     $qry = $this->sql()->tablePosts();
     $qry = $qry->andPost_type('post');
     // check passed value for exist and use it ----------------------------- number of post and offset
     // if pass number of records needed in first param
     if (isset($args[0]) && is_numeric($args[0])) {
         // if pass offset as 2nd param
         if (isset($args[1]) && is_numeric($args[1])) {
             $qry = $qry->limit($args[1], $args[0]);
         } else {
             $qry = $qry->limit($args[0]);
         }
     } else {
         $qry = $qry->limit(10);
     }
     // check passed value for exist and use it ----------------------------- Language
     $post_language = array_column($args, 'language');
     if ($post_language && count($post_language) === 1) {
         $qry = $qry->and('post_language', $post_language);
     } else {
         $qry = $qry->groupOpen('g_language');
         $qry = $qry->and('post_language', substr(\lib\router::get_storage('language'), 0, 2));
         $qry = $qry->or('post_language', 'IS', 'NULL');
         $qry = $qry->groupClose('g_language');
     }
     // check passed value for exist and use it ----------------------------- orderby
     $post_orderby = array_column($args, 'orderby');
     if ($post_orderby && count($post_orderby) === 1) {
         $post_orderby = "order" . ucfirst($post_orderby[0]);
     } else {
         $post_orderby = "orderId";
     }
     // check passed value for exist and use it ----------------------------- order
     $post_order = array_column($args, 'order');
     if ($post_order && count($post_order) === 1) {
         $post_order = $post_order[0];
         if (!is_array($post_order)) {
             $qry = $qry->{$post_orderby}($post_order);
         }
     } else {
         $qry = $qry->{$post_orderby}('desc');
     }
     // check passed value for exist and use it ----------------------------- status
     $post_status = array_column($args, 'status');
     if ($post_status && count($post_status) === 1) {
         $post_status = $post_status[0];
         // if pass in array splite it and create specefic query
         if (is_array($post_status)) {
             foreach ($post_status as $value) {
                 if ($value === reset($post_status)) {
                     $qry = $qry->groupOpen('g_status');
                     $qry = $qry->andPost_status($value);
                 } else {
                     $qry = $qry->orPost_status($value);
                 }
             }
             $qry = $qry->groupClose('g_status');
         } else {
             $qry = $qry->andPost_status($post_status);
         }
     } else {
         $qry = $qry->andPost_status('publish');
     }
     // check passed value for exist and use it ----------------------------- category
     $post_cat = array_column($args, 'cat');
     // INNER JOIN termusages ON posts.id = termusages.object_id
     // INNER JOIN terms ON termusages.term_id = terms.id
     // WHERE
     // termusages.termusage_type = 'posts'
     if ($post_cat && count($post_cat) === 1) {
         // $qry = $qry->query("SELECT `posts`.* FROM `posts` ");
         $post_cat = $post_cat[0];
         $qry->joinTermusages()->on('termusage_id', '#posts.id')->and('termusage_foreign', '#"posts"');
         // $qry->joinTerms()->whereId('#termusages.term_id')->andTerm_slug('#"statements"');
         // $obj = $qry->joinTerms();
         // $obj->whereId('#termusages.term_id')->andTerm_slug('#"statements"');
         $obj = $qry->joinTerms()->on('id', '#termusages.term_id')->groupby('#posts.id');
         // $obj->whereTerm_slug('#"statements"');
         // if pass in array splite it and create specefic query
         if (is_array($post_cat)) {
             foreach ($post_cat as $value) {
                 $opr = '=';
                 if (substr($value, 0, 1) === '-') {
                     $opr = '<>';
                     $value = substr($value, 1);
                 }
                 if ($value === reset($post_cat)) {
                     // $qry = $qry->groupOpen('g_cat');
                     $obj->andTerm_slug($opr, "{$value}");
                 } else {
                     $obj->orTerm_slug($opr, "{$value}");
                 }
             }
             // $qry = $qry->groupClose('g_cat');
         } else {
             $opr = '=';
             if (substr($post_cat, 0, 1) === '-') {
                 $opr = '<>';
                 $post_cat = substr($post_cat, 1);
             }
             $obj->andTerm_slug($opr, "{$post_cat}");
         }
         // $qry->joinUsers()->whereId('#kids.user_id')
         // 						->fieldUser_firstname("firstname")
     }
     $qry = $qry->select();
     // echo $qry->string();
     return $qry->allassoc();
 }
Ejemplo n.º 12
0
 public function __construct($_clean_url = null)
 {
     self::$repository = repository;
     $path = preg_replace("/^\\.\\//", "/", '/');
     $clean_url = $_clean_url !== null ? $_clean_url : $_SERVER['REQUEST_URI'];
     if (preg_match("#0x#", $clean_url)) {
         // error
     }
     $clean_url = preg_replace("#0x#Ui", "", $clean_url);
     $clean_url = preg_replace("#^https?://{$_SERVER['HTTP_HOST']}\\/#", '', $clean_url);
     $clean_url = preg_replace("#^{$path}#", '', $clean_url);
     $clean_url = urldecode($clean_url);
     preg_match("/^([^?]*)(\\?.*)?\$/", $clean_url, $url);
     self::$real_url_string = self::$url_string = $url[1];
     self::$real_url_array = self::$url_array = preg_split("[\\/]", preg_replace("/^\\/|\\/\$/", '', $url[1]), -1, PREG_SPLIT_NO_EMPTY);
     // HTTP_HOST is not secure and attacker can change it
     $domain = $_SERVER['HTTP_HOST'];
     self::$domain = preg_split("[\\.]", $domain);
     self::$sub_domain = self::$domain;
     array_pop(self::$sub_domain);
     array_pop(self::$sub_domain);
     if (isset(self::$real_url_array[0]) && self::$real_url_array[0] == 'home' || isset(self::$real_url_array[1]) && self::$real_url_array[1] == 'home') {
         \lib\error::page("home");
     }
     /**
      * user want control panel or CMS
      */
     if (defined('CMS') && constant('CMS')) {
         $myCP = constant('CMS') === true ? 'cp' : constant('CMS');
         router::set_storage('CMS', $myCP);
     } else {
         router::set_storage('CMS', 'cp');
     }
     /**
      * before router
      */
     if (self::$auto_repository) {
         // first get subdomain and if not exist get first url part as mysub
         $mysub = router::get_sub_domain();
         if (!$mysub) {
             $mysub = router::get_url(0);
             router::$sub_is_fake = true;
             // router::$sub_is_fake = $mysub? true: false;
             // router::set_storage('language', router::get_storage('defaultLanguage') );
         }
         if ($mysub) {
             // automatically set repository if folder of it exist
             $myaddons = array();
             $mysub_real = $mysub;
             $myloc = null;
             $mysub_valid = null;
             // check for account with specefic name
             if (\lib\router::get_storage('CMS')) {
                 $myaddons[\lib\router::get_storage('CMS')] = 'cp';
                 $myaddons['account'] = 'account';
             }
             // check this sub is exist in our data or not
             if (array_key_exists($mysub, $myaddons)) {
                 $mysub = $myaddons[$mysub];
                 $mysub_valid = true;
             }
             // set repository name
             $myrep = 'content_' . $mysub;
             // check content_aaa folder is exist in project or saloos addons folder
             if (is_dir(root . $myrep)) {
                 $myloc = false;
             } elseif ($mysub_valid && is_dir(addons . $myrep)) {
                 $myloc = addons;
             }
             // if folder exist
             if (!is_null($myloc)) {
                 // if url is fake, show it like subdomain and remove from url
                 if (router::$sub_is_fake) {
                     router::remove_url($mysub_real);
                     router::set_sub_domain($mysub_real);
                 }
                 // set repository to this folder
                 $myparam = array($myrep);
                 if ($myloc) {
                     array_push($myparam, $myloc);
                 }
                 // call function and pass param value to it
                 router::set_repository(...$myparam);
             }
         }
     }
     if (self::$auto_api) {
         // automatically allow api, if you wan't to desable it, only set a value
         $route = new router\route("/^api([^\\/]*)/", function ($reg) {
             router::remove_url($reg->url);
             router::set_storage('api', true);
         });
     }
     if (class_exists('\\cls\\route')) {
         $router = new \cls\route();
         $router->main = $this;
         if (method_exists($router, "_before")) {
             $router->_before();
         }
     }
     // like dev or com or ir or ...
     if (!defined('Tld')) {
         define('Tld', router::get_root_domain('tld'));
     }
     $this->check_router();
     /**
      * after router
      */
     if (class_exists('\\cls\\route')) {
         if (method_exists($router, "_after")) {
             $router->_after();
         }
     }
     // Define Project Constants *******************************************************************
     // declate some constant variable for better use in all part of app
     // like .dev or .com
     if (!defined('MainTld')) {
         // if enabling multi domain and set default tld define main tld
         if (\lib\utility\option::get('config', 'meta', 'multiDomain') && ($defaultTld = \lib\utility\option::get('config', 'meta', 'defaultTld'))) {
             define('MainTld', '.' . $defaultTld);
         } else {
             define('MainTld', Tld === 'dev' ? '.dev' : '.com');
         }
     }
     // like ermile
     if (!defined('Domain')) {
         define('Domain', router::get_root_domain('domain'));
     }
     // like account
     if (!defined('SubDomain')) {
         define('SubDomain', router::get_sub_domain());
     }
     // like  127.0.0.1
     if (!defined('ClientIP')) {
         define('ClientIP', router::get_clientIP());
     }
     // like ermile.com
     if (!defined('Service')) {
         define('Service', Domain . '.' . Tld);
     }
     // like test
     if (!defined('Module')) {
         define('Module', router::get_url(0));
     }
     // like https://ermile.com
     router::set_storage('url_site', Protocol . '://' . Domain . '.' . Tld . '/');
     // set MyAccount for use in all part of services
     if (!defined('AccountService')) {
         // if user want main account and set main account name
         if (\lib\utility\option::get('config', 'meta', 'useMainAccount') && \lib\utility\option::get('config', 'meta', 'mainAccount') === constant('MainService')) {
             define('AccountService', constant('MainService'));
         } else {
             define('AccountService', Domain);
         }
     }
     // check for account with specefic name
     if (!defined('MyAccount') && \lib\router::get_storage('CMS')) {
         // set MyAccount for use in all part of services
         define('MyAccount', 'account');
     }
     router::$base = Protocol . '://';
     if (router::$sub_is_fake) {
         router::$base .= Service . (SubDomain ? '/' . SubDomain : null);
     } else {
         router::$base .= SubDomain . '.' . Service;
     }
     if (count(explode('.', SubDomain)) > 1) {
         die("<p>Saloos only support one subdomain!</p>");
     } elseif (SubDomain === 'www') {
         header('Location: ' . router::get_storage('url_site'), true, 301);
     }
 }
Ejemplo n.º 13
0
 function s_template_finder()
 {
     // if lang exist in module or subdomain remove it and continue
     $currentLang = substr(router::get_storage('language'), 0, 2);
     $defaultLang = substr(router::get_storage('defaultLanguage'), 0, 2);
     if ($currentLang === SubDomain && $currentLang !== $defaultLang) {
         \lib\router::set_sub_domain(null);
     }
     // elseif($currentLang === $this->module() && $currentLang !== $defaultLang)
     // 	\lib\router::remove_url($currentLang);
     // continue find best template for this condition
     $mymodule = $this->module();
     if ($mymodule == 'home') {
         // if home template exist show it
         if (is_file(root . 'content/template/home.html')) {
             $this->display_name = 'content\\template\\home.html';
         }
         $this->get()->ALL();
         return 0;
     } elseif ($mymodule == 'search') {
         if (is_file(root . 'content/template/search.html')) {
             $this->display_name = 'content\\template\\search.html';
         }
         $this->get()->ALL();
         return;
     } elseif ($mymodule == 'feed') {
         $site_title = $this->view()->data->site['title'];
         $site_desc = $this->view()->data->site['desc'];
         $site_protocol = $this->url('MainProtocol') . '://';
         $site_url = $this->url('MainSite');
         $rss = new \lib\utility\RSS($site_protocol, $site_url, $site_title, $site_desc);
         // add posts
         foreach ($this->model()->get_feeds() as $row) {
             $rss->addItem($row['link'], $row['title'], $row['desc'], $row['date']);
         }
         $rss->create();
         // \lib\utility\RSS::create();
         exit;
         return;
     }
     if (!empty(db_name)) {
         $myurl = $this->model()->s_template_finder();
     } else {
         $myurl = null;
     }
     // if url does not exist show 404 error
     if (!$myurl) {
         // var_dump($mymodule);
         // var_dump(\lib\router::get_storage('language'));
         // if user entered url contain one of our site language
         $currentPath = $this->url('path', '_');
         // if custom template exist show this template
         if (is_file(root . 'content/template/static_' . $currentPath . '.html')) {
             $this->display_name = 'content\\template\\static_' . $currentPath . '.html';
         } elseif (is_file(root . 'content/template/404.html')) {
             header("HTTP/1.1 404 NOT FOUND");
             $this->display_name = 'content\\template\\404.html';
         } else {
             \lib\error::page(T_("Does not exist!"));
             return;
         }
     } elseif (is_file(root . 'content/template/' . $myurl['type'] . '-' . $myurl['slug'] . '.html')) {
         $this->display_name = 'content\\template\\' . $myurl['type'] . '-' . $myurl['slug'] . '.html';
     } elseif (is_file(root . 'content/template/' . $myurl['type'] . '.html')) {
         $this->display_name = 'content\\template\\' . $myurl['type'] . '.html';
     } elseif (is_file(root . 'content/template/' . $myurl['table'] . '.html')) {
         $this->display_name = 'content\\template\\' . $myurl['table'] . '.html';
     } elseif (is_file(root . 'content/template/dafault.html')) {
         $this->display_name = 'content\\template\\dafault.html';
     }
     $this->route_check_true = true;
     $this->get(null, $myurl['table'])->ALL();
     // $this->get()->ALL();
 }
Ejemplo n.º 14
0
 public function mvc_construct()
 {
     // define default value for url
     $this->url->full = $this->url('full');
     // full url except get parameter with http[s]
     $this->url->path = $this->url('path');
     // full path except parameter and domain name
     $this->url->breadcrumb = $this->url('breadcrumb');
     // full path in array for using in breadcrumb
     $this->url->domain = $this->url('domain');
     // domain name like 'ermile'
     $this->url->base = $this->url('base');
     $this->url->tld = $this->url('tld');
     // domain ltd like 'com'
     $this->url->raw = Service;
     // domain name except subdomain like 'ermile.com'
     $this->url->root = $this->url('root');
     $this->url->static = $this->url->root . 'static/';
     $this->url->protocol = Protocol;
     $this->url->account = $this->url('account');
     $this->url->MainStatic = $this->url('MainService') . '/' . 'static/';
     $this->url->MainSite = $this->url('MainSite');
     $this->url->MainProtocol = $this->url('MainProtocol');
     $this->url->SubDomain = SubDomain ? SubDomain . '.' : null;
     // return all parameters and clean it
     $this->url->param = \lib\utility::get(null, true);
     $this->url->all = $this->url->full . $this->url->param;
     $this->data->site['title'] = T_("Saloos");
     $this->data->site['desc'] = T_("Another Project with Saloos");
     $this->data->site['slogan'] = T_("Saloos is an artichokes for PHP programming!!");
     if (defined('LangList') && constant('LangList')) {
         $this->data->site['langlist'] = unserialize(constant('LangList'));
     } else {
         $this->data->site['langlist'] = ['fa_IR' => 'فارسی', 'en_US' => 'English'];
     }
     $current_lang_cookie = \lib\utility\Cookie::read('lang');
     $current_lang_get = \lib\utility::get('lang');
     if (SubDomain && SubDomain !== 'cp' && SubDomain !== 'account' && SubDomain !== 'files') {
         $this->data->site['currentlang'] = SubDomain;
     } elseif (isset($current_lang_get)) {
         $this->data->site['currentlang'] = substr($current_lang_get, 0, 2);
     } elseif (isset($current_lang_cookie)) {
         $this->data->site['currentlang'] = substr($current_lang_cookie, 0, 2);
     } else {
         $this->data->site['currentlang'] = substr(\lib\router::get_storage('defaultLanguage'), 0, 2);
     }
     $this->data->page['title'] = null;
     $this->data->page['desc'] = null;
     $this->data->page['special'] = null;
     $this->data->bodyclass = null;
     $this->data->module = $this->module();
     $this->data->child = $this->child();
     $this->data->login = $this->login('all');
     $this->data->perm = $this->access(null, 'all');
     $this->data->permContent = $this->access('all');
     // define default value for global
     $this->global->title = null;
     $this->global->login = $this->login();
     $this->global->lang = \lib\router::get_storage('language');
     $this->global->direction = \lib\router::get_storage('direction');
     $this->global->id = $this->url('path', '_');
     // define default value for include
     $this->include->newline = PHP_EOL;
     $this->include->css_main = false;
     $this->include->css_ermile = true;
     $this->include->js_main = true;
     $this->include->css = true;
     $this->include->js = true;
     $this->include->fontawesome = null;
     $this->include->datatable = null;
     $this->include->telinput = null;
     $this->include->lightbox = null;
     $this->include->editor = null;
     if (method_exists($this, '_construct')) {
         $this->_construct();
     }
     if (isset($this->url->MainStatic) && $this->url->MainStatic) {
         $this->url->myStatic = $this->url->MainStatic;
     } elseif (isset($this->url->MainStatic)) {
         $this->url->myStatic = $this->url->static;
     }
     if (method_exists($this, 'config')) {
         $this->config();
     }
     if (method_exists($this, 'options')) {
         $this->options();
     }
     $this->set_title();
     if (defined('SaveAsCookie') && SaveAsCookie) {
         $mygetlist = \lib\utility::get(null, 'raw');
         if ($mygetlist) {
             // var_dump(7); exit();
             foreach ($mygetlist as $name => $value) {
                 if ($name === 'ssid') {
                     $_SESSION['ssid'] = $value;
                 } elseif (!($name === 'dev' || $name === 'lang')) {
                     \lib\utility\Cookie::write($name, $value);
                 }
             }
             // remove get parameter from url
             header('Location: ' . $this->url('full'));
         }
     }
     // check main  ********************************************* CHECK FOR ONLY IN FIRST PAGE IN RIGHT PLACE
     // in all page like ajax request must be run
     if (AccountService === MainService) {
         $this->model()->checkMainAccount();
         $this->controller()->checkSession();
     }
     // if logvisitor on set visitors
     if (defined('LogVisitors') && constant('LogVisitors')) {
         $this->model()->addVisitor();
     }
 }
Ejemplo n.º 15
0
 public static function detect_language()
 {
     /**
      * set default language to storage for next use
      */
     // var_dump(\lib\utility\option::get('config', 'meta', 'defaultLanguage'));
     $default_lang = \lib\utility\option::get('config', 'meta', 'defaultLang');
     if ($default_lang) {
         router::set_storage('defaultLanguage', $default_lang);
     } else {
         router::set_storage('defaultLanguage', 'en_US');
     }
     // if current tld is ir or referrer from site with ir tld,
     // change language to fa_IR
     if (\lib\router::get_storage('language')) {
         $myLang = router::get_storage('language');
         switch (Tld) {
             case 'ir':
                 $myLang = "fa_IR";
                 break;
             default:
                 break;
         }
         if (defined('MainService') && Tld !== 'dev') {
             // for example redirect ermile.ir to ermile.com/fa
             $myLang = substr($myLang, 0, 2);
             $myredirect = new \lib\redirector();
             $myredirect->set_domain()->set_url($myLang)->redirect();
         } else {
             // else show in that domain with fa langusage
             router::set_storage('language', $myLang);
         }
     }
     /**
      * Localized Language, defaults to English.
      *
      * Change this to localize Saloos. A corresponding MO file for the chosen
      * language must be installed to content/languages. For example, install
      * fa_IR.mo to content/languages and set LANGUAGE to 'fa_IR' to enable Persian
      * language support.
      */
     router::set_storage('language', router::get_storage('defaultLanguage'));
     if (router::get_repository_name() === 'content') {
         // $mysub = router::get_sub_domain();
         $mysub = router::get_url(0);
         $myList = \lib\utility\option::languages();
         // check langlist with subdomain and if is equal set current language
         foreach ($myList as $key => $value) {
             $myLang = substr($key, 0, 2);
             if ($mysub === $myLang) {
                 if (router::get_storage('defaultLanguage') === $key) {
                     // redirect to homepage
                     $myredirect = new \lib\redirector();
                     $myredirect->set_domain()->set_url()->redirect();
                 } else {
                     router::set_storage('language', $key);
                     // update base url
                     router::$base .= '/' . router::get_url(0);
                     router::remove_url($myLang);
                 }
             }
         }
     } else {
         // change with get all times except on content or root,
         // because in root user must change language with subdomain
         if (isset($_GET["lang"])) {
             router::set_storage('language', $_GET["lang"]);
         } elseif (isset($_COOKIE["lang"])) {
             router::set_storage('language', $_COOKIE["lang"]);
         }
         // save language preference for future page requests
         setcookie('lang', router::get_storage('language'), time() + 30 * 24 * 60 * 60, '/', '.' . Service);
     }
     // check direction of language and set for rtl languages
     switch (router::get_storage('language')) {
         case 'fa_IR':
         case 'ar_SU':
             router::set_storage('direction', 'rtl');
             break;
         default:
             router::set_storage('direction', 'ltr');
             break;
     }
     return router::get_storage('language');
 }
Ejemplo n.º 16
0
 /**
  * check route of account
  * @return [type] [description]
  */
 function _route()
 {
     // exit();
     // \lib\debug::true("check", 'hi');
     // var_dump();
     $mymodule = $this->module();
     $referer = \lib\router::urlParser('referer', 'domain');
     $from = \lib\utility\cookie::read('from');
     $from = $from ? $from : \lib\utility::get('from');
     $islogin = $this->login();
     // set referrer in cookie
     if ($referer !== Domain) {
         \lib\utility\cookie::write('referer', $referer, 60 * 15);
     }
     // check permission for changepass
     if ($mymodule === 'changepass' && $from !== 'verification' && !$islogin) {
         \lib\error::access(T_("you can't access to this page!"));
     }
     switch ($mymodule) {
         case 'home':
             $this->redirector()->set_url("login")->redirect();
             break;
         case 'verification':
         case 'verificationsms':
             if ($from && $from !== 'recovery' && $from !== 'signup' && $from !== 'verification') {
                 \lib\error::access(T_("you can't access to this page!"));
             }
             $this->model_name = '\\addons\\content_account\\' . $mymodule . '\\model';
             $this->display_name = 'content_account\\' . $mymodule . '\\display.html';
             $this->post($mymodule)->ALL($mymodule);
             $this->get()->ALL($mymodule);
             break;
         case 'signup':
             return;
             /**
             
             Fix it later, only access if posible
             */
         /**
         
         Fix it later, only access if posible
         */
         case 'login':
         case 'recovery':
             if ($islogin) {
                 \lib\debug::true(T_("you are logined to system!"));
                 $myreferer = \lib\router::urlParser('referer', 'host');
                 $myssid = isset($_SESSION['ssid']) ? '?ssid=' . $_SESSION['ssid'] : null;
                 if (\lib\router::get_storage('CMS')) {
                     $this->redirector()->set_domain()->set_sub_domain(\lib\router::get_storage('CMS'))->set_url()->redirect();
                 } else {
                     $this->redirector()->set_domain()->set_url()->redirect();
                 }
             }
         case 'changepass':
             $this->model_name = '\\addons\\content_account\\' . $mymodule . '\\model';
             $this->display_name = 'content_account\\' . $mymodule . '\\display.html';
             $this->post($mymodule)->ALL($mymodule);
             $this->get()->ALL($mymodule);
             break;
         case 'smsdelivery':
         case 'smscallback':
             $uid = 201500001;
             if (\lib\utility::get('uid') == $uid || \lib\utility\cookie::read('uid') == $uid) {
                 $this->model_name = '\\addons\\content_account\\sms\\model';
                 $this->display_name = 'content_account\\sms\\display.html';
                 $this->post($mymodule)->ALL($mymodule);
                 $this->get($mymodule)->ALL($mymodule);
             } else {
                 \lib\error::access("SMS");
             }
             break;
             // logout user from system then redirect to ermile
         // logout user from system then redirect to ermile
         case 'logout':
             $this->model_name = '\\lib\\mvc\\model';
             $this->model()->put_logout();
             $this->redirector()->set_domain()->set_url()->redirect();
             break;
         default:
             \lib\error::page();
             break;
     }
     // $this->route_check_true = true;
 }
Ejemplo n.º 17
0
 function _route()
 {
     if (!$this->login() && Tld !== 'dev') {
         $mydomain = AccountService ? AccountService . MainTld : null;
         \lib\debug::warn(T_("first of all, you must login to system!"));
         $this->redirector(null, false)->set_domain($mydomain)->set_url('login')->redirect();
         exit;
     }
     // // Restrict unwanted module
     // if(!$this->cpModlueList())
     // 	\lib\error::page(T_("Not found!"));
     $mymodule = $this->cpModule('table');
     $cpModule = $this->cpModule('raw');
     // var_dump($this->child());
     $this->display_name = 'content_cp/templates/raw.html';
     switch ($this->child()) {
         case 'dbtables':
             \lib\utility\dbTables::create();
             exit;
             break;
         case 'twigtrans':
             \lib\utility\twigTrans::extract(\lib\utility::get('path'));
             exit;
             break;
         case 'server':
             if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && !class_exists("COM")) {
                 ob_start();
                 echo "<!DOCTYPE html><meta charset='UTF-8'/><title>Extract text form twig files</title><body style='padding:0 1%;margin:0 1%;direction:ltr;overflow:hidden'>";
                 echo "<h1>" . T_("First you need to enable COM on windows") . "</h1>";
                 echo "<a target='_blank' href='http://www.php.net/manual/en/class.com.php'>" . T_("Read More") . "</a>";
                 break;
             }
             \lib\utility\Linfo::show();
             exit;
             $this->display_name = 'content_cp/templates/raw-all.html';
             break;
         case 'twitter':
             $a = \lib\utility\SocialNetwork::twitter('hello! test #api');
             var_dump($a);
             break;
         case 'sitemap':
             $site_url = \lib\router::get_storage('url_site');
             $sitemap = new \lib\utility\Sitemap($site_url, root . 'public_html/', 'sitemap');
             // echo "<pre>";
             // add posts
             foreach ($this->model()->sitemap('posts', 'post') as $row) {
                 $sitemap->addItem($row['post_url'], '0.8', 'daily', $row['post_publishdate']);
             }
             // add pages
             foreach ($this->model()->sitemap('posts', 'page') as $row) {
                 $sitemap->addItem($row['post_url'], '0.6', 'weekly', $row['post_publishdate']);
             }
             // add attachments
             foreach ($this->model()->sitemap('posts', 'attachment') as $row) {
                 $sitemap->addItem($row['post_url'], '0.2', 'weekly', $row['post_publishdate']);
             }
             // add books
             foreach ($this->model()->sitemap('posts', 'book') as $row) {
                 $sitemap->addItem($row['post_url'], '0.6', 'yearly', $row['post_publishdate']);
             }
             // add cats and tags
             foreach ($this->model()->sitemap('terms') as $row) {
                 $sitemap->addItem($row['term_url'], '0.4', 'weekly', $row['date_modified']);
             }
             $sitemap->createSitemapIndex();
             echo "<p class='alert alert-success'>Create sitemap Successfully!</p>";
             // echo "Create Successful";
             break;
         case 'git':
             echo shell_exec("/" . Domain . " git pull");
             // exec('git pull');
             break;
         case null:
             $mypath = $this->url('path', '_');
             if (is_file(addons . 'content_cp/templates/static_' . $mypath . '.html')) {
                 $this->display_name = 'content_cp/templates/static_' . $mypath . '.html';
             }
             // $this->display_name	= 'content_cp/templates/static_'.$mypath.'.html';
             break;
         default:
             $this->display_name = 'content_cp/templates/static_tools.html';
             return;
             break;
     }
     $this->get()->ALL();
     return;
 }
Ejemplo n.º 18
0
 /**
  * [s_template_finder description]
  * @return [type] [description]
  */
 function s_template_finder()
 {
     // if lang exist in module or subdomain remove it and continue
     $currentLang = \lib\define::get_language();
     $defaultLang = substr(\lib\define::get_language('default'), 0, 2);
     if ($currentLang === SubDomain && $currentLang !== $defaultLang) {
         \lib\router::set_sub_domain(null);
     }
     // elseif($currentLang === $this->module() && $currentLang !== $defaultLang)
     // 	\lib\router::remove_url($currentLang);
     // continue find best template for this condition
     $mymodule = $this->module();
     if ($mymodule == 'home') {
         // if home template exist show it
         if (is_file(root . 'content/template/home.html')) {
             $this->display_name = 'content\\template\\home.html';
         }
         $this->get()->ALL();
         return 0;
     } elseif ($mymodule == 'search') {
         if (is_file(root . 'content/template/search.html')) {
             $this->display_name = 'content\\template\\search.html';
         }
         $this->get()->ALL();
         return;
     } elseif ($mymodule == 'feed') {
         $site_title = $this->view()->data->site['title'];
         $site_desc = $this->view()->data->site['desc'];
         $site_protocol = $this->url('MainProtocol') . '://';
         $site_url = $this->url('MainSite');
         $rss = new \lib\utility\RSS($site_protocol, $site_url, $site_title, $site_desc);
         // add posts
         foreach ($this->model()->get_feeds() as $row) {
             $rss->addItem($row['link'], $row['title'], $row['desc'], $row['date']);
         }
         $rss->create();
         // \lib\utility\RSS::create();
         // exit();
         return;
     } else {
         // save name of current module as name of social
         $social_name = $mymodule;
         if ($this->option('socialy')) {
             // declare list of shortkey for socials
             $social_list = ['@' => 'twitter', '~' => 'github', '+' => 'googleplus', 'f' => 'facebook', 'fb' => 'facebook', 'in' => 'linkedin', 'tg' => 'telegram'];
             // if name of current module is exist then save complete name of it
             if (isset($social_list[$mymodule])) {
                 $social_name = $social_list[$mymodule];
             }
         }
         // declare address of social networks
         $social_list = ['twitter' => 'https://twitter.com/', 'github' => 'https://github.com/', 'googleplus' => 'https://plus.google.com/', 'facebook' => 'https://www.facebook.com/', 'linkedin' => 'https://linkedin.com/in/', 'telegram' => 'http://telegram.me/', 'aparat' => 'http://www.aparat.com/'];
         // if social name exist in social adresses then redirect to it
         if (isset($social_list[$social_name]) && $this->option($social_name)) {
             // create url of social network
             $social_url = $social_list[$social_name] . $this->option($social_name);
             // redirect to new address
             $this->redirector($social_url, false)->redirect();
             return;
         }
     }
     $myurl = null;
     if (!empty(db_name)) {
         $myurl = $this->model()->s_template_finder();
     }
     // set post type, get before underscope
     $post_type = null;
     if (isset($myurl['type'])) {
         $post_type = strtok($myurl['type'], '_');
     }
     $route_check_true = false;
     // if url does not exist show 404 error
     if (!$myurl || $myurl['table'] != 'terms' && \lib\router::get_storage("pagenation")) {
         // if user entered url contain one of our site language
         $current_path = $this->url('path', '_');
         // if custom template exist show this template
         if (is_file(root . 'content/template/static_' . $current_path . '.html')) {
             $this->display_name = 'content\\template\\static_' . $current_path . '.html';
             $route_check_true = true;
         } elseif (is_file(root . 'content/template/static/' . $current_path . '.html')) {
             $this->display_name = 'content\\template\\static\\' . $current_path . '.html';
             $route_check_true = true;
         } else {
             // create special url for handle special type of syntax
             // for example see below example
             // ermile.com/legal			 	-> content/template/legal/home.html
             // ermile.com/legal/privacy		-> content/template/legal/privacy.html
             $my_special_url = substr($current_path, strlen($mymodule) + 1);
             if (!$my_special_url) {
                 $my_special_url = 'home';
             }
             $my_special_url = $mymodule . '/' . $my_special_url;
             if (is_file(root . 'content/template/static/' . $my_special_url . '.html')) {
                 $this->display_name = 'content/template/static/' . $my_special_url . '.html';
                 $route_check_true = true;
             }
         }
         // // elseif 404 template exist show it
         // elseif( is_file(root.'content/template/404.html') )
         // {
         // 	header("HTTP/1.1 404 NOT FOUND");
         // 	$this->display_name	= 'content\template\404.html';
         // }
         // // else show saloos default error page
         // else
         // {
         // 	\lib\error::page(T_("Does not exist!"));
         // 	return;
         // }
     } elseif (is_file(root . 'content/template/' . $post_type . '-' . $myurl['slug'] . '.html')) {
         $this->display_name = 'content\\template\\' . $post_type . '-' . $myurl['slug'] . '.html';
         $route_check_true = true;
     } elseif (is_file(root . 'content/template/' . $post_type . '.html')) {
         $this->display_name = 'content\\template\\' . $post_type . '.html';
         $route_check_true = true;
     } elseif (is_file(root . 'content/template/' . $myurl['table'] . '.html')) {
         $this->display_name = 'content\\template\\' . $myurl['table'] . '.html';
         $route_check_true = true;
     } elseif (is_file(root . 'content/template/dafault.html')) {
         $this->display_name = 'content\\template\\dafault.html';
         $route_check_true = true;
     }
     if ($route_check_true) {
         $this->route_check_true = $route_check_true;
         $this->get(null, $myurl['table'])->ALL("/.*/");
     }
 }