From 9fbb4595af6ef07316bb1121d07a6414486bf86f Mon Sep 17 00:00:00 2001 From: ozhozh Date: Mon, 20 Aug 2012 19:24:31 +0000 Subject: [PATCH] Whitespaces, bitches!! Because, you know, CodingStandards. git-svn-id: http://yourls.googlecode.com/svn/trunk@743 12232710-3e20-11de-b438-597f59cd7555 --- admin/admin-ajax.php | 8 +- admin/index.php | 2 +- admin/plugins.php | 2 +- admin/tools.php | 2 +- admin/upgrade.php | 2 +- changelog.txt | 2 + includes/functions-auth.php | 26 ++-- includes/functions-compat.php | 38 ++--- includes/functions-formatting.php | 36 ++--- includes/functions-html.php | 16 +- includes/functions-http.php | 16 +- includes/functions-infos.php | 41 +++--- includes/functions-install.php | 36 ++--- includes/functions-plugins.php | 70 ++++----- includes/functions.php | 236 +++++++++++++++--------------- includes/load-yourls.php | 82 +++++------ includes/version.php | 4 +- yourls-api.php | 4 +- yourls-go.php | 12 +- yourls-infos.php | 4 +- yourls-loader.php | 4 +- 21 files changed, 321 insertions(+), 322 deletions(-) diff --git a/admin/admin-ajax.php b/admin/admin-ajax.php index 372bfe4..9bd8e21 100644 --- a/admin/admin-ajax.php +++ b/admin/admin-ajax.php @@ -1,11 +1,11 @@ $valid_password ) { if( - yourls_salt($valid_user) == $_COOKIE['yourls_username'] - && yourls_salt($valid_password) == $_COOKIE['yourls_password'] + yourls_salt( $valid_user ) == $_COOKIE['yourls_username'] + && yourls_salt( $valid_password ) == $_COOKIE['yourls_password'] ) { yourls_set_user( $valid_user ); return true; @@ -177,7 +177,7 @@ function yourls_store_cookie( $user = null ) { if( isset($yourls_user_passwords[$user]) ) { $pass = $yourls_user_passwords[$user]; } else { - die('Stealing cookies?'); // This should never happen + die( 'Stealing cookies?' ); // This should never happen } $time = time() + YOURLS_COOKIE_LIFE; } @@ -200,6 +200,6 @@ function yourls_store_cookie( $user = null ) { // Set user name function yourls_set_user( $user ) { - if( !defined('YOURLS_USER') ) - define('YOURLS_USER', $user); + if( !defined( 'YOURLS_USER' ) ) + define( 'YOURLS_USER', $user ); } diff --git a/includes/functions-compat.php b/includes/functions-compat.php index e593e7f..25d7240 100644 --- a/includes/functions-compat.php +++ b/includes/functions-compat.php @@ -31,16 +31,16 @@ function yourls_array_to_json( $array ){ // formatting each key and value properly as we go. // Format the key: - if( is_numeric($key) ){ + if( is_numeric( $key ) ){ $key = "key_$key"; } - $key = '"'.addslashes($key).'"'; + $key = '"'.addslashes( $key ).'"'; // Format the value: if( is_array( $value )){ $value = yourls_array_to_json( $value ); } else if( !is_numeric( $value ) || is_string( $value ) ){ - $value = '"'.addslashes($value).'"'; + $value = '"'.addslashes( $value ).'"'; } // Add to staging array: @@ -74,51 +74,51 @@ function yourls_array_to_json( $array ){ } // Compat http_build_query for PHP4 -if (!function_exists('http_build_query')) { - function http_build_query($data, $prefix=null, $sep=null) { - return yourls_http_build_query($data, $prefix, $sep); +if ( !function_exists( 'http_build_query' ) ) { + function http_build_query( $data, $prefix=null, $sep=null ) { + return yourls_http_build_query( $data, $prefix, $sep ); } } // from php.net (modified by Mark Jaquith to behave like the native PHP5 function) -function yourls_http_build_query($data, $prefix=null, $sep=null, $key='', $urlencode=true) { +function yourls_http_build_query( $data, $prefix=null, $sep=null, $key='', $urlencode=true ) { $ret = array(); foreach ( (array) $data as $k => $v ) { if ( $urlencode) - $k = urlencode($k); + $k = urlencode( $k ); if ( is_int($k) && $prefix != null ) $k = $prefix.$k; - if ( !empty($key) ) + if ( !empty( $key ) ) $k = $key . '%5B' . $k . '%5D'; if ( $v === NULL ) continue; elseif ( $v === FALSE ) $v = '0'; - if ( is_array($v) || is_object($v) ) - array_push($ret,yourls_http_build_query($v, '', $sep, $k, $urlencode)); + if ( is_array( $v ) || is_object( $v ) ) + array_push( $ret,yourls_http_build_query( $v, '', $sep, $k, $urlencode ) ); elseif ( $urlencode ) - array_push($ret, $k.'='.urlencode($v)); + array_push( $ret, $k.'='.urlencode( $v ) ); else - array_push($ret, $k.'='.$v); + array_push( $ret, $k.'='.$v ); } if ( NULL === $sep ) - $sep = ini_get('arg_separator.output'); + $sep = ini_get( 'arg_separator.output' ); - return implode($sep, $ret); + return implode( $sep, $ret ); } // htmlspecialchars_decode for PHP < 5.1 -if ( !function_exists('htmlspecialchars_decode') ) { - function htmlspecialchars_decode($text) { - return strtr($text, array_flip(get_html_translation_table(HTML_SPECIALCHARS))); +if ( !function_exists( 'htmlspecialchars_decode' ) ) { + function htmlspecialchars_decode( $text ) { + return strtr( $text, array_flip( get_html_translation_table( HTML_SPECIALCHARS ) ) ); } } // BC Math functions (assuming if one doesn't exist, none does) -if ( !function_exists( 'bcdiv' )) { +if ( !function_exists( 'bcdiv' ) ) { function bcdiv( $dividend, $divisor ) { $quotient = floor( $dividend/$divisor ); return $quotient; diff --git a/includes/functions-formatting.php b/includes/functions-formatting.php index 875e150..de15526 100644 --- a/includes/functions-formatting.php +++ b/includes/functions-formatting.php @@ -13,9 +13,9 @@ function yourls_int2string( $num, $chars = null ) { while( $num >= $len ) { $mod = bcmod( $num, $len ); $num = bcdiv( $num, $len ); - $string = $chars[$mod] . $string; + $string = $chars[ $mod ] . $string; } - $string = $chars[$num] . $string; + $string = $chars[ $num ] . $string; return yourls_apply_filter( 'int2string', $string, $num, $chars ); } @@ -45,7 +45,7 @@ function yourls_string2htmlid( $string ) { function yourls_sanitize_string( $string ) { // make a regexp pattern with the shorturl charset, and remove everything but this $pattern = yourls_make_regexp_pattern( yourls_get_shorturl_charset() ); - $valid = substr(preg_replace('![^'.$pattern.']!', '', $string ), 0, 199); + $valid = substr( preg_replace( '![^'.$pattern.']!', '', $string ), 0, 199 ); return yourls_apply_filter( 'sanitize_string', $valid, $string ); } @@ -104,14 +104,14 @@ function yourls_clean_url( $url ) { // Perform a replacement while a string is found, eg $subject = '%0%0%0DDD', $search ='%0D' -> $result ='' // Stolen from WP's _deep_replace -function yourls_deep_replace($search, $subject){ +function yourls_deep_replace( $search, $subject ){ $found = true; while($found) { $found = false; foreach( (array) $search as $val ) { - while(strpos($subject, $val) !== false) { + while( strpos( $subject, $val ) !== false ) { $found = true; - $subject = str_replace($val, '', $subject); + $subject = str_replace( $val, '', $subject ); } } } @@ -121,20 +121,20 @@ function yourls_deep_replace($search, $subject){ // Make sure an integer is a valid integer (PHP's intval() limits to too small numbers) // TODO FIXME FFS: unused ? -function yourls_sanitize_int($in) { - return ( substr(preg_replace('/[^0-9]/', '', strval($in) ), 0, 20) ); +function yourls_sanitize_int( $in ) { + return ( substr( preg_replace( '/[^0-9]/', '', strval( $in ) ), 0, 20 ) ); } // Make sure a integer is safe // Note: this is not checking for integers, since integers on 32bits system are way too limited // TODO: find a way to validate as integer -function yourls_intval($in) { - return yourls_escape($in); +function yourls_intval( $in ) { + return yourls_escape( $in ); } // Escape a string function yourls_escape( $in ) { - return mysql_real_escape_string($in); + return mysql_real_escape_string( $in ); } // Sanitize an IP address @@ -154,7 +154,7 @@ function yourls_sanitize_date( $date ) { function yourls_sanitize_date_for_sql( $date ) { if( !yourls_sanitize_date( $date ) ) return false; - return date('Y-m-d', strtotime( $date ) ); + return date( 'Y-m-d', strtotime( $date ) ); } // Return word or words if more than one @@ -165,7 +165,7 @@ function yourls_plural( $word, $count=1 ) { // Return trimmed string function yourls_trim_long_string( $string, $length = 60, $append = '[...]' ) { $newstring = $string; - if( function_exists('mb_substr') ) { + if( function_exists( 'mb_substr' ) ) { if ( mb_strlen( $newstring ) > $length ) { $newstring = mb_substr( $newstring, 0, $length - mb_strlen( $append ), 'UTF-8' ) . $append; } @@ -190,11 +190,11 @@ function yourls_sanitize_filename( $file ) { } // Check if a string seems to be UTF-8. Stolen from WP. -function yourls_seems_utf8($str) { - $length = strlen($str); - for ($i=0; $i < $length; $i++) { - $c = ord($str[$i]); - if ($c < 0x80) $n = 0; # 0bbbbbbb +function yourls_seems_utf8( $str ) { + $length = strlen( $str ); + for ( $i=0; $i < $length; $i++ ) { + $c = ord( $str[ $i ] ); + if ( $c < 0x80 ) $n = 0; # 0bbbbbbb elseif (($c & 0xE0) == 0xC0) $n=1; # 110bbbbb elseif (($c & 0xF0) == 0xE0) $n=2; # 1110bbbb elseif (($c & 0xF8) == 0xF0) $n=3; # 11110bbb diff --git a/includes/functions-html.php b/includes/functions-html.php index b99437b..755cd34 100644 --- a/includes/functions-html.php +++ b/includes/functions-html.php @@ -5,7 +5,7 @@ function yourls_html_logo() { yourls_do_action( 'pre_html_logo' ); ?>

- YOURLS: Your Own URL Shortener
+
YOURLS: Your Own URL Shortener
YOURLS

- '. $ydb->all_queries .'

'; } ?> context ); ?> @@ -499,14 +499,14 @@ function yourls_html_link( $href, $title = '', $element = '' ) { function yourls_login_screen( $error_msg = '' ) { yourls_html_head( 'login' ); - $action = ( isset($_GET['action']) && $_GET['action'] == 'logout' ? '?' : '' ); + $action = ( isset( $_GET['action'] ) && $_GET['action'] == 'logout' ? '?' : '' ); yourls_html_logo(); ?>

'.$error_msg.'

'; } ?> @@ -544,18 +544,18 @@ function yourls_html_menu() { $admin_sublinks = array(); $admin_links['admin'] = array( - 'url' => yourls_admin_url('index.php'), - 'title' => 'Go to the admin interface', + 'url' => yourls_admin_url( 'index.php' ), + 'title' => 'Go to the admin interface', 'anchor' => 'Admin interface' ); if( yourls_is_admin() ) { $admin_links['tools'] = array( - 'url' => yourls_admin_url('tools.php'), + 'url' => yourls_admin_url( 'tools.php' ), 'anchor' => 'Tools', ); $admin_links['plugins'] = array( - 'url' => yourls_admin_url('plugins.php'), + 'url' => yourls_admin_url( 'plugins.php' ), 'anchor' => 'Manage Plugins', ); $admin_sublinks['plugins'] = yourls_list_plugin_admin_pages(); diff --git a/includes/functions-http.php b/includes/functions-http.php index 4cd64aa..f5f548b 100644 --- a/includes/functions-http.php +++ b/includes/functions-http.php @@ -16,11 +16,11 @@ function yourls_get_http_transport( $url ) { // Test transports by order of preference, best first // curl - if( function_exists('curl_init') && function_exists('curl_exec') ) + if( function_exists( 'curl_init' ) && function_exists( 'curl_exec' ) ) $transports[]= 'curl'; // fopen. Doesn't work with https? - if( !$is_ssl && function_exists('fopen') && ini_get('allow_url_fopen') ) + if( !$is_ssl && function_exists( 'fopen' ) && ini_get( 'allow_url_fopen' ) ) $transports[]= 'fopen'; // fsock @@ -94,9 +94,9 @@ function yourls_get_remote_content_fopen( $url, $maxlen = 4096, $timeout = 5 ) { } if( $initial_timeout !== false ) - @ini_set('default_socket_timeout', $initial_timeout); + @ini_set( 'default_socket_timeout', $initial_timeout ); if( $initial_user_agent !== false ) - @ini_set('user_agent', $initial_user_agent); + @ini_set( 'user_agent', $initial_user_agent ); restore_error_handler(); @@ -113,20 +113,20 @@ function yourls_get_remote_content_fopen( $url, $maxlen = 4096, $timeout = 5 ) { // Get remote content using fsockopen. Needs sanitized $url. Returns $content or false function yourls_get_remote_content_fsockopen( $url, $maxlen = 4096, $timeout = 5 ) { // get the host name and url path - $parsed_url = parse_url($url); + $parsed_url = parse_url( $url ); $host = $parsed_url['host']; - if ( isset($parsed_url['path']) ) { + if ( isset( $parsed_url['path'] ) ) { $path = $parsed_url['path']; } else { $path = '/'; // the url is pointing to the host like http://www.mysite.com } - if (isset($parsed_url['query'])) { + if ( isset( $parsed_url['query'] ) ) { $path .= '?' . $parsed_url['query']; } - if (isset($parsed_url['port'])) { + if ( isset( $parsed_url['port'] ) ) { $port = $parsed_url['port']; } else { $port = '80'; diff --git a/includes/functions-infos.php b/includes/functions-infos.php index 5af95d1..ff7bf04 100644 --- a/includes/functions-infos.php +++ b/includes/functions-infos.php @@ -38,7 +38,7 @@ function yourls_stats_pie( $data, $limit = 10, $size = '340x220', $id = null ) { // Trim array: $limit first item + the sum of all others if ( count( $data ) > $limit ) { $i= 0; - $trim_data = array('Others' => 0); + $trim_data = array( 'Others' => 0 ); foreach( $data as $item=>$value ) { $i++; if( $i <= $limit ) { @@ -53,7 +53,7 @@ function yourls_stats_pie( $data, $limit = 10, $size = '340x220', $id = null ) { // Scale items $_data = yourls_scale_data( $data ); - list($width, $height) = explode('x', $size); + list($width, $height) = explode( 'x', $size ); $options = array( 'theme' => 'maximized', @@ -66,7 +66,7 @@ function yourls_stats_pie( $data, $limit = 10, $size = '340x220', $id = null ) { ); $options = yourls_apply_filter( 'stats_pie_options', $options ); - $script_data = array_merge( array( 'Country' => 'Value' ), $_data); + $script_data = array_merge( array( 'Country' => 'Value' ), $_data ); $script_data = yourls_google_array_to_data_table( $script_data ); $pie = yourls_google_viz_code( 'PieChart', $script_data, $options, $id ); @@ -98,35 +98,34 @@ function yourls_build_list_of_days( $dates ) { // Get first & last years from our range. In our example: 2009 & 2009 $first_year = key( $dates ); - $last_year = end( array_keys($dates) ); + $last_year = end( array_keys( $dates ) ); reset( $dates ); // Get first & last months from our range. In our example: 08 & 09 - $first_month = key( $dates[$first_year] ); - $last_month = end( array_keys($dates[$last_year]) ); + $first_month = key( $dates[ $first_year ] ); + $last_month = end( array_keys( $dates[ $last_year ] ) ); reset( $dates ); // Get first & last days from our range. In our example: 29 & 05 - $first_day = key( $dates[$first_year][$first_month] ); - $last_day = end( array_keys($dates[$last_year][$last_month]) ); + $first_day = key( $dates[ $first_year ][ $first_month ] ); + $last_day = end( array_keys( $dates[ $last_year ][ $last_month ] ) ); // Now build a list of all years (2009), month (08 & 09) and days (all from 2009-08-29 to 2009-09-05) - $list_of_years = array(); + $list_of_years = array(); $list_of_months = array(); - $list_of_days = array(); + $list_of_days = array(); for ( $year = $first_year; $year <= $last_year; $year++ ) { - $_year = sprintf('%04d', $year); - $list_of_years[$_year] = $_year; + $_year = sprintf( '%04d', $year ); + $list_of_years[ $_year ] = $_year; $current_first_month = ( $year == $first_year ? $first_month : '01' ); $current_last_month = ( $year == $last_year ? $last_month : '12' ); for ( $month = $current_first_month; $month <= $current_last_month; $month++ ) { - $_month = sprintf('%02d', $month); - $list_of_months[$_month] = $_month; + $_month = sprintf( '%02d', $month ); + $list_of_months[ $_month ] = $_month; $current_first_day = ( $year == $first_year && $month == $first_month ? $first_day : '01' ); - $current_last_day = ( $year == $last_year && $month == $last_month ? $last_day : yourls_days_in_month($month, $year) ); + $current_last_day = ( $year == $last_year && $month == $last_month ? $last_day : yourls_days_in_month( $month, $year) ); for ( $day = $current_first_day; $day <= $current_last_day; $day++ ) { - $day = sprintf('%02d', $day); - //$key = "$_year-$_month-$day"; + $day = sprintf( '%02d', $day ); $key = date( 'M d, Y', mktime( 0, 0, 0, $_month, $day, $_year ) ); $list_of_days[ $key ] = isset( $dates[$_year][$_month][$day] ) ? $dates[$_year][$_month][$day] : 0; } @@ -134,9 +133,9 @@ function yourls_build_list_of_days( $dates ) { } return array( - 'list_of_days' => $list_of_days, + 'list_of_days' => $list_of_days, 'list_of_months' => $list_of_months, - 'list_of_years' => $list_of_years, + 'list_of_years' => $list_of_years, ); } @@ -179,9 +178,9 @@ function yourls_stats_line( $values, $id = null ) { } // Return the number of days in a month. From php.net, used if PHP built without calendar functions -function yourls_days_in_month($month, $year) { +function yourls_days_in_month( $month, $year ) { // calculate number of days in a month - return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31); + return $month == 2 ? ( $year % 4 ? 28 : ( $year % 100 ? 29 : ( $year % 400 ? 28 : 29 ) ) ) : ( ( $month - 1 ) % 7 % 2 ? 30 : 31 ); } // Get max value from date array of 'Aug 12, 2012' = '1337' diff --git a/includes/functions-install.php b/includes/functions-install.php index 49720ef..46ecb0f 100644 --- a/includes/functions-install.php +++ b/includes/functions-install.php @@ -2,12 +2,12 @@ // Check if mod_rewrite is enabled. Note: unused, not reliable enough. function yourls_check_mod_rewrite() { - return yourls_apache_mod_loaded('mod_rewrite'); + return yourls_apache_mod_loaded( 'mod_rewrite' ); } // Check if extension cURL is enabled function yourls_check_curl() { - return function_exists('curl_init'); + return function_exists( 'curl_init' ); } // Check if server has MySQL 4.1+ @@ -24,25 +24,25 @@ function yourls_check_php_version() { // Check if server is an Apache function yourls_is_apache() { return ( - strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false - || strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false + strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) !== false + || strpos( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) !== false ); } // Check if module exists in Apache config. Input string eg 'mod_rewrite', return true or $default. Stolen from WordPress -function yourls_apache_mod_loaded($mod, $default = false) { +function yourls_apache_mod_loaded( $mod, $default = false ) { if ( !yourls_is_apache() ) return false; - if ( function_exists('apache_get_modules') ) { + if ( function_exists( 'apache_get_modules' ) ) { $mods = apache_get_modules(); - if ( in_array($mod, $mods) ) + if ( in_array( $mod, $mods ) ) return true; - } elseif ( function_exists('phpinfo') ) { + } elseif ( function_exists( 'phpinfo' ) ) { ob_start(); - phpinfo(8); + phpinfo( 8 ); $phpinfo = ob_get_clean(); - if ( false !== strpos($phpinfo, $mod) ) + if ( false !== strpos( $phpinfo, $mod ) ) return true; } return $default; @@ -70,8 +70,8 @@ function yourls_create_htaccess() { // Inserts $insertion (text in an array of lines) into $filename (.htaccess) between BEGIN/END $marker block. Returns bool. Stolen from WP function yourls_insert_with_markers( $filename, $marker, $insertion ) { - if (!file_exists( $filename ) || is_writeable( $filename ) ) { - if (!file_exists( $filename ) ) { + if ( !file_exists( $filename ) || is_writeable( $filename ) ) { + if ( !file_exists( $filename ) ) { $markerdata = ''; } else { $markerdata = explode( "\n", implode( '', file( $filename ) ) ); @@ -84,7 +84,7 @@ function yourls_insert_with_markers( $filename, $marker, $insertion ) { if ( $markerdata ) { $state = true; foreach ( $markerdata as $n => $markerline ) { - if (strpos($markerline, '# BEGIN ' . $marker) !== false) + if ( strpos($markerline, '# BEGIN ' . $marker) !== false ) $state = false; if ( $state ) { if ( $n + 1 < count( $markerdata ) ) @@ -92,9 +92,9 @@ function yourls_insert_with_markers( $filename, $marker, $insertion ) { else fwrite( $f, "{$markerline}" ); } - if (strpos($markerline, '# END ' . $marker) !== false) { + if ( strpos( $markerline, '# END ' . $marker ) !== false ) { fwrite( $f, "# BEGIN {$marker}\n" ); - if ( is_array( $insertion )) + if ( is_array( $insertion ) ) foreach ( $insertion as $insertline ) fwrite( $f, "{$insertline}\n" ); fwrite( $f, "# END {$marker}\n" ); @@ -167,9 +167,9 @@ function yourls_create_sql_tables() { // Create tables foreach ( $create_tables as $table_name => $table_query ) { - $ydb->query($table_query); - $create_success = $ydb->query("SHOW TABLES LIKE '$table_name'"); - if($create_success) { + $ydb->query( $table_query ); + $create_success = $ydb->query( "SHOW TABLES LIKE '$table_name'" ); + if( $create_success ) { $create_table_count++; $success_msg[] = "Table '$table_name' created."; } else { diff --git a/includes/functions-plugins.php b/includes/functions-plugins.php index 74ff43f..54b6181 100644 --- a/includes/functions-plugins.php +++ b/includes/functions-plugins.php @@ -37,10 +37,10 @@ function yourls_add_filter( $hook, $function_name, $priority = 10, $accepted_arg // At this point, we cannot check if the function exists, as it may well be defined later (which is OK) $id = yourls_filter_unique_id( $hook, $function_name, $priority ); - $yourls_filters[$hook][$priority][$id] = array( - 'function' => $function_name, + $yourls_filters[ $hook ][ $priority ][ $id ] = array( + 'function' => $function_name, 'accepted_args' => $accepted_args, - 'type' => $type, + 'type' => $type, ); } @@ -79,24 +79,24 @@ function yourls_filter_unique_id( $hook, $function, $priority ) { global $yourls_filters; // If function then just skip all of the tests and not overwrite the following. - if ( is_string($function) ) + if ( is_string( $function ) ) return $function; // Object Class Calling - else if (is_object($function[0]) ) { - $obj_idx = get_class($function[0]).$function[1]; - if ( !isset($function[0]->_yourls_filters_id) ) { + else if ( is_object( $function[0] ) ) { + $obj_idx = get_class( $function[0] ) . $function[1]; + if ( !isset( $function[0]->_yourls_filters_id ) ) { if ( false === $priority ) return false; - $count = isset($yourls_filters[$hook][$priority]) ? count((array)$yourls_filters[$hook][$priority]) : 0; + $count = isset( $yourls_filters[ $hook ][ $priority ]) ? count( (array)$yourls_filters[ $hook ][ $priority ] ) : 0; $function[0]->_yourls_filters_id = $count; $obj_idx .= $count; - unset($count); + unset( $count ); } else $obj_idx .= $function[0]->_yourls_filters_id; return $obj_idx; } // Static Calling - else if ( is_string($function[0]) ) + else if ( is_string( $function[0] ) ) return $function[0].$function[1]; } @@ -123,32 +123,32 @@ function yourls_filter_unique_id( $hook, $function, $priority ) { */ function yourls_apply_filter( $hook, $value = '' ) { global $yourls_filters; - if ( !isset( $yourls_filters[$hook] ) ) + if ( !isset( $yourls_filters[ $hook ] ) ) return $value; $args = func_get_args(); // Sort filters by priority - ksort( $yourls_filters[$hook] ); + ksort( $yourls_filters[ $hook ] ); // Loops through each filter - reset( $yourls_filters[$hook] ); + reset( $yourls_filters[ $hook ] ); do { - foreach( (array) current($yourls_filters[$hook]) as $the_ ) { - if ( !is_null($the_['function']) ){ + foreach( (array) current( $yourls_filters[ $hook ] ) as $the_ ) { + if ( !is_null( $the_['function'] ) ){ $args[1] = $value; $count = $the_['accepted_args']; - if (is_null($count)) { - $_value = call_user_func_array($the_['function'], array_slice($args, 1)); + if ( is_null( $count ) ) { + $_value = call_user_func_array( $the_['function'], array_slice( $args, 1 ) ); } else { - $_value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $count)); + $_value = call_user_func_array( $the_['function'], array_slice( $args, 1, (int) $count ) ); } } if( $the_['type'] == 'filter' ) $value = $_value; } - } while ( next($yourls_filters[$hook]) !== false ); + } while ( next( $yourls_filters[ $hook ] ) !== false ); if( $the_['type'] == 'filter' ) return $value; @@ -156,12 +156,12 @@ function yourls_apply_filter( $hook, $value = '' ) { function yourls_do_action( $hook, $arg = '' ) { $args = array(); - if ( is_array($arg) && 1 == count($arg) && isset($arg[0]) && is_object($arg[0]) ) // array(&$this) + if ( is_array( $arg ) && 1 == count( $arg ) && isset( $arg[0] ) && is_object( $arg[0] ) ) // array(&$this) $args[] =& $arg[0]; else $args[] = $arg; for ( $a = 2; $a < func_num_args(); $a++ ) - $args[] = func_get_arg($a); + $args[] = func_get_arg( $a ); yourls_apply_filter( $hook, $args ); } @@ -187,14 +187,14 @@ function yourls_do_action( $hook, $arg = '' ) { function yourls_remove_filter( $hook, $function_to_remove, $priority = 10, $accepted_args = 1 ) { global $yourls_filters; - $function_to_remove = yourls_filter_unique_id($hook, $function_to_remove, $priority); + $function_to_remove = yourls_filter_unique_id( $hook, $function_to_remove, $priority ); - $remove = isset ($yourls_filters[$hook][$priority][$function_to_remove]); + $remove = isset( $yourls_filters[ $hook ][ $priority ][ $function_to_remove ] ); if ( $remove === true ) { - unset ($yourls_filters[$hook][$priority][$function_to_remove]); - if ( empty($yourls_filters[$hook][$priority]) ) - unset ($yourls_filters[$hook]); + unset ( $yourls_filters[$hook][$priority][$function_to_remove] ); + if ( empty( $yourls_filters[$hook][$priority] ) ) + unset( $yourls_filters[$hook] ); } return $remove; } @@ -211,16 +211,16 @@ function yourls_remove_filter( $hook, $function_to_remove, $priority = 10, $acce function yourls_has_filter( $hook, $function_to_check = false ) { global $yourls_filters; - $has = !empty($yourls_filters[$hook]); + $has = !empty( $yourls_filters[ $hook ] ); if ( false === $function_to_check || false == $has ) { return $has; } - if ( !$idx = yourls_filter_unique_id($hook, $function_to_check, false) ) { + if ( !$idx = yourls_filter_unique_id( $hook, $function_to_check, false ) ) { return false; } - foreach ( (array) array_keys($yourls_filters[$hook]) as $priority ) { - if ( isset($yourls_filters[$hook][$priority][$idx]) ) + foreach ( (array) array_keys( $yourls_filters[ $hook ] ) as $priority ) { + if ( isset( $yourls_filters[ $hook ][ $priority ][ $idx ] ) ) return $priority; } return false; @@ -259,7 +259,7 @@ function yourls_get_plugins( ) { if( !$plugins ) return array(); - foreach( $plugins as $key=>$plugin ) { + foreach( $plugins as $key => $plugin ) { $_plugin = yourls_plugin_basename( $plugin ); $plugins[ $_plugin ] = yourls_get_plugin_data( $plugin ); unset( $plugins[ $key ] ); @@ -443,7 +443,7 @@ function yourls_plugin_basename( $file ) { function yourls_plugin_url( $file ) { $url = YOURLS_PLUGINURL . '/' . yourls_plugin_basename( $file ); if( yourls_is_ssl() or yourls_needs_ssl() ) - $url = str_replace('http://', 'https://', $url); + $url = str_replace( 'http://', 'https://', $url ); return yourls_apply_filter( 'plugin_url', $url, $file ); } @@ -458,7 +458,7 @@ function yourls_list_plugin_admin_pages() { $plugin_links = array(); foreach( (array)$ydb->plugin_pages as $plugin => $page ) { - $plugin_links[$plugin] = array( + $plugin_links[ $plugin ] = array( 'url' => yourls_admin_url( 'plugins.php?page='.$page['slug'] ), 'anchor' => $page['title'], ); @@ -476,8 +476,8 @@ function yourls_register_plugin_page( $slug, $title, $function ) { $ydb->plugin_pages = array(); $ydb->plugin_pages[ $slug ] = array( - 'slug' => $slug, - 'title' => $title, + 'slug' => $slug, + 'title' => $title, 'function' => $function, ); } diff --git a/includes/functions.php b/includes/functions.php index db53d76..419bcb0 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -149,9 +149,9 @@ function yourls_add_new_link( $url, $keyword = '', $title = '' ) { return $pre; if ( !$url || $url == 'http://' || $url == 'https://' ) { - $return['status'] = 'fail'; - $return['code'] = 'error:nourl'; - $return['message'] = 'Missing URL input'; + $return['status'] = 'fail'; + $return['code'] = 'error:nourl'; + $return['message'] = 'Missing URL input'; $return['errorCode'] = '400'; return yourls_apply_filter( 'add_new_link_fail_nourl', $return, $url, $keyword, $title ); } @@ -161,12 +161,12 @@ function yourls_add_new_link( $url, $keyword = '', $title = '' ) { yourls_check_IP_flood( $ip ); // Prevent internal redirection loops: cannot shorten a shortened URL - $url = yourls_escape( yourls_sanitize_url($url) ); + $url = yourls_escape( yourls_sanitize_url( $url ) ); if( preg_match( '!^'.YOURLS_SITE.'/!', $url ) ) { if( yourls_is_shorturl( $url ) ) { - $return['status'] = 'fail'; - $return['code'] = 'error:noloop'; - $return['message'] = 'URL is a short URL'; + $return['status'] = 'fail'; + $return['code'] = 'error:noloop'; + $return['message'] = 'URL is a short URL'; $return['errorCode'] = '400'; return yourls_apply_filter( 'add_new_link_fail_noloop', $return, $url, $keyword, $title ); } @@ -174,7 +174,7 @@ function yourls_add_new_link( $url, $keyword = '', $title = '' ) { yourls_do_action( 'pre_add_new_link', $url, $keyword, $title ); - $strip_url = stripslashes($url); + $strip_url = stripslashes( $url ); $return = array(); // duplicates allowed or new URL => store it @@ -192,21 +192,21 @@ function yourls_add_new_link( $url, $keyword = '', $title = '' ) { yourls_do_action( 'add_new_link_custom_keyword', $url, $keyword, $title ); - $keyword = yourls_escape( yourls_sanitize_string($keyword) ); + $keyword = yourls_escape( yourls_sanitize_string( $keyword ) ); $keyword = yourls_apply_filter( 'custom_keyword', $keyword, $url, $title ); - if ( !yourls_keyword_is_free($keyword) ) { + if ( !yourls_keyword_is_free( $keyword ) ) { // This shorturl either reserved or taken already - $return['status'] = 'fail'; - $return['code'] = 'error:keyword'; + $return['status'] = 'fail'; + $return['code'] = 'error:keyword'; $return['message'] = 'Short URL '.$keyword.' already exists in database or is reserved'; } else { // all clear, store ! yourls_insert_link_in_db( $url, $keyword, $title ); - $return['url'] = array('keyword' => $keyword, 'url' => $strip_url, 'title' => $title, 'date' => date('Y-m-d H:i:s'), 'ip' => $ip ); - $return['status'] = 'success'; - $return['message'] = yourls_trim_long_string( $strip_url ).' added to database'; - $return['title'] = $title; - $return['html'] = yourls_table_add_row( $keyword, $url, $title, $ip, 0, time() ); + $return['url'] = array('keyword' => $keyword, 'url' => $strip_url, 'title' => $title, 'date' => date('Y-m-d H:i:s'), 'ip' => $ip ); + $return['status'] = 'success'; + $return['message'] = yourls_trim_long_string( $strip_url ).' added to database'; + $return['title'] = $title; + $return['html'] = yourls_table_add_row( $keyword, $url, $title, $ip, 0, time() ); $return['shorturl'] = YOURLS_SITE .'/'. $keyword; } @@ -215,7 +215,7 @@ function yourls_add_new_link( $url, $keyword = '', $title = '' ) { yourls_do_action( 'add_new_link_create_keyword', $url, $keyword, $title ); - $timestamp = date('Y-m-d H:i:s'); + $timestamp = date( 'Y-m-d H:i:s' ); $id = yourls_get_next_decimal(); $ok = false; do { @@ -230,16 +230,16 @@ function yourls_add_new_link( $url, $keyword = '', $title = '' ) { $return['extra_info'] .= '(deleted '.$keyword.')'; } else { // everything ok, populate needed vars - $return['url'] = array('keyword' => $keyword, 'url' => $strip_url, 'title' => $title, 'date' => $timestamp, 'ip' => $ip ); - $return['status'] = 'success'; - $return['message'] = yourls_trim_long_string( $strip_url ).' added to database'; - $return['title'] = $title; - $return['html'] = yourls_table_add_row( $keyword, $url, $title, $ip, 0, time() ); + $return['url'] = array('keyword' => $keyword, 'url' => $strip_url, 'title' => $title, 'date' => $timestamp, 'ip' => $ip ); + $return['status'] = 'success'; + $return['message'] = yourls_trim_long_string( $strip_url ).' added to database'; + $return['title'] = $title; + $return['html'] = yourls_table_add_row( $keyword, $url, $title, $ip, 0, time() ); $return['shorturl'] = YOURLS_SITE .'/'. $keyword; } $id++; - } while (!$ok); - @yourls_update_next_decimal($id); + } while ( !$ok ); + @yourls_update_next_decimal( $id ); } // URL was already stored @@ -247,11 +247,11 @@ function yourls_add_new_link( $url, $keyword = '', $title = '' ) { yourls_do_action( 'add_new_link_already_stored', $url, $keyword, $title ); - $return['status'] = 'fail'; - $return['code'] = 'error:url'; - $return['url'] = array( 'keyword' => $url_exists->keyword, 'url' => $strip_url, 'title' => $url_exists->title, 'date' => $url_exists->timestamp, 'ip' => $url_exists->ip, 'clicks' => $url_exists->clicks ); - $return['message'] = yourls_trim_long_string( $strip_url ).' already exists in database'; - $return['title'] = $url_exists->title; + $return['status'] = 'fail'; + $return['code'] = 'error:url'; + $return['url'] = array( 'keyword' => $url_exists->keyword, 'url' => $strip_url, 'title' => $url_exists->title, 'date' => $url_exists->timestamp, 'ip' => $url_exists->ip, 'clicks' => $url_exists->clicks ); + $return['message'] = yourls_trim_long_string( $strip_url ).' already exists in database'; + $return['title'] = $url_exists->title; $return['shorturl'] = YOURLS_SITE .'/'. $url_exists->keyword; } @@ -267,13 +267,13 @@ function yourls_edit_link( $url, $keyword, $newkeyword='', $title='' ) { global $ydb; $table = YOURLS_DB_TABLE_URL; - $url = yourls_escape(yourls_sanitize_url($url)); - $keyword = yourls_escape(yourls_sanitize_string( $keyword )); - $title = yourls_escape(yourls_sanitize_title( $title )); - $newkeyword = yourls_escape(yourls_sanitize_string( $newkeyword )); - $strip_url = stripslashes($url); - $strip_title = stripslashes($title); - $old_url = $ydb->get_var("SELECT `url` FROM `$table` WHERE `keyword` = '$keyword';"); + $url = yourls_escape (yourls_sanitize_url( $url ) ); + $keyword = yourls_escape( yourls_sanitize_string( $keyword ) ); + $title = yourls_escape( yourls_sanitize_title( $title ) ); + $newkeyword = yourls_escape( yourls_sanitize_string( $newkeyword ) ); + $strip_url = stripslashes( $url ); + $strip_title = stripslashes( $title ); + $old_url = $ydb->get_var( "SELECT `url` FROM `$table` WHERE `keyword` = '$keyword';" ); // Check if new URL is not here already if ( $old_url != $url && !yourls_allow_duplicate_longurls() ) { @@ -293,19 +293,19 @@ function yourls_edit_link( $url, $keyword, $newkeyword='', $title='' ) { // All clear, update if ( ( !$new_url_already_there || yourls_allow_duplicate_longurls() ) && $keyword_is_ok ) { - $update_url = $ydb->query("UPDATE `$table` SET `url` = '$url', `keyword` = '$newkeyword', `title` = '$title' WHERE `keyword` = '$keyword';"); + $update_url = $ydb->query( "UPDATE `$table` SET `url` = '$url', `keyword` = '$newkeyword', `title` = '$title' WHERE `keyword` = '$keyword';" ); if( $update_url ) { - $return['url'] = array( 'keyword' => $newkeyword, 'shorturl' => YOURLS_SITE.'/'.$newkeyword, 'url' => $strip_url, 'display_url' => yourls_trim_long_string( $strip_url ), 'title' => $strip_title, 'display_title' => yourls_trim_long_string( $strip_title ) ); - $return['status'] = 'success'; + $return['url'] = array( 'keyword' => $newkeyword, 'shorturl' => YOURLS_SITE.'/'.$newkeyword, 'url' => $strip_url, 'display_url' => yourls_trim_long_string( $strip_url ), 'title' => $strip_title, 'display_title' => yourls_trim_long_string( $strip_title ) ); + $return['status'] = 'success'; $return['message'] = 'Link updated in database'; } else { - $return['status'] = 'fail'; + $return['status'] = 'fail'; $return['message'] = 'Error updating '. yourls_trim_long_string( $strip_url ).' (Short URL: '.$keyword.') to database'; } // Nope } else { - $return['status'] = 'fail'; + $return['status'] = 'fail'; $return['message'] = 'URL or keyword already exists in database'; } @@ -341,7 +341,7 @@ function yourls_keyword_is_taken( $keyword ) { $keyword = yourls_sanitize_keyword( $keyword ); $taken = false; $table = YOURLS_DB_TABLE_URL; - $already_exists = $ydb->get_var("SELECT COUNT(`keyword`) FROM `$table` WHERE `keyword` = '$keyword';"); + $already_exists = $ydb->get_var( "SELECT COUNT(`keyword`) FROM `$table` WHERE `keyword` = '$keyword';" ); if ( $already_exists ) $taken = true; @@ -353,33 +353,33 @@ function yourls_keyword_is_taken( $keyword ) { function yourls_db_connect() { global $ydb; - if (!defined('YOURLS_DB_USER') - or !defined('YOURLS_DB_PASS') - or !defined('YOURLS_DB_NAME') - or !defined('YOURLS_DB_HOST') - or !class_exists('ezSQL_mysql') - ) yourls_die ('DB config missing, or could not find DB class', 'Fatal error', 503); + if ( !defined( 'YOURLS_DB_USER' ) + or !defined( 'YOURLS_DB_PASS' ) + or !defined( 'YOURLS_DB_NAME' ) + or !defined( 'YOURLS_DB_HOST' ) + or !class_exists( 'ezSQL_mysql' ) + ) yourls_die ( 'DB config missing, or could not find DB class', 'Fatal error', 503 ); // Are we standalone or in the WordPress environment? - if ( class_exists('wpdb') ) { - $ydb = new wpdb(YOURLS_DB_USER, YOURLS_DB_PASS, YOURLS_DB_NAME, YOURLS_DB_HOST); + if ( class_exists( 'wpdb' ) ) { + $ydb = new wpdb( YOURLS_DB_USER, YOURLS_DB_PASS, YOURLS_DB_NAME, YOURLS_DB_HOST ); } else { - $ydb = new ezSQL_mysql(YOURLS_DB_USER, YOURLS_DB_PASS, YOURLS_DB_NAME, YOURLS_DB_HOST); + $ydb = new ezSQL_mysql( YOURLS_DB_USER, YOURLS_DB_PASS, YOURLS_DB_NAME, YOURLS_DB_HOST ); } if ( $ydb->last_error ) yourls_die( $ydb->last_error, 'Fatal error', 503 ); - if ( defined('YOURLS_DEBUG') && YOURLS_DEBUG === true ) + if ( defined( 'YOURLS_DEBUG' ) && YOURLS_DEBUG === true ) $ydb->show_errors = true; return $ydb; } // Return XML output. -function yourls_xml_encode($array) { - require_once(YOURLS_INC.'/functions-xml.php'); +function yourls_xml_encode( $array ) { + require_once( YOURLS_INC.'/functions-xml.php' ); $converter= new yourls_array2xml; - return $converter->array2xml($array); + return $converter->array2xml( $array ); } // Return array of all informations associated with keyword. Returns false if keyword not found. Set optional $use_cache to false to force fetching from DB @@ -396,13 +396,13 @@ function yourls_get_keyword_infos( $keyword, $use_cache = true ) { yourls_do_action( 'get_keyword_not_cached', $keyword ); $table = YOURLS_DB_TABLE_URL; - $infos = $ydb->get_row("SELECT * FROM `$table` WHERE `keyword` = '$keyword'"); + $infos = $ydb->get_row( "SELECT * FROM `$table` WHERE `keyword` = '$keyword'" ); if( $infos ) { $infos = (array)$infos; - $ydb->infos[$keyword] = $infos; + $ydb->infos[ $keyword ] = $infos; } else { - $ydb->infos[$keyword] = false; + $ydb->infos[ $keyword ] = false; } return yourls_apply_filter( 'get_keyword_infos', $ydb->infos[$keyword], $keyword ); @@ -420,8 +420,8 @@ function yourls_get_keyword_info( $keyword, $field, $notfound = false ) { $infos = yourls_get_keyword_infos( $keyword ); $return = $notfound; - if ( isset($infos[$field]) && $infos[$field] !== false ) - $return = $infos[$field]; + if ( isset( $infos[ $field ] ) && $infos[ $field ] !== false ) + $return = $infos[ $field ]; return yourls_apply_filter( 'get_keyword_info', $return, $keyword, $field, $notfound ); } @@ -462,9 +462,9 @@ function yourls_update_clicks( $keyword, $clicks = false ) { $keyword = yourls_sanitize_string( $keyword ); $table = YOURLS_DB_TABLE_URL; if ( $clicks !== false && is_int( $clicks ) && $clicks >= 0 ) - $update = $ydb->query("UPDATE `$table` SET `clicks` = $clicks WHERE `keyword` = '$keyword'"); + $update = $ydb->query( "UPDATE `$table` SET `clicks` = $clicks WHERE `keyword` = '$keyword'" ); else - $update = $ydb->query("UPDATE `$table` SET `clicks` = clicks + 1 WHERE `keyword` = '$keyword'"); + $update = $ydb->query( "UPDATE `$table` SET `clicks` = clicks + 1 WHERE `keyword` = '$keyword'" ); yourls_do_action( 'update_clicks', $keyword, $update, $clicks ); return $update; @@ -476,21 +476,21 @@ function yourls_get_stats( $filter = 'top', $limit = 10, $start = 0 ) { switch( $filter ) { case 'bottom': - $sort_by = 'clicks'; + $sort_by = 'clicks'; $sort_order = 'asc'; break; case 'last': - $sort_by = 'timestamp'; + $sort_by = 'timestamp'; $sort_order = 'desc'; break; case 'rand': case 'random': - $sort_by = 'RAND()'; + $sort_by = 'RAND()'; $sort_order = ''; break; case 'top': default: - $sort_by = 'clicks'; + $sort_by = 'clicks'; $sort_order = 'desc'; break; } @@ -501,12 +501,12 @@ function yourls_get_stats( $filter = 'top', $limit = 10, $start = 0 ) { if ( $limit > 0 ) { $table_url = YOURLS_DB_TABLE_URL; - $results = $ydb->get_results("SELECT * FROM `$table_url` WHERE 1=1 ORDER BY `$sort_by` $sort_order LIMIT $start, $limit;"); + $results = $ydb->get_results( "SELECT * FROM `$table_url` WHERE 1=1 ORDER BY `$sort_by` $sort_order LIMIT $start, $limit;" ); $return = array(); $i = 1; - foreach ( (array)$results as $res) { + foreach ( (array)$results as $res ) { $return['links']['link_'.$i++] = array( 'shorturl' => YOURLS_SITE .'/'. $res->keyword, 'url' => $res->url, @@ -530,7 +530,7 @@ function yourls_get_link_stats( $shorturl ) { global $ydb; $table_url = YOURLS_DB_TABLE_URL; - $res = $ydb->get_row("SELECT * FROM `$table_url` WHERE keyword = '$shorturl';"); + $res = $ydb->get_row( "SELECT * FROM `$table_url` WHERE keyword = '$shorturl';" ); $return = array(); if( !$res ) { @@ -544,12 +544,12 @@ function yourls_get_link_stats( $shorturl ) { 'statusCode' => 200, 'message' => 'success', 'link' => array( - 'shorturl' => YOURLS_SITE .'/'. $res->keyword, - 'url' => $res->url, - 'title' => $res->title, - 'timestamp'=> $res->timestamp, - 'ip' => $res->ip, - 'clicks' => $res->clicks, + 'shorturl' => YOURLS_SITE .'/'. $res->keyword, + 'url' => $res->url, + 'title' => $res->title, + 'timestamp'=> $res->timestamp, + 'ip' => $res->ip, + 'clicks' => $res->clicks, ) ); } @@ -574,7 +574,7 @@ function yourls_api_db_stats() { } // Return array for API stat requests -function yourls_api_url_stats($shorturl) { +function yourls_api_url_stats( $shorturl ) { $keyword = str_replace( YOURLS_SITE . '/' , '', $shorturl ); // accept either 'http://ozh.in/abc' or 'abc' $keyword = yourls_sanitize_string( $keyword ); @@ -592,18 +592,18 @@ function yourls_api_expand( $shorturl ) { if( $longurl ) { $return = array( - 'keyword' => $keyword, - 'shorturl' => YOURLS_SITE . "/$keyword", - 'longurl' => $longurl, - 'simple' => $longurl, - 'message' => 'success', + 'keyword' => $keyword, + 'shorturl' => YOURLS_SITE . "/$keyword", + 'longurl' => $longurl, + 'simple' => $longurl, + 'message' => 'success', 'statusCode' => 200, ); } else { $return = array( - 'keyword' => $keyword, - 'simple' => 'not found', - 'message' => 'Error: short URL not found', + 'keyword' => $keyword, + 'simple' => 'not found', + 'message' => 'Error: short URL not found', 'errorCode' => 404, ); } @@ -617,7 +617,7 @@ function yourls_get_db_stats( $where = '' ) { global $ydb; $table_url = YOURLS_DB_TABLE_URL; - $totals = $ydb->get_row("SELECT COUNT(keyword) as count, SUM(clicks) as sum FROM `$table_url` WHERE 1=1 $where"); + $totals = $ydb->get_row( "SELECT COUNT(keyword) as count, SUM(clicks) as sum FROM `$table_url` WHERE 1=1 $where" ); $return = array( 'total_links' => $totals->count, 'total_clicks' => $totals->sum ); return yourls_apply_filter( 'get_db_stats', $return, $where ); @@ -634,18 +634,18 @@ function yourls_api_output( $mode, $return ) { switch ( $mode ) { case 'jsonp': - header('Content-type: application/javascript'); - echo $return['callback'] . '(' . json_encode($return) . ')'; + header( 'Content-type: application/javascript' ); + echo $return['callback'] . '(' . json_encode( $return ) . ')'; break; case 'json': - header('Content-type: application/json'); - echo json_encode($return); + header( 'Content-type: application/json' ); + echo json_encode( $return ); break; case 'xml': - header('Content-type: application/xml'); - echo yourls_xml_encode($return); + header( 'Content-type: application/xml' ); + echo yourls_xml_encode( $return ); break; case 'simple': @@ -819,7 +819,7 @@ function yourls_log_redirect( $keyword ) { // Check if we want to not log redirects (for stats) function yourls_do_log_redirect() { - return ( !defined('YOURLS_NOSTATS') || YOURLS_NOSTATS != true ); + return ( !defined( 'YOURLS_NOSTATS' ) || YOURLS_NOSTATS != true ); } // Converts an IP to a 2 letter country code, using GeoIP database if available in includes/geo/ @@ -851,14 +851,14 @@ function yourls_geo_countrycode_to_countryname( $code ) { return $country; // Load the Geo class if not already done - if( !class_exists('GeoIP') ) { - $temp = yourls_geo_ip_to_countrycode('127.0.0.1'); + if( !class_exists( 'GeoIP' ) ) { + $temp = yourls_geo_ip_to_countrycode( '127.0.0.1' ); } - if( class_exists('GeoIP') ) { - $geo = new GeoIP; - $id = $geo->GEOIP_COUNTRY_CODE_TO_NUMBER[$code]; - $long = $geo->GEOIP_COUNTRY_NAMES[$id]; + if( class_exists( 'GeoIP' ) ) { + $geo = new GeoIP; + $id = $geo->GEOIP_COUNTRY_CODE_TO_NUMBER[ $code ]; + $long = $geo->GEOIP_COUNTRY_NAMES[ $id ]; return $long; } else { return false; @@ -868,7 +868,7 @@ function yourls_geo_countrycode_to_countryname( $code ) { // Return flag URL from 2 letter country code function yourls_geo_get_flag( $code ) { if( file_exists( YOURLS_INC.'/geo/flags/flag_'.strtolower($code).'.gif' ) ) { - $img = yourls_match_current_protocol( YOURLS_SITE.'/includes/geo/flags/flag_'.(strtolower($code)).'.gif' ); + $img = yourls_match_current_protocol( YOURLS_SITE.'/includes/geo/flags/flag_'.( strtolower( $code ) ).'.gif' ); } else { $img = false; } @@ -919,7 +919,7 @@ function yourls_get_option( $option_name, $default = false ) { } else { // option does not exist, so we must cache its non-existence $value = $default; } - $ydb->option[$option_name] = yourls_maybe_unserialize( $value ); + $ydb->option[ $option_name ] = yourls_maybe_unserialize( $value ); } return yourls_apply_filter( 'get_option_'.$option_name, $ydb->option[$option_name] ); @@ -936,7 +936,7 @@ function yourls_get_all_options() { $table = YOURLS_DB_TABLE_OPTIONS; - $allopt = $ydb->get_results("SELECT `option_name`, `option_value` FROM `$table` WHERE 1=1"); + $allopt = $ydb->get_results( "SELECT `option_name`, `option_value` FROM `$table` WHERE 1=1" ); foreach( (array)$allopt as $option ) { $ydb->option[$option->option_name] = yourls_maybe_unserialize( $option->option_value ); @@ -967,10 +967,10 @@ function yourls_update_option( $option_name, $newvalue ) { yourls_do_action( 'update_option', $option_name, $oldvalue, $newvalue ); - $ydb->query( "UPDATE `$table` SET `option_value` = '$_newvalue' WHERE `option_name` = '$option_name'"); + $ydb->query( "UPDATE `$table` SET `option_value` = '$_newvalue' WHERE `option_name` = '$option_name'" ); if ( $ydb->rows_affected == 1 ) { - $ydb->option[$option_name] = $newvalue; + $ydb->option[ $option_name ] = $newvalue; return true; } return false; @@ -991,7 +991,7 @@ function yourls_add_option( $name, $value = '' ) { yourls_do_action( 'add_option', $safe_name, $_value ); $ydb->query( "INSERT INTO `$table` (`option_name`, `option_value`) VALUES ('$name', '$_value')" ); - $ydb->option[$name] = $value; + $ydb->option[ $name ] = $value; return; } @@ -1004,7 +1004,7 @@ function yourls_delete_option( $name ) { // Get the ID, if no ID then return $option = $ydb->get_row( "SELECT option_id FROM `$table` WHERE `option_name` = '$name'" ); - if ( is_null($option) || !$option->option_id ) + if ( is_null( $option ) || !$option->option_id ) return false; yourls_do_action( 'delete_option', $option_name ); @@ -1320,8 +1320,8 @@ function yourls_add_query_arg() { } // Navigates through an array and encodes the values to be used in a URL. Stolen from WP, used in yourls_add_query_arg() -function yourls_urlencode_deep($value) { - $value = is_array($value) ? array_map('yourls_urlencode_deep', $value) : urlencode($value); +function yourls_urlencode_deep( $value ) { + $value = is_array( $value ) ? array_map( 'yourls_urlencode_deep', $value ) : urlencode( $value ); return $value; } @@ -1343,7 +1343,7 @@ function yourls_tick() { // Create a time limited, action limited and user limited token function yourls_create_nonce( $action, $user = false ) { if( false == $user ) - $user = defined('YOURLS_USER') ? YOURLS_USER : '-1'; + $user = defined( 'YOURLS_USER' ) ? YOURLS_USER : '-1'; $tick = yourls_tick(); return substr( yourls_salt($tick . $action . $user), 0, 10 ); } @@ -1368,7 +1368,7 @@ function yourls_nonce_url( $action, $url = false, $name = 'nonce', $user = false function yourls_verify_nonce( $action, $nonce = false, $user = false, $return = '' ) { // get user if( false == $user ) - $user = defined('YOURLS_USER') ? YOURLS_USER : '-1'; + $user = defined( 'YOURLS_USER' ) ? YOURLS_USER : '-1'; // get current nonce value if( false == $nonce && isset( $_REQUEST['nonce'] ) ) @@ -1400,28 +1400,28 @@ function yourls_statlink( $keyword = '' ) { // Check if we're in API mode. Returns bool function yourls_is_API() { - if ( defined('YOURLS_API') && YOURLS_API == true ) + if ( defined( 'YOURLS_API' ) && YOURLS_API == true ) return true; return false; } // Check if we're in Ajax mode. Returns bool function yourls_is_Ajax() { - if ( defined('YOURLS_AJAX') && YOURLS_AJAX == true ) + if ( defined( 'YOURLS_AJAX' ) && YOURLS_AJAX == true ) return true; return false; } // Check if we're in GO mode (yourls-go.php). Returns bool function yourls_is_GO() { - if ( defined('YOURLS_GO') && YOURLS_GO == true ) + if ( defined( 'YOURLS_GO' ) && YOURLS_GO == true ) return true; return false; } // Check if we're displaying stats infos (yourls-infos.php). Returns bool function yourls_is_infos() { - if ( defined('YOURLS_INFOS') && YOURLS_INFOS == true ) + if ( defined( 'YOURLS_INFOS' ) && YOURLS_INFOS == true ) return true; return false; } @@ -1435,7 +1435,7 @@ function yourls_has_interface() { // Check if we're in the admin area. Returns bool function yourls_is_admin() { - if ( defined('YOURLS_ADMIN') && YOURLS_ADMIN == true ) + if ( defined( 'YOURLS_ADMIN' ) && YOURLS_ADMIN == true ) return true; return false; } @@ -1481,12 +1481,12 @@ function yourls_site_url( $echo = true, $url = '' ) { // Check if SSL is used, returns bool. Stolen from WP. function yourls_is_ssl() { $is_ssl = false; - if ( isset($_SERVER['HTTPS']) ) { - if ( 'on' == strtolower($_SERVER['HTTPS']) ) + if ( isset( $_SERVER['HTTPS'] ) ) { + if ( 'on' == strtolower( $_SERVER['HTTPS'] ) ) $is_ssl = true; if ( '1' == $_SERVER['HTTPS'] ) $is_ssl = true; - } elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) { + } elseif ( isset( $_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) { $is_ssl = true; } return yourls_apply_filter( 'is_ssl', $is_ssl ); diff --git a/includes/load-yourls.php b/includes/load-yourls.php index 37da106..a27df88 100644 --- a/includes/load-yourls.php +++ b/includes/load-yourls.php @@ -2,97 +2,97 @@ // This file initialize everything needed for YOURLS // Include settings -if( file_exists( dirname(dirname(__FILE__)).'/user/config.php' ) ) { +if( file_exists( dirname( dirname( __FILE__ ) ) . '/user/config.php' ) ) { // config.php in /user/ - require_once( dirname(dirname(__FILE__)).'/user/config.php' ); -} elseif ( file_exists( dirname(__FILE__).'/config.php' ) ) { + require_once( dirname( dirname( __FILE__ ) ) . '/user/config.php' ); +} elseif ( file_exists( dirname( __FILE__ ) . '/config.php' ) ) { // config.php in /includes/ - require_once( dirname(__FILE__).'/config.php' ); + require_once( dirname( __FILE__ ) . '/config.php' ); } else { // config.php not found :( - die('

Cannot find config.php.

Please read the readme.html to learn how to install YOURLS

'); + die( '

Cannot find config.php.

Please read the readme.html to learn how to install YOURLS

' ); } // Check if config.php was properly updated for 1.4 -if( !defined('YOURLS_DB_PREFIX') ) - die('

Your config.php does not contain all the required constant definitions.

Please check config-sample.php and update your config accordingly, there are new stuffs!

'); +if( !defined( 'YOURLS_DB_PREFIX' ) ) + die( '

Your config.php does not contain all the required constant definitions.

Please check config-sample.php and update your config accordingly, there are new stuffs!

' ); // Define core constants that have not been user defined in config.php // physical path of YOURLS root -if( !defined('YOURLS_ABSPATH') ) - define('YOURLS_ABSPATH', str_replace( '\\', '/', dirname(dirname(__FILE__)) ) ); +if( !defined( 'YOURLS_ABSPATH' ) ) + define( 'YOURLS_ABSPATH', str_replace( '\\', '/', dirname( dirname( __FILE__ ) ) ) ); // physical path of includes directory -if( !defined('YOURLS_INC') ) - define('YOURLS_INC', YOURLS_ABSPATH.'/includes' ); +if( !defined( 'YOURLS_INC' ) ) + define( 'YOURLS_INC', YOURLS_ABSPATH.'/includes' ); // physical path of user directory -if( !defined('YOURLS_USERDIR') ) - define('YOURLS_USERDIR', YOURLS_ABSPATH.'/user' ); +if( !defined( 'YOURLS_USERDIR' ) ) + define( 'YOURLS_USERDIR', YOURLS_ABSPATH.'/user' ); // URL of user directory -if( !defined('YOURLS_USERURL') ) - define('YOURLS_USERURL', YOURLS_SITE.'/user'); +if( !defined( 'YOURLS_USERURL' ) ) + define( 'YOURLS_USERURL', YOURLS_SITE.'/user' ); // physical path of plugins directory -if( !defined('YOURLS_PLUGINDIR') ) - define('YOURLS_PLUGINDIR', YOURLS_USERDIR.'/plugins' ); +if( !defined( 'YOURLS_PLUGINDIR' ) ) + define( 'YOURLS_PLUGINDIR', YOURLS_USERDIR.'/plugins' ); // URL of plugins directory -if( !defined('YOURLS_PLUGINURL') ) - define('YOURLS_PLUGINURL', YOURLS_USERURL.'/plugins'); +if( !defined( 'YOURLS_PLUGINURL' ) ) + define( 'YOURLS_PLUGINURL', YOURLS_USERURL.'/plugins' ); // physical path of pages directory -if( !defined('YOURLS_PAGEDIR') ) +if( !defined( 'YOURLS_PAGEDIR' ) ) define('YOURLS_PAGEDIR', YOURLS_ABSPATH.'/pages' ); // table to store URLs -if( !defined('YOURLS_DB_TABLE_URL') ) - define('YOURLS_DB_TABLE_URL', YOURLS_DB_PREFIX.'url'); +if( !defined( 'YOURLS_DB_TABLE_URL' ) ) + define( 'YOURLS_DB_TABLE_URL', YOURLS_DB_PREFIX.'url' ); // table to store options -if( !defined('YOURLS_DB_TABLE_OPTIONS') ) - define('YOURLS_DB_TABLE_OPTIONS', YOURLS_DB_PREFIX.'options'); +if( !defined( 'YOURLS_DB_TABLE_OPTIONS' ) ) + define( 'YOURLS_DB_TABLE_OPTIONS', YOURLS_DB_PREFIX.'options' ); // table to store hits, for stats -if( !defined('YOURLS_DB_TABLE_LOG') ) - define('YOURLS_DB_TABLE_LOG', YOURLS_DB_PREFIX.'log'); +if( !defined( 'YOURLS_DB_TABLE_LOG' ) ) + define( 'YOURLS_DB_TABLE_LOG', YOURLS_DB_PREFIX.'log' ); // minimum delay in sec before a same IP can add another URL. Note: logged in users are not throttled down. -if( !defined('YOURLS_FLOOD_DELAY_SECONDS') ) - define('YOURLS_FLOOD_DELAY_SECONDS', 15 ); +if( !defined( 'YOURLS_FLOOD_DELAY_SECONDS' ) ) + define( 'YOURLS_FLOOD_DELAY_SECONDS', 15 ); // comma separated list of IPs that can bypass flood check. -if( !defined('YOURLS_FLOOD_IP_WHITELIST') ) - define('YOURLS_FLOOD_IP_WHITELIST', '' ); +if( !defined( 'YOURLS_FLOOD_IP_WHITELIST' ) ) + define( 'YOURLS_FLOOD_IP_WHITELIST', '' ); // life span of an auth cookie in seconds (60*60*24*7 = 7 days) -if( !defined('YOURLS_COOKIE_LIFE') ) +if( !defined( 'YOURLS_COOKIE_LIFE' ) ) define( 'YOURLS_COOKIE_LIFE', 60*60*24*7 ); // life span of a nonce in seconds -if( !defined('YOURLS_NONCE_LIFE') ) +if( !defined( 'YOURLS_NONCE_LIFE' ) ) define( 'YOURLS_NONCE_LIFE', 43200 ); // 3600 * 12 // if set to true, disable stat logging (no use for it, too busy servers, ...) -if( !defined('YOURLS_NOSTATS') ) +if( !defined( 'YOURLS_NOSTATS' ) ) define( 'YOURLS_NOSTATS', false ); // if set to true, force https:// in the admin area -if( !defined('YOURLS_ADMIN_SSL') ) +if( !defined( 'YOURLS_ADMIN_SSL' ) ) define( 'YOURLS_ADMIN_SSL', false ); // if set to true, verbose debug infos. Will break things. Don't enable. -if( !defined('YOURLS_DEBUG') ) +if( !defined( 'YOURLS_DEBUG' ) ) define( 'YOURLS_DEBUG', false ); // Error reporting -if (defined('YOURLS_DEBUG') && YOURLS_DEBUG == true) { - error_reporting(E_ALL); +if( defined( 'YOURLS_DEBUG' ) && YOURLS_DEBUG == true ) { + error_reporting( E_ALL ); } else { - error_reporting(E_ERROR | E_PARSE); + error_reporting( E_ERROR | E_PARSE ); } // Include all functions @@ -107,7 +107,7 @@ } else { require_once( YOURLS_INC.'/class-mysql.php' ); } -require_once( YOURLS_INC.'/functions-plugins.php'); +require_once( YOURLS_INC.'/functions-plugins.php' ); // Load auth functions if needed if( yourls_is_private() ) require_once( YOURLS_INC.'/functions-auth.php' ); @@ -118,8 +118,8 @@ // If request for an admin page is http:// and SSL is required, redirect if( yourls_is_admin() && yourls_needs_ssl() && !yourls_is_ssl() ) { - if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) { - yourls_redirect( preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI']) ); + if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) { + yourls_redirect( preg_replace( '|^http://|', 'https://', $_SERVER['REQUEST_URI'] ) ); exit(); } else { yourls_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); diff --git a/includes/version.php b/includes/version.php index 6666154..a40d78c 100644 --- a/includes/version.php +++ b/includes/version.php @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/yourls-api.php b/yourls-api.php index 0db4b5a..2e2c2e1 100644 --- a/yourls-api.php +++ b/yourls-api.php @@ -1,6 +1,6 @@