diff --git a/actions/all.php b/actions/all.php index 29a19afb6b..f1786462e1 100644 --- a/actions/all.php +++ b/actions/all.php @@ -1,5 +1,5 @@ . + * + * @category Actions + * @package Actions + * @author Evan Prodromou + * @author Mike Cochrane + * @author Robin Millette + * @author Adrian Lang + * @author Meitar Moscovitz + * @author Sarven Capadisli + * @author Craig Andrews + * @author Jeffery To + * @author Zach Copley + * @license GNU Affero General Public License http://www.gnu.org/licenses/ + * @link http://status.net */ -if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } +if (!defined('STATUSNET') && !defined('LACONICA')) { + exit(1); +} require_once INSTALLDIR.'/lib/personalgroupnav.php'; require_once INSTALLDIR.'/lib/noticelist.php'; @@ -43,8 +59,8 @@ class AllAction extends ProfileAction $this->notice = $this->user->noticesWithFriends(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); } - if($this->page > 1 && $this->notice->N == 0){ - $this->serverError(_('No such page'),$code=404); + if ($this->page > 1 && $this->notice->N == 0) { + $this->serverError(_('No such page'), $code = 404); } return true; @@ -73,20 +89,33 @@ class AllAction extends ProfileAction function getFeeds() { - return array(new Feed(Feed::RSS1, - common_local_url('allrss', array('nickname' => - $this->user->nickname)), - sprintf(_('Feed for friends of %s (RSS 1.0)'), $this->user->nickname)), - new Feed(Feed::RSS2, - common_local_url('api', array('apiaction' => 'statuses', - 'method' => 'friends_timeline', - 'argument' => $this->user->nickname.'.rss')), - sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->user->nickname)), - new Feed(Feed::ATOM, - common_local_url('api', array('apiaction' => 'statuses', - 'method' => 'friends_timeline', - 'argument' => $this->user->nickname.'.atom')), - sprintf(_('Feed for friends of %s (Atom)'), $this->user->nickname))); + return array( + new Feed(Feed::RSS1, + common_local_url( + 'allrss', array( + 'nickname' => + $this->user->nickname) + ), + sprintf(_('Feed for friends of %s (RSS 1.0)'), $this->user->nickname)), + new Feed(Feed::RSS2, + common_local_url( + 'api', array( + 'apiaction' => 'statuses', + 'method' => 'friends_timeline', + 'argument' => $this->user->nickname.'.rss' + ) + ), + sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->user->nickname)), + new Feed(Feed::ATOM, + common_local_url( + 'api', array( + 'apiaction' => 'statuses', + 'method' => 'friends_timeline', + 'argument' => $this->user->nickname.'.atom' + ) + ), + sprintf(_('Feed for friends of %s (Atom)'), $this->user->nickname)) + ); } function showLocalNav() @@ -106,8 +135,7 @@ class AllAction extends ProfileAction } else { $message .= sprintf(_('You can try to [nudge %s](../%s) from his profile or [post something to his or her attention](%%%%action.newnotice%%%%?status_textarea=%s).'), $this->user->nickname, $this->user->nickname, '@' . $this->user->nickname); } - } - else { + } else { $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to his or her attention.'), $this->user->nickname); } @@ -126,17 +154,19 @@ class AllAction extends ProfileAction $this->showEmptyListMessage(); } - $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, - $this->page, 'all', array('nickname' => $this->user->nickname)); + $this->pagination( + $this->page > 1, $cnt > NOTICES_PER_PAGE, + $this->page, 'all', array('nickname' => $this->user->nickname) + ); } function showPageTitle() { $user =& common_current_user(); if ($user && ($user->id == $this->user->id)) { - $this->element('h1', NULL, _("You and friends")); + $this->element('h1', null, _("You and friends")); } else { - $this->element('h1', NULL, sprintf(_('%s and friends'), $this->user->nickname)); + $this->element('h1', null, sprintf(_('%s and friends'), $this->user->nickname)); } } diff --git a/actions/api.php b/actions/api.php index c236378bcb..d570bb0174 100644 --- a/actions/api.php +++ b/actions/api.php @@ -1,5 +1,5 @@ . + * + * @category Actions + * @package Actions + * @author Evan Prodromou + * @author Brenda Wallace + * @author Jeffery To + * @author Robin Millette + * @author Tom Adams + * @author Christopher Vollick + * @author CiaranG + * @author Craig Andrews + * @author Gina Haeussge + * @author Mike Cochrane + * @author Sarven Capadisli + * @license GNU Affero General Public License http://www.gnu.org/licenses/ + * @link http://status.net */ -if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } +if (!defined('STATUSNET') && !defined('LACONICA')) { + exit(1); +} class ApiAction extends Action { @@ -37,7 +55,7 @@ class ApiAction extends Action $this->api_action = $this->arg('apiaction'); $method = $this->arg('method'); $argument = $this->arg('argument'); - $this->basic_auth_process_header(); + $this->basic_auth_process_header(); if (isset($argument)) { $cmdext = explode('.', $argument); @@ -46,7 +64,7 @@ class ApiAction extends Action $this->content_type = strtolower($cmdext[1]); } else { - # Requested format / content-type will be an extension on the method + //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]); @@ -55,10 +73,10 @@ class ApiAction extends Action if ($this->requires_auth()) { if (!isset($this->auth_user)) { - # This header makes basic auth go + //This header makes basic auth go header('WWW-Authenticate: Basic realm="StatusNet API"'); - # If the user hits cancel -- bam! + //If the user hits cancel -- bam! $this->show_basic_auth_error(); } else { $nickname = $this->auth_user; @@ -69,7 +87,7 @@ class ApiAction extends Action $this->user = $user; $this->process_command(); } else { - # basic authentication failed + //basic authentication failed list($proxy, $ip) = common_client_ip(); common_log(LOG_WARNING, "Failed API auth attempt, nickname = $nickname, proxy = $proxy, ip = $ip."); @@ -84,7 +102,7 @@ class ApiAction extends Action if ($user) { $this->user = $user; } - # Twitter doesn't throw an error if the user isn't found + //Twitter doesn't throw an error if the user isn't found } $this->process_command(); @@ -97,7 +115,7 @@ class ApiAction extends Action $actionfile = INSTALLDIR."/actions/$action.php"; if (file_exists($actionfile)) { - require_once($actionfile); + include_once $actionfile; $action_class = ucfirst($action)."Action"; $action_obj = new $action_class(); @@ -113,10 +131,10 @@ class ApiAction extends Action call_user_func(array($action_obj, $this->api_method), $_REQUEST, $apidata); } else { - $this->clientError("API method not found!", $code=404); + $this->clientError("API method not found!", $code = 404); } } else { - $this->clientError("API method not found!", $code=404); + $this->clientError("API method not found!", $code = 404); } } @@ -184,10 +202,11 @@ class ApiAction extends Action $user_id = $this->arg('user_id'); $screen_name = $this->arg('screen_name'); - if (empty($this->api_arg) && - empty($id) && - empty($user_id) && - empty($screen_name)) { + if (empty($this->api_arg) + && empty($id) + && empty($user_id) + && empty($screen_name) + ) { return true; } else { return false; @@ -208,35 +227,29 @@ class ApiAction extends Action function basic_auth_process_header() { - if(isset($_SERVER['AUTHORIZATION']) || isset($_SERVER['HTTP_AUTHORIZATION'])) - { - $authorization_header = isset($_SERVER['HTTP_AUTHORIZATION'])?$_SERVER['HTTP_AUTHORIZATION']:$_SERVER['AUTHORIZATION']; - } + if (isset($_SERVER['AUTHORIZATION']) || isset($_SERVER['HTTP_AUTHORIZATION'])) { + $authorization_header = isset($_SERVER['HTTP_AUTHORIZATION'])? $_SERVER['HTTP_AUTHORIZATION'] : $_SERVER['AUTHORIZATION']; + } - if(isset($_SERVER['PHP_AUTH_USER'])) - { - $this->auth_user = $_SERVER['PHP_AUTH_USER']; - $this->auth_pw = $_SERVER['PHP_AUTH_PW']; - } - elseif ( isset($authorization_header) && strstr(substr($authorization_header, 0,5),'Basic') ) - { - // decode the HTTP_AUTHORIZATION header on php-cgi server self - // on fcgid server the header name is AUTHORIZATION + if (isset($_SERVER['PHP_AUTH_USER'])) { + $this->auth_user = $_SERVER['PHP_AUTH_USER']; + $this->auth_pw = $_SERVER['PHP_AUTH_PW']; + } elseif (isset($authorization_header) && strstr(substr($authorization_header, 0, 5), 'Basic')) { + // decode the HTTP_AUTHORIZATION header on php-cgi server self + // on fcgid server the header name is AUTHORIZATION - $auth_hash = base64_decode( substr($authorization_header, 6) ); - list($this->auth_user, $this->auth_pw) = explode(':', $auth_hash); + $auth_hash = base64_decode(substr($authorization_header, 6)); + list($this->auth_user, $this->auth_pw) = explode(':', $auth_hash); - // set all to NULL on a empty basic auth request - if($this->auth_user == "") { - $this->auth_user = NULL; - $this->auth_pw = NULL; - } - } - else - { - $this->auth_user = NULL; - $this->auth_pw = NULL; - } + // set all to null on a empty basic auth request + if ($this->auth_user == "") { + $this->auth_user = null; + $this->auth_pw = null; + } + } else { + $this->auth_user = null; + $this->auth_pw = null; + } } function show_basic_auth_error() @@ -252,7 +265,7 @@ class ApiAction extends Action $this->element('request', null, $_SERVER['REQUEST_URI']); $this->elementEnd('hash'); $this->endXML(); - } else if ($this->content_type == 'json') { + } else if ($this->content_type == 'json') { header('Content-Type: application/json; charset=utf-8'); $error_array = array('error' => $msg, 'request' => $_SERVER['REQUEST_URI']); print(json_encode($error_array)); diff --git a/actions/finishremotesubscribe.php b/actions/finishremotesubscribe.php index 44abbfceb7..b1cec66f48 100644 --- a/actions/finishremotesubscribe.php +++ b/actions/finishremotesubscribe.php @@ -41,7 +41,7 @@ require_once INSTALLDIR.'/lib/omb.php'; * * @category Action * @package Laconica - * @author Evan Prodromou + * @author Evan Prodromou * @author Robin Millette * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 * @link http://laconi.ca/ @@ -143,67 +143,4 @@ class FinishremotesubscribeAction extends Action $user->nickname)), 303); } - - function add_avatar($profile, $url) - { - $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar'); - copy($url, $temp_filename); - $imagefile = new ImageFile($profile->id, $temp_filename); - $filename = Avatar::filename($profile->id, - image_type_to_extension($imagefile->type), - null, - common_timestamp()); - rename($temp_filename, Avatar::path($filename)); - return $profile->setOriginal($filename); - } - - function access_token($omb) - { - - common_debug('starting request for access token', __FILE__); - - $con = omb_oauth_consumer(); - $tok = new OAuthToken($omb['token'], $omb['secret']); - - common_debug('using request token "'.$tok.'"', __FILE__); - - $url = $omb['access_token_url']; - - common_debug('using access token url "'.$url.'"', __FILE__); - - # XXX: Is this the right thing to do? Strip off GET params and make them - # POST params? Seems wrong to me. - - $parsed = parse_url($url); - $params = array(); - parse_str($parsed['query'], $params); - - $req = OAuthRequest::from_consumer_and_token($con, $tok, "POST", $url, $params); - - $req->set_parameter('omb_version', OMB_VERSION_01); - - # XXX: test to see if endpoint accepts this signature method - - $req->sign_request(omb_hmac_sha1(), $con, $tok); - - # We re-use this tool's fetcher, since it's pretty good - - common_debug('posting to access token url "'.$req->get_normalized_http_url().'"', __FILE__); - common_debug('posting request data "'.$req->to_postdata().'"', __FILE__); - - $fetcher = Auth_Yadis_Yadis::getHTTPFetcher(); - $result = $fetcher->post($req->get_normalized_http_url(), - $req->to_postdata(), - array('User-Agent: StatusNet/' . STATUSNET_VERSION)); - - common_debug('got result: "'.print_r($result,true).'"', __FILE__); - - if ($result->status != 200) { - return null; - } - - parse_str($result->body, $return); - - return array($return['oauth_token'], $return['oauth_token_secret']); - } } diff --git a/actions/twitapifriendships.php b/actions/twitapifriendships.php index f2ea46910e..eea8945c39 100644 --- a/actions/twitapifriendships.php +++ b/actions/twitapifriendships.php @@ -99,6 +99,12 @@ class TwitapifriendshipsAction extends TwitterapiAction $other = $this->get_profile($id); $user = $apidata['user']; // Alwyas the auth user + if ($user->id == $other->id) { + $this->clientError(_("You cannot unfollow yourself!"), + 403, $apidata['content-type']); + return; + } + $sub = new Subscription(); $sub->subscriber = $user->id; $sub->subscribed = $other->id; diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php index ad6654dff5..2f10ff966c 100644 --- a/actions/twitapistatuses.php +++ b/actions/twitapistatuses.php @@ -136,6 +136,11 @@ class TwitapistatusesAction extends TwitterapiAction } + function home_timeline($args, $apidata) + { + call_user_func(array($this, 'friends_timeline'), $args, $apidata); + } + function user_timeline($args, $apidata) { parent::handle($args); diff --git a/actions/updateprofile.php b/actions/updateprofile.php index 7f7dd75fef..3cec9523cd 100644 --- a/actions/updateprofile.php +++ b/actions/updateprofile.php @@ -38,7 +38,7 @@ require_once INSTALLDIR.'/extlib/libomb/service_provider.php'; * * @category Action * @package Laconica - * @author Evan Prodromou + * @author Evan Prodromou * @author Robin Millette * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 * @link http://laconi.ca/ @@ -55,46 +55,13 @@ class UpdateprofileAction extends Action */ function prepare($argarray) { - $version = $req->get_parameter('omb_version'); - if ($version != OMB_VERSION_01) { - $this->clientError(_('Unsupported OMB version'), 400); - return false; - } - # First, check to see if listenee exists - $listenee = $req->get_parameter('omb_listenee'); - $remote = Remote_profile::staticGet('uri', $listenee); - if (!$remote) { - $this->clientError(_('Profile unknown'), 404); - return false; - } - # Second, check to see if they should be able to post updates! - # We see if there are any subscriptions to that remote user with - # the given token. - - $sub = new Subscription(); - $sub->subscribed = $remote->id; - $sub->token = $token->key; - if (!$sub->find(true)) { - $this->clientError(_('You did not send us that profile'), 403); - return false; - } - - $profile = Profile::staticGet('id', $remote->id); - if (!$profile) { - # This one is our fault - $this->serverError(_('Remote profile with no matching profile'), 500); - return false; - } - $nickname = $req->get_parameter('omb_listenee_nickname'); - if ($nickname && !Validate::string($nickname, array('min_length' => 1, - 'max_length' => 64, - 'format' => NICKNAME_FMT))) { - $this->clientError(_('Nickname must have only lowercase letters and numbers and no spaces.')); - return false; - } - $license = $req->get_parameter('omb_listenee_license'); - if ($license && !common_valid_http_url($license)) { - $this->clientError(sprintf(_("Invalid license URL '%s'"), $license)); + parent::prepare($argarray); + $license = $_POST['omb_listenee_license']; + $site_license = common_config('license', 'url'); + if (!common_compatible_license($license, $site_license)) { + $this->clientError(sprintf(_('Listenee stream license ā€˜%sā€™ is not '. + 'compatible with site license ā€˜%sā€™.'), + $license, $site_license)); return false; } return true; @@ -113,4 +80,4 @@ class UpdateprofileAction extends Action return; } } -} \ No newline at end of file +} diff --git a/classes/Config.php b/classes/Config.php old mode 100755 new mode 100644 index 5bec13fdc8..92f237d7f2 --- a/classes/Config.php +++ b/classes/Config.php @@ -17,7 +17,9 @@ * along with this program. If not, see . */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('STATUSNET')) { + exit(1); +} /** * Table Definition for config diff --git a/classes/Deleted_notice.php b/classes/Deleted_notice.php old mode 100755 new mode 100644 index 474d0b6f41..64dc85da65 --- a/classes/Deleted_notice.php +++ b/classes/Deleted_notice.php @@ -17,7 +17,9 @@ * along with this program. If not, see . */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('STATUSNET')) { + exit(1); +} /** * Table Definition for notice diff --git a/classes/statusnet.ini b/classes/statusnet.ini old mode 100755 new mode 100644 diff --git a/db/notice_source.sql b/db/notice_source.sql index f590d1b97a..2657763f44 100644 --- a/db/notice_source.sql +++ b/db/notice_source.sql @@ -21,6 +21,7 @@ VALUES ('identichat','identichat','http://identichat.prosody.im/', now()), ('IdentiFox','IdentiFox','http://www.bitbucket.org/uncryptic/identifox/', now()), ('identitwitch','IdentiTwitch','http://richfish.org/identitwitch/', now()), + ('Jiminy','Jiminy','http://code.google.com/p/jiminy/', now()), ('LaTwit','LaTwit','http://latwit.mac65.com/', now()), ('LiveTweeter', 'LiveTweeter', 'http://addons.songbirdnest.com/addon/1204', now()), ('livetweeter', 'livetweeter', 'http://addons.songbirdnest.com/addon/1204', now()), diff --git a/index.php b/index.php index e2296549f3..8ff67d19d9 100644 --- a/index.php +++ b/index.php @@ -15,6 +15,22 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . + * + * @category StatusNet + * @package StatusNet + * @author Brenda Wallace + * @author Christopher Vollick + * @author CiaranG + * @author Craig Andrews + * @author Evan Prodromou + * @author Gina Haeussge + * @author Jeffery To + * @author Mike Cochrane + * @author Robin Millette + * @author Sarven Capadisli + * @author Tom Adams + * + * @license GNU Affero General Public License http://www.gnu.org/licenses/ */ define('INSTALLDIR', dirname(__FILE__)); @@ -29,7 +45,8 @@ $action = null; function getPath($req) { if ((common_config('site', 'fancy') || !array_key_exists('PATH_INFO', $_SERVER)) - && array_key_exists('p', $req)) { + && array_key_exists('p', $req) + ) { return $req['p']; } else if (array_key_exists('PATH_INFO', $_SERVER)) { return $_SERVER['PATH_INFO']; @@ -45,28 +62,35 @@ function handleError($error) } $logmsg = "PEAR error: " . $error->getMessage(); - if(common_config('site', 'logdebug')) { + if (common_config('site', 'logdebug')) { $logmsg .= " : ". $error->getDebugInfo(); } common_log(LOG_ERR, $logmsg); - if(common_config('site', 'logdebug')) { + if (common_config('site', 'logdebug')) { $bt = $error->getBacktrace(); foreach ($bt as $line) { common_log(LOG_ERR, $line); } } - if ($error instanceof DB_DataObject_Error || - $error instanceof DB_Error) { - $msg = sprintf(_('The database for %s isn\'t responding correctly, '. - 'so the site won\'t work properly. '. - 'The site admins probably know about the problem, '. - 'but you can contact them at %s to make sure. '. - 'Otherwise, wait a few minutes and try again.'), - common_config('site', 'name'), - common_config('site', 'email')); + if ($error instanceof DB_DataObject_Error + || $error instanceof DB_Error + ) { + $msg = sprintf( + _( + 'The database for %s isn\'t responding correctly, '. + 'so the site won\'t work properly. '. + 'The site admins probably know about the problem, '. + 'but you can contact them at %s to make sure. '. + 'Otherwise, wait a few minutes and try again.' + ), + common_config('site', 'name'), + common_config('site', 'email') + ); } else { - $msg = _('An important error occured, probably related to email setup. '. - 'Check logfiles for more info..'); + $msg = _( + 'An important error occured, probably related to email setup. '. + 'Check logfiles for more info..' + ); } $dac = new DBErrorAction($msg, 500); @@ -127,10 +151,11 @@ function main() $_lighty_url = @parse_url($_lighty_url); if ($_lighty_url['path'] != '/index.php' && $_lighty_url['path'] != '/') { - $_lighty_path = preg_replace('/^'.preg_quote(common_config('site','path')).'\//', '', substr($_lighty_url['path'], 1)); + $_lighty_path = preg_replace('/^'.preg_quote(common_config('site', 'path')).'\//', '', substr($_lighty_url['path'], 1)); $_SERVER['QUERY_STRING'] = 'p='.$_lighty_path; - if ($_lighty_url['query']) + if ($_lighty_url['query']) { $_SERVER['QUERY_STRING'] .= '&'.$_lighty_url['query']; + } parse_str($_lighty_url['query'], $_lighty_query); foreach ($_lighty_query as $key => $val) { $_GET[$key] = $_REQUEST[$key] = $val; @@ -141,7 +166,7 @@ function main() $_SERVER['REDIRECT_URL'] = preg_replace("/\?.+$/", "", $_SERVER['REQUEST_URI']); // quick check for fancy URL auto-detection support in installer. - if (isset($_SERVER['REDIRECT_URL']) && (preg_replace("/^\/$/","",(dirname($_SERVER['REQUEST_URI']))) . '/check-fancy') === $_SERVER['REDIRECT_URL']) { + if (isset($_SERVER['REDIRECT_URL']) && (preg_replace("/^\/$/", "", (dirname($_SERVER['REQUEST_URI']))) . '/check-fancy') === $_SERVER['REDIRECT_URL']) { die("Fancy URL support detection succeeded. We suggest you enable this to get fancy (pretty) URLs."); } global $user, $action; @@ -149,8 +174,12 @@ function main() Snapshot::check(); if (!_have_config()) { - $msg = sprintf(_("No configuration file found. Try running ". - "the installation program first.")); + $msg = sprintf( + _( + "No configuration file found. Try running ". + "the installation program first." + ) + ); $sac = new ServerErrorAction($msg); $sac->showPage(); return; @@ -196,9 +225,10 @@ function main() // If the site is private, and they're not on one of the "public" // parts of the site, redirect to login - if (!$user && common_config('site', 'private') && - !isLoginAction($action) && - !preg_match('/rss$/', $action)) { + if (!$user && common_config('site', 'private') + && !isLoginAction($action) + && !preg_match('/rss$/', $action) + ) { common_redirect(common_local_url('login')); return; } diff --git a/install.php b/install.php index e828fa814b..46248c7891 100644 --- a/install.php +++ b/install.php @@ -15,6 +15,24 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . + * + * @category Installation + * @package Installation + * + * @author Adrian Lang + * @author Brenda Wallace + * @author Brett Taylor + * @author Brion Vibber + * @author CiaranG + * @author Craig Andrews + * @author Eric Helgeson + * @author Evan Prodromou + * @author Robin Millette + * @author Sarven Capadisli + * @author Tom Adams + * @license GNU Affero General Public License http://www.gnu.org/licenses/ + * @version 0.9 + * @link http://status.net */ define('INSTALLDIR', dirname(__FILE__)); @@ -181,17 +199,34 @@ $external_libraries=array( 'check_class'=>'Validate' ) ); +$dbModules = array( + 'mysql' => array( + 'name' => 'MySQL', + 'check_module' => 'mysql', // mysqli? + 'installer' => 'mysql_db_installer', + ), + 'pgsql' => array( + 'name' => 'PostgreSQL', + 'check_module' => 'pgsql', + 'installer' => 'pgsql_db_installer', + ), +); +/** + * the actual installation. + * If call libraries are present, then install + * + * @return void + */ function main() { - if (!checkPrereqs()) - { + if (!checkPrereqs()) { return; } - - if( $_GET['checklibs'] ){ + + if (!empty($_GET['checklibs'])) { showLibs(); - }else{ + } else { if ($_SERVER['REQUEST_METHOD'] == 'POST') { handlePost(); } else { @@ -200,33 +235,44 @@ function main() } } +/** + * checks if an external libary is present + * + * @param string $external_library Name of library + * + * @return boolean indicates if library present + */ function haveExternalLibrary($external_library) { - if(isset($external_library['include']) && ! include_once($external_library['include'])){ + if (isset($external_library['include']) && ! @include_once $external_library['include'] ) { return false; } - if(isset($external_library['check_function']) && ! function_exists($external_library['check_function'])){ + if (isset($external_library['check_function']) && ! function_exists($external_library['check_function'])) { return false; } - if(isset($external_library['check_class']) && ! class_exists($external_library['check_class'])){ + if (isset($external_library['check_class']) && ! class_exists($external_library['check_class'])) { return false; } return true; } +/** + * Check if all is ready for installation + * + * @return void + */ function checkPrereqs() { - $pass = true; + $pass = true; if (file_exists(INSTALLDIR.'/config.php')) { - ?>

Config file "config.php" already exists.

- Config file "config.php" already exists.

'); $pass = false; } if (version_compare(PHP_VERSION, '5.2.3', '<')) { - ?>

Require PHP version 5.2.3 or greater.

Require PHP version 5.2.3 or greater.

'); + $pass = false; } $reqs = array('gd', 'curl', @@ -234,37 +280,52 @@ function checkPrereqs() foreach ($reqs as $req) { if (!checkExtension($req)) { - ?>

Cannot load required extension:

Cannot load required extension: %s

', $req); + $pass = false; } } - if (!checkExtension('pgsql') && !checkExtension('mysql')) { - ?>

Cannot find mysql or pgsql extension. You need one or the other:

$info) { + if (!checkExtension($info['check_module'])) { + $missingExtensions[] = $info['check_module']; + } } - if (!is_writable(INSTALLDIR)) { - ?>

Cannot write config file to:

-

On your server, try this command: chmod a+w - Cannot find mysql or pgsql extension. You need one or the other.'); + $pass = false; + } - // Check the subdirs used for file uploads - $fileSubdirs = array('avatar', 'background', 'file'); - foreach ($fileSubdirs as $fileSubdir) { - $fileFullPath = INSTALLDIR."/$fileSubdir/"; - if (!is_writable($fileFullPath)) { - ?>

Cannot write directory:

-

On your server, try this command: chmod a+w

- Cannot write config file to: %s

', INSTALLDIR); + printf('

On your server, try this command: chmod a+w %s', INSTALLDIR); + $pass = false; + } - return $pass; + // Check the subdirs used for file uploads + $fileSubdirs = array('avatar', 'background', 'file'); + foreach ($fileSubdirs as $fileSubdir) { + $fileFullPath = INSTALLDIR."/$fileSubdir/"; + if (!is_writable($fileFullPath)) { + printf('

Cannot write to %s directory: %s

', $fileSubdir, $fileFullPath); + printf('

On your server, try this command: chmod a+w %s

', $fileFullPath); + $pass = false; + } + } + + return $pass; } +/** + * Checks if a php extension is both installed and loaded + * + * @param string $name of extension to check + * + * @return boolean whether extension is installed and loaded + */ function checkExtension($name) { if (!extension_loaded($name)) { @@ -275,15 +336,20 @@ function checkExtension($name) return true; } +/** + * Show list of libraries + * + * @return void + */ function showLibs() { global $external_libraries; $present_libraries=array(); $absent_libraries=array(); - foreach($external_libraries as $external_library){ - if(haveExternalLibrary($external_library)){ + foreach ($external_libraries as $external_library) { + if (haveExternalLibrary($external_library)) { $present_libraries[]=$external_library; - }else{ + } else { $absent_libraries[]=$external_library; } } @@ -298,22 +364,21 @@ function showLibs()

Absent Libraries

    E_O_T; - foreach($absent_libraries as $library) - { + foreach ($absent_libraries as $library) { echo '
  • '; - if($library['url']){ + if (isset($library['url'])) { echo ''.htmlentities($library['name']).''; - }else{ + } else { echo htmlentities($library['name']); } echo '
      '; - if($library['deb']){ + if (isset($library['deb'])) { echo '
    • deb: ' . htmlentities($library['deb']) . '
    • '; } - if($library['rpm']){ + if (isset($library['rpm'])) { echo '
    • rpm: ' . htmlentities($library['rpm']) . '
    • '; } - if($library['pear']){ + if (isset($library['pear'])) { echo '
    • pear: ' . htmlentities($library['pear']) . '
    • '; } echo '
    '; @@ -323,12 +388,11 @@ E_O_T;

    Installed Libraries

      E_O_T; - foreach($present_libraries as $library) - { + foreach ($present_libraries as $library) { echo '
    • '; - if($library['url']){ + if ($library['url']) { echo ''.htmlentities($library['name']).''; - }else{ + } else { echo htmlentities($library['name']); } echo '
    • '; @@ -340,6 +404,15 @@ E_O_T; function showForm() { + global $dbModules; + $dbRadios = ''; + $checked = 'checked="checked" '; // Check the first one which exists + foreach ($dbModules as $type => $info) { + if (checkExtension($info['check_module'])) { + $dbRadios .= " $info[name]
      \n"; + $checked = ''; + } + } echo<< @@ -376,8 +449,7 @@ function showForm()
    • - MySQL
      - PostgreSQL
      + $dbRadios

      Database type

    • @@ -406,17 +478,11 @@ E_O_T; function updateStatus($status, $error=false) { -?> -
    • >
    • - -$status"; } function handlePost() { -?> - - + echo <<
      Page notice
        -new StatusNet site."); -?> - -server_encoding != 'UTF8') { - updateStatus("StatusNet requires UTF8 character encoding. Your database is ". htmlentities($record->server_encoding)); - showForm(); - return false; - } + //ensure database encoding is UTF8 + $record = pg_fetch_object(pg_query($conn, 'SHOW server_encoding')); + if ($record->server_encoding != 'UTF8') { + updateStatus("StatusNet requires UTF8 character encoding. Your database is ". htmlentities($record->server_encoding)); + showForm(); + return false; + } - updateStatus("Running database script..."); - //wrap in transaction; - pg_query($conn, 'BEGIN'); - $res = runDbScript(INSTALLDIR.'/db/statusnet_pg.sql', $conn, 'pgsql'); + updateStatus("Running database script..."); + //wrap in transaction; + pg_query($conn, 'BEGIN'); + $res = runDbScript(INSTALLDIR.'/db/statusnet_pg.sql', $conn, 'pgsql'); - if ($res === false) { - updateStatus("Can't run database script.", true); - showForm(); - return false; - } - foreach (array('sms_carrier' => 'SMS carrier', + if ($res === false) { + updateStatus("Can't run database script.", true); + showForm(); + return false; + } + foreach (array('sms_carrier' => 'SMS carrier', 'notice_source' => 'notice source', 'foreign_services' => 'foreign service') as $scr => $name) { - updateStatus(sprintf("Adding %s data to database...", $name)); - $res = runDbScript(INSTALLDIR.'/db/'.$scr.'.sql', $conn, 'pgsql'); - if ($res === false) { - updateStatus(sprintf("Can't run %d script.", $name), true); - showForm(); - return false; - } - } - pg_query($conn, 'COMMIT'); + updateStatus(sprintf("Adding %s data to database...", $name)); + $res = runDbScript(INSTALLDIR.'/db/'.$scr.'.sql', $conn, 'pgsql'); + if ($res === false) { + updateStatus(sprintf("Can't run %d script.", $name), true); + showForm(); + return false; + } + } + pg_query($conn, 'COMMIT'); - if (empty($password)) { - $sqlUrl = "pgsql://$username@$host/$database"; - } - else { - $sqlUrl = "pgsql://$username:$password@$host/$database"; - } + if (empty($password)) { + $sqlUrl = "pgsql://$username@$host/$database"; + } else { + $sqlUrl = "pgsql://$username:$password@$host/$database"; + } - $db = array('type' => 'pgsql', 'database' => $sqlUrl); + $db = array('type' => 'pgsql', 'database' => $sqlUrl); - return $db; + return $db; } -function mysql_db_installer($host, $database, $username, $password) { - updateStatus("Starting installation..."); - updateStatus("Checking database..."); +function Mysql_Db_installer($host, $database, $username, $password) +{ + updateStatus("Starting installation..."); + updateStatus("Checking database..."); - $conn = mysql_connect($host, $username, $password); - if (!$conn) { - updateStatus("Can't connect to server '$host' as '$username'.", true); - showForm(); - return false; - } - updateStatus("Changing to database..."); - $res = mysql_select_db($database, $conn); - if (!$res) { - updateStatus("Can't change to database.", true); - showForm(); - return false; - } - updateStatus("Running database script..."); - $res = runDbScript(INSTALLDIR.'/db/statusnet.sql', $conn); - if ($res === false) { - updateStatus("Can't run database script.", true); - showForm(); - return false; - } - foreach (array('sms_carrier' => 'SMS carrier', + $conn = mysql_connect($host, $username, $password); + if (!$conn) { + updateStatus("Can't connect to server '$host' as '$username'.", true); + showForm(); + return false; + } + updateStatus("Changing to database..."); + $res = mysql_select_db($database, $conn); + if (!$res) { + updateStatus("Can't change to database.", true); + showForm(); + return false; + } + updateStatus("Running database script..."); + $res = runDbScript(INSTALLDIR.'/db/statusnet.sql', $conn); + if ($res === false) { + updateStatus("Can't run database script.", true); + showForm(); + return false; + } + foreach (array('sms_carrier' => 'SMS carrier', 'notice_source' => 'notice source', 'foreign_services' => 'foreign service') as $scr => $name) { - updateStatus(sprintf("Adding %s data to database...", $name)); - $res = runDbScript(INSTALLDIR.'/db/'.$scr.'.sql', $conn); - if ($res === false) { - updateStatus(sprintf("Can't run %d script.", $name), true); - showForm(); - return false; - } - } + updateStatus(sprintf("Adding %s data to database...", $name)); + $res = runDbScript(INSTALLDIR.'/db/'.$scr.'.sql', $conn); + if ($res === false) { + updateStatus(sprintf("Can't run %d script.", $name), true); + showForm(); + return false; + } + } - $sqlUrl = "mysqli://$username:$password@$host/$database"; - $db = array('type' => 'mysql', 'database' => $sqlUrl); - return $db; + $sqlUrl = "mysqli://$username:$password@$host/$database"; + $db = array('type' => 'mysql', 'database' => $sqlUrl); + return $db; } function writeConf($sitename, $server, $path, $fancy, $db) @@ -634,7 +684,16 @@ function writeConf($sitename, $server, $path, $fancy, $db) return $res; } -function runDbScript($filename, $conn, $type = 'mysql') +/** + * Install schema into the database + * + * @param string $filename location of database schema file + * @param dbconn $conn connection to database + * @param string $type type of database, currently mysql or pgsql + * + * @return boolean - indicating success or failure + */ +function runDbScript($filename, $conn, $type = 'mysqli') { $sql = trim(file_get_contents($filename)); $stmts = explode(';', $sql); @@ -645,7 +704,7 @@ function runDbScript($filename, $conn, $type = 'mysql') } // FIXME: use PEAR::DB or PDO instead of our own switch switch ($type) { - case 'mysql': + case 'mysqli': $res = mysql_query($stmt, $conn); if ($res === false) { $error = mysql_error(); diff --git a/lib/common.php b/lib/common.php index 3b21b548cf..194eb568f7 100644 --- a/lib/common.php +++ b/lib/common.php @@ -284,6 +284,8 @@ $config = array('contentlimit' => null), 'message' => array('contentlimit' => null), + 'http' => + array('client' => 'curl'), // XXX: should this be the default? ); $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options'); diff --git a/lib/curlclient.php b/lib/curlclient.php new file mode 100644 index 0000000000..36fc7d157e --- /dev/null +++ b/lib/curlclient.php @@ -0,0 +1,179 @@ +n. + * + * @category HTTP + * @package StatusNet + * @author Evan Prodromou + * @copyright 2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +define(CURLCLIENT_VERSION, "0.1"); + +/** + * Wrapper for Curl + * + * Makes Curl HTTP client calls within our HTTPClient framework + * + * @category HTTP + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +class CurlClient extends HTTPClient +{ + function __construct() + { + } + + function head($url, $headers=null) + { + $ch = curl_init($url); + + $this->setup($ch); + + curl_setopt_array($ch, + array(CURLOPT_NOBODY => true)); + + if (!is_null($headers)) { + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + } + + $result = curl_exec($ch); + + curl_close($ch); + + return $this->parseResults($result); + } + + function get($url, $headers=null) + { + $ch = curl_init($url); + + $this->setup($ch); + + if (!is_null($headers)) { + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + } + + $result = curl_exec($ch); + + curl_close($ch); + + return $this->parseResults($result); + } + + function post($url, $headers=null, $body=null) + { + $ch = curl_init($url); + + $this->setup($ch); + + curl_setopt($ch, CURLOPT_POST, true); + + if (!is_null($body)) { + curl_setopt($ch, CURLOPT_POSTFIELDS, $body); + } + + if (!is_null($headers)) { + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + } + + $result = curl_exec($ch); + + curl_close($ch); + + return $this->parseResults($result); + } + + function setup($ch) + { + curl_setopt_array($ch, + array(CURLOPT_USERAGENT => $this->userAgent(), + CURLOPT_HEADER => true, + CURLOPT_RETURNTRANSFER => true)); + } + + function userAgent() + { + $version = curl_version(); + return parent::userAgent() . " CurlClient/".CURLCLIENT_VERSION . " cURL/" . $version['version']; + } + + function parseResults($results) + { + $resp = new HTTPResponse(); + + $lines = explode("\r\n", $results); + + if (preg_match("#^HTTP/1.[01] (\d\d\d) .+$#", $lines[0], $match)) { + $resp->code = $match[1]; + } else { + throw Exception("Bad format: initial line is not HTTP status line"); + } + + $lastk = null; + + for ($i = 1; $i < count($lines); $i++) { + $l =& $lines[$i]; + if (mb_strlen($l) == 0) { + $resp->body = implode("\r\n", array_slice($lines, $i + 1)); + break; + } + if (preg_match("#^(\S+):\s+(.*)$#", $l, $match)) { + $k = $match[1]; + $v = $match[2]; + + if (array_key_exists($k, $resp->headers)) { + if (is_array($resp->headers[$k])) { + $resp->headers[$k][] = $v; + } else { + $resp->headers[$k] = array($resp->headers[$k], $v); + } + } else { + $resp->headers[$k] = $v; + } + $lastk = $k; + } else if (preg_match("#^\s+(.*)$#", $l, $match)) { + // continuation line + if (is_null($lastk)) { + throw Exception("Bad format: initial whitespace in headers"); + } + $h =& $resp->headers[$lastk]; + if (is_array($h)) { + $n = count($h); + $h[$n-1] .= $match[1]; + } else { + $h .= $match[1]; + } + } + } + + return $resp; + } +} diff --git a/lib/httpclient.php b/lib/httpclient.php new file mode 100644 index 0000000000..c8c8ae5b26 --- /dev/null +++ b/lib/httpclient.php @@ -0,0 +1,122 @@ +. + * + * @category Action + * @package StatusNet + * @author Evan Prodromou + * @copyright 2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +/** + * Useful structure for HTTP responses + * + * We make HTTP calls in several places, and we have several different + * ways of doing them. This class hides the specifics of what underlying + * library (curl or PHP-HTTP or whatever) that's used. + * + * @category HTTP + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +class HTTPResponse +{ + public $code = null; + public $headers = null; + public $body = null; +} + +/** + * Utility class for doing HTTP client stuff + * + * We make HTTP calls in several places, and we have several different + * ways of doing them. This class hides the specifics of what underlying + * library (curl or PHP-HTTP or whatever) that's used. + * + * @category HTTP + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +class HTTPClient +{ + static $_client = null; + + static function start() + { + if (!is_null(self::$_client)) { + return self::$_client; + } + + $type = common_config('http', 'client'); + + switch ($type) { + case 'curl': + self::$_client = new CurlClient(); + break; + default: + throw new Exception("Unknown HTTP client type '$type'"); + break; + } + + return self::$_client; + } + + function head($url, $headers) + { + throw new Exception("HEAD method unimplemented"); + } + + function get($url, $headers) + { + throw new Exception("GET method unimplemented"); + } + + function post($url, $headers, $body) + { + throw new Exception("POST method unimplemented"); + } + + function put($url, $headers, $body) + { + throw new Exception("PUT method unimplemented"); + } + + function delete($url, $headers) + { + throw new Exception("DELETE method unimplemented"); + } + + function userAgent() + { + return "StatusNet/".STATUSNET_VERSION." (".STATUSNET_CODENAME.")"; + } +} diff --git a/lib/omb.php b/lib/omb.php index 9133af7a05..0566701ff1 100644 --- a/lib/omb.php +++ b/lib/omb.php @@ -80,14 +80,9 @@ function omb_broadcast_notice($notice) $posted = array(); while ($rp->fetch()) { - if (!array_key_exists($rp->postnoticeurl, $posted)) { - common_log(LOG_DEBUG, 'Posting to ' . $rp->postnoticeurl); - if (omb_post_notice_keys($notice, $rp->postnoticeurl, $rp->token, $rp->secret)) { - common_log(LOG_DEBUG, 'Finished to ' . $rp->postnoticeurl); - $posted[$rp->postnoticeurl] = true; - } else { - common_log(LOG_DEBUG, 'Failed posting to ' . $rp->postnoticeurl); - } + if (isset($posted[$rp->postnoticeurl])) { + /* We already posted to this url. */ + continue; } common_debug('Posting to ' . $rp->postnoticeurl, __FILE__); diff --git a/lib/router.php b/lib/router.php index 8f13b88520..2c4d63b0d7 100644 --- a/lib/router.php +++ b/lib/router.php @@ -265,12 +265,12 @@ class Router $m->connect('api/statuses/:method', array('action' => 'api', 'apiaction' => 'statuses'), - array('method' => '(public_timeline|friends_timeline|user_timeline|update|replies|mentions|show|friends|followers|featured)(\.(atom|rss|xml|json))?')); + array('method' => '(public_timeline|home_timeline|friends_timeline|user_timeline|update|replies|mentions|show|friends|followers|featured)(\.(atom|rss|xml|json))?')); $m->connect('api/statuses/:method/:argument', array('action' => 'api', 'apiaction' => 'statuses'), - array('method' => '(|user_timeline|friends_timeline|replies|mentions|show|destroy|friends|followers)')); + array('method' => '(user_timeline|home_timeline|friends_timeline|replies|mentions|show|destroy|friends|followers)')); // users @@ -429,7 +429,7 @@ class Router $m->connect('api/statuses/:method/:argument', array('action' => 'api', 'apiaction' => 'statuses'), - array('method' => '(|user_timeline|friends_timeline|replies|mentions|show|destroy|friends|followers)')); + array('method' => '(user_timeline|home_timeline|friends_timeline|replies|mentions|show|destroy|friends|followers)')); $m->connect('api/statusnet/groups/:method/:argument', array('action' => 'api', diff --git a/plugins/OpenID/OpenIDPlugin.php b/plugins/OpenID/OpenIDPlugin.php index eb450fc5e5..91bddf381f 100644 --- a/plugins/OpenID/OpenIDPlugin.php +++ b/plugins/OpenID/OpenIDPlugin.php @@ -1,6 +1,6 @@ . * * @category Plugin - * @package Laconica - * @author Evan Prodromou - * @copyright 2009 Control Yourself, Inc. + * @package StatusNet + * @author Evan Prodromou + * @copyright 2009 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ + * @link http://status.net/ */ -if (!defined('LACONICA')) { +if (!defined('STATUSNET')) { exit(1); } @@ -36,10 +36,10 @@ if (!defined('LACONICA')) { * and identity system. * * @category Plugin - * @package Laconica - * @author Evan Prodromou + * @package StatusNet + * @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/ + * @link http://status.net/ * @link http://openid.net/ */ diff --git a/theme/readme.txt b/theme/readme.txt index 151b1fb71c..d030f2db4d 100644 --- a/theme/readme.txt +++ b/theme/readme.txt @@ -1,7 +1,7 @@ /** Howto: create a statusnet theme * * @package StatusNet - * @author Sarven Capadisli + * @author Sarven Capadisli * @copyright 2009 Control Yourself, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://laconi.ca/