<?php include 'PerchContent_Pages.class.php'; include 'PerchContent_Page.class.php'; include 'PerchContent_Regions.class.php'; include 'PerchContent_Region.class.php'; $Pages = new PerchContent_Pages(); $pages = $Pages->get_by_parent(0); $Regions = new PerchContent_Regions(); $shared = $Regions->get_shared(); ?> <div class="widget"> <h2> <?php echo PerchLang::get('Pages'); if ($CurrentUser->has_priv('content.pages.create')) { echo '<a href="' . PerchUtil::html(PERCH_LOGINPATH . '/core/apps/content/page/add/') . '" class="add button">' . PerchLang::get('Add Page') . '</a>'; } ?> </h2> <div class="bd"> <?php if (PerchUtil::count($pages)) { echo '<ul>'; if (PerchUtil::count($shared)) { echo '<li>'; echo '<a href="' . PerchUtil::html(PERCH_LOGINPATH) . '/core/apps/content/page/?id=-1">'; echo PerchUtil::html(PerchLang::get('Shared')); echo '</a>'; echo '</li>'; }
<?php if (isset($_GET['id']) && is_numeric($_GET['id'])) { $id = (int) $_GET['id']; $Pages = new PerchContent_Pages(); $Page = $Pages->find($id); } $Form = new PerchForm('delete'); if (!$Page || !is_object($Page)) { PerchUtil::redirect(PERCH_LOGINPATH . '/core/apps/content'); } // Check permission to delete if (!$CurrentUser->has_priv('content.pages.delete')) { if ($CurrentUser->has_priv('content.pages.delete.own') && $Page->pageCreatorID() == $CurrentUser->id()) { // ok - they can delete their own pages } else { if ($Form->submitted_via_ajax) { echo PERCH_LOGINPATH . '/core/apps/content'; exit; } else { PerchUtil::redirect(PERCH_LOGINPATH . '/core/apps/content'); } } } /* --------- Delete Form ----------- */ if ($Form->posted() && $Form->validate()) { $Page->delete(); if ($Form->submitted_via_ajax) { echo PERCH_LOGINPATH . '/core/apps/content/'; exit; } else {
public function get_page_by_path($path) { if (isset($this->pages_cache[$path])) { return $this->pages_cache[$path]; } $Pages = new PerchContent_Pages(); $Page = $Pages->find_by_path($path); if (is_object($Page)) { $this->pages_cache[$path] = $Page; } return $this->pages_cache[$path]; }
/** * Unshare the region, reverting to original page where possible * * @return void * @author Drew McLellan */ public function make_not_shared() { $Pages = new PerchContent_Pages(); $Page = $Pages->find($this->pageID()); if (is_object($Page)) { $data = array(); $data['regionPage'] = $Page->pagePath(); $this->update($data); $Perch = Perch::fetch(); $Perch->event('region.unshare', $this); return true; } return false; }
<?php if (isset($_GET['id']) && is_numeric($_GET['id'])) { $id = (int) $_GET['id']; $Regions = new PerchContent_Regions(); $Region = $Regions->find($id); $Pages = new PerchContent_Pages(); if (is_object($Region)) { if ($Region->regionPage() == '*') { $Page = $Pages->get_mock_shared_page(); } else { $Page = $Pages->find($Region->pageID()); } } } if (!$Region || !is_object($Region)) { PerchUtil::redirect(PERCH_LOGINPATH . '/core/apps/content'); } // Check permission to delete if ($CurrentUser->has_priv('content.regions.delete') || $CurrentUser->has_priv('content.pages.delete.own') && $Page->pageCreatorID() == $CurrentUser->id()) { // we're ok. } else { PerchUtil::redirect(PERCH_LOGINPATH . '/core/apps/content'); } /* --------- Delete Form ----------- */ $Form = new PerchForm('delete'); if ($Form->posted() && $Form->validate()) { $Region->delete(); if ($Form->submitted_via_ajax) { echo PERCH_LOGINPATH . '/core/apps/content/page/?id=' . $Page->id(); exit;
function perch_page_url($opts = array(), $return = false) { $default_opts = array('hide-extensions' => false, 'hide-default-doc' => true, 'add-trailing-slash' => false, 'include-domain' => true); if (is_array($opts)) { $opts = array_merge($default_opts, $opts); } else { $opts = $default_opts; } $Pages = new PerchContent_Pages(); $r = $Pages->get_full_url($opts); if ($return) { return $r; } echo PerchUtil::html($r); }
public function move_file($new_location) { $new_location = PerchUtil::file_path($new_location); $new_location = str_replace(PERCH_LOGINPATH, '/', $new_location); $new_location = str_replace('\\', '/', $new_location); $new_location = str_replace('..', '', $new_location); $new_location = str_replace('//', '/', $new_location); $old_path = PERCH_SITEPATH . $this->pagePath(); $new_path = PerchUtil::file_path(PERCH_SITEPATH . '/' . ltrim($new_location, '/')); if ($old_path != $new_path) { if (file_exists($old_path)) { if (!file_exists($new_path)) { $new_dir = PerchUtil::strip_file_name($new_path); if (!file_exists($new_dir)) { mkdir($new_dir, 0755, true); } if (is_writable($new_dir)) { if (rename($old_path, $new_path)) { // Is it a reference to a master page? If so, update the include $contents = file_get_contents($new_path); $pattern = '#' . preg_quote("<?php include(str_replace('/', DIRECTORY_SEPARATOR, 'XXX')); ?>") . '#'; $pattern = str_replace('XXX', '([a-zA-Z/\\.-]+)', $pattern); if (preg_match($pattern, $contents, $match)) { $current_path = $match[1]; $template_dir = PERCH_TEMPLATE_PATH . '/pages'; $template_path = str_replace(PERCH_SITEPATH . DIRECTORY_SEPARATOR, '', PERCH_TEMPLATE_PATH) . '/pages/'; // normalise $current_path = str_replace(DIRECTORY_SEPARATOR, '/', $current_path); $template_dir = str_replace(DIRECTORY_SEPARATOR, '/', $template_dir); $template_path = str_replace(DIRECTORY_SEPARATOR, '/', $template_path); $parts = explode($template_path, $current_path); if (PerchUtil::count($parts)) { $master_page_template = $parts[1]; $Pages = new PerchContent_Pages(); $a = PerchUtil::file_path($template_dir . '/' . $master_page_template); $b = PerchUtil::file_path(dirname($new_path)); $new_include_path = $Pages->get_relative_path($a, $b); $new_include = '<' . '?php include(str_replace(\'/\', DIRECTORY_SEPARATOR, \'' . $new_include_path . '\')); ?' . '>'; /* $new_include .= '<' . '?php /* '.PHP_EOL; $new_include .= 'Current path: '.$current_path.PHP_EOL; $new_include .= 'Template dir: '.$template_dir.PHP_EOL; $new_include .= 'Template path: '.$template_path.PHP_EOL; $new_include .= 'Master page template: '.$master_page_template.PHP_EOL; $new_include .= 'A: '.$a.PHP_EOL; $new_include .= 'B: '.$b.PHP_EOL; $new_include .= 'New include path: '.$new_include_path.PHP_EOL; $new_include .= 'Parts: '.print_r($parts, true).PHP_EOL; $new_include .= PHP_EOL.' *'.'/ ?' . '>'; */ file_put_contents($new_path, str_replace($match[0], $new_include, $contents)); } } else { // Else just update the Perch runtime. $pattern = '#' . preg_quote("include(__Y____X__" . trim(PERCH_LOGINPATH, '/') . "__DS__runtime.php__Y__);") . '#'; $pattern = str_replace('__X__', '([a-zA-Z/\\.-]*)', $pattern); $pattern = str_replace('__Y__', '[\'\\"]', $pattern); $pattern = str_replace('__DS__', '[\\\\/]', $pattern); if (preg_match($pattern, $contents, $match)) { PerchUtil::debug($match); $Pages = new PerchContent_Pages(); $a = PerchUtil::file_path(PERCH_PATH . '/runtime.php'); $b = PerchUtil::file_path(dirname($new_path)); $new_include_path = $Pages->get_relative_path($a, $b); PerchUtil::debug('New include path: ' . $new_include_path); $new_include = "include('{$new_include_path}');"; file_put_contents($new_path, str_replace($match[0], $new_include, $contents)); } } return array(true, false); } else { return array(false, 'The page could not be moved.'); } } else { return array(false, 'The destination folder could not be written to, so the page cannot be moved.'); } } else { return array(false, 'A page file already exists at the new location.'); } } else { return array(false, 'No page file exists at that location to move.'); } } else { // It's ok, as the file is already where they want it to be. return array(true, false); } }
public function render_inputs($details = array()) { $Perch = Perch::fetch(); $page = false; // Find the path path. // // Has it been set as an attribute? if ($this->Tag->page()) { $page = $this->Tag->page(); } // Has the PageID been set from the edit page? if (!$page && $this->Tag->page_id()) { $Pages = new PerchContent_Pages(); $Page = $Pages->find($this->Tag->page_id()); if ($Page) { $page = $Page->pagePath(); } } // Use the current page. if (!$page) { $page = $Perch->get_page(); } $region = $this->Tag->region(); $field_id = $this->Tag->options(); $values_id = $this->Tag->values(); if (!class_exists('PerchContent_Regions', false)) { include_once PERCH_CORE . '/apps/content/PerchContent_Regions.class.php'; include_once PERCH_CORE . '/apps/content/PerchContent_Items.class.php'; include_once PERCH_CORE . '/apps/content/PerchContent_Item.class.php'; } $Regions = new PerchContent_Regions(); $opts = $Regions->find_data_select_options($page, $region, $field_id, $values_id); if (PerchUtil::bool_val($this->Tag->allowempty()) == true) { array_unshift($opts, array('label' => '', 'value' => '')); } return $this->Form->select($this->Tag->input_id(), $opts, $this->Form->get($details, $this->Tag->id(), $this->Tag->default(), $this->Tag->post_prefix())); }
<?php $Pages = new PerchContent_Pages(); $Page = false; // Find the page if (isset($_GET['id']) && is_numeric($_GET['id'])) { $id = (int) $_GET['id']; $Page = $Pages->find($id); } // Check we have a page if (!$Page || !is_object($Page)) { PerchUtil::redirect(PERCH_LOGINPATH . '/core/apps/content/'); } // Check permissions if (!$CurrentUser->has_priv('content.pages.attributes')) { PerchUtil::redirect(PERCH_LOGINPATH . '/core/apps/content/'); } // Page attributes $API = new PerchAPI(1.0, 'perch_pages'); $Page->api($API); $Template = $API->get('Template'); $status = $Template->set('pages/attributes/' . $Page->pageAttributeTemplate(), 'pages'); if ($status == 404) { $Alert->set('notice', PerchLang::get('The page attribute template (%s) could not be found.', '<code>templates/pages/attributes/' . $Page->pageAttributeTemplate() . '</code>')); } $details = $Page->to_array(); $Form = $API->get('Form'); $Form->handle_empty_block_generation($Template); $req = array(); $req['pageTitle'] = "Required"; $req['pageNavText'] = "Required";
function perch_members_check_page_access() { $Session = PerchMembers_Session::fetch(); if ($Session->logged_in) { $user_tags = $Session->get_tags(); } else { $user_tags = array(); } if (!is_array($user_tags)) { $user_tags = array(); } $Page = PerchSystem::get_page_object(); if (!$Page) { $Pages = new PerchContent_Pages(); $Perch = Perch::fetch(); $Page = $Pages->find_by_path($Perch->get_page()); if ($Page instanceof PerchContent_Page) { PerchSystem::set_page_object($Page); } } if ($Page) { $page_tags = $Page->access_tags(); if (!is_array($page_tags)) { $page_tags = array(); } if (PerchUtil::count($page_tags)) { $intersection = array_intersect($user_tags, $page_tags); if (PerchUtil::count($intersection) === 0) { // no access! $API = new PerchAPI(1.0, 'perch_members'); $Settings = $API->get('Settings'); $redirect_url = $Settings->get('perch_members_login_page')->val(); if ($redirect_url) { $redirect_url = str_replace('{returnURL}', $Perch->get_page(), $redirect_url); PerchUtil::redirect($redirect_url); } else { die('Access denied.'); } } } } }
<?php $Pages = new PerchContent_Pages(); $Regions = new PerchContent_Regions(); $Page = false; $NavGroups = new PerchContent_NavGroups(); $PageTemplates = new PerchContent_PageTemplates(); if (PERCH_RUNWAY) { $PageRoutes = new PerchPageRoutes(); $Collections = new PerchContent_Collections(); } // Find the page if (isset($_GET['id']) && is_numeric($_GET['id'])) { $id = (int) $_GET['id']; $Page = $Pages->find($id); } // Check we have a page if (!$Page || !is_object($Page)) { PerchUtil::redirect(PERCH_LOGINPATH . '/core/apps/content/'); } // Check permissions if (!$CurrentUser->has_priv('content.pages.edit')) { PerchUtil::redirect(PERCH_LOGINPATH . '/core/apps/content/'); } $ParentPage = $Pages->find($Page->pageParentID()); $Form = new PerchForm('editpage'); $req = array(); $req['pagePath'] = "Required"; $Form->set_required($req); if ($Form->posted() && $Form->validate()) { $postvars = array('pagePath', 'pageSubpagePath', 'pageHidden', 'pageAccessTags', 'pageAttributeTemplate');
<?php $Pages = new PerchContent_Pages(); $Regions = new PerchContent_Regions(); $Perch->add_javascript(PERCH_LOGINPATH . '/core/assets/js/jquery.ui.nestedSortable.js'); $Form = new PerchForm('order'); if ($Form->posted() && $Form->validate()) { // JavaScript tree ordering if (isset($_POST['orders']) && $_POST['orders'] != '') { $pages = explode('&', $_POST['orders']); $sort_orders = array(); if (PerchUtil::count($pages)) { foreach ($pages as $str) { if (trim($str) != '') { $parts = explode('=', $str); $pageID = str_replace(array('page[', ']'), '', $parts[0]); $parentID = $parts[1]; if ($parentID == 'root') { $parentID = '0'; } if (!isset($sort_orders[$parentID])) { $sort_orders[$parentID] = 1; } else { $sort_orders[$parentID]++; } $order = $sort_orders[$parentID]; $Page = $Pages->find($pageID); if (is_object($Page)) { $Page->update_tree_position($parentID, $order); } }
<?php $Pages = new PerchContent_Pages(); $Regions = new PerchContent_Regions(); $Page = false; $collections = false; // Find the page if (isset($_GET['id']) && is_numeric($_GET['id'])) { $id = (int) $_GET['id']; if ($id == -1) { $Page = $Pages->get_mock_shared_page(); } else { $Page = $Pages->find($id); } } // Check we have a page if (!$Page || !is_object($Page)) { PerchUtil::redirect(PERCH_LOGINPATH . '/core/apps/content/'); } if (PERCH_RUNWAY) { $Collections = new PerchContent_Collections(); if ($Page->pageCollections()) { $collections = $Collections->get_by_id_string($Page->pageCollections()); } } if ($Page->pagePath() == '*') { $regions = $Regions->get_shared(); } else { $regions = $Regions->get_for_page($Page->id(), $include_shared = false); }
public function process_response($SubmittedForm) { $opts = $this->_load_options(); $data = array(); $data['fields'] = array(); $data['files'] = array(); $data['page'] = $SubmittedForm->page; if (class_exists('PerchContent_Pages')) { $Pages = new PerchContent_Pages(); $Page = $Pages->find_by_path($SubmittedForm->page); if ($Page) { $data['page'] = array('id' => $Page->pageID(), 'title' => $Page->pageTitle(), 'path' => $Page->pagePath(), 'navtext' => $Page->pageNavText()); } } // Anti-spam $spam = false; $antispam = $SubmittedForm->get_antispam_values(); $environment = $_SERVER; $akismetAPIKey = false; if (isset($opts->akismet) && $opts->akismet) { if (isset($opts->akismetAPIKey) && $opts->akismetAPIKey != '') { $akismetAPIKey = $opts->akismetAPIKey; } } $spam = $this->_check_for_spam($antispam, $environment, $akismetAPIKey); // Files if (!$spam && PerchUtil::count($SubmittedForm->files)) { if (isset($opts->fileLocation) && $opts->fileLocation != '') { foreach ($SubmittedForm->files as $key => &$details) { if ($details['error'] == '0' && $details['size'] > 0) { // no error, upload worked $attrs = $SubmittedForm->get_template_attributes($key); if (is_uploaded_file($details['tmp_name'])) { $filename = $details['name']; $dest = rtrim($opts->fileLocation, '\\/') . DIRECTORY_SEPARATOR; if (file_exists($dest . $filename)) { $filename = time() . $filename; } if (file_exists($dest . $filename)) { $filename = time() . mt_rand() . $filename; } if (PerchUtil::move_uploaded_file($details['tmp_name'], $dest . $filename)) { $details['new_path'] = $dest . $filename; $details['new_filename'] = $filename; $file = new stdClass(); $file->name = $filename; $file->path = $dest . $filename; $file->size = $details['size']; $file->mime = ''; if (isset($SubmittedForm->mimetypes[$key])) { $file->mime = $SubmittedForm->mimetypes[$key]; } $file->attributes = $attrs->get_attributes(); $data['files'][$key] = $file; } } } } } else { PerchUtil::debug('Form ' . $SubmittedForm->id . ': File save location not set, files discarded.', 'error'); } } // Fields if (PerchUtil::count($SubmittedForm->data)) { foreach ($SubmittedForm->data as $key => $value) { $attrs = $SubmittedForm->get_template_attributes($key); if ($attrs) { $field = new stdClass(); $field->attributes = $attrs->get_attributes(); // skip submit fields if (isset($field->attributes['type']) && $field->attributes['type'] == 'submit') { // skip it. } else { // skip honeypot field if (isset($field->attributes['antispam']) && $field->attributes['antispam'] == 'honeypot') { // skip it } else { $field->value = $value; $data['fields'][$attrs->id()] = $field; } } } } } if (!$spam && isset($opts->email) && $opts->email) { $this->_send_email($opts, $data); } if (isset($opts->store) && $opts->store) { $json = PerchUtil::json_safe_encode($data); $record = array(); $record['responseJSON'] = $json; $record['formID'] = $this->id(); $record['responseIP'] = $_SERVER['REMOTE_ADDR']; if ($spam) { $record['responseSpam'] = '1'; } $spam_data = array(); $spam_data['fields'] = $antispam; $spam_data['environment'] = $environment; $record['responseSpamData'] = PerchUtil::json_safe_encode($spam_data); $Responses = new PerchForms_Responses($this->api); $Response = $Responses->create($record); } if ($spam || !isset($opts->store) || !$opts->store) { // not storing, so drop files if (PerchUtil::count($data['files'])) { foreach ($data['files'] as $file) { if (file_exists($file->path)) { @unlink($file->path); } } } } // Redirect? if (isset($opts->successURL) && $opts->successURL) { PerchUtil::redirect(trim($opts->successURL)); } }
<?php $Pages = new PerchContent_Pages(); $Regions = new PerchContent_Regions(); $expand_list = array(0); // Find new pages and initialise $Pages->order_new_pages(); // Collapse list? $do_list_collapse = $Settings->get('content_collapseList')->val(); $Perch->add_javascript_block("Perch.Apps.Content.settings = { 'collapseList':" . (PerchUtil::bool_val($do_list_collapse) ? 'true' : 'false') . " };"); // default state $filter = 'all'; $do_regions = false; $show_shared = true; if (isset($_GET['filter']) && $_GET['filter'] == 'new') { $filter = 'new'; $do_regions = true; $do_list_collapse = false; $show_shared = false; } if (isset($_GET['template']) && $_GET['template'] != '') { $filter = 'template'; $do_regions = true; $do_list_collapse = false; $show_shared = true; $template_to_filter = urldecode($_GET['template']); } // Get pages if ($do_list_collapse) { $expand_list = array(0); // get the existing expand list
<?php include PERCH_PATH . '/core/apps/content/PerchContent_Regions.class.php'; include PERCH_PATH . '/core/apps/content/PerchContent_Region.class.php'; include PERCH_PATH . '/core/apps/content/PerchContent_Pages.class.php'; include PERCH_PATH . '/core/apps/content/PerchContent_Page.class.php'; $Roles = new PerchUserRoles(); $Regions = new PerchContent_Regions(); $Pages = new PerchContent_Pages(); if (isset($_GET['id']) && is_numeric($_GET['id'])) { $id = (int) $_GET['id']; $Role = $Roles->find($id); } else { $id = false; $Role = false; } if (!is_object($Role)) { PerchUtil::redirect(PERCH_LOGINPATH . '/core/users/roles/'); } $Form = new PerchForm('action', false); if ($Form->posted() && $Form->validate()) { PerchUtil::debug($_POST); $action = false; if (isset($_POST['regions']) && $_POST['regions'] != '' && $_POST['regions'] != 'noaction') { if ($_POST['regions'] == 'grant') { $Regions->modify_permissions('grant', $Role->id()); } if ($_POST['regions'] == 'revoke') { $Regions->modify_permissions('revoke', $Role->id()); } $action = true;
<?php if (isset($_GET['id']) && is_numeric($_GET['id'])) { $region_id = (int) $_GET['id']; $item_id = (int) $_GET['itm']; $Regions = new PerchContent_Regions(); $Region = $Regions->find($region_id); $Pages = new PerchContent_Pages(); $Page = $Pages->find($Region->pageID()); } if (!$Region || !is_object($Region)) { PerchUtil::redirect(PERCH_LOGINPATH . '/core/apps/content'); } // set the current user $Region->set_current_user($CurrentUser->id()); /* --------- Delete Form ----------- */ $Form = new PerchForm('delete'); if ($Form->posted() && $Form->validate() && isset($item_id)) { $Region->delete_item($item_id); $Region->index(); if ($Form->submitted_via_ajax) { echo PERCH_LOGINPATH . '/core/apps/content/edit/?id=' . $Region->id(); exit; } else { PerchUtil::redirect(PERCH_LOGINPATH . '/core/apps/content/edit/?id=' . $Region->id()); } }
<?php $Pages = new PerchContent_Pages(); $PageTemplates = new PerchContent_PageTemplates(); $PageTemplates->find_and_add_new_templates(); $Page = false; $Templates = new PerchContent_PageTemplates(); // Find the page if (isset($_GET['pid']) && is_numeric($_GET['pid'])) { $parentID = (int) $_GET['pid']; $ParentPage = $Pages->find($parentID); } else { $parentID = false; $ParentPage = false; } // Check permissions if (!$CurrentUser->has_priv('content.pages.create')) { PerchUtil::redirect(PERCH_LOGINPATH . '/core/apps/content/'); } $Form = new PerchForm('addpage'); $req = array(); $req['pageTitle'] = "Required"; $req['file_name'] = "Required"; $req['pageParentID'] = "Required"; $Form->set_required($req); if ($Form->posted()) { if ($Form->validate()) { $postvars = array('pageTitle', 'pageNavText', 'file_name', 'pageParentID', 'templateID', 'create_folder'); $data = $Form->receive($postvars); $data['pageNew'] = 1; $data['pageCreatorID'] = $CurrentUser->id();