Exemplo n.º 1
0
Arquivo: tools.php Projeto: ph7pal/mei
 public static function formatTime($date)
 {
     $thisyear = intval(zmf::time(NULL, 'Y'));
     $dateyear = intval(zmf::time($date, 'Y'));
     if ($thisyear - $dateyear > 0) {
         return zmf::time($date, 'Y-m-d H:i');
     }
     $thismo = intval(zmf::time(NULL, 'm'));
     $datemo = intval(zmf::time($date, 'm'));
     if ($thisyear == $dateyear && $thismo != $datemo) {
         return zmf::time($date, 'm-d H:i');
     }
     $timer = $date;
     $diff = zmf::now() - $timer;
     $thisto = intval(zmf::time(NULL, 'd'));
     $dateto = intval(zmf::time($date, 'd'));
     $day = $thisto - $dateto;
     $free = $diff % 86400;
     if ($day > 0) {
         if ($day > 7) {
             return zmf::time($date, 'n-j H:i');
         } elseif ($day == 1) {
             return "昨天 " . zmf::time($date, 'H:i');
         } elseif ($day == 2) {
             return "前天 " . zmf::time($date, 'H:i');
         } else {
             return $day . "天前";
         }
     } else {
         if ($free > 0) {
             $hour = floor($free / 3600);
             $free = $free % 3600;
             if ($hour > 0) {
                 return $hour . "小时前";
             } else {
                 if ($free > 0) {
                     $min = floor($free / 60);
                     $free = $free % 60;
                     if ($min > 0) {
                         return $min . "分钟前";
                     } else {
                         if ($free > 0) {
                             return $free . "秒前";
                         } else {
                             return '刚刚';
                         }
                     }
                 } else {
                     return '刚刚';
                 }
             }
         } else {
             return '刚刚';
         }
     }
 }
Exemplo n.º 2
0
        <p class="author">
            <?php 
$this->renderPartial('/common/_user', array('uid' => $data['uid'], 'uname' => $_uname, 'type' => 'l', 'lcss' => ''));
?>
            <?php 
echo Users::getUserClass($userInfo['sex']);
?>
        </p>
        <p>
            <span class="icon-calendar"></span>
            <?php 
echo zmf::time($data['startTime'], 'Y/m/d');
?>
            <span class="icon-arrow-right"></span>
            <?php 
echo zmf::time($data['endTime'], 'Y/m/d');
?>
        </p>
        <p>
            <span class="icon-map-marker"></span>
            <?php 
echo $areaInfo['title'];
?>
            <span class="icon-exchange"></span>
            <?php 
echo $toAreaInfo['title'];
?>
        </p>
        <p>
            说明:<?php 
echo zmf::filterOutput($data['content'], true);
Exemplo n.º 3
0
?>
:</b>
	<?php 
echo CHtml::encode($data->content);
?>
	<br />
	<b><?php 
echo CHtml::encode($data->getAttributeLabel('type'));
?>
:</b>
	<?php 
echo CHtml::encode($data->type);
?>
	<br />        
	<b><?php 
echo CHtml::encode($data->getAttributeLabel('ip'));
?>
:</b>
	<?php 
echo long2ip($data->ip);
?>
	<br />
	<b><?php 
echo CHtml::encode($data->getAttributeLabel('cTime'));
?>
:</b>
	<?php 
echo zmf::time($data->cTime);
?>
	<br />
</div>
Exemplo n.º 4
0
 public function log($content = '')
 {
     if (zmf::config('appRuntimeLog')) {
         if (!$content) {
             $content = '##' . zmf::time() . '===' . ('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']) . PHP_EOL;
             $content .= microtime(true) - $this->startTime . PHP_EOL;
             $content .= var_export($_POST, true) . PHP_EOL;
             $content .= str_repeat('-', 40);
         }
         file_put_contents(Yii::app()->basePath . '/runtime/appTimes.txt', $content . PHP_EOL, FILE_APPEND);
     }
 }
Exemplo n.º 5
0
    /**
     * 生成站点地图
     */
    public function actionSitemap()
    {
        if (!zmf::uid()) {
            $this->redirect(zmf::config('domain'));
        }
        $a = $_GET['a'];
        $basedir = Yii::app()->basePath . '/../attachments/sitemap/';
        zmf::createUploadDir($basedir);
        $total = Chengyu::model()->count('status=' . Posts::STATUS_PASSED);
        $perFileNum = 1000;
        //每个文件的连接数
        $now = zmf::time('', 'Y-m-d');
        $page = isset($_GET['page']) ? $_GET['page'] : 1;
        if ($a == 'indexer') {
            $dir = $basedir . 'indexer.xml';
            $str = '';
            for ($i = 1; $i <= $total / $perFileNum + 1; $i++) {
                $str .= "<sitemap><loc>http://ciyuxinjie.org/attachments/sitemap/sitemap{$i}.xml</loc><lastmod>{$now}</lastmod></sitemap>";
            }
            $content = <<<SITEMAP
<?xml version="1.0" encoding="UTF-8"?>

<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">{$str}</sitemapindex>

SITEMAP;
            file_put_contents($dir, $content);
            exit;
        } elseif ($a == 'create') {
            $criteria = new CDbCriteria();
            $criteria->condition = 'status=' . Posts::STATUS_PASSED;
            $criteria->select = 'id';
            $criteria->order = 'id ASC';
            $criteria->limit = $perFileNum;
            $criteria->offset = ($page - 1) * $perFileNum;
            $items = Chengyu::model()->findAll($criteria);
            if (!empty($items)) {
                foreach ($items as $v) {
                    $str .= "<url><loc>http://ciyuxinjie.org/detail/{$v['id']}</loc><lastmod>{$now}</lastmod><changefreq>weekly</changefreq><priority>0.8</priority></url>";
                }
                $dir = $basedir . "sitemap{$page}.xml";
                $content = <<<SITEMAP
<?xml version='1.0' encoding='UTF-8'?>

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">{$str}</urlset>
SITEMAP;
                file_put_contents($dir, $content);
                $this->message(1, "正在处理{$page}页", Yii::app()->createUrl('site/sitemap', array('a' => 'create', 'page' => $page + 1)));
            } else {
                exit('well done');
            }
        } else {
            exit('不允许的操作');
        }
    }
Exemplo n.º 6
0
 /**
  * 写评论
  */
 public function actionComment()
 {
     if (!Yii::app()->request->isAjaxRequest) {
         $this->jsonOutPut(0, Yii::t('default', 'forbiddenaction'));
     }
     if (Yii::app()->user->isGuest) {
         $this->jsonOutPut(2, Yii::t('default', 'loginfirst'));
     } else {
         $uid = zmf::uid();
     }
     $checkInfo = UserPower::check('addComment', true);
     if (!$checkInfo['status']) {
         $this->jsonOutPut(0, $checkInfo['msg']);
     }
     $keyid = zmf::filterInput($_POST['k']);
     $to = zmf::filterInput($_POST['to']);
     $type = zmf::filterInput($_POST['t'], 't', 1);
     $content = zmf::filterInput($_POST['c'], 't', 1);
     if (!isset($type) or !in_array($type, array('attachments', 'posts', 'poipost', 'poitips', 'question', 'answer', 'yueban', 'goods'))) {
         $this->jsonOutPut(0, Yii::t('default', 'forbiddenaction'));
     }
     if (!isset($keyid) or !is_numeric($keyid)) {
         $this->jsonOutPut(0, Yii::t('default', 'pagenotexists'));
     }
     if (!$content) {
         $this->jsonOutPut(0, '评论不能为空哦~');
     }
     $status = Posts::STATUS_PASSED;
     //判断是否应被禁止
     //        $forbidInfo = Posts::isForbidden($content, 'comment');
     //        if ($forbidInfo['status'] != Posts::STATUS_PASSED) {
     //            //todo,增加用户非法操作次数
     //            $status = Posts::STATUS_STAYCHECK;
     //        }
     //处理文本
     $filter = Posts::handleContent($content);
     $content = $filter['content'];
     if (Yii::app()->session['checkHasBadword'] == 'yes') {
         $status = Posts::STATUS_STAYCHECK;
     }
     $model = new Comments();
     $ainfo = Posts::getSimpleInfo(array('keyid' => $keyid, 'origin' => strtolower($type)));
     if (!$ainfo) {
         $this->jsonOutPut(0, Yii::t('default', 'contentnotexists'));
     }
     $toNotice = true;
     if ($ainfo['uid'] == $uid) {
         $toNotice = false;
     }
     //当为商品评论且不是回复某人时,不提醒发布商品的人
     if ($type == 'goods' && !$to) {
         $toNotice = false;
     }
     $touid = $ainfo['uid'];
     if ($to) {
         $comInfo = Posts::getSimpleInfo(array('keyid' => $to, 'origin' => 'comments'));
         if (!$comInfo || $comInfo['status'] != Posts::STATUS_PASSED) {
             $to = '';
         } elseif ($comInfo['uid'] == $uid) {
             $toNotice = false;
         } else {
             $touid = $comInfo['uid'];
             $toNotice = true;
         }
     }
     $intoData = array('logid' => $keyid, 'uid' => $uid, 'content' => $content, 'cTime' => zmf::now(), 'classify' => $type, 'platform' => $this->platform, 'tocommentid' => $to, 'status' => $status);
     unset(Yii::app()->session['checkHasBadword']);
     $model->attributes = $intoData;
     if ($model->validate()) {
         if ($model->save()) {
             if ($type == 'answer') {
                 Answer::model()->updateCounters(array('comments' => 1), 'id=:id', array(':id' => $keyid));
                 $_url = CHtml::link('查看详情', array('question/answer', 'id' => $keyid, '#' => 'pid-' . $model->id));
                 $_content = '您的回答有了新的评论,' . $_url;
             } elseif ($type == 'poitips') {
                 PoiTips::model()->updateCounters(array('comments' => 1), 'id=:id', array(':id' => $keyid));
                 $_url = CHtml::link('查看详情', array('question/answer', 'id' => $keyid, '#' => 'pid-' . $model->id));
                 $_content = '您的短评有了新的评论,' . $_url;
             } elseif ($type == 'poipost') {
                 $_url = CHtml::link('查看详情', array('poipost/view', 'id' => $keyid, '#' => 'pid-' . $model->id));
                 PoiPost::model()->updateCounters(array('comments' => 1), 'id=:id', array(':id' => $keyid));
                 $_content = '您的点评有了新的评论,' . $_url;
             } elseif ($type == 'question') {
                 $_url = CHtml::link('查看详情', array('question/view', 'id' => $keyid, '#' => 'pid-' . $model->id));
                 Question::model()->updateCounters(array('comments' => 1), 'id=:id', array(':id' => $keyid));
                 $_content = '您的提问有了新的评论,' . $_url;
             } elseif ($type == 'posts') {
                 $_url = CHtml::link('查看详情', array('posts/index', 'id' => $keyid, '#' => 'pid-' . $model->id));
                 Posts::model()->updateCounters(array('comments' => 1), 'id=:id', array(':id' => $keyid));
                 $_content = '您的文章有了新的评论,' . $_url;
             } elseif ($type == 'attachments') {
                 $_url = CHtml::link('查看详情', array('attachments/view', 'id' => $keyid, '#' => 'pid-' . $model->id));
                 Attachments::model()->updateCounters(array('comments' => 1), 'id=:id', array(':id' => $keyid));
                 $_content = '您的图片有了新的评论,' . $_url;
             } elseif ($type == 'yueban') {
                 $_url = CHtml::link('查看详情', array('yueban/index', 'areaid' => $ainfo['toAreaid'], 'year' => zmf::time($ainfo['startTime'], 'Y'), 'month' => zmf::time($ainfo['startTime'], 'm'), 'day' => zmf::time($ainfo['startTime'], 'd')));
                 Posts::updateCount($keyid, 'UserYueban', 1, 'comments');
                 $_content = '您的约伴有了新的评论,' . $_url;
             } elseif ($type == 'goods') {
                 $_url = CHtml::link('查看详情', array('goods/detail', 'id' => $keyid, '#' => 'pid-' . $model->id));
                 Posts::updateCount($keyid, 'Goods', 1, 'comments');
                 $_content = '您的产品有了新的评论,' . $_url;
             }
             if ($to && $_url) {
                 $_content = '您的评论有了新的回复,' . $_url;
             }
             if ($toNotice) {
                 $_noticedata = array('uid' => $touid, 'authorid' => $uid, 'content' => $_content, 'new' => 1, 'type' => 'comment', 'cTime' => zmf::now(), 'from_id' => $model->id, 'from_num' => 1);
                 Notification::add($_noticedata);
             }
             $html = $this->renderPartial('//comments/_comment', array('data' => $model), true);
             $this->jsonOutPut(1, $html);
         } else {
             $this->jsonOutPut(0, '新增评论失败');
         }
     } else {
         $this->jsonOutPut(0, '新增评论失败');
     }
 }