summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--EVENTS.txt84
-rw-r--r--actions/all.php36
-rw-r--r--actions/avatarsettings.php26
-rw-r--r--actions/doc.php12
-rw-r--r--actions/newnotice.php17
-rw-r--r--actions/noticesearch.php42
-rw-r--r--actions/public.php43
-rw-r--r--actions/replies.php28
-rw-r--r--actions/showfavorites.php33
-rw-r--r--actions/showgroup.php27
-rw-r--r--actions/showstream.php91
-rw-r--r--actions/tag.php22
-rw-r--r--actions/tagother.php2
-rw-r--r--actions/twittersettings.php5
-rw-r--r--classes/Notice.php43
-rwxr-xr-xclasses/laconica.ini3
-rw-r--r--config.php.sample4
-rw-r--r--db/carrier.sql61
-rw-r--r--db/laconica.sql12
-rw-r--r--db/sms_carrier.sql63
-rw-r--r--doc-src/about (renamed from doc/about)0
-rw-r--r--doc-src/contact (renamed from doc/contact)0
-rw-r--r--doc-src/faq (renamed from doc/faq)0
-rw-r--r--doc-src/groups (renamed from doc/groups)0
-rw-r--r--doc-src/help (renamed from doc/help)0
-rw-r--r--doc-src/im (renamed from doc/im)0
-rw-r--r--doc-src/openid (renamed from doc/openid)0
-rw-r--r--doc-src/openmublog (renamed from doc/openmublog)0
-rw-r--r--doc-src/privacy (renamed from doc/privacy)0
-rw-r--r--doc-src/sms (renamed from doc/sms)0
-rw-r--r--doc-src/source (renamed from doc/source)0
-rw-r--r--doc-src/tags (renamed from doc/tags)0
-rw-r--r--extlib/Net/URL.php485
-rw-r--r--extlib/Net/URL/Mapper.php324
-rw-r--r--extlib/Net/URL/Mapper/Exception.php104
-rw-r--r--extlib/Net/URL/Mapper/Part.php142
-rw-r--r--extlib/Net/URL/Mapper/Part/Dynamic.php81
-rw-r--r--extlib/Net/URL/Mapper/Part/Fixed.php70
-rw-r--r--extlib/Net/URL/Mapper/Part/Wildcard.php80
-rw-r--r--extlib/Net/URL/Mapper/Path.php430
-rw-r--r--htaccess.sample162
-rw-r--r--index.php144
-rw-r--r--lib/action.php230
-rw-r--r--lib/channel.php (renamed from classes/Channel.php)1
-rw-r--r--lib/clientexception.php56
-rw-r--r--lib/command.php (renamed from classes/Command.php)74
-rw-r--r--lib/commandinterpreter.php (renamed from classes/CommandInterpreter.php)3
-rw-r--r--lib/common.php18
-rw-r--r--lib/dberroraction.php73
-rw-r--r--lib/event.php113
-rw-r--r--lib/facebookutil.php96
-rw-r--r--lib/feed.php110
-rw-r--r--lib/feedlist.php94
-rw-r--r--lib/grouplist.php2
-rw-r--r--lib/htmloutputter.php19
-rw-r--r--lib/imagefile.php50
-rw-r--r--lib/plugin.php79
-rw-r--r--lib/profilelist.php2
-rw-r--r--lib/router.php363
-rw-r--r--lib/serverexception.php55
-rw-r--r--lib/twitter.php97
-rw-r--r--lib/util.php448
-rw-r--r--lib/xmlstringer.php68
-rw-r--r--plugins/GoogleAnalyticsPlugin.php77
-rwxr-xr-xscripts/startdaemons.sh3
-rwxr-xr-xscripts/stopdaemons.sh2
-rwxr-xr-xscripts/twitterqueuehandler.php71
-rwxr-xr-xscripts/update_facebook.php141
-rw-r--r--theme/base/css/display.css3
70 files changed, 3773 insertions, 1252 deletions
diff --git a/.gitignore b/.gitignore
index f5a3e0212..f2e96d3eb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,4 @@ dataobject.ini
*.bak
*.orig
*.rej
+.#*
diff --git a/EVENTS.txt b/EVENTS.txt
new file mode 100644
index 000000000..af0bee587
--- /dev/null
+++ b/EVENTS.txt
@@ -0,0 +1,84 @@
+InitializePlugin: a chance to initialize a plugin in a complete
+ environment
+
+CleanupPlugin: a chance to cleanup a plugin at the end of a program
+
+StartPrimaryNav: Showing the primary nav menu
+- $action: the current action
+
+EndPrimaryNav: At the end of the primary nav menu
+- $action: the current action
+
+StartSecondaryNav: Showing the secondary nav menu
+- $action: the current action
+
+EndSecondaryNav: At the end of the secondary nav menu
+- $action: the current action
+
+StartShowStyles: Showing Style links; good place to add UA style resets
+- $action: the current action
+
+EndShowStyles: End showing Style links; good place to add custom styles
+- $action: the current action
+
+StartShowLaconicaStyles: Showing Laconica Style links
+- $action: the current action
+
+EndShowLaconicaStyles: End showing Laconica Style links; good place to add handheld or JavaScript dependant styles
+- $action: the current action
+
+StartShowUAStyles: Showing custom UA Style links
+- $action: the current action
+
+EndShowUAStyles: End showing custom UA Style links; good place to add user-agent (e.g., filter, -webkit, -moz) specific styles
+- $action: the current action
+
+StartShowScripts: Showing JavaScript links
+- $action: the current action
+
+EndShowScripts: End showing JavaScript links; good place to add custom
+ links like Google Analytics
+- $action: the current action
+
+StartShowJQueryScripts: Showing JQuery script links (use this to link to e.g. Google mirrors)
+- $action: the current action
+
+EndShowJQueryScripts: End showing JQuery script links
+- $action: the current action
+
+StartShowLaconicaScripts: Showing Laconica script links (use this to link to a CDN or something)
+- $action: the current action
+
+EndShowLaconicaScripts: End showing Laconica script links
+- $action: the current action
+
+StartShowSections: Start the list of sections in the sidebar
+- $action: the current action
+
+EndShowSections: End the list of sections in the sidebar
+- $action: the current action
+
+StartShowHeader: Showing before the header container
+- $action: the current action
+
+EndShowHeader: Showing after the header container
+- $action: the current action
+
+StartShowFooter: Showing before the footer container
+- $action: the current action
+
+EndShowFooter: Showing after the footer container
+- $action: the current action
+
+StartShowContentBlock: Showing before the content container
+- $action: the current action
+
+EndShowContentBlock: Showing after the content container
+- $action: the current action
+
+StartNoticeSave: before inserting a notice (good place for content filters)
+- $notice: notice being saved (no ID or URI)
+
+EndNoticeSave: after inserting a notice and related code
+- $notice: notice that was saved (with ID and URI)
+
diff --git a/actions/all.php b/actions/all.php
index d75d1b946..08dcccbdd 100644
--- a/actions/all.php
+++ b/actions/all.php
@@ -42,9 +42,9 @@ class AllAction extends Action
if (!$this->page) {
$this->page = 1;
}
-
+
common_set_returnto($this->selfUrl());
-
+
return true;
}
@@ -69,13 +69,22 @@ class AllAction extends Action
}
}
- function showFeeds()
+ function getFeeds()
{
- $this->element('link', array('rel' => 'alternate',
- 'href' => common_local_url('allrss', array('nickname' =>
- $this->user->nickname)),
- 'type' => 'application/rss+xml',
- 'title' => sprintf(_('Feed for friends of %s'), $this->user->nickname)));
+ return array(new Feed(Feed::RSS1,
+ common_local_url('allrss', array('nickname' =>
+ $this->user->nickname)),
+ sprintf(_('Feed for friends of %s (RSS 1.0)'), $this->user->nickname)),
+ new Feed(Feed::RSS2,
+ common_local_url('api', array('apiaction' => 'statuses',
+ 'method' => 'friends',
+ 'argument' => $this->user->nickname.'.rss')),
+ sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->user->nickname)),
+ new Feed(Feed::ATOM,
+ common_local_url('api', array('apiaction' => 'statuses',
+ 'method' => 'friends',
+ 'argument' => $this->user->nickname.'.atom')),
+ sprintf(_('Feed for friends of %s (Atom)'), $this->user->nickname)));
}
function showLocalNav()
@@ -84,15 +93,6 @@ class AllAction extends Action
$nav->show();
}
- function showExportData()
- {
- $fl = new FeedList($this);
- $fl->show(array(0=>array('href'=>common_local_url('allrss', array('nickname' => $this->user->nickname)),
- 'type' => 'rss',
- 'version' => 'RSS 1.0',
- 'item' => 'allrss')));
- }
-
function showContent()
{
$notice = $this->user->noticesWithFriends(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
@@ -110,7 +110,7 @@ class AllAction extends Action
$user =& common_current_user();
if ($user && ($user->id == $this->user->id)) {
$this->element('h1', NULL, _("You and friends"));
- } else {
+ } else {
$this->element('h1', NULL, sprintf(_('%s and friends'), $this->user->nickname));
}
}
diff --git a/actions/avatarsettings.php b/actions/avatarsettings.php
index 7dd53f6eb..f38a44a24 100644
--- a/actions/avatarsettings.php
+++ b/actions/avatarsettings.php
@@ -145,6 +145,7 @@ class AvatarsettingsAction extends AccountSettingsAction
'height' => AVATAR_PROFILE_SIZE,
'alt' => $user->nickname));
$this->elementEnd('div');
+ $this->submit('delete', _('Delete'));
$this->elementEnd('li');
}
@@ -256,6 +257,8 @@ class AvatarsettingsAction extends AccountSettingsAction
$this->uploadAvatar();
} else if ($this->arg('crop')) {
$this->cropAvatar();
+ } else if ($this->arg('delete')) {
+ $this->deleteAvatar();
} else {
$this->showForm(_('Unexpected form submission.'));
}
@@ -344,6 +347,29 @@ class AvatarsettingsAction extends AccountSettingsAction
$this->showForm(_('Failed updating avatar.'));
}
}
+
+ /**
+ * Get rid of the current avatar.
+ *
+ * @return void
+ */
+
+ function deleteAvatar()
+ {
+ $user = common_current_user();
+ $profile = $user->getProfile();
+
+ $avatar = $profile->getOriginalAvatar();
+ $avatar->delete();
+ $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
+ $avatar->delete();
+ $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
+ $avatar->delete();
+ $avatar = $profile->getAvatar(AVATAR_MINI_SIZE);
+ $avatar->delete();
+
+ $this->showForm(_('Avatar deleted.'), true);
+ }
/**
* Add the jCrop stylesheet
diff --git a/actions/doc.php b/actions/doc.php
index 6957659ad..ebffb7c15 100644
--- a/actions/doc.php
+++ b/actions/doc.php
@@ -50,7 +50,7 @@ class DocAction extends Action
/**
* Class handler.
- *
+ *
* @param array $args array of arguments
*
* @return nothing
@@ -59,7 +59,7 @@ class DocAction extends Action
{
parent::handle($args);
$this->title = $this->trimmed('title');
- $this->filename = INSTALLDIR.'/doc/'.$this->title;
+ $this->filename = INSTALLDIR.'/doc-src/'.$this->title;
if (!file_exists($this->filename)) {
$this->clientError(_('No such document.'));
return;
@@ -71,14 +71,14 @@ class DocAction extends Action
function showPageTitle() {
$this->element('h1', array('class' => 'entry-title'), $this->title());
}
-
+
// overrided to add hentry, and content-inner classes
function showContentBlock()
{
$this->elementStart('div', array('id' => 'content', 'class' => 'hentry'));
$this->showPageTitle();
$this->showPageNoticeBlock();
- $this->elementStart('div', array('id' => 'content_inner',
+ $this->elementStart('div', array('id' => 'content_inner',
'class' => 'entry-content'));
// show the actual content (forms, lists, whatever)
$this->showContent();
@@ -88,7 +88,7 @@ class DocAction extends Action
/**
* Display content.
- *
+ *
* @return nothing
*/
function showContent()
@@ -100,7 +100,7 @@ class DocAction extends Action
/**
* Page title.
- *
+ *
* @return page title
*/
function title()
diff --git a/actions/newnotice.php b/actions/newnotice.php
index 5e7691f33..9face9644 100644
--- a/actions/newnotice.php
+++ b/actions/newnotice.php
@@ -98,7 +98,12 @@ class NewnoticeAction extends Action
return;
}
- $this->saveNewNotice();
+ try {
+ $this->saveNewNotice();
+ } catch (Exception $e) {
+ $this->showForm($e->getMessage());
+ return;
+ }
} else {
$this->showForm();
}
@@ -123,15 +128,13 @@ class NewnoticeAction extends Action
$content = $this->trimmed('status_textarea');
if (!$content) {
- $this->showForm(_('No content!'));
- return;
+ $this->clientError(_('No content!'));
} else {
$content_shortened = common_shorten_links($content);
if (mb_strlen($content_shortened) > 140) {
- $this->showForm(_('That\'s too long. '.
- 'Max notice size is 140 chars.'));
- return;
+ $this->clientError(_('That\'s too long. '.
+ 'Max notice size is 140 chars.'));
}
}
@@ -154,7 +157,7 @@ class NewnoticeAction extends Action
($replyto == 'false') ? null : $replyto);
if (is_string($notice)) {
- $this->showForm($notice);
+ $this->clientError($notice);
return;
}
diff --git a/actions/noticesearch.php b/actions/noticesearch.php
index a5f01350c..dc58d7528 100644
--- a/actions/noticesearch.php
+++ b/actions/noticesearch.php
@@ -57,11 +57,11 @@ class NoticesearchAction extends SearchAction
return true;
}
-
+
/**
* Get instructions
- *
- * @return string instruction text
+ *
+ * @return string instruction text
*/
function getInstructions()
{
@@ -70,7 +70,7 @@ class NoticesearchAction extends SearchAction
/**
* Get title
- *
+ *
* @return string title
*/
function title()
@@ -78,6 +78,20 @@ class NoticesearchAction extends SearchAction
return _('Text search');
}
+ function getFeeds()
+ {
+ $q = $this->trimmed('q');
+
+ if (!$q) {
+ return null;
+ }
+
+ return array(new Feed(Feed::RSS1, common_local_url('noticesearchrss',
+ array('q' => $q)),
+ sprintf(_('Search results for "%s" on %s'),
+ $q, common_config('site', 'name'))));
+ }
+
/**
* Show results
*
@@ -120,26 +134,6 @@ class NoticesearchAction extends SearchAction
}
/**
- * Show header
- *
- * @param array $arr array containing the query
- *
- * @return void
- */
-
- function extraHead()
- {
- $q = $this->trimmed('q');
- if ($q) {
- $this->element('link', array('rel' => 'alternate',
- 'href' => common_local_url('noticesearchrss',
- array('q' => $q)),
- 'type' => 'application/rss+xml',
- 'title' => _('Search Stream Feed')));
- }
- }
-
- /**
* Show notice
*
* @param class $notice notice
diff --git a/actions/public.php b/actions/public.php
index cc6537f74..a20ae4032 100644
--- a/actions/public.php
+++ b/actions/public.php
@@ -73,9 +73,9 @@ class PublicAction extends Action
{
parent::prepare($args);
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
-
+
common_set_returnto($this->selfUrl());
-
+
return true;
}
@@ -119,12 +119,20 @@ class PublicAction extends Action
* @return void
*/
- function showFeeds()
+ function getFeeds()
{
- $this->element('link', array('rel' => 'alternate',
- 'href' => common_local_url('publicrss'),
- 'type' => 'application/rss+xml',
- 'title' => _('Public Stream Feed')));
+ return array(new Feed(Feed::RSS1, common_local_url('publicrss'),
+ _('Public Stream Feed (RSS 1.0)')),
+ new Feed(Feed::RSS2,
+ common_local_url('api',
+ array('apiaction' => 'statuses',
+ 'method' => 'public_timeline.rss')),
+ _('Public Stream Feed (RSS 2.0)')),
+ new Feed(Feed::ATOM,
+ common_local_url('api',
+ array('apiaction' => 'statuses',
+ 'method' => 'public_timeline.atom')),
+ _('Public Stream Feed (Atom)')));
}
/**
@@ -185,27 +193,6 @@ class PublicAction extends Action
$this->page, 'public');
}
- /**
- * Makes a list of exported feeds for this page
- *
- * @return void
- *
- * @todo I18N
- */
-
- function showExportData()
- {
- $fl = new FeedList($this);
- $fl->show(array(0 => array('href' => common_local_url('publicrss'),
- 'type' => 'rss',
- 'version' => 'RSS 1.0',
- 'item' => 'publicrss'),
- 1 => array('href' => common_local_url('publicatom'),
- 'type' => 'atom',
- 'version' => 'Atom 1.0',
- 'item' => 'publicatom')));
- }
-
function showSections()
{
// $top = new TopPostersSection($this);
diff --git a/actions/replies.php b/actions/replies.php
index 7eff74a66..4ab9b14ed 100644
--- a/actions/replies.php
+++ b/actions/replies.php
@@ -84,7 +84,7 @@ class RepliesAction extends Action
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
common_set_returnto($this->selfUrl());
-
+
return true;
}
@@ -129,16 +129,13 @@ class RepliesAction extends Action
* @return void
*/
- function showFeeds()
+ function getFeeds()
{
$rssurl = common_local_url('repliesrss',
array('nickname' => $this->user->nickname));
$rsstitle = sprintf(_('Feed for replies to %s'), $this->user->nickname);
- $this->element('link', array('rel' => 'alternate',
- 'href' => $rssurl,
- 'type' => 'application/rss+xml',
- 'title' => $rsstitle));
+ return array(new Feed(Feed::RSS1, $rssurl, $rsstitle));
}
/**
@@ -154,25 +151,6 @@ class RepliesAction extends Action
}
/**
- * Show the replies feed links
- *
- * @return void
- */
-
- function showExportData()
- {
- $fl = new FeedList($this);
-
- $rssurl = common_local_url('repliesrss',
- array('nickname' => $this->user->nickname));
-
- $fl->show(array(0=>array('href'=> $rssurl,
- 'type' => 'rss',
- 'version' => 'RSS 1.0',
- 'item' => 'repliesrss')));
- }
-
- /**
* Show the content
*
* A list of notices that are replies to the user, plus pagination.
diff --git a/actions/showfavorites.php b/actions/showfavorites.php
index 31479e1a7..d1c9283f0 100644
--- a/actions/showfavorites.php
+++ b/actions/showfavorites.php
@@ -113,7 +113,7 @@ class ShowfavoritesAction extends Action
}
common_set_returnto($this->selfUrl());
-
+
return true;
}
@@ -136,10 +136,10 @@ class ShowfavoritesAction extends Action
/**
* Feeds for the <head> section
*
- * @return void
+ * @return array Feed objects to show
*/
- function showFeeds()
+ function getFeeds()
{
$feedurl = common_local_url('favoritesrss',
array('nickname' =>
@@ -147,10 +147,7 @@ class ShowfavoritesAction extends Action
$feedtitle = sprintf(_('Feed for favorites of %s'),
$this->user->nickname);
- $this->element('link', array('rel' => 'alternate',
- 'href' => $feedurl,
- 'type' => 'application/rss+xml',
- 'title' => $feedtitle));
+ return array(new Feed(Feed::RSS1, $feedurl, $feedtitle));
}
/**
@@ -166,28 +163,6 @@ class ShowfavoritesAction extends Action
}
/**
- * Show the replies feed links
- *
- * @return void
- */
-
- function showExportData()
- {
- $feedurl = common_local_url('favoritesrss',
- array('nickname' =>
- $this->user->nickname));
-
- $fl = new FeedList($this);
-
- // XXX: I18N
-
- $fl->show(array(0=>array('href'=> $feedurl,
- 'type' => 'rss',
- 'version' => 'RSS 1.0',
- 'item' => 'Favorites')));
- }
-
- /**
* Show the content
*
* A list of notices that this user has marked as a favorite
diff --git a/actions/showgroup.php b/actions/showgroup.php
index 7bc68fbc6..c20941a35 100644
--- a/actions/showgroup.php
+++ b/actions/showgroup.php
@@ -244,7 +244,7 @@ class ShowgroupAction extends Action
if ($this->group->location) {
$this->elementStart('dl', 'entity_location');
$this->element('dt', null, _('Location'));
- $this->element('dd', 'location', $this->group->location);
+ $this->element('dd', 'label', $this->group->location);
$this->elementEnd('dl');
}
@@ -292,37 +292,18 @@ class ShowgroupAction extends Action
}
/**
- * Show a list of links to feeds this page produces
+ * Get a list of the feeds for this page
*
* @return void
*/
- function showExportData()
- {
- $fl = new FeedList($this);
- $fl->show(array(0=>array('href'=>common_local_url('grouprss',
- array('nickname' => $this->group->nickname)),
- 'type' => 'rss',
- 'version' => 'RSS 1.0',
- 'item' => 'notices')));
- }
-
- /**
- * Show a list of links to feeds this page produces
- *
- * @return void
- */
-
- function showFeeds()
+ function getFeeds()
{
$url =
common_local_url('grouprss',
array('nickname' => $this->group->nickname));
- $this->element('link', array('rel' => 'alternate',
- 'href' => $url,
- 'type' => 'application/rss+xml',
- 'title' => sprintf(_('Notice feed for %s group'),
+ return array(new Feed(Feed::RSS1, $url, sprintf(_('Notice feed for %s group'),
$this->group->nickname)));
}
diff --git a/actions/showstream.php b/actions/showstream.php
index 28bb8453f..c736c99b5 100644
--- a/actions/showstream.php
+++ b/actions/showstream.php
@@ -111,7 +111,7 @@ class ShowstreamAction extends Action
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
common_set_returnto($this->selfUrl());
-
+
return true;
}
@@ -155,58 +155,39 @@ class ShowstreamAction extends Action
return;
}
- function showExportData()
- {
- $fl = new FeedList($this);
- $fl->show(array(0=>array('href'=>common_local_url('userrss',
- array('nickname' => $this->user->nickname)),
- 'type' => 'rss',
- 'version' => 'RSS 1.0',
- 'item' => 'notices'),
- 1=>array('href'=>common_local_url('usertimeline',
- array('nickname' => $this->user->nickname)),
- 'type' => 'atom',
- 'version' => 'Atom 1.0',
- 'item' => 'usertimeline'),
- 2=>array('href'=>common_local_url('foaf',
- array('nickname' => $this->user->nickname)),
- 'type' => 'rdf',
- 'version' => 'FOAF',
- 'item' => 'foaf')));
- }
-
- function showFeeds()
+ function getFeeds()
{
- $this->element('link', array('rel' => 'alternate',
- 'type' => 'application/rss+xml',
- 'href' => common_local_url('userrss',
- array('nickname' => $this->user->nickname)),
- 'title' => sprintf(_('Notice feed for %s (RSS)'),
- $this->user->nickname)));
-
- $this->element('link',
- array('rel' => 'alternate',
- 'href' => common_local_url('api',
- array('apiaction' => 'statuses',
- 'method' => 'user_timeline.atom',
- 'argument' => $this->user->nickname)),
- 'type' => 'application/atom+xml',
- 'title' => sprintf(_('Notice feed for %s (Atom)'),
- $this->user->nickname)));
+ return array(new Feed(Feed::RSS1,
+ common_local_url('userrss',
+ array('nickname' => $this->user->nickname)),
+ sprintf(_('Notice feed for %s (RSS 1.0)'),
+ $this->user->nickname)),
+ new Feed(Feed::RSS2,
+ common_local_url('api',
+ array('apiaction' => 'statuses',
+ 'method' => 'user_timeline',
+ 'argument' => $this->user->nickname.'.rss')),
+ sprintf(_('Notice feed for %s (RSS 2.0)'),
+ $this->user->nickname)),
+ new Feed(Feed::ATOM,
+ common_local_url('api',
+ array('apiaction' => 'statuses',
+ 'method' => 'user_timeline',
+ 'argument' => $this->user->nickname.'.atom')),
+ sprintf(_('Notice feed for %s (Atom)'),
+ $this->user->nickname)),
+ new Feed(Feed::FOAF,
+ common_local_url('foaf', array('nickname' =>
+ $this->user->nickname)),
+ sprintf(_('FOAF for %s'), $this->user->nickname)));
}
function extraHead()
{
- // FOAF
- $this->element('link', array('rel' => 'meta',
- 'href' => common_local_url('foaf', array('nickname' =>
- $this->user->nickname)),
- 'type' => 'application/rdf+xml',
- 'title' => 'FOAF'));
// for remote subscriptions etc.
$this->element('meta', array('http-equiv' => 'X-XRDS-Location',
'content' => common_local_url('xrds', array('nickname' =>
- $this->user->nickname))));
+ $this->user->nickname))));
if ($this->profile->bio) {
$this->element('meta', array('name' => 'description',
@@ -248,6 +229,15 @@ class ShowstreamAction extends Action
'height' => AVATAR_PROFILE_SIZE,
'alt' => $this->profile->nickname));
$this->elementEnd('dd');
+
+ $user = User::staticGet('id', $this->profile->id);
+ $cur = common_current_user();
+ if ($cur && $cur->id == $user->id) {
+ $this->elementStart('dd');
+ $this->element('a', array('href' => common_local_url('avatarsettings')), _('Edit Avatar'));
+ $this->elementEnd('dd');
+ }
+
$this->elementEnd('dl');
$this->elementStart('dl', 'entity_nickname');
@@ -256,7 +246,7 @@ class ShowstreamAction extends Action
$hasFN = ($this->profile->fullname) ? 'nickname url uid' : 'fn nickname url uid';
$this->element('a', array('href' => $this->profile->profileurl,
'rel' => 'me', 'class' => $hasFN),
- $this->profile->nickname);
+ $this->profile->nickname);
$this->elementEnd('dd');
$this->elementEnd('dl');
@@ -272,7 +262,7 @@ class ShowstreamAction extends Action
if ($this->profile->location) {
$this->elementStart('dl', 'entity_location');
$this->element('dt', null, _('Location'));
- $this->element('dd', 'location', $this->profile->location);
+ $this->element('dd', 'label', $this->profile->location);
$this->elementEnd('dl');
}
@@ -324,7 +314,7 @@ class ShowstreamAction extends Action
$this->elementStart('li', 'entity_edit');
$this->element('a', array('href' => common_local_url('profilesettings'),
'title' => _('Edit profile settings')),
- _('Edit'));
+ _('Edit'));
$this->elementEnd('li');
}
@@ -346,9 +336,8 @@ class ShowstreamAction extends Action
$this->elementEnd('li');
}
- $user = User::staticGet('id', $this->profile->id);
if ($cur && $cur->id != $user->id && $cur->mutuallySubscribed($user)) {
- $this->elementStart('li', 'entity_send-a-message');
+ $this->elementStart('li', 'entity_send-a-message');
$this->element('a', array('href' => common_local_url('newmessage', array('to' => $user->id)),
'title' => _('Send a direct message to this user')),
_('Message'));
@@ -490,7 +479,7 @@ class ShowstreamAction extends Action
$this->elementStart('dl', 'entity_member-since');
$this->element('dt', null, _('Member since'));
$this->element('dd', null, date('j M Y',
- strtotime($this->profile->created)));
+ strtotime($this->profile->created)));
$this->elementEnd('dl');
$this->elementStart('dl', 'entity_subscriptions');
diff --git a/actions/tag.php b/actions/tag.php
index 4401f892a..231f2c299 100644
--- a/actions/tag.php
+++ b/actions/tag.php
@@ -37,9 +37,9 @@ class TagAction extends Action
}
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
-
+
common_set_returnto($this->selfUrl());
-
+
return true;
}
@@ -61,12 +61,11 @@ class TagAction extends Action
$this->showPage();
}
- function showFeeds()
+ function getFeeds()
{
- $this->element('link', array('rel' => 'alternate',
- 'href' => common_local_url('tagrss', array('tag' => $this->tag)),
- 'type' => 'application/rss+xml',
- 'title' => sprintf(_('Feed for tag %s'), $this->tag)));
+ return array(new Feed(Feed::RSS1,
+ common_local_url('tagrss', array('tag' => $this->tag)),
+ sprintf(_('Feed for tag %s'), $this->tag)));
}
function showPageNotice()
@@ -74,15 +73,6 @@ class TagAction extends Action
return sprintf(_('Messages tagged "%s", most recent first'), $this->tag);
}
- function showExportData()
- {
- $fl = new FeedList($this);
- $fl->show(array(0=>array('href'=>common_local_url('tagrss', array('tag' => $this->tag)),
- 'type' => 'rss',
- 'version' => 'RSS 1.0',
- 'item' => 'tagrss')));
- }
-
function showContent()
{
$notice = Notice_tag::getStream($this->tag, (($this->page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
diff --git a/actions/tagother.php b/actions/tagother.php
index 3e8a12fd6..79151c911 100644
--- a/actions/tagother.php
+++ b/actions/tagother.php
@@ -110,7 +110,7 @@ class TagotherAction extends Action
if ($this->profile->location) {
$this->elementStart('dl', 'entity_location');
$this->element('dt', null, _('Location'));
- $this->element('dd', 'location', $this->profile->location);
+ $this->element('dd', 'label', $this->profile->location);
$this->elementEnd('dl');
}
if ($this->profile->homepage) {
diff --git a/actions/twittersettings.php b/actions/twittersettings.php
index 2d41469bb..a79859bbf 100644
--- a/actions/twittersettings.php
+++ b/actions/twittersettings.php
@@ -32,6 +32,7 @@ if (!defined('LACONICA')) {
}
require_once INSTALLDIR.'/lib/connectsettingsaction.php';
+require_once INSTALLDIR.'/lib/twitter.php';
define('SUBSCRIPTIONS', 80);
@@ -90,7 +91,7 @@ class TwittersettingsAction extends ConnectSettingsAction
$fuser = null;
- $flink = Foreign_link::getByUserID($user->id, 1); // 1 == Twitter
+ $flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
if ($flink) {
$fuser = $flink->getForeignUser();
@@ -358,7 +359,7 @@ class TwittersettingsAction extends ConnectSettingsAction
$flink->user_id = $user->id;
$flink->foreign_id = $twit_user->id;
- $flink->service = 1; // Twitter
+ $flink->service = TWITTER_SERVICE;
$flink->credentials = $password;
$flink->created = common_sql_now();
diff --git a/classes/Notice.php b/classes/Notice.php
index 329988368..6db59c96e 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -154,32 +154,37 @@ class Notice extends Memcached_DataObject
$notice->source = $source;
$notice->uri = $uri;
- $id = $notice->insert();
+ if (Event::handle('StartNoticeSave', array(&$notice))) {
- if (!$id) {
- common_log_db_error($notice, 'INSERT', __FILE__);
- return _('Problem saving notice.');
- }
-
- # Update the URI after the notice is in the database
- if (!$uri) {
- $orig = clone($notice);
- $notice->uri = common_notice_uri($notice);
+ $id = $notice->insert();
- if (!$notice->update($orig)) {
- common_log_db_error($notice, 'UPDATE', __FILE__);
+ if (!$id) {
+ common_log_db_error($notice, 'INSERT', __FILE__);
return _('Problem saving notice.');
}
- }
- # XXX: do we need to change this for remote users?
+ # Update the URI after the notice is in the database
+ if (!$uri) {
+ $orig = clone($notice);
+ $notice->uri = common_notice_uri($notice);
+
+ if (!$notice->update($orig)) {
+ common_log_db_error($notice, 'UPDATE', __FILE__);
+ return _('Problem saving notice.');
+ }
+ }
+
+ # XXX: do we need to change this for remote users?
- $notice->saveReplies();
- $notice->saveTags();
- $notice->saveGroups();
+ $notice->saveReplies();
+ $notice->saveTags();
+ $notice->saveGroups();
- $notice->addToInboxes();
- $notice->query('COMMIT');
+ $notice->addToInboxes();
+ $notice->query('COMMIT');
+
+ Event::handle('EndNoticeSave', array($notice));
+ }
# Clear the cache for subscribed users, so they'll update at next request
# XXX: someone clever could prepend instead of clearing the cache
diff --git a/classes/laconica.ini b/classes/laconica.ini
index 255122a97..19267f268 100755
--- a/classes/laconica.ini
+++ b/classes/laconica.ini
@@ -292,7 +292,8 @@ created = 142
modified = 384
[sms_carrier__keys]
-id = N
+id = K
+name = U
[subscription]
subscriber = 129
diff --git a/config.php.sample b/config.php.sample
index db1a21663..a2c5801f4 100644
--- a/config.php.sample
+++ b/config.php.sample
@@ -142,3 +142,7 @@ $config['sphinx']['port'] = 3312;
# config section for the built-in Facebook application
#$config['facebook']['apikey'] = 'APIKEY';
#$config['facebook']['secret'] = 'SECRET';
+
+# Add Google Analytics
+# require_once('plugins/GoogleAnalyticsPlugin.php');
+# $ga = new GoogleAnalyticsPlugin('your secret code');
diff --git a/db/carrier.sql b/db/carrier.sql
deleted file mode 100644
index 932f7c8bb..000000000
--- a/db/carrier.sql
+++ /dev/null
@@ -1,61 +0,0 @@
-insert into sms_carrier
- (name, email_pattern, created)
-values
- ('3 River Wireless', '%s@sms.3rivers.net', now()),
- ('7-11 Speakout', '%s@cingularme.com', now()),
- ('Airtel (Karnataka, India)', '%s@airtelkk.com', now()),
- ('Alaska Communications Systems', '%s@msg.acsalaska.com', now()),
- ('Alltel Wireless', '%s@message.alltel.com', now()),
- ('AT&T Wireless', '%s@txt.att.net', now()),
- ('Bell Mobility (Canada)', '%s@txt.bell.ca', now()),
- ('Boost Mobile', '%s@myboostmobile.com', now()),
- ('Cellular One (Dobson)', '%s@mobile.celloneusa.com', now()),
- ('Cincinnati Bell Wireless', '%s@gocbw.com', now()),
- ('Cingular (Postpaid)', '%s@cingularme.com', now()),
- ('Centennial Wireless', '%s@cwemail.com', now()),
- ('Cingular (GoPhone prepaid)', '%s@cingularme.com', now()),
- ('Claro (Nicaragua)', '%s@ideasclaro-ca.com', now()),
- ('Comcel', '%s@comcel.com.co', now()),
- ('Cricket', '%s@sms.mycricket.com', now()),
- ('CTI', '%s@sms.ctimovil.com.ar', now()),
- ('Emtel (Mauritius)', '%s@emtelworld.net', now()),
- ('Fido (Canada)', '%s@fido.ca', now()),
- ('General Communications Inc.', '%s@msg.gci.net', now()),
- ('Globalstar', '%s@msg.globalstarusa.com', now()),
- ('Helio', '%s@myhelio.com', now()),
- ('Illinois Valley Cellular', '%s@ivctext.com', now()),
- ('i wireless', '%s.iws@iwspcs.net', now()),
- ('Meteor (Ireland)', '%s@sms.mymeteor.ie', now()),
- ('Mero Mobile (Nepal)', '%s@sms.spicenepal.com', now()),
- ('MetroPCS', '%s@mymetropcs.com', now()),
- ('Movicom', '%s@movimensaje.com.ar', now()),
- ('Mobitel (Sri Lanka)', '%s@sms.mobitel.lk', now()),
- ('Movistar (Colombia)', '%s@movistar.com.co', now()),
- ('MTN (South Africa)', '%s@sms.co.za', now()),
- ('MTS (Canada)', '%s@text.mtsmobility.com', now()),
- ('Nextel (Argentina)', '%s@nextel.net.ar', now()),
- ('Orange (Poland)', '%s@orange.pl', now()),
- ('Orange (UK)', '%s@orange.net', now()),
- ('Personal (Argentina)', '%s@personal-net.com.ar', now()),
- ('Plus GSM (Poland)', '%s@text.plusgsm.pl', now()),
- ('President''s Choice (Canada)', '%s@txt.bell.ca', now()),
- ('Qwest', '%s@qwestmp.com', now()),
- ('Rogers (Canada)', '%s@pcs.rogers.com', now()),
- ('Sasktel (Canada)', '%s@sms.sasktel.com', now()),
- ('Setar Mobile email (Aruba)', '%s@mas.aw', now()),
- ('Solo Mobile', '%s@txt.bell.ca', now()),
- ('Sprint (PCS)', '%s@messaging.sprintpcs.com', now()),
- ('Sprint (Nextel)', '%s@page.nextel.com', now()),
- ('Suncom', '%s@tms.suncom.com', now()),
- ('T-Mobile', '%s@tmomail.net', now()),
- ('T-Mobile (Austria)', '%s@sms.t-mobile.at', now()),
- ('Telus Mobility (Canada)', '%s@msg.telus.com', now()),
- ('Thumb Cellular', '%s@sms.thumbcellular.com', now()),
- ('Tigo (Formerly Ola)', '%s@sms.tigo.com.co', now()),
- ('Unicel', '%s@utext.com', now()),
- ('US Cellular', '%s@email.uscc.net', now()),
- ('Verizon', '%s@vtext.com', now()),
- ('Virgin Mobile (Canada)', '%s@vmobile.ca', now()),
- ('Virgin Mobile (USA)', '%s@vmobl.com', now()),
- ('Vodafone NZ (txt ''R'' to 901 to enable first)', '%s@sms.vodafone.net.nz', now()),
- ('YCC', '%s@sms.ycc.ru', now());
diff --git a/db/laconica.sql b/db/laconica.sql
index 012270b51..15f03a978 100644
--- a/db/laconica.sql
+++ b/db/laconica.sql
@@ -31,7 +31,7 @@ create table avatar (
) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
create table sms_carrier (
- id integer auto_increment primary key comment 'primary key for SMS carrier',
+ id integer primary key comment 'primary key for SMS carrier',
name varchar(64) unique key comment 'name of the carrier',
email_pattern varchar(255) not null comment 'sprintf pattern for making an email address from a phone number',
created datetime not null comment 'date this record was created',
@@ -258,7 +258,8 @@ create table notice_tag (
created datetime not null comment 'date this record was created',
constraint primary key (tag, notice_id),
- index notice_tag_created_idx (created)
+ index notice_tag_created_idx (created),
+ index notice_tag_notice_id_idx (notice_id)
) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
/* Synching with foreign services */
@@ -356,7 +357,8 @@ create table profile_tag (
constraint primary key (tagger, tagged, tag),
index profile_tag_modified_idx (modified),
- index profile_tag_tagger_tag_idx (tagger, tag)
+ index profile_tag_tagger_tag_idx (tagger, tag),
+ index profile_tag_tagged_idx (tagged)
) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
create table profile_block (
@@ -400,7 +402,9 @@ create table group_member (
created datetime not null comment 'date this record was created',
modified timestamp comment 'date this record was modified',
- constraint primary key (group_id, profile_id)
+ constraint primary key (group_id, profile_id),
+ index group_member_profile_id_idx (profile_id),
+ index group_member_created_idx (created)
) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
diff --git a/db/sms_carrier.sql b/db/sms_carrier.sql
new file mode 100644
index 000000000..6879f2089
--- /dev/null
+++ b/db/sms_carrier.sql
@@ -0,0 +1,63 @@
+INSERT INTO sms_carrier
+ (id, name, email_pattern, created)
+VALUES
+ (100056, '3 River Wireless', '%s@sms.3rivers.net', now()),
+ (100057, '7-11 Speakout', '%s@cingularme.com', now()),
+ (100058, 'Airtel (Karnataka, India)', '%s@airtelkk.com', now()),
+ (100059, 'Alaska Communications Systems', '%s@msg.acsalaska.com', now()),
+ (100060, 'Alltel Wireless', '%s@message.alltel.com', now()),
+ (100061, 'AT&T Wireless', '%s@txt.att.net', now()),
+ (100062, 'Bell Mobility (Canada)', '%s@txt.bell.ca', now()),
+ (100063, 'Boost Mobile', '%s@myboostmobile.com', now()),
+ (100064, 'Cellular One (Dobson)', '%s@mobile.celloneusa.com', now()),
+ (100065, 'Cingular (Postpaid)', '%s@cingularme.com', now()),
+ (100066, 'Centennial Wireless', '%s@cwemail.com', now()),
+ (100067, 'Cingular (GoPhone prepaid)', '%s@cingularme.com', now()),
+ (100068, 'Claro (Nicaragua)', '%s@ideasclaro-ca.com', now()),
+ (100069, 'Comcel', '%s@comcel.com.co', now()),
+ (100070, 'Cricket', '%s@sms.mycricket.com', now()),
+ (100071, 'CTI', '%s@sms.ctimovil.com.ar', now()),
+ (100072, 'Emtel (Mauritius)', '%s@emtelworld.net', now()),
+ (100073, 'Fido (Canada)', '%s@fido.ca', now()),
+ (100074, 'General Communications Inc.', '%s@msg.gci.net', now()),
+ (100075, 'Globalstar', '%s@msg.globalstarusa.com', now()),
+ (100076, 'Helio', '%s@myhelio.com', now()),
+ (100077, 'Illinois Valley Cellular', '%s@ivctext.com', now()),
+ (100078, 'i wireless', '%s.iws@iwspcs.net', now()),
+ (100079, 'Meteor (Ireland)', '%s@sms.mymeteor.ie', now()),
+ (100080, 'Mero Mobile (Nepal)', '%s@sms.spicenepal.com', now()),
+ (100081, 'MetroPCS', '%s@mymetropcs.com', now()),
+ (100082, 'Movicom', '%s@movimensaje.com.ar', now()),
+ (100083, 'Mobitel (Sri Lanka)', '%s@sms.mobitel.lk', now()),
+ (100084, 'Movistar (Colombia)', '%s@movistar.com.co', now()),
+ (100085, 'MTN (South Africa)', '%s@sms.co.za', now()),
+ (100086, 'MTS (Canada)', '%s@text.mtsmobility.com', now()),
+ (100087, 'Nextel (Argentina)', '%s@nextel.net.ar', now()),
+ (100088, 'Orange (Poland)', '%s@orange.pl', now()),
+ (100089, 'Personal (Argentina)', '%s@personal-net.com.ar', now()),
+ (100090, 'Plus GSM (Poland)', '%s@text.plusgsm.pl', now()),
+ (100091, 'President\'s Choice (Canada)', '%s@txt.bell.ca', now()),
+ (100092, 'Qwest', '%s@qwestmp.com', now()),
+ (100093, 'Rogers (Canada)', '%s@pcs.rogers.com', now()),
+ (100094, 'Sasktel (Canada)', '%s@sms.sasktel.com', now()),
+ (100095, 'Setar Mobile email (Aruba)', '%s@mas.aw', now()),
+ (100096, 'Solo Mobile', '%s@txt.bell.ca', now()),
+ (100097, 'Sprint (PCS)', '%s@messaging.sprintpcs.com', now()),
+ (100098, 'Sprint (Nextel)', '%s@page.nextel.com', now()),
+ (100099, 'Suncom', '%s@tms.suncom.com', now()),
+ (100100, 'T-Mobile', '%s@tmomail.net', now()),
+ (100101, 'T-Mobile (Austria)', '%s@sms.t-mobile.at', now()),
+ (100102, 'Telus Mobility (Canada)', '%s@msg.telus.com', now()),
+ (100103, 'Thumb Cellular', '%s@sms.thumbcellular.com', now()),
+ (100104, 'Tigo (Formerly Ola)', '%s@sms.tigo.com.co', now()),
+ (100105, 'Unicel', '%s@utext.com', now()),
+ (100106, 'US Cellular', '%s@email.uscc.net', now()),
+ (100107, 'Verizon', '%s@vtext.com', now()),
+ (100108, 'Virgin Mobile (Canada)', '%s@vmobile.ca', now()),
+ (100109, 'Virgin Mobile (USA)', '%s@vmobl.com', now()),
+ (100110, 'YCC', '%s@sms.ycc.ru', now()),
+ (100111, 'Orange (UK)', '%s@orange.net', now()),
+ (100112, 'Cincinnati Bell Wireless', '%s@gocbw.com', now()),
+ (100113, 'T-Mobile Germany', '%s@t-mobile-sms.de', now()),
+ (100114, 'Vodafone Germany', '%s@vodafone-sms.de', now()),
+ (100115, 'E-Plus', '%s@smsmail.eplus.de', now());
diff --git a/doc/about b/doc-src/about
index 3036a51b9..3036a51b9 100644
--- a/doc/about
+++ b/doc-src/about
diff --git a/doc/contact b/doc-src/contact
index a8efc456a..a8efc456a 100644
--- a/doc/contact
+++ b/doc-src/contact
diff --git a/doc/faq b/doc-src/faq
index 31582b9f0..31582b9f0 100644
--- a/doc/faq
+++ b/doc-src/faq
diff --git a/doc/groups b/doc-src/groups
index 645390e0c..645390e0c 100644
--- a/doc/groups
+++ b/doc-src/groups
diff --git a/doc/help b/doc-src/help
index a8cfccd2b..a8cfccd2b 100644
--- a/doc/help
+++ b/doc-src/help
diff --git a/doc/im b/doc-src/im
index da07f9fe7..da07f9fe7 100644
--- a/doc/im
+++ b/doc-src/im
diff --git a/doc/openid b/doc-src/openid
index c741e3674..c741e3674 100644
--- a/doc/openid
+++ b/doc-src/openid
diff --git a/doc/openmublog b/doc-src/openmublog
index 6e3abee42..6e3abee42 100644
--- a/doc/openmublog
+++ b/doc-src/openmublog
diff --git a/doc/privacy b/doc-src/privacy
index 90c7b3c7f..90c7b3c7f 100644
--- a/doc/privacy
+++ b/doc-src/privacy
diff --git a/doc/sms b/doc-src/sms
index 1beb49786..1beb49786 100644
--- a/doc/sms
+++ b/doc-src/sms
diff --git a/doc/source b/doc-src/source
index 83debbe53..83debbe53 100644
--- a/doc/source
+++ b/doc-src/source
diff --git a/doc/tags b/doc-src/tags
index 2ed352e70..2ed352e70 100644
--- a/doc/tags
+++ b/doc-src/tags
diff --git a/extlib/Net/URL.php b/extlib/Net/URL.php
new file mode 100644
index 000000000..3dcfef60d
--- /dev/null
+++ b/extlib/Net/URL.php
@@ -0,0 +1,485 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Copyright (c) 2002-2004, Richard Heyes |
+// | All rights reserved. |
+// | |
+// | Redistribution and use in source and binary forms, with or without |
+// | modification, are permitted provided that the following conditions |
+// | are met: |
+// | |
+// | o Redistributions of source code must retain the above copyright |
+// | notice, this list of conditions and the following disclaimer. |
+// | o Redistributions in binary form must reproduce the above copyright |
+// | notice, this list of conditions and the following disclaimer in the |
+// | documentation and/or other materials provided with the distribution.|
+// | o The names of the authors may not be used to endorse or promote |
+// | products derived from this software without specific prior written |
+// | permission. |
+// | |
+// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+// | |
+// +-----------------------------------------------------------------------+
+// | Author: Richard Heyes <richard at php net> |
+// +-----------------------------------------------------------------------+
+//
+// $Id: URL.php,v 1.49 2007/06/28 14:43:07 davidc Exp $
+//
+// Net_URL Class
+
+
+class Net_URL
+{
+ var $options = array('encode_query_keys' => false);
+ /**
+ * Full url
+ * @var string
+ */
+ var $url;
+
+ /**
+ * Protocol
+ * @var string
+ */
+ var $protocol;
+
+ /**
+ * Username
+ * @var string
+ */
+ var $username;
+
+ /**
+ * Password
+ * @var string
+ */
+ var $password;
+
+ /**
+ * Host
+ * @var string
+ */
+ var $host;
+
+ /**
+ * Port
+ * @var integer
+ */
+ var $port;
+
+ /**
+ * Path
+ * @var string
+ */
+ var $path;
+
+ /**
+ * Query string
+ * @var array
+ */
+ var $querystring;
+
+ /**
+ * Anchor
+ * @var string
+ */
+ var $anchor;
+
+ /**
+ * Whether to use []
+ * @var bool
+ */
+ var $useBrackets;
+
+ /**
+ * PHP4 Constructor
+ *
+ * @see __construct()
+ */
+ function Net_URL($url = null, $useBrackets = true)
+ {
+ $this->__construct($url, $useBrackets);
+ }
+
+ /**
+ * PHP5 Constructor
+ *
+ * Parses the given url and stores the various parts
+ * Defaults are used in certain cases
+ *
+ * @param string $url Optional URL
+ * @param bool $useBrackets Whether to use square brackets when
+ * multiple querystrings with the same name
+ * exist
+ */
+ function __construct($url = null, $useBrackets = true)
+ {
+ $this->url = $url;
+ $this->useBrackets = $useBrackets;
+
+ $this->initialize();
+ }
+
+ function initialize()
+ {
+ $HTTP_SERVER_VARS = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
+
+ $this->user = '';
+ $this->pass = '';
+ $this->host = '';
+ $this->port = 80;
+ $this->path = '';
+ $this->querystring = array();
+ $this->anchor = '';
+
+ // Only use defaults if not an absolute URL given
+ if (!preg_match('/^[a-z0-9]+:\/\//i', $this->url)) {
+ $this->protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http');
+
+ /**
+ * Figure out host/port
+ */
+ if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) &&
+ preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches))
+ {
+ $host = $matches[1];
+ if (!empty($matches[3])) {
+ $port = $matches[3];
+ } else {
+ $port = $this->getStandardPort($this->protocol);
+ }
+ }
+
+ $this->user = '';
+ $this->pass = '';
+ $this->host = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost');
+ $this->port = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : $this->getStandardPort($this->protocol));
+ $this->path = !empty($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : '/';
+ $this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null;
+ $this->anchor = '';
+ }
+
+ // Parse the url and store the various parts
+ if (!empty($this->url)) {
+ $urlinfo = parse_url($this->url);
+
+ // Default querystring
+ $this->querystring = array();
+
+ foreach ($urlinfo as $key => $value) {
+ switch ($key) {
+ case 'scheme':
+ $this->protocol = $value;
+ $this->port = $this->getStandardPort($value);
+ break;
+
+ case 'user':
+ case 'pass':
+ case 'host':
+ case 'port':
+ $this->$key = $value;
+ break;
+
+ case 'path':
+ if ($value{0} == '/') {
+ $this->path = $value;
+ } else {
+ $path = dirname($this->path) == DIRECTORY_SEPARATOR ? '' : dirname($this->path);
+ $this->path = sprintf('%s/%s', $path, $value);
+ }
+ break;
+
+ case 'query':
+ $this->querystring = $this->_parseRawQueryString($value);
+ break;
+
+ case 'fragment':
+ $this->anchor = $value;
+ break;
+ }
+ }
+ }
+ }
+ /**
+ * Returns full url
+ *
+ * @return string Full url
+ * @access public
+ */
+ function getURL()
+ {
+ $querystring = $this->getQueryString();
+
+ $this->url = $this->protocol . '://'
+ . $this->user . (!empty($this->pass) ? ':' : '')
+ . $this->pass . (!empty($this->user) ? '@' : '')
+ . $this->host . ($this->port == $this->getStandardPort($this->protocol) ? '' : ':' . $this->port)
+ . $this->path
+ . (!empty($querystring) ? '?' . $querystring : '')
+ . (!empty($this->anchor) ? '#' . $this->anchor : '');
+
+ return $this->url;
+ }
+
+ /**
+ * Adds or updates a querystring item (URL parameter).
+ * Automatically encodes parameters with rawurlencode() if $preencoded
+ * is false.
+ * You can pass an array to $value, it gets mapped via [] in the URL if
+ * $this->useBrackets is activated.
+ *
+ * @param string $name Name of item
+ * @param string $value Value of item
+ * @param bool $preencoded Whether value is urlencoded or not, default = not
+ * @access public
+ */
+ function addQueryString($name, $value, $preencoded = false)
+ {
+ if ($this->getOption('encode_query_keys')) {
+ $name = rawurlencode($name);
+ }
+
+ if ($preencoded) {
+ $this->querystring[$name] = $value;
+ } else {
+ $this->querystring[$name] = is_array($value) ? array_map('rawurlencode', $value): rawurlencode($value);
+ }
+ }
+
+ /**
+ * Removes a querystring item
+ *
+ * @param string $name Name of item
+ * @access public
+ */
+ function removeQueryString($name)
+ {
+ if ($this->getOption('encode_query_keys')) {
+ $name = rawurlencode($name);
+ }
+
+ if (isset($this->querystring[$name])) {
+ unset($this->querystring[$name]);
+ }
+ }
+
+ /**
+ * Sets the querystring to literally what you supply
+ *
+ * @param string $querystring The querystring data. Should be of the format foo=bar&x=y etc
+ * @access public
+ */
+ function addRawQueryString($querystring)
+ {
+ $this->querystring = $this->_parseRawQueryString($querystring);
+ }
+
+ /**
+ * Returns flat querystring
+ *
+ * @return string Querystring
+ * @access public
+ */
+ function getQueryString()
+ {
+ if (!empty($this->querystring)) {
+ foreach ($this->querystring as $name => $value) {
+ // Encode var name
+ $name = rawurlencode($name);
+
+ if (is_array($value)) {
+ foreach ($value as $k => $v) {
+ $querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name . '=' . $v);
+ }
+ } elseif (!is_null($value)) {
+ $querystring[] = $name . '=' . $value;
+ } else {
+ $querystring[] = $name;
+ }
+ }
+ $querystring = implode(ini_get('arg_separator.output'), $querystring);
+ } else {
+ $querystring = '';
+ }
+
+ return $querystring;
+ }
+
+ /**
+ * Parses raw querystring and returns an array of it
+ *
+ * @param string $querystring The querystring to parse
+ * @return array An array of the querystring data
+ * @access private
+ */
+ function _parseRawQuerystring($querystring)
+ {
+ $parts = preg_split('/[' . preg_quote(ini_get('arg_separator.input'), '/') . ']/', $querystring, -1, PREG_SPLIT_NO_EMPTY);
+ $return = array();
+
+ foreach ($parts as $part) {
+ if (strpos($part, '=') !== false) {
+ $value = substr($part, strpos($part, '=') + 1);
+ $key = substr($part, 0, strpos($part, '='));
+ } else {
+ $value = null;
+ $key = $part;
+ }
+
+ if (!$this->getOption('encode_query_keys')) {
+ $key = rawurldecode($key);
+ }
+
+ if (preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) {
+ $key = $matches[1];
+ $idx = $matches[2];
+
+ // Ensure is an array
+ if (empty($return[$key]) || !is_array($return[$key])) {
+ $return[$key] = array();
+ }
+
+ // Add data
+ if ($idx === '') {
+ $return[$key][] = $value;
+ } else {
+ $return[$key][$idx] = $value;
+ }
+ } elseif (!$this->useBrackets AND !empty($return[$key])) {
+ $return[$key] = (array)$return[$key];
+ $return[$key][] = $value;
+ } else {
+ $return[$key] = $value;
+ }
+ }
+
+ return $return;
+ }
+
+ /**
+ * Resolves //, ../ and ./ from a path and returns
+ * the result. Eg:
+ *
+ * /foo/bar/../boo.php => /foo/boo.php
+ * /foo/bar/../../boo.php => /boo.php
+ * /foo/bar/.././/boo.php => /foo/boo.php
+ *
+ * This method can also be called statically.
+ *
+ * @param string $path URL path to resolve
+ * @return string The result
+ */
+ function resolvePath($path)
+ {
+ $path = explode('/', str_replace('//', '/', $path));
+
+ for ($i=0; $i<count($path); $i++) {
+ if ($path[$i] == '.') {
+ unset($path[$i]);
+ $path = array_values($path);
+ $i--;
+
+ } elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != '') ) ) {
+ unset($path[$i]);
+ unset($path[$i-1]);
+ $path = array_values($path);
+ $i -= 2;
+
+ } elseif ($path[$i] == '..' AND $i == 1 AND $path[0] == '') {
+ unset($path[$i]);
+ $path = array_values($path);
+ $i--;
+
+ } else {
+ continue;
+ }
+ }
+
+ return implode('/', $path);
+ }
+
+ /**
+ * Returns the standard port number for a protocol
+ *
+ * @param string $scheme The protocol to lookup
+ * @return integer Port number or NULL if no scheme matches
+ *
+ * @author Philippe Jausions <Philippe.Jausions@11abacus.com>
+ */
+ function getStandardPort($scheme)
+ {
+ switch (strtolower($scheme)) {
+ case 'http': return 80;
+ case 'https': return 443;
+ case 'ftp': return 21;
+ case 'imap': return 143;
+ case 'imaps': return 993;
+ case 'pop3': return 110;
+ case 'pop3s': return 995;
+ default: return null;
+ }
+ }
+
+ /**
+ * Forces the URL to a particular protocol
+ *
+ * @param string $protocol Protocol to force the URL to
+ * @param integer $port Optional port (standard port is used by default)
+ */
+ function setProtocol($protocol, $port = null)
+ {
+ $this->protocol = $protocol;
+ $this->port = is_null($port) ? $this->getStandardPort($protocol) : $port;
+ }
+
+ /**
+ * Set an option
+ *
+ * This function set an option
+ * to be used thorough the script.
+ *
+ * @access public
+ * @param string $optionName The optionname to set
+ * @param string $value The value of this option.
+ */
+ function setOption($optionName, $value)
+ {
+ if (!array_key_exists($optionName, $this->options)) {
+ return false;
+ }
+
+ $this->options[$optionName] = $value;
+ $this->initialize();
+ }
+
+ /**
+ * Get an option
+ *
+ * This function gets an option
+ * from the $this->options array
+ * and return it's value.
+ *
+ * @access public
+ * @param string $opionName The name of the option to retrieve
+ * @see $this->options
+ */
+ function getOption($optionName)
+ {
+ if (!isset($this->options[$optionName])) {
+ return false;
+ }
+
+ return $this->options[$optionName];
+ }
+
+}
+?>
diff --git a/extlib/Net/URL/Mapper.php b/extlib/Net/URL/Mapper.php
new file mode 100644
index 000000000..65e38818b
--- /dev/null
+++ b/extlib/Net/URL/Mapper.php
@@ -0,0 +1,324 @@
+<?php
+/**
+ * URL parser and mapper
+ *
+ * PHP version 5
+ *
+ * LICENSE:
+ *
+ * Copyright (c) 2006, Bertrand Mansion <golgote@mamasam.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * The names of the authors may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @category Net
+ * @package Net_URL_Mapper
+ * @author Bertrand Mansion <golgote@mamasam.com>
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @version CVS: $Id: Mapper.php,v 1.1 2007/03/28 10:23:04 mansion Exp $
+ * @link http://pear.php.net/package/Net_URL_Mapper
+ */
+
+require_once 'Net/URL/Mapper/Path.php';
+require_once 'Net/URL/Mapper/Exception.php';
+
+/**
+ * URL parser and mapper class
+ *
+ * This class takes an URL and a configuration and returns formatted data
+ * about the request according to a configuration parameter
+ *
+ * @category Net
+ * @package Net_URL_Mapper
+ * @author Bertrand Mansion <golgote@mamasam.com>
+ * @version Release: @package_version@
+ */
+class Net_URL_Mapper
+{
+ /**
+ * Array of Net_URL_Mapper instances
+ * @var array
+ */
+ private static $instances = array();
+
+ /**
+ * Mapped paths collection
+ * @var array
+ */
+ protected $paths = array();
+
+ /**
+ * Prefix used for url mapping
+ * @var string
+ */
+ protected $prefix = '';
+
+ /**
+ * Optional scriptname if mod_rewrite is not available
+ * @var string
+ */
+ protected $scriptname = '';
+
+ /**
+ * Mapper instance id
+ * @var string
+ */
+ protected $id = '__default__';
+
+ /**
+ * Class constructor
+ * Constructor is private, you should use getInstance() instead.
+ */
+ private function __construct() { }
+
+ /**
+ * Returns a singleton object corresponding to the requested instance id
+ * @param string Requested instance name
+ * @return Object Net_URL_Mapper Singleton
+ */
+ public static function getInstance($id = '__default__')
+ {
+ if (!isset(self::$instances[$id])) {
+ $m = new Net_URL_Mapper();
+ $m->id = $id;
+ self::$instances[$id] = $m;
+ }
+ return self::$instances[$id];
+ }
+
+ /**
+ * Returns the instance id
+ * @return string Mapper instance id
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * Parses a path and creates a connection
+ * @param string The path to connect
+ * @param array Default values for path parts
+ * @param array Regular expressions for path parts
+ * @return object Net_URL_Mapper_Path
+ */
+ public function connect($path, $defaults = array(), $rules = array())
+ {
+ $pathObj = new Net_URL_Mapper_Path($path, $defaults, $rules);
+ $this->addPath($pathObj);
+ return $pathObj;
+ }
+
+ /**
+ * Set the url prefix if needed
+ *
+ * Example: using the prefix to differenciate mapper instances
+ * <code>
+ * $fr = Net_URL_Mapper::getInstance('fr');
+ * $fr->setPrefix('/fr');
+ * $en = Net_URL_Mapper::getInstance('en');
+ * $en->setPrefix('/en');
+ * </code>
+ *
+ * @param string URL prefix
+ */
+ public function setPrefix($prefix)
+ {
+ $this->prefix = '/'.trim($prefix, '/');
+ }
+
+ /**
+ * Set the scriptname if mod_rewrite not available
+ *
+ * Example: will match and generate url like
+ * - index.php/view/product/1
+ * <code>
+ * $m = Net_URL_Mapper::getInstance();
+ * $m->setScriptname('index.php');
+ * </code>
+ * @param string URL prefix
+ */
+ public function setScriptname($scriptname)
+ {
+ $this->scriptname = $scriptname;
+ }
+
+ /**
+ * Will attempt to match an url with a defined path
+ *
+ * If an url corresponds to a path, the resulting values are returned
+ * in an array. If none is found, null is returned. In case an url is
+ * matched but its content doesn't validate the path rules, an exception is
+ * thrown.
+ *
+ * @param string URL
+ * @return array|null array if match found, null otherwise
+ * @throws Net_URL_Mapper_InvalidException
+ */
+ public function match($url)
+ {
+ $nurl = '/'.trim($url, '/');
+
+ // Remove scriptname if needed
+
+ if (!empty($this->scriptname) &&
+ strpos($nurl, $this->scriptname) === 0) {
+ $nurl = substr($nurl, strlen($this->scriptname));
+ if (empty($nurl)) {
+ $nurl = '/';
+ }
+ }
+
+ // Remove prefix
+
+ if (!empty($this->prefix)) {
+ if (strpos($nurl, $this->prefix) !== 0) {
+ return null;
+ }
+ $nurl = substr($nurl, strlen($this->prefix));
+ if (empty($nurl)) {
+ $nurl = '/';
+ }
+ }
+
+ // Remove query string
+
+ if (($pos = strpos($nurl, '?')) !== false) {
+ $nurl = substr($nurl, 0, $pos);
+ }
+
+ $paths = array();
+ $values = null;
+
+ // Make a list of paths that conform to route format
+
+ foreach ($this->paths as $path) {
+ $regex = $path->getFormat();
+ if (preg_match($regex, $nurl)) {
+ $paths[] = $path;
+ }
+ }
+
+ // Make sure one of the paths found is valid
+
+ foreach ($paths as $path) {
+ $regex = $path->getRule();
+ if (preg_match($regex, $nurl, $matches)) {
+ $values = $path->getDefaults();
+ array_shift($matches);
+ $clean = array();
+ foreach ($matches as $k => $v) {
+ $v = trim($v, '/');
+ if (!is_int($k) && $v !== '') {
+ $values[$k] = $v;
+ }
+ }
+ break;
+ }
+ }
+
+ // A path conforms but does not validate
+
+ if (is_null($values) && !empty($paths)) {
+ $e = new Net_URL_Mapper_InvalidException('A path was found but is invalid.');
+ $e->setPath($paths[0]);
+ $e->setUrl($url);
+ throw $e;
+ }
+
+ return $values;
+ }
+
+ /**
+ * Generate an url based on given parameters
+ *
+ * Will attempt to find a path definition that matches the given parameters and
+ * will generate an url based on this path.
+ *
+ * @param array Values to be used for the url generation
+ * @param array Key/value pairs for query string if needed
+ * @param string Anchor (fragment) if needed
+ * @return string|false String if a rule was found, false otherwise
+ */
+ public function generate($values = array(), $qstring = array(), $anchor = '')
+ {
+ // Use root path if any
+
+ if (empty($values) && isset($this->paths['/'])) {
+ return $this->scriptname.$this->prefix.$this->paths['/']->generate($values, $qstring, $anchor);
+ }
+
+ foreach ($this->paths as $path) {
+ $set = array();
+ foreach ($values as $k => $v) {
+ if ($path->hasKey($k, $v)) {
+ $set[$k] = $v;
+ }
+ }
+
+ if (count($set) == count($values) &&
+ count($set) <= $path->getMaxKeys()) {
+
+ $req = $path->getRequired();
+ if (count(array_intersect(array_keys($set), $req)) != count($req)) {
+ continue;
+ }
+ $gen = $path->generate($set, $qstring, $anchor);
+ return $this->scriptname.$this->prefix.$gen;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns defined paths
+ * @return array Array of paths
+ */
+ public function getPaths()
+ {
+ return $this->paths;
+ }
+
+ /**
+ * Reset all paths
+ * This is probably only useful for testing
+ */
+ public function reset()
+ {
+ $this->paths = array();
+ $this->prefix = '';
+ }
+
+ /**
+ * Add a new path to the mapper
+ * @param object Net_URL_Mapper_Path object
+ */
+ public function addPath(Net_URL_Mapper_Path $path)
+ {
+ $this->paths[$path->getPath()] = $path;
+ }
+
+}
+?> \ No newline at end of file
diff --git a/extlib/Net/URL/Mapper/Exception.php b/extlib/Net/URL/Mapper/Exception.php
new file mode 100644
index 000000000..ac3ad172b
--- /dev/null
+++ b/extlib/Net/URL/Mapper/Exception.php
@@ -0,0 +1,104 @@
+<?php
+/**
+ * Exception classes for Net_URL_Mapper
+ *
+ * PHP version 5
+ *
+ * LICENSE:
+ *
+ * Copyright (c) 2006, Bertrand Mansion <golgote@mamasam.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * The names of the authors may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @category Net
+ * @package Net_URL_Mapper
+ * @author Bertrand Mansion <golgote@mamasam.com>
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @version CVS: $Id: Exception.php,v 1.1 2007/03/28 10:23:04 mansion Exp $
+ * @link http://pear.php.net/package/Net_URL_Mapper
+ */
+
+/**
+ * Base class for exceptions in PEAR
+ */
+require_once 'PEAR/Exception.php';
+
+/**
+ * Base class for exceptions in Net_URL_Mapper package
+ *
+ * Such a base class is required by the Exception RFC:
+ * http://pear.php.net/pepr/pepr-proposal-show.php?id=132
+ * It will rarely be thrown directly, its specialized subclasses will be
+ * thrown most of the time.
+ *
+ * @category Net
+ * @package Net_URL_Mapper
+ * @version Release: @package_version@
+ */
+class Net_URL_Mapper_Exception extends PEAR_Exception
+{
+}
+
+/**
+ * Exception thrown when a path is invalid
+ *
+ * A path can conform to a given structure, but contain invalid parameters.
+ * <code>
+ * $m = Net_URL_Mapper::getInstance();
+ * $m->connect('hi/:name', null, array('name'=>'[a-z]+'));
+ * $m->match('/hi/FOXY'); // Will throw the exception
+ * </code>
+ *
+ * @category Net
+ * @package Net_URL_Mapper
+ * @version Release: @package_version@
+ */
+class Net_URL_Mapper_InvalidException extends Net_URL_Mapper_Exception
+{
+ protected $path;
+ protected $url;
+
+ public function setPath($path)
+ {
+ $this->path = $path;
+ }
+
+ public function getPath()
+ {
+ return $this->path;
+ }
+
+ public function setUrl($url)
+ {
+ $this->url = $url;
+ }
+
+ public function getUrl()
+ {
+ return $this->url;
+ }
+}
+?> \ No newline at end of file
diff --git a/extlib/Net/URL/Mapper/Part.php b/extlib/Net/URL/Mapper/Part.php
new file mode 100644
index 000000000..2f15b2c16
--- /dev/null
+++ b/extlib/Net/URL/Mapper/Part.php
@@ -0,0 +1,142 @@
+<?php
+/**
+ * URL parser and mapper
+ *
+ * PHP version 5
+ *
+ * LICENSE:
+ *
+ * Copyright (c) 2006, Bertrand Mansion <golgote@mamasam.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * The names of the authors may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @category Net
+ * @package Net_URL_Mapper
+ * @author Bertrand Mansion <golgote@mamasam.com>
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @version CVS: $Id: Part.php,v 1.1 2007/03/28 10:23:04 mansion Exp $
+ * @link http://pear.php.net/package/Net_URL_Mapper
+ */
+
+abstract class Net_URL_Mapper_Part
+{
+ protected $defaults;
+ protected $rule;
+ protected $public;
+ protected $type;
+ protected $required = false;
+
+ /**
+ * Part name if dynamic or content, generated from path
+ * @var string
+ */
+ public $content;
+
+ const DYNAMIC = 1;
+ const WILDCARD = 2;
+ const FIXED = 3;
+
+ public function __construct($content, $path)
+ {
+ $this->content = $content;
+ $this->path = $path;
+ }
+
+ public function setRule($rule)
+ {
+ $this->rule = $rule;
+ }
+
+ abstract public function getFormat();
+
+ abstract public function getRule();
+
+ public function addSlash($str)
+ {
+ $str = trim($str, '/');
+ if (($pos = strpos($this->path, '/')) !== false) {
+ if ($pos == 0) {
+ $str = '/'.$str;
+ } else {
+ $str .= '/';
+ }
+ }
+ return $str;
+ }
+
+ public function addSlashRegex($str)
+ {
+ $str = trim($str, '/');
+ if (($pos = strpos($this->path, '/')) !== false) {
+ if ($pos == 0) {
+ $str = '\/'.$str;
+ } else {
+ $str .= '\/';
+ }
+ }
+ if (!$this->isRequired()) {
+ $str = '('.$str.'|)';
+ }
+ return $str;
+ }
+
+ public function setDefaults($defaults)
+ {
+ $this->defaults = (string)$defaults;
+ }
+
+ public function getType()
+ {
+ return $this->type;
+ }
+
+ public function accept($visitor, $method = null)
+ {
+ $args = func_get_args();
+ $visitor->$method($this, $args);
+ }
+
+ public function setRequired($required)
+ {
+ $this->required = $required;
+ }
+
+ public function isRequired()
+ {
+ return $this->required;
+ }
+
+ abstract public function generate($value = null);
+
+ public function match($value)
+ {
+ $rule = $this->getRule();
+ return preg_match('/^'.$rule.'$/', $this->addSlash($value));
+ }
+
+}
+
+?> \ No newline at end of file
diff --git a/extlib/Net/URL/Mapper/Part/Dynamic.php b/extlib/Net/URL/Mapper/Part/Dynamic.php
new file mode 100644
index 000000000..349d87338
--- /dev/null
+++ b/extlib/Net/URL/Mapper/Part/Dynamic.php
@@ -0,0 +1,81 @@
+<?php
+/**
+ * URL parser and mapper
+ *
+ * PHP version 5
+ *
+ * LICENSE:
+ *
+ * Copyright (c) 2006, Bertrand Mansion <golgote@mamasam.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * The names of the authors may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @category Net
+ * @package Net_URL_Mapper
+ * @author Bertrand Mansion <golgote@mamasam.com>
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @version CVS: $Id: Dynamic.php,v 1.1 2007/03/28 10:23:04 mansion Exp $
+ * @link http://pear.php.net/package/Net_URL_Mapper
+ */
+
+require_once 'Net/URL/Mapper/Part.php';
+
+class Net_URL_Mapper_Part_Dynamic extends Net_URL_Mapper_Part
+{
+
+ public function __construct($content, $path)
+ {
+ $this->type = Net_URL_Mapper_Part::DYNAMIC;
+ $this->setRequired(true);
+ parent::__construct($content, $path);
+ }
+
+ public function getFormat()
+ {
+ return $this->addSlashRegex('[^\/]+');
+ }
+
+ public function getRule()
+ {
+ if (!empty($this->rule)) {
+ return '(?P<'.$this->content.'>'.$this->addSlashRegex($this->rule).')';
+ }
+ return '(?P<'.$this->content.'>'.$this->addSlashRegex('[^\/]+').')';
+ }
+
+ public function generate($value = null)
+ {
+ if (is_array($value) && isset($value[$this->content])) {
+ $val = $value[$this->content];
+ } elseif (!is_array($value) && !is_null($value)) {
+ $val = $value;
+ } else {
+ $val = $this->defaults;
+ }
+ return $this->addSlash(urlencode($val));
+ }
+}
+?> \ No newline at end of file
diff --git a/extlib/Net/URL/Mapper/Part/Fixed.php b/extlib/Net/URL/Mapper/Part/Fixed.php
new file mode 100644
index 000000000..b315b442d
--- /dev/null
+++ b/extlib/Net/URL/Mapper/Part/Fixed.php
@@ -0,0 +1,70 @@
+<?php
+/**
+ * URL parser and mapper
+ *
+ * PHP version 5
+ *
+ * LICENSE:
+ *
+ * Copyright (c) 2006, Bertrand Mansion <golgote@mamasam.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * The names of the authors may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @category Net
+ * @package Net_URL_Mapper
+ * @author Bertrand Mansion <golgote@mamasam.com>
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @version CVS: $Id: Fixed.php,v 1.1 2007/03/28 10:23:04 mansion Exp $
+ * @link http://pear.php.net/package/Net_URL_Mapper
+ */
+
+require_once 'Net/URL/Mapper/Part.php';
+
+class Net_URL_Mapper_Part_Fixed extends Net_URL_Mapper_Part
+{
+
+ public function __construct($content, $path)
+ {
+ $this->type = Net_URL_Mapper_Part::FIXED;
+ parent::__construct($content, $path);
+ }
+
+ public function getFormat()
+ {
+ return $this->getRule();
+ }
+
+ public function getRule()
+ {
+ return preg_quote($this->path, '/');
+ }
+
+ public function generate($value = null)
+ {
+ return $this->path;
+ }
+}
+?> \ No newline at end of file
diff --git a/extlib/Net/URL/Mapper/Part/Wildcard.php b/extlib/Net/URL/Mapper/Part/Wildcard.php
new file mode 100644
index 000000000..6085ff648
--- /dev/null
+++ b/extlib/Net/URL/Mapper/Part/Wildcard.php
@@ -0,0 +1,80 @@
+<?php
+/**
+ * URL parser and mapper
+ *
+ * PHP version 5
+ *
+ * LICENSE:
+ *
+ * Copyright (c) 2006, Bertrand Mansion <golgote@mamasam.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * The names of the authors may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @category Net
+ * @package Net_URL_Mapper
+ * @author Bertrand Mansion <golgote@mamasam.com>
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @version CVS: $Id: Wildcard.php,v 1.1 2007/03/28 10:23:04 mansion Exp $
+ * @link http://pear.php.net/package/Net_URL_Mapper
+ */
+
+require_once 'Net/URL/Mapper/Part.php';
+
+class Net_URL_Mapper_Part_Wildcard extends Net_URL_Mapper_Part
+{
+
+ public function __construct($content, $path)
+ {
+ $this->type = Net_URL_Mapper_Part::WILDCARD;
+ $this->setRequired(true);
+ parent::__construct($content, $path);
+ }
+
+ public function getFormat()
+ {
+ return $this->addSlashRegex('.*');;
+ }
+
+ public function getRule()
+ {
+ return '(?P<'.$this->content.'>'.$this->addSlashRegex('.*').')';
+ }
+
+ public function generate($value = null)
+ {
+ if (is_array($value) && isset($value[$this->content])) {
+ $val = $value[$this->content];
+ } elseif (!is_array($value) && !is_null($value)) {
+ $val = $value;
+ } else {
+ $val = $this->defaults;
+ }
+ return $this->addSlash(str_replace(
+ array('%2F', '%23'),
+ array('/', '#'), urlencode($val)));
+ }
+}
+?> \ No newline at end of file
diff --git a/extlib/Net/URL/Mapper/Path.php b/extlib/Net/URL/Mapper/Path.php
new file mode 100644
index 000000000..b541002c7
--- /dev/null
+++ b/extlib/Net/URL/Mapper/Path.php
@@ -0,0 +1,430 @@
+<?php
+/**
+ * URL parser and mapper
+ *
+ * PHP version 5
+ *
+ * LICENSE:
+ *
+ * Copyright (c) 2006, Bertrand Mansion <golgote@mamasam.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * The names of the authors may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @category Net
+ * @package Net_URL_Mapper
+ * @author Bertrand Mansion <golgote@mamasam.com>
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @version CVS: $Id: Path.php,v 1.1 2007/03/28 10:23:04 mansion Exp $
+ * @link http://pear.php.net/package/Net_URL_Mapper
+ */
+
+require_once 'Net/URL.php';
+require_once 'Net/URL/Mapper/Part/Dynamic.php';
+require_once 'Net/URL/Mapper/Part/Wildcard.php';
+require_once 'Net/URL/Mapper/Part/Fixed.php';
+
+class Net_URL_Mapper_Path
+{
+ private $path = '';
+ private $N = 0;
+ public $token;
+ public $value;
+ private $line = 1;
+ private $state = 1;
+
+
+ protected $alias;
+ protected $rules = array();
+ protected $defaults = array();
+ protected $parts = array();
+ protected $rule;
+ protected $format;
+ protected $minKeys;
+ protected $maxKeys;
+ protected $fixed = true;
+ protected $required;
+
+ public function __construct($path = '', $defaults = array(), $rules = array())
+ {
+ $this->path = '/'.trim(Net_URL::resolvePath($path), '/');
+ $this->setDefaults($defaults);
+ $this->setRules($rules);
+
+ try {
+ $this->parsePath();
+ } catch (Exception $e) {
+ // The path could not be parsed correctly, treat it as fixed
+ $this->fixed = true;
+ $part = self::createPart(Net_URL_Mapper_Part::FIXED, $this->path, $this->path);
+ $this->parts = array($part);
+ }
+ $this->getRequired();
+ }
+
+ public function getPath()
+ {
+ return $this->path;
+ }
+
+ protected function parsePath()
+ {
+ while ($this->yylex()) { }
+ }
+
+ /**
+ * Get the path alias
+ * Path aliases can be used instead of full path
+ * @return null|string
+ */
+ public function getAlias()
+ {
+ return $this->alias;
+ }
+
+ /**
+ * Set the path name
+ * @param string Set the path name
+ * @see getAlias()
+ */
+ public function setAlias($alias)
+ {
+ $this->alias = $alias;
+ return $this;
+ }
+
+ /**
+ * Get the path parts default values
+ * @return null|array
+ */
+ public function getDefaults()
+ {
+ return $this->defaults;
+ }
+
+ /**
+ * Set the path parts default values
+ * @param array Associative array with format partname => value
+ */
+ public function setDefaults($defaults)
+ {
+ if (is_array($defaults)) {
+ $this->defaults = $defaults;
+ } else {
+ $this->defaults = array();
+ }
+ }
+
+ /**
+ * Set the path parts default values
+ * @param array Associative array with format partname => value
+ */
+ public function setRules($rules)
+ {
+ if (is_array($rules)) {
+ $this->rules = $rules;
+ } else {
+ $this->rules = array();
+ }
+ }
+
+ /**
+ * Returns the regular expression used to match this path
+ * @return string PERL Regular expression
+ */
+ public function getRule()
+ {
+ if (is_null($this->rule)) {
+ $this->rule = '/^';
+ foreach ($this->parts as $path => $part) {
+ $this->rule .= $part->getRule();
+ }
+ $this->rule .= '$/';
+ }
+ return $this->rule;
+ }
+
+ public function getFormat()
+ {
+ if (is_null($this->format)) {
+ $this->format = '/^';
+ foreach ($this->parts as $path => $part) {
+ $this->format .= $part->getFormat();
+ }
+ $this->format .= '$/';
+ }
+ return $this->format;
+ }
+
+ protected function addPart($part)
+ {
+ if (array_key_exists($part->content, $this->defaults)) {
+ $part->setRequired(false);
+ $part->setDefaults($this->defaults[$part->content]);
+ }
+ if (isset($this->rules[$part->content])) {
+ $part->setRule($this->rules[$part->content]);
+ }
+ $this->rule = null;
+ if ($part->getType() != Net_URL_Mapper_Part::FIXED) {
+ $this->fixed = false;
+ $this->parts[$part->content] = $part;
+ } else {
+ $this->parts[] = $part;
+ }
+ return $part;
+ }
+
+ public static function createPart($type, $content, $path)
+ {
+ switch ($type) {
+ case Net_URL_Mapper_Part::DYNAMIC:
+ return new Net_URL_Mapper_Part_Dynamic($content, $path);
+ break;
+ case Net_URL_Mapper_Part::WILDCARD:
+ return new Net_URL_Mapper_Part_Wildcard($content, $path);
+ break;
+ default:
+ return new Net_URL_Mapper_Part_Fixed($content, $path);
+ }
+ }
+
+ /**
+ * Checks whether the path contains the given part by name
+ * If value parameter is given, the part also checks if the
+ * given value conforms to the part rule.
+ * @param string Part name
+ * @param mixed The value to check against
+ */
+ public function hasKey($partName, $value = null)
+ {
+ if (array_key_exists($partName, $this->parts)) {
+ if (!is_null($value) && $value !== false) {
+ return $this->parts[$partName]->match($value);
+ } else {
+ return true;
+ }
+ } elseif (array_key_exists($partName, $this->defaults) &&
+ $value == $this->defaults[$partName]) {
+ return true;
+ }
+ return false;
+ }
+
+ public function generate($values = array(), $qstring = array(), $anchor = '')
+ {
+ $path = '';
+ foreach ($this->parts as $part) {
+ $path .= $part->generate($values);
+ }
+ $path = '/'.trim(Net_URL::resolvePath($path), '/');
+ if (!empty($qstring)) {
+ $path .= '?'.http_build_query($qstring);
+ }
+ if (!empty($anchor)) {
+ $path .= '#'.ltrim($anchor, '#');
+ }
+ return $path;
+ }
+
+ public function getRequired()
+ {
+ if (!isset($this->required)) {
+ $req = array();
+ foreach ($this->parts as $part) {
+ if ($part->isRequired()) {
+ $req[] = $part->content;
+ }
+ }
+ $this->required = $req;
+ }
+ return $this->required;
+ }
+
+ public function getMaxKeys()
+ {
+ if (is_null($this->maxKeys)) {
+ $this->maxKeys = count($this->required);
+ $this->maxKeys += count($this->defaults);
+ }
+ return $this->maxKeys;
+ }
+
+
+
+
+ private $_yy_state = 1;
+ private $_yy_stack = array();
+
+ function yylex()
+ {
+ return $this->{'yylex' . $this->_yy_state}();
+ }
+
+ function yypushstate($state)
+ {
+ array_push($this->_yy_stack, $this->_yy_state);
+ $this->_yy_state = $state;
+ }
+
+ function yypopstate()
+ {
+ $this->_yy_state = array_pop($this->_yy_stack);
+ }
+
+ function yybegin($state)
+ {
+ $this->_yy_state = $state;
+ }
+
+
+
+ function yylex1()
+ {
+ $tokenMap = array (
+ 1 => 1,
+ 3 => 1,
+ 5 => 1,
+ 7 => 1,
+ 9 => 1,
+ );
+ if ($this->N >= strlen($this->path)) {
+ return false; // end of input
+ }
+ $yy_global_pattern = "/^(\/?:\/?\\(([a-zA-Z0-9_]+)\\))|^(\/?\\*\/?\\(([a-zA-Z0-9_]+)\\))|^(\/?:([a-zA-Z0-9_]+))|^(\/?\\*([a-zA-Z0-9_]+))|^(\/?([^\/:*]+))/";
+
+ do {
+ if (preg_match($yy_global_pattern, substr($this->path, $this->N), $yymatches)) {
+ $yysubmatches = $yymatches;
+ $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
+ if (!count($yymatches)) {
+ throw new Exception('Error: lexing failed because a rule matched' .
+ 'an empty string. Input "' . substr($this->path,
+ $this->N, 5) . '... state START');
+ }
+ next($yymatches); // skip global match
+ $this->token = key($yymatches); // token number
+ if ($tokenMap[$this->token]) {
+ // extract sub-patterns for passing to lex function
+ $yysubmatches = array_slice($yysubmatches, $this->token + 1,
+ $tokenMap[$this->token]);
+ } else {
+ $yysubmatches = array();
+ }
+ $this->value = current($yymatches); // token value
+ $r = $this->{'yy_r1_' . $this->token}($yysubmatches);
+ if ($r === null) {
+ $this->N += strlen($this->value);
+ $this->line += substr_count("\n", $this->value);
+ // accept this token
+ return true;
+ } elseif ($r === true) {
+ // we have changed state
+ // process this token in the new state
+ return $this->yylex();
+ } elseif ($r === false) {
+ $this->N += strlen($this->value);
+ $this->line += substr_count("\n", $this->value);
+ if ($this->N >= strlen($this->path)) {
+ return false; // end of input
+ }
+ // skip this token
+ continue;
+ } else { $yy_yymore_patterns = array(
+ 1 => "^(\/?\\*\/?\\(([a-zA-Z0-9_]+)\\))|^(\/?:([a-zA-Z0-9_]+))|^(\/?\\*([a-zA-Z0-9_]+))|^(\/?([^\/:*]+))",
+ 3 => "^(\/?:([a-zA-Z0-9_]+))|^(\/?\\*([a-zA-Z0-9_]+))|^(\/?([^\/:*]+))",
+ 5 => "^(\/?\\*([a-zA-Z0-9_]+))|^(\/?([^\/:*]+))",
+ 7 => "^(\/?([^\/:*]+))",
+ 9 => "",
+ );
+
+ // yymore is needed
+ do {
+ if (!strlen($yy_yymore_patterns[$this->token])) {
+ throw new Exception('cannot do yymore for the last token');
+ }
+ if (preg_match($yy_yymore_patterns[$this->token],
+ substr($this->path, $this->N), $yymatches)) {
+ $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
+ next($yymatches); // skip global match
+ $this->token = key($yymatches); // token number
+ $this->value = current($yymatches); // token value
+ $this->line = substr_count("\n", $this->value);
+ }
+ } while ($this->{'yy_r1_' . $this->token}() !== null);
+ // accept
+ $this->N += strlen($this->value);
+ $this->line += substr_count("\n", $this->value);
+ return true;
+ }
+ } else {
+ throw new Exception('Unexpected input at line' . $this->line .
+ ': ' . $this->path[$this->N]);
+ }
+ break;
+ } while (true);
+ } // end function
+
+
+ const START = 1;
+ function yy_r1_1($yy_subpatterns)
+ {
+
+ $c = $yy_subpatterns[0];
+ $part = self::createPart(Net_URL_Mapper_Part::DYNAMIC, $c, $this->value);
+ $this->addPart($part);
+ }
+ function yy_r1_3($yy_subpatterns)
+ {
+
+ $c = $yy_subpatterns[0];
+ $part = self::createPart(Net_URL_Mapper_Part::WILDCARD, $c, $this->value);
+ $this->addPart($part);
+ }
+ function yy_r1_5($yy_subpatterns)
+ {
+
+ $c = $yy_subpatterns[0];
+ $part = self::createPart(Net_URL_Mapper_Part::DYNAMIC, $c, $this->value);
+ $this->addPart($part);
+ }
+ function yy_r1_7($yy_subpatterns)
+ {
+
+ $c = $yy_subpatterns[0];
+ $part = self::createPart(Net_URL_Mapper_Part::WILDCARD, $c, $this->value);
+ $this->addPart($part);
+ }
+ function yy_r1_9($yy_subpatterns)
+ {
+
+ $c = $yy_subpatterns[0];
+ $part = self::createPart(Net_URL_Mapper_Part::FIXED, $c, $this->value);
+ $this->addPart($part);
+ }
+
+}
+
+?> \ No newline at end of file
diff --git a/htaccess.sample b/htaccess.sample
index 5f9827f96..634900dbf 100644
--- a/htaccess.sample
+++ b/htaccess.sample
@@ -4,165 +4,9 @@ RewriteEngine On
RewriteBase /mublog/
-RewriteRule ^$ index.php?action=public [L,QSA]
-RewriteRule ^rss$ index.php?action=publicrss [L,QSA]
-RewriteRule ^xrds$ index.php?action=publicxrds [L,QSA]
-RewriteRule ^featuredrss$ index.php?action=featuredrss [L,QSA]
-RewriteRule ^favoritedrss$ index.php?action=favoritedrss [L,QSA]
-RewriteRule ^opensearch/people$ index.php?action=opensearch&type=people [L,QSA]
-RewriteRule ^opensearch/notice$ index.php?action=opensearch&type=notice [L,QSA]
-
-RewriteRule ^doc/about$ index.php?action=doc&title=about [L,QSA]
-RewriteRule ^doc/contact$ index.php?action=doc&title=contact [L,QSA]
-RewriteRule ^doc/faq$ index.php?action=doc&title=faq [L,QSA]
-RewriteRule ^doc/help$ index.php?action=doc&title=help [L,QSA]
-RewriteRule ^doc/im$ index.php?action=doc&title=im [L,QSA]
-RewriteRule ^doc/openid$ index.php?action=doc&title=openid [L,QSA]
-RewriteRule ^doc/openmublog$ index.php?action=doc&title=openmublog [L,QSA]
-RewriteRule ^doc/privacy$ index.php?action=doc&title=privacy [L,QSA]
-RewriteRule ^doc/source$ index.php?action=doc&title=source [L,QSA]
-RewriteRule ^doc/tags$ index.php?action=doc&title=tags [L,QSA]
-RewriteRule ^doc/groups$ index.php?action=doc&title=groups [L,QSA]
-RewriteRule ^doc/sms$ index.php?action=doc&title=sms [L,QSA]
-
-RewriteRule ^facebook/$ index.php?action=facebookhome [L,QSA]
-RewriteRule ^facebook/index.php$ index.php?action=facebookhome [L,QSA]
-RewriteRule ^facebook/settings.php$ index.php?action=facebooksettings [L,QSA]
-RewriteRule ^facebook/invite.php$ index.php?action=facebookinvite [L,QSA]
-RewriteRule ^facebook/remove$ index.php?action=facebookremove [L,QSA]
-
-RewriteRule ^main/login$ index.php?action=login [L,QSA]
-RewriteRule ^main/logout$ index.php?action=logout [L,QSA]
-RewriteRule ^main/register/(.*)$ index.php?action=register&code=$1 [L,QSA]
-RewriteRule ^main/register$ index.php?action=register [L,QSA]
-RewriteRule ^main/openid$ index.php?action=openidlogin [L,QSA]
-RewriteRule ^main/remote$ index.php?action=remotesubscribe [L,QSA]
-
-RewriteRule ^main/subscribe$ index.php?action=subscribe [L,QSA]
-RewriteRule ^main/unsubscribe$ index.php?action=unsubscribe [L,QSA]
-RewriteRule ^main/confirmaddress$ index.php?action=confirmaddress [L,QSA]
-RewriteRule ^main/confirmaddress/(.*)$ index.php?action=confirmaddress&code=$1 [L,QSA]
-RewriteRule ^main/recoverpassword$ index.php?action=recoverpassword [L,QSA]
-RewriteRule ^main/recoverpassword/(.*)$ index.php?action=recoverpassword&code=$1 [L,QSA]
-RewriteRule ^main/invite$ index.php?action=invite [L,QSA]
-
-RewriteRule ^main/favor$ index.php?action=favor [L,QSA]
-RewriteRule ^main/disfavor$ index.php?action=disfavor [L,QSA]
-
-RewriteRule ^main/sup$ index.php?action=sup [L,QSA]
-
-RewriteRule ^main/tagother$ index.php?action=tagother [L,QSA]
-
-RewriteRule ^main/block$ index.php?action=block [L,QSA]
-
-RewriteRule ^settings/profile$ index.php?action=profilesettings [L,QSA]
-RewriteRule ^settings/avatar$ index.php?action=avatarsettings [L,QSA]
-RewriteRule ^settings/password$ index.php?action=passwordsettings [L,QSA]
-RewriteRule ^settings/openid$ index.php?action=openidsettings [L,QSA]
-RewriteRule ^settings/im$ index.php?action=imsettings [L,QSA]
-RewriteRule ^settings/email$ index.php?action=emailsettings [L,QSA]
-RewriteRule ^settings/sms$ index.php?action=smssettings [L,QSA]
-RewriteRule ^settings/twitter$ index.php?action=twittersettings [L,QSA]
-RewriteRule ^settings/other$ index.php?action=othersettings [L,QSA]
-
-RewriteRule ^search/group$ index.php?action=groupsearch [L,QSA]
-RewriteRule ^search/people$ index.php?action=peoplesearch [L,QSA]
-RewriteRule ^search/notice$ index.php?action=noticesearch [L,QSA]
-RewriteRule ^search/notice/rss$ index.php?action=noticesearchrss [L,QSA]
-
-RewriteRule ^notice/new$ index.php?action=newnotice [L,QSA]
-RewriteRule ^notice/(\d+)$ index.php?action=shownotice&notice=$1 [L,QSA]
-RewriteRule ^notice/delete/((\d+))?$ index.php?action=deletenotice&notice=$2 [L,QSA]
-RewriteRule ^notice/delete$ index.php?action=deletenotice [L,QSA]
-
-RewriteRule ^message/new$ index.php?action=newmessage [L,QSA]
-RewriteRule ^message/(\d+)$ index.php?action=showmessage&message=$1 [L,QSA]
-
-RewriteRule ^user/(\d+)$ index.php?action=userbyid&id=$1 [L,QSA]
-
-RewriteRule ^tags/?$ index.php?action=publictagcloud [L,QSA]
-RewriteRule ^tag/([a-zA-Z0-9]+)/rss$ index.php?action=tagrss&tag=$1 [L,QSA]
-RewriteRule ^tag(/(.*))?$ index.php?action=tag&tag=$2 [L,QSA]
-
-RewriteRule ^peopletag/([a-zA-Z0-9]+)$ index.php?action=peopletag&tag=$1 [L,QSA]
-
-RewriteRule ^featured/?$ index.php?action=featured [L,QSA]
-RewriteRule ^favorited/?$ index.php?action=favorited [L,QSA]
-
-RewriteRule ^group/new$ index.php?action=newgroup [L,QSA]
-RewriteRule ^group/([a-zA-Z0-9]+)/edit$ index.php?action=editgroup&nickname=$1 [L,QSA]
-RewriteRule ^group/([a-zA-Z0-9]+)/join$ index.php?action=joingroup&nickname=$1 [L,QSA]
-RewriteRule ^group/([a-zA-Z0-9]+)/leave$ index.php?action=leavegroup&nickname=$1 [L,QSA]
-RewriteRule ^group/([a-zA-Z0-9]+)/members$ index.php?action=groupmembers&nickname=$1 [L,QSA]
-RewriteRule ^group/([a-zA-Z0-9]+)/logo$ index.php?action=grouplogo&nickname=$1 [L,QSA]
-RewriteRule ^group/([0-9]+)/id$ index.php?action=groupbyid&id=$1 [L,QSA]
-RewriteRule ^group/([a-zA-Z0-9]+)/rss$ index.php?action=grouprss&nickname=$1 [L,QSA]
-RewriteRule ^group/([a-zA-Z0-9]+)$ index.php?action=showgroup&nickname=$1 [L,QSA]
-RewriteRule ^group$ index.php?action=groups [L,QSA]
-
-# Twitter-compatible API rewrites
-# XXX: Surely these can be refactored a little -- Zach
-RewriteRule ^api/statuses/public_timeline(.*)$ index.php?action=api&apiaction=statuses&method=public_timeline$1 [L,QSA]
-RewriteRule ^api/statuses/friends_timeline(.*)$ index.php?action=api&apiaction=statuses&method=friends_timeline$1 [L,QSA]
-RewriteRule ^api/statuses/user_timeline/(.*)$ index.php?action=api&apiaction=statuses&method=user_timeline&argument=$1 [L,QSA]
-RewriteRule ^api/statuses/user_timeline(.*)$ index.php?action=api&apiaction=statuses&method=user_timeline$1 [L,QSA]
-RewriteRule ^api/statuses/show/(.*)$ index.php?action=api&apiaction=statuses&method=show&argument=$1 [L,QSA]
-RewriteRule ^api/statuses/update(.*)$ index.php?action=api&apiaction=statuses&method=update$1 [L,QSA]
-RewriteRule ^api/statuses/replies(.*)$ index.php?action=api&apiaction=statuses&method=replies&argument=$1 [L,QSA]
-RewriteRule ^api/statuses/destroy/(.*)$ index.php?action=api&apiaction=statuses&method=destroy&argument=$1 [L,QSA]
-RewriteRule ^api/statuses/friends/(.*)$ index.php?action=api&apiaction=statuses&method=friends&argument=$1 [L,QSA]
-RewriteRule ^api/statuses/friends(.*)$ index.php?action=api&apiaction=statuses&method=friends$1 [L,QSA]
-RewriteRule ^api/statuses/followers/(.*)$ index.php?action=api&apiaction=statuses&method=followers&argument=$1 [L,QSA]
-RewriteRule ^api/statuses/followers(.*)$ index.php?action=api&apiaction=statuses&method=followers$1 [L,QSA]
-RewriteRule ^api/statuses/featured(.*)$ index.php?action=api&apiaction=statuses&method=featured$1 [L,QSA]
-RewriteRule ^api/users/show/(.*)$ index.php?action=api&apiaction=users&method=show&argument=$1 [L,QSA]
-RewriteRule ^api/users/show(.*)$ index.php?action=api&apiaction=users&method=show$1 [L,QSA]
-RewriteRule ^api/direct_messages/sent(.*)$ index.php?action=api&apiaction=direct_messages&method=sent$1 [L,QSA]
-RewriteRule ^api/direct_messages/destroy/(.*)$ index.php?action=api&apiaction=direct_messages&method=destroy&argument=$1 [L,QSA]
-RewriteRule ^api/direct_messages/new(.*)$ index.php?action=api&apiaction=direct_messages&method=create$1 [L,QSA]
-RewriteRule ^api/direct_messages(.*)$ index.php?action=api&apiaction=direct_messages&method=direct_messages$1 [L,QSA]
-RewriteRule ^api/friendships/create/(.*)$ index.php?action=api&apiaction=friendships&method=create&argument=$1 [L,QSA]
-RewriteRule ^api/friendships/destroy/(.*)$ index.php?action=api&apiaction=friendships&method=destroy&argument=$1 [L,QSA]
-RewriteRule ^api/friendships/exists(.*)$ index.php?action=api&apiaction=friendships&method=exists$1 [L,QSA]
-RewriteRule ^api/account/verify_credentials(.*)$ index.php?action=api&apiaction=account&method=verify_credentials$1 [L,QSA]
-RewriteRule ^api/account/end_session$ index.php?action=api&apiaction=account&method=end_session$1 [L,QSA]
-RewriteRule ^api/account/update_location(.*)$ index.php?action=api&apiaction=account&method=update_location$1 [L,QSA]
-RewriteRule ^api/account/update_delivery_device(.*)$ index.php?action=api&apiaction=account&method=update_delivery_device$1 [L,QSA]
-RewriteRule ^api/account/rate_limit_status(.*)$ index.php?action=api&apiaction=account&method=rate_limit_status$1 [L,QSA]
-RewriteRule ^api/favorites/create/(.*)$ index.php?action=api&apiaction=favorites&method=create&argument=$1 [L,QSA]
-RewriteRule ^api/favorites/destroy/(.*)$ index.php?action=api&apiaction=favorites&method=destroy&argument=$1 [L,QSA]
-RewriteRule ^api/favorites/(.*)$ index.php?action=api&apiaction=favorites&method=favorites&argument=$1 [L,QSA]
-RewriteRule ^api/favorites(.*)$ index.php?action=api&apiaction=favorites&method=favorites$1 [L,QSA]
-RewriteRule ^api/notifications/follow/(.*)$ index.php?action=api&apiaction=notifications&method=follow&argument=$1 [L,QSA]
-RewriteRule ^api/notifications/leave/(.*)$ index.php?action=api&apiaction=notifications&method=leave&argument=$1 [L,QSA]
-RewriteRule ^api/blocks/create/(.*)$ index.php?action=api&apiaction=blocks&method=create&argument=$1 [L,QSA]
-RewriteRule ^api/blocks/destroy/(.*)$ index.php?action=api&apiaction=blocks&method=destroy&argument=$1 [L,QSA]
-RewriteRule ^api/help/(.*)$ index.php?action=api&apiaction=help&method=$1 [L,QSA]
-RewriteRule ^api/laconica/version(.*)$ index.php?action=api&apiaction=laconica&method=version$1 [L,QSA]
-RewriteRule ^api/laconica/config(.*)$ index.php?action=api&apiaction=laconica&method=config$1 [L,QSA]
-RewriteRule ^api/laconica/wadl\.xml$ index.php?action=api&apiaction=laconica&method=wadl.xml [L,QSA]
-
-RewriteRule ^(\w+)/subscriptions$ index.php?action=subscriptions&nickname=$1 [L,QSA]
-RewriteRule ^(\w+)/subscriptions/([a-zA-Z0-9]+)$ index.php?action=subscriptions&nickname=$1&tag=$2 [L,QSA]
-RewriteRule ^(\w+)/subscribers/([a-zA-Z0-9]+)$ index.php?action=subscribers&nickname=$1&tag=$2 [L,QSA]
-RewriteRule ^(\w+)/subscribers$ index.php?action=subscribers&nickname=$1 [L,QSA]
-RewriteRule ^(\w+)/nudge$ index.php?action=nudge&nickname=$1 [L,QSA]
-RewriteRule ^(\w+)/xrds$ index.php?action=xrds&nickname=$1 [L,QSA]
-RewriteRule ^(\w+)/rss$ index.php?action=userrss&nickname=$1 [L,QSA]
-RewriteRule ^(\w+)/all$ index.php?action=all&nickname=$1 [L,QSA]
-RewriteRule ^(\w+)/all/rss$ index.php?action=allrss&nickname=$1 [L,QSA]
-RewriteRule ^(\w+)/foaf$ index.php?action=foaf&nickname=$1 [L,QSA]
-RewriteRule ^(\w+)/replies$ index.php?action=replies&nickname=$1 [L,QSA]
-RewriteRule ^(\w+)/replies/rss$ index.php?action=repliesrss&nickname=$1 [L,QSA]
-RewriteRule ^(\w+)/avatar/(original|96|48|24)$ index.php?action=avatarbynickname&nickname=$1&size=$2 [L,QSA]
-RewriteRule ^(\w+)/favorites$ index.php?action=showfavorites&nickname=$1 [L,QSA]
-RewriteRule ^(\w+)/favorites/rss$ index.php?action=favoritesrss&nickname=$1 [L,QSA]
-RewriteRule ^(\w+)/inbox$ index.php?action=inbox&nickname=$1 [L,QSA]
-RewriteRule ^(\w+)/outbox$ index.php?action=outbox&nickname=$1 [L,QSA]
-RewriteRule ^(\w+)/microsummary$ index.php?action=microsummary&nickname=$1 [L,QSA]
-RewriteRule ^(\w+)/groups$ index.php?action=usergroups&nickname=$1 [L,QSA]
-
-RewriteRule ^(\w+)$ index.php?action=showstream&nickname=$1 [L,QSA]
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteCond %{REQUEST_FILENAME} !-d
+RewriteRule (.*) index.php?p=$1 [L,QSA]
<FilesMatch "\.(ini)">
Order allow,deny
diff --git a/index.php b/index.php
index 387b642e2..b180e2b65 100644
--- a/index.php
+++ b/index.php
@@ -22,53 +22,131 @@ define('LACONICA', true);
require_once INSTALLDIR . '/lib/common.php';
-// get and cache current user
+$user = null;
+$action = null;
+
+function getPath($req)
+{
+ if (common_config('site', 'fancy')) {
+ return $req['p'];
+ } else if ($_SERVER['PATH_INFO']) {
+ return $_SERVER['PATH_INFO'];
+ } else {
+ return $req['p'];
+ }
+}
-$user = common_current_user();
+function handleError($error)
+{
+ if ($error->getCode() == DB_DATAOBJECT_ERROR_NODATA) {
+ return;
+ }
-// initialize language env
+ common_log(LOG_ERR, "PEAR error: " . $error->getMessage());
+ $msg = sprintf(_('The database for %s isn\'t responding correctly, '.
+ 'so the site won\'t work properly. '.
+ 'The site admins probably know about the problem, '.
+ 'but you can contact them at %s to make sure. '.
+ 'Otherwise, wait a few minutes and try again.'),
+ common_config('site', 'name'),
+ common_config('site', 'email'));
+
+ $dac = new DBErrorAction($msg, 500);
+ $dac->showPage();
+ exit(-1);
+}
-common_init_language();
+function main()
+{
+ global $user, $action;
-$action = $_REQUEST['action'];
+ // For database errors
-if (!$action || !preg_match('/^[a-zA-Z0-9_-]*$/', $action)) {
- common_redirect(common_local_url('public'));
-}
+ PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handleError');
-// If the site is private, and they're not on one of the "public"
-// parts of the site, redirect to login
+ // XXX: we need a little more structure in this script
-if (!$user && common_config('site', 'private') &&
- !in_array($action, array('login', 'openidlogin', 'finishopenidlogin',
- 'recoverpassword', 'api', 'doc', 'register'))) {
- common_redirect(common_local_url('login'));
-}
+ // get and cache current user
+
+ $user = common_current_user();
+
+ // initialize language env
+
+ common_init_language();
+
+ $path = getPath($_REQUEST);
+
+ $r = Router::get();
+
+ $args = $r->map($path);
+
+ if (!$args) {
+ $cac = new ClientErrorAction(_('Unknown page'), 404);
+ $cac->showPage();
+ return;
+ }
+
+ $args = array_merge($args, $_REQUEST);
-$actionfile = INSTALLDIR."/actions/$action.php";
+ $action = $args['action'];
-if (file_exists($actionfile)) {
+ if (!$action || !preg_match('/^[a-zA-Z0-9_-]*$/', $action)) {
+ common_redirect(common_local_url('public'));
+ return;
+ }
- include_once $actionfile;
+ // If the site is private, and they're not on one of the "public"
+ // parts of the site, redirect to login
+
+ if (!$user && common_config('site', 'private') &&
+ !in_array($action, array('login', 'openidlogin', 'finishopenidlogin',
+ 'recoverpassword', 'api', 'doc', 'register'))) {
+ common_redirect(common_local_url('login'));
+ return;
+ }
$action_class = ucfirst($action).'Action';
- $action_obj = new $action_class();
+ if (!class_exists($action_class)) {
+ $cac = new ClientErrorAction(_('Unknown action'), 404);
+ $cac->showPage();
+ } else {
+ $action_obj = new $action_class();
+
+ // XXX: find somewhere for this little block to live
- if ($config['db']['mirror'] && $action_obj->isReadOnly()) {
- if (is_array($config['db']['mirror'])) {
- // "load balancing", ha ha
- $k = array_rand($config['db']['mirror']);
+ if ($config['db']['mirror'] && $action_obj->isReadOnly()) {
+ if (is_array($config['db']['mirror'])) {
+ // "load balancing", ha ha
+ $k = array_rand($config['db']['mirror']);
- $mirror = $config['db']['mirror'][$k];
- } else {
- $mirror = $config['db']['mirror'];
+ $mirror = $config['db']['mirror'][$k];
+ } else {
+ $mirror = $config['db']['mirror'];
+ }
+ $config['db']['database'] = $mirror;
+ }
+
+ try {
+ if ($action_obj->prepare($args)) {
+ $action_obj->handle($args);
+ }
+ } catch (ClientException $cex) {
+ $cac = new ClientErrorAction($cex->getMessage(), $cex->getCode());
+ $cac->showPage();
+ } catch (ServerException $sex) { // snort snort guffaw
+ $sac = new ServerErrorAction($sex->getMessage(), $sex->getCode());
+ $sac->showPage();
+ } catch (Exception $ex) {
+ $sac = new ServerErrorAction($ex->getMessage());
+ $sac->showPage();
}
- $config['db']['database'] = $mirror;
- }
- if (call_user_func(array($action_obj, 'prepare'), $_REQUEST)) {
- call_user_func(array($action_obj, 'handle'), $_REQUEST);
}
-} else {
- common_user_error(_('Unknown action'));
-} \ No newline at end of file
+}
+
+main();
+
+// XXX: cleanup exit() calls or add an exit handler so
+// this always gets called
+
+Event::handle('CleanupPlugin');
diff --git a/lib/action.php b/lib/action.php
index c4172ada1..cd0db5399 100644
--- a/lib/action.php
+++ b/lib/action.php
@@ -151,25 +151,34 @@ class Action extends HTMLOutputter // lawsuit
*/
function showStylesheets()
{
- $this->element('link', array('rel' => 'stylesheet',
- 'type' => 'text/css',
- 'href' => theme_path('css/display.css', 'base') . '?version=' . LACONICA_VERSION,
- 'media' => 'screen, projection, tv'));
- $this->element('link', array('rel' => 'stylesheet',
- 'type' => 'text/css',
- 'href' => theme_path('css/display.css', null) . '?version=' . LACONICA_VERSION,
- 'media' => 'screen, projection, tv'));
- $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
- 'href="'.theme_path('css/ie.css', 'base').'?version='.LACONICA_VERSION.'" /><![endif]');
- foreach (array(6,7) as $ver) {
- if (file_exists(theme_file('css/ie'.$ver.'.css', 'base'))) {
- // Yes, IE people should be put in jail.
- $this->comment('[if lte IE '.$ver.']><link rel="stylesheet" type="text/css" '.
- 'href="'.theme_path('css/ie'.$ver.'.css', 'base').'?version='.LACONICA_VERSION.'" /><![endif]');
+ if (Event::handle('StartShowStyles', array($this))) {
+ if (Event::handle('StartShowLaconicaStyles', array($this))) {
+ $this->element('link', array('rel' => 'stylesheet',
+ 'type' => 'text/css',
+ 'href' => theme_path('css/display.css', 'base') . '?version=' . LACONICA_VERSION,
+ 'media' => 'screen, projection, tv'));
+ $this->element('link', array('rel' => 'stylesheet',
+ 'type' => 'text/css',
+ 'href' => theme_path('css/display.css', null) . '?version=' . LACONICA_VERSION,
+ 'media' => 'screen, projection, tv'));
+ Event::handle('EndShowLaconicaStyles', array($this));
}
+ if (Event::handle('StartShowUAStyles', array($this))) {
+ $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
+ 'href="'.theme_path('css/ie.css', 'base').'?version='.LACONICA_VERSION.'" /><![endif]');
+ foreach (array(6,7) as $ver) {
+ if (file_exists(theme_file('css/ie'.$ver.'.css', 'base'))) {
+ // Yes, IE people should be put in jail.
+ $this->comment('[if lte IE '.$ver.']><link rel="stylesheet" type="text/css" '.
+ 'href="'.theme_path('css/ie'.$ver.'.css', 'base').'?version='.LACONICA_VERSION.'" /><![endif]');
+ }
+ }
+ $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
+ 'href="'.theme_path('css/ie.css', null).'?version='.LACONICA_VERSION.'" /><![endif]');
+ Event::handle('EndShowUAStyles', array($this));
+ }
+ Event::handle('EndShowStyles', array($this));
}
- $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
- 'href="'.theme_path('css/ie.css', null).'?version='.LACONICA_VERSION.'" /><![endif]');
}
/**
@@ -179,18 +188,27 @@ class Action extends HTMLOutputter // lawsuit
*/
function showScripts()
{
- $this->element('script', array('type' => 'text/javascript',
- 'src' => common_path('js/jquery.min.js')),
- ' ');
- $this->element('script', array('type' => 'text/javascript',
- 'src' => common_path('js/jquery.form.js')),
- ' ');
- $this->element('script', array('type' => 'text/javascript',
- 'src' => common_path('js/xbImportNode.js')),
- ' ');
- $this->element('script', array('type' => 'text/javascript',
- 'src' => common_path('js/util.js?version='.LACONICA_VERSION)),
- ' ');
+ if (Event::handle('StartShowScripts', array($this))) {
+ if (Event::handle('StartShowJQueryScripts', array($this))) {
+ $this->element('script', array('type' => 'text/javascript',
+ 'src' => common_path('js/jquery.min.js')),
+ ' ');
+ $this->element('script', array('type' => 'text/javascript',
+ 'src' => common_path('js/jquery.form.js')),
+ ' ');
+ Event::handle('EndShowJQueryScripts', array($this));
+ }
+ if (Event::handle('StartShowLaconicaScripts', array($this))) {
+ $this->element('script', array('type' => 'text/javascript',
+ 'src' => common_path('js/xbImportNode.js')),
+ ' ');
+ $this->element('script', array('type' => 'text/javascript',
+ 'src' => common_path('js/util.js?version='.LACONICA_VERSION)),
+ ' ');
+ Event::handle('EndShowLaconicaScripts', array($this));
+ }
+ Event::handle('EndShowScripts', array($this));
+ }
}
/**
@@ -216,9 +234,19 @@ class Action extends HTMLOutputter // lawsuit
*
* @return nothing
*/
+
function showFeeds()
{
- // does nothing by default
+ $feeds = $this->getFeeds();
+
+ if ($feeds) {
+ foreach ($feeds as $feed) {
+ $this->element('link', array('rel' => $feed->rel(),
+ 'href' => $feed->url,
+ 'type' => $feed->mimeType(),
+ 'title' => $feed->title));
+ }
+ }
}
/**
@@ -256,9 +284,15 @@ class Action extends HTMLOutputter // lawsuit
{
$this->elementStart('body', array('id' => $this->trimmed('action')));
$this->elementStart('div', array('id' => 'wrap'));
- $this->showHeader();
+ if (Event::handle('StartShowHeader', array($this))) {
+ $this->showHeader();
+ Event::handle('EndShowHeader', array($this));
+ }
$this->showCore();
- $this->showFooter();
+ if (Event::handle('StartShowFooter', array($this))) {
+ $this->showFooter();
+ Event::handle('EndShowFooter', array($this));
+ }
$this->elementEnd('div');
$this->elementEnd('body');
}
@@ -312,42 +346,46 @@ class Action extends HTMLOutputter // lawsuit
*/
function showPrimaryNav()
{
+ $user = common_current_user();
+
$this->elementStart('dl', array('id' => 'site_nav_global_primary'));
$this->element('dt', null, _('Primary site navigation'));
$this->elementStart('dd');
- $user = common_current_user();
$this->elementStart('ul', array('class' => 'nav'));
- if ($user) {
- $this->menuItem(common_local_url('all', array('nickname' => $user->nickname)),
- _('Home'), _('Personal profile and friends timeline'), false, 'nav_home');
- }
- $this->menuItem(common_local_url('peoplesearch'),
- _('Search'), _('Search for people or text'), false, 'nav_search');
- if ($user) {
- $this->menuItem(common_local_url('profilesettings'),
- _('Account'), _('Change your email, avatar, password, profile'), false, 'nav_account');
-
- if (common_config('xmpp', 'enabled')) {
- $this->menuItem(common_local_url('imsettings'),
- _('Connect'), _('Connect to IM, SMS, Twitter'), false, 'nav_connect');
- } else {
- $this->menuItem(common_local_url('smssettings'),
- _('Connect'), _('Connect to SMS, Twitter'), false, 'nav_connect');
+ if (Event::handle('StartPrimaryNav', array($this))) {
+ if ($user) {
+ $this->menuItem(common_local_url('all', array('nickname' => $user->nickname)),
+ _('Home'), _('Personal profile and friends timeline'), false, 'nav_home');
}
- $this->menuItem(common_local_url('logout'),
- _('Logout'), _('Logout from the site'), false, 'nav_logout');
- } else {
- $this->menuItem(common_local_url('login'),
- _('Login'), _('Login to the site'), false, 'nav_login');
- if (!common_config('site', 'closed')) {
- $this->menuItem(common_local_url('register'),
- _('Register'), _('Create an account'), false, 'nav_register');
+ $this->menuItem(common_local_url('peoplesearch'),
+ _('Search'), _('Search for people or text'), false, 'nav_search');
+ if ($user) {
+ $this->menuItem(common_local_url('profilesettings'),
+ _('Account'), _('Change your email, avatar, password, profile'), false, 'nav_account');
+
+ if (common_config('xmpp', 'enabled')) {
+ $this->menuItem(common_local_url('imsettings'),
+ _('Connect'), _('Connect to IM, SMS, Twitter'), false, 'nav_connect');
+ } else {
+ $this->menuItem(common_local_url('smssettings'),
+ _('Connect'), _('Connect to SMS, Twitter'), false, 'nav_connect');
+ }
+ $this->menuItem(common_local_url('logout'),
+ _('Logout'), _('Logout from the site'), false, 'nav_logout');
+ } else {
+ $this->menuItem(common_local_url('login'),
+ _('Login'), _('Login to the site'), false, 'nav_login');
+ if (!common_config('site', 'closed')) {
+ $this->menuItem(common_local_url('register'),
+ _('Register'), _('Create an account'), false, 'nav_register');
+ }
+ $this->menuItem(common_local_url('openidlogin'),
+ _('OpenID'), _('Login with OpenID'), false, 'nav_openid');
}
- $this->menuItem(common_local_url('openidlogin'),
- _('OpenID'), _('Login with OpenID'), false, 'nav_openid');
+ $this->menuItem(common_local_url('doc', array('title' => 'help')),
+ _('Help'), _('Help me!'), false, 'nav_help');
+ Event::handle('EndPrimaryNav', array($this));
}
- $this->menuItem(common_local_url('doc', array('title' => 'help')),
- _('Help'), _('Help me!'), false, 'nav_help');
$this->elementEnd('ul');
$this->elementEnd('dd');
$this->elementEnd('dl');
@@ -409,7 +447,10 @@ class Action extends HTMLOutputter // lawsuit
{
$this->elementStart('div', array('id' => 'core'));
$this->showLocalNavBlock();
- $this->showContentBlock();
+ if (Event::handle('StartShowContentBlock', array($this))) {
+ $this->showContentBlock();
+ Event::handle('EndShowContentBlock', array($this));
+ }
$this->showAside();
$this->elementEnd('div');
}
@@ -511,27 +552,32 @@ class Action extends HTMLOutputter // lawsuit
*
* @return nothing
*/
+
function showAside()
{
$this->elementStart('div', array('id' => 'aside_primary',
'class' => 'aside'));
$this->showExportData();
- $this->showSections();
+ if (Event::handle('StartShowSections', array($this))) {
+ $this->showSections();
+ Event::handle('EndShowSections', array($this));
+ }
$this->elementEnd('div');
}
/**
* Show export data feeds.
*
- * MAY overload if there are feeds
- *
- * @return nothing
+ * @return void
*/
+
function showExportData()
{
- // is there structure to this?
- // list of (visible!) feed links
- // can we reuse list of feeds from showFeeds() ?
+ $feeds = $this->getFeeds();
+ if ($feeds) {
+ $fl = new FeedList($this);
+ $fl->show($feeds);
+ }
}
/**
@@ -570,18 +616,21 @@ class Action extends HTMLOutputter // lawsuit
$this->element('dt', null, _('Secondary site navigation'));
$this->elementStart('dd', null);
$this->elementStart('ul', array('class' => 'nav'));
- $this->menuItem(common_local_url('doc', array('title' => 'help')),
- _('Help'));
- $this->menuItem(common_local_url('doc', array('title' => 'about')),
- _('About'));
- $this->menuItem(common_local_url('doc', array('title' => 'faq')),
- _('FAQ'));
- $this->menuItem(common_local_url('doc', array('title' => 'privacy')),
- _('Privacy'));
- $this->menuItem(common_local_url('doc', array('title' => 'source')),
- _('Source'));
- $this->menuItem(common_local_url('doc', array('title' => 'contact')),
- _('Contact'));
+ if (Event::handle('StartSecondaryNav', array($this))) {
+ $this->menuItem(common_local_url('doc', array('title' => 'help')),
+ _('Help'));
+ $this->menuItem(common_local_url('doc', array('title' => 'about')),
+ _('About'));
+ $this->menuItem(common_local_url('doc', array('title' => 'faq')),
+ _('FAQ'));
+ $this->menuItem(common_local_url('doc', array('title' => 'privacy')),
+ _('Privacy'));
+ $this->menuItem(common_local_url('doc', array('title' => 'source')),
+ _('Source'));
+ $this->menuItem(common_local_url('doc', array('title' => 'contact')),
+ _('Contact'));
+ Event::handle('EndSecondaryNav', array($this));
+ }
$this->elementEnd('ul');
$this->elementEnd('dd');
$this->elementEnd('dl');
@@ -789,11 +838,12 @@ class Action extends HTMLOutputter // lawsuit
*
* @return nothing
*/
+
function serverError($msg, $code=500)
{
$action = $this->trimmed('action');
common_debug("Server error '$code' on '$action': $msg", __FILE__);
- common_server_error($msg, $code);
+ throw new ServerException($msg, $code);
}
/**
@@ -804,11 +854,12 @@ class Action extends HTMLOutputter // lawsuit
*
* @return nothing
*/
+
function clientError($msg, $code=400)
{
$action = $this->trimmed('action');
common_debug("User error '$code' on '$action': $msg", __FILE__);
- common_user_error($msg, $code);
+ throw new ClientException($msg, $code);
}
/**
@@ -902,4 +953,17 @@ class Action extends HTMLOutputter // lawsuit
$this->elementEnd('div');
}
}
+
+ /**
+ * An array of feeds for this action.
+ *
+ * Returns an array of potential feeds for this action.
+ *
+ * @return array Feed object to show in head and links
+ */
+
+ function getFeeds()
+ {
+ return null;
+ }
}
diff --git a/classes/Channel.php b/lib/channel.php
index fdeff21fc..f1e205546 100644
--- a/classes/Channel.php
+++ b/lib/channel.php
@@ -21,7 +21,6 @@ if (!defined('LACONICA')) { exit(1); }
class Channel
{
-
function on($user)
{
return false;
diff --git a/lib/clientexception.php b/lib/clientexception.php
new file mode 100644
index 000000000..3020d7f50
--- /dev/null
+++ b/lib/clientexception.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * Laconica, the distributed open-source microblogging tool
+ *
+ * class for a client exception (user error)
+ *
+ * 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 Exception
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @copyright 2008 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);
+}
+
+/**
+ * Class for client exceptions
+ *
+ * Subclass of PHP Exception for user errors.
+ *
+ * @category Exception
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ */
+
+class ClientException extends Exception
+{
+ public function __construct($message = null, $code = 400) {
+ parent::__construct($message, $code);
+ }
+
+ // custom string representation of object
+ public function __toString() {
+ return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
+ }
+}
diff --git a/classes/Command.php b/lib/command.php
index eacbdacb3..507990a0b 100644
--- a/classes/Command.php
+++ b/lib/command.php
@@ -19,18 +19,18 @@
if (!defined('LACONICA')) { exit(1); }
-require_once(INSTALLDIR.'/classes/Channel.php');
+require_once(INSTALLDIR.'/lib/channel.php');
class Command
{
-
+
var $user = null;
-
+
function __construct($user=null)
{
$this->user = $user;
}
-
+
function execute($channel)
{
return false;
@@ -109,7 +109,7 @@ class StatsCommand extends Command
$notices = new Notice();
$notices->profile_id = $this->user->id;
$notice_count = (int) $notices->count();
-
+
$channel->output($this->user, sprintf(_("Subscriptions: %1\$s\n".
"Subscribers: %2\$s\n".
"Notices: %3\$s"),
@@ -121,21 +121,21 @@ class StatsCommand extends Command
class FavCommand extends Command
{
-
+
var $other = null;
-
+
function __construct($user, $other)
{
parent::__construct($user);
$this->other = $other;
}
-
+
function execute($channel)
{
-
- $recipient =
+
+ $recipient =
common_relative_profile($this->user, common_canonical_nickname($this->other));
-
+
if (!$recipient) {
$channel->error($this->user, _('No such user.'));
return;
@@ -145,7 +145,7 @@ class FavCommand extends Command
$channel->error($this->user, _('User has no last notice'));
return;
}
-
+
$fave = Fave::addNew($this->user, $notice);
if (!$fave) {
@@ -154,15 +154,15 @@ class FavCommand extends Command
}
$other = User::staticGet('id', $recipient->id);
-
+
if ($other && $other->id != $user->id) {
if ($other->email && $other->emailnotifyfav) {
mail_notify_fave($other, $this->user, $notice);
}
}
-
+
$this->user->blowFavesCache();
-
+
$channel->output($this->user, _('Notice marked as fave.'));
}
}
@@ -175,17 +175,17 @@ class WhoisCommand extends Command
parent::__construct($user);
$this->other = $other;
}
-
+
function execute($channel)
{
- $recipient =
+ $recipient =
common_relative_profile($this->user, common_canonical_nickname($this->other));
-
+
if (!$recipient) {
$channel->error($this->user, _('No such user.'));
return;
}
-
+
$whois = sprintf(_("%1\$s (%2\$s)"), $recipient->nickname,
$recipient->profileurl);
if ($recipient->fullname) {
@@ -214,7 +214,7 @@ class MessageCommand extends Command
$this->other = $other;
$this->text = $text;
}
-
+
function execute($channel)
{
$other = User::staticGet('nickname', common_canonical_nickname($this->other));
@@ -229,7 +229,7 @@ class MessageCommand extends Command
return;
}
}
-
+
if (!$other) {
$channel->error($this->user, _('No such user.'));
return;
@@ -251,19 +251,19 @@ class MessageCommand extends Command
class GetCommand extends Command
{
-
+
var $other = null;
-
+
function __construct($user, $other)
{
parent::__construct($user);
$this->other = $other;
}
-
+
function execute($channel)
{
$target_nickname = common_canonical_nickname($this->other);
-
+
$target =
common_relative_profile($this->user, $target_nickname);
@@ -277,32 +277,32 @@ class GetCommand extends Command
return;
}
$notice_content = $notice->content;
-
+
$channel->output($this->user, $target_nickname . ": " . $notice_content);
}
}
class SubCommand extends Command
{
-
+
var $other = null;
-
+
function __construct($user, $other)
{
parent::__construct($user);
$this->other = $other;
}
-
+
function execute($channel)
{
-
+
if (!$this->other) {
$channel->error($this->user, _('Specify the name of the user to subscribe to'));
return;
}
-
+
$result = subs_subscribe_user($this->user, $this->other);
-
+
if ($result == 'true') {
$channel->output($this->user, sprintf(_('Subscribed to %s'), $this->other));
} else {
@@ -315,7 +315,7 @@ class UnsubCommand extends Command
{
var $other = null;
-
+
function __construct($user, $other)
{
parent::__construct($user);
@@ -328,9 +328,9 @@ class UnsubCommand extends Command
$channel->error($this->user, _('Specify the name of the user to unsubscribe from'));
return;
}
-
+
$result=subs_unsubscribe_user($this->user, $this->other);
-
+
if ($result) {
$channel->output($this->user, sprintf(_('Unsubscribed from %s'), $this->other));
} else {
@@ -369,7 +369,7 @@ class OnCommand extends Command
parent::__construct($user);
$this->other = $other;
}
-
+
function execute($channel)
{
if ($other) {
@@ -406,7 +406,7 @@ class HelpCommand extends Command
"unsub <nickname> - same as 'leave'\n".
"last <nickname> - same as 'get'\n".
"on <nickname> - not yet implemented.\n".
- "off <nickname> - not yet implemented.\n".
+ "off <nickname> - not yet implemented.\n".
"nudge <nickname> - not yet implemented.\n".
"invite <phone number> - not yet implemented.\n".
"track <word> - not yet implemented.\n".
diff --git a/classes/CommandInterpreter.php b/lib/commandinterpreter.php
index 0679f5462..49c733c03 100644
--- a/classes/CommandInterpreter.php
+++ b/lib/commandinterpreter.php
@@ -19,11 +19,10 @@
if (!defined('LACONICA')) { exit(1); }
-require_once(INSTALLDIR.'/classes/Command.php');
+require_once INSTALLDIR.'/lib/command.php';
class CommandInterpreter
{
-
function handle_command($user, $text)
{
# XXX: localise
diff --git a/lib/common.php b/lib/common.php
index 5b4e3c40c..7bfd14c42 100644
--- a/lib/common.php
+++ b/lib/common.php
@@ -49,6 +49,12 @@ require_once('DB/DataObject/Cast.php'); # for dates
require_once(INSTALLDIR.'/lib/language.php');
+// This gets included before the config file, so that admin code and plugins
+// can use it
+
+require_once(INSTALLDIR.'/lib/event.php');
+require_once(INSTALLDIR.'/lib/plugin.php');
+
// try to figure out where we are
$_server = array_key_exists('SERVER_NAME', $_SERVER) ?
@@ -177,6 +183,8 @@ foreach ($_config_files as $_config_file) {
}
}
+// XXX: how many of these could be auto-loaded on use?
+
require_once('Validate.php');
require_once('markdown.php');
@@ -188,6 +196,9 @@ 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');
+
// XXX: other formats here
define('NICKNAME_FMT', VALIDATE_NUM.VALIDATE_ALPHA_LOWER);
@@ -200,5 +211,12 @@ function __autoload($class)
require_once(INSTALLDIR.'/classes/' . $class . '.php');
} else if (file_exists(INSTALLDIR.'/lib/' . strtolower($class) . '.php')) {
require_once(INSTALLDIR.'/lib/' . strtolower($class) . '.php');
+ } else if (mb_substr($class, -6) == 'Action' &&
+ file_exists(INSTALLDIR.'/actions/' . strtolower(mb_substr($class, 0, -6)) . '.php')) {
+ require_once(INSTALLDIR.'/actions/' . strtolower(mb_substr($class, 0, -6)) . '.php');
}
}
+
+// Give plugins a chance to initialize in a fully-prepared environment
+
+Event::handle('InitializePlugin');
diff --git a/lib/dberroraction.php b/lib/dberroraction.php
new file mode 100644
index 000000000..0dc92490c
--- /dev/null
+++ b/lib/dberroraction.php
@@ -0,0 +1,73 @@
+<?php
+/**
+ * DB error action.
+ *
+ * PHP version 5
+ *
+ * @category Action
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @author Zach Copley <zach@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link http://laconi.ca/
+ *
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, Inc.
+ *
+ * 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/>.
+ */
+
+if (!defined('LACONICA')) {
+ exit(1);
+}
+
+require_once INSTALLDIR.'/lib/servererroraction.php';
+
+/**
+ * Class for displaying DB Errors
+ *
+ * This only occurs if there's been a DB_DataObject_Error that's
+ * reported through PEAR, so we try to avoid doing anything that connects
+ * to the DB, so we don't trigger it again.
+ *
+ * @category Action
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link http://laconi.ca/
+ */
+
+class DBErrorAction extends ServerErrorAction
+{
+ function __construct($message='Error', $code=500)
+ {
+ parent::__construct($message, $code);
+ }
+
+ function title()
+ {
+ return _('Database error');
+ }
+
+ function getLanguage()
+ {
+ // Don't try to figure out user's language; just show the page
+ return common_config('site', 'language');
+ }
+
+ function showPrimaryNav()
+ {
+ // don't show primary nav
+ }
+}
diff --git a/lib/event.php b/lib/event.php
new file mode 100644
index 000000000..d815ae54b
--- /dev/null
+++ b/lib/event.php
@@ -0,0 +1,113 @@
+<?php
+/**
+ * Laconica, the distributed open-source microblogging tool
+ *
+ * utilities for defining and running event handlers
+ *
+ * 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 Event
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @copyright 2008 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);
+}
+
+/**
+ * Class for events
+ *
+ * This "class" two static functions for managing events in the Laconica code.
+ *
+ * @category Event
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ *
+ * @todo Define a system for using Event instances
+ */
+
+class Event {
+
+ /* Global array of hooks, mapping eventname => array of callables */
+
+ protected static $_handlers = array();
+
+ /**
+ * Add an event handler
+ *
+ * To run some code at a particular point in Laconica processing.
+ * Named events include receiving an XMPP message, adding a new notice,
+ * or showing part of an HTML page.
+ *
+ * The arguments to the handler vary by the event. Handlers can return
+ * two possible values: false means that the event has been replaced by
+ * the handler completely, and no default processing should be done.
+ * Non-false means successful handling, and that the default processing
+ * should succeed. (Note that this only makes sense for some events.)
+ *
+ * Handlers can also abort processing by throwing an exception; these will
+ * be caught by the closest code and displayed as errors.
+ *
+ * @param string $name Name of the event
+ * @param callable $handler Code to run
+ *
+ * @return void
+ */
+
+ public static function addHandler($name, $handler) {
+ if (array_key_exists($name, Event::$_handlers)) {
+ Event::$_handlers[$name][] = $handler;
+ } else {
+ Event::$_handlers[$name] = array($handler);
+ }
+ }
+
+ /**
+ * Handle an event
+ *
+ * Events are any point in the code that we want to expose for admins
+ * or third-party developers to use.
+ *
+ * We pass in an array of arguments (including references, for stuff
+ * that can be changed), and each assigned handler gets run with those
+ * arguments. Exceptions can be thrown to indicate an error.
+ *
+ * @param string $name Name of the event that's happening
+ * @param array $args Arguments for handlers
+ *
+ * @return boolean flag saying whether to continue processing, based
+ * on results of handlers.
+ */
+
+ public static function handle($name, $args=array()) {
+ $result = null;
+ if (array_key_exists($name, Event::$_handlers)) {
+ foreach (Event::$_handlers[$name] as $handler) {
+ $result = call_user_func_array($handler, $args);
+ if ($result === false) {
+ break;
+ }
+ }
+ }
+ return ($result !== false);
+ }
+}
diff --git a/lib/facebookutil.php b/lib/facebookutil.php
index beab51366..e2ad20d19 100644
--- a/lib/facebookutil.php
+++ b/lib/facebookutil.php
@@ -36,7 +36,7 @@ function getFacebookNotices($since)
// XXX: What should the limit be?
//static function getStreamDirect($qry, $offset, $limit, $since_id, $before_id, $order, $since) {
-
+
return Notice::getStreamDirect($qry, 0, 1000, 0, 0, null, $since);
}
@@ -52,3 +52,97 @@ function updateProfileBox($facebook, $flink, $notice) {
$fbaction->updateProfileBox($notice);
}
+function isFacebookBound($notice, $flink) {
+
+ // If the user does not want to broadcast to Facebook, move along
+ if (!($flink->noticesync & FOREIGN_NOTICE_SEND == FOREIGN_NOTICE_SEND)) {
+ common_log(LOG_INFO, "Skipping notice $notice->id " .
+ 'because user has FOREIGN_NOTICE_SEND bit off.');
+ return false;
+ }
+
+ $success = false;
+
+ // If it's not a reply, or if the user WANTS to send @-replies...
+ if (!preg_match('/@[a-zA-Z0-9_]{1,15}\b/u', $notice->content) ||
+ ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY)) {
+
+ $success = true;
+
+ // The two condition below are deal breakers:
+
+ // Avoid a loop
+ if ($notice->source == 'Facebook') {
+ common_log(LOG_INFO, "Skipping notice $notice->id because its " .
+ 'source is Facebook.');
+ $success = false;
+ }
+
+ $facebook = getFacebook();
+ $fbuid = $flink->foreign_id;
+
+ try {
+
+ // Check to see if the user has given the FB app status update perms
+ $result = $facebook->api_client->
+ users_hasAppPermission('status_update', $fbuid);
+
+ if ($result != 1) {
+ $user = $flink->getUser();
+ $msg = "Can't send notice $notice->id to Facebook " .
+ "because user $user->nickname hasn't given the " .
+ 'Facebook app \'status_update\' permission.';
+ common_log(LOG_INFO, $msg);
+ $success = false;
+ }
+
+ } catch(FacebookRestClientException $e){
+ common_log(LOG_ERROR, $e->getMessage());
+ $success = false;
+ }
+
+ }
+
+ return $success;
+
+}
+
+
+function facebookBroadcastNotice($notice)
+{
+ $facebook = getFacebook();
+ $flink = Foreign_link::getByUserID($notice->profile_id, FACEBOOK_SERVICE);
+ $fbuid = $flink->foreign_id;
+
+ if (isFacebookBound($notice, $flink)) {
+
+ $status = null;
+
+ // Get the status 'verb' (prefix) the user has set
+ try {
+ $prefix = $facebook->api_client->
+ data_getUserPreference(FACEBOOK_NOTICE_PREFIX, $fbuid);
+
+ $status = "$prefix $notice->content";
+
+ } catch(FacebookRestClientException $e) {
+ common_log(LOG_ERROR, $e->getMessage());
+ return false;
+ }
+
+ // Okay, we're good to go!
+
+ try {
+ $facebook->api_client->users_setStatus($status, $fbuid, false, true);
+ updateProfileBox($facebook, $flink, $notice);
+ } catch(FacebookRestClientException $e) {
+ common_log(LOG_ERROR, $e->getMessage());
+ return false;
+
+ // Should we remove flink if this fails?
+ }
+
+ }
+
+ return true;
+}
diff --git a/lib/feed.php b/lib/feed.php
new file mode 100644
index 000000000..466926844
--- /dev/null
+++ b/lib/feed.php
@@ -0,0 +1,110 @@
+<?php
+/**
+ * Laconica, the distributed open-source microblogging tool
+ *
+ * Data structure for info about syndication feeds (RSS 1.0, RSS 2.0, Atom)
+ *
+ * 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 Feed
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @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);
+}
+
+/**
+ * Data structure for feeds
+ *
+ * This structure is a helpful container for shipping around information about syndication feeds.
+ *
+ * @category Feed
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @author Sarven Capadisli <csarven@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ */
+
+class Feed
+{
+ const RSS1 = 1;
+ const RSS2 = 2;
+ const ATOM = 3;
+ const FOAF = 4;
+
+ var $type = null;
+ var $url = null;
+ var $title = null;
+
+ function __construct($type, $url, $title)
+ {
+ $this->type = $type;
+ $this->url = $url;
+ $this->title = $title;
+ }
+
+ function mimeType()
+ {
+ switch ($this->type) {
+ case Feed::RSS1:
+ return 'application/rdf+xml';
+ case Feed::RSS2:
+ return 'application/rss+xml';
+ case Feed::ATOM:
+ return 'application/atom+xml';
+ case Feed::FOAF:
+ return 'application/rdf+xml';
+ default:
+ return null;
+ }
+ }
+
+ function typeName()
+ {
+ switch ($this->type) {
+ case Feed::RSS1:
+ return _('RSS 1.0');
+ case Feed::RSS2:
+ return _('RSS 2.0');
+ case Feed::ATOM:
+ return _('Atom');
+ case Feed::FOAF:
+ return _('FOAF');
+ default:
+ return null;
+ }
+ }
+
+ function rel()
+ {
+ switch ($this->type) {
+ case Feed::RSS1:
+ case Feed::RSS2:
+ case Feed::ATOM:
+ return 'alternate';
+ case Feed::FOAF:
+ return 'meta';
+ default:
+ return null;
+ }
+ }
+}
diff --git a/lib/feedlist.php b/lib/feedlist.php
index 47d909e96..927e43c33 100644
--- a/lib/feedlist.php
+++ b/lib/feedlist.php
@@ -50,7 +50,7 @@ if (!defined('LACONICA')) {
class FeedList extends Widget
{
var $action = null;
-
+
function __construct($action=null)
{
parent::__construct($action);
@@ -64,8 +64,8 @@ class FeedList extends Widget
$this->out->element('h2', null, _('Export data'));
$this->out->elementStart('ul', array('class' => 'xoxo'));
- foreach ($feeds as $key => $value) {
- $this->feedItem($feeds[$key]);
+ foreach ($feeds as $feed) {
+ $this->feedItem($feed);
}
$this->out->elementEnd('ul');
@@ -74,85 +74,27 @@ class FeedList extends Widget
function feedItem($feed)
{
- $nickname = $this->action->trimmed('nickname');
-
- switch($feed['item']) {
- case 'notices': default:
- $feed_classname = $feed['type'];
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = "$nickname's ".$feed['version']." notice feed";
- $feed['textContent'] = "RSS";
- break;
-
- case 'allrss':
- $feed_classname = $feed['type'];
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = $feed['version']." feed for $nickname and friends";
- $feed['textContent'] = "RSS";
- break;
-
- case 'repliesrss':
- $feed_classname = $feed['type'];
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = $feed['version']." feed for replies to $nickname";
- $feed['textContent'] = "RSS";
- break;
-
- case 'publicrss':
- $feed_classname = $feed['type'];
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = "Public timeline ".$feed['version']." feed";
- $feed['textContent'] = "RSS";
- break;
+ $classname = null;
- case 'publicatom':
- $feed_classname = "atom";
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = "Public timeline ".$feed['version']." feed";
- $feed['textContent'] = "Atom";
+ switch ($feed->type) {
+ case Feed::RSS1:
+ case Feed::RSS2:
+ $classname = 'rss';
break;
-
- case 'tagrss':
- $feed_classname = $feed['type'];
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = $feed['version']." feed for this tag";
- $feed['textContent'] = "RSS";
+ case Feed::ATOM:
+ $classname = 'atom';
break;
-
- case 'favoritedrss':
- $feed_classname = $feed['type'];
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = "Favorited ".$feed['version']." feed";
- $feed['textContent'] = "RSS";
- break;
-
- case 'foaf':
- $feed_classname = "foaf";
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = "$nickname's FOAF file";
- $feed['textContent'] = "FOAF";
- break;
-
- case 'favoritesrss':
- $feed_classname = "favorites";
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = "Feed for favorites of $nickname";
- $feed['textContent'] = "RSS";
- break;
-
- case 'usertimeline':
- $feed_classname = "atom";
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = "$nickname's ".$feed['version']." notice feed";
- $feed['textContent'] = "Atom";
+ case Feed::FOAF:
+ $classname = 'foaf';
break;
}
+
$this->out->elementStart('li');
- $this->out->element('a', array('href' => $feed['href'],
- 'class' => $feed_classname,
- 'type' => $feed_mimetype,
- 'title' => $feed_title),
- $feed['textContent']);
+ $this->out->element('a', array('href' => $feed->url,
+ 'class' => $classname,
+ 'type' => $feed->mimeType(),
+ 'title' => $feed->title),
+ $feed->typeName());
$this->out->elementEnd('li');
}
}
diff --git a/lib/grouplist.php b/lib/grouplist.php
index 4c448e250..6801ab426 100644
--- a/lib/grouplist.php
+++ b/lib/grouplist.php
@@ -124,7 +124,7 @@ class GroupList extends Widget
if ($this->group->location) {
$this->out->elementStart('dl', 'entity_location');
$this->out->element('dt', null, _('Location'));
- $this->out->elementStart('dd', 'location');
+ $this->out->elementStart('dd', 'label');
$this->out->raw($this->highlight($this->group->location));
$this->out->elementEnd('dd');
$this->out->elementEnd('dl');
diff --git a/lib/htmloutputter.php b/lib/htmloutputter.php
index e2319b1fd..06603ac05 100644
--- a/lib/htmloutputter.php
+++ b/lib/htmloutputter.php
@@ -101,29 +101,32 @@ class HTMLOutputter extends XMLOutputter
$type = common_negotiate_type($cp, $sp);
if (!$type) {
- common_user_error(_('This page is not available in a '.
- 'media type you accept'), 406);
- exit(0);
+ throw new ClientException(_('This page is not available in a '.
+ 'media type you accept'), 406);
}
}
header('Content-Type: '.$type);
-
+
$this->extraHeaders();
$this->startXML('html',
'-//W3C//DTD XHTML 1.0 Strict//EN',
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd');
- // FIXME: correct language for interface
-
- $language = common_language();
+ $language = $this->getLanguage();
$this->elementStart('html', array('xmlns' => 'http://www.w3.org/1999/xhtml',
'xml:lang' => $language,
'lang' => $language));
}
+ function getLanguage()
+ {
+ // FIXME: correct language for interface
+ return common_language();
+ }
+
/**
* Ends an HTML document
*
@@ -134,7 +137,7 @@ class HTMLOutputter extends XMLOutputter
$this->elementEnd('html');
$this->endXML();
}
-
+
/**
* To specify additional HTTP headers for the action
*
diff --git a/lib/imagefile.php b/lib/imagefile.php
index db344db8f..0c93b257e 100644
--- a/lib/imagefile.php
+++ b/lib/imagefile.php
@@ -68,17 +68,17 @@ class ImageFile
static function fromUpload($param='upload')
{
switch ($_FILES[$param]['error']) {
- case UPLOAD_ERR_OK: // success, jump out
+ case UPLOAD_ERR_OK: // success, jump out
break;
- case UPLOAD_ERR_INI_SIZE:
- case UPLOAD_ERR_FORM_SIZE:
+ case UPLOAD_ERR_INI_SIZE:
+ case UPLOAD_ERR_FORM_SIZE:
throw new Exception(sprintf(_('That file is too big. The maximum file size is %d.'), $this->maxFileSize()));
return;
- case UPLOAD_ERR_PARTIAL:
+ case UPLOAD_ERR_PARTIAL:
@unlink($_FILES[$param]['tmp_name']);
throw new Exception(_('Partial upload.'));
return;
- default:
+ default:
throw new Exception(_('System error uploading file.'));
return;
}
@@ -113,6 +113,23 @@ class ImageFile
return;
}
+ // Don't crop/scale if it isn't necessary
+ if ($size === $this->width
+ && $size === $this->height
+ && $x === 0
+ && $y === 0
+ && $w === $this->width
+ && $h === $this->height) {
+
+ $outname = Avatar::filename($this->id,
+ image_type_to_extension($this->type),
+ $size,
+ common_timestamp());
+ $outpath = Avatar::path($outname);
+ @copy($this->filepath, $outpath);
+ return $outname;
+ }
+
switch ($this->type) {
case IMAGETYPE_GIF:
$image_src = imagecreatefromgif($this->filepath);
@@ -154,9 +171,9 @@ class ImageFile
imagecopyresampled($image_dest, $image_src, 0, 0, $x, $y, $size, $size, $w, $h);
$outname = Avatar::filename($this->id,
- image_type_to_extension($this->type),
- $size,
- common_timestamp());
+ image_type_to_extension($this->type),
+ $size,
+ common_timestamp());
$outpath = Avatar::path($outname);
@@ -165,7 +182,7 @@ class ImageFile
imagegif($image_dest, $outpath);
break;
case IMAGETYPE_JPEG:
- imagejpeg($image_dest, $outpath);
+ imagejpeg($image_dest, $outpath, 100);
break;
case IMAGETYPE_PNG:
imagepng($image_dest, $outpath);
@@ -175,6 +192,9 @@ class ImageFile
return;
}
+ imagedestroy($image_src);
+ imagedestroy($image_dest);
+
return $outname;
}
@@ -209,12 +229,12 @@ class ImageFile
$num = substr($str, 0, -1);
switch(strtoupper($unit)){
- case 'G':
- $num *= 1024;
- case 'M':
- $num *= 1024;
- case 'K':
- $num *= 1024;
+ case 'G':
+ $num *= 1024;
+ case 'M':
+ $num *= 1024;
+ case 'K':
+ $num *= 1024;
}
return $num;
diff --git a/lib/plugin.php b/lib/plugin.php
new file mode 100644
index 000000000..7b2436e54
--- /dev/null
+++ b/lib/plugin.php
@@ -0,0 +1,79 @@
+<?php
+/**
+ * Laconica, the distributed open-source microblogging tool
+ *
+ * Utility class for plugins
+ *
+ * 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 Plugin
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @copyright 2008 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);
+}
+
+/**
+ * Base class for plugins
+ *
+ * A base class for Laconica plugins. Mostly a light wrapper around
+ * the Event framework.
+ *
+ * Subclasses of Plugin will automatically handle an event if they define
+ * a method called "onEventName". (Well, OK -- only if they call parent::__construct()
+ * in their constructors.)
+ *
+ * They will also automatically handle the InitializePlugin and CleanupPlugin with the
+ * initialize() and cleanup() methods, respectively.
+ *
+ * @category Plugin
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ *
+ * @see Event
+ */
+
+class Plugin
+{
+ function __construct()
+ {
+ Event::addHandler('InitializePlugin', array($this, 'initialize'));
+ Event::addHandler('CleanupPlugin', array($this, 'cleanup'));
+
+ foreach (get_class_methods($this) as $method) {
+ if (mb_substr($method, 0, 2) == 'on') {
+ Event::addHandler(mb_substr($method, 2), array($this, $method));
+ }
+ }
+ }
+
+ function initialize()
+ {
+ return true;
+ }
+
+ function cleanup()
+ {
+ return true;
+ }
+}
diff --git a/lib/profilelist.php b/lib/profilelist.php
index 4d924b039..8bef49dce 100644
--- a/lib/profilelist.php
+++ b/lib/profilelist.php
@@ -123,7 +123,7 @@ class ProfileList extends Widget
if ($this->profile->location) {
$this->out->elementStart('dl', 'entity_location');
$this->out->element('dt', null, _('Location'));
- $this->out->elementStart('dd', 'location');
+ $this->out->elementStart('dd', 'label');
$this->out->raw($this->highlight($this->profile->location));
$this->out->elementEnd('dd');
$this->out->elementEnd('dl');
diff --git a/lib/router.php b/lib/router.php
new file mode 100644
index 000000000..d47ad7118
--- /dev/null
+++ b/lib/router.php
@@ -0,0 +1,363 @@
+<?php
+/**
+ * Laconica, the distributed open-source microblogging tool
+ *
+ * URL routing utilities
+ *
+ * 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 URL
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @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);
+}
+
+require_once 'Net/URL/Mapper.php';
+
+/**
+ * URL Router
+ *
+ * Cheap wrapper around Net_URL_Mapper
+ *
+ * @category URL
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ */
+
+class Router
+{
+ static $m = null;
+ static $inst = null;
+
+ static function get()
+ {
+ if (!Router::$inst) {
+ Router::$inst = new Router();
+ }
+ return Router::$inst;
+ }
+
+ function __construct()
+ {
+ if (!$this->m) {
+ $this->m = $this->initialize();
+ }
+ }
+
+ function initialize() {
+
+ $m = Net_URL_Mapper::getInstance();
+
+ // In the "root"
+
+ $m->connect('', array('action' => 'public'));
+ $m->connect('rss', array('action' => 'publicrss'));
+ $m->connect('xrds', array('action' => 'publicxrds'));
+ $m->connect('featuredrss', array('action' => 'featuredrss'));
+ $m->connect('favoritedrss', array('action' => 'favoritedrss'));
+ $m->connect('opensearch/people', array('action' => 'opensearch',
+ 'type' => 'people'));
+ $m->connect('opensearch/notice', array('action' => 'opensearch',
+ 'type' => 'notice'));
+
+ // docs
+
+ $m->connect('doc/:title', array('action' => 'doc'));
+
+ // facebook
+
+ $m->connect('facebook', array('action' => 'facebookhome'));
+ $m->connect('facebook/index.php', array('action' => 'facebookhome'));
+ $m->connect('facebook/settings.php', array('action' => 'facebooksettings'));
+ $m->connect('facebook/invite.php', array('action' => 'facebookinvite'));
+ $m->connect('facebook/remove', array('action' => 'facebookremove'));
+
+ // main stuff is repetitive
+
+ $main = array('login', 'logout', 'register', 'subscribe',
+ 'unsubscribe', 'confirmaddress', 'recoverpassword',
+ 'invite', 'favor', 'disfavor', 'sup',
+ 'tagother', 'block');
+
+ foreach ($main as $a) {
+ $m->connect('main/'.$a, array('action' => $a));
+ }
+
+ // these take a code
+
+ foreach (array('register', 'confirmaddress', 'recoverpassword') as $c) {
+ $m->connect('main/'.$c.'/:code', array('action' => $c));
+ }
+
+ // exceptional
+
+ $m->connect('main/openid', array('action' => 'openidlogin'));
+ $m->connect('main/remote', array('action' => 'remotesubscribe'));
+
+ // settings
+
+ foreach (array('profile', 'avatar', 'password', 'openid', 'im',
+ 'email', 'sms', 'twitter', 'other') as $s) {
+ $m->connect('settings/'.$s, array('action' => $s.'settings'));
+ }
+
+ // search
+
+ foreach (array('group', 'people', 'notice') as $s) {
+ $m->connect('search/'.$s, array('action' => $s.'search'));
+ }
+
+ $m->connect('search/notice/rss', array('action' => 'noticesearchrss'));
+
+ // notice
+
+ $m->connect('notice/new', array('action' => 'newnotice'));
+ $m->connect('notice/:notice',
+ array('action' => 'shownotice'),
+ array('notice' => '[0-9]+'));
+ $m->connect('notice/delete', array('action' => 'deletenotice'));
+ $m->connect('notice/delete/:notice',
+ array('action' => 'deletenotice'),
+ array('notice' => '[0-9]+'));
+
+ $m->connect('message/new', array('action' => 'newmessage'));
+ $m->connect('message/:message',
+ array('action' => 'showmessage'),
+ array('message' => '[0-9]+'));
+
+ $m->connect('user/:id',
+ array('action' => 'userbyid'),
+ array('id' => '[0-9]+'));
+
+ $m->connect('tags/', array('action' => 'publictagcloud'));
+ $m->connect('tag/', array('action' => 'publictagcloud'));
+ $m->connect('tags', array('action' => 'publictagcloud'));
+ $m->connect('tag', array('action' => 'publictagcloud'));
+ $m->connect('tag/:tag/rss',
+ array('action' => 'tagrss'),
+ array('tag' => '[a-zA-Z0-9]+'));
+ $m->connect('tag/:tag',
+ array('action' => 'tag'),
+ array('tag' => '[a-zA-Z0-9]+'));
+
+ $m->connect('peopletag/:tag',
+ array('action' => 'peopletag'),
+ array('tag' => '[a-zA-Z0-9]+'));
+
+ $m->connect('featured/', array('action' => 'featured'));
+ $m->connect('featured', array('action' => 'featured'));
+ $m->connect('favorited/', array('action' => 'favorited'));
+ $m->connect('favorited', array('action' => 'favorited'));
+
+ // groups
+
+ $m->connect('group/new', array('action' => 'newgroup'));
+
+ foreach (array('edit', 'join', 'leave') as $v) {
+ $m->connect('group/:nickname/'.$v,
+ array('action' => $v.'group'),
+ array('nickname' => '[a-zA-Z0-9]+'));
+ }
+
+ foreach (array('members', 'logo', 'rss') as $n) {
+ $m->connect('group/:nickname/'.$n,
+ array('action' => 'group'.$n),
+ array('nickname' => '[a-zA-Z0-9]+'));
+ }
+
+ $m->connect('group/:id/id',
+ array('action' => 'groupbyid'),
+ array('id' => '[0-9]+'));
+
+ $m->connect('group/:nickname',
+ array('action' => 'showgroup'),
+ array('nickname' => '[a-zA-Z0-9]+'));
+
+ $m->connect('group/', array('action' => 'groups'));
+ $m->connect('group', array('action' => 'groups'));
+ $m->connect('groups/', array('action' => 'groups'));
+ $m->connect('groups', array('action' => 'groups'));
+
+ // Twitter-compatible API
+
+ // statuses API
+
+ $m->connect('api/statuses/:method',
+ array('action' => 'api',
+ 'apiaction' => 'statuses'),
+ array('method' => '(public_timeline|friends_timeline|user_timeline|update|replies|friends|followers|featured)(\.(atom|rss|xml|json))?'));
+
+ $m->connect('api/statuses/:method/:argument',
+ array('action' => 'api',
+ 'apiaction' => 'statuses'),
+ array('method' => '(user_timeline|show|destroy|friends|followers)'));
+
+ // users
+
+ $m->connect('api/users/show/:argument',
+ array('action' => 'api',
+ 'apiaction' => 'users'));
+
+ $m->connect('api/users/:method',
+ array('action' => 'api',
+ 'apiaction' => 'users'),
+ array('method' => 'show(\.(xml|json|atom|rss))?'));
+
+ // direct messages
+
+ $m->connect('api/direct_messages/:method',
+ array('action' => 'api',
+ 'apiaction' => 'direct_messages'),
+ array('method' => '(sent|new)(\.(xml|json|atom|rss))?'));
+
+ $m->connect('api/direct_messages/destroy/:argument',
+ array('action' => 'api',
+ 'apiaction' => 'direct_messages'));
+
+ $m->connect('api/:method',
+ array('action' => 'api',
+ 'apiaction' => 'direct_messages'),
+ array('method' => 'direct_messages(\.(xml|json|atom|rss))?'));
+
+ // friendships
+
+ $m->connect('api/friendships/:method/:argument',
+ array('action' => 'api',
+ 'apiaction' => 'friendships'),
+ array('method' => '(create|destroy)'));
+
+ $m->connect('api/friendships/:method',
+ array('action' => 'api',
+ 'apiaction' => 'friendships'),
+ array('method' => 'exists(\.(xml|json|rss|atom))'));
+
+ // account
+
+ $m->connect('api/account/:method',
+ array('action' => 'api',
+ 'apiaction' => 'account'));
+
+ // favorites
+
+ $m->connect('api/favorites/:method/:argument',
+ array('action' => 'api',
+ 'apiaction' => 'favorites'));
+
+ $m->connect('api/favorites/:argument',
+ array('action' => 'api',
+ 'apiaction' => 'favorites',
+ 'method' => 'favorites'));
+
+ $m->connect('api/:method',
+ array('action' => 'api',
+ 'apiaction' => 'favorites'),
+ array('method' => 'favorites(\.(xml|json|rss|atom))?'));
+
+ // notifications
+
+ $m->connect('api/notifications/:method/:argument',
+ array('action' => 'api',
+ 'apiaction' => 'favorites'));
+
+ // blocks
+
+ $m->connect('api/blocks/:method/:argument',
+ array('action' => 'api',
+ 'apiaction' => 'blocks'));
+
+ // help
+
+ $m->connect('api/help/:method',
+ array('action' => 'api',
+ 'apiaction' => 'help'));
+
+ // laconica
+
+ $m->connect('api/laconica/:method',
+ array('action' => 'api',
+ 'apiaction' => 'laconica'));
+
+ // user stuff
+
+ foreach (array('subscriptions', 'subscribers',
+ 'nudge', 'xrds', 'all', 'foaf',
+ 'replies', 'inbox', 'outbox', 'microsummary') as $a) {
+ $m->connect(':nickname/'.$a,
+ array('action' => $a),
+ array('nickname' => '[a-zA-Z0-9]{1,64}'));
+ }
+
+ foreach (array('subscriptions', 'subscribers') as $a) {
+ $m->connect(':nickname/'.$a.'/:tag',
+ array('action' => $a),
+ array('tag' => '[a-zA-Z0-9]+',
+ 'nickname' => '[a-zA-Z0-9]{1,64}'));
+ }
+
+ foreach (array('rss', 'groups') as $a) {
+ $m->connect(':nickname/'.$a,
+ array('action' => 'user'.$a),
+ array('nickname' => '[a-zA-Z0-9]{1,64}'));
+ }
+
+ foreach (array('all', 'replies', 'favorites') as $a) {
+ $m->connect(':nickname/'.$a.'/rss',
+ array('action' => $a.'rss'),
+ array('nickname' => '[a-zA-Z0-9]{1,64}'));
+ }
+
+ $m->connect(':nickname/favorites',
+ array('action' => 'showfavorites'),
+ array('nickname' => '[a-zA-Z0-9]{1,64}'));
+
+ $m->connect(':nickname/avatar/:size',
+ array('action' => 'avatarbynickname'),
+ array('size' => '(original|96|48|24)',
+ 'nickname' => '[a-zA-Z0-9]{1,64}'));
+
+ $m->connect(':nickname',
+ array('action' => 'showstream'),
+ array('nickname' => '[a-zA-Z0-9]{1,64}'));
+
+ return $m;
+ }
+
+ function map($path)
+ {
+ return $this->m->match($path);
+ }
+
+ function build($action, $args=null, $fragment=null)
+ {
+ $action_arg = array('action' => $action);
+
+ if ($args) {
+ $args = array_merge($action_arg, $args);
+ } else {
+ $args = $action_arg;
+ }
+
+ return $this->m->generate($args, null, $fragment);
+ }
+} \ No newline at end of file
diff --git a/lib/serverexception.php b/lib/serverexception.php
new file mode 100644
index 000000000..b8ed6846e
--- /dev/null
+++ b/lib/serverexception.php
@@ -0,0 +1,55 @@
+<?php
+/**
+ * Laconica, the distributed open-source microblogging tool
+ *
+ * class for a server exception (user error)
+ *
+ * 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 Exception
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @copyright 2008 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);
+}
+
+/**
+ * Class for server exceptions
+ *
+ * Subclass of PHP Exception for server errors. The user typically can't fix these.
+ *
+ * @category Exception
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ */
+
+class ServerException extends Exception
+{
+ public function __construct($message = null, $code = 400) {
+ parent::__construct($message, $code);
+ }
+
+ public function __toString() {
+ return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
+ }
+}
diff --git a/lib/twitter.php b/lib/twitter.php
index 197298549..deb6fd276 100644
--- a/lib/twitter.php
+++ b/lib/twitter.php
@@ -19,6 +19,8 @@
if (!defined('LACONICA')) { exit(1); }
+define("TWITTER_SERVICE", 1); // Twitter is foreign_service ID 1
+
function get_twitter_data($uri, $screen_name, $password)
{
@@ -28,14 +30,13 @@ function get_twitter_data($uri, $screen_name, $password)
CURLOPT_FAILONERROR => true,
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
- # CURLOPT_USERAGENT => "identi.ca",
+ CURLOPT_USERAGENT => "Laconica",
CURLOPT_CONNECTTIMEOUT => 120,
CURLOPT_TIMEOUT => 120,
# Twitter is strict about accepting invalid "Expect" headers
CURLOPT_HTTPHEADER => array('Expect:')
);
-
$ch = curl_init($uri);
curl_setopt_array($ch, $options);
$data = curl_exec($ch);
@@ -95,7 +96,7 @@ function add_twitter_user($twitter_id, $screen_name)
$fuser->nickname = $screen_name;
$fuser->uri = 'http://twitter.com/' . $screen_name;
$fuser->id = $twitter_id;
- $fuser->service = 1; // Twitter
+ $fuser->service = TWITTER_SERVICE; // Twitter
$fuser->created = common_sql_now();
$result = $fuser->insert();
@@ -206,3 +207,93 @@ function save_twitter_friends($user, $twitter_id, $screen_name, $password)
return true;
}
+function is_twitter_bound($notice, $flink) {
+
+ // Check to see if notice should go to Twitter
+ if (($flink->noticesync & FOREIGN_NOTICE_SEND)) {
+
+ // If it's not a Twitter-style reply, or if the user WANTS to send replies.
+ if (!preg_match('/^@[a-zA-Z0-9_]{1,15}\b/u', $notice->content) ||
+ ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+function broadcast_twitter($notice)
+{
+ global $config;
+ $success = true;
+
+ $flink = Foreign_link::getByUserID($notice->profile_id,
+ TWITTER_SERVICE);
+
+ // XXX: Not sure WHERE to check whether a notice should go to
+ // Twitter. Should we even put in the queue if it shouldn't? --Zach
+ if (is_twitter_bound($notice, $flink)) {
+
+ $fuser = $flink->getForeignUser();
+ $twitter_user = $fuser->nickname;
+ $twitter_password = $flink->credentials;
+ $uri = 'http://www.twitter.com/statuses/update.json';
+
+ // XXX: Hack to get around PHP cURL's use of @ being a a meta character
+ $statustxt = preg_replace('/^@/', ' @', $notice->content);
+
+ $options = array(
+ CURLOPT_USERPWD => "$twitter_user:$twitter_password",
+ CURLOPT_POST => true,
+ CURLOPT_POSTFIELDS =>
+ array(
+ 'status' => $statustxt,
+ 'source' => $config['integration']['source']
+ ),
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_FAILONERROR => true,
+ CURLOPT_HEADER => false,
+ CURLOPT_FOLLOWLOCATION => true,
+ CURLOPT_USERAGENT => "Laconica",
+ CURLOPT_CONNECTTIMEOUT => 120, // XXX: How long should this be?
+ CURLOPT_TIMEOUT => 120,
+
+ # Twitter is strict about accepting invalid "Expect" headers
+ CURLOPT_HTTPHEADER => array('Expect:')
+ );
+
+ $ch = curl_init($uri);
+ curl_setopt_array($ch, $options);
+ $data = curl_exec($ch);
+ $errmsg = curl_error($ch);
+
+ if ($errmsg) {
+ common_debug("cURL error: $errmsg - " .
+ "trying to send notice for $twitter_user.",
+ __FILE__);
+ $success = false;
+ }
+
+ curl_close($ch);
+
+ if (!$data) {
+ common_debug("No data returned by Twitter's " .
+ "API trying to send update for $twitter_user",
+ __FILE__);
+ $success = false;
+ }
+
+ // Twitter should return a status
+ $status = json_decode($data);
+
+ if (!$status->id) {
+ common_debug("Unexpected data returned by Twitter " .
+ " API trying to send update for $twitter_user",
+ __FILE__);
+ $success = false;
+ }
+ }
+
+ return $success;
+}
+
diff --git a/lib/util.php b/lib/util.php
index 7ce4e229e..b065c2d74 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -394,32 +394,32 @@ function common_render_text($text)
function common_replace_urls_callback($text, $callback) {
// Start off with a regex
- $regex = '#
- (?:
- (?:
- (?:https?|ftps?|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|xmpp|irc)://
- |
- (?:mailto|aim|tel):
- )
- [^.\s]+\.[^\s]+
- |
- (?:[^.\s/:]+\.)+
- (?:museum|travel|[a-z]{2,4})
- (?:[:/][^\s]*)?
- )
- #ix';
+ $regex = '#'.
+ '(?:'.
+ '(?:'.
+ '(?:https?|ftps?|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|xmpp|irc)://'.
+ '|'.
+ '(?:mailto|aim|tel):'.
+ ')'.
+ '[^.\s]+\.[^\s]+'.
+ '|'.
+ '(?:[^.\s/:]+\.)+'.
+ '(?:museum|travel|[a-z]{2,4})'.
+ '(?:[:/][^\s]*)?'.
+ ')'.
+ '#ix';
preg_match_all($regex, $text, $matches);
// Then clean up what the regex left behind
$offset = 0;
- foreach($matches[0] as $url) {
- $url = htmlspecialchars_decode($url);
+ foreach($matches[0] as $orig_url) {
+ $url = htmlspecialchars_decode($orig_url);
// Make sure we didn't pick up an email address
if (preg_match('#^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$#i', $url)) continue;
- // Remove trailing punctuation
- $url = rtrim($url, '.?!,;:\'"`');
+ // Remove surrounding punctuation
+ $url = trim($url, '.?!,;:\'"`([<');
// Remove surrounding parens and the like
preg_match('/[)\]>]+$/', $url, $trailing);
@@ -446,7 +446,7 @@ function common_replace_urls_callback($text, $callback) {
// If the first part wasn't cap'd but the last part was, we captured too much
if ((!$prev_part && $last_part)) {
- $url = substr_replace($url, '', mb_strpos($url, '.'.$url_parts[2], 0));
+ $url = mb_substr($url, 0 , mb_strpos($url, '.'.$url_parts['2'], 0));
}
// Capture the new TLD
@@ -456,6 +456,9 @@ function common_replace_urls_callback($text, $callback) {
if (!in_array($url_parts[2], $tlds)) continue;
+ // Put the url back the way we found it.
+ $url = (mb_strpos($orig_url, htmlspecialchars($url)) === FALSE) ? $url:htmlspecialchars($url);
+
// Call user specified func
$modified_url = $callback($url);
@@ -469,16 +472,19 @@ function common_replace_urls_callback($text, $callback) {
}
function common_linkify($url) {
+ // It comes in special'd, so we unspecial it before passing to the stringifying
+ // functions
+ $url = htmlspecialchars_decode($url);
$display = $url;
- $url = (!preg_match('#^([a-z]+://|(mailto|aim|tel):)#i', $url)) ? 'http://'.$url:$url;
+ $url = (!preg_match('#^([a-z]+://|(mailto|aim|tel):)#i', $url)) ? 'http://'.$url : $url;
+
+ $attrs = array('href' => $url, 'rel' => 'external');
if ($longurl = common_longurl($url)) {
- $longurl = htmlentities($longurl, ENT_QUOTES, 'UTF-8');
- $title = "title=\"$longurl\"";
+ $attrs['title'] = $longurl;
}
- else $title = '';
- return "<a href=\"$url\" $title class=\"extlink\">$display</a>";
+ return XMLStringer::estring('a', $attrs, $display);
}
function common_longurl($short_url)
@@ -579,7 +585,13 @@ function common_tag_link($tag)
{
$canonical = common_canonical_tag($tag);
$url = common_local_url('tag', array('tag' => $canonical));
- return '<span class="tag"><a href="' . htmlspecialchars($url) . '" rel="tag">' . htmlspecialchars($tag) . '</a></span>';
+ $xs = new XMLStringer();
+ $xs->elementStart('span', 'tag');
+ $xs->element('a', array('href' => $url,
+ 'rel' => 'tag'),
+ $tag);
+ $xs->elementEnd();
+ return $xs->getString();
}
function common_canonical_tag($tag)
@@ -597,7 +609,14 @@ function common_at_link($sender_id, $nickname)
$sender = Profile::staticGet($sender_id);
$recipient = common_relative_profile($sender, common_canonical_nickname($nickname));
if ($recipient) {
- return '<span class="vcard"><a href="'.htmlspecialchars($recipient->profileurl).'" class="url"><span class="fn nickname">'.$nickname.'</span></a></span>';
+ $xs = new XMLStringer(false);
+ $xs->elementStart('span', 'vcard');
+ $xs->elementStart('a', array('href' => $recipient->profileurl,
+ 'class' => 'url'));
+ $xs->element('span', 'fn nickname', $nickname);
+ $xs->elementEnd('a');
+ $xs->elementEnd('span');
+ return $xs->getString();
} else {
return $nickname;
}
@@ -608,7 +627,14 @@ function common_group_link($sender_id, $nickname)
$sender = Profile::staticGet($sender_id);
$group = User_group::staticGet('nickname', common_canonical_nickname($nickname));
if ($group && $sender->isMember($group)) {
- return '<span class="vcard"><a href="'.htmlspecialchars($group->permalink()).'" class="url"><span class="fn nickname">'.$nickname.'</span></a></span>';
+ $xs = new XMLStringer();
+ $xs->elementStart('span', 'vcard');
+ $xs->elementStart('a', array('href' => $group->permalink(),
+ 'class' => 'url'));
+ $xs->element('span', 'fn nickname', $nickname);
+ $xs->elementEnd('a');
+ $xs->elementEnd('span');
+ return $xs->getString();
} else {
return $nickname;
}
@@ -625,7 +651,13 @@ function common_at_hash_link($sender_id, $tag)
$url = common_local_url('subscriptions',
array('nickname' => $user->nickname,
'tag' => $tag));
- return '<span class="tag"><a href="'.htmlspecialchars($url).'" rel="tag">'.$tag.'</a></span>';
+ $xs = new XMLStringer();
+ $xs->elementStart('span', 'tag');
+ $xs->element('a', array('href' => $url,
+ 'rel' => $tag),
+ $tag);
+ $xs->elementEnd('span');
+ return $xs->getString();
} else {
return $tag;
}
@@ -669,275 +701,18 @@ function common_relative_profile($sender, $nickname, $dt=null)
function common_local_url($action, $args=null, $fragment=null)
{
- $url = null;
+ $r = Router::get();
+ $path = $r->build($action, $args, $fragment);
+ if ($path) {
+ }
if (common_config('site','fancy')) {
- $url = common_fancy_url($action, $args);
+ $url = common_path(mb_substr($path, 1));
} else {
- $url = common_simple_url($action, $args);
- }
- if (!is_null($fragment)) {
- $url .= '#'.$fragment;
+ $url = common_path('index.php'.$path);
}
return $url;
}
-function common_fancy_url($action, $args=null)
-{
- switch (strtolower($action)) {
- case 'public':
- if ($args && isset($args['page'])) {
- return common_path('?page=' . $args['page']);
- } else {
- return common_path('');
- }
- case 'featured':
- if ($args && isset($args['page'])) {
- return common_path('featured?page=' . $args['page']);
- } else {
- return common_path('featured');
- }
- case 'favorited':
- if ($args && isset($args['page'])) {
- return common_path('favorited?page=' . $args['page']);
- } else {
- return common_path('favorited');
- }
- case 'publicrss':
- return common_path('rss');
- case 'publicatom':
- return common_path("api/statuses/public_timeline.atom");
- case 'publicxrds':
- return common_path('xrds');
- case 'tagrss':
- return common_path('tag/' . $args['tag'] . '/rss');
- case 'featuredrss':
- return common_path('featuredrss');
- case 'favoritedrss':
- return common_path('favoritedrss');
- case 'opensearch':
- if ($args && $args['type']) {
- return common_path('opensearch/'.$args['type']);
- } else {
- return common_path('opensearch/people');
- }
- case 'doc':
- return common_path('doc/'.$args['title']);
- case 'block':
- case 'login':
- case 'logout':
- case 'subscribe':
- case 'unsubscribe':
- case 'invite':
- return common_path('main/'.$action);
- case 'tagother':
- return common_path('main/tagother?id='.$args['id']);
- case 'register':
- if ($args && $args['code']) {
- return common_path('main/register/'.$args['code']);
- } else {
- return common_path('main/register');
- }
- case 'remotesubscribe':
- if ($args && $args['nickname']) {
- return common_path('main/remote?nickname=' . $args['nickname']);
- } else {
- return common_path('main/remote');
- }
- case 'nudge':
- return common_path($args['nickname'].'/nudge');
- case 'openidlogin':
- return common_path('main/openid');
- case 'profilesettings':
- return common_path('settings/profile');
- case 'passwordsettings':
- return common_path('settings/password');
- case 'emailsettings':
- return common_path('settings/email');
- case 'openidsettings':
- return common_path('settings/openid');
- case 'smssettings':
- return common_path('settings/sms');
- case 'twittersettings':
- return common_path('settings/twitter');
- case 'othersettings':
- return common_path('settings/other');
- case 'deleteprofile':
- return common_path('settings/delete');
- case 'newnotice':
- if ($args && $args['replyto']) {
- return common_path('notice/new?replyto='.$args['replyto']);
- } else {
- return common_path('notice/new');
- }
- case 'shownotice':
- return common_path('notice/'.$args['notice']);
- case 'deletenotice':
- if ($args && $args['notice']) {
- return common_path('notice/delete/'.$args['notice']);
- } else {
- return common_path('notice/delete');
- }
- case 'microsummary':
- case 'xrds':
- case 'foaf':
- return common_path($args['nickname'].'/'.$action);
- case 'all':
- case 'replies':
- case 'inbox':
- case 'outbox':
- if ($args && isset($args['page'])) {
- return common_path($args['nickname'].'/'.$action.'?page=' . $args['page']);
- } else {
- return common_path($args['nickname'].'/'.$action);
- }
- case 'subscriptions':
- case 'subscribers':
- $nickname = $args['nickname'];
- unset($args['nickname']);
- if (isset($args['tag'])) {
- $tag = $args['tag'];
- unset($args['tag']);
- }
- $params = http_build_query($args);
- if ($params) {
- return common_path($nickname.'/'.$action . (($tag) ? '/' . $tag : '') . '?' . $params);
- } else {
- return common_path($nickname.'/'.$action . (($tag) ? '/' . $tag : ''));
- }
- case 'allrss':
- return common_path($args['nickname'].'/all/rss');
- case 'repliesrss':
- return common_path($args['nickname'].'/replies/rss');
- case 'userrss':
- if (isset($args['limit']))
- return common_path($args['nickname'].'/rss?limit=' . $args['limit']);
- return common_path($args['nickname'].'/rss');
- case 'showstream':
- if ($args && isset($args['page'])) {
- return common_path($args['nickname'].'?page=' . $args['page']);
- } else {
- return common_path($args['nickname']);
- }
-
- case 'usertimeline':
- return common_path("api/statuses/user_timeline/".$args['nickname'].".atom");
- case 'confirmaddress':
- return common_path('main/confirmaddress/'.$args['code']);
- case 'userbyid':
- return common_path('user/'.$args['id']);
- case 'recoverpassword':
- $path = 'main/recoverpassword';
- if ($args['code']) {
- $path .= '/' . $args['code'];
- }
- return common_path($path);
- case 'imsettings':
- return common_path('settings/im');
- case 'avatarsettings':
- return common_path('settings/avatar');
- case 'groupsearch':
- return common_path('search/group' . (($args) ? ('?' . http_build_query($args)) : ''));
- case 'peoplesearch':
- return common_path('search/people' . (($args) ? ('?' . http_build_query($args)) : ''));
- case 'noticesearch':
- return common_path('search/notice' . (($args) ? ('?' . http_build_query($args)) : ''));
- case 'noticesearchrss':
- return common_path('search/notice/rss' . (($args) ? ('?' . http_build_query($args)) : ''));
- case 'avatarbynickname':
- return common_path($args['nickname'].'/avatar/'.$args['size']);
- case 'tag':
- $path = 'tag/' . $args['tag'];
- unset($args['tag']);
- return common_path($path . (($args) ? ('?' . http_build_query($args)) : ''));
- case 'publictagcloud':
- return common_path('tags');
- case 'peopletag':
- $path = 'peopletag/' . $args['tag'];
- unset($args['tag']);
- return common_path($path . (($args) ? ('?' . http_build_query($args)) : ''));
- case 'tags':
- return common_path('tags' . (($args) ? ('?' . http_build_query($args)) : ''));
- case 'favor':
- return common_path('main/favor');
- case 'disfavor':
- return common_path('main/disfavor');
- case 'showfavorites':
- if ($args && isset($args['page'])) {
- return common_path($args['nickname'].'/favorites?page=' . $args['page']);
- } else {
- return common_path($args['nickname'].'/favorites');
- }
- case 'favoritesrss':
- return common_path($args['nickname'].'/favorites/rss');
- case 'showmessage':
- return common_path('message/' . $args['message']);
- case 'newmessage':
- return common_path('message/new' . (($args) ? ('?' . http_build_query($args)) : ''));
- case 'api':
- // XXX: do fancy URLs for all the API methods
- switch (strtolower($args['apiaction'])) {
- case 'statuses':
- switch (strtolower($args['method'])) {
- case 'user_timeline.rss':
- return common_path('api/statuses/user_timeline/'.$args['argument'].'.rss');
- case 'user_timeline.atom':
- return common_path('api/statuses/user_timeline/'.$args['argument'].'.atom');
- case 'user_timeline.json':
- return common_path('api/statuses/user_timeline/'.$args['argument'].'.json');
- case 'user_timeline.xml':
- return common_path('api/statuses/user_timeline/'.$args['argument'].'.xml');
- default: return common_simple_url($action, $args);
- }
- default: return common_simple_url($action, $args);
- }
- case 'sup':
- if ($args && isset($args['seconds'])) {
- return common_path('main/sup?seconds='.$args['seconds']);
- } else {
- return common_path('main/sup');
- }
- case 'newgroup':
- return common_path('group/new');
- case 'showgroup':
- return common_path('group/'.$args['nickname'] . (($args['page']) ? ('?page=' . $args['page']) : ''));
- case 'editgroup':
- return common_path('group/'.$args['nickname'].'/edit');
- case 'joingroup':
- return common_path('group/'.$args['nickname'].'/join');
- case 'leavegroup':
- return common_path('group/'.$args['nickname'].'/leave');
- case 'groupbyid':
- return common_path('group/'.$args['id'].'/id');
- case 'grouprss':
- return common_path('group/'.$args['nickname'].'/rss');
- case 'groupmembers':
- return common_path('group/'.$args['nickname'].'/members' . (($args['page']) ? ('?page=' . $args['page']) : ''));
- case 'grouplogo':
- return common_path('group/'.$args['nickname'].'/logo');
- case 'usergroups':
- $nickname = $args['nickname'];
- unset($args['nickname']);
- return common_path($nickname.'/groups' . (($args) ? ('?' . http_build_query($args)) : ''));
- case 'groups':
- return common_path('group' . (($args) ? ('?' . http_build_query($args)) : ''));
- default:
- return common_simple_url($action, $args);
- }
-}
-
-function common_simple_url($action, $args=null)
-{
- global $config;
- /* XXX: pretty URLs */
- $extra = '';
- if ($args) {
- foreach ($args as $key => $value) {
- $extra .= "&${key}=${value}";
- }
- }
- return common_path("index.php?action=${action}${extra}");
-}
-
function common_path($relative)
{
global $config;
@@ -1046,24 +821,6 @@ function common_redirect($url, $code=307)
function common_broadcast_notice($notice, $remote=false)
{
-
- // Check to see if notice should go to Twitter
- $flink = Foreign_link::getByUserID($notice->profile_id, 1); // 1 == Twitter
- if (($flink->noticesync & FOREIGN_NOTICE_SEND) == FOREIGN_NOTICE_SEND) {
-
- // If it's not a Twitter-style reply, or if the user WANTS to send replies...
-
- if (!preg_match('/^@[a-zA-Z0-9_]{1,15}\b/u', $notice->content) ||
- (($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) == FOREIGN_NOTICE_SEND_REPLY)) {
-
- $result = common_twitter_broadcast($notice, $flink);
-
- if (!$result) {
- common_debug('Unable to send notice: ' . $notice->id . ' to Twitter.', __FILE__);
- }
- }
- }
-
if (common_config('queue', 'enabled')) {
// Do it later!
return common_enqueue_notice($notice);
@@ -1072,73 +829,11 @@ function common_broadcast_notice($notice, $remote=false)
}
}
-function common_twitter_broadcast($notice, $flink)
-{
- global $config;
- $success = true;
- $fuser = $flink->getForeignUser();
- $twitter_user = $fuser->nickname;
- $twitter_password = $flink->credentials;
- $uri = 'http://www.twitter.com/statuses/update.json';
-
- // XXX: Hack to get around PHP cURL's use of @ being a a meta character
- $statustxt = preg_replace('/^@/', ' @', $notice->content);
-
- $options = array(
- CURLOPT_USERPWD => "$twitter_user:$twitter_password",
- CURLOPT_POST => true,
- CURLOPT_POSTFIELDS => array(
- 'status' => $statustxt,
- 'source' => $config['integration']['source']
- ),
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_FAILONERROR => true,
- CURLOPT_HEADER => false,
- CURLOPT_FOLLOWLOCATION => true,
- CURLOPT_USERAGENT => "Laconica",
- CURLOPT_CONNECTTIMEOUT => 120, // XXX: Scary!!!! How long should this be?
- CURLOPT_TIMEOUT => 120,
-
- # Twitter is strict about accepting invalid "Expect" headers
- CURLOPT_HTTPHEADER => array('Expect:')
- );
-
- $ch = curl_init($uri);
- curl_setopt_array($ch, $options);
- $data = curl_exec($ch);
- $errmsg = curl_error($ch);
-
- if ($errmsg) {
- common_debug("cURL error: $errmsg - trying to send notice for $twitter_user.",
- __FILE__);
- $success = false;
- }
-
- curl_close($ch);
-
- if (!$data) {
- common_debug("No data returned by Twitter's API trying to send update for $twitter_user",
- __FILE__);
- $success = false;
- }
-
- // Twitter should return a status
- $status = json_decode($data);
-
- if (!$status->id) {
- common_debug("Unexpected data returned by Twitter API trying to send update for $twitter_user",
- __FILE__);
- $success = false;
- }
-
- return $success;
-}
-
// Stick the notice on the queue
function common_enqueue_notice($notice)
{
- foreach (array('jabber', 'omb', 'sms', 'public') as $transport) {
+ foreach (array('jabber', 'omb', 'sms', 'public', 'twitter', 'facebook') as $transport) {
$qi = new Queue_item();
$qi->notice_id = $notice->id;
$qi->transport = $transport;
@@ -1185,6 +880,15 @@ function common_real_broadcast($notice, $remote=false)
common_log(LOG_ERR, 'Error in public broadcast for notice ' . $notice->id);
}
}
+ if ($success) {
+ $success = broadcast_twitter($notice);
+ if (!$success) {
+ common_log(LOG_ERR, 'Error in Twitter broadcast for notice ' . $notice->id);
+ }
+ }
+
+ // XXX: Do a real-time FB broadcast here?
+
// XXX: broadcast notices to other IM
return $success;
}
diff --git a/lib/xmlstringer.php b/lib/xmlstringer.php
new file mode 100644
index 000000000..951b13b67
--- /dev/null
+++ b/lib/xmlstringer.php
@@ -0,0 +1,68 @@
+<?php
+/**
+ * Laconica, the distributed open-source microblogging tool
+ *
+ * Generator for in-memory XML
+ *
+ * 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 Output
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @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);
+}
+
+/**
+ * Create in-memory XML
+ *
+ * @category Output
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ * @see Action
+ * @see HTMLOutputter
+ */
+
+class XMLStringer extends XMLOutputter
+{
+ function __construct($indent=false)
+ {
+ $this->xw = new XMLWriter();
+ $this->xw->openMemory();
+ $this->xw->setIndent($indent);
+ }
+
+ function getString()
+ {
+ return $this->xw->outputMemory();
+ }
+
+ // utility for quickly creating XML-strings
+
+ static function estring($tag, $attrs=null, $content=null)
+ {
+ $xs = new XMLStringer();
+ $xs->element($tag, $attrs, $content);
+ return $xs->getString();
+ }
+} \ No newline at end of file
diff --git a/plugins/GoogleAnalyticsPlugin.php b/plugins/GoogleAnalyticsPlugin.php
new file mode 100644
index 000000000..1ecbb664e
--- /dev/null
+++ b/plugins/GoogleAnalyticsPlugin.php
@@ -0,0 +1,77 @@
+<?php
+/**
+ * Laconica, the distributed open-source microblogging tool
+ *
+ * Plugin to use Google Analytics
+ *
+ * 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 Plugin
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @copyright 2008 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);
+}
+
+/**
+ * Plugin to use Google Analytics
+ *
+ * This plugin will spoot out the correct JavaScript spell to invoke Google Analytics on a page.
+ *
+ * Note that Google Analytics is not compatible with the Franklin Street Statement; consider using
+ * Piwik (http://www.piwik.org/) instead!
+ *
+ * @category Plugin
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ *
+ * @see Event
+ */
+
+class GoogleAnalyticsPlugin extends Plugin
+{
+ var $code = null;
+
+ function __construct($code=null)
+ {
+ $this->code = $code;
+ parent::__construct();
+ }
+
+ function onEndShowScripts($action)
+ {
+ $js1 = 'var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");'.
+ 'document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));';
+ $js2 = sprintf('try{'.
+ 'var pageTracker = _gat._getTracker("%s");'.
+ 'pageTracker._trackPageview();'.
+ '} catch(err) {}',
+ $this->code);
+ $action->elementStart('script', array('type' => 'text/javascript'));
+ $action->raw($js1);
+ $action->elementEnd('script');
+ $action->elementStart('script', array('type' => 'text/javascript'));
+ $action->raw($js2);
+ $action->elementEnd('script');
+ }
+}
diff --git a/scripts/startdaemons.sh b/scripts/startdaemons.sh
index 685bd938f..a3256966d 100755
--- a/scripts/startdaemons.sh
+++ b/scripts/startdaemons.sh
@@ -23,7 +23,8 @@
DIR=`dirname $0`
for f in xmppdaemon.php jabberqueuehandler.php publicqueuehandler.php \
- xmppconfirmhandler.php smsqueuehandler.php ombqueuehandler.php; do
+ xmppconfirmhandler.php smsqueuehandler.php ombqueuehandler.php \
+ twitterqueuehandler.php facebookqueuehandler.php; do
echo -n "Starting $f...";
php $DIR/$f
diff --git a/scripts/stopdaemons.sh b/scripts/stopdaemons.sh
index 08e1d4714..fd4406d41 100755
--- a/scripts/stopdaemons.sh
+++ b/scripts/stopdaemons.sh
@@ -24,7 +24,7 @@ SDIR=`dirname $0`
DIR=`php $SDIR/getpiddir.php`
for f in jabberhandler ombhandler publichandler smshandler \
- xmppconfirmhandler xmppdaemon; do
+ xmppconfirmhandler xmppdaemon twitterhandler facebookhandler ; do
FILES="$DIR/$f.*.pid"
for ff in "$FILES" ; do
diff --git a/scripts/twitterqueuehandler.php b/scripts/twitterqueuehandler.php
new file mode 100755
index 000000000..7da4f1e20
--- /dev/null
+++ b/scripts/twitterqueuehandler.php
@@ -0,0 +1,71 @@
+#!/usr/bin/env php
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, Inc.
+ *
+ * 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/>.
+ */
+
+# Abort if called from a web server
+if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
+ print "This script must be run from the command line\n";
+ exit();
+}
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
+define('LACONICA', true);
+
+require_once(INSTALLDIR . '/lib/common.php');
+require_once(INSTALLDIR . '/lib/twitter.php');
+require_once(INSTALLDIR . '/lib/queuehandler.php');
+
+set_error_handler('common_error_handler');
+
+class TwitterQueueHandler extends QueueHandler
+{
+
+ function transport()
+ {
+ return 'twitter';
+ }
+
+ function start()
+ {
+ $this->log(LOG_INFO, "INITIALIZE");
+ return true;
+ }
+
+ function handle_notice($notice)
+ {
+ return broadcast_twitter($notice);
+ }
+
+ function finish()
+ {
+ }
+
+}
+
+ini_set("max_execution_time", "0");
+ini_set("max_input_time", "0");
+set_time_limit(0);
+
+mb_internal_encoding('UTF-8');
+
+$id = ($argc > 1) ? $argv[1] : null;
+
+$handler = new TwitterQueueHandler($id);
+
+$handler->runOnce();
diff --git a/scripts/update_facebook.php b/scripts/update_facebook.php
deleted file mode 100755
index 60e10417f..000000000
--- a/scripts/update_facebook.php
+++ /dev/null
@@ -1,141 +0,0 @@
-#!/usr/bin/env php
-<?php
-/*
- * Laconica - a distributed open-source microblogging tool
- * Copyright (C) 2008, Controlez-Vous, Inc.
- *
- * 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/>.
- */
-
-# Abort if called from a web server
-if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
- print "This script must be run from the command line\n";
- exit();
-}
-
-define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
-define('LACONICA', true);
-
-require_once INSTALLDIR . '/lib/common.php';
-require_once INSTALLDIR . '/lib/facebookutil.php';
-
-// For storing the last run date-time
-$last_updated_file = INSTALLDIR . '/scripts/facebook_last_updated';
-
-// Lock file name
-$lock_file = INSTALLDIR . '/scripts/update_facebook.lock';
-
-// Make sure only one copy of the script is running at a time
-$lock_file = @fopen($lock_file, "w+");
-if (!flock( $lock_file, LOCK_EX | LOCK_NB, &$wouldblock) || $wouldblock) {
- die("Can't open lock file. Script already running?\n");
-}
-
-$facebook = getFacebook();
-$current_time = time();
-$since = getLastUpdated();
-updateLastUpdated($current_time);
-$notice = getFacebookNotices($since);
-$cnt = 0;
-
-while($notice->fetch()) {
-
- $flink = Foreign_link::getByUserID($notice->profile_id, FACEBOOK_SERVICE);
- $user = $flink->getUser();
- $fbuid = $flink->foreign_id;
-
- if (!userCanUpdate($fbuid)) {
- continue;
- }
-
- $prefix = $facebook->api_client->data_getUserPreference(FACEBOOK_NOTICE_PREFIX, $fbuid);
- $content = "$prefix $notice->content";
-
- if (($flink->noticesync & FOREIGN_NOTICE_SEND) == FOREIGN_NOTICE_SEND) {
-
- // If it's not a reply, or if the user WANTS to send replies...
- if (!preg_match('/@[a-zA-Z0-9_]{1,15}\b/u', $content) ||
- (($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) == FOREIGN_NOTICE_SEND_REPLY)) {
-
- // Avoid a Loop
- if ($notice->source != 'Facebook') {
-
- try {
- $facebook->api_client->users_setStatus($content,
- $fbuid, false, true);
- updateProfileBox($facebook, $flink, $notice);
- $cnt++;
- } catch(FacebookRestClientException $e) {
- print "Couldn't sent notice $notice->id!\n";
- print $e->getMessage();
-
- // Remove flink?
- }
- }
- }
- }
-}
-
-if ($cnt > 0) {
- print date('r', $current_time) .
- ": Found $cnt new notices for Facebook since last run at " .
- date('r', $since) . "\n";
-}
-
-fclose($lock_file);
-exit(0);
-
-
-function userCanUpdate($fbuid) {
-
- global $facebook;
-
- $result = false;
-
- try {
- $result = $facebook->api_client->users_hasAppPermission('status_update', $fbuid);
- } catch(FacebookRestClientException $e){
- print_r($e);
- }
-
- return $result;
-}
-
-function getLastUpdated(){
- global $last_updated_file, $current_time;
- $last = $current_time;
-
- if (file_exists($last_updated_file) &&
- ($file = fopen($last_updated_file, 'r'))) {
- $last = fgets($file);
- } else {
- print "$last_updated_file doesn't exit. Trying to create it...\n";
- $file = fopen($last_updated_file, 'w+') or
- die("Can't open $last_updated_file for writing!\n");
- print 'Success. Using current time (' . date('r', $last) .
- ") to look for new notices.\n";
- }
-
- fclose($file);
- return $last;
-}
-
-function updateLastUpdated($time){
- global $last_updated_file;
- $file = fopen($last_updated_file, 'w') or
- die("Can't open $last_updated_file for writing!");
- fwrite($file, $time);
- fclose($file);
-}
-
diff --git a/theme/base/css/display.css b/theme/base/css/display.css
index 3b72d00ce..1ac63927d 100644
--- a/theme/base/css/display.css
+++ b/theme/base/css/display.css
@@ -22,7 +22,7 @@ line-height:1.65;
position:relative;
}
h1,h2,h3,h4,h5,h6 {
-text-transform:uppercase;
+text-transform:capitalize;
margin-bottom:7px;
overflow:hidden;
}
@@ -43,7 +43,6 @@ font-weight:bold;
legend {
font-weight:bold;
font-size:1.3em;
-text-transform:uppercase;
}
input, textarea, select, option {
padding:4px;