summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/imagefile.php105
-rw-r--r--lib/util.php98
2 files changed, 118 insertions, 85 deletions
diff --git a/lib/imagefile.php b/lib/imagefile.php
new file mode 100644
index 000000000..f15a72c76
--- /dev/null
+++ b/lib/imagefile.php
@@ -0,0 +1,105 @@
+<?php
+/**
+ * Laconica, the distributed open-source microblogging tool
+ *
+ * Abstraction for an image file
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Image
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @author Zach Copley <zach@controlyourself.ca>
+ * @copyright 2008-2009 Control Yourself, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ */
+
+if (!defined('LACONICA')) {
+ exit(1);
+}
+
+/**
+ * A wrapper on uploaded files
+ *
+ * Makes it slightly easier to accept an image file from upload.
+ *
+ * @category Image
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @author Zach Copley <zach@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ */
+
+class ImageFile
+{
+ var $filename = null;
+ var $type = null;
+
+ function __construct($filename=null, $type=null)
+ {
+ $this->filename = $filename;
+ $this->type = $type;
+ }
+
+ static function fromUpload($param='upload')
+ {
+ switch ($_FILES[$param]['error']) {
+ case UPLOAD_ERR_OK: // success, jump out
+ break;
+ case UPLOAD_ERR_INI_SIZE:
+ case UPLOAD_ERR_FORM_SIZE:
+ throw new Exception(_('That file is too big.'));
+ return;
+ case UPLOAD_ERR_PARTIAL:
+ @unlink($_FILES[$param]['tmp_name']);
+ throw new Exception(_('Partial upload.'));
+ return;
+ default:
+ throw new Exception(_('System error uploading file.'));
+ return;
+ }
+
+ $imagefile = new ImageFile($_FILES[$param]['tmp_name']);
+ $info = @getimagesize($imagefile->filename);
+
+ if (!$info) {
+ @unlink($imagefile->filename);
+ throw new Exception(_('Not an image or corrupt file.'));
+ return;
+ }
+
+ switch ($info[2]) {
+ case IMAGETYPE_GIF:
+ case IMAGETYPE_JPEG:
+ case IMAGETYPE_PNG:
+ $imagefile->type = $info[2];
+ break;
+ default:
+ @unlink($imagefile->filename);
+ throw new Exception(_('Unsupported image file format.'));
+ return;
+ }
+
+ return $imagefile;
+ }
+
+ function unlink()
+ {
+ @unlink($this->filename);
+ }
+} \ No newline at end of file
diff --git a/lib/util.php b/lib/util.php
index 61f5d6c16..d30a56c77 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -424,6 +424,7 @@ function common_render_content($text, $notice)
$r = preg_replace('/(^|\s+)@([A-Za-z0-9]{1,64})/e', "'\\1@'.common_at_link($id, '\\2')", $r);
$r = preg_replace('/^T ([A-Z0-9]{1,64}) /e', "'T '.common_at_link($id, '\\1').' '", $r);
$r = preg_replace('/(^|\s+)@#([A-Za-z0-9]{1,64})/e', "'\\1@#'.common_at_hash_link($id, '\\2')", $r);
+ $r = preg_replace('/(^|\s)!([A-Za-z0-9]{1,64})/e', "'\\1!'.common_group_link($id, '\\2')", $r);
return $r;
}
@@ -595,6 +596,17 @@ function common_at_link($sender_id, $nickname)
}
}
+function common_group_link($sender_id, $nickname)
+{
+ $sender = Profile::staticGet($sender_id);
+ $group = User_group::staticGet('nickname', common_canonical_nickname($nickname));
+ if ($group && $sender->isMember($group)) {
+ return '<span class="vcard"><a href="'.htmlspecialchars($group->permalink()).'" class="url"><span class="fn nickname">'.$nickname.'</span></a></span>';
+ } else {
+ return $nickname;
+ }
+}
+
function common_at_hash_link($sender_id, $tag)
{
$user = User::staticGet($sender_id);
@@ -1052,95 +1064,11 @@ function common_redirect($url, $code=307)
$xo->startXML('a',
'-//W3C//DTD XHTML 1.0 Strict//EN',
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd');
- $xo->output('a', array('href' => $url), $url);
+ $xo->element('a', array('href' => $url), $url);
$xo->endXML();
exit;
}
-function common_save_replies($notice)
-{
- // Alternative reply format
- $tname = false;
- if (preg_match('/^T ([A-Z0-9]{1,64}) /', $notice->content, $match)) {
- $tname = $match[1];
- }
- // extract all @messages
- $cnt = preg_match_all('/(?:^|\s)@([a-z0-9]{1,64})/', $notice->content, $match);
-
- $names = array();
-
- if ($cnt || $tname) {
- // XXX: is there another way to make an array copy?
- $names = ($tname) ? array_unique(array_merge(array(strtolower($tname)), $match[1])) : array_unique($match[1]);
- }
-
- $sender = Profile::staticGet($notice->profile_id);
-
- $replied = array();
-
- // store replied only for first @ (what user/notice what the reply directed,
- // we assume first @ is it)
-
- for ($i=0; $i<count($names); $i++) {
- $nickname = $names[$i];
- $recipient = common_relative_profile($sender, $nickname, $notice->created);
- if (!$recipient) {
- continue;
- }
- if ($i == 0 && ($recipient->id != $sender->id) && !$notice->reply_to) { // Don't save reply to self
- $reply_for = $recipient;
- $recipient_notice = $reply_for->getCurrentNotice();
- if ($recipient_notice) {
- $orig = clone($notice);
- $notice->reply_to = $recipient_notice->id;
- $notice->update($orig);
- }
- }
- // Don't save replies from blocked profile to local user
- $recipient_user = User::staticGet('id', $recipient->id);
- if ($recipient_user && $recipient_user->hasBlocked($sender)) {
- continue;
- }
- $reply = new Reply();
- $reply->notice_id = $notice->id;
- $reply->profile_id = $recipient->id;
- $id = $reply->insert();
- if (!$id) {
- $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
- common_log(LOG_ERR, 'DB error inserting reply: ' . $last_error->message);
- common_server_error(sprintf(_('DB error inserting reply: %s'), $last_error->message));
- return;
- } else {
- $replied[$recipient->id] = 1;
- }
- }
-
- // Hash format replies, too
- $cnt = preg_match_all('/(?:^|\s)@#([a-z0-9]{1,64})/', $notice->content, $match);
- if ($cnt) {
- foreach ($match[1] as $tag) {
- $tagged = Profile_tag::getTagged($sender->id, $tag);
- foreach ($tagged as $t) {
- if (!$replied[$t->id]) {
- // Don't save replies from blocked profile to local user
- $t_user = User::staticGet('id', $t->id);
- if ($t_user && $t_user->hasBlocked($sender)) {
- continue;
- }
- $reply = new Reply();
- $reply->notice_id = $notice->id;
- $reply->profile_id = $t->id;
- $id = $reply->insert();
- if (!$id) {
- common_log_db_error($reply, 'INSERT', __FILE__);
- return;
- }
- }
- }
- }
- }
-}
-
function common_broadcast_notice($notice, $remote=false)
{