Replace existing autoloader with Composer-supplied
- Move Friendica namespace to `src` - Move required `ezyang/htmlpurifier` to vendor - Remove existing static autoloader - Change boot.php reference to the autoloader
This commit is contained in:
parent
cae0543629
commit
799e60aa62
419 changed files with 618 additions and 542 deletions
|
@ -1,216 +0,0 @@
|
|||
<?php
|
||||
namespace Friendica\Core;
|
||||
|
||||
use dbm;
|
||||
|
||||
/**
|
||||
* @file include/Core/Config.php
|
||||
*
|
||||
* @brief Contains the class with methods for system configuration
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Arbitrary sytem configuration storage
|
||||
* Note:
|
||||
* Please do not store booleans - convert to 0/1 integer values
|
||||
* The Config::get() functions return boolean false for keys that are unset,
|
||||
* and this could lead to subtle bugs.
|
||||
*
|
||||
* There are a few places in the code (such as the admin panel) where boolean
|
||||
* configurations need to be fixed as of 10/08/2011.
|
||||
*/
|
||||
class Config {
|
||||
|
||||
private static $cache;
|
||||
private static $in_db;
|
||||
|
||||
/**
|
||||
* @brief Loads all configuration values of family into a cached storage.
|
||||
*
|
||||
* All configuration values of the system are stored in global cache
|
||||
* which is available under the global variable $a->config
|
||||
*
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @return void
|
||||
*/
|
||||
public static function load($family = "config") {
|
||||
|
||||
// We don't preload "system" anymore.
|
||||
// This reduces the number of database reads a lot.
|
||||
if ($family === 'system') {
|
||||
return;
|
||||
}
|
||||
|
||||
$a = get_app();
|
||||
|
||||
$r = q("SELECT `v`, `k` FROM `config` WHERE `cat` = '%s'", dbesc($family));
|
||||
if (dbm::is_result($r)) {
|
||||
foreach ($r as $rr) {
|
||||
$k = $rr['k'];
|
||||
if ($family === 'config') {
|
||||
$a->config[$k] = $rr['v'];
|
||||
} else {
|
||||
$a->config[$family][$k] = $rr['v'];
|
||||
self::$cache[$family][$k] = $rr['v'];
|
||||
self::$in_db[$family][$k] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a particular user's config variable given the category name
|
||||
* ($family) and a key.
|
||||
*
|
||||
* Get a particular config value from the given category ($family)
|
||||
* and the $key from a cached storage in $a->config[$uid].
|
||||
* $instore is only used by the set_config function
|
||||
* to determine if the key already exists in the DB
|
||||
* If a key is found in the DB but doesn't exist in
|
||||
* local config cache, pull it into the cache so we don't have
|
||||
* to hit the DB again for this item.
|
||||
*
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to query
|
||||
* @param mixed $default_value optional
|
||||
* The value to return if key is not set (default: null)
|
||||
* @param boolean $refresh optional
|
||||
* If true the config is loaded from the db and not from the cache (default: false)
|
||||
* @return mixed Stored value or null if it does not exist
|
||||
*/
|
||||
public static function get($family, $key, $default_value = null, $refresh = false) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
if (!$refresh) {
|
||||
|
||||
// Do we have the cached value? Then return it
|
||||
if (isset(self::$cache[$family][$key])) {
|
||||
if (self::$cache[$family][$key] === '!<unset>!') {
|
||||
return $default_value;
|
||||
} else {
|
||||
return self::$cache[$family][$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ret = q("SELECT `v` FROM `config` WHERE `cat` = '%s' AND `k` = '%s'",
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
if (dbm::is_result($ret)) {
|
||||
// manage array value
|
||||
$val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret[0]['v']) ? unserialize($ret[0]['v']) : $ret[0]['v']);
|
||||
|
||||
// Assign the value from the database to the cache
|
||||
self::$cache[$family][$key] = $val;
|
||||
self::$in_db[$family][$key] = true;
|
||||
return $val;
|
||||
} elseif (isset($a->config[$family][$key])) {
|
||||
|
||||
// Assign the value (mostly) from the .htconfig.php to the cache
|
||||
self::$cache[$family][$key] = $a->config[$family][$key];
|
||||
self::$in_db[$family][$key] = false;
|
||||
|
||||
return $a->config[$family][$key];
|
||||
}
|
||||
|
||||
self::$cache[$family][$key] = '!<unset>!';
|
||||
self::$in_db[$family][$key] = false;
|
||||
|
||||
return $default_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets a configuration value for system config
|
||||
*
|
||||
* Stores a config value ($value) in the category ($family) under the key ($key)
|
||||
* for the user_id $uid.
|
||||
*
|
||||
* Note: Please do not store booleans - convert to 0/1 integer values!
|
||||
*
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to set
|
||||
* @param string $value
|
||||
* The value to store
|
||||
* @return mixed Stored $value or false if the database update failed
|
||||
*/
|
||||
public static function set($family, $key, $value) {
|
||||
$a = get_app();
|
||||
|
||||
// We store our setting values in a string variable.
|
||||
// So we have to do the conversion here so that the compare below works.
|
||||
// The exception are array values.
|
||||
$dbvalue = (!is_array($value) ? (string)$value : $value);
|
||||
|
||||
$stored = self::get($family, $key, null, true);
|
||||
|
||||
if (($stored === $dbvalue) AND self::$in_db[$family][$key]) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($family === 'config') {
|
||||
$a->config[$key] = $dbvalue;
|
||||
} elseif ($family != 'system') {
|
||||
$a->config[$family][$key] = $dbvalue;
|
||||
}
|
||||
|
||||
// Assign the just added value to the cache
|
||||
self::$cache[$family][$key] = $dbvalue;
|
||||
|
||||
// manage array value
|
||||
$dbvalue = (is_array($value) ? serialize($value) : $dbvalue);
|
||||
|
||||
if (is_null($stored) OR !self::$in_db[$family][$key]) {
|
||||
$ret = q("INSERT INTO `config` (`cat`, `k`, `v`) VALUES ('%s', '%s', '%s') ON DUPLICATE KEY UPDATE `v` = '%s'",
|
||||
dbesc($family),
|
||||
dbesc($key),
|
||||
dbesc($dbvalue),
|
||||
dbesc($dbvalue)
|
||||
);
|
||||
} else {
|
||||
$ret = q("UPDATE `config` SET `v` = '%s' WHERE `cat` = '%s' AND `k` = '%s'",
|
||||
dbesc($dbvalue),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
}
|
||||
if ($ret) {
|
||||
self::$in_db[$family][$key] = true;
|
||||
return $value;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deletes the given key from the system configuration.
|
||||
*
|
||||
* Removes the configured value from the stored cache in $a->config
|
||||
* and removes it from the database.
|
||||
*
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to delete
|
||||
* @return mixed
|
||||
*/
|
||||
public static function delete($family, $key) {
|
||||
|
||||
if (isset(self::$cache[$family][$key])) {
|
||||
unset(self::$cache[$family][$key]);
|
||||
unset(self::$in_db[$family][$key]);
|
||||
}
|
||||
$ret = q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s'",
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
|
@ -1,204 +0,0 @@
|
|||
<?php
|
||||
namespace Friendica\Core;
|
||||
|
||||
use dbm;
|
||||
|
||||
/**
|
||||
* @file include/Core/PConfig.php
|
||||
* @brief contains the class with methods for the management
|
||||
* of the user configuration
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Management of user configuration storage
|
||||
* Note:
|
||||
* Please do not store booleans - convert to 0/1 integer values
|
||||
* The PConfig::get() functions return boolean false for keys that are unset,
|
||||
* and this could lead to subtle bugs.
|
||||
*/
|
||||
class PConfig {
|
||||
|
||||
private static $in_db;
|
||||
|
||||
/**
|
||||
* @brief Loads all configuration values of a user's config family into a cached storage.
|
||||
*
|
||||
* All configuration values of the given user are stored in global cache
|
||||
* which is available under the global variable $a->config[$uid].
|
||||
*
|
||||
* @param string $uid
|
||||
* The user_id
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @return void
|
||||
*/
|
||||
public static function load($uid, $family) {
|
||||
$a = get_app();
|
||||
$r = q("SELECT `v`,`k` FROM `pconfig` WHERE `cat` = '%s' AND `uid` = %d ORDER BY `cat`, `k`, `id`",
|
||||
dbesc($family),
|
||||
intval($uid)
|
||||
);
|
||||
if (dbm::is_result($r)) {
|
||||
foreach ($r as $rr) {
|
||||
$k = $rr['k'];
|
||||
$a->config[$uid][$family][$k] = $rr['v'];
|
||||
self::$in_db[$uid][$family][$k] = true;
|
||||
}
|
||||
} else if ($family != 'config') {
|
||||
// Negative caching
|
||||
$a->config[$uid][$family] = "!<unset>!";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a particular user's config variable given the category name
|
||||
* ($family) and a key.
|
||||
*
|
||||
* Get a particular user's config value from the given category ($family)
|
||||
* and the $key from a cached storage in $a->config[$uid].
|
||||
*
|
||||
* @param string $uid
|
||||
* The user_id
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to query
|
||||
* @param mixed $default_value optional
|
||||
* The value to return if key is not set (default: null)
|
||||
* @param boolean $refresh optional
|
||||
* If true the config is loaded from the db and not from the cache (default: false)
|
||||
* @return mixed Stored value or null if it does not exist
|
||||
*/
|
||||
public static function get($uid, $family, $key, $default_value = null, $refresh = false) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
if (!$refresh) {
|
||||
// Looking if the whole family isn't set
|
||||
if (isset($a->config[$uid][$family])) {
|
||||
if ($a->config[$uid][$family] === '!<unset>!') {
|
||||
return $default_value;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($a->config[$uid][$family][$key])) {
|
||||
if ($a->config[$uid][$family][$key] === '!<unset>!') {
|
||||
return $default_value;
|
||||
}
|
||||
return $a->config[$uid][$family][$key];
|
||||
}
|
||||
}
|
||||
|
||||
$ret = q("SELECT `v` FROM `pconfig` WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s' ORDER BY `id` DESC LIMIT 1",
|
||||
intval($uid),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
if (count($ret)) {
|
||||
$val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret[0]['v'])?unserialize( $ret[0]['v']):$ret[0]['v']);
|
||||
$a->config[$uid][$family][$key] = $val;
|
||||
self::$in_db[$uid][$family][$key] = true;
|
||||
|
||||
return $val;
|
||||
} else {
|
||||
$a->config[$uid][$family][$key] = '!<unset>!';
|
||||
self::$in_db[$uid][$family][$key] = false;
|
||||
|
||||
return $default_value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets a configuration value for a user
|
||||
*
|
||||
* Stores a config value ($value) in the category ($family) under the key ($key)
|
||||
* for the user_id $uid.
|
||||
*
|
||||
* @note Please do not store booleans - convert to 0/1 integer values!
|
||||
*
|
||||
* @param string $uid
|
||||
* The user_id
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to set
|
||||
* @param string $value
|
||||
* The value to store
|
||||
* @return mixed Stored $value or false
|
||||
*/
|
||||
public static function set($uid, $family, $key, $value) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
// We store our setting values in a string variable.
|
||||
// So we have to do the conversion here so that the compare below works.
|
||||
// The exception are array values.
|
||||
$dbvalue = (!is_array($value) ? (string)$value : $value);
|
||||
|
||||
$stored = self::get($uid, $family, $key, null, true);
|
||||
|
||||
if (($stored === $dbvalue) AND self::$in_db[$uid][$family][$key]) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$a->config[$uid][$family][$key] = $dbvalue;
|
||||
|
||||
// manage array value
|
||||
$dbvalue = (is_array($value) ? serialize($value) : $dbvalue);
|
||||
|
||||
if (is_null($stored) OR !self::$in_db[$uid][$family][$key]) {
|
||||
$ret = q("INSERT INTO `pconfig` (`uid`, `cat`, `k`, `v`) VALUES (%d, '%s', '%s', '%s') ON DUPLICATE KEY UPDATE `v` = '%s'",
|
||||
intval($uid),
|
||||
dbesc($family),
|
||||
dbesc($key),
|
||||
dbesc($dbvalue),
|
||||
dbesc($dbvalue)
|
||||
);
|
||||
} else {
|
||||
$ret = q("UPDATE `pconfig` SET `v` = '%s' WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s'",
|
||||
dbesc($dbvalue),
|
||||
intval($uid),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
}
|
||||
|
||||
if ($ret) {
|
||||
self::$in_db[$uid][$family][$key] = true;
|
||||
return $value;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deletes the given key from the users's configuration.
|
||||
*
|
||||
* Removes the configured value from the stored cache in $a->config[$uid]
|
||||
* and removes it from the database.
|
||||
*
|
||||
* @param string $uid The user_id
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to delete
|
||||
* @return mixed
|
||||
*/
|
||||
public static function delete($uid,$family,$key) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
if (x($a->config[$uid][$family], $key)) {
|
||||
unset($a->config[$uid][$family][$key]);
|
||||
unset(self::$in_db[$uid][$family][$key]);
|
||||
}
|
||||
|
||||
$ret = q("DELETE FROM `pconfig` WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s'",
|
||||
intval($uid),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
|
@ -1,532 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file include/ParseUrl.php
|
||||
* @brief Get informations about a given URL
|
||||
*/
|
||||
|
||||
namespace Friendica;
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("include/network.php");
|
||||
require_once("include/Photo.php");
|
||||
require_once("include/oembed.php");
|
||||
require_once("include/xml.php");
|
||||
|
||||
/**
|
||||
* @brief Class with methods for extracting certain content from an url
|
||||
*/
|
||||
class ParseUrl {
|
||||
|
||||
/**
|
||||
* @brief Search for chached embeddable data of an url otherwise fetch it
|
||||
*
|
||||
* @param type $url The url of the page which should be scraped
|
||||
* @param type $no_guessing If true the parse doens't search for
|
||||
* preview pictures
|
||||
* @param type $do_oembed The false option is used by the function fetch_oembed()
|
||||
* to avoid endless loops
|
||||
*
|
||||
* @return array which contains needed data for embedding
|
||||
* string 'url' => The url of the parsed page
|
||||
* string 'type' => Content type
|
||||
* string 'title' => The title of the content
|
||||
* string 'text' => The description for the content
|
||||
* string 'image' => A preview image of the content (only available
|
||||
* if $no_geuessing = false
|
||||
* array'images' = Array of preview pictures
|
||||
* string 'keywords' => The tags which belong to the content
|
||||
*
|
||||
* @see ParseUrl::getSiteinfo() for more information about scraping
|
||||
* embeddable content
|
||||
*/
|
||||
public static function getSiteinfoCached($url, $no_guessing = false, $do_oembed = true) {
|
||||
|
||||
if ($url == "") {
|
||||
return false;
|
||||
}
|
||||
|
||||
$r = q("SELECT * FROM `parsed_url` WHERE `url` = '%s' AND `guessing` = %d AND `oembed` = %d",
|
||||
dbesc(normalise_link($url)), intval(!$no_guessing), intval($do_oembed));
|
||||
|
||||
if ($r) {
|
||||
$data = $r[0]["content"];
|
||||
}
|
||||
|
||||
if (!is_null($data)) {
|
||||
$data = unserialize($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
$data = self::getSiteinfo($url, $no_guessing, $do_oembed);
|
||||
|
||||
q("INSERT INTO `parsed_url` (`url`, `guessing`, `oembed`, `content`, `created`) VALUES ('%s', %d, %d, '%s', '%s')
|
||||
ON DUPLICATE KEY UPDATE `content` = '%s', `created` = '%s'",
|
||||
dbesc(normalise_link($url)), intval(!$no_guessing), intval($do_oembed),
|
||||
dbesc(serialize($data)), dbesc(datetime_convert()),
|
||||
dbesc(serialize($data)), dbesc(datetime_convert()));
|
||||
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* @brief Parse a page for embeddable content information
|
||||
*
|
||||
* This method parses to url for meta data which can be used to embed
|
||||
* the content. If available it prioritizes Open Graph meta tags.
|
||||
* If this is not available it uses the twitter cards meta tags.
|
||||
* As fallback it uses standard html elements with meta informations
|
||||
* like \<title\>Awesome Title\</title\> or
|
||||
* \<meta name="description" content="An awesome description"\>
|
||||
*
|
||||
* @param type $url The url of the page which should be scraped
|
||||
* @param type $no_guessing If true the parse doens't search for
|
||||
* preview pictures
|
||||
* @param type $do_oembed The false option is used by the function fetch_oembed()
|
||||
* to avoid endless loops
|
||||
* @param type $count Internal counter to avoid endless loops
|
||||
*
|
||||
* @return array which contains needed data for embedding
|
||||
* string 'url' => The url of the parsed page
|
||||
* string 'type' => Content type
|
||||
* string 'title' => The title of the content
|
||||
* string 'text' => The description for the content
|
||||
* string 'image' => A preview image of the content (only available
|
||||
* if $no_geuessing = false
|
||||
* array'images' = Array of preview pictures
|
||||
* string 'keywords' => The tags which belong to the content
|
||||
*
|
||||
* @todo https://developers.google.com/+/plugins/snippet/
|
||||
* @verbatim
|
||||
* <meta itemprop="name" content="Awesome title">
|
||||
* <meta itemprop="description" content="An awesome description">
|
||||
* <meta itemprop="image" content="http://maple.libertreeproject.org/images/tree-icon.png">
|
||||
*
|
||||
* <body itemscope itemtype="http://schema.org/Product">
|
||||
* <h1 itemprop="name">Shiny Trinket</h1>
|
||||
* <img itemprop="image" src="{image-url}" />
|
||||
* <p itemprop="description">Shiny trinkets are shiny.</p>
|
||||
* </body>
|
||||
* @endverbatim
|
||||
*/
|
||||
public static function getSiteinfo($url, $no_guessing = false, $do_oembed = true, $count = 1) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
$siteinfo = array();
|
||||
|
||||
// Check if the URL does contain a scheme
|
||||
$scheme = parse_url($url, PHP_URL_SCHEME);
|
||||
|
||||
if ($scheme == "") {
|
||||
$url = "http://".trim($url, "/");
|
||||
}
|
||||
|
||||
if ($count > 10) {
|
||||
logger("parseurl_getsiteinfo: Endless loop detected for ".$url, LOGGER_DEBUG);
|
||||
return($siteinfo);
|
||||
}
|
||||
|
||||
$url = trim($url, "'");
|
||||
$url = trim($url, '"');
|
||||
|
||||
$url = strip_tracking_query_params($url);
|
||||
|
||||
$siteinfo["url"] = $url;
|
||||
$siteinfo["type"] = "link";
|
||||
|
||||
$check_cert = Config::get("system", "verifyssl");
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent());
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false));
|
||||
if ($check_cert) {
|
||||
@curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
|
||||
}
|
||||
|
||||
$header = curl_exec($ch);
|
||||
$curl_info = @curl_getinfo($ch);
|
||||
curl_close($ch);
|
||||
|
||||
$a->save_timestamp($stamp1, "network");
|
||||
|
||||
if ((($curl_info["http_code"] == "301") || ($curl_info["http_code"] == "302") || ($curl_info["http_code"] == "303") || ($curl_info["http_code"] == "307"))
|
||||
&& (($curl_info["redirect_url"] != "") || ($curl_info["location"] != ""))) {
|
||||
if ($curl_info["redirect_url"] != "") {
|
||||
$siteinfo = self::getSiteinfo($curl_info["redirect_url"], $no_guessing, $do_oembed, ++$count);
|
||||
} else {
|
||||
$siteinfo = self::getSiteinfo($curl_info["location"], $no_guessing, $do_oembed, ++$count);
|
||||
}
|
||||
return($siteinfo);
|
||||
}
|
||||
|
||||
// If the file is too large then exit
|
||||
if ($curl_info["download_content_length"] > 1000000) {
|
||||
return($siteinfo);
|
||||
}
|
||||
|
||||
// If it isn't a HTML file then exit
|
||||
if (($curl_info["content_type"] != "") && !strstr(strtolower($curl_info["content_type"]), "html")) {
|
||||
return($siteinfo);
|
||||
}
|
||||
|
||||
if ($do_oembed) {
|
||||
|
||||
$oembed_data = oembed_fetch_url($url);
|
||||
|
||||
if (!in_array($oembed_data->type, array("error", "rich"))) {
|
||||
$siteinfo["type"] = $oembed_data->type;
|
||||
}
|
||||
|
||||
if (($oembed_data->type == "link") && ($siteinfo["type"] != "photo")) {
|
||||
if (isset($oembed_data->title)) {
|
||||
$siteinfo["title"] = $oembed_data->title;
|
||||
}
|
||||
if (isset($oembed_data->description)) {
|
||||
$siteinfo["text"] = trim($oembed_data->description);
|
||||
}
|
||||
if (isset($oembed_data->thumbnail_url)) {
|
||||
$siteinfo["image"] = $oembed_data->thumbnail_url;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch the first mentioned charset. Can be in body or header
|
||||
$charset = "";
|
||||
if (preg_match('/charset=(.*?)['."'".'"\s\n]/', $header, $matches)) {
|
||||
$charset = trim(trim(trim(array_pop($matches)), ';,'));
|
||||
}
|
||||
|
||||
if ($charset == "") {
|
||||
$charset = "utf-8";
|
||||
}
|
||||
|
||||
$pos = strpos($header, "\r\n\r\n");
|
||||
|
||||
if ($pos) {
|
||||
$body = trim(substr($header, $pos));
|
||||
} else {
|
||||
$body = $header;
|
||||
}
|
||||
|
||||
if (($charset != "") && (strtoupper($charset) != "UTF-8")) {
|
||||
logger("parseurl_getsiteinfo: detected charset ".$charset, LOGGER_DEBUG);
|
||||
//$body = mb_convert_encoding($body, "UTF-8", $charset);
|
||||
$body = iconv($charset, "UTF-8//TRANSLIT", $body);
|
||||
}
|
||||
|
||||
$body = mb_convert_encoding($body, 'HTML-ENTITIES', "UTF-8");
|
||||
|
||||
$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");
|
||||
|
||||
$xpath = new \DomXPath($doc);
|
||||
|
||||
$list = $xpath->query("//meta[@content]");
|
||||
foreach ($list as $node) {
|
||||
$attr = array();
|
||||
if ($node->attributes->length) {
|
||||
foreach ($node->attributes as $attribute) {
|
||||
$attr[$attribute->name] = $attribute->value;
|
||||
}
|
||||
}
|
||||
|
||||
if (@$attr["http-equiv"] == "refresh") {
|
||||
$path = $attr["content"];
|
||||
$pathinfo = explode(";", $path);
|
||||
$content = "";
|
||||
foreach ($pathinfo as $value) {
|
||||
if (substr(strtolower($value), 0, 4) == "url=") {
|
||||
$content = substr($value, 4);
|
||||
}
|
||||
}
|
||||
if ($content != "") {
|
||||
$siteinfo = self::getSiteinfo($content, $no_guessing, $do_oembed, ++$count);
|
||||
return($siteinfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$list = $xpath->query("//title");
|
||||
if ($list->length > 0) {
|
||||
$siteinfo["title"] = $list->item(0)->nodeValue;
|
||||
}
|
||||
|
||||
//$list = $xpath->query("head/meta[@name]");
|
||||
$list = $xpath->query("//meta[@name]");
|
||||
foreach ($list as $node) {
|
||||
$attr = array();
|
||||
if ($node->attributes->length) {
|
||||
foreach ($node->attributes as $attribute) {
|
||||
$attr[$attribute->name] = $attribute->value;
|
||||
}
|
||||
}
|
||||
|
||||
$attr["content"] = trim(html_entity_decode($attr["content"], ENT_QUOTES, "UTF-8"));
|
||||
|
||||
if ($attr["content"] != "") {
|
||||
switch (strtolower($attr["name"])) {
|
||||
case "fulltitle":
|
||||
$siteinfo["title"] = $attr["content"];
|
||||
break;
|
||||
case "description":
|
||||
$siteinfo["text"] = $attr["content"];
|
||||
break;
|
||||
case "thumbnail":
|
||||
$siteinfo["image"] = $attr["content"];
|
||||
break;
|
||||
case "twitter:image":
|
||||
$siteinfo["image"] = $attr["content"];
|
||||
break;
|
||||
case "twitter:image:src":
|
||||
$siteinfo["image"] = $attr["content"];
|
||||
break;
|
||||
case "twitter:card":
|
||||
if (($siteinfo["type"] == "") || ($attr["content"] == "photo")) {
|
||||
$siteinfo["type"] = $attr["content"];
|
||||
}
|
||||
break;
|
||||
case "twitter:description":
|
||||
$siteinfo["text"] = $attr["content"];
|
||||
break;
|
||||
case "twitter:title":
|
||||
$siteinfo["title"] = $attr["content"];
|
||||
break;
|
||||
case "dc.title":
|
||||
$siteinfo["title"] = $attr["content"];
|
||||
break;
|
||||
case "dc.description":
|
||||
$siteinfo["text"] = $attr["content"];
|
||||
break;
|
||||
case "keywords":
|
||||
$keywords = explode(",", $attr["content"]);
|
||||
break;
|
||||
case "news_keywords":
|
||||
$keywords = explode(",", $attr["content"]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($siteinfo["type"] == "summary") {
|
||||
$siteinfo["type"] = "link";
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($keywords)) {
|
||||
$siteinfo["keywords"] = array();
|
||||
foreach ($keywords as $keyword) {
|
||||
if (!in_array(trim($keyword), $siteinfo["keywords"])) {
|
||||
$siteinfo["keywords"][] = trim($keyword);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//$list = $xpath->query("head/meta[@property]");
|
||||
$list = $xpath->query("//meta[@property]");
|
||||
foreach ($list as $node) {
|
||||
$attr = array();
|
||||
if ($node->attributes->length) {
|
||||
foreach ($node->attributes as $attribute) {
|
||||
$attr[$attribute->name] = $attribute->value;
|
||||
}
|
||||
}
|
||||
|
||||
$attr["content"] = trim(html_entity_decode($attr["content"], ENT_QUOTES, "UTF-8"));
|
||||
|
||||
if ($attr["content"] != "") {
|
||||
switch (strtolower($attr["property"])) {
|
||||
case "og:image":
|
||||
$siteinfo["image"] = $attr["content"];
|
||||
break;
|
||||
case "og:title":
|
||||
$siteinfo["title"] = $attr["content"];
|
||||
break;
|
||||
case "og:description":
|
||||
$siteinfo["text"] = $attr["content"];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((@$siteinfo["image"] == "") && !$no_guessing) {
|
||||
$list = $xpath->query("//img[@src]");
|
||||
foreach ($list as $node) {
|
||||
$attr = array();
|
||||
if ($node->attributes->length) {
|
||||
foreach ($node->attributes as $attribute) {
|
||||
$attr[$attribute->name] = $attribute->value;
|
||||
}
|
||||
}
|
||||
|
||||
$src = self::completeUrl($attr["src"], $url);
|
||||
$photodata = get_photo_info($src);
|
||||
|
||||
if (($photodata) && ($photodata[0] > 150) && ($photodata[1] > 150)) {
|
||||
if ($photodata[0] > 300) {
|
||||
$photodata[1] = round($photodata[1] * (300 / $photodata[0]));
|
||||
$photodata[0] = 300;
|
||||
}
|
||||
if ($photodata[1] > 300) {
|
||||
$photodata[0] = round($photodata[0] * (300 / $photodata[1]));
|
||||
$photodata[1] = 300;
|
||||
}
|
||||
$siteinfo["images"][] = array("src" => $src,
|
||||
"width" => $photodata[0],
|
||||
"height" => $photodata[1]);
|
||||
}
|
||||
|
||||
}
|
||||
} elseif ($siteinfo["image"] != "") {
|
||||
$src = self::completeUrl($siteinfo["image"], $url);
|
||||
|
||||
unset($siteinfo["image"]);
|
||||
|
||||
$photodata = get_photo_info($src);
|
||||
|
||||
if (($photodata) && ($photodata[0] > 10) && ($photodata[1] > 10)) {
|
||||
$siteinfo["images"][] = array("src" => $src,
|
||||
"width" => $photodata[0],
|
||||
"height" => $photodata[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if ((@$siteinfo["text"] == "") && (@$siteinfo["title"] != "") && !$no_guessing) {
|
||||
$text = "";
|
||||
|
||||
$list = $xpath->query("//div[@class='article']");
|
||||
foreach ($list as $node) {
|
||||
if (strlen($node->nodeValue) > 40) {
|
||||
$text .= " ".trim($node->nodeValue);
|
||||
}
|
||||
}
|
||||
|
||||
if ($text == "") {
|
||||
$list = $xpath->query("//div[@class='content']");
|
||||
foreach ($list as $node) {
|
||||
if (strlen($node->nodeValue) > 40) {
|
||||
$text .= " ".trim($node->nodeValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If none text was found then take the paragraph content
|
||||
if ($text == "") {
|
||||
$list = $xpath->query("//p");
|
||||
foreach ($list as $node) {
|
||||
if (strlen($node->nodeValue) > 40) {
|
||||
$text .= " ".trim($node->nodeValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($text != "") {
|
||||
$text = trim(str_replace(array("\n", "\r"), array(" ", " "), $text));
|
||||
|
||||
while (strpos($text, " ")) {
|
||||
$text = trim(str_replace(" ", " ", $text));
|
||||
}
|
||||
|
||||
$siteinfo["text"] = trim(html_entity_decode(substr($text, 0, 350), ENT_QUOTES, "UTF-8").'...');
|
||||
}
|
||||
}
|
||||
|
||||
logger("parseurl_getsiteinfo: Siteinfo for ".$url." ".print_r($siteinfo, true), LOGGER_DEBUG);
|
||||
|
||||
call_hooks("getsiteinfo", $siteinfo);
|
||||
|
||||
return($siteinfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert tags from CSV to an array
|
||||
*
|
||||
* @param string $string Tags
|
||||
* @return array with formatted Hashtags
|
||||
*/
|
||||
public static function convertTagsToArray($string) {
|
||||
$arr_tags = str_getcsv($string);
|
||||
if (count($arr_tags)) {
|
||||
// add the # sign to every tag
|
||||
array_walk($arr_tags, array("self", "arrAddHashes"));
|
||||
|
||||
return $arr_tags;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Add a hasht sign to a string
|
||||
*
|
||||
* This method is used as callback function
|
||||
*
|
||||
* @param string $tag The pure tag name
|
||||
* @param int $k Counter for internal use
|
||||
*/
|
||||
private static function arrAddHashes(&$tag, $k) {
|
||||
$tag = "#" . $tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Add a scheme to an url
|
||||
*
|
||||
* The src attribute of some html elements (e.g. images)
|
||||
* can miss the scheme so we need to add the correct
|
||||
* scheme
|
||||
*
|
||||
* @param string $url The url which possibly does have
|
||||
* a missing scheme (a link to an image)
|
||||
* @param string $scheme The url with a correct scheme
|
||||
* (e.g. the url from the webpage which does contain the image)
|
||||
*
|
||||
* @return string The url with a scheme
|
||||
*/
|
||||
private static function completeUrl($url, $scheme) {
|
||||
$urlarr = parse_url($url);
|
||||
|
||||
// If the url does allready have an scheme
|
||||
// we can stop the process here
|
||||
if (isset($urlarr["scheme"])) {
|
||||
return($url);
|
||||
}
|
||||
|
||||
$schemearr = parse_url($scheme);
|
||||
|
||||
$complete = $schemearr["scheme"]."://".$schemearr["host"];
|
||||
|
||||
if (@$schemearr["port"] != "") {
|
||||
$complete .= ":".$schemearr["port"];
|
||||
}
|
||||
|
||||
if (strpos($urlarr["path"],"/") !== 0) {
|
||||
$complete .= "/";
|
||||
}
|
||||
|
||||
$complete .= $urlarr["path"];
|
||||
|
||||
if (@$urlarr["query"] != "") {
|
||||
$complete .= "?".$urlarr["query"];
|
||||
}
|
||||
|
||||
if (@$urlarr["fragment"] != "") {
|
||||
$complete .= "#".$urlarr["fragment"];
|
||||
}
|
||||
|
||||
return($complete);
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @file include/autoloader.php
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief composer-derived autoloader init
|
||||
**/
|
||||
class FriendicaAutoloaderInit
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
public static function loadClassLoader($class)
|
||||
{
|
||||
if ('Composer\Autoload\ClassLoader' === $class) {
|
||||
require __DIR__ . '/autoloader/ClassLoader.php';
|
||||
}
|
||||
}
|
||||
|
||||
public static function getLoader()
|
||||
{
|
||||
if (null !== self::$loader) {
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('FriendicaAutoloaderInit', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
||||
spl_autoload_unregister(array('FriendicaAutoloaderInit', 'loadClassLoader'));
|
||||
|
||||
// library
|
||||
$map = require __DIR__ . '/autoloader/autoload_namespaces.php';
|
||||
foreach ($map as $namespace => $path) {
|
||||
$loader->set($namespace, $path);
|
||||
}
|
||||
|
||||
$map = require __DIR__ . '/autoloader/autoload_psr4.php';
|
||||
foreach ($map as $namespace => $path) {
|
||||
$loader->setPsr4($namespace, $path);
|
||||
}
|
||||
|
||||
$classMap = require __DIR__ . '/autoloader/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
$loader->addClassMap($classMap);
|
||||
}
|
||||
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = require __DIR__ . '/autoloader/autoload_files.php';
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
friendicaRequire($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function friendicaRequire($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return FriendicaAutoloaderInit::getLoader();
|
|
@ -1,413 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
* Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE.composer
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
/**
|
||||
* ClassLoader implements a PSR-0 class loader
|
||||
*
|
||||
* See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
|
||||
*
|
||||
* $loader = new \Composer\Autoload\ClassLoader();
|
||||
*
|
||||
* // register classes with namespaces
|
||||
* $loader->add('Symfony\Component', __DIR__.'/component');
|
||||
* $loader->add('Symfony', __DIR__.'/framework');
|
||||
*
|
||||
* // activate the autoloader
|
||||
* $loader->register();
|
||||
*
|
||||
* // to enable searching the include path (eg. for PEAR packages)
|
||||
* $loader->setUseIncludePath(true);
|
||||
*
|
||||
* In this example, if you try to use a class in the Symfony\Component
|
||||
* namespace or one of its children (Symfony\Component\Console for instance),
|
||||
* the autoloader will first look for the class under the component/
|
||||
* directory, and it will then fallback to the framework/ directory if not
|
||||
* found before giving up.
|
||||
*
|
||||
* This class is loosely based on the Symfony UniversalClassLoader.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*/
|
||||
class ClassLoader
|
||||
{
|
||||
// PSR-4
|
||||
private $prefixLengthsPsr4 = array();
|
||||
private $prefixDirsPsr4 = array();
|
||||
private $fallbackDirsPsr4 = array();
|
||||
|
||||
// PSR-0
|
||||
private $prefixesPsr0 = array();
|
||||
private $fallbackDirsPsr0 = array();
|
||||
|
||||
private $useIncludePath = false;
|
||||
private $classMap = array();
|
||||
|
||||
private $classMapAuthoritative = false;
|
||||
|
||||
public function getPrefixes()
|
||||
{
|
||||
if (!empty($this->prefixesPsr0)) {
|
||||
return call_user_func_array('array_merge', $this->prefixesPsr0);
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getPrefixesPsr4()
|
||||
{
|
||||
return $this->prefixDirsPsr4;
|
||||
}
|
||||
|
||||
public function getFallbackDirs()
|
||||
{
|
||||
return $this->fallbackDirsPsr0;
|
||||
}
|
||||
|
||||
public function getFallbackDirsPsr4()
|
||||
{
|
||||
return $this->fallbackDirsPsr4;
|
||||
}
|
||||
|
||||
public function getClassMap()
|
||||
{
|
||||
return $this->classMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $classMap Class to filename map
|
||||
*/
|
||||
public function addClassMap(array $classMap)
|
||||
{
|
||||
if ($this->classMap) {
|
||||
$this->classMap = array_merge($this->classMap, $classMap);
|
||||
} else {
|
||||
$this->classMap = $classMap;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-0 directories for a given prefix, either
|
||||
* appending or prepending to the ones previously set for this prefix.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
* @param array|string $paths The PSR-0 root directories
|
||||
* @param bool $prepend Whether to prepend the directories
|
||||
*/
|
||||
public function add($prefix, $paths, $prepend = false)
|
||||
{
|
||||
if (!$prefix) {
|
||||
if ($prepend) {
|
||||
$this->fallbackDirsPsr0 = array_merge(
|
||||
(array) $paths,
|
||||
$this->fallbackDirsPsr0
|
||||
);
|
||||
} else {
|
||||
$this->fallbackDirsPsr0 = array_merge(
|
||||
$this->fallbackDirsPsr0,
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$first = $prefix[0];
|
||||
if (!isset($this->prefixesPsr0[$first][$prefix])) {
|
||||
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
|
||||
|
||||
return;
|
||||
}
|
||||
if ($prepend) {
|
||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||
(array) $paths,
|
||||
$this->prefixesPsr0[$first][$prefix]
|
||||
);
|
||||
} else {
|
||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||
$this->prefixesPsr0[$first][$prefix],
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-4 directories for a given namespace, either
|
||||
* appending or prepending to the ones previously set for this namespace.
|
||||
*
|
||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||
* @param array|string $paths The PSR-0 base directories
|
||||
* @param bool $prepend Whether to prepend the directories
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function addPsr4($prefix, $paths, $prepend = false)
|
||||
{
|
||||
if (!$prefix) {
|
||||
// Register directories for the root namespace.
|
||||
if ($prepend) {
|
||||
$this->fallbackDirsPsr4 = array_merge(
|
||||
(array) $paths,
|
||||
$this->fallbackDirsPsr4
|
||||
);
|
||||
} else {
|
||||
$this->fallbackDirsPsr4 = array_merge(
|
||||
$this->fallbackDirsPsr4,
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
|
||||
// Register directories for a new namespace.
|
||||
$length = strlen($prefix);
|
||||
if ('\\' !== $prefix[$length - 1]) {
|
||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||
}
|
||||
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||
$this->prefixDirsPsr4[$prefix] = (array) $paths;
|
||||
} elseif ($prepend) {
|
||||
// Prepend directories for an already registered namespace.
|
||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||
(array) $paths,
|
||||
$this->prefixDirsPsr4[$prefix]
|
||||
);
|
||||
} else {
|
||||
// Append directories for an already registered namespace.
|
||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||
$this->prefixDirsPsr4[$prefix],
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-0 directories for a given prefix,
|
||||
* replacing any others previously set for this prefix.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
* @param array|string $paths The PSR-0 base directories
|
||||
*/
|
||||
public function set($prefix, $paths)
|
||||
{
|
||||
if (!$prefix) {
|
||||
$this->fallbackDirsPsr0 = (array) $paths;
|
||||
} else {
|
||||
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-4 directories for a given namespace,
|
||||
* replacing any others previously set for this namespace.
|
||||
*
|
||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||
* @param array|string $paths The PSR-4 base directories
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setPsr4($prefix, $paths)
|
||||
{
|
||||
if (!$prefix) {
|
||||
$this->fallbackDirsPsr4 = (array) $paths;
|
||||
} else {
|
||||
$length = strlen($prefix);
|
||||
if ('\\' !== $prefix[$length - 1]) {
|
||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||
}
|
||||
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||
$this->prefixDirsPsr4[$prefix] = (array) $paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns on searching the include path for class files.
|
||||
*
|
||||
* @param bool $useIncludePath
|
||||
*/
|
||||
public function setUseIncludePath($useIncludePath)
|
||||
{
|
||||
$this->useIncludePath = $useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to check if the autoloader uses the include path to check
|
||||
* for classes.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getUseIncludePath()
|
||||
{
|
||||
return $this->useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns off searching the prefix and fallback directories for classes
|
||||
* that have not been registered with the class map.
|
||||
*
|
||||
* @param bool $classMapAuthoritative
|
||||
*/
|
||||
public function setClassMapAuthoritative($classMapAuthoritative)
|
||||
{
|
||||
$this->classMapAuthoritative = $classMapAuthoritative;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should class lookup fail if not found in the current class map?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isClassMapAuthoritative()
|
||||
{
|
||||
return $this->classMapAuthoritative;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers this instance as an autoloader.
|
||||
*
|
||||
* @param bool $prepend Whether to prepend the autoloader or not
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters this instance as an autoloader.
|
||||
*/
|
||||
public function unregister()
|
||||
{
|
||||
spl_autoload_unregister(array($this, 'loadClass'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the given class or interface.
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
* @return bool|null True if loaded, null otherwise
|
||||
*/
|
||||
public function loadClass($class)
|
||||
{
|
||||
if ($file = $this->findFile($class)) {
|
||||
includeFile($file);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the path to the file where the class is defined.
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
*
|
||||
* @return string|false The path if found, false otherwise
|
||||
*/
|
||||
public function findFile($class)
|
||||
{
|
||||
// work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
|
||||
if ('\\' == $class[0]) {
|
||||
$class = substr($class, 1);
|
||||
}
|
||||
|
||||
// class map lookup
|
||||
if (isset($this->classMap[$class])) {
|
||||
return $this->classMap[$class];
|
||||
}
|
||||
if ($this->classMapAuthoritative) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$file = $this->findFileWithExtension($class, '.php');
|
||||
|
||||
// Search for Hack files if we are running on HHVM
|
||||
if ($file === null && defined('HHVM_VERSION')) {
|
||||
$file = $this->findFileWithExtension($class, '.hh');
|
||||
}
|
||||
|
||||
if ($file === null) {
|
||||
// Remember that this class does not exist.
|
||||
return $this->classMap[$class] = false;
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
private function findFileWithExtension($class, $ext)
|
||||
{
|
||||
// PSR-4 lookup
|
||||
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
|
||||
|
||||
$first = $class[0];
|
||||
if (isset($this->prefixLengthsPsr4[$first])) {
|
||||
foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
|
||||
if (0 === strpos($class, $prefix)) {
|
||||
foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
|
||||
if (is_file($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-4 fallback dirs
|
||||
foreach ($this->fallbackDirsPsr4 as $dir) {
|
||||
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 lookup
|
||||
if (false !== $pos = strrpos($class, '\\')) {
|
||||
// namespaced class name
|
||||
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
|
||||
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
|
||||
} else {
|
||||
// PEAR-like class name
|
||||
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
|
||||
}
|
||||
|
||||
if (isset($this->prefixesPsr0[$first])) {
|
||||
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
|
||||
if (0 === strpos($class, $prefix)) {
|
||||
foreach ($dirs as $dir) {
|
||||
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 fallback dirs
|
||||
foreach ($this->fallbackDirsPsr0 as $dir) {
|
||||
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 include paths.
|
||||
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope isolated include.
|
||||
*
|
||||
* Prevents access to $this/self from included files.
|
||||
*/
|
||||
function includeFile($file)
|
||||
{
|
||||
include $file;
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
Copyright (c) 2015 Nils Adermann, Jordi Boggiano
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the Software), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, andor sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
|
@ -1,9 +0,0 @@
|
|||
<?php
|
||||
|
||||
// autoload_classmap.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(dirname(__FILE__)))."/library";
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
);
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
// autoload_files.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(dirname(__FILE__)))."/library";
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'2cffec82183ee1cea088009cef9a6fc3' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier.composer.php',
|
||||
);
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
// autoload_namespaces.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(dirname(__FILE__)))."/library";
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'HTMLPurifier' => array($vendorDir . '/ezyang/htmlpurifier/library'),
|
||||
);
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
// autoload_psr4.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(dirname(__FILE__)))."/library";
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'Friendica\\' => array($baseDir . '/include'),
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue