/** * Gets the url where pages are displayed based on tag selected * * @since 1.4.0 */ public static function tag_url($page_id = NULL) { $page_option = $page_id !== NULL ? " AND id = {$page_id}" : ""; $sql = 'SELECT id FROM ' . TABLE_PREFIX . 'page WHERE behavior_id = "tagger"' . $page_option; $stmt = Record::getConnection()->prepare($sql); $stmt->execute(); $id = $stmt->fetchColumn(); if (!is_null($id) && $id !== false) { $page = Page::findById($id); $url = $page->getUri(); return BASE_URL . $url . '/'; } else { return self::tag_url(NULL); } }
/** * Executes on saving a page_part. * Cleans out any code (Not Textile or Markdown) and adds it to a dedicated search field. * * @param PagePart $page_part The object instance for the page_part that is being edited. */ function fsearch_clean_contents($page_part) { global $__FROG_CONN__; // Currently we only support searching in the Body-part (This is in the @todo) if ($page_part->name == 'body') { $page = Page::findById($page_part->page_id); $title = ''; if ($page) { $title = $page->title; if ($page->is_fsearchable == 1) { $sql = 'UPDATE ' . TABLE_PREFIX . 'page_part ' . ' SET content_fsearchable = ' . $__FROG_CONN__->quote($title . "\n\n" . strip_tags($page_part->content)) . ' ' . ' WHERE id=' . (int) $page_part->id; $__FROG_CONN__->exec($sql); } } } }
/** * Action to edit a page. * * @aram int $id Page ID for page to edit. * @return <type> */ public function edit($id) { if (!is_numeric($id)) { redirect(get_url('page')); } // Check if trying to save. if (get_request_method() == 'POST') { return $this->_store('edit', $id); } $page = Page::findById($id); if (!$page) { Flash::set('error', __('Page not found!')); redirect(get_url('page')); } // check for protected page and editor user if (!AuthUser::hasPermission('page_edit') || !AuthUser::hasPermission('admin_edit') && $page->is_protected) { Flash::set('error', __('You do not have permission to access the requested page!')); redirect(get_url('page')); } // Encode the string to prevent page title input break // Unless people specify "Allow html in title" in the backend. // Then only replace double quotes. if (!Setting::get('allow_html_title')) { $page->title = html_encode($page->title); } else { $page->title = str_replace('"', '"', $page->title); } // find all page_part of this pages $page_parts = PagePart::findByPageId($id); if (empty($page_parts)) { $page_parts = array(new PagePart()); } // display things ... $this->setLayout('backend'); $this->display('page/edit', array('action' => 'edit', 'csrf_token' => SecureToken::generateToken(BASE_URL . 'page/edit'), 'page' => $page, 'tags' => $page->getTags(), 'filters' => Filter::findAll(), 'behaviors' => Behavior::findAll(), 'page_parts' => $page_parts, 'layouts' => Record::findAllFrom('Layout', '1=1 ORDER BY position'))); }
private function setup($exclude_relations = [], $qrfields = []) { $postObject = get_post($this->id); $post_type = strtolower(get_called_class()); $_class = get_called_class(); $image_sizes = array_merge(['thumbnail', 'medium', 'large', 'full'], $this->getSizes()); $fields = $this->getFields(); $taxonomies = $this->getTaxonomies(); $modelDefaultFields = ['title', 'thumbnail', 'editor']; $multipleFields = ['checkbox_list', 'plupload_image', 'checkbox_tree']; // Post default properties foreach ($postObject as $key => $value) { $chave = str_replace('post_', '', $key); if ($this->shouldMount("post", $qrfields) || $this->shouldMount($chave, $qrfields)) { $this->{$chave} = $value; } } // Permalink if ($this->shouldMount('permalink', $qrfields)) { $this->permalink = get_permalink($this->ID); } // Default post taxonomies if ($post_type == "post" && empty($taxonomies)) { $taxonomies = array("post_tag", "category"); } // Author $author = new \stdClass(); if ($this->shouldMount('author', $qrfields)) { foreach (array('ID', 'display_name', 'nickname', 'first_name', 'last_name', 'description', 'email') as $field) { $author->{$field} = get_the_author_meta($field, $this->author); } } if ($this->shouldMount('author', $qrfields)) { $this->author = $author; } if ($post_type == "post" || $this->shouldMount('content', $qrfields)) { $this->content = apply_filters('the_content', $this->content); } // Terms if (!empty($taxonomies) && $this->shouldMount('taxonomies', $qrfields)) { foreach ($taxonomies as $taxonomy) { $terms = array(); $obj = get_the_terms($this->ID, $taxonomy); if (is_array($obj)) { foreach ($obj as $term) { $term->link = get_term_link($term->term_id, $taxonomy); array_push($terms, $term); } } $this->{$taxonomy} = $terms; } } // Custom fields foreach ($fields as $key => $value) { $is_multiple = !empty($value['multiple']) && $value['multiple']; if (!in_array($key, $modelDefaultFields) && $this->shouldMount($key, $qrfields)) { if ($value['type'] !== 'image' && $value['type'] !== 'file') { if ($is_multiple || in_array($value['type'], $multipleFields)) { $this->{$key} = get_post_meta($postObject->ID, $key); } else { $this->{$key} = get_post_meta($postObject->ID, $key, true); } } else { switch ($value['type']) { case 'image': $this->{$key} = $this->getImage($postObject, $key, $value); break; case 'file': $this->{$key} = $this->getFile($postObject, $key, $value); break; } } } } // Relations $has_many = Store::get('relation_has_many'); if ($this->shouldMount('relations', $qrfields)) { foreach ($has_many as $many) { if ($many['target'] == $post_type && !in_array($many['model'], $exclude_relations)) { $manyqr = new \WP_Query(['post_type' => $many['model'], 'meta_key' => $many['target'], 'meta_value' => $this->ID]); if ($manyqr->have_posts()) { $ids = []; foreach ($manyqr->posts as $_post) { $klass = $this->getClass($many['model']); array_push($ids, new $klass($_post->ID, [$many['target']])); } $this->{$many['model']} = $ids; } else { $this->{$many['model']} = []; } } else { if ($many['model'] == $post_type) { if (is_array($this->{$many['target']})) { $ids = []; foreach ($this->{$many['target']} as $item) { $klass = $this->getClass($many['target']); array_push($ids, new $klass($item, [$many['model']])); } $this->{$many['target']} = $ids; } else { $klass = $this->getClass($many['target']); $this->{$many['target']} = new $klass($this->{$many['target']}, [$many['model']]); } } } } } $belongs_to = Store::get('relation_belongs_to'); if ($this->shouldMount('relations', $qrfields)) { foreach ($belongs_to as $bel) { if ($bel['target'] == $post_type && !in_array($bel['model'], $exclude_relations)) { $belqr = new \WP_Query(['post_type' => $bel['model'], 'meta_key' => $bel['target'], 'meta_value' => $this->ID]); if ($belqr->have_posts()) { $klass = $this->getClass($bel['model']); $this->{$bel['model']} = new $klass($belqr->posts[0], [$bel['target']]); } else { $this->{$bel['model']} = null; } } else { if ($bel['model'] == $post_type) { $klass = $this->getClass($bel['target']); $this->{$bel['target']} = new $klass($this->{$bel['target']}, [$bel['model']]); } } } } // Include subpages if ($post_type == 'page' && $this->shouldMount('children', $qrfields)) { $my_wp_query = new \WP_Query(); $all_wp_pages = $my_wp_query->query(array('post_type' => 'page')); // Filter through all pages and find Portfolio's children $children = get_page_children($this->ID, $all_wp_pages); $this->children = array(); foreach ($children as $child) { array_push($this->children, \Page::findById($child->ID)); } } // Set the thumbnail if ($this->shouldMount('thumbnail', $qrfields)) { $image = get_post_thumbnail_id($postObject->ID); $img = new \stdClass(); foreach ($image_sizes as $s) { $wp_image = wp_get_attachment_image_src($image, $s); $img->{$s} = $wp_image[0]; } $this->thumbnail = $img; } }
public static function findBySlugAndParentId($slug, $parent_id = 0, $class = __CLASS__) { /* TODO: Behaviour pagehack seems kludgish. */ $parent = Page::findById($parent_id); if ($parent && $parent->behaviorId()) { $class = Behavior::loadPageHack($parent->behaviorId()); } $params['where'] = sprintf("slug=%s AND parent_id=%d", self::connection()->quote($slug), $parent_id); $sql = Record::buildSql($params, $class); // print_r(self::connection()->query($sql, PDO::FETCH_CLASS, $class)->fetch()); return self::connection()->query($sql, PDO::FETCH_CLASS, $class)->fetch(); }
public static function countVersionsFrom($page) { if (is_numeric($page)) { $page = Page::findById($page); } return $page->childrenCount(array('where' => 'behavior_id="versions" or behavior_id="current_version"'), array(), true); }
protected function setUrl() { $page = Page::findById($this->id); $this->url = trim($page->getUri(), '/'); }
public function preview_json() { $json = '{ "slides":"' . addslashes($this->get_inner()) . '", '; $json .= '"aid":' . $this->aid . ', '; $json .= '"page_id":' . $this->page_id . ', '; $json .= '"page_url":"' . Page::findById($this->page_id)->url() . '", '; $json .= '"speed":' . $this->speed . ', '; $json .= '"transition":"' . $this->transition . '", '; $json .= '"show_indicators":' . var_export($this->show_indicators, true) . ', '; $json .= '"random":' . var_export($this->random, true) . ', '; $json .= '"pause_on_hover":' . var_export($this->pause_on_hover, true) . ', '; $json .= '"include_style":' . var_export($this->include_style, true) . ', '; $json .= '"ssp_ss":"' . $this->elid . '"'; $json .= '}'; return $json; }
private function _edit($id) { $data = $_POST['page']; $page = Page::findById($id); // need to do this because the use of a checkbox $data['is_protected'] = !empty($data['is_protected']) ? 1 : 0; $page->setFromData($data); Observer::notify('page_edit_before_save'); if ($page->save()) { // get data for parts of this page $data_parts = $_POST['part']; $old_parts = PagePart::findByPageId($id); // check if all old page part are passed in POST // if not ... we need to delete it! foreach ($old_parts as $old_part) { $not_in = true; foreach ($data_parts as $part_id => $data) { $data['name'] = trim($data['name']); if ($old_part->name == $data['name']) { $not_in = false; $part = new PagePart($data); $part->page_id = $id; $part->save(); unset($data_parts[$part_id]); break; } } if ($not_in) { $old_part->delete(); } } // add the new ones foreach ($data_parts as $part_id => $data) { $data['name'] = trim($data['name']); $part = new PagePart($data); $part->page_id = $id; $part->save(); } // save tags $page->saveTags($_POST['page_tag']['tags']); Flash::set('success', __('Page has been saved!')); /* Successfully edited so notify. */ Observer::notify('page_edit_after_save', $page); } else { Flash::set('error', __('Page has not been saved!')); redirect(get_url('page/edit/' . $id)); } // save and quit or save and continue editing ? if (isset($_POST['commit'])) { redirect(get_url('page')); } else { redirect(get_url('page/edit/' . $id)); } }
<?php $id = isset($vars[1]) ? $vars[1] : null; $object = Page::findById($id); $error_flag = false; if ($object) { if ($object->delete()) { Message::register(new Message(Message::SUCCESS, i18n(array('en' => 'Record deleted', 'zh' => '记录删除成功')))); } else { $error_flag = true; } } else { $error_flag = true; } if ($error_flag) { Message::register(new Message(Message::DANGER, i18n(array('en' => 'Record deletion failed', 'zh' => '记录删除失败')))); } HTML::forwardBackToReferer();
public function edit($id = null) { if (is_null($id)) { redirect(get_url('page')); } $page = Page::findById($id); if (!$page) { Flash::set('error', __('Page not found!')); redirect(get_url('page')); } // check for protected page and editor user if (!AuthUser::hasPermission('administrator') && !AuthUser::hasPermission('developer') && $page->is_protected) { Flash::set('error', __('You do not have permission to access the requested page!')); redirect(get_url('page')); } // check if trying to save if (get_request_method() == 'POST') { return $this->_edit($id); } // find all page_part of this pages $page_parts = PagePart::findByPageId($id); if (empty($page_parts)) { $page_parts = array(new PagePart()); } // display things ... $this->setLayout('backend'); $this->display('page/edit', array('action' => 'edit', 'page' => $page, 'tags' => $page->getTags(), 'filters' => Filter::findAll(), 'behaviors' => Behavior::findAll(), 'page_parts' => $page_parts, 'layouts' => Record::findAllFrom('Layout', '1=1 ORDER BY position'))); }
public static function cloneTree($page, $parent_id) { /* This will hold new id of root of cloned tree. */ static $new_root_id = false; /* Clone passed in page. */ $clone = Page::findById($page->id); $clone->parent_id = (int) $parent_id; $clone->id = null; if (!$new_root_id) { $clone->title .= " (copy)"; $clone->slug .= "-copy"; } $clone->save(); /* Also clone the page parts. */ $page_part = PagePart::findByPageId($page->id); if (count($page_part)) { foreach ($page_part as $part) { $part->page_id = $clone->id; $part->id = null; $part->save(); } } /* Also clone the page tags. */ $page_tags = $page->getTags(); if (count($page_tags)) { foreach ($page_tags as $tag_id => $tag_name) { // create the relation between the page and the tag $tag = new PageTag(array('page_id' => $clone->id, 'tag_id' => $tag_id)); $tag->save(); } } /* This gets set only once even when called recursively. */ if (!$new_root_id) { $new_root_id = $clone->id; } /* Clone and update childrens parent_id to clones new id. */ if (Page::hasChildren($page->id)) { foreach (Page::childrenOf($page->id) as $child) { Page::cloneTree($child, $clone->id); } } return $new_root_id; }
public static function find($args = null) { if (is_int($args)) { // Assumes find was called with an id return Page::findById($args); } if (is_string($args)) { // Assumes find was called with a uri return Page::findByUri($args); } elseif (!is_array($args)) { $args = (array) $args; } // Collect attributes... $where = isset($args['where']) ? trim($args['where']) : ''; $order_by = isset($args['order']) ? trim($args['order']) : ''; $offset = isset($args['offset']) ? (int) $args['offset'] : 0; $limit = isset($args['limit']) ? (int) $args['limit'] : 0; $values = isset($args['values']) ? (array) $args['values'] : null; // Prepare query parts $where_string = empty($where) ? '' : "WHERE {$where}"; $order_by_string = empty($order_by) ? '' : "ORDER BY {$order_by}"; $limit_string = $limit > 0 ? "LIMIT {$offset}, {$limit}" : ''; $tablename = self::tableNameFromClassName('Page'); $tablename_user = self::tableNameFromClassName('User'); // Prepare SQL $sql = "SELECT page.*, creator.name AS created_by_name, updater.name AS updated_by_name FROM {$tablename} AS page" . " LEFT JOIN {$tablename_user} AS creator ON page.created_by_id = creator.id" . " LEFT JOIN {$tablename_user} AS updater ON page.updated_by_id = updater.id" . " {$where_string} {$order_by_string} {$limit_string}"; $stmt = self::$__CONN__->prepare($sql); if ($values) { $stmt->execute($values); } else { $stmt->execute(); } // Run! if ($limit == 1) { return $stmt->fetchObject('Page'); // $page = $stmt->fetchObject('Page'); // if ( ! empty($page->behavior_id)) { // $page_class = Behavior::loadPageHack($page->behavior_id); // $ret = new $page_class($page); // } else { // $ret = $page; // } } else { $objects = array(); while ($object = $stmt->fetchObject('Page')) { $objects[] = $object; } return $objects; // $ret = array(); // while ($page = $stmt->fetchObject('Page')){ // if ( ! empty($page->behavior_id)) { // $page_class = Behavior::loadPageHack($page->behavior_id); // $page = new $page_class($page); // } // $ret[] = $page; // } } // return $ret; }
public static function commentUnapprove($comment) { $page = Page::findById($comment->page_id); $link = sprintf('<a href="%s">%s</a>', get_url("plugin/comment/edit/" . $comment->id), __("comment")); $title = sprintf('<a href="%s">%s</a>', get_url("page/edit/" . $page->id), $page->title); $replace = array(":admin" => AuthUser::getRecord()->name, ":author" => $comment->author_name, ":comment" => $link, ":page" => $title); $message = __(":admin rejected a :comment by :author on :page.", $replace); self::logEvent($message, "core"); }
*/ include_once 'lib/Chapter.php'; include_once 'lib/Comic.php'; include_once 'lib/Page.php'; $requestMethod = $_SERVER['REQUEST_METHOD']; // Get all images and chapters if ($requestMethod == 'GET') { $comic = Comic::factory(); echo json_encode($comic->toArray()); } // Only logged in users have access to POST and DELETE if (!current_user_can('upload_files')) { return; } if ($requestMethod == 'DELETE') { $page = Page::findById($_GET['page_id']); if (!$page) { return; } $page->delete(); } if ($requestMethod == 'POST') { $data = $_POST; $resourceType = $data['resource']; if ($resourceType == 'page') { $resource = new Page($data['page_name'], $data['page_number'], $data['chapter_id'], $_FILES['page_image']['name']); // Upload the image $filePath = $_FILES['page_image']['tmp_name']; $newFilePath = getcwd() . '/../../../wp-content/uploads/live/' . $_FILES['page_image']['name']; rename($filePath, $newFilePath); chmod($newFilePath, 0644);