From 7f81597a8146e0fa5f062cf42a30c86914877ec5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 13 Apr 2009 15:49:26 -0400 Subject: isReadOnly() now takes arguments Add an array of arguments to isReadOnly() method of actions, to let them change their results depending on what actions are called. Primarily used by the 'api' action. Ideally in the future that will be multiple actions. But this might still be useful. --- lib/action.php | 5 ++++- lib/error.php | 2 +- lib/galleryaction.php | 2 +- lib/peoplesearchresults.php | 2 +- lib/personal.php | 2 +- lib/searchaction.php | 2 +- 6 files changed, 9 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/action.php b/lib/action.php index cc98d4445..673549246 100644 --- a/lib/action.php +++ b/lib/action.php @@ -791,9 +791,12 @@ class Action extends HTMLOutputter // lawsuit * * MAY override * + * @param array $args other arguments + * * @return boolean is read only action? */ - function isReadOnly() + + function isReadOnly($args)($args) { return false; } diff --git a/lib/error.php b/lib/error.php index 526d9f81b..282682133 100644 --- a/lib/error.php +++ b/lib/error.php @@ -93,7 +93,7 @@ class ErrorAction extends Action return $this->message; } - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/lib/galleryaction.php b/lib/galleryaction.php index 8e21d7393..0484918ce 100644 --- a/lib/galleryaction.php +++ b/lib/galleryaction.php @@ -76,7 +76,7 @@ class GalleryAction extends Action return true; } - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/lib/peoplesearchresults.php b/lib/peoplesearchresults.php index f8ab7cf3b..d3f840852 100644 --- a/lib/peoplesearchresults.php +++ b/lib/peoplesearchresults.php @@ -67,7 +67,7 @@ class PeopleSearchResults extends ProfileList return preg_replace($this->pattern, '\\1', htmlspecialchars($text)); } - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/lib/personal.php b/lib/personal.php index e46350c63..f92732375 100644 --- a/lib/personal.php +++ b/lib/personal.php @@ -47,7 +47,7 @@ class PersonalAction extends Action var $user = null; - function isReadOnly() + function isReadOnly($args) { return true; } diff --git a/lib/searchaction.php b/lib/searchaction.php index e7ad4affd..e74450e11 100644 --- a/lib/searchaction.php +++ b/lib/searchaction.php @@ -51,7 +51,7 @@ class SearchAction extends Action * * @return boolean true */ - function isReadOnly() + function isReadOnly($args) { return true; } -- cgit v1.2.3-54-g00ecf From 1bae34e24fe87ed1abcd5c27e183e8a826fbf775 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 13 Apr 2009 15:54:16 -0400 Subject: typo in lib action --- lib/action.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/action.php b/lib/action.php index 673549246..1ba062812 100644 --- a/lib/action.php +++ b/lib/action.php @@ -796,7 +796,7 @@ class Action extends HTMLOutputter // lawsuit * @return boolean is read only action? */ - function isReadOnly($args)($args) + function isReadOnly($args) { return false; } -- cgit v1.2.3-54-g00ecf From cd9a24798001cfa5e6ecfbfbccc5c0ce07726846 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 13 Apr 2009 15:03:34 -0700 Subject: Fix bad dates in API's JSON search results --- lib/jsonsearchresultslist.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/jsonsearchresultslist.php b/lib/jsonsearchresultslist.php index 0cdcf0c51..f786c20a8 100644 --- a/lib/jsonsearchresultslist.php +++ b/lib/jsonsearchresultslist.php @@ -232,7 +232,7 @@ class ResultItem $this->profile_image_url = ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE); - $this->created_at = date('r', $this->notice->created); + $this->created_at = common_date_rfc2822($this->notice->created); } /** -- cgit v1.2.3-54-g00ecf From ff7d71181038ba1e97e9bbcaa7901638aa715574 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 15 Apr 2009 10:05:16 -0400 Subject: add user id to statistics --- lib/profileaction.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib') diff --git a/lib/profileaction.php b/lib/profileaction.php index c81924e31..1f2e30994 100644 --- a/lib/profileaction.php +++ b/lib/profileaction.php @@ -179,6 +179,11 @@ class ProfileAction extends Action $this->element('h2', null, _('Statistics')); // Other stats...? + $this->elementStart('dl', 'entity_user-id'); + $this->element('dt', null, _('User ID')); + $this->element('dd', null, $this->profile->id); + $this->elementEnd('dl'); + $this->elementStart('dl', 'entity_member-since'); $this->element('dt', null, _('Member since')); $this->element('dd', null, date('j M Y', -- cgit v1.2.3-54-g00ecf From c4040303cecc48aed66d0102de6b9f5ffdc64b22 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 16 Apr 2009 10:18:16 -0400 Subject: initial snapshot stuff --- lib/common.php | 3 ++ lib/snapshot.php | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 lib/snapshot.php (limited to 'lib') diff --git a/lib/common.php b/lib/common.php index dd2570e75..f81c3dc76 100644 --- a/lib/common.php +++ b/lib/common.php @@ -157,6 +157,9 @@ $config = 'newuser' => array('subscribe' => null, 'welcome' => null), + 'snapshot' => + array('run' => 'web', + 'frequency' => 10000), ); $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options'); diff --git a/lib/snapshot.php b/lib/snapshot.php new file mode 100644 index 000000000..4f9bb3f62 --- /dev/null +++ b/lib/snapshot.php @@ -0,0 +1,101 @@ +. + * + * @category Stats + * @package Laconica + * @author Evan Prodromou + * @copyright 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 snapshot of site stats that can report itself to headquarters + * + * This class will collect statistics on the site and report them to + * a statistics server of the admin's choice. (Default is the big one + * at laconi.ca.) + * + * It can either be called from a cron job, or run occasionally by the + * Web site. + * + * @category Stats + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + */ + +class Snapshot { + + function __construct() + { + } + + function take() + { + } + + function report() + { + } + + static function check() + { + switch (common_config('snapshot', 'run')) { + case 'web': + // skip if we're not running on the Web. + if (!isset($_SERVER) || !array_key_exists('REQUEST_METHOD', $_SERVER)) { + break; + } + // Run once every frequency hits + // XXX: do frequency by time (once a week, etc.) rather than + // hits + if (rand() % common_config('snapshot', 'frequency') == 0) { + $snapshot = new Snapshot(); + if ($snapshot->take()) { + $snapshot->report(); + } + } + break; + case 'cron': + // skip if we're running on the Web + if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { + break; + } + // We're running from the command line; assume + $snapshot = new Snapshot(); + if ($snapshot->take()) { + $snapshot->report(); + } + break; + case 'never': + break; + default: + common_log(LOG_WARNING, "Unrecognized value for snapshot run config."); + } + } +} -- cgit v1.2.3-54-g00ecf From 5128448c777e74c0e294c21ce80711c04395d6d4 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 16 Apr 2009 12:41:30 -0400 Subject: code complete on snapshot.php --- lib/snapshot.php | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 80 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/snapshot.php b/lib/snapshot.php index 4f9bb3f62..338c8d559 100644 --- a/lib/snapshot.php +++ b/lib/snapshot.php @@ -51,15 +51,9 @@ if (!defined('LACONICA')) { class Snapshot { - function __construct() - { - } + var $stats = null; - function take() - { - } - - function report() + function __construct() { } @@ -98,4 +92,82 @@ class Snapshot { common_log(LOG_WARNING, "Unrecognized value for snapshot run config."); } } + + function take() + { + $this->stats = array(); + + // Some basic identification stuff + + $this->stats['version'] = LACONICA_VERSION; + $this->stats['phpversion'] = phpversion(); + $this->stats['name'] = common_config('site', 'name'); + $this->stats['root'] = common_root_url(); + + // non-identifying stats on various tables. Primary + // interest is size and rate of activity of service. + + $tables = array('user', + 'notice', + 'subscription', + 'remote_profile', + 'user_group'); + + foreach ($tables as $table) { + $this->tableStats($table); + } + + // stats on some important config options + + $this->stats['theme'] = common_config('site', 'theme'); + $this->stats['dbtype'] = common_config('db', 'type'); + $this->stats['xmpp'] = common_config('xmpp', 'enabled'); + $this->stats['inboxes'] = common_config('inboxes', 'enabled'); + $this->stats['queue'] = common_config('queue', 'enabled'); + $this->stats['license'] = common_config('license', 'url'); + $this->stats['fancy'] = common_config('site', 'fancy'); + $this->stats['private'] = common_config('site', 'private'); + $this->stats['closed'] = common_config('site', 'closed'); + $this->stats['memcached'] = common_config('memcached', 'enabled'); + $this->stats['language'] = common_config('site', 'language'); + $this->stats['timezone'] = common_config('site', 'timezone'); + } + + function report() + { + // XXX: Use OICU2 and OAuth to make authorized requests + + $postdata = http_build_query($this->stats); + + $opts = array('http' => + array( + 'method' => 'POST', + 'header' => 'Content-type: application/x-www-form-urlencoded', + 'content' => $postdata, + 'user_agent' => 'Laconica/'.LACONICA_VERSION + ) + ); + + $context = stream_context_create($opts); + + $reporturl = common_config('snapshot', 'reporturl'); + + $result = file_get_contents($reporturl, false, $context); + } + + function tableStats($table) + { + $inst = DB_DataObject::Factory($table); + $res = $inst->query('SELECT count(*) as cnt, '. + 'min(created) as first, '. + 'max(created) as last '. + 'from ' . $table); + if ($res) { + $this->stats[$table.'count'] = $inst->cnt; + $this->stats[$table.'first'] = $inst->first; + $this->stats[$table.'last'] = $inst->last; + } + $inst->free(); + unset($inst); + } } -- cgit v1.2.3-54-g00ecf From 415abdfdef64608d6c4ba081dd21575e1920770b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 16 Apr 2009 12:50:13 -0400 Subject: config options for snapshots --- lib/common.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/common.php b/lib/common.php index f81c3dc76..05539af83 100644 --- a/lib/common.php +++ b/lib/common.php @@ -159,7 +159,8 @@ $config = 'welcome' => null), 'snapshot' => array('run' => 'web', - 'frequency' => 10000), + 'frequency' => 10000, + 'reporturl' => 'http://laconi.ca/stats/report'), ); $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options'); -- cgit v1.2.3-54-g00ecf From 6a247acb45198c3748df48d8b14b71c8f8b839de Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 16 Apr 2009 12:50:29 -0400 Subject: Do some phpcs reformatting for snapshot --- lib/snapshot.php | 107 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 78 insertions(+), 29 deletions(-) (limited to 'lib') diff --git a/lib/snapshot.php b/lib/snapshot.php index 338c8d559..a014d3435 100644 --- a/lib/snapshot.php +++ b/lib/snapshot.php @@ -49,18 +49,32 @@ if (!defined('LACONICA')) { * */ -class Snapshot { - +class Snapshot +{ var $stats = null; + /** + * Constructor for a snapshot + */ + function __construct() { } + /** + * Static function for reporting statistics + * + * This function checks whether it should report statistics, based on + * the current configuation settings. If it should, it creates a new + * Snapshot object, takes a snapshot, and reports it to headquarters. + * + * @return void + */ + static function check() { switch (common_config('snapshot', 'run')) { - case 'web': + case 'web': // skip if we're not running on the Web. if (!isset($_SERVER) || !array_key_exists('REQUEST_METHOD', $_SERVER)) { break; @@ -75,7 +89,7 @@ class Snapshot { } } break; - case 'cron': + case 'cron': // skip if we're running on the Web if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { break; @@ -86,23 +100,33 @@ class Snapshot { $snapshot->report(); } break; - case 'never': + case 'never': break; - default: + default: common_log(LOG_WARNING, "Unrecognized value for snapshot run config."); } } + /** + * Take a snapshot of the server + * + * Builds an array of statistical and configuration data based + * on the local database and config files. We avoid grabbing any + * information that could be personal or private. + * + * @return void + */ + function take() { $this->stats = array(); // Some basic identification stuff - $this->stats['version'] = LACONICA_VERSION; + $this->stats['version'] = LACONICA_VERSION; $this->stats['phpversion'] = phpversion(); - $this->stats['name'] = common_config('site', 'name'); - $this->stats['root'] = common_root_url(); + $this->stats['name'] = common_config('site', 'name'); + $this->stats['root'] = common_root_url(); // non-identifying stats on various tables. Primary // interest is size and rate of activity of service. @@ -119,34 +143,44 @@ class Snapshot { // stats on some important config options - $this->stats['theme'] = common_config('site', 'theme'); - $this->stats['dbtype'] = common_config('db', 'type'); - $this->stats['xmpp'] = common_config('xmpp', 'enabled'); - $this->stats['inboxes'] = common_config('inboxes', 'enabled'); - $this->stats['queue'] = common_config('queue', 'enabled'); - $this->stats['license'] = common_config('license', 'url'); - $this->stats['fancy'] = common_config('site', 'fancy'); - $this->stats['private'] = common_config('site', 'private'); - $this->stats['closed'] = common_config('site', 'closed'); + $this->stats['theme'] = common_config('site', 'theme'); + $this->stats['dbtype'] = common_config('db', 'type'); + $this->stats['xmpp'] = common_config('xmpp', 'enabled'); + $this->stats['inboxes'] = common_config('inboxes', 'enabled'); + $this->stats['queue'] = common_config('queue', 'enabled'); + $this->stats['license'] = common_config('license', 'url'); + $this->stats['fancy'] = common_config('site', 'fancy'); + $this->stats['private'] = common_config('site', 'private'); + $this->stats['closed'] = common_config('site', 'closed'); $this->stats['memcached'] = common_config('memcached', 'enabled'); - $this->stats['language'] = common_config('site', 'language'); - $this->stats['timezone'] = common_config('site', 'timezone'); + $this->stats['language'] = common_config('site', 'language'); + $this->stats['timezone'] = common_config('site', 'timezone'); } + /** + * Reports statistics to headquarters + * + * Posts statistics to a reporting server. + * + * @return void + */ + function report() { // XXX: Use OICU2 and OAuth to make authorized requests $postdata = http_build_query($this->stats); - $opts = array('http' => - array( - 'method' => 'POST', - 'header' => 'Content-type: application/x-www-form-urlencoded', - 'content' => $postdata, - 'user_agent' => 'Laconica/'.LACONICA_VERSION - ) - ); + $opts = + array('http' => + array( + 'method' => 'POST', + 'header' => 'Content-type: '. + 'application/x-www-form-urlencoded', + 'content' => $postdata, + 'user_agent' => 'Laconica/'.LACONICA_VERSION + ) + ); $context = stream_context_create($opts); @@ -155,18 +189,33 @@ class Snapshot { $result = file_get_contents($reporturl, false, $context); } + /** + * Updates statistics for a single table + * + * Determines the size of a table and its oldest and newest rows. + * Goal here is to see how active a site is. Note that it + * fills up the instance stats variable. + * + * @param string $table name of table to check + * + * @return void + */ + function tableStats($table) { $inst = DB_DataObject::Factory($table); + $res = $inst->query('SELECT count(*) as cnt, '. 'min(created) as first, '. 'max(created) as last '. 'from ' . $table); + if ($res) { $this->stats[$table.'count'] = $inst->cnt; $this->stats[$table.'first'] = $inst->first; - $this->stats[$table.'last'] = $inst->last; + $this->stats[$table.'last'] = $inst->last; } + $inst->free(); unset($inst); } -- cgit v1.2.3-54-g00ecf From 0838143d5855bb013b355d4abb7ec7a643ef37dc Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 16 Apr 2009 12:53:17 -0400 Subject: allow snapshots to be disabled easily --- lib/common.php | 3 ++- lib/snapshot.php | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/common.php b/lib/common.php index 05539af83..2c60b0442 100644 --- a/lib/common.php +++ b/lib/common.php @@ -158,7 +158,8 @@ $config = array('subscribe' => null, 'welcome' => null), 'snapshot' => - array('run' => 'web', + array('enabled' => true, + 'run' => 'web', 'frequency' => 10000, 'reporturl' => 'http://laconi.ca/stats/report'), ); diff --git a/lib/snapshot.php b/lib/snapshot.php index a014d3435..75850a301 100644 --- a/lib/snapshot.php +++ b/lib/snapshot.php @@ -73,6 +73,10 @@ class Snapshot static function check() { + if (!common_config('snapshot', 'enabled')) { + return; + } + switch (common_config('snapshot', 'run')) { case 'web': // skip if we're not running on the Web. -- cgit v1.2.3-54-g00ecf From 546ab05dba507b67f40eff9aa17f684e2f9f244b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 16 Apr 2009 12:57:57 -0400 Subject: update version string for dev version --- lib/common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/common.php b/lib/common.php index dd2570e75..3f8123c51 100644 --- a/lib/common.php +++ b/lib/common.php @@ -19,7 +19,7 @@ if (!defined('LACONICA')) { exit(1); } -define('LACONICA_VERSION', '0.7.3'); +define('LACONICA_VERSION', '0.8.0dev'); define('AVATAR_PROFILE_SIZE', 96); define('AVATAR_STREAM_SIZE', 48); -- cgit v1.2.3-54-g00ecf From d76bb2fd115f120d799335069d6bc59203650d55 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 16 Apr 2009 13:05:35 -0400 Subject: Revert "allow snapshots to be disabled easily" This reverts commit 0838143d5855bb013b355d4abb7ec7a643ef37dc. Already handled with the 'never' option. --- lib/common.php | 3 +-- lib/snapshot.php | 4 ---- 2 files changed, 1 insertion(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/common.php b/lib/common.php index 37744ebd4..e64ca34da 100644 --- a/lib/common.php +++ b/lib/common.php @@ -158,8 +158,7 @@ $config = array('subscribe' => null, 'welcome' => null), 'snapshot' => - array('enabled' => true, - 'run' => 'web', + array('run' => 'web', 'frequency' => 10000, 'reporturl' => 'http://laconi.ca/stats/report'), ); diff --git a/lib/snapshot.php b/lib/snapshot.php index 75850a301..a014d3435 100644 --- a/lib/snapshot.php +++ b/lib/snapshot.php @@ -73,10 +73,6 @@ class Snapshot static function check() { - if (!common_config('snapshot', 'enabled')) { - return; - } - switch (common_config('snapshot', 'run')) { case 'web': // skip if we're not running on the Web. -- cgit v1.2.3-54-g00ecf From 9f23807af4495889a96713c798c0007d5bd6cba7 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 22 May 2009 02:47:34 +0000 Subject: Removed inline styles from notice list items --- lib/noticelist.php | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) (limited to 'lib') diff --git a/lib/noticelist.php b/lib/noticelist.php index 004905056..a52132171 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -180,25 +180,14 @@ class NoticeListItem extends Widget $this->showStart(); $this->showNotice(); $this->showNoticeAttachments(); - $this->showNoticeOptions(); $this->showNoticeInfo(); + $this->showNoticeOptions(); $this->showEnd(); } function showNotice() { -if(0) - $this->out->elementStart('entry-title'); -else - - if ('shownotice' === $this->out->args['action']) { - $width = '85%'; - } else { - $width = '90%'; - } - - - $this->out->elementStart('div', array('class' => 'entry-title', 'style' => "float: left; width: $width;")); + $this->out->elementStart('div', 'entry-title'); $this->showAuthor(); $this->showContent(); $this->out->elementEnd('div'); @@ -248,17 +237,7 @@ else function showNoticeInfo() { -if(0) $this->out->elementStart('div', 'entry-content'); -else - - if ('shownotice' === $this->out->args['action']) { - $width = '85%'; - } else { - $width = '90%'; - } - - $this->out->elementStart('div', array('class' => 'entry-content', 'style' => "float: left; width: $width;")); $this->showNoticeLink(); $this->showNoticeSource(); $this->showContext(); @@ -269,10 +248,7 @@ else { $user = common_current_user(); if ($user) { -if(0) $this->out->elementStart('div', 'notice-options'); -else - $this->out->elementStart('div', array('class' => 'notice-options', 'style' => 'float: right; width: 16%;')); $this->showFaveForm(); $this->showReplyLink(); $this->showDeleteLink(); -- cgit v1.2.3-54-g00ecf From b5ac6e31f2f148164860aeabec6899b75d7292ec Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Sun, 24 May 2009 04:43:34 -0400 Subject: Rearranged attachment info to only appear on each applicable notice page and thru an ajax popup. --- actions/attachment.php | 10 ++++----- actions/attachment_ajax.php | 24 +------------------- actions/attachments.php | 2 -- actions/tag.php | 4 ++-- js/util.js | 7 +++--- lib/attachmentlist.php | 6 +---- lib/noticelist.php | 55 +++++++++++++++++++++------------------------ lib/router.php | 15 ++++++++++--- theme/base/css/display.css | 20 ++++++++++++++++- 9 files changed, 68 insertions(+), 75 deletions(-) (limited to 'lib') diff --git a/actions/attachment.php b/actions/attachment.php index b9187ff08..c51c75120 100644 --- a/actions/attachment.php +++ b/actions/attachment.php @@ -31,8 +31,6 @@ if (!defined('LACONICA')) { exit(1); } -//require_once INSTALLDIR.'/lib/personalgroupnav.php'; -//require_once INSTALLDIR.'/lib/feedlist.php'; require_once INSTALLDIR.'/lib/attachmentlist.php'; /** @@ -67,11 +65,11 @@ class AttachmentAction extends Action { parent::prepare($args); - $id = $this->arg('attachment'); - - $this->attachment = File::staticGet($id); + if ($id = $this->trimmed('attachment')) { + $this->attachment = File::staticGet($id); + } - if (!$this->attachment) { + if (empty($this->attachment)) { $this->clientError(_('No such attachment.'), 404); return false; } diff --git a/actions/attachment_ajax.php b/actions/attachment_ajax.php index 1620b27dd..6930dc112 100644 --- a/actions/attachment_ajax.php +++ b/actions/attachment_ajax.php @@ -45,26 +45,6 @@ require_once INSTALLDIR.'/actions/attachment.php'; class Attachment_ajaxAction extends AttachmentAction { - /** - * Load attributes based on database arguments - * - * Loads all the DB stuff - * - * @param array $args $_REQUEST array - * - * @return success flag - */ - - function prepare($args) - { - parent::prepare($args); - if (!$this->attachment) { - $this->clientError(_('No such attachment.'), 404); - return false; - } - return true; - } - /** * Show page, a template method. * @@ -87,7 +67,7 @@ class Attachment_ajaxAction extends AttachmentAction */ function showCore() { - $this->elementStart('div', array('id' => 'core')); + $this->elementStart('div', array('id' => 'ajaxcore')); if (Event::handle('StartShowContentBlock', array($this))) { $this->showContentBlock(); Event::handle('EndShowContentBlock', array($this)); @@ -95,8 +75,6 @@ class Attachment_ajaxAction extends AttachmentAction $this->elementEnd('div'); } - - /** * Last-modified date for page * diff --git a/actions/attachments.php b/actions/attachments.php index 6b31c839d..d3c90fec2 100644 --- a/actions/attachments.php +++ b/actions/attachments.php @@ -31,8 +31,6 @@ if (!defined('LACONICA')) { exit(1); } -//require_once INSTALLDIR.'/lib/personalgroupnav.php'; -//require_once INSTALLDIR.'/lib/feedlist.php'; require_once INSTALLDIR.'/lib/attachmentlist.php'; /** diff --git a/actions/tag.php b/actions/tag.php index 47420e4c3..e71ec06a8 100644 --- a/actions/tag.php +++ b/actions/tag.php @@ -49,8 +49,8 @@ class TagAction extends Action { $pop = new PopularNoticeSection($this); $pop->show(); - $freqatt = new FrequentAttachmentSection($this); - $freqatt->show(); +// $freqatt = new FrequentAttachmentSection($this); +// $freqatt->show(); } function title() diff --git a/js/util.js b/js/util.js index 2dfaafd76..4f2b036fa 100644 --- a/js/util.js +++ b/js/util.js @@ -17,9 +17,10 @@ */ $(document).ready(function(){ - $('.attachments').click(function() {$().jOverlay({zIndex:999, success:function(html) {$('.attachment').click(function() {$().jOverlay({url:$(this).attr('href') + '/ajax'}); return false; }); - }, url:$(this).attr('href') + '/ajax'}); return false; }); - $('.attachment').click(function() {$().jOverlay({url:$(this).attr('href') + '/ajax'}); return false; }); +// attachments and attachment pages not used at the moment except for attachment_ajax version +// $('.attachments').click(function() {$().jOverlay({zIndex:999, success:function(html) {$('.attachment').click(function() {$().jOverlay({url:$(this).attr('href') + '/ajax'}); return false; }); +// }, url:$(this).attr('href') + '/ajax'}); return false; }); + $('.attachment').click(function() {$().jOverlay({url:'http://laptop.waglo.com/attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'}); return false; }); // count character on keyup function counter(event){ diff --git a/lib/attachmentlist.php b/lib/attachmentlist.php index 9485fe3d6..1be7b2fee 100644 --- a/lib/attachmentlist.php +++ b/lib/attachmentlist.php @@ -191,7 +191,7 @@ class AttachmentListItem extends Widget } function linkAttr() { - return array('class' => 'attachment', 'href' => common_local_url('attachment', array('attachment' => $this->attachment->id))); + return array('class' => 'attachment', 'href' => $this->attachment->url, 'id' => 'attachment-' . $this->attachment->id); } function showLink() { @@ -200,10 +200,6 @@ class AttachmentListItem extends Widget $this->out->elementStart('h4'); $this->out->element('a', $attr, $text); - if ($this->attachment->url !== $this->title()) - $this->out->element('span', null, " ({$this->attachment->url})"); - - $this->out->elementEnd('h4'); } diff --git a/lib/noticelist.php b/lib/noticelist.php index a52132171..e3361fc99 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -34,6 +34,7 @@ if (!defined('LACONICA')) { require_once INSTALLDIR.'/lib/favorform.php'; require_once INSTALLDIR.'/lib/disfavorform.php'; +require_once INSTALLDIR.'/lib/attachmentlist.php'; /** * widget for displaying a list of notices @@ -179,9 +180,10 @@ class NoticeListItem extends Widget { $this->showStart(); $this->showNotice(); - $this->showNoticeAttachments(); + $this->showNoticeAttachmentsIcon(); $this->showNoticeInfo(); $this->showNoticeOptions(); + $this->showNoticeAttachments(); $this->showEnd(); } @@ -193,45 +195,38 @@ class NoticeListItem extends Widget $this->out->elementEnd('div'); } - function showNoticeAttachments() - { + function showNoticeAttachments() { + if ($this->isUsedInList()) { + return; + } + $al = new AttachmentList($this->notice, $this->out); + $al->show(); + } + + function isUsedInList() { + return 'shownotice' !== $this->out->args['action']; + } + + function attachmentCount() { $f2p = new File_to_post; $f2p->post_id = $this->notice->id; $file = new File; $file->joinAdd($f2p); $file->selectAdd(); $file->selectAdd('file.id as id'); - $count = $file->find(true); - if (!$count) return; - if (1 === $count) { - $href = common_local_url('attachment', array('attachment' => $file->id)); - $att_class = 'attachment'; - } else { - $href = common_local_url('attachments', array('notice' => $this->notice->id)); - $att_class = 'attachments'; - } + return $file->find(true); + } - $clip = theme_path('images/icons/clip', 'base'); - if ('shownotice' === $this->out->args['action']) { - $height = '96px'; - $width = '83%'; - $width_att = '15%'; - $clip .= '-big.png'; - $top = '70px'; - } else { - $height = '48px'; - $width = '90%'; - $width_att = '8%'; - $clip .= '.png'; - $top = '20px'; + function showNoticeAttachmentsIcon() + { + if (!($this->isUsedInList() && ($count = $this->attachmentCount()))) { + return; } -if(0) - $this->out->elementStart('div', 'entry-attachments'); -else - $this->out->elementStart('p', array('class' => 'entry-attachments', 'style' => "float: right; width: $width_att; background: url($clip) no-repeat; text-align: right; height: $height;")); - $this->out->element('a', array('class' => $att_class, 'style' => "text-decoration: none; padding-top: $top; display: block; height: $height;", 'href' => $href, 'title' => "# of attachments: $count"), $count === 1 ? '' : $count); + $href = common_local_url('shownotice', array('notice' => $this->notice->id)) . '#attachments'; + $this->out->elementStart('p', 'entry-attachments'); + $this->out->element('a', array('href' => $href, 'title' => "# of attachments: $count"), $count === 1 ? '' : $count); $this->out->elementEnd('p'); } diff --git a/lib/router.php b/lib/router.php index 70ee0f3fb..39c005609 100644 --- a/lib/router.php +++ b/lib/router.php @@ -151,26 +151,35 @@ class Router $m->connect('search/notice/rss?q=:q', array('action' => 'noticesearchrss'), array('q' => '.+')); +/* + $m->connect('attachment/ajax_by_url/*url', + array('action' => 'attachment_ajax')); +*/ $m->connect('attachment/:attachment/ajax', array('action' => 'attachment_ajax'), - array('notice' => '[0-9]+')); + array('attachment' => '[0-9]+')); +/* + TODO + not used right now, will revisit later $m->connect('attachment/:attachment', array('action' => 'attachment'), - array('notice' => '[0-9]+')); - + array('attachment' => '[0-9]+')); +*/ // notice $m->connect('notice/new', array('action' => 'newnotice')); $m->connect('notice/new?replyto=:replyto', array('action' => 'newnotice'), array('replyto' => '[A-Za-z0-9_-]+')); +/* $m->connect('notice/:notice/attachments/ajax', array('action' => 'attachments_ajax'), array('notice' => '[0-9]+')); $m->connect('notice/:notice/attachments', array('action' => 'attachments'), array('notice' => '[0-9]+')); +*/ $m->connect('notice/:notice', array('action' => 'shownotice'), array('notice' => '[0-9]+')); diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 5d2b5231c..cb4680c39 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -379,6 +379,12 @@ max-width:1003px; overflow:hidden; } +#ajaxcore { +width: 520px; +height: 600px; +background: #fff; +} + #core { position:relative; width:100%; @@ -1048,8 +1054,20 @@ margin-bottom:18px; margin-left:18px; } +p.entry-attachments { +float: right; +width: 8%; +background: url(../images/icons/clip.png) no-repeat; +text-align: right; +height: 48px; +} - +p.entry-attachments a { +text-decoration: none; +padding-top: 20px; +display: block; +height: 48px; +} /* TOP_POSTERS */ .section tbody td { -- cgit v1.2.3-54-g00ecf From bd70caace84758e6655f8db4957049492834a6c6 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Sun, 24 May 2009 18:06:19 -0400 Subject: Only show number of attachments if > 1 --- lib/noticelist.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/noticelist.php b/lib/noticelist.php index e3361fc99..51b8987fe 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -207,14 +207,12 @@ class NoticeListItem extends Widget return 'shownotice' !== $this->out->args['action']; } - function attachmentCount() { - $f2p = new File_to_post; - $f2p->post_id = $this->notice->id; - $file = new File; - $file->joinAdd($f2p); - $file->selectAdd(); - $file->selectAdd('file.id as id'); - return $file->find(true); + function attachmentCount($discriminant = true) { + $file_oembed = new File_oembed; + $query = "select count(*) as c from file_oembed join file_to_post on file_oembed.file_id = file_to_post.file_id where post_id=" . $this->notice->id; + $file_oembed->query($query); + $file_oembed->fetch(); + return intval($file_oembed->c); } function showNoticeAttachmentsIcon() @@ -224,7 +222,6 @@ class NoticeListItem extends Widget } $href = common_local_url('shownotice', array('notice' => $this->notice->id)) . '#attachments'; - $this->out->elementStart('p', 'entry-attachments'); $this->out->element('a', array('href' => $href, 'title' => "# of attachments: $count"), $count === 1 ? '' : $count); $this->out->elementEnd('p'); -- cgit v1.2.3-54-g00ecf From 5f3acc252738e408ea2447b7541eae66c1e9e09a Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Sun, 24 May 2009 21:13:42 -0400 Subject: Removed big clip and replaced with smaller inline one next to each URL (in a notice) that's actually an attachment. Overlay (popup) on click. --- js/util.js | 6 +++++- lib/noticelist.php | 1 - lib/util.php | 11 +++++++++++ theme/base/images/icons/clip-inline.png | Bin 0 -> 1646 bytes 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 theme/base/images/icons/clip-inline.png (limited to 'lib') diff --git a/js/util.js b/js/util.js index 6511c0380..b6848abaa 100644 --- a/js/util.js +++ b/js/util.js @@ -20,7 +20,11 @@ $(document).ready(function(){ // attachments and attachment pages not used at the moment except for attachment_ajax version // $('.attachments').click(function() {$().jOverlay({zIndex:999, success:function(html) {$('.attachment').click(function() {$().jOverlay({url:$(this).attr('href') + '/ajax'}); return false; }); // }, url:$(this).attr('href') + '/ajax'}); return false; }); - $('.attachment').click(function() {$().jOverlay({url:'../attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'}); return false; }); + + //FIXME + //need to link to proper url depending on site config (path name and theme, for instance) + $('a.attachment').click(function() {$().jOverlay({url:'/attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'}); return false; }); + $('.entry-title a.attachment').append(' Attachment'); // count character on keyup function counter(event){ diff --git a/lib/noticelist.php b/lib/noticelist.php index 51b8987fe..ae1438892 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -180,7 +180,6 @@ class NoticeListItem extends Widget { $this->showStart(); $this->showNotice(); - $this->showNoticeAttachmentsIcon(); $this->showNoticeInfo(); $this->showNoticeOptions(); $this->showNoticeAttachments(); diff --git a/lib/util.php b/lib/util.php index fbef8764a..4a55cbfe5 100644 --- a/lib/util.php +++ b/lib/util.php @@ -496,6 +496,17 @@ function common_linkify($url) { } $attrs = array('href' => $longurl, 'rel' => 'external'); + +// if this URL is an attachment, then we set class='attachment' and id='attahcment-ID' +// where ID is the id of the attachment for the given URL. + $query = "select file_oembed.file_id as file_id from file join file_oembed on file.id = file_oembed.file_id where file.url='$longurl'"; + $file = new File; + $file->query($query); + $file->fetch(); + if (!empty($file->file_id)) { + $attrs['class'] = 'attachment'; + $attrs['id'] = "attachment-{$file->file_id}"; + } return XMLStringer::estring('a', $attrs, $display); } diff --git a/theme/base/images/icons/clip-inline.png b/theme/base/images/icons/clip-inline.png new file mode 100644 index 000000000..870f8b2e8 Binary files /dev/null and b/theme/base/images/icons/clip-inline.png differ -- cgit v1.2.3-54-g00ecf From 84edf12791dc3d44625b156cda6296f1f74f8a9d Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Mon, 25 May 2009 11:13:13 -0400 Subject: Display thumbnail on hover over links in notices when appropriate. --- js/util.js | 13 +++++++++++++ lib/attachmentlist.php | 4 ++-- lib/router.php | 4 ++++ lib/util.php | 12 +++++++++++- theme/base/css/display.css | 8 ++++++++ 5 files changed, 38 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/js/util.js b/js/util.js index b6848abaa..9ee2a1963 100644 --- a/js/util.js +++ b/js/util.js @@ -25,6 +25,19 @@ $(document).ready(function(){ //need to link to proper url depending on site config (path name and theme, for instance) $('a.attachment').click(function() {$().jOverlay({url:'/attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'}); return false; }); $('.entry-title a.attachment').append(' Attachment'); + $('a.thumbnail').hover(function() { + anchor = $(this); + $.get('/attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) { + anchor.append(data); + $('#thumbnail').fadeIn('def'); + }); + }, + function() { + setTimeout(function() { + $('#thumbnail').fadeOut('slow', function() {$(this).remove();}); + }, 500); + } + ); // count character on keyup function counter(event){ diff --git a/lib/attachmentlist.php b/lib/attachmentlist.php index 1be7b2fee..52aa5d9ee 100644 --- a/lib/attachmentlist.php +++ b/lib/attachmentlist.php @@ -171,7 +171,7 @@ class AttachmentListItem extends Widget } function linkTitle() { - return 'Our page for ' . $this->title(); + return $this->title(); } /** @@ -256,7 +256,7 @@ class Attachment extends AttachmentListItem } function linkTitle() { - return 'Direct link to ' . $this->title(); + return $this->attachment->url; } function showRepresentation() { diff --git a/lib/router.php b/lib/router.php index 39c005609..d1e2970c5 100644 --- a/lib/router.php +++ b/lib/router.php @@ -159,6 +159,10 @@ class Router array('action' => 'attachment_ajax'), array('attachment' => '[0-9]+')); + $m->connect('attachment/:attachment/thumbnail', + array('action' => 'attachment_thumbnail'), + array('attachment' => '[0-9]+')); + /* TODO not used right now, will revisit later diff --git a/lib/util.php b/lib/util.php index 4a55cbfe5..d56f44f7b 100644 --- a/lib/util.php +++ b/lib/util.php @@ -503,8 +503,18 @@ function common_linkify($url) { $file = new File; $file->query($query); $file->fetch(); + if (!empty($file->file_id)) { - $attrs['class'] = 'attachment'; + $query = "select file_thumbnail.file_id as file_id from file join file_thumbnail on file.id = file_thumbnail.file_id where file.url='$longurl'"; + $file2 = new File; + $file2->query($query); + $file2->fetch(); + + if (empty($file2->file_id)) { + $attrs['class'] = 'attachment'; + } else { + $attrs['class'] = 'attachment thumbnail'; + } $attrs['id'] = "attachment-{$file->file_id}"; } return XMLStringer::estring('a', $attrs, $display); diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 8f72460a8..71a434c54 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -1205,3 +1205,11 @@ display:none; .guide { clear:both; } + +#thumbnail { +position:absolute; +z-index: 999; +display: none; +left: 100px; +} + -- cgit v1.2.3-54-g00ecf From 594454ced3d02ceb766bdbdce1dbfa871abec464 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Mon, 25 May 2009 15:38:50 -0400 Subject: Single anchor to include thumbnail and title for attachment --- lib/attachmentlist.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/attachmentlist.php b/lib/attachmentlist.php index 52aa5d9ee..2a0114b12 100644 --- a/lib/attachmentlist.php +++ b/lib/attachmentlist.php @@ -198,23 +198,22 @@ class AttachmentListItem extends Widget $attr = $this->linkAttr(); $text = $this->linkTitle(); $this->out->elementStart('h4'); - $this->out->element('a', $attr, $text); - + $this->out->elementStart('a', $attr); + $this->out->element('span', null, $text); + $this->showRepresentation(); + $this->out->elementEnd('a'); $this->out->elementEnd('h4'); } function showNoticeAttachment() { $this->showLink(); - $this->showRepresentation(); } function showRepresentation() { $thumbnail = File_thumbnail::staticGet('file_id', $this->attachment->id); if (!empty($thumbnail)) { - $this->out->elementStart('a', $this->linkAttr()/*'href' => $this->linkTo()*/); $this->out->element('img', array('alt' => 'nothing to say', 'src' => $thumbnail->url, 'width' => $thumbnail->width, 'height' => $thumbnail->height)); - $this->out->elementEnd('a'); } } -- cgit v1.2.3-54-g00ecf From 64d0767654d93de81a0779f04eb992c574bbdece Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Mon, 25 May 2009 19:42:03 +0000 Subject: Removed more cruft from old attachment/attachements pages --- actions/tag.php | 2 -- lib/router.php | 22 +--------------------- 2 files changed, 1 insertion(+), 23 deletions(-) (limited to 'lib') diff --git a/actions/tag.php b/actions/tag.php index e71ec06a8..e9351d241 100644 --- a/actions/tag.php +++ b/actions/tag.php @@ -49,8 +49,6 @@ class TagAction extends Action { $pop = new PopularNoticeSection($this); $pop->show(); -// $freqatt = new FrequentAttachmentSection($this); -// $freqatt->show(); } function title() diff --git a/lib/router.php b/lib/router.php index d1e2970c5..fc119821b 100644 --- a/lib/router.php +++ b/lib/router.php @@ -151,10 +151,6 @@ class Router $m->connect('search/notice/rss?q=:q', array('action' => 'noticesearchrss'), array('q' => '.+')); -/* - $m->connect('attachment/ajax_by_url/*url', - array('action' => 'attachment_ajax')); -*/ $m->connect('attachment/:attachment/ajax', array('action' => 'attachment_ajax'), array('attachment' => '[0-9]+')); @@ -163,27 +159,11 @@ class Router array('action' => 'attachment_thumbnail'), array('attachment' => '[0-9]+')); -/* - TODO - not used right now, will revisit later - $m->connect('attachment/:attachment', - array('action' => 'attachment'), - array('attachment' => '[0-9]+')); -*/ - // notice - $m->connect('notice/new', array('action' => 'newnotice')); $m->connect('notice/new?replyto=:replyto', array('action' => 'newnotice'), array('replyto' => '[A-Za-z0-9_-]+')); -/* - $m->connect('notice/:notice/attachments/ajax', - array('action' => 'attachments_ajax'), - array('notice' => '[0-9]+')); - $m->connect('notice/:notice/attachments', - array('action' => 'attachments'), - array('notice' => '[0-9]+')); -*/ + $m->connect('notice/:notice', array('action' => 'shownotice'), array('notice' => '[0-9]+')); -- cgit v1.2.3-54-g00ecf From 01dad5729827870d87f87118c336dcf2acc4af32 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Mon, 25 May 2009 15:53:19 -0400 Subject: Markup cleanup for attachments --- actions/attachment.php | 2 -- actions/attachment_ajax.php | 2 +- js/util.js | 6 ------ lib/attachmentlist.php | 17 +++++++---------- lib/noticelist.php | 14 +------------- theme/base/css/display.css | 3 +++ 6 files changed, 12 insertions(+), 32 deletions(-) (limited to 'lib') diff --git a/actions/attachment.php b/actions/attachment.php index c51c75120..16ee723d9 100644 --- a/actions/attachment.php +++ b/actions/attachment.php @@ -176,10 +176,8 @@ class AttachmentAction extends Action function showContent() { - $this->elementStart('ul', array('class' => 'attachments')); $ali = new Attachment($this->attachment, $this); $cnt = $ali->show(); - $this->elementEnd('ul'); } /** diff --git a/actions/attachment_ajax.php b/actions/attachment_ajax.php index 6930dc112..3d83393c5 100644 --- a/actions/attachment_ajax.php +++ b/actions/attachment_ajax.php @@ -67,7 +67,7 @@ class Attachment_ajaxAction extends AttachmentAction */ function showCore() { - $this->elementStart('div', array('id' => 'ajaxcore')); + $this->elementStart('div', array('id' => 'core')); if (Event::handle('StartShowContentBlock', array($this))) { $this->showContentBlock(); Event::handle('EndShowContentBlock', array($this)); diff --git a/js/util.js b/js/util.js index ffaedc690..cba6f822e 100644 --- a/js/util.js +++ b/js/util.js @@ -17,12 +17,6 @@ */ $(document).ready(function(){ -// attachments and attachment pages not used at the moment except for attachment_ajax version -// $('.attachments').click(function() {$().jOverlay({zIndex:999, success:function(html) {$('.attachment').click(function() {$().jOverlay({url:$(this).attr('href') + '/ajax'}); return false; }); -// }, url:$(this).attr('href') + '/ajax'}); return false; }); - - //FIXME - //need to link to proper url depending on site config (path name and theme, for instance) $('a.attachment').click(function() {$().jOverlay({url: $('address .url')[0].href+'/attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'}); return false; }); $('a.thumbnail').hover( function() { diff --git a/lib/attachmentlist.php b/lib/attachmentlist.php index 2a0114b12..d0478bad3 100644 --- a/lib/attachmentlist.php +++ b/lib/attachmentlist.php @@ -80,9 +80,9 @@ class AttachmentList extends Widget function show() { -// $this->out->elementStart('div', array('id' =>'attachments_primary')); - $this->out->elementStart('div', array('id' =>'content')); - $this->out->element('h2', null, _('Attachments')); + $this->out->elementStart('dl', array('id' =>'attachment')); + $this->out->element('dt', null, _('Attachments')); + $this->out->elementStart('dd'); $this->out->elementStart('ul', array('class' => 'attachments')); $atts = new File; @@ -92,8 +92,9 @@ class AttachmentList extends Widget $item->show(); } + $this->out->elementEnd('dd'); $this->out->elementEnd('ul'); - $this->out->elementEnd('div'); + $this->out->elementEnd('dl'); return count($att); } @@ -195,14 +196,10 @@ class AttachmentListItem extends Widget } function showLink() { - $attr = $this->linkAttr(); - $text = $this->linkTitle(); - $this->out->elementStart('h4'); - $this->out->elementStart('a', $attr); - $this->out->element('span', null, $text); + $this->out->elementStart('a', $this->linkAttr()); + $this->out->element('span', null, $this->linkTitle()); $this->showRepresentation(); $this->out->elementEnd('a'); - $this->out->elementEnd('h4'); } function showNoticeAttachment() diff --git a/lib/noticelist.php b/lib/noticelist.php index ae1438892..50a95cfcb 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -180,9 +180,9 @@ class NoticeListItem extends Widget { $this->showStart(); $this->showNotice(); + $this->showNoticeAttachments(); $this->showNoticeInfo(); $this->showNoticeOptions(); - $this->showNoticeAttachments(); $this->showEnd(); } @@ -214,18 +214,6 @@ class NoticeListItem extends Widget return intval($file_oembed->c); } - function showNoticeAttachmentsIcon() - { - if (!($this->isUsedInList() && ($count = $this->attachmentCount()))) { - return; - } - - $href = common_local_url('shownotice', array('notice' => $this->notice->id)) . '#attachments'; - $this->out->elementStart('p', 'entry-attachments'); - $this->out->element('a', array('href' => $href, 'title' => "# of attachments: $count"), $count === 1 ? '' : $count); - $this->out->elementEnd('p'); - } - function showNoticeInfo() { $this->out->elementStart('div', 'entry-content'); diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 74f369142..aa76910f0 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -861,6 +861,9 @@ top:11px; left:0; z-index:99; } +#shownotice .notice .attachment img { +position:static; +} .notice-options { -- cgit v1.2.3-54-g00ecf From a598dcccba21daa6decefb7fb38882c1e77904eb Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Mon, 25 May 2009 19:58:31 +0000 Subject: Really removing the old files, thanks git! --- actions/attachments.php | 290 -------------------------------------- actions/attachments_ajax.php | 115 --------------- lib/attachmentsection.php | 80 ----------- lib/frequentattachmentsection.php | 66 --------- 4 files changed, 551 deletions(-) delete mode 100644 actions/attachments.php delete mode 100644 actions/attachments_ajax.php delete mode 100644 lib/attachmentsection.php delete mode 100644 lib/frequentattachmentsection.php (limited to 'lib') diff --git a/actions/attachments.php b/actions/attachments.php deleted file mode 100644 index d3c90fec2..000000000 --- a/actions/attachments.php +++ /dev/null @@ -1,290 +0,0 @@ -. - * - * @category Personal - * @package Laconica - * @author Evan Prodromou - * @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); -} - -require_once INSTALLDIR.'/lib/attachmentlist.php'; - -/** - * Show notice attachments - * - * @category Personal - * @package Laconica - * @author Evan Prodromou - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ - */ - -class AttachmentsAction extends Action -{ - /** - * Notice object to show - */ - - var $notice = null; - - /** - * Profile of the notice object - */ - - var $profile = null; - - /** - * Avatar of the profile of the notice object - */ - - var $avatar = null; - - /** - * Is this action read-only? - * - * @return boolean true - */ - - function isReadOnly($args) - { - return true; - } - - /** - * Last-modified date for page - * - * When was the content of this page last modified? Based on notice, - * profile, avatar. - * - * @return int last-modified date as unix timestamp - */ - - function lastModified() - { - return max(strtotime($this->notice->created), - strtotime($this->profile->modified), - ($this->avatar) ? strtotime($this->avatar->modified) : 0); - } - - /** - * An entity tag for this page - * - * Shows the ETag for the page, based on the notice ID and timestamps - * for the notice, profile, and avatar. It's weak, since we change - * the date text "one hour ago", etc. - * - * @return string etag - */ - - function etag() - { - $avtime = ($this->avatar) ? - strtotime($this->avatar->modified) : 0; - - return 'W/"' . implode(':', array($this->arg('action'), - common_language(), - $this->notice->id, - strtotime($this->notice->created), - strtotime($this->profile->modified), - $avtime)) . '"'; - } - - /** - * Title of the page - * - * @return string title of the page - */ - - function title() - { - return sprintf(_('%1$s\'s status on %2$s'), - $this->profile->nickname, - common_exact_date($this->notice->created)); - } - - - /** - * Load attributes based on database arguments - * - * Loads all the DB stuff - * - * @param array $args $_REQUEST array - * - * @return success flag - */ - - function prepare($args) - { - parent::prepare($args); - - $id = $this->arg('notice'); - - $this->notice = Notice::staticGet($id); - - if (!$this->notice) { - $this->clientError(_('No such notice.'), 404); - return false; - } - - -/* -// STOP if there are no attachments -// maybe even redirect if there's a single one -// RYM FIXME TODO - $this->clientError(_('No such attachment.'), 404); - return false; - -*/ - - - - - $this->profile = $this->notice->getProfile(); - - if (!$this->profile) { - $this->serverError(_('Notice has no profile'), 500); - return false; - } - - $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE); - return true; - } - - - - /** - * Handle input - * - * Only handles get, so just show the page. - * - * @param array $args $_REQUEST data (unused) - * - * @return void - */ - - function handle($args) - { - parent::handle($args); - - if ($this->notice->is_local == 0) { - if (!empty($this->notice->url)) { - common_redirect($this->notice->url, 301); - } else if (!empty($this->notice->uri) && preg_match('/^https?:/', $this->notice->uri)) { - common_redirect($this->notice->uri, 301); - } - } else { - $f2p = new File_to_post; - $f2p->post_id = $this->notice->id; - $file = new File; - $file->joinAdd($f2p); - $file->selectAdd(); - $file->selectAdd('file.id as id'); - $count = $file->find(true); - if (!$count) return; - if (1 === $count) { - common_redirect(common_local_url('attachment', array('attachment' => $file->id)), 301); - } else { - $this->showPage(); - } - } - } - - /** - * Don't show local navigation - * - * @return void - */ - - function showLocalNavBlock() - { - } - - /** - * Fill the content area of the page - * - * Shows a single notice list item. - * - * @return void - */ - - function showContent() - { - $al = new AttachmentList($this->notice, $this); - $cnt = $al->show(); - } - - /** - * Don't show page notice - * - * @return void - */ - - function showPageNoticeBlock() - { - } - - /** - * Don't show aside - * - * @return void - */ - - function showAside() { - } - - /** - * Extra content - * - * We show the microid(s) for the author, if any. - * - * @return void - */ - - function extraHead() - { - $user = User::staticGet($this->profile->id); - - if (!$user) { - return; - } - - if ($user->emailmicroid && $user->email && $this->notice->uri) { - $id = new Microid('mailto:'. $user->email, - $this->notice->uri); - $this->element('meta', array('name' => 'microid', - 'content' => $id->toString())); - } - - if ($user->jabbermicroid && $user->jabber && $this->notice->uri) { - $id = new Microid('xmpp:', $user->jabber, - $this->notice->uri); - $this->element('meta', array('name' => 'microid', - 'content' => $id->toString())); - } - } -} - diff --git a/actions/attachments_ajax.php b/actions/attachments_ajax.php deleted file mode 100644 index 402d8b5e7..000000000 --- a/actions/attachments_ajax.php +++ /dev/null @@ -1,115 +0,0 @@ -. - * - * @category Personal - * @package Laconica - * @author Evan Prodromou - * @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); -} - -//require_once INSTALLDIR.'/lib/personalgroupnav.php'; -//require_once INSTALLDIR.'/lib/feedlist.php'; -require_once INSTALLDIR.'/actions/attachments.php'; - -/** - * Show notice attachments - * - * @category Personal - * @package Laconica - * @author Evan Prodromou - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ - */ - -class Attachments_ajaxAction extends AttachmentsAction -{ - function showContent() - { - } - - /** - * Fill the content area of the page - * - * Shows a single notice list item. - * - * @return void - */ - - function showContentBlock() - { - $al = new AttachmentList($this->notice, $this); - $cnt = $al->show(); - } - - /** - * Extra content - * - * We show the microid(s) for the author, if any. - * - * @return void - */ - - function extraHead() - { - } - - - /** - * Show page, a template method. - * - * @return nothing - */ - function showPage() - { - if (Event::handle('StartShowBody', array($this))) { - $this->showCore(); - Event::handle('EndShowBody', array($this)); - } - } - - /** - * Show core. - * - * Shows local navigation, content block and aside. - * - * @return nothing - */ - function showCore() - { - $this->elementStart('div', array('id' => 'core')); - if (Event::handle('StartShowContentBlock', array($this))) { - $this->showContentBlock(); - Event::handle('EndShowContentBlock', array($this)); - } - $this->elementEnd('div'); - } - - - - -} - diff --git a/lib/attachmentsection.php b/lib/attachmentsection.php deleted file mode 100644 index 20e620b9b..000000000 --- a/lib/attachmentsection.php +++ /dev/null @@ -1,80 +0,0 @@ -. - * - * @category Widget - * @package Laconica - * @author Evan Prodromou - * @copyright 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); -} - -define('ATTACHMENTS_PER_SECTION', 6); - -/** - * Base class for sections showing lists of attachments - * - * These are the widgets that show interesting data about a person - * group, or site. - * - * @category Widget - * @package Laconica - * @author Evan Prodromou - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ - */ - -class AttachmentSection extends Section -{ - function showContent() - { - $attachments = $this->getAttachments(); - - $cnt = 0; - - $this->out->elementStart('ul', 'attachments'); - - while ($attachments->fetch() && ++$cnt <= ATTACHMENTS_PER_SECTION) { - $this->showAttachment($attachments); - } - - $this->out->elementEnd('ul'); - - return ($cnt > ATTACHMENTS_PER_SECTION); - } - - function getAttachments() - { - return null; - } - - function showAttachment($attachment) - { - $this->out->elementStart('li'); - $this->out->element('a', array('class' => 'attachment', 'href' => common_local_url('attachment', array('attachment' => $attachment->file_id))), "Attachment tagged {$attachment->c} times"); - $this->out->elementEnd('li'); - } -} - diff --git a/lib/frequentattachmentsection.php b/lib/frequentattachmentsection.php deleted file mode 100644 index 0ce0d1871..000000000 --- a/lib/frequentattachmentsection.php +++ /dev/null @@ -1,66 +0,0 @@ -. - * - * @category Widget - * @package Laconica - * @author Evan Prodromou - * @copyright 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); -} - -/** - * FIXME - * - * These are the widgets that show interesting data about a person - * group, or site. - * - * @category Widget - * @package Laconica - * @author Evan Prodromou - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ - */ - -class FrequentAttachmentSection extends AttachmentSection -{ - function getAttachments() { - $notice_tag = new Notice_tag; - $query = 'select file_id, count(file_id) as c from notice_tag join file_to_post on post_id = notice_id where tag="' . $notice_tag->escape($this->out->tag) . '" group by file_id order by c desc'; - $notice_tag->query($query); - return $notice_tag; - } - - function title() - { - return sprintf(_('Attachments frequently tagged with %s'), $this->out->tag); - } - - function divId() - { - return 'frequent_attachments'; - } -} - -- cgit v1.2.3-54-g00ecf From 0e8358bd2335bfc71ac5b2ee93e866fa5c571c89 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Tue, 26 May 2009 02:34:36 +0000 Subject: Updated stylesheet paths for facebook app --- lib/facebookaction.php | 4 ---- theme/base/css/facebookapp.css | 2 -- 2 files changed, 6 deletions(-) (limited to 'lib') diff --git a/lib/facebookaction.php b/lib/facebookaction.php index 043a078cd..00db79400 100644 --- a/lib/facebookaction.php +++ b/lib/facebookaction.php @@ -98,10 +98,6 @@ class FacebookAction extends Action // Add a timestamp to the file so Facebook cache wont ignore our changes $ts = filemtime(INSTALLDIR.'/theme/base/css/display.css'); - $this->element('link', array('rel' => 'stylesheet', - 'type' => 'text/css', - 'href' => theme_path('css/display.css', 'base') . '?ts=' . $ts)); - $theme = common_config('site', 'theme'); $ts = filemtime(INSTALLDIR. '/theme/' . $theme .'/css/display.css'); diff --git a/theme/base/css/facebookapp.css b/theme/base/css/facebookapp.css index 9f269b96f..e6b1c9ee5 100644 --- a/theme/base/css/facebookapp.css +++ b/theme/base/css/facebookapp.css @@ -1,5 +1,3 @@ -@import url("../../identica/css/display.css"); - * { font-size:14px; font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif; -- cgit v1.2.3-54-g00ecf From c93031c2aa49b8a044e896ca1e07f5f4f429308e Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Tue, 26 May 2009 03:34:00 +0000 Subject: Reusing base stylesheet (instead of hoping for FB to import it) in FB app. --- lib/facebookaction.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/facebookaction.php b/lib/facebookaction.php index 00db79400..637a6284d 100644 --- a/lib/facebookaction.php +++ b/lib/facebookaction.php @@ -97,6 +97,10 @@ class FacebookAction extends Action { // Add a timestamp to the file so Facebook cache wont ignore our changes $ts = filemtime(INSTALLDIR.'/theme/base/css/display.css'); + + $this->element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => theme_path('css/display.css', 'base') . '?ts=' . $ts)); $theme = common_config('site', 'theme'); -- cgit v1.2.3-54-g00ecf From da035331d81bc73f488968d835e4d05a2da975f3 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 26 May 2009 17:26:31 -0400 Subject: fixes during checking of snapshot --- lib/snapshot.php | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/snapshot.php b/lib/snapshot.php index a014d3435..4b05b502d 100644 --- a/lib/snapshot.php +++ b/lib/snapshot.php @@ -84,9 +84,8 @@ class Snapshot // hits if (rand() % common_config('snapshot', 'frequency') == 0) { $snapshot = new Snapshot(); - if ($snapshot->take()) { - $snapshot->report(); - } + $snapshot->take(); + $snapshot->report(); } break; case 'cron': @@ -94,11 +93,14 @@ class Snapshot if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { break; } + common_log(LOG_INFO, 'Running snapshot from cron job'); // We're running from the command line; assume + $snapshot = new Snapshot(); - if ($snapshot->take()) { - $snapshot->report(); - } + $snapshot->take(); + common_log(LOG_INFO, count($snapshot->stats) . " statistics being uploaded."); + $snapshot->report(); + break; case 'never': break; @@ -155,6 +157,7 @@ class Snapshot $this->stats['memcached'] = common_config('memcached', 'enabled'); $this->stats['language'] = common_config('site', 'language'); $this->stats['timezone'] = common_config('site', 'timezone'); + } /** @@ -186,7 +189,9 @@ class Snapshot $reporturl = common_config('snapshot', 'reporturl'); - $result = file_get_contents($reporturl, false, $context); + $result = @file_get_contents($reporturl, false, $context); + + return $result; } /** @@ -203,14 +208,14 @@ class Snapshot function tableStats($table) { - $inst = DB_DataObject::Factory($table); + $inst = DB_DataObject::factory($table); - $res = $inst->query('SELECT count(*) as cnt, '. - 'min(created) as first, '. - 'max(created) as last '. - 'from ' . $table); + $inst->selectAdd(); + $inst->selectAdd('count(*) as cnt, '. + 'min(created) as first, '. + 'max(created) as last'); - if ($res) { + if ($inst->find(true)) { $this->stats[$table.'count'] = $inst->cnt; $this->stats[$table.'first'] = $inst->first; $this->stats[$table.'last'] = $inst->last; -- cgit v1.2.3-54-g00ecf From 69a656af2210acf9211aa4fcb1c05bfd5c5a2e1f Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 26 May 2009 23:21:10 +0000 Subject: Some adjustments to allow the Facebook app work with Laconica 0.8 --- actions/facebookhome.php | 2 +- lib/facebookaction.php | 262 ++++++++++++++++++++--------------------------- 2 files changed, 110 insertions(+), 154 deletions(-) (limited to 'lib') diff --git a/actions/facebookhome.php b/actions/facebookhome.php index 4c2b26355..00b35ef68 100644 --- a/actions/facebookhome.php +++ b/actions/facebookhome.php @@ -115,7 +115,7 @@ class FacebookhomeAction extends FacebookAction $flink->foreign_id = $this->fbuid; $flink->service = FACEBOOK_SERVICE; $flink->created = common_sql_now(); - $flink->set_flags(true, false, false); + $flink->set_flags(true, false, false, false); $flink_id = $flink->insert(); diff --git a/lib/facebookaction.php b/lib/facebookaction.php index 637a6284d..a445750f7 100644 --- a/lib/facebookaction.php +++ b/lib/facebookaction.php @@ -38,14 +38,14 @@ require_once INSTALLDIR.'/lib/noticeform.php'; class FacebookAction extends Action { - + var $facebook = null; var $fbuid = null; var $flink = null; var $action = null; var $app_uri = null; var $app_name = null; - + /** * Constructor * @@ -60,71 +60,71 @@ class FacebookAction extends Action function __construct($output='php://output', $indent=true, $facebook=null, $flink=null) { parent::__construct($output, $indent); - + $this->facebook = $facebook; $this->flink = $flink; - + if ($this->flink) { - $this->fbuid = $flink->foreign_id; + $this->fbuid = $flink->foreign_id; $this->user = $flink->getUser(); } - + $this->args = array(); } - + function prepare($argarray) - { + { parent::prepare($argarray); - + $this->facebook = getFacebook(); $this->fbuid = $this->facebook->require_login(); - + $this->action = $this->trimmed('action'); - + $app_props = $this->facebook->api_client->Admin_getAppProperties( array('canvas_name', 'application_name')); - + $this->app_uri = 'http://apps.facebook.com/' . $app_props['canvas_name']; $this->app_name = $app_props['application_name']; $this->flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE); - + return true; - + } - + function showStylesheets() { // Add a timestamp to the file so Facebook cache wont ignore our changes $ts = filemtime(INSTALLDIR.'/theme/base/css/display.css'); - $this->element('link', array('rel' => 'stylesheet', - 'type' => 'text/css', - 'href' => theme_path('css/display.css', 'base') . '?ts=' . $ts)); - + $this->element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => theme_path('css/display.css', 'base') . '?ts=' . $ts)); + $theme = common_config('site', 'theme'); - + $ts = filemtime(INSTALLDIR. '/theme/' . $theme .'/css/display.css'); - + $this->element('link', array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => theme_path('css/display.css', null) . '?ts=' . $ts)); - + $ts = filemtime(INSTALLDIR.'/theme/base/css/facebookapp.css'); - + $this->element('link', array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => theme_path('css/facebookapp.css', 'base') . '?ts=' . $ts)); } - + function showScripts() { // Add a timestamp to the file so Facebook cache wont ignore our changes $ts = filemtime(INSTALLDIR.'/js/facebookapp.js'); - + $this->element('script', array('src' => common_path('js/facebookapp.js') . '?ts=' . $ts)); } - + /** * Start an Facebook ready HTML document * @@ -138,11 +138,11 @@ class FacebookAction extends Action * @return void */ - function startHTML($type=null) - { + function startHTML($type=null) + { $this->showStylesheets(); $this->showScripts(); - + $this->elementStart('div', array('class' => 'facebook-page')); } @@ -177,18 +177,18 @@ class FacebookAction extends Action $this->showFooter(); $this->elementEnd('div'); } - + function showAside() { } function showHead($error, $success) { - + if ($error) { $this->element("h1", null, $error); } - + if ($success) { $this->element("h1", null, $success); } @@ -198,10 +198,10 @@ class FacebookAction extends Action $this->element('fb:add-section-button', array('section' => 'profile')); $this->elementEnd('span'); $this->elementEnd('fb:if-section-not-added'); - + } - + // Make this into a widget later function showLocalNav() { @@ -229,8 +229,8 @@ class FacebookAction extends Action $this->elementEnd('li'); $this->elementEnd('ul'); - } - + } + /** * Show header of the page. * @@ -245,7 +245,7 @@ class FacebookAction extends Action $this->showNoticeForm(); $this->elementEnd('div'); } - + /** * Show page, a template method. * @@ -258,7 +258,7 @@ class FacebookAction extends Action $this->showBody(); $this->endHTML(); } - + function showInstructions() { @@ -278,7 +278,7 @@ class FacebookAction extends Action $this->element('a', array('href' => common_local_url('register')), _('Register')); $this->text($loginmsg_part2); - $this->elementEnd('p'); + $this->elementEnd('p'); $this->elementEnd('dd'); $this->elementEnd('dl'); @@ -317,7 +317,7 @@ class FacebookAction extends Action $this->elementEnd('ul'); $this->submit('submit', _('Login')); - $this->elementEnd('fieldset'); + $this->elementEnd('fieldset'); $this->elementEnd('form'); $this->elementStart('p'); @@ -329,73 +329,73 @@ class FacebookAction extends Action $this->elementEnd('div'); } - - + + function updateProfileBox($notice) { // Need to include inline CSS for styling the Profile box - $app_props = $this->facebook->api_client->Admin_getAppProperties(array('icon_url')); - $icon_url = $app_props['icon_url']; + $app_props = $this->facebook->api_client->Admin_getAppProperties(array('icon_url')); + $icon_url = $app_props['icon_url']; $style = ''; + #facebook_laconica_app { + text-indent:-9999px; + height:16px; + width:16px; + display:block; + background:url('.$icon_url.') no-repeat 0 0; + float:right; + } + '; $this->xw->openMemory(); @@ -407,12 +407,12 @@ class FacebookAction extends Action $fbml_main = "$style " . $this->xw->outputMemory(false) . ""; - $this->facebook->api_client->profile_setFBML(null, $this->fbuid, $fbml, null, null, $fbml_main); + $this->facebook->api_client->profile_setFBML(null, $this->fbuid, $fbml, null, null, $fbml_main); $this->xw->openURI('php://output'); } - - + + /** * Generate pagination links * @@ -457,24 +457,24 @@ class FacebookAction extends Action $this->elementEnd('div'); } } - - function updateFacebookStatus($notice) + + function updateFacebookStatus($notice) { $prefix = $this->facebook->api_client->data_getUserPreference(FACEBOOK_NOTICE_PREFIX, $this->fbuid); $content = "$prefix $notice->content"; - + if ($this->facebook->api_client->users_hasAppPermission('status_update', $this->fbuid)) { $this->facebook->api_client->users_setStatus($content, $this->fbuid, false, true); } } - + function saveNewNotice() { $user = $this->flink->getUser(); $content = $this->trimmed('status_textarea'); - + if (!$content) { $this->showPage(_('No notice content!')); return; @@ -492,9 +492,9 @@ class FacebookAction extends Action $cmd = $inter->handle_command($user, $content_shortened); if ($cmd) { - + // XXX fix this - + $cmd->execute(new WebChannel()); return; } @@ -510,20 +510,20 @@ class FacebookAction extends Action } common_broadcast_notice($notice); - + // Also update the user's Facebook status $this->updateFacebookStatus($notice); $this->updateProfileBox($notice); - + } } -class FacebookNoticeForm extends NoticeForm +class FacebookNoticeForm extends NoticeForm { - + var $post_action = null; - + /** * Constructor * @@ -532,13 +532,13 @@ class FacebookNoticeForm extends NoticeForm * @param string $content content to pre-fill */ - function __construct($out=null, $action=null, $content=null, + function __construct($out=null, $action=null, $content=null, $post_action=null, $user=null) { parent::__construct($out, $action, $content, $user); $this->post_action = $post_action; } - + /** * Action of the form * @@ -554,7 +554,7 @@ class FacebookNoticeForm extends NoticeForm class FacebookNoticeList extends NoticeList { - + /** * constructor * @@ -565,7 +565,7 @@ class FacebookNoticeList extends NoticeList { parent::__construct($notice, $out); } - + /** * show the list of notices * @@ -619,7 +619,7 @@ class FacebookNoticeList extends NoticeList } class FacebookNoticeListItem extends NoticeListItem -{ +{ /** * constructor @@ -646,51 +646,19 @@ class FacebookNoticeListItem extends NoticeListItem function show() { $this->showStart(); + $this->showNotice(); + $this->showNoticeInfo(); - $this->out->elementStart('div', 'entry-title'); - $this->showAuthor(); - $this->showContent(); - $this->out->elementEnd('div'); - - $this->out->elementStart('div', 'entry-content'); - $this->showNoticeLink(); - $this->showNoticeSource(); - $this->showReplyTo(); - $this->out->elementEnd('div'); + // XXX: Need to update to show attachements and controls $this->showEnd(); } - function showNoticeLink() - { - $noticeurl = common_local_url('shownotice', - array('notice' => $this->notice->id)); - // XXX: we need to figure this out better. Is this right? - if (strcmp($this->notice->uri, $noticeurl) != 0 && - preg_match('/^http/', $this->notice->uri)) { - $noticeurl = $this->notice->uri; - } - - $this->out->elementStart('dl', 'timestamp'); - $this->out->element('dt', null, _('Published')); - $this->out->elementStart('dd', null); - $this->out->elementStart('a', array('rel' => 'bookmark', - 'href' => $noticeurl)); - $dt = common_date_iso8601($this->notice->created); - $this->out->element('abbr', array('class' => 'published', - 'title' => $dt), - common_date_string($this->notice->created)); - $this->out->elementEnd('a'); - $this->out->elementEnd('dd'); - $this->out->elementEnd('dl'); - } - } - class FacebookProfileBoxNotice extends FacebookNoticeListItem -{ - +{ + /** * constructor * @@ -703,36 +671,24 @@ class FacebookProfileBoxNotice extends FacebookNoticeListItem { parent::__construct($notice, $out); } - + /** - * Recipe function for displaying a single notice in the - * Facebook App's Profile + * Recipe function for displaying a single notice in the + * Facebook App profile notice box * * @return void */ function show() { - - $this->out->elementStart('div', 'entry-title'); - $this->showAuthor(); - $this->showContent(); - $this->out->elementEnd('div'); - - $this->out->elementStart('div', 'entry-content'); - - $this->showNoticeLink(); - $this->showNoticeSource(); - $this->showReplyTo(); - $this->out->elementEnd('div'); - + $this->showNotice(); + $this->showNoticeInfo(); $this->showAppLink(); - } - function showAppLink() + function showAppLink() { - + $this->facebook = getFacebook(); $app_props = $this->facebook->api_client->Admin_getAppProperties( @@ -740,7 +696,7 @@ class FacebookProfileBoxNotice extends FacebookNoticeListItem $this->app_uri = 'http://apps.facebook.com/' . $app_props['canvas_name']; $this->app_name = $app_props['application_name']; - + $this->out->elementStart('a', array('id' => 'facebook_laconica_app', 'href' => $this->app_uri)); $this->out->text($this->app_name); -- cgit v1.2.3-54-g00ecf From 2b81dcb25329c496c7c4f2c99334b79ba0421c1e Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 15 May 2009 21:44:58 +0000 Subject: Better err handling when trying to get Facebook client --- lib/facebookutil.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/facebookutil.php b/lib/facebookutil.php index ec3987273..242d2e06f 100644 --- a/lib/facebookutil.php +++ b/lib/facebookutil.php @@ -27,9 +27,21 @@ define("FACEBOOK_PROMPTED_UPDATE_PREF", 2); function getFacebook() { + static $facebook = null; + $apikey = common_config('facebook', 'apikey'); $secret = common_config('facebook', 'secret'); - return new Facebook($apikey, $secret); + + if ($facebook === null) { + $facebook = new Facebook($apikey, $secret); + } + + if (!$facebook) { + common_log(LOG_ERR, 'Could not make new Facebook client obj!', + __FILE__); + } + + return $facebook; } function updateProfileBox($facebook, $flink, $notice) { @@ -92,7 +104,6 @@ function isFacebookBound($notice, $flink) { } - function facebookBroadcastNotice($notice) { $facebook = getFacebook(); -- cgit v1.2.3-54-g00ecf From af700ea27703bbec5aa1078a84f9fd44c0260322 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Tue, 26 May 2009 21:20:04 -0400 Subject: Let's you upload a file with a notice and have it shown with other attachments. --- actions/newnotice.php | 37 +++++++++++++++++++++++++++++++++++-- js/jquery.form.js | 4 ++-- js/util.js | 12 ++++++++++++ lib/attachmentlist.php | 6 ++++-- lib/form.php | 16 +++++++++++----- lib/noticeform.php | 12 ++++++++++-- lib/noticelist.php | 11 +++++++++++ lib/router.php | 6 ++++++ 8 files changed, 91 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/actions/newnotice.php b/actions/newnotice.php index ae0ff9636..d7507c118 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -109,6 +109,10 @@ class NewnoticeAction extends Action } } + function isFileAttached() { + return $_FILES['attach']['error'] === UPLOAD_ERR_OK; + } + /** * Save a new notice, based on arguments * @@ -158,7 +162,6 @@ class NewnoticeAction extends Action $replyto = 'false'; } -// $notice = Notice::saveNew($user->id, $content_shortened, 'web', 1, $notice = Notice::saveNew($user->id, $content_shortened, 'web', 1, ($replyto == 'false') ? null : $replyto); @@ -167,6 +170,9 @@ class NewnoticeAction extends Action return; } + if ($this->isFileAttached()) { + $this->storeFile($notice); + } $this->saveUrls($notice); common_broadcast_notice($notice); @@ -194,6 +200,33 @@ class NewnoticeAction extends Action } } + function storeFile($notice) { + $filename = basename($_FILES['attach']['name']); + $destination = "file/{$notice->id}-$filename"; + if (move_uploaded_file($_FILES['attach']['tmp_name'], INSTALLDIR . "/$destination")) { + $file = new File; +// $file->url = common_local_url('file', array('notice' => $notice->id)); + $file->url = common_path($destination); + $file->size = filesize(INSTALLDIR . "/$destination"); + $file->date = time(); + $file->mimetype = $_FILES['attach']['type']; + if ($ok = $file->insert()) { + $f2p = new File_to_post; + $f2p->file_id = $ok; + $f2p->post_id = $notice->id; + $f2p->insert(); + } else { + die('inserting file, dying'); + } + } +/* + $url = common_local_url('file', array('notice' => $notice->id)); + echo "$destination
"; + die($url); +*/ + } + + /** save all urls in the notice to the db * * follow redirects and save all available file information @@ -203,7 +236,7 @@ class NewnoticeAction extends Action * * @return void */ - function saveUrls($notice) { + function saveUrls($notice, $uploaded = null) { common_replace_urls_callback($notice->content, array($this, 'saveUrl'), $notice->id); } diff --git a/js/jquery.form.js b/js/jquery.form.js index cb8b5a660..936b847ab 100644 --- a/js/jquery.form.js +++ b/js/jquery.form.js @@ -157,7 +157,7 @@ $.fn.ajaxSubmit = function(options) { function fileUpload() { var form = $form[0]; - if ($(':input[@name=submit]', form).length) { + if ($(':input[name=submit]', form).length) { alert('Error: Form elements must not be named "submit".'); return; } @@ -570,7 +570,7 @@ $.fn.clearForm = function() { $.fn.clearFields = $.fn.clearInputs = function() { return this.each(function() { var t = this.type, tag = this.tagName.toLowerCase(); - if (t == 'text' || t == 'password' || tag == 'textarea') + if (t == 'file' || t == 'text' || t == 'password' || tag == 'textarea') this.value = ''; else if (t == 'checkbox' || t == 'radio') this.checked = false; diff --git a/js/util.js b/js/util.js index b1b6ec82b..85ab48b4c 100644 --- a/js/util.js +++ b/js/util.js @@ -17,6 +17,17 @@ */ $(document).ready(function(){ + $('input#notice_data-attach').toggle(); + $('label[for=notice_data-attach]').text('Upload a file as an attachment?'); + $('label[for=notice_data-attach]').click(function () { + if ('Upload a file as an attachment?' == $(this).text()) { + $(this).text('Upload: '); + $('input#notice_data-attach').slideDown('fast'); + } else { + $('input#notice_data-attach').slideUp('fast', function() {$('label[for=notice_data-attach]').text('Upload a file as an attachment?');}); + } + }); + $('a.attachment').click(function() {$().jOverlay({url: $('address .url')[0].href+'/attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'}); return false; }); $("a.thumbnail").hover( function() { @@ -227,6 +238,7 @@ $(document).ready(function(){ } } $("#notice_data-text").val(""); + $("#notice_data-attach").val(""); counter(); } $("#form_notice").removeClass("processing"); diff --git a/lib/attachmentlist.php b/lib/attachmentlist.php index d0478bad3..a58a50f6f 100644 --- a/lib/attachmentlist.php +++ b/lib/attachmentlist.php @@ -80,13 +80,15 @@ class AttachmentList extends Widget function show() { + $atts = new File; + $att = $atts->getAttachments($this->notice->id); + if (empty($att)) return 0; + $this->out->elementStart('dl', array('id' =>'attachment')); $this->out->element('dt', null, _('Attachments')); $this->out->elementStart('dd'); $this->out->elementStart('ul', array('class' => 'attachments')); - $atts = new File; - $att = $atts->getAttachments($this->notice->id); foreach ($att as $n=>$attachment) { $item = $this->newListItem($attachment); $item->show(); diff --git a/lib/form.php b/lib/form.php index 5317df471..f872aef0b 100644 --- a/lib/form.php +++ b/lib/form.php @@ -52,6 +52,8 @@ require_once INSTALLDIR.'/lib/widget.php'; class Form extends Widget { + var $enctype = null; + /** * Show the form * @@ -63,11 +65,15 @@ class Form extends Widget function show() { - $this->out->elementStart('form', - array('id' => $this->id(), - 'class' => $this->formClass(), - 'method' => 'post', - 'action' => $this->action())); + $attributes = array('id' => $this->id(), + 'class' => $this->formClass(), + 'method' => 'post', + 'action' => $this->action()); + + if (!empty($this->enctype)) { + $attributes['enctype'] = $this->enctype; + } + $this->out->elementStart('form', $attributes); $this->out->elementStart('fieldset'); $this->formLegend(); $this->sessionToken(); diff --git a/lib/noticeform.php b/lib/noticeform.php index 606b5d028..707768cd5 100644 --- a/lib/noticeform.php +++ b/lib/noticeform.php @@ -89,7 +89,8 @@ class NoticeForm extends Form } else { $this->user = common_current_user(); } - + + $this->enctype = 'multipart/form-data'; } /** @@ -136,18 +137,25 @@ class NoticeForm extends Form { $this->out->element('label', array('for' => 'notice_data-text'), sprintf(_('What\'s up, %s?'), $this->user->nickname)); + $this->out->elementStart('span', array('style' => 'float: right; margin-top: 2em;')); +// $this->out->element('a', array('href' => '#attach'), ' [ATTACH]'); + $this->out->elementEnd('span'); // XXX: vary by defined max size $this->out->element('textarea', array('id' => 'notice_data-text', 'cols' => 35, 'rows' => 4, 'name' => 'status_textarea'), ($this->content) ? $this->content : ''); - $this->out->elementStart('dl', 'form_note'); $this->out->element('dt', null, _('Available characters')); $this->out->element('dd', array('id' => 'notice_text-count'), '140'); $this->out->elementEnd('dl'); + $this->out->element('br', array('style' => 'clear:both')); +// $this->out->elementStart('a', array('href' => '#')); + $this->out->element('label', array('for' => 'notice_data-attach'), _('Upload: ')); +// $this->out->elementEnd('a'); + $this->out->element('input', array('id' => 'notice_data-attach', 'type' => 'file', 'name' => 'attach')); if ($this->action) { $this->out->hidden('notice_return-to', $this->action, 'returnto'); diff --git a/lib/noticelist.php b/lib/noticelist.php index 50a95cfcb..420272515 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -206,6 +206,7 @@ class NoticeListItem extends Widget return 'shownotice' !== $this->out->args['action']; } +/* function attachmentCount($discriminant = true) { $file_oembed = new File_oembed; $query = "select count(*) as c from file_oembed join file_to_post on file_oembed.file_id = file_to_post.file_id where post_id=" . $this->notice->id; @@ -213,11 +214,16 @@ class NoticeListItem extends Widget $file_oembed->fetch(); return intval($file_oembed->c); } +*/ + + function showWithAttachment() { + } function showNoticeInfo() { $this->out->elementStart('div', 'entry-content'); $this->showNoticeLink(); +// $this->showWithAttachment(); $this->showNoticeSource(); $this->showContext(); $this->out->elementEnd('div'); @@ -388,6 +394,11 @@ class NoticeListItem extends Widget $this->out->element('abbr', array('class' => 'published', 'title' => $dt), common_date_string($this->notice->created)); + + $f2p = File_to_post::staticGet('post_id', $this->notice->id); + if (!empty($f2p)) { + $this->out->text(_(' (with attachments) ')); + } $this->out->elementEnd('a'); $this->out->elementEnd('dd'); $this->out->elementEnd('dl'); diff --git a/lib/router.php b/lib/router.php index fc119821b..bd482eafa 100644 --- a/lib/router.php +++ b/lib/router.php @@ -164,6 +164,12 @@ class Router array('action' => 'newnotice'), array('replyto' => '[A-Za-z0-9_-]+')); +/* + $m->connect('notice/:notice/file', + array('action' => 'file'), + array('notice' => '[0-9]+')); +*/ + $m->connect('notice/:notice', array('action' => 'shownotice'), array('notice' => '[0-9]+')); -- cgit v1.2.3-54-g00ecf From ed1e1d9f440acfbb99c7a6e3d2b5c11fdcfa27ce Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Wed, 27 May 2009 03:47:45 -0400 Subject: Handles local aliases (redirection) for file uploads attached to notices. --- .gitignore | 6 ++++++ actions/file.php | 40 ++++++++++++++++++++++++++++++++++++++++ actions/newnotice.php | 15 ++++++++++----- classes/File_redirection.php | 2 +- lib/router.php | 2 -- lib/util.php | 5 +++++ 6 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 actions/file.php (limited to 'lib') diff --git a/.gitignore b/.gitignore index da6947bfd..3418d8ee5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ avatar/* files/* +file/* _darcs/* logs/* config.php @@ -16,3 +17,8 @@ dataobject.ini .buildpath .project .settings +TODO.rym +config-*.php +good-config.php +lac08.log +php.log diff --git a/actions/file.php b/actions/file.php new file mode 100644 index 000000000..1179dbe9a --- /dev/null +++ b/actions/file.php @@ -0,0 +1,40 @@ +. + */ + +if (!defined('LACONICA')) { exit(1); } + +require_once(INSTALLDIR.'/actions/shownotice.php'); + +class FileAction extends ShowNoticeAction +{ + function showPage() { + $source_url = common_local_url('file', array('notice' => $this->notice->id)); + $query = "select file_redirection.url as url from file join file_redirection on file.id = file_redirection.file_id where file.url = '$source_url'"; + $file = new File_redirection; + $file->query($query); + $file->fetch(); + if (empty($file->url)) { + die('nothing attached here'); + } else { + header("Location: {$file->url}"); + die(); + } + } +} + diff --git a/actions/newnotice.php b/actions/newnotice.php index d7507c118..aebdab3cc 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -110,7 +110,7 @@ class NewnoticeAction extends Action } function isFileAttached() { - return $_FILES['attach']['error'] === UPLOAD_ERR_OK; + return isset($_FILES['attach']['error']) && ($_FILES['attach']['error'] === UPLOAD_ERR_OK); } /** @@ -205,14 +205,19 @@ class NewnoticeAction extends Action $destination = "file/{$notice->id}-$filename"; if (move_uploaded_file($_FILES['attach']['tmp_name'], INSTALLDIR . "/$destination")) { $file = new File; -// $file->url = common_local_url('file', array('notice' => $notice->id)); - $file->url = common_path($destination); + $file->url = common_local_url('file', array('notice' => $notice->id)); +// $file->url = common_path($destination); $file->size = filesize(INSTALLDIR . "/$destination"); $file->date = time(); $file->mimetype = $_FILES['attach']['type']; - if ($ok = $file->insert()) { + if ($file_id = $file->insert()) { + $file_redir = new File_redirection; + $file_redir->url = common_path($destination); + $file_redir->file_id = $file_id; + $file_redir->insert(); + $f2p = new File_to_post; - $f2p->file_id = $ok; + $f2p->file_id = $file_id; $f2p->post_id = $notice->id; $f2p->insert(); } else { diff --git a/classes/File_redirection.php b/classes/File_redirection.php index 0eae68178..212cc3615 100644 --- a/classes/File_redirection.php +++ b/classes/File_redirection.php @@ -133,7 +133,7 @@ class File_redirection extends Memcached_DataObject $file->limit(1); $file->orderBy('len'); $file->find(true); - if (!empty($file->id)) { + if (!empty($file->url) && (strlen($file->url) < strlen($long_url))) { return $file->url; } diff --git a/lib/router.php b/lib/router.php index bd482eafa..456d1793e 100644 --- a/lib/router.php +++ b/lib/router.php @@ -164,11 +164,9 @@ class Router array('action' => 'newnotice'), array('replyto' => '[A-Za-z0-9_-]+')); -/* $m->connect('notice/:notice/file', array('action' => 'file'), array('notice' => '[0-9]+')); -*/ $m->connect('notice/:notice', array('action' => 'shownotice'), diff --git a/lib/util.php b/lib/util.php index d56f44f7b..ab1272309 100644 --- a/lib/util.php +++ b/lib/util.php @@ -499,6 +499,11 @@ function common_linkify($url) { // if this URL is an attachment, then we set class='attachment' and id='attahcment-ID' // where ID is the id of the attachment for the given URL. +// +// we need a better test telling what can be shown as an attachment +// we're currently picking up oembeds only. +// I think the best option is another file_view table in the db +// and associated dbobject. $query = "select file_oembed.file_id as file_id from file join file_oembed on file.id = file_oembed.file_id where file.url='$longurl'"; $file = new File; $file->query($query); -- cgit v1.2.3-54-g00ecf From d068680e1913a32eba0f5b0e1e746ac66ec638d3 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 27 May 2009 14:57:45 -0400 Subject: optionally use SET NAMES for utf8 to DB --- README | 4 ++++ classes/Memcached_DataObject.php | 4 +++- lib/common.php | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/README b/README index 7b2dcacc5..c23d4e464 100644 --- a/README +++ b/README @@ -906,6 +906,10 @@ mirror: you can set this to an array of DSNs, like the above and adding the slaves to this array. Note that if you want some requests to go to the 'database' (master) server, you'll need to include it in this array, too. +utf8: whether to talk to the database in UTF-8 mode. This is the default + with new installations, but older sites may want to turn it off + until they get their databases fixed up. See "UTF-8 database" + above for details. syslog ------ diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index 877bbf2e0..52ad4100f 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -239,7 +239,9 @@ class Memcached_DataObject extends DB_DataObject $result = parent::_connect(); if (!$exists) { $DB = &$_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]; - $DB->query('SET NAMES "utf8"'); + if (common_config('db', 'utf8')) { + $DB->query('SET NAMES "utf8"'); + } } return $result; } diff --git a/lib/common.php b/lib/common.php index f983c4d16..8f95c2361 100644 --- a/lib/common.php +++ b/lib/common.php @@ -167,6 +167,7 @@ $config['db'] = 'require_prefix' => 'classes/', 'class_prefix' => '', 'mirror' => null, + 'utf8' => true, 'db_driver' => 'DB', # XXX: JanRain libs only work with DB 'quote_identifiers' => false, 'type' => 'mysql' ); -- cgit v1.2.3-54-g00ecf From 60ac9bc6fda74278d98890a2c26f3834acad8222 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Wed, 27 May 2009 19:43:43 +0000 Subject: Bunch of UI fixes/improvements for attachments (hover, overlay, notice view, clip) --- js/util.js | 72 ++++++++++++++-------- lib/attachmentlist.php | 6 +- theme/base/css/display.css | 67 +++++++++++++++----- theme/base/images/icons/twotone/green/clip-02.gif | Bin 0 -> 70 bytes theme/default/css/display.css | 6 ++ theme/identica/css/display.css | 6 ++ 6 files changed, 116 insertions(+), 41 deletions(-) create mode 100644 theme/base/images/icons/twotone/green/clip-02.gif (limited to 'lib') diff --git a/js/util.js b/js/util.js index b1b6ec82b..08cc1d370 100644 --- a/js/util.js +++ b/js/util.js @@ -17,30 +17,6 @@ */ $(document).ready(function(){ - $('a.attachment').click(function() {$().jOverlay({url: $('address .url')[0].href+'/attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'}); return false; }); - $("a.thumbnail").hover( - function() { - var anchor = $(this); - $("a.thumbnail").children('img').remove(); - - setTimeout(function() { - anchor.closest(".entry-title").addClass('ov'); - $.get($('address .url')[0].href+'/attachment/' + (anchor.attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) { - anchor.append(data); - }); - }, 250); - - setTimeout(function() { - anchor.children('img').remove(); - anchor.closest(".entry-title").removeClass('ov'); - }, 3000); - }, - function() { - $(this).children('img').remove(); - $(this).closest(".entry-title").removeClass('ov'); - } - ); - // count character on keyup function counter(event){ var maxLength = 140; @@ -238,6 +214,7 @@ $(document).ready(function(){ $("#form_notice").each(addAjaxHidden); NoticeHover(); NoticeReply(); + NoticeAttachments(); }); @@ -276,3 +253,50 @@ function NoticeReplySet(nick,id) { } return true; } + +function NoticeAttachments() { + $.fn.jOverlay.options = { + method : 'GET', + data : '', + url : '', + color : '#000', + opacity : '0.6', + zIndex : 9999, + center : true, + imgLoading : $('address .url')[0].href+'theme/base/images/illustrations/illu_progress_loading-01.gif', + bgClickToClose : true, + success : function() { + $('#jOverlayContent').append(''); + $('#jOverlayContent button').click($.closeOverlay); + }, + timeout : 0 + }; + + $('a.attachment').click(function() { + $().jOverlay({url: $('address .url')[0].href+'/attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'}); + return false; + }); + $("body:not(#shownotice) a.thumbnail").hover( + function() { + var anchor = $(this); + $("a.thumbnail").children('img').remove(); + anchor.closest(".entry-title").addClass('ov'); + + setTimeout(function() { + $.get($('address .url')[0].href+'/attachment/' + (anchor.attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) { + anchor.append(data); + }); + }, 500); + + setTimeout(function() { + anchor.children('img').remove(); + anchor.closest(".entry-title").removeClass('ov'); + }, 3000); + }, + function() { + $("a.thumbnail").children('img').remove(); + $(this).closest(".entry-title").removeClass('ov'); + } + ); +} + diff --git a/lib/attachmentlist.php b/lib/attachmentlist.php index d0478bad3..559962acc 100644 --- a/lib/attachmentlist.php +++ b/lib/attachmentlist.php @@ -80,10 +80,10 @@ class AttachmentList extends Widget function show() { - $this->out->elementStart('dl', array('id' =>'attachment')); + $this->out->elementStart('dl', array('id' =>'attachments')); $this->out->element('dt', null, _('Attachments')); $this->out->elementStart('dd'); - $this->out->elementStart('ul', array('class' => 'attachments')); + $this->out->elementStart('ol', array('class' => 'attachments')); $atts = new File; $att = $atts->getAttachments($this->notice->id); @@ -93,7 +93,7 @@ class AttachmentList extends Widget } $this->out->elementEnd('dd'); - $this->out->elementEnd('ul'); + $this->out->elementEnd('ol'); $this->out->elementEnd('dl'); return count($att); diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 9bc1417b1..16c9e3c00 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -855,20 +855,6 @@ display:inline-block; text-transform:lowercase; } -.notice .attachment { -position:relative; -} -.notice .attachment img { -position:absolute; -top:18px; -left:0; -z-index:99; -} -#shownotice .notice .attachment img { -position:static; -} - - .notice-options { position:relative; font-size:0.95em; @@ -936,6 +922,59 @@ padding:0; } +.notice .attachment { +position:relative; +padding-left:16px; +} +#attachments .attachment { +padding-left:0; +} +.notice .attachment img { +position:absolute; +top:18px; +left:0; +z-index:99; +} +#shownotice .notice .attachment img { +position:static; +} + +#attachments { +clear:both; +float:left; +width:100%; +margin-top:18px; +} +#attachments dt { +font-weight:bold; +font-size:1.3em; +margin-bottom:4px; +} + +#attachments li { +margin-bottom:18px; +list-style-type:decimal; +float:left; +clear:both; +} + +#jOverlayContent, +#jOverlayContent #content { +width: auto !important; +} +#jOverlayContent .external span { +display:block; +margin-bottom:11px; +} +#jOverlayContent button { +position:absolute; +top:0; +right:0; +padding:3px 4px; +font-weight:bold; +} + + #usergroups #new_group { float: left; margin-right: 2em; diff --git a/theme/base/images/icons/twotone/green/clip-02.gif b/theme/base/images/icons/twotone/green/clip-02.gif new file mode 100644 index 000000000..77a729799 Binary files /dev/null and b/theme/base/images/icons/twotone/green/clip-02.gif differ diff --git a/theme/default/css/display.css b/theme/default/css/display.css index 737db7ce9..e08a4783b 100644 --- a/theme/default/css/display.css +++ b/theme/default/css/display.css @@ -175,6 +175,12 @@ background-image:url(../../base/images/icons/twotone/green/shield.gif); } /* NOTICES */ +.notice .attachment { +background:transparent url(../../base/images/icons/twotone/green/clip-02.gif) no-repeat 0 45%; +} +#attachments .attachment { +background:none; +} .notice-options .notice_reply a, .notice-options form input.submit { background-color:transparent; diff --git a/theme/identica/css/display.css b/theme/identica/css/display.css index f7abac482..1f1298737 100644 --- a/theme/identica/css/display.css +++ b/theme/identica/css/display.css @@ -175,6 +175,12 @@ background-image:url(../../base/images/icons/twotone/green/shield.gif); } /* NOTICES */ +.notice .attachment { +background:transparent url(../../base/images/icons/twotone/green/clip-02.gif) no-repeat 0 45%; +} +#attachments .attachment { +background:none; +} .notice-options .notice_reply a, .notice-options form input.submit { background-color:transparent; -- cgit v1.2.3-54-g00ecf From b8de7935568e631bc99aec6120f2bc4090f50fec Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 29 May 2009 02:38:38 +0000 Subject: Changed ul to ol and added xoxo for notice lists. --- actions/conversation.php | 10 +++++----- actions/shownotice.php | 4 ++-- lib/noticelist.php | 4 ++-- lib/noticesection.php | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/actions/conversation.php b/actions/conversation.php index ef189016a..0d7cb9a87 100644 --- a/actions/conversation.php +++ b/actions/conversation.php @@ -179,14 +179,14 @@ class ConversationTree extends NoticeList $this->out->elementStart('div', array('id' =>'notices_primary')); $this->out->element('h2', null, _('Notices')); - $this->out->elementStart('ul', array('class' => 'notices')); + $this->out->elementStart('ol', array('class' => 'notices xoxo')); if (array_key_exists('root', $this->tree)) { $rootid = $this->tree['root'][0]; $this->showNoticePlus($rootid); } - $this->out->elementEnd('ul'); + $this->out->elementEnd('ol'); $this->out->elementEnd('div'); return $cnt; @@ -215,13 +215,13 @@ class ConversationTree extends NoticeList if (array_key_exists($id, $this->tree)) { $children = $this->tree[$id]; - $this->out->elementStart('ul', array('class' => 'notices')); + $this->out->elementStart('ol', array('class' => 'notices')); foreach ($children as $child) { $this->showNoticePlus($child); } - $this->out->elementEnd('ul'); + $this->out->elementEnd('ol'); } $this->out->elementEnd('li'); @@ -295,4 +295,4 @@ class ConversationTreeItem extends NoticeListItem { return; } -} \ No newline at end of file +} diff --git a/actions/shownotice.php b/actions/shownotice.php index 2c469c9de..34c8a8e94 100644 --- a/actions/shownotice.php +++ b/actions/shownotice.php @@ -208,10 +208,10 @@ class ShownoticeAction extends Action function showContent() { - $this->elementStart('ul', array('class' => 'notices')); + $this->elementStart('ol', array('class' => 'notices xoxo')); $nli = new NoticeListItem($this->notice, $this); $nli->show(); - $this->elementEnd('ul'); + $this->elementEnd('ol'); } /** diff --git a/lib/noticelist.php b/lib/noticelist.php index 50a95cfcb..0e80a9778 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -86,7 +86,7 @@ class NoticeList extends Widget { $this->out->elementStart('div', array('id' =>'notices_primary')); $this->out->element('h2', null, _('Notices')); - $this->out->elementStart('ul', array('class' => 'notices')); + $this->out->elementStart('ol', array('class' => 'notices xoxo')); $cnt = 0; @@ -101,7 +101,7 @@ class NoticeList extends Widget $item->show(); } - $this->out->elementEnd('ul'); + $this->out->elementEnd('ol'); $this->out->elementEnd('div'); return $cnt; diff --git a/lib/noticesection.php b/lib/noticesection.php index 37aafdaf6..ca1432686 100644 --- a/lib/noticesection.php +++ b/lib/noticesection.php @@ -52,12 +52,12 @@ class NoticeSection extends Section { $notices = $this->getNotices(); $cnt = 0; - $this->out->elementStart('ul', 'notices'); + $this->out->elementStart('ol', 'notices xoxo'); while ($notices->fetch() && ++$cnt <= NOTICES_PER_SECTION) { $this->showNotice($notices); } - $this->out->elementEnd('ul'); + $this->out->elementEnd('ol'); return ($cnt > NOTICES_PER_SECTION); } -- cgit v1.2.3-54-g00ecf From 3e0c291810d23bb54c337c0fe95c1ba441459c4c Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Sun, 31 May 2009 16:42:29 -0400 Subject: Added configurable options for attachments: supported mimetypes and quotas for uploads. --- actions/newnotice.php | 118 ++++++++-- config.php.sample | 8 + extlib/MIME/Type.php | 523 +++++++++++++++++++++++++++++++++++++++++ extlib/MIME/Type/Extension.php | 298 +++++++++++++++++++++++ extlib/MIME/Type/Parameter.php | 163 +++++++++++++ lib/common.php | 56 ++++- 6 files changed, 1136 insertions(+), 30 deletions(-) create mode 100644 extlib/MIME/Type.php create mode 100644 extlib/MIME/Type/Extension.php create mode 100644 extlib/MIME/Type/Parameter.php (limited to 'lib') diff --git a/actions/newnotice.php b/actions/newnotice.php index aebdab3cc..29b748dd1 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -84,20 +84,24 @@ class NewnoticeAction extends Action function handle($args) { - parent::handle($args); - if (!common_logged_in()) { $this->clientError(_('Not logged in.')); } else if ($_SERVER['REQUEST_METHOD'] == 'POST') { + // check for this before token since all POST and FILES data + // is losts when size is exceeded + if (empty($_POST) && $_SERVER['CONTENT_LENGTH']) { + $this->clientError(sprintf(_('The server was unable to handle ' . + 'that much POST data (%s bytes) due to its current configuration.'), + $_SERVER['CONTENT_LENGTH'])); + } + parent::handle($args); // CSRF protection $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { $this->clientError(_('There was a problem with your session token. '. 'Try again, please.')); - return; } - try { $this->saveNewNotice(); } catch (Exception $e) { @@ -109,8 +113,55 @@ class NewnoticeAction extends Action } } - function isFileAttached() { - return isset($_FILES['attach']['error']) && ($_FILES['attach']['error'] === UPLOAD_ERR_OK); + function isSupportedFileType() { + require_once 'MIME/Type.php'; + + $filetype = MIME_Type::autoDetect($_FILES['attach']['tmp_name']); + if (in_array($filetype, common_config('attachments', 'supported'))) { + return true; + } + $media = MIME_Type::getMedia($filetype); + if ('application' !== $media) { + $hint = sprintf(_(' Try using another %s format.'), $media); + } else { + $hint = ''; + } + $this->clientError(sprintf( + _('%s is not a supported filetype on this server.'), $filetype) . $hint); + } + + function isRespectsQuota($user) { + if ($_FILES['attach']['size'] > common_config('attachments', 'file_quota')) { + $this->clientError(sprintf(_('No file may be larger than %d bytes ' . + 'and the file you sent was %d bytes. Try to upload a smaller version.'), + common_config('attachments', 'file_quota'), $_FILES['attach']['size'])); + } + + $query = "select sum(size) as total from file join file_to_post on file_to_post.file_id = file.id join notice on file_to_post.post_id = notice.id where profile_id = {$user->id} and file.url like '%/notice/%/file'"; + $file = new File; + $file->query($query); + $file->fetch(); + $total = $file->total + $_FILES['attach']['size']; + if ($total > common_config('attachments', 'user_quota')) { + $this->clientError(sprintf(_('A file this large would exceed your user quota of %d bytes.'), common_config('attachments', 'user_quota'))); + } + + $query .= ' month(modified) = month(now()) and year(modified) = year(now())'; + $file2 = new File; + $file2->query($query); + $file2->fetch(); + $total2 = $file2->total + $_FILES['attach']['size']; + if ($total2 > common_config('attachments', 'monthly_quota')) { + $this->clientError(sprintf(_('A file this large would exceed your monthly quota of %d bytes.'), common_config('attachments', 'monthly_quota'))); + } + return true; + } + + function isValidFileAttached($user) { + return isset($_FILES['attach']['error']) + && ($_FILES['attach']['error'] === UPLOAD_ERR_OK) + && $this->isSupportedFileType() + && $this->isRespectsQuota($user); } /** @@ -135,7 +186,6 @@ class NewnoticeAction extends Action $this->clientError(_('No content!')); } else { $content_shortened = common_shorten_links($content); - if (mb_strlen($content_shortened) > 140) { $this->clientError(_('That\'s too long. '. 'Max notice size is 140 chars.')); @@ -162,19 +212,54 @@ class NewnoticeAction extends Action $replyto = 'false'; } + switch ($_FILES['attach']['error']) { + case UPLOAD_ERR_NO_FILE: + // no file uploaded + // nothing to do + break; + + case UPLOAD_ERR_OK: + // file was uploaded alright + // lets check if we really support its format + // and it doesn't go over quotas + + + if (!$this->isValidFileAttached($user)) { + die('clientError() should trigger an exception before reaching here.'); + } + break; + + case UPLOAD_ERR_INI_SIZE: + $this->clientError(_('The uploaded file exceeds the upload_max_filesize directive in php.ini.')); + + case UPLOAD_ERR_FORM_SIZE: + $this->clientError(_('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.')); + + case UPLOAD_ERR_PARTIAL: + $this->clientError(_('The uploaded file was only partially uploaded.')); + + case UPLOAD_ERR_NO_TMP_DIR: + $this->clientError(_('Missing a temporary folder.')); + + case UPLOAD_ERR_CANT_WRITE: + $this->clientError(_('Failed to write file to disk.')); + + case UPLOAD_ERR_EXTENSION: + $this->clientError(_('File upload stopped by extension.')); + + default: + die('Should never reach here.'); + } + $notice = Notice::saveNew($user->id, $content_shortened, 'web', 1, ($replyto == 'false') ? null : $replyto); if (is_string($notice)) { $this->clientError($notice); - return; } - if ($this->isFileAttached()) { - $this->storeFile($notice); - } + $this->storeFile($notice); $this->saveUrls($notice); - common_broadcast_notice($notice); if ($this->boolean('ajax')) { @@ -201,12 +286,12 @@ class NewnoticeAction extends Action } function storeFile($notice) { + if (UPLOAD_ERR_NO_FILE === $_FILES['attach']['error']) return; $filename = basename($_FILES['attach']['name']); $destination = "file/{$notice->id}-$filename"; if (move_uploaded_file($_FILES['attach']['tmp_name'], INSTALLDIR . "/$destination")) { $file = new File; $file->url = common_local_url('file', array('notice' => $notice->id)); -// $file->url = common_path($destination); $file->size = filesize(INSTALLDIR . "/$destination"); $file->date = time(); $file->mimetype = $_FILES['attach']['type']; @@ -221,14 +306,9 @@ class NewnoticeAction extends Action $f2p->post_id = $notice->id; $f2p->insert(); } else { - die('inserting file, dying'); + $this->clientError(_('There was a database error while saving your file. Please try again.')); } } -/* - $url = common_local_url('file', array('notice' => $notice->id)); - echo "$destination
"; - die($url); -*/ } diff --git a/config.php.sample b/config.php.sample index 282826a7f..636f4cf8e 100644 --- a/config.php.sample +++ b/config.php.sample @@ -215,3 +215,11 @@ $config['sphinx']['port'] = 3312; // $config['snapshot']['run'] = 'never'; // If you want to report statistics in a cron job instead. // $config['snapshot']['run'] = 'cron'; + +// Support for file uploads (attachments), +// select supported mimetypes and quotas (in bytes) +// $config['attachments']['supported'] = array('image/png', 'application/ogg'); +// $config['attachments']['file_quota'] = 5000000; +// $config['attachments']['user_quota'] = 50000000; +// $config['attachments']['monthly_quota'] = 15000000; + diff --git a/extlib/MIME/Type.php b/extlib/MIME/Type.php new file mode 100644 index 000000000..c335f8d92 --- /dev/null +++ b/extlib/MIME/Type.php @@ -0,0 +1,523 @@ + | +// +----------------------------------------------------------------------+ +// +// $Id: Type.php,v 1.6 2009/01/16 11:49:45 cweiske Exp $ + +require_once 'PEAR.php'; + +$_fileCmd = &PEAR::getStaticProperty('MIME_Type', 'fileCmd'); +$_fileCmd = 'file'; + +/** + * Class for working with MIME types + * + * @category MIME + * @package MIME_Type + * @license PHP License 3.0 + * @version 1.2.0 + * @link http://pear.php.net/package/MIME_Type + * @author Ian Eure + */ +class MIME_Type +{ + /** + * The MIME media type + * + * @var string + */ + var $media = ''; + + /** + * The MIME media sub-type + * + * @var string + */ + var $subType = ''; + + /** + * Optional MIME parameters + * + * @var array + */ + var $parameters = array(); + + /** + * List of valid media types. + * A media type is the string in front of the slash. + * The media type of "text/xml" would be "text". + * + * @var array + */ + var $validMediaTypes = array( + 'text', + 'image', + 'audio', + 'video', + 'application', + 'multipart', + 'message' + ); + + + /** + * Constructor. + * + * If $type is set, if will be parsed and the appropriate class vars set. + * If not, you get an empty class. + * This is useful, but not quite as useful as parsing a type. + * + * @param string $type MIME type + * + * @return void + */ + function MIME_Type($type = false) + { + if ($type) { + $this->parse($type); + } + } + + + /** + * Parse a mime-type and set the class variables. + * + * @param string $type MIME type to parse + * + * @return void + */ + function parse($type) + { + $this->media = $this->getMedia($type); + $this->subType = $this->getSubType($type); + $this->parameters = array(); + if (MIME_Type::hasParameters($type)) { + require_once 'MIME/Type/Parameter.php'; + foreach (MIME_Type::getParameters($type) as $param) { + $param = new MIME_Type_Parameter($param); + $this->parameters[$param->name] = $param; + } + } + } + + + /** + * Does this type have any parameters? + * + * @param string $type MIME type to check + * + * @return boolean true if $type has parameters, false otherwise + * @static + */ + function hasParameters($type) + { + if (strstr($type, ';')) { + return true; + } + return false; + } + + + /** + * Get a MIME type's parameters + * + * @param string $type MIME type to get parameters of + * + * @return array $type's parameters + * @static + */ + function getParameters($type) + { + $params = array(); + $tmp = explode(';', $type); + for ($i = 1; $i < count($tmp); $i++) { + $params[] = trim($tmp[$i]); + } + return $params; + } + + + /** + * Strip parameters from a MIME type string. + * + * @param string $type MIME type string + * + * @return string MIME type with parameters removed + * @static + */ + function stripParameters($type) + { + if (strstr($type, ';')) { + return substr($type, 0, strpos($type, ';')); + } + return $type; + } + + + /** + * Removes comments from a media type, subtype or parameter. + * + * @param string $string String to strip comments from + * @param string &$comment Comment is stored in there. + * + * @return string String without comments + * @static + */ + function stripComments($string, &$comment) + { + if (strpos($string, '(') === false) { + return $string; + } + + $inquote = false; + $quoting = false; + $incomment = 0; + $newstring = ''; + + for ($n = 0; $n < strlen($string); $n++) { + if ($quoting) { + if ($incomment == 0) { + $newstring .= $string[$n]; + } else if ($comment !== null) { + $comment .= $string[$n]; + } + $quoting = false; + } else if ($string[$n] == '\\') { + $quoting = true; + } else if (!$inquote && $incomment > 0 && $string[$n] == ')') { + $incomment--; + if ($incomment == 0 && $comment !== null) { + $comment .= ' '; + } + } else if (!$inquote && $string[$n] == '(') { + $incomment++; + } else if ($string[$n] == '"') { + if ($inquote) { + $inquote = false; + } else { + $inquote = true; + } + } else if ($incomment == 0) { + $newstring .= $string[$n]; + } else if ($comment !== null) { + $comment .= $string[$n]; + } + } + + if ($comment !== null) { + $comment = trim($comment); + } + + return $newstring; + } + + + /** + * Get a MIME type's media + * + * @note 'media' refers to the portion before the first slash + * + * @param string $type MIME type to get media of + * + * @return string $type's media + * @static + */ + function getMedia($type) + { + $tmp = explode('/', $type); + return strtolower(trim(MIME_Type::stripComments($tmp[0], $null))); + } + + + /** + * Get a MIME type's subtype + * + * @param string $type MIME type to get subtype of + * + * @return string $type's subtype, null if invalid mime type + * @static + */ + function getSubType($type) + { + $tmp = explode('/', $type); + if (!isset($tmp[1])) { + return null; + } + $tmp = explode(';', $tmp[1]); + return strtolower(trim(MIME_Type::stripComments($tmp[0], $null))); + } + + + /** + * Create a textual MIME type from object values + * + * This function performs the opposite function of parse(). + * + * @return string MIME type string + */ + function get() + { + $type = strtolower($this->media . '/' . $this->subType); + if (count($this->parameters)) { + foreach ($this->parameters as $key => $null) { + $type .= '; ' . $this->parameters[$key]->get(); + } + } + return $type; + } + + + /** + * Is this type experimental? + * + * @note Experimental types are denoted by a leading 'x-' in the media or + * subtype, e.g. text/x-vcard or x-world/x-vrml. + * + * @param string $type MIME type to check + * + * @return boolean true if $type is experimental, false otherwise + * @static + */ + function isExperimental($type) + { + if (substr(MIME_Type::getMedia($type), 0, 2) == 'x-' || + substr(MIME_Type::getSubType($type), 0, 2) == 'x-') { + return true; + } + return false; + } + + + /** + * Is this a vendor MIME type? + * + * @note Vendor types are denoted with a leading 'vnd. in the subtype. + * + * @param string $type MIME type to check + * + * @return boolean true if $type is a vendor type, false otherwise + * @static + */ + function isVendor($type) + { + if (substr(MIME_Type::getSubType($type), 0, 4) == 'vnd.') { + return true; + } + return false; + } + + + /** + * Is this a wildcard type? + * + * @param string $type MIME type to check + * + * @return boolean true if $type is a wildcard, false otherwise + * @static + */ + function isWildcard($type) + { + if ($type == '*/*' || MIME_Type::getSubtype($type) == '*') { + return true; + } + return false; + } + + + /** + * Perform a wildcard match on a MIME type + * + * Example: + * MIME_Type::wildcardMatch('image/*', 'image/png') + * + * @param string $card Wildcard to check against + * @param string $type MIME type to check + * + * @return boolean true if there was a match, false otherwise + * @static + */ + function wildcardMatch($card, $type) + { + if (!MIME_Type::isWildcard($card)) { + return false; + } + + if ($card == '*/*') { + return true; + } + + if (MIME_Type::getMedia($card) == MIME_Type::getMedia($type)) { + return true; + } + + return false; + } + + + /** + * Add a parameter to this type + * + * @param string $name Attribute name + * @param string $value Attribute value + * @param string $comment Comment for this parameter + * + * @return void + */ + function addParameter($name, $value, $comment = false) + { + $tmp = new MIME_Type_Parameter(); + + $tmp->name = $name; + $tmp->value = $value; + $tmp->comment = $comment; + $this->parameters[$name] = $tmp; + } + + + /** + * Remove a parameter from this type + * + * @param string $name Parameter name + * + * @return void + */ + function removeParameter($name) + { + unset($this->parameters[$name]); + } + + + /** + * Autodetect a file's MIME-type + * + * This function may be called staticly. + * + * @internal Tries to use fileinfo extension at first. If that + * does not work, mime_magic is used. If this is also not available + * or does not succeed, "file" command is tried to be executed with + * System_Command. When that fails, too, then we use our in-built + * extension-to-mimetype-mapping list. + * + * @param string $file Path to the file to get the type of + * @param bool $params Append MIME parameters if true + * + * @return string $file's MIME-type on success, PEAR_Error otherwise + * + * @since 1.0.0beta1 + * @static + */ + function autoDetect($file, $params = false) + { + // Sanity checks + if (!file_exists($file)) { + return PEAR::raiseError("File \"$file\" doesn't exist"); + } + + if (!is_readable($file)) { + return PEAR::raiseError("File \"$file\" is not readable"); + } + + if (function_exists('finfo_file')) { + $finfo = finfo_open(FILEINFO_MIME); + $type = finfo_file($finfo, $file); + finfo_close($finfo); + if ($type !== false && $type !== '') { + return MIME_Type::_handleDetection($type, $params); + } + } + + if (function_exists('mime_content_type')) { + $type = mime_content_type($file); + if ($type !== false && $type !== '') { + return MIME_Type::_handleDetection($type, $params); + } + } + + @include_once 'System/Command.php'; + if (class_exists('System_Command')) { + return MIME_Type::_handleDetection( + MIME_Type::_fileAutoDetect($file), + $params + ); + } + + require_once 'MIME/Type/Extension.php'; + $mte = new MIME_Type_Extension(); + return $mte->getMIMEType($file); + } + + + /** + * Handles a detected MIME type and modifies it if necessary. + * + * @param string $type MIME Type of a file + * @param bool $params Append MIME parameters if true + * + * @return string $file's MIME-type on success, PEAR_Error otherwise + */ + function _handleDetection($type, $params) + { + // _fileAutoDetect() may have returned an error. + if (PEAR::isError($type)) { + return $type; + } + + // Don't return an empty string + if (!$type || !strlen($type)) { + return PEAR::raiseError("Sorry, couldn't determine file type."); + } + + // Strip parameters if present & requested + if (MIME_Type::hasParameters($type) && !$params) { + $type = MIME_Type::stripParameters($type); + } + + return $type; + } + + + /** + * Autodetect a file's MIME-type with 'file' and System_Command + * + * This function may be called staticly. + * + * @param string $file Path to the file to get the type of + * + * @return string $file's MIME-type + * + * @since 1.0.0beta1 + * @static + */ + function _fileAutoDetect($file) + { + $cmd = new System_Command(); + + // Make sure we have the 'file' command. + $fileCmd = PEAR::getStaticProperty('MIME_Type', 'fileCmd'); + if (!$cmd->which($fileCmd)) { + unset($cmd); + return PEAR::raiseError("Can't find file command \"{$fileCmd}\""); + } + + $cmd->pushCommand($fileCmd, "-bi " . escapeshellarg($file)); + $res = $cmd->execute(); + unset($cmd); + + return $res; + } +} + diff --git a/extlib/MIME/Type/Extension.php b/extlib/MIME/Type/Extension.php new file mode 100644 index 000000000..1987e2a10 --- /dev/null +++ b/extlib/MIME/Type/Extension.php @@ -0,0 +1,298 @@ + | +// +----------------------------------------------------------------------+ +// +// $Id: Extension.php,v 1.1 2009/01/16 11:49:45 cweiske Exp $ + +require_once 'PEAR.php'; + +/** + * Class for mapping file extensions to MIME types. + * + * @category MIME + * @package MIME_Type + * @author Christian Schmidt + * @license PHP License 3.0 + * @version 1.2.0 + * @link http://pear.php.net/package/MIME_Type + */ +class MIME_Type_Extension +{ + /** + * Mapping between file extension and MIME type. + * + * @internal The array is sorted alphabetically by value and with primary + * extension first. Be careful about not adding duplicate keys - PHP + * silently ignores duplicates. The following command can be used for + * checking for duplicates: + * grep "=> '" Extension.php | cut -d\' -f2 | sort | uniq -d + * application/octet-stream is generally used as fallback when no other + * MIME-type can be found, but the array does not contain a lot of such + * unknown extension. One entry exists, though, to allow detection of + * file extension for this MIME-type. + * + * @var array + */ + var $extensionToType = array ( + 'ez' => 'application/andrew-inset', + 'atom' => 'application/atom+xml', + 'jar' => 'application/java-archive', + 'hqx' => 'application/mac-binhex40', + 'cpt' => 'application/mac-compactpro', + 'mathml' => 'application/mathml+xml', + 'doc' => 'application/msword', + 'dat' => 'application/octet-stream', + 'oda' => 'application/oda', + 'ogg' => 'application/ogg', + 'pdf' => 'application/pdf', + 'ai' => 'application/postscript', + 'eps' => 'application/postscript', + 'ps' => 'application/postscript', + 'rdf' => 'application/rdf+xml', + 'rss' => 'application/rss+xml', + 'smi' => 'application/smil', + 'smil' => 'application/smil', + 'gram' => 'application/srgs', + 'grxml' => 'application/srgs+xml', + 'kml' => 'application/vnd.google-earth.kml+xml', + 'kmz' => 'application/vnd.google-earth.kmz', + 'mif' => 'application/vnd.mif', + 'xul' => 'application/vnd.mozilla.xul+xml', + 'xls' => 'application/vnd.ms-excel', + 'xlb' => 'application/vnd.ms-excel', + 'xlt' => 'application/vnd.ms-excel', + 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', + 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', + 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12', + 'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12', + 'docm' => 'application/vnd.ms-word.document.macroEnabled.12', + 'dotm' => 'application/vnd.ms-word.template.macroEnabled.12', + 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', + 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', + 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', + 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', + 'ppt' => 'application/vnd.ms-powerpoint', + 'pps' => 'application/vnd.ms-powerpoint', + 'odc' => 'application/vnd.oasis.opendocument.chart', + 'odb' => 'application/vnd.oasis.opendocument.database', + 'odf' => 'application/vnd.oasis.opendocument.formula', + 'odg' => 'application/vnd.oasis.opendocument.graphics', + 'otg' => 'application/vnd.oasis.opendocument.graphics-template', + 'odi' => 'application/vnd.oasis.opendocument.image', + 'odp' => 'application/vnd.oasis.opendocument.presentation', + 'otp' => 'application/vnd.oasis.opendocument.presentation-template', + 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', + 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', + 'odt' => 'application/vnd.oasis.opendocument.text', + 'odm' => 'application/vnd.oasis.opendocument.text-master', + 'ott' => 'application/vnd.oasis.opendocument.text-template', + 'oth' => 'application/vnd.oasis.opendocument.text-web', + 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', + 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', + 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', + 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', + 'vsd' => 'application/vnd.visio', + 'wbxml' => 'application/vnd.wap.wbxml', + 'wmlc' => 'application/vnd.wap.wmlc', + 'wmlsc' => 'application/vnd.wap.wmlscriptc', + 'vxml' => 'application/voicexml+xml', + 'bcpio' => 'application/x-bcpio', + 'vcd' => 'application/x-cdlink', + 'pgn' => 'application/x-chess-pgn', + 'cpio' => 'application/x-cpio', + 'csh' => 'application/x-csh', + 'dcr' => 'application/x-director', + 'dir' => 'application/x-director', + 'dxr' => 'application/x-director', + 'dvi' => 'application/x-dvi', + 'spl' => 'application/x-futuresplash', + 'tgz' => 'application/x-gtar', + 'gtar' => 'application/x-gtar', + 'hdf' => 'application/x-hdf', + 'js' => 'application/x-javascript', + 'skp' => 'application/x-koan', + 'skd' => 'application/x-koan', + 'skt' => 'application/x-koan', + 'skm' => 'application/x-koan', + 'latex' => 'application/x-latex', + 'nc' => 'application/x-netcdf', + 'cdf' => 'application/x-netcdf', + 'sh' => 'application/x-sh', + 'shar' => 'application/x-shar', + 'swf' => 'application/x-shockwave-flash', + 'sit' => 'application/x-stuffit', + 'sv4cpio' => 'application/x-sv4cpio', + 'sv4crc' => 'application/x-sv4crc', + 'tar' => 'application/x-tar', + 'tcl' => 'application/x-tcl', + 'tex' => 'application/x-tex', + 'texinfo' => 'application/x-texinfo', + 'texi' => 'application/x-texinfo', + 't' => 'application/x-troff', + 'tr' => 'application/x-troff', + 'roff' => 'application/x-troff', + 'man' => 'application/x-troff-man', + 'me' => 'application/x-troff-me', + 'ms' => 'application/x-troff-ms', + 'ustar' => 'application/x-ustar', + 'src' => 'application/x-wais-source', + 'xhtml' => 'application/xhtml+xml', + 'xht' => 'application/xhtml+xml', + 'xslt' => 'application/xslt+xml', + 'xml' => 'application/xml', + 'xsl' => 'application/xml', + 'dtd' => 'application/xml-dtd', + 'zip' => 'application/zip', + 'au' => 'audio/basic', + 'snd' => 'audio/basic', + 'mid' => 'audio/midi', + 'midi' => 'audio/midi', + 'kar' => 'audio/midi', + 'mpga' => 'audio/mpeg', + 'mp2' => 'audio/mpeg', + 'mp3' => 'audio/mpeg', + 'aif' => 'audio/x-aiff', + 'aiff' => 'audio/x-aiff', + 'aifc' => 'audio/x-aiff', + 'm3u' => 'audio/x-mpegurl', + 'wma' => 'audio/x-ms-wma', + 'wax' => 'audio/x-ms-wax', + 'ram' => 'audio/x-pn-realaudio', + 'ra' => 'audio/x-pn-realaudio', + 'rm' => 'application/vnd.rn-realmedia', + 'wav' => 'audio/x-wav', + 'pdb' => 'chemical/x-pdb', + 'xyz' => 'chemical/x-xyz', + 'bmp' => 'image/bmp', + 'cgm' => 'image/cgm', + 'gif' => 'image/gif', + 'ief' => 'image/ief', + 'jpeg' => 'image/jpeg', + 'jpg' => 'image/jpeg', + 'jpe' => 'image/jpeg', + 'png' => 'image/png', + 'svg' => 'image/svg+xml', + 'tiff' => 'image/tiff', + 'tif' => 'image/tiff', + 'djvu' => 'image/vnd.djvu', + 'djv' => 'image/vnd.djvu', + 'wbmp' => 'image/vnd.wap.wbmp', + 'ras' => 'image/x-cmu-raster', + 'ico' => 'image/x-icon', + 'pnm' => 'image/x-portable-anymap', + 'pbm' => 'image/x-portable-bitmap', + 'pgm' => 'image/x-portable-graymap', + 'ppm' => 'image/x-portable-pixmap', + 'rgb' => 'image/x-rgb', + 'xbm' => 'image/x-xbitmap', + 'psd' => 'image/x-photoshop', + 'xpm' => 'image/x-xpixmap', + 'xwd' => 'image/x-xwindowdump', + 'eml' => 'message/rfc822', + 'igs' => 'model/iges', + 'iges' => 'model/iges', + 'msh' => 'model/mesh', + 'mesh' => 'model/mesh', + 'silo' => 'model/mesh', + 'wrl' => 'model/vrml', + 'vrml' => 'model/vrml', + 'ics' => 'text/calendar', + 'ifb' => 'text/calendar', + 'css' => 'text/css', + 'csv' => 'text/csv', + 'html' => 'text/html', + 'htm' => 'text/html', + 'txt' => 'text/plain', + 'asc' => 'text/plain', + 'rtx' => 'text/richtext', + 'rtf' => 'text/rtf', + 'sgml' => 'text/sgml', + 'sgm' => 'text/sgml', + 'tsv' => 'text/tab-separated-values', + 'wml' => 'text/vnd.wap.wml', + 'wmls' => 'text/vnd.wap.wmlscript', + 'etx' => 'text/x-setext', + 'mpeg' => 'video/mpeg', + 'mpg' => 'video/mpeg', + 'mpe' => 'video/mpeg', + 'qt' => 'video/quicktime', + 'mov' => 'video/quicktime', + 'mxu' => 'video/vnd.mpegurl', + 'm4u' => 'video/vnd.mpegurl', + 'flv' => 'video/x-flv', + 'asf' => 'video/x-ms-asf', + 'asx' => 'video/x-ms-asf', + 'wmv' => 'video/x-ms-wmv', + 'wm' => 'video/x-ms-wm', + 'wmx' => 'video/x-ms-wmx', + 'avi' => 'video/x-msvideo', + 'ogv' => 'video/ogg', + 'movie' => 'video/x-sgi-movie', + 'ice' => 'x-conference/x-cooltalk', + ); + + + + /** + * Autodetect a file's MIME-type. + * + * @param string $file Path to the file to get the type of + * + * @return string $file's MIME-type on success, PEAR_Error otherwise + */ + function getMIMEType($file) + { + $extension = substr(strrchr($file, '.'), 1); + if ($extension === false) { + return PEAR::raiseError("File has no extension."); + } + + if (!isset($this->extensionToType[$extension])) { + return PEAR::raiseError("Sorry, couldn't determine file type."); + } + + return $this->extensionToType[$extension]; + } + + + + /** + * Return default MIME-type for the specified extension. + * + * @param string $type MIME-type + * + * @return string A file extension without leading period. + */ + function getExtension($type) + { + require_once 'MIME/Type.php'; + // Strip parameters and comments. + $type = MIME_Type::getMedia($type) . '/' . MIME_Type::getSubType($type); + + $extension = array_search($type, $this->extensionToType); + if ($extension === false) { + return PEAR::raiseError("Sorry, couldn't determine extension."); + } + return $extension; + } + +} + +?> \ No newline at end of file diff --git a/extlib/MIME/Type/Parameter.php b/extlib/MIME/Type/Parameter.php new file mode 100644 index 000000000..399d3dd7a --- /dev/null +++ b/extlib/MIME/Type/Parameter.php @@ -0,0 +1,163 @@ + | +// +----------------------------------------------------------------------+ +// +// $Id: Parameter.php,v 1.1 2007/03/25 10:10:21 cweiske Exp $ + +/** + * Class for working with MIME type parameters + * + * @version 1.2.0 + * @package MIME_Type + * @author Ian Eure + */ +class MIME_Type_Parameter { + /** + * Parameter name + * + * @var string + */ + var $name; + + /** + * Parameter value + * + * @var string + */ + var $value; + + /** + * Parameter comment + * + * @var string + */ + var $comment; + + + /** + * Constructor. + * + * @param string $param MIME parameter to parse, if set. + * @return void + */ + function MIME_Type_Parameter($param = false) + { + if ($param) { + $this->parse($param); + } + } + + + /** + * Parse a MIME type parameter and set object fields + * + * @param string $param MIME type parameter to parse + * @return void + */ + function parse($param) + { + $comment = ''; + $param = MIME_Type::stripComments($param, $comment); + $this->name = $this->getAttribute($param); + $this->value = $this->getValue($param); + $this->comment = $comment; + } + + + /** + * Get a parameter attribute (e.g. name) + * + * @param string MIME type parameter + * @return string Attribute name + * @static + */ + function getAttribute($param) + { + $tmp = explode('=', $param); + return trim($tmp[0]); + } + + + /** + * Get a parameter value + * + * @param string $param MIME type parameter + * @return string Value + * @static + */ + function getValue($param) + { + $tmp = explode('=', $param, 2); + $value = $tmp[1]; + $value = trim($value); + if ($value[0] == '"' && $value[strlen($value)-1] == '"') { + $value = substr($value, 1, -1); + } + $value = str_replace('\\"', '"', $value); + return $value; + } + + + /** + * Get a parameter comment + * + * @param string $param MIME type parameter + * @return string Parameter comment + * @see getComment() + * @static + */ + function getComment($param) + { + $cs = strpos($param, '('); + $comment = substr($param, $cs); + return trim($comment, '() '); + } + + + /** + * Does this parameter have a comment? + * + * @param string $param MIME type parameter + * @return boolean true if $param has a comment, false otherwise + * @static + */ + function hasComment($param) + { + if (strstr($param, '(')) { + return true; + } + return false; + } + + + /** + * Get a string representation of this parameter + * + * This function performs the oppsite of parse() + * + * @return string String representation of parameter + */ + function get() + { + $val = $this->name . '="' . str_replace('"', '\\"', $this->value) . '"'; + if ($this->comment) { + $val .= ' (' . $this->comment . ')'; + } + return $val; + } +} +?> \ No newline at end of file diff --git a/lib/common.php b/lib/common.php index 0ce46442d..ede8d6277 100644 --- a/lib/common.php +++ b/lib/common.php @@ -163,6 +163,40 @@ $config = array('run' => 'web', 'frequency' => 10000, 'reporturl' => 'http://laconi.ca/stats/report'), + 'attachments' => + array('supported' => array('image/png', + 'image/jpeg', + 'image/gif', + 'image/svg+xml', + 'audio/mpeg', + 'application/ogg', + 'application/pdf', + 'application/vnd.oasis.opendocument.text', + 'application/vnd.oasis.opendocument.text-template', + 'application/vnd.oasis.opendocument.graphics', + 'application/vnd.oasis.opendocument.graphics-template', + 'application/vnd.oasis.opendocument.presentation', + 'application/vnd.oasis.opendocument.presentation-template', + 'application/vnd.oasis.opendocument.spreadsheet', + 'application/vnd.oasis.opendocument.spreadsheet-template', + 'application/vnd.oasis.opendocument.chart', + 'application/vnd.oasis.opendocument.chart-template', + 'application/vnd.oasis.opendocument.image', + 'application/vnd.oasis.opendocument.image-template', + 'application/vnd.oasis.opendocument.formula', + 'application/vnd.oasis.opendocument.formula-template', + 'application/vnd.oasis.opendocument.text-master', + 'application/vnd.oasis.opendocument.text-web', + 'application/zip', + 'text/plain', + 'video/mpeg', + 'video/mp4', + 'video/quicktime', + 'video/mpeg'), + 'file_quota' => 5000000, + 'user_quota' => 50000000, + 'monthly_quota' => 15000000, + ), ); $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options'); @@ -223,19 +257,19 @@ if ($_db_name != 'laconica' && !array_key_exists('ini_'.$_db_name, $config['db'] // XXX: how many of these could be auto-loaded on use? -require_once('Validate.php'); -require_once('markdown.php'); +require_once 'Validate.php'; +require_once 'markdown.php'; -require_once(INSTALLDIR.'/lib/util.php'); -require_once(INSTALLDIR.'/lib/action.php'); -require_once(INSTALLDIR.'/lib/theme.php'); -require_once(INSTALLDIR.'/lib/mail.php'); -require_once(INSTALLDIR.'/lib/subs.php'); -require_once(INSTALLDIR.'/lib/Shorturl_api.php'); -require_once(INSTALLDIR.'/lib/twitter.php'); +require_once INSTALLDIR.'/lib/util.php'; +require_once INSTALLDIR.'/lib/action.php'; +require_once INSTALLDIR.'/lib/theme.php'; +require_once INSTALLDIR.'/lib/mail.php'; +require_once INSTALLDIR.'/lib/subs.php'; +require_once INSTALLDIR.'/lib/Shorturl_api.php'; +require_once INSTALLDIR.'/lib/twitter.php'; -require_once(INSTALLDIR.'/lib/clientexception.php'); -require_once(INSTALLDIR.'/lib/serverexception.php'); +require_once INSTALLDIR.'/lib/clientexception.php'; +require_once INSTALLDIR.'/lib/serverexception.php'; // XXX: other formats here -- cgit v1.2.3-54-g00ecf From abe68f4318009ed839c1998d91459f26d09f76c8 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Sun, 31 May 2009 18:33:38 -0400 Subject: Added attachments config descriptions to README. --- README | 24 ++++++++++++++++++++---- lib/noticeform.php | 8 +++----- 2 files changed, 23 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/README b/README index 76b56a52e..9cbe84f0e 100644 --- a/README +++ b/README @@ -1204,11 +1204,27 @@ The software lets users upload files with their notices. You can configure the types of accepted files by mime types and a trio of quota options: per file, per user (total), per user per month. +We suggest the use of the pecl file_info extension to handle mime type +detection. + supported: an array of mime types you accept to store and distribute, - like 'image/gif', 'video/mpeg', 'audio/mpeg', etc. -file_quota: maximum size for a single file upload in bytes. -user_quota: total size in bytes a user can store. -monthly_quota: total size permitted in the current month. + like 'image/gif', 'video/mpeg', 'audio/mpeg', etc. Make sure you + setup your server to properly reckognize the types you want to + support. + +For quotas, be sure you've set the upload_max_filesize and post_max_size +in php.ini to be large enough to handle your upload. In httpd.conf +(if you're using apache), check that the LimitRequestBody directive isn't +set too low (it's optional, so it may not be there at all). + +file_quota: maximum size for a single file upload in bytes. A user can send + any amount of notices with attachments as long as each attachment + is smaller than file_quota. +user_quota: total size in bytes a user can store on this server. Each user + can store any number of files as long as their total size does + not exceed the user_quota. +monthly_quota: total size permitted in the current month. This is the total + size in bytes that a user can upload each month. Troubleshooting diff --git a/lib/noticeform.php b/lib/noticeform.php index 707768cd5..5f438327d 100644 --- a/lib/noticeform.php +++ b/lib/noticeform.php @@ -137,9 +137,6 @@ class NoticeForm extends Form { $this->out->element('label', array('for' => 'notice_data-text'), sprintf(_('What\'s up, %s?'), $this->user->nickname)); - $this->out->elementStart('span', array('style' => 'float: right; margin-top: 2em;')); -// $this->out->element('a', array('href' => '#attach'), ' [ATTACH]'); - $this->out->elementEnd('span'); // XXX: vary by defined max size $this->out->element('textarea', array('id' => 'notice_data-text', 'cols' => 35, @@ -152,15 +149,16 @@ class NoticeForm extends Form '140'); $this->out->elementEnd('dl'); $this->out->element('br', array('style' => 'clear:both')); -// $this->out->elementStart('a', array('href' => '#')); $this->out->element('label', array('for' => 'notice_data-attach'), _('Upload: ')); -// $this->out->elementEnd('a'); $this->out->element('input', array('id' => 'notice_data-attach', 'type' => 'file', 'name' => 'attach')); if ($this->action) { $this->out->hidden('notice_return-to', $this->action, 'returnto'); } $this->out->hidden('notice_in-reply-to', $this->action, 'inreplyto'); + + $this->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota')); + } /** -- cgit v1.2.3-54-g00ecf From f8dae2bbc9600a4ad474e924dc540491e29e2767 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Sun, 31 May 2009 21:03:55 -0400 Subject: Refactored some attachment code and fixed upload bug in interface. --- actions/newnotice.php | 38 ++++++-------------------------------- classes/File.php | 26 ++++++++++++++++++++++++++ lib/noticeform.php | 2 -- 3 files changed, 32 insertions(+), 34 deletions(-) (limited to 'lib') diff --git a/actions/newnotice.php b/actions/newnotice.php index 29b748dd1..a24d62684 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -131,37 +131,10 @@ class NewnoticeAction extends Action } function isRespectsQuota($user) { - if ($_FILES['attach']['size'] > common_config('attachments', 'file_quota')) { - $this->clientError(sprintf(_('No file may be larger than %d bytes ' . - 'and the file you sent was %d bytes. Try to upload a smaller version.'), - common_config('attachments', 'file_quota'), $_FILES['attach']['size'])); - } - - $query = "select sum(size) as total from file join file_to_post on file_to_post.file_id = file.id join notice on file_to_post.post_id = notice.id where profile_id = {$user->id} and file.url like '%/notice/%/file'"; $file = new File; - $file->query($query); - $file->fetch(); - $total = $file->total + $_FILES['attach']['size']; - if ($total > common_config('attachments', 'user_quota')) { - $this->clientError(sprintf(_('A file this large would exceed your user quota of %d bytes.'), common_config('attachments', 'user_quota'))); - } - - $query .= ' month(modified) = month(now()) and year(modified) = year(now())'; - $file2 = new File; - $file2->query($query); - $file2->fetch(); - $total2 = $file2->total + $_FILES['attach']['size']; - if ($total2 > common_config('attachments', 'monthly_quota')) { - $this->clientError(sprintf(_('A file this large would exceed your monthly quota of %d bytes.'), common_config('attachments', 'monthly_quota'))); - } - return true; - } - - function isValidFileAttached($user) { - return isset($_FILES['attach']['error']) - && ($_FILES['attach']['error'] === UPLOAD_ERR_OK) - && $this->isSupportedFileType() - && $this->isRespectsQuota($user); + $ret = $file->isRespectsQuota($user); + if (true === $ret) return true; + $this->clientError($ret); } /** @@ -212,6 +185,7 @@ class NewnoticeAction extends Action $replyto = 'false'; } + if (isset($_FILES['attach']['error'])) { switch ($_FILES['attach']['error']) { case UPLOAD_ERR_NO_FILE: // no file uploaded @@ -223,8 +197,7 @@ class NewnoticeAction extends Action // lets check if we really support its format // and it doesn't go over quotas - - if (!$this->isValidFileAttached($user)) { + if (!$this->isSupportedFileType() || !$this->isRespectsQuota($user)) { die('clientError() should trigger an exception before reaching here.'); } break; @@ -250,6 +223,7 @@ class NewnoticeAction extends Action default: die('Should never reach here.'); } + } $notice = Notice::saveNew($user->id, $content_shortened, 'web', 1, ($replyto == 'false') ? null : $replyto); diff --git a/classes/File.php b/classes/File.php index e5913115b..24ab11b8e 100644 --- a/classes/File.php +++ b/classes/File.php @@ -120,4 +120,30 @@ class File extends Memcached_DataObject File_to_post::processNew($file_id, $notice_id); return $x; } + + function isRespectsQuota($user) { + if ($_FILES['attach']['size'] > common_config('attachments', 'file_quota')) { + return sprintf(_('No file may be larger than %d bytes ' . + 'and the file you sent was %d bytes. Try to upload a smaller version.'), + common_config('attachments', 'file_quota'), $_FILES['attach']['size']); + } + + $query = "select sum(size) as total from file join file_to_post on file_to_post.file_id = file.id join notice on file_to_post.post_id = notice.id where profile_id = {$user->id} and file.url like '%/notice/%/file'"; + $this->query($query); + $this->fetch(); + $total = $this->total + $_FILES['attach']['size']; + if ($total > common_config('attachments', 'user_quota')) { + return sprintf(_('A file this large would exceed your user quota of %d bytes.'), common_config('attachments', 'user_quota')); + } + + $query .= ' month(modified) = month(now()) and year(modified) = year(now())'; + $this->query($query); + $this->fetch(); + $total = $this->total + $_FILES['attach']['size']; + if ($total > common_config('attachments', 'monthly_quota')) { + return sprintf(_('A file this large would exceed your monthly quota of %d bytes.'), common_config('attachments', 'monthly_quota')); + } + return true; + } } + diff --git a/lib/noticeform.php b/lib/noticeform.php index 5f438327d..7c88bd7b1 100644 --- a/lib/noticeform.php +++ b/lib/noticeform.php @@ -156,9 +156,7 @@ class NoticeForm extends Form $this->out->hidden('notice_return-to', $this->action, 'returnto'); } $this->out->hidden('notice_in-reply-to', $this->action, 'inreplyto'); - $this->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota')); - } /** -- cgit v1.2.3-54-g00ecf From 683b835c3ed0be5f691795c64b1217896e1dad95 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Mon, 1 Jun 2009 14:02:59 -0400 Subject: Attachments popups for supported files are now embedded with the object xhtml tag. --- actions/newnotice.php | 69 ++++++++++++++++++++++++-------------------------- lib/attachmentlist.php | 17 +++++++++++++ lib/common.php | 1 + 3 files changed, 51 insertions(+), 36 deletions(-) (limited to 'lib') diff --git a/actions/newnotice.php b/actions/newnotice.php index a24d62684..3e6ff1518 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -113,12 +113,12 @@ class NewnoticeAction extends Action } } - function isSupportedFileType() { + function getUploadedFileType() { require_once 'MIME/Type.php'; $filetype = MIME_Type::autoDetect($_FILES['attach']['tmp_name']); if (in_array($filetype, common_config('attachments', 'supported'))) { - return true; + return $filetype; } $media = MIME_Type::getMedia($filetype); if ('application' !== $media) { @@ -186,43 +186,39 @@ class NewnoticeAction extends Action } if (isset($_FILES['attach']['error'])) { - switch ($_FILES['attach']['error']) { - case UPLOAD_ERR_NO_FILE: - // no file uploaded - // nothing to do - break; + switch ($_FILES['attach']['error']) { + case UPLOAD_ERR_NO_FILE: + // no file uploaded, nothing to do + break; - case UPLOAD_ERR_OK: - // file was uploaded alright - // lets check if we really support its format - // and it doesn't go over quotas + case UPLOAD_ERR_OK: + $mimetype = $this->getUploadedFileType(); + if (!$this->isRespectsQuota($user)) { + die('clientError() should trigger an exception before reaching here.'); + } + break; - if (!$this->isSupportedFileType() || !$this->isRespectsQuota($user)) { - die('clientError() should trigger an exception before reaching here.'); - } - break; + case UPLOAD_ERR_INI_SIZE: + $this->clientError(_('The uploaded file exceeds the upload_max_filesize directive in php.ini.')); - case UPLOAD_ERR_INI_SIZE: - $this->clientError(_('The uploaded file exceeds the upload_max_filesize directive in php.ini.')); + case UPLOAD_ERR_FORM_SIZE: + $this->clientError(_('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.')); - case UPLOAD_ERR_FORM_SIZE: - $this->clientError(_('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.')); + case UPLOAD_ERR_PARTIAL: + $this->clientError(_('The uploaded file was only partially uploaded.')); - case UPLOAD_ERR_PARTIAL: - $this->clientError(_('The uploaded file was only partially uploaded.')); + case UPLOAD_ERR_NO_TMP_DIR: + $this->clientError(_('Missing a temporary folder.')); - case UPLOAD_ERR_NO_TMP_DIR: - $this->clientError(_('Missing a temporary folder.')); + case UPLOAD_ERR_CANT_WRITE: + $this->clientError(_('Failed to write file to disk.')); - case UPLOAD_ERR_CANT_WRITE: - $this->clientError(_('Failed to write file to disk.')); + case UPLOAD_ERR_EXTENSION: + $this->clientError(_('File upload stopped by extension.')); - case UPLOAD_ERR_EXTENSION: - $this->clientError(_('File upload stopped by extension.')); - - default: - die('Should never reach here.'); - } + default: + die('Should never reach here.'); + } } $notice = Notice::saveNew($user->id, $content_shortened, 'web', 1, @@ -232,7 +228,9 @@ class NewnoticeAction extends Action $this->clientError($notice); } - $this->storeFile($notice); + if (isset($mimetype)) { + $this->storeFile($notice, $mimetype); + } $this->saveUrls($notice); common_broadcast_notice($notice); @@ -259,8 +257,7 @@ class NewnoticeAction extends Action } } - function storeFile($notice) { - if (UPLOAD_ERR_NO_FILE === $_FILES['attach']['error']) return; + function storeFile($notice, $mimetype) { $filename = basename($_FILES['attach']['name']); $destination = "file/{$notice->id}-$filename"; if (move_uploaded_file($_FILES['attach']['tmp_name'], INSTALLDIR . "/$destination")) { @@ -268,7 +265,7 @@ class NewnoticeAction extends Action $file->url = common_local_url('file', array('notice' => $notice->id)); $file->size = filesize(INSTALLDIR . "/$destination"); $file->date = time(); - $file->mimetype = $_FILES['attach']['type']; + $file->mimetype = $mimetype; if ($file_id = $file->insert()) { $file_redir = new File_redirection; $file_redir->url = common_path($destination); @@ -285,7 +282,6 @@ class NewnoticeAction extends Action } } - /** save all urls in the notice to the db * * follow redirects and save all available file information @@ -408,3 +404,4 @@ class NewnoticeAction extends Action $nli->show(); } } + diff --git a/lib/attachmentlist.php b/lib/attachmentlist.php index 61749dca5..45e4fa319 100644 --- a/lib/attachmentlist.php +++ b/lib/attachmentlist.php @@ -268,6 +268,23 @@ class Attachment extends AttachmentListItem case 'image/jpeg': $this->out->element('img', array('src' => $this->attachment->url, 'alt' => 'alt')); break; + + case 'application/ogg': + case 'audio/x-speex': + case 'video/mpeg': + case 'audio/mpeg': + case 'video/mp4': + case 'video/quicktime': + $arr = array('type' => $this->attachment->mimetype, + 'data' => $this->attachment->url, + 'width' => 320, + 'height' => 240 + ); + $this->out->elementStart('object', $arr); + $this->out->element('param', array('name' => 'src', 'value' => $this->attachment->url)); + $this->out->element('param', array('name' => 'autoStart', 'value' => 1)); + $this->out->elementEnd('object'); + break; } } } else { diff --git a/lib/common.php b/lib/common.php index 838f52f9d..ceb50337c 100644 --- a/lib/common.php +++ b/lib/common.php @@ -169,6 +169,7 @@ $config = 'image/gif', 'image/svg+xml', 'audio/mpeg', + 'audio/x-speex', 'application/ogg', 'application/pdf', 'application/vnd.oasis.opendocument.text', -- cgit v1.2.3-54-g00ecf From 95bcc5afa11ccbff82c2d0d16a286014ba96acb1 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Mon, 1 Jun 2009 15:18:23 -0400 Subject: Updated markup for notice form attachment --- lib/noticeform.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/noticeform.php b/lib/noticeform.php index 7c88bd7b1..5a6c7cf38 100644 --- a/lib/noticeform.php +++ b/lib/noticeform.php @@ -148,10 +148,10 @@ class NoticeForm extends Form $this->out->element('dd', array('id' => 'notice_text-count'), '140'); $this->out->elementEnd('dl'); - $this->out->element('br', array('style' => 'clear:both')); - $this->out->element('label', array('for' => 'notice_data-attach'), _('Upload: ')); - $this->out->element('input', array('id' => 'notice_data-attach', 'type' => 'file', 'name' => 'attach')); - + $this->out->element('label', array('for' => 'notice_data-attach'), _('Attach')); + $this->out->element('input', array('id' => 'notice_data-attach', + 'type' => 'file', + 'name' => 'attach')); if ($this->action) { $this->out->hidden('notice_return-to', $this->action, 'returnto'); } -- cgit v1.2.3-54-g00ecf From 4bd195b80f1bf9f7da11ed8cc14a0027228f733e Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Mon, 1 Jun 2009 19:40:39 +0000 Subject: Fixed small bug for attachment layout (css/js). --- lib/attachmentlist.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/attachmentlist.php b/lib/attachmentlist.php index 45e4fa319..898be1bb0 100644 --- a/lib/attachmentlist.php +++ b/lib/attachmentlist.php @@ -83,7 +83,7 @@ class AttachmentList extends Widget $atts = new File; $att = $atts->getAttachments($this->notice->id); if (empty($att)) return 0; - $this->out->elementStart('dl', array('id' =>'attachments')); + $this->out->elementStart('dl', array('id' =>'attachment')); $this->out->element('dt', null, _('Attachments')); $this->out->elementStart('dd'); $this->out->elementStart('ol', array('class' => 'attachments')); -- cgit v1.2.3-54-g00ecf From 0cbd72e0927cbe9b605e34d7bbd86d2046ea0c49 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Mon, 1 Jun 2009 15:52:52 -0400 Subject: Re-added some javascript to toggle upload field. --- js/util.js | 11 +++++++++++ lib/noticeform.php | 1 + 2 files changed, 12 insertions(+) (limited to 'lib') diff --git a/js/util.js b/js/util.js index 20f17f6e7..acf44a17c 100644 --- a/js/util.js +++ b/js/util.js @@ -17,6 +17,17 @@ */ $(document).ready(function(){ + $('input#notice_data-attach').toggle(); + $('label[for=notice_data-attach]').text('Upload a file as an attachment?'); + $('label[for=notice_data-attach]').click(function () { + if ('Upload a file as an attachment?' == $(this).text()) { + $(this).text('Upload: '); + $('input#notice_data-attach').slideDown('fast'); + } else { + $('input#notice_data-attach').slideUp('fast', function() {$('label[for=notice_data-attach]').text('Upload a file as an attachment?');}); + } + }); + $('a.attachment').click(function() {$().jOverlay({url: $('address .url')[0].href+'/attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'}); return false; }); $("a.thumbnail").hover( function() { diff --git a/lib/noticeform.php b/lib/noticeform.php index 5a6c7cf38..805cd56b1 100644 --- a/lib/noticeform.php +++ b/lib/noticeform.php @@ -148,6 +148,7 @@ class NoticeForm extends Form $this->out->element('dd', array('id' => 'notice_text-count'), '140'); $this->out->elementEnd('dl'); + $this->out->element('br', array('style' => 'clear:both')); $this->out->element('label', array('for' => 'notice_data-attach'), _('Attach')); $this->out->element('input', array('id' => 'notice_data-attach', 'type' => 'file', -- cgit v1.2.3-54-g00ecf From fe38827a76520e4a910f9e988b11d0914872d44e Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Mon, 1 Jun 2009 17:40:53 -0400 Subject: Remove js that crept back in, added another error string. --- actions/newnotice.php | 2 ++ js/util.js | 24 ------------------------ lib/attachmentlist.php | 2 +- 3 files changed, 3 insertions(+), 25 deletions(-) (limited to 'lib') diff --git a/actions/newnotice.php b/actions/newnotice.php index 3e6ff1518..02976a2ae 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -279,6 +279,8 @@ class NewnoticeAction extends Action } else { $this->clientError(_('There was a database error while saving your file. Please try again.')); } + } else { + $this->clientError(_('File could not be moved to destination directory.')); } } diff --git a/js/util.js b/js/util.js index acf44a17c..bffbf916f 100644 --- a/js/util.js +++ b/js/util.js @@ -28,30 +28,6 @@ $(document).ready(function(){ } }); - $('a.attachment').click(function() {$().jOverlay({url: $('address .url')[0].href+'/attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'}); return false; }); - $("a.thumbnail").hover( - function() { - var anchor = $(this); - $("a.thumbnail").children('img').remove(); - - setTimeout(function() { - anchor.closest(".entry-title").addClass('ov'); - $.get($('address .url')[0].href+'/attachment/' + (anchor.attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) { - anchor.append(data); - }); - }, 250); - - setTimeout(function() { - anchor.children('img').remove(); - anchor.closest(".entry-title").removeClass('ov'); - }, 3000); - }, - function() { - $(this).children('img').remove(); - $(this).closest(".entry-title").removeClass('ov'); - } - ); - // count character on keyup function counter(event){ var maxLength = 140; diff --git a/lib/attachmentlist.php b/lib/attachmentlist.php index 898be1bb0..45e4fa319 100644 --- a/lib/attachmentlist.php +++ b/lib/attachmentlist.php @@ -83,7 +83,7 @@ class AttachmentList extends Widget $atts = new File; $att = $atts->getAttachments($this->notice->id); if (empty($att)) return 0; - $this->out->elementStart('dl', array('id' =>'attachment')); + $this->out->elementStart('dl', array('id' =>'attachments')); $this->out->element('dt', null, _('Attachments')); $this->out->elementStart('dd'); $this->out->elementStart('ol', array('class' => 'attachments')); -- cgit v1.2.3-54-g00ecf From b708b81065b4adc46026e570d8e2cb9d37bc24af Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 5 Jun 2009 00:00:04 -0400 Subject: Init notice_data-attach UI for form_notice --- js/util.js | 11 ----------- lib/noticeform.php | 1 - theme/base/css/display.css | 16 ++++++++++++++++ theme/identica/css/display.css | 7 +++++++ 4 files changed, 23 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/js/util.js b/js/util.js index bffbf916f..b712ba8e2 100644 --- a/js/util.js +++ b/js/util.js @@ -17,17 +17,6 @@ */ $(document).ready(function(){ - $('input#notice_data-attach').toggle(); - $('label[for=notice_data-attach]').text('Upload a file as an attachment?'); - $('label[for=notice_data-attach]').click(function () { - if ('Upload a file as an attachment?' == $(this).text()) { - $(this).text('Upload: '); - $('input#notice_data-attach').slideDown('fast'); - } else { - $('input#notice_data-attach').slideUp('fast', function() {$('label[for=notice_data-attach]').text('Upload a file as an attachment?');}); - } - }); - // count character on keyup function counter(event){ var maxLength = 140; diff --git a/lib/noticeform.php b/lib/noticeform.php index 805cd56b1..5a6c7cf38 100644 --- a/lib/noticeform.php +++ b/lib/noticeform.php @@ -148,7 +148,6 @@ class NoticeForm extends Form $this->out->element('dd', array('id' => 'notice_text-count'), '140'); $this->out->elementEnd('dl'); - $this->out->element('br', array('style' => 'clear:both')); $this->out->element('label', array('for' => 'notice_data-attach'), _('Attach')); $this->out->element('input', array('id' => 'notice_data-attach', 'type' => 'file', diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 7d495c539..7eea54eb2 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -452,6 +452,22 @@ float:left; font-size:1.3em; margin-bottom:7px; } +#form_notice label[for=notice_data-attach] { +text-indent:-9999px; +display:block; +} +#form_notice label[for=notice_data-attach], +#form_notice #notice_data-attach { +position:absolute; +top:25px; +right:49px; +width:16px; +height:16px; +cursor:pointer; +} +#form_notice #notice_data-attach { +text-indent:-279px; +} #form_notice #notice_submit label { display:none; } diff --git a/theme/identica/css/display.css b/theme/identica/css/display.css index 1f1298737..8a03a4d77 100644 --- a/theme/identica/css/display.css +++ b/theme/identica/css/display.css @@ -82,6 +82,13 @@ color:#333; #form_notice.warning #notice_text-count { color:#000; } +#form_notice label[for=notice_data-attach] { +background:transparent url(../../base/images/icons/twotone/green/clip-01.gif) no-repeat 0 45%; +} +#form_notice #notice_data-attach { +opacity:0; +} + #form_notice.processing #notice_action-submit { background:#fff url(../../base/images/icons/icon_processing.gif) no-repeat 47% 47%; cursor:wait; -- cgit v1.2.3-54-g00ecf From 3aebd847e72e929f05e5d217e037b3ccc9169306 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Tue, 9 Jun 2009 17:34:33 +0000 Subject: Added title and minor CSS cleanup to notice attach --- lib/noticeform.php | 3 ++- theme/base/css/display.css | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/noticeform.php b/lib/noticeform.php index 5a6c7cf38..5d7cf194e 100644 --- a/lib/noticeform.php +++ b/lib/noticeform.php @@ -151,7 +151,8 @@ class NoticeForm extends Form $this->out->element('label', array('for' => 'notice_data-attach'), _('Attach')); $this->out->element('input', array('id' => 'notice_data-attach', 'type' => 'file', - 'name' => 'attach')); + 'name' => 'attach', + 'title' => _('Attach a file'))); if ($this->action) { $this->out->hidden('notice_return-to', $this->action, 'returnto'); } diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 7eea54eb2..dc275e19f 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -454,7 +454,6 @@ margin-bottom:7px; } #form_notice label[for=notice_data-attach] { text-indent:-9999px; -display:block; } #form_notice label[for=notice_data-attach], #form_notice #notice_data-attach { -- cgit v1.2.3-54-g00ecf From 27af3c67a2a9ea856aa2de041a986d452cce3025 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Tue, 9 Jun 2009 15:18:12 -0400 Subject: Improve file upload and attachment interface. --- classes/Notice.php | 12 ++++++++++++ lib/common.php | 1 + lib/noticelist.php | 8 ++++---- 3 files changed, 17 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/classes/Notice.php b/classes/Notice.php index 1b5c0ab0a..0b1017e12 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -277,6 +277,18 @@ class Notice extends Memcached_DataObject return true; } + function getUploadedAttachment() { + $post = clone $this; + $query = 'select file.url as uploaded from file join file_to_post on file.id = file_id where post_id=' . $post->escape($post->id) . ' and url like "%/notice/%/file"'; + $post->query($query); + $post->fetch(); + $ret = $post->uploaded; +// var_dump($post); + $post->free(); +// die(); + return $ret; + } + function hasAttachments() { $post = clone $this; $query = "select count(file_id) as n_attachments from file join file_to_post on (file_id = file.id) join notice on (post_id = notice.id) where post_id = " . $post->escape($post->id); diff --git a/lib/common.php b/lib/common.php index ceb50337c..5aafdfe0e 100644 --- a/lib/common.php +++ b/lib/common.php @@ -188,6 +188,7 @@ $config = 'application/vnd.oasis.opendocument.formula-template', 'application/vnd.oasis.opendocument.text-master', 'application/vnd.oasis.opendocument.text-web', + 'application/x-zip', 'application/zip', 'text/plain', 'video/mpeg', diff --git a/lib/noticelist.php b/lib/noticelist.php index 5513e317e..9ace341d8 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -364,6 +364,10 @@ class NoticeListItem extends Widget // versions (>> 0.4.x) $this->out->raw(common_render_content($this->notice->content, $this->notice)); } + $uploaded = $this->notice->getUploadedAttachment(); + if ($uploaded) { + $this->out->element('a', array('href' => $uploaded, 'class' => 'attachment'), $uploaded); + } $this->out->elementEnd('p'); } @@ -395,10 +399,6 @@ class NoticeListItem extends Widget 'title' => $dt), common_date_string($this->notice->created)); - $f2p = File_to_post::staticGet('post_id', $this->notice->id); - if (!empty($f2p)) { - $this->out->text(_(' (with attachments) ')); - } $this->out->elementEnd('a'); $this->out->elementEnd('dd'); $this->out->elementEnd('dl'); -- cgit v1.2.3-54-g00ecf