Exemple #1
0
 /**
  * this function is calling at the end of all codes
  * @return [type] [description]
  */
 public function sp_shutdown()
 {
     // close writing sessions and start saving it
     // session_write_close();
     // $visitor = new \lib\utility\visitors();
     // if logvisitor on set visitors
     if (\lib\utility\option::get('config', 'meta', 'logVisitors')) {
         \lib\utility\visitor::save();
     }
 }
Exemple #2
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'];
 }
Exemple #3
0
 /**
  * run something for config of options
  * @return [type] [description]
  */
 public function doConfig($_config)
 {
     // run visitor table installation
     // need to run only one times
     if (isset($_config['logVisitors'])) {
         $result = \lib\utility\visitor::install();
         if (!in_array(false, $result)) {
             debug::true(T_("Start logging visitors"));
         }
     }
     if (isset($_config['coming'])) {
         setcookie('preview', 'yes', time() + 365 * 24 * 60 * 60, '/', '.' . Service);
     }
 }
Exemple #4
0
 /**
  * set new record in options
  * @param [array] $_args contain key and value of new record
  */
 public static function set($_args, $_ifExistUpdate = true)
 {
     $datarow = ['option_status' => 'enable'];
     // add option user if set
     if (isset($_args['user'])) {
         $op_user = $_args['user'];
         if ($op_user === true) {
             $op_user = \lib\utility\visitor::user_id(false);
             if (!$op_user) {
                 $op_user = '******';
             }
         }
         if ($op_user) {
             $datarow['user_id'] = $op_user;
         }
     }
     // add option post if set
     if (isset($_args['post'])) {
         $datarow['post_id'] = $_args['post'];
     }
     // add option cat if set
     if (isset($_args['cat'])) {
         $datarow['option_cat'] = $_args['cat'];
     } else {
         return false;
     }
     // add option key if set
     if (isset($_args['key'])) {
         // replace _USER_ with user_id if exist
         $replace = "";
         if (isset($datarow['user_id'])) {
             $replace = $datarow['user_id'];
         }
         $_args['key'] = str_replace('_USER_', $replace, $_args['key']);
         $datarow['option_key'] = $_args['key'];
     } else {
         return false;
     }
     // add option value if set
     if (isset($_args['value'])) {
         $datarow['option_value'] = $_args['value'];
     } else {
         $datarow['option_value'] = null;
     }
     // add option meta if set
     if (isset($_args['meta'])) {
         $datarow['option_meta'] = $_args['meta'];
         if (is_array($datarow['option_meta'])) {
             $datarow['option_meta'] = json_encode($datarow['option_meta'], JSON_UNESCAPED_UNICODE);
         }
     }
     // add option status if set
     if (isset($_args['status'])) {
         // only allow defined$_args['status'])e
         switch ($_args['status']) {
             case 'enable':
             case 'disable':
             case 'expire':
                 break;
             default:
                 $_args['status'] = 'enable';
                 break;
         }
         $datarow['option_status'] = $_args['status'];
     }
     // add date modified manually
     if (isset($_args['modify']) && $_args['modify'] === 'now') {
         $datarow['date_modified'] = 'now()';
     }
     // create query string
     $qry_fields = implode(', ', array_keys($datarow));
     foreach ($datarow as $key => $value) {
         switch ($key) {
             case 'user_id':
             case 'post_id':
             case 'date_modified':
                 $datarow[$key] = $value;
                 break;
             case 'option_meta':
                 if ($value === '++') {
                     $datarow[$key] = "coalesce({$key}, 0)" . '+1';
                 } else {
                     $datarow[$key] = "'" . $value . "'";
                 }
                 break;
             default:
                 $datarow[$key] = "'" . $value . "'";
                 break;
         }
     }
     $qry_values = implode(', ', $datarow);
     // connect to database
     if ($_ifExistUpdate) {
         // start creating query data
         $qry_data = null;
         foreach ($datarow as $key => $value) {
             $qry_data .= $key . '=' . $datarow[$key] . ', ';
         }
         // remove last ,
         $qry_data = substr($qry_data, 0, -2);
         if (isset($_args['id']) && is_numeric($_args['id'])) {
             $qry = "UPDATE options SET {$qry_data} WHERE `id` = " . $_args['id'];
             // var_dump($qry);
         } else {
             $qry = "UPDATE options\n\t\t\t\t\tSET {$qry_data}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`option_cat`   =" . $datarow['option_cat'] . " AND\n\t\t\t\t\t\t`option_key`   =" . $datarow['option_key'] . " AND\n\t\t\t\t\t\t`option_value` =" . $datarow['option_value'];
         }
         $result = \lib\db::query($qry);
         // if row is match then return true
         // this means row is same and data is duplicate or not
         // affecting row is not important in this condition
         if ($result && \lib\db::qry_info('Rows matched')) {
             return true;
         }
     }
     // create query string
     $qry = "INSERT INTO options ( {$qry_fields} ) VALUES ( {$qry_values} );";
     // execute query
     $result = \lib\db::query($qry);
     // give last insert id
     $last_id = @mysqli_insert_id(\lib\db::$link);
     // if have last insert it return it
     if ($last_id) {
         return $last_id;
     }
     // return default value
     return false;
 }