Example #1
0
 /**
  * @param $id
  *
  * @return mixed
  */
 public function togglePublish($id)
 {
     $page = $this->page->find($id);
     $page->is_published = $page->is_published ? false : true;
     $page->save();
     return Response::json(array('result' => 'success', 'changed' => $page->is_published ? 1 : 0));
 }
Example #2
0
 public function action_update($id)
 {
     $post_page = Input::get('postpage') ? 1 : 0;
     $page = Page::where('page_name', '=', str_replace('-', '', Input::get('sub')))->first();
     $order = Page::order_by('created_at', 'desc')->first();
     $level = Input::get('subpage') ? $page->level + 1 : 0;
     $parent = Input::get('subpage') ? $page->slug : 'none';
     $slug = $this->slugger(Input::get('title'));
     $oldpage = Page::find($id);
     $oldpage->page_name = Input::get('title');
     $oldpage->page_content = Input::get('content');
     $oldpage->level = $level;
     $oldpage->parent = $parent;
     $oldpage->post_page = $post_page;
     $success = $oldpage->save();
     if (Input::get('subpage')) {
         $p = Page::where('page_name', '=', str_replace('-', '', Input::get('sub')))->first();
         $p->has_child = '1';
         $p->save();
     }
     if (!$success) {
         Log::write('/admin/pages/:id/edit', 'could not update page - $oldpage->save returned false');
         return Redirect::to("admin/pages/{$oldpage->id}/edit")->with('error_update', 'page could not be updated');
     }
     return Redirect::to("admin/pages/{$oldpage->id}/edit")->with('status_update', 'page updated');
 }
Example #3
0
 protected function createComponentPageEditForm($name)
 {
     $form = $this->createPageFormBase($name, false);
     if (!$form->isSubmitted()) {
         $id = $this->getParam("id");
         $page = Page::find($id);
         $values = $page->getValues();
         $values["tags"] = $page->Tags->fetchColumn("id");
         $form->setDefaults($values);
     }
     $presenter = $this;
     $form->onSubmit[] = function ($form) use($presenter) {
         $values = $form->values;
         try {
             $page = Page::create($values);
             $page->Tags = array_map(function ($id) {
                 return Tag::create($id);
             }, $values["tags"]);
             $page->save();
             $presenter->flashMessage("Page '{$page->name}' was changed!");
             $presenter->redirect("default", array("id" => $page->id));
         } catch (ModelException $e) {
             $page->addErrorsToForm($form);
         }
     };
 }
 public function destroy($id)
 {
     $page = Page::find($id);
     //$page->delete();
     Notification::success('The page was deleted.');
     return Redirect::route('admin.pages.index');
 }
Example #5
0
 public function index()
 {
     $page = Page::find(1);
     $menuItems = Page::where('parent_id', 0)->get();
     $news = News::with('user')->orderBy('created_at', 'desc')->first();
     return View::make('front.pages.index')->with(['page' => $page, 'news' => $news, 'menuitems' => $menuItems]);
 }
Example #6
0
 public function test_delete()
 {
     $pageService = new PageService(666);
     $page = $pageService->save(true, ['en_US' => new PageLangDTO('Name US', 'Content US', 'SEO Title US', 'SEO Description US', 'handle-us')]);
     $this->DELETE("/666/pages/{$page->id}");
     $page = Page::find($page->id);
     $this->assertNotNull($page->deleted_at);
 }
Example #7
0
 function view()
 {
     if (isset($_REQUEST['id'])) {
         $page = new Page();
         $this->columns = $page->_columns;
         $this->page = $page->find($_REQUEST['id']);
     }
 }
Example #8
0
 /**
  * Retrieves the given $url and returns the first match for the nonce regex or false if not found.
  * 
  * @param \Requests_Session $session The session to send the request from.
  * @param string $url The page URL.
  * @param string $regex The regex to use to find the nonce. It must have a single capture group.
  * 
  * @return string|false The nonce if found, otherwise false.
  */
 public static function findOnPage(\Requests_Session $session, $url, $regex = '/name="_wpnonce"\\s+value="(.+?)"/')
 {
     //TODO: improve this to be more than just a dumb regex match
     $nonceMatches = Page::find($session, $url, $regex);
     if (!is_array($nonceMatches) || count($nonceMatches) < 2 || empty($nonceMatches[1])) {
         return false;
     }
     return $nonceMatches[1];
 }
Example #9
0
 public static function listPagesUrl()
 {
     $model = Page::find()->asArray()->all();
     $pages = [];
     foreach ($model as $page) {
         $pages[$page['url']] = $page['name'];
     }
     return $pages;
 }
Example #10
0
 public function get_page($page_id)
 {
     if ($page = Page::find($page_id)) {
         if (Auth::check()) {
             History::add_page($page_id);
         }
         return view('content.page')->with('page', $page);
     }
     return Response::error('404');
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($url_seo)
 {
     $page = DB::table('banners')->where('url_seo', '=', $url_seo)->first();
     $id = $page->id;
     $page = Page::find($id);
     $page->visitas++;
     $page->save();
     // show the view and pass the nerd to it
     return View::make('pages.show', array('page' => $page));
 }
Example #12
0
 public function showDetails($id)
 {
     $page = Page::find($id);
     // If no item in database
     if (empty($page) || empty($page->id)) {
         return Redirect::route('home')->with('message', Lang::get('pages.inexistant'));
     }
     $this->layout->content = View::make('public.pages.details');
     $this->layout->content->page = $page;
     $this->layout->content_title = $page->title;
 }
 /**
  * Scoped finder for page versions
  *
  * @param page page object or page_id as number
  * @return array of page objects or null
  */
 public static function find($args = null)
 {
     if (is_array($args)) {
         if (array_key_exists('where', $args) and !empty($args['where'])) {
             $args['where'] .= ' and (behavior_id="version" or behavior_id="current_version")';
         } else {
             $args['where'] = '(behavior_id="version" or behavior_id="current_version")';
         }
     }
     return parent::find($args);
 }
Example #14
0
 /**
  * ページリストを取得する
  * 
  * @param string $categoryId
  * @return mixed boolean / array
  * @access public
  */
 function getPageList($categoryId = null)
 {
     if ($this->Page) {
         $conditions = array('Page.status' => 1);
         if ($categoryId) {
             $conditions['Page.page_category_id'] = $categoryId;
         }
         $this->Page->unbindModel(array('belongsTo' => array('PageCategory')));
         $pages = $this->Page->find('all', array('conditions' => $conditions, 'fields' => array('title', 'url'), 'order' => 'Page.sort'));
         return Set::extract('/Page/.', $pages);
     } else {
         return false;
     }
 }
Example #15
0
 /**
  * @param $postId
  * @param \User $author
  * @return bool|void
  */
 public static function minus($postId, \User $author)
 {
     $page = \Page::find(intval($postId));
     if (!$page) {
         return false;
     }
     if ($page->author_id == $author->id) {
         return $page->author_id;
     }
     if ($page->author->rate(-1)) {
         return $page->author_id;
     }
     return false;
 }
Example #16
0
 public function test_greater_less_search()
 {
     $page = Page::find_by_position(1);
     $matches = Page::find(array('position_less_than' => 2));
     FuzzyTest::assert_equal(count($matches), 1, "Should find one page here");
     $matches = Page::find_all_by_position_less_than(2);
     FuzzyTest::assert_equal(count($matches), 1, "Should find one page here");
     $matches = Page::find(array('position_greater_than' => 2));
     FuzzyTest::assert_equal(count($matches), 1, "Should find one page here");
     $matches = Page::find_all_by_position_greater_than(2);
     FuzzyTest::assert_equal(count($matches), 1, "Should find one page here");
     $matches = Page::find_all_by_position_greater_than_and_position_less_than(1, 3);
     FuzzyTest::assert_equal(count($matches), 1, "Should find one page here");
 }
Example #17
0
 public function deletePost()
 {
     if (Request::ajax()) {
         $id = (int) Input::get('id');
         $rules = array('id' => 'required');
         $validator = Validator::make(Input::all(), $rules);
         if ($validator->fails()) {
             return Response::json(['success' => false]);
         } else {
             if (Page::find($id)->delete()) {
                 return Response::json(['success' => true]);
             }
             return Response::json(['success' => false]);
         }
     }
 }
Example #18
0
 /**
  * delete
  *
  * @param mixed $id ID of record to delete
  * @param array $expected 期待値
  * @param string $message テストが失敗した時に表示されるメッセージ
  * @dataProvider deleteDataProvider
  */
 public function testDelete($id, $expected, $message = null)
 {
     // 削除したファイルを再生するため内容を取得
     $Page = $this->Page->find('first', ['conditions' => ['Page.id' => $id], 'fields' => ['Content.url'], 'recursive' => 0]);
     $path = APP . 'View' . DS . 'Pages' . $Page['Content']['url'] . '.php';
     $File = new File($path);
     $Content = $File->read();
     // 削除実行
     $this->Page->delete($id);
     $this->assertFileNotExists($path, $message);
     // 元のファイルを再生成
     $File->write($Content);
     $File->close();
     // 削除できているか確認用にデータ取得
     $result = $this->Page->exists($id);
     $this->assertEquals($expected, $result, $message);
 }
Example #19
0
 public function updatePage($id)
 {
     $page = Page::find($id);
     $input = ["titrePage" => Input::get('titrePage'), "titreLien" => Input::get('titreLien'), "submenu" => Input::get('submenu'), "contenu" => Input::get('contenu'), "slug" => Str::slug(Input::get('titreLien'))];
     $rules = array('titrePage' => 'required', 'titreLien' => 'required|max:255', 'submenu' => 'required|integer', 'contenu' => 'required');
     $messages = array('required' => ":attribute est requis pour la modification d'une page.", 'max' => "Le titre du lien est trop long.", 'integer' => "Sous-menu selectionné incorrect");
     $validator = Validator::make(Input::all(), $rules, $messages);
     if ($validator->fails()) {
         $messages = $validator->messages();
         return Redirect::to(URL::previous())->withErrors($validator);
     } else {
         Session::flash('flash_msg', "La page {$input['titrePage']} a bien été modifiée.");
         Session::flash('flash_type', "success");
         $page->fill($input)->save();
         return Redirect::to("/admin/pages/{$id}");
     }
 }
Example #20
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $validator = Validator::make(Input::all(), array('title' => 'required', 'slug' => 'regex:/^\\/[A-Za-z0-9_]+$/'));
     $page_update = Input::all();
     $page = Page::find($id);
     if ($validator->passes()) {
         $page->title = $page_update['title'];
         $page->body = $page_update['body'];
         $page->seo = $page_update['seo'];
         $page->slug = isset($page_update['slug']) ? $page_update['slug'] : $page->slug;
         $page->save();
         $banner = $this->bannerSet($page);
         return Redirect::to("/pages/")->withMessage("Page Updated");
     } else {
         return Redirect::to('pages/' . $page->id . '/edit')->withErrors($validator)->withMessage("Error ");
         return $this->respond(null, 'pages.edit', compact('page', 'banner'));
     }
 }
Example #21
0
File: Theme.php Project: eadz/chyrp
 /**
  * Function: pages_list
  * Returns a simple array of list items to be used by the theme to generate a recursive array of pages.
  *
  * Parameters:
  *     $start - Page ID or slug to start at.
  *     $exclude - Page ID to exclude from the list. Used in the admin area.
  */
 public function pages_list($start = 0, $exclude = null)
 {
     if (isset($this->pages_list[$start])) {
         return $this->pages_list[$start];
     }
     $this->linear_children = array();
     $this->pages_flat = array();
     $this->children = array();
     $this->end_tags_for = array();
     if ($start and !is_numeric($start)) {
         $begin_page = new Page(array("url" => $start));
     }
     $start = ($start and !is_numeric($start)) ? $begin_page->id : $start;
     $where = ADMIN ? array("id not" => $exclude) : array("show_in_list" => true);
     $pages = Page::find(array("where" => $where, "order" => "list_order ASC"));
     if (empty($pages)) {
         return $this->pages_list[$start] = array();
     }
     foreach ($pages as $page) {
         $this->end_tags_for[$page->id] = $this->children[$page->id] = array();
     }
     foreach ($pages as $page) {
         if ($page->parent_id != 0) {
             $this->children[$page->parent_id][] = $page;
         }
     }
     foreach ($pages as $page) {
         if (!$start and $page->parent_id == 0 or $start and $page->id == $start) {
             $this->recurse_pages($page);
         }
     }
     $array = array();
     foreach ($this->pages_flat as $page) {
         $array[$page->id]["has_children"] = !empty($this->children[$page->id]);
         if ($array[$page->id]["has_children"]) {
             $this->end_tags_for[$this->get_last_linear_child($page->id)][] = array("</ul>", "</li>");
         }
         $array[$page->id]["end_tags"] =& $this->end_tags_for[$page->id];
         $array[$page->id]["page"] = $page;
     }
     return $this->pages_list[$start] = $array;
 }
Example #22
0
 function __invoke($request, $response)
 {
     $exception = $response->getException();
     $code = $exception->getCode();
     if ($code == null or ENVIRONMENT === "production" and $code > 500) {
         $code = 500;
     }
     if (!($page = Page::find("_errors/{$code}"))) {
         $e = "No Error Page Template found. Make sure you have a file named " . "\"{$code}.txt\" in your \"/pages/_error\" directory";
         throw new \Spark\Controller\Exception($e);
     }
     $page->code = $code;
     $page->message = $exception->getMessage();
     $page->stackTrace = $exception->getTrace();
     $page->requestedPage = $request->meta("page");
     $page->exceptionType = get_class($exception);
     $page->requestUri = $request->getRequestUri();
     $page->requestMethod = $request->getMethod();
     $response->renderExceptions(false);
     $response->append($page);
 }
Example #23
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     var_dump(Input::get('content'));
     // validate
     // read more on validation at http://laravel.com/docs/validation
     $validator = Validator::make(Input::all(), Page::$rules);
     //var_dump(Input::all());
     // process the login
     if ($validator->fails()) {
         return Redirect::to('pages/' . $id . '/edit')->withErrors($validator)->withInput(Input::except('password'));
     } else {
         $page = Page::find($id);
         $page->name = Input::get('name');
         $page->content = Input::get('content');
         $page->save();
         Logfile::addData('Sửa', 'Page', $page->id, $page->name);
         // redirect
         Session::flash('message', 'Sủa Page  thành công!');
         return Redirect::to('pages');
     }
 }
Example #24
0
 /**
  * 固定ページ機能で作成したページの一覧データを取得する
  *
  * @param string $categoryId 固定ページカテゴリID(初期値 : null)※ 指定しない場合は全ページを取得
  * @param array $options オプション(初期値 : array())
  *	- `conditions` : 検索条件(初期値 : array('Page.status' => 1))
  *	- `fields` : 取得フィールド(初期値 : array('title', 'url'))
  *	- `order` : 並び順(初期値 : array('Page.sort'))
  * @return mixed ページ一覧、または、false
  */
 public function getPageList($categoryId = null, $options = array())
 {
     if (empty($this->_Page)) {
         return false;
     }
     if (!is_array($options)) {
         $options = array();
     }
     $options = array_merge(array('conditions' => array('Page.status' => 1), 'fields' => array('title', 'url'), 'order' => 'Page.sort'), $options);
     if ($categoryId) {
         $options['conditions']['Page.page_category_id'] = $categoryId;
     }
     $this->_Page->unbindModel(array('belongsTo' => array('PageCategory')));
     $pages = $this->_Page->find('all', $options);
     if (empty($pages)) {
         return false;
     }
     foreach ($pages as $key => $page) {
         $pages[$key]['Page']['url'] = $this->_Page->convertViewUrl($page['Page']['url']);
     }
     return Hash::extract($pages, '{n}.Page');
 }
 public function terms($app)
 {
     if (!$app->user->isLoggedIn()) {
         $app->output->redirect('/account/login');
     }
     $request = $app->router->flight->request();
     if ($request->data->agree == 'on') {
         $app->user->tos_agree = 1;
         $app->user->save();
     }
     if ($app->user->tos_agree) {
         $app->output->redirect('/');
     } else {
         $app->logger->log('Redirected to TOS', 'INFO', array(), 'user');
         $page = Page::find(3);
         $app->output->addBreadcrumb('', 'CSGOShop');
         $app->output->addBreadcrumb('account/terms', 'Terms & Conditions');
         $app->output->setTitle('Terms & Conditions');
         $app->output->setActiveTab('account');
         $app->output->render('account.terms', ['pageData' => $page]);
     }
 }
Example #26
0
 /**
  * Creates a new Project model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     foreach (Yii::$app->params['availableLocales'] as $key => $value) {
         $currentModel = Project::getLocaleInstance($key);
         $currentModel->locale = $key;
         if (Yii::$app->request->get('scenario')) {
             $currentModel->on_scenario = Yii::$app->request->get('scenario');
         }
         $models[$key] = $currentModel;
     }
     //set data from default model
     if (Yii::$app->request->get('locale_group_id')) {
         $defaultDomainModels = Page::find()->andFilterWhere(['domain_id' => Yii::getAlias('@defaultDomainId'), 'locale_group_id' => Yii::$app->request->get('locale_group_id')])->all();
         foreach ($defaultDomainModels as $key => $value) {
             if (!in_array($value->locale, array_keys(Yii::$app->params['availableLocales']))) {
                 continue;
             }
             $models[$value->locale]->slug = $value->slug;
             $models[$value->locale]->title = $value->title;
             $models[$value->locale]->head = $value->head;
             $models[$value->locale]->body = $value->body;
             $models[$value->locale]->before_body = $value->before_body;
             $models[$value->locale]->after_body = $value->after_body;
         }
     }
     $model = new MultiModel(['models' => $models]);
     if ($model->load(Yii::$app->request->post()) && Project::multiSave($model)) {
         return $this->redirect(['index']);
     } else {
         switch (Yii::$app->request->get('scenario')) {
             case 'extend':
                 $viewName = 'extend';
                 break;
             default:
                 $viewName = 'create';
         }
         return $this->render($viewName, ['model' => $model, 'categories' => ProjectCategory::find()->active()->all(), 'domains' => array_combine(explode(',', Yii::getAlias('@frontendUrls')), explode(',', Yii::getAlias('@frontendUrls')))]);
     }
 }
Example #27
0
 public function chi_tiet($id, $title)
 {
     $ip = Request::getClientIp();
     if (Cache::has($ip . '_viewpost_' . $id)) {
         $data['post'] = Cache::get($ip . '_viewpost_' . $id);
         $data['loai'] = $data['post']->loai;
         $data['title'] = $data['post']->title;
         $data['user'] = Cache::get($ip . '_user_' . $id);
     } else {
         $post = Page::find($id);
         $post->view = $post->view + 1;
         $post->save();
         $data['post'] = Cache::remember($ip . '_viewpost_' . $id, 15, function () use($id) {
             return Page::find($id);
         });
         $data['loai'] = $data['post']->loai;
         $data['title'] = $data['post']->title;
         $data['user'] = Cache::remember($ip . '_user_' . $id, 15, function () use($id) {
             return Page::find($id)->user()->get()->first();
         });
     }
     return View::make('template.view_post', $data);
 }
Example #28
0
 /**
  * 指定した固定ページデータの次、または、前のデータを取得する
  *
  * @param array $page 固定ページデータ
  * @param string $type next Or prev
  * @param bool $overCategory カテゴリをまたがるかどうか
  * @return array 次、または、前の固定ページデータ
  */
 protected function _getPageByNextOrPrev($page, $type, $overCategory = false)
 {
     switch ($type) {
         case 'next':
             $operator = '>';
             $sort = 'sort';
             break;
         case 'prev':
             $operator = '<';
             $sort = 'sort DESC';
             break;
     }
     if ($overCategory === true) {
         $requestAgent = Configure::read('BcRequest.agent');
         if ($requestAgent) {
             $pageCategoryConditions = array('Page.page_category_id' => $this->_getAgentCategoryIds($requestAgent));
         } else {
             $pageCategoryConditions = array('or' => array(array('Page.page_category_id !=' => $this->_getAllAgentCategoryIds()), array('Page.page_category_id' => null)));
         }
     } else {
         $pageCategoryConditions = array('Page.sort ' . $operator => $page['Page']['sort'], 'Page.page_category_id' => $page['Page']['page_category_id']);
     }
     return $this->Page->find('first', array('conditions' => array_merge(array(array('Page.sort ' . $operator => $page['Page']['sort']), $this->Page->getConditionAllowPublish(), $pageCategoryConditions)), 'fields' => array('title', 'url'), 'order' => $sort, 'recursive' => -1, 'cache' => false));
 }
Example #29
0
 /**
  * Store a newly created resource in storage.
  * POST /menuitems
  *
  * @return Response
  */
 public function store()
 {
     // tergantung tipe menu apa yang ingin disimpan, perilaku setiap tipe berbeda prosesnya
     $type = Input::get('menuitem_type');
     if ($type == 'page') {
         $inputdata = Input::all();
         $menu_id = $inputdata['menu_id'];
         foreach ($inputdata['menuitems'] as $menuitem) {
             if (isset($menuitem['id'])) {
                 $type = $menuitem['type'];
                 $id = $menuitem['id'];
                 // Set the item data based on type, manual code currently for each type. Refer to routes.
                 if ($type == 'page') {
                     $page = Page::find($id);
                     $itemdata['name'] = $page->title;
                     $itemdata['link'] = 'pages/' . $page->slug;
                     $itemdata['menu_id'] = $menu_id;
                 }
                 // Validate and crate the data
                 $validator = Validator::make($itemdata, MenuItem::$rules);
                 if ($validator->fails()) {
                     return Redirect::back()->withErrors($validator)->withInput();
                 }
                 MenuItem::create($itemdata);
             }
         }
     }
     if ($type == 'custom') {
         $validator = Validator::make(Input::all(), MenuItem::$rules);
         if ($validator->fails()) {
             return Redirect::back()->withErrors($validator)->withInput();
         }
         MenuItem::create(Input::except('menuitem_type'));
     }
     return Redirect::route('admin.menus.index')->with("message", "Data berhasil disimpan");
 }
Example #30
0
    $user->lastname = Input::get('lastname');
    $user->email = Input::get('email');
    $user->role = Input::get('role');
    $user->save();
    return Redirect::to('admin/users');
}), 'POST /admin/newpage/(:any?)' => array('before' => 'auth', function () {
    $rules = array('slug' => 'required', 'title' => 'required');
    $validator = Validator::make(Input::all(), $rules);
    if ($validator->invalid()) {
        return Redirect::to('admin/newpage')->with_errors($validator);
    }
    $slug = Input::get('slug');
    $slug = URL::slug($slug);
    //make url friendly
    if (Input::get('pageid')) {
        $page = Page::find(Input::get('pageid'));
    } else {
        $page = new Page();
    }
    $page->slug = $slug;
    $page->title = Input::get('title');
    $page->summary = Input::get('summary');
    $page->content = Input::get('content');
    $page->publish = Input::get('publish');
    $page->save();
    return Redirect::to('admin/pages');
}), 'POST /admin/newmedia' => array('before' => 'auth', function () {
    $imagename = time() . Input::file('image.name');
    File::upload('image', PUBLIC_PATH . 'img/' . $imagename);
    $newimage = PUBLIC_PATH . 'img/' . $imagename;
    $image = new Imagick($newimage);