Пример #1
0
 protected function _exception()
 {
     // run if get is set and no database exist
     if ($this->cpModule('raw') == 'install' && \lib\utility::get('time') == 'first_time' && !\lib\db::exist()) {
         require_once lib . "install.php";
         \lib\main::$controller->_processor(['force_stop' => true, 'force_json' => false]);
     }
 }
Пример #2
0
 /**
  * generate signup stats by custom period
  * @param  string $_period [description]
  * @return [type]          [description]
  */
 public static function signup($_period)
 {
     if (!$_period) {
         $_period = "%Y-%m";
     }
     $qry = "SELECT\n\t\t\t\tDATE_FORMAT(user_createdate, '{$_period}') as date,\n\t\t\t\tcount(id) as total\n\t\t\tFROM users\n\t\t\tWHERE user_createdate != 0\n\t\t\tGROUP BY date\n\t\t";
     $result = \lib\db::get($qry);
     return $result;
 }
Пример #3
0
 /**
  * [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;
 }
Пример #4
0
 /**
  * [find_url_from_shortURL description]
  * @param  [type] $_shortURL [description]
  * @return [type]            [description]
  */
 public static function checkShortURL($_shortURL = null)
 {
     // set this shorturl, real url:)
     if (!\lib\utility\option::get('config', 'meta', 'shortURL')) {
         return null;
     }
     if (!$_shortURL) {
         $_shortURL = \lib\router::get_url();
     }
     $table = null;
     $field = null;
     $urlPrefix = substr($_shortURL, 0, 3);
     switch ($urlPrefix) {
         case 'sp_':
             // if this is url of one post
             $table = 'post';
             $field = "*";
             break;
         case 'st_':
             // else if this is url of one term
             $table = 'term';
             $field = 'term_url as url';
             break;
     }
     // if prefix is not correct return false
     if (!$table) {
         return null;
     }
     // remove prefix from url
     $_shortURL = substr($_shortURL, 3);
     $id = \lib\utility\shortURL::decode($_shortURL);
     $table .= 's';
     $qry = "SELECT {$field} FROM {$table} WHERE id = {$id}";
     $result = \lib\db::get($qry, null, true);
     if (!is_array($result)) {
         return false;
     }
     if (!\lib\utility\option::get('config', 'meta', 'forceShortURL') && isset($result['post_url'])) {
         $post_url = $result['post_url'];
         // redirect to url of this post
         $myredirect = new \lib\redirector();
         $myredirect->set_url($post_url)->redirect();
     }
     // if not force simulate this url
     return $result;
 }
Пример #5
0
 /**
  * we can not delete a record from database
  * we just update field status to 'deleted' or 'disable' or set this record to black list
  * @param string || int $_id record id
  * @return mysql result
  */
 public static function delete($_id)
 {
     // get id
     $query = "\n\t\t\t\tUPDATE FROM options\n\t\t\t\tSET options.option_status = 'disable'\n\t\t\t\tWHERE options.id = {$_id}\n\t\t\t\t";
     return \lib\db::query($query);
 }
Пример #6
0
 /**
  * Gets the logitem id by logitem title
  *
  * @param      <type>  $_logitem_title  The logitem title
  *
  * @return     <type>  The identifier.
  */
 public static function get_id($_logitem_title)
 {
     $query = "\n\t\t\tSELECT\n\t\t\t\tid\n\t\t\tFROM\n\t\t\t\tlogitems\n\t\t\tWHERE\n\t\t\t\tlogitems.logitem_title = '{$_logitem_title}'\n\t\t\tLIMIT 1\n\t\t";
     $id = \lib\db::get($query, 'id', true);
     return $id;
 }
Пример #7
0
 /**
  * generate temp mobile
  *
  * @return     string  ( description_of_the_return_value )
  */
 public static function temp_mobile()
 {
     // get auto increment id from users table
     $query = "\n\t\t\tSELECT\n\t\t\t\tAUTO_INCREMENT AS 'NEXTID'\n\t\t\tFROM\n\t\t\t\tinformation_schema.tables\n\t\t\tWHERE\n\t\t\t\ttable_name = 'users' AND\n\t\t\t\ttable_schema = DATABASE()\n\t\t";
     $result = \lib\db::get($query, "NEXTID", true);
     $next_id = intval($result) + 1;
     $next_id = self::temp_password($next_id);
     return "temp_" . $next_id;
 }
Пример #8
0
 /**
  * save question into post table
  * @param  [type] $_title    [description]
  * @param  [type] $_answersList [description]
  * @return [type]               [description]
  */
 public static function insertOrder($_title, $_meta, $_user_id = null)
 {
     $slug = \lib\utility\filter::slug($_title);
     $pubDate = date('Y-m-d H:i:s');
     $url = 'order/' . date('Y-m-d') . $_user_id . '/' . $slug;
     $_meta = json_encode($_meta, JSON_UNESCAPED_UNICODE);
     // create query string
     $qry = "INSERT INTO posts\n\t\t(\n\t\t\t`post_language`,\n\t\t\t`post_title`,\n\t\t\t`post_slug`,\n\t\t\t`post_url`,\n\t\t\t`post_meta`,\n\t\t\t`post_type`,\n\t\t\t`post_status`,\n\t\t\t`post_publishdate`,\n\t\t\t`user_id`\n\t\t)\n\t\tVALUES\n\t\t(\n\t\t\t'fa',\n\t\t\t'{$_title}',\n\t\t\t'{$slug}',\n\t\t\t'{$url}',\n\t\t\t'{$_meta}',\n\t\t\t'order',\n\t\t\t'draft',\n\t\t\t'{$pubDate}',\n\t\t\t{$_user_id}\n\t\t)";
     // run query
     $result = \lib\db::query($qry);
     // return last insert id
     $newId = \lib\db::insert_id();
     // save answers into options table
     return $newId;
 }
Пример #9
0
 /**
  * we can not delete a record from database
  * we just update field status to 'deleted' or 'disable' or set this record to black list
  * @param string || int $_id record id
  * @return mysql result
  */
 public static function delete($_id)
 {
     // get id
     $query = "\n\t\t\t\tUPDATE FROM notifications\n\t\t\t\tSET notifications.notification_status = 'expire'\n\t\t\t\tWHERE notifications.id = {$_id}\n\t\t\t\t";
     return \lib\db::query($query);
 }
Пример #10
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;
 }
Пример #11
0
 /**
  * set new record in options
  * @param [array] $_args contain key and value of new record
  */
 public static function set($_args, $_ifExistUpdate = true)
 {
     $datarow = ['option_status' => 'enable'];
     // add option user if set
     if (isset($_args['user'])) {
         $op_user = $_args['user'];
         if ($op_user === true) {
             $op_user = \lib\utility\visitor::user_id(false);
             if (!$op_user) {
                 $op_user = '******';
             }
         }
         if ($op_user) {
             $datarow['user_id'] = $op_user;
         }
     }
     // add option post if set
     if (isset($_args['post'])) {
         $datarow['post_id'] = $_args['post'];
     }
     // add option cat if set
     if (isset($_args['cat'])) {
         $datarow['option_cat'] = $_args['cat'];
     } else {
         return false;
     }
     // add option key if set
     if (isset($_args['key'])) {
         // replace _USER_ with user_id if exist
         $replace = "";
         if (isset($datarow['user_id'])) {
             $replace = $datarow['user_id'];
         }
         $_args['key'] = str_replace('_USER_', $replace, $_args['key']);
         $datarow['option_key'] = $_args['key'];
     } else {
         return false;
     }
     // add option value if set
     if (isset($_args['value'])) {
         $datarow['option_value'] = $_args['value'];
     } else {
         $datarow['option_value'] = null;
     }
     // add option meta if set
     if (isset($_args['meta'])) {
         $datarow['option_meta'] = $_args['meta'];
         if (is_array($datarow['option_meta'])) {
             $datarow['option_meta'] = json_encode($datarow['option_meta'], JSON_UNESCAPED_UNICODE);
         }
     }
     // add option status if set
     if (isset($_args['status'])) {
         // only allow defined$_args['status'])e
         switch ($_args['status']) {
             case 'enable':
             case 'disable':
             case 'expire':
                 break;
             default:
                 $_args['status'] = 'enable';
                 break;
         }
         $datarow['option_status'] = $_args['status'];
     }
     // add date modified manually
     if (isset($_args['modify']) && $_args['modify'] === 'now') {
         $datarow['date_modified'] = 'now()';
     }
     // create query string
     $qry_fields = implode(', ', array_keys($datarow));
     foreach ($datarow as $key => $value) {
         switch ($key) {
             case 'user_id':
             case 'post_id':
             case 'date_modified':
                 $datarow[$key] = $value;
                 break;
             case 'option_meta':
                 if ($value === '++') {
                     $datarow[$key] = "coalesce({$key}, 0)" . '+1';
                 } else {
                     $datarow[$key] = "'" . $value . "'";
                 }
                 break;
             default:
                 $datarow[$key] = "'" . $value . "'";
                 break;
         }
     }
     $qry_values = implode(', ', $datarow);
     // connect to database
     if ($_ifExistUpdate) {
         // start creating query data
         $qry_data = null;
         foreach ($datarow as $key => $value) {
             $qry_data .= $key . '=' . $datarow[$key] . ', ';
         }
         // remove last ,
         $qry_data = substr($qry_data, 0, -2);
         if (isset($_args['id']) && is_numeric($_args['id'])) {
             $qry = "UPDATE options SET {$qry_data} WHERE `id` = " . $_args['id'];
             // var_dump($qry);
         } else {
             $qry = "UPDATE options\n\t\t\t\t\tSET {$qry_data}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`option_cat`   =" . $datarow['option_cat'] . " AND\n\t\t\t\t\t\t`option_key`   =" . $datarow['option_key'] . " AND\n\t\t\t\t\t\t`option_value` =" . $datarow['option_value'];
         }
         $result = \lib\db::query($qry);
         // if row is match then return true
         // this means row is same and data is duplicate or not
         // affecting row is not important in this condition
         if ($result && \lib\db::qry_info('Rows matched')) {
             return true;
         }
     }
     // create query string
     $qry = "INSERT INTO options ( {$qry_fields} ) VALUES ( {$qry_values} );";
     // execute query
     $result = \lib\db::query($qry);
     // give last insert id
     $last_id = @mysqli_insert_id(\lib\db::$link);
     // if have last insert it return it
     if ($last_id) {
         return $last_id;
     }
     // return default value
     return false;
 }
Пример #12
0
 /**
  * Gets the post similar.
  * default get the post id and return similar post
  * you can set the poll is null and send list of tags in array or string of tags has splitable by ','
  * and get post similar this tags
  *
  * @param      <type>  $_post_id  The post identifier
  * @param      array   $_options  The options
  *
  * @return     <type>  The post similar.
  */
 public static function get_post_similar($_post_id, $_limit = 5)
 {
     if (!is_numeric($_limit)) {
         $_limit = 5;
     }
     $query = "\n\t\t\tSELECT\n\t\t\t\tposts.id AS 'id',\n\t\t\t\tposts.post_title AS 'title',\n\t\t\t\tposts.post_url AS 'url'\n\t\t\tFROM\n\t\t\t\ttermusages\n\t\t\tINNER JOIN posts ON posts.id = termusages.termusage_id\n\t\t\tWHERE\n\t\t\t\ttermusages.termusage_foreign  = 'posts' AND\n\t\t\t\ttermusages.termusage_id      != {$_post_id} AND\n\t\t\t\ttermusages.term_id IN\n\t\t\t\t(\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tterm_id\n\t\t\t\t\tFROM\n\t\t\t\t\t\ttermusages\n\t\t\t\t\tWHERE\n\t\t\t\t\t\ttermusages.termusage_foreign = 'posts' AND\n\t\t\t\t\t\ttermusages.termusage_id      = {$_post_id}\n\t\t\t\t)\n\t\t\tGROUP BY title,url,id\n\t\t\tORDER BY id DESC\n\t\t\tLIMIT {$_limit}\n\t\t";
     $result = \lib\db::get($query);
     return $result;
 }
Пример #13
0
 /**
  * update status of words
  *
  * @param      <type>  $_words   The words
  * @param      <type>  $_status  The status
  */
 public static function set_status($_words, $_status)
 {
     if (!$_words) {
         return false;
     }
     $_words = self::to_array($_words);
     $where = [];
     foreach ($_words as $key => $value) {
         $where[] = ' words.word = \'' . $value . '\' ';
     }
     $where = join($where, "OR");
     $query = "UPDATE words SET words.status = '{$_status}' WHERE {$where}";
     return \lib\db::query($query);
 }
Пример #14
0
 /**
  * Gets the user language.
  *
  * @return     <type>  The language.
  */
 public static function get_language($_user_id = null)
 {
     if ($_user_id === null) {
         $user_id = self::$user_id;
     } else {
         $user_id = $_user_id;
     }
     $query = "\n\t\t\tSELECT\n\t\t\t\toption_value AS 'language'\n\t\t\tFROM\n\t\t\t\toptions\n\t\t\tWHERE\n\t\t\t\tpost_id IS NULL AND\n\t\t\t\tuser_id = {$user_id} AND\n\t\t\t\toption_cat = 'user_detail_{$user_id}' AND\n\t\t\t\toption_key = 'language'\n\t\t\tLIMIT 1\n\t\t";
     return \lib\db::get($query, 'language', true);
 }
Пример #15
0
 /**
  * save once telegram user details
  * @param  [type] $_telegram_id [description]
  * @param  [type] $_fromDetail  [description]
  * @return [type]               [description]
  */
 private static function catchTelegramUser($_telegram_id, $_fromDetail = null)
 {
     // if user_id is not set try to give user_id from database
     // search in db to find user_id
     $qry = "SELECT `user_id`\n\t\t\tFROM options\n\t\t\tWHERE\n\t\t\t\t`option_cat` LIKE 'telegram\\_%' AND\n\t\t\t\t`option_key` LIKE 'user\\_%' AND\n\t\t\t\t`option_value` = {$_telegram_id}\n\t\t";
     $my_user_id = \lib\db::get($qry, 'user_id', true);
     if (is_numeric($my_user_id)) {
         self::$user_id = $my_user_id;
     }
     // if user does not exist in db, signup it
     if (!self::$user_id) {
         // calc full_name of user
         $fullName = trim(self::response('from', 'first_name') . ' ' . self::response('from', 'last_name'));
         $mobile = 'tg_' . $_telegram_id;
         // generate password
         $password = \lib\utility\filter::temp_password();
         \lib\db\users::signup($mobile, $password, true, $fullName);
         self::$user_id = \lib\db\users::$user_id;
         // save telegram user detail like name and username into options
         $userDetail = ['cat' => 'telegram_' . self::$user_id, 'key' => 'user_' . self::response('from', 'username'), 'value' => $_telegram_id, 'meta' => $_fromDetail];
         if (isset(self::$user_id)) {
             $userDetail['user'] = self::$user_id;
             $userDetail['status'] = 'enable';
         } else {
             $userDetail['status'] = 'disable';
         }
         // save in options table
         \lib\utility\option::set($userDetail, true);
     }
     // save session id database only one time
     // if exist use old one else insert new one to database
     \lib\utility\session::save_once(self::$user_id, 'telegram_' . $_telegram_id);
     if (!array_key_exists('tg', $_SESSION) || !is_array($_SESSION['tg'])) {
         $_SESSION['tg'] = array();
     }
     if (self::$user_id) {
         return true;
     }
     return false;
 }
Пример #16
0
 /**
  * Gets all comments for  admin accept
  *
  * @param      integer  $_limit  The limit
  *
  * @return     <type>   All.
  */
 public static function admin_get($_limit = 50)
 {
     if (!is_numeric($_limit)) {
         $_limit = 50;
     }
     $pagenation_query = "SELECT\tid\tFROM comments WHERE\tcomments.comment_type = 'comment' AND comments.comment_status = 'unapproved'\n\t\t -- comments::admin_get() for pagenation ";
     list($limit_start, $_limit) = \lib\db::pagnation($pagenation_query, $_limit);
     $limit = " LIMIT {$limit_start}, {$_limit} ";
     $query = "\n\t\t\tSELECT\n\t\t\t\tcomments.*,\n\t\t\t\tposts.post_title AS 'title',\n\t\t\t\tposts.post_url  AS 'url',\n\t\t\t\tusers.user_status AS 'status',\n\t\t\t\tusers.user_email AS 'email'\n\t\t\tFROM\n\t\t\t\tcomments\n\t\t\tINNER JOIN posts ON posts.id = comments.post_id\n\t\t\tINNER JOIN users ON users.id = comments.user_id\n\t\t\tWHERE\n\t\t\t\tcomments.comment_type = 'comment' AND\n\t\t\t\tcomments.comment_status = 'unapproved'\n\t\t\tORDER BY id ASC\n\t\t\t{$limit}\n\t\t\t-- comments::admin_get()\n\t\t";
     return \lib\db::get($query);
 }
Пример #17
0
 /**
  * Sets the comment data.
  *
  * @param      <type>  $_comment_id  The comment identifier
  * @param      <type>  $_type        The type
  */
 public static function set_comment_data($_comment_id, $_type, $_update = false)
 {
     if ($_type != 'minus' && $_type != 'plus') {
         return false;
     }
     $set = [];
     $set[] = " comment_{$_type} = IF(comment_{$_type} IS NULL, 1, comment_{$_type} + 1) ";
     if ($_update) {
         $reverse = 'minus';
         if ($_type == 'minus') {
             $reverse = 'plus';
         }
         $set[] = " comment_{$reverse} = IF(comment_{$reverse} IS NULL, 0, comment_{$reverse} - 1) ";
     }
     $set = join($set, ', ');
     $query = "\n\t\t\tUPDATE\n\t\t\t\tcomments\n\t\t\tSET\n\t\t\t\t{$set}\n\t\t\tWHERE\n\t\t\t\tid = {$_comment_id}\n\t\t";
     return \lib\db::query($query);
 }
Пример #18
0
 /**
  * delete session file with given perm name
  * @param  [type]  $_permName [description]
  * @param  boolean $_exceptMe [description]
  * @return [type]             [description]
  */
 public static function deleteByPerm($_permName)
 {
     $permList = \lib\utility\option::permList(true);
     $deleteResult = [];
     // if permission exist
     if (isset($permList[$_permName])) {
         // find user with this permission
         $perm_id = $permList[$_permName];
         // connect to database
         \lib\db::connect(true);
         $qry = "SELECT `options`.option_value\n\t\t\t\tFROM users\n\t\t\t\tINNER JOIN `options` ON `options`.user_id = `users`.id\n\t\t\t\tWHERE `options`.option_cat = 'session' AND\n\t\t\t\t\tuser_permission = {$perm_id};";
         // run query and give result
         $result = @mysqli_query(\lib\db::$link, $qry);
         // fetch all records
         $result = \lib\db::fetch_all($result, 'option_value');
         if ($result) {
             $deleteResult = self::delete($result);
             // for each file in delete
             foreach ($deleteResult as $key => $value) {
                 // if file is deleted
                 if ($value === true) {
                     $qry = "DELETE FROM options WHERE option_cat = 'session' AND option_value = '{$key}';";
                     @mysqli_query(\lib\db::$link, $qry);
                 }
             }
             return $deleteResult;
         }
     }
     return null;
 }
Пример #19
0
 public function query_search($_parameter = array())
 {
     $search = array_key_exists('search', $_parameter) ? $_parameter['search'] : null;
     $image = array_key_exists('image', $_parameter) ? $_parameter['image'] : null;
     $video = array_key_exists('video', $_parameter) ? $_parameter['video'] : null;
     $audio = array_key_exists('audio', $_parameter) ? $_parameter['audio'] : null;
     $other = array_key_exists('other', $_parameter) ? $_parameter['other'] : null;
     $where = '';
     if ($search) {
         $where .= "(post_title LIKE '%{$search}%' OR post_content LIKE '%{$search}%')";
     }
     $_type = ['image', 'audio', 'video'];
     $type = array();
     if ($image) {
         array_push($type, 'image');
     }
     if ($video) {
         array_push($type, 'video');
     }
     if ($audio) {
         array_push($type, 'audio');
     }
     if ($other) {
         array_push($type, 'other');
     }
     if (count($type) > 0 && count($type) < 4) {
         $where .= empty($where) ? '' : " AND ";
         if ($other) {
             if (count($type) == 1) {
                 $_type = join("\"' ,'\"", $_type);
                 $where .= "json_extract(post_meta, '\$.type') NOT IN ('\"{$_type}\"')";
             } else {
                 $_type = join("\"' ,'\"", array_diff($_type, $type));
                 $type = count($type) > 1 ? "\"" . join("\"' ,'\"", $type) . "\"" : $type[0];
                 $where .= "(json_extract(post_meta, '\$.type') IN ('{$type}')";
                 $where .= " OR json_extract(post_meta, '\$.type') NOT IN ('\"{$_type}\"'))";
             }
         } else {
             $type = count($type) > 1 ? "\"" . join("\"' ,'\"", $type) . "\"" : $type[0];
             $where .= "json_extract(post_meta, '\$.type') in ('{$type}')";
         }
     }
     $where .= empty($where) ? '' : " AND ";
     $where .= "post_type = 'attachment'";
     $length = 5;
     $start = 0;
     if ($_parameter['pagnation']) {
         list($start, $length) = $this->controller->pagnation_make_limit($length);
     }
     $query = "SELECT SQL_CALC_FOUND_ROWS posts.*, FOUND_ROWS() FROM posts WHERE {$where} LIMIT {$start}, {$length}";
     $result = \lib\db::query($query);
     $query_rows = "SELECT FOUND_ROWS() as rows";
     $result_rows = \lib\db::query($query_rows);
     $rows = $result_rows->fetch_assoc()['rows'];
     if ($_parameter['pagnation']) {
         $this->controller->pagnation_make($rows);
         $pagnation = $this->controller->pagnation;
     } else {
         $pagnation['total_pages'] = intval(ceil($rows / $length));
         $pagnation['current'] = 1;
         $pagnation['next'] = $pagnation['current'] + 1 <= $pagnation['total_pages'] ? $pagnation['current'] + 1 : false;
         $pagnation['prev'] = $pagnation['current'] - 1 >= 1 ? $pagnation['current'] - 1 : false;
         $pagnation['count_link'] = 7;
         $pagnation['current_url'] = \lib\router::get_class() . '/attachments_data';
         $pagnation['length'] = $length;
     }
     $decode_result = \lib\utility\filter::meta_decode(\lib\db::fetch_all($result));
     return ['data' => $decode_result, 'pagnation' => $pagnation];
 }
Пример #20
0
 /**
  * remove record
  *
  * @param      <type>  $_args  The arguments
  */
 public static function remove($_args)
 {
     if (!is_array($_args)) {
         return false;
     }
     $default_args = ['term_id' => false, 'termusage_id' => false, 'termusage_foreign' => false];
     $_args = array_merge($default_args, $_args);
     if (!$_args['termusage_foreign'] || !$_args['termusage_id']) {
         return false;
     }
     $query = "\n\t\t\tDELETE FROM termusages\n\t\t\tWHERE\n\t\t\t\ttermusage_foreign = '{$_args['termusage_foreign']}' AND\n\t\t\t\ttermusage_id = {$_args['termusage_id']}\n\t\t";
     if ($_args['term_id']) {
         $query .= " AND term_id = {$_args['term_id']} ";
     }
     return \lib\db::query($query);
 }
Пример #21
0
 /**
  * Searches for the first match.
  *
  * @param      <type>  $_title  The title
  *
  * @return     <type>  ( description_of_the_return_value )
  */
 public static function search($_title, $_term_type = 'tag')
 {
     $query = "\n\t\t\tSELECT\n\t\t\t\tterms.id,\n\t\t\t\tterms.term_title,\n\t\t\t\tterms.term_count,\n\t\t\t\tterms.term_url\n\t\t\tFROM\n\t\t\t\tterms\n\t\t\tWHERE\n\t\t\t\tterms.term_type = '{$_term_type}' AND\n\t\t\t\tterms.term_title LIKE '%{$_title}%'\n\t\t\tLIMIT 0,20\n\t\t";
     return \lib\db::get($query);
 }
Пример #22
0
<html>
<head>
 <meta charset="UTF-8"/>
 <title>Install</title>
 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no"/>
 <link rel="shortcut icon"    href="/static/images/favicon-error.png"/>
 <style type="text/css">*{font-family:sans-serif;-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;}body{width:90%;height:94%;margin:0 auto;padding:3% 5%;background-color:rgba(61, 174, 255, 0.1);;color:#3DAEFF}a{color:#0091D6;}.slash{padding: 0 2px;}ol{direction:ltr;font-size: 14px;}li{padding-bottom:5px}.addr{font-size: 11px; font-weight: normal;}#no{z-index:-1;position:absolute;bottom:5%;right:5%;opacity:0.9;width: 250px}#smile{font-size:7em}img{max-width: 100%;}.btn{position:relative;width:300px;margin:100px auto 0;font-size:1em}.btn a{text-decoration:none;background-color:#0091D6;color:#fff;font-size:1.5em;text-align:center;padding:5px 10%;border-radius:10px;position:relative;display:block;width:100%;z-index:1}.btn span{background-color:#222;color:#fff;font-size:.8em;text-align:center;padding:5px 10%;position:absolute;width:90%;right:0;left:0;margin:0 auto;max-width:100%;overflow:hidden;transition:.5s}.btn .top{top:0;border-top-right-radius:10px;border-top-left-radius:10px}.btn:hover .top{top:-60%}.btn .bottom{bottom:0;border-bottom-right-radius:10px;border-bottom-left-radius:10px}.btn:hover .bottom{bottom:-60%}.btn span:hover{overflow:visible}pre{overflow:auto;background-color:#eee;font-size:0.7em;padding:1%;}
 </style>
</head>
<body>
 <h1>Saloos Installation</h1>
 <p>Welcome to saloos installation process.</p>
 <p>First of all set database connection detail on <b>config.php</b> then we do others!</p>
<?php 
if (isset($_GET['install']) && $_GET['install'] === 'go' && isset($_GET['time']) && $_GET['time'] === 'first_time') {
    $result = \lib\db::install();
    if ($result) {
        ?>
 <div class="btn">
  <span class="top">Install Successfully:)</span>
  <a href="/">Lets GO!</a>
 </div>
 <pre class="result">
<?php 
        $sqlFiles = \lib\utility\dbTables::create();
        if (DEBUG) {
            print_r($result);
            echo $sqlFiles;
        }
        ?>
 </pre>
Пример #23
0
 public function query($string)
 {
     // if(self::$db_lang = 'fa_IR')
     // {
     // 	$patterns = array(
     // 		'/ة/',
     // 		'/إ/',
     // 		'/أ/',
     // 		'/ي/',
     // 		'/ئ/',
     // 		'/ؤ/',
     // 		'/ك/'
     // 	);
     // 	$replacements = array(
     // 		'ه',
     // 		'ا',
     // 		'ا',
     // 		'ی',
     // 		'ی',
     // 		'و',
     // 		'ک'
     // 	);
     // 	$string = preg_replace($patterns, $replacements, $string);
     // }
     // $patterns = array(
     // 	'/۰/',
     // 	'/۱/',
     // 	'/۲/',
     // 	'/۳/',
     // 	'/۴/',
     // 	'/۵/',
     // 	'/۶/',
     // 	'/۷/',
     // 	'/۸/',
     // 	'/۹/'
     // );
     // $replacements = array(
     // 	'0',
     // 	'1',
     // 	'2',
     // 	'3',
     // 	'4',
     // 	'5',
     // 	'6',
     // 	'7',
     // 	'8',
     // 	'9'
     // );
     // $string = preg_replace($patterns, $replacements, $string);
     if (DEBUG) {
         \lib\db::log($string);
     }
     if (debug::$status) {
         $this->string = $string;
         $this->result = self::$connection->query($string);
         if (self::$connection->error) {
             $this->status = false;
             $this->error(self::$connection->error, self::$connection->errno);
         }
     }
     return $this;
 }
Пример #24
0
 /**
  * return top pages visited on this site
  * @return [type] [description]
  */
 public static function top_pages($_count = 10)
 {
     self::createLink();
     $service_id = self::service();
     $qry = "SELECT\n\t\t\t\turls.url_url as url,\n\t\t\t\tcount(visitors.id) as total\n\t\t\tFROM urls\n\t\t\tINNER JOIN visitors ON urls.id = visitors.url_id\n\t\t\tWHERE visitors.`service_id` = {$service_id}\n\n\t\t\tGROUP BY visitors.url_id\n\t\t\tORDER BY total DESC\n\t\t\tLIMIT 0, {$_count}";
     $result = @mysqli_query(self::$link, $qry);
     if (!$result) {
         return false;
     }
     $result = \lib\db::fetch_all($result);
     foreach ($result as $key => $row) {
         $result[$key]['url'] = urldecode($row['url']);
         if (strpos($result[$key]['url'], 'http://') !== false) {
             $result[$key]['text'] = substr($result[$key]['url'], 7);
         }
     }
     return $result;
 }