Skip to content

Commit

Permalink
add pages
Browse files Browse the repository at this point in the history
  • Loading branch information
skywalker512 committed Jul 6, 2018
1 parent fc2530b commit 05feaaf
Show file tree
Hide file tree
Showing 13 changed files with 623 additions and 0 deletions.
12 changes: 12 additions & 0 deletions addons/languages/Chinese/definitions.Pages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$definitions["Manage Static Pages"] = "管理静态页面";
$definitions["Create Page"] = "创建页面";
$definitions["Edit Page"] = "编辑页面";
$definitions["Pages"] = "页面";
$definitions["Page title"] = "页面标题";
$definitions["Page slug"] = "页面URL";
$definitions["Page content"] = "页面内容(bbcode)";
$definitions["Input menu"] = "入口位置";
$definitions["Options"] = "选项";
$definitions["Hide field from guests"] = "对游客隐藏";
69 changes: 69 additions & 0 deletions addons/plugins/Pages/PageModel.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
// Copyright 2014 Toby Zerner, Simon Zerner
// This file is part of esoTalk. Please see the included license file for usage information.

if (!defined("IN_ESOTALK")) exit;

class PageModel extends ETModel {

public function __construct()
{
parent::__construct("page", "pageId");
}

public function getWithSQL($sql)
{
return $sql
->select("f.*")
->from("page f")
->orderBy("f.position ASC")
->exec()
->allRows();
}

public function setData($values)
{
if (!isset($values["title"])) $values["title"] = "";
$this->validate("title", $values["title"], array($this, "validateTitle"));

if (!isset($values["menu"])) $values["menu"] = "user";
$this->validate("menu", $values["menu"], array($this, "validateMenu"));

if (!isset($values["slug"])) $values["slug"] = "";
$this->validate("slug", $values["slug"], array($this, "validateSlug"));
$values["slug"] = slug($values["slug"]);

if ($this->errorCount()) return false;

$pageId = parent::create($values);
return $pageId;
}

public function deleteById($id)
{
return $this->delete(array("pageId" => $id));
}

public function validateTitle($title)
{
if (!strlen($title)) return "empty";
}

public function validateMenu($menu)
{
if (!in_array($menu, array('user','statistics','meta'))) return "empty";
}

public function validateSlug($slug)
{
if (!strlen($slug)) return "empty";
if (ET::SQL()
->select("COUNT(pageId)")
->from("page")
->where("slug=:slug")
->bind(":slug", $slug)
->exec()
->result() > 0)
return "channelSlugTaken";
}
}
128 changes: 128 additions & 0 deletions addons/plugins/Pages/PagesAdminController.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php
// This file is part of esoTalk. Please see the included license file for usage information.

if (!defined("IN_ESOTALK")) exit;

class PagesAdminController extends ETAdminController {

protected function model()
{
return ET::getInstance("pageModel");
}

protected function plugin()
{
return ET::$plugins["Pages"];
}

public function action_index()
{
$pages = $this->model()->get();

$this->addCSSFile($this->plugin()->resource("admin.css"));

$this->addJSFile("core/js/lib/jquery.ui.js");
$this->addJSFile($this->plugin()->resource("admin.js"));
$this->addJSLanguage("message.confirmDelete");

$this->data("pages", $pages);
$this->render($this->plugin()->view("admin/pages"));
}

public function action_edit($pageId = "")
{
if (!($page = $this->model()->getById((int)$pageId))) {
$this->render404();
return;
}

$form = ETFactory::make("form");
$form->action = URL("admin/pages/edit/".$page["pageId"]);
$form->setValues($page);

if ($form->isPostBack("cancel")) $this->redirect(URL("admin/pages"));

if ($form->validPostBack("save")) {

$data = array(
"title" => $form->getValue("title"),
"content" => $form->getValue("content"),
"slug"=>slug($form->getValue("slug")),
"hideFromGuests" => (bool)$form->getValue("hideFromGuests"),
"menu" => $form->getValue("menu")
);

$model = $this->model();
$model->updateById($page["pageId"], $data);

if ($model->errorCount()) $form->errors($model->errors());

else $this->redirect(URL("admin/pages"));
}

$this->data("form", $form);
$this->data("page", $page);
$this->render($this->plugin()->view("admin/editPage"));
}


public function action_create()
{
$form = ETFactory::make("form");
$form->action = URL("admin/pages/create");

if ($form->isPostBack("cancel")) $this->redirect(URL("admin/pages"));

if ($form->validPostBack("save")) {

$model = $this->model();

$data = array(
"title" => $form->getValue("title"),
"content" => $form->getValue("content"),
"slug"=>slug($form->getValue("slug")),
"hideFromGuests" => (bool)$form->getValue("hideFromGuests"),
"menu" => $form->getValue("menu"),
"position" => $model->count()
);

$model->create($data);

if ($model->errorCount()) $form->errors($model->errors());

else $this->redirect(URL("admin/pages"));
}

$this->data("form", $form);
$this->data("page", null);
$this->render($this->plugin()->view("admin/editPage"));
}


public function action_delete($pageId = "")
{
if (!$this->validateToken()) return;

// Get this field's details. If it doesn't exist, show an error.
if (!($page = $this->model()->getById((int)$pageId))) {
$this->render404();
return;
}

$this->model()->deleteById($page["pageId"]);

$this->redirect(URL("admin/pages"));
}

public function action_reorder()
{
if (!$this->validateToken()) return;

$ids = (array)R("ids");

for ($i = 0; $i < count($ids); $i++) {
$this->model()->updateById($ids[$i], array("position" => $i));
}
}

}
49 changes: 49 additions & 0 deletions addons/plugins/Pages/PagesController.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
// This file is part of esoTalk. Please see the included license file for usage information.

if (!defined("IN_ESOTALK")) exit;

class PagesController extends ETController {

protected function model()
{
return ET::getInstance("pageModel");
}

protected function plugin()
{
return ET::$plugins["Pages"];
}

public function action_index($pageSlug = false)
{
list($pageId,$slug) = explode('-',trim($pageSlug));
if(!is_numeric($pageId)){
$this->redirect(URL(""));
}

$page = $this->model()->getById((int)$pageId);

// Stop here with a 404 header if the page wasn't found.
if (!$page) {
$this->render404(T("message.pageNotFound"), true);
return false;
}elseif(!ET::$session->userId and $page['hideFromGuests']){
$this->render404(T("message.pageNotFound"), true);
return false;
}
$this->title = $page["title"];

if (strlen($page['content']) > 155) {
$description = substr($page['content'], 0, 155) . " ...";
$description = str_replace(array("\n\n", "\n"), " ", $description);
}else{
$description = $page["content"];
}
$this->addToHead("<meta name='description' content='".sanitizeHTML($description)."'>");

$page['content'] = ET::formatter()->init($page["content"])->format()->get();
$this->data("page", $page);
$this->render($this->plugin()->view("page"));
}
}
Binary file added addons/plugins/Pages/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added addons/plugins/Pages/index.html
Empty file.
Loading

0 comments on commit 05feaaf

Please sign in to comment.