Example #1
0
 function __construct()
 {
     parent::__construct(Config::getCfg('site')['pagetitle'], "", 0);
     $boards = Model::get()->getBoards();
     $archiveBoards = array_filter($boards, function ($b) {
         return $b->isArchive();
     });
     $plainBoards = array_filter($boards, function ($b) {
         return !$b->isArchive();
     });
     $html = "<div class='boardlist_big'><h1>Archived Boards</h1><hr style='width:64px;'>";
     foreach ($archiveBoards as $b) {
         $html .= Site::parseHtmlFragment("indexArchiveBoard.html", ["%ago%", "%crawltime%", "%shortname%", "%longname%", "%posts%", "%threads%", "%firstcrawl%"], [ago(time() - $b->getLastCrawl()), $b->getLastCrawl(), $b->getName(), $b->getLongName(), $b->getNoPosts(), $b->getNoThreads(), date("j F Y", $b->getFirstCrawl())]);
     }
     $html .= "</div>";
     $html .= "<script type='text/javascript' src='/script/boardUpdate.js'></script>";
     if (count($plainBoards) > 0) {
         $html .= "<div class='boardlist_big'><h1>Boards</h1><hr style='width:64px;'>";
         foreach ($plainBoards as $b) {
             $html .= Site::parseHtmlFragment("indexBoard.html", ["%ago%", "%crawltime%", "%shortname%", "%longname%", "%posts%", "%threads%", "%firstcrawl%"], [ago(time() - $b->getLastCrawl()), $b->getLastCrawl(), $b->getName(), $b->getLongName(), $b->getNoPosts(), $b->getNoThreads(), date("j F Y", $b->getFirstCrawl())]);
         }
         $html .= "</div>";
     }
     $this->setBody($html);
 }
Example #2
0
 public function __construct()
 {
     parent::__construct("Report Queue", el('h2', "Reports"), Config::getCfg('permissions')['delete']);
     $reports = Model::get()->getReports();
     $html = "<table class='reportTable'><tr><th colspan='3'>Report Queue</th></tr><tr><th style='width:3em;'>Times</th><th>Post</th><th style='width:20em;'>Options</th></tr>";
     foreach ($reports as $report) {
         $hash = bin2hex($report['md5']);
         $html .= "<tr id='report{$report['no']}'>";
         $html .= "<td>" . $report['count'] . "</td>";
         $html .= "<td><a href='{$report['threadid']}#p{$report['no']}' data-board='{$report['board']}' data-thread='{$report['threadid']}' data-post='{$report['no']}' class='quotelink noEmbed'>&gt;&gt;{$report['no']}</a></td>";
         $html .= "<td><a class='button' href='javascript:deletePost({$report['no']},\"{$report['board']}\");' >Delete&nbsp;Post</a>&nbsp;";
         $html .= "<a class='button' href='javascript:banImage(\"{$hash}\");' id='ban{$hash}'>Ban&nbsp;Image</a>&nbsp;";
         $html .= "<a class='button' href='javascript:deleteReport({$report['no']},\"{$report['board']}\");'>Delete&nbsp;Report</a>&nbsp;";
         $html .= "<a class='button' href='javascript:banReporter({$report['no']},\"{$report['board']}\");'>Ban&nbsp;Reporter</a></td>";
         $html .= "</tr>";
     }
     $html .= "</table>";
     if (Site::getUser()->getPrivilege() >= Config::getCfg('permissions')['owner']) {
         $html .= "<br><table class='reportTable'><tr><th colspan='3'>Last Few Deleted Posts</th></tr><tr><th style='width:3em;'>Board</th><th>Post</th><th style='width:7em;'>Options</th></tr>";
         foreach (Model::get()->getBoards() as $board) {
             $lastFew = OldModel::getLastNDeletedPosts($board->getName(), 5);
             foreach ($lastFew as $report) {
                 $html .= "<tr id='report{$report['no']}'>";
                 $html .= "<td>" . $board->getName() . "</td>";
                 $html .= "<td>&gt;&gt;{$report['no']} ({$report['name']}{$report['trip']})</td>";
                 $html .= "<td><a class='button' href='javascript:restorePost({$report['no']},\"{$board->getName()}\");' >Restore&nbsp;Post</a></td>";
                 $html .= "</tr>";
             }
         }
         $html .= "</table>";
     }
     $this->appendToBody($html);
 }
Example #3
0
 public function post()
 {
     if ($this->user->isUnVerified()) {
         $this->alert('Your account is not active now, plz check your mail and active.');
     }
     if (!($article = Model::factory('Article')->find_one($this->input->param('id')))) {
         $this->alert('Article is not exists');
     }
     $comment = Model::factory('Comment')->create(array('article_id' => $this->input->param('id'), 'text' => $this->input->data('text'), 'user_id' => $this->user->id));
     try {
         ORM::get_db()->beginTransaction();
         if (!$comment->save()) {
             $this->alert('Comment create error');
         }
         $article->set_expr('comments_count', '`comments_count` + 1');
         $article->save();
         ORM::get_db()->commit();
     } catch (\PDOException $e) {
         ORM::get_db()->rollBack();
         // @TODO Logging
         $this->alert('Comment error because of the bad database');
     }
     $this->app->emit('comment', $comment);
     $this->redirect('/p/' . $comment->article_id);
 }
Example #4
0
 public function get()
 {
     $posts = Model::factory('Article')->where('status', '1')->order_by_desc('point')->limit(100)->find_many();
     $xml = new \XMLWriter();
     $xml->openMemory();
     $xml->startDocument();
     $xml->startElement('urlset');
     foreach ($posts as $post) {
         $xml->startElement('url');
         $xml->startElement('loc');
         $xml->writeCdata($post->permalink());
         $xml->endElement();
         $xml->startElement('lastmod');
         $xml->writeCdata(date(DATE_ATOM, strtotime($post->modified_at ? $post->modified_at : $post->created_at)));
         $xml->endElement();
         $xml->startElement('changefreq');
         $xml->writeCdata('always');
         $xml->endElement();
         $xml->startElement('priority');
         $xml->writeCdata('1.0');
         $xml->endElement();
         $xml->endElement();
     }
     $xml->endElement();
     $this->data = $xml->outputMemory();
 }
Example #5
0
 public function get()
 {
     if (($page = $this->input->query('page', 1)) < 1) {
         $page = 1;
     }
     $limit = 20;
     $offset = ($page - 1) * $limit;
     $total = Model::factory('Article')->where('status', '1')->count();
     $this->data['articles'] = Model::factory('Article')->where('status', '1')->order_by_desc('point')->offset($offset)->limit($limit)->find_many();
     $this->data['latest_articles'] = array();
     /**
      * 第一页加载最新的几篇文章
      */
     if ($page == 1) {
         $this->data['latest_articles'] = Model::factory('Article')->where('status', '1')->order_by_desc('created_at')->limit(5)->find_many();
         if ($this->data['latest_articles'] && !$this->input->query('force_latest')) {
             $exists_articles_ids = array();
             foreach ($this->data['articles'] as $article) {
                 $exists_articles_ids[] = $article->id;
             }
             $this->data['latest_articles'] = array_filter($this->data['latest_articles'], function ($article) use($exists_articles_ids) {
                 if (in_array($article->id, $exists_articles_ids)) {
                     return false;
                 }
                 return true;
             });
         }
     }
     $this->data['page'] = Html::makePage($this->input->uri(), 'page=(:num)', $page, $total, $limit);
 }
Example #6
0
 public function post()
 {
     if (!$this->user->isOK()) {
         $this->alert('Your account is not ok, plz check active or contact the admin.');
     }
     if (!$this->input->data('link') && !$this->input->data('content')) {
         $this->alert('At least one between url and content');
     }
     // Check link format
     if ($this->input->data('link') && !filter_var($this->input->data('link'), FILTER_VALIDATE_URL)) {
         $this->alert('Url format is wrong');
     }
     // Check url if exists
     if ($this->input->data('link') && Model::factory('Article')->where('link', $this->input->data('link'))->find_one()) {
         $this->alert('Url "' . $this->input->data('link') . '" is already exists');
     }
     // Check title
     if (!$this->input->data('title')) {
         $this->alert('Title need');
     }
     $article = Model::factory('Article')->create(array('title' => $this->input->data('title'), 'link' => $this->input->data('link'), 'content' => $this->input->data('content'), 'user_id' => $this->user->id, 'status' => Article::OK));
     try {
         ORM::get_db()->beginTransaction();
         if (!$article->save()) {
             $this->alert('Submit error');
         }
         $this->user->set_expr('posts_count', '`posts_count` + 1');
         $this->user->save();
         ORM::get_db()->commit();
     } catch (\PDOException $e) {
         ORM::get_db()->rollback();
         $this->alert('Share error with error database');
     }
     $this->redirect('/p/' . $article->id);
 }
Example #7
0
 public static function post(array $path) : array
 {
     $model = Model::get();
     $board = $model->getBoard(get('board'));
     $num = (int) get('num');
     $post = $model->getPost($board, $num);
     return self::fuukaFormat($post);
 }
Example #8
0
 public function get()
 {
     $this->tpl = 'user.php';
     $this->data['author'] = Model::factory('User')->find_one($this->input->params['id']);
     if (!$this->data['author']) {
         $this->alert('User is not exists');
     }
     $this->title = $this->data['author']->name;
 }
Example #9
0
 /**
  * Logs in the session user. Throws exception if username
  * and password don't match any users.
  *
  * @param string $username
  * @param string $password
  * @throws NotFoundException
  */
 static function logIn(string $username, string $password)
 {
     $user = Model::get()->getUser($username, $password);
     $_SESSION['user'] = $user;
     $uid = $user->getUID();
     $time = time();
     $ip = $_SERVER['REMOTE_ADDR'];
     Config::getPDOConnectionRW()->query("INSERT INTO `logins` (`uid`,`time`,`ip`) VALUES ({$uid},{$time},'{$ip}')");
 }
Example #10
0
 public function __construct(Factory $factory, $name, $id = Null)
 {
     // 		$this->ref = microtime(true);
     if (!is_numeric($id)) {
         $id = (int) "{$id}";
     }
     parent::__construct($factory, $id);
     $this->name = Name::create($name);
 }
 public function __construct(Factory $factory, $link, $title, array $tags = array(), $id = 0)
 {
     parent::__construct($factory, $id);
     $this->link = trim($link);
     $this->title = $title;
     foreach ($tags as $tag) {
         $this->addTag($tag);
     }
 }
Example #12
0
 /**
  * Save
  *
  * @return mixed
  */
 public function save()
 {
     if ($this->is_new()) {
         $this->created_at = Time::now();
     } else {
         $this->modified_at = Time::now();
     }
     return parent::save();
 }
Example #13
0
 public function run()
 {
     $articles = Model::factory('Article')->find_many();
     foreach ($articles as $article) {
         $article->comments_count = $article->comments()->count();
         $article->digg_count = Model::factory('UserDigg')->where('article_id', $article->id)->count();
         $article->save();
     }
     print Cli::text('Update article count ok' . PHP_EOL, 'green');
 }
Example #14
0
 /**
  * 删除菜单
  */
 public function menuAction()
 {
     $id = $this->isG('id', $GLOBALS['_LANG']['COMMON']['DELETE_ID']);
     $result = \Model\Model::deleteFromModelId('menu', $id);
     if (empty($result)) {
         $this->error($GLOBALS['_LANG']['COMMON']['DELETE_ERROR']);
     } else {
         $this->success($GLOBALS['_LANG']['COMMON']['DELETE_SUCCESS']);
     }
 }
Example #15
0
 /**
  * 更新模型
  */
 public function action()
 {
     $model = \Model\Model::findModel($_POST['model_id']);
     $result = \Model\Model::updateModel();
     if ($result['status'] == false) {
         $this->error($result['mes']);
     }
     //更新菜单
     $this->db('menu')->where('menu_name = :old_name')->update(array('menu_name' => $this->p('display_name'), 'noset' => array('old_name' => $model['lang_key'])));
     $this->success($GLOBALS['_LANG']['MODEL']['UPDATE_MODEL_SUCCESS'], $this->url('Team-Model-index'));
 }
Example #16
0
 /**
  * Before logic
  */
 protected function before()
 {
     $this->loadOrm();
     $user_id = $this->input->session('login');
     if ($user_id) {
         $this->user = Model::factory('User')->find_one($user_id);
     }
     if ($this->auth) {
         $this->auth();
     }
 }
Example #17
0
 public function get()
 {
     if (($page = $this->input->query('page', 1)) < 1) {
         $page = 1;
     }
     $limit = 20;
     $offset = ($page - 1) * $limit;
     $total = Model::factory('Article')->where('status', '1')->count();
     $this->data['articles'] = Model::factory('Article')->where('status', '1')->order_by_desc('created_at')->offset($offset)->limit($limit)->find_many();
     $this->data['page'] = Html::makePage($this->input->uri(), 'page=(:num)', $page, $total, $limit);
 }
Example #18
0
 function __construct()
 {
     parent::__construct("b-stats news", "", 0);
     $this->appendToBody("<h2>News</h2>");
     $articles = Model::get()->getAllNewsArticles();
     foreach ($articles as $article) {
         $date = date("Y-m-d g:i a", $article['time']);
         $content = nl2br($article['content']);
         $this->appendToBody(Site::parseHtmlFragment("article.html", ['_author_', '_id_', '_title_', '_content_', '_date_'], [$article['username'], $article['article_id'], $article['title'], $content, $date]));
     }
 }
Example #19
0
 public function __init()
 {
     parent::__init();
     $this->table = strtolower(MODULE);
     $this->fieldPrefix = $this->table . "_";
     $this->model = \Model\Model::findModel($this->table, 'model_name');
     if (empty($this->model)) {
         $this->error($GLOBALS['_LANG']['MODEL']['NOT_EXIST_MODEL']);
     }
     $this->assign('fieldPrefix', $this->fieldPrefix);
     $this->theme = \Model\Option::findOption('theme');
 }
Example #20
0
 public function post()
 {
     if (!($article = Model::factory('Article')->find_one($this->input->params['id']))) {
         $this->alert('Article is not exists');
     }
     if (!$this->user->isAdmin() && $article->user_id != $this->user->id) {
         $this->alert('Article only can be deleted by owner');
     }
     $article->status = Article::DELETED;
     $article->save();
     $this->redirect('/my/posts');
 }
Example #21
0
 /**
  * 内容排序
  */
 public function listsort()
 {
     foreach ($_POST['id'] as $key => $value) {
         \Model\Model::updateSortFromModel(MODULE, $key, $value);
     }
     if (!empty($_SERVER['HTTP_REFERER'])) {
         $url = $_SERVER['HTTP_REFERER'];
     } else {
         $url = "";
     }
     $this->success($GLOBALS['_LANG']['COMMON']['SORT_SUCCESS'], $url);
 }
Example #22
0
 public function post()
 {
     $is_verify_user = $this->app->verify_user;
     // Check email
     if (!filter_var($this->input->data('email'), FILTER_VALIDATE_EMAIL)) {
         $this->alert('Email format is wrong');
     }
     // Check user name rule
     if (!preg_match("/^[\\w]{4,20}\$/", $this->input->data('name'))) {
         $this->alert('User name only use a-z and 0-9, length must be 6-20');
     }
     // Check password length
     if (strlen($this->input->data('password')) < 6) {
         $this->alert('Password length must be great than or equal 6');
     }
     // Check if exists user name
     if (Model::factory('User')->where('name', $this->input->data('name'))->find_one()) {
         $this->alert('User already exists');
     }
     // Check if exists user email
     if (Model::factory('User')->where('email', $this->input->data('email'))->find_one()) {
         $this->alert('Email already taken');
     }
     // Create user
     /** @var $user \Model\User */
     $user = Model::factory('User')->create(array('name' => $this->input->data('name'), 'password' => Crypt::makePassword($this->input->data('password'), $this->app->password_salt), 'email' => $this->input->data('email'), 'bio' => $this->input->data('bio')));
     // If disable verify_user will set user verified automatic.
     if (!$is_verify_user) {
         $user->setVerified();
     }
     try {
         ORM::get_db()->beginTransaction();
         if (!$user->save()) {
             $this->alert('User create error');
         }
         ORM::get_db()->commit();
     } catch (\PDOException $e) {
         $this->alert('User register error because of the bad database');
         //@TODO log
         ORM::get_db()->rollback();
     }
     // login when success
     $this->input->session('login', $user->id);
     // Check if verify user
     if ($is_verify_user) {
         // Send verify email
         SendVerifyEmail::perform($user);
         $this->redirect('/account/welcome');
     } else {
         $this->redirect('/');
     }
 }
Example #23
0
 public function run()
 {
     $users = Model::factory('User')->find_many();
     foreach ($users as $user) {
         $user->posts_count = $user->articles()->where('status', Article::OK)->count();
         $user->digged_count = 0;
         foreach ($user->articles()->where('status', Article::OK)->find_many() as $article) {
             $user->digged_count += $article->digg_count;
         }
         $user->save();
     }
     print Cli::text('Update user count ok' . PHP_EOL, 'green');
 }
Example #24
0
 public function get()
 {
     $posts = Model::factory('Article')->where('status', '1')->order_by_desc('point')->limit(10)->find_many();
     $feed = new FeedFactory();
     $channel = new Channel();
     $channel->title(config('site.title'))->description(config('site.default_meta'))->url(Url::site())->appendTo($feed);
     foreach ($posts as $post) {
         $item = new Item();
         /** @var $post \Model\Article */
         $item->title($post->title)->description(Html::fromMarkdown($post->content))->url($post->permalink())->pubDate(strtotime($post->created_at))->appendTo($channel);
     }
     $this->data = substr($feed, 0, -1);
 }
Example #25
0
 public function post()
 {
     if (!isset($this->input->auth)) {
         $this->alert('Authorize failed!');
     }
     $auth = $this->input->auth['auth'];
     try {
         if ($passport = Model::factory('Passport')->where('provider', $auth['provider'])->where('uid', $auth['uid'])->find_one()) {
             $passport->access_token = $auth['credentials']['token'];
             $passport->expired_at = !empty($auth['credentials']['expires']) ? $auth['credentials']['expires'] : null;
             $passport->save();
         } else {
             // 检查当前是否有登陆用户
             if (!($user_id = $this->input->session('login'))) {
                 // 没有用户创建一个
                 $user = Model::factory('User')->create();
                 $name = preg_replace('/\\s/', '', $auth['info']['name']);
                 if (Model::factory('User')->where('name', $name)->find_one()) {
                     $name .= rand(100, 999);
                 }
                 $user->name = $name;
                 if (isset($auth['info']['description']) && ($bio = $auth['info']['description']) || isset($auth['raw']['description']) && ($bio = $auth['raw']['description'])) {
                     $user->bio = $bio;
                 }
                 if (isset($auth['info']['email']) && ($email = $auth['info']['email'])) {
                     $user->email = $email;
                 }
                 $user->status = User::OK;
                 $user->save();
                 $user_id = $user->id;
             }
             // 绑定Passport
             $passport = Model::factory('Passport')->create();
             $passport->provider = $auth['provider'];
             $passport->uid = $auth['uid'];
             $passport->display_name = isset($auth['info']['nickname']) ? $auth['info']['nickname'] : $auth['info']['name'];
             $passport->access_token = $auth['credentials']['token'];
             $passport->expired_at = !empty($auth['credentials']['expires']) ? $auth['credentials']['expires'] : null;
             $passport->user_id = $user_id;
             $passport->save();
             if (!empty($user)) {
                 $user->create_passport_id = $passport->id;
                 $user->save();
             }
         }
     } catch (\Exception $e) {
         $this->alert("Create user error: " . $e->getMessage());
     }
     $this->input->session('login', $passport->user_id);
     $this->redirect('/');
 }
Example #26
0
 public function run()
 {
     $model = Model::factory('Article');
     if (!$this->params['all']) {
         $model->where_gte('created_at', date('Y-m-d', strtotime('-1 month')));
     }
     /** @var $articles \Model\Article[] */
     $articles = $model->find_many();
     foreach ($articles as $article) {
         $article->digg_count = $article->diggs()->count();
         $article->comments_count = $article->comments()->count();
         $article->point = $article->analysisPoint();
         $article->save();
     }
     print Cli::text('Analysis article point ok' . PHP_EOL, 'green');
 }
Example #27
0
 public function get()
 {
     $this->tpl = 'account/verify.php';
     $email = $this->app->cryptor->decrypt($this->input->query('code'));
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         $this->alert('Verify data is error');
     }
     $user = Model::factory('User')->where('email', $email)->find_one();
     if (!$user) {
         $this->alert('Verify email is not exists');
     }
     if ($user->isUnVerified()) {
         $user->status = User::OK;
         $user->save();
     }
 }
Example #28
0
 public function get()
 {
     $this->tpl = 'article.php';
     $this->data['article'] = Model::factory('Article')->find_one($this->input->params['id']);
     if (!$this->data['article']) {
         $this->alert('Article is not exists');
     }
     // Un-normal Article is only display for his author
     if (!$this->data['article']->isOK() && (!$this->user || $this->data['article']->user_id != $this->user->id)) {
         $this->alert('Article is not ready');
     }
     if ($this->is_robot) {
         $this->data['comments'] = $this->data['article']->comments()->order_by_desc('created_at')->find_many();
     }
     $this->data['json']['pid'] = $this->input->params['id'];
     $this->title = $this->data['article']->title;
 }
Example #29
0
 public function post()
 {
     if (filter_var($this->input->data('name'), FILTER_VALIDATE_EMAIL)) {
         if (!($user = Model::factory('User')->where('email', $this->input->data('name'))->find_one())) {
             $this->alert('User email not found');
         }
     } else {
         if (!($user = Model::factory('User')->where('name', $this->input->data('name'))->find_one())) {
             $this->alert('User name not found');
         }
     }
     if ($user->password != Crypt::makePassword($this->input->data('password'), $this->app->password_salt)) {
         $this->alert('User name and password is not match');
     }
     $this->input->session('login', $user->id);
     $this->redirect($this->input->query('continue') ? $this->input->query('continue') : '/');
 }
Example #30
0
 public function delete()
 {
     $directoryPath = $this->getDirectoryPath();
     $iterator = new \DirectoryIterator($directoryPath);
     foreach ($iterator as $fileinfo) {
         if ($fileinfo->isDir() && !$fileinfo->isDot()) {
             $file = $directoryPath . $fileinfo->getFilename() . '/' . $this->filename;
             if (is_file($file)) {
                 unlink($file);
             }
         }
     }
     $main_file = $directoryPath . $this->filename;
     if (is_file($main_file)) {
         unlink($main_file);
     }
     parent::delete();
 }