Example #1
1
 /**
  * start conversation
  * @return [type] [description]
  */
 public static function start()
 {
     $result = [['text' => "به *_fullName_* خوش آمدید." . " /help", 'reply_markup' => menu::main(true)]];
     // on debug mode send made by ermile at the end of start msg
     if (\lib\utility\option::get('telegram', 'meta', 'debug')) {
         $result[] = ['text' => "Made by @Ermile"];
     }
     return $result;
 }
Example #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_meta', '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"));
                 \lib\utility\session::save();
                 $referer = \lib\router::urlParser('referer', 'host');
                 // set redirect to homepage
                 $this->redirector()->set_domain()->set_url();
                 if (\lib\utility\option::get('account', 'status')) {
                     $_redirect_sub = \lib\utility\option::get('account', 'meta', 'redirect');
                     if ($_redirect_sub !== 'home') {
                         if (\lib\utility\option::get('config', 'meta', 'fakeSub')) {
                             $this->redirector()->set_url($_redirect_sub);
                         } else {
                             $this->redirector()->set_sub_domain($_redirect_sub);
                         }
                     }
                 }
                 // do not use pushstate and run link direct
                 debug::msg('direct', true);
             });
             $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);
 }
Example #3
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;
 }
Example #4
0
 /**
  * return list of exist permission in system
  * @return [array] contain list of permissions
  */
 public function permList($_status = false)
 {
     $permList = [];
     if ($_status === false) {
         $permList = \lib\utility\option::get('permissions', 'meta');
         return $permList;
     }
     // get list of permissions
     $qryPerm = $this->sql()->table('options')->where('user_id', 'IS', 'NULL')->and('post_id', 'IS', "NULL")->and('option_cat', 'permissions')->and('option_status', "enable");
     if ($_status) {
         $qryPerm->groupOpen('g_status')->and('option_status', '=', "'enable'")->or('option_status', 'IS', "NULL")->or('option_status', "")->groupClose('g_status');
     }
     $qryPerm = $qryPerm->select()->allassoc();
     foreach ($qryPerm as $row) {
         $permList[$row['option_key']] = $row['option_value'];
     }
     return $permList;
 }
Example #5
0
 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');
 }
Example #6
0
 /**
  * default action to handle message texts
  * @param  [type] [description]
  * @return [type]       [description]
  */
 public static function answer($forceSample = null)
 {
     $answer = null;
     // read from saloos command template
     $cmdFolder = __NAMESPACE__ . '\\commands\\';
     // use user defined command
     if (!$forceSample && self::$cmdFolder) {
         $cmdFolder = self::$cmdFolder;
     }
     foreach (self::$priority as $class) {
         $funcName = $cmdFolder . $class . '::exec';
         // generate func name
         if (is_callable($funcName)) {
             // get response
             $answer = call_user_func($funcName, self::$cmd);
             // if has response break loop
             if ($answer || is_array($answer)) {
                 break;
             }
         }
     }
     // if we dont have answer text then use default text
     if (!$answer) {
         if (self::response('chat', 'type') === 'group') {
             // if saloos bot joied to group show thanks message
             if (self::response('new_chat_member', 'username') === self::$name) {
                 $msg = "Thanks for using me!\r\n\nI'm Bot.";
                 $msg = "با تشکر از شما عزیزان به خاطر دعوت از من!\r\n\nمن یک ربات هستم.";
                 $answer = ['text' => $msg];
             }
         } elseif (\lib\utility\option::get('telegram', 'meta', 'debug') && !is_array($answer)) {
             // then if not exist set default text
             $answer = ['text' => self::$defaultText];
             if (self::$defaultMenu && is_object(self::$defaultMenu)) {
                 $answer['reply_markup'] = call_user_func(self::$defaultMenu);
             }
         }
     }
     return $answer;
 }
Example #7
0
 /**
  * call model func and return needed option in all condition
  * @return [type] return string or array contain option value
  */
 public function option()
 {
     return \lib\utility\option::get(...func_get_args());
 }
Example #8
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;
 }
Example #9
0
 /**
  * check current protocol and if needed redirect to another!
  * @return [type] [description]
  */
 private static function check_protocol()
 {
     // create new url for protocol checker
     $newUrl = "";
     $currentPath = $_SERVER['REQUEST_URI'];
     $mainSite = \lib\utility\option::get('config', 'meta', 'redirectURL');
     // if redirect to main site is enable and all thing is okay
     // then redirect to the target url
     if (\lib\utility\option::get('config', 'meta', 'multiDomain') && \lib\utility\option::get('config', 'meta', 'redirectToMain') && $mainSite && Tld !== 'dev' && parse_url($mainSite, PHP_URL_HOST) != \lib\router::get_root_domain()) {
         // as soon as posible we create language detector library
         switch (Tld) {
             case 'ir':
                 $newUrl = $mainSite . "/fa";
                 break;
             default:
                 break;
         }
     } elseif ($currentPath !== '/' && rtrim($currentPath, '/') !== $currentPath) {
         $newUrl = $mainSite . rtrim($currentPath, '/');
     } else {
         // if want to force using https then redirect to https of current url
         if (\lib\utility\option::get('config', 'meta', 'https')) {
             if (Protocol === 'http') {
                 $newUrl = 'https://';
             }
         } elseif (Protocol === 'https') {
             $newUrl = 'http://';
         }
         if ($newUrl) {
             $newUrl .= router::get_root_domain() . '/' . router::get_url();
         }
     }
     // var_dump($newUrl);exit();
     // if newUrl is exist and we must to redirect
     // then complete url and redirect to this address
     if ($newUrl && !\lib\utility::get('force')) {
         // redirect to best protocol because we want it!
         $redirector = new \lib\redirector($newUrl);
         $redirector->redirect();
     }
 }
Example #10
0
 public function __construct()
 {
     // check php version to upper than 5.6
     if (version_compare(phpversion(), '5.6', '<')) {
         die("<p>For using Saloos you must update php version to 5.6 or higher!</p>");
     }
     /**
      * If DEBUG is TRUE you can see the full error description, If set to FALSE show userfriendly messages
      * change it from project config.php
      */
     if (!defined('DEBUG')) {
         if (\lib\utility\option::get('config', 'meta', 'debug')) {
             define('DEBUG', true);
         } elseif (Tld === 'dev') {
             define('DEBUG', true);
         } else {
             define('DEBUG', false);
         }
     }
     if (DEBUG) {
         ini_set('display_errors', 'On');
         ini_set('display_startup_errors', 'On');
         ini_set('error_reporting', 'E_ALL | E_STRICT');
         ini_set('track_errors', 'On');
         ini_set('display_errors', 1);
         error_reporting(E_ALL);
         //Setting for the PHP Error Handler
         // set_error_handler('\lib\error::myErrorHandler');
         //Setting for the PHP Exceptions Error Handler
         // set_exception_handler('\lib\error::myErrorHandler');
         //Setting for the PHP Fatal Error
         // register_shutdown_function('\lib\error::myErrorHandler');
     } else {
         error_reporting(0);
         ini_set('display_errors', 0);
     }
     /**
      * A session is a way to store information (in variables) to be used across multiple pages.
      * Unlike a cookie, the information is not stored on the users computer.
      * access to session with this code: $_SESSION["test"]
      */
     if (is_string(Domain)) {
         session_name(Domain);
     }
     // set session cookie params
     session_set_cookie_params(0, '/', '.' . Service, false, true);
     // if user enable saving sessions in db
     // temporary disable because not work properly
     if (false) {
         $handler = new \lib\utility\sessionHandler();
         session_set_save_handler($handler, true);
     }
     // start sessions
     session_start();
     /**
      * in coming soon period show public_html/pages/coming/ folder
      * developer must set get parameter like site.com/dev=anyvalue
      * for disable this attribute turn off it from config.php in project root
      */
     if (\lib\utility\option::get('config', 'meta', 'coming') || defined('CommingSoon')) {
         // if user set dev in get, show the site
         if (isset($_GET['dev'])) {
             setcookie('preview', 'yes', time() + 30 * 24 * 60 * 60, '/', '.' . Service);
         } elseif (router::get_url(0) === 'saloos_tg') {
             // allow telegram to commiunate on coming soon
         } elseif (!isset($_COOKIE["preview"])) {
             header('Location: http://' . AccountService . MainTld . '/static/page/coming/', true, 302);
             exit;
         }
     }
     // use saloos php gettext function
     require_once lib . 'utility/gettext/gettext.inc';
     // change header and remove php from it
     header("X-Powered-By: Saloos!");
 }
Example #11
0
 /**
  * [permListFill description]
  * @param  boolean $_fill [description]
  * @return [type]         [description]
  */
 public static function permListFill($_fill = false)
 {
     $permResult = [];
     $permCond = ['view', 'add', 'edit', 'delete', 'admin'];
     foreach (\lib\utility\option::contentList() as $myContent) {
         // for superusers allow access
         if ($_fill === "su") {
             $permResult[$myContent]['enable'] = true;
         } elseif ($_fill) {
             // step1: get and fill content enable status
             $postValue = \lib\utility::post('content-' . $myContent);
             if ($postValue === 'on') {
                 $permResult[$myContent]['enable'] = true;
             } else {
                 $permResult[$myContent]['enable'] = false;
             }
         } else {
             $permResult[$myContent]['enable'] = null;
         }
         // step2: fill content modules status
         foreach (self::moduleList($myContent) as $myLoc => $value) {
             foreach ($permCond as $cond) {
                 // for superusers allow access
                 if ($_fill === "su") {
                     $permResult[$myContent]['modules'][$myLoc][$cond] = true;
                 } elseif ($_fill) {
                     $locName = $myContent . '-' . $myLoc . '-' . $cond;
                     $postValue = \lib\utility::post($locName);
                     if ($postValue === 'on') {
                         $permResult[$myContent]['modules'][$myLoc][$cond] = true;
                     }
                     // else
                     // {
                     // $permResult[$myContent]['modules'][$myLoc][$cond] = null;
                     // }
                 } else {
                     $permResult[$myContent]['modules'][$myLoc][$cond] = null;
                 }
             }
         }
     }
     return $permResult;
 }
Example #12
0
 public function sp_savePoll($_post_new_id, $_onlyAns = false)
 {
     $answers = [];
     $max_ans = 10;
     for ($i = 1; $i <= $max_ans; $i++) {
         if (utility::post('ans' . $i)) {
             $answers[$i]['id'] = $i;
             $answers[$i]['point'] = utility::post('ans' . $i . '_point');
             $answers[$i]['txt'] = utility::post('ans' . $i);
         }
     }
     if ($_onlyAns === true) {
         return $answers;
     }
     $answers = json_encode($answers, JSON_UNESCAPED_UNICODE);
     $option_data = ['post' => $_post_new_id, 'cat' => 'meta_polls', 'key' => 'answers_' . $_post_new_id, 'value' => "", 'meta' => $answers, 'status' => 'enable'];
     // save in options table and if successful return session_id
     return \lib\utility\option::set($option_data, true);
 }
Example #13
0
 /**
  * read permission data and fill in array
  * @param  [type] $_list [description]
  * @return [type]        [description]
  */
 public function permModuleFill()
 {
     $permResult = [];
     // 1. get the name of permission
     $myChild = $this->child();
     if ($myChild === 'edit') {
         $myChild = $this->childparam('edit');
     }
     // 2. get perm data from table
     $qry = $this->sql()->table('options')->where('user_id', 'IS', 'NULL')->and('post_id', 'IS', "NULL")->and('option_cat', 'permissions')->and('option_value', $myChild)->and('option_status', "enable");
     $datarow = $qry->select()->assoc('option_meta');
     if (substr($datarow, 0, 1) == '{') {
         $datarow = json_decode($datarow, true);
     }
     // 3. fill the result
     foreach (\lib\utility\option::contentList() as $myContent) {
         // 3.1 fill null
         $permResult[$myContent] = ['enable' => null, 'modules' => null, 'roles' => null];
         // 3.2 set enable status
         if (isset($datarow[$myContent]['enable']) && $datarow[$myContent]['enable']) {
             $permResult[$myContent]['enable'] = true;
         }
         // 3.3 get modules list of specefic content and fill it with db values
         foreach (\lib\utility\permission::moduleList($myContent) as $myLoc => $value) {
             if (isset($datarow[$myContent]['modules'][$myLoc]) && is_array($datarow[$myContent]['modules'][$myLoc])) {
                 $permResult[$myContent]['modules'][$myLoc] = $datarow[$myContent]['modules'][$myLoc];
                 // if user set specefic value for this location add it to db values
                 if (is_array($value)) {
                     $permResult[$myContent]['modules'][$myLoc] += $value;
                 }
             } else {
                 $permResult[$myContent]['modules'][$myLoc] = $value;
             }
         }
     }
     return $permResult;
 }
Example #14
0
 /**
  * Execute cURL call
  * @return mixed Result of the cURL call
  */
 public static function send($_method = null, array $_data = null, $_output = null)
 {
     if (!isset($_data['is_json'])) {
         $is_json = true;
     } else {
         $is_json = $_data['is_json'];
         unset($_data['is_json']);
     }
     // if telegram is off then do not run
     if (!\lib\utility\option::get('telegram', 'status')) {
         return 'telegram is off!';
     }
     // if method or data is not set return
     if (!$_method || !$_data) {
         return 'method or data is not set!';
     }
     if (array_key_exists('method', $_data)) {
         if ($_data['method'] == 'answerInlineQuery') {
             $is_json = true;
         }
         unset($_data['method']);
     }
     $response_callback = null;
     if (array_key_exists('response_callback', $_data)) {
         $response_callback = $_data['response_callback'];
         unset($_data['response_callback']);
     }
     // if api key is not set get it from options
     if (!self::$api_key) {
         self::$api_key = \lib\utility\option::get('telegram', 'meta', 'key');
     }
     // if key is not correct return
     if (strlen(self::$api_key) < 20) {
         return 'api key is not correct!';
     }
     // initialize curl
     $ch = curl_init();
     if ($ch === false) {
         return 'Curl failed to initialize';
     }
     $curlConfig = [CURLOPT_URL => "https://api.telegram.org/bot" . self::$api_key . "/{$_method}", CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_SAFE_UPLOAD => true, CURLOPT_SSL_VERIFYPEER => false];
     curl_setopt_array($ch, $curlConfig);
     if (!empty($_data)) {
         if ($is_json) {
             $data_string = json_encode($_data);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
             curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string)));
         } else {
             curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
             // curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
             // curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query($_data));
             curl_setopt($ch, CURLOPT_POSTFIELDS, $_data);
         }
     }
     if (Tld === 'dev') {
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     }
     $result = curl_exec($ch);
     if ($response_callback) {
         if (is_object($response_callback)) {
             call_user_func_array($response_callback, [json_decode($result), $_data]);
         } elseif (is_array($response_callback)) {
             $args = array_splice($response_callback, 1);
             array_unshift($args, json_decode($result), $_data);
             call_user_func_array($response_callback[0], $args);
         }
     }
     if ($result === false) {
         return curl_error($ch) . ':' . curl_errno($ch);
     }
     if (empty($result) | is_null($result)) {
         return 'Empty server response';
     }
     curl_close($ch);
     //Logging curl requests
     if (substr($result, 0, 1) === "{") {
         $result = json_decode($result, true);
         if ($_output && isset($result[$_output])) {
             $result = $result[$_output];
         }
     }
     log::save($result);
     // return result
     return $result;
 }
Example #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');
 }
Example #16
0
 function view_datatable()
 {
     $form_general = $this->createform('.options', 'general', true);
     $form_config = $this->createform('.options', 'config', true);
     $form_social = $this->createform('.options', 'social', true);
     $form_twitter = $this->createform('.options', 'twitter', true);
     $form_facebook = $this->createform('.options', 'facebook', true);
     $form_telegram = $this->createform('.options', 'telegram', true);
     $form_sms = $this->createform('.options', 'sms', true);
     $form_register = $this->createform('.options', 'account', true);
     // add languages item
     foreach (\lib\utility\option::languages() as $key => $value) {
         $form_config->config_defaultLang->child()->id('lang_' . $key)->value($key)->label($value);
     }
     // add sms items
     $form_sms->sms_name->child()->id('sms_kavenegar')->value('kavenegar_api')->label(T_('Kavenegar'));
     $tld_list = ['com', 'org', 'edu', 'net', 'ir'];
     foreach ($tld_list as $key => $tld) {
         $form_config->config_defaultTld->child()->id('config_tld_' . $tld)->value($tld)->label($tld);
     }
     // add content list to show for redirect
     foreach (\lib\utility\option::contentList(true) as $key => $value) {
         $form_register->account_redirect->child()->id('redirect_' . $key)->value($value)->label(T_($value));
     }
     // give perm list and fill it in default register type
     $myPermList = $form_register->account_default;
     $myPermNames = \lib\utility\option::permList();
     if (!$myPermNames) {
         $myPermNames = [];
     }
     $myPerm = 1;
     // if list of permission is more than 6 item show in select
     if (count($myPermNames) > 6) {
         $myPermList = $form_register->account_default->type('select');
     }
     // get list of permissions
     foreach ($myPermNames as $key => $value) {
         if ($myPerm == $key) {
             $myPermList->child()->value($key)->label(T_($value))->elname(null)->pl(null)->attr('type', null)->id('perm_' . $key)->selected();
         } else {
             $myPermList->child()->value($key)->label(T_($value))->elname(null)->pl(null)->attr('type', null)->id('perm_' . $key);
         }
     }
     // get the datatable of options
     $datatable = $this->model()->draw_options();
     // $datatable['sms']['sms'] = null;
     // fill all forms used in options page
     if (isset($datatable['general'])) {
         $this->form_fill($form_general, $datatable['general']);
     }
     if (isset($datatable['config']['config'])) {
         $this->form_fill($form_config, $datatable['config']['config']);
         // add default tld to domain name
         if (isset($datatable['config']['config']['meta']['defaultTld'])) {
             $selectedTld = $datatable['config']['config']['meta']['defaultTld'];
             $form_config->config_domainName->attr('data-after', $selectedTld);
         }
     }
     if (isset($datatable['social'])) {
         $this->form_fill($form_social, $datatable['social']);
     }
     if (isset($datatable['social']['twitter'])) {
         $this->form_fill($form_twitter, $datatable['social']['twitter']);
     }
     if (isset($datatable['social']['facebook'])) {
         $this->form_fill($form_facebook, $datatable['social']['facebook']);
     }
     if (isset($datatable['social']['telegram'])) {
         $this->form_fill($form_telegram, $datatable['social']['telegram']);
     }
     if (isset($datatable['sms']['sms'])) {
         $this->form_fill($form_sms, $datatable['sms']['sms']);
     }
     if (isset($datatable['account']['account'])) {
         $this->form_fill($form_register, $datatable['account']['account']);
     }
 }
Example #17
0
 /**
  * { function_description }
  *
  * @param      <type>  $_user   The user
  * @param      <type>  $_type   The type
  * @param      <type>  $_value  The value
  * @param      <type>  $_args   The arguments
  *
  * @return     <type>  ( description_of_the_return_value )
  */
 public static function updateDetail($_user, $_type, $_value, $_args)
 {
     $changeDate = date('Y-m-d H:i:s');
     // save mobile number in user history
     $userDetail = ['user' => $_user, 'cat' => 'history_' . $_user, 'key' => $_type, 'value' => $_value, 'meta' => $_args];
     $result = \lib\utility\option::set($userDetail);
     return $result;
 }
Example #18
0
 /**
  * [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();
     }
 }
Example #19
0
 /**
  * setWebhook for telegram
  * @param string $_url  [description]
  * @param [type] $_file [description]
  */
 public static function setWebhook($_url = '', $_file = null)
 {
     if (empty($_url)) {
         $_url = \lib\utility\option::get('telegram', 'meta', 'hook');
     }
     $answer = ['url' => $_url];
     // if (!is_null($_file))
     // {
     // 	$data['certificate'] = \CURLFile($_file);
     // }
     return exec::send('setWebhook', $answer, 'description') . ': ' . $_url;
 }
Example #20
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;
 }
Example #21
0
 function draw_users()
 {
     $mychild = $this->child();
     $this->data->form->users->user_status->required('required');
     $checkStatus = null;
     $myPerm = null;
     $myPermNames = \lib\utility\option::permList();
     $myPermList = $this->data->form->users->user_permission;
     if (count($myPermNames) > 5) {
         $myPermList->type('select');
         $checkStatus = 'selected';
     } else {
         $myPermList->type('radio');
         $checkStatus = 'checked';
     }
     if ($mychild === 'edit') {
         $myPerm = $this->model()->datarow('users');
         $myPerm = $myPerm['user_permission'];
         if ($myPerm === "1") {
             $myPermList->addClass('hide');
         }
     }
     // get list of permissions
     foreach ($myPermNames as $key => $value) {
         if ($myPerm == $key) {
             $myPermList->child()->value($key)->label(T_($value))->elname(null)->pl(null)->attr('type', null)->id('perm' . $key)->{$checkStatus}();
         } else {
             $myPermList->child()->value($key)->label(T_($value))->elname(null)->pl(null)->attr('type', null)->id('perm' . $key);
         }
     }
     $this->data->form->users->user_pass->autocomplete('new-password');
     $myPass = $this->data->form->users->user_pass;
     if ($mychild === 'add') {
         $myPass->attr('required', 'required')->pl(T_('Enter password within 5 to 40 character'));
     } else {
         $myPass->label(T_('New Password'))->value(null)->pl(T_('If you want to change password enter it, else leave it blank'));
     }
     // get user position and set it
     $position = null;
     if (isset($this->data->form->users->datarow['user_meta'])) {
         $meta = $this->data->form->users->datarow['user_meta'];
         $meta = json_decode($meta, true);
         if (isset($meta['position'])) {
             $position = $meta['position'];
         }
     }
     $this->data->form->users->add('position', 'text')->name('position')->label(T_("position"))->value($position)->compile();
     $this->data->form->users->after('position', 'user_displayname');
 }
Example #22
0
 public function __construct($object = false)
 {
     parent::__construct($object);
     $this->permissions = \lib\utility\option::get('permissions', 'meta');
 }