public function post_verificationsms() { $mymobile = utility\cookie::read('mobile'); $tmp_result = $this->sql()->tableSmss()->whereSms_from($mymobile)->andSms_type('receive')->andSms_status('enable')->select(); if ($tmp_result->num() == 1) { $this->put_changeSmsStatus($mymobile); } else { debug::warn(T_('we are waiting for your message!')); } }
function _route() { if (!$this->login()) { $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; } // Check permission and if user can do this operation // allow to do it, else show related message in notify center $this->access('cp', null, null, 'block'); }
public static function send($_mobile, $_status = null, $_arg = null, $_service = MainService) { $_status = is_null($_status) ? \lib\router::get_url() : $_status; $mymessage = T_(ucfirst($_service)) . "\n"; switch ($_status) { case 'signup': $mymessage .= T_('your verification code is') . ' ' . $_arg; break; case 'recovery': $mymessage .= T_('your recovery code is') . ' ' . $_arg; break; case 'verification': $mymessage .= T_('you account is verified successfully'); break; case 'changepass': $mymessage .= T_('your password is changed successfully'); break; default: $mymessage .= T_('thanks for using our service') . "\n" . T_('made in iran'); break; } $mymessage .= "\n\n" . ucfirst($_service) . '.com'; if (substr($_mobile, 0, 2) == '98') { $iran = true; } else { $iran = null; } if ($iran) { $api = new \KavenegarApi(); $result = $api->send($_mobile, $mymessage, 0); // $result = $api->select(27657835); // $result = $api->cancel(27657835); // $result = $api->selectoutbox(1410570000); // $result = $api->account_info(); // var_dump($result);exit(); } else { \lib\debug::warn(T_('now we only support Iran!')); if (DEBUG) { \lib\debug::warn("Think sms is send to {$_mobile}!"); \lib\debug::true($mymessage); } } }
function _permission($_content = null, $_login = true) { // if user is not login then redirect if ($_login && !$this->login()) { \lib\debug::warn(T_("first of all, you must login to system!")); $mydomain = \lib\utility\option::get('config', 'meta', 'redirectURL'); if ($mydomain && $mydomain !== 'on') { $this->redirector($mydomain . '/login', false)->redirect(); } else { $this->redirector(null, false)->set_domain()->set_url('login')->redirect(); } } // if content is not set then if ($_content === null) { $_content = \lib\router::get_sub_domain(); } // Check permission and if user can do this operation // allow to do it, else show related message in notify center $this->access($_content, null, null, 'block'); }
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; }
/** * create a related query and run it * @param [type] $_type [description] * @return [type] [description] */ protected function qryPermission($_type) { $newPerm = utility::post('pName'); switch ($_type) { case 'add': if (!$newPerm) { debug::warn(T_("First you must enter name of permission")); return; } // check permission exist or not $qryExist = $this->qryCreator($_type); $qryExist = $qryExist->select()->num(); // if exist show related message if ($qryExist) { debug::warn(T_("This permission name exist!") . " " . T_("You can edit this permission")); return; } // get last id in permissions $qryMaxID = $this->qryCreator(); $qryMaxID = $qryMaxID->field('#max(option_key) as id')->select()->assoc('id'); // permission id start from 2 because id 1 used for superuser $qryMaxID += $qryMaxID == 0 ? 2 : 1; $qryAdd = $this->qryCreator(); $qryAdd = $qryAdd->set('option_cat', 'permissions')->set('option_key', $qryMaxID)->set('option_value', $newPerm)->set('option_status', 'enable')->insert(); $qryAdd = $qryAdd; break; case 'delete': $delParam = $this->childparam('delete'); // if user pass child param, get this param and update status of permission if ($delParam) { $qryDel = $this->qryCreator($_type, $delParam); $qryDel = $qryDel->set('option_status', 'disable')->update(); \lib\utility\session::deleteByPerm($editParam); } break; case 'edit': $editParam = $this->childparam('edit'); if ($editParam) { $permResult = \lib\utility\permission::permListFill(true); $permResult = json_encode($permResult, JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE); $qryEdit = $this->qryCreator($_type, $editParam); $qryEdit = $qryEdit->set('option_meta', $permResult)->update(); \lib\utility\session::deleteByPerm($editParam); $this->setPermissionSession(); } break; default: break; } $this->commit(function ($_type, $_permName) { switch ($_type) { case 'add': debug::true(T_("Insert Successfully")); $this->redirector()->set_url('permissions/' . $_permName); break; case 'delete': debug::true(T_("Delete Successfully")); break; case 'edit': debug::true(T_("Update Successfully")); break; default: break; } }, $_type, $newPerm); // if a query has error or any error occour in any part of codes, run roolback $this->rollback(function () { debug::title(T_("Transaction error") . ': '); }); }
public function create_query($_type = null, $_id = null) { $qry_module = $this->module(SubDomain); $qry_table = 'table' . ucfirst($qry_module); $qry = $this->sql()->{$qry_table}(); // in update type save record data and check if change set this else don't need to set if ($_type == 'update') { $mydatarow = $this->datarow($qry_module, $_id); $not_change = true; } // get all fields of table and filter fields name for show in datatable // access from columns variable // check if datatable exist then get this data $incomplete_fields = []; $fields = \lib\sql\getTable::get($qry_module); // var_dump(utility::post()); // var_dump($qry_module); foreach ($fields as $key => $value) { // if this field can exist in query string if ($value['query']) { $tmp_setfield = 'set' . ucfirst($key); $tmp_value = utility::post($value['value']); if ($value['value'] === 'pass') { $tmp_value = utility::post('pass', 'hash'); } $tmp_value = trim($tmp_value); // if user fill box and post data for this field add to query string if ($tmp_value || $tmp_value === '0') { // in update type check for change or not if ($_type == 'update') { // if change add to query string and set it if ($mydatarow[$key] != $tmp_value) { $qry = $qry->{$tmp_setfield}($tmp_value); $not_change = false; } } else { $qry = $qry->{$tmp_setfield}($tmp_value); } } elseif ($key == 'user_id') { $qry = $qry->{$tmp_setfield}($this->login('id')); } elseif (!$value['null']) { // $incomplete_fields[$key] = $value['value']; array_push($incomplete_fields, $value['value']); } } } // on cp depending on module add some variable to query if (SubDomain === 'cp') { switch ($this->module()) { case 'tags': if (count($incomplete_fields) === 3) { $qry_module = 'terms'; $incomplete_fields = null; $term_url = utility::post('slug'); $qry = $qry->setTerm_type('tag')->setTerm_url($term_url); } break; case 'categories': if (count($incomplete_fields) === 3) { $qry_module = 'terms'; $incomplete_fields = null; $term_url = utility::post('slug'); $qry = $qry->setTerm_type('cat')->setTerm_url($term_url); } break; case 'pages': $qry = $qry->setPost_type('page'); $qry_module = 'posts'; break; case 'users': if ($_type == 'insert') { // remove createdate from incomplete and fill it with current datetime if (($key = array_search('createdate', $incomplete_fields)) !== false) { unset($incomplete_fields[$key]); } $qry = $qry->set('user_createdate', date('Y-m-d H:i:s')); } else { $incomplete_fields = null; } // add meta to save position of users and new properties $meta = ['position' => utility::post('position')]; if ($meta) { $not_change = false; } $meta = json_encode($meta, JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE); $qry = $qry->set('user_meta', $meta); break; } } if ($incomplete_fields) { debug::error(T_("all require fields must fill"), json_encode($incomplete_fields)); // return false; } if ($_type == 'update' && $not_change) { debug::warn(T_("some fields must be change for update!")); return false; } // var_dump($qry);exit(); return $qry; }
/** * this function set custom operator for each custom module in cp * @param [type] $_id [description] * @return [type] [description] */ function cp_create_query($_id = null, $_data = null) { if (!$_id) { $_id = $this->childparam('edit'); } // set useful variables $cpModule = $this->cpModule(); $qry = $this->sql()->table('posts'); $datarow = null; $defaultCat = null; // if datarow is not sending from parameter give it form post if (!(is_array($_data) && $_data)) { $datarow = self::cp_getPosts($_id); $defaultCat = utility::post('cat'); } else { // if default cat isset then if (isset($_data['defaultCat'])) { $defaultCat = $_data['defaultCat']; unset($_data['defaultCat']); } $datarow = $_data; } // if don't set title return error if (!(isset($datarow['title']) && $datarow['title'])) { debug::warn(T_("Please enter title") . "!", 'title'); return false; } // set slug if is not set if (!$datarow['slug']) { $datarow['slug'] = utility\filter::slug($datarow['title']); } // fix post language $datarow['language'] = substr($datarow['language'], 0, 2); // start generate post url $url_slug = $datarow['slug']; $url_body = null; $url_prefix = null; switch ($cpModule['raw']) { case 'pages': case 'books': // calc and set url if ($datarow['parent']) { $url_body = $this->sql()->table('posts')->where('post_type', $cpModule['type'])->and('id', $datarow['parent'])->select()->assoc('post_url'); } else { $datarow['parent'] = '#NULL'; } if ($cpModule['raw'] === 'books') { $url_prefix = 'book/'; } break; // only on edit // only on edit case 'attachments': // remove unuse fields like slug, url, data, status, ... // commented row not deleted and check unset($datarow['language']); // unset($datarow['title']); unset($datarow['slug']); // unset($datarow['content']); unset($datarow['type']); // unset($datarow['url']); // unset($datarow['status']); unset($datarow['parent']); // unset($datarow['user_id']); unset($datarow['publishdate']); if (!$defaultCat) { $defaultCat = 'file'; } $url_body = $defaultCat; // // read post meta and rewrite it // $datarow['meta'] = $this->sql()->table('posts') // ->where('post_type', 'attachment')->and('id', $_id) // ->select()->assoc('post_meta'); // $datarow['meta'] = json_decode($datarow['meta'], true); // $datarow['meta']['slug'] = $datarow['slug']; // $datarow['meta'] = json_encode($datarow['meta']); break; case 'socialnetwork': $datarow['slug'] = 'social' . md5(time()); $url_slug = $datarow['slug']; $url_prefix = 'social/'; $datarow['status'] = 'draft'; break; // all other type of post // all other type of post default: unset($datarow['parent']); case 'polls': $url_body = $defaultCat; if (!$url_body) { // calc and set url $url_body = $this->sql()->table('terms')->where('id', 1)->select()->assoc('term_url'); } if ($cpModule['raw'] === 'polls') { $datarow['type'] = 'poll_sarshomar'; } break; } // generate posturl $datarow['url'] = self::sp_generateUrl($url_slug, $url_body, $url_prefix); // if in edit get this record data if ($_id) { $record = $this->sql()->table('posts')->where('id', $_id)->select()->assoc(); $record_meta = $this->sql()->table('options')->where('post_id', $_id)->order('id', 'asc')->select()->allassoc(); // fill options value like posts field foreach ($record_meta as $key => $value) { $record[$record_meta[$key]['option_key']] = $record_meta[$key]['option_value']; } } $changed = false; // set values if exist foreach ($datarow as $key => $value) { $key = $key === 'user_id' ? 'user_id' : 'post_' . $key; if ($_id) { // check with old data and if change then set it if ($record[$key] !== $value) { $qry = $qry->set($key, $value); $changed = true; } } elseif ($value) { $qry = $qry->set($key, $value); } } $post_new_id = $_id; if ($_id) { // on edit if ($changed) { $qry = $qry->where('id', $_id)->update(); } } else { // on add $qry = $qry->insert(); $post_new_id = $qry->LAST_INSERT_ID(); } if ($post_new_id === 0 || !$post_new_id) { return; } // if publish post share it on twitter and save in options // before share check db for share before // if on add or in edit and staus exist and status !== 400 // then if status == publish and changed from old position // $post_status = isset($record['post_status'])? $record['post_status']: null; // $post_type = isset($record['post_type'])? $record['post_type'] : null; // $post_type = ($post_type) ? $post_type : $cpModule['type']; // if($datarow['status'] === 'publish' && $datarow['status'] !== $post_status && $post_type === 'post') // { // $url_main = $this->url('MainProtocol'). '://'.$this->url('MainSite'); // if(!(isset($record['twitter']['status']) && $record['twitter']['status'] === 400 )) // { // $mytwitte = $datarow['title'] . ' '. $url_main.'/'.$datarow['url']; // $twitte_result = \lib\utility\socialNetwork::twitter($mytwitte); // if(isset($twitte_result) && isset($twitte_result['status'])) // { // $twitte_result = json_encode($twitte_result); // $qry_twitter = $this->sql()->table('options') // ->set('post_id', $post_new_id) // ->set('option_cat', 'post'. $post_new_id. '_SocialNetwork') // ->set('option_key', 'twitter') // ->set('option_value', $twitte_result); // // $qry_twitter = $qry_twitter->insertString(); // $qry_twitter = $qry_twitter->insert(); // } // } // $telegram = \lib\utility\socialNetwork::telegram($datarow['title'] . "\n". $url_main.'/'.$datarow['url']); // $facebook_content = html_entity_decode($datarow['content']); // $facebook_content = preg_replace("/<\/p>/", "\n", $facebook_content); // $facebook_content = preg_replace("/<[^>]+>/", "", $facebook_content); // $facebook_content = preg_replace("/^[\s\n\r\t]+/", "", $facebook_content); // $facebook_url = $url_main.'/'.$datarow['url']; // $result_fb = \lib\utility\socialNetwork::facebook($facebook_url, $facebook_content); // if(isset($result_fb)) // { // // $result_fb = json_encode($result_fb); // $qry_facebook = $this->sql()->table('options') // ->set('post_id', $post_new_id) // ->set('option_cat', 'post'. $post_new_id. '_SocialNetwork') // ->set('option_key', 'facebook') // ->set('option_value', $result_fb); // // $qry_facebook = $qry_facebook->insertString(); // $qry_facebook = $qry_facebook->insert(); // } // } // add tags to terms table $mycats = utility::post('categories'); // if(!$mycats) // $mycats = [1]; $mytags = utility::post('tags'); $mytags = explode(',', $mytags); foreach ($mytags as $key => $value) { $value = trim($value, " "); $value = trim($value, "'"); if ($value) { $mytags[$key] = $value; } else { unset($mytags[$key]); } } // --------------------------------------------------- check new tag and cats with old one on edit if ($_id) { $myterms_del = null; // get old tags and diff of it with new one by title of tags $old_tags = $this->sp_term_list('tag', false); $tags_diff = array_diff($old_tags, $mytags); if (count($tags_diff) > 0) { // get the list of tags id $tags_id = $this->cp_tag_id($tags_diff); $myterms_del = $tags_id; } // get old cats and diff of it with new one by id if ($cpModule['raw'] === 'attachments') { $old_cats = $this->sp_term_list('filecat', false); if (!is_array($mycats)) { $mycats = null; } } elseif ($cpModule['raw'] === 'books') { $old_cats = $this->sp_term_list('bookcat', false); if (!is_array($mycats)) { $mycats = null; } } else { $old_cats = $this->sp_term_list('cat', false); if (!is_array($mycats)) { $mycats = [1]; } } if (is_array($old_cats) && count($old_cats) && is_array($mycats) && count($mycats)) { $cats_diff = array_diff($old_cats, $mycats); } elseif (is_array($mycats) && count($mycats)) { $cats_diff = $mycats; } else { $cats_diff = $old_cats; } if (is_array($cats_diff) && count($cats_diff) > 0) { $cats_diff = implode(",", $cats_diff); if ($myterms_del) { $myterms_del .= ','; } $myterms_del .= $cats_diff; } // delete deleted tags and cats together in one query if ($myterms_del) { $qry_term_del = $this->sql()->table('termusages')->where('termusage_id', $post_new_id); if (count(explode(',', $myterms_del)) === 1) { $qry_term_del = $qry_term_del->and('term_id', '=', $myterms_del)->delete(); } else { $qry_term_del = $qry_term_del->and('term_id', 'in', "(" . $myterms_del . ")")->delete(); } } } // ------------------------------------------------- if user enter new tag $tags_id = array(); if (count($mytags) > 0) { $qry_tag = $this->sql()->table('terms'); // add each tag to sql syntax foreach ($mytags as $value) { if ($value) { $qry_tag = $qry_tag->set('term_type', 'tag')->set('term_title', $value)->set('term_slug', $value)->set('term_url', $value); } } $qry_tag->insert('IGNORE'); // get the list of tags id $tags_id = $this->cp_tag_id($mytags, false); if (!is_array($tags_id)) { $tags_id = array(); } } // add selected tag to term usages table // on pages dont need cats and only add tags if ($cpModule['raw'] === 'pages') { $myterms = $tags_id; } elseif (is_array($mycats) && count($mycats)) { $myterms = array_merge($tags_id, $mycats); } else { $myterms = $tags_id; } // ---------------------------------------------- set termusage table // if terms exist go to foreach if (isset($myterms) && count($myterms) > 0) { $qry_tagusages = $this->sql()->table('termusages'); foreach ($myterms as $value) { $qry_tagusages = $qry_tagusages->set('term_id', $value)->set('termusage_id', $post_new_id)->set('termusage_foreign', 'posts'); } $qry_tagusages->insert('IGNORE'); } // update post url // $post_url = utility::post('slug', 'filter'); // $this->sql()->table('posts')->set('post_url', $post_url) // ->where('id', $post_new_id)->update(); // ====================================================== // you can manage next event with one of these variables, // commit for successfull and rollback for failed // if query run without error means commit if ($cpModule['raw'] == 'socialnetwork') { $twitte_result = \lib\utility\socialNetwork::telegram($datarow['content']); } $this->commit(function ($_postId, $_edit = null) { $_module = $this->cpModule('raw'); // if we are on create poll add into options table if ($_module === 'polls') { self::sp_savePoll($_postId); } if ($_edit) { debug::true(T_("Update Successfully")); $this->redirector()->set_url($_module . '/edit=' . $_postId); } else { debug::true(T_("Insert Successfully")); $this->redirector()->set_url($_module . '/edit=' . $_postId); } }, $post_new_id, $_id); // if a query has error or any error occour in any part of codes, run roolback $this->rollback(function () { debug::title(T_("Transaction error") . ': '); }); }