/** * @todo log try * @param int $type type of try * @return bool */ public function Log($type = 0) { // pre hook _hk('P' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $type); // make value $data = array('type' => 'iii', 'trylog_type' => $type, 'trylog_ip' => _ipi(), 'trylog_time' => time()); // send to insert in regiery return $this->db->Insert('trylog', $data); }
/** * * @param string $algo The algorithm (md5, sha1, whirlpool, etc) * @param string $data The data to encode * @return string The hashed/salted data */ public static function Create($algo, $data) { // pre hook _hk('P' . ':' . __CLASS__ . ':' . __FUNCTION__, __CLASS__, $algo, $data); $context = hash_init($algo, HASH_HMAC, HASH_KEY); hash_update($context, $data); $result = hash_final($context); // result hook _hk('R' . ':' . __CLASS__ . ':' . __FUNCTION__, __CLASS__, $result); return $result; }
/** * @todo render item and show form added items */ public function Render() { $result = ''; foreach ($this->item as $itm) { // replace item values in body $temp = str_replace('%text%', $itm['text'], self::$item_body); $temp = str_replace('%url%', $itm['link'], $temp); $result .= $temp; } // result hook _hk('R' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $result); echo $result; }
/** * send usual mail to any one * @param string $to mail addr * @param string $subject * @param string $message * @param string $from_name snder name * @param string $from_mail sender mail addr * @param string $reply reply mail * @return bool */ public static function SendMail($to, $subject, $message, $from_name = "Toos FrameWork", $from_mail = null, $reply = null) { // pre hook _hk('P' . ':' . __CLASS__ . ':' . __FUNCTION__, __CLASS__, $to, $subject, $from_name, $from_mail, $reply); if ($reply == null) { $reply = $from_mail; } $subject = "=?utf-8?b?" . base64_encode($subject) . "?="; $headers = "MIME-Version: 1.0\r\n"; $headers .= "From: =?utf-8?b?" . base64_encode($from_name) . "?= <" . $from_mail . ">\r\n"; $headers .= "Content-Type: text/plain;charset=utf-8\r\n"; $headers .= "Reply-To: {$reply}\r\n"; $headers .= "X-Mailer: PHP/" . phpversion(); $result = mail($to, $subject, $message, $headers); // result hook _hk('R' . ':' . __CLASS__ . ':' . __FUNCTION__, __CLASS__, $result); return $result; }
/** * show added notification * @global mixed $notifications notifications list */ public static function Show() { // pre hook _hk('P' . ':' . __CLASS__ . ':' . __FUNCTION__, __CLASS__); $icons['error'] = 'fa-times-circle'; $icons['warning'] = 'fa-exclamation-triangle'; $icons['info'] = 'fa-info-circle'; $icons['success'] = 'fa-check-circle'; $icons[''] = 'fa-dot-circle-o'; if (isset($_SESSION['notification']) && is_array($_SESSION['notification'])) { $result = null; foreach ($_SESSION['notification'] as $k => $notify) { $result .= "\t" . '<div class="notification ' . $notify['type'] . '"> <span class="fa ' . $icons[$notify['type']] . '"></span> ' . $notify['text'] . ' <span class="fa fa-close"></span> </div>'; unset($_SESSION['notification'][$k]); } } // result hook _hk('R' . ':' . __CLASS__ . ':' . __FUNCTION__, __CLASS__, $result); echo $result; }
/** * save dropwodn item position * @param int $id * @param int $parent * @param int $index * @return boolean */ public function SavePosition($id, $parent, $index) { // Pre hook _hk('P' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $id, $parent, $index); // save the current needed item position index and parant $data = array('dropdown_parent' => (int) $parent, 'dropdown_sort_index' => (int) $index); $this->Edit($id, $data); // increment index of after current item in this parant return $this->db->CustomQuery('UPDATE ' . DB_PREFIX . $this->table_name . ' SET ' . 'dropdown_sort_index = dropdown_sort_index + 1 ' . 'WHERE dropdown_sort_index >= ' . (int) $index . ' AND dropdown_id <> ' . (int) $id . ' AND dropdown_parent = ' . (int) $parent, array()); }
/** * @todo load css from cm public dir */ public function LoadTemplateCMCSS($css_name) { // pre hook _hk('P' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $css_name); $result = ''; foreach ($css_name as $name) { $result .= "\t" . '<link type="text/css" rel="stylesheet" href="' . UR_MP_ASSETS . 'template/' . $this->template . '/css/' . $name . '.css" />' . PHP_EOL; } $result .= PHP_EOL . PHP_EOL; // result hook _hk('R' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $result); echo $result; }
/** * get online user count * @return type */ public function OnlineCount() { $rs = $this->db->Select("SELECT COUNT(*) AS 'count' FROM %table% WHERE \n statistic_last_visit > " . (time() - ONLINE_LONG), array('statistic')); $result = $rs[0]['count']; // result hook _hk('R' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $result); return $result; }
/** * padd watter mark to image * @param string $source_image * @param string $watermark_text * @param string $destination_file */ public static function WatermarkImage($source_image, $watermark_text, $destination_file) { // pre hook _hk('P' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $source_image, $watermark_text, $destination_file); list($width, $height) = getimagesize($source_image); $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($source_image); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height); $black = imagecolorallocate($image_p, 0, 0, 0); $font = 'NanumBarunGothicBold.ttf'; $font_size = 10; imagettftext($image_p, $font_size, 0, 10, 20, $black, $font, $watermark_text); if ($destination_file != '') { imagejpeg($image_p, $destination_file, 100); } else { header('Content-Type: image/jpeg'); imagejpeg($image_p, null, 100); } imagedestroy($image); imagedestroy($image_p); }
public static function GetServerMemUsage() { try { $free = shell_exec('free'); $free = (string) trim($free); $free_arr = explode("\n", $free); $mem = explode(" ", $free_arr[1]); $mem = array_filter($mem); $mem = array_merge($mem); $result = round($mem[2] / $mem[1] * 100, 2); } catch (Exception $exc) { $result = 0; } _hk('R' . ':' . __CLASS__ . ':' . __FUNCTION__, __CLASS__, $result); return $result; }
/** * hijri date to time stamp * @param string $date date * @param string $time time clock * @return type */ public function Ism2Timestamp($date = null, $time = '00:00:00') { // Pre hook _hk('P' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $date, $time); if ($date != null) { list($jy, $jm, $jd) = explode('/', $date); } else { list($jy, $jm, $jd) = array(0, 0, 0); } $arr = $this->Ism2Ge($jy, $jm, $jd); $result = strtotime($arr[0] . '/' . $arr[1] . '/' . $arr[2] . ' ' . $time); // result hook _hk('R' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $result); return $result; }
public function FormFooter() { $result = '</form>' . PHP_EOL; // result hook _hk('R' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $result); return $result; }
/** * tag synchronizing * @param string $tag_list new tag lists * @param int $object_id * @param int $type * @return boolean */ public function Sync($tag_list, $object_id, $type) { // pre _hk('P' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $tag_list, $object_id, $type); // get new tags $new_tags = explode(',', $tag_list); // get old tags $old_tags = $this->TList($object_id, $type); // remove common tag with new and olds foreach ($new_tags as $key => $value) { if (($key2 = array_search($value, $old_tags)) !== false) { unset($old_tags[$key2]); unset($new_tags[$key]); } } // add all remaining new tags foreach ($new_tags as $tag) { $this->Add($tag, $object_id, $type); } // remove all remaining old tags foreach ($old_tags as $tag) { $this->Remove($tag, $object_id, $type); } $result = TRUE; // result hook _hk('R' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $result); return $result; }
/** * is key Exists * @param int $root root of key * @param string $key name * @return bool */ public function Exists($root, $key) { // pre hook _hk('P' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $root, $key); // sql $sql = "SELECT COUNT(*) AS 'count' FROM %table% WHERE \n registry_root = :registry_root AND registry_key = :registry_key ;"; // select $result = $this->db->Select($sql, array('registry'), array('type' => 'is', ":registry_root" => $root, ":registry_key" => $key)); if ($result[0]['count'] == 0) { $result_ = false; } else { $result_ = true; } // result hook _hk('R' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $result_); // retrun result return $result_; }
/** * Render and show menu * @param string $id menu id * @param string $class menu classes */ public function Render($id = 'TMenu', $class = '') { // pre hook _hk('P' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $id, $class); $result = '<ul class="' . $class . '" id="' . $id . '" >' . PHP_EOL; $this->_renderArray(); $result .= $this->_showList(0); $result .= '</ul>' . PHP_EOL; // result hook _hk('R' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $result); return $result; }
/** * @todo check is user login don't redirect * @return bool */ public static function IsLogin() { //check if seted session user user logined if (isset($_SESSION['MN_ID'], $_SESSION['MN_TYPE'], $_SESSION['MN_UA'], $_SESSION['MN_LK'])) { $result = TRUE; } else { $result = FALSE; } // result hook _hk('R' . ':' . __CLASS__ . ':' . __FUNCTION__, __CLASS__, $result); return $result; }
/** * render pagonation * @param int $acvtive_page */ public function RenderX($acvtive_page = '') { // pre hook _hk('P' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $acvtive_page); // get active page if ($acvtive_page == '' && isset($_GET['page'])) { $acvtive_page = intval($_GET['page']); } else { $acvtive_page = 1; } //$this->page_count = 100; // make prefix link $prefix = '?'; foreach ($this->allow_in_next_pages as $get_value) { if (isset($_GET[$get_value])) { $prefix .= $get_value . '=' . $_GET[$get_value] . "&"; } } $result = '<div class="pagination">'; // if greater than 1 show first and prv if ($acvtive_page > 1) { $result .= '<a href="' . $prefix . "page=" . 1 . '" title="' . 'اولین' . '" >' . '<<' . "</a> \n"; $result .= '<a href="' . $prefix . "page=" . ($acvtive_page - 1) . '" >' . 'قبلی' . "</a> \n"; } // if page count less than 10 . if ($this->page_count <= 10) { // show all page for ($i = 1; $i <= $this->page_count; $i++) { if ($i != $acvtive_page) { $result .= '<a href="' . $prefix . "page=" . $i . '" >' . $i . "</a> \n"; } else { $result .= '<a class="actived">' . $i . "</a> \n"; } } } else { // more than 10 page switch ($acvtive_page) { // if active page less than 7 case $acvtive_page < 7: for ($i = 1; $i <= $acvtive_page + 3; $i++) { if ($i != $acvtive_page) { $result .= '<a href="' . $prefix . "page=" . $i . '" >' . $i . "</a> \n"; } else { $result .= '<a class="actived">' . $i . "</a> \n"; } } // show over flow $result .= '<a href="overflow-last" >' . '...' . "</a> \n"; $result .= '<div class="overflow" id="overflow-last">'; for ($i = $acvtive_page + 4; $i < $this->page_count; $i++) { $result .= '<a href="' . $prefix . "page=" . $i . '" >' . $i . "</a> \n"; } $result .= '</div>'; break; // if active page in last 5 page // if active page in last 5 page case $acvtive_page > $this->page_count - 5: // show overflows pages $result .= '<a href="overflow-first" >' . '...' . "</a> \n"; $result .= '<div class="overflow" id="overflow-first">'; for ($i = 1; $i < $acvtive_page - 3; $i++) { $result .= '<a href="' . $prefix . "page=" . $i . '" >' . $i . "</a> \n"; } $result .= '</div>'; for ($i = $acvtive_page - 3; $i <= $this->page_count; $i++) { if ($i != $acvtive_page) { $result .= '<a href="' . $prefix . "page=" . $i . '" >' . $i . "</a> \n"; } else { $result .= '<a class="actived">' . $i . "</a> \n"; } } break; default: // else not in 5 first page or 5 last page $result .= '<a href="overflow-first" >' . '...' . "</a> \n"; $result .= '<div class="overflow" id="overflow-first">'; for ($i = 1; $i < $acvtive_page - 3; $i++) { $result .= '<a href="' . $prefix . "page=" . $i . '" >' . $i . "</a> \n"; } $result .= '</div>'; for ($i = $acvtive_page - 3; $i <= $acvtive_page + 3; $i++) { if ($i != $acvtive_page) { $result .= '<a href="' . $prefix . "page=" . $i . '" >' . $i . "</a> \n"; } else { $result .= '<a class="actived">' . $i . "</a> \n"; } } $result .= '<a href="overflow-last" >' . '...' . "</a> \n"; $result .= '<div class="overflow" id="overflow-last">'; for ($i = $acvtive_page + 4; $i < $this->page_count; $i++) { $result .= '<a href="' . $prefix . "page=" . $i . '" >' . $i . "</a> \n"; } $result .= '</div>'; break; } } // if not last page show last and next if ($acvtive_page < $this->page_count) { $result .= '<a href="' . $prefix . "page=" . ($acvtive_page + 1) . '" >' . 'بعدی' . "</a> \n"; $result .= '<a href="' . $prefix . "page=" . $this->page_count . '" title="' . 'آخرین' . '" >' . '>>' . "</a> \n"; } $result .= '</div>'; // result hook _hk('R' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $result); return $result; }
/** * render listview and show * @param string $location base of controller class name */ public function Render($location = '') { $date_format = 'Y/m/d H:i'; // pre hook _hk('P' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $location, $date_format); $date = TDate::GetInstance(); $result = null; // show saerch or item if ($this->search != null || $this->relation != array()) { $result .= '<div class="listview-search row" action="' . UR_MP . $location . '" >'; // show search here if ($this->search != null) { // die($prefix); $result .= '<form class="grd12" action="' . UR_MP . $location . '">'; $result .= '<input type="text" name="search" class="search-box" placeholder="' . _lg('Search') . '..." />'; $result .= '<input type="hidden" name="fields" class="search-fields" value="' . $this->search . '" />'; if (isset($_GET['filter'])) { $result .= '<input type="hidden" name="filter" value="' . $_GET['filter'] . '" />'; } $result .= ' <button><span class="fa fa-search"></span></button>'; if (isset($_GET['search']) && $_GET['search'] != '') { $result .= ' <button onclick="$(this).parent().find(\'.search,.search-fields\').remove();"><span class="fa fa-close"></span></button>'; } $result .= '</form>'; } // relation info if ($this->relation != array()) { $md = new TModel($this->relation['table']); $result .= '<form class="grd12 " action="' . UR_MP . $location . '">' . ($this->relation['ico'] != '' ? '<span class="fa fa-' . $this->relation['ico'] . '"></span>' : '') . '<select name="rel" class="rel">'; $result .= '<option value="0" >' . _lg('Select an item to search') . '</option>'; foreach ($md->Selectable($this->relation['title'], $this->relation['value']) as $item) { $result .= '<option value="' . $item[0] . '" ' . (isset($_GET['rel']) && $_GET['rel'] == $item[0] ? 'selected="selected"' : '') . ' >' . $item[1] . '</option>'; } $result .= '</select>'; $result .= '<input type="hidden" name="typ" class="rel-type" value="' . $this->relation['rel_type'] . '" />'; $result .= ' <button><span class="fa fa-search"></span></button>'; if (isset($_GET['rel']) && $_GET['rel'] != '') { $result .= ' <button onclick="$(this).parent().find(\'.rel,.rel-type\').remove();"><span class="fa fa-close"></span></button>'; } $result .= '</form>'; } $result .= '</div>'; } // show all filter here if ($this->filter['title'] != array()) { $result .= '<div class="filter">'; // get prefix $prefix = GetLinkPrefix('filter'); // show title and no filter item named "All"; $result .= '<span> ' . _lg('Filter') . ': </span> <a class="button" href="' . $prefix . '"> ' . _lg('All') . '</a>'; // show filter lisr foreach ($this->filter['title'] as $key => $value) { $result .= '<a class="button" href="' . $prefix . 'filter=' . $this->filter['key'][$key] . ',' . $this->filter['value'][$key] . '">' . $value . '</a>'; } $result .= '</div>'; } // get order by column $prefix = GetLinkPrefix('order,desc'); // get id order and choose good value for this if (isset($_GET['order']) && $_GET['order'] == $this->id) { $id_order = $prefix; } else { $id_order = $prefix . 'order=' . $this->id; } // show form head here when have bulk action if ($this->bulk_action['title'] != array()) { $result .= '<form method="post" action="' . UR_MP . $location . '/BulkAction">'; } //start render listview header // start with bulk action checkbox and id header $result .= '<ul class="listview"> <li class="pinned animate"> <div class="row"> <div class="grd1"> <input type="checkbox" class="checkall" /> </div> <a href="' . $id_order . '"><div class="grd2 header"> ' . _lg('no.') . ' </div></a>'; // show header column title foreach ($this->column['title'] as $key => $value) { if (substr($this->column['key'][$key], 0, 1) == '%') { $col_name = substr($this->column['key'][$key], 2); } else { $col_name = $this->column['key'][$key]; } $result .= '<a href="' . $prefix . 'order=' . $col_name . (!isset($_GET['desc']) && isset($_GET['order']) && $_GET['order'] == $col_name ? '&desc=1' : '') . '"><div class="grd' . $this->column['size'][$key] . '">' . $value . '</div></a>'; } // action haader $result .= '<div class="grd' . $this->action['size'] . '"> </div>'; $result .= '</div> </li>'; // show all records in this page foreach ($this->assoc_list as $record) { //start with bulk action checkbox and id $result .= '<li> <div class="row">'; $result .= '<div class="grd1">' . PHP_EOL . ' <input type="checkbox" ' . 'class="listview-checkbox" name="id[]" value="' . $record[$this->id] . '" />' . PHP_EOL . ' </div>' . PHP_EOL; $result .= '<div class="grd2"> ' . $record[$this->id] . ' </div>'; // show record columns added before by size foreach ($this->column['key'] as $key => $value) { if (strpos($value, ',') == false) { $result .= PHP_EOL . '<div class="grd' . $this->column['size'][$key] . '">' . PHP_EOL; switch (substr($value, 0, 2)) { case '%i': $a = substr($value, 2); $result .= long2ip($record[$a]); break; case '%t': $a = substr($value, 2); $result .= $date->PDate($date_format, $record[$a]); break; // show array // show array case '%a': $a = substr($value, 2); $v = explode('|', $a); $arr = $v[0]; global ${$arr}; $array = ${$arr}; $result .= $array[$record[$v[1]]]; break; case '%1': case '%2': case '%3': case '%4': case '%5': case '%6': case '%7': case '%8': case '%9': $p = substr($value, 1, 1); $a = substr($value, 2); $result .= sprintf($this->pattren[$p], $record[$a]); break; default: $result .= $record[$value]; break; } $result .= '</div>' . PHP_EOL; } else { $temp = explode(',', $value); $result .= PHP_EOL . '<div class="grd' . $this->column['size'][$key] . '">'; foreach ($temp as $col) { $result .= $record[$col] . PHP_EOL; } $result .= '</div>' . PHP_EOL; } } // add action to record $result .= PHP_EOL . '<div class="grd' . $this->action['size'] . ' c' . ($this->action['class'] == '' ? '' : $record[$this->action['class']]) . '">'; $tmp = str_replace("%id%", $record[$this->id], $this->action['pattern']); if ($this->id == 'comment_id') { $result .= str_replace("%topic%", $record['comment_topic_id'], $tmp); } else { $result .= $tmp; } $result .= '</div>' . PHP_EOL; $result .= '</div>' . PHP_EOL . '</li>' . PHP_EOL; } $result .= '</ul>' . PHP_EOL; // if have bulk action show this after list view if ($this->bulk_action['title'] != array()) { $result .= '<div class="bulk-action"> <select name="action">'; // list of bulk actions foreach ($this->bulk_action['function'] as $key => $value) { $result .= '<option value="' . $value . ',' . $this->bulk_action['value'][$key] . '">' . $this->bulk_action['title'][$key] . '</option>'; } $result .= '</select>'; $result .= '<input type="submit" value="' . _lg('Bulk apply') . '" />' . '<div class="left" > ' . '<input type="button" value="' . _lg('Check All') . '" class="chkall" data-chekbox="listview-checkbox" /> ' . '<input type="button" value="' . _lg('Check None') . '" class="chknone" data-chekbox="listview-checkbox" /> ' . '<input type="button" value="' . _lg('Check Toggle') . '" class="chktoggle" data-chekbox="listview-checkbox" /> ' . '</div>' . '</div>' . '</form>'; } // result hook _hk('R' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $result); echo $result; }
/** * Get categories of a destination * @param int $destination destination id * @param int $type */ public function GetCategories($destination, $type = RELATION_CATEGORY) { // Pre hook _hk('P' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $destination, $type); $rel = TRelation::GetInstance(); $sources = $rel->GetByDestination($destination, $type); $result = $this->GetCheckedCategories($sources); // result hook _hk('R' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $result); return $result; }
/** * save force by take and folder file * @param string $file_name $_FILES array key * @param string $dir directory in upload folder * @param int|string $id file id * @param bool $allow_overwrite * @param bool $is_visitor * @return mixed file upload result */ public function SaveForce($file_name, $dir, $id, $allow_overwrite = true, $is_visitor = FALSE) { // pre _hk('P' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $file_name, $dir, $id, $allow_overwrite, $is_visitor); $uploaded_file = ($is_visitor ? '' : '.') . './upload/' . $dir . '/' . $id . '.' . strtolower(pathinfo($_FILES[$file_name]["name"], PATHINFO_EXTENSION)); $result['success'] = $this->_save($file_name, $uploaded_file, $allow_overwrite); if ($result['success'] !== TRUE) { $result['value'] = $result['success']; $result['success'] = FALSE; } else { $result['value'] = $uploaded_file; } // result hook _hk('R' . ':' . __CLASS__ . ':' . __FUNCTION__, $this, $result); return $result; }
/** * @param string $class alternative class * return vistor browser icon * @uses awesome font */ public static function GetBrowerIcon($class = '') { // get os $bowser = self::DetectBrowser(); $result = '<span class="fa fa-' . strtolower($bowser) . ' ' . $class . '" title="' . self::DetectBrowser() . '" ></span>'; //result hook _hk('R' . ':' . __CLASS__ . ':' . __FUNCTION__, __CLASS__, $result); return $result; }
/** * @todo get value by key * @param int $key key of request * @return string translate value */ public static function Index($key) { // pre hook _hk('P' . ':' . __CLASS__ . ':' . __FUNCTION__, __CLASS__, $key); $result = self::$_lang[$key]; // result hook _hk('R' . ':' . __CLASS__ . ':' . __FUNCTION__, __CLASS__, $result); return $result; }