We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit edbc0c66 authored by Evan Prodromou's avatar Evan Prodromou

replace all tabs with four spaces

The PEAR coding standards decree: no tabs, but indent by four spaces.
I've done a global search-and-replace on all tabs, replacing them by
four spaces. This is a huge change, but it will go a long way to
getting us towards phpcs-compliance. And that means better code
readability, and that means more participation.

darcs-hash:20081223191907-84dde-21e8efe210e6d5d54e935a22d0cee5c7bbfc007d.gz
parent 17ece077
......@@ -49,4 +49,14 @@ Evan Prodromou <evan@prodromou.name>**20081223173330]
[bring lib/noticelist.php into line with PEAR code standards
Evan Prodromou <evan@prodromou.name>**20081223190851]
[incorrect label on notice list file comment
Evan Prodromou <evan@prodromou.name>**20081223191430]
\ No newline at end of file
Evan Prodromou <evan@prodromou.name>**20081223191430]
[replace all tabs with four spaces
Evan Prodromou <evan@prodromou.name>**20081223191907
The PEAR coding standards decree: no tabs, but indent by four spaces.
I've done a global search-and-replace on all tabs, replacing them by
four spaces. This is a huge change, but it will go a long way to
getting us towards phpcs-compliance. And that means better code
readability, and that means more participation.
]
\ No newline at end of file
......@@ -22,21 +22,21 @@ if (!defined('LACONICA')) { exit(1); }
require_once(INSTALLDIR.'/lib/omb.php');
class AccesstokenAction extends Action {
function handle($args) {
parent::handle($args);
try {
common_debug('getting request from env variables', __FILE__);
common_remove_magic_from_request();
$req = OAuthRequest::from_request();
common_debug('getting a server', __FILE__);
$server = omb_oauth_server();
common_debug('fetching the access token', __FILE__);
$token = $server->fetch_access_token($req);
common_debug('got this token: "'.print_r($token,TRUE).'"', __FILE__);
common_debug('printing the access token', __FILE__);
print $token;
} catch (OAuthException $e) {
common_server_error($e->getMessage());
}
}
function handle($args) {
parent::handle($args);
try {
common_debug('getting request from env variables', __FILE__);
common_remove_magic_from_request();
$req = OAuthRequest::from_request();
common_debug('getting a server', __FILE__);
$server = omb_oauth_server();
common_debug('fetching the access token', __FILE__);
$token = $server->fetch_access_token($req);
common_debug('got this token: "'.print_r($token,TRUE).'"', __FILE__);
common_debug('printing the access token', __FILE__);
print $token;
} catch (OAuthException $e) {
common_server_error($e->getMessage());
}
}
}
......@@ -23,71 +23,71 @@ require_once(INSTALLDIR.'/actions/showstream.php');
class AllAction extends StreamAction {
function handle($args) {
function handle($args) {
parent::handle($args);
parent::handle($args);
$nickname = common_canonical_nickname($this->arg('nickname'));
$user = User::staticGet('nickname', $nickname);
$nickname = common_canonical_nickname($this->arg('nickname'));
$user = User::staticGet('nickname', $nickname);
if (!$user) {
$this->client_error(_('No such user.'));
return;
}
if (!$user) {
$this->client_error(_('No such user.'));
return;
}
$profile = $user->getProfile();
$profile = $user->getProfile();
if (!$profile) {
common_server_error(_('User has no profile.'));
return;
}
if (!$profile) {
common_server_error(_('User has no profile.'));
return;
}
# Looks like we're good; show the header
# Looks like we're good; show the header
common_show_header(sprintf(_("%s and friends"), $profile->nickname),
array($this, 'show_header'), $user,
array($this, 'show_top'));
common_show_header(sprintf(_("%s and friends"), $profile->nickname),
array($this, 'show_header'), $user,
array($this, 'show_top'));
$this->show_notices($user);
$this->show_notices($user);
common_show_footer();
}
common_show_footer();
}
function show_header($user) {
common_element('link', array('rel' => 'alternate',
'href' => common_local_url('allrss', array('nickname' =>
$user->nickname)),
'type' => 'application/rss+xml',
'title' => sprintf(_('Feed for friends of %s'), $user->nickname)));
}
function show_header($user) {
common_element('link', array('rel' => 'alternate',
'href' => common_local_url('allrss', array('nickname' =>
$user->nickname)),
'type' => 'application/rss+xml',
'title' => sprintf(_('Feed for friends of %s'), $user->nickname)));
}
function show_top($user) {
$cur = common_current_user();
function show_top($user) {
$cur = common_current_user();
if ($cur && $cur->id == $user->id) {
common_notice_form('all');
}
if ($cur && $cur->id == $user->id) {
common_notice_form('all');
}
$this->views_menu();
$this->views_menu();
$this->show_feeds_list(array(0=>array('href'=>common_local_url('allrss', array('nickname' => $user->nickname)),
'type' => 'rss',
'version' => 'RSS 1.0',
'item' => 'allrss')));
}
$this->show_feeds_list(array(0=>array('href'=>common_local_url('allrss', array('nickname' => $user->nickname)),
'type' => 'rss',
'version' => 'RSS 1.0',
'item' => 'allrss')));
}
function show_notices($user) {
function show_notices($user) {
$page = $this->trimmed('page');
if (!$page) {
$page = 1;
}
$page = $this->trimmed('page');
if (!$page) {
$page = 1;
}
$notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
$notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
$cnt = $this->show_notice_list($notice);
common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
$page, 'all', array('nickname' => $user->nickname));
}
common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
$page, 'all', array('nickname' => $user->nickname));
}
}
......@@ -25,53 +25,53 @@ require_once(INSTALLDIR.'/lib/rssaction.php');
class AllrssAction extends Rss10Action {
var $user = NULL;
var $user = NULL;
function init() {
$nickname = $this->trimmed('nickname');
$this->user = User::staticGet('nickname', $nickname);
function init() {
$nickname = $this->trimmed('nickname');
$this->user = User::staticGet('nickname', $nickname);
if (!$this->user) {
common_user_error(_('No such user.'));
return false;
} else {
return true;
}
}
if (!$this->user) {
common_user_error(_('No such user.'));
return false;
} else {
return true;
}
}
function get_notices($limit=0) {
function get_notices($limit=0) {
$user = $this->user;
$notice = $user->noticesWithFriends(0, $limit);
while ($notice->fetch()) {
$notices[] = clone($notice);
}
$user = $this->user;
$notice = $user->noticesWithFriends(0, $limit);
while ($notice->fetch()) {
$notices[] = clone($notice);
}
return $notices;
}
return $notices;
}
function get_channel() {
$user = $this->user;
$c = array('url' => common_local_url('allrss',
array('nickname' =>
$user->nickname)),
'title' => sprintf(_('%s and friends'), $user->nickname),
'link' => common_local_url('all',
array('nickname' =>
$user->nickname)),
'description' => sprintf(_('Feed for friends of %s'), $user->nickname));
return $c;
}
function get_channel() {
$user = $this->user;
$c = array('url' => common_local_url('allrss',
array('nickname' =>
$user->nickname)),
'title' => sprintf(_('%s and friends'), $user->nickname),
'link' => common_local_url('all',
array('nickname' =>
$user->nickname)),
'description' => sprintf(_('Feed for friends of %s'), $user->nickname));
return $c;
}
function get_image() {
$user = $this->user;
$profile = $user->getProfile();
if (!$profile) {
return NULL;
}
$avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
return ($avatar) ? $avatar->url : NULL;
}
function get_image() {
$user = $this->user;
$profile = $user->getProfile();
if (!$profile) {
return NULL;
}
$avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
return ($avatar) ? $avatar->url : NULL;
}
}
\ No newline at end of file
......@@ -10,115 +10,115 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('LACONICA')) { exit(1); }
class ApiAction extends Action {
var $user;
var $content_type;
var $api_arg;
var $api_method;
var $api_action;
function handle($args) {
parent::handle($args);
$this->api_action = $this->arg('apiaction');
$method = $this->arg('method');
$argument = $this->arg('argument');
if (isset($argument)) {
$cmdext = explode('.', $argument);
$this->api_arg = $cmdext[0];
$this->api_method = $method;
$this->content_type = strtolower($cmdext[1]);
} else {
# Requested format / content-type will be an extension on the method
$cmdext = explode('.', $method);
$this->api_method = $cmdext[0];
$this->content_type = strtolower($cmdext[1]);
}
if ($this->requires_auth()) {
if (!isset($_SERVER['PHP_AUTH_USER'])) {
# This header makes basic auth go
header('WWW-Authenticate: Basic realm="Laconica API"');
# If the user hits cancel -- bam!
$this->show_basic_auth_error();
} else {
$nickname = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
$user = common_check_user($nickname, $password);
if ($user) {
$this->user = $user;
$this->process_command();
} else {
# basic authentication failed
$this->show_basic_auth_error();
}
}
} else {
# Look for the user in the session
if (common_logged_in()) {
$this->user = common_current_user();
}
$this->process_command();
}
}
function process_command() {
$action = "twitapi$this->api_action";
$actionfile = INSTALLDIR."/actions/$action.php";
if (file_exists($actionfile)) {
require_once($actionfile);
$action_class = ucfirst($action)."Action";
$action_obj = new $action_class();
var $user;
var $content_type;
var $api_arg;
var $api_method;
var $api_action;
function handle($args) {
parent::handle($args);
$this->api_action = $this->arg('apiaction');
$method = $this->arg('method');
$argument = $this->arg('argument');
if (isset($argument)) {
$cmdext = explode('.', $argument);
$this->api_arg = $cmdext[0];
$this->api_method = $method;
$this->content_type = strtolower($cmdext[1]);
} else {
# Requested format / content-type will be an extension on the method
$cmdext = explode('.', $method);
$this->api_method = $cmdext[0];
$this->content_type = strtolower($cmdext[1]);
}
if ($this->requires_auth()) {
if (!isset($_SERVER['PHP_AUTH_USER'])) {
# This header makes basic auth go
header('WWW-Authenticate: Basic realm="Laconica API"');
# If the user hits cancel -- bam!
$this->show_basic_auth_error();
} else {
$nickname = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
$user = common_check_user($nickname, $password);
if ($user) {
$this->user = $user;
$this->process_command();
} else {
# basic authentication failed
$this->show_basic_auth_error();
}
}
} else {
# Look for the user in the session
if (common_logged_in()) {
$this->user = common_current_user();
}
$this->process_command();
}
}
function process_command() {
$action = "twitapi$this->api_action";
$actionfile = INSTALLDIR."/actions/$action.php";
if (file_exists($actionfile)) {
require_once($actionfile);
$action_class = ucfirst($action)."Action";
$action_obj = new $action_class();
if (!$action_obj->prepare($this->args)) {
return;
}
if (method_exists($action_obj, $this->api_method)) {
$apidata = array( 'content-type' => $this->content_type,
'api_method' => $this->api_method,
'api_arg' => $this->api_arg,
'user' => $this->user);
call_user_func(array($action_obj, $this->api_method), $_REQUEST, $apidata);
} else {
common_user_error("API method not found!", $code=404);
}
} else {
common_user_error("API method not found!", $code=404);
}
}
# Whitelist of API methods that don't need authentication
function requires_auth() {
static $noauth = array( 'statuses/public_timeline',
'statuses/show',
'users/show',
'help/test',
'help/downtime_schedule');
static $bareauth = array('statuses/user_timeline',
'statuses/friends',
'statuses/followers',
'favorites/favorites');
if (method_exists($action_obj, $this->api_method)) {
$apidata = array( 'content-type' => $this->content_type,
'api_method' => $this->api_method,
'api_arg' => $this->api_arg,
'user' => $this->user);
call_user_func(array($action_obj, $this->api_method), $_REQUEST, $apidata);
} else {
common_user_error("API method not found!", $code=404);
}
} else {
common_user_error("API method not found!", $code=404);
}
}
# Whitelist of API methods that don't need authentication
function requires_auth() {
static $noauth = array( 'statuses/public_timeline',
'statuses/show',
'users/show',
'help/test',
'help/downtime_schedule');
static $bareauth = array('statuses/user_timeline',
'statuses/friends',
'statuses/followers',
'favorites/favorites');
# If the site is "private", all API methods need authentication
......@@ -126,71 +126,71 @@ class ApiAction extends Action {
return true;
}
$fullname = "$this->api_action/$this->api_method";
if (in_array($fullname, $bareauth)) {
# bareauth: only needs auth if without an argument
if ($this->api_arg) {
return false;
} else {
return true;
}
} else if (in_array($fullname, $noauth)) {
# noauth: never needs auth
return false;
} else {
# everybody else needs auth
return true;
}
}
function show_basic_auth_error() {
header('HTTP/1.1 401 Unauthorized');
$msg = 'Could not authenticate you.';
if ($this->content_type == 'xml') {
header('Content-Type: application/xml; charset=utf-8');
common_start_xml();