public function show($id = 0) { if (!($id && ($article_info = render_cell('site_cache_cell', 'article', $id)))) { return redirect_message(array('articles'), array('_flash_message' => '找不到該筆資料。')); } $article = $article_info['article']; $tags = $article_info['tags']; $others = $article_info['others']; $user = $article_info['user']; $sources = $article_info['sources']; $this->set_title($article['title'] . ' - ' . Cfg::setting('site', 'site', 'title'))->add_hidden(array('id' => 'id', 'value' => $article['id']))->add_meta(array('name' => 'keywords', 'content' => $article['title'] . ',' . implode(',', Cfg::setting('site', 'site', 'keywords'))))->add_meta(array('name' => 'description', 'content' => $article['mini_content']['150']))->add_meta(array('property' => 'og:title', 'content' => $article['title'] . ' - ' . Cfg::setting('site', 'site', 'title')))->add_meta(array('property' => 'og:description', 'content' => $article['mini_content']['300']))->add_meta(array('property' => 'og:image', 'tag' => 'larger', 'content' => $img = $article['cover_url']['1200x630c'], 'alt' => $article['title'] . ' - ' . Cfg::setting('site', 'site', 'title')))->add_meta(array('property' => 'og:image:type', 'tag' => 'larger', 'content' => 'image/' . pathinfo($img, PATHINFO_EXTENSION)))->add_meta(array('property' => 'og:image:width', 'tag' => 'larger', 'content' => '1200'))->add_meta(array('property' => 'og:image:height', 'tag' => 'larger', 'content' => '630'))->add_meta(array('property' => 'article:modified_time', 'content' => $article['updated_at']['c']))->add_meta(array('property' => 'article:published_time', 'content' => $article['created_at']['c']))->add_param('tags', $tags); if (($tags = column_array($tags, 'name')) || ($tags = Cfg::setting('site', 'site', 'keywords'))) { foreach ($tags as $i => $tag) { if (!$i) { $this->add_meta(array('property' => 'article:section', 'content' => $tag))->add_meta(array('property' => 'article:tag', 'content' => $tag)); } else { $this->add_meta(array('property' => 'article:tag', 'content' => $tag)); } } } if ($others) { foreach ($others as $other) { $this->add_meta(array('property' => 'og:see_also', 'content' => base_url('article', $other['site_show_page_last_uri']))); } } $this->add_css(resource_url('resource', 'css', 'fancyBox_v2.1.5', 'my.css'))->add_js(resource_url('resource', 'javascript', 'fancyBox_v2.1.5', 'my.js'))->load_view(array('article' => $article, 'sources' => $sources, 'user' => $user)); }
public function __construct() { parent::__construct(); if (!(($id = $this->uri->rsegments(3, 0)) && (is_numeric($id) ? $this->tag = ArticleTag::find_by_id($id) : ($this->tag = ArticleTag::find_by_name(trim(urldecode($id))))))) { return redirect_message(array('articles'), array('_flash_message' => '找不到該筆資料。')); } if (in_array($this->uri->rsegments(2, 0), array('edit', 'update', 'destroy', 'sort'))) { if (!(($id = $this->uri->rsegments(4, 0)) && ($this->article = Article::find_by_id($id)))) { return redirect_message(array('articles', $this->tag->id, 'articles'), array('_flash_message' => '找不到該筆資料。')); } } $this->add_js(resource_url('resource', 'javascript', 'jquery-timeago_v1.3.1', 'jquery.timeago.js'))->add_js(resource_url('resource', 'javascript', 'jquery-timeago_v1.3.1', 'locales', 'jquery.timeago.zh-TW.js')); }
public function is_visibled($id = 0) { if (!$this->has_post()) { return redirect_message(array('admin', $this->get_class(), 'add'), array('_flash_message' => '非 POST 方法,錯誤的頁面請求。')); } if (!($id && ($contact = Contact::find_by_id($id, array('select' => 'id, is_visibled, updated_at'))))) { return redirect_message(array('admin', $this->get_class(), 'hidden'), array('_flash_message' => '找不到該筆資料。')); } $contact->is_visibled = Contact::IS_VISIBLED; $delete = Contact::transaction(function () use($contact) { return $contact->save(); }); if (!$delete) { return redirect_message(array('admin', $this->get_class(), 'hidden'), array('_flash_message' => '顯示失敗!')); } return redirect_message(array('admin', $this->get_class(), 'hidden'), array('_flash_message' => '顯示成功!')); }
public function create() { if (!$this->has_post()) { return redirect_message(array($this->get_class()), array('_flash_message' => '非 POST 方法,錯誤的頁面請求。')); } $posts = OAInput::post(); if ($msg = $this->_validation_posts($posts)) { return redirect_message(array($this->get_class()), array('_flash_message' => $msg, 'posts' => $posts)); } $contact = null; $create = Contact::transaction(function () use($posts, &$contact) { return verifyCreateOrm($contact = Contact::create(array_intersect_key($posts, Contact::table()->columns))); }); if (!($create && $contact)) { return redirect_message(array($this->get_class()), array('_flash_message' => '新增失敗,系統可能在維修,請稍候再嘗試一次!', 'posts' => $posts)); } delay_job('contacts', 'mail', array('id' => $contact->id)); return redirect_message(array($this->get_class()), array('_flash_message' => '新增成功,已經收到您的建議,我們會儘快回覆您!')); }
public function update() { if (!$this->has_post()) { return redirect_message(array('admin', $this->get_class(), $this->user->id, 'edit'), array('_flash_message' => '非 POST 方法,錯誤的頁面請求。')); } $posts = OAInput::post(); if ($msg = $this->_validation_posts($posts)) { return redirect_message(array('admin', $this->get_class(), $this->user->id, 'edit'), array('_flash_message' => $msg, 'posts' => $posts)); } if ($columns = array_intersect_key($posts, $this->user->table()->columns)) { foreach ($columns as $column => $value) { $this->user->{$column} = $value; } } $user = $this->user; $update = user::transaction(function () use($user) { return $user->save(); }); if (!$update) { return redirect_message(array('admin', $this->get_class(), $this->user->id, 'edit'), array('_flash_message' => '更新失敗!', 'posts' => $posts)); } $ori_keys = column_array($user->roles, 'name'); if (($del_keys = array_diff($ori_keys, $posts['roles'])) && ($roles = UserRole::find('all', array('select' => 'id', 'conditions' => array('user_id = ? AND name IN (?)', $user->id, $del_keys))))) { foreach ($roles as $role) { UserRole::transaction(function () use($role) { return $role->destroy(); }); } } if ($add_keys = array_diff($posts['roles'], $ori_keys)) { foreach ($add_keys as $add_key) { UserRole::transaction(function () use($add_key, $user) { return verifyCreateOrm(UserRole::create(Array_intersect_key(array('name' => $add_key, 'user_id' => $user->id), UserRole::table()->columns))); }); } } return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '更新成功!')); }
public function __construct() { parent::__construct(); if (!(User::current() && User::current()->is_login())) { Session::setData('_flash_message', '', true); return redirect_message(array('login'), array('_flash_message' => '請先登入,或者您沒有後台權限!')); } $class = $this->get_class(); $method = $this->get_method(); $menus_list = array_map(function ($menus) use($class, $method, &$has_active) { return array_map(function ($item) use($class, $method, &$has_active) { $has_active |= $a = isset($item['class']) && $item['class'] && $class == $item['class'] && (isset($item['method']) && $item['method']) && $method == $item['method'] || isset($item['class']) && $item['class'] && $class == $item['class'] && !(isset($item['method']) && $item['method']) || !(isset($item['class']) && $item['class']) && (isset($item['method']) && $item['method']) && $method == $item['method']; return array_merge($item, array('active' => $a)); }, $menus); }, array_filter(array_map(function ($group) { return array_filter($group, function ($item) { return User::current()->in_roles($item['roles']); }); }, Cfg::setting('menu', 'admin')))); if (!$has_active) { return redirect_message(array('admin'), array('_flash_message' => '您沒有此頁面的管理權限。')); } $this->set_componemt_path('component', 'admin')->set_frame_path('frame', 'admin')->set_content_path('content', 'admin')->set_public_path('public')->set_title(Cfg::setting('site', 'admin', 'title'))->_add_meta()->_add_css()->_add_js()->add_param('_menus_list', $menus_list); }
public function destroy() { $tag = $this->tag; $delete = ArticleTag::transaction(function () use($tag) { return $tag->destroy(); }); if (!$delete) { return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '刪除失敗!')); } $this->_clean_cell(); return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '刪除成功!')); }
public function sort($id, $sort) { if (!in_array($sort, array('up', 'down'))) { return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '排序失敗!')); } $total = WorkTag::count(array('conditions' => array('work_tag_id = ?', 0))); switch ($sort) { case 'up': $sort = $this->tag->sort; $this->tag->sort = $this->tag->sort - 1 < 0 ? $total - 1 : $this->tag->sort - 1; break; case 'down': $sort = $this->tag->sort; $this->tag->sort = $this->tag->sort + 1 >= $total ? 0 : $this->tag->sort + 1; break; } WorkTag::addConditions($conditions, 'sort = ? AND work_tag_id = ?', $this->tag->sort, 0); $tag = $this->tag; $update = WorkTag::transaction(function () use($conditions, $tag, $sort) { if (($next = WorkTag::find('one', array('conditions' => $conditions))) && (($next->sort = $sort) || true)) { if (!$next->save()) { return false; } } if (!$tag->save()) { return false; } return true; }); if (!$update) { return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '排序失敗!', 'posts' => $posts)); } return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '排序成功!')); }
public function destroy() { if (!User::current()->id) { return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '刪除失敗!')); } $posts = array('destroy_user_id' => User::current()->id); $article = $this->article; if ($columns = array_intersect_key($posts, $article->table()->columns)) { foreach ($columns as $column => $value) { $article->{$column} = $value; } } $delete = Article::transaction(function () use($article) { return $article->save(); }); if (!$delete) { return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '刪除失敗!')); } $this->_clean_cell($article); return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '刪除成功!')); }
public function sign_out() { Session::setData('user_id', 0); return redirect_message(func_get_args(), array('_flash_message' => '登出成功!')); }
public function destroy() { $work = $this->work; $delete = Work::transaction(function () use($work) { return $work->destroy(); }); if (!$delete) { return redirect_message(array('admin', 'work_tags', $this->tag->id, 'works'), array('_flash_message' => '刪除失敗!')); } return redirect_message(array('admin', 'work_tags', $this->tag->id, 'works'), array('_flash_message' => '刪除成功!')); }
public function destroy() { $promo = $this->promo; $delete = Promo::transaction(function () use($promo) { return $promo->destroy(); }); if (!$delete) { return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '刪除失敗!')); } return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '刪除成功!')); }
public function destroy() { $banner = $this->banner; $delete = Banner::transaction(function () use($banner) { return $banner->destroy(); }); if (!$delete) { return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '刪除失敗!')); } return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '刪除成功!')); }