Exemplo n.º 1
0
 /**
  * If this Known installation has a PubSubHubbub hub, send a publish notification to the hub
  * @param \Idno\Common\Entity $object
  * @return array
  */
 static function publish($object)
 {
     if ($hub = Idno::site()->config()->hub) {
         $base = Idno::site()->config()->getDisplayURL();
         $feeds = array();
         // Check to make sure there's an entity
         if (!$object instanceof Entity) {
             return false;
         }
         // homepage feed
         $homepage_types = Idno::site()->config()->getHomepageContentTypes();
         $type_in_homepage = false;
         if ($object instanceof Entity) {
             if ($object->getContentType() && in_array($object->getContentType()->getEntityClass(), $homepage_types)) {
                 $type_in_homepage = true;
             }
         }
         if (empty($homepage_types) || $type_in_homepage) {
             $feeds[] = $base;
         }
         // type-specific feeds
         if ($object instanceof Entity) {
             $feeds[] = $base . 'content/' . $object->getContentTypeCategorySlug() . '/';
         }
         $feeds[] = $base . 'content/all/';
         // tag feeds
         foreach ($object->getTags() as $tag) {
             $feeds[] = $base . 'tag/' . $tag;
         }
         if (!empty($feeds)) {
             // encode the feeds and their RSS counterparts
             $encurls = array();
             foreach ($feeds as $feed) {
                 $encurls[] = urlencode($feed);
                 $encurls[] = urlencode(Idno::site()->template()->getURLWithVar('_t', 'rss', $feed));
             }
             $formdata = 'hub.mode=publish&hub.url=' . implode(',', $encurls);
             Idno::site()->logging()->info('Pinging ' . $hub . ' with data ' . $formdata);
             Webservice::post($hub, $formdata, array('Content-Type' => 'application/x-www-form-urlencoded'));
         }
         return true;
     }
     return false;
 }