summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorZach Copley <zach@status.net>2010-11-17 22:16:08 +0000
committerZach Copley <zach@status.net>2010-11-17 22:16:08 +0000
commit645a4d1754128fdb34e4805ea9aa59f41af8df6f (patch)
tree10336fb9b33aa12b8bffa03d1d93e2b30d6d7b6d /lib
parent163f18b8acd59e7343da4bdde9d0a5f5bd762308 (diff)
parent197b56778a04a1d0f12dabb84e95dc9b80902aeb (diff)
Merge branch '0.9.x' of git@gitorious.org:statusnet/mainline into 0.9.x
Diffstat (limited to 'lib')
-rw-r--r--lib/action.php17
-rw-r--r--lib/default.php1
-rw-r--r--lib/popularity.php92
-rw-r--r--lib/popularnoticesection.php41
-rw-r--r--lib/util.php8
5 files changed, 115 insertions, 44 deletions
diff --git a/lib/action.php b/lib/action.php
index 17d3e2311..0e5d7ae36 100644
--- a/lib/action.php
+++ b/lib/action.php
@@ -274,15 +274,15 @@ class Action extends HTMLOutputter // lawsuit
if (Event::handle('StartShowScripts', array($this))) {
if (Event::handle('StartShowJQueryScripts', array($this))) {
$this->script('jquery.min.js');
- $this->script('jquery.form.js');
- $this->script('jquery.cookie.js');
- $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/json2.js').'"); }');
+ $this->script('jquery.form.min.js');
+ $this->script('jquery.cookie.min.js');
+ $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/json2.min.js').'"); }');
$this->script('jquery.joverlay.min.js');
Event::handle('EndShowJQueryScripts', array($this));
}
if (Event::handle('StartShowStatusNetScripts', array($this)) &&
Event::handle('StartShowLaconicaScripts', array($this))) {
- $this->script('util.js');
+ $this->script('util.min.js');
$this->showScriptMessages();
// Frame-busting code to avoid clickjacking attacks.
$this->inlineScript('if (window.top !== window.self) { window.top.location.href = window.self.location.href; }');
@@ -300,9 +300,11 @@ class Action extends HTMLOutputter // lawsuit
* events and appending to the array. Try to avoid adding strings that won't be used, as
* they'll be added to HTML output.
*/
+
function showScriptMessages()
{
$messages = array();
+
if (Event::handle('StartScriptMessages', array($this, &$messages))) {
// Common messages needed for timeline views etc...
@@ -310,11 +312,14 @@ class Action extends HTMLOutputter // lawsuit
$messages['showmore_tooltip'] = _m('TOOLTIP', 'Show more');
$messages = array_merge($messages, $this->getScriptMessages());
+
+ Event::handle('EndScriptMessages', array($this, &$messages));
}
- Event::handle('EndScriptMessages', array($this, &$messages));
- if ($messages) {
+
+ if (!empty($messages)) {
$this->inlineScript('SN.messages=' . json_encode($messages));
}
+
return $messages;
}
diff --git a/lib/default.php b/lib/default.php
index ece01f2a8..a91fa338f 100644
--- a/lib/default.php
+++ b/lib/default.php
@@ -253,6 +253,7 @@ $default =
'show_thumbs' => true, // show thumbnails in notice lists for uploaded images, and photos and videos linked remotely that provide oEmbed info
'thumb_width' => 100,
'thumb_height' => 75,
+ 'process_links' => true, // check linked resources for embeddable photos and videos; this will hit referenced external web sites when processing new messages.
),
'application' =>
array('desclimit' => null),
diff --git a/lib/popularity.php b/lib/popularity.php
new file mode 100644
index 000000000..b6987138b
--- /dev/null
+++ b/lib/popularity.php
@@ -0,0 +1,92 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Wrapper for fetching lists of popular notices.
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Widget
+ * @package StatusNet
+ * @author Evan Prodromou <evan@status.net>
+ * @author Brion Vibber <brion@status.net>
+ * @copyright 2010 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://status.net/
+ */
+
+if (!defined('STATUSNET') && !defined('LACONICA')) {
+ exit(1);
+}
+
+/**
+ * Wrapper for fetching notices ranked according to popularity,
+ * broken out so it can be called from multiple actions with
+ * less code duplication.
+ */
+class Popularity
+{
+ public $limit = NOTICES_PER_PAGE;
+ public $offset = 0;
+ public $tag = false;
+ public $expiry = 600;
+
+ /**
+ * Run a cached query to fetch notices, whee!
+ *
+ * @return Notice
+ */
+ function getNotices()
+ {
+ // @fixme there should be a common func for this
+ if (common_config('db', 'type') == 'pgsql') {
+ if (!empty($this->out->tag)) {
+ $tag = pg_escape_string($this->out->tag);
+ }
+ } else {
+ if (!empty($this->out->tag)) {
+ $tag = mysql_escape_string($this->out->tag);
+ }
+ }
+ $weightexpr = common_sql_weight('fave.modified', common_config('popular', 'dropoff'));
+ $cutoff = sprintf("fave.modified > '%s'",
+ common_sql_date(time() - common_config('popular', 'cutoff')));
+ $qry = "SELECT notice.*, $weightexpr as weight ";
+ if(isset($tag)) {
+ $qry .= 'FROM notice_tag, notice JOIN fave ON notice.id = fave.notice_id ' .
+ "WHERE $cutoff and notice.id = notice_tag.notice_id and '$tag' = notice_tag.tag";
+ } else {
+ $qry .= 'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
+ "WHERE $cutoff";
+ }
+ $qry .= ' GROUP BY notice.id,notice.profile_id,notice.content,notice.uri,' .
+ 'notice.rendered,notice.url,notice.created,notice.modified,' .
+ 'notice.reply_to,notice.is_local,notice.source,notice.conversation, ' .
+ 'notice.lat,notice.lon,location_id,location_ns,notice.repeat_of';
+ $qry .= ' HAVING \'silenced\' NOT IN (SELECT role FROM profile_role WHERE profile_id=notice.profile_id)';
+ $qry .= ' ORDER BY weight DESC';
+
+ $offset = $this->offset;
+ $limit = $this->limit + 1;
+
+ $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
+
+ $notice = Memcached_DataObject::cachedQuery('Notice',
+ $qry,
+ 1200);
+ return $notice;
+ }
+} \ No newline at end of file
diff --git a/lib/popularnoticesection.php b/lib/popularnoticesection.php
index f70a972ef..a4f038b24 100644
--- a/lib/popularnoticesection.php
+++ b/lib/popularnoticesection.php
@@ -48,42 +48,13 @@ class PopularNoticeSection extends NoticeSection
{
function getNotices()
{
- // @fixme there should be a common func for this
- if (common_config('db', 'type') == 'pgsql') {
- if (!empty($this->out->tag)) {
- $tag = pg_escape_string($this->out->tag);
- }
- } else {
- if (!empty($this->out->tag)) {
- $tag = mysql_escape_string($this->out->tag);
- }
+ $pop = new Popularity();
+ if (!empty($this->out->tag)) {
+ $pop->tag = $this->out->tag;
}
- $weightexpr = common_sql_weight('fave.modified', common_config('popular', 'dropoff'));
- $cutoff = sprintf("fave.modified > '%s'",
- common_sql_date(time() - common_config('popular', 'cutoff')));
- $qry = "SELECT notice.*, $weightexpr as weight ";
- if(isset($tag)) {
- $qry .= 'FROM notice_tag, notice JOIN fave ON notice.id = fave.notice_id ' .
- "WHERE $cutoff and notice.id = notice_tag.notice_id and '$tag' = notice_tag.tag";
- } else {
- $qry .= 'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
- "WHERE $cutoff";
- }
- $qry .= ' GROUP BY notice.id,notice.profile_id,notice.content,notice.uri,' .
- 'notice.rendered,notice.url,notice.created,notice.modified,' .
- 'notice.reply_to,notice.is_local,notice.source,notice.conversation, ' .
- 'notice.lat,notice.lon,location_id,location_ns,notice.repeat_of' .
- ' ORDER BY weight DESC';
-
- $offset = 0;
- $limit = NOTICES_PER_SECTION + 1;
-
- $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
-
- $notice = Memcached_DataObject::cachedQuery('Notice',
- $qry,
- 1200);
- return $notice;
+ $pop->limit = NOTICES_PER_SECTION;
+ $pop->expiry = 1200;
+ return $pop->getNotices();
}
function title()
diff --git a/lib/util.php b/lib/util.php
index 68592bf74..ce5da1cd8 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -848,7 +848,7 @@ function common_linkify($url) {
$canon = File_redirection::_canonUrl($url);
- $longurl_data = File_redirection::where($canon);
+ $longurl_data = File_redirection::where($canon, common_config('attachments', 'process_links'));
if (is_array($longurl_data)) {
$longurl = $longurl_data['url'];
} elseif (is_string($longurl_data)) {
@@ -872,8 +872,10 @@ function common_linkify($url) {
$f = File::staticGet('url', $longurl);
if (empty($f)) {
- // XXX: this writes to the database. :<
- $f = File::processNew($longurl);
+ if (common_config('attachments', 'process_links')) {
+ // XXX: this writes to the database. :<
+ $f = File::processNew($longurl);
+ }
}
if (!empty($f)) {