<?php if ($CurrentUser->has_priv('content.pages.edit')) { echo '<li class="fin selected"><a href="' . PERCH_LOGINPATH . '/core/apps/content/page/edit/?id=' . PerchUtil::html($Page->id()) . '" class="icon setting">' . PerchLang::get('Page Options') . '</a></li>'; } if ($Page->pagePath() != '*') { $view_page_url = rtrim($Settings->get('siteURL')->val(), '/') . $Page->pagePath(); echo '<li class="fin">'; echo '<a href="' . PerchUtil::html($view_page_url) . '" class="icon page assist">' . PerchLang::get('View Page') . '</a>'; echo '</li>'; } ?> </ul> <?php if ($details['pageSubpagePath'] == '') { $details['pageSubpagePath'] = PerchUtil::strip_file_name($Page->pagePath()); } $Pages->find_site_path(); if (!PERCH_RUNWAY && !file_exists(PerchUtil::file_path(PERCH_SITEPATH . $details['pageSubpagePath']))) { $Alert->set('error', PerchLang::get('Subpage folder does not exist')); $Alert->output(); PerchUtil::debug(PerchUtil::file_path(PERCH_SITEPATH . $details['pageSubpagePath'])); } ?> <form method="post" action="<?php echo PerchUtil::html($Form->action()); ?> " class="magnetic-save-bar">
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); } }
/** * Create a new page, either from an existing page, or just as a nav link * * @param string $data * @return void * @author Drew McLellan */ public function create_without_file($data) { $create_folder = false; if (isset($data['create_folder'])) { $create_folder = $data['create_folder']; unset($data['create_folder']); } $link_only = false; // is this a URL or just local file? if (isset($data['file_name'])) { $url = parse_url($data['file_name']); if ($url && is_array($url) && isset($url['scheme']) && $url['scheme'] != '') { $link_only = true; $url = $data['file_name']; unset($data['file_name']); } } // Find the parent page $ParentPage = $this->find($data['pageParentID']); if ($link_only) { $data['pagePath'] = $url; $data['pageNavOnly'] = '1'; // Insert into the DB $Page = $this->create($data); // Set its position in the tree if (is_object($Page)) { if (is_object($ParentPage)) { $Page->update_tree_position($ParentPage->id()); } return $Page; } } else { // use the file name given (if stated) or create from the title. Sans extension. if (isset($data['file_name'])) { $file_name = $data['file_name']; unset($data['file_name']); } else { $file_name = PerchUtil::urlify($data['pageTitle']); } $this->find_site_path(); // Find the parent page $ParentPage = $this->find($data['pageParentID']); if (is_object($ParentPage)) { if (PERCH_RUNWAY) { $pageSection = $ParentPage->pageSortPath(); } else { if ($ParentPage->pageSubpagePath()) { $pageSection = $ParentPage->pageSubpagePath(); } else { $pageSection = PerchUtil::strip_file_name($ParentPage->pagePath()); } } // Copy subpage info $data['pageSubpageRoles'] = $ParentPage->pageSubpageRoles(); $data['pageSubpageTemplates'] = $ParentPage->pageSubpageTemplates(); $parentPageID = $ParentPage->id(); $data['pageDepth'] = $ParentPage->pageDepth() + 1; } else { $pageSection = '/'; $parentPageID = 0; $data['pageParentID'] = '0'; $data['pageDepth'] = '1'; } if (!isset($data['templateID']) || $data['templateID'] == '') { $data['templateID'] = 0; } $dir = PERCH_SITEPATH . str_replace('/', DIRECTORY_SEPARATOR, $pageSection); // Get the new file path $new_url = $pageSection . '/' . str_replace($dir, '', $file_name); $r = str_replace(DIRECTORY_SEPARATOR, '/', $new_url); while (strpos($r, '//') !== false) { $r = str_replace('//', '/', $r); } $data['pagePath'] = $r; // Insert into the DB $Page = $this->create($data); // Set its position in the tree if (is_object($Page)) { $Page->update_tree_position($parentPageID); if (PERCH_RUNWAY) { // Grab the template this page uses $Templates = new PerchContent_PageTemplates(); $Template = $Templates->find($Page->templateID()); if (is_object($Template)) { // Add to nav groups if ($Template->templateNavGroups() != '') { $Page->update_navgroups(explode(',', $Template->templateNavGroups())); } // Copy page options? if ($Template->optionsPageID() != '0') { $CopyPage = $this->find($Template->optionsPageID()); if (is_object($CopyPage)) { $sql = 'INSERT INTO ' . PERCH_DB_PREFIX . 'content_regions ( pageID, regionKey, regionPage, regionHTML, regionNew, regionOrder, regionTemplate, regionMultiple, regionOptions, regionSearchable, regionEditRoles ) SELECT ' . $this->db->pdb($Page->id()) . ' AS pageID, regionKey, ' . $this->db->pdb($r) . ' AS regionPage, "<!-- Undefined content -->" AS regionHTML, regionNew, regionOrder, regionTemplate, regionMultiple, regionOptions, regionSearchable, regionEditRoles FROM ' . PERCH_DB_PREFIX . 'content_regions WHERE regionPage!=' . $this->db->pdb('*') . ' AND pageID=' . $this->db->pdb((int) $CopyPage->id()); $this->db->execute($sql); } } } } return $Page; } } return false; }