/** * Creates the global constructor used in user-land * @return Func */ static function getGlobalConstructor() { $Buffer = new Func('Buffer', function () { $self = new Buffer(); $self->init(func_get_args()); return $self; }); $Buffer->set('prototype', Buffer::$protoObject); $Buffer->setMethods(Buffer::$classMethods, true, false, true); return $Buffer; }
/** * Creates the global constructor used in user-land * @return Func */ static function getGlobalConstructor() { $Error = new Func(function ($str = null) { $error = new self($str); $error->stack = debug_backtrace(); return $error; }); $Error->set('prototype', self::$protoObject); $Error->setMethods(self::$classMethods, true, false, true); return $Error; }
/** * @param Func $function * @param bool $hack * * @return bool */ private function shouldWriteReturnType(Func $function, $hack) { $name = $function->getReflection()->getName(); if ($function->getReflection() instanceof \ReflectionMethod && in_array($name, ['__construct', '__destruct', '__clone'])) { return false; } $comment = $function->getReturnComment(); if (!$comment) { return false; } return $comment->getType() && $comment->getType()->getDeclaration($hack); }
/** * @param Func $function * @return SignatureData[] */ public function read(Func $function) { $params = array(); foreach ($function->reflection()->getParameters() as $param) { $data = new SignatureData(); $data->name = $param->getName(); $data->type = $this->getType($param); $data->default = $this->getDefault($param); $data->hasDefault = $param->isOptional(); $params[] = $data; } return $params; }
/** загрузка(сохранение/обновление) аватара * @param integer ID записи * @param boolean удалять предыдущий аватар * @return имя файла успешно загруженной аватары | false */ function update($nRecordID, $bDeletePrevious = false, $bDoUpdateQuery = false) { global $oDb; if ($nRecordID && !empty($_FILES) && $_FILES[$this->input]['error'] == UPLOAD_ERR_OK) { $oUpload = new Upload($this->input, false); $aImageSize = getimagesize($_FILES[$this->input]['tmp_name']); if ($oUpload->isSuccessfull() && $aImageSize !== FALSE && in_array($aImageSize[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) { if ($bDeletePrevious) { $this->delete($nRecordID, false); } $sExtension = func::image_type_to_extension($aImageSize[2], false); $sFilename = Func::generateRandomName($this->filenameLetters, true, true) . '.' . $sExtension; //проверяем размер файла if (!$oUpload->checkSize($this->maxsize)) { return false; } //создаем thumbnail $oThumb = new thumbnail($_FILES[$this->input]['tmp_name']); $oThumb->jpeg_quality(85); $oThumb->crop_proportionaly(1, 1, 'middle', 'center'); $oThumb->createTumbnail_if_more_then($this->path . $nRecordID . '_' . $sFilename, $this->width, $this->height, true); @unlink($_FILES[$this->input]['tmp_name']); if ($bDoUpdateQuery) { $oDb->execute("UPDATE {$this->table} \n SET {$this->fieldAvatar} =" . $oDb->str2sql($sFilename) . "\n WHERE {$this->fieldID} = {$nRecordID} "); } return $sFilename; } } return false; }
public static function signUp(array $data) { if (!$data) { return false; } if (!isset($data['last_login_time'])) { $data['last_login_time'] = time(); } if (!isset($data['last_login_ip'])) { $data['last_login_ip'] = Func::getIP(); } if (!isset($data['login_time'])) { $data['login_time'] = time(); } if (!isset($data['login_ip'])) { $data['login_ip'] = Func::getIP(); } if (!isset($data['create_time'])) { $data['create_time'] = time(); } $data['login_count'] = 1; $data['user_code'] = self::getNewUserCode(); $insertid = 0; DB::tranBegin(); $insertid = self::insert($data); DB::tranEnd(); return $insertid; }
/** * 合作机构基本信息 */ public function basicAction($uni_id) { //判断是否是ajax if ($this->request->isAjax()) { $validate = new \Validate(); $data['union_logo'] = $validate->getPost('union_logo'); //机构logo $data['union_name'] = $validate->getPost('union_name', \Validate::regex('/^[a-z0-9\\x{4e00}-\\x{9fa5}]{2,30}$/iu')); //机构名称 //验证参数 if ($validate->getMessage()) { $this->end(400); } //生成机构logo,缩略图 if ($data['union_logo']) { $data['union_logo'] = \Func::touchImg($data['union_logo'], 'union_logo'); //监测图片是否生成成功 if (!$data['union_logo']) { \FileUtil::getInstance()->unlink(UPLOAD_PATH . $data['union_logo']); $this->end(400); } } $this->end((new \Union())->updUnionBasic($this->session->get('id'), $uni_id, $data)); } //机构id $uni_id = (int) $uni_id; //获取基本数据 $basic = (new \Union())->getUnionBasic($uni_id); //加载js $this->assets->addJs('backend/mt-js/union.js'); $this->view->setVars(['uni_id' => $uni_id, 'basic' => $basic]); }
/** * 新增属性 */ public function newAction() { //检查是否是ajax请求 if ($this->request->isAjax()) { $validate = new \Validate(); $data['att_img'] = $validate->getPost('att_img', \Validate::base64()); //属性图 $data['att_name'] = $validate->getPost('att_name', \Validate::regex('/^[a-z0-9\\x{4e00}-\\x{9fa5}]{2,30}$/iu')); //属性名称 $data['att_sort'] = $validate->getPost('att_sort', \Validate::int()); //排序 //验证数据 if ($validate->getMessage()) { $this->end(400); } //生成学校logo,缩略图 $data['att_img'] = \Func::touchImg($data['att_img'], 'att_img'); //将生成的图片地址存入img,用户失败时删除 $img = [UPLOAD_PATH . $data['att_img'], UPLOAD_PATH . $data['att_img']]; //监测图片是否全部生成成功 if (!$data['att_img']) { \FileUtil::getInstance()->unlink($img); } //新增高校 $result = (new \Attribute())->addAttribute($this->session->get('id'), $data); if ($result != 200) { \FileUtil::getInstance()->unlink($img); } $this->end($result); } //加载所需js $this->assets->addJs('backend/mt-js/attribute-new.js'); }
public function init() { Yii::app()->user->opt_id = time() . rand(10000, 99999); Yii::app()->user->logNotice = array(); Func::validateURL(); $this->request = Yii::app()->request; }
/** * Smarty dateleft modifier plugin * * Type: modifier<br> * Name: dateleft<br> * Purpose: dateleft * @author battazo * @param string * @param string * @param interger * @param interger * @param string * @param string */ function smarty_modifier_dateleft($sDatetime, $getTime = false) { //get datetime if (!$sDatetime) { return false; } $date = Func::parse_datetime($sDatetime); // function dateDiff($dformat, $endDate, $beginDate) // { // $date_parts1 = explode($dformat, $beginDate); // $date_parts2 = explode($dformat, $endDate); // $start_date = gregoriantojd($date_parts1[0], $date_parts1[1], $date_parts1[2]); // $end_date = gregoriantojd($date_parts2[0], $date_parts2[1], $date_parts2[2]); // return $end_date - $start_date; // } // $date1="07/11/2003"; // $date2="09/04/2004"; // print "If we minus " . $date1 . " from " . $date2 . " we get " . dateDiff("/", $date2, $date1) . "."; // If we minus 07/11/2003 from 09/04/2004 we get 421. //$dob="08/12/1975"; //echo "If you were born on " . $dob . ", then today your age is approximately " . //round(dateDiff("/", date("m/d/Y", time()), $dob)/365, 0) . " years."; //If you were born on 08/12/1975, then today your age is approximately 30 years. smarty_modifier_datespent($sDatetime, $getTime); }
/** * @descrpition 修改 */ public function edit() { if (Request::getRequest('dosubmit', 'str')) { $jumpUrl = '/admin.php/itemdocmenu/edit/id-' . $this->param['id']; $fields = array(); $fields['name'] = Request::getRequest('name', 'str'); $fields['pid'] = Request::getRequest('pid', 'str'); $fields['in_out'] = Request::getRequest('in_out', 'str'); $fields['url'] = Request::getRequest('url', 'str'); $fields['item'] = strtolower(Request::getRequest('item', 'item')); if (empty($fields['name']) || empty($fields['item'])) { View::showAdminErrorMessage($jumpUrl, '未填写完成'); } $result = ItemDocMenuBusiness::editMenu($this->param['id'], $fields); if ($result) { View::showAdminMessage('/admin.php/itemdocmenu/lists', '修改成功'); } else { View::showAdminErrorMessage($jumpUrl, '修改失败'); } } $menuList = ItemDocMenuBusiness::getMenuList(); $menuList = Func::arrayKey($menuList); $blogMenuList = Func::categoryTree($menuList); $blogMenu = ItemDocMenuBusiness::getMenu($this->param['id']); View::assign('blogMenu', $blogMenu); View::assign('blogMenuList', $blogMenuList); View::showAdminTpl('item_doc_menu_edit'); }
/** * 数据库备份 */ public function backup() { set_time_limit(0); $data = array(); if ($_POST) { $backup_dir = BASEPATH . '../cache/backup/'; if (!is_dir($backup_dir)) { mkdir($backup_dir, '0777', true); } include dirname(__FILE__) . '/../../config/config.db.php'; $cfg = $db[$db['active_group']]; $is_export_student = intval($this->input->post('is_export_student')); $sql_file = DbmanageModel::backupTables($cfg['database'], $backup_dir, array('*'), $is_export_student); if (file_exists($backup_dir . $sql_file)) { require_once APPPATH . 'libraries/Pclzip.php'; $save_file = $backup_dir . "/zmte_database.zip"; if (is_file($save_file)) { @unlink($save_file); } $archive = new PclZip($save_file); //将文件进行压缩 $archive->create($backup_dir . $sql_file, PCLZIP_OPT_REMOVE_ALL_PATH); @unlink($backup_dir . $sql_file); Func::dumpFile('application/zip', $save_file, 'zmte_database_' . date('YmdHis') . '.zip'); @unlink($save_file); redirect('/admin/dbmanage/backup'); } else { message('数据库备份失败,请稍后重试!'); } } else { $this->load->view('dbmanage/backup', $data); } }
/** * 回答接口 */ public function addAction() { //取值,参数验证,签名验证 $vars = ['mem_id', 'mem_mark', 'empty_ans_id', 'mem_relation_id', 'que_id', 'ans_content', 'is_img', 'sign']; $this->beforeGetVarExecVerify($vars, 'post'); //判断是否是图片 if ($this->data['is_img'] == 1) { $this->data['ans_content'] = \Func::touchImg($this->data['ans_content'], 'ans'); if (!$this->data['ans_content']) { $this->throwMessage(ILLEGAL_IMAGE); } } //默认执行回答提问方法 $func = 'addAnswer'; //需要的字段 $field = ['mem_id', 'mem_mark', 'mem_relation_id', 'que_id', 'ans_content']; //根据可空回答id,empty_ans_id判断是否执行追问方法 if ($this->data['empty_ans_id']) { array_push($field, $this->data['empty_ans_id']); $func = 'addAnswerAsk'; } //转义回答内容 $this->data['ans_content'] = mb_substr(\Func::escape($this->data['ans_content']), 0, 250, 'utf-8'); //获取执行状态,执行失败,并且是图片信息,则删除上传的图片 $add_status = $this->callModelFunc('Answer', $func, $field); if ($add_status != OK && $this->data['is_img'] == 1) { \FileUtil::getInstance()->unlink(PUBLIC_PATH . $this->data['ans_content']); } $this->throwMessage($add_status); }
/** @return Table */ function toTable() { $zcoeffs = array(); foreach ($this->function->getSet() as $var => $coeff) { $zcoeffs[$var] = $coeff->multiply(-1); } $z = new ValueFunc($zcoeffs, 0); $z2b = Fraction::create(0); $z2coeffs = array(); foreach ($this->restrictions as $idx => $r) { foreach ($r->getSet() as $var => $coeff) { if (strncmp($var, 'y', 1) === 0 && $coeff->isEqualTo(1)) { foreach ($r->getSet() as $v => $c) { !isset($z2coeffs[$v]) && ($z2coeffs[$v] = Fraction::create(0)); strncmp($v, 'y', 1) !== 0 && ($z2coeffs[$v] = $z2coeffs[$v]->subtract($c)); } $z2b = $z2b->subtract($r->getLimit()); } } } $z2 = count($z2coeffs) ? new ValueFunc($z2coeffs, $z2b) : NULL; $table = new Table($z, $z2); foreach ($this->basismap as $var => $idx) { $table->addRow(new TableRow($var, $this->restrictions[$idx]->getSet(), $this->restrictions[$idx]->getLimit())); } return $table; }
public function __construct($wrapped, $params) { $this->order = empty($params[0]) ? 1 : -1; $case = !empty($params[1]); $nat = !empty($params[2]); $this->fn = $case ? $nat ? 'strnatcasecmp' : 'strcasecmp' : ($nat ? 'strnatcmp' : 'strcmp'); parent::__construct($wrapped, $params); }
function init() { $errno = strip_tags(Func::GETPOST('errno')); if ($errno) { $this->set($errno); $this->sm->assign('errno', $errno); } }
/** * Creates the global constructor used in user-land * @return Func */ static function getGlobalConstructor() { $String = new Func(function ($value = '') { $self = Func::getContext(); if ($self instanceof Str) { $self->value = to_string($value); return $self; } else { return to_string($value); } }); $String->instantiate = function () { return new Str(); }; $String->set('prototype', Str::$protoObject); $String->setMethods(Str::$classMethods, true, false, true); return $String; }
/** * Creates the global constructor used in user-land * @return Func */ static function getGlobalConstructor() { $Boolean = new Func(function ($value = false) { $self = Func::getContext(); if ($self instanceof Bln) { $self->value = $value ? true : false; return $self; } else { return $value ? true : false; } }); $Boolean->instantiate = function () { return new Bln(); }; $Boolean->set('prototype', Bln::$protoObject); $Boolean->setMethods(Bln::$classMethods, true, false, true); return $Boolean; }
public static function call($kid, $queueName, $info, $mod = '', $action = 'run') { $queue = new CloudTaskQueue($queueName); $logtime = time(); $params = base64_encode(json_encode($info)); $key = Func::madeQueueKey($kid, $logtime, $params); $queue->addTask(QUEUE_URL, "mod={$mod}&action={$action}&kid={$kid}&logtime={$logtime}¶ms=" . urlencode($params) . "&key={$key}"); $ret = $queue->push(); return true; }
/** * * 构造函数 * @param $param 实例化时传入的参数 */ public function __construct($param = array()) { $this->param = $param; //分类菜单相关 $this->adminMenuObi = new AdminMenuModel(); $this->menuList = $this->adminMenuObi->getList(); $this->menuList = Func::arrayKey($this->menuList); $this->menuListTree = Func::categoryTree($this->menuList); View::assign('menuList', $this->menuListTree); }
/** * Smarty date_format2 modifier plugin * * Type: modifier<br> * Name: date_format2<br> * Purpose: date_format2 * @author battazo * @param string * @param string * @param interger * @param interger * @param string * @param string */ function smarty_modifier_date_format2($sDatetime, $getTime = false, $bSkipYearIfCurrent = false, $glue1 = ' ', $glue2 = ' в ') { if (!$sDatetime) { if (is_string($bSkipYearIfCurrent)) { return $bSkipYearIfCurrent; } return false; } $res = Func::parse_datetime($sDatetime); switch (intval($res['month'])) { case '1': $res['month'] = 'Января'; break; case '2': $res['month'] = 'Февраля'; break; case '3': $res['month'] = 'Марта'; break; case '4': $res['month'] = 'Апреля'; break; case '5': $res['month'] = 'Мая'; break; case '6': $res['month'] = 'Июня'; break; case '7': $res['month'] = 'Июля'; break; case '8': $res['month'] = 'Августа'; break; case '9': $res['month'] = 'Сентября'; break; case '10': $res['month'] = 'Октября'; break; case '11': $res['month'] = 'Ноября'; break; case '12': $res['month'] = 'Декабря'; break; default: break; } if ($getTime) { return intval($res['day']) . ' ' . $res['month'] . ($bSkipYearIfCurrent === true && date('Y', time()) == $res['year'] ? '' : $glue1 . $res['year']) . (!(int) $res['hour'] && !(int) $res['min'] ? '' : $glue2 . $res['hour'] . ':' . $res['min']); } else { return intval($res['day']) . ' ' . $res['month'] . ($bSkipYearIfCurrent === true && date('Y', time()) == $res['year'] ? '' : $glue1 . $res['year']); } }
/** * Function for Saving config module * * @access public * @param string $file file for config * @param string $config_var config varname * @param array $save_con config for save * @return void */ public static function SaveConfig($file, $config_var, array $save_con) { if (!is_writable($file)) { throw new ExceptionAllError("File {$file} is not for writable"); } self::$handler = fopen($file, "w"); fwrite(self::$handler, "<?php \n\${$config_var} = array (\n"); self::_save_conf($save_con); fwrite(self::$handler, ");\n?>"); fclose(self::$handler); }
/** * @descrpition 检测队列权限 * @return array|bool */ public static function checkQueueAuth() { $key = urldecode(Request::getRequest('key', 'str')); $kid = Request::getRequest('kid', 'str'); $logtime = Request::getRequest('logtime', 'str'); $params = urldecode(Request::getRequest('params', 'str')); if (empty($kid) || empty($key) || $key != Func::madeQueueKey($kid, $logtime, $params)) { return false; } $params = json_decode(base64_decode($params), true); return array('kid' => $kid, 'params' => $params); }
/** * Восстановление шаблона письма к состоянию по-умолчанию (из файла). * @param string $sTemplateKey(tpl) ключ шаблона */ function template_restore() { if (!$this->haveAccessTo('templates-edit')) { return $this->showAccessDenied(); } $sTemplateKey = Func::POSTGET('tpl', true); if (empty($sTemplateKey)) { $this->adminRedirect(Errors::IMPOSSIBLE, 'template_listing'); } $this->restoreMailTemplateFile($sTemplateKey); $this->adminRedirect(Errors::SUCCESSFULL, 'template_edit&tpl=' . $sTemplateKey); }
function load($skinname) { global $service; $this->url = "{$service['path']}/skin/$skinname/"; if(!file_exists(ROOT."/skin/$skinname/skin.html")) { Func::printError(_f('%1 스킨이 존재하지 않습니다.',$skinname),'error','admin'); } else { $this->output = file_get_contents(ROOT."/skin/$skinname/skin.html"); $this->output = str_replace('./', $this->url , $this->output); } }
/** * 手册首页 */ public function main() { $articleId = isset($this->param['aid']) ? $this->param['aid'] : 0; if (!$articleId) { $article = ItemDocArticleBusiness::getOneMostOld(); } else { //获取文章信息 $article = ItemDocArticleBusiness::getArticle($articleId); } if (empty($article)) { View::showErrorMessage(ITEM_DOMAIN, '内容丢掉了-.-'); } $articleId = $article['id']; $article['ctime'] = date('Y-m-d H:i:s', $article['ctime']); $article['tag'] = empty($article['tag']) ? '' : explode('|', $article['tag']); //获取该文章的评论 $commentList = ItemDocCommentBusiness::getCommentByAid($articleId); $commentList = Func::arrayKey($commentList); //将评论二级分类 foreach ($commentList as $key => $comment) { if ($comment['cid'] != 0) { $commentList[$comment['cid']]['son'][] = $comment; unset($commentList[$key]); } } //对文章进行处理,代码部分特殊显示. $article['content'] = preg_replace('/\\[code\\]/s', '<pre class="prettyprint linenums">', $article['content']); $article['content'] = preg_replace('/\\[\\/code\\]/s', '</pre>', $article['content']); //SEO的title,keywords,description $seo_title = $article['seo_title']; $seo_description = $article['seo_description']; $seo_keywords = $article['seo_keywords']; //文章的点击数+1 ItemDocArticleBusiness::clicks($articleId); //获取项目下的菜单列表 $itemMenuList = ItemDocMenuBusiness::getMenuListByItem(); $itemMenuList = Func::arrayKey($itemMenuList); //获取项目下的文章列表 $itemArticleList = ItemDocArticleBusiness::getListByItem(); foreach ($itemArticleList as $itemArticle) { if (isset($itemMenuList[$itemArticle['mid']])) { $itemMenuList[$itemArticle['mid']]['article_list'][] = $itemArticle; } } View::assign('itemMenuList', $itemMenuList); View::assign('seo_title', $seo_title); View::assign('seo_description', $seo_description); View::assign('seo_keywords', $seo_keywords); View::assign('commentList', $commentList); View::assign('article', $article); View::showFrontTpl('doc'); }
/** * * 构造函数 * @param $param 实例化时传入的参数 */ public function __construct($param = array()) { $this->param = $param; //分类菜单相关 $this->menuList = MenuBusiness::getMenuList(); $this->menuList = Func::arrayKey($this->menuList); $actionMenuId = 0; if (isset($param['mid']) && isset($this->menuList[$param['mid']])) { $actionMenuId = $param['mid']; } View::assign('actionMenuId', $actionMenuId); View::assign('menuList', $this->menuList); }
public static function getCurl($code, $no, $url) { if (function_exists('curl_init') == 1) { $result = Func::curlGet($url); } else { $snoopy = new Snoopy(); $snoopy->referer = 'http://www.baidu.com/'; //伪装来源 $snoopy->fetch($url); $result = $snoopy->results; } return $result; }
function get_info() { $res = $this->db->prepare("SELECT users.*,groups.title AS group_title\n FROM users\n LEFT JOIN groups ON groups.name=users.group\n WHERE users.id=?;"); $res->execute(array($this->arr['id'])); if ($row = $res->fetch()) { $row['reg_date'] = Func::unix2human($row['reg_time'], 'H:i <b>d.m.Y</b>'); foreach ($row as $key => $val) { $this->arr[$key] = $val; } return $row; } else { return false; } }
/** * All LVP related messages will pass through here, checked if there's * a command in there, and if so, the command will be executed depending * on the input. * * @param Bot $pBot The bot that received the message. * @param string $sChannel The channel we received this message in. * @param string $sNickname The nickname from which we got this message. * @param string $sMessage And of course the message itself. */ public function handle(Bot $pBot, $sChannel, $sNickname, $sMessage) { if ($sMessage[0] != '!') { return; } list($sTrigger, $sParams, $aParams) = Func::parseMessage($sMessage); $nLevel = $this->m_pModule->getChannelLevel($sChannel); try { $sOutput = $this->handleCommands(LVPCommand::MODE_IRC, $nLevel, $sChannel, $sNickname, $sTrigger, $sParams, $aParams); $this->processOutput($pBot, $sChannel, $sOutput, LVPCommand::MODE_IRC); } catch (Exception $pException) { echo 'Exception while executing command ' . $sTrigger . ': ' . $pException->getMessage(); } }