Merge remote-tracking branch 'upstream/develop' into 1705-some-more-dba

This commit is contained in:
Michael 2017-05-12 16:12:00 +00:00
commit 2b180d7804
5 changed files with 93 additions and 71 deletions

View File

@ -1,8 +1,11 @@
<?php
use DDDBL\DataObjectPool;
use DDDBL\Queue;
require_once('include/datetime.php');
$objDDDBLResultHandler = new \DDDBL\DataObjectPool('Result-Handler');
$objDDDBLResultHandler = new DataObjectPool('Result-Handler');
/**
* create handler, which returns just the PDOStatement object
@ -10,11 +13,11 @@ $objDDDBLResultHandler = new \DDDBL\DataObjectPool('Result-Handler');
* big result-sets
*
**/
$cloPDOStatementResultHandler = function(\DDDBL\Queue $objQueue) {
$cloPDOStatementResultHandler = function(Queue $objQueue) {
$objPDO = $objQueue->getState()->get('PDOStatement');
$objQueue->getState()->update(array('result' => $objPDO));
# delete handler which closes the PDOStatement-cursor
# this will be done manual if using this handler
$objQueue->deleteHandler(QUEUE_CLOSE_CURSOR_POSITION);
@ -29,12 +32,12 @@ $objDDDBLResultHandler->add('PDOStatement', array('HANDLER' => $cloPDOStatementR
*
* For debugging, insert 'dbg(1);' anywhere in the program flow.
* dbg(0); will turn it off. Logging is performed at LOGGER_DATA level.
* When logging, all binary info is converted to text and html entities are escaped so that
* When logging, all binary info is converted to text and html entities are escaped so that
* the debugging stream is safe to view within both terminals and web pages.
*
*/
if (! class_exists('dba')) {
if (! class_exists('dba')) {
class dba {
private $debug = 0;
@ -45,9 +48,9 @@ class dba {
function __construct($server,$user,$pass,$db,$install = false) {
$a = get_app();
# work around, to store the database - configuration in DDDBL
$objDataObjectPool = new \DDDBL\DataObjectPool('Database-Definition');
$objDataObjectPool = new DataObjectPool('Database-Definition');
$objDataObjectPool->add('DEFAULT', array('CONNECTION' => "mysql:host=$server;dbname=$db",
'USER' => $user,
'PASS' => $pass,
@ -78,13 +81,13 @@ class dba {
}
# etablish connection to database and store PDO object
\DDDBL\connect();
$this->db = \DDDBL\getDB();
if (\DDDBL\isConnected()) {
DDDBL\connect();
$this->db = DDDBL\getDB();
if (DDDBL\isConnected()) {
$this->connected = true;
}
if (! $this->connected) {
$this->db = null;
if (! $install)
@ -102,12 +105,12 @@ class dba {
$a = get_app();
$strHandler = (true === $onlyquery) ? 'PDOStatement' : 'MULTI';
$strQueryAlias = md5($sql);
$strSQLType = strtoupper(strstr($sql, ' ', true));
$objPreparedQueryPool = new \DDDBL\DataObjectPool('Query-Definition');
$objPreparedQueryPool = new DataObjectPool('Query-Definition');
# check if query do not exists till now, if so create its definition
if (!$objPreparedQueryPool->exists($strQueryAlias))
$objPreparedQueryPool->add($strQueryAlias, array('QUERY' => $sql,
@ -121,14 +124,14 @@ class dba {
$stamp1 = microtime(true);
try {
$r = \DDDBL\get($strQueryAlias);
$r = DDDBL\get($strQueryAlias);
# bad workaround to emulate the bizzare behavior of mysql_query
if (in_array($strSQLType, array('INSERT', 'UPDATE', 'DELETE', 'CREATE', 'DROP', 'SET')))
$result = true;
$intErrorCode = false;
} catch (\Exception $objException) {
} catch (Exception $objException) {
$result = false;
$intErrorCode = $objPreparedQueryPool->get($strQueryAlias)->get('PDOStatement')->errorCode();
}
@ -166,7 +169,7 @@ class dba {
$mesg = 'true';
else {
# this needs fixing, but is a bug itself
#$mesg = mysql_num_rows($result) . ' results' . EOL;
#$mesg = mysql_num_rows($result) . ' results' . EOL;
}
$str = 'SQL = ' . printable($sql) . EOL . 'SQL returned ' . $mesg
@ -190,13 +193,13 @@ class dba {
if (isset($result) AND (($result === true) || ($result === false)))
return $result;
if ($onlyquery) {
$this->result = $r; # this will store an PDOStatement Object in result
$this->result->execute(); # execute the Statement, to get its result
return true;
}
//$a->save_timestamp($stamp1, "database");
if ($this->debug)
@ -212,7 +215,7 @@ class dba {
return $this->result->fetch();
}
public function qclose() {
if ($this->result)
return $this->result->closeCursor();
@ -228,13 +231,13 @@ class dba {
# this workaround is needed, because quote creates "'" and the beginning and the end
# of the string, which is correct. but until now the queries set this delimiter manually,
# so we must remove them from here and wait until everything uses prepared statements
return mb_substr($strQuoted, 1, mb_strlen($strQuoted) - 2);
return mb_substr($strQuoted, 1, mb_strlen($strQuoted) - 2);
}
}
function __destruct() {
if ($this->db)
\DDDBL\disconnect();
if ($this->db)
DDDBL\disconnect();
}
}}
@ -248,14 +251,14 @@ function printable($s) {
}}
// Procedural functions
if (! function_exists('dbg')) {
if (! function_exists('dbg')) {
function dbg($state) {
global $db;
if ($db)
$db->dbg($state);
}}
if (! function_exists('dbesc')) {
if (! function_exists('dbesc')) {
function dbesc($str) {
global $db;
if ($db && $db->connected)
@ -271,7 +274,7 @@ function dbesc($str) {
// Example: $r = q("SELECT * FROM `%s` WHERE `uid` = %d",
// 'user', 1);
if (! function_exists('q')) {
if (! function_exists('q')) {
function q($sql) {
global $db;
@ -288,12 +291,12 @@ function q($sql) {
/**
*
* This will happen occasionally trying to store the
* session data after abnormal program termination
* This will happen occasionally trying to store the
* session data after abnormal program termination
*
*/
logger('dba: no database: ' . print_r($args,true));
return false;
return false;
}}
@ -303,7 +306,7 @@ function q($sql) {
*
*/
if (! function_exists('dbq')) {
if (! function_exists('dbq')) {
function dbq($sql) {
global $db;
@ -315,10 +318,10 @@ function dbq($sql) {
}}
// Caller is responsible for ensuring that any integer arguments to
// Caller is responsible for ensuring that any integer arguments to
// dbesc_array are actually integers and not malformed strings containing
// SQL injection vectors. All integer array elements should be specifically
// cast to int to avoid trouble.
// SQL injection vectors. All integer array elements should be specifically
// cast to int to avoid trouble.
if (! function_exists('dbesc_array_cb')) {

View File

@ -890,9 +890,9 @@ function poco_fetch_nodeinfo($server_url) {
function poco_detect_server_type($body) {
$server = false;
$doc = new \DOMDocument();
$doc = new DOMDocument();
@$doc->loadHTML($body);
$xpath = new \DomXPath($doc);
$xpath = new DomXPath($doc);
$list = $xpath->query("//meta[@name]");

View File

@ -5,6 +5,13 @@ namespace Friendica;
use Friendica\Core\Config;
use Friendica\Core\PConfig;
use Cache;
use dbm;
use Detection\MobileDetect;
use Exception;
/**
*
* class: App
@ -192,7 +199,7 @@ class App {
}
if (! static::directory_usable($basepath, false)) {
throw new \Exception('Basepath ' . $basepath . ' isn\'t usable.');
throw new Exception('Basepath ' . $basepath . ' isn\'t usable.');
}
$this->basepath = rtrim($basepath, DIRECTORY_SEPARATOR);
@ -276,7 +283,7 @@ class App {
$this->pager['total'] = 0;
// Detect mobile devices
$mobile_detect = new \Mobile_Detect();
$mobile_detect = new MobileDetect();
$this->is_mobile = $mobile_detect->isMobile();
$this->is_tablet = $mobile_detect->isTablet();
@ -687,7 +694,7 @@ class App {
q('START TRANSACTION');
$r = q('SELECT `pid` FROM `process` WHERE `pid` = %d', intval(getmypid()));
if (!\dbm::is_result($r)) {
if (!dbm::is_result($r)) {
q("INSERT INTO `process` (`pid`,`command`,`created`) VALUES (%d, '%s', '%s')", intval(getmypid()), dbesc($command), dbesc(datetime_convert()));
}
q('COMMIT');
@ -700,7 +707,7 @@ class App {
q('START TRANSACTION');
$r = q('SELECT `pid` FROM `process`');
if (\dbm::is_result($r)) {
if (dbm::is_result($r)) {
foreach ($r AS $process) {
if (!posix_kill($process['pid'], 0)) {
q('DELETE FROM `process` WHERE `pid` = %d', intval($process['pid']));
@ -805,7 +812,7 @@ class App {
}
}
$processlist = \dbm::processlist();
$processlist = dbm::processlist();
if ($processlist['list'] != '') {
logger('Processcheck: Processes: ' . $processlist['amount'] . ' - Processlist: ' . $processlist['list'], LOGGER_DEBUG);
@ -896,14 +903,14 @@ class App {
// If the last worker fork was less than 10 seconds before then don't fork another one.
// This should prevent the forking of masses of workers.
$cachekey = 'app:proc_run:started';
$result = \Cache::get($cachekey);
$result = Cache::get($cachekey);
if (!is_null($result) AND ( time() - $result) < 10) {
return;
}
// Set the timestamp of the last proc_run
\Cache::set($cachekey, time(), CACHE_MINUTE);
Cache::set($cachekey, time(), CACHE_MINUTE);
array_unshift($args, ((x($this->config, 'php_path')) && (strlen($this->config['php_path'])) ? $this->config['php_path'] : 'php'));

View File

@ -11,6 +11,13 @@ namespace Friendica\Network;
use Friendica\App;
use Friendica\Core\Config;
use dbm;
use Cache;
use xml;
use DomXPath;
use DOMDocument;
require_once 'include/feed.php';
require_once 'include/email.php';
require_once 'include/network.php';
@ -92,7 +99,7 @@ class Probe {
return false;
}
$links = \xml::element_to_array($xrd);
$links = xml::element_to_array($xrd);
if (!isset($links["xrd"]["link"])) {
return false;
}
@ -275,7 +282,7 @@ class Probe {
public static function uri($uri, $network = "", $uid = 0, $cache = true) {
if ($cache) {
$result = \Cache::get("probe_url:".$network.":".$uri);
$result = Cache::get("probe_url:".$network.":".$uri);
if (!is_null($result)) {
return $result;
}
@ -327,7 +334,7 @@ class Probe {
// Only store into the cache if the value seems to be valid
if (!in_array($data['network'], array(NETWORK_PHANTOM, NETWORK_MAIL))) {
\Cache::set("probe_url:".$network.":".$uri, $data, CACHE_DAY);
Cache::set("probe_url:".$network.":".$uri, $data, CACHE_DAY);
/// @todo temporary fix - we need a real contact update function that updates only changing fields
/// The biggest problem is the avatar picture that could have a reduced image size.
@ -543,7 +550,7 @@ class Probe {
return $webfinger;
}
$xrd_arr = \xml::element_to_array($xrd);
$xrd_arr = xml::element_to_array($xrd);
if (!isset($xrd_arr["xrd"]["link"])) {
return false;
}
@ -811,12 +818,12 @@ class Probe {
return false;
}
$doc = new \DOMDocument();
$doc = new DOMDocument();
if (!@$doc->loadHTML($content)) {
return false;
}
$xpath = new \DomXPath($doc);
$xpath = new DomXPath($doc);
$vcards = $xpath->query("//div[contains(concat(' ', @class, ' '), ' vcard ')]");
if (!is_object($vcards)) {
@ -1099,12 +1106,12 @@ class Probe {
*/
private function pumpioProfileData($profile_link) {
$doc = new \DOMDocument();
$doc = new DOMDocument();
if (!@$doc->loadHTMLFile($profile_link)) {
return false;
}
$xpath = new \DomXPath($doc);
$xpath = new DomXPath($doc);
$data = array();
@ -1186,13 +1193,13 @@ class Probe {
* @return string feed link
*/
private function getFeedLink($url) {
$doc = new \DOMDocument();
$doc = new DOMDocument();
if (!@$doc->loadHTMLFile($url)) {
return false;
}
$xpath = new \DomXPath($doc);
$xpath = new DomXPath($doc);
//$feeds = $xpath->query("/html/head/link[@type='application/rss+xml']");
$feeds = $xpath->query("/html/head/link[@type='application/rss+xml' and @rel='alternate']");
@ -1298,7 +1305,7 @@ class Probe {
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval($uid));
if (\dbm::is_result($x) && \dbm::is_result($r)) {
if (dbm::is_result($x) && dbm::is_result($r)) {
$mailbox = construct_mailbox_name($r[0]);
$password = '';
openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']);

View File

@ -9,6 +9,11 @@ namespace Friendica;
use Friendica\Core\Config;
use xml;
use DomXPath;
use DOMDocument;
require_once("include/network.php");
require_once("include/Photo.php");
require_once("include/oembed.php");
@ -223,22 +228,22 @@ class ParseUrl {
$body = mb_convert_encoding($body, 'HTML-ENTITIES', "UTF-8");
$doc = new \DOMDocument();
$doc = new DOMDocument();
@$doc->loadHTML($body);
\xml::deleteNode($doc, "style");
\xml::deleteNode($doc, "script");
\xml::deleteNode($doc, "option");
\xml::deleteNode($doc, "h1");
\xml::deleteNode($doc, "h2");
\xml::deleteNode($doc, "h3");
\xml::deleteNode($doc, "h4");
\xml::deleteNode($doc, "h5");
\xml::deleteNode($doc, "h6");
\xml::deleteNode($doc, "ol");
\xml::deleteNode($doc, "ul");
xml::deleteNode($doc, "style");
xml::deleteNode($doc, "script");
xml::deleteNode($doc, "option");
xml::deleteNode($doc, "h1");
xml::deleteNode($doc, "h2");
xml::deleteNode($doc, "h3");
xml::deleteNode($doc, "h4");
xml::deleteNode($doc, "h5");
xml::deleteNode($doc, "h6");
xml::deleteNode($doc, "ol");
xml::deleteNode($doc, "ul");
$xpath = new \DomXPath($doc);
$xpath = new DomXPath($doc);
$list = $xpath->query("//meta[@content]");
foreach ($list as $node) {