]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch '0.7.x' of git://gitorious.org/laconica/sgmurphy-clone into sgmurphy...
authorEvan Prodromou <evan@controlyourself.ca>
Thu, 5 Feb 2009 17:04:06 +0000 (12:04 -0500)
committerEvan Prodromou <evan@controlyourself.ca>
Thu, 5 Feb 2009 17:04:06 +0000 (12:04 -0500)
Conflicts:

actions/avatarsettings.php

1  2 
actions/avatarsettings.php
actions/login.php
lib/util.php

index 3029b06211e21c6aa0fb1e2611b1af00f1cc65c9,643c0e567590dc102e05d519074a9ae5d9dbc5d2..68c6ce701d524896cea954b272c3b95c2cc2deaf
@@@ -34,6 -34,8 +34,8 @@@ if (!defined('LACONICA')) 
  
  require_once INSTALLDIR.'/lib/accountsettingsaction.php';
  
+ define('MAX_ORIGINAL', 480);
  /**
   * Upload an avatar
   *
@@@ -286,7 -288,7 +288,7 @@@ class AvatarsettingsAction extends Acco
  
          $filepath = common_avatar_path($filename);
  
-         move_uploaded_file($imagefile->filename, $filepath);
+         move_uploaded_file($imagefile->filepath, $filepath);
  
          $filedata = array('filename' => $filename,
                            'filepath' => $filepath,
  
      function cropAvatar()
      {
-         $user = common_current_user();
-         $profile = $user->getProfile();
          $filedata = $_SESSION['FILEDATA'];
  
          if (!$filedata) {
              $this->serverError(_('Lost our file data.'));
              return;
          }
 -        
 +
-         $x = $this->arg('avatar_crop_x');
-         $y = $this->arg('avatar_crop_y');
-         $w = ($this->arg('avatar_crop_w')) ? $this->arg('avatar_crop_w') : $filedata['width'];
-         $h = ($this->arg('avatar_crop_h')) ? $this->arg('avatar_crop_h') : $filedata['height'];
-         $filepath = common_avatar_path($filedata['filename']);
-         if (!file_exists($filepath)) {
-             $this->serverError(_('Lost our file.'));
-             return;
-         }
-         switch ($filedata['type']) {
-         case IMAGETYPE_GIF:
-             $image_src = imagecreatefromgif($filepath);
-             break;
-         case IMAGETYPE_JPEG:
-             $image_src = imagecreatefromjpeg($filepath);
-             break;
-         case IMAGETYPE_PNG:
-             $image_src = imagecreatefrompng($filepath);
-             break;
-          default:
-             $this->serverError(_('Unknown file type'));
-             return;
-         }
-         common_debug("W = $w, H = $h, X = $x, Y = $y");
-         $image_dest = imagecreatetruecolor($w, $h);
-         $background = imagecolorallocate($image_dest, 0, 0, 0);
-         ImageColorTransparent($image_dest, $background);
-         imagealphablending($image_dest, false);
-         imagecopyresized($image_dest, $image_src, 0, 0, $x, $y, $w, $h, $w, $h);
-         $cur = common_current_user();
-         $filename = common_avatar_filename($cur->id,
-                                            image_type_to_extension($filedata['type']),
-                                            null,
-                                            common_timestamp());
-         $filepath = common_avatar_path($filename);
-         switch ($filedata['type']) {
-         case IMAGETYPE_GIF:
-             imagegif($image_dest, $filepath);
-             break;
-         case IMAGETYPE_JPEG:
-             imagejpeg($image_dest, $filepath);
-             break;
-         case IMAGETYPE_PNG:
-             imagepng($image_dest, $filepath);
-             break;
-          default:
-             $this->serverError(_('Unknown file type'));
-             return;
-         }
+         // If image is not being cropped assume pos & dimentions of original
+         $dest_x = $this->arg('avatar_crop_x') ? $this->arg('avatar_crop_x'):0;
+         $dest_y = $this->arg('avatar_crop_y') ? $this->arg('avatar_crop_y'):0;
+         $dest_w = $this->arg('avatar_crop_w') ? $this->arg('avatar_crop_w'):$filedata['width'];
+         $dest_h = $this->arg('avatar_crop_h') ? $this->arg('avatar_crop_h'):$filedata['height'];
+         $size = min($dest_w, $dest_h);
+         $size = ($size > MAX_ORIGINAL) ? MAX_ORIGINAL:$size;
 -        
 +
          $user = common_current_user();
 -        
+         $profile = $user->getProfile();
-         $profile = $cur->getProfile();
 +
+         $imagefile = new ImageFile($user->id, $filedata['filepath']);
+         $filename = $imagefile->resize($size, $dest_x, $dest_y, $dest_w, $dest_h);
  
-         if ($profile->setOriginal($filepath)) {
-             @unlink(common_avatar_path($filedata['filename']));
+         if ($profile->setOriginal($filename)) {
+             @unlink($filedata['filepath']);
              unset($_SESSION['FILEDATA']);
              $this->mode = 'upload';
              $this->showForm(_('Avatar updated.'), true);
diff --combined actions/login.php
index 98cc8a855fbd65102f6cce5416b7a3a07acc1709,7a3c6d3748435780c93e466008ad4c0fb8b401d6..71e4679292c79102dd97f80f6683a655dfef5535
@@@ -78,6 -78,7 +78,7 @@@ class LoginAction extends Actio
          } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
              $this->checkLogin();
          } else {
+             common_ensure_session();
              $this->showForm();
          }
      }
@@@ -96,7 -97,7 +97,7 @@@
      {
          // XXX: login throttle
  
 -        // CSRF protection - token set in common_notice_form()
 +        // CSRF protection - token set in NoticeForm
          $token = $this->trimmed('token');
          if (!$token || $token != common_session_token()) {
              $this->clientError(_('There was a problem with your session token. '.
  
          $nickname = common_canonical_nickname($this->trimmed('nickname'));
          $password = $this->arg('password');
 -        if (common_check_user($nickname, $password)) {
 -            // success!
 -            if (!common_set_user($nickname)) {
 -                $this->serverError(_('Error setting user.'));
 -                return;
 -            }
 -            common_real_login(true);
 -            if ($this->boolean('rememberme')) {
 -                common_debug('Adding rememberme cookie for ' . $nickname);
 -                common_rememberme();
 -            }
 -            // success!
 -            $url = common_get_returnto();
 -            if ($url) {
 -                // We don't have to return to it again
 -                common_set_returnto(null);
 -            } else {
 -                $url = common_local_url('all',
 -                                        array('nickname' =>
 -                                              $nickname));
 -            }
 -            common_redirect($url);
 -        } else {
 +
 +        if (!common_check_user($nickname, $password)) {
              $this->showForm(_('Incorrect username or password.'));
              return;
          }
  
          // success!
 -        if (!common_set_user($user)) {
 +        if (!common_set_user($nickname)) {
              $this->serverError(_('Error setting user.'));
              return;
          }
          common_real_login(true);
  
          if ($this->boolean('rememberme')) {
 -            common_debug('Adding rememberme cookie for ' . $nickname);
              common_rememberme($user);
          }
 -        // success!
 +
          $url = common_get_returnto();
 +
          if ($url) {
              // We don't have to return to it again
              common_set_returnto(null);
                                      array('nickname' =>
                                            $nickname));
          }
 +
          common_redirect($url);
      }
  
diff --combined lib/util.php
index 8f93a83191eaf3fcdff6577e51aeeae0bf0d987e,87c239d5d9ceac16493c488491f893788ec2e943..579f964acab34ac7c248dddb607a377c2e109ad7
@@@ -386,46 -386,85 +386,85 @@@ function common_render_text($text
      $r = htmlspecialchars($text);
  
      $r = preg_replace('/[\x{0}-\x{8}\x{b}-\x{c}\x{e}-\x{19}]/', '', $r);
-     $r = preg_replace_callback('@(ftp|http|https|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|xmpp|irc)://[^\]>\s]+@', 'common_render_uri_thingy', $r);
-     $r = preg_replace_callback('@(mailto|aim|tel):[^\]>\s]+@', 'common_render_uri_thingy', $r); // Pseudo-protocols don't require '//' after ':'.
-     $r = preg_replace('/(^|\s+)#([A-Za-z0-9_\-\.]{1,64})/e', "'\\1#'.common_tag_link('\\2')", $r);
+     $r = common_replace_urls_callback($r, 'common_linkify');
+     $r = preg_replace('/(^|\(|\[|\s+)#([A-Za-z0-9_\-\.]{1,64})/e', "'\\1#'.common_tag_link('\\2')", $r);
      // XXX: machine tags
      return $r;
  }
  
- function common_render_uri_thingy($matches)
- {
-     $uri = $matches[0];
-     $trailer = '';
-     // Some heuristics for extracting URIs from surrounding punctuation
-     // Strip from trailing text...
-     if (preg_match('/^(.*)([,.:"\']+)$/', $uri, $matches)) {
-         $uri = $matches[1];
-         $trailer = $matches[2];
-     }
+ function common_replace_urls_callback($text, $callback) {
+     // Start off with a regex
+         preg_match_all('#(?:(?:(?:https?|ftps?|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|xmpp|irc)://|(?:mailto|aim|tel):)[^.\s]+\.[^\s]+|(?:[^.\s/]+\.)+(?:museum|travel|[a-z]{2,4})(?:[:/][^\s]*)?)#i', $text, $matches);
+     
+     // Then clean up what the regex left behind
+     $offset = 0;
+     foreach($matches[0] as $url) {
+         $url = htmlspecialchars_decode($url);
+         
+         // Make sure we didn't pick up an email address
+         if (preg_match('#^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$#i', $url)) continue;
+         
+         // Remove trailing punctuation
+         $url = rtrim($url, '.?!,;:\'"`');
+         // Remove surrounding parens and the like
+         preg_match('/[)\]>]+$/', $url, $trailing);
+         if (isset($trailing[0])) {
+             preg_match_all('/[(\[<]/', $url, $opened);
+             preg_match_all('/[)\]>]/', $url, $closed);
+             $unopened = count($closed[0]) - count($opened[0]);
+             // Make sure not to take off more closing parens than there are at the end
+             $unopened = ($unopened > mb_strlen($trailing[0])) ? mb_strlen($trailing[0]):$unopened;
+             $url = ($unopened > 0) ? mb_substr($url, 0, $unopened * -1):$url;
+         }
  
-     $pairs = array(
-                    ']' => '[', // technically disallowed in URIs, but used in Java docs
-                    ')' => '(', // far too frequent in Wikipedia and MSDN
-                    );
-     $final = substr($uri, -1, 1);
-     if (isset($pairs[$final])) {
-         $openers = substr_count($uri, $pairs[$final]);
-         $closers = substr_count($uri, $final);
-         if ($closers > $openers) {
-             // Assume the paren was opened outside the URI
-             $uri = substr($uri, 0, -1);
-             $trailer = $final . $trailer;
+         // Remove trailing punctuation again (in case there were some inside parens)
+         $url = rtrim($url, '.?!,;:\'"`');
+         
+         // Make sure we didn't capture part of the next sentence
+         preg_match('#((?:[^.\s/]+\.)+)(museum|travel|[a-z]{2,4})#i', $url, $url_parts);
+         
+         // Were the parts capitalized any?
+         $last_part = (mb_strtolower($url_parts[2]) !== $url_parts[2]) ? true:false;
+         $prev_part = (mb_strtolower($url_parts[1]) !== $url_parts[1]) ? true:false;
+         
+         // If the first part wasn't cap'd but the last part was, we captured too much
+         if ((!$prev_part && $last_part)) {
+             $url = substr_replace($url, '', mb_strpos($url, '.'.$url_parts[2], 0));
          }
+         
+         // Capture the new TLD
+         preg_match('#((?:[^.\s/]+\.)+)(museum|travel|[a-z]{2,4})#i', $url, $url_parts);
+         
+         $tlds = array('ac', 'ad', 'ae', 'aero', 'af', 'ag', 'ai', 'al', 'am', 'an', 'ao', 'aq', 'ar', 'arpa', 'as', 'asia', 'at', 'au', 'aw', 'ax', 'az', 'ba', 'bb', 'bd', 'be', 'bf', 'bg', 'bh', 'bi', 'biz', 'bj', 'bm', 'bn', 'bo', 'br', 'bs', 'bt', 'bv', 'bw', 'by', 'bz', 'ca', 'cat', 'cc', 'cd', 'cf', 'cg', 'ch', 'ci', 'ck', 'cl', 'cm', 'cn', 'co', 'com', 'coop', 'cr', 'cu', 'cv', 'cx', 'cy', 'cz', 'de', 'dj', 'dk', 'dm', 'do', 'dz', 'ec', 'edu', 'ee', 'eg', 'er', 'es', 'et', 'eu', 'fi', 'fj', 'fk', 'fm', 'fo', 'fr', 'ga', 'gb', 'gd', 'ge', 'gf', 'gg', 'gh', 'gi', 'gl', 'gm', 'gn', 'gov', 'gp', 'gq', 'gr', 'gs', 'gt', 'gu', 'gw', 'gy', 'hk', 'hm', 'hn', 'hr', 'ht', 'hu', 'id', 'ie', 'il', 'im', 'in', 'info', 'int', 'io', 'iq', 'ir', 'is', 'it', 'je', 'jm', 'jo', 'jobs', 'jp', 'ke', 'kg', 'kh', 'ki', 'km', 'kn', 'kp', 'kr', 'kw', 'ky', 'kz', 'la', 'lb', 'lc', 'li', 'lk', 'lr', 'ls', 'lt', 'lu', 'lv', 'ly', 'ma', 'mc', 'md', 'me', 'mg', 'mh', 'mil', 'mk', 'ml', 'mm', 'mn', 'mo', 'mobi', 'mp', 'mq', 'mr', 'ms', 'mt', 'mu', 'museum', 'mv', 'mw', 'mx', 'my', 'mz', 'na', 'name', 'nc', 'ne', 'net', 'nf', 'ng', 'ni', 'nl', 'no', 'np', 'nr', 'nu', 'nz', 'om', 'org', 'pa', 'pe', 'pf', 'pg', 'ph', 'pk', 'pl', 'pm', 'pn', 'pr', 'pro', 'ps', 'pt', 'pw', 'py', 'qa', 're', 'ro', 'rs', 'ru', 'rw', 'sa', 'sb', 'sc', 'sd', 'se', 'sg', 'sh', 'si', 'sj', 'sk', 'sl', 'sm', 'sn', 'so', 'sr', 'st', 'su', 'sv', 'sy', 'sz', 'tc', 'td', 'tel', 'tf', 'tg', 'th', 'tj', 'tk', 'tl', 'tm', 'tn', 'to', 'tp', 'tr', 'travel', 'tt', 'tv', 'tw', 'tz', 'ua', 'ug', 'uk', 'us', 'uy', 'uz', 'va', 'vc', 've', 'vg', 'vi', 'vn', 'vu', 'wf', 'ws', 'ye', 'yt', 'yu', 'za', 'zm', 'zw');
+         if (!in_array($url_parts[2], $tlds)) continue;
+         
+         // Call user specified func
+         $modified_url = $callback($url);
+         
+         // Replace it!
+         $start = mb_strpos($text, $url, $offset);
+         $text = substr_replace($text, $modified_url, $start, mb_strlen($url));
+         $offset = $start + mb_strlen($modified_url);
      }
-     if ($longurl = common_longurl($uri)) {
+     
+     return $text;
+ }
+ function common_linkify($url) {
+     $display = $url;
+     $url = (!preg_match('#^([a-z]+://|(mailto|aim|tel):)#i', $url)) ? 'http://'.$url:$url;
+     
+     if ($longurl = common_longurl($url)) {
          $longurl = htmlentities($longurl, ENT_QUOTES, 'UTF-8');
-         $title = " title='$longurl'";
+         $title = "title=\"$longurl\"";
      }
      else $title = '';
-     return '<a href="' . $uri . '"' . $title . ' class="extlink">' . $uri . '</a>' . $trailer;
+     
+     return "<a href=\"$url\" $title class=\"extlink\">$display</a>";
  }
  
  function common_longurl($short_url)
@@@ -449,7 -488,7 +488,7 @@@ function common_shorten_links($text
      static $cache = array();
      if (isset($cache[$text])) return $cache[$text];
      // \s = not a horizontal whitespace character (since PHP 5.2.4)
-     return $cache[$text] = preg_replace('@https?://[^)\]>\s]+@e', "common_shorten_link('\\0')", $text);
+     return $cache[$text] = common_replace_urls_callback($text, 'common_shorten_link');;
  }
  
  function common_shorten_link($url, $reverse = false)
@@@ -898,7 -937,7 +937,7 @@@ function common_fancy_url($action, $arg
       case 'grouprss':
          return common_path('group/'.$args['nickname'].'/rss');
       case 'groupmembers':
 -        return common_path('group/'.$args['nickname'].'/members');
 +        return common_path('group/'.$args['nickname'].'/members' . (($args['page']) ? ('?page=' . $args['page']) : ''));
       case 'grouplogo':
          return common_path('group/'.$args['nickname'].'/logo');
       case 'usergroups':