/**
  * Update the page's position in the tree
  *
  * @param string $parentID 
  * @param string $order 
  * @return void
  * @author Drew McLellan
  */
 public function update_tree_position($parentID, $order = false, $cascade = false)
 {
     PerchUtil::debug('updating tree position');
     $Pages = new PerchContent_Pages();
     $ParentPage = $Pages->find($parentID);
     $data = array();
     $data['pageParentID'] = $parentID;
     if ($order === false) {
         if (is_object($ParentPage)) {
             $data['pageOrder'] = $ParentPage->find_next_child_order();
         } else {
             $data['pageOrder'] = $this->find_next_child_order(0);
         }
     } else {
         $data['pageOrder'] = $order;
     }
     if (is_object($ParentPage)) {
         $data['pageDepth'] = $ParentPage->pageDepth() + 1;
         $data['pageTreePosition'] = $ParentPage->pageTreePosition() . '-' . str_pad($data['pageOrder'], 3, '0', STR_PAD_LEFT);
     } else {
         PerchUtil::debug('Could not find parent page');
         $data['pageDepth'] = 1;
         $data['pageTreePosition'] = '000-' . str_pad($data['pageOrder'], 3, '0', STR_PAD_LEFT);
         $data['pageParentID'] = 0;
     }
     $this->update($data);
     if ($cascade) {
         $child_pages = $Pages->get_by('pageParentID', $this->id());
         if (PerchUtil::count($child_pages)) {
             foreach ($child_pages as $ChildPage) {
                 $ChildPage->update_tree_position($this->id());
             }
         }
     }
 }
Exemplo n.º 2
0
<?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());
    }
}
Exemplo n.º 3
0
 public function get_page_by_id($id)
 {
     $id = (int) $id;
     if (isset($this->pages_cache[$id])) {
         return $this->pages_cache[$id];
     }
     $Pages = new PerchContent_Pages();
     $Page = $Pages->find($id);
     if (is_object($Page)) {
         $this->pages_cache[$id] = $Page;
     }
     return $this->pages_cache[$id];
 }
Exemplo n.º 4
0
<?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 {
 /**
  * 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;
 }
 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();
$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');
Exemplo n.º 8
0
     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);
                 }
             }
         }
     }
 } else {
     // Basic, non JavaScript ordering within section.
     PerchUtil::debug($_POST);
     $items = $Form->find_items('p-');
     if (PerchUtil::count($items)) {
         foreach ($items as $pageID => $pageOrder) {
             $Page = $Pages->find($pageID);
             if (is_object($Page)) {
                 $Page->update_tree_position($Page->pageParentID(), $pageOrder);
Exemplo n.º 9
0
<?php

$Pages = new PerchContent_Pages();
$Page = $Pages->find((int) $Region->pageID());
if (!is_object($Page)) {
    $Page = $Pages->get_mock_shared_page();
}
$Form = new PerchForm('add');
if ($Form->posted() && $Form->validate()) {
    $Item = $Region->add_new_item();
    if (is_object($Item)) {
        PerchUtil::redirect(PERCH_LOGINPATH . '/core/apps/content/edit/?id=' . $Region->id() . '&itm=' . $Item->itemID());
    }
}
$items = $Region->get_items_for_editing();
if (!PerchUtil::count($items)) {
    // No items(!) so add a new one and edit it.
    $Item = $Region->add_new_item();
    if (is_object($Item)) {
        PerchUtil::redirect(PERCH_LOGINPATH . '/core/apps/content/edit/?id=' . $Region->id() . '&itm=' . $Item->itemID());
    }
}
$cols = $Region->get_edit_columns();
Exemplo n.º 10
0
<?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();