/** * [get_posts description] * @param boolean $_forcheck [description] * @return [type] [description] */ public function get_posts($_forcheck = false, $_args = null) { // check shortURL $shortURL = \lib\db\url::checkShortURL(); if ($shortURL & is_array($shortURL)) { // set datarow $datarow = $shortURL; } else { $url = $this->url('path'); if (substr($url, 0, 7) == 'static/') { return false; } $language = \lib\define::get_language(); $preview = \lib\utility::get('preview'); // search in url field if exist return row data $post_status = ""; if (!$preview) { $post_status = " AND post_status = 'publish' "; } $qry = "\n\t\t\t\tSELECT\n\t\t\t\t\t*\n\t\t\t\tFROM\n\t\t\t\t\tposts\n\t\t\t\tWHERE\n\t\t\t\t\tpost_url = '{$url}'\n\t\t\t\t\t{$post_status}\n\t\t\t\tLIMIT 1\n\t\t\t"; $datarow = \lib\db::get($qry, null, true); // we have more than one record if (isset($datarow[0])) { $datarow = false; } } if (isset($datarow['id'])) { $post_id = $datarow['id']; } else { $datarow = false; $post_id = 0; } if ($datarow && $post_id) { if ($_forcheck && isset($datarow['post_type']) && isset($datarow['post_slug'])) { return ['table' => 'posts', 'type' => $datarow['post_type'], 'slug' => $datarow['post_slug']]; } else { foreach ($datarow as $key => $value) { // if field contain json, decode it if (substr($value, 0, 1) == '{') { $datarow[$key] = json_decode($value, true); if (is_null($datarow[$key]) && preg_match("/meta\$/", $key)) { $datarow[$key] = json_decode(html_entity_decode($value), true); } } } // get meta of this post $meta = \lib\db\posts::get_post_meta($post_id); $datarow['postmeta'] = $meta; return $datarow; } } return false; }
/** * [get_feeds description] * @param boolean $_forcheck [description] * @return [type] [description] */ public function get_feeds($_forcheck = false) { $start = \lib\utility::get('start'); $lenght = \lib\utility::get('lenght'); // search in url field if exist return row data $qry = $this->sql()->table('posts')->field('#post_language as `lang`', '#post_title as `title`', '#post_content as `desc`', '#post_url as `link`', '#post_publishdate as `date`')->where('post_type', 'post')->and('post_status', 'publish')->limit(0, 10); $qry = $qry->groupOpen('g_language'); $qry = $qry->and('post_language', \lib\define::get_language()); $qry = $qry->or('post_language', 'IS', 'NULL'); $qry = $qry->groupClose('g_language'); $qry = $qry->select(); return $qry->allassoc(); }
/** * save data on hooking * @param [type] $_data [description] * @return [type] [description] */ private static function saveHook($_data) { // define user detail array $from_id = self::response('from'); $from_key = ['message', 'callback_query', 'chosen_inline_result', 'inline_query']; $from = false; foreach ($from_key as $key => $value) { if (array_key_exists($value, $_data)) { $from = $_data[$value]['from']; break; } } // add user_id to save dest of files self::$saveDest .= $from_id . '-' . self::response('from', 'username') . '/'; // if we do not have from id return false if (!$from || !$from_id) { return false; } // catch user telegram from database and if not exist insert as new user self::catchTelegramUser($from_id, $from); // save user detail like contact or location if sended if ($contact = self::response('contact', null)) { self::saveUserDetail('contact', $contact); } elseif ($location = self::response('location')) { self::saveUserDetail('location', $location); } // change language if needede if (\lib\define::get_language('iso') !== self::$language) { \lib\define::set_language(self::$language); } return true; }
/** * 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[0]); } else { $qry = $qry->groupOpen('g_language'); $qry = $qry->and('post_language', \lib\define::get_language()); $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"')->field(false); // $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')->field(false)->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") } // var_dump($qry); $qry = $qry->select('DISTINCT'); // echo $qry->string(); $result = $qry->allassoc(); // decode and change name of all record to better name foreach ($result as $id => $row) { foreach ($row as $key => $value) { $pos = strpos($key, 'post_'); if ($pos !== false) { $fieldName = substr($key, 5); if ($fieldName === 'content') { $value = html_entity_decode($value, ENT_QUOTES | ENT_HTML5, "UTF-8"); } $result[$id][$fieldName] = $value; unset($result[$id][$key]); } } } return $result; }
/** * [mvc_construct description] * @return [type] [description] */ public function mvc_construct() { array_push($this->twig_include_path, addons); // define default value for url $this->url->fakesub = $this->url('fakesub'); // the $_SERVER[REQUEST_URI] $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!!"); $this->data->site['langlist'] = \lib\utility\option::languages(); $this->data->site['currentlang'] = \lib\define::get_language(); $this->data->site['defaultLang'] = \lib\define::get_language('default'); // if allow to use social then get social network account list if (\lib\utility\option::get('social', 'status')) { $this->data->social = \lib\utility\option::get('social', 'meta'); } $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 = $this->data->site['currentlang']; $this->global->direction = \lib\define::get_language('direction'); $this->global->id = $this->url('path', '_'); // add special pages to display array to use without name $this->data->display['main'] = "content/main/layout.html"; $this->data->display['home'] = "content/home/display.html"; $this->data->display['account'] = "content_account/home/layout.html"; $this->data->display['cp'] = "content_cp/home/layout.html"; $this->data->display['pagination'] = "content_cp/templates/inc_pagination.html"; // add special pages to template array to use without name $this->data->template['header'] = 'content/template/header.html'; $this->data->template['sidebar'] = 'content/template/sidebar.html'; $this->data->template['footer'] = 'content/template/footer.html'; // 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 (isset($this->controller->pagnation)) { $this->data->pagnation = $this->controller->pagnation_get(); } 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, 'options')) { $this->options(); } if (\lib\utility\option::get('config', 'meta', 'saveAsCookie')) { $mygetlist = \lib\utility::get(null, 'raw'); if ($mygetlist) { 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(); } }
/** * [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("/.*/"); } }