Exemplo n.º 1
0
Arquivo: Post.php Projeto: emory/Known
 function postContent()
 {
     $body = strip_tags($this->getInput('body'));
     $name = strip_tags($this->getInput('name'));
     $url = trim($this->getInput('url'));
     $url2 = trim($this->getInput('url-2'));
     $validator = $this->getInput('validator');
     if (!empty($url2)) {
         $this->deniedContent();
     }
     $this->referrerGatekeeper();
     if (!empty($body) && !empty($name) && !empty($validator)) {
         if ($object = Entity::getByUUID($validator)) {
             if ($url = Webservice::sanitizeURL($url)) {
                 if ($content = Webservice::get($url)) {
                     if ($content['response'] == '200') {
                         $icon = Webmention::getIconFromWebsiteContent($content['content'], $url);
                     }
                 }
             }
             if (empty($icon)) {
                 $bn = hexdec(substr(md5($url), 0, 15));
                 $number = 1 + $bn % 5;
                 $icon = \Idno\Core\site()->config()->url . 'gfx/users/default-' . str_pad($number, 2, '0', STR_PAD_LEFT) . '.png';
             }
             $object->addAnnotation('reply', $name, $url, $icon, $body);
             $this->forward($object->getDisplayURL());
         }
     }
 }
Exemplo n.º 2
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();
 }
Exemplo n.º 3
0
 function getContent()
 {
     $subject = $this->getInput('q');
     $types = $this->getInput('types');
     $subject = trim($subject);
     $offset = (int) $this->getInput('offset');
     if (empty($types)) {
         $types = '!Idno\\Entities\\ActivityStreamPost';
     } else {
         if (!is_array($types)) {
             $types = [$types];
         }
         $types[] = '!Idno\\Entities\\ActivityStreamPost';
     }
     if (!empty($subject)) {
         $regexObj = new \MongoRegex("/" . addslashes($subject) . "/i");
         $items = \Idno\Common\Entity::getFromX($types, ['$or' => [['body' => $regexObj], ['title' => $regexObj], ['description' => $regexObj]]], [], 10, $offset);
         $count = \Idno\Common\Entity::countFromX($types, ['$or' => [['body' => $regexObj], ['title' => $regexObj], ['description' => $regexObj]]]);
     } else {
         $items = [];
         $subject = 'Search';
         $count = 0;
     }
     $t = \Idno\Core\site()->template();
     $t->__(array('title' => $subject, 'body' => $t->__(array('subject' => $subject, 'items' => $items, 'count' => $count, 'offset' => $offset))->draw('entity/search')))->drawPage();
 }
Exemplo n.º 4
0
Arquivo: Post.php Projeto: hank/Known
 function postContent()
 {
     $this->createGatekeeper();
     // User is logged in and can post content
     // Get variables
     $body = $this->getInput('body');
     $object_uuid = $this->getInput('object');
     $type = $this->getInput('type');
     $user = \Idno\Core\site()->session()->currentUser();
     if ($type != 'like') {
         $type = 'reply';
     }
     if ($object = Entity::getByUUID($object_uuid)) {
         $has_liked = false;
         if ($type == 'like') {
             if ($like_annotations = $object->getAnnotations('like')) {
                 foreach ($like_annotations as $like) {
                     if ($like['owner_url'] == \Idno\Core\site()->session()->currentUser()->getURL()) {
                         $object->removeAnnotation($like['permalink']);
                         $object->save();
                         $has_liked = true;
                     }
                 }
             }
         }
         if (!$has_liked) {
             if ($object->addAnnotation($type, $user->getTitle(), $user->getURL(), $user->getIcon(), $body)) {
                 $object->save();
             }
         }
         $this->forward($object->getURL() . '#comments');
     }
 }
Exemplo n.º 5
0
 function save()
 {
     // generate our own meaningful, unique(ish) slug
     if (!$this->getSlug() && !$this->_id && $this->getTitle() && $this->likeof) {
         $this->setSlugResilient($this->getTitle() . '-' . substr(md5($this->likeof), 0, 10));
     }
     return parent::save();
 }
Exemplo n.º 6
0
 function __construct()
 {
     parent::__construct();
     $this->code = hash('sha256', mt_rand() . microtime(true));
     $this->expires = strtotime('now + 10 minutes');
     $this->setTitle($this->code);
     // better stub generation, not that it matters
 }
Exemplo n.º 7
0
 function getURL()
 {
     if (!$this->getSlug() && $this->getID()) {
         return \Idno\Core\site()->config()->url . 'entry/' . $this->getID() . '/' . $this->getPrettyURLTitle();
     } else {
         return parent::getURL();
     }
 }
Exemplo n.º 8
0
 function getURL()
 {
     if (!$this->getSlug() && $this->getID()) {
         return \Idno\Core\site()->config()->url . 'rsvp/' . $this->getID() . '/';
     } else {
         return parent::getURL();
     }
 }
Exemplo n.º 9
0
 function getURL()
 {
     if ($this->getID()) {
         return \Idno\Core\site()->config()->url . 'slides/' . $this->getID();
         // . '/' . $this->getPrettyURLTitle();
     } else {
         return parent::getURL();
     }
 }
Exemplo n.º 10
0
 /**
  * Retrieve icon
  * @return mixed|string
  */
 function getIcon()
 {
     $xpath = new \DOMXPath(@\DOMDocument::loadHTML($this->getDescription()));
     $src = $xpath->evaluate("string(//img/@src)");
     if (!empty($src)) {
         return $src;
     }
     return parent::getIcon();
 }
Exemplo n.º 11
0
 function __construct($token_type = 'grant', $expires_in = 2419200)
 {
     parent::__construct();
     $this->access_token = hash('sha256', mt_rand() . microtime(true));
     $this->refresh_token = hash('sha256', mt_rand() . microtime(true));
     $this->expires_in = $expires_in;
     // Default expires is 1 month, like facebook
     $this->token_type = $token_type;
     $this->setTitle($this->access_token);
     // better stub generation, not that it matters
 }
Exemplo n.º 12
0
 /**
  * Extend json serialisable to include some extra data
  */
 public function jsonSerialize()
 {
     $object = parent::jsonSerialize();
     // Add some thumbs
     $object['thumbnails'] = [];
     $sizes = \Idno\Core\site()->events()->dispatch('photo/thumbnail/getsizes', new \Idno\Core\Event(array('sizes' => ['large' => 800, 'medium' => 400, 'small' => 200])));
     foreach ($sizes->data()['sizes'] as $label => $size) {
         $varname = "thumbnail_{$label}";
         $object['thumbnails'][$label] = $this->{$varname};
     }
     return $object;
 }
Exemplo n.º 13
0
 /**
  * Sets a static page as the homepage, overwriting the current setting if one is set.
  * @param $pageId
  * @return bool
  */
 function setAsHomepage($pageId)
 {
     if (\Idno\Core\Idno::site()->session()->isLoggedIn()) {
         if (\Idno\Core\Idno::site()->session()->currentUser()->isAdmin()) {
             if (!empty(\Idno\Common\Entity::getByID($pageId))) {
                 \Idno\Core\Idno::site()->config->staticPages['homepage'] = $pageId;
                 return \Idno\Core\Idno::site()->config->save();
             }
         }
     }
     return false;
 }
Exemplo n.º 14
0
 /**
  * Extend json serialisable to include some extra data
  */
 public function jsonSerialize()
 {
     $object = parent::jsonSerialize();
     // Add some thumbs
     $object['thumbnails'] = array();
     $sizes = \Idno\Core\Idno::site()->events()->dispatch('photo/thumbnail/getsizes', new \Idno\Core\Event(array('sizes' => array('large' => 800, 'medium' => 400, 'small' => 200))));
     $eventdata = $sizes->data();
     foreach ($eventdata['sizes'] as $label => $size) {
         $varname = "thumbnail_{$label}";
         $object['thumbnails'][$label] = preg_replace('/^(https?:\\/\\/\\/)/', \Idno\Core\Idno::site()->config()->url, $this->{$varname});
     }
     return $object;
 }
Exemplo n.º 15
0
 function deleteContent()
 {
     if (!empty($this->arguments[0])) {
         $object = \Idno\Common\Entity::getByID($this->arguments[0]);
     }
     if (empty($object)) {
         $this->forward();
     }
     // TODO: 404
     if ($object->delete()) {
         \Idno\Core\Idno::site()->session()->addMessage($object->getTitle() . ' was deleted.');
     }
     $this->forward($_SERVER['HTTP_REFERER']);
 }
Exemplo n.º 16
0
 function webmentionContent($source, $target, $source_content, $source_mf2)
 {
     if (!empty($this->arguments[0])) {
         $object = \Idno\Common\Entity::getByShortURL($this->arguments[0]);
     }
     if (empty($object)) {
         return false;
     }
     $return = true;
     if ($object instanceof \Idno\Common\Entity) {
         $return = $object->addWebmentions($source, $target, $source_content, $source_mf2);
     }
     return $return;
 }
Exemplo n.º 17
0
 function getURL()
 {
     // If we have a URL override, use it
     if (!empty($this->url)) {
         return $this->url;
     }
     if (!empty($this->canonical)) {
         return $this->canonical;
     }
     if (!$this->getSlug() && $this->getID()) {
         return \Idno\Core\Idno::site()->config()->url . 'event/' . $this->getID() . '/' . $this->getPrettyURLTitle();
     } else {
         return parent::getURL();
     }
 }
Exemplo n.º 18
0
 function getContent()
 {
     if (!empty($this->arguments[0])) {
         $object = \Idno\Common\Entity::getByID($this->arguments[0]);
     }
     if (empty($object)) {
         $this->forward();
     }
     // TODO: 404
     if (!$object->canEdit()) {
         $this->forward($object->getURL());
     }
     $t = \Idno\Core\site()->template();
     $t->__(array('title' => $object->getTitle(), 'body' => $object->drawEdit()))->drawPage();
 }
Exemplo n.º 19
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();
 }
Exemplo n.º 20
0
 function getContent()
 {
     if (!empty($this->arguments[0])) {
         $object = \Idno\Common\Entity::getByID($this->arguments[0]);
     }
     if (empty($object)) {
         $this->forward();
     }
     // TODO: 404
     if (!$object->canEdit()) {
         $this->forward($object->getDisplayURL());
     }
     if ($owner = $object->getOwner()) {
         $this->setOwner($owner);
     }
     session_write_close();
     $t = \Idno\Core\Idno::site()->template();
     $t->__(array('title' => $object->getTitle(), 'body' => $t->__(['object' => $object])->draw('entity/editwrapper')))->drawPage();
 }
Exemplo n.º 21
0
 function postContent()
 {
     if (!empty($this->arguments[0])) {
         $object = \Idno\Common\Entity::getByID($this->arguments[0]);
     }
     if (empty($object)) {
         $this->setResponse(404);
         echo \Idno\Core\Idno::site()->template()->__(array('body' => \Idno\Core\Idno::site()->template()->draw('404'), 'title' => 'Not found'))->drawPage();
         exit;
     }
     if (!$object->canEdit()) {
         $this->setResponse(403);
         echo \Idno\Core\Idno::site()->template()->__(array('body' => \Idno\Core\Idno::site()->template()->draw('403'), 'title' => 'Permission denied'))->drawPage();
         exit;
     }
     $object->unsyndicate();
     \Idno\Core\Idno::site()->session()->addMessage("We removed copies on all the syndicated sites.");
     $this->forward($object->getDisplayURL());
 }
Exemplo n.º 22
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');
 }
Exemplo n.º 23
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']);
 }
Exemplo n.º 24
0
 function postContent()
 {
     $this->createGatekeeper();
     if (!empty($this->arguments)) {
         $object = Entity::getByID($this->arguments[0]);
     }
     if ($object) {
         if (!$object->canEdit()) {
             $this->setResponse(403);
             Idno::site()->session()->addErrorMessage("You don't have permission to delete this object.");
         } else {
             if ($object->delete()) {
                 Idno::site()->session()->addMessage($object->getTitle() . ' was deleted.');
             } else {
                 Idno::site()->session()->addErrorMessage("We couldn't delete " . $object->getTitle() . ".");
             }
         }
     }
     $this->forward($_SERVER['HTTP_REFERER']);
 }
Exemplo n.º 25
0
 function post()
 {
     \Idno\Core\Idno::site()->logging->debug("Pubsub: Ping received");
     // Since we've overloaded post, we need to parse the arguments
     $arguments = func_get_args();
     if (!empty($arguments)) {
         $this->arguments = $arguments;
     }
     // Find users
     if (!empty($this->arguments[0])) {
         $subscriber = \Idno\Common\Entity::getByID($this->arguments[0]);
     }
     if (empty($subscriber) || !$subscriber instanceof \Idno\Entities\User) {
         $this->goneContent();
     }
     if (!empty($this->arguments[1])) {
         $subscription = \Idno\Common\Entity::getByID($this->arguments[1]);
     }
     if (empty($subscription) || !$subscription instanceof \Idno\Entities\User) {
         $this->goneContent();
     }
     \Idno\Core\Idno::site()->logging->debug("Pubsub: Ping received, pinging out...");
     \Idno\Core\Idno::site()->triggerEvent('pubsubhubbub/ping', array('subscriber' => $subscriber, 'subscription' => $subscription, 'data' => trim(file_get_contents("php://input"))));
 }
Exemplo n.º 26
0
 function post()
 {
     parse_str(trim(file_get_contents("php://input")), $vars);
     // Check that both source and target are non-empty
     if (!empty($vars['source']) && !empty($vars['target']) && $vars['source'] != $vars['target']) {
         $source = $vars['source'];
         $target = $vars['target'];
         // Remove anchors from target URL, but save them to '#' input so we can still reference them later
         if (strpos($target, '#')) {
             list($target, $fragment) = explode('#', $target, 2);
             if (!empty($fragment)) {
                 $this->setInput('#', $fragment);
             }
         }
         // Get the page handler for target
         if ($page = \Idno\Core\Idno::site()->getPageHandler($target)) {
             // First of all, make sure the target page isn't the source page. Let's not webmention ourselves!
             $webmention_ok = true;
             if (\Idno\Common\Entity::isLocalUUID($source)) {
                 if ($source_page = \Idno\Core\Idno::site()->getPageHandler($source)) {
                     if ($source_page == $page) {
                         $webmention_ok = false;
                     }
                 }
             }
             // Check that source exists, parse it for mf2 content,
             // and ensure that it genuinely mentions this page
             if ($webmention_ok) {
                 if ($source_content = \Idno\Core\Webservice::get($source)) {
                     if (substr_count($source_content['content'], $target) || $source_content['response'] == 410) {
                         $source_mf2 = \Idno\Core\Webmention::parseContent($source_content['content'], $source);
                         // Set source and target information as input variables
                         $page->setPermalink();
                         if ($page->webmentionContent($source, $target, $source_content, $source_mf2)) {
                             $this->setResponse(202);
                             // Webmention received a-ok.
                             exit;
                         } else {
                             $error = 'target_not_supported';
                             $error_text = 'This is not webmentionable.';
                         }
                     } else {
                         $error = 'no_link_found';
                         $error_text = 'The source URI does not contain a link to the target URI.';
                         \Idno\Core\Idno::site()->logging->warning('No link from ' . $source . ' to ' . $target);
                     }
                 } else {
                     $error = 'source_not_found';
                     $error_text = 'The source content for ' . $source . ' could not be obtained.';
                     \Idno\Core\Idno::site()->logging->warning('No content from ' . $source);
                 }
             } else {
                 $error = 'target_not_supported';
                 $error_text = 'A page can\'t webmention itself.';
             }
         } else {
             $error = 'target_not_found';
             $error_text = 'The target page ' . $target . ' does not exist.';
             \Idno\Core\Idno::site()->logging()->error('Could not find handler for ' . $target);
         }
     }
     $this->setResponse(400);
     // Webmention failed.
     if (empty($error)) {
         $error = 'unknown_error';
         $error_text = 'Not all the required webmention variables were set.';
     }
     echo json_encode(array('error' => $error, 'error_text' => $error_text));
 }
Exemplo n.º 27
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;
 }
Exemplo n.º 28
0
 public function jsonSerialize()
 {
     $data = parent::jsonSerialize();
     $data['image'] = array('url' => $this->getIcon());
     return $data;
 }
Exemplo n.º 29
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;
 }
Exemplo n.º 30
0
 /**
  * Get the actor associated with this entity
  */
 function getActor()
 {
     return \Idno\Common\Entity::getByUUID($this->actor);
 }