From a459313e109dca9979a5beab50da5782e7e544f4 Mon Sep 17 00:00:00 2001 From: Jeffery To Date: Tue, 11 Aug 2009 20:29:45 +0800 Subject: Updated Jcrop to 0.9.8 (avatar cropping wasn't working in IE7 with 0.9.5) --- actions/avatarsettings.php | 2 +- actions/grouplogo.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'actions') diff --git a/actions/avatarsettings.php b/actions/avatarsettings.php index 38e3103f4..c45514ff6 100644 --- a/actions/avatarsettings.php +++ b/actions/avatarsettings.php @@ -396,7 +396,7 @@ class AvatarsettingsAction extends AccountSettingsAction parent::showScripts(); if ($this->mode == 'crop') { - $this->script('js/jcrop/jquery.Jcrop.pack.js'); + $this->script('js/jcrop/jquery.Jcrop.min.js'); $this->script('js/jcrop/jquery.Jcrop.go.js'); } } diff --git a/actions/grouplogo.php b/actions/grouplogo.php index 5edb10cf8..87c68e2a2 100644 --- a/actions/grouplogo.php +++ b/actions/grouplogo.php @@ -442,7 +442,7 @@ class GrouplogoAction extends GroupDesignAction parent::showScripts(); if ($this->mode == 'crop') { - $this->script('js/jcrop/jquery.Jcrop.pack.js'); + $this->script('js/jcrop/jquery.Jcrop.min.js'); $this->script('js/jcrop/jquery.Jcrop.go.js'); } } -- cgit v1.2.3-54-g00ecf From 7eda7295e47688fd582338ef6c83e6b6267f202f Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Tue, 11 Aug 2009 21:15:42 -0400 Subject: oEmbed provider does not use the twitter api library classes any more --- actions/attachment.php | 12 +-- actions/oembed.php | 206 ++++++++++++++++++++++++++++++++++++++++++++++ actions/shownotice.php | 12 +-- actions/twitapioembed.php | 173 -------------------------------------- lib/router.php | 11 +-- 5 files changed, 220 insertions(+), 194 deletions(-) create mode 100644 actions/oembed.php delete mode 100644 actions/twitapioembed.php (limited to 'actions') diff --git a/actions/attachment.php b/actions/attachment.php index c6a5d0d52..f42906fd8 100644 --- a/actions/attachment.php +++ b/actions/attachment.php @@ -103,18 +103,18 @@ class AttachmentAction extends Action $this->element('link',array('rel'=>'alternate', 'type'=>'application/json+oembed', 'href'=>common_local_url( - 'api', - array('apiaction'=>'oembed','method'=>'oembed.json'), - array('url'=> + 'oembed', + array(), + array('format'=>'json', 'url'=> common_local_url('attachment', array('attachment' => $this->attachment->id)))), 'title'=>'oEmbed'),null); $this->element('link',array('rel'=>'alternate', 'type'=>'text/xml+oembed', 'href'=>common_local_url( - 'api', - array('apiaction'=>'oembed','method'=>'oembed.xml'), - array('url'=> + 'oembed', + array(), + array('format'=>'xml','url'=> common_local_url('attachment', array('attachment' => $this->attachment->id)))), 'title'=>'oEmbed'),null); diff --git a/actions/oembed.php b/actions/oembed.php new file mode 100644 index 000000000..3e46a7262 --- /dev/null +++ b/actions/oembed.php @@ -0,0 +1,206 @@ +. + * + * @category Twitter + * @package Laconica + * @author Evan Prodromou + * @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); +} + +/** + * Oembed provider implementation + * + * This class handles all /main/oembed(.xml|.json)/ requests. + * + * @category oEmbed + * @package Laconica + * @author Craig Andrews + * @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/ + */ + +class OembedAction extends Action +{ + + function handle($args) + { + common_debug("in oembed api action"); + + $url = $args['url']; + if( substr(strtolower($url),0,strlen(common_root_url())) == strtolower(common_root_url()) ){ + $path = substr($url,strlen(common_root_url())); + + $r = Router::get(); + + $proxy_args = $r->map($path); + + if (!$proxy_args) { + $this->serverError(_("$path not found"), 404); + } + $oembed=array(); + $oembed['version']='1.0'; + $oembed['provider_name']=common_config('site', 'name'); + $oembed['provider_url']=common_root_url(); + switch($proxy_args['action']){ + case 'shownotice': + $oembed['type']='link'; + $id = $proxy_args['notice']; + $notice = Notice::staticGet($id); + if(empty($notice)){ + $this->serverError(_("notice $id not found"), 404); + } + $profile = $notice->getProfile(); + if (empty($profile)) { + $this->serverError(_('Notice has no profile'), 500); + } + if (!empty($profile->fullname)) { + $authorname = $profile->fullname . ' (' . $profile->nickname . ')'; + } else { + $authorname = $profile->nickname; + } + $oembed['title'] = sprintf(_('%1$s\'s status on %2$s'), + $authorname, + common_exact_date($notice->created)); + $oembed['author_name']=$authorname; + $oembed['author_url']=$profile->profileurl; + $oembed['url']=($notice->url?$notice->url:$notice->uri); + $oembed['html']=$notice->rendered; + break; + case 'attachment': + $id = $proxy_args['attachment']; + $attachment = File::staticGet($id); + if(empty($attachment)){ + $this->serverError(_("attachment $id not found"), 404); + } + if(empty($attachment->filename) && $file_oembed = File_oembed::staticGet('file_id', $attachment->id)){ + // Proxy the existing oembed information + $oembed['type']=$file_oembed->type; + $oembed['provider']=$file_oembed->provider; + $oembed['provider_url']=$file_oembed->provider_url; + $oembed['width']=$file_oembed->width; + $oembed['height']=$file_oembed->height; + $oembed['html']=$file_oembed->html; + $oembed['title']=$file_oembed->title; + $oembed['author_name']=$file_oembed->author_name; + $oembed['author_url']=$file_oembed->author_url; + $oembed['url']=$file_oembed->url; + }else if(substr($attachment->mimetype,0,strlen('image/'))=='image/'){ + $oembed['type']='photo'; + //TODO set width and height + //$oembed['width']= + //$oembed['height']= + $oembed['url']=$attachment->url; + }else{ + $oembed['type']='link'; + $oembed['url']=common_local_url('attachment', + array('attachment' => $attachment->id)); + } + if($attachment->title) $oembed['title']=$attachment->title; + break; + default: + $this->serverError(_("$path not supported for oembed requests"), 501); + } + switch($args['format']){ + case 'xml': + $this->init_document('xml'); + $this->elementStart('oembed'); + $this->element('version',null,$oembed['version']); + $this->element('type',null,$oembed['type']); + if($oembed['provider_name']) $this->element('provider_name',null,$oembed['provider_name']); + if($oembed['provider_url']) $this->element('provider_url',null,$oembed['provider_url']); + if($oembed['title']) $this->element('title',null,$oembed['title']); + if($oembed['author_name']) $this->element('author_name',null,$oembed['author_name']); + if($oembed['author_url']) $this->element('author_url',null,$oembed['author_url']); + if($oembed['url']) $this->element('url',null,$oembed['url']); + if($oembed['html']) $this->element('html',null,$oembed['html']); + if($oembed['width']) $this->element('width',null,$oembed['width']); + if($oembed['height']) $this->element('height',null,$oembed['height']); + if($oembed['cache_age']) $this->element('cache_age',null,$oembed['cache_age']); + if($oembed['thumbnail_url']) $this->element('thumbnail_url',null,$oembed['thumbnail_url']); + if($oembed['thumbnail_width']) $this->element('thumbnail_width',null,$oembed['thumbnail_width']); + if($oembed['thumbnail_height']) $this->element('thumbnail_height',null,$oembed['thumbnail_height']); + + $this->elementEnd('oembed'); + $this->end_document('xml'); + break; + case 'json': case '': + $this->init_document('json'); + print(json_encode($oembed)); + $this->end_document('json'); + break; + default: + $this->serverError(_('content type ' . $apidata['content-type'] . ' not supported'), 501); + } + }else{ + $this->serverError(_('Only ' . common_root_url() . ' urls over plain http please'), 404); + } + } + + function init_document($type) + { + switch ($type) { + case 'xml': + header('Content-Type: application/xml; charset=utf-8'); + $this->startXML(); + break; + case 'json': + header('Content-Type: application/json; charset=utf-8'); + + // Check for JSONP callback + $callback = $this->arg('callback'); + if ($callback) { + print $callback . '('; + } + break; + default: + $this->serverError(_('Not a supported data format.'), 501); + break; + } + } + + function end_document($type='xml') + { + switch ($type) { + case 'xml': + $this->endXML(); + break; + case 'json': + // Check for JSONP callback + $callback = $this->arg('callback'); + if ($callback) { + print ')'; + } + break; + default: + $this->serverError(_('Not a supported data format.'), 501); + break; + } + return; + } + +} diff --git a/actions/shownotice.php b/actions/shownotice.php index 4b179bc72..8f2ffd6b9 100644 --- a/actions/shownotice.php +++ b/actions/shownotice.php @@ -278,16 +278,16 @@ class ShownoticeAction extends OwnerDesignAction $this->element('link',array('rel'=>'alternate', 'type'=>'application/json+oembed', 'href'=>common_local_url( - 'api', - array('apiaction'=>'oembed','method'=>'oembed.json'), - array('url'=>$this->notice->uri)), + 'oembed', + array(), + array('format'=>'json','url'=>$this->notice->uri)), 'title'=>'oEmbed'),null); $this->element('link',array('rel'=>'alternate', 'type'=>'text/xml+oembed', 'href'=>common_local_url( - 'api', - array('apiaction'=>'oembed','method'=>'oembed.xml'), - array('url'=>$this->notice->uri)), + 'oembed', + array(), + array('format'=>'xml','url'=>$this->notice->uri)), 'title'=>'oEmbed'),null); } } diff --git a/actions/twitapioembed.php b/actions/twitapioembed.php deleted file mode 100644 index 3019e5878..000000000 --- a/actions/twitapioembed.php +++ /dev/null @@ -1,173 +0,0 @@ -. - * - * @category Twitter - * @package Laconica - * @author Evan Prodromou - * @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); -} - -require_once INSTALLDIR.'/lib/twitterapi.php'; - -/** - * Oembed provider implementation - * - * This class handles all /main/oembed(.xml|.json)/ requests. - * - * @category oEmbed - * @package Laconica - * @author Craig Andrews - * @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/ - */ - -class TwitapioembedAction extends TwitterapiAction -{ - - function oembed($args, $apidata) - { - parent::handle($args); - - common_debug("in oembed api action"); - - $this->auth_user = $apidata['user']; - - $url = $args['url']; - if( substr(strtolower($url),0,strlen(common_root_url())) == strtolower(common_root_url()) ){ - $path = substr($url,strlen(common_root_url())); - - $r = Router::get(); - - $proxy_args = $r->map($path); - - if (!$proxy_args) { - $this->serverError(_("$path not found"), 404); - } - $oembed=array(); - $oembed['version']='1.0'; - $oembed['provider_name']=common_config('site', 'name'); - $oembed['provider_url']=common_root_url(); - switch($proxy_args['action']){ - case 'shownotice': - $oembed['type']='link'; - $id = $proxy_args['notice']; - $notice = Notice::staticGet($id); - if(empty($notice)){ - $this->serverError(_("notice $id not found"), 404); - } - $profile = $notice->getProfile(); - if (empty($profile)) { - $this->serverError(_('Notice has no profile'), 500); - } - if (!empty($profile->fullname)) { - $authorname = $profile->fullname . ' (' . $profile->nickname . ')'; - } else { - $authorname = $profile->nickname; - } - $oembed['title'] = sprintf(_('%1$s\'s status on %2$s'), - $authorname, - common_exact_date($notice->created)); - $oembed['author_name']=$authorname; - $oembed['author_url']=$profile->profileurl; - $oembed['url']=($notice->url?$notice->url:$notice->uri); - $oembed['html']=$notice->rendered; - break; - case 'attachment': - $id = $proxy_args['attachment']; - $attachment = File::staticGet($id); - if(empty($attachment)){ - $this->serverError(_("attachment $id not found"), 404); - } - if(empty($attachment->filename) && $file_oembed = File_oembed::staticGet('file_id', $attachment->id)){ - // Proxy the existing oembed information - $oembed['type']=$file_oembed->type; - $oembed['provider']=$file_oembed->provider; - $oembed['provider_url']=$file_oembed->provider_url; - $oembed['width']=$file_oembed->width; - $oembed['height']=$file_oembed->height; - $oembed['html']=$file_oembed->html; - $oembed['title']=$file_oembed->title; - $oembed['author_name']=$file_oembed->author_name; - $oembed['author_url']=$file_oembed->author_url; - $oembed['url']=$file_oembed->url; - }else if(substr($attachment->mimetype,0,strlen('image/'))=='image/'){ - $oembed['type']='photo'; - //TODO set width and height - //$oembed['width']= - //$oembed['height']= - $oembed['url']=$attachment->url; - }else{ - $oembed['type']='link'; - $oembed['url']=common_local_url('attachment', - array('attachment' => $attachment->id)); - } - if($attachment->title) $oembed['title']=$attachment->title; - break; - default: - $this->serverError(_("$path not supported for oembed requests"), 501); - } - - switch($apidata['content-type']){ - case 'xml': - $this->init_document('xml'); - $this->elementStart('oembed'); - $this->element('version',null,$oembed['version']); - $this->element('type',null,$oembed['type']); - if($oembed['provider_name']) $this->element('provider_name',null,$oembed['provider_name']); - if($oembed['provider_url']) $this->element('provider_url',null,$oembed['provider_url']); - if($oembed['title']) $this->element('title',null,$oembed['title']); - if($oembed['author_name']) $this->element('author_name',null,$oembed['author_name']); - if($oembed['author_url']) $this->element('author_url',null,$oembed['author_url']); - if($oembed['url']) $this->element('url',null,$oembed['url']); - if($oembed['html']) $this->element('html',null,$oembed['html']); - if($oembed['width']) $this->element('width',null,$oembed['width']); - if($oembed['height']) $this->element('height',null,$oembed['height']); - if($oembed['cache_age']) $this->element('cache_age',null,$oembed['cache_age']); - if($oembed['thumbnail_url']) $this->element('thumbnail_url',null,$oembed['thumbnail_url']); - if($oembed['thumbnail_width']) $this->element('thumbnail_width',null,$oembed['thumbnail_width']); - if($oembed['thumbnail_height']) $this->element('thumbnail_height',null,$oembed['thumbnail_height']); - - - $this->elementEnd('oembed'); - $this->end_document('xml'); - break; - case 'json': - $this->init_document('json'); - print(json_encode($oembed)); - $this->end_document('json'); - break; - default: - $this->serverError(_('content type ' . $apidata['content-type'] . ' not supported'), 501); - } - - }else{ - $this->serverError(_('Only ' . common_root_url() . ' urls over plain http please'), 404); - } - } -} - diff --git a/lib/router.php b/lib/router.php index f03cfcf6d..04c6dd414 100644 --- a/lib/router.php +++ b/lib/router.php @@ -117,15 +117,8 @@ class Router $m->connect('main/tagother/:id', array('action' => 'tagother')); - $m->connect('main/oembed.xml', - array('action' => 'api', - 'method' => 'oembed.xml', - 'apiaction' => 'oembed')); - - $m->connect('main/oembed.json', - array('action' => 'api', - 'method' => 'oembed.json', - 'apiaction' => 'oembed')); + $m->connect('main/oembed', + array('action' => 'oembed')); // these take a code -- cgit v1.2.3-54-g00ecf From 355effe6315ab7927a54f44fc9ce903085769b5f Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Tue, 11 Aug 2009 22:09:02 -0400 Subject: Return a 404 when a page is request that has no notices --- actions/public.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'actions') diff --git a/actions/public.php b/actions/public.php index dd128925b..ca352faf8 100644 --- a/actions/public.php +++ b/actions/public.php @@ -59,6 +59,7 @@ class PublicAction extends Action */ var $page = null; + var $notice; function isReadOnly($args) { @@ -84,6 +85,18 @@ class PublicAction extends Action common_set_returnto($this->selfUrl()); + $this->notice = Notice::publicStream(($this->page-1)*NOTICES_PER_PAGE, + NOTICES_PER_PAGE + 1); + + if (!$this->notice) { + $this->serverError(_('Could not retrieve public stream.')); + return; + } + + if($this->page > 0 && $this->notice->N == 0){ + $this->serverError(_('No such page'),$code=404); + } + return true; } @@ -204,15 +217,7 @@ class PublicAction extends Action function showContent() { - $notice = Notice::publicStream(($this->page-1)*NOTICES_PER_PAGE, - NOTICES_PER_PAGE + 1); - - if (!$notice) { - $this->serverError(_('Could not retrieve public stream.')); - return; - } - - $nl = new NoticeList($notice, $this); + $nl = new NoticeList($this->notice, $this); $cnt = $nl->show(); -- cgit v1.2.3-54-g00ecf From c29892c87573e0575b9a4a13210c562e08411148 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Tue, 11 Aug 2009 22:48:35 -0400 Subject: Return a 404 when a page is request that has no notices --- actions/all.php | 30 +++++++++++++++++++++--------- actions/public.php | 2 +- actions/replies.php | 13 +++++++++---- actions/showfavorites.php | 44 ++++++++++++++++++++++++-------------------- actions/tag.php | 13 ++++++++++--- 5 files changed, 65 insertions(+), 37 deletions(-) (limited to 'actions') diff --git a/actions/all.php b/actions/all.php index 5db09a0e6..38aee65b6 100644 --- a/actions/all.php +++ b/actions/all.php @@ -25,11 +25,31 @@ require_once INSTALLDIR.'/lib/feedlist.php'; class AllAction extends ProfileAction { + var $notice; + function isReadOnly($args) { return true; } + function prepare($args) + { + parent::prepare($args); + $cur = common_current_user(); + + if (!empty($cur) && $cur->id == $this->user->id) { + $this->notice = $this->user->noticeInbox(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); + } else { + $this->notice = $this->user->noticesWithFriends(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); + } + + if($this->page > 1 && $this->notice->N == 0){ + $this->serverError(_('No such page'),$code=404); + } + + return true; + } + function handle($args) { parent::handle($args); @@ -100,15 +120,7 @@ class AllAction extends ProfileAction function showContent() { - $cur = common_current_user(); - - if (!empty($cur) && $cur->id == $this->user->id) { - $notice = $this->user->noticeInbox(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); - } else { - $notice = $this->user->noticesWithFriends(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); - } - - $nl = new NoticeList($notice, $this); + $nl = new NoticeList($this->notice, $this); $cnt = $nl->show(); diff --git a/actions/public.php b/actions/public.php index ca352faf8..2cf2e96e6 100644 --- a/actions/public.php +++ b/actions/public.php @@ -93,7 +93,7 @@ class PublicAction extends Action return; } - if($this->page > 0 && $this->notice->N == 0){ + if($this->page > 1 && $this->notice->N == 0){ $this->serverError(_('No such page'),$code=404); } diff --git a/actions/replies.php b/actions/replies.php index f14383d33..fcfc3a272 100644 --- a/actions/replies.php +++ b/actions/replies.php @@ -48,6 +48,7 @@ require_once INSTALLDIR.'/lib/feedlist.php'; class RepliesAction extends OwnerDesignAction { var $page = null; + var $notice; /** * Prepare the object @@ -84,6 +85,13 @@ class RepliesAction extends OwnerDesignAction common_set_returnto($this->selfUrl()); + $this->notice = $this->user->getReplies(($this->page-1) * NOTICES_PER_PAGE, + NOTICES_PER_PAGE + 1); + + if($this->page > 1 && $this->notice->N == 0){ + $this->serverError(_('No such page'),$code=404); + } + return true; } @@ -159,10 +167,7 @@ class RepliesAction extends OwnerDesignAction function showContent() { - $notice = $this->user->getReplies(($this->page-1) * NOTICES_PER_PAGE, - NOTICES_PER_PAGE + 1); - - $nl = new NoticeList($notice, $this); + $nl = new NoticeList($this->notice, $this); $cnt = $nl->show(); if (0 === $cnt) { diff --git a/actions/showfavorites.php b/actions/showfavorites.php index 9f549baf2..91287cc96 100644 --- a/actions/showfavorites.php +++ b/actions/showfavorites.php @@ -114,6 +114,29 @@ class ShowfavoritesAction extends OwnerDesignAction common_set_returnto($this->selfUrl()); + $cur = common_current_user(); + + if (!empty($cur) && $cur->id == $this->user->id) { + + // Show imported/gateway notices as well as local if + // the user is looking at his own favorites + + $this->notice = $this->user->favoriteNotices(($this->page-1)*NOTICES_PER_PAGE, + NOTICES_PER_PAGE + 1, true); + } else { + $this->notice = $this->user->favoriteNotices(($this->page-1)*NOTICES_PER_PAGE, + NOTICES_PER_PAGE + 1, false); + } + + if (empty($this->notice)) { + $this->serverError(_('Could not retrieve favorite notices.')); + return; + } + + if($this->page > 1 && $this->notice->N == 0){ + $this->serverError(_('No such page'),$code=404); + } + return true; } @@ -193,26 +216,7 @@ class ShowfavoritesAction extends OwnerDesignAction function showContent() { - $cur = common_current_user(); - - if (!empty($cur) && $cur->id == $this->user->id) { - - // Show imported/gateway notices as well as local if - // the user is looking at his own favorites - - $notice = $this->user->favoriteNotices(($this->page-1)*NOTICES_PER_PAGE, - NOTICES_PER_PAGE + 1, true); - } else { - $notice = $this->user->favoriteNotices(($this->page-1)*NOTICES_PER_PAGE, - NOTICES_PER_PAGE + 1, false); - } - - if (empty($notice)) { - $this->serverError(_('Could not retrieve favorite notices.')); - return; - } - - $nl = new NoticeList($notice, $this); + $nl = new NoticeList($this->notice, $this); $cnt = $nl->show(); if (0 == $cnt) { diff --git a/actions/tag.php b/actions/tag.php index 020399d9e..771eb2861 100644 --- a/actions/tag.php +++ b/actions/tag.php @@ -21,6 +21,9 @@ if (!defined('LACONICA')) { exit(1); } class TagAction extends Action { + + var $notice; + function prepare($args) { parent::prepare($args); @@ -42,6 +45,12 @@ class TagAction extends Action common_set_returnto($this->selfUrl()); + $this->notice = Notice_tag::getStream($this->tag, (($this->page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1); + + if($this->page > 1 && $this->notice->N == 0){ + $this->serverError(_('No such page'),$code=404); + } + return true; } @@ -94,9 +103,7 @@ class TagAction extends Action function showContent() { - $notice = Notice_tag::getStream($this->tag, (($this->page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1); - - $nl = new NoticeList($notice, $this); + $nl = new NoticeList($this->notice, $this); $cnt = $nl->show(); -- cgit v1.2.3-54-g00ecf