public function actionDemo() { $headers = get_headers('http://www.liangshan-online.com/public/uploadfiles/86991333899060.gif', 1); UtilHelper::dump($headers); UtilHelper::dump(date('Y-m-d H:i:s', strtotime($headers['Last-Modified']))); $this->render('demo'); }
/** * 函数名称:isChinese * 简要描述:检查是否输入为汉字 * 输入:string * 输出:boolean **/ public static function isChinese($str) { $words = UtilHelper::chineseSplit($str); foreach ($words as $word) { if (ord($word) < 224 || ord($word) > 240) { return false; } } return true; }
public static function sendMail($to, $subject, $message) { $transport = new Zend_Mail_Transport_Smtp('smtp.yuekegu.com', self::$_config); $mail = new Zend_Mail('UTF-8'); $mail->setHeaderEncoding(Zend_Mime::ENCODING_BASE64); $mail->setBodyHtml($message); $mail->setFrom('*****@*****.**', 'Administrator'); // $mail->addTo(Yii::app()->params['mail'], Yii::app()->params['author']); $mail->addTo($to, 'Receiver'); $mail->setSubject($subject); $mail->send($transport); UtilHelper::writeToFile($mail, 'a+'); }
public function actionIgnore() { ignore_user_abort(); //关掉浏览器,PHP脚本也可以继续执行. set_time_limit(0); // 通过set_time_limit(0)可以让程序无限制的执行下去 $interval = 10; // 每隔半小时运行 static $i = 1; do { //这里是你要执行的代码 UtilHelper::writeToFile(date('y/m/d h:i:s') . "\t i = " . $i++ . "\r\n", 'a+'); sleep($interval); // 等待5分钟 } while (true); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $this->layout = '//layouts/blank'; $model = new Channel(); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); if (isset($_POST['Channel'])) { $model->attributes = $_POST['Channel']; if ($model->save()) { echo UtilHelper::formatRightAnswer('频道创建成功'); die; // $this->redirect(array('view','id'=>$model->id)); } else { echo CHtml::errorSummary($model); die; } } $this->render('create', array('model' => $model)); }
/** * 此方法用于发布广告信息 */ public function actionRelease() { $this->layout = '//layouts/column1'; $model = new Advertisement(); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); if (isset($_POST['Advertisement'])) { $model->attributes = $_POST['Advertisement']; $model->start = strtotime($model->start); $model->end = strtotime($model->end); $model->hasimg = UtilMatch::hasImage($model->content); $model->imginfo = UtilMatch::getAllImageInfo($model->content); // UtilHelper::dump(UtilMatch::hasImage($model->content)); // UtilHelper::dump(UtilMatch::getAllImageInfo($model->content)); // UtilHelper::writeToFile($model->attributes); // // die(); $return = array(); if ($model->save()) { $return = array('status' => 'ok', 'data' => CHtml::link('继续添加广告', array('/archiver/release', 'uid' => $model->uid)) . CHtml::link('/查看刚发布的广告', array('/info/view', 'uid' => $model->uid, 'id' => $model->id))); } else { $return = array('status' => 'false', 'data' => CHtml::errorSummary($model)); } UtilHelper::writeToFile($return, 'a+'); echo json_encode($return); die; } $this->render('release', array('model' => $model)); }
public function actionRegister() { $this->layout = '//layouts/site'; $model = new RegisterForm(); // uncomment the following code to enable ajax-based validation if (isset($_POST['ajax']) && $_POST['ajax'] === 'register-form') { echo CActiveForm::validate($model); Yii::app()->end(); } if (isset($_POST['RegisterForm'])) { $model->attributes = $_POST['RegisterForm']; // UtilHelper::dump($model->attributes); if ($model->validate() && $model->register()) { Yii::app()->user->setFlash('register', '你是本站的第' . User::model()->count() . '位悦珂人'); $this->refresh(); // form inputs are valid, do something here // return; } else { UtilHelper::writeToFile(CHtml::errorSummary($model), 'a+'); } } $this->render('register', array('model' => $model)); }
public function actionTest2() { require 'Zend/Search/Lucene.php'; require 'Zend/Search/Lucene/Analysis/TokenFilter/StopWords.php'; Yii::import('application.helpers.search.*'); $str = "OK"; $analyzer = new Phpbean_Lucene_Analyzer(); $keywords = strtolower($str); $stopWords = array("a", "an", "at", "the", "and", "or", "is", "am"); $stopWordsFilter = new Zend_Search_Lucene_Analysis_TokenFilter_StopWords($stopWords); $analyzer = new Phpbean_Lucene_Analyzer(); $cnStopWords = array("的"); $analyzer->setCnStopWords($cnStopWords); $analyzer->addFilter($stopWordsFilter); $value = "this is a test二元分词是中文分词最简单的一种算法,就是把一个句子中相邻的两个字当作一个...就是读取数据库,然后分词建立二进制格式的索引保存在文件中"; $analyzer->setInput($value, "utf-8"); $position = 0; $tokenCounter = 0; while (($token = $analyzer->nextToken()) !== null) { $tokenCounter++; $tokens[] = $token->getTermText(); } UtilHelper::dump($tokens); }
public function actionForm() { $this->layout = '//layouts/basic'; $model = new Template(); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); if (isset($_POST['Template'])) { $model->attributes = $_POST['Template']; UtilHelper::writeToFile($_POST); UtilHelper::writeToFile($model->attributes, 'a+'); if ($model->save()) { // $this->redirect(array('view','id'=>$model->id)); echo "OK"; Yii::app()->end(); } else { UtilHelper::writeToFile(CHtml::errorSummary($model)); echo CHtml::errorSummary($model); Yii::app()->end(); } } $this->render('form', array('model' => $model)); }
/** * 获取用户图片上传目录信息 */ private function getUserAlbum($userID, $name, $type) { $model = Lookup::model()->find(array('condition' => 'uid = :uid AND type = :type', 'params' => array(':uid' => $userID, ':type' => $type))); if ($model == null) { $model = new Lookup(); $model->type = $type; $model->name = $name; $model->ename = Yii::app()->user->name . '_' . ucfirst(UtilHelper::words2PinYin($name)) . 'Album'; $model->weight = 1; $model->description = $name . '相关图册'; $model->save(); } return $model; }
/** * 根据用户ID获取用户头像路径 * @param unknown_type $id * @param unknown_type $size */ public function getUserAvatarPath($id, $size = 60) { $path = ''; $model = User::model()->findByPk($id); if ($model->profiles) { if ($model->profiles->birthyear) { $path = UtilHelper::getZodiacPath($model->profiles->birthyear); } if ($model->profiles->avatar) { $data = File::model()->findByPk($model->profiles->avatar); $originPath = File::model()->generateFileName($data, 'avatar', true, null); if (file_exists($originPath)) { $avatarPath = File::model()->generateFileName($data, 'avatar', false, $size); if (!file_exists('.' . $avatarPath)) { self::generateUserAvatars($data, $size); } $path = $avatarPath; } } } else { $path = Yii::app()->params->defaultAvatarPath; } return $path; }
public function actionTest() { UtilHelper::writeToFile($_GET); }
<?php foreach ($model as $info) { ?> <li> <a href="<?php echo $this->createUrl('/info/view/', array('id' => $info->id, 't' => urlencode($info->title))); ?> " title="<?php echo $info->title; ?> " class="span-4 adLatestTitle">[<?php echo UtilHelper::strSlice(Channel::model()->getChannelName($info->cid), 0, 4); ?> ]<?php echo UtilHelper::strSlice($info->title, 0, 4); ?> </a> <span class="span-8 adLatestDes"> <?php echo UtilHelper::strSlice(str_replace(' ', '', strip_tags($info->content)), 0, 20); ?> </span> <span class="span-2 adLatestDate"><?php echo date('Y-m-d', $info->update); ?> </span> </li> <?php }
echo CHtml::link(Profile::model()->getUserNickName($_GET['uid']), array('achiver/index', 'name' => $data->user->username, 'uid' => $data->uid)); ?> <span class="lightview">[<?php echo Channel::model()->getChannelName($data->cid); ?> ]</span> <?php echo CHtml::link(CHtml::encode($data->title), array('/info/view', 'uid' => $data->uid, 'id' => $data->id, 't' => urlencode($data->title)), array('target' => '_blank')); ?> <br /> <?php echo UtilHelper::timeFormat(intval($data->moddate)); ?> <br /> <br /> <?php echo UtilHelper::pureStrSlice($data->content, 0, 150); ?> <br /> <hr class="span-5 space" /> <a href="javascript:void();" xid="<?php echo $data->id; ?> " class="button right" onclick="showArticle($(this));">浏览全文</a> <a href="javascript:void();" class="right" onclick="">加入收藏</a> <input type="hidden" class="span-5" style="border:1px solid #e0e0e0;padding:5px;" /> </div> </div>
/** * Lists all models. */ public function actionIndex() { $model = Advertisement::model()->findAll(array('join' => '{{profile}}')); UtilHelper::dump($model); $dataProvider = new CActiveDataProvider('Job'); $this->render('index', array('dataProvider' => $dataProvider)); }
/** * Saves/Edits an deployment * */ public function postEdit($deployment = false) { $this->check(); try { if (empty($deployment)) { $deployment = new Deployment(); } else { if ($deployment->user_id !== Auth::id()) { throw new Exception('general.access_denied'); } } $deployment->name = Input::get('name'); $deployment->cloudAccountId = Input::get('cloudAccountId'); //Check if account credentials are valid $account = CloudAccountHelper::findAndDecrypt($deployment->cloudAccountId); if (!CloudProvider::authenticate($account)) { Log::error('Failed to authenticate before deployment! ' . json_encode($account)); return Redirect::to('deployment/')->with('error', 'Failed to authenticate before deployment! ' . $deployment->name); } $params = Input::get('parameters'); //$params['instanceImage'] = Input::get('instanceImage'); $arr = explode(':', Input::get('instanceAmi')); $params['instanceAmi'] = $arr[1]; $params['OS'] = $arr[0]; $deployment->parameters = json_encode($params); $deployment->docker_name = Input::get('docker_name'); $deployment->user_id = Auth::id(); // logged in user id try { // Get and save status from external WS $user = Auth::user(); $responseJson = xDockerEngine::authenticate(array('username' => $user->username, 'password' => md5($user->engine_key))); EngineLog::logIt(array('user_id' => Auth::id(), 'method' => 'authenticate', 'return' => $responseJson)); $obj = json_decode($responseJson); if (!empty($obj) && $obj->status == 'OK') { $deployment->token = $obj->token; $this->prepare($user, $account, $deployment); $responseJson = xDockerEngine::run(json_decode($deployment->wsParams)); EngineLog::logIt(array('user_id' => Auth::id(), 'method' => 'run', 'return' => $responseJson)); $obj1 = json_decode($responseJson); if (!empty($obj1) && $obj1->status == 'OK') { $deployment->job_id = $obj1->job_id; $deployment->status = Lang::get('deployment/deployment.status'); unset($deployment->token); $success = $deployment->save(); if (!$success) { Log::error('Error while saving deployment : ' . json_encode($deployment->errors())); return Redirect::to('deployment')->with('error', 'Error saving deployment!'); } } else { if (!empty($obj1) && $obj1->status == 'error') { Log::error('Failed during deployment!' . $obj1->fail_message); Log::error('Log :' . implode(' ', $obj2->job_log)); return Redirect::to('deployment')->with('error', 'Failed during deployment!' . $obj1->fail_message); } } UtilHelper::sendMail(Auth::user(), $account->name, $deployment, 'site/deployment/email', Lang::get('deployment/deployment.deployment_updated')); return Redirect::to('deployment')->with('success', Lang::get('deployment/deployment.deployment_updated')); } else { if (!empty($obj) && $obj->status == 'error') { Log::error('Failed to authenticate before deployment!' . $obj2->fail_code . ':' . $obj->fail_message); Log::error('Log :' . implode(' ', $obj2->job_log)); return Redirect::to('deployment')->with('error', 'Failed to authenticate before deployment!' . $obj->fail_message); } else { Log::error('error', 'Unexpected error - Backend Engine API should be down!'); return Redirect::to('ServiceStatus')->with('error', 'Backend API is down, please try again later!'); } } } catch (Exception $err) { $status = 'Unexpected Error: ' . $err->getMessage(); Log::error('Error while saving deployment : ' . $status); throw new Exception($err->getMessage()); } } catch (Exception $e) { Log::error('Error while saving deployment : ' . $e->getMessage()); return Redirect::back()->with('error', $e->getMessage()); } }
<ul> <?php foreach ($model as $data) { ?> <li class="right" style="margin:2px;text-align:center;width:54px;"> <?php UtilHelper::writeToFile($data->attributes, 'a+'); ?> <?php $avatar = Profile::model()->getUserAvatar($data->id, array('class' => 'left roundSection', 'style' => 'width:50px;margin:10px;padding:10px;'), 50); echo CHtml::link($avatar, array('/archiver/index', 'uid' => $data->id, 'name' => $data->username), array('title' => $data->username)); ?> <br /> <?php // echo UtilHelper::strlen_utf8($data->username)>=8?$data->username:UtilHelper::strSlice($data->username,0,5); ?> </li> <?php } ?> </ul>
public function getSPaceInfo() { $id = 'statistics_space'; $result = Yii::app()->cache->get($id); if ($result === false) { $directory = UtilHelper::getDirectorySize('./'); $all = $directory['size']; $directory = UtilHelper::getDirectorySize('./public/uploadfiles'); $uploadfiles = $directory['size']; $directory = UtilHelper::getDirectorySize('./public/uploads'); $uploadimage = $directory['size']; $upload = $uploadfiles + $uploadimage; $system = $all - $upload; $free = Yii::app()->params->fullSpace - $all; $result = array('all' => $all, 'upload' => $upload, 'system' => $system, 'free' => $free); Yii::app()->cache->set($id, $result, 36000, new CDirectoryCacheDependency('./public')); } return $result; }
return false; } var data = { 'Template[name]':\$("#Template_name").val(), 'Template[code]':formatTemplateCode(), 'Template[sorttype]':\$("#Template_sorttype").val(), 'Template[cname]':\$("#Template_cname").val() }; \$.post("{$submitUrl}",data,function(msg){ console.log(msg); if(msg == 'OK') uu.alert("操作提示","模板添加成功!"); else{ \$(".errorSummary").show().html(\$(msg).html()); } }); } SCRIPT; // Yii::app()->getClientScript()->registerScript('ext-create-CodeMirrorWidget',$script,CClientScript::POS_END); UtilHelper::writeToFile(Yii::app()->getClientScript());
public function actionTT() { UtilHelper::dump($_REQUEST); }
/** * * 根据模型,获取文件路径 * @param unknown_type $model * @param unknown_type $path * @param unknown_type $isUploadPath * @param unknown_type $width */ public function generateFileName($model, $path, $isUploadPath = true, $width = null) { $result = ''; if ($isUploadPath) { $result = '.'; } $result .= Yii::app()->params->uploadPath[$path]; $result .= date('Y', $model->created) . '/' . date('m', $model->created) . '/' . date('d', $model->created) . '/'; $result .= md5($model->name) . $model->created; if ($width) { $result .= '_'; } $result .= $width . '.' . $model->ext; if (!is_dir(dirname($result))) { UtilHelper::createFolder(dirname($result)); } return $result; }
<section class="span-19"> <h4 class="pageTitle">服务器参数</h4> <?php $log = new CFileLogRoute(); UtilHelper::dump($log->getLogFile()); ?> <ul id="sys-info"> <li>系统类型及版本号:<?php echo php_uname(); ?> </li> <li>服务器解译引擎:<?php echo $_SERVER['SERVER_SOFTWARE']; ?> </li> <li>域名:<?php echo $_SERVER["HTTP_HOST"]; ?> </li> <li>Zend 版本:<?php echo zend_version(); ?> </li> <li>PHP安装路径:<?php echo DEFAULT_INCLUDE_PATH; ?> </li> <li>可用扩展:<?php var_dump(extension_loaded('id3')); ?>
public function actionGetRemoteImage() { $url = isset($_POST['url']) ? $_POST['url'] : die('图片地址不正确~'); $info = UtilHelper::resourceLocalize($url); // UtilHelper::dump($info); $model = new File(); $model->name = $info['filename']; $model->ext = $info['extension']; $model->created = time(); $model->size = $info['size']; $model->pid = Lookup::model()->getUserAdThemeAlbum(Yii::app()->user->id)->id; $model->mime = File::model()->getMimeType($model->ext, $info['mime']); $src = './public/favorite/' . $model->name . '.' . $model->ext; $target = File::model()->generateFileName($model, 'adtheme', true); // UtilHelper::dump($model->attributes); if ($model->save()) { UtilFile::moveFile($src, $target); $result = array('id' => $model->id, 'path' => File::model()->generateFileName($model, 'adtheme', false)); echo json_encode($result); } }
<div class="left"> <?php if ($preview) { $string = strlen(strip_tags($preview->title)) ? strip_tags($preview->title) : date('y-m-d', $preview->create); ?> 前一篇:<?php echo CHtml::link(UtilHelper::strSlice($string, 0, $this->length), array($this->linkview, 'id' => $preview->id, 't' => urlencode($preview->title)), array('title' => $preview->title)); } else { ?> 已经是第一篇了! <?php } ?> </div> <div class="right"> <?php if ($next) { $string = strlen(strip_tags($next->title)) ? strip_tags($next->title) : date('y-m-d', $next->create); ?> 前一篇:<?php echo CHtml::link(UtilHelper::strSlice($string, 0, $this->length), array($this->linkview, 'id' => $next->id, 't' => urlencode($next->title)), array('title' => $next->title)); } else { ?> 已经是第一篇了! <?php } ?> </div>
public function generateJobLinks($pid, $link = '', $htmlOptions = array(), $addmore = true) { $links = ''; $model = self::getJobs($pid); foreach ($model as $item) { $htmlOptions['id'] = $item->id; $links .= CHtml::link($item->name, array($link, 'id' => $item->id), $htmlOptions); } UtilHelper::writeToFile($links); if ($addmore) { $links .= '<br />如果这里没有您所从事的工作,点这里' . CHtml::link('添加', 'javascript:void();', array('style' => 'border:none;', 'onclick' => 'addRegion();return false;')); } return $links; }
/** * * Get the visitors who have read this blog * @param int $id */ public function getArticleVisitors($id) { $model = self::model()->findAll(array('condition' => 'aid = ' . $id, 'order' => 'lasttime DESC')); UtilHelper::dump($model); return $model; }
<?php foreach ($model as $data) { UtilHelper::dump($data->attributes); }
/** * 获取格式化标签 * 供给archive/favorite,archiver/efavorite使用 * @param unknown_type $type * @param unknown_type $limit * @param unknown_type $offset * @param unknown_type $htmlOptions * @param unknown_type $url */ public function getTags($type, $limit = 10, $offset = 20, $htmlOptions = array(), $url = 'javascript:void();') { $cacheId = 'getTags_' . $type . '_' . $offset; $result = Yii::app()->cache->get($cacheId); if ($result === false) { if (!isset($htmlOptions['class'])) { $htmlOptions['class'] = 'select'; } $criteria = new CDbCriteria(); $criteria->condition = 'tid = ' . $type; $criteria->limit = $limit; $criteria->offset = $offset; $model = Tag::model()->findAll($criteria); if ($model == null) { $criteria->offset = 0; $model = Tag::model()->findAll($criteria); return '没有了~'; } foreach ($model as $tag) { $htmlOptions['id'] = 'tag-' . $tag->id; $result .= CHtml::link($tag->name, $url, $htmlOptions); // $result .= '<span>'.$tag->name.'</span>'; } Yii::app()->cache->set($cacheId, $result, 3600, new CDbCacheDependency("SELECT MAX(id) FROM {{tag}} WHERE tid = {$type}")); } UtilHelper::writeToFile($result); return $result; }
<div class="scrollItem" data-id="scroll-<?php echo $model->id; ?> "> <?php echo Profile::model()->getUserAvatar($model->uid, array('class' => 'left roundSection', 'style' => 'width:50px;padding:10px;'), 50); ?> <span style="color:red;font-weight:bold;"><?php echo $model->title; ?> </span> <?php echo UtilHelper::strSlice(str_replace(' ', '', strip_tags($model->content)), 0, 50); ?> </div>
}); //--> </script> <?php Channel::model()->showCategories($_GET['id'], 8); ?> <!-- <ul id="channelBox" class="image-grid"> <?php foreach ($model as $item) { ?> <li data-id="<?php echo UtilHelper::words2PinYin($item->name); ?> " class="<?php echo UtilHelper::words2PinYin(Channel::model()->getChannel(Channel::model()->getChannelModel($item->pid)->type)); ?> "> <?php echo CHtml::image(Channel::model()->getChannelIco($item->id), $item->name); ?> <?php echo $item->name . $item->id; ?> </li> <?php } ?> </ul> --> <?php