From 6b4410d9eace776182f373886785cfd1f2736764 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 15 May 2009 15:07:23 -0400 Subject: add a hook to muck around with the arguments array after it's initialized --- index.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'index.php') diff --git a/index.php b/index.php index e24bde917..0c69e226f 100644 --- a/index.php +++ b/index.php @@ -101,6 +101,8 @@ function main() $args = array_merge($args, $_REQUEST); + Event::handle('ArgsInitialize', array(&$args)); + $action = $args['action']; if (!$action || !preg_match('/^[a-zA-Z0-9_-]*$/', $action)) { -- cgit v1.2.3-54-g00ecf From f3ea79a12a7bdf0d4efcd7eb706d25ae81b7fad9 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Sun, 17 May 2009 00:05:07 -0400 Subject: Added site path field to installer + fancy URL javascript auto-detection. --- index.php | 4 ++++ install.php | 31 ++++++++++++++++++++++++++----- js/install.js | 18 ++++++++++++++++++ 3 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 js/install.js (limited to 'index.php') diff --git a/index.php b/index.php index e24bde917..cfef21189 100644 --- a/index.php +++ b/index.php @@ -63,6 +63,10 @@ function handleError($error) function main() { + // quick check for fancy URL auto-detection support in installer. + if ('/check-fancy' === $_SERVER['REDIRECT_URL']) { + die("Fancy URL support detection succeeded. We suggest you enable this to get fancy (pretty) URLs."); + } global $user, $action, $config; if (!_have_config()) { diff --git a/install.php b/install.php index 66e8e8712..32915200b 100644 --- a/install.php +++ b/install.php @@ -86,7 +86,8 @@ function checkExtension($name) function showForm() { -?> + $config_path = htmlentities(trim(dirname($_SERVER['REQUEST_URI']), '/')); + echo<< @@ -108,11 +109,21 @@ function showForm()

The name of your site

  • + + enable
    + disable
    +

    Enable fancy (pretty) URLs. Auto-detection failed, it depends on Javascript.

    +
  • Database hostname

  • +
  • + + +

    Site path, following the "/" after the domain name in the URL. Empty is fine. Field should be filled automatically.

    +
  • @@ -132,7 +143,8 @@ function showForm() -
    Page notice
    @@ -225,29 +239,34 @@ function handlePost() } updateStatus("Writing config file..."); $sqlUrl = "mysqli://$username:$password@$host/$database"; - $res = writeConf($sitename, $sqlUrl); + $res = writeConf($sitename, $sqlUrl, $fancy, $path); if (!$res) { updateStatus("Can't write config file.", true); showForm(); return; } updateStatus("Done!"); + if ($path) $path .= '/'; + updateStatus("You can visit your new Laconica site + +
    diff --git a/js/install.js b/js/install.js new file mode 100644 index 000000000..32a54111e --- /dev/null +++ b/js/install.js @@ -0,0 +1,18 @@ +$(document).ready(function(){ + $.ajax({url:'check-fancy', + type:'GET', + success:function(data, textStatus) { + $('#fancy-enable').attr('checked', true); + $('#fancy-disable').attr('checked', false); + $('#fancy-form_guide').text(data); + }, + error:function(XMLHttpRequest, textStatus, errorThrown) { + $('#fancy-enable').attr('checked', false); + $('#fancy-disable').attr('checked', true); + $('#fancy-enable').attr('disabled', true); + $('#fancy-disable').attr('disabled', true); + $('#fancy-form_guide').text("Fancy URL support detection failed, disabling this option. Make sure you renamed htaccess.sample to .htaccess."); + } + }); +}); + -- cgit v1.2.3-54-g00ecf From 5897dfa4c37d6a44bcde5dc7569c8b0d30f21b84 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Sun, 17 May 2009 22:06:08 -0400 Subject: Refactored new sections code to proper classes and added notice link to links in notice sections. --- actions/attachment.php | 53 +++---------------------- actions/tag.php | 13 +----- classes/Notice.php | 6 +-- config.php.sample | 6 +++ index.php | 2 +- lib/attachmentnoticesection.php | 75 +++++++++++++++++++++++++++++++++++ lib/attachmentsection.php | 80 +++++++++++++++++++++++++++++++++++++ lib/attachmenttagcloudsection.php | 83 +++++++++++++++++++++++++++++++++++++++ lib/frequentattachmentsection.php | 66 +++++++++++++++++++++++++++++++ lib/noticesection.php | 35 +++++++++++++++-- lib/popularnoticesection.php | 2 +- 11 files changed, 354 insertions(+), 67 deletions(-) create mode 100644 lib/attachmentnoticesection.php create mode 100644 lib/attachmentsection.php create mode 100644 lib/attachmenttagcloudsection.php create mode 100644 lib/frequentattachmentsection.php (limited to 'index.php') diff --git a/actions/attachment.php b/actions/attachment.php index 981882a5b..b9187ff08 100644 --- a/actions/attachment.php +++ b/actions/attachment.php @@ -53,18 +53,6 @@ class AttachmentAction extends Action var $attachment = null; - /** - * Profile of the notice object - */ - -// var $profile = null; - - /** - * Avatar of the profile of the notice object - */ - -// var $avatar = null; - /** * Load attributes based on database arguments * @@ -112,8 +100,6 @@ class AttachmentAction extends Action return $a->title(); } - - /** * Last-modified date for page * @@ -213,38 +199,11 @@ class AttachmentAction extends Action * * @return void */ - - function showAside() { - $notice = new Notice; - $f2p = new File_to_post; - $f2p->file_id = $this->attachment->id; - $notice->joinAdd($f2p); - $notice->orderBy('created desc'); - $x = $notice->find(); - $this->elementStart('ol'); - while($notice->fetch()) { - $this->elementStart('li'); - $profile = $notice->getProfile(); - $this->element('a', array('href' => $notice->uri), $profile->nickname . ' on ' . $notice->created); - $this->elementEnd('li'); - } - $this->elementEnd('ol'); - $notice->free(); - $f2p->free(); - - $notice_tag = new Notice_tag; - $attachment = new File; - - $query = 'select tag,count(tag) as c from notice_tag join file_to_post on (notice_tag.notice_id=post_id) join notice on notice_id = notice.id where file_id=' . $notice_tag->escape($this->attachment->id) . ' group by tag order by c desc'; - - $notice_tag->query($query); - $this->elementStart('ol'); - while($notice_tag->fetch()) { - $this->elementStart('li'); - $href = common_local_url('tag', array('tag' => $notice_tag->tag)); - $this->element('a', array('href' => $href), $notice_tag->tag . ' (' . $notice_tag->c . ')'); - $this->elementEnd('li'); - } - $this->elementEnd('ol'); + function showSections() { + $ns = new AttachmentNoticeSection($this); + $ns->show(); + $atcs = new AttachmentTagCloudSection($this); + $atcs->show(); } } + diff --git a/actions/tag.php b/actions/tag.php index 2202f9bb0..47420e4c3 100644 --- a/actions/tag.php +++ b/actions/tag.php @@ -49,17 +49,8 @@ class TagAction extends Action { $pop = new PopularNoticeSection($this); $pop->show(); - - $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->tag) . '" group by file_id order by c desc'; - $notice_tag->query($query); - $this->elementStart('ol'); - while ($notice_tag->fetch()) { - $this->elementStart('li'); - $this->element('a', array('class' => 'attachment', 'href' => common_local_url('attachment', array('attachment' => $notice_tag->file_id))), "Attachment tagged {$notice_tag->c} times"); - $this->elementEnd('li'); - } - $this->elementEnd('ol'); + $freqatt = new FrequentAttachmentSection($this); + $freqatt->show(); } function title() diff --git a/classes/Notice.php b/classes/Notice.php index 30508070e..f6ac4f780 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -134,7 +134,7 @@ class Notice extends Memcached_DataObject return _('Too many notices too fast; take a breather and post again in a few minutes.'); } - if (common_config('site', 'dupelimit') > 0 && !Notice::checkDupes($profile_id, $final)) { + if (common_config('site', 'dupelimit') > 0 && !Notice::checkDupes($profile_id, $content)) { common_log(LOG_WARNING, 'Dupe posting by profile #' . $profile_id . '; throttled.'); return _('Too many duplicate messages too quickly; take a breather and post again in a few minutes.'); } @@ -278,8 +278,8 @@ class Notice extends Memcached_DataObject } 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($this->id); + $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); $post->query($query); $post->fetch(); $n_attachments = intval($post->n_attachments); diff --git a/config.php.sample b/config.php.sample index 0e6bf0e5f..826b086a3 100644 --- a/config.php.sample +++ b/config.php.sample @@ -33,6 +33,12 @@ $config['site']['path'] = 'laconica'; #Make the site invisible to non-logged-in users #$config['site']['private'] = true; +# 'direct' for direct notice links in sections +# 'attachment' for notice attachment links in sections +# left undefined, no link is showed +#$config['site']['notice_link'] = 'attachment'; +#$config['site']['notice_link'] = 'direct'; + # If you want logging sent to a file instead of syslog #$config['site']['logfile'] = '/tmp/laconica.log'; diff --git a/index.php b/index.php index cfef21189..1b4fbf81b 100644 --- a/index.php +++ b/index.php @@ -64,7 +64,7 @@ function handleError($error) function main() { // quick check for fancy URL auto-detection support in installer. - if ('/check-fancy' === $_SERVER['REDIRECT_URL']) { + if (isset($_SERVER['REDIRECT_URL']) && ('/check-fancy' === $_SERVER['REDIRECT_URL'])) { die("Fancy URL support detection succeeded. We suggest you enable this to get fancy (pretty) URLs."); } global $user, $action, $config; diff --git a/lib/attachmentnoticesection.php b/lib/attachmentnoticesection.php new file mode 100644 index 000000000..eb3176376 --- /dev/null +++ b/lib/attachmentnoticesection.php @@ -0,0 +1,75 @@ +. + * + * @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 AttachmentNoticeSection extends NoticeSection +{ + function showContent() { + parent::showContent(); + return false; + } + + function getNotices() + { + $notice = new Notice; + $f2p = new File_to_post; + $f2p->file_id = $this->out->attachment->id; + $notice->joinAdd($f2p); + $notice->orderBy('created desc'); + $notice->selectAdd('post_id as id'); + $notice->find(); + return $notice; + } + + function title() + { + return _('Notices where this attachment appears'); + } + + function divId() + { + return 'popular_notices'; + } +} + diff --git a/lib/attachmentsection.php b/lib/attachmentsection.php new file mode 100644 index 000000000..20e620b9b --- /dev/null +++ b/lib/attachmentsection.php @@ -0,0 +1,80 @@ +. + * + * @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/attachmenttagcloudsection.php b/lib/attachmenttagcloudsection.php new file mode 100644 index 000000000..50bfceccb --- /dev/null +++ b/lib/attachmenttagcloudsection.php @@ -0,0 +1,83 @@ +. + * + * @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); +} + +/** + * Attachment tag cloud section + * + * @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 AttachmentTagCloudSection extends TagCloudSection +{ + function title() + { + return _('Tags for this attachment'); + } + + function showTag($tag, $weight, $relative) + { + if ($relative > 0.5) { + $rel = 'tag-cloud-7'; + } else if ($relative > 0.4) { + $rel = 'tag-cloud-6'; + } else if ($relative > 0.3) { + $rel = 'tag-cloud-5'; + } else if ($relative > 0.2) { + $rel = 'tag-cloud-4'; + } else if ($relative > 0.1) { + $rel = 'tag-cloud-3'; + } else if ($relative > 0.05) { + $rel = 'tag-cloud-2'; + } else { + $rel = 'tag-cloud-1'; + } + + $this->out->elementStart('li', $rel); + $this->out->element('a', array('href' => $this->tagUrl($tag)), + $tag); + $this->out->elementEnd('li'); + } + + function getTags() + { + $notice_tag = new Notice_tag; + $query = 'select tag,count(tag) as weight from notice_tag join file_to_post on (notice_tag.notice_id=post_id) join notice on notice_id = notice.id where file_id=' . $notice_tag->escape($this->out->attachment->id) . ' group by tag order by weight desc'; + $notice_tag->query($query); + return $notice_tag; + } +} + diff --git a/lib/frequentattachmentsection.php b/lib/frequentattachmentsection.php new file mode 100644 index 000000000..0ce0d1871 --- /dev/null +++ b/lib/frequentattachmentsection.php @@ -0,0 +1,66 @@ +. + * + * @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'; + } +} + diff --git a/lib/noticesection.php b/lib/noticesection.php index 94c2738ef..37aafdaf6 100644 --- a/lib/noticesection.php +++ b/lib/noticesection.php @@ -51,17 +51,13 @@ class NoticeSection extends Section function showContent() { $notices = $this->getNotices(); - $cnt = 0; - $this->out->elementStart('ul', 'notices'); - while ($notices->fetch() && ++$cnt <= NOTICES_PER_SECTION) { $this->showNotice($notices); } $this->out->elementEnd('ul'); - return ($cnt > NOTICES_PER_SECTION); } @@ -100,6 +96,37 @@ class NoticeSection extends Section $this->out->elementStart('p', 'entry-content'); $this->out->raw($notice->rendered); + + $notice_link_cfg = common_config('site', 'notice_link'); + if ('direct' === $notice_link_cfg) { + $this->out->text(' ('); + $this->out->element('a', array('href' => $notice->uri), 'see'); + $this->out->text(')'); + } elseif ('attachment' === $notice_link_cfg) { + if ($count = $notice->hasAttachments()) { + // link to attachment(s) pages + if (1 === $count) { + $f2p = File_to_post::staticGet('post_id', $notice->id); + $href = common_local_url('attachment', array('attachment' => $f2p->file_id)); + $att_class = 'attachment'; + } else { + $href = common_local_url('attachments', array('notice' => $notice->id)); + $att_class = 'attachments'; + } + + $clip = theme_path('images/icons/clip.png', 'base'); + $this->out->elementStart('a', array('class' => $att_class, 'style' => "font-style: italic;", 'href' => $href, 'title' => "# of attachments: $count")); + $this->out->raw(" ($count "); + $this->out->element('img', array('style' => 'display: inline', 'align' => 'top', 'width' => 20, 'height' => 20, 'src' => $clip, 'alt' => 'alt')); + $this->out->text(')'); + $this->out->elementEnd('a'); + } else { + $this->out->text(' ('); + $this->out->element('a', array('href' => $notice->uri), 'see'); + $this->out->text(')'); + } + } + $this->out->elementEnd('p'); if (!empty($notice->value)) { $this->out->elementStart('p'); diff --git a/lib/popularnoticesection.php b/lib/popularnoticesection.php index a8d47ef54..375d5538b 100644 --- a/lib/popularnoticesection.php +++ b/lib/popularnoticesection.php @@ -51,7 +51,7 @@ class PopularNoticeSection extends NoticeSection if (common_config('db', 'type') == 'pgsql') { $weightexpr='sum(exp(-extract(epoch from (now() - fave.modified)) / %s))'; if (!empty($this->out->tag)) { - $tag = pg_escape_string($this->tag); + $tag = pg_escape_string($this->out->tag); } } else { $weightexpr='sum(exp(-(now() - fave.modified) / %s))'; -- cgit v1.2.3-54-g00ecf