Example #1
0
 public function ___import($page, $data = null)
 {
     if (is_null($data)) {
         $data = $page;
         $page = new Page();
     }
     if (empty($data['core_version'])) {
         throw new WireException("Invalid import data");
     }
     $page->of(false);
     $page->resetTrackChanges(true);
     if (!is_array($data)) {
         throw new WireException("Data passed to import() must be an array");
     }
     if (!$page->parent_id) {
         $parent = $this->wire('pages')->get($data['parent']);
         if (!$parent->id) {
             throw new WireException("Unknown parent: {$data['parent']}");
         }
         $page->parent = $parent;
     }
     if (!$page->templates_id) {
         $template = $this->wire('templates')->get($data['template']);
         if (!$template) {
             throw new WireException("Unknown template: {$data['template']}");
         }
         $page->template = $template;
     }
     $page->name = $data['name'];
     $page->sort = $data['sort'];
     $page->sortfield = $data['sortfield'];
     $page->status = $data['status'];
     $page->guid = $data['id'];
     if (!$page->id) {
         $page->save();
     }
     foreach ($data['data'] as $name => $value) {
         $field = $this->wire('fields')->get($name);
         if (!$field) {
             $this->error("Unknown field: {$name}");
             continue;
         }
         if ($data['types'][$name] != $field->type->className()) {
             $this->error("Import data for field '{$field->name}' has different fieldtype '" . $data['types'][$name] . "' != '" . $field->type->className() . "', skipping...");
             continue;
         }
         $newStr = var_export($value, true);
         $oldStr = var_export($this->exportValue($page, $field, $page->get($field->name)), true);
         if ($newStr === $oldStr) {
             continue;
         }
         // value has not changed, so abort
         $value = $this->importValue($page, $field, $value);
         $page->set($field->name, $value);
     }
     return $page;
 }
 /**
  * Save any changes or additions that were made to these Notifications
  * 
  * @return bool
  * 
  */
 public function save()
 {
     $of = $this->page->of();
     if ($of) {
         $this->page->of(false);
     }
     $result = $this->page->save(SystemNotifications::fieldName, array('quiet' => true));
     if ($of) {
         $this->page->of(true);
     }
     return $result;
 }
Example #3
0
 /**
  * Retrieve a value from the Notification
  * 
  * @param string $key
  * @return mixed
  *
  */
 public function get($key)
 {
     if ($key == 'id') {
         return $this->getID();
     }
     if ($key == 'page') {
         return $this->page;
     }
     if ($key == 'hash') {
         return $this->getHash();
     }
     if ($key == 'flagNames') {
         $flags = parent::get('flags');
         $flagNames = array();
         foreach (self::$_flagNames as $val => $name) {
             if ($flags & $val) {
                 $flagNames[$val] = $name;
             }
         }
         return $flagNames;
     }
     $value = parent::get($key);
     // if the page's output formatting is on, then we'll return formatted values
     if ($this->page && $this->page->of()) {
         if ($key == 'created' || $key == 'expires' || $key == 'modified') {
             // format a unix timestamp to a date string
             $value = date('Y-m-d H:i:s', $value);
         } else {
             if ($key == 'title' || $key == 'text' || $key == 'from') {
                 // return entity encoded versions of strings
                 if ($key == 'title' && $this->flags & self::flagAllowMarkup) {
                     // leave title alone when markup is allowed
                 } else {
                     $value = $this->sanitizer->entities($value);
                 }
             }
         }
     } else {
         if ($key == 'created' && !$value) {
             $value = time();
         }
     }
     return $value;
 }
 /**
  * Handler for the InputfieldPageTableAdd ajax action
  * 
  * @param Page $page
  * @param Field $field
  * @param Page $item
  * @return bool
  * 
  */
 protected function addItem(Page $page, Field $field, Page $item)
 {
     // add an item and save the field
     if (!$item->id || $item->createdUser->id != $this->wire('user')->id) {
         return false;
     }
     $value = $page->getUnformatted($field->name);
     if ($value instanceof PageArray && !$value->has($item)) {
         $of = $page->of();
         $page->of(false);
         $value->add($item);
         $page->set($field->name, $value);
         $page->save($field->name);
         $this->notes = $this->_('Added item') . ' - ' . $item->name;
         $page->of($of);
         return true;
     }
     return false;
 }
 public function topicSave($options = array())
 {
     $pages = wire('pages');
     $templates = wire('templates');
     $defaultOptions = array('topicContent' => '', 'topicTitle' => '', 'forumID' => 0, 'status' => 'published', 'pinned' => 0, 'locked' => 0, 'isEdit' => false, 'editID' => 0);
     // Use the defaults if any options are omitted
     $topic = array_merge($defaultOptions, $options);
     // Store the forum id from our options in a variable (readability)
     $forumID = $topic['forumID'];
     $currentDateTime = date('U');
     // Unix timestamp
     // Update the topic if requested (edit == true)
     if ($topic['isEdit'] == true) {
         $editTopic = $pages->get($topic['editID']);
         $editTopic->of(false);
         $editTopic->hbb_topic_content = $topic['topicContent'];
         $editTopic->title = $topic['topicTitle'];
         $editTopic->hbb_edate = $currentDateTime;
         if ($topic['pinned'] == 1) {
             $editTopic->hbb_pinned = 1;
         } else {
             $editTopic->hbb_pinned = 0;
         }
         if ($topic['locked'] == 1) {
             $editTopic->hbb_locked = 1;
         } else {
             $editTopic->hbb_locked = 0;
         }
         $editTopic->save();
         $editTopic->of(true);
         // Otherwise, save a new topic (edit == false)
     } else {
         // Save the topic
         $template_topic = $templates->get('hbb_topic');
         $newTopic = new Page();
         $newTopic->of(false);
         $newTopic->parent = $pages->get($forumID)->path();
         $newTopic->template = $template_topic;
         $newTopic->title = $topic['topicTitle'];
         $newTopic->hbb_topic_content = $topic['topicContent'];
         $newTopic->hbb_ip = $this->wire('session')->getIP();
         $newTopic->hbb_agent = $_SERVER['HTTP_USER_AGENT'];
         $newTopic->hbb_edate = $currentDateTime;
         $newTopic->hbb_date = $currentDateTime;
         $newTopic->hbb_ldate = $currentDateTime;
         if ($comment['locked'] == 1) {
             $newComment->hbb_locked = 1;
         }
         if ($comment['pinned'] == 1) {
             $newComment->hbb_pinned = 1;
         }
         if ($topic['status'] == 'published') {
             $newTopic->addStatus(Page::statusOn);
         } elseif ($topic['status'] == 'unpublished') {
             $newTopic->addStatus(Page::statusUnpublished);
         }
         $newTopic->save();
         $newTopic->of(true);
     }
 }
if ($this->input->post->save_new_aanvraag) {
    // now we assume the form has been submitted.
    // tell the form to process input from the post vars.
    $form->processInput($this->input->post);
    // see if any errors occurred
    if (count($form->getErrors())) {
        $form->setMarkup(array('list' => "<div {attrs}>{out}</div>", 'item' => "<div {attrs}>{out}</div>"));
        // re-render the form, it will include the error messages
        $content = $form->render();
    } else {
        // successful form submission
        $np = new Page();
        // create new page object
        $np->template = $form->get("template_name")->value;
        // set template
        $np->parent = $pages->get('/aanvraag/');
        // set the parent
        $np->of(false);
        // turn off output formatting before setting values
        $np->save();
        foreach ($np->fields as $f) {
            $np->set($f->name, $form->get($f->name)->value);
        }
        $np->save();
        //create the page
        $content = "<p>Page saved.</p>";
    }
} else {
    $form->setMarkup(array('list' => "<div {attrs}>{out}</div>", 'item' => "<div {attrs}>{out}</div>"));
    $content = $form->render();
}