コード例 #1
0
ファイル: logitems.php プロジェクト: Ermile/Saloos-Addons
 /**
  * update field from logitems table
  * get fields and value to update
  * @param array $_args fields data
  * @param string || int $_id record id
  * @return mysql result
  */
 public static function update($_args, $_id)
 {
     // ready fields and values to update syntax query [update table set field = 'value' , field = 'value' , .....]
     $query = [];
     foreach ($_args as $field => $value) {
         $query[] = "{$field} = '{$value}'";
     }
     $query = join($query, ",");
     // make update query
     $query = "\n\t\t\t\tUPDATE logitems\n\t\t\t\tSET {$query}\n\t\t\t\tWHERE logitems.id = {$_id};\n\t\t\t\t";
     return \lib\db::query($query);
 }
コード例 #2
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);
 }
コード例 #3
0
ファイル: terms.php プロジェクト: Ermile/Saloos-Addons
 /**
  * we can not delete a record from database
  * we just update field status to 'deleted' or set this record to black list
  * @param string || int $_id record id
  * @return mysql result
  */
 public static function block($_id)
 {
     // get id
     $query = "\n\t\t\t\tUPDATE FROM terms\n\t\t\t\tSET terms.term_status = 'block'\n\t\t\t\tWHERE terms.id = {$_id}\n\t\t\t\t";
     return \lib\db::query($query);
 }
コード例 #4
0
ファイル: model.php プロジェクト: Ermile/Saloos-Addons
 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];
 }
コード例 #5
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);
 }
コード例 #6
0
ファイル: options.php プロジェクト: Ermile/Saloos-Addons
 /**
  * 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);
 }
コード例 #7
0
ファイル: termusages.php プロジェクト: Ermile/Saloos-Addons
 /**
  * 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);
 }
コード例 #8
0
ファイル: comments.php プロジェクト: Ermile/Saloos-Addons
 public static function save($_content, $_args = null)
 {
     $values = ["post_id" => null, "comment_author" => null, "comment_email" => null, "comment_url" => null, "comment_meta" => null, "comment_status" => null, "comment_parent" => null, "user_id" => null, "visitor_id" => null];
     if (!$_args) {
         $_args = [];
     }
     // foreach args if isset use it
     foreach ($_args as $key => $value) {
         $value = "'" . $value . "'";
         // check in normal condition exist
         if (array_key_exists($key, $values)) {
             $values[$key] = $value;
         }
         // check for id
         $newKey = $key . '_id';
         if (array_key_exists($newKey, $values)) {
             $values[$newKey] = $value;
         }
         // check for table prefix
         $newKey = 'comment_' . $key;
         if (array_key_exists($newKey, $values)) {
             $values[$newKey] = $value;
         }
     }
     foreach ($values as $key => $value) {
         if (!$value) {
             unset($values[$key]);
         }
     }
     // set not null fields
     // set comment content
     $values['comment_content'] = "'" . htmlspecialchars($_content) . "'";
     // set comment status if not set
     if (!isset($values['comment_status'])) {
         $values['comment_status'] = "'unapproved'";
     }
     // set time of comment
     if (isset($values['comment_meta']) && is_array($values['comment_meta'])) {
         $values['comment_meta']['time'] = date('Y-m-d H:i:s');
     } else {
         $values['comment_meta'] = ['time' => date('Y-m-d H:i:s')];
     }
     $values['comment_meta'] = "'" . json_encode($values['comment_meta'], JSON_UNESCAPED_UNICODE) . "'";
     // generate query text
     $list_field = array_keys($values);
     $list_field = implode($list_field, ', ');
     $list_values = implode($values, ', ');
     // create query string
     $qry = "INSERT INTO comments ( {$list_field} ) VALUES ( {$list_values} )";
     var_dump($qry);
     // run query and insert into db
     $result = \lib\db::query($qry);
     // get insert id
     $commentId = \lib\db::insert_id();
     // return last insert id
     return $commentId;
 }
コード例 #9
0
ファイル: option.php プロジェクト: Ermile/Saloos
 /**
  * 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;
 }
コード例 #10
0
ファイル: words.php プロジェクト: Ermile/Saloos-Addons
 /**
  * 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);
 }
コード例 #11
0
ファイル: users.php プロジェクト: Ermile/Saloos-Addons
 /**
  * Sets the user data.
  *
  * @param      <type>  $_user_id  The user identifier
  * @param      <type>  $_field    The field
  * @param      <type>  $_value    The value
  *
  * @return     <type>  ( description_of_the_return_value )
  */
 public static function set_user_data($_user_id, $_field, $_value)
 {
     $query = "\n\t\t\tUPDATE\n\t\t\t\tusers\n\t\t\tSET\n\t\t\t\tusers.{$_field} = '{$_value}'\n\t\t\tWHERE\n\t\t\t\tusers.id = {$_user_id}\n\t\t";
     $result = \lib\db::query($query);
     return $result;
 }
コード例 #12
0
ファイル: posts.php プロジェクト: Ermile/Saloos-Addons
 /**
  * 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;
 }