/**
  * Creates a page version children
  *
  * @param the current page
  */
 public static function callback_page_updated($page)
 {
     if ($page->behavior_id == 'version' || $page->behavior_id == 'current_version') {
         return;
     }
     $new_version = PageVersion::createFrom($page);
     $new_version->save();
     Observer::notify('version_add_after_save', $new_version);
     /* Clone the page parts. */
     $page_parts = PagePart::findByPageId($page->id);
     if (count($page_parts)) {
         foreach ($page_parts as $part) {
             $part->page_id = $new_version->id;
             $part->id = null;
             $part->save();
         }
     }
 }
Пример #2
0
 /**
  * Runs checks and stores a page.
  *
  * @param string $action   What kind of action this is: add or edit.
  * @param mixed $id        Page to edit if any.
  */
 private function _store($action, $id = false)
 {
     // Sanity checks
     if ($action == 'edit' && !$id) {
         throw new Exception('Trying to edit page when $id is false.');
     }
     use_helper('Validate');
     $data = $_POST['page'];
     $data['is_protected'] = !empty($data['is_protected']) ? 1 : 0;
     Flash::set('post_data', (object) $data);
     // Add pre-save checks here
     $errors = false;
     // CSRF checks
     if (isset($_POST['csrf_token'])) {
         $csrf_token = $_POST['csrf_token'];
         if (!SecureToken::validateToken($csrf_token, BASE_URL . 'page/' . $action)) {
             $errors[] = __('Invalid CSRF token found!');
         }
     } else {
         $errors[] = __('No CSRF token found!');
     }
     $data['title'] = trim($data['title']);
     if (empty($data['title'])) {
         $errors[] = __('You have to specify a title!');
     }
     $data['slug'] = trim($data['slug']);
     if (empty($data['slug']) && $id != '1') {
         $errors[] = __('You have to specify a slug!');
     } else {
         if ($data['slug'] == ADMIN_DIR) {
             $errors[] = __('You cannot have a slug named :slug!', array(':slug' => ADMIN_DIR));
         }
         if (!Validate::slug($data['slug']) && (!empty($data['slug']) && $id == '1')) {
             $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => 'slug'));
         }
     }
     // Check all numerical fields for a page
     $fields = array('parent_id', 'layout_id', 'needs_login');
     foreach ($fields as $field) {
         if (!Validate::digit($data[$field])) {
             $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field));
         }
     }
     // Check all date fields for a page
     $fields = array('created_on', 'published_on', 'valid_until');
     foreach ($fields as $field) {
         if (isset($data[$field])) {
             $data[$field] = trim($data[$field]);
             if (!empty($data[$field]) && !(bool) preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/D', (string) $data[$field])) {
                 $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field));
             }
         }
     }
     // Check all time fields for a page
     $fields = array('created_on_time', 'published_on_time', 'valid_until_time');
     foreach ($fields as $field) {
         if (isset($data[$field])) {
             $data[$field] = trim($data[$field]);
             if (!empty($data[$field]) && !(bool) preg_match('/^[0-9]{2}:[0-9]{2}:[0-9]{2}$/D', (string) $data[$field])) {
                 $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field));
             }
         }
     }
     // Check alphanumerical fields
     $fields = array('keywords', 'description');
     foreach ($fields as $field) {
         use_helper('Kses');
         $data[$field] = kses(trim($data[$field]), array());
         /*
                     if (!empty($data[$field]) && !Validate::alpha_comma($data[$field])) {
            $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field));
                     }
         * 
         */
     }
     // Check behaviour_id field
     if (!empty($data['behaviour_id']) && !Validate::slug($data['behaviour_id'])) {
         $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => 'behaviour_id'));
     }
     // Make sure the title doesn't contain HTML
     if (Setting::get('allow_html_title') == 'off') {
         use_helper('Kses');
         $data['title'] = kses(trim($data['title']), array());
     }
     // Create the page object to be manipulated and populate data
     if ($action == 'add') {
         $page = new Page($data);
     } else {
         $page = Record::findByIdFrom('Page', $id);
         $page->setFromData($data);
     }
     // Upon errors, rebuild original page and return to screen with errors
     if (false !== $errors) {
         $tags = $_POST['page_tag'];
         // Rebuild time fields
         if (isset($page->created_on)) {
             $page->created_on = $page->created_on . ' ' . $page->created_on_time;
         }
         if (isset($page->published_on)) {
             $page->published_on = $page->published_on . ' ' . $page->published_on_time;
         }
         if (isset($page->valid_until)) {
             $page->valid_until = $page->valid_until . ' ' . $page->valid_until_time;
         }
         // Rebuild parts
         $part = $_POST['part'];
         if (!empty($part)) {
             $tmp = false;
             foreach ($part as $key => $val) {
                 $tmp[$key] = (object) $val;
             }
             $part = $tmp;
         }
         // Set the errors to be displayed.
         Flash::setNow('error', implode('<br/>', $errors));
         // display things ...
         $this->setLayout('backend');
         $this->display('page/edit', array('action' => $action, 'csrf_token' => SecureToken::generateToken(BASE_URL . 'page/' . $action), 'page' => (object) $page, 'tags' => $tags, 'filters' => Filter::findAll(), 'behaviors' => Behavior::findAll(), 'page_parts' => (object) $part, 'layouts' => Record::findAllFrom('Layout')));
     }
     // Notify
     if ($action == 'add') {
         Observer::notify('page_add_before_save', $page);
     } else {
         Observer::notify('page_edit_before_save', $page);
     }
     // Time to actually save the page
     // @todo rebuild this so parts are already set before save?
     // @todo determine lazy init impact
     if ($page->save()) {
         // Get data for parts of this page
         $data_parts = $_POST['part'];
         Flash::set('post_parts_data', (object) $data_parts);
         if ($action == 'edit') {
             $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;
                         // this will not really create a new page part because
                         // the id of the part is passed in $data
                         $part = new PagePart($data);
                         $part->page_id = $id;
                         Observer::notify('part_edit_before_save', $part);
                         $part->save();
                         Observer::notify('part_edit_after_save', $part);
                         unset($data_parts[$part_id]);
                         break;
                     }
                 }
                 if ($not_in) {
                     $old_part->delete();
                 }
             }
         }
         // add the new parts
         foreach ($data_parts as $data) {
             $data['name'] = trim($data['name']);
             $part = new PagePart($data);
             $part->page_id = $page->id;
             Observer::notify('part_add_before_save', $part);
             $part->save();
             Observer::notify('part_add_after_save', $part);
         }
         // save tags
         $page->saveTags($_POST['page_tag']['tags']);
         Flash::set('success', __('Page has been saved!'));
     } else {
         Flash::set('error', __('Page has not been saved!'));
         $url = 'page/';
         $url .= $action == 'edit' ? 'edit/' . $id : 'add/';
         redirect(get_url($url));
     }
     if ($action == 'add') {
         Observer::notify('page_add_after_save', $page);
     } else {
         Observer::notify('page_edit_after_save', $page);
     }
     // save and quit or save and continue editing ?
     if (isset($_POST['commit'])) {
         redirect(get_url('page'));
     } else {
         redirect(get_url('page/edit/' . $page->id));
     }
 }
Пример #3
0
 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 = Record::findByIdFrom('Page', $page->id);
     $clone->parent_id = (int) $parent_id;
     $clone->id = null;
     $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();
         }
     }
     /* 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;
 }
Пример #4
0
 /**
  * Runs checks and stores a page.
  *
  * @param string $action   What kind of action this is: add or edit.
  * @param mixed $id        Page to edit if any.
  */
 private function _store($action, $id = false)
 {
     // Sanity checks
     if ($action == 'edit' && !$id) {
         throw new Exception('Trying to edit page when $id is false.');
     }
     use_helper('Validate');
     $data = $_POST['page'];
     $data['is_protected'] = !empty($data['is_protected']) ? 1 : 0;
     Flash::set('post_data', (object) $data);
     $pagesetting = array();
     //For homepage info & about page info okstmtcc
     if ($id == 1 || $id == 4) {
         $upload = $_POST['upload'];
         $pagesetting = $_POST['pagesetting'];
         //Flash::set('post_settingdata', (object) $pagesetting);
     }
     // Add pre-save checks here
     $errors = false;
     $error_fields = false;
     // CSRF checks
     if (isset($_POST['csrf_token'])) {
         $csrf_token = $_POST['csrf_token'];
         $csrf_id = '';
         if ($action === 'edit') {
             $csrf_id = '/' . $id;
         }
         if (!SecureToken::validateToken($csrf_token, BASE_URL . 'page/' . $action . $csrf_id)) {
             $errors[] = __('Invalid CSRF token found!');
         }
     } else {
         $errors[] = __('No CSRF token found!');
     }
     $data['title'] = trim($data['title']);
     if (empty($data['title'])) {
         $error_fields[] = __('Page Title');
     }
     /** homepage setting check okstmtcc **/
     if ($id == 1) {
         /** homepage page title **/
         if (empty($pagesetting['homepage_discover_title'])) {
             $error_fields[] = __('Homepage Title');
         }
         if (empty($pagesetting['homepage_discover_teaser'])) {
             $error_fields[] = __('Homepage Teaser');
         }
         /** highlight 1 **/
         // if (empty($pagesetting['highlight_title'])){
         //     $error_fields[] = __('Highlight 1&acute;s Title');
         // }
         // if (empty($pagesetting['highlight_text1'])){
         //     $error_fields[] = __('Highlight 1&acute;s Text 1');
         // }
         // if (empty($pagesetting['highlight_url'])){
         //     $error_fields[] = __('Highlight 1&acute;s Read More URL');
         // }
         // $pagesetting_ori = PageSetting::init();
         // if (isset($_FILES)) {
         //     if(empty($_FILES['upload_highlight_image']['name'])){
         //         $pagesetting['highlight_image'] =  $pagesetting_ori->highlight_image;
         //     } else {
         //         $pagesetting['highlight_image'] = $_FILES['upload_highlight_image']['name'];
         //     }
         // } else {
         //     $pagesetting['highlight_image'] =  $pagesetting_ori->highlight_image;
         // }
         // if (empty($pagesetting['highlight_image'])){
         //     $error_fields[] = __('Highlight 1&acute;s Image');
         // }
         // /** highlight 2 **/
         // if (empty($pagesetting['highlight2_title'])){
         //     $error_fields[] = __('Highlight 2&acute;s Title');
         // }
         // if (empty($pagesetting['highlight2_text1'])){
         //     $error_fields[] = __('Highlight 2&acute;s Text 1');
         // }
         // if (empty($pagesetting['highlight2_url'])){
         //     $error_fields[] = __('Highlight 2&acute;s Read More URL');
         // }
         // if (isset($_FILES)) {
         //     if(empty($_FILES['upload_highlight2_image']['name'])){
         //         $pagesetting['highlight2_image'] =  $pagesetting_ori->highlight2_image;
         //     } else {
         //         $pagesetting['highlight2_image'] = $_FILES['upload_highlight2_image']['name'];
         //     }
         // } else {
         //     $pagesetting['highlight2_image'] =  $pagesetting_ori->highlight2_image;
         // }
         // if (empty($pagesetting['highlight2_image'])){
         //     $error_fields[] = __('Highlight 2&acute;s Image');
         // }
         // if (isset($_FILES)) {
         //     if(empty($_FILES['upload_newdev_image']['name'])){
         //         $pagesetting['newdev_image'] =  $pagesetting_ori->newdev_image;
         //     } else {
         //         $pagesetting['newdev_image'] = $_FILES['upload_newdev_image']['name'];
         //     }
         // } else {
         //     $pagesetting['newdev_image'] =  $pagesetting_ori->newdev_image;
         // }
         // if (empty($pagesetting['newdev_image'])){
         //     $error_fields[] = __('New Development Image');
         // }
     }
     /** homepage setting check okstmtcc **/
     $data['slug'] = !empty($data['slug']) ? trim($data['slug']) : '';
     if (empty($data['slug']) && $id != '1') {
         $error_fields[] = __('Slug');
     } else {
         if ($data['slug'] == ADMIN_DIR) {
             $errors[] = __('You cannot have a slug named :slug!', array(':slug' => ADMIN_DIR));
         }
         if (!Validate::slug($data['slug']) && (!empty($data['slug']) && $id == '1')) {
             $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => 'slug'));
         }
     }
     // Check all numerical fields for a page
     $fields = array('parent_id', 'layout_id', 'needs_login');
     foreach ($fields as $field) {
         if (!Validate::digit($data[$field])) {
             $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field));
         }
     }
     // Check all date fields for a page
     $fields = array('created_on', 'published_on', 'valid_until');
     foreach ($fields as $field) {
         if (isset($data[$field])) {
             $data[$field] = trim($data[$field]);
             if (!empty($data[$field]) && !(bool) preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/D', (string) $data[$field])) {
                 $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field));
             }
         }
     }
     // Check all time fields for a page
     $fields = array('created_on_time', 'published_on_time', 'valid_until_time');
     foreach ($fields as $field) {
         if (isset($data[$field])) {
             $data[$field] = trim($data[$field]);
             if (!empty($data[$field]) && !(bool) preg_match('/^[0-9]{2}:[0-9]{2}:[0-9]{2}$/D', (string) $data[$field])) {
                 $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field));
             }
         }
     }
     // Check alphanumerical fields
     $fields = array('keywords', 'description');
     foreach ($fields as $field) {
         use_helper('Kses');
         $data[$field] = kses(trim($data[$field]), array());
         /*
                     if (!empty($data[$field]) && !Validate::alpha_comma($data[$field])) {
            $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field));
                     }
         *
         */
     }
     // Check behaviour_id field
     if (!empty($data['behaviour_id']) && !Validate::slug($data['behaviour_id'])) {
         $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => 'behaviour_id'));
     }
     // Make sure the title doesn't contain HTML
     if (Setting::get('allow_html_title') == 'off') {
         use_helper('Kses');
         $data['title'] = kses(trim($data['title']), array());
     }
     // Create the page object to be manipulated and populate data
     if ($action == 'add') {
         $page = new Page($data);
     } else {
         $page = Record::findByIdFrom('Page', $id);
         $page->setFromData($data);
     }
     // Upon errors, rebuild original page and return to screen with errors
     if (false !== $errors || $error_fields !== false) {
         $tags = $_POST['page_tag'];
         // Rebuild time fields
         if (isset($page->created_on) && isset($page->created_on_time)) {
             $page->created_on = $page->created_on . ' ' . $page->created_on_time;
         }
         if (isset($page->published_on) && isset($page->published_on_time)) {
             $page->published_on = $page->published_on . ' ' . $page->published_on_time;
         }
         if (isset($page->valid_until)) {
             $page->valid_until = $page->valid_until . ' ' . $page->valid_until_time;
         }
         // Rebuild parts
         $part = '';
         if (!empty($_POST['part'])) {
             $part = $_POST['part'];
             $tmp = false;
             foreach ($part as $key => $val) {
                 $tmp[$key] = (object) $val;
             }
             $part = $tmp;
         }
         // Set the errors to be displayed.
         $err_msg = $errors != false ? implode('<br/>', $errors) : '';
         $err_msg .= $error_fields != false ? '<br />Please specify these fields: ' . implode(', ', $error_fields) : '';
         Flash::setNow('error', $err_msg);
         //$settingdata = 'aaa';
         // display things ...
         $this->setLayout('backend');
         $pagesettingobj = new stdClass();
         foreach ($pagesetting as $name => $value) {
             $pagesettingobj->{$name} = $value;
         }
         $this->display('page/edit', array('action' => $action, 'csrf_token' => SecureToken::generateToken(BASE_URL . 'page/' . $action), 'page' => (object) $page, 'pagesetting' => $pagesettingobj, 'tags' => $tags, 'filters' => Filter::findAll(), 'behaviors' => Behavior::findAll(), 'page_parts' => $part, 'layouts' => Record::findAllFrom('Layout')));
     }
     // Notify
     if ($action == 'add') {
         Observer::notify('page_add_before_save', $page);
     } else {
         Observer::notify('page_edit_before_save', $page);
     }
     // Time to actually save the page
     // @todo rebuild this so parts are already set before save?
     // @todo determine lazy init impact
     $page->newwindow = !empty($data['newwindow']) ? '1' : '0';
     if ($page->save()) {
         // Get data for parts of this page
         $data_parts = $_POST['part'];
         Flash::set('post_parts_data', (object) $data_parts);
         if ($action == 'edit') {
             $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;
                         // this will not really create a new page part because
                         // the id of the part is passed in $data
                         $part = new PagePart($data);
                         $part->page_id = $id;
                         Observer::notify('part_edit_before_save', $part);
                         $part->save();
                         Observer::notify('part_edit_after_save', $part);
                         unset($data_parts[$part_id]);
                         break;
                     }
                 }
                 if ($not_in) {
                     $old_part->delete();
                 }
             }
         }
         // add the new parts
         foreach ($data_parts as $data) {
             $data['name'] = trim($data['name']);
             $part = new PagePart($data);
             $part->page_id = $page->id;
             Observer::notify('part_add_before_save', $part);
             $part->save();
             Observer::notify('part_add_after_save', $part);
         }
         // save tags
         $page->saveTags($_POST['page_tag']['tags']);
         // save homepage banner info okstmtcc
         if ($id == 1) {
             // upload home banner image 1, 2
             if (isset($_FILES) && !empty($_FILES['upload_banner_image1']['name'])) {
                 //okstmtcc 20150827 Replace image filename spaces
                 $_FILES['upload_banner_image1']['name'] = str_replace(array(" ", "(", ")"), array("_", "", ""), $_FILES['upload_banner_image1']['name']);
                 $file = $this->upload_file($_FILES['upload_banner_image1']['name'], FILES_DIR . '/pagesetting/images/', $_FILES['upload_banner_image1']['tmp_name'], $overwrite);
                 if ($file === false) {
                     Flash::set('error', __('Home banner could not be uploaded!'));
                     redirect(get_url('page/edit/1'));
                 } else {
                     $pagesetting['banner_image1'] = $file;
                 }
             }
             if (isset($_FILES) && !empty($_FILES['upload_banner_image2']['name'])) {
                 //okstmtcc 20150827 Replace image filename spaces
                 $_FILES['upload_banner_image2']['name'] = str_replace(array(" ", "(", ")"), array("_", "", ""), $_FILES['upload_banner_image2']['name']);
                 $file = $this->upload_file($_FILES['upload_banner_image2']['name'], FILES_DIR . '/pagesetting/images/', $_FILES['upload_banner_image2']['tmp_name'], $overwrite);
                 if ($file === false) {
                     Flash::set('error', __('Home banner could not be uploaded!'));
                     redirect(get_url('page/edit/1'));
                 } else {
                     $pagesetting['banner_image2'] = $file;
                 }
             }
             PageSetting::saveFromData($pagesetting);
         }
         // save homepage banner info okstmtcc
         // save about banner info okstmtcc
         if ($id == 4) {
             // upload about page image 1
             if (isset($_FILES) && !empty($_FILES['upload_about_image1']['name'])) {
                 //okstmtcc 20150827 Replace image filename spaces
                 $_FILES['upload_about_image1']['name'] = str_replace(array(" ", "(", ")"), array("_", "", ""), $_FILES['upload_about_image1']['name']);
                 $file = $this->upload_file($_FILES['upload_about_image1']['name'], FILES_DIR . '/pagesetting/images/', $_FILES['upload_about_image1']['tmp_name'], $overwrite);
                 if ($file === false) {
                     Flash::set('error', __('Home banner could not be uploaded!'));
                     redirect(get_url('page/edit/1'));
                 } else {
                     $pagesetting['about_image1'] = $file;
                 }
             }
             PageSetting::saveFromData($pagesetting);
         }
         // save about banner info okstmtcc
         Flash::set('success', __('Page has been saved.'));
     } else {
         Flash::set('error', __('Page has not been saved!'));
         $url = 'page/';
         $url .= $action == 'edit' ? 'edit/' . $id : 'add/';
         redirect(get_url($url));
     }
     if ($action == 'add') {
         Observer::notify('page_add_after_save', $page);
     } else {
         Observer::notify('page_edit_after_save', $page);
     }
     // save and quit or save and continue editing ?
     if (isset($_POST['commit'])) {
         redirect(get_url('page'));
     } else {
         redirect(get_url('page/edit/' . $page->id));
     }
 }
Пример #5
0
 public function delete($id)
 {
     // security (dont delete the root page)
     if ($id > 1) {
         // find the page to delete
         if ($page = Record::findByIdFrom('Page', $id)) {
             // check for permission to delete this page
             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'));
             }
             // need to delete all page_parts too !!
             PagePart::deleteByPageId($id);
             if ($page->delete()) {
                 Flash::set('success', __('Page :title has been deleted!', array(':title' => $page->title)));
                 Observer::notify('page_delete', $page);
             } else {
                 Flash::set('error', __('Page :title has not been deleted!', array(':title' => $page->title)));
             }
         } else {
             Flash::set('error', __('Page not found!'));
         }
     } else {
         Flash::set('error', __('Action disabled!'));
     }
     redirect(get_url('page'));
 }
Пример #6
0
 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;
 }
 /**
  * View callback function. Adds the page_part_form to the admin page.
  *
  * @param page the current page to edit
  */
 public static function callback_view_page($page)
 {
     // Because the metadata is not visible, we can't use $page->metadata[self::PLUGIN_ID]
     if (isset($page->id) && ($form = PageMetadata::FindOneByPageAndKeyword($page->id, self::PLUGIN_ID)) || ($form = PageMetadata::FindOneByPageAndKeyword($page->parent_id, self::PLUGIN_ID . '_children'))) {
         if ($definition = Record::findByIdFrom('PagePartForm', $form->value)) {
             // Convert page_parts array to hash
             $page_parts = array();
             if (isset($page->id)) {
                 foreach (PagePart::findByPageId($page->id) as $page_part) {
                     $page_parts[$page_part->name] = $page_part;
                 }
             }
             // Add the page_part_form to the admin view
             self::Get_instance()->create_view('observers/page_form', array('page' => $page, 'page_parts' => $page_parts, 'structure' => self::Get_structure($definition)))->display();
         }
     }
 }
Пример #8
0
function PageContent()
{
    global $message;
    global $template_id;
    global $menu_title;
    global $page_title;
    global $title_tag;
    global $friendly_url;
    global $meta_keywords;
    global $meta_description;
    global $is_menu;
    global $published;
    global $parent_page_id;
    global $id;
    ?>

	<script type="text/javascript" src="tinymce/js/tinymce/tinymce.min.js"></script>
	<script type="text/javascript">
	tinyMCE.init({
	    selector : "textarea.mceEditor",
	    plugins : "image code pagebreak table spellchecker preview searchreplace print contextmenu paste fullscreen link nonbreaking",
	    image_advtab : true,
	    forced_root_block : "",
	    setup: function (editor) {
	        editor.on('init', function(args) {
	            editor = args.target;
	
	            editor.on('NodeChange', function(e) {
	                if (e && e.element.nodeName.toLowerCase() == 'img') {
	//                     width = e.element.width;
	//                     height = e.element.height;
	                    tinyMCE.DOM.setAttribs(e.element, {'class':'img_responsive', 'height' : null, 'width' : null});
	                    tinyMCE.DOM.setStyle(e.element, 'max-width', '100%');
	                }
	            });
	        });
	    },
		content_css : ["../css/bootstrip.min.css"],
	    document_base_url : "http://havells.boxkitemedia.com"
	});
	</script>

	<div id="content">

		<div class="layout">
	        <?php 
    if ($id == 0) {
        $bread_title = 'Page Add';
    } else {
        $bread_title = 'Page Edit';
    }
    $aLabels = array();
    $aLinks = array();
    $aLabels[0] = 'Home';
    $aLinks[0] = 'mainpage.php';
    $aLabels[1] = 'Pages';
    $aLinks[1] = 'page_list.php';
    $aLabels[2] = $bread_title;
    $aLinks[2] = '';
    echo Helpers::CreateBreadCrumbs($aLabels, $aLinks);
    ?>

		    <p class="larger botspace heading"><?php 
    echo $bread_title;
    ?>
</p>

			<div class="formstyle ">
                <?php 
    if ($message != "") {
        echo "<p class=\"err\">" . $message . "</p>";
    }
    ?>
				<form method="post" action="page_admin.php">
					<table class="form-table">
         <?php 
    if (!isset($id) || $id == 0) {
        ?>
         <tr>
            <td class="table-label" align="right"><strong>Page Template: </strong></td>
            <td>
               <select name="template_id">
                   <option value=""></option>
               <?php 
        $objTemplate = new Template();
        $oTemplate = $objTemplate->GetAllTemplate('name');
        foreach ($oTemplate as $template) {
            $cSelected = '';
            if ($template_id == $template->Id) {
                $cSelected = 'selected';
            }
            echo '<option ' . $cSelected . ' value="' . $template->Id . '">' . $template->Name . '</option>';
        }
        ?>
               </select>
            </td>
         </tr>
         <?php 
    }
    ?>
         <tr>
            <td class="table-label" align="right"><strong>Menu Title: </strong></td>
            <td>
               <input type="text" class="form midform" class="form midform" maxlength="100" size="40" value="<?php 
    echo $menu_title;
    ?>
" name="menu_title" /> <em>(This is what displays in the menu dropdown)</em>
            </td>
         </tr>
         <tr>
            <td class="table-label" align="right"><strong>Page Title: </strong></td>
            <td>
               <input type="text" class="form midform" class="form midform" maxlength="100" size="40" value="<?php 
    echo $page_title;
    ?>
" name="page_title" /> <em>(This is what displays on the top of this page)</em>
            </td>
         </tr>
         <!--
         <tr>
            <td class="table-label" align="right"><strong>Friendly URL: </strong></td>
            <td>
               <input type="text" class="form midform" maxlength="100" size="40" value="<?php 
    echo $friendly_url;
    ?>
" name="friendly_url" />
            </td>
         </tr>
         -->
         <tr>
            <td class="table-label" align="right"><strong>Title Tag: </strong></td>
            <td>
               <input type="text" class="form midform" maxlength="100" size="60" value="<?php 
    echo $title_tag;
    ?>
" name="title_tag" />
            </td>
         </tr>
         <tr>
            <td class="table-label" align="right"><strong>META Keywords: </strong></td>
            <td>
               <input type="text" class="form midform" maxlength="255" size="60" value="<?php 
    echo $meta_keywords;
    ?>
" name="meta_keywords" />
            </td>
         </tr>
         <tr>
            <td class="table-label" align="right" valign="top"><strong>META Description: </strong></td>
            <td>
               <textarea rows="3" cols="60" class="mceNoEditor" name="meta_description" style="width: 400px;"><?php 
    echo $meta_description;
    ?>
</textarea>
            </td>
         </tr>
         <tr>
            <td colspan="2">&nbsp;</td>
         </tr>
         
         <?php 
    if (isset($id)) {
        $objPagePart = new PagePart();
        $oPageParts = $objPagePart->GetAllPagePartByPageId($id);
        foreach ($oPageParts as $pagepart) {
            $objTemplatePartType = new TemplatePartType($pagepart->TemplatePartId);
            if ($objTemplatePartType->Name == 'Right Column' && $pagepart->Content == '') {
                $content = '%%P3_REQUEST_A_QUOTE_SIDE%% %%P3_VIDEO_SIDE%% %%P3_TESTIMONIAL_SIDE%%';
            } else {
                $content = $pagepart->Content;
            }
            ?>
             <tr>
                <td class="table-label" align="right" valign="top"><strong><?php 
            echo $objTemplatePartType->Name;
            ?>
: </strong></td>
                <td>
                   <textarea style="width:90%; height:400px;" class="mceEditor" id="page_part_<?php 
            echo $pagepart->Id;
            ?>
" name="page_part_<?php 
            echo $pagepart->Id;
            ?>
"><?php 
            echo $content;
            ?>
</textarea>
                </td>
             </tr>
             <tr>
                <td colspan="2">&nbsp;</td>
             </tr>
             <?php 
        }
    }
    ?>
         <!--
         <tr>
            <td class="table-label" align="right"><strong>Is Menu Page?: </strong></td>
            <td valign="bottom">
               <input type="checkbox" <?php 
    if ($is_menu == '1') {
        echo 'checked';
    }
    ?>
 value="1" name="is_menu" />
            </td>
         </tr>
         -->
         <!--
         <tr>
            <td class="table-label" align="right"><strong>Parent Page: </strong></td>
            <td>
               <select name="parent_page_id">
                   <option value=""></option>
                   <option <?php 
    if ($parent_page_id == '1') {
        echo 'selected';
    }
    ?>
 value="1">Products</option>
                   <option <?php 
    if ($parent_page_id == '2') {
        echo 'selected';
    }
    ?>
 value="2">Media + Resources</option>
                   <option <?php 
    if ($parent_page_id == '3') {
        echo 'selected';
    }
    ?>
 value="3">Company</option>
                   <option <?php 
    if ($parent_page_id == '4') {
        echo 'selected';
    }
    ?>
 value="4">Contact</option>
               </select>
            </td>
         </tr>
         -->
         <tr>
            <td class="table-label" align="right"><strong>Published?: </strong></td>
            <td valign="bottom">
               <input type="checkbox" <?php 
    if ($published == '1') {
        echo 'checked';
    }
    ?>
 value="1" name="published" />
            </td>
         </tr>
					</table>
				
					<p class="submit"><input type="submit" name="commit" value="Save Page">&nbsp;&nbsp;<input type="submit" name="commit" value="Cancel"></p>
				
                    <input type="hidden" name="page_id" value="<?php 
    echo $id;
    ?>
" id="page_id">
                   	<input type="hidden" name="id" value="<?php 
    echo $id;
    ?>
" />

				</form>
		</div>

	</div>

<?php 
}