Exemplo n.º 1
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;
 }
Exemplo n.º 2
0
 public function view_child()
 {
     $mytable = $this->cpModule('table');
     $mychild = $this->child();
     // $this->global->js       = array($this->url->myStatic.'js/cp/medium-editor.min.js');
     $this->data->enum = \lib\sql\getTable::enumValues('posts');
     switch ($mytable) {
         case 'posts':
             // show list of tags
             $this->data->tagList = $this->model()->sp_term_list();
             // for each type of post
             switch ($this->cpModule('raw')) {
                 case 'pages':
                     $this->data->parentList = $this->model()->sp_parent_list();
                     break;
                 case 'polls':
                     $this->data->parentList = $this->model()->sp_parent_list(true, 'poll');
                     $this->data->catList = $this->model()->sp_cats('cat_poll');
                     break;
                 case 'attachments':
                     $this->data->maxSize = \lib\utility\upload::max_file_upload_in_bytes();
                     // $this->include->uploader      = true;
                     // array_push($this->global->js, $this->url->myStatic.'js/cp/uploader.js');
                     $this->data->catList = $this->model()->sp_cats('filecat');
                     $this->data->catListSelected = $this->model()->sp_cats('filecat', true);
                     break;
                 case 'books':
                     $this->data->catList = $this->model()->sp_cats('bookcat');
                     $this->data->catListSelected = $this->model()->sp_cats('bookcat', true);
                     $this->data->parentList = $this->model()->sp_parent_list(true, 'book');
                     break;
                 case 'socialnetwork':
                     $this->data->catList = null;
                     break;
                 default:
                     $this->data->catList = $this->model()->sp_cats();
                     break;
             }
             break;
         default:
             switch ($this->cpModule('raw')) {
                 case 'categories':
                 case 'pollcategories':
                 case 'filecategories':
                 case 'bookcategories':
                     $this->data->parentList = $this->model()->sp_category_list($this->cpModule('type'));
                     break;
             }
             $this->data->field_list = \lib\sql\getTable::get($mytable);
             $myform = $this->createform('@' . db_name . '.' . $mytable, $this->data->child);
             break;
     }
     // if module for users then fill permission list
     if ($this->cpModule('raw') === 'users') {
         $this->draw_users();
     }
     if ($mychild === 'edit') {
         $this->data->datarow = $this->model()->datarow($mytable, null, true);
         // set shortURL
         $this->data->shortURL = 'sp_' . \lib\utility\shortURL::encode($this->data->datarow['id']);
         if (isset($this->data->datarow['post_meta'])) {
             $this->data->datarow['post_meta'] = json_decode($this->data->datarow['post_meta'], true);
         }
         if ($this->cpModule('raw') === 'attachments') {
             if (isset($this->data->datarow['meta']['slug'])) {
                 $this->data->datarow['post_slug'] = $this->data->datarow['meta']['slug'];
             }
         }
         if ($mytable === 'posts') {
             // $this->data->datarow['post_content'] .= '<img src="/static/images/logo.png" />';
             // var_dump($this->data->datarow['post_content']);
             $url = $this->data->datarow['post_url'];
             $this->data->datarow['cat_url'] = substr($url, 0, strrpos($url, '/'));
             // if defaultlang and lang of the post is not the same then add lang to url
             $defaultLang = substr(\lib\utility\option::get('config', 'meta', 'defaultLang'), 0, 2);
             if ($defaultLang !== $this->data->datarow['post_language']) {
                 $this->data->datarow['post_url'] = $this->data->datarow['post_language'] . "/" . $this->data->datarow['post_url'];
             }
         }
     }
 }
Exemplo n.º 3
0
 /**
  * gnerate temp password
  */
 public static function temp_password($_num = null)
 {
     // alphabet
     $alphabet = '1234567890abcdefghijklmnopqrstuvwxyz';
     if (!$_num) {
         $_num = time() . rand(0, 9);
     }
     $rand = \lib\utility\shortURL::encode($_num, $alphabet);
     if (!$_num) {
         return "rand_" . $rand;
     }
     return $rand;
 }