]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch 'master' of git://gitorious.org/laconica/br3nda into review/master
authorCiaranG <ciaran@ciarang.com>
Wed, 8 Apr 2009 21:11:58 +0000 (22:11 +0100)
committerCiaranG <ciaran@ciarang.com>
Wed, 8 Apr 2009 21:11:58 +0000 (22:11 +0100)
1  2 
classes/Notice.php
lib/util.php

diff --combined classes/Notice.php
index 44a6aeb986914b4ab6c6c8ccc8987d2a67443329,6573c337c5e64bd2caf7fe46feac494099f716b0..5fa0d79a1639ddb03eba10832391500d6902f5f7
@@@ -67,6 -67,8 +67,8 @@@ class Notice extends Memcached_DataObje
          $this->blowSubsCache(true);
  
          $this->query('BEGIN');
+         //Null any notices that are replies to this notice
+         $this->query(sprintf("UPDATE notice set reply_to = null WHERE reply_to = %d", $this->id));
          $related = array('Reply',
                           'Fave',
                           'Notice_tag',
              }
          }
      }
 +
 +    function asAtomEntry($namespace=false, $source=false)
 +    {
 +        $profile = $this->getProfile();
 +
 +        $xs = new XMLStringer(true);
 +
 +        if ($namespace) {
 +            $attrs = array('xmlns' => 'http://www.w3.org/2005/Atom',
 +                           'xmlns:thr' => 'http://purl.org/syndication/thread/1.0');
 +        } else {
 +            $attrs = array();
 +        }
 +
 +        $xs->elementStart('entry', $attrs);
 +
 +        if ($source) {
 +            $xs->elementStart('source');
 +            $xs->element('title', null, $profile->nickname . " - " . common_config('site', 'name'));
 +            $xs->element('link', array('href' => $profile->profileurl));
 +            $user = User::staticGet('id', $profile->id);
 +            if (!empty($user)) {
 +                $atom_feed = common_local_url('api',
 +                                              array('apiaction' => 'statuses',
 +                                                    'method' => 'user_timeline',
 +                                                    'argument' => $profile->nickname.'.atom'));
 +                $xs->element('link', array('rel' => 'self',
 +                                           'type' => 'application/atom+xml',
 +                                           'href' => $profile->profileurl));
 +                $xs->element('link', array('rel' => 'license',
 +                                           'href' => common_config('license', 'url')));
 +            }
 +
 +            $xs->element('icon', null, $profile->avatarUrl(AVATAR_PROFILE_SIZE));
 +        }
 +
 +        $xs->elementStart('author');
 +        $xs->element('name', null, $profile->nickname);
 +        $xs->element('uri', null, $profile->profileurl);
 +        $xs->elementEnd('author');
 +
 +        if ($source) {
 +            $xs->elementEnd('source');
 +        }
 +
 +        $xs->element('title', null, $this->content);
 +        $xs->element('summary', null, $this->content);
 +
 +        $xs->element('link', array('rel' => 'alternate',
 +                                   'href' => $this->bestUrl()));
 +
 +        $xs->element('id', null, $this->uri);
 +
 +        $xs->element('published', null, common_date_w3dtf($this->created));
 +        $xs->element('updated', null, common_date_w3dtf($this->modified));
 +
 +        if ($this->reply_to) {
 +            $reply_notice = Notice::staticGet('id', $this->reply_to);
 +            if (!empty($reply_notice)) {
 +                $xs->element('link', array('rel' => 'related',
 +                                           'href' => $reply_notice->bestUrl()));
 +                $xs->element('thr:in-reply-to',
 +                             array('ref' => $reply_notice->uri,
 +                                   'href' => $reply_notice->bestUrl()));
 +            }
 +        }
 +
 +        $xs->element('content', array('type' => 'html'), $this->rendered);
 +
 +        $tag = new Notice_tag();
 +        $tag->notice_id = $this->id;
 +        if ($tag->find()) {
 +            while ($tag->fetch()) {
 +                $xs->element('category', array('term' => $tag->tag));
 +            }
 +        }
 +        $tag->free();
 +
 +        $xs->elementEnd('entry');
 +
 +        return $xs->getString();
 +    }
 +
 +    function bestUrl()
 +    {
 +        if (!empty($this->url)) {
 +            return $this->url;
 +        } else if (!empty($this->uri) && preg_match('/^https?:/', $this->uri)) {
 +            return $this->uri;
 +        } else {
 +            return common_local_url('shownotice',
 +                                    array('notice' => $this->id));
 +        }
 +    }
  }
diff --combined lib/util.php
index b17a44bd8538255fd348ed17433e24268ecd4bac,19637d546562792c25a7e6bc021cb10c8fd5018f..675ff51f016dd0a53b87b5cc9c227b5e5a5f9d97
@@@ -480,12 -480,18 +480,12 @@@ function common_replace_urls_callback($
  function common_linkify($url) {
      // It comes in special'd, so we unspecial it before passing to the stringifying
      // functions
 -    $ext = pathinfo($url, PATHINFO_EXTENSION);
      $url = htmlspecialchars_decode($url);
 -    $video_ext = array('mp4', 'flv', 'avi', 'mpg', 'mp3', 'ogg');
      $display = $url;
      $url = (!preg_match('#^([a-z]+://|(mailto|aim|tel):)#i', $url)) ? 'http://'.$url : $url;
  
      $attrs = array('href' => $url, 'rel' => 'external');
  
 -    if (in_array($ext, $video_ext)) {
 -        $attrs['class'] = 'media';
 -    }
 -
      if ($longurl = common_longurl($url)) {
          $attrs['title'] = $longurl;
      }
@@@ -581,8 -587,10 +581,8 @@@ function common_shorten_link($url, $rev
  
  function common_xml_safe_str($str)
  {
 -    $xmlStr = htmlentities(iconv('UTF-8', 'UTF-8//IGNORE', $str), ENT_NOQUOTES, 'UTF-8');
 -
 -    // Replace control, formatting, and surrogate characters with '*', ala Twitter
 -    return preg_replace('/[\p{Cc}\p{Cf}\p{Cs}]/u', '*', $str);
 +    // Neutralize control codes and surrogates
 +      return preg_replace('/[\p{Cc}\p{Cs}]/u', '*', $str);
  }
  
  function common_tag_link($tag)
@@@ -620,13 -628,9 +620,13 @@@ function common_at_link($sender_id, $ni
              $url = $recipient->profileurl;
          }
          $xs = new XMLStringer(false);
 +        $attrs = array('href' => $url,
 +                       'class' => 'url');
 +        if (!empty($recipient->fullname)) {
 +            $attrs['title'] = $recipient->fullname . ' (' . $recipient->nickname . ')';
 +        }
          $xs->elementStart('span', 'vcard');
 -        $xs->elementStart('a', array('href' => $url,
 -                                     'class' => 'url'));
 +        $xs->elementStart('a', $attrs);
          $xs->element('span', 'fn nickname', $nickname);
          $xs->elementEnd('a');
          $xs->elementEnd('span');
@@@ -641,14 -645,10 +641,14 @@@ function common_group_link($sender_id, 
      $sender = Profile::staticGet($sender_id);
      $group = User_group::staticGet('nickname', common_canonical_nickname($nickname));
      if ($group && $sender->isMember($group)) {
 +        $attrs = array('href' => $group->permalink(),
 +                       'class' => 'url');
 +        if (!empty($group->fullname)) {
 +            $attrs['title'] = $group->fullname . ' (' . $group->nickname . ')';
 +        }
          $xs = new XMLStringer();
          $xs->elementStart('span', 'vcard');
 -        $xs->elementStart('a', array('href' => $group->permalink(),
 -                                     'class' => 'url'));
 +        $xs->elementStart('a', $attrs);
          $xs->element('span', 'fn nickname', $nickname);
          $xs->elementEnd('a');
          $xs->elementEnd('span');
@@@ -719,46 -719,25 +719,46 @@@ function common_relative_profile($sende
  
  function common_local_url($action, $args=null, $params=null, $fragment=null)
  {
 +    static $sensitive = array('login', 'register', 'passwordsettings',
 +                              'twittersettings', 'finishopenidlogin',
 +                              'finishaddopenid', 'api');
 +
      $r = Router::get();
      $path = $r->build($action, $args, $params, $fragment);
  
 +    $ssl = in_array($action, $sensitive);
 +
      if (common_config('site','fancy')) {
 -        $url = common_path(mb_substr($path, 1));
 +        $url = common_path(mb_substr($path, 1), $ssl);
      } else {
          if (mb_strpos($path, '/index.php') === 0) {
 -            $url = common_path(mb_substr($path, 1));
 +            $url = common_path(mb_substr($path, 1), $ssl);
          } else {
 -            $url = common_path('index.php'.$path);
 +            $url = common_path('index.php'.$path, $ssl);
          }
      }
      return $url;
  }
  
 -function common_path($relative)
 +function common_path($relative, $ssl=false)
  {
      $pathpart = (common_config('site', 'path')) ? common_config('site', 'path')."/" : '';
 -    return "http://".common_config('site', 'server').'/'.$pathpart.$relative;
 +
 +    if (($ssl && (common_config('site', 'ssl') === 'sometimes'))
 +        || common_config('site', 'ssl') === 'always') {
 +        $proto = 'https';
 +        if (is_string(common_config('site', 'sslserver')) &&
 +            mb_strlen(common_config('site', 'sslserver')) > 0) {
 +            $serverpart = common_config('site', 'sslserver');
 +        } else {
 +            $serverpart = common_config('site', 'server');
 +        }
 +    } else {
 +        $proto = 'http';
 +        $serverpart = common_config('site', 'server');
 +    }
 +
 +    return $proto.'://'.$serverpart.'/'.$pathpart.$relative;
  }
  
  function common_date_string($dt)
@@@ -848,7 -827,7 +848,7 @@@ function common_redirect($url, $code=30
                             303 => "See Other",
                             307 => "Temporary Redirect");
  
 -    header("Status: ${code} $status[$code]");
 +    header('HTTP/1.1 '.$code.' '.$status[$code]);
      header("Location: $url");
  
      $xo = new XMLOutputter();
@@@ -950,9 -929,9 +950,9 @@@ function common_profile_url($nickname
  
  // Should make up a reasonable root URL
  
 -function common_root_url()
 +function common_root_url($ssl=false)
  {
 -    return common_path('');
 +    return common_path('', $ssl);
  }
  
  // returns $bytes bytes of random data as a hexadecimal string
@@@ -1321,3 -1300,16 +1321,16 @@@ function common_compatible_license($fro
      // XXX: better compatibility check needed here!
      return ($from == $to);
  }
+ /**
+  * returns a quoted table name, if required according to config
+  */
+ function common_database_tablename($tablename)
+ {
+   
+   if(common_config('db','quote_identifiers')) {
+       $tablename = '"'. $tablename .'"';
+   }
+   //table prefixes could be added here later
+   return $tablename;
+ }