Ejemplo n.º 1
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();
 }
Ejemplo n.º 2
0
 function getContent()
 {
     if (!empty($this->arguments[0])) {
         $user = \Idno\Entities\User::getByHandle($this->arguments[0]);
     }
     if (empty($user)) {
         $this->noContent();
     }
     // Users own their own profiles
     $this->setOwner($user);
     $types = \Idno\Common\ContentType::getRegisteredClasses();
     $offset = (int) $this->getInput('offset');
     $count = \Idno\Common\Entity::countFromX($types, array('owner' => $user->getUUID()));
     $feed = \Idno\Common\Entity::getFromX($types, array('owner' => $user->getUUID()), array(), \Idno\Core\Idno::site()->config()->items_per_page, $offset);
     $last_modified = $user->updated;
     if (!empty($feed) && is_array($feed)) {
         if ($feed[0]->updated > $last_modified) {
             $last_modified = $feed[0]->updated;
         }
     }
     $this->setLastModifiedHeader($last_modified);
     $t = \Idno\Core\Idno::site()->template();
     $t->__(array('title' => $user->getTitle(), 'body' => $t->__(array('user' => $user, 'items' => $feed, 'count' => $count, 'offset' => $offset))->draw('entity/User/profile'), 'description' => 'The ' . \Idno\Core\Idno::site()->config()->title . ' profile for ' . $user->getTitle()))->drawPage();
 }
Ejemplo n.º 3
0
 /**
  * Count the number of posts this user has made
  * @return int
  */
 function countPosts()
 {
     $types = \Idno\Common\ContentType::getRegisteredClasses();
     return \Idno\Common\Entity::countFromX($types, array('owner' => $this->getUUID()));
 }
Ejemplo n.º 4
0
 function getContent()
 {
     $query = $this->getInput('q');
     $offset = (int) $this->getInput('offset');
     $types = $this->getInput('types');
     $friendly_types = array();
     // Check for an empty site
     if (!\Idno\Entities\User::get()) {
         $this->forward(\Idno\Core\Idno::site()->config()->getURL() . 'begin/');
     }
     // Set the homepage owner for single-user sites
     if (!$this->getOwner() && \Idno\Core\Idno::site()->config()->single_user) {
         $owners = \Idno\Entities\User::get(['admin' => true]);
         if (count($owners) === 1) {
             $this->setOwner($owners[0]);
         } else {
             \Idno\Core\Idno::site()->logging()->warning('Expected exactly 1 admin user for single-user site; got ' . count($owners));
         }
     }
     if (!empty($this->arguments[0])) {
         // If we're on the friendly content-specific URL
         if ($friendly_types = explode('/', $this->arguments[0])) {
             $friendly_types = array_filter($friendly_types);
             if (empty($friendly_types) && !empty($query)) {
                 $friendly_types = array('all');
             }
             $types = array();
             // Run through the URL parameters and set content types appropriately
             foreach ($friendly_types as $friendly_type) {
                 if ($friendly_type == 'all') {
                     $types = \Idno\Common\ContentType::getRegisteredClasses();
                     break;
                 }
                 if ($content_type_class = \Idno\Common\ContentType::categoryTitleToClass($friendly_type)) {
                     $types[] = $content_type_class;
                 }
             }
         }
     } else {
         // If user has content-specific preferences, do something with $friendly_types
         if (empty($query)) {
             $types = \Idno\Core\Idno::site()->config()->getHomepageContentTypes();
         }
     }
     $search = array();
     if (!empty($query)) {
         $search = \Idno\Core\Idno::site()->db()->createSearchArray($query);
     }
     if (empty($types)) {
         $types = \Idno\Common\ContentType::getRegisteredClasses();
     } else {
         $types = (array) $types;
     }
     $count = \Idno\Common\Entity::countFromX($types, array());
     $feed = \Idno\Common\Entity::getFromX($types, $search, array(), \Idno\Core\Idno::site()->config()->items_per_page, $offset);
     if (\Idno\Core\Idno::site()->session()->isLoggedIn()) {
         $create = \Idno\Common\ContentType::getRegistered();
         // If we can't create an object of this type, hide from the button bar
         foreach ($create as $key => $obj) {
             if (!$obj->createable) {
                 unset($create[$key]);
             }
         }
     } else {
         $create = false;
     }
     if (!empty(\Idno\Core\Idno::site()->config()->description)) {
         $description = \Idno\Core\Idno::site()->config()->description;
     } else {
         $description = 'An independent social website, powered by Known.';
     }
     // If we have a feed, set our last modified flag to the time of the latest returned entry
     if (!empty($feed)) {
         if (is_array($feed)) {
             $feed = array_filter($feed);
             $this->setLastModifiedHeader(reset($feed)->updated);
         }
     }
     if (!empty(\Idno\Core\Idno::site()->config()->homepagetitle)) {
         $title = \Idno\Core\Idno::site()->config()->homepagetitle;
     } else {
         $title = \Idno\Core\Idno::site()->config()->title;
     }
     $t = \Idno\Core\Idno::site()->template();
     $t->__(array('title' => $title, 'description' => $description, 'content' => $friendly_types, 'body' => $t->__(array('items' => $feed, 'contentTypes' => $create, 'offset' => $offset, 'count' => $count, 'subject' => $query, 'content' => $friendly_types))->draw('pages/home')))->drawPage();
 }