-<?php\r
-\r
-namespace Friendica\Core\Cache;\r
-\r
-use dba;\r
-use Friendica\Core\Cache;\r
-use Friendica\Database\DBM;\r
-use Friendica\Util\DateTimeFormat;\r
-\r
-/**\r
- * Database Cache Driver\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class DatabaseCacheDriver implements ICacheDriver\r
-{\r
- public function get($key)\r
- {\r
- $cache = dba::selectFirst('cache', ['v'], ['`k` = ? AND `expires` >= ?', $key, DateTimeFormat::utcNow()]);\r
-\r
- if (DBM::is_result($cache)) {\r
- $cached = $cache['v'];\r
- $value = @unserialize($cached);\r
-\r
- // Only return a value if the serialized value is valid.\r
- // We also check if the db entry is a serialized\r
- // boolean 'false' value (which we want to return).\r
- if ($cached === serialize(false) || $value !== false) {\r
- return $value;\r
- }\r
- }\r
-\r
- return null;\r
- }\r
-\r
- public function set($key, $value, $duration = Cache::MONTH)\r
- {\r
- $fields = [\r
- 'v' => serialize($value),\r
- 'expires' => DateTimeFormat::utc('now + ' . $duration . ' seconds'),\r
- 'updated' => DateTimeFormat::utcNow()\r
- ];\r
-\r
- return dba::update('cache', $fields, ['k' => $key], true);\r
- }\r
-\r
- public function delete($key)\r
- {\r
- return dba::delete('cache', ['k' => $key]);\r
- }\r
-\r
- public function clear()\r
- {\r
- return dba::delete('cache', ['`expires` < NOW()']);\r
- }\r
-}\r
+<?php
+
+namespace Friendica\Core\Cache;
+
+use dba;
+use Friendica\Core\Cache;
+use Friendica\Database\DBM;
+use Friendica\Util\DateTimeFormat;
+
+/**
+ * Database Cache Driver
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class DatabaseCacheDriver implements ICacheDriver
+{
+ public function get($key)
+ {
+ $cache = dba::selectFirst('cache', ['v'], ['`k` = ? AND `expires` >= ?', $key, DateTimeFormat::utcNow()]);
+
+ if (DBM::is_result($cache)) {
+ $cached = $cache['v'];
+ $value = @unserialize($cached);
+
+ // Only return a value if the serialized value is valid.
+ // We also check if the db entry is a serialized
+ // boolean 'false' value (which we want to return).
+ if ($cached === serialize(false) || $value !== false) {
+ return $value;
+ }
+ }
+
+ return null;
+ }
+
+ public function set($key, $value, $duration = Cache::MONTH)
+ {
+ $fields = [
+ 'v' => serialize($value),
+ 'expires' => DateTimeFormat::utc('now + ' . $duration . ' seconds'),
+ 'updated' => DateTimeFormat::utcNow()
+ ];
+
+ return dba::update('cache', $fields, ['k' => $key], true);
+ }
+
+ public function delete($key)
+ {
+ return dba::delete('cache', ['k' => $key]);
+ }
+
+ public function clear()
+ {
+ return dba::delete('cache', ['`expires` < NOW()']);
+ }
+}
-<?php\r
-\r
-namespace Friendica\Core\Cache;\r
-\r
-use Friendica\Core\Cache;\r
-\r
-/**\r
- * Cache Driver Interface\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-interface ICacheDriver\r
-{\r
- /**\r
- * Fetches cached data according to the key\r
- *\r
- * @param string $key The key to the cached data\r
- *\r
- * @return mixed Cached $value or "null" if not found\r
- */\r
- public function get($key);\r
-\r
- /**\r
- * Stores data in the cache identified by the key. The input $value can have multiple formats.\r
- *\r
- * @param string $key The cache key\r
- * @param mixed $value The value to store\r
- * @param integer $duration The cache lifespan, must be one of the Cache constants\r
- *\r
- * @return bool\r
- */\r
- public function set($key, $value, $duration = Cache::MONTH);\r
-\r
-\r
- /**\r
- * Delete a key from the cache\r
- *\r
- * @param string $key\r
- *\r
- * @return bool\r
- */\r
- public function delete($key);\r
-\r
- /**\r
- * Remove outdated data from the cache\r
- *\r
- * @return bool\r
- */\r
- public function clear();\r
-}\r
+<?php
+
+namespace Friendica\Core\Cache;
+
+use Friendica\Core\Cache;
+
+/**
+ * Cache Driver Interface
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+interface ICacheDriver
+{
+ /**
+ * Fetches cached data according to the key
+ *
+ * @param string $key The key to the cached data
+ *
+ * @return mixed Cached $value or "null" if not found
+ */
+ public function get($key);
+
+ /**
+ * Stores data in the cache identified by the key. The input $value can have multiple formats.
+ *
+ * @param string $key The cache key
+ * @param mixed $value The value to store
+ * @param integer $duration The cache lifespan, must be one of the Cache constants
+ *
+ * @return bool
+ */
+ public function set($key, $value, $duration = Cache::MONTH);
+
+
+ /**
+ * Delete a key from the cache
+ *
+ * @param string $key
+ *
+ * @return bool
+ */
+ public function delete($key);
+
+ /**
+ * Remove outdated data from the cache
+ *
+ * @return bool
+ */
+ public function clear();
+}
-<?php\r
-\r
-namespace Friendica\Core\Cache;\r
-\r
-use Friendica\BaseObject;\r
-use Friendica\Core\Cache;\r
-\r
-/**\r
- * Memcache Cache Driver\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class MemcacheCacheDriver extends BaseObject implements ICacheDriver\r
-{\r
- /**\r
- * @var Memcache\r
- */\r
- private $memcache;\r
-\r
- public function __construct($memcache_host, $memcache_port)\r
- {\r
- if (!class_exists('Memcache', false)) {\r
- throw new \Exception('Memcache class isn\'t available');\r
- }\r
-\r
- $this->memcache = new \Memcache();\r
-\r
- if (!$this->memcache->connect($memcache_host, $memcache_port)) {\r
- throw new \Exception('Expected Memcache server at ' . $memcache_host . ':' . $memcache_port . ' isn\'t available');\r
- }\r
- }\r
-\r
- public function get($key)\r
- {\r
- $return = null;\r
-\r
- // We fetch with the hostname as key to avoid problems with other applications\r
- $cached = $this->memcache->get(self::getApp()->get_hostname() . ':' . $key);\r
-\r
- // @see http://php.net/manual/en/memcache.get.php#84275\r
- if (is_bool($cached) || is_double($cached) || is_long($cached)) {\r
- return $return;\r
- }\r
-\r
- $value = @unserialize($cached);\r
-\r
- // Only return a value if the serialized value is valid.\r
- // We also check if the db entry is a serialized\r
- // boolean 'false' value (which we want to return).\r
- if ($cached === serialize(false) || $value !== false) {\r
- $return = $value;\r
- }\r
-\r
- return $return;\r
- }\r
-\r
- public function set($key, $value, $duration = Cache::MONTH)\r
- {\r
- // We store with the hostname as key to avoid problems with other applications\r
- return $this->memcache->set(\r
- self::getApp()->get_hostname() . ":" . $key,\r
- serialize($value),\r
- MEMCACHE_COMPRESSED,\r
- time() + $duration\r
- );\r
- }\r
-\r
- public function delete($key)\r
- {\r
- return $this->memcache->delete($key);\r
- }\r
-\r
- public function clear()\r
- {\r
- return true;\r
- }\r
-}\r
+<?php
+
+namespace Friendica\Core\Cache;
+
+use Friendica\BaseObject;
+use Friendica\Core\Cache;
+
+/**
+ * Memcache Cache Driver
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class MemcacheCacheDriver extends BaseObject implements ICacheDriver
+{
+ /**
+ * @var Memcache
+ */
+ private $memcache;
+
+ public function __construct($memcache_host, $memcache_port)
+ {
+ if (!class_exists('Memcache', false)) {
+ throw new \Exception('Memcache class isn\'t available');
+ }
+
+ $this->memcache = new \Memcache();
+
+ if (!$this->memcache->connect($memcache_host, $memcache_port)) {
+ throw new \Exception('Expected Memcache server at ' . $memcache_host . ':' . $memcache_port . ' isn\'t available');
+ }
+ }
+
+ public function get($key)
+ {
+ $return = null;
+
+ // We fetch with the hostname as key to avoid problems with other applications
+ $cached = $this->memcache->get(self::getApp()->get_hostname() . ':' . $key);
+
+ // @see http://php.net/manual/en/memcache.get.php#84275
+ if (is_bool($cached) || is_double($cached) || is_long($cached)) {
+ return $return;
+ }
+
+ $value = @unserialize($cached);
+
+ // Only return a value if the serialized value is valid.
+ // We also check if the db entry is a serialized
+ // boolean 'false' value (which we want to return).
+ if ($cached === serialize(false) || $value !== false) {
+ $return = $value;
+ }
+
+ return $return;
+ }
+
+ public function set($key, $value, $duration = Cache::MONTH)
+ {
+ // We store with the hostname as key to avoid problems with other applications
+ return $this->memcache->set(
+ self::getApp()->get_hostname() . ":" . $key,
+ serialize($value),
+ MEMCACHE_COMPRESSED,
+ time() + $duration
+ );
+ }
+
+ public function delete($key)
+ {
+ return $this->memcache->delete($key);
+ }
+
+ public function clear()
+ {
+ return true;
+ }
+}
-<?php\r
-\r
-namespace Friendica\Core\Cache;\r
-\r
-use Friendica\BaseObject;\r
-use Friendica\Core\Cache;\r
-\r
-/**\r
- * Memcached Cache Driver\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class MemcachedCacheDriver extends BaseObject implements ICacheDriver\r
-{\r
- /**\r
- * @var Memcached\r
- */\r
- private $memcached;\r
-\r
- public function __construct(array $memcached_hosts)\r
- {\r
- if (!class_exists('Memcached', false)) {\r
- throw new \Exception('Memcached class isn\'t available');\r
- }\r
-\r
- $this->memcached = new \Memcached();\r
-\r
- $this->memcached->addServers($memcached_hosts);\r
-\r
- if (count($this->memcached->getServerList()) == 0) {\r
- throw new \Exception('Expected Memcached servers aren\'t available, config:' . var_export($memcached_hosts, true));\r
- }\r
- }\r
-\r
- public function get($key)\r
- {\r
- $return = null;\r
-\r
- // We fetch with the hostname as key to avoid problems with other applications\r
- $value = $this->memcached->get(self::getApp()->get_hostname() . ':' . $key);\r
-\r
- if ($this->memcached->getResultCode() === \Memcached::RES_SUCCESS) {\r
- $return = $value;\r
- }\r
-\r
- return $return;\r
- }\r
-\r
- public function set($key, $value, $duration = Cache::MONTH)\r
- {\r
- // We store with the hostname as key to avoid problems with other applications\r
- return $this->memcached->set(\r
- self::getApp()->get_hostname() . ":" . $key,\r
- $value,\r
- time() + $duration\r
- );\r
- }\r
-\r
- public function delete($key)\r
- {\r
- return $this->memcached->delete($key);\r
- }\r
-\r
- public function clear()\r
- {\r
- return true;\r
- }\r
-}\r
+<?php
+
+namespace Friendica\Core\Cache;
+
+use Friendica\BaseObject;
+use Friendica\Core\Cache;
+
+/**
+ * Memcached Cache Driver
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class MemcachedCacheDriver extends BaseObject implements ICacheDriver
+{
+ /**
+ * @var Memcached
+ */
+ private $memcached;
+
+ public function __construct(array $memcached_hosts)
+ {
+ if (!class_exists('Memcached', false)) {
+ throw new \Exception('Memcached class isn\'t available');
+ }
+
+ $this->memcached = new \Memcached();
+
+ $this->memcached->addServers($memcached_hosts);
+
+ if (count($this->memcached->getServerList()) == 0) {
+ throw new \Exception('Expected Memcached servers aren\'t available, config:' . var_export($memcached_hosts, true));
+ }
+ }
+
+ public function get($key)
+ {
+ $return = null;
+
+ // We fetch with the hostname as key to avoid problems with other applications
+ $value = $this->memcached->get(self::getApp()->get_hostname() . ':' . $key);
+
+ if ($this->memcached->getResultCode() === \Memcached::RES_SUCCESS) {
+ $return = $value;
+ }
+
+ return $return;
+ }
+
+ public function set($key, $value, $duration = Cache::MONTH)
+ {
+ // We store with the hostname as key to avoid problems with other applications
+ return $this->memcached->set(
+ self::getApp()->get_hostname() . ":" . $key,
+ $value,
+ time() + $duration
+ );
+ }
+
+ public function delete($key)
+ {
+ return $this->memcached->delete($key);
+ }
+
+ public function clear()
+ {
+ return true;
+ }
+}
-<?php\r
-\r
-namespace Friendica\Core\Config;\r
-\r
-/**\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-interface IConfigAdapter\r
-{\r
- /**\r
- * @brief Loads all configuration values into a cached storage.\r
- *\r
- * All configuration values of the system are stored in global cache\r
- * which is available under the global variable $a->config\r
- *\r
- * @param string $cat The category of the configuration values to load\r
- *\r
- * @return void\r
- */\r
- public function load($cat = "config");\r
-\r
- /**\r
- * @brief Get a particular user's config variable given the category name\r
- * ($family) and a key.\r
- *\r
- * Get a particular config value from the given category ($family)\r
- * and the $key from a cached storage in $a->config[$uid].\r
- * $instore is only used by the set_config function\r
- * to determine if the key already exists in the DB\r
- * If a key is found in the DB but doesn't exist in\r
- * local config cache, pull it into the cache so we don't have\r
- * to hit the DB again for this item.\r
- *\r
- * @param string $cat The category of the configuration value\r
- * @param string $k The configuration key to query\r
- * @param mixed $default_value optional, The value to return if key is not set (default: null)\r
- * @param boolean $refresh optional, If true the config is loaded from the db and not from the cache (default: false)\r
- *\r
- * @return mixed Stored value or null if it does not exist\r
- */\r
- public function get($cat, $k, $default_value = null, $refresh = false);\r
-\r
- /**\r
- * @brief Sets a configuration value for system config\r
- *\r
- * Stores a config value ($value) in the category ($family) under the key ($key)\r
- * for the user_id $uid.\r
- *\r
- * Note: Please do not store booleans - convert to 0/1 integer values!\r
- *\r
- * @param string $family The category of the configuration value\r
- * @param string $key The configuration key to set\r
- * @param mixed $value The value to store\r
- *\r
- * @return mixed Stored $value or false if the database update failed\r
- */\r
- public function set($cat, $k, $value);\r
-\r
- /**\r
- * @brief Deletes the given key from the system configuration.\r
- *\r
- * Removes the configured value from the stored cache in $a->config\r
- * and removes it from the database.\r
- *\r
- * @param string $cat The category of the configuration value\r
- * @param string $k The configuration key to delete\r
- *\r
- * @return mixed\r
- */\r
- public function delete($cat, $k);\r
-}\r
+<?php
+
+namespace Friendica\Core\Config;
+
+/**
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+interface IConfigAdapter
+{
+ /**
+ * @brief Loads all configuration values 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 $cat The category of the configuration values to load
+ *
+ * @return void
+ */
+ public function load($cat = "config");
+
+ /**
+ * @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 $cat The category of the configuration value
+ * @param string $k 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 function get($cat, $k, $default_value = null, $refresh = false);
+
+ /**
+ * @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 mixed $value The value to store
+ *
+ * @return mixed Stored $value or false if the database update failed
+ */
+ public function set($cat, $k, $value);
+
+ /**
+ * @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 $cat The category of the configuration value
+ * @param string $k The configuration key to delete
+ *
+ * @return mixed
+ */
+ public function delete($cat, $k);
+}
-<?php\r
-\r
-/*\r
- * To change this license header, choose License Headers in Project Properties.\r
- * To change this template file, choose Tools | Templates\r
- * and open the template in the editor.\r
- */\r
-\r
-namespace Friendica\Core\Config;\r
-\r
-/**\r
- *\r
- * @author benlo\r
- */\r
-interface IPConfigAdapter\r
-{\r
- /**\r
- * @brief Loads all configuration values of a user's config family into a cached storage.\r
- *\r
- * All configuration values of the given user are stored in global cache\r
- * which is available under the global variable $a->config[$uid].\r
- *\r
- * @param string $uid The user_id\r
- * @param string $cat The category of the configuration value\r
- *\r
- * @return void\r
- */\r
- public function load($uid, $cat);\r
-\r
- /**\r
- * @brief Get a particular user's config variable given the category name\r
- * ($family) and a key.\r
- *\r
- * Get a particular user's config value from the given category ($family)\r
- * and the $key from a cached storage in $a->config[$uid].\r
- *\r
- * @param string $uid The user_id\r
- * @param string $cat The category of the configuration value\r
- * @param string $k The configuration key to query\r
- * @param mixed $default_value optional, The value to return if key is not set (default: null)\r
- * @param boolean $refresh optional, If true the config is loaded from the db and not from the cache (default: false)\r
- *\r
- * @return mixed Stored value or null if it does not exist\r
- */\r
- public function get($uid, $cat, $k, $default_value = null, $refresh = false);\r
-\r
- /**\r
- * @brief Sets a configuration value for a user\r
- *\r
- * Stores a config value ($value) in the category ($family) under the key ($key)\r
- * for the user_id $uid.\r
- *\r
- * @note Please do not store booleans - convert to 0/1 integer values!\r
- *\r
- * @param string $uid The user_id\r
- * @param string $cat The category of the configuration value\r
- * @param string $k The configuration key to set\r
- * @param string $value The value to store\r
- *\r
- * @return mixed Stored $value or false\r
- */\r
- public function set($uid, $cat, $k, $value);\r
-\r
- /**\r
- * @brief Deletes the given key from the users's configuration.\r
- *\r
- * Removes the configured value from the stored cache in $a->config[$uid]\r
- * and removes it from the database.\r
- *\r
- * @param string $uid The user_id\r
- * @param string $cat The category of the configuration value\r
- * @param string $k The configuration key to delete\r
- *\r
- * @return mixed\r
- */\r
- public function delete($uid, $cat, $k);\r
-}\r
+<?php
+
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+namespace Friendica\Core\Config;
+
+/**
+ *
+ * @author benlo
+ */
+interface IPConfigAdapter
+{
+ /**
+ * @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 $cat The category of the configuration value
+ *
+ * @return void
+ */
+ public function load($uid, $cat);
+
+ /**
+ * @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 $cat The category of the configuration value
+ * @param string $k 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 function get($uid, $cat, $k, $default_value = null, $refresh = false);
+
+ /**
+ * @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 $cat The category of the configuration value
+ * @param string $k The configuration key to set
+ * @param string $value The value to store
+ *
+ * @return mixed Stored $value or false
+ */
+ public function set($uid, $cat, $k, $value);
+
+ /**
+ * @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 $cat The category of the configuration value
+ * @param string $k The configuration key to delete
+ *
+ * @return mixed
+ */
+ public function delete($uid, $cat, $k);
+}
-<?php\r
-\r
-namespace Friendica\Core\Config;\r
-\r
-use dba;\r
-use Exception;\r
-use Friendica\App;\r
-use Friendica\BaseObject;\r
-use Friendica\Database\DBM;\r
-\r
-require_once 'include/dba.php';\r
-\r
-/**\r
- * Preload Configuration Adapter\r
- *\r
- * Minimizes the number of database queries to retrieve configuration values at the cost of memory.\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class PreloadConfigAdapter extends BaseObject implements IConfigAdapter\r
-{\r
- private $config_loaded = false;\r
-\r
- public function __construct()\r
- {\r
- $this->load();\r
- }\r
-\r
- public function load($family = 'config')\r
- {\r
- if ($this->config_loaded) {\r
- return;\r
- }\r
-\r
- $configs = dba::select('config', ['cat', 'v', 'k']);\r
- while ($config = dba::fetch($configs)) {\r
- self::getApp()->setConfigValue($config['cat'], $config['k'], $config['v']);\r
- }\r
- dba::close($configs);\r
-\r
- $this->config_loaded = true;\r
- }\r
-\r
- public function get($cat, $k, $default_value = null, $refresh = false)\r
- {\r
- if ($refresh) {\r
- $config = dba::selectFirst('config', ['v'], ['cat' => $cat, 'k' => $k]);\r
- if (DBM::is_result($config)) {\r
- self::getApp()->setConfigValue($cat, $k, $config['v']);\r
- }\r
- }\r
-\r
- $return = self::getApp()->getConfigValue($cat, $k, $default_value);\r
-\r
- return $return;\r
- }\r
-\r
- public function set($cat, $k, $value)\r
- {\r
- // We store our setting values as strings.\r
- // So we have to do the conversion here so that the compare below works.\r
- // The exception are array values.\r
- $compare_value = !is_array($value) ? (string)$value : $value;\r
-\r
- if (self::getApp()->getConfigValue($cat, $k) === $compare_value) {\r
- return true;\r
- }\r
-\r
- self::getApp()->setConfigValue($cat, $k, $value);\r
-\r
- // manage array value\r
- $dbvalue = is_array($value) ? serialize($value) : $value;\r
-\r
- $result = dba::update('config', ['v' => $dbvalue], ['cat' => $cat, 'k' => $k], true);\r
- if (!$result) {\r
- throw new Exception('Unable to store config value in [' . $cat . '][' . $k . ']');\r
- }\r
-\r
- return true;\r
- }\r
-\r
- public function delete($cat, $k)\r
- {\r
- self::getApp()->deleteConfigValue($cat, $k);\r
-\r
- $result = dba::delete('config', ['cat' => $cat, 'k' => $k]);\r
-\r
- return $result;\r
- }\r
-}\r
+<?php
+
+namespace Friendica\Core\Config;
+
+use dba;
+use Exception;
+use Friendica\App;
+use Friendica\BaseObject;
+use Friendica\Database\DBM;
+
+require_once 'include/dba.php';
+
+/**
+ * Preload Configuration Adapter
+ *
+ * Minimizes the number of database queries to retrieve configuration values at the cost of memory.
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class PreloadConfigAdapter extends BaseObject implements IConfigAdapter
+{
+ private $config_loaded = false;
+
+ public function __construct()
+ {
+ $this->load();
+ }
+
+ public function load($family = 'config')
+ {
+ if ($this->config_loaded) {
+ return;
+ }
+
+ $configs = dba::select('config', ['cat', 'v', 'k']);
+ while ($config = dba::fetch($configs)) {
+ self::getApp()->setConfigValue($config['cat'], $config['k'], $config['v']);
+ }
+ dba::close($configs);
+
+ $this->config_loaded = true;
+ }
+
+ public function get($cat, $k, $default_value = null, $refresh = false)
+ {
+ if ($refresh) {
+ $config = dba::selectFirst('config', ['v'], ['cat' => $cat, 'k' => $k]);
+ if (DBM::is_result($config)) {
+ self::getApp()->setConfigValue($cat, $k, $config['v']);
+ }
+ }
+
+ $return = self::getApp()->getConfigValue($cat, $k, $default_value);
+
+ return $return;
+ }
+
+ public function set($cat, $k, $value)
+ {
+ // We store our setting values as strings.
+ // So we have to do the conversion here so that the compare below works.
+ // The exception are array values.
+ $compare_value = !is_array($value) ? (string)$value : $value;
+
+ if (self::getApp()->getConfigValue($cat, $k) === $compare_value) {
+ return true;
+ }
+
+ self::getApp()->setConfigValue($cat, $k, $value);
+
+ // manage array value
+ $dbvalue = is_array($value) ? serialize($value) : $value;
+
+ $result = dba::update('config', ['v' => $dbvalue], ['cat' => $cat, 'k' => $k], true);
+ if (!$result) {
+ throw new Exception('Unable to store config value in [' . $cat . '][' . $k . ']');
+ }
+
+ return true;
+ }
+
+ public function delete($cat, $k)
+ {
+ self::getApp()->deleteConfigValue($cat, $k);
+
+ $result = dba::delete('config', ['cat' => $cat, 'k' => $k]);
+
+ return $result;
+ }
+}
-<?php\r
-\r
-namespace Friendica\Core\Config;\r
-\r
-use dba;\r
-use Exception;\r
-use Friendica\App;\r
-use Friendica\BaseObject;\r
-use Friendica\Database\DBM;\r
-\r
-require_once 'include/dba.php';\r
-\r
-/**\r
- * Preload User Configuration Adapter\r
- *\r
- * Minimizes the number of database queries to retrieve configuration values at the cost of memory.\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class PreloadPConfigAdapter extends BaseObject implements IPConfigAdapter\r
-{\r
- private $config_loaded = false;\r
-\r
- public function __construct($uid)\r
- {\r
- $this->load($uid, 'config');\r
- }\r
-\r
- public function load($uid, $family)\r
- {\r
- if ($this->config_loaded) {\r
- return;\r
- }\r
-\r
- $pconfigs = dba::select('pconfig', ['cat', 'v', 'k'], ['uid' => $uid]);\r
- while ($pconfig = dba::fetch($pconfigs)) {\r
- self::getApp()->setPConfigValue($uid, $pconfig['cat'], $pconfig['k'], $pconfig['v']);\r
- }\r
- dba::close($pconfigs);\r
-\r
- $this->config_loaded = true;\r
- }\r
-\r
- public function get($uid, $cat, $k, $default_value = null, $refresh = false)\r
- {\r
- if ($refresh) {\r
- $config = dba::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $k]);\r
- if (DBM::is_result($config)) {\r
- self::getApp()->setPConfigValue($uid, $cat, $k, $config['v']);\r
- } else {\r
- self::getApp()->deletePConfigValue($uid, $cat, $k);\r
- }\r
- }\r
-\r
- $return = self::getApp()->getPConfigValue($uid, $cat, $k, $default_value);\r
-\r
- return $return;\r
- }\r
-\r
- public function set($uid, $cat, $k, $value)\r
- {\r
- // We store our setting values as strings.\r
- // So we have to do the conversion here so that the compare below works.\r
- // The exception are array values.\r
- $compare_value = !is_array($value) ? (string)$value : $value;\r
-\r
- if (self::getApp()->getPConfigValue($uid, $cat, $k) === $compare_value) {\r
- return true;\r
- }\r
-\r
- self::getApp()->setPConfigValue($uid, $cat, $k, $value);\r
-\r
- // manage array value\r
- $dbvalue = is_array($value) ? serialize($value) : $value;\r
-\r
- $result = dba::update('pconfig', ['v' => $dbvalue], ['uid' => $uid, 'cat' => $cat, 'k' => $k], true);\r
- if (!$result) {\r
- throw new Exception('Unable to store config value in [' . $uid . '][' . $cat . '][' . $k . ']');\r
- }\r
-\r
- return true;\r
- }\r
-\r
- public function delete($uid, $cat, $k)\r
- {\r
- self::getApp()->deletePConfigValue($uid, $cat, $k);\r
-\r
- $result = dba::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $k]);\r
-\r
- return $result;\r
- }\r
-}\r
+<?php
+
+namespace Friendica\Core\Config;
+
+use dba;
+use Exception;
+use Friendica\App;
+use Friendica\BaseObject;
+use Friendica\Database\DBM;
+
+require_once 'include/dba.php';
+
+/**
+ * Preload User Configuration Adapter
+ *
+ * Minimizes the number of database queries to retrieve configuration values at the cost of memory.
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class PreloadPConfigAdapter extends BaseObject implements IPConfigAdapter
+{
+ private $config_loaded = false;
+
+ public function __construct($uid)
+ {
+ $this->load($uid, 'config');
+ }
+
+ public function load($uid, $family)
+ {
+ if ($this->config_loaded) {
+ return;
+ }
+
+ $pconfigs = dba::select('pconfig', ['cat', 'v', 'k'], ['uid' => $uid]);
+ while ($pconfig = dba::fetch($pconfigs)) {
+ self::getApp()->setPConfigValue($uid, $pconfig['cat'], $pconfig['k'], $pconfig['v']);
+ }
+ dba::close($pconfigs);
+
+ $this->config_loaded = true;
+ }
+
+ public function get($uid, $cat, $k, $default_value = null, $refresh = false)
+ {
+ if ($refresh) {
+ $config = dba::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $k]);
+ if (DBM::is_result($config)) {
+ self::getApp()->setPConfigValue($uid, $cat, $k, $config['v']);
+ } else {
+ self::getApp()->deletePConfigValue($uid, $cat, $k);
+ }
+ }
+
+ $return = self::getApp()->getPConfigValue($uid, $cat, $k, $default_value);
+
+ return $return;
+ }
+
+ public function set($uid, $cat, $k, $value)
+ {
+ // We store our setting values as strings.
+ // So we have to do the conversion here so that the compare below works.
+ // The exception are array values.
+ $compare_value = !is_array($value) ? (string)$value : $value;
+
+ if (self::getApp()->getPConfigValue($uid, $cat, $k) === $compare_value) {
+ return true;
+ }
+
+ self::getApp()->setPConfigValue($uid, $cat, $k, $value);
+
+ // manage array value
+ $dbvalue = is_array($value) ? serialize($value) : $value;
+
+ $result = dba::update('pconfig', ['v' => $dbvalue], ['uid' => $uid, 'cat' => $cat, 'k' => $k], true);
+ if (!$result) {
+ throw new Exception('Unable to store config value in [' . $uid . '][' . $cat . '][' . $k . ']');
+ }
+
+ return true;
+ }
+
+ public function delete($uid, $cat, $k)
+ {
+ self::getApp()->deletePConfigValue($uid, $cat, $k);
+
+ $result = dba::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $k]);
+
+ return $result;
+ }
+}
-<?php\r
-\r
-namespace Friendica\Core;\r
-\r
-/**\r
- * Description of Console\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class Console extends \Asika\SimpleConsole\Console\r
-{\r
- // Disables the default help handling\r
- protected $helpOptions = [];\r
- protected $customHelpOptions = ['h', 'help', '?'];\r
-\r
- protected $subConsoles = [\r
- 'config' => __NAMESPACE__ . '\Console\Config',\r
- 'createdoxygen' => __NAMESPACE__ . '\Console\CreateDoxygen',\r
- 'docbloxerrorchecker' => __NAMESPACE__ . '\Console\DocBloxErrorChecker',\r
- 'dbstructure' => __NAMESPACE__ . '\Console\DatabaseStructure',\r
- 'extract' => __NAMESPACE__ . '\Console\Extract',\r
- 'globalcommunityblock' => __NAMESPACE__ . '\Console\GlobalCommunityBlock',\r
- 'globalcommunitysilence' => __NAMESPACE__ . '\Console\GlobalCommunitySilence',\r
- 'maintenance' => __NAMESPACE__ . '\Console\Maintenance',\r
- 'php2po' => __NAMESPACE__ . '\Console\PhpToPo',\r
- 'po2php' => __NAMESPACE__ . '\Console\PoToPhp',\r
- 'typo' => __NAMESPACE__ . '\Console\Typo',\r
- ];\r
-\r
- protected function getHelp()\r
- {\r
- $help = <<<HELP\r
-Usage: bin/console [--version] [-h|--help|-?] <command> [<args>] [-v]\r
-\r
-Commands:\r
- config Edit site config\r
- createdoxygen Generate Doxygen headers\r
- dbstructure Do database updates\r
- docbloxerrorchecker Check the file tree for DocBlox errors\r
- extract Generate translation string file for the Friendica project (deprecated)\r
- globalcommunityblock Block remote profile from interacting with this node\r
- globalcommunitysilence Silence remote profile from global community page\r
- help Show help about a command, e.g (bin/console help config)\r
- maintenance Set maintenance mode for this node\r
- php2po Generate a messages.po file from a strings.php file\r
- po2php Generate a strings.php file from a messages.po file\r
- typo Checks for parse errors in Friendica files\r
-\r
-Options:\r
- -h|--help|-? Show help information\r
- -v Show more debug information.\r
-HELP;\r
- return $help;\r
- }\r
-\r
- protected function doExecute()\r
- {\r
- if ($this->getOption('v')) {\r
- $this->out('Executable: ' . $this->executable);\r
- $this->out('Arguments: ' . var_export($this->args, true));\r
- $this->out('Options: ' . var_export($this->options, true));\r
- }\r
-\r
- $showHelp = false;\r
- $subHelp = false;\r
- $command = null;\r
-\r
- if ($this->getOption('version')) {\r
- $this->out('Friendica Console version ' . FRIENDICA_VERSION);\r
-\r
- return 0;\r
- } elseif ((count($this->options) === 0 || $this->getOption($this->customHelpOptions) === true || $this->getOption($this->customHelpOptions) === 1) && count($this->args) === 0\r
- ) {\r
- $showHelp = true;\r
- } elseif (count($this->args) >= 2 && $this->getArgument(0) == 'help') {\r
- $command = $this->getArgument(1);\r
- $subHelp = true;\r
- array_shift($this->args);\r
- array_shift($this->args);\r
- } elseif (count($this->args) >= 1) {\r
- $command = $this->getArgument(0);\r
- array_shift($this->args);\r
- }\r
-\r
- if (is_null($command)) {\r
- $this->out($this->getHelp());\r
- return 0;\r
- }\r
-\r
- $console = $this->getSubConsole($command);\r
-\r
- if ($subHelp) {\r
- $console->setOption($this->customHelpOptions, true);\r
- }\r
-\r
- return $console->execute();\r
- }\r
-\r
- private function getSubConsole($command)\r
- {\r
- if ($this->getOption('v')) {\r
- $this->out('Command: ' . $command);\r
- }\r
-\r
- if (!isset($this->subConsoles[$command])) {\r
- throw new \Asika\SimpleConsole\CommandArgsException('Command ' . $command . ' doesn\'t exist');\r
- }\r
-\r
- $subargs = $this->args;\r
- array_unshift($subargs, $this->executable);\r
-\r
- $className = $this->subConsoles[$command];\r
-\r
- $subconsole = new $className($subargs);\r
-\r
- foreach ($this->options as $name => $value) {\r
- $subconsole->setOption($name, $value);\r
- }\r
-\r
- return $subconsole;\r
- }\r
-\r
-}\r
+<?php
+
+namespace Friendica\Core;
+
+/**
+ * Description of Console
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class Console extends \Asika\SimpleConsole\Console
+{
+ // Disables the default help handling
+ protected $helpOptions = [];
+ protected $customHelpOptions = ['h', 'help', '?'];
+
+ protected $subConsoles = [
+ 'config' => __NAMESPACE__ . '\Console\Config',
+ 'createdoxygen' => __NAMESPACE__ . '\Console\CreateDoxygen',
+ 'docbloxerrorchecker' => __NAMESPACE__ . '\Console\DocBloxErrorChecker',
+ 'dbstructure' => __NAMESPACE__ . '\Console\DatabaseStructure',
+ 'extract' => __NAMESPACE__ . '\Console\Extract',
+ 'globalcommunityblock' => __NAMESPACE__ . '\Console\GlobalCommunityBlock',
+ 'globalcommunitysilence' => __NAMESPACE__ . '\Console\GlobalCommunitySilence',
+ 'maintenance' => __NAMESPACE__ . '\Console\Maintenance',
+ 'php2po' => __NAMESPACE__ . '\Console\PhpToPo',
+ 'po2php' => __NAMESPACE__ . '\Console\PoToPhp',
+ 'typo' => __NAMESPACE__ . '\Console\Typo',
+ ];
+
+ protected function getHelp()
+ {
+ $help = <<<HELP
+Usage: bin/console [--version] [-h|--help|-?] <command> [<args>] [-v]
+
+Commands:
+ config Edit site config
+ createdoxygen Generate Doxygen headers
+ dbstructure Do database updates
+ docbloxerrorchecker Check the file tree for DocBlox errors
+ extract Generate translation string file for the Friendica project (deprecated)
+ globalcommunityblock Block remote profile from interacting with this node
+ globalcommunitysilence Silence remote profile from global community page
+ help Show help about a command, e.g (bin/console help config)
+ maintenance Set maintenance mode for this node
+ php2po Generate a messages.po file from a strings.php file
+ po2php Generate a strings.php file from a messages.po file
+ typo Checks for parse errors in Friendica files
+
+Options:
+ -h|--help|-? Show help information
+ -v Show more debug information.
+HELP;
+ return $help;
+ }
+
+ protected function doExecute()
+ {
+ if ($this->getOption('v')) {
+ $this->out('Executable: ' . $this->executable);
+ $this->out('Arguments: ' . var_export($this->args, true));
+ $this->out('Options: ' . var_export($this->options, true));
+ }
+
+ $showHelp = false;
+ $subHelp = false;
+ $command = null;
+
+ if ($this->getOption('version')) {
+ $this->out('Friendica Console version ' . FRIENDICA_VERSION);
+
+ return 0;
+ } elseif ((count($this->options) === 0 || $this->getOption($this->customHelpOptions) === true || $this->getOption($this->customHelpOptions) === 1) && count($this->args) === 0
+ ) {
+ $showHelp = true;
+ } elseif (count($this->args) >= 2 && $this->getArgument(0) == 'help') {
+ $command = $this->getArgument(1);
+ $subHelp = true;
+ array_shift($this->args);
+ array_shift($this->args);
+ } elseif (count($this->args) >= 1) {
+ $command = $this->getArgument(0);
+ array_shift($this->args);
+ }
+
+ if (is_null($command)) {
+ $this->out($this->getHelp());
+ return 0;
+ }
+
+ $console = $this->getSubConsole($command);
+
+ if ($subHelp) {
+ $console->setOption($this->customHelpOptions, true);
+ }
+
+ return $console->execute();
+ }
+
+ private function getSubConsole($command)
+ {
+ if ($this->getOption('v')) {
+ $this->out('Command: ' . $command);
+ }
+
+ if (!isset($this->subConsoles[$command])) {
+ throw new \Asika\SimpleConsole\CommandArgsException('Command ' . $command . ' doesn\'t exist');
+ }
+
+ $subargs = $this->args;
+ array_unshift($subargs, $this->executable);
+
+ $className = $this->subConsoles[$command];
+
+ $subconsole = new $className($subargs);
+
+ foreach ($this->options as $name => $value) {
+ $subconsole->setOption($name, $value);
+ }
+
+ return $subconsole;
+ }
+
+}
-<?php\r
-\r
-/*\r
- * To change this license header, choose License Headers in Project Properties.\r
- * To change this template file, choose Tools | Templates\r
- * and open the template in the editor.\r
- */\r
-\r
-namespace Friendica\Core\Console;\r
-\r
-use Asika\SimpleConsole\CommandArgsException;\r
-use dba;\r
-use Friendica\Core;\r
-\r
-require_once 'include/dba.php';\r
-require_once 'include/text.php';\r
-\r
-/**\r
- * @brief tool to access the system config from the CLI\r
- *\r
- * With this script you can access the system configuration of your node from\r
- * the CLI. You can do both, reading current values stored in the database and\r
- * set new values to config variables.\r
- *\r
- * Usage:\r
- * If you specify no parameters at the CLI, the script will list all config\r
- * variables defined.\r
- *\r
- * If you specify one parameter, the script will list all config variables\r
- * defined in this section of the configuration (e.g. "system").\r
- *\r
- * If you specify two parameters, the script will show you the current value\r
- * of the named configuration setting. (e.g. "system loglevel")\r
- *\r
- * If you specify three parameters, the named configuration setting will be\r
- * set to the value of the last parameter. (e.g. "system loglevel 0" will\r
- * disable logging)\r
- *\r
- * @author Tobias Diekershoff\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class Config extends \Asika\SimpleConsole\Console\r
-{\r
- protected $helpOptions = ['h', 'help', '?'];\r
-\r
- protected function getHelp()\r
- {\r
- $help = <<<HELP\r
-console config - Manage site configuration\r
-Synopsis\r
- bin/console config [-h|--help|-?] [-v]\r
- bin/console config <category> [-h|--help|-?] [-v]\r
- bin/console config <category> <key> [-h|--help|-?] [-v]\r
- bin/console config <category> <key> <value> [-h|--help|-?] [-v]\r
-\r
-Description\r
- bin/console config\r
- Lists all config values\r
-\r
- bin/console config <category>\r
- Lists all config values in the provided category\r
-\r
- bin/console config <category> <key>\r
- Shows the value of the provided key in the category\r
-\r
- bin/console config <category> <key> <value>\r
- Sets the value of the provided key in the category\r
-\r
-Notes:\r
- Setting config entries which are manually set in .htconfig.php may result in\r
- conflict between database settings and the manual startup settings.\r
-\r
-Options\r
- -h|--help|-? Show help information\r
- -v Show more debug information.\r
-HELP;\r
- return $help;\r
- }\r
-\r
- protected function doExecute()\r
- {\r
- if ($this->getOption('v')) {\r
- $this->out('Executable: ' . $this->executable);\r
- $this->out('Class: ' . __CLASS__);\r
- $this->out('Arguments: ' . var_export($this->args, true));\r
- $this->out('Options: ' . var_export($this->options, true));\r
- }\r
-\r
- if (count($this->args) > 3) {\r
- throw new CommandArgsException('Too many arguments');\r
- }\r
-\r
- require_once '.htconfig.php';\r
- $result = dba::connect($db_host, $db_user, $db_pass, $db_data);\r
- unset($db_host, $db_user, $db_pass, $db_data);\r
-\r
- if (!$result) {\r
- throw new \RuntimeException('Unable to connect to database');\r
- }\r
-\r
- if (count($this->args) == 3) {\r
- Core\Config::set($this->getArgument(0), $this->getArgument(1), $this->getArgument(2));\r
- $this->out("config[{$this->getArgument(0)}][{$this->getArgument(1)}] = " . Core\Config::get($this->getArgument(0),\r
- $this->getArgument(1)));\r
- }\r
-\r
- if (count($this->args) == 2) {\r
- $this->out("config[{$this->getArgument(0)}][{$this->getArgument(1)}] = " . Core\Config::get($this->getArgument(0),\r
- $this->getArgument(1)));\r
- }\r
-\r
- if (count($this->args) == 1) {\r
- Core\Config::load($this->getArgument(0));\r
-\r
- $a = get_app();\r
- if (!is_null($a->config[$this->getArgument(0)])) {\r
- foreach ($a->config[$this->getArgument(0)] as $k => $x) {\r
- $this->out("config[{$this->getArgument(0)}][{$k}] = " . $x);\r
- }\r
- } else {\r
- $this->out('Config section ' . $this->getArgument(0) . ' returned nothing');\r
- }\r
- }\r
-\r
- if (count($this->args) == 0) {\r
- $configs = dba::select('config');\r
- foreach ($configs as $config) {\r
- $this->out("config[{$config['cat']}][{$config['k']}] = " . $config['v']);\r
- }\r
- }\r
-\r
- return 0;\r
- }\r
-\r
-}\r
+<?php
+
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+namespace Friendica\Core\Console;
+
+use Asika\SimpleConsole\CommandArgsException;
+use dba;
+use Friendica\Core;
+
+require_once 'include/dba.php';
+require_once 'include/text.php';
+
+/**
+ * @brief tool to access the system config from the CLI
+ *
+ * With this script you can access the system configuration of your node from
+ * the CLI. You can do both, reading current values stored in the database and
+ * set new values to config variables.
+ *
+ * Usage:
+ * If you specify no parameters at the CLI, the script will list all config
+ * variables defined.
+ *
+ * If you specify one parameter, the script will list all config variables
+ * defined in this section of the configuration (e.g. "system").
+ *
+ * If you specify two parameters, the script will show you the current value
+ * of the named configuration setting. (e.g. "system loglevel")
+ *
+ * If you specify three parameters, the named configuration setting will be
+ * set to the value of the last parameter. (e.g. "system loglevel 0" will
+ * disable logging)
+ *
+ * @author Tobias Diekershoff
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class Config extends \Asika\SimpleConsole\Console
+{
+ protected $helpOptions = ['h', 'help', '?'];
+
+ protected function getHelp()
+ {
+ $help = <<<HELP
+console config - Manage site configuration
+Synopsis
+ bin/console config [-h|--help|-?] [-v]
+ bin/console config <category> [-h|--help|-?] [-v]
+ bin/console config <category> <key> [-h|--help|-?] [-v]
+ bin/console config <category> <key> <value> [-h|--help|-?] [-v]
+
+Description
+ bin/console config
+ Lists all config values
+
+ bin/console config <category>
+ Lists all config values in the provided category
+
+ bin/console config <category> <key>
+ Shows the value of the provided key in the category
+
+ bin/console config <category> <key> <value>
+ Sets the value of the provided key in the category
+
+Notes:
+ Setting config entries which are manually set in .htconfig.php may result in
+ conflict between database settings and the manual startup settings.
+
+Options
+ -h|--help|-? Show help information
+ -v Show more debug information.
+HELP;
+ return $help;
+ }
+
+ protected function doExecute()
+ {
+ if ($this->getOption('v')) {
+ $this->out('Executable: ' . $this->executable);
+ $this->out('Class: ' . __CLASS__);
+ $this->out('Arguments: ' . var_export($this->args, true));
+ $this->out('Options: ' . var_export($this->options, true));
+ }
+
+ if (count($this->args) > 3) {
+ throw new CommandArgsException('Too many arguments');
+ }
+
+ require_once '.htconfig.php';
+ $result = dba::connect($db_host, $db_user, $db_pass, $db_data);
+ unset($db_host, $db_user, $db_pass, $db_data);
+
+ if (!$result) {
+ throw new \RuntimeException('Unable to connect to database');
+ }
+
+ if (count($this->args) == 3) {
+ Core\Config::set($this->getArgument(0), $this->getArgument(1), $this->getArgument(2));
+ $this->out("config[{$this->getArgument(0)}][{$this->getArgument(1)}] = " . Core\Config::get($this->getArgument(0),
+ $this->getArgument(1)));
+ }
+
+ if (count($this->args) == 2) {
+ $this->out("config[{$this->getArgument(0)}][{$this->getArgument(1)}] = " . Core\Config::get($this->getArgument(0),
+ $this->getArgument(1)));
+ }
+
+ if (count($this->args) == 1) {
+ Core\Config::load($this->getArgument(0));
+
+ $a = get_app();
+ if (!is_null($a->config[$this->getArgument(0)])) {
+ foreach ($a->config[$this->getArgument(0)] as $k => $x) {
+ $this->out("config[{$this->getArgument(0)}][{$k}] = " . $x);
+ }
+ } else {
+ $this->out('Config section ' . $this->getArgument(0) . ' returned nothing');
+ }
+ }
+
+ if (count($this->args) == 0) {
+ $configs = dba::select('config');
+ foreach ($configs as $config) {
+ $this->out("config[{$config['cat']}][{$config['k']}] = " . $config['v']);
+ }
+ }
+
+ return 0;
+ }
+
+}
-<?php\r
-\r
-namespace Friendica\Core\Console;\r
-\r
-/**\r
- * Description of CreateDoxygen\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class CreateDoxygen extends \Asika\SimpleConsole\Console\r
-{\r
- protected $helpOptions = ['h', 'help', '?'];\r
-\r
- protected function getHelp()\r
- {\r
- $help = <<<HELP\r
-console createdoxygen - Generate Doxygen headers\r
-Usage\r
- bin/console createdoxygen <file> [-h|--help|-?] [-v]\r
-\r
-Description\r
- Outputs the provided file with added Doxygen headers to functions\r
-\r
-Options\r
- -h|--help|-? Show help information\r
- -v Show more debug information.\r
-HELP;\r
- return $help;\r
- }\r
-\r
- protected function doExecute()\r
- {\r
- if ($this->getOption('v')) {\r
- $this->out('Class: ' . __CLASS__);\r
- $this->out('Arguments: ' . var_export($this->args, true));\r
- $this->out('Options: ' . var_export($this->options, true));\r
- }\r
-\r
- if (count($this->args) == 0) {\r
- $this->out($this->getHelp());\r
- return 0;\r
- }\r
-\r
- if (count($this->args) > 1) {\r
- throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');\r
- }\r
-\r
- $file = $this->getArgument(0);\r
- if (!file_exists($file)) {\r
- throw new \RuntimeException('Unable to find specified file.');\r
- }\r
-\r
- $data = file_get_contents($file);\r
-\r
- $lines = explode("\n", $data);\r
-\r
- $previous = "";\r
-\r
- foreach ($lines AS $line) {\r
- $line = rtrim(trim($line, "\r"));\r
-\r
- if (strstr(strtolower($line), "function")) {\r
- $detect = strtolower(trim($line));\r
- $detect = implode(" ", explode(" ", $detect));\r
-\r
- $found = false;\r
-\r
- if (substr($detect, 0, 9) == "function ") {\r
- $found = true;\r
- }\r
-\r
- if (substr($detect, 0, 19) == "protected function ") {\r
- $found = true;\r
- }\r
-\r
- if (substr($detect, 0, 17) == "private function ") {\r
- $found = true;\r
- }\r
-\r
- if (substr($detect, 0, 23) == "public static function ") {\r
- $found = true;\r
- }\r
-\r
- if (substr($detect, 0, 24) == "private static function ") {\r
- $found = true;\r
- }\r
-\r
- if (substr($detect, 0, 10) == "function (") {\r
- $found = false;\r
- }\r
-\r
- if ($found && ( trim($previous) == "*/")) {\r
- $found = false;\r
- }\r
-\r
- if ($found) {\r
- $this->out($this->addDocumentation($line));\r
- }\r
- }\r
- $this->out($line);\r
- $previous = $line;\r
- }\r
-\r
- return 0;\r
- }\r
-\r
- /**\r
- * @brief Adds a doxygen header\r
- *\r
- * @param string $line The current line of the document\r
- *\r
- * @return string added doxygen header\r
- */\r
- private function addDocumentation($line)\r
- {\r
- $trimmed = ltrim($line);\r
- $length = strlen($line) - strlen($trimmed);\r
- $space = substr($line, 0, $length);\r
-\r
- $block = $space . "/**\n" .\r
- $space . " * @brief \n" .\r
- $space . " *\n"; /**/\r
-\r
-\r
- $left = strpos($line, "(");\r
- $line = substr($line, $left + 1);\r
-\r
- $right = strpos($line, ")");\r
- $line = trim(substr($line, 0, $right));\r
-\r
- if ($line != "") {\r
- $parameters = explode(",", $line);\r
- foreach ($parameters AS $parameter) {\r
- $parameter = trim($parameter);\r
- $splitted = explode("=", $parameter);\r
-\r
- $block .= $space . " * @param " . trim($splitted[0], "& ") . "\n";\r
- }\r
- if (count($parameters) > 0) $block .= $space . " *\n";\r
- }\r
-\r
- $block .= $space . " * @return \n" .\r
- $space . " */\n";\r
-\r
- return $block;\r
- }\r
-\r
-}\r
+<?php
+
+namespace Friendica\Core\Console;
+
+/**
+ * Description of CreateDoxygen
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class CreateDoxygen extends \Asika\SimpleConsole\Console
+{
+ protected $helpOptions = ['h', 'help', '?'];
+
+ protected function getHelp()
+ {
+ $help = <<<HELP
+console createdoxygen - Generate Doxygen headers
+Usage
+ bin/console createdoxygen <file> [-h|--help|-?] [-v]
+
+Description
+ Outputs the provided file with added Doxygen headers to functions
+
+Options
+ -h|--help|-? Show help information
+ -v Show more debug information.
+HELP;
+ return $help;
+ }
+
+ protected function doExecute()
+ {
+ if ($this->getOption('v')) {
+ $this->out('Class: ' . __CLASS__);
+ $this->out('Arguments: ' . var_export($this->args, true));
+ $this->out('Options: ' . var_export($this->options, true));
+ }
+
+ if (count($this->args) == 0) {
+ $this->out($this->getHelp());
+ return 0;
+ }
+
+ if (count($this->args) > 1) {
+ throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
+ }
+
+ $file = $this->getArgument(0);
+ if (!file_exists($file)) {
+ throw new \RuntimeException('Unable to find specified file.');
+ }
+
+ $data = file_get_contents($file);
+
+ $lines = explode("\n", $data);
+
+ $previous = "";
+
+ foreach ($lines AS $line) {
+ $line = rtrim(trim($line, "\r"));
+
+ if (strstr(strtolower($line), "function")) {
+ $detect = strtolower(trim($line));
+ $detect = implode(" ", explode(" ", $detect));
+
+ $found = false;
+
+ if (substr($detect, 0, 9) == "function ") {
+ $found = true;
+ }
+
+ if (substr($detect, 0, 19) == "protected function ") {
+ $found = true;
+ }
+
+ if (substr($detect, 0, 17) == "private function ") {
+ $found = true;
+ }
+
+ if (substr($detect, 0, 23) == "public static function ") {
+ $found = true;
+ }
+
+ if (substr($detect, 0, 24) == "private static function ") {
+ $found = true;
+ }
+
+ if (substr($detect, 0, 10) == "function (") {
+ $found = false;
+ }
+
+ if ($found && ( trim($previous) == "*/")) {
+ $found = false;
+ }
+
+ if ($found) {
+ $this->out($this->addDocumentation($line));
+ }
+ }
+ $this->out($line);
+ $previous = $line;
+ }
+
+ return 0;
+ }
+
+ /**
+ * @brief Adds a doxygen header
+ *
+ * @param string $line The current line of the document
+ *
+ * @return string added doxygen header
+ */
+ private function addDocumentation($line)
+ {
+ $trimmed = ltrim($line);
+ $length = strlen($line) - strlen($trimmed);
+ $space = substr($line, 0, $length);
+
+ $block = $space . "/**\n" .
+ $space . " * @brief \n" .
+ $space . " *\n"; /**/
+
+
+ $left = strpos($line, "(");
+ $line = substr($line, $left + 1);
+
+ $right = strpos($line, ")");
+ $line = trim(substr($line, 0, $right));
+
+ if ($line != "") {
+ $parameters = explode(",", $line);
+ foreach ($parameters AS $parameter) {
+ $parameter = trim($parameter);
+ $splitted = explode("=", $parameter);
+
+ $block .= $space . " * @param " . trim($splitted[0], "& ") . "\n";
+ }
+ if (count($parameters) > 0) $block .= $space . " *\n";
+ }
+
+ $block .= $space . " * @return \n" .
+ $space . " */\n";
+
+ return $block;
+ }
+
+}
-<?php\r
-\r
-namespace Friendica\Core\Console;\r
-\r
-use Friendica\Core;\r
-use Friendica\Database\DBStructure;\r
-\r
-require_once 'boot.php';\r
-require_once 'include/dba.php';\r
-\r
-/**\r
- * @brief Does database updates from the command line\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class DatabaseStructure extends \Asika\SimpleConsole\Console\r
-{\r
- protected $helpOptions = ['h', 'help', '?'];\r
-\r
- protected function getHelp()\r
- {\r
- $help = <<<HELP\r
-console dbstructure - Does database updates\r
-Usage\r
- bin/console dbstructure <command> [-h|--help|-?] [-v]\r
-\r
-Commands\r
- dryrun Show database update schema queries without running them\r
- update Update database schema\r
- dumpsql Dump database schema\r
- toinnodb Convert all tables from MyISAM to InnoDB\r
-\r
-Options\r
- -h|--help|-? Show help information\r
- -v Show more debug information.\r
-HELP;\r
- return $help;\r
- }\r
-\r
- protected function doExecute()\r
- {\r
- if ($this->getOption('v')) {\r
- $this->out('Class: ' . __CLASS__);\r
- $this->out('Arguments: ' . var_export($this->args, true));\r
- $this->out('Options: ' . var_export($this->options, true));\r
- }\r
-\r
- if (count($this->args) == 0) {\r
- $this->out($this->getHelp());\r
- return 0;\r
- }\r
-\r
- if (count($this->args) > 1) {\r
- throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');\r
- }\r
-\r
- require_once '.htconfig.php';\r
- $result = \dba::connect($db_host, $db_user, $db_pass, $db_data);\r
- unset($db_host, $db_user, $db_pass, $db_data);\r
-\r
- if (!$result) {\r
- throw new \RuntimeException('Unable to connect to database');\r
- }\r
-\r
- Core\Config::load();\r
-\r
- switch ($this->getArgument(0)) {\r
- case "dryrun":\r
- $output = DBStructure::update(true, false);\r
- break;\r
- case "update":\r
- $output = DBStructure::update(true, true);\r
-\r
- $build = Core\Config::get('system', 'build');\r
- if (empty($build)) {\r
- Core\Config::set('system', 'build', DB_UPDATE_VERSION);\r
- $build = DB_UPDATE_VERSION;\r
- }\r
-\r
- $stored = intval($build);\r
- $current = intval(DB_UPDATE_VERSION);\r
-\r
- // run any left update_nnnn functions in update.php\r
- for ($x = $stored; $x < $current; $x ++) {\r
- $r = run_update_function($x);\r
- if (!$r) {\r
- break;\r
- }\r
- }\r
-\r
- Core\Config::set('system', 'build', DB_UPDATE_VERSION);\r
- break;\r
- case "dumpsql":\r
- ob_start();\r
- DBStructure::printStructure();\r
- $output = ob_get_clean();\r
- break;\r
- case "toinnodb":\r
- ob_start();\r
- DBStructure::convertToInnoDB();\r
- $output = ob_get_clean();\r
- break;\r
- }\r
-\r
- $this->out($output);\r
-\r
- return 0;\r
- }\r
-\r
-}\r
+<?php
+
+namespace Friendica\Core\Console;
+
+use Friendica\Core;
+use Friendica\Database\DBStructure;
+
+require_once 'boot.php';
+require_once 'include/dba.php';
+
+/**
+ * @brief Does database updates from the command line
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class DatabaseStructure extends \Asika\SimpleConsole\Console
+{
+ protected $helpOptions = ['h', 'help', '?'];
+
+ protected function getHelp()
+ {
+ $help = <<<HELP
+console dbstructure - Does database updates
+Usage
+ bin/console dbstructure <command> [-h|--help|-?] [-v]
+
+Commands
+ dryrun Show database update schema queries without running them
+ update Update database schema
+ dumpsql Dump database schema
+ toinnodb Convert all tables from MyISAM to InnoDB
+
+Options
+ -h|--help|-? Show help information
+ -v Show more debug information.
+HELP;
+ return $help;
+ }
+
+ protected function doExecute()
+ {
+ if ($this->getOption('v')) {
+ $this->out('Class: ' . __CLASS__);
+ $this->out('Arguments: ' . var_export($this->args, true));
+ $this->out('Options: ' . var_export($this->options, true));
+ }
+
+ if (count($this->args) == 0) {
+ $this->out($this->getHelp());
+ return 0;
+ }
+
+ if (count($this->args) > 1) {
+ throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
+ }
+
+ require_once '.htconfig.php';
+ $result = \dba::connect($db_host, $db_user, $db_pass, $db_data);
+ unset($db_host, $db_user, $db_pass, $db_data);
+
+ if (!$result) {
+ throw new \RuntimeException('Unable to connect to database');
+ }
+
+ Core\Config::load();
+
+ switch ($this->getArgument(0)) {
+ case "dryrun":
+ $output = DBStructure::update(true, false);
+ break;
+ case "update":
+ $output = DBStructure::update(true, true);
+
+ $build = Core\Config::get('system', 'build');
+ if (empty($build)) {
+ Core\Config::set('system', 'build', DB_UPDATE_VERSION);
+ $build = DB_UPDATE_VERSION;
+ }
+
+ $stored = intval($build);
+ $current = intval(DB_UPDATE_VERSION);
+
+ // run any left update_nnnn functions in update.php
+ for ($x = $stored; $x < $current; $x ++) {
+ $r = run_update_function($x);
+ if (!$r) {
+ break;
+ }
+ }
+
+ Core\Config::set('system', 'build', DB_UPDATE_VERSION);
+ break;
+ case "dumpsql":
+ ob_start();
+ DBStructure::printStructure();
+ $output = ob_get_clean();
+ break;
+ case "toinnodb":
+ ob_start();
+ DBStructure::convertToInnoDB();
+ $output = ob_get_clean();
+ break;
+ }
+
+ $this->out($output);
+
+ return 0;
+ }
+
+}
-<?php\r
-\r
-namespace Friendica\Core\Console;\r
-\r
-/**\r
- * When I installed docblox, I had the experience that it does not generate any output at all.\r
- * This script may be used to find that kind of problems with the documentation build process.\r
- * If docblox generates output, use another approach for debugging.\r
- *\r
- * Basically, docblox takes a list of files to build documentation from. This script assumes there is a file or set of files\r
- * breaking the build when it is included in that list. It tries to calculate the smallest list containing these files.\r
- * Unfortunatly, the original problem is NP-complete, so what the script does is a best guess only.\r
- *\r
- * So it starts with a list of all files in the project.\r
- * If that list can't be build, it cuts it in two parts and tries both parts independently. If only one of them breaks,\r
- * it takes that one and tries the same independently. If both break, it assumes this is the smallest set. This assumption\r
- * is not necessarily true. Maybe the smallest set consists of two files and both of them were in different parts when\r
- * the list was divided, but by now it is my best guess. To make this assumption better, the list is shuffled after every step.\r
- *\r
- * After that, the script tries to remove a file from the list. It tests if the list breaks and if so, it\r
- * assumes that the file it removed belongs to the set of erroneous files.\r
- * This is done for all files, so, in the end removing one file leads to a working doc build.\r
- *\r
- * @author Alexander Kampmann\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class DocBloxErrorChecker extends \Asika\SimpleConsole\Console\r
-{\r
-\r
- protected $helpOptions = ['h', 'help', '?'];\r
-\r
- protected function getHelp()\r
- {\r
- $help = <<<HELP\r
-console docbloxerrorchecker - Checks the file tree for docblox errors\r
-Usage\r
- bin/console docbloxerrorchecker [-h|--help|-?] [-v]\r
-\r
-Options\r
- -h|--help|-? Show help information\r
- -v Show more debug information.\r
-HELP;\r
- return $help;\r
- }\r
-\r
- protected function doExecute()\r
- {\r
- if ($this->getOption('v')) {\r
- $this->out('Class: ' . __CLASS__);\r
- $this->out('Arguments: ' . var_export($this->args, true));\r
- $this->out('Options: ' . var_export($this->options, true));\r
- }\r
-\r
- if (count($this->args) > 0) {\r
- throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');\r
- }\r
-\r
- if (!$this->commandExists('docblox')) {\r
- throw new \RuntimeException('DocBlox isn\'t available.');\r
- }\r
-\r
- //return from util folder to frindica base dir\r
- $dir = get_app()->get_basepath();\r
-\r
- //stack for dirs to search\r
- $dirstack = [];\r
- //list of source files\r
- $filelist = [];\r
-\r
- //loop over all files in $dir\r
- while ($dh = opendir($dir)) {\r
- while ($file = readdir($dh)) {\r
- if (is_dir($dir . "/" . $file)) {\r
- //add to directory stack\r
- if (strpos($file, '.') !== 0) {\r
- array_push($dirstack, $dir . "/" . $file);\r
- $this->out('dir ' . $dir . '/' . $file);\r
- }\r
- } else {\r
- //test if it is a source file and add to filelist\r
- if (substr($file, strlen($file) - 4) == ".php") {\r
- array_push($filelist, $dir . "/" . $file);\r
- $this->out($dir . '/' . $file);\r
- }\r
- }\r
- }\r
- //look at the next dir\r
- $dir = array_pop($dirstack);\r
- }\r
-\r
- //check the entire set\r
- if ($this->runs($filelist)) {\r
- throw new \RuntimeException("I can not detect a problem.");\r
- }\r
-\r
- //check half of the set and discard if that half is okay\r
- $res = $filelist;\r
- $i = count($res);\r
- do {\r
- $this->out($i . '/' . count($filelist) . ' elements remaining.');\r
- $res = $this->reduce($res, count($res) / 2);\r
- shuffle($res);\r
- $i = count($res);\r
- } while (count($res) < $i);\r
-\r
- //check one file after another\r
- $needed = [];\r
-\r
- while (count($res) != 0) {\r
- $file = array_pop($res);\r
-\r
- if ($this->runs(array_merge($res, $needed))) {\r
- $this->out('needs: ' . $file . ' and file count ' . count($needed));\r
- array_push($needed, $file);\r
- }\r
- }\r
-\r
- $this->out('Smallest Set is: ' . $this->namesList($needed) . ' with ' . count($needed) . ' files. ');\r
-\r
- return 0;\r
- }\r
-\r
- private function commandExists($command)\r
- {\r
- $prefix = strpos(strtolower(PHP_OS),'win') > -1 ? 'where' : 'which';\r
- exec("{$prefix} {$command}", $output, $returnVal);\r
- return $returnVal === 0;\r
- }\r
-\r
- /**\r
- * This function generates a comma separated list of file names.\r
- *\r
- * @package util\r
- *\r
- * @param array $fileset Set of file names\r
- *\r
- * @return string comma-separated list of the file names\r
- */\r
- private function namesList($fileset)\r
- {\r
- return implode(',', $fileset);\r
- }\r
-\r
- /**\r
- * This functions runs phpdoc on the provided list of files\r
- * @package util\r
- *\r
- * @param array $fileset Set of filenames\r
- *\r
- * @return bool true, if that set can be built\r
- */\r
- private function runs($fileset)\r
- {\r
- $fsParam = $this->namesList($fileset);\r
- $this->exec('docblox -t phpdoc_out -f ' . $fsParam);\r
- if (file_exists("phpdoc_out/index.html")) {\r
- $this->out('Subset ' . $fsParam . ' is okay.');\r
- $this->exec('rm -r phpdoc_out');\r
- return true;\r
- } else {\r
- $this->out('Subset ' . $fsParam . ' failed.');\r
- return false;\r
- }\r
- }\r
-\r
- /**\r
- * This functions cuts down a fileset by removing files until it finally works.\r
- * it was meant to be recursive, but php's maximum stack size is to small. So it just simulates recursion.\r
- *\r
- * In that version, it does not necessarily generate the smallest set, because it may not alter the elements order enough.\r
- *\r
- * @package util\r
- *\r
- * @param array $fileset set of filenames\r
- * @param int $ps number of files in subsets\r
- *\r
- * @return array a part of $fileset, that crashes\r
- */\r
- private function reduce($fileset, $ps)\r
- {\r
- //split array...\r
- $parts = array_chunk($fileset, $ps);\r
- //filter working subsets...\r
- $parts = array_filter($parts, [$this, 'runs']);\r
- //melt remaining parts together\r
- if (is_array($parts)) {\r
- return array_reduce($parts, "array_merge", []);\r
- }\r
- return [];\r
- }\r
-\r
-}\r
+<?php
+
+namespace Friendica\Core\Console;
+
+/**
+ * When I installed docblox, I had the experience that it does not generate any output at all.
+ * This script may be used to find that kind of problems with the documentation build process.
+ * If docblox generates output, use another approach for debugging.
+ *
+ * Basically, docblox takes a list of files to build documentation from. This script assumes there is a file or set of files
+ * breaking the build when it is included in that list. It tries to calculate the smallest list containing these files.
+ * Unfortunatly, the original problem is NP-complete, so what the script does is a best guess only.
+ *
+ * So it starts with a list of all files in the project.
+ * If that list can't be build, it cuts it in two parts and tries both parts independently. If only one of them breaks,
+ * it takes that one and tries the same independently. If both break, it assumes this is the smallest set. This assumption
+ * is not necessarily true. Maybe the smallest set consists of two files and both of them were in different parts when
+ * the list was divided, but by now it is my best guess. To make this assumption better, the list is shuffled after every step.
+ *
+ * After that, the script tries to remove a file from the list. It tests if the list breaks and if so, it
+ * assumes that the file it removed belongs to the set of erroneous files.
+ * This is done for all files, so, in the end removing one file leads to a working doc build.
+ *
+ * @author Alexander Kampmann
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class DocBloxErrorChecker extends \Asika\SimpleConsole\Console
+{
+
+ protected $helpOptions = ['h', 'help', '?'];
+
+ protected function getHelp()
+ {
+ $help = <<<HELP
+console docbloxerrorchecker - Checks the file tree for docblox errors
+Usage
+ bin/console docbloxerrorchecker [-h|--help|-?] [-v]
+
+Options
+ -h|--help|-? Show help information
+ -v Show more debug information.
+HELP;
+ return $help;
+ }
+
+ protected function doExecute()
+ {
+ if ($this->getOption('v')) {
+ $this->out('Class: ' . __CLASS__);
+ $this->out('Arguments: ' . var_export($this->args, true));
+ $this->out('Options: ' . var_export($this->options, true));
+ }
+
+ if (count($this->args) > 0) {
+ throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
+ }
+
+ if (!$this->commandExists('docblox')) {
+ throw new \RuntimeException('DocBlox isn\'t available.');
+ }
+
+ //return from util folder to frindica base dir
+ $dir = get_app()->get_basepath();
+
+ //stack for dirs to search
+ $dirstack = [];
+ //list of source files
+ $filelist = [];
+
+ //loop over all files in $dir
+ while ($dh = opendir($dir)) {
+ while ($file = readdir($dh)) {
+ if (is_dir($dir . "/" . $file)) {
+ //add to directory stack
+ if (strpos($file, '.') !== 0) {
+ array_push($dirstack, $dir . "/" . $file);
+ $this->out('dir ' . $dir . '/' . $file);
+ }
+ } else {
+ //test if it is a source file and add to filelist
+ if (substr($file, strlen($file) - 4) == ".php") {
+ array_push($filelist, $dir . "/" . $file);
+ $this->out($dir . '/' . $file);
+ }
+ }
+ }
+ //look at the next dir
+ $dir = array_pop($dirstack);
+ }
+
+ //check the entire set
+ if ($this->runs($filelist)) {
+ throw new \RuntimeException("I can not detect a problem.");
+ }
+
+ //check half of the set and discard if that half is okay
+ $res = $filelist;
+ $i = count($res);
+ do {
+ $this->out($i . '/' . count($filelist) . ' elements remaining.');
+ $res = $this->reduce($res, count($res) / 2);
+ shuffle($res);
+ $i = count($res);
+ } while (count($res) < $i);
+
+ //check one file after another
+ $needed = [];
+
+ while (count($res) != 0) {
+ $file = array_pop($res);
+
+ if ($this->runs(array_merge($res, $needed))) {
+ $this->out('needs: ' . $file . ' and file count ' . count($needed));
+ array_push($needed, $file);
+ }
+ }
+
+ $this->out('Smallest Set is: ' . $this->namesList($needed) . ' with ' . count($needed) . ' files. ');
+
+ return 0;
+ }
+
+ private function commandExists($command)
+ {
+ $prefix = strpos(strtolower(PHP_OS),'win') > -1 ? 'where' : 'which';
+ exec("{$prefix} {$command}", $output, $returnVal);
+ return $returnVal === 0;
+ }
+
+ /**
+ * This function generates a comma separated list of file names.
+ *
+ * @package util
+ *
+ * @param array $fileset Set of file names
+ *
+ * @return string comma-separated list of the file names
+ */
+ private function namesList($fileset)
+ {
+ return implode(',', $fileset);
+ }
+
+ /**
+ * This functions runs phpdoc on the provided list of files
+ * @package util
+ *
+ * @param array $fileset Set of filenames
+ *
+ * @return bool true, if that set can be built
+ */
+ private function runs($fileset)
+ {
+ $fsParam = $this->namesList($fileset);
+ $this->exec('docblox -t phpdoc_out -f ' . $fsParam);
+ if (file_exists("phpdoc_out/index.html")) {
+ $this->out('Subset ' . $fsParam . ' is okay.');
+ $this->exec('rm -r phpdoc_out');
+ return true;
+ } else {
+ $this->out('Subset ' . $fsParam . ' failed.');
+ return false;
+ }
+ }
+
+ /**
+ * This functions cuts down a fileset by removing files until it finally works.
+ * it was meant to be recursive, but php's maximum stack size is to small. So it just simulates recursion.
+ *
+ * In that version, it does not necessarily generate the smallest set, because it may not alter the elements order enough.
+ *
+ * @package util
+ *
+ * @param array $fileset set of filenames
+ * @param int $ps number of files in subsets
+ *
+ * @return array a part of $fileset, that crashes
+ */
+ private function reduce($fileset, $ps)
+ {
+ //split array...
+ $parts = array_chunk($fileset, $ps);
+ //filter working subsets...
+ $parts = array_filter($parts, [$this, 'runs']);
+ //melt remaining parts together
+ if (is_array($parts)) {
+ return array_reduce($parts, "array_merge", []);
+ }
+ return [];
+ }
+
+}
-<?php\r
-\r
-namespace Friendica\Core\Console;\r
-\r
-/**\r
- * Extracts translation strings from the Friendica project's files to be exported\r
- * to Transifex for translation.\r
- *\r
- * Outputs a PHP file with language strings used by Friendica\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class Extract extends \Asika\SimpleConsole\Console\r
-{\r
- protected $helpOptions = ['h', 'help', '?'];\r
-\r
- protected function getHelp()\r
- {\r
- $help = <<<HELP\r
-console extract - Generate translation string file for the Friendica project (deprecated)\r
-Usage\r
- bin/console extract [-h|--help|-?] [-v]\r
-\r
-Description\r
- This script was used to generate the translation string file to be exported to Transifex,\r
- please use bin/run_xgettext.sh instead\r
-\r
-Options\r
- -h|--help|-? Show help information\r
- -v Show more debug information.\r
-HELP;\r
- return $help;\r
- }\r
-\r
- protected function doExecute()\r
- {\r
- if ($this->getOption('v')) {\r
- $this->out('Class: ' . __CLASS__);\r
- $this->out('Arguments: ' . var_export($this->args, true));\r
- $this->out('Options: ' . var_export($this->options, true));\r
- }\r
-\r
- if (count($this->args) > 0) {\r
- throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');\r
- }\r
-\r
- $s = '<?php' . PHP_EOL;\r
- $s .= '\r
- function string_plural_select($n){\r
- return ($n != 1);\r
- }\r
-\r
- ';\r
-\r
- $arr = [];\r
-\r
- $files = array_merge(\r
- ['index.php', 'boot.php'],\r
- glob('mod/*'),\r
- glob('include/*'),\r
- glob('addon/*/*'),\r
- $this->globRecursive('src')\r
- );\r
-\r
- foreach ($files as $file) {\r
- $str = file_get_contents($file);\r
-\r
- $pat = '|L10n::t\(([^\)]*+)[\)]|';\r
- $patt = '|L10n::tt\(([^\)]*+)[\)]|';\r
-\r
- $matches = [];\r
- $matchestt = [];\r
-\r
- preg_match_all($pat, $str, $matches);\r
- preg_match_all($patt, $str, $matchestt);\r
-\r
- if (count($matches) || count($matchestt)) {\r
- $s .= '// ' . $file . PHP_EOL;\r
- }\r
-\r
- if (!empty($matches[1])) {\r
- foreach ($matches[1] as $long_match) {\r
- $match_arr = preg_split('/(?<=[\'"])\s*,/', $long_match);\r
- $match = $match_arr[0];\r
- if (!in_array($match, $arr)) {\r
- if (substr($match, 0, 1) == '$') {\r
- continue;\r
- }\r
-\r
- $arr[] = $match;\r
-\r
- $s .= '$a->strings[' . $match . '] = ' . $match . ';' . "\n";\r
- }\r
- }\r
- }\r
- if (!empty($matchestt[1])) {\r
- foreach ($matchestt[1] as $match) {\r
- $matchtkns = preg_split("|[ \t\r\n]*,[ \t\r\n]*|", $match);\r
- if (count($matchtkns) == 3 && !in_array($matchtkns[0], $arr)) {\r
- if (substr($matchtkns[1], 0, 1) == '$') {\r
- continue;\r
- }\r
-\r
- $arr[] = $matchtkns[0];\r
-\r
- $s .= '$a->strings[' . $matchtkns[0] . "] = array(\n";\r
- $s .= "\t0 => " . $matchtkns[0] . ",\n";\r
- $s .= "\t1 => " . $matchtkns[1] . ",\n";\r
- $s .= ");\n";\r
- }\r
- }\r
- }\r
- }\r
-\r
- $s .= '// Timezones' . PHP_EOL;\r
-\r
- $zones = timezone_identifiers_list();\r
- foreach ($zones as $zone) {\r
- $s .= '$a->strings[\'' . $zone . '\'] = \'' . $zone . '\';' . "\n";\r
- }\r
-\r
- $this->out($s);\r
-\r
- return 0;\r
- }\r
-\r
- private function globRecursive($path) {\r
- $dir_iterator = new \RecursiveDirectoryIterator($path);\r
- $iterator = new \RecursiveIteratorIterator($dir_iterator, \RecursiveIteratorIterator::SELF_FIRST);\r
-\r
- $return = [];\r
- foreach ($iterator as $file) {\r
- if ($file->getBasename() != '.' && $file->getBasename() != '..') {\r
- $return[] = $file->getPathname();\r
- }\r
- }\r
-\r
- return $return;\r
- }\r
-}\r
+<?php
+
+namespace Friendica\Core\Console;
+
+/**
+ * Extracts translation strings from the Friendica project's files to be exported
+ * to Transifex for translation.
+ *
+ * Outputs a PHP file with language strings used by Friendica
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class Extract extends \Asika\SimpleConsole\Console
+{
+ protected $helpOptions = ['h', 'help', '?'];
+
+ protected function getHelp()
+ {
+ $help = <<<HELP
+console extract - Generate translation string file for the Friendica project (deprecated)
+Usage
+ bin/console extract [-h|--help|-?] [-v]
+
+Description
+ This script was used to generate the translation string file to be exported to Transifex,
+ please use bin/run_xgettext.sh instead
+
+Options
+ -h|--help|-? Show help information
+ -v Show more debug information.
+HELP;
+ return $help;
+ }
+
+ protected function doExecute()
+ {
+ if ($this->getOption('v')) {
+ $this->out('Class: ' . __CLASS__);
+ $this->out('Arguments: ' . var_export($this->args, true));
+ $this->out('Options: ' . var_export($this->options, true));
+ }
+
+ if (count($this->args) > 0) {
+ throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
+ }
+
+ $s = '<?php' . PHP_EOL;
+ $s .= '
+ function string_plural_select($n){
+ return ($n != 1);
+ }
+
+ ';
+
+ $arr = [];
+
+ $files = array_merge(
+ ['index.php', 'boot.php'],
+ glob('mod/*'),
+ glob('include/*'),
+ glob('addon/*/*'),
+ $this->globRecursive('src')
+ );
+
+ foreach ($files as $file) {
+ $str = file_get_contents($file);
+
+ $pat = '|L10n::t\(([^\)]*+)[\)]|';
+ $patt = '|L10n::tt\(([^\)]*+)[\)]|';
+
+ $matches = [];
+ $matchestt = [];
+
+ preg_match_all($pat, $str, $matches);
+ preg_match_all($patt, $str, $matchestt);
+
+ if (count($matches) || count($matchestt)) {
+ $s .= '// ' . $file . PHP_EOL;
+ }
+
+ if (!empty($matches[1])) {
+ foreach ($matches[1] as $long_match) {
+ $match_arr = preg_split('/(?<=[\'"])\s*,/', $long_match);
+ $match = $match_arr[0];
+ if (!in_array($match, $arr)) {
+ if (substr($match, 0, 1) == '$') {
+ continue;
+ }
+
+ $arr[] = $match;
+
+ $s .= '$a->strings[' . $match . '] = ' . $match . ';' . "\n";
+ }
+ }
+ }
+ if (!empty($matchestt[1])) {
+ foreach ($matchestt[1] as $match) {
+ $matchtkns = preg_split("|[ \t\r\n]*,[ \t\r\n]*|", $match);
+ if (count($matchtkns) == 3 && !in_array($matchtkns[0], $arr)) {
+ if (substr($matchtkns[1], 0, 1) == '$') {
+ continue;
+ }
+
+ $arr[] = $matchtkns[0];
+
+ $s .= '$a->strings[' . $matchtkns[0] . "] = array(\n";
+ $s .= "\t0 => " . $matchtkns[0] . ",\n";
+ $s .= "\t1 => " . $matchtkns[1] . ",\n";
+ $s .= ");\n";
+ }
+ }
+ }
+ }
+
+ $s .= '// Timezones' . PHP_EOL;
+
+ $zones = timezone_identifiers_list();
+ foreach ($zones as $zone) {
+ $s .= '$a->strings[\'' . $zone . '\'] = \'' . $zone . '\';' . "\n";
+ }
+
+ $this->out($s);
+
+ return 0;
+ }
+
+ private function globRecursive($path) {
+ $dir_iterator = new \RecursiveDirectoryIterator($path);
+ $iterator = new \RecursiveIteratorIterator($dir_iterator, \RecursiveIteratorIterator::SELF_FIRST);
+
+ $return = [];
+ foreach ($iterator as $file) {
+ if ($file->getBasename() != '.' && $file->getBasename() != '..') {
+ $return[] = $file->getPathname();
+ }
+ }
+
+ return $return;
+ }
+}
-<?php\r
-\r
-namespace Friendica\Core\Console;\r
-\r
-use Friendica\Core\L10n;\r
-use Friendica\Model\Contact;\r
-\r
-/**\r
- * @brief tool to block an account from the node\r
- *\r
- * With this tool, you can block an account in such a way, that no postings\r
- * or comments this account writes are accepted to the node.\r
- *\r
- * License: AGPLv3 or later, same as Friendica\r
- *\r
- * @author Tobias Diekershoff <mrpetovan@gmail.com>\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class GlobalCommunityBlock extends \Asika\SimpleConsole\Console\r
-{\r
- protected $helpOptions = ['h', 'help', '?'];\r
-\r
- protected function getHelp()\r
- {\r
- $help = <<<HELP\r
-console globalcommunityblock - Block remote profile from interacting with this node\r
-Usage\r
- bin/console globalcommunityblock <profile_url> [-h|--help|-?] [-v]\r
-\r
-Description\r
- Blocks an account in such a way that no postings or comments this account writes are accepted to this node.\r
-\r
-Options\r
- -h|--help|-? Show help information\r
- -v Show more debug information.\r
-HELP;\r
- return $help;\r
- }\r
-\r
- protected function doExecute()\r
- {\r
- if ($this->getOption('v')) {\r
- $this->out('Class: ' . __CLASS__);\r
- $this->out('Arguments: ' . var_export($this->args, true));\r
- $this->out('Options: ' . var_export($this->options, true));\r
- }\r
-\r
- if (count($this->args) == 0) {\r
- $this->out($this->getHelp());\r
- return 0;\r
- }\r
-\r
- if (count($this->args) > 1) {\r
- throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');\r
- }\r
-\r
- require_once '.htconfig.php';\r
- $result = \dba::connect($db_host, $db_user, $db_pass, $db_data);\r
- unset($db_host, $db_user, $db_pass, $db_data);\r
-\r
- if (!$result) {\r
- throw new \RuntimeException('Unable to connect to database');\r
- }\r
-\r
- $contact_id = Contact::getIdForURL($this->getArgument(0));\r
- if (!$contact_id) {\r
- throw new \RuntimeException(L10n::t('Could not find any contact entry for this URL (%s)', $nurl));\r
- }\r
- if(Contact::block($contact_id)) {\r
- $this->out(L10n::t('The contact has been blocked from the node'));\r
- } else {\r
- throw new \RuntimeException('The contact block failed.');\r
- }\r
-\r
- return 0;\r
- }\r
-}\r
+<?php
+
+namespace Friendica\Core\Console;
+
+use Friendica\Core\L10n;
+use Friendica\Model\Contact;
+
+/**
+ * @brief tool to block an account from the node
+ *
+ * With this tool, you can block an account in such a way, that no postings
+ * or comments this account writes are accepted to the node.
+ *
+ * License: AGPLv3 or later, same as Friendica
+ *
+ * @author Tobias Diekershoff <mrpetovan@gmail.com>
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class GlobalCommunityBlock extends \Asika\SimpleConsole\Console
+{
+ protected $helpOptions = ['h', 'help', '?'];
+
+ protected function getHelp()
+ {
+ $help = <<<HELP
+console globalcommunityblock - Block remote profile from interacting with this node
+Usage
+ bin/console globalcommunityblock <profile_url> [-h|--help|-?] [-v]
+
+Description
+ Blocks an account in such a way that no postings or comments this account writes are accepted to this node.
+
+Options
+ -h|--help|-? Show help information
+ -v Show more debug information.
+HELP;
+ return $help;
+ }
+
+ protected function doExecute()
+ {
+ if ($this->getOption('v')) {
+ $this->out('Class: ' . __CLASS__);
+ $this->out('Arguments: ' . var_export($this->args, true));
+ $this->out('Options: ' . var_export($this->options, true));
+ }
+
+ if (count($this->args) == 0) {
+ $this->out($this->getHelp());
+ return 0;
+ }
+
+ if (count($this->args) > 1) {
+ throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
+ }
+
+ require_once '.htconfig.php';
+ $result = \dba::connect($db_host, $db_user, $db_pass, $db_data);
+ unset($db_host, $db_user, $db_pass, $db_data);
+
+ if (!$result) {
+ throw new \RuntimeException('Unable to connect to database');
+ }
+
+ $contact_id = Contact::getIdForURL($this->getArgument(0));
+ if (!$contact_id) {
+ throw new \RuntimeException(L10n::t('Could not find any contact entry for this URL (%s)', $nurl));
+ }
+ if(Contact::block($contact_id)) {
+ $this->out(L10n::t('The contact has been blocked from the node'));
+ } else {
+ throw new \RuntimeException('The contact block failed.');
+ }
+
+ return 0;
+ }
+}
-<?php\r
-\r
-namespace Friendica\Core\Console;\r
-\r
-use Friendica\Core\Protocol;\r
-use Friendica\Database\DBM;\r
-use Friendica\Network\Probe;\r
-\r
-require_once 'include/text.php';\r
-\r
-/**\r
- * @brief tool to silence accounts on the global community page\r
- *\r
- * With this tool, you can silence an account on the global community page.\r
- * Postings from silenced accounts will not be displayed on the community\r
- * page. This silencing does only affect the display on the community page,\r
- * accounts following the silenced accounts will still get their postings.\r
- *\r
- * License: AGPLv3 or later, same as Friendica\r
- *\r
- * @author Tobias Diekershoff\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class GlobalCommunitySilence extends \Asika\SimpleConsole\Console\r
-{\r
- protected $helpOptions = ['h', 'help', '?'];\r
-\r
- protected function getHelp()\r
- {\r
- $help = <<<HELP\r
-console globalcommunitysilence - Silence remote profile from global community page\r
-Usage\r
- bin/console globalcommunitysilence <profile_url> [-h|--help|-?] [-v]\r
-\r
-Description\r
- With this tool, you can silence an account on the global community page.\r
- Postings from silenced accounts will not be displayed on the community page.\r
- This silencing does only affect the display on the community page, accounts\r
- following the silenced accounts will still get their postings.\r
-\r
-Options\r
- -h|--help|-? Show help information\r
- -v Show more debug information.\r
-HELP;\r
- return $help;\r
- }\r
-\r
- protected function doExecute()\r
- {\r
- if ($this->getOption('v')) {\r
- $this->out('Class: ' . __CLASS__);\r
- $this->out('Arguments: ' . var_export($this->args, true));\r
- $this->out('Options: ' . var_export($this->options, true));\r
- }\r
-\r
- if (count($this->args) == 0) {\r
- $this->out($this->getHelp());\r
- return 0;\r
- }\r
-\r
- if (count($this->args) > 1) {\r
- throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');\r
- }\r
-\r
- require_once '.htconfig.php';\r
- $result = \dba::connect($db_host, $db_user, $db_pass, $db_data);\r
- unset($db_host, $db_user, $db_pass, $db_data);\r
-\r
- if (!$result) {\r
- throw new \RuntimeException('Unable to connect to database');\r
- }\r
-\r
- /**\r
- * 1. make nurl from last parameter\r
- * 2. check DB (contact) if there is a contact with uid=0 and that nurl, get the ID\r
- * 3. set the flag hidden=1 for the contact entry with the found ID\r
- * */\r
- $net = Probe::uri($this->getArgument(0));\r
- if (in_array($net['network'], [Protocol::PHANTOM, Protocol::MAIL])) {\r
- throw new \RuntimeException('This account seems not to exist.');\r
- }\r
-\r
- $nurl = normalise_link($net['url']);\r
- $contact = \dba::selectFirst("contact", ["id"], ["nurl" => $nurl, "uid" => 0]);\r
- if (DBM::is_result($contact)) {\r
- \dba::update("contact", ["hidden" => true], ["id" => $contact["id"]]);\r
- $this->out('NOTICE: The account should be silenced from the global community page');\r
- } else {\r
- throw new \RuntimeException('NOTICE: Could not find any entry for this URL (' . $nurl . ')');\r
- }\r
-\r
- return 0;\r
- }\r
-}\r
+<?php
+
+namespace Friendica\Core\Console;
+
+use Friendica\Core\Protocol;
+use Friendica\Database\DBM;
+use Friendica\Network\Probe;
+
+require_once 'include/text.php';
+
+/**
+ * @brief tool to silence accounts on the global community page
+ *
+ * With this tool, you can silence an account on the global community page.
+ * Postings from silenced accounts will not be displayed on the community
+ * page. This silencing does only affect the display on the community page,
+ * accounts following the silenced accounts will still get their postings.
+ *
+ * License: AGPLv3 or later, same as Friendica
+ *
+ * @author Tobias Diekershoff
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class GlobalCommunitySilence extends \Asika\SimpleConsole\Console
+{
+ protected $helpOptions = ['h', 'help', '?'];
+
+ protected function getHelp()
+ {
+ $help = <<<HELP
+console globalcommunitysilence - Silence remote profile from global community page
+Usage
+ bin/console globalcommunitysilence <profile_url> [-h|--help|-?] [-v]
+
+Description
+ With this tool, you can silence an account on the global community page.
+ Postings from silenced accounts will not be displayed on the community page.
+ This silencing does only affect the display on the community page, accounts
+ following the silenced accounts will still get their postings.
+
+Options
+ -h|--help|-? Show help information
+ -v Show more debug information.
+HELP;
+ return $help;
+ }
+
+ protected function doExecute()
+ {
+ if ($this->getOption('v')) {
+ $this->out('Class: ' . __CLASS__);
+ $this->out('Arguments: ' . var_export($this->args, true));
+ $this->out('Options: ' . var_export($this->options, true));
+ }
+
+ if (count($this->args) == 0) {
+ $this->out($this->getHelp());
+ return 0;
+ }
+
+ if (count($this->args) > 1) {
+ throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
+ }
+
+ require_once '.htconfig.php';
+ $result = \dba::connect($db_host, $db_user, $db_pass, $db_data);
+ unset($db_host, $db_user, $db_pass, $db_data);
+
+ if (!$result) {
+ throw new \RuntimeException('Unable to connect to database');
+ }
+
+ /**
+ * 1. make nurl from last parameter
+ * 2. check DB (contact) if there is a contact with uid=0 and that nurl, get the ID
+ * 3. set the flag hidden=1 for the contact entry with the found ID
+ * */
+ $net = Probe::uri($this->getArgument(0));
+ if (in_array($net['network'], [Protocol::PHANTOM, Protocol::MAIL])) {
+ throw new \RuntimeException('This account seems not to exist.');
+ }
+
+ $nurl = normalise_link($net['url']);
+ $contact = \dba::selectFirst("contact", ["id"], ["nurl" => $nurl, "uid" => 0]);
+ if (DBM::is_result($contact)) {
+ \dba::update("contact", ["hidden" => true], ["id" => $contact["id"]]);
+ $this->out('NOTICE: The account should be silenced from the global community page');
+ } else {
+ throw new \RuntimeException('NOTICE: Could not find any entry for this URL (' . $nurl . ')');
+ }
+
+ return 0;
+ }
+}
-<?php\r
-\r
-namespace Friendica\Core\Console;\r
-\r
-use Friendica\Core;\r
-\r
-require_once 'boot.php';\r
-require_once 'include/dba.php';\r
-\r
-/**\r
- * @brief Sets maintenance mode for this node\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class Maintenance extends \Asika\SimpleConsole\Console\r
-{\r
- protected $helpOptions = ['h', 'help', '?'];\r
-\r
- protected function getHelp()\r
- {\r
- $help = <<<HELP\r
-console maintenance - Sets maintenance mode for this node\r
-Usage\r
- bin/console maintenance <enable> [<reason>] [-h|--help|-?] [-v]\r
-\r
-Description\r
- <enable> cen be either 0 or 1 to disabled or enable the maintenance mode on this node.\r
-\r
- <reason> is a quote-enclosed string with the optional reason for the maintenance mode.\r
-\r
-Examples\r
- bin/console maintenance 1\r
- Enables the maintenance mode without setting a reason message\r
-\r
- bin/console maintenance 1 "SSL certification update"\r
- Enables the maintenance mode with setting a reason message\r
-\r
- bin/console maintenance 0\r
- Disables the maintenance mode\r
-\r
-Options\r
- -h|--help|-? Show help information\r
- -v Show more debug information.\r
-HELP;\r
- return $help;\r
- }\r
-\r
- protected function doExecute()\r
- {\r
- if ($this->getOption('v')) {\r
- $this->out('Class: ' . __CLASS__);\r
- $this->out('Arguments: ' . var_export($this->args, true));\r
- $this->out('Options: ' . var_export($this->options, true));\r
- }\r
-\r
- if (count($this->args) == 0) {\r
- $this->out($this->getHelp());\r
- return 0;\r
- }\r
-\r
- if (count($this->args) > 2) {\r
- throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');\r
- }\r
-\r
- require_once '.htconfig.php';\r
- $result = \dba::connect($db_host, $db_user, $db_pass, $db_data);\r
- unset($db_host, $db_user, $db_pass, $db_data);\r
-\r
- if (!$result) {\r
- throw new \RuntimeException('Unable to connect to database');\r
- }\r
-\r
- Core\Config::load();\r
-\r
- $lang = Core\L10n::getBrowserLanguage();\r
- Core\L10n::loadTranslationTable($lang);\r
-\r
- $enabled = intval($this->getArgument(0));\r
-\r
- Core\Config::set('system', 'maintenance', $enabled);\r
-\r
- $reason = $this->getArgument(1);\r
-\r
- if ($enabled && $this->getArgument(1)) {\r
- Core\Config::set('system', 'maintenance_reason', $this->getArgument(1));\r
- } else {\r
- Core\Config::set('system', 'maintenance_reason', '');\r
- }\r
-\r
- if ($enabled) {\r
- $mode_str = "maintenance mode";\r
- } else {\r
- $mode_str = "normal mode";\r
- }\r
-\r
- $this->out('System set in ' . $mode_str);\r
-\r
- if ($enabled && $reason != '') {\r
- $this->out('Maintenance reason: ' . $reason);\r
- }\r
-\r
- return 0;\r
- }\r
-\r
-}\r
+<?php
+
+namespace Friendica\Core\Console;
+
+use Friendica\Core;
+
+require_once 'boot.php';
+require_once 'include/dba.php';
+
+/**
+ * @brief Sets maintenance mode for this node
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class Maintenance extends \Asika\SimpleConsole\Console
+{
+ protected $helpOptions = ['h', 'help', '?'];
+
+ protected function getHelp()
+ {
+ $help = <<<HELP
+console maintenance - Sets maintenance mode for this node
+Usage
+ bin/console maintenance <enable> [<reason>] [-h|--help|-?] [-v]
+
+Description
+ <enable> cen be either 0 or 1 to disabled or enable the maintenance mode on this node.
+
+ <reason> is a quote-enclosed string with the optional reason for the maintenance mode.
+
+Examples
+ bin/console maintenance 1
+ Enables the maintenance mode without setting a reason message
+
+ bin/console maintenance 1 "SSL certification update"
+ Enables the maintenance mode with setting a reason message
+
+ bin/console maintenance 0
+ Disables the maintenance mode
+
+Options
+ -h|--help|-? Show help information
+ -v Show more debug information.
+HELP;
+ return $help;
+ }
+
+ protected function doExecute()
+ {
+ if ($this->getOption('v')) {
+ $this->out('Class: ' . __CLASS__);
+ $this->out('Arguments: ' . var_export($this->args, true));
+ $this->out('Options: ' . var_export($this->options, true));
+ }
+
+ if (count($this->args) == 0) {
+ $this->out($this->getHelp());
+ return 0;
+ }
+
+ if (count($this->args) > 2) {
+ throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
+ }
+
+ require_once '.htconfig.php';
+ $result = \dba::connect($db_host, $db_user, $db_pass, $db_data);
+ unset($db_host, $db_user, $db_pass, $db_data);
+
+ if (!$result) {
+ throw new \RuntimeException('Unable to connect to database');
+ }
+
+ Core\Config::load();
+
+ $lang = Core\L10n::getBrowserLanguage();
+ Core\L10n::loadTranslationTable($lang);
+
+ $enabled = intval($this->getArgument(0));
+
+ Core\Config::set('system', 'maintenance', $enabled);
+
+ $reason = $this->getArgument(1);
+
+ if ($enabled && $this->getArgument(1)) {
+ Core\Config::set('system', 'maintenance_reason', $this->getArgument(1));
+ } else {
+ Core\Config::set('system', 'maintenance_reason', '');
+ }
+
+ if ($enabled) {
+ $mode_str = "maintenance mode";
+ } else {
+ $mode_str = "normal mode";
+ }
+
+ $this->out('System set in ' . $mode_str);
+
+ if ($enabled && $reason != '') {
+ $this->out('Maintenance reason: ' . $reason);
+ }
+
+ return 0;
+ }
+
+}
-<?php\r
-\r
-namespace Friendica\Core\Console;\r
-\r
-/**\r
- * Read a strings.php file and create messages.po in the same directory\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class PhpToPo extends \Asika\SimpleConsole\Console\r
-{\r
-\r
- protected $helpOptions = ['h', 'help', '?'];\r
-\r
- private $normBaseMsgIds = [];\r
- const NORM_REGEXP = "|[\\\]|";\r
-\r
- protected function getHelp()\r
- {\r
- $help = <<<HELP\r
-console php2po - Generate a messages.po file from a strings.php file\r
-Usage\r
- bin/console php2po [-p <n>] [--base <file>] <path/to/strings.php> [-h|--help|-?] [-v]\r
-\r
-Description\r
- Read a strings.php file and create the according messages.po in the same directory\r
-\r
-Options\r
- -p <n> Number of plural forms. Default: 2\r
- --base <file> Path to base messages.po file. Default: util/messages.po\r
- -h|--help|-? Show help information\r
- -v Show more debug information.\r
-HELP;\r
- return $help;\r
- }\r
-\r
- protected function doExecute()\r
- {\r
- if ($this->getOption('v')) {\r
- $this->out('Class: ' . __CLASS__);\r
- $this->out('Arguments: ' . var_export($this->args, true));\r
- $this->out('Options: ' . var_export($this->options, true));\r
- }\r
-\r
- if (count($this->args) == 0) {\r
- $this->out($this->getHelp());\r
- return 0;\r
- }\r
-\r
- if (count($this->args) > 1) {\r
- throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');\r
- }\r
-\r
- $a = get_app();\r
-\r
- $phpfile = realpath($this->getArgument(0));\r
-\r
- if (!file_exists($phpfile)) {\r
- throw new \RuntimeException('Supplied file path doesn\'t exist.');\r
- }\r
-\r
- if (!is_writable(dirname($phpfile))) {\r
- throw new \RuntimeException('Supplied directory isn\'t writable.');\r
- }\r
-\r
- $pofile = dirname($phpfile) . DIRECTORY_SEPARATOR . 'messages.po';\r
-\r
- // start !\r
- include_once($phpfile);\r
-\r
- $out = '';\r
- $out .= "# FRIENDICA Distributed Social Network\n";\r
- $out .= "# Copyright (C) 2010, 2011, 2012, 2013 the Friendica Project\n";\r
- $out .= "# This file is distributed under the same license as the Friendica package.\n";\r
- $out .= "# \n";\r
- $out .= 'msgid ""' . "\n";\r
- $out .= 'msgstr ""' . "\n";\r
- $out .= '"Project-Id-Version: friendica\n"' . "\n";\r
- $out .= '"Report-Msgid-Bugs-To: \n"' . "\n";\r
- $out .= '"POT-Creation-Date: ' . date("Y-m-d H:i:sO") . '\n"' . "\n";\r
- $out .= '"MIME-Version: 1.0\n"' . "\n";\r
- $out .= '"Content-Type: text/plain; charset=UTF-8\n"' . "\n";\r
- $out .= '"Content-Transfer-Encoding: 8bit\n"' . "\n";\r
-\r
- // search for plural info\r
- $lang = "";\r
- $lang_logic = "";\r
- $lang_pnum = $this->getOption('p', 2);\r
-\r
- $infile = file($phpfile);\r
- foreach ($infile as $l) {\r
- $l = trim($l);\r
- if ($this->startsWith($l, 'function string_plural_select_')) {\r
- $lang = str_replace('function string_plural_select_', '', str_replace('($n){', '', $l));\r
- }\r
- if ($this->startsWith($l, 'return')) {\r
- $lang_logic = str_replace('$', '', trim(str_replace('return ', '', $l), ';'));\r
- break;\r
- }\r
- }\r
-\r
- $this->out('Language: ' . $lang);\r
- $this->out('Plural forms: ' . $lang_pnum);\r
- $this->out('Plural forms: ' . $lang_logic);\r
-\r
- $out .= sprintf('"Language: %s\n"', $lang) . "\n";\r
- $out .= sprintf('"Plural-Forms: nplurals=%s; plural=%s;\n"', $lang_pnum, $lang_logic) . "\n";\r
- $out .= "\n";\r
-\r
- $base_path = $this->getOption('base', 'util' . DIRECTORY_SEPARATOR . 'messages.po');\r
-\r
- // load base messages.po and extract msgids\r
- $base_msgids = [];\r
- $base_f = file($base_path);\r
- if (!$base_f) {\r
- throw new \RuntimeException('The base ' . $base_path . ' file is missing or unavailable to read.');\r
- }\r
-\r
- $this->out('Loading base file ' . $base_path . '...');\r
-\r
- $_f = 0;\r
- $_mid = "";\r
- $_mids = [];\r
- foreach ($base_f as $l) {\r
- $l = trim($l);\r
-\r
- if ($this->startsWith($l, 'msgstr')) {\r
- if ($_mid != '""') {\r
- $base_msgids[$_mid] = $_mids;\r
- $this->normBaseMsgIds[preg_replace(self::NORM_REGEXP, "", $_mid)] = $_mid;\r
- }\r
-\r
- $_f = 0;\r
- $_mid = "";\r
- $_mids = [];\r
- }\r
-\r
- if ($this->startsWith($l, '"') && $_f == 2) {\r
- $_mids[count($_mids) - 1] .= "\n" . $l;\r
- }\r
- if ($this->startsWith($l, 'msgid_plural ')) {\r
- $_f = 2;\r
- $_mids[] = str_replace('msgid_plural ', '', $l);\r
- }\r
-\r
- if ($this->startsWith($l, '"') && $_f == 1) {\r
- $_mid .= "\n" . $l;\r
- $_mids[count($_mids) - 1] .= "\n" . $l;\r
- }\r
- if ($this->startsWith($l, 'msgid ')) {\r
- $_f = 1;\r
- $_mid = str_replace('msgid ', '', $l);\r
- $_mids = [$_mid];\r
- }\r
- }\r
-\r
- $this->out('Creating ' . $pofile . '...');\r
-\r
- // create msgid and msgstr\r
- $warnings = "";\r
- foreach ($a->strings as $key => $str) {\r
- $msgid = $this->massageString($key);\r
-\r
- if (preg_match("|%[sd0-9](\$[sn])*|", $msgid)) {\r
- $out .= "#, php-format\n";\r
- }\r
- $msgid = $this->findOriginalMsgId($msgid);\r
- $out .= 'msgid ' . $msgid . "\n";\r
-\r
- if (is_array($str)) {\r
- if (array_key_exists($msgid, $base_msgids) && isset($base_msgids[$msgid][1])) {\r
- $out .= 'msgid_plural ' . $base_msgids[$msgid][1] . "\n";\r
- } else {\r
- $out .= 'msgid_plural ' . $msgid . "\n";\r
- $warnings .= "[W] No source plural form for msgid:\n" . str_replace("\n", "\n\t", $msgid) . "\n\n";\r
- }\r
- foreach ($str as $n => $msgstr) {\r
- $out .= 'msgstr[' . $n . '] ' . $this->massageString($msgstr) . "\n";\r
- }\r
- } else {\r
- $out .= 'msgstr ' . $this->massageString($str) . "\n";\r
- }\r
-\r
- $out .= "\n";\r
- }\r
-\r
- if (!file_put_contents($pofile, $out)) {\r
- throw new \RuntimeException('Unable to write to ' . $pofile);\r
- }\r
-\r
- if ($warnings != '') {\r
- $this->out($warnings);\r
- }\r
-\r
- return 0;\r
- }\r
-\r
- private function startsWith($haystack, $needle)\r
- {\r
- // search backwards starting from haystack length characters from the end\r
- return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE;\r
- }\r
-\r
- /**\r
- * Get a string and retun a message.po ready text\r
- * - replace " with \"\r
- * - replace tab char with \t\r
- * - manage multiline strings\r
- */\r
- private function massageString($str)\r
- {\r
- $str = str_replace('\\', '\\\\', $str);\r
- $str = str_replace('"', '\"', $str);\r
- $str = str_replace("\t", '\t', $str);\r
- $str = str_replace("\n", '\n"' . "\n" . '"', $str);\r
- if (strpos($str, "\n") !== false && $str[0] !== '"') {\r
- $str = '"' . "\n" . $str;\r
- }\r
-\r
- $str = preg_replace("|\n([^\"])|", "\n\"$1", $str);\r
- return sprintf('"%s"', $str);\r
- }\r
-\r
- private function findOriginalMsgId($str)\r
- {\r
- $norm_str = preg_replace(self::NORM_REGEXP, "", $str);\r
- if (array_key_exists($norm_str, $this->normBaseMsgIds)) {\r
- return $this->normBaseMsgIds[$norm_str];\r
- }\r
-\r
- return $str;\r
- }\r
-\r
-}\r
+<?php
+
+namespace Friendica\Core\Console;
+
+/**
+ * Read a strings.php file and create messages.po in the same directory
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class PhpToPo extends \Asika\SimpleConsole\Console
+{
+
+ protected $helpOptions = ['h', 'help', '?'];
+
+ private $normBaseMsgIds = [];
+ const NORM_REGEXP = "|[\\\]|";
+
+ protected function getHelp()
+ {
+ $help = <<<HELP
+console php2po - Generate a messages.po file from a strings.php file
+Usage
+ bin/console php2po [-p <n>] [--base <file>] <path/to/strings.php> [-h|--help|-?] [-v]
+
+Description
+ Read a strings.php file and create the according messages.po in the same directory
+
+Options
+ -p <n> Number of plural forms. Default: 2
+ --base <file> Path to base messages.po file. Default: util/messages.po
+ -h|--help|-? Show help information
+ -v Show more debug information.
+HELP;
+ return $help;
+ }
+
+ protected function doExecute()
+ {
+ if ($this->getOption('v')) {
+ $this->out('Class: ' . __CLASS__);
+ $this->out('Arguments: ' . var_export($this->args, true));
+ $this->out('Options: ' . var_export($this->options, true));
+ }
+
+ if (count($this->args) == 0) {
+ $this->out($this->getHelp());
+ return 0;
+ }
+
+ if (count($this->args) > 1) {
+ throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
+ }
+
+ $a = get_app();
+
+ $phpfile = realpath($this->getArgument(0));
+
+ if (!file_exists($phpfile)) {
+ throw new \RuntimeException('Supplied file path doesn\'t exist.');
+ }
+
+ if (!is_writable(dirname($phpfile))) {
+ throw new \RuntimeException('Supplied directory isn\'t writable.');
+ }
+
+ $pofile = dirname($phpfile) . DIRECTORY_SEPARATOR . 'messages.po';
+
+ // start !
+ include_once($phpfile);
+
+ $out = '';
+ $out .= "# FRIENDICA Distributed Social Network\n";
+ $out .= "# Copyright (C) 2010, 2011, 2012, 2013 the Friendica Project\n";
+ $out .= "# This file is distributed under the same license as the Friendica package.\n";
+ $out .= "# \n";
+ $out .= 'msgid ""' . "\n";
+ $out .= 'msgstr ""' . "\n";
+ $out .= '"Project-Id-Version: friendica\n"' . "\n";
+ $out .= '"Report-Msgid-Bugs-To: \n"' . "\n";
+ $out .= '"POT-Creation-Date: ' . date("Y-m-d H:i:sO") . '\n"' . "\n";
+ $out .= '"MIME-Version: 1.0\n"' . "\n";
+ $out .= '"Content-Type: text/plain; charset=UTF-8\n"' . "\n";
+ $out .= '"Content-Transfer-Encoding: 8bit\n"' . "\n";
+
+ // search for plural info
+ $lang = "";
+ $lang_logic = "";
+ $lang_pnum = $this->getOption('p', 2);
+
+ $infile = file($phpfile);
+ foreach ($infile as $l) {
+ $l = trim($l);
+ if ($this->startsWith($l, 'function string_plural_select_')) {
+ $lang = str_replace('function string_plural_select_', '', str_replace('($n){', '', $l));
+ }
+ if ($this->startsWith($l, 'return')) {
+ $lang_logic = str_replace('$', '', trim(str_replace('return ', '', $l), ';'));
+ break;
+ }
+ }
+
+ $this->out('Language: ' . $lang);
+ $this->out('Plural forms: ' . $lang_pnum);
+ $this->out('Plural forms: ' . $lang_logic);
+
+ $out .= sprintf('"Language: %s\n"', $lang) . "\n";
+ $out .= sprintf('"Plural-Forms: nplurals=%s; plural=%s;\n"', $lang_pnum, $lang_logic) . "\n";
+ $out .= "\n";
+
+ $base_path = $this->getOption('base', 'util' . DIRECTORY_SEPARATOR . 'messages.po');
+
+ // load base messages.po and extract msgids
+ $base_msgids = [];
+ $base_f = file($base_path);
+ if (!$base_f) {
+ throw new \RuntimeException('The base ' . $base_path . ' file is missing or unavailable to read.');
+ }
+
+ $this->out('Loading base file ' . $base_path . '...');
+
+ $_f = 0;
+ $_mid = "";
+ $_mids = [];
+ foreach ($base_f as $l) {
+ $l = trim($l);
+
+ if ($this->startsWith($l, 'msgstr')) {
+ if ($_mid != '""') {
+ $base_msgids[$_mid] = $_mids;
+ $this->normBaseMsgIds[preg_replace(self::NORM_REGEXP, "", $_mid)] = $_mid;
+ }
+
+ $_f = 0;
+ $_mid = "";
+ $_mids = [];
+ }
+
+ if ($this->startsWith($l, '"') && $_f == 2) {
+ $_mids[count($_mids) - 1] .= "\n" . $l;
+ }
+ if ($this->startsWith($l, 'msgid_plural ')) {
+ $_f = 2;
+ $_mids[] = str_replace('msgid_plural ', '', $l);
+ }
+
+ if ($this->startsWith($l, '"') && $_f == 1) {
+ $_mid .= "\n" . $l;
+ $_mids[count($_mids) - 1] .= "\n" . $l;
+ }
+ if ($this->startsWith($l, 'msgid ')) {
+ $_f = 1;
+ $_mid = str_replace('msgid ', '', $l);
+ $_mids = [$_mid];
+ }
+ }
+
+ $this->out('Creating ' . $pofile . '...');
+
+ // create msgid and msgstr
+ $warnings = "";
+ foreach ($a->strings as $key => $str) {
+ $msgid = $this->massageString($key);
+
+ if (preg_match("|%[sd0-9](\$[sn])*|", $msgid)) {
+ $out .= "#, php-format\n";
+ }
+ $msgid = $this->findOriginalMsgId($msgid);
+ $out .= 'msgid ' . $msgid . "\n";
+
+ if (is_array($str)) {
+ if (array_key_exists($msgid, $base_msgids) && isset($base_msgids[$msgid][1])) {
+ $out .= 'msgid_plural ' . $base_msgids[$msgid][1] . "\n";
+ } else {
+ $out .= 'msgid_plural ' . $msgid . "\n";
+ $warnings .= "[W] No source plural form for msgid:\n" . str_replace("\n", "\n\t", $msgid) . "\n\n";
+ }
+ foreach ($str as $n => $msgstr) {
+ $out .= 'msgstr[' . $n . '] ' . $this->massageString($msgstr) . "\n";
+ }
+ } else {
+ $out .= 'msgstr ' . $this->massageString($str) . "\n";
+ }
+
+ $out .= "\n";
+ }
+
+ if (!file_put_contents($pofile, $out)) {
+ throw new \RuntimeException('Unable to write to ' . $pofile);
+ }
+
+ if ($warnings != '') {
+ $this->out($warnings);
+ }
+
+ return 0;
+ }
+
+ private function startsWith($haystack, $needle)
+ {
+ // search backwards starting from haystack length characters from the end
+ return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE;
+ }
+
+ /**
+ * Get a string and retun a message.po ready text
+ * - replace " with \"
+ * - replace tab char with \t
+ * - manage multiline strings
+ */
+ private function massageString($str)
+ {
+ $str = str_replace('\\', '\\\\', $str);
+ $str = str_replace('"', '\"', $str);
+ $str = str_replace("\t", '\t', $str);
+ $str = str_replace("\n", '\n"' . "\n" . '"', $str);
+ if (strpos($str, "\n") !== false && $str[0] !== '"') {
+ $str = '"' . "\n" . $str;
+ }
+
+ $str = preg_replace("|\n([^\"])|", "\n\"$1", $str);
+ return sprintf('"%s"', $str);
+ }
+
+ private function findOriginalMsgId($str)
+ {
+ $norm_str = preg_replace(self::NORM_REGEXP, "", $str);
+ if (array_key_exists($norm_str, $this->normBaseMsgIds)) {
+ return $this->normBaseMsgIds[$norm_str];
+ }
+
+ return $str;
+ }
+
+}
-<?php\r
-\r
-namespace Friendica\Core\Console;\r
-\r
-/**\r
- * Read a messages.po file and create strings.php in the same directory\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class PoToPhp extends \Asika\SimpleConsole\Console\r
-{\r
- protected $helpOptions = ['h', 'help', '?'];\r
-\r
- const DQ_ESCAPE = "__DQ__";\r
-\r
- protected function getHelp()\r
- {\r
- $help = <<<HELP\r
-console php2po - Generate a strings.php file from a messages.po file\r
-Usage\r
- bin/console php2po <path/to/messages.po> [-h|--help|-?] [-v]\r
-\r
-Description\r
- Read a messages.po file and create the according strings.php in the same directory\r
-\r
-Options\r
- -h|--help|-? Show help information\r
- -v Show more debug information.\r
-HELP;\r
- return $help;\r
- }\r
-\r
- protected function doExecute()\r
- {\r
- if ($this->getOption('v')) {\r
- $this->out('Class: ' . __CLASS__);\r
- $this->out('Arguments: ' . var_export($this->args, true));\r
- $this->out('Options: ' . var_export($this->options, true));\r
- }\r
-\r
- if (count($this->args) == 0) {\r
- $this->out($this->getHelp());\r
- return 0;\r
- }\r
-\r
- if (count($this->args) > 1) {\r
- throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');\r
- }\r
-\r
- $a = get_app();\r
-\r
- $pofile = realpath($this->getArgument(0));\r
-\r
- if (!file_exists($pofile)) {\r
- throw new \RuntimeException('Supplied file path doesn\'t exist.');\r
- }\r
-\r
- if (!is_writable(dirname($pofile))) {\r
- throw new \RuntimeException('Supplied directory isn\'t writable.');\r
- }\r
-\r
- $outfile = dirname($pofile) . DIRECTORY_SEPARATOR . 'strings.php';\r
-\r
- if (strstr($outfile, 'util')) {\r
- $lang = 'en';\r
- } else {\r
- $lang = str_replace('-', '_', basename(dirname($pofile)));\r
- }\r
-\r
- $this->out('Out to ' . $outfile);\r
-\r
- $out = "<?php\n\n";\r
-\r
- $infile = file($pofile);\r
- $k = '';\r
- $v = '';\r
- $arr = false;\r
- $ink = false;\r
- $inv = false;\r
- $escape_s_exp = '|[^\\\\]\$[a-z]|';\r
-\r
- foreach ($infile as $l) {\r
- $l = str_replace('\"', self::DQ_ESCAPE, $l);\r
- $len = strlen($l);\r
- if ($l[0] == "#") {\r
- $l = "";\r
- }\r
-\r
- if (substr($l, 0, 15) == '"Plural-Forms: ') {\r
- $match = [];\r
- preg_match("|nplurals=([0-9]*); *plural=(.*)[;\\\\]|", $l, $match);\r
- $cond = str_replace('n', '$n', $match[2]);\r
- // define plural select function if not already defined\r
- $fnname = 'string_plural_select_' . $lang;\r
- $out .= 'if(! function_exists("' . $fnname . '")) {' . "\n";\r
- $out .= 'function ' . $fnname . '($n){' . "\n";\r
- $out .= ' return ' . $cond . ';' . "\n";\r
- $out .= '}}' . "\n";\r
- }\r
-\r
- if ($k != "" && substr($l, 0, 7) == 'msgstr ') {\r
- if ($ink) {\r
- $ink = false;\r
- $out .= '$a->strings["' . $k . '"] = ';\r
- }\r
-\r
- if ($inv) {\r
- $inv = false;\r
- $out .= '"' . $v . '"';\r
- }\r
-\r
- $v = substr($l, 8, $len - 11);\r
- $v = preg_replace_callback($escape_s_exp, [$this, 'escapeDollar'], $v);\r
-\r
- $inv = true;\r
- }\r
- if ($k != "" && substr($l, 0, 7) == 'msgstr[') {\r
- if ($ink) {\r
- $ink = false;\r
- $out .= '$a->strings["' . $k . '"] = ';\r
- }\r
- if ($inv) {\r
- $inv = false;\r
- $out .= '"' . $v . '"';\r
- }\r
-\r
- if (!$arr) {\r
- $arr = True;\r
- $out .= "[\n";\r
- }\r
- $match = [];\r
- preg_match("|\[([0-9]*)\] (.*)|", $l, $match);\r
- $out .= "\t"\r
- . preg_replace_callback($escape_s_exp, [$this, 'escapeDollar'], $match[1])\r
- . ' => '\r
- . preg_replace_callback($escape_s_exp, [$this, 'escapeDollar'], $match[2])\r
- . ",\n";\r
- }\r
-\r
- if (substr($l, 0, 6) == 'msgid_') {\r
- $ink = false;\r
- $out .= '$a->strings["' . $k . '"] = ';\r
- }\r
-\r
- if ($ink) {\r
- $k .= trim($l, "\"\r\n");\r
- $k = preg_replace_callback($escape_s_exp, [$this, 'escapeDollar'], $k);\r
- }\r
-\r
- if (substr($l, 0, 6) == 'msgid ') {\r
- if ($inv) {\r
- $inv = false;\r
- $out .= '"' . $v . '"';\r
- }\r
- if ($k != "") {\r
- $out .= ($arr) ? "];\n" : ";\n";\r
- }\r
- $arr = false;\r
- $k = str_replace("msgid ", "", $l);\r
- if ($k != '""') {\r
- $k = trim($k, "\"\r\n");\r
- } else {\r
- $k = '';\r
- }\r
-\r
- $k = preg_replace_callback($escape_s_exp, [$this, 'escapeDollar'], $k);\r
- $ink = true;\r
- }\r
-\r
- if ($inv && substr($l, 0, 6) != "msgstr") {\r
- $v .= trim($l, "\"\r\n");\r
- $v = preg_replace_callback($escape_s_exp, [$this, 'escapeDollar'], $v);\r
- }\r
- }\r
-\r
- if ($inv) {\r
- $inv = false;\r
- $out .= '"' . $v . '"';\r
- }\r
-\r
- if ($k != '') {\r
- $out .= ($arr ? "];\n" : ";\n");\r
- }\r
-\r
- $out = str_replace(self::DQ_ESCAPE, '\"', $out);\r
- if (!file_put_contents($outfile, $out)) {\r
- throw new \RuntimeException('Unable to write to ' . $outfile);\r
- }\r
-\r
- return 0;\r
- }\r
-\r
- private function escapeDollar($match)\r
- {\r
- return str_replace('$', '\$', $match[0]);\r
- }\r
-}\r
+<?php
+
+namespace Friendica\Core\Console;
+
+/**
+ * Read a messages.po file and create strings.php in the same directory
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class PoToPhp extends \Asika\SimpleConsole\Console
+{
+ protected $helpOptions = ['h', 'help', '?'];
+
+ const DQ_ESCAPE = "__DQ__";
+
+ protected function getHelp()
+ {
+ $help = <<<HELP
+console php2po - Generate a strings.php file from a messages.po file
+Usage
+ bin/console php2po <path/to/messages.po> [-h|--help|-?] [-v]
+
+Description
+ Read a messages.po file and create the according strings.php in the same directory
+
+Options
+ -h|--help|-? Show help information
+ -v Show more debug information.
+HELP;
+ return $help;
+ }
+
+ protected function doExecute()
+ {
+ if ($this->getOption('v')) {
+ $this->out('Class: ' . __CLASS__);
+ $this->out('Arguments: ' . var_export($this->args, true));
+ $this->out('Options: ' . var_export($this->options, true));
+ }
+
+ if (count($this->args) == 0) {
+ $this->out($this->getHelp());
+ return 0;
+ }
+
+ if (count($this->args) > 1) {
+ throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
+ }
+
+ $a = get_app();
+
+ $pofile = realpath($this->getArgument(0));
+
+ if (!file_exists($pofile)) {
+ throw new \RuntimeException('Supplied file path doesn\'t exist.');
+ }
+
+ if (!is_writable(dirname($pofile))) {
+ throw new \RuntimeException('Supplied directory isn\'t writable.');
+ }
+
+ $outfile = dirname($pofile) . DIRECTORY_SEPARATOR . 'strings.php';
+
+ if (strstr($outfile, 'util')) {
+ $lang = 'en';
+ } else {
+ $lang = str_replace('-', '_', basename(dirname($pofile)));
+ }
+
+ $this->out('Out to ' . $outfile);
+
+ $out = "<?php\n\n";
+
+ $infile = file($pofile);
+ $k = '';
+ $v = '';
+ $arr = false;
+ $ink = false;
+ $inv = false;
+ $escape_s_exp = '|[^\\\\]\$[a-z]|';
+
+ foreach ($infile as $l) {
+ $l = str_replace('\"', self::DQ_ESCAPE, $l);
+ $len = strlen($l);
+ if ($l[0] == "#") {
+ $l = "";
+ }
+
+ if (substr($l, 0, 15) == '"Plural-Forms: ') {
+ $match = [];
+ preg_match("|nplurals=([0-9]*); *plural=(.*)[;\\\\]|", $l, $match);
+ $cond = str_replace('n', '$n', $match[2]);
+ // define plural select function if not already defined
+ $fnname = 'string_plural_select_' . $lang;
+ $out .= 'if(! function_exists("' . $fnname . '")) {' . "\n";
+ $out .= 'function ' . $fnname . '($n){' . "\n";
+ $out .= ' return ' . $cond . ';' . "\n";
+ $out .= '}}' . "\n";
+ }
+
+ if ($k != "" && substr($l, 0, 7) == 'msgstr ') {
+ if ($ink) {
+ $ink = false;
+ $out .= '$a->strings["' . $k . '"] = ';
+ }
+
+ if ($inv) {
+ $inv = false;
+ $out .= '"' . $v . '"';
+ }
+
+ $v = substr($l, 8, $len - 11);
+ $v = preg_replace_callback($escape_s_exp, [$this, 'escapeDollar'], $v);
+
+ $inv = true;
+ }
+ if ($k != "" && substr($l, 0, 7) == 'msgstr[') {
+ if ($ink) {
+ $ink = false;
+ $out .= '$a->strings["' . $k . '"] = ';
+ }
+ if ($inv) {
+ $inv = false;
+ $out .= '"' . $v . '"';
+ }
+
+ if (!$arr) {
+ $arr = True;
+ $out .= "[\n";
+ }
+ $match = [];
+ preg_match("|\[([0-9]*)\] (.*)|", $l, $match);
+ $out .= "\t"
+ . preg_replace_callback($escape_s_exp, [$this, 'escapeDollar'], $match[1])
+ . ' => '
+ . preg_replace_callback($escape_s_exp, [$this, 'escapeDollar'], $match[2])
+ . ",\n";
+ }
+
+ if (substr($l, 0, 6) == 'msgid_') {
+ $ink = false;
+ $out .= '$a->strings["' . $k . '"] = ';
+ }
+
+ if ($ink) {
+ $k .= trim($l, "\"\r\n");
+ $k = preg_replace_callback($escape_s_exp, [$this, 'escapeDollar'], $k);
+ }
+
+ if (substr($l, 0, 6) == 'msgid ') {
+ if ($inv) {
+ $inv = false;
+ $out .= '"' . $v . '"';
+ }
+ if ($k != "") {
+ $out .= ($arr) ? "];\n" : ";\n";
+ }
+ $arr = false;
+ $k = str_replace("msgid ", "", $l);
+ if ($k != '""') {
+ $k = trim($k, "\"\r\n");
+ } else {
+ $k = '';
+ }
+
+ $k = preg_replace_callback($escape_s_exp, [$this, 'escapeDollar'], $k);
+ $ink = true;
+ }
+
+ if ($inv && substr($l, 0, 6) != "msgstr") {
+ $v .= trim($l, "\"\r\n");
+ $v = preg_replace_callback($escape_s_exp, [$this, 'escapeDollar'], $v);
+ }
+ }
+
+ if ($inv) {
+ $inv = false;
+ $out .= '"' . $v . '"';
+ }
+
+ if ($k != '') {
+ $out .= ($arr ? "];\n" : ";\n");
+ }
+
+ $out = str_replace(self::DQ_ESCAPE, '\"', $out);
+ if (!file_put_contents($outfile, $out)) {
+ throw new \RuntimeException('Unable to write to ' . $outfile);
+ }
+
+ return 0;
+ }
+
+ private function escapeDollar($match)
+ {
+ return str_replace('$', '\$', $match[0]);
+ }
+}
-<?php\r
-\r
-namespace Friendica\Core\Console;\r
-\r
-/**\r
- * Tired of chasing typos and finding them after a commit.\r
- * Run this and quickly see if we've got any parse errors in our application files.\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class Typo extends \Asika\SimpleConsole\Console\r
-{\r
- protected $helpOptions = ['h', 'help', '?'];\r
-\r
- protected function getHelp()\r
- {\r
- $help = <<<HELP\r
-console typo - Checks for parse errors in Friendica files\r
-Usage\r
- bin/console typo [-h|--help|-?] [-v]\r
-\r
-Description\r
- Checks all PHP files in the Friendica file tree for parse errors\r
-\r
-Options\r
- -h|--help|-? Show help information\r
- -v Show more debug information.\r
-HELP;\r
- return $help;\r
- }\r
-\r
- protected function doExecute()\r
- {\r
- if ($this->getOption('v')) {\r
- $this->out('Class: ' . __CLASS__);\r
- $this->out('Arguments: ' . var_export($this->args, true));\r
- $this->out('Options: ' . var_export($this->options, true));\r
- }\r
-\r
- if (count($this->args) > 0) {\r
- throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');\r
- }\r
-\r
- $a = get_app();\r
-\r
- $php_path = $a->getConfigValue('config', 'php_path', 'php');\r
-\r
- if ($this->getOption('v')) {\r
- $this->out('Directory: src');\r
- }\r
-\r
- $Iterator = new \RecursiveDirectoryIterator('src');\r
-\r
- foreach (new \RecursiveIteratorIterator($Iterator) as $file) {\r
- if (substr($file, -4) === '.php') {\r
- $this->checkFile($php_path, $file);\r
- }\r
- }\r
-\r
- if ($this->getOption('v')) {\r
- $this->out('Directory: mod');\r
- }\r
-\r
- $files = glob('mod/*.php');\r
- $this->checkFiles($php_path, $files);\r
-\r
- if ($this->getOption('v')) {\r
- $this->out('Directory: include');\r
- }\r
-\r
- $files = glob('include/*.php');\r
- $this->checkFiles($php_path, $files);\r
-\r
- if ($this->getOption('v')) {\r
- $this->out('Directory: addon');\r
- }\r
-\r
- $dirs = glob('addon/*');\r
- foreach ($dirs as $dir) {\r
- $addon = basename($dir);\r
- $files = glob($dir . '/' . $addon . '.php');\r
- $this->checkFiles($php_path, $files);\r
- }\r
-\r
- if ($this->getOption('v')) {\r
- $this->out('String files');\r
- }\r
-\r
- $this->checkFile($php_path, 'util/strings.php');\r
-\r
- $files = glob('view/lang/*/strings.php');\r
- $this->checkFiles($php_path, $files);\r
-\r
- $this->out('No errors.');\r
-\r
- return 0;\r
- }\r
-\r
- private function checkFiles($php_path, array $files)\r
- {\r
- foreach ($files as $file) {\r
- $this->checkFile($php_path, $file);\r
- }\r
- }\r
-\r
- private function checkFile($php_path, $file)\r
- {\r
- if ($this->getOption('v')) {\r
- $this->out('Checking ' . $file);\r
- }\r
-\r
- $output = [];\r
- $ret = 0;\r
- exec("$php_path -l $file", $output, $ret);\r
- if ($ret !== 0) {\r
- throw new \RuntimeException('Parse error found in ' . $file . ', scan stopped.');\r
- }\r
- }\r
-}\r
+<?php
+
+namespace Friendica\Core\Console;
+
+/**
+ * Tired of chasing typos and finding them after a commit.
+ * Run this and quickly see if we've got any parse errors in our application files.
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
+class Typo extends \Asika\SimpleConsole\Console
+{
+ protected $helpOptions = ['h', 'help', '?'];
+
+ protected function getHelp()
+ {
+ $help = <<<HELP
+console typo - Checks for parse errors in Friendica files
+Usage
+ bin/console typo [-h|--help|-?] [-v]
+
+Description
+ Checks all PHP files in the Friendica file tree for parse errors
+
+Options
+ -h|--help|-? Show help information
+ -v Show more debug information.
+HELP;
+ return $help;
+ }
+
+ protected function doExecute()
+ {
+ if ($this->getOption('v')) {
+ $this->out('Class: ' . __CLASS__);
+ $this->out('Arguments: ' . var_export($this->args, true));
+ $this->out('Options: ' . var_export($this->options, true));
+ }
+
+ if (count($this->args) > 0) {
+ throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
+ }
+
+ $a = get_app();
+
+ $php_path = $a->getConfigValue('config', 'php_path', 'php');
+
+ if ($this->getOption('v')) {
+ $this->out('Directory: src');
+ }
+
+ $Iterator = new \RecursiveDirectoryIterator('src');
+
+ foreach (new \RecursiveIteratorIterator($Iterator) as $file) {
+ if (substr($file, -4) === '.php') {
+ $this->checkFile($php_path, $file);
+ }
+ }
+
+ if ($this->getOption('v')) {
+ $this->out('Directory: mod');
+ }
+
+ $files = glob('mod/*.php');
+ $this->checkFiles($php_path, $files);
+
+ if ($this->getOption('v')) {
+ $this->out('Directory: include');
+ }
+
+ $files = glob('include/*.php');
+ $this->checkFiles($php_path, $files);
+
+ if ($this->getOption('v')) {
+ $this->out('Directory: addon');
+ }
+
+ $dirs = glob('addon/*');
+ foreach ($dirs as $dir) {
+ $addon = basename($dir);
+ $files = glob($dir . '/' . $addon . '.php');
+ $this->checkFiles($php_path, $files);
+ }
+
+ if ($this->getOption('v')) {
+ $this->out('String files');
+ }
+
+ $this->checkFile($php_path, 'util/strings.php');
+
+ $files = glob('view/lang/*/strings.php');
+ $this->checkFiles($php_path, $files);
+
+ $this->out('No errors.');
+
+ return 0;
+ }
+
+ private function checkFiles($php_path, array $files)
+ {
+ foreach ($files as $file) {
+ $this->checkFile($php_path, $file);
+ }
+ }
+
+ private function checkFile($php_path, $file)
+ {
+ if ($this->getOption('v')) {
+ $this->out('Checking ' . $file);
+ }
+
+ $output = [];
+ $ret = 0;
+ exec("$php_path -l $file", $output, $ret);
+ if ($ret !== 0) {
+ throw new \RuntimeException('Parse error found in ' . $file . ', scan stopped.');
+ }
+ }
+}