예제 #1
0
파일: Content.class.php 프로젝트: jyht/v5
 public function add($data)
 {
     $ContentModel = ContentModel::getInstance($this->_mid);
     if (!isset($this->_model[$this->_mid])) {
         $this->error = '模型不存在';
     }
     $ContentInputModel = new ContentInputModel($this->_mid);
     $insertData = $ContentInputModel->get($data);
     if ($insertData == false) {
         $this->error = $ContentInputModel->error;
         return false;
     }
     if ($ContentModel->create($insertData)) {
         $result = $ContentModel->add($insertData);
         $aid = $result[$ContentModel->table];
         $this->editTagData($aid);
         M('upload')->where(array('uid' => $_SESSION['uid']))->save(array('state' => 1));
         //============记录动态
         $DMessage = "发表了文章:<a target='_blank' href='" . U('Index/Index/content', array('mid' => $insertData['mid'], 'cid' => $insertData['cid'], 'aid' => $aid)) . "'>{$insertData['title']}</a>";
         addDynamic($_SESSION['uid'], $DMessage);
         //内容静态
         $Html = new Html();
         $Html->content($this->find($aid));
         $categoryCache = cache('category');
         $cat = $categoryCache[$insertData['cid']];
         $Html->relation_category($insertData['cid']);
         $Html->index();
         return $aid;
     } else {
         $this->error = $ContentModel->error;
         return false;
     }
 }
예제 #2
0
 public function addComment()
 {
     $Model = K('Comment');
     $ModelCache = cache('model');
     $mid = Q('mid', 0, 'intval');
     $cid = Q('cid', 0, 'intval');
     $aid = Q('aid', 0, 'intval');
     if (!session("uid")) {
         $this->_ajax('nologin', '没有登录');
     }
     //-验证评论发表间隔时间
     Q('session.comment_send_time', 0, 'intval');
     //间隔时间小于配置项
     if (!IN_ADMIN && Q('session.comment_send_time') + C('comment_step_time') > time()) {
         $_time = Q('session.comment_send_time') + C('comment_step_time') - time();
         $step = $_time / 60 > 1 ? intval($_time / 60) . '分钟' : $_time . '秒';
         $this->error('请' . $step . '后发表');
     }
     $content = Q('content');
     if (!$content) {
         $this->error('评论内容不能为空');
     }
     $state = $Model->where("cid={$cid} && aid={$aid} && " . C("DB_PREFIX") . "comment.uid=" . session('uid'))->where("content='{$content}'")->order("comment_id DESC")->find();
     if ($state) {
         $this->error('请不要发表重复内容');
     }
     //添加积分
     $reply_credits = intval(C('reply_credits'));
     $credits_msg = '';
     if ($reply_credits) {
         $sql = "UPDATE " . C('DB_PREFIX') . 'user AS u SET credits=credits+' . $reply_credits;
         M()->exe($sql);
         $_SESSION['credits'] += $reply_credits;
         $credits_msg = '奖励' . $reply_credits . '个积分';
     }
     //添加
     if ($comment_id = $Model->addComment()) {
         //记录发表时间
         session('comment_send_time', time());
         //修改文章评论数
         M($ModelCache[$mid]['table_name'])->inc('comment_num', 'aid=' . $aid);
         $comment_state = M('role')->where('rid=' . $_SESSION['rid'])->getField('comment_state');
         if ($comment_state == 1 || IN_ADMIN) {
             $comment = $this->getCommentHtml($comment_id);
             $msg = '评论成功!' . $credits_msg;
         } else {
             $comment = '';
             $msg = '评论成功,审核后显示';
         }
         //添加动态
         $Message = mb_substr($content, 0, 30, 'utf-8');
         $DyMessge = "<a target='_blank' href='" . __WEB__ . "?a=Index&c=Index&m=content&mid={$mid}&cid={$cid}&aid={$aid}'>" . $Message . "</a>";
         addDynamic($_SESSION['uid'], "发表了评论: " . $DyMessge);
         //向文章作者发送系统消息
         $article = M($ModelCache[$mid]['table_name'])->where("aid={$aid}")->find();
         $articleUrl = __WEB__ . "?a=Index&c=Index&m=content&mid={$mid}&cid={$cid}&aid={$aid}";
         $title = mb_substr($article['title'], 0, 30, 'utf-8');
         addSystemMessage($_SESSION['uid'], " <a target='_blank' href='" . $articleUrl . "'>{$title}</a> 有了新评论");
         $this->_ajax(1, $msg, $comment);
     } else {
         $this->error('失败了哟');
     }
 }
예제 #3
0
파일: world.php 프로젝트: hrosalgado/TFG
/**
 * It puts a Wolf element into the world. It adds it in the hashmap of dynamic elements and in the world array
 *
 * @return bool True, if the element is putted in the world; false, in the opposite case
 */
function addWolf()
{
    if (!isFull()) {
        $wolf = new Wolf();
        $row = rand(0, getSizeWorld()['row'] - 1);
        $col = rand(0, getSizeWorld()['col'] - 1);
        while (!putElement($wolf, $row, $col)) {
            $row = rand(0, getSizeWorld()['row'] - 1);
            $col = rand(0, getSizeWorld()['col'] - 1);
        }
        $wolf->setPosition(array($row, $col));
        $wolf->setActPerTurn($_POST['maxUseWolf']);
        addDynamic($wolf);
        writeFileCSV('Log', array(getTime(), 'New element', get_class($wolf), $wolf->getId(), '[ ' . $wolf->getPosition()[0] . ' - ' . $wolf->getPosition()[1] . ' ]', '', '', ''));
        return true;
    } else {
        writeFileCSV('Log', array(getTime(), 'World is full! It can\'t put a wolf', '', '', '', '', '', ''));
        return false;
    }
}