From a88770a26951e0fdbf00c18a2e25bf4e2dd60154 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 30 Dec 2008 15:25:13 -0500 Subject: add laconica-specific methods to htaccess.sample darcs-hash:20081230202513-84dde-47ab363eae62e1b9fc9280e579d348520c1233cc.gz --- htaccess.sample | 3 +++ 1 file changed, 3 insertions(+) (limited to 'htaccess.sample') diff --git a/htaccess.sample b/htaccess.sample index bd29d318f..e348635a8 100644 --- a/htaccess.sample +++ b/htaccess.sample @@ -143,6 +143,9 @@ RewriteRule ^api/notifications/leave/(.*)$ index.php?action=api&apiaction=notifi 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] Order allow,deny -- cgit v1.2.3-54-g00ecf From 1b7b58192bd34f7d34ae6712ac1b09130bca6bd0 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 16 Jan 2009 22:29:13 +0000 Subject: Split avatar upload to its own page --- actions/avatarsettings.php | 306 +++++++++++++++++++++++++++++++++++++++++++++ htaccess.sample | 3 +- 2 files changed, 308 insertions(+), 1 deletion(-) create mode 100644 actions/avatarsettings.php (limited to 'htaccess.sample') diff --git a/actions/avatarsettings.php b/actions/avatarsettings.php new file mode 100644 index 000000000..de5473d9f --- /dev/null +++ b/actions/avatarsettings.php @@ -0,0 +1,306 @@ +. + * + * @category Settings + * @package Laconica + * @author Evan Prodromou + * @author Zach Copley + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/settingsaction.php'; + +/** + * Upload an avatar + * + * We use jQuery to crop the image after upload. + * + * @category Settings + * @package Laconica + * @author Evan Prodromou + * @author Zach Copley + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class AvatarsettingsAction extends SettingsAction +{ + /** + * Title of the page + * + * @return string Title of the page + */ + + function title() + { + return _('Avatar'); + } + + /** + * Instructions for use + * + * @return instructions for use + */ + + function getInstructions() + { + return _('Set your personal avatar.'); + } + + /** + * Content area of the page + * + * Shows a form for uploading an avatar. + * + * @return void + */ + + function showContent() + { + $user = common_current_user(); + + $profile = $user->getProfile(); + + if (!$profile) { + common_log_db_error($user, 'SELECT', __FILE__); + $this->serverError(_('User without matching profile')); + return; + } + + $original = $profile->getOriginalAvatar(); + + $this->elementStart('form', array('enctype' => 'multipart/form-data', + 'method' => 'POST', + 'id' => 'avatar', + 'action' => + common_local_url('avatarsettings'))); + $this->hidden('token', common_session_token()); + + if ($original) { + $this->elementStart('div', + array('id' => 'avatar_original', + 'class' => 'avatar_view')); + $this->element('h3', null, _("Original:")); + $this->elementStart('div', array('id'=>'avatar_original_view')); + $this->element('img', array('src' => $original->url, + 'class' => 'avatar original', + 'width' => $original->width, + 'height' => $original->height, + 'alt' => $user->nickname)); + $this->elementEnd('div'); + $this->elementEnd('div'); + } + + $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE); + + if ($avatar) { + $this->elementStart('div', + array('id' => 'avatar_preview', + 'class' => 'avatar_view')); + $this->element('h3', null, _("Preview:")); + $this->elementStart('div', array('id'=>'avatar_preview_view')); + $this->element('img', array('src' => $original->url,//$avatar->url, + 'class' => 'avatar profile', + 'width' => AVATAR_PROFILE_SIZE, + 'height' => AVATAR_PROFILE_SIZE, + 'alt' => $user->nickname)); + $this->elementEnd('div'); + $this->elementEnd('div'); + + foreach (array('avatar_crop_x', 'avatar_crop_y', + 'avatar_crop_w', 'avatar_crop_h') as $crop_info) { + $this->element('input', array('name' => $crop_info, + 'type' => 'hidden', + 'id' => $crop_info)); + } + $this->submit('crop', _('Crop')); + } + + $this->element('input', array('name' => 'MAX_FILE_SIZE', + 'type' => 'hidden', + 'id' => 'MAX_FILE_SIZE', + 'value' => MAX_AVATAR_SIZE)); + + $this->elementStart('p'); + + $this->element('input', array('name' => 'avatarfile', + 'type' => 'file', + 'id' => 'avatarfile')); + $this->elementEnd('p'); + + $this->submit('upload', _('Upload')); + $this->elementEnd('form'); + + } + + /** + * Handle a post + * + * We mux on the button name to figure out what the user actually wanted. + * + * @return void + */ + + function handlePost() + { + // CSRF protection + + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->show_form(_('There was a problem with your session token. '. + 'Try again, please.')); + return; + } + + if ($this->arg('upload')) { + $this->uploadAvatar(); + } else if ($this->arg('crop')) { + $this->cropAvatar(); + } else { + $this->showForm(_('Unexpected form submission.')); + } + } + + /** + * Handle an image upload + * + * Does all the magic for handling an image upload, and crops the + * image by default. + * + * @return void + */ + + function uploadAvatar() + { + switch ($_FILES['avatarfile']['error']) { + case UPLOAD_ERR_OK: // success, jump out + break; + case UPLOAD_ERR_INI_SIZE: + case UPLOAD_ERR_FORM_SIZE: + $this->showForm(_('That file is too big.')); + return; + case UPLOAD_ERR_PARTIAL: + @unlink($_FILES['avatarfile']['tmp_name']); + $this->showForm(_('Partial upload.')); + return; + default: + $this->showForm(_('System error uploading file.')); + return; + } + + $info = @getimagesize($_FILES['avatarfile']['tmp_name']); + + if (!$info) { + @unlink($_FILES['avatarfile']['tmp_name']); + $this->showForm(_('Not an image or corrupt file.')); + return; + } + + switch ($info[2]) { + case IMAGETYPE_GIF: + case IMAGETYPE_JPEG: + case IMAGETYPE_PNG: + break; + default: + $this->showForm(_('Unsupported image file format.')); + return; + } + + $user = common_current_user(); + + $profile = $user->getProfile(); + + if ($profile->setOriginal($_FILES['avatarfile']['tmp_name'])) { + $this->showForm(_('Avatar updated.'), true); + } else { + $this->showForm(_('Failed updating avatar.')); + } + + @unlink($_FILES['avatarfile']['tmp_name']); + } + + /** + * Handle the results of jcrop. + * + * @return void + */ + + function cropAvatar() + { + $user = common_current_user(); + + $profile = $user->getProfile(); + + $x = $this->arg('avatar_crop_x'); + $y = $this->arg('avatar_crop_y'); + $w = $this->arg('avatar_crop_w'); + $h = $this->arg('avatar_crop_h'); + + if ($profile->crop_avatars($x, $y, $w, $h)) { + $this->showForm(_('Avatar updated.'), true); + } else { + $this->showForm(_('Failed updating avatar.')); + } + } + + /** + * Add the jCrop stylesheet + * + * @return void + */ + + function showStylesheets() + { + parent::showStylesheets(); + $jcropStyle = + common_path('js/jcrop/jquery.Jcrop.css?version='.LACONICA_VERSION); + + $this->element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => $jcropStyle, + 'media' => 'screen, projection, tv')); + } + + /** + * Add the jCrop scripts + * + * @return void + */ + + function showScripts() + { + parent::showScripts(); + + $jcropPack = common_path('js/jcrop/jquery.Jcrop.pack.js'); + $jcropGo = common_path('js/jcrop/jquery.Jcrop.go.js'); + + $this->element('script', array('type' => 'text/javascript', + 'src' => $jcropPack)); + $this->element('script', array('type' => 'text/javascript', + 'src' => $jcropGo)); + } +} diff --git a/htaccess.sample b/htaccess.sample index e348635a8..10e51b5b0 100644 --- a/htaccess.sample +++ b/htaccess.sample @@ -52,8 +52,9 @@ RewriteRule ^main/tagother$ index.php?action=tagother [L,QSA] RewriteRule ^main/block$ index.php?action=block [L,QSA] -RewriteRule ^settings/delete$ index.php?action=deleteprofile [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] -- cgit v1.2.3-54-g00ecf From 930f82a95170e05ad2d4fc079cc944d29521797d Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 19 Jan 2009 18:21:14 +0000 Subject: Update tag to use new framework Broke up the tag action into two different actions (publictagcloud and tag). Brought it up-to-date with the new framework, but haven't fixed it for phpcs yet. --- actions/publictagcloud.php | 149 +++++++++++++++++++++++++++++++++++++++++ actions/tag.php | 161 +++++++++++---------------------------------- htaccess.sample | 2 +- lib/publicgroupnav.php | 4 +- lib/util.php | 10 ++- 5 files changed, 195 insertions(+), 131 deletions(-) create mode 100644 actions/publictagcloud.php (limited to 'htaccess.sample') diff --git a/actions/publictagcloud.php b/actions/publictagcloud.php new file mode 100644 index 000000000..ec28edbad --- /dev/null +++ b/actions/publictagcloud.php @@ -0,0 +1,149 @@ +. + * + * @category Public + * @package Laconica + * @author Mike Cochrane + * @author Evan Prodromou + * @copyright 2008 Mike Cochrane + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { exit(1); } + +define('TAGS_PER_PAGE', 100); + +/** + * Public tag cloud for notices + * + * @category Personal + * @package Laconica + * @author Mike Cochrane + * @author Evan Prodromou + * @copyright 2008 Mike Cochrane + * @copyright 2008-2009 Control Yourself, Inc. + * @link http://laconi.ca/ + */ + +class PublictagcloudAction extends Action +{ + function isReadOnly() + { + return true; + } + + function title() + { + return _('Public tag cloud'); + } + + function showPageNotice() + { + $this->element('p', 'instructions', + sprintf(_('These are most popular recent tags on %s '), + common_config('site', 'name'))); + } + + function showLocalNav() + { + $nav = new PublicGroupNav($this); + $nav->show(); + } + + function handle($args) + { + parent::handle($args); + $this->showPage(); + } + + function showContent() + { + # This should probably be cached rather than recalculated + $tags = new Notice_tag(); + + #Need to clear the selection and then only re-add the field + #we are grouping by, otherwise it's not a valid 'group by' + #even though MySQL seems to let it slide... + $tags->selectAdd(); + $tags->selectAdd('tag'); + + #Add the aggregated columns... + $tags->selectAdd('max(notice_id) as last_notice_id'); + if(common_config('db','type')=='pgsql') { + $calc='sum(exp(-extract(epoch from (now()-created))/%s)) as weight'; + } else { + $calc='sum(exp(-(now() - created)/%s)) as weight'; + } + $tags->selectAdd(sprintf($calc, common_config('tag', 'dropoff'))); + $tags->groupBy('tag'); + $tags->orderBy('weight DESC'); + + $tags->limit(TAGS_PER_PAGE); + + $cnt = $tags->find(); + + if ($cnt > 0) { + $this->elementStart('p', 'tagcloud'); + + $tw = array(); + $sum = 0; + while ($tags->fetch()) { + $tw[$tags->tag] = $tags->weight; + $sum += $tags->weight; + } + + ksort($tw); + + foreach ($tw as $tag => $weight) { + $this->showTag($tag, $weight, $weight/$sum); + } + + $this->elementEnd('p'); + } + } + + function showTag($tag, $weight, $relative) + { + # XXX: these should probably tune to the size of the site + if ($relative > 0.1) { + $cls = 'largest'; + } else if ($relative > 0.05) { + $cls = 'verylarge'; + } else if ($relative > 0.02) { + $cls = 'large'; + } else if ($relative > 0.01) { + $cls = 'medium'; + } else if ($relative > 0.005) { + $cls = 'small'; + } else if ($relative > 0.002) { + $cls = 'verysmall'; + } else { + $cls = 'smallest'; + } + + $this->element('a', array('class' => "$cls weight-$weight relative-$relative", + 'href' => common_local_url('tag', array('tag' => $tag))), + $tag); + $this->text(' '); + } +} diff --git a/actions/tag.php b/actions/tag.php index 3096b75b3..039cd9660 100644 --- a/actions/tag.php +++ b/actions/tag.php @@ -19,154 +19,71 @@ if (!defined('LACONICA')) { exit(1); } -require_once(INSTALLDIR.'/actions/showstream.php'); -define('TAGS_PER_PAGE', 100); - -class TagAction extends StreamAction +class TagAction extends Action { - - function handle($args) + function prepare($args) { + parent::prepare($args); + $this->tag = $this->trimmed('tag'); - parent::handle($args); - - # Looks like we're good; show the header - - if (isset($args['tag']) && $args['tag']) { - $tag = $args['tag']; - common_show_header(sprintf(_("Notices tagged with %s"), $tag), - array($this, 'show_header'), $tag, - array($this, 'show_top')); - $this->show_notices($tag); - } else { - common_show_header(_("Tags"), - array($this, 'show_header'), '', - array($this, 'show_top')); - $this->show_tags(); + if (!$this->tag) { + common_redirect(common_local_url('publictagcloud'), 301); + return false; } - common_show_footer(); + $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; + return true; } - function show_header($tag = false) + function title() { - if ($tag) { - $this->element('link', array('rel' => 'alternate', - 'href' => common_local_url('tagrss', array('tag' => $tag)), - 'type' => 'application/rss+xml', - 'title' => sprintf(_('Feed for tag %s'), $tag))); + if ($this->page == 1) { + return sprintf(_("Notices tagged with %s"), $this->tag); + } else { + return sprintf(_("Notices tagged with %s, page %d"), + $this->tag, + $this->page); } } - function get_instructions() + function handle($args) { - return _('Showing most popular tags from the last week'); + parent::handle($args); + + $this->showPage(); } - function show_top($tag = false) + function showFeeds() { - if (!$tag) { - $instr = $this->get_instructions(); - $output = common_markup_to_html($instr); - $this->elementStart('div', 'instructions'); - $this->raw($output); - $this->elementEnd('div'); - $this->public_views_menu(); - } - else { - $this->show_feeds_list(array(0=>array('href'=>common_local_url('tagrss'), - 'type' => 'rss', - 'version' => 'RSS 1.0', - 'item' => 'tagrss'))); - } + $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))); } - function show_tags() + function showPageNotice() { - # This should probably be cached rather than recalculated - $tags = DB_DataObject::factory('Notice_tag'); - - #Need to clear the selection and then only re-add the field - #we are grouping by, otherwise it's not a valid 'group by' - #even though MySQL seems to let it slide... - $tags->selectAdd(); - $tags->selectAdd('tag'); - - #Add the aggregated columns... - $tags->selectAdd('max(notice_id) as last_notice_id'); - if(common_config('db','type')=='pgsql') { - $calc='sum(exp(-extract(epoch from (now()-created))/%s)) as weight'; - } else { - $calc='sum(exp(-(now() - created)/%s)) as weight'; - } - $tags->selectAdd(sprintf($calc, common_config('tag', 'dropoff'))); - $tags->groupBy('tag'); - $tags->orderBy('weight DESC'); - - # $tags->whereAdd('created > "' . strftime('%Y-%m-%d %H:%M:%S', strtotime('-1 MONTH')) . '"'); - - $tags->limit(TAGS_PER_PAGE); - - $cnt = $tags->find(); - - if ($cnt > 0) { - $this->elementStart('p', 'tagcloud'); - - $tw = array(); - $sum = 0; - while ($tags->fetch()) { - $tw[$tags->tag] = $tags->weight; - $sum += $tags->weight; - } - - ksort($tw); - - foreach ($tw as $tag => $weight) { - $this->show_tag($tag, $weight, $weight/$sum); - } - - $this->elementEnd('p'); - } + return sprintf(_('Messages tagged "%s", most recent first'), $this->tag); } - function show_tag($tag, $weight, $relative) + function showExportData() { - - # XXX: these should probably tune to the size of the site - if ($relative > 0.1) { - $cls = 'largest'; - } else if ($relative > 0.05) { - $cls = 'verylarge'; - } else if ($relative > 0.02) { - $cls = 'large'; - } else if ($relative > 0.01) { - $cls = 'medium'; - } else if ($relative > 0.005) { - $cls = 'small'; - } else if ($relative > 0.002) { - $cls = 'verysmall'; - } else { - $cls = 'smallest'; - } - - $this->element('a', array('class' => "$cls weight-$weight relative-$relative", - 'href' => common_local_url('tag', array('tag' => $tag))), - $tag); - $this->text(' '); + $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 show_notices($tag) + function showContent() { + $notice = Notice_tag::getStream($this->tag, (($this->page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1); - $cnt = 0; - - $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; - - $notice = Notice_tag::getStream($tag, (($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1); + $nl = new NoticeList($notice, $this); - $cnt = $this->show_notice_list($notice); + $cnt = $nl->show(); - common_pagination($page > 1, $cnt > NOTICES_PER_PAGE, - $page, 'tag', array('tag' => $tag)); + $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, + $this->page, 'tag', array('tag' => $this->tag)); } } diff --git a/htaccess.sample b/htaccess.sample index 10e51b5b0..b0e3e93e0 100644 --- a/htaccess.sample +++ b/htaccess.sample @@ -76,7 +76,7 @@ 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=tag [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] diff --git a/lib/publicgroupnav.php b/lib/publicgroupnav.php index 97b57ec17..8dd97a3b7 100644 --- a/lib/publicgroupnav.php +++ b/lib/publicgroupnav.php @@ -76,8 +76,8 @@ class PublicGroupNav extends Widget $this->out->menuItem(common_local_url('public'), _('Public'), _('Public timeline'), $action_name == 'public', 'nav_timeline_public'); - $this->out->menuItem(common_local_url('tag'), _('Recent tags'), - _('Recent tags'), $action_name == 'tag', 'nav_recent-tags'); + $this->out->menuItem(common_local_url('publictagcloud'), _('Recent tags'), + _('Recent tags'), $action_name == 'publictagcloud', 'nav_recent-tags'); if (count(common_config('nickname', 'featured')) > 0) { $this->out->menuItem(common_local_url('featured'), _('Featured'), diff --git a/lib/util.php b/lib/util.php index d67c64972..73c4cdcc8 100644 --- a/lib/util.php +++ b/lib/util.php @@ -865,13 +865,11 @@ function common_fancy_url($action, $args=null) case 'avatarbynickname': return common_path($args['nickname'].'/avatar/'.$args['size']); case 'tag': - if (isset($args['tag']) && $args['tag']) { - $path = 'tag/' . $args['tag']; - unset($args['tag']); - } else { - $path = 'tags'; - } + $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']); -- cgit v1.2.3-54-g00ecf From 6b97eab11a3bcf20f82859d02f69b32e3cfedcc5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 20 Jan 2009 23:15:18 -0500 Subject: Move username catchalls to end of file Although there hadn't been any conflicts yet, I moved the username catchalls to the end of the file anyways. --- htaccess.sample | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'htaccess.sample') diff --git a/htaccess.sample b/htaccess.sample index b0e3e93e0..8c8b2152a 100644 --- a/htaccess.sample +++ b/htaccess.sample @@ -85,27 +85,6 @@ 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 ^(\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+)$ index.php?action=showstream&nickname=$1 [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] @@ -148,6 +127,27 @@ RewriteRule ^api/laconica/version(.*)$ index.php?action=api&apiaction=laconica&m 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+)$ index.php?action=showstream&nickname=$1 [L,QSA] + Order allow,deny -- cgit v1.2.3-54-g00ecf From 97f14ef1f9c9a1151c149eb1e95646081918befb Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 21 Jan 2009 00:38:33 -0500 Subject: Define URLs for groups --- htaccess.sample | 8 ++++++++ lib/util.php | 14 ++++++++++++++ 2 files changed, 22 insertions(+) (limited to 'htaccess.sample') diff --git a/htaccess.sample b/htaccess.sample index 8c8b2152a..3406554d0 100644 --- a/htaccess.sample +++ b/htaccess.sample @@ -85,6 +85,14 @@ 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]+) index.php?action=showgroup&nickname=$1 [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/([0-9]+)/id index.php?action=groupbyid&id=$1 [L,QSA] +RewriteRule ^group/([0-9]+)/rss index.php?action=grouprss&id=$1 [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] diff --git a/lib/util.php b/lib/util.php index 73c4cdcc8..7b30aeab4 100644 --- a/lib/util.php +++ b/lib/util.php @@ -915,6 +915,20 @@ function common_fancy_url($action, $args=null) } else { return common_path('main/sup'); } + case 'newgroup': + return common_path('group/new'); + case 'showgroup': + return common_path('group/'.$args['nickname']); + 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'); default: return common_simple_url($action, $args); } -- cgit v1.2.3-54-g00ecf From 0ab9c222682de39dab3c760673fc8f5a0bd8b854 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 21 Jan 2009 02:45:37 -0500 Subject: Some more group URLs --- htaccess.sample | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'htaccess.sample') diff --git a/htaccess.sample b/htaccess.sample index 3406554d0..caf44bab8 100644 --- a/htaccess.sample +++ b/htaccess.sample @@ -90,8 +90,9 @@ RewriteRule ^group/([a-zA-Z0-9]+) index.php?action=showgroup&nickname=$1 [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/([0-9]+)/id index.php?action=groupbyid&id=$1 [L,QSA] -RewriteRule ^group/([0-9]+)/rss index.php?action=grouprss&id=$1 [L,QSA] +RewriteRule ^group/([a-zA-Z0-9]+)/rss index.php?action=grouprss&nickname=$1 [L,QSA] # Twitter-compatible API rewrites # XXX: Surely these can be refactored a little -- Zach @@ -153,6 +154,7 @@ RewriteRule ^(\w+)/favorites/rss$ index.php?action=favoritesrss&nickname=$1 [L,Q 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] -- cgit v1.2.3-54-g00ecf From b7bf1f87f31dac025875e3ff1e656a077dafe2b3 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 21 Jan 2009 02:55:08 -0500 Subject: fix hungry match for group name --- htaccess.sample | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'htaccess.sample') diff --git a/htaccess.sample b/htaccess.sample index caf44bab8..a0fc74248 100644 --- a/htaccess.sample +++ b/htaccess.sample @@ -86,13 +86,13 @@ 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]+) index.php?action=showgroup&nickname=$1 [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/([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] # Twitter-compatible API rewrites # XXX: Surely these can be refactored a little -- Zach -- cgit v1.2.3-54-g00ecf From 8942e3a445d6e4965fc46e08cb90bbfed17cd56a Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 23 Jan 2009 03:00:51 +0100 Subject: Add an action to show the list of the latest groups --- actions/groups.php | 117 +++++++++++++++++++++++++++++++++++++++++++++++++ htaccess.sample | 1 + lib/publicgroupnav.php | 3 ++ lib/util.php | 2 + 4 files changed, 123 insertions(+) create mode 100644 actions/groups.php (limited to 'htaccess.sample') diff --git a/actions/groups.php b/actions/groups.php new file mode 100644 index 000000000..154976f21 --- /dev/null +++ b/actions/groups.php @@ -0,0 +1,117 @@ +. + * + * @category Personal + * @package Laconica + * @author Evan Prodromou + * @author Sarven Capadisli + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/grouplist.php'; + +/** + * Latest groups + * + * Show the latest groups on the site + * + * @category Personal + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class GroupsAction extends Action +{ + var $page = null; + var $profile = null; + + function title() + { + if ($this->page == 1) { + return _("Groups"); + } else { + return sprintf(_("Groups, page %d"), $this->page); + } + } + + function prepare($args) + { + parent::prepare($args); + $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; + return true; + } + + function handle($args) + { + parent::handle($args); + $this->showPage(); + } + + function showLocalNav() + { + $nav = new PublicGroupNav($this); + $nav->show(); + } + + function showPageNotice() + { + $notice = + sprintf(_('%%%%site.name%%%% groups let you find and talk with ' . + 'people of similar interests. After you join a group ' . + 'you can send messages to all other members using the ' . + 'syntax "!groupname". Don\'t see a group you like? Try ' . + '[searching for one](%%%%action.groupsearch%%%%) or ' . + '[start your own!](%%%%action.newgroup%%%%)')); + $this->elementStart('div', 'instructions'); + $this->raw(common_markup_to_html($notice)); + $this->elementEnd('div'); + } + + function showContent() + { + $this->element('a', array('href' => common_local_url('newgroup'), + 'id' => 'new_group'), + _('Create a new group')); + + $offset = ($this->page-1) * GROUPS_PER_PAGE; + $limit = GROUPS_PER_PAGE + 1; + + $groups = new User_group(); + $groups->orderBy('created DESC'); + $groups->limit($offset, $limit); + + if ($groups->find()) { + $gl = new GroupList($groups, null, $this); + $cnt = $gl->show(); + } + + $this->pagination($this->page > 1, $cnt > GROUPS_PER_PAGE, + $this->page, 'groups'); + } +} diff --git a/htaccess.sample b/htaccess.sample index a0fc74248..2a64e8060 100644 --- a/htaccess.sample +++ b/htaccess.sample @@ -93,6 +93,7 @@ RewriteRule ^group/([a-zA-Z0-9]+)/members index.php?action=groupmembers&nickname 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 diff --git a/lib/publicgroupnav.php b/lib/publicgroupnav.php index 8dd97a3b7..d72475e20 100644 --- a/lib/publicgroupnav.php +++ b/lib/publicgroupnav.php @@ -76,6 +76,9 @@ class PublicGroupNav extends Widget $this->out->menuItem(common_local_url('public'), _('Public'), _('Public timeline'), $action_name == 'public', 'nav_timeline_public'); + $this->out->menuItem(common_local_url('groups'), _('Groups'), + _('User groups'), $action_name == 'groups', 'nav_groups'); + $this->out->menuItem(common_local_url('publictagcloud'), _('Recent tags'), _('Recent tags'), $action_name == 'publictagcloud', 'nav_recent-tags'); diff --git a/lib/util.php b/lib/util.php index d30a56c77..42bc08e7e 100644 --- a/lib/util.php +++ b/lib/util.php @@ -945,6 +945,8 @@ function common_fancy_url($action, $args=null) return common_path('group/'.$args['nickname'].'/members'); case 'usergroups': return common_path($args['nickname'].'/groups'); + case 'groups': + return common_path('group'); default: return common_simple_url($action, $args); } -- cgit v1.2.3-54-g00ecf From 745885902ae69e832d910b82c6bc21520885b136 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 23 Jan 2009 06:32:56 +0000 Subject: Add several more help files --- doc/groups | 42 +++++++++++++++++++++++++++++++++++ doc/help | 3 +++ doc/sms | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ doc/tags | 40 +++++++++++++++++++++++++++++++++ htaccess.sample | 3 +++ 5 files changed, 156 insertions(+) create mode 100644 doc/groups create mode 100644 doc/sms create mode 100644 doc/tags (limited to 'htaccess.sample') diff --git a/doc/groups b/doc/groups new file mode 100644 index 000000000..645390e0c --- /dev/null +++ b/doc/groups @@ -0,0 +1,42 @@ +Users on %%site.name%% can create *groups* that other users can join. +Groups can be a great way to share information and entertainment with +a group of people who have a common interest or background. + +You can find out about groups on the server on the +[Groups](%%action.groups%%) page. You can join a group by clicking on +the "Join" button either in the group list or on the group's home page. + +Starting a new group +-------------------- + +If you want, you can start a new group for friends and people with +common interests. Note that all groups are free for anyone to join. + +To start a new group, use the [new group](%%action.newgroup%%) tool +and fill out the form. Describe your group as best you can if you want +people to be able to find it. + +When choosing the nickname for your group, try to keep it short. The +nickname is included in every message to and from the group, so the +less chars the better. Try using acronyms for organizations, or +airport codes for places (like 'pdx' instead of 'portland'). + +Sending messages to a group +--------------------------- + +You can send a message to a group using the syntax "!groupname" +anywhere in the message. If you have more than one group named, the +notice will go to each group. Only members can send notices to a +group, and groups do not respond to direct messages (DMs). + +Receiving messages +------------------ + +New group messages will appear in your inbox, and will also come to +your phone or IM client if you've set them up to receive notices. + +Remote groups +------------- + +While it's technically possible, this version of Laconica does not +support remote group membership. diff --git a/doc/help b/doc/help index 5b60072e2..a8cfccd2b 100644 --- a/doc/help +++ b/doc/help @@ -23,6 +23,9 @@ Here are some documents that you might find helpful in understanding * [FAQ](%%doc.faq%%) - frequently-asked questions about %%site.name%% * [Contact](%%doc.contact%%) - who to contact with questions about the service * [IM](%%doc.im%%) - using the instant-message (IM) features of %%site.name%% +* [SMS](%%doc.sms%%) - tying your cellphone to %%site.name%% +* [tags](%%doc.tags%%) - different ways to use tagging +* [Groups](%%doc.groups%%) - joining together in groups * [OpenID](%%doc.openid%%) - what OpenID is and how to use it with this service * [OpenMicroBlogging](%%doc.openmublog%%) - subscribing to remote users * [Privacy](%%doc.privacy%%) - %%site.name%%'s privacy policy diff --git a/doc/sms b/doc/sms new file mode 100644 index 000000000..1beb49786 --- /dev/null +++ b/doc/sms @@ -0,0 +1,68 @@ +You can post messages to %%site.name%% using a many kinds of cell +phones that support SMS messaging. This site does not support SMS +directly; rather, it uses your carrier's email gateway to send and +receive messages. + +Managing your SMS settings +-------------------------- + +Use the [SMS settings](%%action.smssettings%%) page to set your SMS +preferences. You can add or change your SMS number and set the +flags for SMS updates. + +When you add or change your phone number, you'll receive a message on your +phone with a verification code. Enter it into the SMS settings page to +confirm that the owner of the phone authorizes sending it messages. + +Note that only the carriers listed in the drop down list on the form +are supported by %%site.name%%. They're the only ones we know how to +make email addresses for. + +Receiving messages +------------------ + +Once you've verified your phone number, you can enable sending +messages to your phone. If you have a lot of friends and a typical +phone, it can be hard to keep up. + +Sending messages +---------------- + +To send a message, you must send an email to the incoming email +address visible on your SMS settings page. The method for sending +email from your phone varies from carrier to carrier and from handset +to handet; if in doubt, ask your carrier. + +Keep your incoming email address a secret -- it's the only way we know +you're really you! + +Commands +-------- + +You can use the following commands with %%site.name%%. + +* on - turn on notifications +* off - turn off notifications +* help - show this help +* follow - subscribe to user +* leave - unsubscribe from user +* d - direct message to user +* get - get last notice from user +* whois - get profile info on user +* fav - add user's last notice as a 'fave' +* stats - get your stats +* stop - same as 'off' +* quit - same as 'off' +* sub - same as 'follow' +* unsub - same as 'leave' +* last - same as 'get' +* on - not yet implemented. +* off - not yet implemented. +* nudge - not yet implemented. +* invite - not yet implemented. +* track - not yet implemented. +* untrack - not yet implemented. +* track off - not yet implemented. +* untrack all - not yet implemented. +* tracks - not yet implemented. +* tracking - not yet implemented. diff --git a/doc/tags b/doc/tags new file mode 100644 index 000000000..2ed352e70 --- /dev/null +++ b/doc/tags @@ -0,0 +1,40 @@ +%%site.name%% supports +[tags](http://en.wikipedia.org/wiki/Tag_(metadata)) to help you +organize your activities here. You can use tags for people and for +notices. + +Tagging a notice +---------------- + +You can tag a notice using a *hashtag*; a # character followed by +letters and numbers as well as '.', '-', and '_'. Note that accented +latin characters are not supported, and non-roman scripts are right out. + +The HTML for the notice will link to a stream of all the other notices +with that tag. This can be a great way to keep track of a conversation. + +The most popular current tags on the site can be found in the [public +tag cloud](%%action.publictagcloud%%). Their size shows their +popularity and recency. + +Tagging yourself +---------------- + +You can also add tags for yourself on your [profile +settings](%%action.profilesettings%%) page. Use single words to +describe yourself, your experiences and your interest. The tags will +become links on your profile page to a list of all the users on the +site who use that same tag. It can be a nice way to find people who +are related to you geographically or who have a common interest. + +Tagging your subscriptions +-------------------------- + +You can also tag your subscriptions, on the subscriptions page. This +makes it easy to organize your subscriptions into groups and sort +through them separately. + +You can also send a notice "to the attention of" everyone you've +marked with a particular tag (note: *not* people who've marked +themselves with that tag). "@#family hello" will send a notice to +everyone you've marked with the tag 'family'. \ No newline at end of file diff --git a/htaccess.sample b/htaccess.sample index 2a64e8060..b80dd88fe 100644 --- a/htaccess.sample +++ b/htaccess.sample @@ -21,6 +21,9 @@ 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] -- cgit v1.2.3-54-g00ecf From 50ec1cc26ec1c27a2d80dcab27214aa6e7a6416f Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 23 Jan 2009 08:15:29 +0100 Subject: Upload logos for groups --- actions/grouplogo.php | 511 +++++++++++++++++++++++++++++++++++++++++++++++++ classes/User_group.php | 78 ++++++++ htaccess.sample | 15 +- lib/groupnav.php | 6 + lib/util.php | 2 + 5 files changed, 605 insertions(+), 7 deletions(-) create mode 100644 actions/grouplogo.php (limited to 'htaccess.sample') diff --git a/actions/grouplogo.php b/actions/grouplogo.php new file mode 100644 index 000000000..393070d5d --- /dev/null +++ b/actions/grouplogo.php @@ -0,0 +1,511 @@ +. + * + * @category Settings + * @package Laconica + * @author Evan Prodromou + * @author Zach Copley + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/accountsettingsaction.php'; + +/** + * Upload an avatar + * + * We use jCrop plugin for jQuery to crop the image after upload. + * + * @category Settings + * @package Laconica + * @author Evan Prodromou + * @author Zach Copley + * @author Sarven Capadisli + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class GrouplogoAction extends Action +{ + var $mode = null; + var $imagefile = null; + var $filename = null; + + /** + * Prepare to run + */ + + function prepare($args) + { + parent::prepare($args); + + if (!common_config('inboxes','enabled')) { + $this->serverError(_('Inboxes must be enabled for groups to work')); + return false; + } + + if (!common_logged_in()) { + $this->clientError(_('You must be logged in to create a group.')); + return false; + } + + $nickname_arg = $this->trimmed('nickname'); + $nickname = common_canonical_nickname($nickname_arg); + + // Permanent redirect on non-canonical nickname + + if ($nickname_arg != $nickname) { + $args = array('nickname' => $nickname); + common_redirect(common_local_url('editgroup', $args), 301); + return false; + } + + if (!$nickname) { + $this->clientError(_('No nickname'), 404); + return false; + } + + $groupid = $this->trimmed('groupid'); + + if ($groupid) { + $this->group = User_group::staticGet('id', $groupid); + } else { + $this->group = User_group::staticGet('nickname', $nickname); + } + + if (!$this->group) { + $this->clientError(_('No such group'), 404); + return false; + } + + $cur = common_current_user(); + + if (!$cur->isAdmin($this->group)) { + $this->clientError(_('You must be an admin to edit the group'), 403); + return false; + } + + return true; + } + + function handle($args) + { + parent::handle($args); + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $this->handlePost(); + } else { + $this->showForm(); + } + } + + function showForm($msg = null) + { + $this->msg = $msg; + $this->showPage(); + } + + /** + * Title of the page + * + * @return string Title of the page + */ + + function title() + { + return _('Group logo'); + } + + /** + * Instructions for use + * + * @return instructions for use + */ + + function getInstructions() + { + return _('You can upload a logo image for your group.'); + } + + /** + * Content area of the page + * + * Shows a form for uploading an avatar. + * + * @return void + */ + + function showContent() + { + if ($this->mode == 'crop') { + $this->showCropForm(); + } else { + $this->showUploadForm(); + } + } + + function showUploadForm() + { + $user = common_current_user(); + + $profile = $user->getProfile(); + + if (!$profile) { + common_log_db_error($user, 'SELECT', __FILE__); + $this->serverError(_('User without matching profile')); + return; + } + + $original = $this->group->original_logo; + + $this->elementStart('form', array('enctype' => 'multipart/form-data', + 'method' => 'post', + 'id' => 'form_settings_logo', + 'class' => 'form_settings', + 'action' => + common_local_url('grouplogo', + array('nickname' => $this->group->nickname)))); + $this->elementStart('fieldset'); + $this->element('legend', null, _('Group logo')); + $this->hidden('token', common_session_token()); + + $this->elementStart('ul', 'form_data'); + if ($original) { + $this->elementStart('li', array('id' => 'avatar_original', + 'class' => 'avatar_view')); + $this->element('h2', null, _("Original")); + $this->elementStart('div', array('id'=>'avatar_original_view')); + $this->element('img', array('src' => $this->group->original_logo, + 'alt' => $this->group->nickname)); + $this->elementEnd('div'); + $this->elementEnd('li'); + } + + if ($this->group->homepage_logo) { + $this->elementStart('li', array('id' => 'avatar_preview', + 'class' => 'avatar_view')); + $this->element('h2', null, _("Preview")); + $this->elementStart('div', array('id'=>'avatar_preview_view')); + $this->element('img', array('src' => $this->group->homepage_logo, + 'width' => AVATAR_PROFILE_SIZE, + 'height' => AVATAR_PROFILE_SIZE, + 'alt' => $this->group->nickname)); + $this->elementEnd('div'); + $this->elementEnd('li'); + } + + $this->elementStart('li', array ('id' => 'settings_attach')); + $this->element('input', array('name' => 'avatarfile', + 'type' => 'file', + 'id' => 'avatarfile')); + $this->element('input', array('name' => 'MAX_FILE_SIZE', + 'type' => 'hidden', + 'id' => 'MAX_FILE_SIZE', + 'value' => MAX_AVATAR_SIZE)); + $this->elementEnd('li'); + $this->elementEnd('ul'); + + $this->elementStart('ul', 'form_actions'); + $this->elementStart('li'); + $this->submit('upload', _('Upload')); + $this->elementEnd('li'); + $this->elementEnd('ul'); + + $this->elementEnd('fieldset'); + $this->elementEnd('form'); + + } + + function showCropForm() + { + $this->elementStart('form', array('method' => 'post', + 'id' => 'form_settings_avatar', + 'class' => 'form_settings', + 'action' => + common_local_url('grouplogo', + array('nickname' => $this->group->nickname)))); + $this->elementStart('fieldset'); + $this->element('legend', null, _('Avatar settings')); + $this->hidden('token', common_session_token()); + + $this->elementStart('ul', 'form_data'); + + $this->elementStart('li', + array('id' => 'avatar_original', + 'class' => 'avatar_view')); + $this->element('h2', null, _("Original")); + $this->elementStart('div', array('id'=>'avatar_original_view')); + $this->element('img', array('src' => common_avatar_url($this->filedata['filename']), + 'width' => $this->filedata['width'], + 'height' => $this->filedata['height'], + 'alt' => $this->group->nickname)); + $this->elementEnd('div'); + $this->elementEnd('li'); + + $this->elementStart('li', + array('id' => 'avatar_preview', + 'class' => 'avatar_view')); + $this->element('h2', null, _("Preview")); + $this->elementStart('div', array('id'=>'avatar_preview_view')); + $this->element('img', array('src' => common_avatar_url($this->filedata['filename']), + 'width' => AVATAR_PROFILE_SIZE, + 'height' => AVATAR_PROFILE_SIZE, + 'alt' => $this->group->nickname)); + $this->elementEnd('div'); + + foreach (array('avatar_crop_x', 'avatar_crop_y', + 'avatar_crop_w', 'avatar_crop_h') as $crop_info) { + $this->element('input', array('name' => $crop_info, + 'type' => 'hidden', + 'id' => $crop_info)); + } + $this->submit('crop', _('Crop')); + + $this->elementEnd('li'); + $this->elementEnd('ul'); + $this->elementEnd('fieldset'); + $this->elementEnd('form'); + + } + + /** + * Handle a post + * + * We mux on the button name to figure out what the user actually wanted. + * + * @return void + */ + + function handlePost() + { + // CSRF protection + + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->show_form(_('There was a problem with your session token. '. + 'Try again, please.')); + return; + } + + if ($this->arg('upload')) { + $this->uploadAvatar(); + } else if ($this->arg('crop')) { + $this->cropAvatar(); + } else { + $this->showForm(_('Unexpected form submission.')); + } + } + + /** + * Handle an image upload + * + * Does all the magic for handling an image upload, and crops the + * image by default. + * + * @return void + */ + + function uploadAvatar() + { + try { + $imagefile = ImageFile::fromUpload('avatarfile'); + } catch (Exception $e) { + $this->showForm($e->getMessage()); + return; + } + + $filename = common_avatar_filename($this->group->id, + image_type_to_extension($imagefile->type), + null, + 'group-temp-'.common_timestamp()); + + $filepath = common_avatar_path($filename); + + move_uploaded_file($imagefile->filename, $filepath); + + $filedata = array('filename' => $filename, + 'filepath' => $filepath, + 'width' => $imagefile->width, + 'height' => $imagefile->height, + 'type' => $imagefile->type); + + $_SESSION['FILEDATA'] = $filedata; + + $this->filedata = $filedata; + + $this->mode = 'crop'; + + $this->showForm(_('Pick a square area of the image to be your avatar'), + true); + } + + /** + * Handle the results of jcrop. + * + * @return void + */ + + function cropAvatar() + { + $user = common_current_user(); + + $profile = $user->getProfile(); + + $x = $this->arg('avatar_crop_x'); + $y = $this->arg('avatar_crop_y'); + $w = $this->arg('avatar_crop_w'); + $h = $this->arg('avatar_crop_h'); + + $filedata = $_SESSION['FILEDATA']; + + if (!$filedata) { + $this->serverError(_('Lost our file data.')); + return; + } + + $filepath = common_avatar_path($filedata['filename']); + + if (!file_exists($filepath)) { + $this->serverError(_('Lost our file.')); + return; + } + + switch ($filedata['type']) { + case IMAGETYPE_GIF: + $image_src = imagecreatefromgif($filepath); + break; + case IMAGETYPE_JPEG: + $image_src = imagecreatefromjpeg($filepath); + break; + case IMAGETYPE_PNG: + $image_src = imagecreatefrompng($filepath); + break; + default: + $this->serverError(_('Unknown file type')); + return; + } + + common_debug("W = $w, H = $h, X = $x, Y = $y"); + + $image_dest = imagecreatetruecolor($w, $h); + + $background = imagecolorallocate($image_dest, 0, 0, 0); + ImageColorTransparent($image_dest, $background); + imagealphablending($image_dest, false); + + imagecopyresized($image_dest, $image_src, 0, 0, $x, $y, $w, $h, $w, $h); + + $cur = common_current_user(); + + $filename = common_avatar_filename($this->group->id, + image_type_to_extension($imagefile->type), + null, + 'group-'.common_timestamp()); + + $filepath = common_avatar_path($filename); + + switch ($filedata['type']) { + case IMAGETYPE_GIF: + imagegif($image_dest, $filepath); + break; + case IMAGETYPE_JPEG: + imagejpeg($image_dest, $filepath); + break; + case IMAGETYPE_PNG: + imagepng($image_dest, $filepath); + break; + default: + $this->serverError(_('Unknown file type')); + return; + } + + if ($this->group->setOriginal($filename, $filedata['type'])) { + @unlink(common_avatar_path($filedata['filename'])); + unset($_SESSION['FILEDATA']); + $this->mode = 'upload'; + $this->showForm(_('Logo updated.'), true); + } else { + $this->showForm(_('Failed updating logo.')); + } + } + + function showPageNotice() + { + if ($this->msg) { + $this->element('div', ($this->success) ? 'success' : 'error', + $this->msg); + } else { + $inst = $this->getInstructions(); + $output = common_markup_to_html($inst); + + $this->elementStart('div', 'instructions'); + $this->raw($output); + $this->elementEnd('div'); + } + } + + /** + * Add the jCrop stylesheet + * + * @return void + */ + + function showStylesheets() + { + parent::showStylesheets(); + $jcropStyle = + common_path('theme/base/css/jquery.Jcrop.css?version='.LACONICA_VERSION); + + $this->element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => $jcropStyle, + 'media' => 'screen, projection, tv')); + } + + /** + * Add the jCrop scripts + * + * @return void + */ + + function showScripts() + { + parent::showScripts(); + + $jcropPack = common_path('js/jcrop/jquery.Jcrop.pack.js'); + $jcropGo = common_path('js/jcrop/jquery.Jcrop.go.js'); + + $this->element('script', array('type' => 'text/javascript', + 'src' => $jcropPack)); + $this->element('script', array('type' => 'text/javascript', + 'src' => $jcropGo)); + } + + function showLocalNav() + { + $nav = new GroupNav($this, $this->group); + $nav->show(); + } +} diff --git a/classes/User_group.php b/classes/User_group.php index 484b2fe0a..98ad77cc0 100755 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -86,4 +86,82 @@ class User_group extends Memcached_DataObject return $members; } + + function setOriginal($filename, $type) + { + $orig = clone($this); + $this->original_logo = common_avatar_url($filename); + $this->homepage_logo = common_avatar_url($this->scale($filename, + AVATAR_PROFILE_SIZE, + $type)); + $this->stream_logo = common_avatar_url($this->scale($filename, + AVATAR_STREAM_SIZE, + $type)); + $this->mini_logo = common_avatar_url($this->scale($filename, + AVATAR_MINI_SIZE, + $type)); + common_debug(common_log_objstring($this)); + return $this->update($orig); + } + + function scale($filename, $size, $type) + { + $filepath = common_avatar_path($filename); + + if (!file_exists($filepath)) { + $this->serverError(_('Lost our file.')); + return; + } + + $info = @getimagesize($filepath); + + switch ($type) { + case IMAGETYPE_GIF: + $image_src = imagecreatefromgif($filepath); + break; + case IMAGETYPE_JPEG: + $image_src = imagecreatefromjpeg($filepath); + break; + case IMAGETYPE_PNG: + $image_src = imagecreatefrompng($filepath); + break; + default: + $this->serverError(_('Unknown file type')); + return; + } + + $image_dest = imagecreatetruecolor($size, $size); + + $background = imagecolorallocate($image_dest, 0, 0, 0); + ImageColorTransparent($image_dest, $background); + imagealphablending($image_dest, false); + + imagecopyresized($image_dest, $image_src, 0, 0, $x, $y, $size, $size, $info[0], $info[1]); + + $cur = common_current_user(); + + $outname = common_avatar_filename($cur->id, + image_type_to_extension($type), + null, + common_timestamp()); + + $outpath = common_avatar_path($outname); + + switch ($type) { + case IMAGETYPE_GIF: + imagegif($image_dest, $outpath); + break; + case IMAGETYPE_JPEG: + imagejpeg($image_dest, $outpath); + break; + case IMAGETYPE_PNG: + imagepng($image_dest, $outpath); + break; + default: + $this->serverError(_('Unknown file type')); + return; + } + + return $outname; + } } diff --git a/htaccess.sample b/htaccess.sample index b80dd88fe..73b52c55e 100644 --- a/htaccess.sample +++ b/htaccess.sample @@ -88,13 +88,14 @@ 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/([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/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] diff --git a/lib/groupnav.php b/lib/groupnav.php index 32803fd42..90bdc1014 100644 --- a/lib/groupnav.php +++ b/lib/groupnav.php @@ -101,6 +101,12 @@ class GroupNav extends Widget sprintf(_('Edit %s group properties'), $nickname), $action_name == 'editgroup', 'nav_group_admin'); + $this->out->menuItem(common_local_url('grouplogo', array('nickname' => + $nickname)), + _('Logo'), + sprintf(_('Add or edit %s logo'), $nickname), + $action_name == 'grouplogo', + 'nav_group_logo'); } $this->out->elementEnd('ul'); } diff --git a/lib/util.php b/lib/util.php index 0b5abfa48..03d6b6199 100644 --- a/lib/util.php +++ b/lib/util.php @@ -898,6 +898,8 @@ function common_fancy_url($action, $args=null) return common_path('group/'.$args['nickname'].'/rss'); case 'groupmembers': return common_path('group/'.$args['nickname'].'/members'); + case 'grouplogo': + return common_path('group/'.$args['nickname'].'/logo'); case 'usergroups': return common_path($args['nickname'].'/groups'); case 'groups': -- cgit v1.2.3-54-g00ecf