Skip to content

Commit

Permalink
A bit more PHP 5.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
Erwann MEST committed Mar 22, 2012
1 parent b179c95 commit 59a83c9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
18 changes: 10 additions & 8 deletions tmhOAuth.php
Expand Up @@ -11,6 +11,8 @@
*
* 01 March 2012
*/
namespace Tmhoauth;

class tmhOAuth {
const VERSION = 0.62;

Expand All @@ -19,7 +21,7 @@ class tmhOAuth {
*
* @param string $config, the configuration to use for this request
*/
function __construct($config) {
public function __construct($config) {
$this->params = array();
$this->headers = array();
$this->auto_fixed_time = false;
Expand Down Expand Up @@ -83,7 +85,7 @@ function __construct($config) {
$this->set_user_agent();
}

function set_user_agent() {
public function set_user_agent() {
if (!empty($this->config['user_agent']))
return;

Expand Down Expand Up @@ -196,7 +198,7 @@ private function get_defaults() {
* @param string $body the response body from an OAuth flow method
* @return array the response body safely decoded to an array of key => values
*/
function extract_params($body) {
public function extract_params($body) {
$kvs = explode('&', $body);
$decoded = array();
foreach ($kvs as $kv) {
Expand Down Expand Up @@ -386,7 +388,7 @@ private function sign($method, $url, $params, $useauth) {
* @param string $useauth whether to use authentication when making the request. Default true.
* @param string $multipart whether this request contains multipart data. Default false
*/
function request($method, $url, $params=array(), $useauth=true, $multipart=false) {
public function request($method, $url, $params=array(), $useauth=true, $multipart=false) {
$this->config['multipart'] = $multipart;

$this->create_nonce();
Expand All @@ -408,7 +410,7 @@ function request($method, $url, $params=array(), $useauth=true, $multipart=false
* @param array $params the request parameters as an array of key=value pairs
* @param string $callback the callback function to stream the buffer to.
*/
function streaming_request($method, $url, $params=array(), $callback='') {
public function streaming_request($method, $url, $params=array(), $callback='') {
if ( ! empty($callback) ) {
if ( ! is_callable($callback) ) {
return false;
Expand All @@ -428,7 +430,7 @@ function streaming_request($method, $url, $params=array(), $callback='') {
/**
* Handles the updating of the current Streaming API metrics.
*/
function update_metrics() {
public function update_metrics() {
$now = time();
if (($this->metrics['interval_start'] + $this->config['streaming_metrics_interval']) > $now)
return false;
Expand All @@ -449,7 +451,7 @@ function update_metrics() {
* @param string $format the format of the response. Default json. Set to an empty string to exclude the format
* @return string the concatenation of the host, API version, API method and format
*/
function url($request, $format='json') {
public function url($request, $format='json') {
$format = strlen($format) > 0 ? ".$format" : '';
$proto = $this->config['use_ssl'] ? 'https:/' : 'http:/';

Expand All @@ -471,7 +473,7 @@ function url($request, $format='json') {
* @param string $mode the transformation mode. either encode or decode
* @return the string as transformed by the given mode
*/
function transformText($text, $mode='encode') {
public function transformText($text, $mode='encode') {
return $this->{"safe_$mode"}($text);
}

Expand Down
22 changes: 12 additions & 10 deletions tmhUtilities.php
Expand Up @@ -9,6 +9,8 @@
*
* 01 March 2012
*/
namespace Tmhoauth;

class tmhUtilities {
/**
* Entifies the tweet using the given entities element.
Expand All @@ -19,8 +21,8 @@ class tmhUtilities {
* @param array $replacements if specified, the entities and their replacements will be stored to this variable
* @return the tweet text with entities replaced with hyperlinks
*/
function entify($tweet, &$replacements=array()) {
return tmhUtilities::entify_with_options($tweet, array(), $replacements);
public function entify($tweet, &$replacements=array()) {
return self::entify_with_options($tweet, array(), $replacements);
}

/**
Expand All @@ -32,7 +34,7 @@ function entify($tweet, &$replacements=array()) {
* @param array $replacements if specified, the entities and their replacements will be stored to this variable
* @return the tweet text with entities replaced with hyperlinks
*/
function entify_with_options($tweet, $options=array(), &$replacements=array()) {
public function entify_with_options($tweet, $options=array(), &$replacements=array()) {
$default_opts = array(
'encoding' => 'UTF-8',
'target' => '',
Expand Down Expand Up @@ -108,7 +110,7 @@ function entify_with_options($tweet, $options=array(), &$replacements=array()) {
* @param bool $dropqs whether to drop the querystring or not. Default true
* @return string the current URL
*/
function php_self($dropqs=true) {
public function php_self($dropqs=true) {
$protocol = 'http';
if (strtolower($_SERVER['HTTPS']) == 'on') {
$protocol = 'https';
Expand Down Expand Up @@ -143,7 +145,7 @@ function php_self($dropqs=true) {
return $url;
}

function is_cli() {
public function is_cli() {
return (PHP_SAPI == 'cli' && empty($_SERVER['REMOTE_ADDR']));
}

Expand All @@ -152,7 +154,7 @@ function is_cli() {
*
* @param mixes $obj
*/
function pr($obj) {
public function pr($obj) {

if (!self::is_cli())
echo '<pre style="word-wrap: break-word">';
Expand Down Expand Up @@ -184,7 +186,7 @@ function pr($obj) {
* @param string $useauth whether to use authentication when making the request. Default true.
* @param string $multipart whether this request contains multipart data. Default false
*/
function auto_fix_time_request($tmhOAuth, $method, $url, $params=array(), $useauth=true, $multipart=false) {
public function auto_fix_time_request($tmhOAuth, $method, $url, $params=array(), $useauth=true, $multipart=false) {
$tmhOAuth->request($method, $url, $params, $useauth, $multipart);

// if we're not doing auth the timestamp isn't important
Expand Down Expand Up @@ -213,7 +215,7 @@ function auto_fix_time_request($tmhOAuth, $method, $url, $params=array(), $useau
* @param string $prompt the text to display to the user
* @return the text entered by the user
*/
function read_input($prompt) {
public function read_input($prompt) {
echo $prompt;
$handle = fopen("php://stdin","r");
$data = fgets($handle);
Expand All @@ -229,7 +231,7 @@ function read_input($prompt) {
* @return string
* @url http://www.dasprids.de/blog/2008/08/22/getting-a-password-hidden-from-stdin-with-php-cli
*/
function read_password($prompt, $stars=false) {
public function read_password($prompt, $stars=false) {
echo $prompt;
$style = shell_exec('stty -g');

Expand Down Expand Up @@ -268,7 +270,7 @@ function read_password($prompt, $stars=false) {
* @param string $needle the string to check $haystack ends with
* @return true if $haystack ends with $needle, false otherwise
*/
function endswith($haystack, $needle) {
public function endswith($haystack, $needle) {
$haylen = strlen($haystack);
$needlelen = strlen($needle);
if ($needlelen > $haylen)
Expand Down

0 comments on commit 59a83c9

Please sign in to comment.