Ejemplo n.º 1
0
 /**
  * Update options data
  * @return run update query and no return value
  */
 function put_options()
 {
     $myFields = ['title' => 'site-title', 'desc' => 'site-desc', 'email' => 'site-email', 'url' => 'site-url', 'redirect' => 'site-redirect', 'register' => 'site-reg', 'permissions' => 'site-role'];
     foreach ($myFields as $field => $postName) {
         $qry = $this->sql()->table('options')->where('option_cat', 'options')->and('option_key', $field)->and('post_id', '#NULL')->and('user_id', '#NULL');
         $fieldExist = $qry->select()->num();
         // if exist more than 2 times remove all the properties
         if ($fieldExist > 1) {
             debug::true(T_("We find a problem and solve it!"));
             $qry->delete();
             $fieldExist = 0;
         }
         $value = utility::post($postName);
         if (!$value) {
             $value = '#""';
         }
         $qry = $qry->set('option_cat', 'options')->set('option_status', 'enable')->set('option_key', $field)->set('option_value', $value);
         // if exist update field
         if ($fieldExist == 1) {
             $qry->update();
         } else {
             $qry->insert('IGNORE');
         }
     }
     // exit();
     $this->commit(function () {
         debug::true(T_("Update Successfully"));
         // $this->redirector()->set_url($_module.'/edit='.$_postId);
     });
     // if a query has error or any error occour in any part of codes, run roolback
     $this->rollback(function () {
         debug::title(T_("Transaction error") . ': ');
     });
 }
Ejemplo n.º 2
0
 public function post_signup()
 {
     // get parameters and set to local variables
     $mymobile = utility::post('mobile', 'filter');
     $mypass = utility::post('password', 'hash');
     // check for mobile exist
     $tmp_result = $this->sql()->tableUsers()->whereUser_mobile($mymobile)->select();
     // if exist
     if ($tmp_result->num() == 1) {
         debug::error(T_("mobile number exist!"));
     } elseif ($tmp_result->num() == 0) {
         $qry = $this->sql()->tableUsers()->setUser_mobile($mymobile)->setUser_pass($mypass)->setUser_permission(3)->setUser_createdate(date('Y-m-d H:i:s'));
         $sql = $qry->insert();
         // ======================================================
         // 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 ($_mobile) {
             // \lib\utility\Sms::send($_mobile, 'signup', $_code);
             debug::true(T_("register successfully"));
             // $this->redirector()->set_url('verification?from=signup&mobile='.$_mobile.'&referer='.$myreferer);
             // $this->redirector()->set_url('login?from=signup&mobile='.$_mobile);
         }, $mymobile);
         // if a query has error or any error occour in any part of codes, run roolback
         $this->rollback(function () {
             debug::error(T_("register failed!"));
         });
     } else {
         debug::error(T_("please forward this message to administrator"));
     }
 }
Ejemplo n.º 3
0
 function post_changepass()
 {
     $myid = $this->login('id');
     $newpass = utility::post('password-new', 'hash');
     $oldpass = utility::post('password-old');
     $tmp_result = $this->sql()->tableUsers()->where('id', $myid)->and('user_status', 'active')->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($oldpass, $myhashedPassword)) {
             $newpass = utility::post('password-new', 'hash');
             $qry = $this->sql()->table('users')->where('id', $myid)->set('user_pass', $newpass);
             $sql = $qry->update();
             $this->commit(function () {
                 debug::true(T_("change password successfully"));
                 $this->redirector()->set_domain()->set_url();
                 // \lib\utility\Sms::send($_mobile, 'changepass');
             });
             // if a query has error or any error occour in any part of codes, run roolback
             $this->rollback(function () {
                 debug::error(T_("change password failed!"));
             });
         } else {
             debug::error(T_("Password is incorrect"));
         }
     } elseif ($tmp_result->num() == 0) {
         debug::error(T_("user is incorrect"));
     } else {
         debug::error(T_("Please forward this message to administrator"));
     }
     sleep(0.1);
 }
Ejemplo n.º 4
0
 /**
  * signup to system
  * @return [type] [description]
  */
 public function post_signup()
 {
     // get parameters and set to local variables
     $mymobile = utility::post('mobile', 'filter');
     $mypass = utility::post('password', 'hash');
     $myperm = $this->option('account');
     if (!$myperm) {
         $myperm = 'NULL';
     }
     $user_id = \lib\db\users::signup($mymobile, $mypass, $myperm);
     if ($user_id) {
         // generate verification code
         // save in logs table
         // set SESSION verification_mobile
         $code = \lib\utility\filter::generate_verification_code($user_id, $mymobile);
         if ($code) {
             \lib\utility\sms::send($mymobile, 'signup', $code);
             debug::true(T_("Register successfully"));
             $this->redirector()->set_url('verification?from=signup&mobile=' . $mymobile);
             // $this->redirector()->set_url('login?from=signup&cp=1&mobile='.$mymobile);
         } else {
             debug::error(T_("Please contact to administrator!"));
         }
     } elseif ($user_id === false) {
         debug::error(T_("Mobile number exist!"));
     } else {
         debug::error(T_("Please contact to administrator!"));
     }
 }
Ejemplo n.º 5
0
 /**
  * this function set custom operator for each custom module in cp
  * @param  [type] $_id [description]
  * @return [type]      [description]
  */
 function cp_create_query($_id = null)
 {
     if (!$_id) {
         $_id = $this->childparam('edit');
     }
     $cpModule = $this->cpModule();
     $mymodule = $this->cpModule('raw');
     $qry = $this->sql();
     $datarow = array();
     $datarow['slug'] = utility::post('slug', 'filter');
     $datarow['parent'] = utility::post('parent');
     if (!$datarow['slug']) {
         $datarow['slug'] = utility\filter::slug(utility::post('title'));
     }
     if ($datarow['parent']) {
         $datarow['url'] = $this->sql()->table('terms')->where('id', $datarow['parent'])->select()->assoc('term_url') . '/' . $datarow['slug'];
     } else {
         $datarow['parent'] = '#NULL';
         $datarow['url'] = $datarow['slug'];
     }
     if ($cpModule['raw'] === 'bookcategories') {
         $datarow['url'] = 'book-index/' . preg_replace("#^(book-index\\/)+#", "", $datarow['url']);
     }
     // var_dump($datarow['slug']);exit();
     if (utility::post('title')) {
         $qry = $qry->table('terms')->set('term_type', $cpModule['type'])->set('term_language', utility::post('language'))->set('term_title', utility::post('title'))->set('term_slug', $datarow['slug'])->set('term_desc', utility::post('desc'))->set('term_parent', $datarow['parent'])->set('term_url', $datarow['url']);
     } else {
         debug::error(T_("Please enter title!"));
         return false;
     }
     $post_new_id = null;
     if ($_id) {
         // on edit
         $qry = $qry->where('id', $_id)->update();
         $post_new_id = $_id;
     } else {
         // on add
         $qry = $qry->insert();
         $post_new_id = $qry->LAST_INSERT_ID();
     }
     // ======================================================
     // 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 ($_module, $_postId, $_edit = null) {
         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 . '/add');
             // $this->redirector()->set_url($_module.'/edit='.$_postId);
         }
     }, $mymodule, $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") . ': ');
     });
 }
Ejemplo n.º 6
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);
 }
Ejemplo n.º 7
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]);
     }
 }
Ejemplo n.º 8
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_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"));
                 $referer = \lib\router::urlParser('referer', 'host');
                 /**
                  * temporary: after fix permissions below line must be delete
                  */
                 if ($referer == 'archiver.dev' || $referer == 'irancamera.ir') {
                     $this->redirector()->set_domain()->set_sub_domain('files')->set_url();
                 } elseif (\lib\router::get_storage('CMS')) {
                     $this->redirector()->set_domain()->set_sub_domain(\lib\router::get_storage('CMS'))->set_url();
                 } else {
                     $this->redirector()->set_domain()->set_url();
                 }
             });
             $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);
 }
Ejemplo n.º 9
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;
 }
Ejemplo n.º 10
0
 /**
  * Update profile data
  * @return run update query and no return value
  */
 function put_profile()
 {
     $qry = $this->sql()->table('users')->where('id', $this->login('id'))->set('user_mobile', utility::post('mobile'))->set('user_email', utility::post('email'))->set('user_displayname', utility::post('displayname'));
     $qry->update();
     $this->commit(function () {
         debug::true(T_("Update Successfully"));
         // $this->redirector()->set_url($_module.'/edit='.$_postId);
     });
     // if a query has error or any error occour in any part of codes, run roolback
     $this->rollback(function () {
         debug::title(T_("Transaction error") . ': ');
     });
 }
Ejemplo n.º 11
0
 /**
  * [get_feeds description]
  * @param  boolean $_forcheck [description]
  * @return [type]             [description]
  */
 public function get_feeds($_forcheck = false)
 {
     $start = \lib\utility::get('start');
     $lenght = \lib\utility::get('lenght');
     // search in url field if exist return row data
     $qry = $this->sql()->table('posts')->field('#post_language as `lang`', '#post_title as `title`', '#post_content as `desc`', '#post_url as `link`', '#post_publishdate as `date`')->where('post_type', 'post')->and('post_status', 'publish')->limit(0, 10);
     $qry = $qry->groupOpen('g_language');
     $qry = $qry->and('post_language', \lib\define::get_language());
     $qry = $qry->or('post_language', 'IS', 'NULL');
     $qry = $qry->groupClose('g_language');
     $qry = $qry->select();
     return $qry->allassoc();
 }
Ejemplo n.º 12
0
 public function put_verification()
 {
     // get parameters and set to local variables
     $mycode = utility::post('code');
     $mymobile = utility::post('mobile', 'filter');
     if ($mymobile == '' && isset($_SESSION['verification_mobile'])) {
         $mymobile = $_SESSION['verification_mobile'];
     }
     $myuserid = $this->sql()->table('users')->field('id')->where('user_mobile', $mymobile)->select()->assoc('id');
     // check for mobile exist
     $tmp_result = $this->sql()->table('logs')->where('user_id', $myuserid)->and('log_data', $mycode)->and('log_status', 'enable')->select();
     if ($tmp_result->num()) {
         // mobile and code exist update the record and verify
         $qry = $this->sql()->table('logs')->set('log_status', 'expire')->where('user_id', $myuserid)->and('log_data', $mycode)->and('log_status', 'enable');
         $sql = $qry->update();
         $sql_users = $this->sql()->table('users')->where('id', $myuserid)->set('user_status', 'active')->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
         $this->commit(function ($_mobile, $_userid) {
             $myfrom = utility\cookie::read('from');
             if ($myfrom == 'signup') {
                 // login user to system
                 $this->model()->setLogin($_userid);
                 //Send SMS
                 \lib\utility\sms::send($_mobile, 'verification');
                 debug::true(T_("verify successfully."));
             } else {
                 // login user to system
                 $this->model()->setLogin($_userid, false);
                 $this->redirector()->set_url('changepass');
                 $myreferer = utility\cookie::write('mobile', $_mobile, 60 * 5);
                 $myreferer = utility\cookie::write('from', 'verification', 60 * 5);
                 debug::true(T_("verify successfully.") . ' ' . T_("please Input your new password"));
             }
         }, $mymobile, $myuserid);
         // if a query has error or any error occour in any part of codes, run roolback
         $this->rollback(function () {
             debug::error(T_("verify failed!"));
         });
     } elseif ($tmp_result->num() == 0) {
         debug::error(T_("this data is incorrect"));
     } else {
         debug::error(T_("please forward this message to administrator"));
     }
 }
Ejemplo n.º 13
0
 /**
  * Update profile data
  * @return run update query and no return value
  */
 function put_profile()
 {
     // Check permission and if user can do this operation
     // allow to do it, else show related message in notify center
     $this->access('cp', 'posts', 'delete', 'notify');
     $qry = $this->sql()->table('users')->where('id', $this->login('id'))->set('user_mobile', utility::post('mobile'))->set('user_email', utility::post('email'))->set('user_displayname', utility::post('displayname'));
     $qry->update();
     $this->commit(function () {
         debug::true(T_("Update Successfully"));
         // $this->redirector()->set_url($_module.'/edit='.$_postId);
     });
     // if a query has error or any error occour in any part of codes, run roolback
     $this->rollback(function () {
         debug::title(T_("Transaction error") . ': ');
     });
 }
Ejemplo n.º 14
0
 function __construct($object = false)
 {
     parent::__construct($object);
     $settings = $this->option('account', null, false, $this);
     $mymodule = $this->module();
     $isValid = false;
     // // entire account part is disabled
     // if(isset($settings['status']) && !$settings['status'])
     // {
     // 	\lib\error::core('Disabled!');
     // }
     // check access permission to account
     // if user set passphrase for enter account
     if (isset($settings['meta']['passphrase']) && $settings['meta']['passphrase'] && $mymodule !== 'logout') {
         // if user set pass key
         if (isset($settings['meta']['passkey']) && $settings['meta']['passkey']) {
             // get pass key and save it in myphrase variable
             $myPassKey = $settings['meta']['passkey'];
             $myPassValue = \lib\utility::get($myPassKey);
             // if user not set pass value in get, then check cookie for it
             if ($myPassValue === null) {
                 $myPassValue = \lib\utility\cookie::read($myPassKey);
             }
             // if not set this passkey and incorrect
             if ($myPassValue === null) {
                 $isValid = false;
             } elseif (isset($settings['meta']['passvalue']) && $settings['meta']['passvalue']) {
                 // passvalue exist and equal
                 if ($settings['meta']['passvalue'] === $myPassValue) {
                     $isValid = true;
                 } else {
                     $isValid = false;
                 }
             } else {
                 $isValid = true;
             }
             // if can access set cookie
             if ($isValid) {
                 \lib\utility\cookie::write($myPassKey, $myPassValue, 60 * 60 * 24 * 7);
                 // allow 1week
             } else {
                 \lib\utility\cookie::delete($myPassKey);
                 \lib\error::login();
             }
         }
     }
 }
Ejemplo n.º 15
0
 public function permList($_fill = false)
 {
     $permResult = [];
     $permCond = ['view', 'add', 'edit', 'delete', 'admin'];
     foreach ($this->permContentsList() 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 ($this->permModulesList($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;
 }
Ejemplo n.º 16
0
 public function post_recovery()
 {
     // get parameters and set to local variables
     $mymobile = utility::post('mobile', 'filter');
     // check for mobile exist
     $tmp_result = $this->sql()->table('users')->where('user_mobile', $mymobile)->select();
     if ($tmp_result->num() == 1) {
         $myuserid = $tmp_result->assoc('id');
         $mylogitem = $this->sql()->table('logitems')->field('id')->where('logitem_title', 'account/recovery')->select()->assoc('id');
         if (!isset($mylogitem)) {
             return;
         }
         $mycode = utility::randomCode();
         $qry = $this->sql()->table('logs')->set('logitem_id', $mylogitem)->set('user_id', $myuserid)->set('log_data', $mycode)->set('log_status', 'enable')->set('log_createdate', date('Y-m-d H:i:s'));
         // var_dump($qry->insertString());
         // return;
         $sql = $qry->insert();
         // ======================================================
         // 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 ($_mobile, $_code) {
             $myreferer = utility\Cookie::read('referer');
             //Send SMS
             \lib\utility\Sms::send($_mobile, 'recovery', $_code);
             debug::true(T_("we send a verification code for you"));
             $myreferer = utility\Cookie::write('mobile', $_mobile, 60 * 5);
             $myreferer = utility\Cookie::write('from', 'recovery', 60 * 5);
             $this->redirector()->set_url('verification?from=recovery&mobile=' . $_mobile . '&referer=' . $myreferer);
         }, $mymobile, $mycode);
         // if a query has error or any error occour in any part of codes, run roolback
         $this->rollback(function () {
             debug::error(T_("recovery failed!"));
         });
     } elseif ($tmp_result->num() == 0) {
         debug::error(T_("Mobile number is incorrect"));
     } else {
         debug::error(T_("please forward this message to administrator"));
     }
 }
Ejemplo n.º 17
0
 /**
  * check route of account
  * @return [type] [description]
  */
 function _route()
 {
     // exit();
     // \lib\debug::true("check", 'hi');
     // var_dump();
     $mymodule = $this->module();
     $referer = \lib\router::urlParser('referer', 'domain');
     $from = \lib\utility\cookie::read('from');
     $from = $from ? $from : \lib\utility::get('from');
     $islogin = $this->login();
     // set referrer in cookie
     if ($referer !== Domain) {
         \lib\utility\cookie::write('referer', $referer, 60 * 15);
     }
     // check permission for changepass
     if ($mymodule === 'changepass' && $from !== 'verification' && !$islogin) {
         \lib\error::access(T_("you can't access to this page!"));
     }
     switch ($mymodule) {
         case 'home':
             $this->redirector()->set_url("login")->redirect();
             break;
         case 'verification':
         case 'verificationsms':
             if ($from && $from !== 'recovery' && $from !== 'signup' && $from !== 'verification') {
                 \lib\error::access(T_("you can't access to this page!"));
             }
             $this->model_name = '\\addons\\content_account\\' . $mymodule . '\\model';
             $this->display_name = 'content_account\\' . $mymodule . '\\display.html';
             $this->post($mymodule)->ALL($mymodule);
             $this->get()->ALL($mymodule);
             break;
         case 'signup':
             return;
             /**
             
             Fix it later, only access if posible
             */
         /**
         
         Fix it later, only access if posible
         */
         case 'login':
         case 'recovery':
             if ($islogin) {
                 \lib\debug::true(T_("you are logined to system!"));
                 $myreferer = \lib\router::urlParser('referer', 'host');
                 $myssid = isset($_SESSION['ssid']) ? '?ssid=' . $_SESSION['ssid'] : null;
                 if (\lib\router::get_storage('CMS')) {
                     $this->redirector()->set_domain()->set_sub_domain(\lib\router::get_storage('CMS'))->set_url()->redirect();
                 } else {
                     $this->redirector()->set_domain()->set_url()->redirect();
                 }
             }
         case 'changepass':
             $this->model_name = '\\addons\\content_account\\' . $mymodule . '\\model';
             $this->display_name = 'content_account\\' . $mymodule . '\\display.html';
             $this->post($mymodule)->ALL($mymodule);
             $this->get()->ALL($mymodule);
             break;
         case 'smsdelivery':
         case 'smscallback':
             $uid = 201500001;
             if (\lib\utility::get('uid') == $uid || \lib\utility\cookie::read('uid') == $uid) {
                 $this->model_name = '\\addons\\content_account\\sms\\model';
                 $this->display_name = 'content_account\\sms\\display.html';
                 $this->post($mymodule)->ALL($mymodule);
                 $this->get($mymodule)->ALL($mymodule);
             } else {
                 \lib\error::access("SMS");
             }
             break;
             // logout user from system then redirect to ermile
         // logout user from system then redirect to ermile
         case 'logout':
             $this->model_name = '\\lib\\mvc\\model';
             $this->model()->put_logout();
             $this->redirector()->set_domain()->set_url()->redirect();
             break;
         default:
             \lib\error::page();
             break;
     }
     // $this->route_check_true = true;
 }
Ejemplo n.º 18
0
 public function config()
 {
     // $this->data->list             = $this->cpModlueList('all');
     $this->data->bodyclass = 'fixed';
     $this->include->css = false;
     $this->include->js = false;
     $this->include->fontawesome = true;
     $this->include->datatable = true;
     $this->include->chart = true;
     $this->include->introjs = true;
     $this->include->lightbox = true;
     $this->include->editor = true;
     $this->include->cp = true;
     $this->include->uploader = true;
     $this->global->js = array();
     // $this->global->js             = [$this->url->myStatic.'js/highcharts/highcharts.js'];
     // $this->data->page['desc']  = 'salam';
     $this->data->page['haschild'] = true;
     $this->data->page['title'] = T_(ucfirst(\lib\router::get_url(' ')));
     $this->data->dir['right'] = $this->global->direction == 'rtl' ? 'left' : 'right';
     $this->data->dir['left'] = $this->global->direction == 'rtl' ? 'right' : 'left';
     $mymodule = $this->module();
     switch ($mymodule) {
         case 'tags':
             $this->data->page['desc'] = T_('Assign keywords to your posts using tags');
             break;
         case 'categories':
             $this->data->page['desc'] = T_('Use categories to define sections of your site and group related posts');
             $this->data->page['title'] = T_('Categories');
             break;
         case 'filecategories':
             $this->data->page['desc'] = T_('Use categories to define sections of your site and group related files');
             $this->data->page['title'] = T_('File Categories');
             break;
         case 'bookcategories':
             $this->data->page['desc'] = T_('Use categories to define sections of your site and group related books');
             $this->data->page['title'] = T_('Book Categories');
             break;
         case 'books':
             $this->data->page['desc'] = T_('Use book to define important parts to use in posts');
             $this->data->page['title'] = T_('books');
             break;
         case 'posts':
             $this->data->page['desc'] = T_('Use posts to share your news in specefic category');
             break;
         case 'pages':
             $this->data->page['desc'] = T_('Use pages to share your static content');
             break;
         case 'attachments':
             $this->data->page['desc'] = T_('Upload your media');
             break;
         case 'socialnetwork':
             $this->data->page['desc'] = T_('Publish new post in social networks');
             break;
         case 'options':
             $this->data->page['desc'] = T_('Edit your site general options');
             $this->data->page['haschild'] = false;
             break;
         case 'visitors':
             if (LogVisitors) {
                 // create for chart
                 $type = \lib\utility::get('type');
                 $utype = \lib\utility::get('utype');
                 $this->data->chart_type = $type ? $type : 'column';
                 $this->data->chart_unique_type = $utype ? $utype : 'areaspline';
                 $this->data->visitors = $this->model()->visitors();
                 $this->data->visitors_unique = $this->model()->visitors(true);
                 if ($this->data->visitors <= 1) {
                     $this->data->error = T_("Chart must be contain at least 2 column!");
                 }
             }
             break;
         case 'home':
             $this->data->page['title'] = T_('Dashboard');
             $this->data->countOf['posts'] = $this->model()->countOf('posts');
             $this->data->countOf['pages'] = $this->model()->countOf('pages');
             $this->data->countOf['attachments'] = $this->model()->countOf('attachments');
             $this->data->countOf['books'] = $this->model()->countOf('books');
             $this->data->countOf['tags'] = $this->model()->countOf('tags');
             $this->data->countOf['categories'] = $this->model()->countOf('categories');
             $this->data->countOf['users'] = $this->model()->countOf('users');
             $this->data->bodyclass .= ' unselectable';
             // check visitor is new or not
             $this->data->visitor_new = false;
             $ref = \lib\router::urlParser('referer', 'sub');
             if ($ref !== 'cp' && $ref !== null) {
                 $this->data->visitor_new = true;
             }
             if (LogVisitors) {
                 // create for chart
                 $this->data->chart_type = 'column';
                 $this->data->visitors = $this->model()->visitors();
                 $this->data->visitors_toppages = $this->model()->visitors_toppages(15);
                 if ($this->data->visitors <= 1) {
                     $this->data->error = T_("Chart must be contain at least 2 column!");
                 }
             }
             break;
         default:
             # code...
             break;
     }
     if ($this->data->page['haschild']) {
         // Check permission and if user can do this operation
         // allow to do it, else show related message in notify center
         $myResult = $this->access('cp', $mymodule, 'add');
         $this->data->page['haschild'] = $myResult ? true : false;
     }
     // $this->data->site['title']  = T_('Control Panel'). ' - ' . $this->data->site['title'];
 }
Ejemplo n.º 19
0
 public function config()
 {
     // $this->data->list             = $this->cpModlueList('all');
     $this->data->bodyclass = 'fixed unselectable';
     $this->include->css = false;
     $this->include->js = false;
     $this->include->fontawesome = true;
     $this->include->datatable = true;
     $this->include->chart = true;
     $this->include->introjs = true;
     $this->include->lightbox = true;
     $this->include->editor = true;
     $this->include->cp = true;
     $this->include->uploader = true;
     $this->global->js = array();
     $this->data->display['cp_posts'] = "content_cp/posts/layout.html";
     $this->data->saloos['version'] = \lib\saloos::getLastVersion();
     $this->data->saloos['lastUpdate'] = \lib\saloos::getLastUpdate();
     $this->data->saloos['langlist'] = ['fa_IR' => 'Persian - فارسی', 'en_US' => 'English', 'ar_SU' => 'Arabic - العربية'];
     $this->data->modules = $this->controller::$manifest['modules']->get_modules();
     // $this->global->js             = [$this->url->myStatic.'js/highcharts/highcharts.js'];
     // $this->data->page['desc']  = 'salam';
     $mymodule = $this->module();
     $this->data->page['desc'] = $this->controller::$manifest['modules']->get_modules($mymodule, "desc");
     $this->data->page['title'] = $this->controller::$manifest['modules']->get_modules($mymodule, "title");
     $this->data->page['haschild'] = $this->controller::$manifest['modules']->get_modules($mymodule, "childless") ? false : true;
     $this->data->page['title'] = T_(ucfirst(\lib\router::get_url(' ')));
     $this->data->cpModule = $this->cpModule();
     $this->data->dir['right'] = $this->global->direction == 'rtl' ? 'left' : 'right';
     $this->data->dir['left'] = $this->global->direction == 'rtl' ? 'right' : 'left';
     switch ($mymodule) {
         case 'visitors':
             if (\lib\utility\option::get('config', 'meta', 'logVisitors')) {
                 // create for chart
                 $type = \lib\utility::get('type');
                 $utype = \lib\utility::get('utype');
                 $stype = \lib\utility::get('stype');
                 $atype = \lib\utility::get('atype');
                 $this->data->chart_type = $type ? $type : 'column';
                 $this->data->chart_unique_type = $utype ? $utype : 'areaspline';
                 $this->data->chart_signup_type = $stype ? $stype : 'areaspline';
                 $this->data->chart_answered_type = $atype ? $atype : 'column';
                 // $this->data->visitors               = $this->model()->visitors();
                 // $this->data->visitors_unique        = $this->model()->visitors(true);
                 $this->data->visitors = \lib\utility\visitor::chart();
                 $this->data->visitors_unique = \lib\utility\visitor::chart(true);
                 // get period of signup from user
                 $this->data->period = \lib\utility::get('period');
                 switch ($this->data->period) {
                     case 'year':
                         $period = "%Y";
                         break;
                     case 'month':
                         $period = "%Y-%m";
                         break;
                     case 'week':
                         $period = "%Y " . T_('week') . "%V";
                         break;
                     case 'day':
                     default:
                         $period = "%Y-%m-%d";
                         break;
                 }
                 $this->data->signup = \lib\db\chart\users::signup($period);
                 if (class_exists('\\lib\\db\\chart\\polls')) {
                     $this->data->answered = \lib\db\chart\polls::answeredCount($period);
                 }
                 if ($this->data->visitors <= 1) {
                     $this->data->error = T_("Chart must be contain at least 2 column!");
                 }
             }
             break;
         case 'home':
             $this->data->countOf['posts'] = $this->model()->countOf('posts');
             $this->data->countOf['pages'] = $this->model()->countOf('pages');
             $this->data->countOf['attachments'] = $this->model()->countOf('attachments');
             $this->data->countOf['books'] = $this->model()->countOf('books');
             $this->data->countOf['tags'] = $this->model()->countOf('tags');
             $this->data->countOf['categories'] = $this->model()->countOf('categories');
             $this->data->countOf['users'] = $this->model()->countOf('users');
             $this->data->bodyclass .= ' unselectable';
             // check visitor is new or not
             $this->data->visitor_new = false;
             $ref = \lib\router::urlParser('referer', 'sub');
             if ($ref !== 'cp' && $ref !== null) {
                 $this->data->visitor_new = true;
             }
             if (\lib\utility\option::get('config', 'meta', 'logVisitors')) {
                 // create for chart
                 $this->data->chart_type = 'column';
                 $this->data->visitors = \lib\utility\visitor::chart();
                 $this->data->visitors_toppages = \lib\utility\visitor::top_pages(15);
                 if ($this->data->visitors <= 1) {
                     $this->data->error = T_("Chart must be contain at least 2 column!");
                 }
             }
             break;
         default:
             # code...
             break;
     }
     if ($this->data->page['haschild']) {
         // Check permission and if user can do this operation
         // allow to do it, else show related message in notify center
         $myResult = $this->access('cp', $mymodule, 'add');
         $this->data->page['haschild'] = $myResult ? true : false;
     }
     // $f = array_keys($this->controller::modules_hasnot('disable'));
     // $feature = [];
     // foreach ($f as $key => $value) {
     // 	$feature[$value] = true;
     // }
     // $this->data->site['title']  = T_('Control Panel'). ' - ' . $this->data->site['title'];
 }
Ejemplo n.º 20
0
 public function mvc_construct()
 {
     // define default value for url
     $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!!");
     if (defined('LangList') && constant('LangList')) {
         $this->data->site['langlist'] = unserialize(constant('LangList'));
     } else {
         $this->data->site['langlist'] = ['fa_IR' => 'فارسی', 'en_US' => 'English'];
     }
     $current_lang_cookie = \lib\utility\Cookie::read('lang');
     $current_lang_get = \lib\utility::get('lang');
     if (SubDomain && SubDomain !== 'cp' && SubDomain !== 'account' && SubDomain !== 'files') {
         $this->data->site['currentlang'] = SubDomain;
     } elseif (isset($current_lang_get)) {
         $this->data->site['currentlang'] = substr($current_lang_get, 0, 2);
     } elseif (isset($current_lang_cookie)) {
         $this->data->site['currentlang'] = substr($current_lang_cookie, 0, 2);
     } else {
         $this->data->site['currentlang'] = substr(\lib\router::get_storage('defaultLanguage'), 0, 2);
     }
     $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 = \lib\router::get_storage('language');
     $this->global->direction = \lib\router::get_storage('direction');
     $this->global->id = $this->url('path', '_');
     // 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 (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, 'config')) {
         $this->config();
     }
     if (method_exists($this, 'options')) {
         $this->options();
     }
     $this->set_title();
     if (defined('SaveAsCookie') && SaveAsCookie) {
         $mygetlist = \lib\utility::get(null, 'raw');
         if ($mygetlist) {
             // var_dump(7); exit();
             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();
     }
     // if logvisitor on set visitors
     if (defined('LogVisitors') && constant('LogVisitors')) {
         $this->model()->addVisitor();
     }
 }
Ejemplo n.º 21
0
 /**
  * draw list of permissions
  * @return [type] return array contain list of permission and detail of it
  */
 public function draw_permissions()
 {
     $pType = utility::get('name');
     $qry_result = [];
     $qry = $this->sql()->table('options')->where('user_id', 'IS', 'NULL')->and('post_id', 'IS', "NULL")->and('option_cat', 'permissions')->and('option_status', "enable");
     $datatable = $qry->select()->allassoc();
     foreach ($datatable as $key => $row) {
         $myMeta = $row['option_meta'];
         if (substr($myMeta, 0, 1) == '{') {
             $myMeta = json_decode($myMeta, true);
         }
         $qry_result[$row['option_value']] = $myMeta;
     }
     // on first level return result
     if (!$pType) {
         return $qry_result;
     } else {
         return $qry_result[$pType];
     }
 }
Ejemplo n.º 22
0
 /**
  * get post variables and fill it in array for default condition
  * @return [array] contain list of all data entered
  */
 private function getDefault()
 {
     $myDefaults = ['general' => ['title' => 'Ermile', 'desc' => 'Powered by Saloss'], 'config' => ['config' => ['meta' => ['logVisitors' => 'on', 'defaultLang' => 'en_US', 'fakeSub' => 'on', 'account' => 'on']]], 'sms' => ['sms' => ['meta' => ['one' => 'on', 'signup' => 'on', 'verification' => 'on', 'recovery' => 'on', 'changepass' => 'on']]], 'account' => ['account' => ['status' => 'on', 'value' => utility::post('account-default'), 'meta' => ['redirect' => 'cp']]]];
     return $myDefaults;
 }
Ejemplo n.º 23
0
 /**
  * generate response and sending message
  * @return [type] result of sending
  */
 public static function sendResponse($_prop)
 {
     if (self::$skipText && !\lib\utility\option::get('telegram', 'meta', 'debug')) {
         return false;
     }
     // if method is not set user sendmessage method
     if (!isset($_prop['method'])) {
         if (isset($_prop['text'])) {
             $_prop['method'] = 'sendMessage';
         } else {
             return 'method is not set!';
         }
     }
     switch ($_prop['method']) {
         // create send message format
         case 'sendMessage':
             // if chat id is not set then set it
             if (!isset($_prop['chat_id'])) {
                 // require chat id
                 $_prop['chat_id'] = self::response('chat');
             }
             // add reply message id
             if (isset($_prop['reply_to_message_id']) && $_prop['reply_to_message_id'] === true) {
                 $_prop['reply_to_message_id'] = $rsp;
                 if (!$_prop['reply_to_message_id']) {
                     unset($_prop['reply_to_message_id']);
                 }
             }
             break;
         case 'editMessageText':
         case 'editMessageCaption':
         case 'editMessageReplyMarkup':
             $_prop['chat_id'] = array_key_exists('chat_id', $_prop) ? $_prop['chat_id'] : self::response('chat');
             $_prop['message_id'] = array_key_exists('message_id', $_prop) ? $_prop['message_id'] : self::response('message_id');
             break;
         case 'getUserProfilePhotos':
             $_prop['user_id'] = self::response('from');
             break;
         case 'sendPhoto':
         case 'sendAudio':
         case 'sendDocument':
         case 'sendSticker':
         case 'sendVideo':
         case 'sendVoice':
         case 'sendLocation':
         case 'sendVenue':
         case 'sendContact':
         case 'sendChatAction':
         default:
             if (!isset($_prop['chat_id'])) {
                 // require chat id
                 $_prop['chat_id'] = self::response('chat');
             }
             break;
     }
     // if array key exist but is null
     if (array_key_exists('chat_id', $_prop) && is_null($_prop['chat_id'])) {
         $_prop['chat_id'] = \lib\utility::get('id');
     }
     // if on answer we have callback analyse it and send answer
     if (isset($_prop['callback']) && isset($_prop['callback']['text'])) {
         // generate callback query
         $data = ['callback_query_id' => self::response('callback_query_id'), 'text' => $_prop['callback']['text']];
         if (isset($_prop['callback']['show_alert'])) {
             $data['show_alert'] = $_prop['callback']['show_alert'];
         }
         // call callback answer
         self::answerCallbackQuery($data);
         // unset callback
         unset($_prop['callback']);
     }
     // replace values of text and markup
     $_prop = generate::replaceFill($_prop);
     // decode markup if exist
     if (isset($_prop['is_json']) && $_prop['is_json'] == false && isset($_prop['reply_markup'])) {
         $_prop['reply_markup'] = json_encode($_prop['reply_markup'], JSON_UNESCAPED_UNICODE);
     }
     // markdown is enable by default
     if (isset($_prop['text']) && !isset($_prop['parse_mode'])) {
         $_prop['parse_mode'] = 'markdown';
     }
     // call bot send message func
     $funcName = 'self::' . $_prop['method'];
     $result = call_user_func($funcName, $_prop);
     // return result of sending
     return $result;
 }
Ejemplo n.º 24
0
 /**
  * check status of
  * @return [type] [description]
  */
 public function put_ssidStatus()
 {
     $myreferer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
     $mytrusturl = $this->url('account') . '/login';
     $is_trustreferer = $mytrusturl === substr($myreferer, 0, strlen($mytrusturl)) ? true : false;
     if ($is_trustreferer === false) {
         $myfrom = utility::get('from');
         $is_trustreferer = $myfrom === 'login' ? true : false;
     }
     // set ssid from session
     $myssid = isset($_SESSION['ssid']) ? $_SESSION['ssid'] : null;
     // if ssid does not exist return null
     if ($myssid === null) {
         return 'notlogin';
     }
     // ***************************************************** CHECK LOGIN TIME UNDER 1 MIN
     // whereId("<", 10)
     // whereTime('<', 2015)->andTime('>', 2014)
     $tmp_result = $this->sql()->table('options')->where('option_cat', 'cookie_token')->and('option_key', ClientIP)->and('option_value', $myssid)->and('option_status', 'enable')->select()->assoc();
     if (!is_array($tmp_result)) {
         return 'attack';
     }
     // if user passed ssid is correct then update record and set login sessions
     if ($tmp_result['option_status'] === 'enable') {
         $qry = $this->sql()->table('options')->set('option_status', 'expire')->where('option_cat', 'cookie_token')->and('option_key', ClientIP)->and('option_value', $myssid)->and('option_status', 'enable');
         $sql = $qry->update();
         $this->commit();
         $this->rollback();
         return $tmp_result['user_id'];
     }
     // for second page user check or antoher website after login in first one
     if ($tmp_result['usermeta_status'] === 'expire') {
         return $tmp_result['user_id'];
     }
     // if code is disable with logout then return logout
     // this condition is occur when user logout form main service
     if ($tmp_result['usermeta_status'] === 'disable') {
         return 'logout';
     }
     return 'attack';
 }
Ejemplo n.º 25
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;
 }
Ejemplo n.º 26
0
 public function delete($_qry = null, $_id = null, $_table = null)
 {
     // if user pass the qry use it else use our automatic creator
     // $myqry = $_qry? $_qry: null;
     if (!$_qry) {
         $tmp_table = $_table ? $_table : 'table' . ucfirst($this->module());
         $tmp_id = $_id ? $_id : $this->childparam('delete');
         $tmp_id = $tmp_id ? $tmp_id : \lib\utility::post('id');
         $_qry = $this->sql()->{$tmp_table}()->whereId($tmp_id);
         // var_dump($_qry);
     }
     if (!$_qry->select()->num()) {
         debug::error(T_("id does not exist!"));
         return false;
     }
     return $this->delete_commit($_qry);
 }
Ejemplo n.º 27
0
 /**
  * twig custom filter for convert date to best type of showing
  */
 public function twig_filter_sdate()
 {
     return new \Twig_SimpleFilter('sdate', function ($_string, $_max = "day", $_format = "Y/m/d") {
         return \lib\utility::humanTiming($_string, $_max, $_format, $this->data->site['currentlang']);
     });
 }
Ejemplo n.º 28
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();
     }
 }
Ejemplo n.º 29
0
 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;
 }
Ejemplo n.º 30
0
 /**
  * clearly return url property for use
  * @param  [type] $_type type of url you need
  * @param  [type] $_arg  an argument for pass into some condition
  * @return [type]        the url value
  */
 public function url($_type = null, $_arg = null)
 {
     $tmp_result = null;
     $myprefix = Protocol . "://";
     $mypostfix = '/';
     $mytld = router::get_root_domain('tld');
     switch ($_type) {
         // sub domain like 'account'
         case 'sub':
             return router::get_sub_domain($_arg);
             break;
         case 'path':
             $myUrl = router::get_url($_arg);
             if ($_arg == '_') {
                 // filter url to delete disallow characters
                 $myUrl = router::urlfilterer($myUrl);
                 // dont use $ in id
                 $myUrl = str_replace('$', 'dollar', $myUrl);
             }
             return $myUrl;
             break;
         case 'breadcrumb':
             $myurl = router::get_url(-1);
             $breadcrumb = array();
             foreach ($myurl as $value) {
                 $tmp_pos = strpos($value, '=');
                 array_push($breadcrumb, $tmp_pos ? substr($value, 0, $tmp_pos) : $value);
             }
             return $breadcrumb;
             break;
         case 'param':
             return \lib\utility::get(null, $_arg);
             break;
             // domain tld like 'com'
         // domain tld like 'com'
         case 'tld':
             return $mytld;
             break;
             // domain name like 'ermile'
         // domain name like 'ermile'
         case 'domain':
             return router::get_root_domain('domain');
             break;
             // domain name except subdomain like 'ermile.com'
         // domain name except subdomain like 'ermile.com'
         case 'raw':
             return router::get_root_domain('domain') . '.' . $mytld;
             break;
             // like raw plus http[s]:// domain name except subdomain like 'http://ermile.com/'
         // like raw plus http[s]:// domain name except subdomain like 'http://ermile.com/'
         case 'root':
             return $myprefix . router::get_root_domain() . $mypostfix;
             break;
             // use main protocol and give it from config file if not exist use root url
             // return http or https
         // use main protocol and give it from config file if not exist use root url
         // return http or https
         case 'MainProtocol':
             if (defined('MainProtocol') && constant('MainProtocol') && is_string(constant('MainProtocol'))) {
                 return constant('MainProtocol');
             } else {
                 return 'http';
             }
             break;
             // use main site and give it from config file if not exist use root url
             // like raw plus http[s]:// domain name except subdomain like 'http://ermile.com/'
         // use main site and give it from config file if not exist use root url
         // like raw plus http[s]:// domain name except subdomain like 'http://ermile.com/'
         case 'MainSite':
             if (defined('MainSite') && constant('MainSite') && is_string(constant('MainSite'))) {
                 return constant('MainSite');
             } else {
                 return router::get_root_domain() . $mypostfix;
             }
             break;
             // base url for user in base tag with http[s]
         // base url for user in base tag with http[s]
         case 'base':
             return router::$base;
             break;
             // full url except get parameter with http[s]
         // full url except get parameter with http[s]
         case 'full':
             return $myprefix . router::get_domain() . '/' . router::get_url();
             break;
             // return module info
         // return module info
         case 'module':
             if ($_arg === 'prefix') {
                 $mymodule = substr(router::get_url(0), 0, -1);
             } elseif ($_arg == 'array') {
                 $mymodule = router::get_url(-1);
             } elseif ($_arg == 'cp') {
                 $mymodule = router::get_url(0);
                 switch ($mymodule) {
                     case 'tags':
                     case 'cats':
                         $mymodule = 'terms';
                         break;
                     case 'pages':
                         $mymodule = 'posts';
                         break;
                 }
             } else {
                 $mymodule = router::get_url(0);
             }
             return $mymodule;
             break;
         case 'child':
             $mychild = router::get_url(1);
             if (strrpos($mychild, '=') !== false) {
                 $mychild = substr($mychild, 0, strrpos($mychild, '='));
             }
             if (!$_arg) {
                 return $mychild;
             }
             if ($mychild == 'add') {
                 return T_('add new');
             }
             if ($mychild == 'edit') {
                 return T_('edit');
             }
             if ($mychild == 'delete') {
                 return T_('delete');
             }
             break;
             // login service and main service with full address
         // login service and main service with full address
         case 'LoginService':
         case 'account':
             return $myprefix . AccountService . MainTld . '/' . MyAccount;
             break;
         case 'MainService':
             $_arg = is_array($_arg) ? $_arg : array('com', 'dev');
             if (in_array($mytld, $_arg)) {
                 return $myprefix . constant('MainService') . '.' . $mytld;
             } else {
                 return $myprefix . constant('MainService') . MainTld;
             }
             break;
         default:
             return null;
             break;
     }
 }