From b12aa06ba9c4e712ba829571b1b3e46276c9aff8 Mon Sep 17 00:00:00 2001 From: Tobias Zeising Date: Sun, 28 Apr 2013 10:38:40 +0200 Subject: [PATCH] * update fat free php framework to newest versoin 3.0.6 * only allow update for localhost or loggedin users (thanks a lot to Tiouss) --- README.md | 2 + controllers/Index.php | 6 + libs/f3/audit.php | 60 ++-- libs/f3/auth.php | 79 ++--- libs/f3/base.php | 596 ++++++++++++++++++----------------- libs/f3/basket.php | 94 +++--- libs/f3/changelog.txt | 27 ++ libs/f3/code.css | 2 +- libs/f3/db/cursor.php | 88 +++--- libs/f3/db/jig.php | 36 +-- libs/f3/db/jig/mapper.php | 117 ++++--- libs/f3/db/jig/session.php | 64 ++-- libs/f3/db/mongo.php | 18 +- libs/f3/db/mongo/mapper.php | 117 ++++--- libs/f3/db/mongo/session.php | 64 ++-- libs/f3/db/sql.php | 70 ++-- libs/f3/db/sql/mapper.php | 164 +++++----- libs/f3/db/sql/session.php | 64 ++-- libs/f3/f3.php | 10 +- libs/f3/image.php | 183 ++++++----- libs/f3/log.php | 18 +- libs/f3/magic.php | 86 ++--- libs/f3/markdown.php | 291 +++++++++-------- libs/f3/matrix.php | 48 +-- libs/f3/session.php | 62 ++-- libs/f3/smtp.php | 70 ++-- libs/f3/template.php | 105 +++--- libs/f3/test.php | 26 +- libs/f3/utf.php | 118 +++---- libs/f3/web.php | 197 +++++++----- libs/f3/web/geo.php | 22 +- libs/f3/web/openid.php | 49 +-- libs/f3/web/pingback.php | 34 +- 33 files changed, 1552 insertions(+), 1435 deletions(-) diff --git a/README.md b/README.md index 395ae89fc4..00b2c7ba4e 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,8 @@ Version 2.7-SNAPSHOT * Fix issues with refreshing the items list and slow ajax requests (thanks a lot to Sean Rand) * Don't leave behind sp-container divs when refreshing the tags (thanks a lot to Sean Rand) * Clean up orphaned items of deleted sources (thanks a lot to Sean Rand) +* update fat free php framework to newest versoin 3.0.6 +* only allow update for localhost or loggedin users (thanks a lot to Tiouss) Version 2.6 * fixed OPML import for other formats (thanks a lot to Remy Gardette) diff --git a/controllers/Index.php b/controllers/Index.php index b93262d58c..793adccb68 100644 --- a/controllers/Index.php +++ b/controllers/Index.php @@ -176,8 +176,14 @@ public function logout() { * @return void */ public function update() { + // only allow access for localhost and loggedin users + if ($_SERVER['REMOTE_ADDR'] !== $_SERVER['SERVER_ADDR'] && $_SERVER['REMOTE_ADDR'] !== "127.0.0.1" && \F3::get('auth')->isLoggedin() != 1) + die("unallowed access"); + + // update feeds $loader = new \helpers\ContentLoader(); $loader->update(); + echo "finished"; } diff --git a/libs/f3/audit.php b/libs/f3/audit.php index d83d004868..f429801cd9 100644 --- a/libs/f3/audit.php +++ b/libs/f3/audit.php @@ -1,7 +1,7 @@ args['dc']); @@ -125,10 +125,10 @@ protected function _ldap($id,$pw) { } /** - SMTP storage handler - @return bool - @param $id string - @param $pw string + * SMTP storage handler + * @return bool + * @param $id string + * @param $pw string **/ protected function _smtp($id,$pw) { $socket=@fsockopen( @@ -172,22 +172,23 @@ protected function _smtp($id,$pw) { } /** - Login auth mechanism - @return bool - @param $id string - @param $pw string - @param $realm string + * Login auth mechanism + * @return bool + * @param $id string + * @param $pw string + * @param $realm string **/ function login($id,$pw,$realm=NULL) { return $this->{'_'.$this->storage}($id,$pw,$realm); } /** - HTTP basic auth mechanism - @return bool - @param $func callback + * HTTP basic auth mechanism + * @return bool + * @param $func callback + * @param $halt bool **/ - function basic($func=NULL) { + function basic($func=NULL,$halt=TRUE) { $fw=Base::instance(); $realm=$fw->get('REALM'); if (isset($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW']) && @@ -201,14 +202,16 @@ function basic($func=NULL) { return TRUE; if (PHP_SAPI!='cli') header('WWW-Authenticate: Basic realm="'.$realm.'"'); - $fw->error(401); + if ($halt) + $fw->error(401); + return FALSE; } /** - Instantiate class - @return object - @param $storage string|object - @param $args array + * Instantiate class + * @return object + * @param $storage string|object + * @param $args array **/ function __construct($storage,array $args=NULL) { if (is_object($storage) && is_a($storage,'DB\Cursor')) { diff --git a/libs/f3/base.php b/libs/f3/base.php index 683324d98a..12611b7836 100644 --- a/libs/f3/base.php +++ b/libs/f3/base.php @@ -1,7 +1,7 @@ hive[$key]=&$GLOBALS['_'.$key]; } /** - Return the parts of specified hive key - @return array - @param $key string + * Return the parts of specified hive key + * @return array + * @param $key string **/ private function cut($key) { return preg_split('/\[\h*[\'"]?(.+?)[\'"]?\h*\]|(->)|\./', @@ -125,11 +125,11 @@ private function cut($key) { } /** - Get hive key reference/contents; Add non-existent hive keys, - array elements, and object properties by default - @return mixed - @param $key string - @param $add bool + * Get hive key reference/contents; Add non-existent hive keys, + * array elements, and object properties by default + * @return mixed + * @param $key string + * @param $add bool **/ function &ref($key,$add=TRUE) { $parts=$this->cut($key); @@ -170,9 +170,9 @@ function &ref($key,$add=TRUE) { } /** - Return TRUE if hive key is not empty - @return bool - @param $key string + * Return TRUE if hive key is not empty + * @return bool + * @param $key string **/ function exists($key) { $ref=&$this->ref($key,FALSE); @@ -182,11 +182,11 @@ function exists($key) { } /** - Bind value to hive key - @return mixed - @param $key string - @param $val mixed - @param $ttl int + * Bind value to hive key + * @return mixed + * @param $key string + * @param $val mixed + * @param $ttl int **/ function set($key,$val,$ttl=0) { if (preg_match('/^(GET|POST|COOKIE)\b(.+)/',$key,$expr)) { @@ -204,9 +204,6 @@ function set($key,$val,$ttl=0) { case 'ENCODING': $val=ini_set('default_charset',$val); break; - case 'JAR': - call_user_func_array('session_set_cookie_params',$val); - break; case 'FALLBACK': $this->fallback=$val; $lang=$this->language($this->hive['LANGUAGE']); @@ -224,17 +221,20 @@ function set($key,$val,$ttl=0) { } $ref=&$this->ref($key); $ref=$val; + if (preg_match('/^JAR\b/',$key)) + call_user_func_array( + 'session_set_cookie_params',$this->hive['JAR']); if ($ttl) // Persist the key-value pair - Cache::instance()->set($this->hash($key).'.var',$val); + Cache::instance()->set($this->hash($key).'.var',$val,$ttl); return $ref; } /** - Retrieve contents of hive key - @return mixed - @param $key string - @param $args string|array + * Retrieve contents of hive key + * @return mixed + * @param $key string + * @param $args string|array **/ function get($key,$args=NULL) { if (is_string($val=$this->ref($key,FALSE)) && !is_null($args)) @@ -251,9 +251,9 @@ function get($key,$args=NULL) { } /** - Unset hive key - @return NULL - @param $key string + * Unset hive key + * @return NULL + * @param $key string **/ function clear($key) { // Normalize array literal @@ -307,11 +307,11 @@ function clear($key) { } /** - Multi-variable assignment using associative array - @return NULL - @param $vars array - @param $prefix string - @param $ttl int + * Multi-variable assignment using associative array + * @return NULL + * @param $vars array + * @param $prefix string + * @param $ttl int **/ function mset(array $vars,$prefix='',$ttl=0) { foreach ($vars as $key=>$val) @@ -319,18 +319,18 @@ function mset(array $vars,$prefix='',$ttl=0) { } /** - Publish hive contents - @return array + * Publish hive contents + * @return array **/ function hive() { return $this->hive; } /** - Copy contents of hive variable to another - @return mixed - @param $src string - @param $dst string + * Copy contents of hive variable to another + * @return mixed + * @param $src string + * @param $dst string **/ function copy($src,$dst) { $ref=&$this->ref($dst); @@ -338,10 +338,10 @@ function copy($src,$dst) { } /** - Concatenate string to hive string variable - @return string - @param $key string - @param $val string + * Concatenate string to hive string variable + * @return string + * @param $key string + * @param $val string **/ function concat($key,$val) { $ref=&$this->ref($key); @@ -350,10 +350,10 @@ function concat($key,$val) { } /** - Swap keys and values of hive array variable - @return array - @param $key string - @public + * Swap keys and values of hive array variable + * @return array + * @param $key string + * @public **/ function flip($key) { $ref=&$this->ref($key); @@ -361,10 +361,10 @@ function flip($key) { } /** - Add element to the end of hive array variable - @return mixed - @param $key string - @param $val mixed + * Add element to the end of hive array variable + * @return mixed + * @param $key string + * @param $val mixed **/ function push($key,$val) { $ref=&$this->ref($key); @@ -373,9 +373,9 @@ function push($key,$val) { } /** - Remove last element of hive array variable - @return mixed - @param $key string + * Remove last element of hive array variable + * @return mixed + * @param $key string **/ function pop($key) { $ref=&$this->ref($key); @@ -383,10 +383,10 @@ function pop($key) { } /** - Add element to the beginning of hive array variable - @return mixed - @param $key string - @param $val mixed + * Add element to the beginning of hive array variable + * @return mixed + * @param $key string + * @param $val mixed **/ function unshift($key,$val) { $ref=&$this->ref($key); @@ -395,9 +395,9 @@ function unshift($key,$val) { } /** - Remove first element of hive array variable - @return mixed - @param $key string + * Remove first element of hive array variable + * @return mixed + * @param $key string **/ function shift($key) { $ref=&$this->ref($key); @@ -405,18 +405,18 @@ function shift($key) { } /** - Convert backslashes to slashes - @return string - @param $str string + * Convert backslashes to slashes + * @return string + * @param $str string **/ function fixslashes($str) { return $str?strtr($str,'\\','/'):$str; } /** - Split comma-, semi-colon, or pipe-separated string - @return array - @param $str string + * Split comma-, semi-colon, or pipe-separated string + * @return array + * @param $str string **/ function split($str) { return array_map('trim', @@ -424,9 +424,9 @@ function split($str) { } /** - Convert PHP expression/value to compressed exportable string - @return string - @param $arg mixed + * Convert PHP expression/value to compressed exportable string + * @return string + * @param $arg mixed **/ function stringify($arg) { switch (gettype($arg)) { @@ -456,9 +456,9 @@ function stringify($arg) { } /** - Flatten array values and return as CSV string - @return string - @param $args array + * Flatten array values and return as CSV string + * @return string + * @param $args array **/ function csv(array $args) { return implode(',',array_map('stripcslashes', @@ -466,9 +466,9 @@ function csv(array $args) { } /** - Convert snakecase string to camelcase - @return string - @param $str string + * Convert snakecase string to camelcase + * @return string + * @param $str string **/ function camelcase($str) { return preg_replace_callback( @@ -481,28 +481,28 @@ function($match) { } /** - Convert camelcase string to snakecase - @return string - @param $str string + * Convert camelcase string to snakecase + * @return string + * @param $str string **/ function snakecase($str) { return strtolower(preg_replace('/[[:upper:]]/','_\0',$str)); } /** - Return -1 if specified number is negative, 0 if zero, - or 1 if the number is positive - @return int - @param $num mixed + * Return -1 if specified number is negative, 0 if zero, + * or 1 if the number is positive + * @return int + * @param $num mixed **/ function sign($num) { return $num?($num/abs($num)):0; } /** - Generate 64bit/base36 hash - @return string - @param $str + * Generate 64bit/base36 hash + * @return string + * @param $str **/ function hash($str) { return str_pad(base_convert( @@ -510,19 +510,19 @@ function hash($str) { } /** - Return Base64-encoded equivalent - @return string - @param $data string - @param $mime string + * Return Base64-encoded equivalent + * @return string + * @param $data string + * @param $mime string **/ function base64($data,$mime) { return 'data:'.$mime.';base64,'.base64_encode($data); } /** - Convert special characters to HTML entities - @return string - @param $str string + * Convert special characters to HTML entities + * @return string + * @param $str string **/ function encode($str) { return @htmlentities($str,ENT_COMPAT,$this->hive['ENCODING'],FALSE)?: @@ -530,27 +530,27 @@ function encode($str) { } /** - Convert HTML entities back to characters - @return string - @param $str string + * Convert HTML entities back to characters + * @return string + * @param $str string **/ function decode($str) { return html_entity_decode($str,ENT_COMPAT,$this->hive['ENCODING']); } /** - Remove HTML tags (except those enumerated) and non-printable - characters to mitigate XSS/code injection attacks - @return mixed - @param $var mixed - @param $tags string + * Remove HTML tags (except those enumerated) and non-printable + * characters to mitigate XSS/code injection attacks + * @return mixed + * @param $var mixed + * @param $tags string **/ function scrub(&$var,$tags=NULL) { - if (is_string($var)) { - if ($tags) - $tags='<'.implode('><',$this->split($tags)).'>'; - $var=trim(preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F]/','', - ($tags=='*')?$var:strip_tags($var,$tags))); + if (is_string($var) && strlen($var)) { + if ($tags!='*') + $var=strip_tags($var, + '<'.implode('><',$this->split($tags)).'>'); + $var=trim(preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F]/','',$var)); } elseif (is_array($var)) foreach ($var as &$val) { @@ -561,40 +561,46 @@ function scrub(&$var,$tags=NULL) { } /** - Encode characters to equivalent HTML entities - @return string - @param $arg mixed + * Encode characters to equivalent HTML entities + * @return string + * @param $arg mixed **/ function esc($arg) { if (is_string($arg)) return $this->encode($arg); - if (is_array($arg)) + if (is_array($arg) || is_a($arg,'ArrayAccess')) foreach ($arg as &$val) { $val=$this->esc($val); unset($val); } + if (is_object($arg)) + foreach (get_object_vars($arg) as $key=>$val) + $arg->$key=$this->esc($val); return $arg; } /** - Decode HTML entities to equivalent characters - @return string - @param $arg mixed + * Decode HTML entities to equivalent characters + * @return string + * @param $arg mixed **/ function raw($arg) { if (is_string($arg)) return $this->decode($arg); - if (is_array($arg)) + if (is_array($arg) || is_a($arg,'ArrayAccess')) foreach ($arg as &$val) { $val=$this->raw($val); unset($val); } + if (is_object($arg)) + foreach (get_object_vars($arg) as $key=>$val) + $arg->$key=$this->raw($val); return $arg; } /** - Return locale-aware formatted string - @return string + * Return locale-aware formatted string + * @return string **/ function format() { $args=func_get_args(); @@ -664,9 +670,9 @@ function($expr) use($args,$conv) { } /** - Assign/auto-detect language - @return string - @param $code string + * Assign/auto-detect language + * @return string + * @param $code string **/ function language($code=NULL) { if (!$code) { @@ -706,9 +712,9 @@ function language($code=NULL) { } /** - Transfer lexicon entries to hive - @return NULL - @param $path string + * Transfer lexicon entries to hive + * @return NULL + * @param $path string **/ function lexicon($path) { $lex=array(); @@ -737,9 +743,9 @@ function lexicon($path) { } /** - Return string representation of PHP value - @return string - @param $arg mixed + * Return string representation of PHP value + * @return string + * @param $arg mixed **/ function serialize($arg) { switch (strtolower($this->hive['SERIALIZER'])) { @@ -753,9 +759,9 @@ function serialize($arg) { } /** - Return PHP value derived from string - @return string - @param $arg mixed + * Return PHP value derived from string + * @return string + * @param $arg mixed **/ function unserialize($arg) { switch (strtolower($this->hive['SERIALIZER'])) { @@ -769,9 +775,9 @@ function unserialize($arg) { } /** - Send HTTP/1.1 status header; Return text equivalent of status code - @return string - @param $code int + * Send HTTP/1.1 status header; Return text equivalent of status code + * @return string + * @param $code int **/ function status($code) { if (PHP_SAPI!='cli') @@ -780,9 +786,9 @@ function status($code) { } /** - Send cache metadata to HTTP client - @return NULL - @param $secs int + * Send cache metadata to HTTP client + * @return NULL + * @param $secs int **/ function expire($secs=0) { if (PHP_SAPI!='cli') { @@ -806,13 +812,13 @@ function expire($secs=0) { } /** - Log error; Execute ONERROR handler if defined, else display - default error page (HTML for synchronous requests, JSON string - for AJAX requests) - @return NULL - @param $code int - @param $text string - @param $trace array + * Log error; Execute ONERROR handler if defined, else display + * default error page (HTML for synchronous requests, JSON string + * for AJAX requests) + * @return NULL + * @param $code int + * @param $text string + * @param $trace array **/ function error($code,$text='',array $trace=NULL) { $prior=$this->hive['ERROR']; @@ -882,12 +888,12 @@ function($frame) use($debug) { } /** - Mock HTTP request - @return NULL - @param $pattern string - @param $args array - @param $headers array - @param $body string + * Mock HTTP request + * @return NULL + * @param $pattern string + * @param $args array + * @param $headers array + * @param $body string **/ function mock($pattern,array $args=NULL,array $headers=NULL,$body=NULL) { $types=array('sync','ajax'); @@ -919,12 +925,12 @@ function mock($pattern,array $args=NULL,array $headers=NULL,$body=NULL) { } /** - Bind handler to route pattern - @return NULL - @param $pattern string - @param $handler callback - @param $ttl int - @param $kbps int + * Bind handler to route pattern + * @return NULL + * @param $pattern string + * @param $handler callback + * @param $ttl int + * @param $kbps int **/ function route($pattern,$handler,$ttl=0,$kbps=0) { $types=array('sync','ajax'); @@ -944,27 +950,28 @@ function route($pattern,$handler,$ttl=0,$kbps=0) { } /** - Reroute to specified URI - @return NULL - @param $uri string + * Reroute to specified URI + * @return NULL + * @param $uri string + * @param $permanent bool **/ - function reroute($uri) { + function reroute($uri,$permanent=FALSE) { if (PHP_SAPI!='cli') { @session_commit(); header('Location: '.(preg_match('/^https?:\/\//',$uri)? $uri:($this->hive['BASE'].$uri))); - $this->status($this->hive['VERB']=='GET'?301:303); + $this->status($permanent?301:303); die; } $this->mock('GET '.$uri); } /** - Provide ReST interface by mapping HTTP verb to class method - @param $url string - @param $class string - @param $ttl int - @param $kbps int + * Provide ReST interface by mapping HTTP verb to class method + * @param $url string + * @param $class string + * @param $ttl int + * @param $kbps int **/ function map($url,$class,$ttl=0,$kbps=0) { $fluid=preg_match('/@\w+/',$url); @@ -977,9 +984,9 @@ function map($url,$class,$ttl=0,$kbps=0) { } /** - Return TRUE if IPv4 address exists in DNSBL - @return bool - @param $ip string + * Return TRUE if IPv4 address exists in DNSBL + * @return bool + * @param $ip string **/ function blacklisted($ip) { if ($this->hive['DNSBL'] && @@ -1000,8 +1007,8 @@ function blacklisted($ip) { } /** - Match routes against incoming URI - @return NULL + * Match routes against incoming URI + * @return NULL **/ function run() { if ($this->blacklisted($this->hive['IP'])) @@ -1014,7 +1021,7 @@ function run() { krsort($this->hive['ROUTES']); // Convert to BASE-relative URL $req=preg_replace( - '/^'.preg_quote($this->hive['BASE'],'/').'\b(.*)/','\1', + '/^'.preg_quote($this->hive['BASE'],'/').'(\/.*|$)/','\1', $this->hive['URI'] ); $allowed=array(); @@ -1056,6 +1063,7 @@ function($id) use($args) { // Save matching route $this->hive['PATTERN']=$url; // Process request + $body=''; $now=microtime(TRUE); if (preg_match('/GET|HEAD/',$this->hive['VERB']) && isset($ttl)) { @@ -1066,13 +1074,6 @@ function($id) use($args) { $hash=$this->hash($this->hive['VERB'].' '. $this->hive['URI']).'.url',$data); if ($cached && $cached+$ttl>$now) { - if (isset($headers['If-Modified-Since']) && - strtotime($headers['If-Modified-Since'])> - floor($cached)) { - // HTTP client-cached page is fresh - $this->status(304); - die; - } // Retrieve from cache backend list($headers,$body)=$data; if (PHP_SAPI!='cli') @@ -1085,14 +1086,16 @@ function($id) use($args) { } else $this->expire(0); - ob_start(); - // Call route handler - $this->call($handler,array($this,$args), - 'beforeroute,afterroute'); - $body=ob_get_clean(); - if ($ttl && !error_get_last()) - // Save to cache backend - $cache->set($hash,array(headers_list(),$body),$ttl); + if (!strlen($body)) { + ob_start(); + // Call route handler + $this->call($handler,array($this,$args), + 'beforeroute,afterroute'); + $body=ob_get_clean(); + if ($ttl && !error_get_last()) + // Save to cache backend + $cache->set($hash,array(headers_list(),$body),$ttl); + } $this->hive['RESPONSE']=$body; if (!$this->hive['QUIET']) { if ($kbps) { @@ -1126,11 +1129,11 @@ function($id) use($args) { } /** - Execute callback/hooks (supports 'class->method' format) - @return mixed|FALSE - @param $func callback - @param $args mixed - @param $hooks string + * Execute callback/hooks (supports 'class->method' format) + * @return mixed|FALSE + * @param $func callback + * @param $args mixed + * @param $hooks string **/ function call($func,$args=NULL,$hooks='') { if (!is_array($args)) @@ -1173,11 +1176,11 @@ function call($func,$args=NULL,$hooks='') { } /** - Execute specified callbacks in succession; Apply same arguments - to all callbacks - @return array - @param $funcs array|string - @param $args mixed + * Execute specified callbacks in succession; Apply same arguments + * to all callbacks + * @return array + * @param $funcs array|string + * @param $args mixed **/ function chain($funcs,$args=NULL) { $out=array(); @@ -1187,11 +1190,11 @@ function chain($funcs,$args=NULL) { } /** - Execute specified callbacks in succession; Relay result of - previous callback as argument to the next callback - @return array - @param $funcs array|string - @param $args mixed + * Execute specified callbacks in succession; Relay result of + * previous callback as argument to the next callback + * @return array + * @param $funcs array|string + * @param $args mixed **/ function relay($funcs,$args=NULL) { foreach (is_array($funcs)?$funcs:$this->split($funcs) as $func) @@ -1200,9 +1203,9 @@ function relay($funcs,$args=NULL) { } /** - Configure framework according to .ini-style file settings - @return NULL - @param $file string + * Configure framework according to .ini-style file settings + * @return NULL + * @param $file string **/ function config($file) { preg_match_all( @@ -1251,11 +1254,11 @@ function($val) { } /** - Create mutex, invoke callback then drop ownership when done - @return mixed - @param $id string - @param $func callback - @param $args mixed + * Create mutex, invoke callback then drop ownership when done + * @return mixed + * @param $id string + * @param $func callback + * @param $args mixed **/ function mutex($id,$func,$args=NULL) { if (!is_dir($tmp=$this->hive['TEMP'])) @@ -1276,10 +1279,10 @@ function mutex($id,$func,$args=NULL) { } /** - Read file (with option to apply Unix LF as standard line ending) - @return string - @param $file string - @param $lf bool + * Read file (with option to apply Unix LF as standard line ending) + * @return string + * @param $file string + * @param $lf bool **/ function read($file,$lf=FALSE) { $out=file_get_contents($file); @@ -1287,20 +1290,20 @@ function read($file,$lf=FALSE) { } /** - Exclusive file write - @return int|FALSE - @param $file string - @param $data mixed - @param $append bool + * Exclusive file write + * @return int|FALSE + * @param $file string + * @param $data mixed + * @param $append bool **/ function write($file,$data,$append=FALSE) { return file_put_contents($file,$data,LOCK_EX|($append?FILE_APPEND:0)); } /** - Apply syntax highlighting - @return string - @param $text string + * Apply syntax highlighting + * @return string + * @param $text string **/ function highlight($text) { $out=''; @@ -1325,18 +1328,18 @@ function highlight($text) { } /** - Dump expression with syntax highlighting - @return NULL - @param $expr mixed + * Dump expression with syntax highlighting + * @return NULL + * @param $expr mixed **/ function dump($expr) { echo $this->highlight($this->stringify($expr)); } /** - Namespace-aware class autoloader - @return mixed - @param $class string + * Namespace-aware class autoloader + * @return mixed + * @param $class string **/ protected function autoload($class) { $class=$this->fixslashes(ltrim($class,'\\')); @@ -1348,8 +1351,8 @@ protected function autoload($class) { } /** - Execute framework/application shutdown sequence - @return NULL + * Execute framework/application shutdown sequence + * @return NULL **/ function unload() { if (($error=error_get_last()) && @@ -1363,8 +1366,8 @@ function unload() { } /** - Return class instance - @return object + * Return class instance + * @return object **/ static function instance() { if (!Registry::exists($class=__CLASS__)) @@ -1421,9 +1424,7 @@ function($code,$text) use($fw) { $scheme=isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on' || isset($headers['X-Forwarded-Proto']) && $headers['X-Forwarded-Proto']=='https'?'https':'http'; - $base=implode('/',array_map('urlencode', - explode('/',$this->fixslashes( - preg_replace('/\/[^\/]+$/','',$_SERVER['SCRIPT_NAME']))))); + $base=preg_replace('/\/[^\/]+$/','',$_SERVER['PHP_SELF']); call_user_func_array('session_set_cookie_params', $jar=array( 'expire'=>0, @@ -1517,8 +1518,8 @@ function($code,$text) use($fw) { } /** - Wrap-up - @return NULL + * Wrap-up + * @return NULL **/ function __destruct() { Registry::clear(__CLASS__); @@ -1538,10 +1539,10 @@ final class Cache { $ref; /** - Return timestamp of cache entry or FALSE if not found - @return float|FALSE - @param $key string - @param $val mixed + * Return timestamp of cache entry or FALSE if not found + * @return float|FALSE + * @param $key string + * @param $val mixed **/ function exists($key,&$val=NULL) { $fw=Base::instance(); @@ -1577,11 +1578,11 @@ function exists($key,&$val=NULL) { } /** - Store value in cache - @return mixed|FALSE - @param $key string - @param $val mixed - @param $ttl int + * Store value in cache + * @return mixed|FALSE + * @param $key string + * @param $val mixed + * @param $ttl int **/ function set($key,$val,$ttl=0) { $fw=Base::instance(); @@ -1606,18 +1607,18 @@ function set($key,$val,$ttl=0) { } /** - Retrieve value of cache entry - @return mixed|FALSE - @param $key string + * Retrieve value of cache entry + * @return mixed|FALSE + * @param $key string **/ function get($key) { return $this->dsn && $this->exists($key,$data)?$data:FALSE; } /** - Delete cache entry - @return bool - @param $key string + * Delete cache entry + * @return bool + * @param $key string **/ function clear($key) { if (!$this->dsn) @@ -1640,10 +1641,10 @@ function clear($key) { } /** - Clear contents of cache backend - @return bool - @param $suffix string - @param $lifetime int + * Clear contents of cache backend + * @return bool + * @param $suffix string + * @param $lifetime int **/ function reset($suffix=NULL,$lifetime=0) { if (!$this->dsn) @@ -1662,9 +1663,10 @@ function reset($suffix=NULL,$lifetime=0) { case 'memcache': foreach (memcache_get_extended_stats( $this->ref,'slabs') as $slabs) - foreach (array_keys($slabs) as $id) + foreach (array_filter(array_keys($slabs),'is_numeric') + as $id) foreach (memcache_get_extended_stats( - $this->ref,'cachedump',floor($id)) as $data) + $this->ref,'cachedump',$id) as $data) if (is_array($data)) foreach ($data as $key=>$val) if (preg_match($regex,$key) && @@ -1691,9 +1693,9 @@ function reset($suffix=NULL,$lifetime=0) { } /** - Load/auto-detect cache backend - @return string - @param $dsn bool|string + * Load/auto-detect cache backend + * @return string + * @param $dsn bool|string **/ function load($dsn) { if ($dsn=trim($dsn)) { @@ -1727,8 +1729,8 @@ function load($dsn) { } /** - Return class instance - @return object + * Return class instance + * @return object **/ static function instance() { if (!Registry::exists($class=__CLASS__)) @@ -1747,8 +1749,8 @@ private function __construct() { } /** - Wrap-up - @return NULL + * Wrap-up + * @return NULL **/ function __destruct() { Registry::clear(__CLASS__); @@ -1760,8 +1762,8 @@ function __destruct() { abstract class Prefab { /** - Return class instance - @return object + * Return class instance + * @return object **/ static function instance() { if (!Registry::exists($class=get_called_class())) @@ -1770,8 +1772,8 @@ static function instance() { } /** - Wrap-up - @return NULL + * Wrap-up + * @return NULL **/ function __destruct() { Registry::clear(get_called_class()); @@ -1789,8 +1791,8 @@ class View extends Prefab { $hive; /** - Create sandbox for template execution - @return string + * Create sandbox for template execution + * @return string **/ protected function sandbox() { extract($this->hive); @@ -1800,11 +1802,11 @@ protected function sandbox() { } /** - Render template - @return string - @param $file string - @param $mime string - @param $hive array + * Render template + * @return string + * @param $file string + * @param $mime string + * @param $hive array **/ function render($file,$mime='text/html',array $hive=NULL) { $fw=Base::instance(); @@ -2170,9 +2172,9 @@ class ISO extends Prefab { //@} /** - Convert class constants to array - @return array - @param $prefix string + * Convert class constants to array + * @return array + * @param $prefix string **/ protected function constants($prefix) { $ref=new ReflectionClass($this); @@ -2187,16 +2189,16 @@ protected function constants($prefix) { } /** - Return list of languages indexed by ISO 639-1 language code - @return array + * Return list of languages indexed by ISO 639-1 language code + * @return array **/ function languages() { return $this->constants('LC_'); } /** - Return list of countries indexed by ISO 3166-1 country code - @return array + * Return list of countries indexed by ISO 3166-1 country code + * @return array **/ function countries() { return $this->constants('CC_'); @@ -2212,37 +2214,37 @@ final class Registry { $table; /** - Return TRUE if object exists in catalog - @return bool - @param $key string + * Return TRUE if object exists in catalog + * @return bool + * @param $key string **/ static function exists($key) { return isset(self::$table[$key]); } /** - Add object to catalog - @return object - @param $key string - @param $obj object + * Add object to catalog + * @return object + * @param $key string + * @param $obj object **/ static function set($key,$obj) { return self::$table[$key]=$obj; } /** - Retrieve object from catalog - @return object - @param $key string + * Retrieve object from catalog + * @return object + * @param $key string **/ static function get($key) { return self::$table[$key]; } /** - Remove object from catalog - @return NULL - @param $key string + * Remove object from catalog + * @return NULL + * @param $key string **/ static function clear($key) { unset(self::$table[$key]); diff --git a/libs/f3/basket.php b/libs/f3/basket.php index 0be3e3a033..b1c8f4b264 100644 --- a/libs/f3/basket.php +++ b/libs/f3/basket.php @@ -1,7 +1,7 @@ item); } /** - Assign value to field - @return scalar|FALSE - @param $key string - @param $val scalar + * Assign value to field + * @return scalar|FALSE + * @param $key string + * @param $val scalar **/ function set($key,$val) { return ($key=='_id')?FALSE:($this->item[$key]=$val); } /** - Retrieve value of field - @return scalar|FALSE - @param $key string + * Retrieve value of field + * @return scalar|FALSE + * @param $key string **/ function get($key) { if ($key=='_id') @@ -58,19 +58,19 @@ function get($key) { } /** - Delete field - @return NULL - @param $key string + * Delete field + * @return NULL + * @param $key string **/ function clear($key) { unset($this->item[$key]); } /** - Return item that matches key/value pair - @return object|FALSE - @param $key string - @param $val mixed + * Return item that matches key/value pair + * @return object|FALSE + * @param $key string + * @param $val mixed **/ function find($key,$val) { if (isset($_SESSION[$this->key])) @@ -85,10 +85,10 @@ function find($key,$val) { } /** - Map current item to matching key/value pair - @return array - @param $key string - @param $val mixed + * Map current item to matching key/value pair + * @return array + * @param $key string + * @param $val mixed **/ function load($key,$val) { if ($found=$this->find($key,$val)) { @@ -100,24 +100,24 @@ function load($key,$val) { } /** - Return TRUE if current item is empty/undefined - @return bool + * Return TRUE if current item is empty/undefined + * @return bool **/ function dry() { return !$this->item; } /** - Return number of items in basket - @return int + * Return number of items in basket + * @return int **/ function count() { return isset($_SESSION[$this->key])?count($_SESSION[$this->key]):0; } /** - Save current item - @return array + * Save current item + * @return array **/ function save() { if (!$this->id) @@ -126,10 +126,10 @@ function save() { } /** - Erase item matching key/value pair - @return bool - @param $key string - @param $val mixed + * Erase item matching key/value pair + * @return bool + * @param $key string + * @param $val mixed **/ function erase($key,$val) { if ($id=$this->find($key,$val)->id) { @@ -142,8 +142,8 @@ function erase($key,$val) { } /** - Reset cursor - @return NULL + * Reset cursor + * @return NULL **/ function reset() { $this->id=NULL; @@ -151,17 +151,17 @@ function reset() { } /** - Empty basket - @return NULL + * Empty basket + * @return NULL **/ function drop() { unset($_SESSION[$this->key]); } /** - Hydrate item using hive array variable - @return NULL - @param $key string + * Hydrate item using hive array variable + * @return NULL + * @param $key string **/ function copyfrom($key) { foreach (\Base::instance()->get($key) as $key=>$val) @@ -169,9 +169,9 @@ function copyfrom($key) { } /** - Populate hive array variable with item contents - @return NULL - @param $key string + * Populate hive array variable with item contents + * @return NULL + * @param $key string **/ function copyto($key) { $var=&\Base::instance()->ref($key); @@ -180,8 +180,8 @@ function copyto($key) { } /** - Check out basket contents - @return array + * Check out basket contents + * @return array **/ function checkout() { if (isset($_SESSION[$this->key])) { @@ -193,9 +193,9 @@ function checkout() { } /** - Instantiate class - @return void - @param $key string + * Instantiate class + * @return void + * @param $key string **/ function __construct($key='basket') { $this->key=$key; diff --git a/libs/f3/changelog.txt b/libs/f3/changelog.txt index b9202c69f3..8e3befa771 100644 --- a/libs/f3/changelog.txt +++ b/libs/f3/changelog.txt @@ -1,5 +1,32 @@ CHANGELOG +3.0.6 (31 Mar 2013) +* NEW: Image->crop() +* Modify documentation blocks for PHPDoc interoperability +* Allow user to control whether Base->rerouet() uses a permanent or + temporary redirect +* Allow JAR elements to be set individually +* Refactor DB\SQL\Mapper->insert() to cope with autoincrement fields +* Trigger error when captcha() font is missing +* Remove unnecessary markdown regex recursion +* Check for scalars instead of DB\SQL strings +* Implement more comprehensive diacritics table +* Add option for disabling 401 errors when basic auth() fails +* Add markdown syntax highlighting for Apache configuration +* Markdown->render() deprecated to remove dependency on UI variable; + Feature replaced by Markdown->convert() to enable translation from + markdown string to HTML +* Optimize factory() code of all data mappers +* Apply backticks on MySQL table names +* Bug fix: Routing failure when directory path contains a tilde (Issue #291) +* Bug fix: Incorrect markdown parsing of strong/em sequences and inline HTML +* Bug fix: Cached page not echoed (Issue #278) +* Bug fix: Object properties not escaped when rendering +* Bug fix: OpenID error response ignored +* Bug fix: memcache_get_extended_stats() timeout +* Bug fix: Base->set() doesn't pass TTL to Cache->set() +* Bug fix: Base->scrub() ignores pass-thru * argument (Issue #274) + 3.0.5 (16 Feb 2013) * NEW: Markdown class with PHP, HTML, and .ini syntax highlighting support * NEW: Options for caching of select() and find() results diff --git a/libs/f3/code.css b/libs/f3/code.css index 9c7b4dc2d9..40e40feb13 100644 --- a/libs/f3/code.css +++ b/libs/f3/code.css @@ -1 +1 @@ -code{word-wrap:break-word;color:black}.comment,.doc_comment,.ml_comment{color:orange}.variable{color:mediumorchid;font-style:italic}.const,.constant_encapsed_string,.class_c,.dir,.file,.func_c,.halt_compiler,.line,.method_c,.ns_c,.ns_separator,.lnumber,.dnumber{color:red}.string,.and_equal,.boolean_and,.boolean_or,.concat_equal,.dec,.div_equal,.inc,.is_equal,.is_greater_or_equal,.is_identical,.is_not_equal,.is_not_identical,.is_smaller_or_equal,.logical_and,.logical_or,.logical_xor,.minus_equal,.mod_equal,.mul_equal,.or_equal,.plus_equal,.sl,.sl_equal,.sr,.sr_equal,.xor_equal,.start_heredoc,.end_heredoc,.object_operator,.paamayim_nekudotayim{color:dimgray}.abstract,.array,.array_cast,.as,.break,.case,.catch,.class,.clone,.continue,.declare,.default,.do,.echo,.else,.elseif,.empty.enddeclare,.endfor,.endforach,.endif,.endswitch,.endwhile,.eval,.exit,.extends,.final,.for,.foreach,.function,.global,.goto,.if,.implements,.include,.include_once,.instanceof,.interface,.isset,.list,.namespace,.new,.print,.private,.public,.protected,.require,.require_once,.return,.static,.switch,.throw,.try,.unset,.use,.var,.while{color:royalblue}.open_tag,.open_tag_with_echo,.close_tag{color:magenta}.ini_section{color:black}.ini_key{color:mediumorchid}.ini_value{color:red}.xml_tag{color:dodgerblue}.xml_attr{color:mediumorchid}.xml_data{color:red} +code{word-wrap:break-word;color:black}.comment,.doc_comment,.ml_comment{color:orange}.variable{color:blueviolet;font-style:italic}.const,.constant_encapsed_string,.class_c,.dir,.file,.func_c,.halt_compiler,.line,.method_c,.ns_c,.ns_separator,.lnumber,.dnumber{color:crimson}.string,.and_equal,.boolean_and,.boolean_or,.concat_equal,.dec,.div_equal,.inc,.is_equal,.is_greater_or_equal,.is_identical,.is_not_equal,.is_not_identical,.is_smaller_or_equal,.logical_and,.logical_or,.logical_xor,.minus_equal,.mod_equal,.mul_equal,.or_equal,.plus_equal,.sl,.sl_equal,.sr,.sr_equal,.xor_equal,.start_heredoc,.end_heredoc,.object_operator,.paamayim_nekudotayim{color:black}.abstract,.array,.array_cast,.as,.break,.case,.catch,.class,.clone,.continue,.declare,.default,.do,.echo,.else,.elseif,.empty.enddeclare,.endfor,.endforach,.endif,.endswitch,.endwhile,.eval,.exit,.extends,.final,.for,.foreach,.function,.global,.goto,.if,.implements,.include,.include_once,.instanceof,.interface,.isset,.list,.namespace,.new,.print,.private,.public,.protected,.require,.require_once,.return,.static,.switch,.throw,.try,.unset,.use,.var,.while{color:royalblue}.open_tag,.open_tag_with_echo,.close_tag{color:orange}.ini_section{color:black}.ini_key{color:royalblue}.ini_value{color:crimson}.xml_tag{color:dodgerblue}.xml_attr{color:blueviolet}.xml_data{color:red}.section{color:black}.directive{color:blue}.data{color:dimgray} diff --git a/libs/f3/db/cursor.php b/libs/f3/db/cursor.php index 6afbde02a8..cab7b9eca2 100644 --- a/libs/f3/db/cursor.php +++ b/libs/f3/db/cursor.php @@ -1,7 +1,7 @@ query[$this->ptr]); } /** - Return first record (mapper object) that matches criteria - @return object|FALSE - @param $filter string|array - @param $options array - @param $ttl int + * Return first record (mapper object) that matches criteria + * @return object|FALSE + * @param $filter string|array + * @param $options array + * @param $ttl int **/ function findone($filter=NULL,array $options=NULL,$ttl=0) { return ($data=$this->find($filter,$options,$ttl))?$data[0]:FALSE; } /** - Return array containing subset of records matching criteria, - number of subsets available, and actual subset position - @return array - @param $pos int - @param $size int - @param $filter string|array - @param $options array + * Return array containing subset of records matching criteria, + * number of subsets available, and actual subset position + * @return array + * @param $pos int + * @param $size int + * @param $filter string|array + * @param $options array **/ function paginate($pos=0,$size=10,$filter=NULL,array $options=NULL) { $count=ceil($this->count($filter,$options)/$size); @@ -93,10 +93,10 @@ function paginate($pos=0,$size=10,$filter=NULL,array $options=NULL) { } /** - Map to first record that matches criteria - @return array|FALSE - @param $filter string|array - @param $options array + * Map to first record that matches criteria + * @return array|FALSE + * @param $filter string|array + * @param $options array **/ function load($filter=NULL,array $options=NULL) { return ($this->query=$this->find($filter,$options)) && @@ -104,25 +104,25 @@ function load($filter=NULL,array $options=NULL) { } /** - Move pointer to first record in cursor - @return mixed + * Move pointer to first record in cursor + * @return mixed **/ function first() { return $this->query[$this->ptr=0]; } /** - Move pointer to last record in cursor - @return mixed + * Move pointer to last record in cursor + * @return mixed **/ function last() { return $this->query[$this->ptr=($ctr=count($this->query))?$ctr-1:0]; } /** - Map to nth record relative to current cursor position - @return mixed - @param $ofs int + * Map to nth record relative to current cursor position + * @return mixed + * @param $ofs int **/ function skip($ofs=1) { $this->ptr+=$ofs; @@ -131,32 +131,32 @@ function skip($ofs=1) { } /** - Map next record - @return mixed + * Map next record + * @return mixed **/ function next() { return $this->skip(); } /** - Map previous record - @return mixed + * Map previous record + * @return mixed **/ function prev() { return $this->skip(-1); } /** - Save mapped record - @return mixed + * Save mapped record + * @return mixed **/ function save() { return $this->query?$this->update():$this->insert(); } /** - Delete current record - @return int|bool + * Delete current record + * @return int|bool **/ function erase() { $this->query=array_slice($this->query,0,$this->ptr,TRUE)+ @@ -165,8 +165,8 @@ function erase() { } /** - Reset cursor - @return NULL + * Reset cursor + * @return NULL **/ function reset() { $this->query=array(); diff --git a/libs/f3/db/jig.php b/libs/f3/db/jig.php index ceab2bcef5..8cc89b9cb4 100644 --- a/libs/f3/db/jig.php +++ b/libs/f3/db/jig.php @@ -1,7 +1,7 @@ log; } /** - Jot down log entry - @return NULL - @param $frame string + * Jot down log entry + * @return NULL + * @param $frame string **/ function jot($frame) { if ($frame) @@ -92,8 +92,8 @@ function jot($frame) { } /** - Clean storage - @return NULL + * Clean storage + * @return NULL **/ function drop() { foreach (glob($this->dir.'/*',GLOB_NOSORT) as $file) @@ -101,9 +101,9 @@ function drop() { } /** - Instantiate class - @param $dir string - @param $format int + * Instantiate class + * @param $dir string + * @param $format int **/ function __construct($dir,$format=self::FORMAT_JSON) { if (!is_dir($dir)) diff --git a/libs/f3/db/jig/mapper.php b/libs/f3/db/jig/mapper.php index b06ea6d1ba..19f418b4c6 100644 --- a/libs/f3/db/jig/mapper.php +++ b/libs/f3/db/jig/mapper.php @@ -1,7 +1,7 @@ document); } /** - Assign value to field - @return scalar|FALSE - @param $key string - @param $val scalar + * Assign value to field + * @return scalar|FALSE + * @param $key string + * @param $val scalar **/ function set($key,$val) { return ($key=='_id')?FALSE:($this->document[$key]=$val); } /** - Retrieve value of field - @return scalar|FALSE - @param $key string + * Retrieve value of field + * @return scalar|FALSE + * @param $key string **/ function get($key) { if ($key=='_id') @@ -62,19 +62,19 @@ function get($key) { } /** - Delete field - @return NULL - @param $key string + * Delete field + * @return NULL + * @param $key string **/ function clear($key) { unset($this->document[$key]); } /** - Convert array to mapper object - @return object - @param $id string - @param $row array + * Convert array to mapper object + * @return object + * @param $id string + * @param $row array **/ protected function factory($id,$row) { $mapper=clone($this); @@ -83,15 +83,14 @@ protected function factory($id,$row) { $mapper->id=$id; $mapper->document[$field]=$val; } - $mapper->query=array($row); - $mapper->ptr=0; + $mapper->query=array(clone($mapper)); return $mapper; } /** - Return fields of mapper object as an associative array - @return array - @param $obj object + * Return fields of mapper object as an associative array + * @return array + * @param $obj object **/ function cast($obj=NULL) { if (!$obj) @@ -100,9 +99,9 @@ function cast($obj=NULL) { } /** - Convert tokens in string expression to variable names - @return string - @param $str string + * Convert tokens in string expression to variable names + * @return string + * @param $str string **/ function token($str) { $self=$this; @@ -114,7 +113,7 @@ function($token) use($self) { '/(\.\w+)|\[((?:[^\[\]]*|(?R))*)\]/', function($expr) use($self) { $fw=\Base::instance(); - return + return '['. ($expr[1]? $fw->stringify(substr($expr[1],1)): @@ -133,12 +132,12 @@ function($expr) use($self) { } /** - Return records that match criteria - @return array|FALSE - @param $filter array - @param $options array - @param $ttl int - @param $log bool + * Return records that match criteria + * @return array|FALSE + * @param $filter array + * @param $options array + * @param $ttl int + * @param $log bool **/ function find($filter=NULL,array $options=NULL,$ttl=0,$log=TRUE) { if (!$options) @@ -261,9 +260,9 @@ function($val1,$val2) use($cols) { } /** - Count records that match criteria - @return int - @param $filter array + * Count records that match criteria + * @return int + * @param $filter array **/ function count($filter=NULL) { $now=microtime(TRUE); @@ -274,10 +273,10 @@ function count($filter=NULL) { } /** - Return record at specified offset using criteria of previous - load() call and make it active - @return array - @param $ofs int + * Return record at specified offset using criteria of previous + * load() call and make it active + * @return array + * @param $ofs int **/ function skip($ofs=1) { $this->document=($out=parent::skip($ofs))?$out->document:array(); @@ -286,8 +285,8 @@ function skip($ofs=1) { } /** - Insert new record - @return array + * Insert new record + * @return array **/ function insert() { if ($this->id) @@ -309,8 +308,8 @@ function insert() { } /** - Update current record - @return array + * Update current record + * @return array **/ function update() { $db=$this->db; @@ -325,9 +324,9 @@ function update() { } /** - Delete current record - @return bool - @param $filter array + * Delete current record + * @return bool + * @param $filter array **/ function erase($filter=NULL) { $db=$this->db; @@ -364,8 +363,8 @@ function erase($filter=NULL) { } /** - Reset cursor - @return NULL + * Reset cursor + * @return NULL **/ function reset() { $this->id=NULL; @@ -374,9 +373,9 @@ function reset() { } /** - Hydrate mapper object using hive array variable - @return NULL - @param $key string + * Hydrate mapper object using hive array variable + * @return NULL + * @param $key string **/ function copyfrom($key) { foreach (\Base::instance()->get($key) as $key=>$val) @@ -384,9 +383,9 @@ function copyfrom($key) { } /** - Populate hive array variable with mapper fields - @return NULL - @param $key string + * Populate hive array variable with mapper fields + * @return NULL + * @param $key string **/ function copyto($key) { $var=&\Base::instance()->ref($key); @@ -395,10 +394,10 @@ function copyto($key) { } /** - Instantiate class - @return void - @param $db object - @param $file string + * Instantiate class + * @return void + * @param $db object + * @param $file string **/ function __construct(\DB\Jig $db,$file) { $this->db=$db; diff --git a/libs/f3/db/jig/session.php b/libs/f3/db/jig/session.php index 180c5a16d4..044da860fb 100644 --- a/libs/f3/db/jig/session.php +++ b/libs/f3/db/jig/session.php @@ -1,7 +1,7 @@ load(array('@session_id==?',$id)); @@ -47,10 +47,10 @@ function read($id) { } /** - Write session data - @return TRUE - @param $id string - @param $data string + * Write session data + * @return TRUE + * @param $id string + * @param $data string **/ function write($id,$data) { $fw=\Base::instance(); @@ -67,9 +67,9 @@ function write($id,$data) { } /** - Destroy session - @return TRUE - @param $id string + * Destroy session + * @return TRUE + * @param $id string **/ function destroy($id) { $this->erase(array('@session_id==?',$id)); @@ -77,9 +77,9 @@ function destroy($id) { } /** - Garbage collector - @return TRUE - @param $max int + * Garbage collector + * @return TRUE + * @param $max int **/ function cleanup($max) { $this->erase(array('@stamp+?load(array('@session_id==?',$id?:session_id())); @@ -97,9 +97,9 @@ function ip($id=NULL) { } /** - Return Unix timestamp associated with specified session ID - @return string|FALSE - @param $id string + * Return Unix timestamp associated with specified session ID + * @return string|FALSE + * @param $id string **/ function stamp($id=NULL) { $this->load(array('@session_id==?',$id?:session_id())); @@ -107,9 +107,9 @@ function stamp($id=NULL) { } /** - Return HTTP user agent associated with specified session ID - @return string|FALSE - @param $id string + * Return HTTP user agent associated with specified session ID + * @return string|FALSE + * @param $id string **/ function agent($id=NULL) { $this->load(array('@session_id==?',$id?:session_id())); @@ -117,9 +117,9 @@ function agent($id=NULL) { } /** - Instantiate class - @param $db object - @param $table string + * Instantiate class + * @param $db object + * @param $table string **/ function __construct(\DB\Jig $db,$table='sessions') { parent::__construct($db,'sessions'); diff --git a/libs/f3/db/mongo.php b/libs/f3/db/mongo.php index 061a9b8ed5..baa781d88e 100644 --- a/libs/f3/db/mongo.php +++ b/libs/f3/db/mongo.php @@ -1,7 +1,7 @@ selectcollection('system.profile')->find(); @@ -47,8 +47,8 @@ function log() { } /** - Intercept native call to re-enable profiler - @return int + * Intercept native call to re-enable profiler + * @return int **/ function drop() { $out=parent::drop(); @@ -57,10 +57,10 @@ function drop() { } /** - Instantiate class - @param $dsn string - @param $dbname string - @param $options array + * Instantiate class + * @param $dsn string + * @param $dbname string + * @param $options array **/ function __construct($dsn,$dbname,array $options=NULL) { $class=class_exists('\MongoClient')?'\MongoClient':'\Mongo'; diff --git a/libs/f3/db/mongo/mapper.php b/libs/f3/db/mongo/mapper.php index d8f0d4c846..8e11430fb8 100644 --- a/libs/f3/db/mongo/mapper.php +++ b/libs/f3/db/mongo/mapper.php @@ -1,7 +1,7 @@ document); } /** - Assign value to field - @return scalar|FALSE - @param $key string - @param $val scalar + * Assign value to field + * @return scalar|FALSE + * @param $key string + * @param $val scalar **/ function set($key,$val) { return $this->document[$key]=$val; } /** - Retrieve value of field - @return scalar|FALSE - @param $key string + * Retrieve value of field + * @return scalar|FALSE + * @param $key string **/ function get($key) { if ($this->exists($key)) @@ -58,33 +58,32 @@ function get($key) { } /** - Delete field - @return NULL - @param $key string + * Delete field + * @return NULL + * @param $key string **/ function clear($key) { unset($this->document[$key]); } /** - Convert array to mapper object - @return object - @param $row array + * Convert array to mapper object + * @return object + * @param $row array **/ protected function factory($row) { $mapper=clone($this); $mapper->reset(); foreach ($row as $key=>$val) $mapper->document[$key]=$val; - $mapper->query=array($row); - $mapper->ptr=0; + $mapper->query=array(clone($mapper)); return $mapper; } /** - Return fields of mapper object as an associative array - @return array - @param $obj object + * Return fields of mapper object as an associative array + * @return array + * @param $obj object **/ function cast($obj=NULL) { if (!$obj) @@ -93,12 +92,12 @@ function cast($obj=NULL) { } /** - Build query and execute - @return array - @param $fields string - @param $filter array - @param $options array - @param $ttl int + * Build query and execute + * @return array + * @param $fields string + * @param $filter array + * @param $options array + * @param $ttl int **/ function select($fields=NULL,$filter=NULL,array $options=NULL,$ttl=0) { if (!$options) @@ -167,11 +166,11 @@ function select($fields=NULL,$filter=NULL,array $options=NULL,$ttl=0) { } /** - Return records that match criteria - @return array - @param $filter array - @param $options array - @param $ttl int + * Return records that match criteria + * @return array + * @param $filter array + * @param $options array + * @param $ttl int **/ function find($filter=NULL,array $options=NULL,$ttl=0) { if (!$options) @@ -186,19 +185,19 @@ function find($filter=NULL,array $options=NULL,$ttl=0) { } /** - Count records that match criteria - @return int - @param $filter array + * Count records that match criteria + * @return int + * @param $filter array **/ function count($filter=NULL) { return $this->collection->count($filter); } /** - Return record at specified offset using criteria of previous - load() call and make it active - @return array - @param $ofs int + * Return record at specified offset using criteria of previous + * load() call and make it active + * @return array + * @param $ofs int **/ function skip($ofs=1) { $this->document=($out=parent::skip($ofs))?$out->document:array(); @@ -206,8 +205,8 @@ function skip($ofs=1) { } /** - Insert new record - @return array + * Insert new record + * @return array **/ function insert() { if (isset($this->document['_id'])) @@ -217,8 +216,8 @@ function insert() { } /** - Update current record - @return array + * Update current record + * @return array **/ function update() { $this->collection->update( @@ -227,9 +226,9 @@ function update() { } /** - Delete current record - @return bool - @param $filter array + * Delete current record + * @return bool + * @param $filter array **/ function erase($filter=NULL) { if ($filter) @@ -242,8 +241,8 @@ function erase($filter=NULL) { } /** - Reset cursor - @return NULL + * Reset cursor + * @return NULL **/ function reset() { $this->document=array(); @@ -251,9 +250,9 @@ function reset() { } /** - Hydrate mapper object using hive array variable - @return NULL - @param $key string + * Hydrate mapper object using hive array variable + * @return NULL + * @param $key string **/ function copyfrom($key) { foreach (\Base::instance()->get($key) as $key=>$val) @@ -261,9 +260,9 @@ function copyfrom($key) { } /** - Populate hive array variable with mapper fields - @return NULL - @param $key string + * Populate hive array variable with mapper fields + * @return NULL + * @param $key string **/ function copyto($key) { $var=&\Base::instance()->ref($key); @@ -272,10 +271,10 @@ function copyto($key) { } /** - Instantiate class - @return void - @param $db object - @param $collection string + * Instantiate class + * @return void + * @param $db object + * @param $collection string **/ function __construct(\DB\Mongo $db,$collection) { $this->db=$db; diff --git a/libs/f3/db/mongo/session.php b/libs/f3/db/mongo/session.php index 986ea82b8c..2e5974dc31 100644 --- a/libs/f3/db/mongo/session.php +++ b/libs/f3/db/mongo/session.php @@ -1,7 +1,7 @@ load(array('session_id'=>$id)); @@ -47,10 +47,10 @@ function read($id) { } /** - Write session data - @return TRUE - @param $id string - @param $data string + * Write session data + * @return TRUE + * @param $id string + * @param $data string **/ function write($id,$data) { $fw=\Base::instance(); @@ -67,9 +67,9 @@ function write($id,$data) { } /** - Destroy session - @return TRUE - @param $id string + * Destroy session + * @return TRUE + * @param $id string **/ function destroy($id) { $this->erase(array('session_id'=>$id)); @@ -77,9 +77,9 @@ function destroy($id) { } /** - Garbage collector - @return TRUE - @param $max int + * Garbage collector + * @return TRUE + * @param $max int **/ function cleanup($max) { $this->erase(array('$where'=>'this.stamp+'.$max.'<'.time())); @@ -87,9 +87,9 @@ function cleanup($max) { } /** - Return IP address associated with specified session ID - @return string|FALSE - @param $id string + * Return IP address associated with specified session ID + * @return string|FALSE + * @param $id string **/ function ip($id=NULL) { $this->load(array('session_id'=>$id?:session_id())); @@ -97,9 +97,9 @@ function ip($id=NULL) { } /** - Return Unix timestamp associated with specified session ID - @return string|FALSE - @param $id string + * Return Unix timestamp associated with specified session ID + * @return string|FALSE + * @param $id string **/ function stamp($id=NULL) { $this->load(array('session_id'=>$id?:session_id())); @@ -107,9 +107,9 @@ function stamp($id=NULL) { } /** - Return HTTP user agent associated with specified session ID - @return string|FALSE - @param $id string + * Return HTTP user agent associated with specified session ID + * @return string|FALSE + * @param $id string **/ function agent($id=NULL) { $this->load(array('session_id'=>$id?:session_id())); @@ -117,9 +117,9 @@ function agent($id=NULL) { } /** - Instantiate class - @param $db object - @param $table string + * Instantiate class + * @param $db object + * @param $table string **/ function __construct(\DB\Mongo $db,$table='sessions') { parent::__construct($db,$table); diff --git a/libs/f3/db/sql.php b/libs/f3/db/sql.php index 614da2d617..4475ab4a87 100644 --- a/libs/f3/db/sql.php +++ b/libs/f3/db/sql.php @@ -3,7 +3,7 @@ namespace DB; /* - Copyright (c) 2009-2012 F3::Factory/Bong Cosca, All rights reserved. + Copyright (c) 2009-2013 F3::Factory/Bong Cosca, All rights reserved. This file is part of the Fat-Free Framework (http://fatfree.sf.net). @@ -31,8 +31,8 @@ class SQL extends \PDO { $log; /** - Begin SQL transaction - @return NULL + * Begin SQL transaction + * @return NULL **/ function begin() { parent::begintransaction(); @@ -40,8 +40,8 @@ function begin() { } /** - Rollback SQL transaction - @return NULL + * Rollback SQL transaction + * @return NULL **/ function rollback() { parent::rollback(); @@ -49,8 +49,8 @@ function rollback() { } /** - Commit SQL transaction - @return NULL + * Commit SQL transaction + * @return NULL **/ function commit() { parent::commit(); @@ -58,9 +58,9 @@ function commit() { } /** - Map data type of argument to a PDO constant - @return int - @param $val scalar + * Map data type of argument to a PDO constant + * @return int + * @param $val scalar **/ function type($val) { switch (gettype($val)) { @@ -77,17 +77,17 @@ function type($val) { /** - Execute SQL statement(s) - @return array|int|FALSE - @param $cmds string|array - @param $args string|array - @param $ttl int + * Execute SQL statement(s) + * @return array|int|FALSE + * @param $cmds string|array + * @param $args string|array + * @param $ttl int **/ function exec($cmds,$args=NULL,$ttl=0) { $auto=FALSE; if (is_null($args)) $args=array(); - elseif (is_string($args)) + elseif (is_scalar($args)) $args=array(1=>$args); if (is_array($cmds)) { if (count($args)<($count=count($cmds))) @@ -169,26 +169,26 @@ function exec($cmds,$args=NULL,$ttl=0) { } /** - Return number of rows affected by last query - @return int + * Return number of rows affected by last query + * @return int **/ function count() { return $this->rows; } /** - Return SQL profiler results - @return string + * Return SQL profiler results + * @return string **/ function log() { return $this->log; } /** - Retrieve schema of SQL table - @return array|FALSE - @param $table string - @param $ttl int + * Retrieve schema of SQL table + * @return array|FALSE + * @param $table string + * @param $ttl int **/ function schema($table,$ttl=0) { // Supported engines @@ -258,35 +258,35 @@ function schema($table,$ttl=0) { } /** - Return database engine - @return string + * Return database engine + * @return string **/ function driver() { return $this->engine; } /** - Return server version - @return string + * Return server version + * @return string **/ function version() { return parent::getattribute(parent::ATTR_SERVER_VERSION); } /** - Return database name - @return string + * Return database name + * @return string **/ function name() { return $this->dbname; } /** - Instantiate class - @param $dsn string - @param $user string - @param $pw string - @param $options array + * Instantiate class + * @param $dsn string + * @param $user string + * @param $pw string + * @param $options array **/ function __construct($dsn,$user=NULL,$pw=NULL,array $options=NULL) { if (preg_match('/^.+?(?:dbname|database)=(.+?)(?=;|$)/i',$dsn,$parts)) diff --git a/libs/f3/db/sql/mapper.php b/libs/f3/db/sql/mapper.php index 44e9aa5aee..a2ed47246a 100644 --- a/libs/f3/db/sql/mapper.php +++ b/libs/f3/db/sql/mapper.php @@ -1,7 +1,7 @@ fields+$this->adhoc); } /** - Assign value to field - @return scalar - @param $key string - @param $val scalar + * Assign value to field + * @return scalar + * @param $key string + * @param $val scalar **/ function set($key,$val) { if (array_key_exists($key,$this->fields)) { @@ -67,9 +67,9 @@ function set($key,$val) { } /** - Retrieve value of field - @return scalar - @param $key string + * Retrieve value of field + * @return scalar + * @param $key string **/ function get($key) { if ($key=='_id') @@ -82,9 +82,9 @@ function get($key) { } /** - Clear value of field - @return NULL - @param $key string + * Clear value of field + * @return NULL + * @param $key string **/ function clear($key) { if (array_key_exists($key,$this->adhoc)) @@ -92,9 +92,9 @@ function clear($key) { } /** - Get PHP type equivalent of PDO constant - @return string - @param $pdo string + * Get PHP type equivalent of PDO constant + * @return string + * @param $pdo string **/ function type($pdo) { switch ($pdo) { @@ -110,10 +110,10 @@ function type($pdo) { } /** - Cast value to PHP type - @return scalar - @param $type string - @param $val scalar + * Cast value to PHP type + * @return scalar + * @param $type string + * @param $val scalar **/ function value($type,$val) { switch ($type) { @@ -129,9 +129,9 @@ function value($type,$val) { } /** - Convert array to mapper object - @return object - @param $row array + * Convert array to mapper object + * @return object + * @param $row array **/ protected function factory($row) { $mapper=clone($this); @@ -142,15 +142,14 @@ protected function factory($row) { if ($var=='fields' && $mapper->{$var}[$key]['pkey']) $mapper->{$var}[$key]['previous']=$val; } - $mapper->query=array($row); - $mapper->ptr=0; + $mapper->query=array(clone($mapper)); return $mapper; } /** - Return fields of mapper object as an associative array - @return array - @param $obj object + * Return fields of mapper object as an associative array + * @return array + * @param $obj object **/ function cast($obj=NULL) { if (!$obj) @@ -164,12 +163,12 @@ function($row) { } /** - Build query string and execute - @return array - @param $fields string - @param $filter string|array - @param $options array - @param $ttl int + * Build query string and execute + * @return array + * @param $fields string + * @param $filter string|array + * @param $options array + * @param $ttl int **/ function select($fields,$filter=NULL,array $options=NULL,$ttl=0) { if (!$options) @@ -220,11 +219,11 @@ function select($fields,$filter=NULL,array $options=NULL,$ttl=0) { } /** - Return records that match criteria - @return array - @param $filter string|array - @param $options array - @param $ttl int + * Return records that match criteria + * @return array + * @param $filter string|array + * @param $options array + * @param $ttl int **/ function find($filter=NULL,array $options=NULL,$ttl=0) { if (!$options) @@ -242,9 +241,9 @@ function find($filter=NULL,array $options=NULL,$ttl=0) { } /** - Count records that match criteria - @return int - @param $filter string|array + * Count records that match criteria + * @return int + * @param $filter string|array **/ function count($filter=NULL) { $sql='SELECT COUNT(*) AS rows FROM '.$this->table; @@ -264,10 +263,10 @@ function count($filter=NULL) { } /** - Return record at specified offset using same criteria as - previous load() call and make it active - @return array - @param $ofs int + * Return record at specified offset using same criteria as + * previous load() call and make it active + * @return array + * @param $ofs int **/ function skip($ofs=1) { if ($out=parent::skip($ofs)) { @@ -287,27 +286,14 @@ function skip($ofs=1) { } /** - Insert new record - @return array + * Insert new record + * @return array **/ function insert() { $args=array(); $ctr=0; $fields=''; $values=''; - foreach ($this->fields as $key=>$field) - if ($field['changed']) { - $fields.=($ctr?',':''). - ($this->engine=='mysql'?('`'.$key.'`'):$key); - $values.=($ctr?',':'').'?'; - $args[$ctr+1]=array($field['value'],$field['pdo_type']); - $ctr++; - } - if ($fields) - $this->db->exec( - 'INSERT INTO '.$this->table.' ('.$fields.') '. - 'VALUES ('.$values.');',$args - ); $pkeys=array(); $inc=NULL; foreach ($this->fields as $key=>&$field) { @@ -315,12 +301,24 @@ function insert() { $pkeys[]=$key; $field['previous']=$field['value']; if (!$inc && $field['pdo_type']==\PDO::PARAM_INT && - is_null($field['value']) && !$field['nullable']) + empty($field['value']) && !$field['nullable']) $inc=$key; } + if ($field['changed'] && $key!=$inc) { + $fields.=($ctr?',':''). + ($this->engine=='mysql'?('`'.$key.'`'):$key); + $values.=($ctr?',':'').'?'; + $args[$ctr+1]=array($field['value'],$field['pdo_type']); + $ctr++; + } $field['changed']=FALSE; unset($field); } + if ($fields) + $this->db->exec( + 'INSERT INTO '.$this->table.' ('.$fields.') '. + 'VALUES ('.$values.');',$args + ); $seq=NULL; if ($this->engine=='pgsql') $seq=$this->table.'_'.end($pkeys).'_seq'; @@ -342,8 +340,8 @@ function insert() { } /** - Update current record - @return array + * Update current record + * @return array **/ function update() { $args=array(); @@ -372,9 +370,9 @@ function update() { } /** - Delete current record - @return int - @param $filter string|array + * Delete current record + * @return int + * @param $filter string|array **/ function erase($filter=NULL) { if ($filter) { @@ -415,8 +413,8 @@ function erase($filter=NULL) { } /** - Reset cursor - @return NULL + * Reset cursor + * @return NULL **/ function reset() { foreach ($this->fields as &$field) { @@ -434,9 +432,9 @@ function reset() { } /** - Hydrate mapper object using hive array variable - @return NULL - @param $key string + * Hydrate mapper object using hive array variable + * @return NULL + * @param $key string **/ function copyfrom($key) { foreach (\Base::instance()->get($key) as $key=>$val) @@ -451,9 +449,9 @@ function copyfrom($key) { } /** - Populate hive array variable with mapper fields - @return NULL - @param $key string + * Populate hive array variable with mapper fields + * @return NULL + * @param $key string **/ function copyto($key) { $var=&\Base::instance()->ref($key); @@ -462,22 +460,24 @@ function copyto($key) { } /** - Return schema - @return array + * Return schema + * @return array **/ function schema() { return $this->fields; } /** - Instantiate class - @param $db object - @param $table string - @param $ttl int + * Instantiate class + * @param $db object + * @param $table string + * @param $ttl int **/ function __construct(\DB\SQL $db,$table,$ttl=60) { $this->db=$db; $this->engine=$db->driver(); + if ($this->engine=='mysql') + $table='`'.$table.'`'; $this->table=$table; $this->fields=$db->schema($table,$ttl); $this->reset(); diff --git a/libs/f3/db/sql/session.php b/libs/f3/db/sql/session.php index 33bef7ab1d..b147be47a1 100644 --- a/libs/f3/db/sql/session.php +++ b/libs/f3/db/sql/session.php @@ -1,7 +1,7 @@ load(array('session_id=?',$id)); @@ -47,10 +47,10 @@ function read($id) { } /** - Write session data - @return TRUE - @param $id string - @param $data string + * Write session data + * @return TRUE + * @param $id string + * @param $data string **/ function write($id,$data) { $fw=\Base::instance(); @@ -67,9 +67,9 @@ function write($id,$data) { } /** - Destroy session - @return TRUE - @param $id string + * Destroy session + * @return TRUE + * @param $id string **/ function destroy($id) { $this->erase(array('session_id=?',$id)); @@ -77,9 +77,9 @@ function destroy($id) { } /** - Garbage collector - @return TRUE - @param $max int + * Garbage collector + * @return TRUE + * @param $max int **/ function cleanup($max) { $this->erase('stamp+'.$max.'<'.time()); @@ -87,9 +87,9 @@ function cleanup($max) { } /** - Return IP address associated with specified session ID - @return string|FALSE - @param $id string + * Return IP address associated with specified session ID + * @return string|FALSE + * @param $id string **/ function ip($id=NULL) { $this->load(array('session_id=?',$id?:session_id())); @@ -97,9 +97,9 @@ function ip($id=NULL) { } /** - Return Unix timestamp associated with specified session ID - @return string|FALSE - @param $id string + * Return Unix timestamp associated with specified session ID + * @return string|FALSE + * @param $id string **/ function stamp($id=NULL) { $this->load(array('session_id=?',$id?:session_id())); @@ -107,9 +107,9 @@ function stamp($id=NULL) { } /** - Return HTTP user agent associated with specified session ID - @return string|FALSE - @param $id string + * Return HTTP user agent associated with specified session ID + * @return string|FALSE + * @param $id string **/ function agent($id=NULL) { $this->load(array('session_id=?',$id?:session_id())); @@ -117,9 +117,9 @@ function agent($id=NULL) { } /** - Instantiate class - @param $db object - @param $table string + * Instantiate class + * @param $db object + * @param $table string **/ function __construct(\DB\SQL $db,$table='sessions') { $db->exec( diff --git a/libs/f3/f3.php b/libs/f3/f3.php index dfed454e9e..f8c7aebfe6 100644 --- a/libs/f3/f3.php +++ b/libs/f3/f3.php @@ -1,7 +1,7 @@ data,IMG_FILTER_NEGATE); @@ -68,9 +69,9 @@ function invert() { } /** - Adjust brightness (range:-255 to 255) - @return object - @param $level int + * Adjust brightness (range:-255 to 255) + * @return object + * @param $level int **/ function brightness($level) { imagefilter($this->data,IMG_FILTER_BRIGHTNESS,$level); @@ -78,9 +79,9 @@ function brightness($level) { } /** - Adjust contrast (range:-100 to 100) - @return object - @param $level int + * Adjust contrast (range:-100 to 100) + * @return object + * @param $level int **/ function contrast($level) { imagefilter($this->data,IMG_FILTER_CONTRAST,$level); @@ -88,8 +89,8 @@ function contrast($level) { } /** - Convert to grayscale - @return object + * Convert to grayscale + * @return object **/ function grayscale() { imagefilter($this->data,IMG_FILTER_GRAYSCALE); @@ -97,9 +98,9 @@ function grayscale() { } /** - Adjust smoothness - @return object - @param $level int + * Adjust smoothness + * @return object + * @param $level int **/ function smooth($level) { imagefilter($this->data,IMG_FILTER_SMOOTH,$level); @@ -107,8 +108,8 @@ function smooth($level) { } /** - Emboss the image - @return object + * Emboss the image + * @return object **/ function emboss() { imagefilter($this->data,IMG_FILTER_EMBOSS); @@ -116,8 +117,8 @@ function emboss() { } /** - Apply sepia effect - @return object + * Apply sepia effect + * @return object **/ function sepia() { imagefilter($this->data,IMG_FILTER_GRAYSCALE); @@ -126,9 +127,9 @@ function sepia() { } /** - Pixelate the image - @return object - @param $size int + * Pixelate the image + * @return object + * @param $size int **/ function pixelate($size) { imagefilter($this->data,IMG_FILTER_PIXELATE,$size,TRUE); @@ -136,9 +137,9 @@ function pixelate($size) { } /** - Blur the image using Gaussian filter - @return object - @param $selective bool + * Blur the image using Gaussian filter + * @return object + * @param $selective bool **/ function blur($selective=FALSE) { imagefilter($this->data, @@ -147,8 +148,8 @@ function blur($selective=FALSE) { } /** - Apply sketch effect - @return object + * Apply sketch effect + * @return object **/ function sketch() { imagefilter($this->data,IMG_FILTER_MEAN_REMOVAL); @@ -156,8 +157,8 @@ function sketch() { } /** - Flip on horizontal axis - @return object + * Flip on horizontal axis + * @return object **/ function hflip() { $tmp=imagecreatetruecolor( @@ -172,8 +173,8 @@ function hflip() { } /** - Flip on vertical axis - @return object + * Flip on vertical axis + * @return object **/ function vflip() { $tmp=imagecreatetruecolor( @@ -188,12 +189,31 @@ function vflip() { } /** - Resize image (Maintain aspect ratio); Crop relative to center - if flag is enabled - @return object - @param $width int - @param $height int - @param $crop bool + * Crop the image + * @return object + * @param $x1 int + * @param $y1 int + * @param $x2 int + * @param $y2 int + **/ + function crop($x1,$y1,$x2,$y2) { + $tmp=imagecreatetruecolor($width=$x2-$x1+1,$height=$y2-$y1+1); + imagesavealpha($tmp,TRUE); + imagefill($tmp,0,0,IMG_COLOR_TRANSPARENT); + imagecopyresampled($tmp,$this->data, + 0,0,$x1,$y1,$width,$height,$width,$height); + imagedestroy($this->data); + $this->data=$tmp; + return $this->save(); + } + + /** + * Resize image (Maintain aspect ratio); Crop relative to center + * if flag is enabled + * @return object + * @param $width int + * @param $height int + * @param $crop bool **/ function resize($width,$height,$crop=TRUE) { // Adjust dimensions; retain aspect ratio @@ -229,9 +249,9 @@ function resize($width,$height,$crop=TRUE) { } /** - Rotate image - @return object - @param $angle int + * Rotate image + * @return object + * @param $angle int **/ function rotate($angle) { $this->data=imagerotate($this->data,$angle,IMG_COLOR_TRANSPARENT); @@ -240,10 +260,10 @@ function rotate($angle) { } /** - Apply an image overlay - @return object - @param $img object - @param $align int + * Apply an image overlay + * @return object + * @param $img object + * @param $align int **/ function overlay(Image $img,$align=NULL) { if (is_null($align)) @@ -275,11 +295,11 @@ function overlay(Image $img,$align=NULL) { } /** - Generate identicon - @return object - @param $str string - @param $size int - @param $blocks int + * Generate identicon + * @return object + * @param $str string + * @param $size int + * @param $blocks int **/ function identicon($str,$size=64,$blocks=4) { $sprites=array( @@ -333,12 +353,12 @@ function identicon($str,$size=64,$blocks=4) { } /** - Generate CAPTCHA image - @return object|FALSE - @param $font string - @param $size int - @param $len int - @param $key string + * Generate CAPTCHA image + * @return object|FALSE + * @param $font string + * @param $size int + * @param $len int + * @param $key string **/ function captcha($font,$size=24,$len=5,$key=NULL) { $fw=Base::instance(); @@ -381,28 +401,29 @@ function captcha($font,$size=24,$len=5,$key=NULL) { $fw->set($key,$seed); return $this->save(); } + user_error(self::E_Font); return FALSE; } /** - Return image width - @return int + * Return image width + * @return int **/ function width() { return imagesx($this->data); } /** - Return image height - @return int + * Return image height + * @return int **/ function height() { return imagesy($this->data); } /** - Send image to HTTP client - @return NULL + * Send image to HTTP client + * @return NULL **/ function render() { $args=func_get_args(); @@ -411,24 +432,26 @@ function render() { header('Content-Type: image/'.$format); header('X-Powered-By: '.Base::instance()->get('PACKAGE')); } - call_user_func_array('image'.$format,array_merge(array($this->data),$args)); + call_user_func_array('image'.$format, + array_merge(array($this->data),$args)); } /** - Return image as a string - @return string + * Return image as a string + * @return string **/ function dump() { $args=func_get_args(); $format=$args?array_shift($args):'png'; ob_start(); - call_user_func_array('image'.$format,array_merge(array($this->data),$args)); + call_user_func_array('image'.$format, + array_merge(array($this->data),$args)); return ob_get_clean(); } /** - Save current state - @return object + * Save current state + * @return object **/ function save() { $fw=Base::instance(); @@ -445,9 +468,9 @@ function save() { } /** - Revert to specified state - @return object - @param $state int + * Revert to specified state + * @return object + * @param $state int **/ function restore($state=1) { $fw=Base::instance(); @@ -468,8 +491,8 @@ function restore($state=1) { } /** - Undo most recently applied filter - @return object + * Undo most recently applied filter + * @return object **/ function undo() { if ($this->flag) { @@ -481,9 +504,9 @@ function undo() { } /** - Instantiate image - @param $file string - @param $flag bool + * Instantiate image + * @param $file string + * @param $flag bool **/ function __construct($file=NULL,$flag=FALSE) { $this->flag=$flag; @@ -501,8 +524,8 @@ function __construct($file=NULL,$flag=FALSE) { } /** - Wrap-up - @return NULL + * Wrap-up + * @return NULL **/ function __destruct() { if (is_resource($this->data)) { diff --git a/libs/f3/log.php b/libs/f3/log.php index eb938e51d9..d674699786 100644 --- a/libs/f3/log.php +++ b/libs/f3/log.php @@ -1,7 +1,7 @@ file); } /** - Instantiate class - @param $file string + * Instantiate class + * @param $file string **/ function __construct($file) { $fw=Base::instance(); diff --git a/libs/f3/magic.php b/libs/f3/magic.php index 39277e4bbe..1663a3bdb9 100644 --- a/libs/f3/magic.php +++ b/libs/f3/magic.php @@ -1,7 +1,7 @@ visible($key)?isset($this->$key):$this->exists($key); } /** - Alias for offsetexists() - @return mixed - @param $key string + * Alias for offsetexists() + * @return mixed + * @param $key string **/ function __isset($key) { return $this->offsetexists($key); } /** - Convenience method for assigning property value - @return mixed - @param $key string - @param $val scalar + * Convenience method for assigning property value + * @return mixed + * @param $key string + * @param $val scalar **/ function offsetset($key,$val) { return $this->visible($key)?($this->key=$val):$this->set($key,$val); } /** - Alias for offsetset() - @return mixed - @param $key string - @param $val scalar + * Alias for offsetset() + * @return mixed + * @param $key string + * @param $val scalar **/ function __set($key,$val) { return $this->offsetset($key,$val); } /** - Convenience method for retrieving property value - @return mixed - @param $key string + * Convenience method for retrieving property value + * @return mixed + * @param $key string **/ function offsetget($key) { return $this->visible($key)?$this->$key:$this->get($key); } /** - Alias for offsetget() - @return mixed - @param $key string + * Alias for offsetget() + * @return mixed + * @param $key string **/ function __get($key) { return $this->offsetget($key); } /** - Convenience method for checking property value - @return NULL - @param $key string + * Convenience method for checking property value + * @return NULL + * @param $key string **/ function offsetunset($key) { if ($this->visible($key)) @@ -129,9 +129,9 @@ function offsetunset($key) { } /** - Alias for offsetunset() - @return NULL - @param $key string + * Alias for offsetunset() + * @return NULL + * @param $key string **/ function __unset($key) { $this->offsetunset($key); diff --git a/libs/f3/markdown.php b/libs/f3/markdown.php index cf952d0246..6f36f67ccc 100644 --- a/libs/f3/markdown.php +++ b/libs/f3/markdown.php @@ -1,7 +1,7 @@ \h?(.*?(?:\n+|$))/','\1',$str); @@ -34,9 +34,9 @@ protected function _blockquote($str) { } /** - Process whitespace-prefixed code block - @return string - @param $str string + * Process whitespace-prefixed code block + * @return string + * @param $str string **/ protected function _pre($str) { $str=preg_replace('/(?<=^|\n)(?: {4}|\t)(.+?(?:\n+|$))/','\1', @@ -49,10 +49,10 @@ protected function _pre($str) { } /** - Process fenced code block - @return string - @param $hint string - @param $str string + * Process fenced code block + * @return string + * @param $hint string + * @param $str string **/ protected function _fence($hint,$str) { $str=$this->snip($str); @@ -62,6 +62,35 @@ protected function _fence($hint,$str) { case 'php': $str=$fw->highlight($str); break; + case 'apache': + preg_match_all('/(?<=^|\n)(\h*)'. + '(?:(<\/?)(\w+)((?:\h+[^>]+)*)(>)|'. + '(?:(\w+)(\h.+?)))(\h*(?:\n+|$))/', + $str,$matches,PREG_SET_ORDER); + $out=''; + foreach ($matches as $match) + $out.=$match[1]. + ($match[3]? + (''. + $this->esc($match[2]).$match[3]. + ''. + ($match[4]? + (''. + $this->esc($match[4]). + ''): + ''). + ''. + $this->esc($match[5]). + ''): + (''. + $match[6]. + ''. + ''. + $this->esc($match[7]). + '')). + $match[8]; + $str=''.$out.''; + break; case 'html': preg_match_all( '/(?:(?:<(\/?)(\w+)'. @@ -142,18 +171,18 @@ protected function _fence($hint,$str) { } /** - Process horizontal rule - @return string + * Process horizontal rule + * @return string **/ protected function _hr() { return '
'."\n\n"; } /** - Process atx-style heading - @return string - @param $type string - @param $str string + * Process atx-style heading + * @return string + * @param $type string + * @param $str string **/ protected function _atx($type,$str) { $level=strlen($type); @@ -162,10 +191,10 @@ protected function _atx($type,$str) { } /** - Process setext-style heading - @return string - @param $str string - @param $type string + * Process setext-style heading + * @return string + * @param $str string + * @param $type string **/ protected function _setext($str,$type) { $level=strpos('=-',$type)+1; @@ -174,9 +203,9 @@ protected function _setext($str,$type) { } /** - Process ordered/unordered list - @return string - @param $str string + * Process ordered/unordered list + * @return string + * @param $str string **/ protected function _li($str) { // Initialize list parser @@ -199,33 +228,34 @@ protected function _li($str) { elseif (preg_match('/(?<=^|\n)([*+-]|\d+\.)\h'. '(.+?(?:\n+|$))((?:(?: {4}|\t)+.+?(?:\n+|$))*)/s', substr($str,$ptr),$match)) { + $match[3]=preg_replace('/(?<=^|\n)(?: {4}|\t)/','',$match[3]); + $found=FALSE; + foreach (array_slice($this->blocks,0,-1) as $regex) + if (preg_match($regex,$match[3])) { + $found=TRUE; + break; + } // List - $block=preg_match( - '/^\h+([*+-]|\d+\.)\h?.+?(?:\n+|$)/',$match[3]); if ($first) { // First pass if (is_numeric($match[1])) $type='ol'; - if (preg_match('/\n{2,}$/', - $match[2].($block?'':$match[3]))) + if (preg_match('/\n{2,}$/',$match[2]. + ($found?'':$match[3]))) // Loose structure; Use paragraphs $tight=FALSE; $first=FALSE; } - $ptr+=strlen($match[0]); // Strip leading whitespaces - $match[3]=preg_replace('/(?<=^|\n)(?: {4}|\t)/','',$match[3]); + $ptr+=strlen($match[0]); $tmp=$this->snip($match[2].$match[3]); - $dst.='
  • '.$this->scan( - trim( - $tight? - ($block? - ($match[2]. - $this->_li($this->snip($match[3]))): - $tmp): - $this->build($tmp) - ) - ).'
  • '."\n"; + if ($tight) { + if ($found) + $tmp=$match[2].$this->build($this->snip($match[3])); + } + else + $tmp=$this->build($tmp); + $dst.='
  • '.$this->scan(trim($tmp)).'
  • '."\n"; } } return strlen($dst)? @@ -233,19 +263,18 @@ protected function _li($str) { } /** - Ignore raw HTML - @return string - @param $str string + * Ignore raw HTML + * @return string + * @param $str string **/ protected function _raw($str) { - //var_dump($str); return $str; } /** - Process paragraph - @return string - @param $str string + * Process paragraph + * @return string + * @param $str string **/ protected function _p($str) { $str=trim($str); @@ -254,7 +283,7 @@ protected function _p($str) { return $this->_p($parts[1]).$this->build($parts[2]); $self=$this; $str=preg_replace_callback( - '/([^<\[]+)?(<.+?>|\[.+?\]\s*\(.+?\))([^>\]]+)?|(.+)/s', + '/([^<>\[]+)?(<.+?>|\[.+?\]\s*\(.+?\))([^<>\]]+)?|(.+)/s', function($expr) use($self) { $tmp=''; if (isset($expr[4])) @@ -276,39 +305,32 @@ function($expr) use($self) { } /** - Process mixed strong/em span - @return string - @param $str string - **/ - protected function _mixed($str) { - return preg_replace('/(?\2',$str); - } - - /** - Process strong span - @return string - @param $str string + * Process strong/em spans + * @return string + * @param $str string **/ - protected function _strong($str) { - return preg_replace('/(?\2',$str); - } - - /** - Reduce em span - @return string - @param $str string - **/ - protected function _em($str) { - return preg_replace('/(?\2',$str); + protected function _text($str) { + $tmp=''; + while ($str!=$tmp) + $str=preg_replace_callback( + '/(?'.$expr[2].''; + case 2: + return ''.$expr[2].''; + } + }, + $tmp=$str + ); + return $str; } /** - Process image span - @return string - @param $str string + * Process image span + * @return string + * @param $str string **/ protected function _img($str) { $self=$this; @@ -328,9 +350,9 @@ function($expr) use($self) { } /** - Process anchor span - @return string - @param $str string + * Process anchor span + * @return string + * @param $str string **/ protected function _a($str) { $self=$this; @@ -341,16 +363,16 @@ function($expr) use($self) { (empty($expr[3])? '': (' title="'.$self->esc($expr[3]).'"')). - '>'.$expr[1].''; + '>'.$self->scan($expr[1]).''; }, $str ); } /** - Auto-convert links - @return string - @param $str string + * Auto-convert links + * @return string + * @param $str string **/ protected function _auto($str) { $self=$this; @@ -368,29 +390,26 @@ function($expr) use($self) { } /** - Process code span - @return string - @param $str string + * Process code span + * @return string + * @param $str string **/ protected function _code($str) { $self=$this; return preg_replace_callback( - '/(".*?`.+?`.*?")|`` (.+?) ``|(?'. - $self->esc(empty($expr[2])?$expr[3]:$expr[2]). - ''): - $expr[1]; + return ''. + $self->esc(empty($expr[1])?$expr[2]:$expr[1]).''; }, $str ); } /** - Convert characters to HTML entities - @return string - @param $str string + * Convert characters to HTML entities + * @return string + * @param $str string **/ function esc($str) { if (!$this->special) @@ -407,30 +426,30 @@ function esc($str) { } /** - Reduce multiple line feeds - @return string - @param $str string + * Reduce multiple line feeds + * @return string + * @param $str string **/ protected function snip($str) { return preg_replace('/(?:(?<=\n)\n+)|\n+$/',"\n",$str); } /** - Scan line for convertible spans - @return string - @param $str string + * Scan line for convertible spans + * @return string + * @param $str string **/ - protected function scan($str) { - $inline=array('img','a','mixed','strong','em','auto','code'); + function scan($str) { + $inline=array('img','a','text','auto','code'); foreach ($inline as $func) $str=$this->{'_'.$func}($str); return $str; } /** - Assemble blocks - @return string - @param $str string + * Assemble blocks + * @return string + * @param $str string **/ protected function build($str) { if (!$this->blocks) { @@ -446,7 +465,11 @@ protected function build($str) { 'li'=>'/^(?:(?:[*+-]|\d+\.)\h.+?(?:\n+|$)'. '(?:(?: {4}|\t)+.+?(?:\n+|$))*)+/s', 'raw'=>'/^((?:|<\?.+?\?>|<%.+?%>|'. - '<(\w+).*?(?:\/>|>(?:(?>[^><]+)|(?R))*<\/\2>))'. + '<(address|article|aside|audio|blockquote|canvas|dd|'. + 'div|dl|fieldset|figcaption|figure|footer|form|h\d|'. + 'header|hgroup|hr|noscript|object|ol|output|p|pre|'. + 'section|table|tfoot|ul|video).*?'. + '(?:\/>|>(?:(?>[^><]+)|(?R))*<\/\2>))'. '\h*(?:\n{2,}|\n?$))/s', 'p'=>'/^(.+?(?:\n{2,}|\n?$))/s' ); @@ -481,12 +504,13 @@ function($expr) use($match,$self) { (' title="'. $self->esc($match[3]).'"')).'>'. // Link - (empty($expr[3])? - (empty($expr[1])? - $expr[4]: - $expr[1]): - $expr[3]). - ''): + $self->scan( + empty($expr[3])? + (empty($expr[1])? + $expr[4]: + $expr[1]): + $expr[3] + ).''): // Image ('blocks as $func=>$regex) if (preg_match($regex,substr($str,$ptr),$match)) { - //echo '{'.$func.','.$ptr.':'.strlen($match[0]).'}->'; - //var_dump($match[0]); $ptr+=strlen($match[0]); $dst.=call_user_func_array( array($this,'_'.$func), @@ -520,29 +542,22 @@ function($expr) use($match,$self) { } /** - Render HTML equivalent of markdown - @return string - @param $file string + * Render HTML equivalent of markdown + * @return string + * @param $txt string **/ - function render($file) { - $fw=Base::instance(); - if (!is_dir($tmp=$fw->get('TEMP'))) - mkdir($tmp,Base::MODE,TRUE); - foreach ($fw->split($fw->get('UI')) as $dir) - if (is_file($abs=$fw->fixslashes($dir.$file))) { - $str=preg_replace_callback( - '/(.+?<\/code>|'. - '<[^>\n]+>|\([^\n\)]+\)|"[^"\n]+")|'. - '\\\\(.)/s', - function($expr) { - // Process escaped characters - return empty($expr[1])?$expr[2]:$expr[1]; - }, - $this->build($fw->read($abs,TRUE)) - ); - return $this->snip($str); - } - user_error(sprintf(Base::E_Open,$file)); + function convert($txt) { + $txt=preg_replace_callback( + '/(.+?<\/code>|'. + '<[^>\n]+>|\([^\n\)]+\)|"[^"\n]+")|'. + '\\\\(.)/s', + function($expr) { + // Process escaped characters + return empty($expr[1])?$expr[2]:$expr[1]; + }, + $this->build(preg_replace('/\r\n|\r/',"\n",$txt)) + ); + return $this->snip($txt); } } diff --git a/libs/f3/matrix.php b/libs/f3/matrix.php index 8b94a0814e..c7aeecfacf 100644 --- a/libs/f3/matrix.php +++ b/libs/f3/matrix.php @@ -1,7 +1,7 @@ exists($id.'.@',$data)?$data['data']:FALSE; } /** - Write session data - @return TRUE - @param $id string - @param $data string + * Write session data + * @return TRUE + * @param $id string + * @param $data string **/ function write($id,$data) { $fw=Base::instance(); @@ -67,9 +67,9 @@ function write($id,$data) { } /** - Destroy session - @return TRUE - @param $id string + * Destroy session + * @return TRUE + * @param $id string **/ function destroy($id) { Cache::instance()->clear($id.'.@'); @@ -77,9 +77,9 @@ function destroy($id) { } /** - Garbage collector - @return TRUE - @param $max int + * Garbage collector + * @return TRUE + * @param $max int **/ function cleanup($max) { Cache::instance()->reset('.@',$max); @@ -87,9 +87,9 @@ function cleanup($max) { } /** - Return IP address associated with specified session ID - @return string|FALSE - @param $id string + * Return IP address associated with specified session ID + * @return string|FALSE + * @param $id string **/ function ip($id=NULL) { return Cache::instance()->exists(($id?:session_id()).'.@',$data)? @@ -97,9 +97,9 @@ function ip($id=NULL) { } /** - Return Unix timestamp associated with specified session ID - @return string|FALSE - @param $id string + * Return Unix timestamp associated with specified session ID + * @return string|FALSE + * @param $id string **/ function stamp($id=NULL) { return Cache::instance()->exists(($id?:session_id()).'.@',$data)? @@ -107,9 +107,9 @@ function stamp($id=NULL) { } /** - Return HTTP user agent associated with specified session ID - @return string|FALSE - @param $id string + * Return HTTP user agent associated with specified session ID + * @return string|FALSE + * @param $id string **/ function agent($id=NULL) { return Cache::instance()->exists(($id?:session_id()).'.@',$data)? @@ -117,8 +117,8 @@ function agent($id=NULL) { } /** - Instantiate class - @return object + * Instantiate class + * @return object **/ function __construct() { session_set_save_handler( diff --git a/libs/f3/smtp.php b/libs/f3/smtp.php index 38969690c8..1ca1b3d891 100644 --- a/libs/f3/smtp.php +++ b/libs/f3/smtp.php @@ -1,7 +1,7 @@ fixheader($key); @@ -64,10 +64,10 @@ function exists($key) { } /** - Bind value to e-mail header - @return string - @param $key string - @param $val string + * Bind value to e-mail header + * @return string + * @param $key string + * @param $val string **/ function set($key,$val) { $key=$this->fixheader($key); @@ -75,9 +75,9 @@ function set($key,$val) { } /** - Return value of e-mail header - @return string|NULL - @param $key string + * Return value of e-mail header + * @return string|NULL + * @param $key string **/ function get($key) { $key=$this->fixheader($key); @@ -85,9 +85,9 @@ function get($key) { } /** - Remove header - @return NULL - @param $key string + * Remove header + * @return NULL + * @param $key string **/ function clear($key) { $key=$this->fixheader($key); @@ -95,18 +95,18 @@ function clear($key) { } /** - Return client-server conversation history - @return string + * Return client-server conversation history + * @return string **/ function log() { return str_replace("\n",PHP_EOL,$this->log); } /** - Send SMTP command and record server response - @return NULL - @param $cmd string - @param $log bool + * Send SMTP command and record server response + * @return NULL + * @param $cmd string + * @param $log bool **/ protected function dialog($cmd=NULL,$log=FALSE) { $socket=&$this->socket; @@ -126,9 +126,9 @@ protected function dialog($cmd=NULL,$log=FALSE) { } /** - Add e-mail attachment - @return NULL - @param $file + * Add e-mail attachment + * @return NULL + * @param $file **/ function attach($file) { if (!is_file($file)) @@ -137,9 +137,9 @@ function attach($file) { } /** - Transmit message - @return bool - @param $message string + * Transmit message + * @return bool + * @param $message string **/ function send($message) { if ($this->scheme=='ssl' && !extension_loaded('openssl')) @@ -242,12 +242,12 @@ function send($message) { } /** - Instantiate class - @param $host string - @param $port int - @param $scheme string - @param $user string - @param $pw string + * Instantiate class + * @param $host string + * @param $port int + * @param $scheme string + * @param $user string + * @param $pw string **/ function __construct($host,$port,$scheme,$user,$pw) { $this->headers=array( diff --git a/libs/f3/template.php b/libs/f3/template.php index fbd0866e1e..ba790ca96f 100644 --- a/libs/f3/template.php +++ b/libs/f3/template.php @@ -1,7 +1,7 @@ stringify(substr($expr[1],1)): @@ -63,9 +63,9 @@ function($expr) use($self) { } /** - Template -set- tag handler - @return string - @param $node array + * Template -set- tag handler + * @return string + * @param $node array **/ protected function _set(array $node) { $out=''; @@ -78,9 +78,9 @@ protected function _set(array $node) { } /** - Template -include- tag handler - @return string - @param $node array + * Template -include- tag handler + * @return string + * @param $node array **/ protected function _include(array $node) { $attrib=$node['@attrib']; @@ -95,26 +95,26 @@ protected function _include(array $node) { } /** - Template -exclude- tag handler - @return string + * Template -exclude- tag handler + * @return string **/ protected function _exclude() { return ''; } /** - Template -ignore- tag handler - @return string - @param $node array + * Template -ignore- tag handler + * @return string + * @param $node array **/ protected function _ignore(array $node) { return $node[0]; } /** - Template -loop- tag handler - @return string - @param $node array + * Template -loop- tag handler + * @return string + * @param $node array **/ protected function _loop(array $node) { $attrib=$node['@attrib']; @@ -129,9 +129,9 @@ protected function _loop(array $node) { } /** - Template -repeat- tag handler - @return string - @param $node array + * Template -repeat- tag handler + * @return string + * @param $node array **/ protected function _repeat(array $node) { $attrib=$node['@attrib']; @@ -151,9 +151,9 @@ protected function _repeat(array $node) { } /** - Template -check- tag handler - @return string - @param $node array + * Template -check- tag handler + * @return string + * @param $node array **/ protected function _check(array $node) { $attrib=$node['@attrib']; @@ -174,27 +174,27 @@ protected function _check(array $node) { } /** - Template -true- tag handler - @return string - @param $node array + * Template -true- tag handler + * @return string + * @param $node array **/ protected function _true(array $node) { return $this->build($node); } /** - Template -false- tag handler - @return string - @param $node array + * Template -false- tag handler + * @return string + * @param $node array **/ protected function _false(array $node) { return ''.$this->build($node); } /** - Assemble markup - @return string - @param $node array|string + * Assemble markup + * @return string + * @param $node array|string **/ protected function build($node) { if (is_string($node)) { @@ -218,10 +218,10 @@ function($expr) use($self) { } /** - Extend template with custom tag - @return NULL - @param $tag string - @param $func callback + * Extend template with custom tag + * @return NULL + * @param $tag string + * @param $func callback **/ function extend($tag,$func) { $this->tags.='|'.$tag; @@ -229,10 +229,10 @@ function extend($tag,$func) { } /** - Call custom tag handler - @return string|FALSE - @param $func callback - @param $args array + * Call custom tag handler + * @return string|FALSE + * @param $func callback + * @param $args array **/ function __call($func,array $args) { if ($func[0]=='_') @@ -243,11 +243,11 @@ function __call($func,array $args) { } /** - Render template - @return string - @param $file string - @param $mime string - @param $hive array + * Render template + * @return string + * @param $file string + * @param $mime string + * @param $hive array **/ function render($file,$mime='text/html',array $hive=NULL) { $fw=Base::instance(); @@ -340,4 +340,13 @@ function render($file,$mime='text/html',array $hive=NULL) { user_error(sprintf(Base::E_Open,$file)); } + function __construct() { + $ref=new ReflectionClass(__CLASS__); + $this->tags=''; + foreach ($ref->getmethods() as $method) + if (preg_match('/^_(?=[[:alpha:]])/',$method->name)) + $this->tags.=(strlen($this->tags)?'|':''). + substr($method->name,1); + } + } diff --git a/libs/f3/test.php b/libs/f3/test.php index 92f1e967ff..c1c315a410 100644 --- a/libs/f3/test.php +++ b/libs/f3/test.php @@ -1,7 +1,7 @@ data; } /** - Evaluate condition and save test result - @return NULL - @param $cond bool - @param $text string + * Evaluate condition and save test result + * @return NULL + * @param $cond bool + * @param $text string **/ function expect($cond,$text=NULL) { $out=(bool)$cond; @@ -58,18 +58,18 @@ function expect($cond,$text=NULL) { } /** - Push message to test results - @return NULL - @param $text string + * Append message to test results + * @return NULL + * @param $text string **/ function message($text) { $this->expect(TRUE,$text); } /** - Class constructor - @return NULL - @param $level int + * Class constructor + * @return NULL + * @param $level int **/ function __construct($level=self::FLAG_Both) { $this->level=$level; diff --git a/libs/f3/utf.php b/libs/f3/utf.php index e6c7588d95..fbce43e6c0 100644 --- a/libs/f3/utf.php +++ b/libs/f3/utf.php @@ -1,7 +1,7 @@ strpos($stack,$needle,$ofs,TRUE); } /** - Get string length - @return int - @param $str string + * Get string length + * @return int + * @param $str string **/ function strlen($str) { preg_match_all('/./u',$str,$parts); @@ -38,12 +38,12 @@ function strlen($str) { } /** - Find position of first occurrence of a string - @return int|FALSE - @param $stack string - @param $needle string - @param $ofs int - @param $case bool + * Find position of first occurrence of a string + * @return int|FALSE + * @param $stack string + * @param $needle string + * @param $ofs int + * @param $case bool **/ function strpos($stack,$needle,$ofs=0,$case=FALSE) { preg_match('/^(.*?)'.preg_quote($needle,'/').'/u'.($case?'i':''), @@ -52,23 +52,23 @@ function strpos($stack,$needle,$ofs=0,$case=FALSE) { } /** - Finds position of last occurrence of a string (case-insensitive) - @return int|FALSE - @param $stack string - @param $needle string - @param $ofs int + * Finds position of last occurrence of a string (case-insensitive) + * @return int|FALSE + * @param $stack string + * @param $needle string + * @param $ofs int **/ function strripos($stack,$needle,$ofs=0) { return $this->strrpos($stack,$needle,$ofs,TRUE); } /** - Find position of last occurrence of a string - @return int|FALSE - @param $stack string - @param $needle string - @param $ofs int - @param $case bool + * Find position of last occurrence of a string + * @return int|FALSE + * @param $stack string + * @param $needle string + * @param $ofs int + * @param $case bool **/ function strrpos($stack,$needle,$ofs=0,$case=FALSE) { if (!$needle) @@ -85,25 +85,25 @@ function strrpos($stack,$needle,$ofs=0,$case=FALSE) { } /** - Returns part of haystack string from the first occurrence of - needle to the end of haystack (case-insensitive) - @return string|FALSE - @param $stack string - @param $needle string - @param $before bool + * Returns part of haystack string from the first occurrence of + * needle to the end of haystack (case-insensitive) + * @return string|FALSE + * @param $stack string + * @param $needle string + * @param $before bool **/ function stristr($stack,$needle,$before=FALSE) { return strstr($stack,$needle,$before,TRUE); } /** - Returns part of haystack string from the first occurrence of - needle to the end of haystack - @return string|FALSE - @param $stack string - @param $needle string - @param $before bool - @param $case bool + * Returns part of haystack string from the first occurrence of + * needle to the end of haystack + * @return string|FALSE + * @param $stack string + * @param $needle string + * @param $before bool + * @param $case bool **/ function strstr($stack,$needle,$before=FALSE,$case=FALSE) { if (!$needle) @@ -118,11 +118,11 @@ function strstr($stack,$needle,$before=FALSE,$case=FALSE) { } /** - Return part of a string - @return string|FALSE - @param $str string - @param $start int - @param $len int + * Return part of a string + * @return string|FALSE + * @param $str string + * @param $start int + * @param $len int **/ function substr($str,$start,$len=0) { if ($start<0) { @@ -136,10 +136,10 @@ function substr($str,$start,$len=0) { } /** - Count the number of substring occurrences - @return int - @param $stack string - @param $needle string + * Count the number of substring occurrences + * @return int + * @param $stack string + * @param $needle string **/ function substr_count($stack,$needle) { preg_match_all('/'.preg_quote($needle,'/').'/u',$stack, @@ -148,35 +148,35 @@ function substr_count($stack,$needle) { } /** - Strip whitespaces from the beginning of a string - @return string - @param $str string + * Strip whitespaces from the beginning of a string + * @return string + * @param $str string **/ function ltrim($str) { return preg_replace('/^[\pZ\pC]+/u','',$str); } /** - Strip whitespaces from the end of a string - @return string - @param $str string + * Strip whitespaces from the end of a string + * @return string + * @param $str string **/ function rtrim($str) { return preg_replace('/[\pZ\pC]+$/u','',$str); } /** - Strip whitespaces from the beginning and end of a string - @return string - @param $str string + * Strip whitespaces from the beginning and end of a string + * @return string + * @param $str string **/ function trim($str) { return preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u','',$str); } /** - Return UTF-8 byte order mark - @return string + * Return UTF-8 byte order mark + * @return string **/ function bom() { return chr(0xef).chr(0xbb).chr(0xbf); diff --git a/libs/f3/web.php b/libs/f3/web.php index 5ce14cba49..4edc2fad7b 100644 --- a/libs/f3/web.php +++ b/libs/f3/web.php @@ -1,7 +1,7 @@ request($url)) @@ -664,31 +664,62 @@ function rss($url,$max=10,$tags=NULL) { } /** - Return a URL/filesystem-friendly version of string - @return string - @param $text string + * Return a URL/filesystem-friendly version of string + * @return string + * @param $text string **/ function slug($text) { return trim(strtolower(preg_replace('/([^\pL\pN])+/u','-', trim(strtr(str_replace('\'','',$text), Base::instance()->get('DIACRITICS')+ array( - 'À'=>'A','Á'=>'A','Â'=>'A','Ã'=>'A','Å'=>'A','Ä'=>'A', - 'Ă'=>'A','Æ'=>'AE','à'=>'a','á'=>'a','â'=>'a','ã'=>'a', - 'å'=>'a','ä'=>'a','ă'=>'a','æ'=>'ae','Þ'=>'B','þ'=>'b', - 'Č'=>'C','Ć'=>'C','Ç'=>'C','č'=>'c','ć'=>'c','ç'=>'c', - 'Ď'=>'D','ð'=>'d','ď'=>'d','Đ'=>'Dj','đ'=>'dj','È'=>'E', - 'É'=>'E','Ê'=>'E','Ë'=>'E','Ě'=>'e','ě'=>'e','è'=>'e', - 'é'=>'e','ê'=>'e','ë'=>'e','Ì'=>'I','Í'=>'I','Î'=>'I', - 'Ï'=>'I','ì'=>'i','í'=>'i','î'=>'i','ï'=>'i','Ľ'=>'L', - 'ľ'=>'l','Ñ'=>'N','Ň'=>'N','ñ'=>'n','ň'=>'n','Ò'=>'O', - 'Ó'=>'O','Ô'=>'O','Õ'=>'O','Ø'=>'O','Ö'=>'O','Œ'=>'OE', - 'ò'=>'o','ó'=>'o','ô'=>'o','õ'=>'o','ö'=>'o','œ'=>'oe', - 'ø'=>'o','Ŕ'=>'R','Ř'=>'R','ŕ'=>'r','ř'=>'r','Š'=>'S', - 'Ș'=>'s','ș'=>'s','š'=>'s','ß'=>'ss','Ț'=>'T','ț'=>'t', - 'Ť'=>'T','ť'=>'t','Ù'=>'U','Ú'=>'U','Û'=>'U','Ü'=>'U', - 'Ů'=>'U','ù'=>'u','ú'=>'u','û'=>'u','ü'=>'u','ů'=>'u', - 'Ý'=>'Y','Ÿ'=>'Y','ý'=>'y','ÿ'=>'y','Ž'=>'Z','ž'=>'z' + 'Ǎ'=>'A','А'=>'A','Ā'=>'A','Ă'=>'A','Ą'=>'A','Å'=>'A', + 'Ǻ'=>'A','Ä'=>'A','Á'=>'A','À'=>'A','Ã'=>'A','Â'=>'A', + 'Æ'=>'AE','Ǽ'=>'AE','Б'=>'B','Ç'=>'C','Ć'=>'C','Ĉ'=>'C', + 'Č'=>'C','Ċ'=>'C','Ц'=>'C','Ч'=>'Ch','Ð'=>'Dj','Đ'=>'Dj', + 'Ď'=>'Dj','Д'=>'Dj','É'=>'E','Ę'=>'E','Ё'=>'E','Ė'=>'E', + 'Ê'=>'E','Ě'=>'E','Ē'=>'E','È'=>'E','Е'=>'E','Э'=>'E', + 'Ë'=>'E','Ĕ'=>'E','Ф'=>'F','Г'=>'G','Ģ'=>'G','Ġ'=>'G', + 'Ĝ'=>'G','Ğ'=>'G','Х'=>'H','Ĥ'=>'H','Ħ'=>'H','Ï'=>'I', + 'Ĭ'=>'I','İ'=>'I','Į'=>'I','Ī'=>'I','Í'=>'I','Ì'=>'I', + 'И'=>'I','Ǐ'=>'I','Ĩ'=>'I','Î'=>'I','IJ'=>'IJ','Ĵ'=>'J', + 'Й'=>'J','Я'=>'Ja','Ю'=>'Ju','К'=>'K','Ķ'=>'K','Ĺ'=>'L', + 'Л'=>'L','Ł'=>'L','Ŀ'=>'L','Ļ'=>'L','Ľ'=>'L','М'=>'M', + 'Н'=>'N','Ń'=>'N','Ñ'=>'N','Ņ'=>'N','Ň'=>'N','Ō'=>'O', + 'О'=>'O','Ǿ'=>'O','Ǒ'=>'O','Ơ'=>'O','Ŏ'=>'O','Ő'=>'O', + 'Ø'=>'O','Ö'=>'O','Õ'=>'O','Ó'=>'O','Ò'=>'O','Ô'=>'O', + 'Œ'=>'OE','П'=>'P','Ŗ'=>'R','Р'=>'R','Ř'=>'R','Ŕ'=>'R', + 'Ŝ'=>'S','Ş'=>'S','Š'=>'S','Ș'=>'S','Ś'=>'S','С'=>'S', + 'Ш'=>'Sh','Щ'=>'Shch','Ť'=>'T','Ŧ'=>'T','Ţ'=>'T','Ț'=>'T', + 'Т'=>'T','Ů'=>'U','Ű'=>'U','Ŭ'=>'U','Ũ'=>'U','Ų'=>'U', + 'Ū'=>'U','Ǜ'=>'U','Ǚ'=>'U','Ù'=>'U','Ú'=>'U','Ü'=>'U', + 'Ǘ'=>'U','Ǖ'=>'U','У'=>'U','Ư'=>'U','Ǔ'=>'U','Û'=>'U', + 'В'=>'V','Ŵ'=>'W','Ы'=>'Y','Ŷ'=>'Y','Ý'=>'Y','Ÿ'=>'Y', + 'Ź'=>'Z','З'=>'Z','Ż'=>'Z','Ž'=>'Z','Ж'=>'Zh','á'=>'a', + 'ă'=>'a','â'=>'a','à'=>'a','ā'=>'a','ǻ'=>'a','å'=>'a', + 'ä'=>'a','ą'=>'a','ǎ'=>'a','ã'=>'a','а'=>'a','ª'=>'a', + 'æ'=>'ae','ǽ'=>'ae','б'=>'b','č'=>'c','ç'=>'c','ц'=>'c', + 'ċ'=>'c','ĉ'=>'c','ć'=>'c','ч'=>'ch','ð'=>'dj','ď'=>'dj', + 'д'=>'dj','đ'=>'dj','э'=>'e','é'=>'e','ё'=>'e','ë'=>'e', + 'ê'=>'e','е'=>'e','ĕ'=>'e','è'=>'e','ę'=>'e','ě'=>'e', + 'ė'=>'e','ē'=>'e','ƒ'=>'f','ф'=>'f','ġ'=>'g','ĝ'=>'g', + 'ğ'=>'g','г'=>'g','ģ'=>'g','х'=>'h','ĥ'=>'h','ħ'=>'h', + 'ǐ'=>'i','ĭ'=>'i','и'=>'i','ī'=>'i','ĩ'=>'i','į'=>'i', + 'ı'=>'i','ì'=>'i','î'=>'i','í'=>'i','ï'=>'i','ij'=>'ij', + 'ĵ'=>'j','й'=>'j','я'=>'ja','ю'=>'ju','ķ'=>'k','к'=>'k', + 'ľ'=>'l','ł'=>'l','ŀ'=>'l','ĺ'=>'l','ļ'=>'l','л'=>'l', + 'м'=>'m','ņ'=>'n','ñ'=>'n','ń'=>'n','н'=>'n','ň'=>'n', + 'ʼn'=>'n','ó'=>'o','ò'=>'o','ǒ'=>'o','ő'=>'o','о'=>'o', + 'ō'=>'o','º'=>'o','ơ'=>'o','ŏ'=>'o','ô'=>'o','ö'=>'o', + 'õ'=>'o','ø'=>'o','ǿ'=>'o','œ'=>'oe','п'=>'p','р'=>'r', + 'ř'=>'r','ŕ'=>'r','ŗ'=>'r','ſ'=>'s','ŝ'=>'s','ș'=>'s', + 'š'=>'s','ś'=>'s','с'=>'s','ş'=>'s','ш'=>'sh','щ'=>'shch', + 'ß'=>'ss','ţ'=>'t','т'=>'t','ŧ'=>'t','ť'=>'t','ț'=>'t', + 'у'=>'u','ǘ'=>'u','ŭ'=>'u','û'=>'u','ú'=>'u','ų'=>'u', + 'ù'=>'u','ű'=>'u','ů'=>'u','ư'=>'u','ū'=>'u','ǚ'=>'u', + 'ǜ'=>'u','ǔ'=>'u','ǖ'=>'u','ũ'=>'u','ü'=>'u','в'=>'v', + 'ŵ'=>'w','ы'=>'y','ÿ'=>'y','ý'=>'y','ŷ'=>'y','ź'=>'z', + 'ž'=>'z','з'=>'z','ż'=>'z','ж'=>'zh' ))))),'-'); } @@ -697,8 +728,8 @@ function slug($text) { if (!function_exists('gzdecode')) { /** - Decode gzip-compressed string - @param $data string + * Decode gzip-compressed string + * @param $data string **/ function gzdecode($str) { $fw=Base::instance(); diff --git a/libs/f3/web/geo.php b/libs/f3/web/geo.php index 86c1553e55..73bcd4ded2 100644 --- a/libs/f3/web/geo.php +++ b/libs/f3/web/geo.php @@ -1,7 +1,7 @@ $val) if (preg_match('/^openid_(.+)/',$key,$match)) $this->args[$match[1]]=$val; - if ($url=$this->discover($proxy)) { + if ($this->args['mode']!='error' && $url=$this->discover($proxy)) { $this->args['mode']='check_authentication'; $var=array(); foreach ($this->args as $key=>$val) @@ -178,36 +178,37 @@ function verified($proxy=NULL) { } /** - Return TRUE if OpenID request parameter exists - @return bool - @param $key string + * Return TRUE if OpenID request parameter exists + * @return bool + * @param $key string **/ function exists($key) { return isset($this->args[$key]); } /** - Bind value to OpenID request parameter - @return string - @param $key string - @param $val string + * Bind value to OpenID request parameter + * @return string + * @param $key string + * @param $val string **/ function set($key,$val) { return $this->args[$key]=$val; } /** - Return value of OpenID request parameter - @return mixed - @param $key string + * Return value of OpenID request parameter + * @return mixed + * @param $key string **/ function get($key) { return isset($this->args[$key])?$this->args[$key]:NULL; } /** - Remove OpenID request parameter - @param $key + * Remove OpenID request parameter + * @return NULL + * @param $key **/ function clear($key) { unset($this->args[$key]); diff --git a/libs/f3/web/pingback.php b/libs/f3/web/pingback.php index 3b68e9ae1a..e6057a4dd8 100644 --- a/libs/f3/web/pingback.php +++ b/libs/f3/web/pingback.php @@ -1,7 +1,7 @@ log; } /** - Instantiate class - @return object + * Instantiate class + * @return object **/ function __construct() { // Suppress errors caused by invalid HTML structures