]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch 'testing' of gitorious.org:statusnet/mainline into testing
authorZach Copley <zach@status.net>
Thu, 25 Feb 2010 00:52:16 +0000 (16:52 -0800)
committerZach Copley <zach@status.net>
Thu, 25 Feb 2010 00:52:16 +0000 (16:52 -0800)
* 'testing' of gitorious.org:statusnet/mainline:
  Merge StatusNet core localization updates from 0.9.x branch
  Fix update_po_templates.php to support the plural and context variants of _m() in plugins
  Drop HTMLPurifier; we don't need its extra capabilities and we're already using htmLawed which is lighter-weight.
  OStatus: handle update-profile Salmon pings
  Revert "Updated jQuery Form Plugin from v2.17 to v2.36"
  OStatus: disable HTMLPurify cache unless we've configured a writable path for it.

1  2 
lib/activity.php
plugins/OStatus/classes/Ostatus_profile.php

diff --combined lib/activity.php
index eace672a5a1605367fdcb6029029e33f8b388b1c,25727bf2b55314c806b39d390876e183be8d3bbe..3de5f62c7caf4a4d95c88cbd6a6f47c94cb4efd5
@@@ -154,15 -154,7 +154,15 @@@ class PoC
                  PoCo::NS
              );
  
 -            array_push($urls, new PoCoURL($type, $value, $primary));
 +            $isPrimary = false;
 +
 +            if (isset($primary) && $primary == 'true') {
 +                $isPrimary = true;
 +            }
 +
 +            // @todo check to make sure a primary hasn't already been added
 +
 +            array_push($urls, new PoCoURL($type, $value, $isPrimary));
          }
          return $urls;
      }
              PoCo::NS
          );
  
-         $formatted = ActivityUtils::childContent(
-             $addressEl,
-             PoCoAddress::FORMATTED,
-             self::NS
-         );
+         if (!empty($addressEl)) {
+             $formatted = ActivityUtils::childContent(
+                 $addressEl,
+                 PoCoAddress::FORMATTED,
+                 self::NS
+             );
  
-         if (!empty($formatted)) {
-             $address = new PoCoAddress();
-             $address->formatted = $formatted;
-             return $address;
+             if (!empty($formatted)) {
+                 $address = new PoCoAddress();
+                 $address->formatted = $formatted;
+                 return $address;
+             }
          }
  
          return null;
          return $poco;
      }
  
 +    function getPrimaryURL()
 +    {
 +        foreach ($this->urls as $url) {
 +            if ($url->primary) {
 +                return $url;
 +            }
 +        }
 +    }
 +
      function asString()
      {
          $xs = new XMLStringer(true);
@@@ -309,7 -294,7 +311,7 @@@ class ActivityUtil
       * @return string related link, if any
       */
  
-     static function getLink($element, $rel, $type=null)
+     static function getLink(DOMNode $element, $rel, $type=null)
      {
          $links = $element->getElementsByTagnameNS(self::ATOM, self::LINK);
  
       * @return DOMElement found element or null
       */
  
-     static function child($element, $tag, $namespace=self::ATOM)
+     static function child(DOMNode $element, $tag, $namespace=self::ATOM)
      {
          $els = $element->childNodes;
          if (empty($els) || $els->length == 0) {
       * @return string content of the child
       */
  
-     static function childContent($element, $tag, $namespace=self::ATOM)
+     static function childContent(DOMNode $element, $tag, $namespace=self::ATOM)
      {
          $el = self::child($element, $tag, $namespace);
  
@@@ -511,12 -496,6 +513,12 @@@ class ActivityObjec
  
          $this->element = $element;
  
 +        $this->geopoint = $this->_childContent(
 +            $element,
 +            ActivityContext::POINT,
 +            ActivityContext::GEORSS
 +        );
 +
          if ($element->tagName == 'author') {
  
              $this->type  = self::PERSON; // XXX: is this fair?
@@@ -782,29 -761,22 +784,29 @@@ class ActivityContex
  
          for ($i = 0; $i < $points->length; $i++) {
              $point = $points->item($i)->textContent;
 -            $point = str_replace(',', ' ', $point); // per spec "treat commas as whitespace"
 -            $point = preg_replace('/\s+/', ' ', $point);
 -            $point = trim($point);
 -            $coords = explode(' ', $point);
 -            if (count($coords) == 2) {
 -                list($lat, $lon) = $coords;
 -                if (is_numeric($lat) && is_numeric($lon)) {
 -                    common_log(LOG_INFO, "Looking up location for $lat $lon from georss");
 -                    return Location::fromLatLon($lat, $lon);
 -                }
 -            }
 -            common_log(LOG_ERR, "Ignoring bogus georss:point value $point");
 +            return self::locationFromPoint($point);
          }
  
          return null;
      }
 +
 +    // XXX: Move to ActivityUtils or Location?
 +    static function locationFromPoint($point)
 +    {
 +        $point = str_replace(',', ' ', $point); // per spec "treat commas as whitespace"
 +        $point = preg_replace('/\s+/', ' ', $point);
 +        $point = trim($point);
 +        $coords = explode(' ', $point);
 +        if (count($coords) == 2) {
 +            list($lat, $lon) = $coords;
 +            if (is_numeric($lat) && is_numeric($lon)) {
 +                common_log(LOG_INFO, "Looking up location for $lat $lon from georss point");
 +                return Location::fromLatLon($lat, $lon);
 +            }
 +        }
 +        common_log(LOG_ERR, "Ignoring bogus georss:point value $point");
 +        return null;
 +    }
  }
  
  /**
index 144fdfa8b7ad4693e12dbf336a288714cf92ddd8,a366c1c2cf4b96fe5d7eea042c1358bedc774ca2..4f73fd65be9dcc6cb04792ec105bc2ab44a1afc3
@@@ -668,10 -668,9 +668,9 @@@ class Ostatus_profile extends Memcached
       */
      protected function purify($html)
      {
-         // @fixme disable caching or set a sane temp dir
-         require_once(INSTALLDIR.'/extlib/HTMLPurifier/HTMLPurifier.auto.php');
-         $purifier = new HTMLPurifier();
-         return $purifier->purify($html);
+         require_once INSTALLDIR.'/extlib/htmLawed/htmLawed.php';
+         $config = array('safe' => 1);
+         return htmLawed($html, $config);
      }
  
      /**
       * @param Activity $activity
       * @return mixed matching Ostatus_profile or false if none known
       */
-     protected static function getActorProfile($activity)
+     public static function getActorProfile($activity)
      {
          return self::getActivityObjectProfile($activity->actor);
      }
       * @param ActivityObject $object
       * @param array $hints
       */
-     protected function updateFromActivityObject($object, $hints=array())
+     public function updateFromActivityObject($object, $hints=array())
      {
          if ($this->isGroup()) {
              $group = $this->localGroup();
              $profile->profileurl = $hints['profileurl'];
          }
  
 -        // @fixme bio
 +        $profile->bio      = self::getActivityObjectBio($object, $hints);
 +        $profile->location = self::getActivityObjectLocation($object, $hints);
 +        $profile->homepage = self::getActivityObjectHomepage($object, $hints);
 +
 +        if (!empty($object->geopoint)) {
 +            $location = ActivityContext::locationFromPoint($object->geopoint);
 +            if (!empty($location)) {
 +                $profile->lat = $location->lat;
 +                $profile->lon = $location->lon;
 +            }
 +        }
 +
          // @fixme tags/categories
 -        // @fixme location?
          // @todo tags from categories
 -        // @todo lat/lon/location?
  
          if ($profile->id) {
              common_log(LOG_DEBUG, "Updating OStatus profile $profile->id from remote info $object->id: " . var_export($object, true) . var_export($hints, true));
          }
      }
  
 +    protected static function getActivityObjectHomepage($object, $hints=array())
 +    {
 +        $homepage = null;
 +        $poco     = $object->poco;
 +
 +        if (!empty($poco)) {
 +            $url = $poco->getPrimaryURL();
 +            if ($url->type == 'homepage') {
 +                $homepage = $url->value;
 +            }
 +        }
 +
 +        // @todo Try for a another PoCo URL?
 +
 +        return $homepage;
 +    }
 +
 +    protected static function getActivityObjectLocation($object, $hints=array())
 +    {
 +        $location = null;
 +
 +        if (!empty($object->poco)) {
 +            if (isset($object->poco->address->formatted)) {
 +                $location = $object->poco->address->formatted;
 +                if (mb_strlen($location) > 255) {
 +                    $location = mb_substr($note, 0, 255 - 3) . ' … ';
 +                }
 +            }
 +        }
 +
 +        // @todo Try to find location some othe way? Via goerss point?
 +
 +        return $location;
 +    }
 +
 +    protected static function getActivityObjectBio($object, $hints=array())
 +    {
 +        $bio  = null;
 +
 +        if (!empty($object->poco)) {
 +            $note = $object->poco->note;
 +            if (!empty($note)) {
 +                if (mb_strlen($note) > Profile::maxBio()) {
 +                    // XXX: truncate ok?
 +                    $bio = mb_substr($note, 0, Profile::maxBio() - 3) . ' … ';
 +                } else {
 +                    $bio = $note;
 +                }
 +            }
 +        }
 +
 +        // @todo Try to get bio info some other way?
 +
 +        return $bio;
 +    }
 +
      protected static function getActivityObjectNickname($object, $hints=array())
      {
          if ($object->poco) {