From 5d76234a6031fdf5df2aeea974777b006961cc7a Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 20 Dec 2008 19:58:37 -0500 Subject: [PATCH] reformat for phpcs darcs-hash:20081221005837-84dde-07cd6bb27d5f601360a686538dd76f1dca9af3c4.gz --- _darcs/inventory | 4 +- ...7cd6bb27d5f601360a686538dd76f1dca9af3c4.gz | Bin 0 -> 3698 bytes _darcs/pristine/lib/gallery.php | 500 +++++------ _darcs/tentative_pristine | 774 +++++++++++++----- lib/gallery.php | 500 +++++------ 5 files changed, 1081 insertions(+), 697 deletions(-) create mode 100644 _darcs/patches/20081221005837-84dde-07cd6bb27d5f601360a686538dd76f1dca9af3c4.gz diff --git a/_darcs/inventory b/_darcs/inventory index 0ee79eeaa2..3fba388223 100644 --- a/_darcs/inventory +++ b/_darcs/inventory @@ -27,4 +27,6 @@ Evan Prodromou **20081221003016] [some modifications to assuage phpcs Evan Prodromou **20081221003955] [reformat lib/daemon.php for phpcs -Evan Prodromou **20081221004607] \ No newline at end of file +Evan Prodromou **20081221004607] +[reformat for phpcs +Evan Prodromou **20081221005837] \ No newline at end of file diff --git a/_darcs/patches/20081221005837-84dde-07cd6bb27d5f601360a686538dd76f1dca9af3c4.gz b/_darcs/patches/20081221005837-84dde-07cd6bb27d5f601360a686538dd76f1dca9af3c4.gz new file mode 100644 index 0000000000000000000000000000000000000000..34fd52db4b2720aa67663266d2c08dc86b620adc GIT binary patch literal 3698 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. */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} -require_once(INSTALLDIR.'/lib/profilelist.php'); +require_once INSTALLDIR.'/lib/profilelist.php'; -# 10x8 +// 10x8 define('AVATARS_PER_PAGE', 80); -class GalleryAction extends Action { +class GalleryAction extends Action +{ + function is_readonly() + { + return true; + } - function is_readonly() { - return true; - } + function handle($args) + { + parent::handle($args); - function handle($args) { - parent::handle($args); + // Post from the tag dropdown; redirect to a GET - # Post from the tag dropdown; redirect to a GET + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + common_redirect($this->self_url(), 307); + } - if ($_SERVER['REQUEST_METHOD'] == 'POST') { - common_redirect($this->self_url(), 307); - } + $nickname = common_canonical_nickname($this->arg('nickname')); - $nickname = common_canonical_nickname($this->arg('nickname')); - $user = User::staticGet('nickname', $nickname); + $user = User::staticGet('nickname', $nickname); - if (!$user) { - $this->no_such_user(); - return; - } + if (!$user) { + $this->no_such_user(); + return; + } - $profile = $user->getProfile(); + $profile = $user->getProfile(); - if (!$profile) { - $this->server_error(_('User without matching profile in system.')); - return; - } + if (!$profile) { + $this->server_error(_('User without matching profile in system.')); + return; + } - $page = $this->arg('page'); + $page = $this->arg('page'); - if (!$page) { - $page = 1; - } + if (!$page) { + $page = 1; + } - $display = $this->arg('display'); + $display = $this->arg('display'); - if (!$display) { - $display = 'list'; - } + if (!$display) { + $display = 'list'; + } - $tag = $this->arg('tag'); + $tag = $this->arg('tag'); - common_show_header($profile->nickname . ": " . $this->gallery_type(), - NULL, $profile, - array($this, 'show_top')); + common_show_header($profile->nickname . ": " . $this->gallery_type(), + null, $profile, + array($this, 'show_top')); - $this->display_links($profile, $page, $display); - $this->show_tags_dropdown($profile); + $this->display_links($profile, $page, $display); + $this->show_tags_dropdown($profile); - $this->show_gallery($profile, $page, $display, $tag); - common_show_footer(); - } + $this->show_gallery($profile, $page, $display, $tag); + common_show_footer(); + } - function no_such_user() { - $this->client_error(_('No such user.')); - } + function no_such_user() + { + $this->client_error(_('No such user.')); + } - function show_tags_dropdown($profile) { - $tag = $this->trimmed('tag'); - list($lst, $usr) = $this->fields(); - $tags = $this->get_all_tags($profile, $lst, $usr); - $content = array(); - foreach ($tags as $t) { - $content[$t] = $t; - } - if ($tags) { - common_element_start('dl', array('id'=>'filter_tags')); - common_element('dt', null, _('Filter tags')); - common_element_start('dd'); - common_element_start('ul'); - common_element_start('li', array('id'=>'filter_tags_all', 'class'=>'child_1')); - common_element('a', array('href' => common_local_url($this->trimmed('action'), - array('nickname' => $profile->nickname))), - _('All')); - common_element_end('li'); - common_element_start('li', array('id'=>'filter_tags_item')); - common_element_start('form', array('name' => 'bytag', 'id' => 'bytag', 'method' => 'post')); - common_dropdown('tag', _('Tag'), $content, - _('Choose a tag to narrow list'), FALSE, $tag); - common_submit('go', _('Go')); - common_element_end('form'); - common_element_end('li'); - common_element_end('ul'); - common_element_end('dd'); - common_element_end('dl'); - } - } + function show_tags_dropdown($profile) + { + $tag = $this->trimmed('tag'); - function show_top($profile) { - common_element('div', 'instructions', - $this->get_instructions($profile)); + list($lst, $usr) = $this->fields(); + + $tags = $this->get_all_tags($profile, $lst, $usr); + + $content = array(); + + foreach ($tags as $t) { + $content[$t] = $t; + } + if ($tags) { + common_element_start('dl', array('id'=>'filter_tags')); + common_element('dt', null, _('Filter tags')); + common_element_start('dd'); + common_element_start('ul'); + common_element_start('li', array('id' => 'filter_tags_all', + 'class' => 'child_1')); + common_element('a', + array('href' => + common_local_url($this->trimmed('action'), + array('nickname' => + $profile->nickname))), + _('All')); + common_element_end('li'); + common_element_start('li', array('id'=>'filter_tags_item')); + common_element_start('form', array('name' => 'bytag', + 'id' => 'bytag', + 'method' => 'post')); + common_dropdown('tag', _('Tag'), $content, + _('Choose a tag to narrow list'), false, $tag); + common_submit('go', _('Go')); + common_element_end('form'); + common_element_end('li'); + common_element_end('ul'); + common_element_end('dd'); + common_element_end('dl'); + } + } + + function show_top($profile) + { + common_element('div', 'instructions', + $this->get_instructions($profile)); $this->show_menu(); - } + } - function show_menu() { - # action => array('prompt', 'title', $args) - $action = $this->trimmed('action'); - $nickname = $this->trimmed('nickname'); - $menu = - array('subscriptions' => - array( _('Subscriptions'), - _('Subscriptions'), + function show_menu() + { + // action => array('prompt', 'title', $args) + $action = $this->trimmed('action'); + $nickname = $this->trimmed('nickname'); + + $menu = + array('subscriptions' => + array( _('Subscriptions'), + _('Subscriptions'), + array('nickname' => $nickname)), + 'subscribers' => + array( + _('Subscribers'), + _('Subscribers'), array('nickname' => $nickname)), - 'subscribers' => - array( - _('Subscribers'), - _('Subscribers'), - array('nickname' => $nickname)), - ); - $this->nav_menu($menu); - } + ); + $this->nav_menu($menu); + } - function show_gallery($profile, $page, $display='list', $tag=NULL) { + function show_gallery($profile, $page, $display='list', $tag=null) + { + $other = new Profile(); - $other = new Profile(); + list($lst, $usr) = $this->fields(); - list($lst, $usr) = $this->fields(); + $per_page = ($display == 'list') ? PROFILES_PER_PAGE : AVATARS_PER_PAGE; - $per_page = ($display == 'list') ? PROFILES_PER_PAGE : AVATARS_PER_PAGE; + $offset = ($page-1)*$per_page; + $limit = $per_page + 1; - $offset = ($page-1)*$per_page; - $limit = $per_page + 1; + if (common_config('db', 'type') == 'pgsql') { + $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $lim = ' LIMIT ' . $offset . ', ' . $limit; + } - if (common_config('db','type') == 'pgsql') { - $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset; - } else { - $lim = ' LIMIT ' . $offset . ', ' . $limit; - } + // XXX: memcached results + // FIXME: SQL injection on $tag - # XXX: memcached results - # FIXME: SQL injection on $tag + $other->query('SELECT profile.* ' . + 'FROM profile JOIN subscription ' . + 'ON profile.id = subscription.' . $lst . ' ' . + (($tag) ? 'JOIN profile_tag ON (profile.id = profile_tag.tagged AND subscription.'.$usr.'= profile_tag.tagger) ' : '') . + 'WHERE ' . $usr . ' = ' . $profile->id . ' ' . + 'AND subscriber != subscribed ' . + (($tag) ? 'AND profile_tag.tag= "' . $tag . '" ': '') . + 'ORDER BY subscription.created DESC, profile.id DESC ' . + $lim); - $other->query('SELECT profile.* ' . - 'FROM profile JOIN subscription ' . - 'ON profile.id = subscription.' . $lst . ' ' . - (($tag) ? 'JOIN profile_tag ON (profile.id = profile_tag.tagged AND subscription.'.$usr.'= profile_tag.tagger) ' : '') . - 'WHERE ' . $usr . ' = ' . $profile->id . ' ' . - 'AND subscriber != subscribed ' . - (($tag) ? 'AND profile_tag.tag= "' . $tag . '" ': '') . - 'ORDER BY subscription.created DESC, profile.id DESC ' . - $lim); - - if ($display == 'list') { + if ($display == 'list') { $cls = $this->profile_list_class(); - $profile_list = new $cls($other, $profile, $this->trimmed('action')); - $cnt = $profile_list->show_list(); - } else { - $cnt = $this->icon_list($other); - } + $profile_list = new $cls($other, $profile, $this->trimmed('action')); + $cnt = $profile_list->show_list(); + } else { + $cnt = $this->icon_list($other); + } - # For building the pagination URLs + // For building the pagination URLs - $args = array('nickname' => $profile->nickname); + $args = array('nickname' => $profile->nickname); - if ($display != 'list') { - $args['display'] = $display; - } + if ($display != 'list') { + $args['display'] = $display; + } - common_pagination($page > 1, - $cnt > $per_page, - $page, - $this->trimmed('action'), - $args); - } + common_pagination($page > 1, + $cnt > $per_page, + $page, + $this->trimmed('action'), + $args); + } - function profile_list_class() { + function profile_list_class() + { return 'ProfileList'; } - function icon_list($other) { + function icon_list($other) + { + common_element_start('ul', $this->div_class()); - common_element_start('ul', $this->div_class()); + $cnt = 0; - $cnt = 0; + while ($other->fetch()) { - while ($other->fetch()) { + $cnt++; - $cnt++; + if ($cnt > AVATARS_PER_PAGE) { + break; + } - if ($cnt > AVATARS_PER_PAGE) { - break; - } + common_element_start('li'); - common_element_start('li'); + common_element_start('a', array('title' => ($other->fullname) ? + $other->fullname : + $other->nickname, + 'href' => $other->profileurl, + 'class' => 'subscription')); + $avatar = $other->getAvatar(AVATAR_STREAM_SIZE); + common_element('img', + array('src' => + (($avatar) ? common_avatar_display_url($avatar) : + common_default_avatar(AVATAR_STREAM_SIZE)), + 'width' => AVATAR_STREAM_SIZE, + 'height' => AVATAR_STREAM_SIZE, + 'class' => 'avatar stream', + 'alt' => ($other->fullname) ? + $other->fullname : + $other->nickname)); + common_element_end('a'); - common_element_start('a', array('title' => ($other->fullname) ? - $other->fullname : - $other->nickname, - 'href' => $other->profileurl, - 'class' => 'subscription')); - $avatar = $other->getAvatar(AVATAR_STREAM_SIZE); - common_element('img', - array('src' => - (($avatar) ? common_avatar_display_url($avatar) : - common_default_avatar(AVATAR_STREAM_SIZE)), - 'width' => AVATAR_STREAM_SIZE, - 'height' => AVATAR_STREAM_SIZE, - 'class' => 'avatar stream', - 'alt' => ($other->fullname) ? - $other->fullname : - $other->nickname)); - common_element_end('a'); + // XXX: subscribe form here - # XXX: subscribe form here + common_element_end('li'); + } - common_element_end('li'); - } + common_element_end('ul'); - common_element_end('ul'); + return $cnt; + } - return $cnt; - } + function gallery_type() + { + return null; + } - function gallery_type() { - return NULL; - } + function get_instructions(&$profile) + { + return null; + } - function get_instructions(&$profile) { - return NULL; - } + function fields() + { + return null; + } - function fields() { - return NULL; - } + function div_class() + { + return ''; + } - function div_class() { - return ''; - } + function display_links($profile, $page, $display) + { + $tag = $this->trimmed('tag'); - function display_links($profile, $page, $display) { - $tag = $this->trimmed('tag'); + common_element_start('dl', array('id'=>'subscriptions_nav')); + common_element('dt', null, _('Subscriptions navigation')); + common_element_start('dd'); + common_element_start('ul', array('class'=>'nav')); - common_element_start('dl', array('id'=>'subscriptions_nav')); - common_element('dt', null, _('Subscriptions navigation')); - common_element_start('dd'); - common_element_start('ul', array('class'=>'nav')); + switch ($display) { + case 'list': + common_element('li', array('class'=>'child_1'), _('List')); + common_element_start('li'); + $url_args = array('display' => 'icons', + 'nickname' => $profile->nickname, + 'page' => 1 + floor((($page - 1) * PROFILES_PER_PAGE) / AVATARS_PER_PAGE)); + if ($tag) { + $url_args['tag'] = $tag; + } + $url = common_local_url($this->trimmed('action'), $url_args); + common_element('a', array('href' => $url), + _('Icons')); + common_element_end('li'); + break; + default: + common_element_start('li', array('class'=>'child_1')); + $url_args = array('nickname' => $profile->nickname, + 'page' => 1 + floor((($page - 1) * AVATARS_PER_PAGE) / PROFILES_PER_PAGE)); + if ($tag) { + $url_args['tag'] = $tag; + } + $url = common_local_url($this->trimmed('action'), $url_args); + common_element('a', array('href' => $url), + _('List')); + common_element_end('li'); + common_element('li', null, _('Icons')); + break; + } - switch ($display) { - case 'list': - common_element('li', array('class'=>'child_1'), _('List')); - common_element_start('li'); - $url_args = array('display' => 'icons', - 'nickname' => $profile->nickname, - 'page' => 1 + floor((($page - 1) * PROFILES_PER_PAGE) / AVATARS_PER_PAGE)); - if ($tag) { - $url_args['tag'] = $tag; - } - $url = common_local_url($this->trimmed('action'), $url_args); - common_element('a', array('href' => $url), - _('Icons')); - common_element_end('li'); - break; - default: - common_element_start('li', array('class'=>'child_1')); - $url_args = array('nickname' => $profile->nickname, - 'page' => 1 + floor((($page - 1) * AVATARS_PER_PAGE) / PROFILES_PER_PAGE)); - if ($tag) { - $url_args['tag'] = $tag; - } - $url = common_local_url($this->trimmed('action'), $url_args); - common_element('a', array('href' => $url), - _('List')); - common_element_end('li'); - common_element('li', NULL, _('Icons')); - break; - } + common_element_end('ul'); + common_element_end('dd'); + common_element_end('dl'); + } - common_element_end('ul'); - common_element_end('dd'); - common_element_end('dl'); - } + // Get list of tags we tagged other users with - # Get list of tags we tagged other users with - - function get_all_tags($profile, $lst, $usr) { - $profile_tag = new Notice_tag(); - $profile_tag->query('SELECT DISTINCT(tag) ' . - 'FROM profile_tag, subscription ' . - 'WHERE tagger = ' . $profile->id . ' ' . - 'AND ' . $usr . ' = ' . $profile->id . ' ' . - 'AND ' . $lst . ' = tagged ' . - 'AND tagger != tagged'); - $tags = array(); - while ($profile_tag->fetch()) { - $tags[] = $profile_tag->tag; - } - $profile_tag->free(); - return $tags; - } + function get_all_tags($profile, $lst, $usr) + { + $profile_tag = new Notice_tag(); + $profile_tag->query('SELECT DISTINCT(tag) ' . + 'FROM profile_tag, subscription ' . + 'WHERE tagger = ' . $profile->id . ' ' . + 'AND ' . $usr . ' = ' . $profile->id . ' ' . + 'AND ' . $lst . ' = tagged ' . + 'AND tagger != tagged'); + $tags = array(); + while ($profile_tag->fetch()) { + $tags[] = $profile_tag->tag; + } + $profile_tag->free(); + return $tags; + } } \ No newline at end of file diff --git a/_darcs/tentative_pristine b/_darcs/tentative_pristine index 73c44f1dc6..4e6b1fca93 100644 --- a/_darcs/tentative_pristine +++ b/_darcs/tentative_pristine @@ -1,232 +1,562 @@ -hunk ./lib/daemon.php 2 +hunk ./lib/gallery.php 2 +- -/* +/** -hunk ./lib/daemon.php 20 +hunk ./lib/gallery.php 20 -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} -hunk ./lib/daemon.php 24 --class Daemon { -+class Daemon +hunk ./lib/gallery.php 24 +-require_once(INSTALLDIR.'/lib/profilelist.php'); ++require_once INSTALLDIR.'/lib/profilelist.php'; +hunk ./lib/gallery.php 26 +-# 10x8 ++// 10x8 +hunk ./lib/gallery.php 30 +-class GalleryAction extends Action { ++class GalleryAction extends Action +{ -+ function name() -+ { -+ return null; -+ } -hunk ./lib/daemon.php 31 -- function name() { -- return NULL; -- } -- -- function background() { -- $pid = pcntl_fork(); -- if ($pid < 0) { # error -- common_log(LOG_ERR, "Could not fork."); -- return false; -- } else if ($pid > 0) { # parent -- common_log(LOG_INFO, "Successfully forked."); -- exit(0); -- } else { # child -- return true; -- } -- } -+ function background() -+ { -+ $pid = pcntl_fork(); -+ if ($pid < 0) { // error -+ common_log(LOG_ERR, "Could not fork."); -+ return false; -+ } else if ($pid > 0) { // parent -+ common_log(LOG_INFO, "Successfully forked."); -+ exit(0); -+ } else { // child -+ return true; -+ } -+ } -hunk ./lib/daemon.php 45 -- function alreadyRunning() { -+ function alreadyRunning() -+ { -+ $pidfilename = $this->pidFilename(); -hunk ./lib/daemon.php 49 -- $pidfilename = $this->pidFilename(); -+ if (!$pidfilename) { -+ return false; -+ } -hunk ./lib/daemon.php 53 -- if (!$pidfilename) { -- return false; -- } -- -- if (!file_exists($pidfilename)) { -- return false; -- } -- $contents = file_get_contents($pidfilename); -- if (posix_kill(trim($contents),0)) { -- return true; -- } else { -- return false; -- } -- } -- -- function writePidFile() { -- $pidfilename = $this->pidFilename(); -- -- if (!$pidfilename) { -- return false; -- } -- -- return file_put_contents($pidfilename, posix_getpid() . "\n"); -- } -+ if (!file_exists($pidfilename)) { -+ return false; -+ } -+ $contents = file_get_contents($pidfilename); -+ if (posix_kill(trim($contents), 0)) { -+ return true; -+ } else { -+ return false; -+ } -+ } -hunk ./lib/daemon.php 64 -- function clearPidFile() { -- $pidfilename = $this->pidFilename(); -- if (!$pidfilename) { -- return false; -- } -- return unlink($pidfilename); -- } -- -- function pidFilename() { -- $piddir = common_config('daemon', 'piddir'); -- if (!$piddir) { -- return NULL; -- } -- $name = $this->name(); -- if (!$name) { -- return NULL; -- } -- return $piddir . '/' . $name . '.pid'; -- } -+ function writePidFile() -+ { -+ $pidfilename = $this->pidFilename(); -hunk ./lib/daemon.php 68 -- function changeUser() { -+ if (!$pidfilename) { -+ return false; -+ } -hunk ./lib/daemon.php 72 -- $username = common_config('daemon', 'user'); -- -- if ($username) { -- $user_info = posix_getpwnam($username); -- if (!$user_info) { -- common_log(LOG_WARNING, 'Ignoring unknown user for daemon: ' . $username); -- } else { -- common_log(LOG_INFO, "Setting user to " . $username); -- posix_setuid($user_info['uid']); -- } -- } -+ return file_put_contents($pidfilename, posix_getpid() . "\n"); -+ } -hunk ./lib/daemon.php 75 -- $groupname = common_config('daemon', 'group'); -- -- if ($groupname) { -- $group_info = posix_getgrnam($groupname); -- if (!$group_info) { -- common_log(LOG_WARNING, 'Ignoring unknown group for daemon: ' . $groupname); -- } else { -- common_log(LOG_INFO, "Setting group to " . $groupname); -- posix_setgid($group_info['gid']); -- } -- } -- } -- -- function runOnce() { -- if ($this->alreadyRunning()) { -- common_log(LOG_INFO, $this->name() . ' already running. Exiting.'); -- exit(0); -- } -- if ($this->background()) { -- $this->writePidFile(); -- $this->changeUser(); -- $this->run(); -- $this->clearPidFile(); -- } -- } -- -- function run() { -- return true; -- } -+ function clearPidFile() -+ { -+ $pidfilename = $this->pidFilename(); -+ if (!$pidfilename) { -+ return false; -+ } -+ return unlink($pidfilename); -+ } -+ -+ function pidFilename() -+ { -+ $piddir = common_config('daemon', 'piddir'); -+ if (!$piddir) { -+ return null; -+ } -+ $name = $this->name(); -+ if (!$name) { -+ return null; -+ } -+ return $piddir . '/' . $name . '.pid'; -+ } -+ -+ function changeUser() -+ { -+ $username = common_config('daemon', 'user'); -+ -+ if ($username) { -+ $user_info = posix_getpwnam($username); -+ if (!$user_info) { -+ common_log(LOG_WARNING, -+ 'Ignoring unknown user for daemon: ' . $username); -+ } else { -+ common_log(LOG_INFO, "Setting user to " . $username); -+ posix_setuid($user_info['uid']); -+ } -+ } -+ -+ $groupname = common_config('daemon', 'group'); -+ -+ if ($groupname) { -+ $group_info = posix_getgrnam($groupname); -+ if (!$group_info) { -+ common_log(LOG_WARNING, -+ 'Ignoring unknown group for daemon: ' . $groupname); -+ } else { -+ common_log(LOG_INFO, "Setting group to " . $groupname); -+ posix_setgid($group_info['gid']); -+ } -+ } -+ } -+ -+ function runOnce() -+ { -+ if ($this->alreadyRunning()) { -+ common_log(LOG_INFO, $this->name() . ' already running. Exiting.'); -+ exit(0); -+ } -+ if ($this->background()) { -+ $this->writePidFile(); -+ $this->changeUser(); -+ $this->run(); -+ $this->clearPidFile(); -+ } -+ } -+ -+ function run() ++ function is_readonly() + { + return true; + } ++ ++ function handle($args) ++ { ++ parent::handle($args); ++ ++ // Post from the tag dropdown; redirect to a GET ++ ++ if ($_SERVER['REQUEST_METHOD'] == 'POST') { ++ common_redirect($this->self_url(), 307); ++ } ++ ++ $nickname = common_canonical_nickname($this->arg('nickname')); +hunk ./lib/gallery.php 49 +- function is_readonly() { +- return true; +- } ++ $user = User::staticGet('nickname', $nickname); +hunk ./lib/gallery.php 51 +- function handle($args) { +- parent::handle($args); ++ if (!$user) { ++ $this->no_such_user(); ++ return; ++ } +hunk ./lib/gallery.php 56 +- # Post from the tag dropdown; redirect to a GET ++ $profile = $user->getProfile(); +hunk ./lib/gallery.php 58 +- if ($_SERVER['REQUEST_METHOD'] == 'POST') { +- common_redirect($this->self_url(), 307); +- } ++ if (!$profile) { ++ $this->server_error(_('User without matching profile in system.')); ++ return; ++ } +hunk ./lib/gallery.php 63 +- $nickname = common_canonical_nickname($this->arg('nickname')); +- $user = User::staticGet('nickname', $nickname); ++ $page = $this->arg('page'); +hunk ./lib/gallery.php 65 +- if (!$user) { +- $this->no_such_user(); +- return; +- } ++ if (!$page) { ++ $page = 1; ++ } +hunk ./lib/gallery.php 69 +- $profile = $user->getProfile(); ++ $display = $this->arg('display'); +hunk ./lib/gallery.php 71 +- if (!$profile) { +- $this->server_error(_('User without matching profile in system.')); +- return; +- } ++ if (!$display) { ++ $display = 'list'; ++ } +hunk ./lib/gallery.php 75 +- $page = $this->arg('page'); ++ $tag = $this->arg('tag'); +hunk ./lib/gallery.php 77 +- if (!$page) { +- $page = 1; +- } ++ common_show_header($profile->nickname . ": " . $this->gallery_type(), ++ null, $profile, ++ array($this, 'show_top')); +hunk ./lib/gallery.php 81 +- $display = $this->arg('display'); ++ $this->display_links($profile, $page, $display); ++ $this->show_tags_dropdown($profile); +hunk ./lib/gallery.php 84 +- if (!$display) { +- $display = 'list'; +- } ++ $this->show_gallery($profile, $page, $display, $tag); ++ common_show_footer(); ++ } +hunk ./lib/gallery.php 88 +- $tag = $this->arg('tag'); ++ function no_such_user() ++ { ++ $this->client_error(_('No such user.')); ++ } +hunk ./lib/gallery.php 93 +- common_show_header($profile->nickname . ": " . $this->gallery_type(), +- NULL, $profile, +- array($this, 'show_top')); ++ function show_tags_dropdown($profile) ++ { ++ $tag = $this->trimmed('tag'); +hunk ./lib/gallery.php 97 +- $this->display_links($profile, $page, $display); +- $this->show_tags_dropdown($profile); ++ list($lst, $usr) = $this->fields(); +hunk ./lib/gallery.php 99 +- $this->show_gallery($profile, $page, $display, $tag); +- common_show_footer(); +- } ++ $tags = $this->get_all_tags($profile, $lst, $usr); +hunk ./lib/gallery.php 101 +- function no_such_user() { +- $this->client_error(_('No such user.')); +- } ++ $content = array(); +hunk ./lib/gallery.php 103 +- function show_tags_dropdown($profile) { +- $tag = $this->trimmed('tag'); +- list($lst, $usr) = $this->fields(); +- $tags = $this->get_all_tags($profile, $lst, $usr); +- $content = array(); +- foreach ($tags as $t) { +- $content[$t] = $t; +- } +- if ($tags) { +- common_element_start('dl', array('id'=>'filter_tags')); +- common_element('dt', null, _('Filter tags')); +- common_element_start('dd'); +- common_element_start('ul'); +- common_element_start('li', array('id'=>'filter_tags_all', 'class'=>'child_1')); +- common_element('a', array('href' => common_local_url($this->trimmed('action'), +- array('nickname' => $profile->nickname))), +- _('All')); +- common_element_end('li'); +- common_element_start('li', array('id'=>'filter_tags_item')); +- common_element_start('form', array('name' => 'bytag', 'id' => 'bytag', 'method' => 'post')); +- common_dropdown('tag', _('Tag'), $content, +- _('Choose a tag to narrow list'), FALSE, $tag); +- common_submit('go', _('Go')); +- common_element_end('form'); +- common_element_end('li'); +- common_element_end('ul'); +- common_element_end('dd'); +- common_element_end('dl'); +- } +- } ++ foreach ($tags as $t) { ++ $content[$t] = $t; ++ } ++ if ($tags) { ++ common_element_start('dl', array('id'=>'filter_tags')); ++ common_element('dt', null, _('Filter tags')); ++ common_element_start('dd'); ++ common_element_start('ul'); ++ common_element_start('li', array('id' => 'filter_tags_all', ++ 'class' => 'child_1')); ++ common_element('a', ++ array('href' => ++ common_local_url($this->trimmed('action'), ++ array('nickname' => ++ $profile->nickname))), ++ _('All')); ++ common_element_end('li'); ++ common_element_start('li', array('id'=>'filter_tags_item')); ++ common_element_start('form', array('name' => 'bytag', ++ 'id' => 'bytag', ++ 'method' => 'post')); ++ common_dropdown('tag', _('Tag'), $content, ++ _('Choose a tag to narrow list'), false, $tag); ++ common_submit('go', _('Go')); ++ common_element_end('form'); ++ common_element_end('li'); ++ common_element_end('ul'); ++ common_element_end('dd'); ++ common_element_end('dl'); ++ } ++ } +hunk ./lib/gallery.php 135 +- function show_top($profile) { +- common_element('div', 'instructions', +- $this->get_instructions($profile)); ++ function show_top($profile) ++ { ++ common_element('div', 'instructions', ++ $this->get_instructions($profile)); +hunk ./lib/gallery.php 140 +- } ++ } +hunk ./lib/gallery.php 142 +- function show_menu() { +- # action => array('prompt', 'title', $args) +- $action = $this->trimmed('action'); +- $nickname = $this->trimmed('nickname'); +- $menu = +- array('subscriptions' => +- array( _('Subscriptions'), +- _('Subscriptions'), +- array('nickname' => $nickname)), +- 'subscribers' => +- array( +- _('Subscribers'), +- _('Subscribers'), +- array('nickname' => $nickname)), +- ); +- $this->nav_menu($menu); +- } ++ function show_menu() ++ { ++ // action => array('prompt', 'title', $args) ++ $action = $this->trimmed('action'); ++ $nickname = $this->trimmed('nickname'); +hunk ./lib/gallery.php 148 +- function show_gallery($profile, $page, $display='list', $tag=NULL) { ++ $menu = ++ array('subscriptions' => ++ array( _('Subscriptions'), ++ _('Subscriptions'), ++ array('nickname' => $nickname)), ++ 'subscribers' => ++ array( ++ _('Subscribers'), ++ _('Subscribers'), ++ array('nickname' => $nickname)), ++ ); ++ $this->nav_menu($menu); ++ } +hunk ./lib/gallery.php 162 +- $other = new Profile(); ++ function show_gallery($profile, $page, $display='list', $tag=null) ++ { ++ $other = new Profile(); +hunk ./lib/gallery.php 166 +- list($lst, $usr) = $this->fields(); ++ list($lst, $usr) = $this->fields(); +hunk ./lib/gallery.php 168 +- $per_page = ($display == 'list') ? PROFILES_PER_PAGE : AVATARS_PER_PAGE; ++ $per_page = ($display == 'list') ? PROFILES_PER_PAGE : AVATARS_PER_PAGE; +hunk ./lib/gallery.php 170 +- $offset = ($page-1)*$per_page; +- $limit = $per_page + 1; ++ $offset = ($page-1)*$per_page; ++ $limit = $per_page + 1; +hunk ./lib/gallery.php 173 +- if (common_config('db','type') == 'pgsql') { +- $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset; +- } else { +- $lim = ' LIMIT ' . $offset . ', ' . $limit; +- } ++ if (common_config('db', 'type') == 'pgsql') { ++ $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset; ++ } else { ++ $lim = ' LIMIT ' . $offset . ', ' . $limit; ++ } +hunk ./lib/gallery.php 179 +- # XXX: memcached results +- # FIXME: SQL injection on $tag ++ // XXX: memcached results ++ // FIXME: SQL injection on $tag +hunk ./lib/gallery.php 182 +- $other->query('SELECT profile.* ' . +- 'FROM profile JOIN subscription ' . +- 'ON profile.id = subscription.' . $lst . ' ' . +- (($tag) ? 'JOIN profile_tag ON (profile.id = profile_tag.tagged AND subscription.'.$usr.'= profile_tag.tagger) ' : '') . +- 'WHERE ' . $usr . ' = ' . $profile->id . ' ' . +- 'AND subscriber != subscribed ' . +- (($tag) ? 'AND profile_tag.tag= "' . $tag . '" ': '') . +- 'ORDER BY subscription.created DESC, profile.id DESC ' . +- $lim); ++ $other->query('SELECT profile.* ' . ++ 'FROM profile JOIN subscription ' . ++ 'ON profile.id = subscription.' . $lst . ' ' . ++ (($tag) ? 'JOIN profile_tag ON (profile.id = profile_tag.tagged AND subscription.'.$usr.'= profile_tag.tagger) ' : '') . ++ 'WHERE ' . $usr . ' = ' . $profile->id . ' ' . ++ 'AND subscriber != subscribed ' . ++ (($tag) ? 'AND profile_tag.tag= "' . $tag . '" ': '') . ++ 'ORDER BY subscription.created DESC, profile.id DESC ' . ++ $lim); +hunk ./lib/gallery.php 192 +- if ($display == 'list') { ++ if ($display == 'list') { +hunk ./lib/gallery.php 194 +- $profile_list = new $cls($other, $profile, $this->trimmed('action')); +- $cnt = $profile_list->show_list(); +- } else { +- $cnt = $this->icon_list($other); +- } ++ $profile_list = new $cls($other, $profile, $this->trimmed('action')); ++ $cnt = $profile_list->show_list(); ++ } else { ++ $cnt = $this->icon_list($other); ++ } +hunk ./lib/gallery.php 200 +- # For building the pagination URLs ++ // For building the pagination URLs +hunk ./lib/gallery.php 202 +- $args = array('nickname' => $profile->nickname); ++ $args = array('nickname' => $profile->nickname); +hunk ./lib/gallery.php 204 +- if ($display != 'list') { +- $args['display'] = $display; +- } ++ if ($display != 'list') { ++ $args['display'] = $display; ++ } +hunk ./lib/gallery.php 208 +- common_pagination($page > 1, +- $cnt > $per_page, +- $page, +- $this->trimmed('action'), +- $args); +- } ++ common_pagination($page > 1, ++ $cnt > $per_page, ++ $page, ++ $this->trimmed('action'), ++ $args); ++ } +hunk ./lib/gallery.php 215 +- function profile_list_class() { ++ function profile_list_class() ++ { +hunk ./lib/gallery.php 220 +- function icon_list($other) { ++ function icon_list($other) ++ { ++ common_element_start('ul', $this->div_class()); +hunk ./lib/gallery.php 224 +- common_element_start('ul', $this->div_class()); ++ $cnt = 0; +hunk ./lib/gallery.php 226 +- $cnt = 0; ++ while ($other->fetch()) { +hunk ./lib/gallery.php 228 +- while ($other->fetch()) { ++ $cnt++; +hunk ./lib/gallery.php 230 +- $cnt++; ++ if ($cnt > AVATARS_PER_PAGE) { ++ break; ++ } +hunk ./lib/gallery.php 234 +- if ($cnt > AVATARS_PER_PAGE) { +- break; +- } ++ common_element_start('li'); +hunk ./lib/gallery.php 236 +- common_element_start('li'); ++ common_element_start('a', array('title' => ($other->fullname) ? ++ $other->fullname : ++ $other->nickname, ++ 'href' => $other->profileurl, ++ 'class' => 'subscription')); ++ $avatar = $other->getAvatar(AVATAR_STREAM_SIZE); ++ common_element('img', ++ array('src' => ++ (($avatar) ? common_avatar_display_url($avatar) : ++ common_default_avatar(AVATAR_STREAM_SIZE)), ++ 'width' => AVATAR_STREAM_SIZE, ++ 'height' => AVATAR_STREAM_SIZE, ++ 'class' => 'avatar stream', ++ 'alt' => ($other->fullname) ? ++ $other->fullname : ++ $other->nickname)); ++ common_element_end('a'); +hunk ./lib/gallery.php 254 +- common_element_start('a', array('title' => ($other->fullname) ? +- $other->fullname : +- $other->nickname, +- 'href' => $other->profileurl, +- 'class' => 'subscription')); +- $avatar = $other->getAvatar(AVATAR_STREAM_SIZE); +- common_element('img', +- array('src' => +- (($avatar) ? common_avatar_display_url($avatar) : +- common_default_avatar(AVATAR_STREAM_SIZE)), +- 'width' => AVATAR_STREAM_SIZE, +- 'height' => AVATAR_STREAM_SIZE, +- 'class' => 'avatar stream', +- 'alt' => ($other->fullname) ? +- $other->fullname : +- $other->nickname)); +- common_element_end('a'); ++ // XXX: subscribe form here +hunk ./lib/gallery.php 256 +- # XXX: subscribe form here ++ common_element_end('li'); ++ } +hunk ./lib/gallery.php 259 +- common_element_end('li'); +- } ++ common_element_end('ul'); +hunk ./lib/gallery.php 261 +- common_element_end('ul'); +- +- return $cnt; +- } ++ return $cnt; ++ } +hunk ./lib/gallery.php 264 +- function gallery_type() { +- return NULL; +- } ++ function gallery_type() ++ { ++ return null; ++ } +hunk ./lib/gallery.php 269 +- function get_instructions(&$profile) { +- return NULL; +- } ++ function get_instructions(&$profile) ++ { ++ return null; ++ } +hunk ./lib/gallery.php 274 +- function fields() { +- return NULL; +- } ++ function fields() ++ { ++ return null; ++ } +hunk ./lib/gallery.php 279 +- function div_class() { +- return ''; +- } ++ function div_class() ++ { ++ return ''; ++ } +hunk ./lib/gallery.php 284 +- function display_links($profile, $page, $display) { +- $tag = $this->trimmed('tag'); ++ function display_links($profile, $page, $display) ++ { ++ $tag = $this->trimmed('tag'); +hunk ./lib/gallery.php 288 +- common_element_start('dl', array('id'=>'subscriptions_nav')); +- common_element('dt', null, _('Subscriptions navigation')); +- common_element_start('dd'); +- common_element_start('ul', array('class'=>'nav')); ++ common_element_start('dl', array('id'=>'subscriptions_nav')); ++ common_element('dt', null, _('Subscriptions navigation')); ++ common_element_start('dd'); ++ common_element_start('ul', array('class'=>'nav')); +hunk ./lib/gallery.php 293 +- switch ($display) { +- case 'list': +- common_element('li', array('class'=>'child_1'), _('List')); +- common_element_start('li'); +- $url_args = array('display' => 'icons', +- 'nickname' => $profile->nickname, +- 'page' => 1 + floor((($page - 1) * PROFILES_PER_PAGE) / AVATARS_PER_PAGE)); +- if ($tag) { +- $url_args['tag'] = $tag; +- } +- $url = common_local_url($this->trimmed('action'), $url_args); +- common_element('a', array('href' => $url), +- _('Icons')); +- common_element_end('li'); +- break; +- default: +- common_element_start('li', array('class'=>'child_1')); +- $url_args = array('nickname' => $profile->nickname, +- 'page' => 1 + floor((($page - 1) * AVATARS_PER_PAGE) / PROFILES_PER_PAGE)); +- if ($tag) { +- $url_args['tag'] = $tag; +- } +- $url = common_local_url($this->trimmed('action'), $url_args); +- common_element('a', array('href' => $url), +- _('List')); +- common_element_end('li'); +- common_element('li', NULL, _('Icons')); +- break; +- } ++ switch ($display) { ++ case 'list': ++ common_element('li', array('class'=>'child_1'), _('List')); ++ common_element_start('li'); ++ $url_args = array('display' => 'icons', ++ 'nickname' => $profile->nickname, ++ 'page' => 1 + floor((($page - 1) * PROFILES_PER_PAGE) / AVATARS_PER_PAGE)); ++ if ($tag) { ++ $url_args['tag'] = $tag; ++ } ++ $url = common_local_url($this->trimmed('action'), $url_args); ++ common_element('a', array('href' => $url), ++ _('Icons')); ++ common_element_end('li'); ++ break; ++ default: ++ common_element_start('li', array('class'=>'child_1')); ++ $url_args = array('nickname' => $profile->nickname, ++ 'page' => 1 + floor((($page - 1) * AVATARS_PER_PAGE) / PROFILES_PER_PAGE)); ++ if ($tag) { ++ $url_args['tag'] = $tag; ++ } ++ $url = common_local_url($this->trimmed('action'), $url_args); ++ common_element('a', array('href' => $url), ++ _('List')); ++ common_element_end('li'); ++ common_element('li', null, _('Icons')); ++ break; ++ } +hunk ./lib/gallery.php 323 +- common_element_end('ul'); +- common_element_end('dd'); +- common_element_end('dl'); +- } ++ common_element_end('ul'); ++ common_element_end('dd'); ++ common_element_end('dl'); ++ } +hunk ./lib/gallery.php 328 +- # Get list of tags we tagged other users with ++ // Get list of tags we tagged other users with +hunk ./lib/gallery.php 330 +- function get_all_tags($profile, $lst, $usr) { +- $profile_tag = new Notice_tag(); +- $profile_tag->query('SELECT DISTINCT(tag) ' . +- 'FROM profile_tag, subscription ' . +- 'WHERE tagger = ' . $profile->id . ' ' . +- 'AND ' . $usr . ' = ' . $profile->id . ' ' . +- 'AND ' . $lst . ' = tagged ' . +- 'AND tagger != tagged'); +- $tags = array(); +- while ($profile_tag->fetch()) { +- $tags[] = $profile_tag->tag; +- } +- $profile_tag->free(); +- return $tags; +- } ++ function get_all_tags($profile, $lst, $usr) ++ { ++ $profile_tag = new Notice_tag(); ++ $profile_tag->query('SELECT DISTINCT(tag) ' . ++ 'FROM profile_tag, subscription ' . ++ 'WHERE tagger = ' . $profile->id . ' ' . ++ 'AND ' . $usr . ' = ' . $profile->id . ' ' . ++ 'AND ' . $lst . ' = tagged ' . ++ 'AND tagger != tagged'); ++ $tags = array(); ++ while ($profile_tag->fetch()) { ++ $tags[] = $profile_tag->tag; ++ } ++ $profile_tag->free(); ++ return $tags; ++ } diff --git a/lib/gallery.php b/lib/gallery.php index 0dd351bab5..34b58518c6 100644 --- a/lib/gallery.php +++ b/lib/gallery.php @@ -1,6 +1,5 @@ . */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} -require_once(INSTALLDIR.'/lib/profilelist.php'); +require_once INSTALLDIR.'/lib/profilelist.php'; -# 10x8 +// 10x8 define('AVATARS_PER_PAGE', 80); -class GalleryAction extends Action { +class GalleryAction extends Action +{ + function is_readonly() + { + return true; + } - function is_readonly() { - return true; - } + function handle($args) + { + parent::handle($args); - function handle($args) { - parent::handle($args); + // Post from the tag dropdown; redirect to a GET - # Post from the tag dropdown; redirect to a GET + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + common_redirect($this->self_url(), 307); + } - if ($_SERVER['REQUEST_METHOD'] == 'POST') { - common_redirect($this->self_url(), 307); - } + $nickname = common_canonical_nickname($this->arg('nickname')); - $nickname = common_canonical_nickname($this->arg('nickname')); - $user = User::staticGet('nickname', $nickname); + $user = User::staticGet('nickname', $nickname); - if (!$user) { - $this->no_such_user(); - return; - } + if (!$user) { + $this->no_such_user(); + return; + } - $profile = $user->getProfile(); + $profile = $user->getProfile(); - if (!$profile) { - $this->server_error(_('User without matching profile in system.')); - return; - } + if (!$profile) { + $this->server_error(_('User without matching profile in system.')); + return; + } - $page = $this->arg('page'); + $page = $this->arg('page'); - if (!$page) { - $page = 1; - } + if (!$page) { + $page = 1; + } - $display = $this->arg('display'); + $display = $this->arg('display'); - if (!$display) { - $display = 'list'; - } + if (!$display) { + $display = 'list'; + } - $tag = $this->arg('tag'); + $tag = $this->arg('tag'); - common_show_header($profile->nickname . ": " . $this->gallery_type(), - NULL, $profile, - array($this, 'show_top')); + common_show_header($profile->nickname . ": " . $this->gallery_type(), + null, $profile, + array($this, 'show_top')); - $this->display_links($profile, $page, $display); - $this->show_tags_dropdown($profile); + $this->display_links($profile, $page, $display); + $this->show_tags_dropdown($profile); - $this->show_gallery($profile, $page, $display, $tag); - common_show_footer(); - } + $this->show_gallery($profile, $page, $display, $tag); + common_show_footer(); + } - function no_such_user() { - $this->client_error(_('No such user.')); - } + function no_such_user() + { + $this->client_error(_('No such user.')); + } - function show_tags_dropdown($profile) { - $tag = $this->trimmed('tag'); - list($lst, $usr) = $this->fields(); - $tags = $this->get_all_tags($profile, $lst, $usr); - $content = array(); - foreach ($tags as $t) { - $content[$t] = $t; - } - if ($tags) { - common_element_start('dl', array('id'=>'filter_tags')); - common_element('dt', null, _('Filter tags')); - common_element_start('dd'); - common_element_start('ul'); - common_element_start('li', array('id'=>'filter_tags_all', 'class'=>'child_1')); - common_element('a', array('href' => common_local_url($this->trimmed('action'), - array('nickname' => $profile->nickname))), - _('All')); - common_element_end('li'); - common_element_start('li', array('id'=>'filter_tags_item')); - common_element_start('form', array('name' => 'bytag', 'id' => 'bytag', 'method' => 'post')); - common_dropdown('tag', _('Tag'), $content, - _('Choose a tag to narrow list'), FALSE, $tag); - common_submit('go', _('Go')); - common_element_end('form'); - common_element_end('li'); - common_element_end('ul'); - common_element_end('dd'); - common_element_end('dl'); - } - } + function show_tags_dropdown($profile) + { + $tag = $this->trimmed('tag'); - function show_top($profile) { - common_element('div', 'instructions', - $this->get_instructions($profile)); + list($lst, $usr) = $this->fields(); + + $tags = $this->get_all_tags($profile, $lst, $usr); + + $content = array(); + + foreach ($tags as $t) { + $content[$t] = $t; + } + if ($tags) { + common_element_start('dl', array('id'=>'filter_tags')); + common_element('dt', null, _('Filter tags')); + common_element_start('dd'); + common_element_start('ul'); + common_element_start('li', array('id' => 'filter_tags_all', + 'class' => 'child_1')); + common_element('a', + array('href' => + common_local_url($this->trimmed('action'), + array('nickname' => + $profile->nickname))), + _('All')); + common_element_end('li'); + common_element_start('li', array('id'=>'filter_tags_item')); + common_element_start('form', array('name' => 'bytag', + 'id' => 'bytag', + 'method' => 'post')); + common_dropdown('tag', _('Tag'), $content, + _('Choose a tag to narrow list'), false, $tag); + common_submit('go', _('Go')); + common_element_end('form'); + common_element_end('li'); + common_element_end('ul'); + common_element_end('dd'); + common_element_end('dl'); + } + } + + function show_top($profile) + { + common_element('div', 'instructions', + $this->get_instructions($profile)); $this->show_menu(); - } + } - function show_menu() { - # action => array('prompt', 'title', $args) - $action = $this->trimmed('action'); - $nickname = $this->trimmed('nickname'); - $menu = - array('subscriptions' => - array( _('Subscriptions'), - _('Subscriptions'), + function show_menu() + { + // action => array('prompt', 'title', $args) + $action = $this->trimmed('action'); + $nickname = $this->trimmed('nickname'); + + $menu = + array('subscriptions' => + array( _('Subscriptions'), + _('Subscriptions'), + array('nickname' => $nickname)), + 'subscribers' => + array( + _('Subscribers'), + _('Subscribers'), array('nickname' => $nickname)), - 'subscribers' => - array( - _('Subscribers'), - _('Subscribers'), - array('nickname' => $nickname)), - ); - $this->nav_menu($menu); - } + ); + $this->nav_menu($menu); + } - function show_gallery($profile, $page, $display='list', $tag=NULL) { + function show_gallery($profile, $page, $display='list', $tag=null) + { + $other = new Profile(); - $other = new Profile(); + list($lst, $usr) = $this->fields(); - list($lst, $usr) = $this->fields(); + $per_page = ($display == 'list') ? PROFILES_PER_PAGE : AVATARS_PER_PAGE; - $per_page = ($display == 'list') ? PROFILES_PER_PAGE : AVATARS_PER_PAGE; + $offset = ($page-1)*$per_page; + $limit = $per_page + 1; - $offset = ($page-1)*$per_page; - $limit = $per_page + 1; + if (common_config('db', 'type') == 'pgsql') { + $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $lim = ' LIMIT ' . $offset . ', ' . $limit; + } - if (common_config('db','type') == 'pgsql') { - $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset; - } else { - $lim = ' LIMIT ' . $offset . ', ' . $limit; - } + // XXX: memcached results + // FIXME: SQL injection on $tag - # XXX: memcached results - # FIXME: SQL injection on $tag + $other->query('SELECT profile.* ' . + 'FROM profile JOIN subscription ' . + 'ON profile.id = subscription.' . $lst . ' ' . + (($tag) ? 'JOIN profile_tag ON (profile.id = profile_tag.tagged AND subscription.'.$usr.'= profile_tag.tagger) ' : '') . + 'WHERE ' . $usr . ' = ' . $profile->id . ' ' . + 'AND subscriber != subscribed ' . + (($tag) ? 'AND profile_tag.tag= "' . $tag . '" ': '') . + 'ORDER BY subscription.created DESC, profile.id DESC ' . + $lim); - $other->query('SELECT profile.* ' . - 'FROM profile JOIN subscription ' . - 'ON profile.id = subscription.' . $lst . ' ' . - (($tag) ? 'JOIN profile_tag ON (profile.id = profile_tag.tagged AND subscription.'.$usr.'= profile_tag.tagger) ' : '') . - 'WHERE ' . $usr . ' = ' . $profile->id . ' ' . - 'AND subscriber != subscribed ' . - (($tag) ? 'AND profile_tag.tag= "' . $tag . '" ': '') . - 'ORDER BY subscription.created DESC, profile.id DESC ' . - $lim); - - if ($display == 'list') { + if ($display == 'list') { $cls = $this->profile_list_class(); - $profile_list = new $cls($other, $profile, $this->trimmed('action')); - $cnt = $profile_list->show_list(); - } else { - $cnt = $this->icon_list($other); - } + $profile_list = new $cls($other, $profile, $this->trimmed('action')); + $cnt = $profile_list->show_list(); + } else { + $cnt = $this->icon_list($other); + } - # For building the pagination URLs + // For building the pagination URLs - $args = array('nickname' => $profile->nickname); + $args = array('nickname' => $profile->nickname); - if ($display != 'list') { - $args['display'] = $display; - } + if ($display != 'list') { + $args['display'] = $display; + } - common_pagination($page > 1, - $cnt > $per_page, - $page, - $this->trimmed('action'), - $args); - } + common_pagination($page > 1, + $cnt > $per_page, + $page, + $this->trimmed('action'), + $args); + } - function profile_list_class() { + function profile_list_class() + { return 'ProfileList'; } - function icon_list($other) { + function icon_list($other) + { + common_element_start('ul', $this->div_class()); - common_element_start('ul', $this->div_class()); + $cnt = 0; - $cnt = 0; + while ($other->fetch()) { - while ($other->fetch()) { + $cnt++; - $cnt++; + if ($cnt > AVATARS_PER_PAGE) { + break; + } - if ($cnt > AVATARS_PER_PAGE) { - break; - } + common_element_start('li'); - common_element_start('li'); + common_element_start('a', array('title' => ($other->fullname) ? + $other->fullname : + $other->nickname, + 'href' => $other->profileurl, + 'class' => 'subscription')); + $avatar = $other->getAvatar(AVATAR_STREAM_SIZE); + common_element('img', + array('src' => + (($avatar) ? common_avatar_display_url($avatar) : + common_default_avatar(AVATAR_STREAM_SIZE)), + 'width' => AVATAR_STREAM_SIZE, + 'height' => AVATAR_STREAM_SIZE, + 'class' => 'avatar stream', + 'alt' => ($other->fullname) ? + $other->fullname : + $other->nickname)); + common_element_end('a'); - common_element_start('a', array('title' => ($other->fullname) ? - $other->fullname : - $other->nickname, - 'href' => $other->profileurl, - 'class' => 'subscription')); - $avatar = $other->getAvatar(AVATAR_STREAM_SIZE); - common_element('img', - array('src' => - (($avatar) ? common_avatar_display_url($avatar) : - common_default_avatar(AVATAR_STREAM_SIZE)), - 'width' => AVATAR_STREAM_SIZE, - 'height' => AVATAR_STREAM_SIZE, - 'class' => 'avatar stream', - 'alt' => ($other->fullname) ? - $other->fullname : - $other->nickname)); - common_element_end('a'); + // XXX: subscribe form here - # XXX: subscribe form here + common_element_end('li'); + } - common_element_end('li'); - } + common_element_end('ul'); - common_element_end('ul'); + return $cnt; + } - return $cnt; - } + function gallery_type() + { + return null; + } - function gallery_type() { - return NULL; - } + function get_instructions(&$profile) + { + return null; + } - function get_instructions(&$profile) { - return NULL; - } + function fields() + { + return null; + } - function fields() { - return NULL; - } + function div_class() + { + return ''; + } - function div_class() { - return ''; - } + function display_links($profile, $page, $display) + { + $tag = $this->trimmed('tag'); - function display_links($profile, $page, $display) { - $tag = $this->trimmed('tag'); + common_element_start('dl', array('id'=>'subscriptions_nav')); + common_element('dt', null, _('Subscriptions navigation')); + common_element_start('dd'); + common_element_start('ul', array('class'=>'nav')); - common_element_start('dl', array('id'=>'subscriptions_nav')); - common_element('dt', null, _('Subscriptions navigation')); - common_element_start('dd'); - common_element_start('ul', array('class'=>'nav')); + switch ($display) { + case 'list': + common_element('li', array('class'=>'child_1'), _('List')); + common_element_start('li'); + $url_args = array('display' => 'icons', + 'nickname' => $profile->nickname, + 'page' => 1 + floor((($page - 1) * PROFILES_PER_PAGE) / AVATARS_PER_PAGE)); + if ($tag) { + $url_args['tag'] = $tag; + } + $url = common_local_url($this->trimmed('action'), $url_args); + common_element('a', array('href' => $url), + _('Icons')); + common_element_end('li'); + break; + default: + common_element_start('li', array('class'=>'child_1')); + $url_args = array('nickname' => $profile->nickname, + 'page' => 1 + floor((($page - 1) * AVATARS_PER_PAGE) / PROFILES_PER_PAGE)); + if ($tag) { + $url_args['tag'] = $tag; + } + $url = common_local_url($this->trimmed('action'), $url_args); + common_element('a', array('href' => $url), + _('List')); + common_element_end('li'); + common_element('li', null, _('Icons')); + break; + } - switch ($display) { - case 'list': - common_element('li', array('class'=>'child_1'), _('List')); - common_element_start('li'); - $url_args = array('display' => 'icons', - 'nickname' => $profile->nickname, - 'page' => 1 + floor((($page - 1) * PROFILES_PER_PAGE) / AVATARS_PER_PAGE)); - if ($tag) { - $url_args['tag'] = $tag; - } - $url = common_local_url($this->trimmed('action'), $url_args); - common_element('a', array('href' => $url), - _('Icons')); - common_element_end('li'); - break; - default: - common_element_start('li', array('class'=>'child_1')); - $url_args = array('nickname' => $profile->nickname, - 'page' => 1 + floor((($page - 1) * AVATARS_PER_PAGE) / PROFILES_PER_PAGE)); - if ($tag) { - $url_args['tag'] = $tag; - } - $url = common_local_url($this->trimmed('action'), $url_args); - common_element('a', array('href' => $url), - _('List')); - common_element_end('li'); - common_element('li', NULL, _('Icons')); - break; - } + common_element_end('ul'); + common_element_end('dd'); + common_element_end('dl'); + } - common_element_end('ul'); - common_element_end('dd'); - common_element_end('dl'); - } + // Get list of tags we tagged other users with - # Get list of tags we tagged other users with - - function get_all_tags($profile, $lst, $usr) { - $profile_tag = new Notice_tag(); - $profile_tag->query('SELECT DISTINCT(tag) ' . - 'FROM profile_tag, subscription ' . - 'WHERE tagger = ' . $profile->id . ' ' . - 'AND ' . $usr . ' = ' . $profile->id . ' ' . - 'AND ' . $lst . ' = tagged ' . - 'AND tagger != tagged'); - $tags = array(); - while ($profile_tag->fetch()) { - $tags[] = $profile_tag->tag; - } - $profile_tag->free(); - return $tags; - } + function get_all_tags($profile, $lst, $usr) + { + $profile_tag = new Notice_tag(); + $profile_tag->query('SELECT DISTINCT(tag) ' . + 'FROM profile_tag, subscription ' . + 'WHERE tagger = ' . $profile->id . ' ' . + 'AND ' . $usr . ' = ' . $profile->id . ' ' . + 'AND ' . $lst . ' = tagged ' . + 'AND tagger != tagged'); + $tags = array(); + while ($profile_tag->fetch()) { + $tags[] = $profile_tag->tag; + } + $profile_tag->free(); + return $tags; + } } \ No newline at end of file