Exemple #1
0
 function getContent()
 {
     if ($staticpages = \Idno\Core\Idno::site()->plugins()->get('StaticPages')) {
         if (!empty($staticpages->getCurrentHomepageId())) {
             $object = \Idno\Common\Entity::getByID($staticpages->getCurrentHomepageId());
             if (empty($object)) {
                 $object = \Idno\Common\Entity::getBySlug($staticpages->getCurrentHomepageId());
             }
             if (empty($object)) {
                 $this->goneContent();
             }
             // From here, we know the object is set
             // Ensure we're talking about pages ...
             if (!$object instanceof \IdnoPlugins\StaticPages\StaticPage) {
                 $this->goneContent();
             }
             // Check that we can see it
             if (!$object->canRead()) {
                 $this->deniedContent();
             }
             // Forward if necessary
             if (!empty($object->forward_url) && !\Idno\Core\Idno::site()->session()->isAdmin()) {
                 $this->forward($object->forward_url);
             }
             $this->setOwner($object->getOwner());
             $this->setPermalink();
             // This is a permalink
             $this->setLastModifiedHeader($object->updated);
             // Say when this was last modified
             $t = \Idno\Core\Idno::site()->template();
             $t->__(array('title' => $object->getTitle(), 'body' => $t->__(array('object' => $object))->draw('staticpages/page'), 'description' => $object->getShortDescription()))->drawPage();
         }
     }
     parent::getContent();
 }
Exemple #2
0
 function deleteContent()
 {
     if (!empty($this->arguments[0])) {
         $object = \Idno\Common\Entity::getByID($this->arguments[0]);
         if (empty($object)) {
             $object = \Idno\Common\Entity::getBySlug($this->arguments[0]);
         }
     }
     if (empty($object)) {
         $this->forward();
     }
     // TODO: 404
     if ($object->delete()) {
         \Idno\Core\site()->session()->addMessage($object->getTitle() . ' was deleted.');
     }
     $this->forward($_SERVER['HTTP_REFERER']);
 }
Exemple #3
0
 function getContent()
 {
     if (!empty($this->arguments[0])) {
         $object = \Idno\Common\Entity::getByID($this->arguments[0]);
         if (empty($object)) {
             $object = \Idno\Common\Entity::getBySlug($this->arguments[0]);
         }
     }
     if (empty($object)) {
         $this->goneContent();
     }
     $permalink = $object->getUrl() . '/annotations/' . $this->arguments[1];
     $annotation = $object->getAnnotation($permalink);
     $subtype = $object->getAnnotationSubtype($permalink);
     $this->setPermalink();
     // This is a permalink
     $t = \Idno\Core\site()->template();
     $t->__(array('title' => $object->getTitle(), 'body' => $t->__(array('annotation' => $annotation, 'subtype' => $subtype, 'permalink' => $permalink, 'object' => $object))->draw('entity/annotations/shell'), 'description' => $object->getShortDescription()))->drawPage();
 }
Exemple #4
0
 function postContent()
 {
     $this->gatekeeper();
     if (!empty($this->arguments[0])) {
         $object = \Idno\Common\Entity::getByID($this->arguments[0]);
         if (empty($object)) {
             $object = \Idno\Common\Entity::getBySlug($this->arguments[0]);
         }
     }
     if (empty($object)) {
         $this->goneContent();
     }
     $permalink = $object->getURL() . '/annotations/' . $this->arguments[1];
     if ($object->canEditAnnotation($permalink)) {
         if ($object->removeAnnotation($permalink) && $object->save()) {
             //\Idno\Core\site()->session()->addMessage('The annotation was deleted.');
         }
     }
     $this->forward($object->getURL() . '#comments');
 }
Exemple #5
0
 function postContent()
 {
     $this->gatekeeper();
     if (!empty($this->arguments[0])) {
         $object = \Idno\Common\Entity::getByID($this->arguments[0]);
         if (empty($object)) {
             $object = \Idno\Common\Entity::getBySlug($this->arguments[0]);
         }
     }
     if (empty($object)) {
         $this->goneContent();
     }
     $permalink = $object->getUrl() . '/annotations/' . $this->arguments[1];
     if ($object->canEdit()) {
         if ($object->removeAnnotation($permalink) && $object->save()) {
             \Idno\Core\site()->session()->addMessage('Annotation ' . $permalink . ' was deleted.');
         }
     }
     $this->forward($_SERVER['HTTP_REFERER']);
 }
Exemple #6
0
 /**
  * Sets the URL slug of this entity to the given non-empty string, returning
  * the sanitized slug on success
  * @param string $slug
  * @param int $max_pieces The maximum number of words in the slug (default: 10)
  * @param int $max_chars The maximum number of characters in the slug (default: 255)
  * @return bool
  */
 function setSlug($slug, $max_pieces = 10, $max_chars = 255)
 {
     $plugin_slug = \Idno\Core\Idno::site()->triggerEvent('entity/slug', array('object' => $this));
     if (!empty($plugin_slug) && $plugin_slug !== true) {
         return $plugin_slug;
     }
     $slug = $this->prepare_slug($slug, $max_pieces, $max_chars);
     if (empty($slug)) {
         return false;
     }
     if ($entity = \Idno\Common\Entity::getBySlug($slug)) {
         if ($entity->getUUID() != $this->getUUID()) {
             return false;
         }
     }
     $this->slug = $slug;
     return $slug;
 }
Exemple #7
0
 /**
  * Sets the URL slug of this entity to the given non-empty string, returning
  * the sanitized slug on success
  * @param string $slug
  * @param int $limit The maximum length of the slug
  * @return bool
  */
 function setSlug($slug, $limit = 140)
 {
     $plugin_slug = \Idno\Core\site()->triggerEvent('entity/slug', ['object' => $this]);
     if (!empty($plugin_slug) && $plugin_slug !== true) {
         return $plugin_slug;
     }
     $slug = trim($slug);
     $slug = strtolower($slug);
     $slug = preg_replace('|https?://[a-z\\.0-9]+|i', '', $slug);
     $slug = preg_replace("/[^A-Za-z0-9\\-\\_ ]/", '', $slug);
     $slug = preg_replace("/[ ]+/", ' ', $slug);
     $slug = substr($slug, 0, $limit);
     $slug = str_replace(' ', '-', $slug);
     if (empty($slug)) {
         return false;
     }
     if ($entity = \Idno\Common\Entity::getBySlug($slug)) {
         if ($entity->getUUID() != $this->getUUID()) {
             return false;
         }
     }
     $this->slug = $slug;
     return $slug;
 }