diff options
Diffstat (limited to 'extlib')
-rw-r--r-- | extlib/DB/DataObject.php | 243 | ||||
-rw-r--r-- | extlib/DB/DataObject/Cast.php | 9 | ||||
-rw-r--r-- | extlib/DB/DataObject/Error.php | 2 | ||||
-rw-r--r-- | extlib/DB/DataObject/Generator.php | 68 | ||||
-rw-r--r--[-rwxr-xr-x] | extlib/DB/DataObject/createTables.php | 2 | ||||
-rw-r--r-- | extlib/Services/oEmbed.php | 4 | ||||
-rw-r--r-- | extlib/facebook/facebook.php | 6 | ||||
-rwxr-xr-x | extlib/facebook/facebookapi_php5_restlib.php | 354 |
8 files changed, 489 insertions, 199 deletions
diff --git a/extlib/DB/DataObject.php b/extlib/DB/DataObject.php index 0c6a13dc2..8e226b8fa 100644 --- a/extlib/DB/DataObject.php +++ b/extlib/DB/DataObject.php @@ -2,11 +2,11 @@ /** * Object Based Database Query Builder and data store * - * PHP versions 4 and 5 + * For PHP versions 4,5 and 6 * - * LICENSE: This source file is subject to version 3.0 of the PHP license + * LICENSE: This source file is subject to version 3.01 of the PHP license * that is available through the world-wide-web at the following URI: - * http://www.php.net/license/3_0.txt. If you did not receive a copy of + * http://www.php.net/license/3_01.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * @@ -14,8 +14,8 @@ * @package DB_DataObject * @author Alan Knowles <alan@akbkhome.com> * @copyright 1997-2006 The PHP Group - * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: DataObject.php,v 1.439 2008/01/30 02:14:06 alan_k Exp $ + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @version CVS: $Id: DataObject.php 284150 2009-07-15 23:27:59Z alan_k $ * @link http://pear.php.net/package/DB_DataObject */ @@ -235,7 +235,7 @@ class DB_DataObject extends DB_DataObject_Overload * @access private * @var string */ - var $_DB_DataObject_version = "1.8.8"; + var $_DB_DataObject_version = "1.8.11"; /** * The Database table (used by table extends) @@ -1027,7 +1027,13 @@ class DB_DataObject extends DB_DataObject_Overload if ($leftq || $useNative) { $table = ($quoteIdentifiers ? $DB->quoteIdentifier($this->__table) : $this->__table); - $r = $this->_query("INSERT INTO {$table} ($leftq) VALUES ($rightq) "); + + if (($dbtype == 'pgsql') && empty($leftq)) { + $r = $this->_query("INSERT INTO {$table} DEFAULT VALUES"); + } else { + $r = $this->_query("INSERT INTO {$table} ($leftq) VALUES ($rightq) "); + } + @@ -1339,7 +1345,7 @@ class DB_DataObject extends DB_DataObject_Overload * build the condition only using the object parameters. * * @access public - * @return mixed True on success, false on failure, 0 on no data affected + * @return mixed Int (No. of rows affected) on success, false on failure, 0 on no data affected */ function delete($useWhere = false) { @@ -1369,7 +1375,13 @@ class DB_DataObject extends DB_DataObject_Overload if (($this->_query !== false) && $this->_query['condition']) { $table = ($quoteIdentifiers ? $DB->quoteIdentifier($this->__table) : $this->__table); - $sql = "DELETE FROM {$table} {$this->_query['condition']}{$extra_cond}"; + $sql = "DELETE "; + // using a joined delete. - with useWhere.. + $sql .= (!empty($this->_join) && $useWhere) ? + "{$table} FROM {$table} {$this->_join} " : + "FROM {$table} "; + + $sql .= $this->_query['condition']. $extra_cond; // add limit.. @@ -1521,15 +1533,15 @@ class DB_DataObject extends DB_DataObject_Overload } $keys = $this->keys(); - if (!$keys[0] && !is_string($countWhat)) { + if (empty($keys[0]) && (!is_string($countWhat) || (strtoupper($countWhat) == 'DISTINCT'))) { $this->raiseError( - "You cannot do run count without keys - use \$do->keys('id');", + "You cannot do run count without keys - use \$do->count('id'), or use \$do->count('distinct id')';", DB_DATAOBJECT_ERROR_INVALIDARGS,PEAR_ERROR_DIE); return false; } $table = ($quoteIdentifiers ? $DB->quoteIdentifier($this->__table) : $this->__table); - $key_col = ($quoteIdentifiers ? $DB->quoteIdentifier($keys[0]) : $keys[0]); + $key_col = empty($keys[0]) ? '' : (($quoteIdentifiers ? $DB->quoteIdentifier($keys[0]) : $keys[0])); $as = ($quoteIdentifiers ? $DB->quoteIdentifier('DATAOBJECT_NUM') : 'DATAOBJECT_NUM'); // support distinct on default keys. @@ -2044,7 +2056,7 @@ class DB_DataObject extends DB_DataObject_Overload // technically postgres native here... // we need to get the new improved tabledata sorted out first. - if ( in_array($dbtype , array('psql', 'mysql', 'mysqli', 'mssql', 'ifx')) && + if ( in_array($dbtype , array('pgsql', 'mysql', 'mysqli', 'mssql', 'ifx')) && ($table[$usekey] & DB_DATAOBJECT_INT) && isset($realkeys[$usekey]) && ($realkeys[$usekey] == 'N') ) { @@ -2125,10 +2137,13 @@ class DB_DataObject extends DB_DataObject_Overload $this->_loadConfig(); } // Set database driver for reference - $db_driver = empty($_DB_DATAOBJECT['CONFIG']['db_driver']) ? 'DB' : $_DB_DATAOBJECT['CONFIG']['db_driver']; - // is it already connected ? - + $db_driver = empty($_DB_DATAOBJECT['CONFIG']['db_driver']) ? + 'DB' : $_DB_DATAOBJECT['CONFIG']['db_driver']; + + // is it already connected ? if ($this->_database_dsn_md5 && !empty($_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5])) { + + // connection is an error... if (PEAR::isError($_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5])) { return $this->raiseError( $_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]->message, @@ -2137,7 +2152,7 @@ class DB_DataObject extends DB_DataObject_Overload } - if (!$this->_database) { + if (empty($this->_database)) { $this->_database = $_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]->dsn['database']; $hasGetDatabase = method_exists($_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5], 'getDatabase'); @@ -2166,6 +2181,7 @@ class DB_DataObject extends DB_DataObject_Overload // try and work out what to use for the dsn ! $options= &$_DB_DATAOBJECT['CONFIG']; + // if the databse dsn dis defined in the object.. $dsn = isset($this->_database_dsn) ? $this->_database_dsn : null; if (!$dsn) { @@ -2173,14 +2189,14 @@ class DB_DataObject extends DB_DataObject_Overload $this->_database = isset($options["table_{$this->__table}"]) ? $options["table_{$this->__table}"] : null; } if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) { - $this->debug("Checking for database database_{$this->_database} in options","CONNECT"); + $this->debug("Checking for database specific ini ('{$this->_database}') : database_{$this->_database} in options","CONNECT"); } if ($this->_database && !empty($options["database_{$this->_database}"])) { - $dsn = $options["database_{$this->_database}"]; } else if (!empty($options['database'])) { $dsn = $options['database']; + } } @@ -2205,6 +2221,9 @@ class DB_DataObject extends DB_DataObject_Overload if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) { $this->debug("USING CACHED CONNECTION", "CONNECT",3); } + + + if (!$this->_database) { $hasGetDatabase = method_exists($_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5], 'getDatabase'); @@ -2221,7 +2240,7 @@ class DB_DataObject extends DB_DataObject_Overload return true; } if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) { - $this->debug("NEW CONNECTION", "CONNECT",3); + $this->debug("NEW CONNECTION TP DATABASE :" .$this->_database , "CONNECT",3); /* actualy make a connection */ $this->debug(print_r($dsn,true) ." {$this->_database_dsn_md5}", "CONNECT",3); } @@ -2265,8 +2284,8 @@ class DB_DataObject extends DB_DataObject_Overload ); } - - if (!$this->_database) { + + if (empty($this->_database)) { $hasGetDatabase = method_exists($_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5], 'getDatabase'); $this->_database = ($db_driver != 'DB' && $hasGetDatabase) @@ -2357,38 +2376,38 @@ class DB_DataObject extends DB_DataObject_Overload $t= explode(' ',microtime()); $_DB_DATAOBJECT['QUERYENDTIME'] = $time = $t[0]+$t[1]; - - do { - if ($_DB_driver == 'DB') { - $result = $DB->query($string); - } else { - switch (strtolower(substr(trim($string),0,6))) { + for ($tries = 0;$tries < 3;$tries++) { - case 'insert': - case 'update': - case 'delete': - $result = $DB->exec($string); - break; - - default: - $result = $DB->query($string); - break; + if ($_DB_driver == 'DB') { + + $result = $DB->query($string); + } else { + switch (strtolower(substr(trim($string),0,6))) { + + case 'insert': + case 'update': + case 'delete': + $result = $DB->exec($string); + break; + + default: + $result = $DB->query($string); + break; + } } + + // see if we got a failure.. - try again a few times.. + if (!is_a($result,'PEAR_Error')) { + break; + } + if ($result->getCode() != -14) { // *DB_ERROR_NODBSELECTED + break; // not a connection error.. + } + sleep(1); // wait before retyring.. + $DB->connect($DB->dsn); } - - // try to reconnect, at most 3 times - $again = false; - if (is_a($result, 'PEAR_Error') - AND $result->getCode() == DB_ERROR_NODBSELECTED - AND $cpt++<3) { - $DB->disconnect(); - sleep(1); - $DB->connect($DB->dsn); - $again = true; - } - - } while ($again); + if (is_a($result,'PEAR_Error')) { if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) { @@ -2556,11 +2575,13 @@ class DB_DataObject extends DB_DataObject_Overload * use @ to silence it (if you are sure it is acceptable) * eg. $do = @DB_DataObject::factory('person') * - * table name will eventually be databasename/table + * table name can bedatabasename/table * - and allow modular dataobjects to be written.. * (this also helps proxy creation) * - * + * Experimental Support for Multi-Database factory eg. mydatabase.mytable + * + * * @param string $table tablename (use blank to create a new instance of the same class.) * @access private * @return DataObject|PEAR_Error @@ -2570,9 +2591,27 @@ class DB_DataObject extends DB_DataObject_Overload function factory($table = '') { global $_DB_DATAOBJECT; + + + // multi-database support.. - experimental. + $database = ''; + + if (strpos( $table,'/') !== false ) { + list($database,$table) = explode('.',$table, 2); + + } + if (empty($_DB_DATAOBJECT['CONFIG'])) { DB_DataObject::_loadConfig(); } + // no configuration available for database + if (!empty($database) && empty($_DB_DATAOBJECT['CONFIG']['database_'.$database])) { + return DB_DataObject::raiseError( + "unable to find database_{$database} in Configuration, It is required for factory with database" + , 0, PEAR_ERROR_DIE ); + } + + if ($table === '') { if (is_a($this,'DB_DataObject') && strlen($this->__table)) { @@ -2584,17 +2623,22 @@ class DB_DataObject extends DB_DataObject_Overload } } - + // does this need multi db support?? $p = isset($_DB_DATAOBJECT['CONFIG']['class_prefix']) ? $_DB_DATAOBJECT['CONFIG']['class_prefix'] : ''; $class = $p . preg_replace('/[^A-Z0-9]/i','_',ucfirst($table)); - $ce = substr(phpversion(),0,1) > 4 ? class_exists($class,false) : class_exists($class); + $class = $ce ? $class : DB_DataObject::_autoloadClass($class); // proxy = full|light if (!$class && isset($_DB_DATAOBJECT['CONFIG']['proxy'])) { + + DB_DataObject::debug("FAILED TO Autoload $database.$table - using proxy.","FACTORY",1); + + $proxyMethod = 'getProxy'.$_DB_DATAOBJECT['CONFIG']['proxy']; + // if you have loaded (some other way) - dont try and load it again.. class_exists('DB_DataObject_Generator') ? '' : require_once 'DB/DataObject/Generator.php'; @@ -2614,8 +2658,12 @@ class DB_DataObject extends DB_DataObject_Overload "factory could not find class $class from $table", DB_DATAOBJECT_ERROR_INVALIDCONFIG); } - - return new $class; + $ret = new $class; + if (!empty($database)) { + DB_DataObject::debug("Setting database to $database","FACTORY",1); + $ret->database($database); + } + return $ret; } /** * autoload Class @@ -3079,7 +3127,7 @@ class DB_DataObject extends DB_DataObject_Overload return; } - + //echo '<PRE>'; print_r(func_get_args()); $useWhereAsOn = false; // support for 2nd argument as an array of options if (is_array($joinType)) { @@ -3119,8 +3167,39 @@ class DB_DataObject extends DB_DataObject_Overload $DB = &$_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]; + /// CHANGED 26 JUN 2009 - we prefer links from our local table over the remote one. - + /* otherwise see if there are any links from this table to the obj. */ + //print_r($this->links()); + if (($ofield === false) && ($links = $this->links())) { + foreach ($links as $k => $v) { + /* link contains {this column} = {linked table}:{linked column} */ + $ar = explode(':', $v); + // Feature Request #4266 - Allow joins with multiple keys + if (strpos($k, ',') !== false) { + $k = explode(',', $k); + } + if (strpos($ar[1], ',') !== false) { + $ar[1] = explode(',', $ar[1]); + } + + if ($ar[0] == $obj->__table) { + if ($joinCol !== false) { + if ($k == $joinCol) { + $tfield = $k; + $ofield = $ar[1]; + break; + } else { + continue; + } + } else { + $tfield = $k; + $ofield = $ar[1]; + break; + } + } + } + } /* look up the links for obj table */ //print_r($obj->links()); if (!$ofield && ($olinks = $obj->links())) { @@ -3164,37 +3243,6 @@ class DB_DataObject extends DB_DataObject_Overload } } - /* otherwise see if there are any links from this table to the obj. */ - //print_r($this->links()); - if (($ofield === false) && ($links = $this->links())) { - foreach ($links as $k => $v) { - /* link contains {this column} = {linked table}:{linked column} */ - $ar = explode(':', $v); - // Feature Request #4266 - Allow joins with multiple keys - if (strpos($k, ',') !== false) { - $k = explode(',', $k); - } - if (strpos($ar[1], ',') !== false) { - $ar[1] = explode(',', $ar[1]); - } - - if ($ar[0] == $obj->__table) { - if ($joinCol !== false) { - if ($k == $joinCol) { - $tfield = $k; - $ofield = $ar[1]; - break; - } else { - continue; - } - } else { - $tfield = $k; - $ofield = $ar[1]; - break; - } - } - } - } // finally if these two table have column names that match do a join by default on them if (($ofield === false) && $joinCol) { @@ -3383,22 +3431,25 @@ class DB_DataObject extends DB_DataObject_Overload case 'RIGHT': // others??? .. cross, left outer, right outer, natural..? // Feature Request #4266 - Allow joins with multiple keys - $this->_join .= "\n {$joinType} JOIN {$objTable} {$fullJoinAs}"; + $jadd = "\n {$joinType} JOIN {$objTable} {$fullJoinAs}"; + //$this->_join .= "\n {$joinType} JOIN {$objTable} {$fullJoinAs}"; if (is_array($ofield)) { $key_count = count($ofield); for($i = 0; $i < $key_count; $i++) { if ($i == 0) { - $this->_join .= " ON ({$joinAs}.{$ofield[$i]}={$table}.{$tfield[$i]}) "; + $jadd .= " ON ({$joinAs}.{$ofield[$i]}={$table}.{$tfield[$i]}) "; } else { - $this->_join .= " AND {$joinAs}.{$ofield[$i]}={$table}.{$tfield[$i]} "; + $jadd .= " AND {$joinAs}.{$ofield[$i]}={$table}.{$tfield[$i]} "; } } - $this->_join .= ' ' . $appendJoin . ' '; + $jadd .= ' ' . $appendJoin . ' '; } else { - $this->_join .= " ON ({$joinAs}.{$ofield}={$table}.{$tfield}) {$appendJoin} "; + $jadd .= " ON ({$joinAs}.{$ofield}={$table}.{$tfield}) {$appendJoin} "; } - + // jadd avaliable for debugging join build. + //echo $jadd ."\n"; + $this->_join .= $jadd; break; case '': // this is just a standard multitable select.. @@ -3459,7 +3510,7 @@ class DB_DataObject extends DB_DataObject_Overload continue; } - if (empty($from[$k]) && $skipEmpty) { + if (empty($from[sprintf($format,$k)]) && $skipEmpty) { continue; } diff --git a/extlib/DB/DataObject/Cast.php b/extlib/DB/DataObject/Cast.php index 616abb55e..095d2a4d2 100644 --- a/extlib/DB/DataObject/Cast.php +++ b/extlib/DB/DataObject/Cast.php @@ -15,9 +15,9 @@ * @category Database * @package DB_DataObject * @author Alan Knowles <alan@akbkhome.com> - * @copyright 1997-2006 The PHP Group + * @copyright 1997-2008 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Cast.php,v 1.15 2005/07/07 05:30:53 alan_k Exp $ + * @version CVS: $Id: Cast.php 264148 2008-08-04 03:44:59Z alan_k $ * @link http://pear.php.net/package/DB_DataObject */ @@ -391,7 +391,10 @@ class DB_DataObject_Cast { // this is funny - the parameter order is reversed ;) return "'".mysqli_real_escape_string($db->connection, $this->value)."'"; - + case 'sqlite': + // this is funny - the parameter order is reversed ;) + return "'".sqlite_escape_string($this->value)."'"; + default: return PEAR::raiseError("DB_DataObject_Cast cant handle blobs for Database:{$db->dsn['phptype']} Yet"); diff --git a/extlib/DB/DataObject/Error.php b/extlib/DB/DataObject/Error.php index 05a741408..382115453 100644 --- a/extlib/DB/DataObject/Error.php +++ b/extlib/DB/DataObject/Error.php @@ -18,7 +18,7 @@ * @author Alan Knowles <alan@akbkhome.com> * @copyright 1997-2006 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Error.php,v 1.3 2005/03/23 02:35:35 alan_k Exp $ + * @version CVS: $Id: Error.php 277015 2009-03-12 05:51:03Z alan_k $ * @link http://pear.php.net/package/DB_DataObject */ diff --git a/extlib/DB/DataObject/Generator.php b/extlib/DB/DataObject/Generator.php index de16af692..ff6e42c7d 100644 --- a/extlib/DB/DataObject/Generator.php +++ b/extlib/DB/DataObject/Generator.php @@ -4,9 +4,9 @@ * * PHP versions 4 and 5 * - * LICENSE: This source file is subject to version 3.0 of the PHP license + * LICENSE: This source file is subject to version 3.01 of the PHP license * that is available through the world-wide-web at the following URI: - * http://www.php.net/license/3_0.txt. If you did not receive a copy of + * http://www.php.net/license/3_01.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * @@ -14,8 +14,8 @@ * @package DB_DataObject * @author Alan Knowles <alan@akbkhome.com> * @copyright 1997-2006 The PHP Group - * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Generator.php,v 1.141 2008/01/30 02:29:39 alan_k Exp $ + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @version CVS: $Id: Generator.php 284150 2009-07-15 23:27:59Z alan_k $ * @link http://pear.php.net/package/DB_DataObject */ @@ -193,7 +193,11 @@ class DB_DataObject_Generator extends DB_DataObject /** * set portability and some modules to fetch the informations */ - $__DB->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_FIX_CASE); + $db_options = PEAR::getStaticProperty('MDB2','options'); + if (empty($db_options)) { + $__DB->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_FIX_CASE); + } + $__DB->loadModule('Manager'); $__DB->loadModule('Reverse'); } @@ -265,12 +269,7 @@ class DB_DataObject_Generator extends DB_DataObject } else { $defs = $__DB->reverse->tableInfo($quotedTable); // rename the length value, so it matches db's return. - foreach ($defs as $k => $v) { - if (!isset($defs[$k]['length'])) { - continue; - } - $defs[$k]['len'] = $defs[$k]['length']; - } + } if (is_a($defs,'PEAR_Error')) { @@ -286,7 +285,10 @@ class DB_DataObject_Generator extends DB_DataObject if (!is_array($def)) { continue; } - + // rename the length value, so it matches db's return. + if (isset($def['length']) && !isset($def['len'])) { + $def['len'] = $def['length']; + } $this->_definitions[$table][] = (object) $def; } @@ -391,7 +393,10 @@ class DB_DataObject_Generator extends DB_DataObject $fk = array(); foreach($this->tables as $this->table) { - $res =& $DB->query('SHOW CREATE TABLE ' . $this->table); + $quotedTable = !empty($options['quote_identifiers_tableinfo']) ? $DB->quoteIdentifier($table) : $this->table; + + $res =& $DB->query('SHOW CREATE TABLE ' . $quotedTable ); + if (PEAR::isError($res)) { die($res->getMessage()); } @@ -467,7 +472,7 @@ class DB_DataObject_Generator extends DB_DataObject function _generateDefinitionsTable() { global $_DB_DATAOBJECT; - + $options = PEAR::getStaticProperty('DB_DataObject','options'); $defs = $this->_definitions[$this->table]; $this->_newConfig .= "\n[{$this->table}]\n"; $keys_out = "\n[{$this->table}__keys]\n"; @@ -551,6 +556,9 @@ class DB_DataObject_Generator extends DB_DataObject case 'ENUM': case 'SET': // not really but oh well + + case 'POINT': // mysql geometry stuff - not really string - but will do.. + case 'TIMESTAMPTZ': // postgres case 'BPCHAR': // postgres case 'INTERVAL': // postgres (eg. '12 days') @@ -594,14 +602,18 @@ class DB_DataObject_Generator extends DB_DataObject DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME; break; - - case 'TINYBLOB': + case 'BLOB': /// these should really be ignored!!!??? + case 'TINYBLOB': case 'MEDIUMBLOB': case 'LONGBLOB': + + case 'CLOB': // oracle character lob support + case 'BYTEA': // postgres blob support.. $type = DB_DATAOBJECT_STR + DB_DATAOBJECT_BLOB; break; + default: echo "*****************************************************************\n". "** WARNING UNKNOWN TYPE **\n". @@ -653,7 +665,9 @@ class DB_DataObject_Generator extends DB_DataObject // only use primary key or nextval(), cause the setFrom blocks you setting all key items... // if no keys exist fall back to using unique //echo "\n{$t->name} => {$t->flags}\n"; - if (preg_match("/(auto_increment|nextval\()/i",rawurldecode($t->flags)) + $secondary_key_match = isset($options['generator_secondary_key_match']) ? $options['generator_secondary_key_match'] : 'primary|unique'; + + if (preg_match('/(auto_increment|nextval\()/i',rawurldecode($t->flags)) || (isset($t->autoincrement) && ($t->autoincrement === true))) { // native sequences = 2 @@ -662,7 +676,7 @@ class DB_DataObject_Generator extends DB_DataObject } $ret_keys_primary[$t->name] = 'N'; - } else if (preg_match("/(primary|unique)/i",$t->flags)) { + } else if ($secondary_key_match && preg_match('/('.$secondary_key_match.')/i',$t->flags)) { // keys.. = 1 $key_type = 'K'; if (!preg_match("/(primary)/i",$t->flags)) { @@ -868,10 +882,13 @@ class DB_DataObject_Generator extends DB_DataObject // then we should add var $_database = here // as database names may not always match.. + if (empty($GLOBALS['_DB_DATAOBJECT']['CONFIG'])) { + DB_DataObject::_loadConfig(); + } + + // Only include the $_database property if the omit_database_var is unset or false - - - if (isset($options["database_{$this->_database}"])) { + if (isset($options["database_{$this->_database}"]) && empty($GLOBALS['_DB_DATAOBJECT']['CONFIG']['generator_omit_database_var'])) { $body .= " {$var} \$_database = '{$this->_database}'; {$p}// database name (used with database_{*} config)\n"; } @@ -904,9 +921,10 @@ class DB_DataObject_Generator extends DB_DataObject $padding = (30 - strlen($t->name)); if ($padding < 2) $padding =2; $p = str_repeat(' ',$padding) ; - - $body .=" {$var} \${$t->name}; {$p}// {$t->type}({$t->len}) {$t->flags}\n"; - + + $length = empty($t->len) ? '' : '('.$t->len.')'; + $body .=" {$var} \${$t->name}; {$p}// {$t->type}$length {$t->flags}\n"; + // can not do set as PEAR::DB table info doesnt support it. //if (substr($t->Type,0,3) == "set") // $sets[$t->Field] = "array".substr($t->Type,3); @@ -1185,7 +1203,7 @@ class DB_DataObject_Generator extends DB_DataObject $__DB->loadModule('Manager'); $__DB->loadModule('Reverse'); } - $quotedTable = !empty($options['quote_identifiers']) ? + $quotedTable = !empty($options['quote_identifiers_tableinfo']) ? $__DB->quoteIdentifier($table) : $table; if (!$is_MDB2) { diff --git a/extlib/DB/DataObject/createTables.php b/extlib/DB/DataObject/createTables.php index c0659574e..d54d28c24 100755..100644 --- a/extlib/DB/DataObject/createTables.php +++ b/extlib/DB/DataObject/createTables.php @@ -16,7 +16,7 @@ // | Author: Alan Knowles <alan@akbkhome.com> // +----------------------------------------------------------------------+ // -// $Id: createTables.php,v 1.24 2006/01/13 01:27:55 alan_k Exp $ +// $Id: createTables.php 277015 2009-03-12 05:51:03Z alan_k $ // // since this version doesnt use overload, diff --git a/extlib/Services/oEmbed.php b/extlib/Services/oEmbed.php index 5d38ed883..7d507b6f6 100644 --- a/extlib/Services/oEmbed.php +++ b/extlib/Services/oEmbed.php @@ -162,7 +162,7 @@ class Services_oEmbed } if ($this->options[self::OPTION_API] === null) { - $this->options[self::OPTION_API] = $this->discover(); + $this->options[self::OPTION_API] = $this->discover($url); } } @@ -319,7 +319,7 @@ class Services_oEmbed } } - return (isset($ret['json']) ? $ret['json'] : array_pop($ret)); + return (isset($ret['application/json']) ? $ret['application/json'] : array_pop($ret)); } /** diff --git a/extlib/facebook/facebook.php b/extlib/facebook/facebook.php index fee1dd086..016e8e8e0 100644 --- a/extlib/facebook/facebook.php +++ b/extlib/facebook/facebook.php @@ -107,13 +107,13 @@ class Facebook { * @param bool resolve_auth_token convert an auth token into a session */ public function validate_fb_params($resolve_auth_token=true) { - $this->fb_params = $this->get_valid_fb_params($_POST, 48*3600, 'fb_sig'); + $this->fb_params = $this->get_valid_fb_params($_POST, 48 * 3600, 'fb_sig'); // note that with preload FQL, it's possible to receive POST params in // addition to GET, so use a different prefix to differentiate them if (!$this->fb_params) { - $fb_params = $this->get_valid_fb_params($_GET, 48*3600, 'fb_sig'); - $fb_post_params = $this->get_valid_fb_params($_POST, 48*3600, 'fb_post_sig'); + $fb_params = $this->get_valid_fb_params($_GET, 48 * 3600, 'fb_sig'); + $fb_post_params = $this->get_valid_fb_params($_POST, 48 * 3600, 'fb_post_sig'); $this->fb_params = array_merge($fb_params, $fb_post_params); } diff --git a/extlib/facebook/facebookapi_php5_restlib.php b/extlib/facebook/facebookapi_php5_restlib.php index 3fec06e8a..55cb7fb86 100755 --- a/extlib/facebook/facebookapi_php5_restlib.php +++ b/extlib/facebook/facebookapi_php5_restlib.php @@ -55,6 +55,7 @@ class FacebookRestClient { private $pending_batch; private $call_as_apikey; private $use_curl_if_available; + private $format = null; const BATCH_MODE_DEFAULT = 0; const BATCH_MODE_SERVER_PARALLEL = 0; @@ -178,39 +179,32 @@ function toggleDisplay(id, type) { private function execute_server_side_batch() { $item_count = count($this->batch_queue); $method_feed = array(); - foreach($this->batch_queue as $batch_item) { + foreach ($this->batch_queue as $batch_item) { $method = $batch_item['m']; $params = $batch_item['p']; - $this->finalize_params($method, $params); - $method_feed[] = $this->create_post_string($method, $params); + list($get, $post) = $this->finalize_params($method, $params); + $method_feed[] = $this->create_url_string(array_merge($post, $get)); } - $method_feed_json = json_encode($method_feed); - $serial_only = ($this->batch_mode == FacebookRestClient::BATCH_MODE_SERIAL_ONLY); - $params = array('method_feed' => $method_feed_json, - 'serial_only' => $serial_only); - if ($this->call_as_apikey) { - $params['call_as_apikey'] = $this->call_as_apikey; - } - - $xml = $this->post_request('batch.run', $params); - - $result = $this->convert_xml_to_result($xml, 'batch.run', $params); + $params = array('method_feed' => json_encode($method_feed), + 'serial_only' => $serial_only, + 'format' => $this->format); + $result = $this->call_method('facebook.batch.run', $params); if (is_array($result) && isset($result['error_code'])) { throw new FacebookRestClientException($result['error_msg'], $result['error_code']); } - for($i = 0; $i < $item_count; $i++) { + for ($i = 0; $i < $item_count; $i++) { $batch_item = $this->batch_queue[$i]; - $batch_item_result_xml = $result[$i]; - $batch_item_result = $this->convert_xml_to_result($batch_item_result_xml, - $batch_item['m'], - $batch_item['p']); + $batch_item['p']['format'] = $this->format; + $batch_item_result = $this->convert_result($result[$i], + $batch_item['m'], + $batch_item['p']); if (is_array($batch_item_result) && isset($batch_item_result['error_code'])) { @@ -516,12 +510,20 @@ function toggleDisplay(id, type) { * behalf of app. Successful creation guarantees app will be admin. * * @param assoc array $event_info json encoded event information + * @param string $file (Optional) filename of picture to set * * @return int event id */ - public function &events_create($event_info) { - return $this->call_method('facebook.events.create', + public function events_create($event_info, $file = null) { + if ($file) { + return $this->call_upload_method('facebook.events.create', + array('event_info' => $event_info), + $file, + Facebook::get_facebook_url('api-photo') . '/restserver.php'); + } else { + return $this->call_method('facebook.events.create', array('event_info' => $event_info)); + } } /** @@ -529,13 +531,21 @@ function toggleDisplay(id, type) { * * @param int $eid event id * @param assoc array $event_info json encoded event information + * @param string $file (Optional) filename of new picture to set * * @return bool true if successful */ - public function &events_edit($eid, $event_info) { - return $this->call_method('facebook.events.edit', + public function events_edit($eid, $event_info, $file = null) { + if ($file) { + return $this->call_upload_method('facebook.events.edit', + array('eid' => $eid, 'event_info' => $event_info), + $file, + Facebook::get_facebook_url('api-photo') . '/restserver.php'); + } else { + return $this->call_method('facebook.events.edit', array('eid' => $eid, - 'event_info' => $event_info)); + 'event_info' => $event_info)); + } } /** @@ -935,7 +945,7 @@ function toggleDisplay(id, type) { /** * Makes an FQL query. This is a generalized way of accessing all the data * in the API, as an alternative to most of the other method calls. More - * info at http://developers.facebook.com/documentation.php?v=1.0&doc=fql + * info at http://wiki.developers.facebook.com/index.php/FQL * * @param string $query the query to evaluate * @@ -947,6 +957,21 @@ function toggleDisplay(id, type) { } /** + * Makes a set of FQL queries in parallel. This method takes a dictionary + * of FQL queries where the keys are names for the queries. Results from + * one query can be used within another query to fetch additional data. More + * info about FQL queries at http://wiki.developers.facebook.com/index.php/FQL + * + * @param string $queries JSON-encoded dictionary of queries to evaluate + * + * @return array generalized array representing the results + */ + public function &fql_multiquery($queries) { + return $this->call_method('facebook.fql.multiquery', + array('queries' => $queries)); + } + + /** * Returns whether or not pairs of users are friends. * Note that the Facebook friend relationship is symmetric. * @@ -995,6 +1020,23 @@ function toggleDisplay(id, type) { } /** + * Returns the mutual friends between the target uid and a source uid or + * the current session user. + * + * @param int $target_uid Target uid for which mutual friends will be found. + * @param int $source_uid (optional) Source uid for which mutual friends will + * be found. If no source_uid is specified, + * source_id will default to the session + * user. + * @return array An array of friend uids + */ + public function &friends_getMutualFriends($target_uid, $source_uid = null) { + return $this->call_method('facebook.friends.getMutualFriends', + array("target_uid" => $target_uid, + "source_uid" => $source_uid)); + } + + /** * Returns the set of friend lists for the current session user. * * @return array An array of friend list objects @@ -1169,6 +1211,44 @@ function toggleDisplay(id, type) { } /** + * Payments Order API + */ + + /** + * Set Payments properties for an app. + * + * @param properties a map from property names to values + * @return true on success + */ + public function payments_setProperties($properties) { + return $this->call_method ('facebook.payments.setProperties', + array('properties' => json_encode($properties))); + } + + public function payments_getOrderDetails($order_id) { + return json_decode($this->call_method( + 'facebook.payments.getOrderDetails', + array('order_id' => $order_id)), true); + } + + public function payments_updateOrder($order_id, $status, + $params) { + return $this->call_method('facebook.payments.updateOrder', + array('order_id' => $order_id, + 'status' => $status, + 'params' => json_encode($params))); + } + + public function payments_getOrders($status, $start_time, + $end_time, $test_mode=false) { + return json_decode($this->call_method('facebook.payments.getOrders', + array('status' => $status, + 'start_time' => $start_time, + 'end_time' => $end_time, + 'test_mode' => $test_mode)), true); + } + + /** * Creates a note with the specified title and content. * * @param string $title Title of the note. @@ -1233,7 +1313,6 @@ function toggleDisplay(id, type) { * notes. */ public function ¬es_get($uid, $note_ids = null) { - return $this->call_method('notes.get', array('uid' => $uid, 'note_ids' => $note_ids)); @@ -1632,6 +1711,63 @@ function toggleDisplay(id, type) { } /** + * Gets the comments for a particular xid. This is essentially a wrapper + * around the comment FQL table. + * + * @param string $xid external id associated with the comments + * + * @return array of comment objects + */ + public function &comments_get($xid) { + $args = array('xid' => $xid); + return $this->call_method('facebook.comments.get', $args); + } + + /** + * Add a comment to a particular xid on behalf of a user. If called + * without an app_secret (with session secret), this will only work + * for the session user. + * + * @param string $xid external id associated with the comments + * @param string $text text of the comment + * @param int $uid user adding the comment (def: session user) + * @param string $title optional title for the stream story + * @param string $url optional url for the stream story + * @param bool $publish_to_stream publish a feed story about this comment? + * a link will be generated to title/url in the story + * + * @return string comment_id associated with the comment + */ + public function &comments_add($xid, $text, $uid=0, $title='', $url='', + $publish_to_stream=false) { + $args = array( + 'xid' => $xid, + 'uid' => $this->get_uid($uid), + 'text' => $text, + 'title' => $title, + 'url' => $url, + 'publish_to_stream' => $publish_to_stream); + + return $this->call_method('facebook.comments.add', $args); + } + + /** + * Remove a particular comment. + * + * @param string $xid the external id associated with the comments + * @param string $comment_id id of the comment to remove (returned by + * comments.add and comments.get) + * + * @return boolean + */ + public function &comments_remove($xid, $comment_id) { + $args = array( + 'xid' => $xid, + 'comment_id' => $comment_id); + return $this->call_method('facebook.comments.remove', $args); + } + + /** * Gets the stream on behalf of a user using a set of users. This * call will return the latest $limit queries between $start_time * and $end_time. @@ -1642,11 +1778,16 @@ function toggleDisplay(id, type) { * @param int $end_time end time to look for stories (def: now) * @param int $limit number of stories to attempt to fetch (def: 30) * @param string $filter_key key returned by stream.getFilters to fetch + * @param array $metadata metadata to include with the return, allows + * requested metadata to be returned, such as + * profiles, albums, photo_tags * * @return array( - * 'posts' => array of posts, - * 'profiles' => array of profile metadata of users/pages in posts - * 'albums' => array of album metadata in posts + * 'posts' => array of posts, + * // if requested, the following data may be returned + * 'profiles' => array of profile metadata of users/pages in posts + * 'albums' => array of album metadata in posts + * 'photo_tags' => array of photo_tags for photos in posts * ) */ public function &stream_get($viewer_id = null, @@ -2849,6 +2990,7 @@ function toggleDisplay(id, type) { array('uids' => $uids ? json_encode($uids) : null)); } + /* UTILITY FUNCTIONS */ /** @@ -2862,18 +3004,15 @@ function toggleDisplay(id, type) { * See: http://wiki.developers.facebook.com/index.php/Using_batching_API */ public function &call_method($method, $params = array()) { + if ($this->format) { + $params['format'] = $this->format; + } if (!$this->pending_batch()) { if ($this->call_as_apikey) { $params['call_as_apikey'] = $this->call_as_apikey; } $data = $this->post_request($method, $params); - if (empty($params['format']) || strtolower($params['format']) != 'json') { - $result = $this->convert_xml_to_result($data, $method, $params); - } - else { - $result = json_decode($data, true); - } - + $result = $this->convert_result($data, $method, $params); if (is_array($result) && isset($result['error_code'])) { throw new FacebookRestClientException($result['error_msg'], $result['error_code']); @@ -2888,6 +3027,32 @@ function toggleDisplay(id, type) { return $result; } + protected function convert_result($data, $method, $params) { + $is_xml = (empty($params['format']) || + strtolower($params['format']) != 'json'); + return ($is_xml) ? $this->convert_xml_to_result($data, $method, $params) + : json_decode($data, true); + } + + /** + * Change the response format + * + * @param string $format The response format (json, xml) + */ + public function setFormat($format) { + $this->format = $format; + return $this; + } + + /** + * get the current response serialization format + * + * @return string 'xml', 'json', or null (which means 'xml') + */ + public function getFormat() { + return $this->format; + } + /** * Calls the specified file-upload POST method with the specified parameters * @@ -2906,8 +3071,14 @@ function toggleDisplay(id, type) { throw new FacebookRestClientException($description, $code); } - $xml = $this->post_upload_request($method, $params, $file, $server_addr); - $result = $this->convert_xml_to_result($xml, $method, $params); + if ($this->format) { + $params['format'] = $this->format; + } + $data = $this->post_upload_request($method, + $params, + $file, + $server_addr); + $result = $this->convert_result($data, $method, $params); if (is_array($result) && isset($result['error_code'])) { throw new FacebookRestClientException($result['error_msg'], @@ -2946,11 +3117,13 @@ function toggleDisplay(id, type) { return $result; } - private function finalize_params($method, &$params) { - $this->add_standard_params($method, $params); + protected function finalize_params($method, $params) { + list($get, $post) = $this->add_standard_params($method, $params); // we need to do this before signing the params - $this->convert_array_values_to_json($params); - $params['sig'] = Facebook::generate_sig($params, $this->secret); + $this->convert_array_values_to_json($post); + $post['sig'] = Facebook::generate_sig(array_merge($get, $post), + $this->secret); + return array($get, $post); } private function convert_array_values_to_json(&$params) { @@ -2961,28 +3134,38 @@ function toggleDisplay(id, type) { } } - private function add_standard_params($method, &$params) { + /** + * Add the generally required params to our request. + * Params method, api_key, and v should be sent over as get. + */ + private function add_standard_params($method, $params) { + $post = $params; + $get = array(); if ($this->call_as_apikey) { - $params['call_as_apikey'] = $this->call_as_apikey; + $get['call_as_apikey'] = $this->call_as_apikey; } - $params['method'] = $method; - $params['session_key'] = $this->session_key; - $params['api_key'] = $this->api_key; - $params['call_id'] = microtime(true); - if ($params['call_id'] <= $this->last_call_id) { - $params['call_id'] = $this->last_call_id + 0.001; + $get['method'] = $method; + $get['session_key'] = $this->session_key; + $get['api_key'] = $this->api_key; + $post['call_id'] = microtime(true); + if ($post['call_id'] <= $this->last_call_id) { + $post['call_id'] = $this->last_call_id + 0.001; } - $this->last_call_id = $params['call_id']; - if (!isset($params['v'])) { - $params['v'] = '1.0'; + $this->last_call_id = $post['call_id']; + if (isset($post['v'])) { + $get['v'] = $post['v']; + unset($post['v']); + } else { + $get['v'] = '1.0'; } if (isset($this->use_ssl_resources) && $this->use_ssl_resources) { - $params['return_ssl_resources'] = true; + $post['return_ssl_resources'] = true; } + return array($get, $post); } - private function create_post_string($method, $params) { + private function create_url_string($params) { $post_params = array(); foreach ($params as $key => &$val) { $post_params[] = $key.'='.urlencode($val); @@ -3022,48 +3205,64 @@ function toggleDisplay(id, type) { } public function post_request($method, $params) { - $this->finalize_params($method, $params); - $post_string = $this->create_post_string($method, $params); + list($get, $post) = $this->finalize_params($method, $params); + $post_string = $this->create_url_string($post); + $get_string = $this->create_url_string($get); + $url_with_get = $this->server_addr . '?' . $get_string; if ($this->use_curl_if_available && function_exists('curl_init')) { $useragent = 'Facebook API PHP5 Client 1.1 (curl) ' . phpversion(); $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $this->server_addr); + curl_setopt($ch, CURLOPT_URL, $url_with_get); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, $useragent); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_TIMEOUT, 30); - $result = curl_exec($ch); + $result = $this->curl_exec($ch); curl_close($ch); } else { $content_type = 'application/x-www-form-urlencoded'; $content = $post_string; $result = $this->run_http_post_transaction($content_type, $content, - $this->server_addr); + $url_with_get); } return $result; } + /** + * execute a curl transaction -- this exists mostly so subclasses can add + * extra options and/or process the response, if they wish. + * + * @param resource $ch a curl handle + */ + protected function curl_exec($ch) { + $result = curl_exec($ch); + return $result; + } + private function post_upload_request($method, $params, $file, $server_addr = null) { $server_addr = $server_addr ? $server_addr : $this->server_addr; - $this->finalize_params($method, $params); + list($get, $post) = $this->finalize_params($method, $params); + $get_string = $this->create_url_string($get); + $url_with_get = $server_addr . '?' . $get_string; if ($this->use_curl_if_available && function_exists('curl_init')) { // prepending '@' causes cURL to upload the file; the key is ignored. - $params['_file'] = '@' . $file; + $post['_file'] = '@' . $file; $useragent = 'Facebook API PHP5 Client 1.1 (curl) ' . phpversion(); $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $server_addr); + curl_setopt($ch, CURLOPT_URL, $url_with_get); // this has to come before the POSTFIELDS set! - curl_setopt($ch, CURLOPT_POST, 1 ); + curl_setopt($ch, CURLOPT_POST, 1); // passing an array gets curl to use the multipart/form-data content type - curl_setopt($ch, CURLOPT_POSTFIELDS, $params); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, $useragent); - $result = curl_exec($ch); + $result = $this->curl_exec($ch); curl_close($ch); } else { - $result = $this->run_multipart_http_transaction($method, $params, $file, $server_addr); + $result = $this->run_multipart_http_transaction($method, $post, + $file, $url_with_get); } return $result; } @@ -3110,7 +3309,7 @@ function toggleDisplay(id, type) { } } - private function get_uid($uid) { + protected function get_uid($uid) { return $uid ? $uid : $this->user; } } @@ -3145,6 +3344,7 @@ class FacebookAPIErrorCodes { const API_EC_DEPRECATED = 11; const API_EC_VERSION = 12; const API_EC_INTERNAL_FQL_ERROR = 13; + const API_EC_HOST_PUP = 14; /* * PARAMETER ERRORS @@ -3179,6 +3379,7 @@ class FacebookAPIErrorCodes { const API_EC_PERMISSION = 200; const API_EC_PERMISSION_USER = 210; const API_EC_PERMISSION_NO_DEVELOPERS = 211; + const API_EC_PERMISSION_OFFLINE_ACCESS = 212; const API_EC_PERMISSION_ALBUM = 220; const API_EC_PERMISSION_PHOTO = 221; const API_EC_PERMISSION_MESSAGE = 230; @@ -3267,6 +3468,7 @@ class FacebookAPIErrorCodes { const FQL_EC_DEPRECATED_TABLE = 611; const FQL_EC_EXTENDED_PERMISSION = 612; const FQL_EC_RATE_LIMIT_EXCEEDED = 613; + const FQL_EC_UNRESOLVED_DEPENDENCY = 614; const API_EC_REF_SET_FAILED = 700; @@ -3319,6 +3521,21 @@ class FacebookAPIErrorCodes { const API_EC_LIVEMESSAGE_MESSAGE_TOO_LONG = 1102; /* + * PAYMENTS API ERRORS + */ + const API_EC_PAYMENTS_UNKNOWN = 1150; + const API_EC_PAYMENTS_APP_INVALID = 1151; + const API_EC_PAYMENTS_DATABASE = 1152; + const API_EC_PAYMENTS_PERMISSION_DENIED = 1153; + const API_EC_PAYMENTS_APP_NO_RESPONSE = 1154; + const API_EC_PAYMENTS_APP_ERROR_RESPONSE = 1155; + const API_EC_PAYMENTS_INVALID_ORDER = 1156; + const API_EC_PAYMENTS_INVALID_PARAM = 1157; + const API_EC_PAYMENTS_INVALID_OPERATION = 1158; + const API_EC_PAYMENTS_PAYMENT_FAILED = 1159; + const API_EC_PAYMENTS_DISABLED = 1160; + + /* * CONNECT SESSION ERRORS */ const API_EC_CONNECT_FEED_DISABLED = 1300; @@ -3347,6 +3564,7 @@ class FacebookAPIErrorCodes { const API_EC_COMMENTS_INVALID_XID = 1703; const API_EC_COMMENTS_INVALID_UID = 1704; const API_EC_COMMENTS_INVALID_POST = 1705; + const API_EC_COMMENTS_INVALID_REMOVE = 1706; /** * This array is no longer maintained; to view the description of an error |