/**
  * Display the list of paginated Posts (draft and published)
  */
 function home()
 {
     Doo::loadHelper('DooPager');
     Doo::loadModel('Post');
     $p = new Post();
     //if default, no sorting defined by user, show this as pager link
     if ($this->sortField == 'createtime' && $this->orderType == 'desc') {
         $pager = new DooPager(Doo::conf()->APP_URL . 'admin/post/page', $p->count(), 6, 10);
     } else {
         $pager = new DooPager(Doo::conf()->APP_URL . "admin/post/sort/{$this->sortField}/{$this->orderType}/page", $p->count(), 6, 10);
     }
     if (isset($this->params['pindex'])) {
         $pager->paginate(intval($this->params['pindex']));
     } else {
         $pager->paginate(1);
     }
     $data['rootUrl'] = Doo::conf()->APP_URL;
     $data['pager'] = $pager->output;
     //Order by ASC or DESC
     if ($this->orderType == 'desc') {
         $data['posts'] = $p->limit($pager->limit, null, $this->sortField, array('select' => 'id,createtime,status,title,totalcomment'));
         $data['order'] = 'asc';
     } else {
         $data['posts'] = $p->limit($pager->limit, $this->sortField, null, array('select' => 'id,createtime,status,title,totalcomment'));
         $data['order'] = 'desc';
     }
     $this->render('admin', $data);
 }
Example #2
0
 /**
  * 查看专题
  */
 public function actionShow($name)
 {
     $specialModel = Special::model()->find('title_alias=:titleAlias', array('titleAlias' => CHtml::encode(strip_tags($name))));
     if (false == $specialModel) {
         throw new CHttpException(404, '专题不存在');
     }
     //更新浏览次数
     $specialModel->updateCounters(array('view_count' => 1), 'id=:id', array('id' => $specialModel->id));
     $specialPostModel = new Post();
     $criteria = new CDbCriteria();
     $criteria->addCondition('t.status_is=:status AND special_id=:specialId');
     $criteria->params = array('status' => 'Y', 'specialId' => $specialModel->id);
     $criteria->order = 't.id DESC';
     $bagecmsSpecialCount = $specialPostModel->count($criteria);
     $postPage = new CPagination($bagecmsSpecialCount);
     $postPage->pageSize = 10;
     $postPageParams = XUtils::buildCondition($_GET, array());
     $postPageParams['#'] = 'list';
     $postPage->params = is_array($postPageParams) ? $postPageParams : array();
     $criteria->limit = $postPage->pageSize;
     $criteria->offset = $postPage->currentPage * $postPage->pageSize;
     $specialPostList = $specialPostModel->findAll($criteria);
     $this->_seoTitle = empty($specialModel->seo_title) ? $specialModel->title . ' - ' . $this->_conf['site_name'] : $specialModel->seo_title;
     $tpl = empty($specialModel->tpl) ? 'show' : $specialModel->tpl;
     $data = array('specialShow' => $specialModel, 'specialPostList' => $specialPostList, 'bagecmsPagebar' => $postPage);
     $this->render($tpl, $data);
 }
 public function testDestroy()
 {
     $post = Factory::create('Post');
     $this->action('DELETE', 'Admin\\PostsController@destroy', $post->slug);
     $this->assertRedirectedToRoute('admin.posts.index');
     $this->assertEquals(0, Post::count());
 }
 public function testAggregate()
 {
     $count = Post::count();
     $debug = last(DB::getQueryLog());
     $this->assertEquals(3, $count);
     $this->assertEquals('select count(*) as aggregate from "posts" where "published" = ? and "status" = ?', $debug['query']);
 }
 /**
  * 首页
  *
  */
 public function actionIndex()
 {
     $model = new Post();
     $criteria = new CDbCriteria();
     $condition = "1=1";
     $title = trim($this->_request->getParam('title'));
     $catalogId = intval($this->_request->getParam('catalogId'));
     $title && ($condition .= ' AND title LIKE \'%' . $title . '%\'');
     $catalogId && ($condition .= ' AND catalog_id= ' . $catalogId);
     $criteria->condition = $condition;
     $criteria->order = 't.id DESC';
     $criteria->with = array('catalog');
     $count = $model->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = 10;
     //根据title,catelogId,titleAlias查询
     $pageParams = $this->buildCondition($_GET, array('title', 'catalogId'));
     $pages->params = is_array($pageParams) ? $pageParams : array();
     $criteria->limit = $pages->pageSize;
     $criteria->offset = $pages->currentPage * $pages->pageSize;
     $result = $model->findAll($criteria);
     //推荐位
     $recom_list = RecommendPosition::model()->findAll('type=:type', array(':type' => $this->_type), array('order' => 'id'));
     $this->render('index', array('datalist' => $result, 'pagebar' => $pages, 'recom_list' => $recom_list));
 }
Example #6
0
 /**
  * 首页
  *
  */
 public function actionIndex()
 {
     parent::_acl();
     $model = new Post();
     $criteria = new CDbCriteria();
     $condition = '1';
     $title = trim($this->_gets->getParam('title'));
     $titleAlias = trim($this->_gets->getParam('titleAlias'));
     $catalogId = intval($this->_gets->getParam('catalogId'));
     $title && ($condition .= ' AND title LIKE \'%' . $title . '%\'');
     $titleAlias && ($condition .= ' AND title_alias LIKE \'%' . $titleAlias . '%\'');
     $catalogId && ($condition .= ' AND catalog_id= ' . $catalogId);
     $criteria->condition = $condition;
     $criteria->order = 't.id DESC';
     $criteria->with = array('catalog');
     $count = $model->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = 13;
     $pageParams = XUtils::buildCondition($_GET, array('title', 'catalogId', 'titleAlias'));
     $pages->params = is_array($pageParams) ? $pageParams : array();
     $criteria->limit = $pages->pageSize;
     $criteria->offset = $pages->currentPage * $pages->pageSize;
     $result = $model->findAll($criteria);
     $this->render('index', array('datalist' => $result, 'pagebar' => $pages));
 }
Example #7
0
 /**
  * 获取栏目内容数据
  *
  * @param array   $params
  * @return array  数组
  */
 protected function _catalogList($params = array())
 {
     $postModel = new Post();
     $postCriteria = new CDbCriteria();
     $condition = '1';
     if ($params['catalog']) {
         $condition .= ' AND t.catalog_id=:catalogId';
         $criteriaParams[':catalogId'] = intval($params['catalog']);
     }
     if ($params['keyword']) {
         $condition .= ' AND t.title=:title';
         $criteriaParams[':title'] = CHtml::encode(strip_tags($params['keyword']));
     }
     $condition .= " AND t.status_is='Y'";
     $postCriteria->condition = $condition;
     $postCriteria->params = $criteriaParams;
     $postCriteria->order = 't.id DESC';
     $postCriteria->with = 'catalog';
     $count = $postModel->count($postCriteria);
     $postPages = new CPagination($count);
     $postPages->pageSize = $params['pageSize'] > 0 ? $params['pageSize'] : 20;
     $pageParams = XUtils::buildCondition($_GET, array('catalog', 'keyword'));
     $postPages->params = is_array($pageParams) ? $pageParams : array();
     $postCriteria->limit = $postPages->pageSize;
     $postCriteria->offset = $postPages->currentPage * $postPages->pageSize;
     $bagecmsDataList = $postModel->findAll($postCriteria);
     $catalogArr = Catalog::item($params['catalog'], $this->_catalog);
     if ($catalogArr) {
         $this->_seoTitle = empty($catalogArr['catalog_name']) ? $this->_seoTitle : $catalogArr['catalog_name'];
         $bagecmsCatalogData = $catalogArr;
         $this->_seoKeywords = empty($catalogArr['seo_keywords']) ? $this->_seoKeywords : $catalogArr['seo_keywords'];
         $this->_seoDescription = empty($catalogArr['seo_description']) ? $this->_seoDescription : $catalogArr['seo_description'];
     }
     return array('bagecmsDataList' => $bagecmsDataList, 'bagecmsPagebar' => $postPages, 'bagecmsCatalogData' => $bagecmsCatalogData);
 }
 public function showWelcome()
 {
     //echo "Coming Soon";
     try {
         DB::connection()->getDatabaseName();
         //Session::set('locale' , 'es');
         $post = Post::get();
         $cats = Category::orderBy('order_type')->get();
         $noti_post = Post::orderBy(DB::raw('RAND()'))->where('is_approved', 1)->first();
         $post_test = Post::count();
         // i++ page count
         counter('home');
         return View::make('index')->with('posts', $post)->with('noti_post', $noti_post)->with('cats', $cats)->with('post_test', $post_test);
     } catch (Exception $e) {
         return Redirect::route('install');
     }
 }
Example #9
0
 public function run()
 {
     $model = new Post();
     //条件
     $criteria = new CDbCriteria();
     $title = trim(Yii::app()->request->getParam('title'));
     $catalogId = intval(Yii::app()->request->getParam('catalogId'));
     $criteria->addColumnCondition(array('type' => $this->controller->_type));
     $title && $criteria->addSearchCondition('title', $title);
     $catalogId && $criteria->addColumnCondition(array('catalog_id' => $catalogId));
     $criteria->order = 't.id DESC';
     $criteria->with = array('catalog');
     $count = $model->count($criteria);
     //分页
     $pages = new CPagination($count);
     $pages->pageSize = 10;
     $pages->applyLimit($criteria);
     $result = $model->findAll($criteria);
     $this->controller->render('index', array('model' => $model, 'datalist' => $result, 'pagebar' => $pages));
 }
Example #10
0
 /**
  * Список сообщений
  */
 public function topic($id)
 {
     if (!($topic = Topic::find_by_id($id))) {
         App::abort('default', 'Данной темы не существует!');
     }
     if (User::check()) {
         $bookmark = Bookmark::find_by_topic_id_and_user_id($id, User::get('id'));
         if ($bookmark && $topic->postCount() > $bookmark->posts) {
             $bookmark->posts = $topic->postCount();
             $bookmark->save();
         }
     }
     $total = Post::count(['conditions' => ['topic_id = ?', $id]]);
     $page = App::paginate(Setting::get('posts_per_page'), $total);
     $posts = Post::all(['conditions' => ['topic_id = ?', $id], 'offset' => $page['offset'], 'limit' => $page['limit'], 'order' => 'created_at', 'include' => ['user']]);
     $crumbs = ['/forum' => 'Форум', '/forum/' . $topic->forum()->id => $topic->forum()->title, $topic->title];
     if ($topic->forum()->parent_id) {
         $crumbs = ['/forum' => 'Форум', '/forum/' . $topic->forum()->parent_id => $topic->forum()->parent()->title, '/forum/' . $topic->forum()->id => $topic->forum()->title, $topic->title];
     }
     App::view('forums.topic', compact('topic', 'posts', 'page', 'crumbs'));
 }
 function home()
 {
     Doo::loadHelper('DooPager');
     Doo::loadModel('Post');
     $p = new Post();
     $p->status = 1;
     //published post only
     $pager = new DooPager(Doo::conf()->APP_URL . 'page', $p->count(), 4, 10);
     if (isset($this->params['pindex'])) {
         $pager->paginate(intval($this->params['pindex']));
     } else {
         $pager->paginate(1);
     }
     //limit post and order by create time descendingly, get only Posts
     //$this->data['posts'] = $p->limit($pager->limit, null, 'createtime');
     //limit post and order by create time descendingly with post's tags
     $this->data['posts'] = $p->relateTag(array('limit' => $pager->limit, 'desc' => 'post.createtime', 'asc' => 'tag.name', 'match' => false));
     $this->data['pager'] = $pager->output;
     $this->data['rootUrl'] = Doo::conf()->APP_URL;
     //prepare sidebar data, tags and archive list
     $this->prepareSidebar();
     $this->render('index', $this->data);
 }
Example #12
0
 /**
  * 首页
  */
 public function actionIndex()
 {
     $keyword = CHtml::encode(strip_tags(trim($this->_gets->getParam('keyword'))));
     $postModel = new Post();
     $postCriteria = new CDbCriteria();
     if ($keyword) {
         $postCriteria->addSearchCondition('t.title', $keyword);
     }
     $postCriteria->addCondition('t.status_is=:status');
     $postCriteria->params[':status'] = 'Y';
     $postCriteria->with = 'catalog';
     $postCriteria->order = 't.id DESC';
     $bagecmsQuestionCount = $postModel->count($postCriteria);
     $postPages = new CPagination($bagecmsQuestionCount);
     $postPages->pageSize = 15;
     $postPageParams = XUtils::buildCondition($_GET, array('keyword'));
     $postPageParams['#'] = 'list';
     $postPages->params = is_array($postPageParams) ? $postPageParams : array();
     $postCriteria->limit = $postPages->pageSize;
     $postCriteria->offset = $postPages->currentPage * $postPages->pageSize;
     $postList = $postModel->findAll($postCriteria);
     $this->render('index', array('bagecmsDataList' => $postList, 'bagecmsPagebar' => $postPages));
 }
Example #13
0
 /**
  * Posts list
  *
  * @param Request $request
  * @param $opts
  * @return mixed
  */
 public function posts_list(Request $request, $opts)
 {
     $title = $this->lang->translate('post.list');
     // Delete post
     if ($request->get('delete')) {
         $post = \Post::find_by_id(intval($request->get('delete')));
         if ($post && $post->delete()) {
             $this->view->assign('message', $this->lang->translate('form.deleted'));
         }
     }
     // Publish post
     if ($request->get('accept')) {
         $post = \Post::find_by_id(intval($request->get('accept')));
         if ($post) {
             $post->moderate = '0';
             $post->created_at = time();
             if ($post->save()) {
                 $this->view->assign('message', $this->lang->translate('post.published'));
             }
             // Export to social
             $post->export();
             // Pinging sitemap
             NCService::load('SocialMedia.Ping');
         } else {
             $this->view->assign('message', $this->lang->translate('post.error_publish'));
         }
     }
     // Filter
     $filter['order'] = 'id DESC';
     if ($request->order) {
         $filter['order'] = $request->order;
     }
     $conditions = [];
     $values = [];
     // By Category
     if ($request->get('category')) {
         $category = \PostCategory::find($request->get('category'));
         if ($category) {
             $conditions[] = 'category_id = ?';
             $values[] = $category->id;
         }
     }
     // By Author
     if ($request->get('author')) {
         $author = \User::find($request->get('author'));
         if ($author) {
             $conditions[] = 'author_id = ?';
             $values[] = $author->id;
         }
     }
     // Premoderate
     $conditions[] = 'moderate = ?';
     if ($opts->get('mod')) {
         $title = $this->lang->translate('post.onmoderation');
         $values[] = '1';
     } else {
         $values[] = '0';
     }
     if ($conditions) {
         $filter['conditions'] = array_merge([implode(' AND ', $conditions)], $values);
     }
     /** @var Listing $paginator */
     $paginator = NCService::load('Paginator.Listing', [$request->page, \Post::count($filter)]);
     $filter = array_merge($filter, $paginator->limit());
     // Filter users
     $posts = \Post::all($filter);
     // Mass managing
     // Accept all visible
     if ($request->get('accept') == 'all') {
         foreach ($posts as $item) {
             $item->moderate = '0';
             $item->save();
             // Export to social
             Module::export($item, $this->view);
         }
         // Pinging sitemap
         NCService::load('SocialMedia.Ping');
         return static::redirect_response($request->getPathInfo());
     }
     // Sent to moderate all visible
     if ($request->get('moderate') == 'all') {
         foreach ($posts as $item) {
             $item->moderate = '1';
             $item->save();
         }
         return static::redirect_response($request->getPathInfo());
     }
     // Delete all visible
     if ($request->get('delete') == 'all') {
         foreach ($posts as $item) {
             $item->delete();
         }
         return static::redirect_response($request->getPathInfo());
     }
     $posts = array_map(function ($i) {
         return $i->to_array();
     }, $posts);
     return $this->view->render('posts/list.twig', ['title' => $title, 'posts_list' => $posts, 'listing' => $paginator->pages(), 'page' => $paginator->cur_page, 'moderate' => $opts->get('mod')]);
 }
Example #14
0
<?php

Route::collection(array('before' => 'auth,csrf'), function () {
    /*
    	List all posts and paginate through them
    */
    Route::get(array('admin/posts', 'admin/posts/(:num)'), function ($page = 1) {
        $perpage = Post::perPage();
        $total = Post::count();
        $posts = Post::sort('created', 'desc')->take($perpage)->skip(($page - 1) * $perpage)->get();
        $url = Uri::to('admin/posts');
        $pagination = new Paginator($posts, $total, $page, $perpage, $url);
        $vars['messages'] = Notify::read();
        $vars['posts'] = $pagination;
        $vars['categories'] = Category::sort('title')->get();
        $vars['status'] = 'all';
        return View::create('posts/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    /*
    	List posts by category and paginate through them
    */
    Route::get(array('admin/posts/category/(:any)', 'admin/posts/category/(:any)/(:num)'), function ($slug, $page = 1) {
        if (!($category = Category::slug($slug))) {
            return Response::error(404);
        }
        $query = Post::where('category', '=', $category->id);
        $perpage = Post::perPage();
        $total = $query->count();
        $posts = $query->sort('created', 'desc')->take($perpage)->skip(($page - 1) * $perpage)->get();
        $url = Uri::to('admin/posts/category/' . $category->slug);
        $pagination = new Paginator($posts, $total, $page, $perpage, $url);
Example #15
0
<?php

required_params('post');
if (User::is('<=20') && Post::count(array('conditions' => array("user_id = ? AND created_at > ? ", User::$current->id, gmd_math('sub', '1D')))) >= CONFIG::member_post_limit) {
    respond_to_error("Daily limit exceeded", "#error", array('status' => 421));
}
auto_set_params(array('md5'));
$status = User::is('>=30') ? 'active' : 'pending';
Request::$params->post = array_merge(Request::$params->post, array('updater_user_id' => User::$current->id, 'updater_ip_addr' => Request::$remote_ip, 'user_id' => User::$current->id, 'ip_addr' => Request::$remote_ip, 'status' => $status, 'tempfile_path' => $_FILES['post']['tmp_name']['file'], 'tempfile_name' => $_FILES['post']['name']['file'], 'is_upload' => true));
$post = Post::create(Request::$params->post);
if ($post->record_errors->blank()) {
    if (Request::$params->md5 && $post->md5 != strtolower(Request::$params->md5)) {
        $post->destroy();
        respond_to_error("MD5 mismatch", '#error', array('status' => 420));
    } else {
        $api_data = array('post_id' => $post->id, 'location' => url_for('post#show', array('id' => $post->id)));
        if (CONFIG::dupe_check_on_upload && $post->is_image() && empty($post->parent_id)) {
            // if (Request::$format == "xml" || Request::$format == "json") {
            // $options = array('services' => SimilarImages::get_services('local'), 'type' => 'post', 'source' => $post);
            // $res = SimilarImages::similar_images($options);
            // if (!empty($res['posts'])) {
            // $post->tags .= " possible_duplicate";
            // $post->save();
            // $api_data['has_similar_hits'] = true;
            // }
            // }
            $api_data['similar_location'] = url_for('post#similar', array('id' => $post->id, 'initial' => 1));
            respond_to_success("Post uploaded", array('#similar', array('id' => $post->id, 'initial' => 1)), array('api' => $api_data));
        } else {
            respond_to_success("Post uploaded", array('#show', array('id' => $post->id, 'tag_title' => $post->tag_title())), array('api' => $api_data));
        }
 public function postList()
 {
     $take = Input::get('take');
     $skip = Input::get('skip');
     $validator = Validator::make(array('take' => $take, 'skip' => $skip), array('take' => 'required', 'skip' => 'required'));
     if ($validator->fails()) {
         $error_messages = $validator->messages()->all();
         $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages);
         $response_code = 200;
     } else {
         $posts = Post::take($take)->skip($skip)->orderBy('created_at', 'desc')->get();
         $counts = Post::count();
         $datas = array();
         foreach ($posts as $post) {
             $publisher_name = "";
             $publisher_image = "";
             if ($post) {
                 $publisher = Publisher::find($post->publisher_id)->first();
                 if (count($publisher) != 0) {
                     $publisher_name = $publisher->name;
                     $publisher_image = $publisher->image;
                 }
             }
             $data = array();
             $data['id'] = $post->id;
             $data['title'] = $post->title;
             $data['description'] = $post->des;
             $data['url'] = $post->url;
             $data['image'] = $post->image;
             $data['time'] = $post->created_at;
             $data['share_link'] = $post->link;
             $data['category'] = $post->category;
             $data['is_approved'] = $post->is_approved;
             $data['title_tag'] = $post->title_tag;
             $data['meta_desc'] = $post->meta_des;
             $data['publisher_image'] = $publisher_image;
             $data['publisher_name'] = $publisher_name;
             array_push($datas, $data);
         }
         $response_array = array('success' => true, 'posts' => $datas, 'counts' => $counts);
     }
     return Response::json($response_array);
 }
Example #17
0
 public function testBootMethodAgainAndAgain()
 {
     Post::create(['comments_count' => 2]);
     $this->assertEquals(1, Post::count());
     $this->assertEquals(6, Post::first()->comments_count);
 }
Example #18
0
/**
 *  Количество сообщений в форума
 * @return integer сообщений в форуме
 */
function forumCount()
{
    return Topic::count() . '/' . Post::count();
}
Example #19
0
 function held_post_count()
 {
     // version = Cache.get("$cache_version").to_i
     // key = "held-post-count/v=#{version}/u=#{self.id}"
     // return Cache.get(key) {
     // Post.count(:conditions => ["user_id = ? AND is_held AND status <> 'deleted'", self.id])
     // }.to_i
     $count = Post::count(array('conditions' => array("user_id = ? AND is_held AND status <> 'deleted'", $this->id)));
     return $count;
 }
Example #20
0
 /**
  * Post page
  */
 public function news(Request $request, $matches)
 {
     $filter = ['conditions' => ['moderate = ?', 0]];
     // Rows count
     $rows = \Post::count($filter);
     // Paginator
     /** @var Listing $pagination */
     $pagination = NCService::load('Paginator.Listing', [$request->page, $rows]);
     // Limitation
     $filter = array_merge($filter, $pagination->limit());
     // Ordering
     if ($request->order) {
         $filter['order'] = $request->order;
     } else {
         $filter['order'] = 'created_at DESC';
     }
     // Get posts
     $posts = \Post::all($filter);
     // Rendering
     return $this->view->render('posts/list.twig', ['title' => $this->lang->translate('post.title'), 'posts' => array_map(function ($i) {
         return $i->to_array();
     }, $posts), 'listing' => $pagination->pages(), 'page' => $request->page]);
 }
Example #21
0
      <td><strong>Posts</strong></td>
      <td><a href="/post?tags=user%3A<?php 
echo $user->name;
?>
"><?php 
echo Post::count(array('conditions' => array("user_id = ?", $user->id)));
?>
</a></td>
    </tr>
    <tr>
      <td><strong>Deleted Posts</strong></td>
      <td><a href="/post/deleted_index?user_id=<?php 
echo $user->id;
?>
"><?php 
echo Post::count(array('conditions' => array("status = 'deleted' AND user_id = ?", $user->id)));
?>
</a></td>
    </tr>
    <tr>
      <th>Votes</th>
      <td>
        <span class="stars">
          <?php 
foreach (range(1, 3) as $i) {
    ?>
            <a class="star star-<?php 
    echo $i;
    ?>
" href="<?php 
    echo url_for('post#index', array('tags' => "vote:>={$i}:{$user->name} order:vote"));
Example #22
0
<?php

require_once __DIR__ . '/Model.php';
require_once __DIR__ . '/Connect.php';
require_once __DIR__ . '/Post.php';
require_once __DIR__ . '/User.php';
$database = ['dsn' => 'mysql:host=localhost;dbname=ecole_multimedia', 'password' => 'root', 'username' => 'antoine'];
$connect = new Connect($database);
/* ------------------------------------------------- *\
    Name of Model $postModel or $userModel ...
\* ------------------------------------------------- */
$postModel = new Post($connect->getDB());
var_dump($postModel->count());
$posts = $postModel->select(['title', 'status', 'content'])->where('id', '>', 1)->where('status', '=', 'published')->get();
foreach ($posts as $post) {
    echo "<h1>{$post->title}</h1>";
}
/* ------------------------------------------------- *\
    Count method
\* ------------------------------------------------- */
var_dump($postModel->count());
var_dump($postModel->where('id', '>', 1)->count());
/* ------------------------------------------------- *\
    Method all
\* ------------------------------------------------- */
var_dump($postModel->all());
$posts = $postModel->all();
foreach ($posts as $post) {
    echo "<h1>{$post->title}...</h1>";
}
/* ------------------------------------------------- *\
Example #23
0
 public function testClear()
 {
     Post::clear();
     $this->assertFalse(!!Post::count());
 }
Example #24
0
 function check_pending_count()
 {
     if (!CONFIG::max_pending_images) {
         return;
     }
     if ($this->status != "pending") {
         return;
     }
     if ($this->user->level >= 33) {
         return;
     }
     $pending_posts = Post::count(array('conditions' => array("user_id = ? AND status = 'pending'", $this->user_id)));
     if ($pending_posts < CONFIG::max_pending_images) {
         return;
     }
     $this->record_errors->add_to_base("You have too many posts pending moderation");
     return false;
 }
Example #25
0
$protected->get('/settings', function (Request $request) use($app) {
    $account = Account::findOne(array('_id' => new MongoId($app['account']['id'])));
    unset($account->users);
    return $app->json($account->toArray());
});
$protected->post('/settings', function (Request $request) use($app) {
    $email = $app['data']['email'];
    $m = new Mongo();
    if ($email) {
        $m->circular->accounts->update(array('_id' => new MongoId($app['account']['id'])), array('$set' => array('email' => $email)));
    } else {
        $m->circular->accounts->update(array('_id' => new MongoId($app['account']['id'])), array('$unset' => array('email' => true)));
    }
});
/***
 *
 * The `/counter` public endpoint returns the number of scheduled posts queued right now.
 *
 */
$public->get('/counter', function (Request $request) use($app) {
    $count = Post::count();
    return $app->json(array('count' => $count));
});
/***
 *
 * Run, App, Run!
 *
 */
$app->mount('/', $public);
$app->mount('/', $protected);
$app->run();
Example #26
0
     require_once mnminclude . 'geo.php';
     if ($current_user->user_id > 0 && ($latlng = geo_latlng('user', $current_user->user_id))) {
         geo_init('onLoad', $latlng, 5);
     } else {
         geo_init('onLoad', false, 2);
     }
     break;
 case '':
 case '_all':
     $tab_option = 1;
     //$sql = "SELECT SQL_CACHE post_id FROM posts ORDER BY post_id desc limit $offset,$page_size";
     $where = "post_id > 0";
     $order_by = "ORDER BY post_id desc";
     $limit = "LIMIT {$offset},{$page_size}";
     //$rows = $db->get_var("SELECT count(*) FROM posts");
     $rows = Post::count();
     $min_date = date("Y-m-d 00:00:00", time() - 86400 * 10);
     //$rows = $db->get_var("SELECT SQL_CACHE count(*) FROM posts where post_date > '$min_date'");
     $rss_option = "sneakme_rss2.php";
     break;
 default:
     $tab_option = 4;
     if (is_numeric($argv[0]) && ($post_id = intval($argv[0])) > 0 || is_numeric($argv[1]) && ($post_id = intval($argv[1])) > 0) {
         // Individual post
         $user->id = $db->get_var("select post_user_id from posts where post_id={$post_id}");
         if (!$user->read()) {
             do_error(_('usuario no encontrado'), 404);
         }
         $globals['permalink'] = 'http://' . get_server_name() . post_get_base_url($post_id);
         // Fill title
         $summary = text_to_summary($db->get_var("SELECT post_content from posts where post_id = {$post_id}"), 250);
Example #27
0
 function admin_get_posts()
 {
     $token = $_SERVER['Authorization'];
     extract($_GET);
     $admin = __get_auth_admin($token);
     $result = array();
     if ($admin == NULL) {
         $result['success'] = 'false';
         $result['message'] = 'You are not authorized';
     } else {
         $total = Post::count();
         $posts = Post::with('user')->whereNull('deleted_at');
         if (!isset($per)) {
             $per = 20;
         }
         if (isset($page)) {
             $posts->skip(($page - 1) * $per);
         }
         $posts->take($per);
         $result['success'] = 'true';
         $result['posts'] = $posts->get();
         $result['total'] = $total;
     }
     echo json_encode($result);
 }