Merge pull request #4628 from MrPetovan/task/add-console
Add Friendica console part 2: Script removal
This commit is contained in:
commit
e1423c5342
40 changed files with 1845 additions and 1244 deletions
|
@ -27,17 +27,17 @@ The location of the translated files in the source tree is
|
|||
/view/lang/LNG-CODE/
|
||||
where LNG-CODE is the language code used, e.g. de for German or fr for French.
|
||||
The translated strings come as a "message.po" file from transifex which needs to be translated into the PHP file friendica uses.
|
||||
To do so, place the file in the directory mentioned above and use the "po2php" utility from the util directory of your friendica installation.
|
||||
To do so, place the file in the directory mentioned above and use the "po2php" command from the console.
|
||||
|
||||
Assuming you want to convert the German localization which is placed in view/lang/de/message.po you would do the following.
|
||||
|
||||
1. Navigate at the command prompt to the base directory of your
|
||||
friendica installation
|
||||
|
||||
2. Execute the po2php script, which will place the translation
|
||||
2. Execute the po2php command, which will place the translation
|
||||
in the strings.php file that is used by friendica.
|
||||
|
||||
$> php util/po2php.php view/lang/de/messages.po
|
||||
$> php bin/console po2php view/lang/de/messages.po
|
||||
|
||||
The output of the script will be placed at view/lang/de/strings.php where
|
||||
friendica is expecting it, so you can test your translation immediately.
|
||||
|
@ -62,7 +62,7 @@ Otherwise your work might get lost, when the translation from Transifex is inclu
|
|||
Utilities
|
||||
---------
|
||||
|
||||
Additional to the po2php script there are some more utilities for translation in the "util" directory of the friendica source tree.
|
||||
Additional to the po2php command there are some more utilities for translation in the console.
|
||||
If you only want to translate friendica into another language you wont need any of these tools most likely but it gives you an idea how the translation process of friendica works.
|
||||
|
||||
For further information see the utils/README file.
|
||||
|
@ -90,9 +90,9 @@ To update the translation files after you have translated strings of e.g. Espera
|
|||
|
||||
$> tx pull -l eo
|
||||
|
||||
And then use the `po2php` utility described above to convert the `messages.po` file to the `strings.php` file Friendica is loading.
|
||||
And then use the `po2php` command described above to convert the `messages.po` file to the `strings.php` file Friendica is loading.
|
||||
|
||||
$> php util/po2php.php view/lang/eo/messages.po
|
||||
$> php bin/console po2php view/lang/eo/messages.po
|
||||
|
||||
Afterwards, just commit the two changed files to a feature branch of your Friendica repository, push the changes to github and open a pull request for your changes.
|
||||
|
||||
|
|
10
bin/console
Executable file
10
bin/console
Executable file
|
@ -0,0 +1,10 @@
|
|||
#!/bin/sh
|
||||
|
||||
dir=$(cd "${0%[/\\]*}" > /dev/null; pwd)
|
||||
|
||||
if [[ -d /proc/cygdrive && $(which php) == $(readlink -n /proc/cygdrive)/* ]]; then
|
||||
# We are in Cgywin using Windows php, so the path must be translated
|
||||
dir=$(cygpath -m "$dir");
|
||||
fi
|
||||
|
||||
php "${dir}/console.php" "$@"
|
4
bin/console.bat
Executable file
4
bin/console.bat
Executable file
|
@ -0,0 +1,4 @@
|
|||
@echo OFF
|
||||
:: in case DelayedExpansion is on and a path contains !
|
||||
setlocal DISABLEDELAYEDEXPANSION
|
||||
php "%~dp0console.php" %*
|
9
bin/console.php
Executable file
9
bin/console.php
Executable file
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
include_once dirname(__DIR__) . '/boot.php';
|
||||
|
||||
$a = new Friendica\App(dirname(__DIR__));
|
||||
\Friendica\BaseObject::setApp($a);
|
||||
|
||||
(new Friendica\Core\Console())->execute();
|
|
@ -24,6 +24,7 @@
|
|||
"pear/Text_LanguageDetect": "1.*",
|
||||
"pear/Text_Highlighter": "dev-master",
|
||||
"smarty/smarty": "^3.1",
|
||||
"asika/simple-console": "^1.0",
|
||||
"fxp/composer-asset-plugin": "~1.3",
|
||||
"bower-asset/base64": "^1.0",
|
||||
"bower-asset/Chart-js": "^2.7",
|
||||
|
|
35
composer.lock
generated
35
composer.lock
generated
|
@ -4,8 +4,41 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "3ff4187b4f7167583a3b8caa5f7c2a8a",
|
||||
"content-hash": "6a87e56bade65fa14f5f74e74109b66f",
|
||||
"packages": [
|
||||
{
|
||||
"name": "asika/simple-console",
|
||||
"version": "1.0.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/asika32764/php-simple-console.git",
|
||||
"reference": "0b624c1a999849dc6481a47182e58d593bf65068"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/asika32764/php-simple-console/zipball/0b624c1a999849dc6481a47182e58d593bf65068",
|
||||
"reference": "0b624c1a999849dc6481a47182e58d593bf65068",
|
||||
"shasum": ""
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Asika\\SimpleConsole\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Simon Asika",
|
||||
"email": "asika32764@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "One file console framework to help you write build scripts.",
|
||||
"time": "2018-03-08T12:05:40+00:00"
|
||||
},
|
||||
{
|
||||
"name": "bower-asset/Chart-js",
|
||||
"version": "v2.7.1",
|
||||
|
|
|
@ -94,7 +94,7 @@ Please remove all the `require_once` mentions of the former file, as they will p
|
|||
|
||||
## Miscellaneous tips
|
||||
|
||||
When you are done with moving the class, please run `php util/typo.php` from the Friendica base directory to check for obvious mistakes.
|
||||
When you are done with moving the class, please run `php bin/console typo` from the Friendica base directory to check for obvious mistakes.
|
||||
Howevever, this tool isn't bullet-proof, and a staging install of Friendica is recommended to test your class move without impairing your production server if you host one.
|
||||
|
||||
Most of Friendica processes are run in the background, so make sure to turn on your debug log to check for errors that wouldn't show up while simply browsing Friendica.
|
||||
|
|
|
@ -213,8 +213,8 @@ The listed emails need to be separated by a comma.
|
|||
Please have a look at the Admin panel under [DB updates](/admin/dbsync/) and follow the link to *check database structure*.
|
||||
This will start a background process to check if the structure is up to the current definition.
|
||||
|
||||
You can manually execute the structure update from the CLI in the base directory of your Friendica installation by running the following script:
|
||||
You can manually execute the structure update from the CLI in the base directory of your Friendica installation by running the following command:
|
||||
|
||||
scripts/dbstructure.php update
|
||||
bin/console dbstructure update
|
||||
|
||||
if there occur any errors, please contact the [support forum](https://forum.friendi.ca/profile/helpers).
|
||||
|
|
|
@ -68,7 +68,9 @@ If possible get an experienced Friendica developer to review the code.
|
|||
Don't hesitate to ask us in case of doubt.
|
||||
|
||||
3. Check your code for typos.
|
||||
There is a PHP script in the *util* directory called *typos.php* for this.
|
||||
There is a console command called *typo* for this.
|
||||
|
||||
$> php bin/console typo
|
||||
|
||||
Check out how to work with [our Vagrant](help/Vagrant) to save a lot of setup time!
|
||||
|
||||
|
|
|
@ -235,8 +235,8 @@ Rufe bitte im Admin Panel den Punkt [DB Updates](/admin/dbsync/) auf und folge d
|
|||
Damit wird ein Hintergrundprozess gestartet der die Struktur deiner Datenbank überprüft und gegebenenfalls aktualisiert.
|
||||
|
||||
Du kannst das Struktur Updatee auch manuell auf der Kommandoeingabe ausführen.
|
||||
Starte dazu bitte vom Grundverzeichnis deiner Friendica Instanz folgendes Skript:
|
||||
Starte dazu bitte vom Grundverzeichnis deiner Friendica Instanz folgendes Kommand:
|
||||
|
||||
scripts/dbstructure.php update
|
||||
bin/console dbstructure update
|
||||
|
||||
sollten bei der Ausführung Fehler auftreten, kontaktiere bitte das [Support Forum](https://forum.friendi.ca/profile/helpers).
|
||||
|
|
|
@ -29,17 +29,17 @@ The location of the translated files in the source tree is
|
|||
/view/lang/LNG-CODE/
|
||||
where LNG-CODE is the language code used, e.g. de for German or fr for French.
|
||||
The translated strings come as a "message.po" file from transifex which needs to be translated into the PHP file friendica uses.
|
||||
To do so, place the file in the directory mentioned above and use the "po2php" utility from the util directory of your friendica installation.
|
||||
To do so, place the file in the directory mentioned above and use the "po2php" command from the Friendica Console.
|
||||
|
||||
Assuming you want to convert the German localization which is placed in view/lang/de/message.po you would do the following.
|
||||
|
||||
1. Navigate at the command prompt to the base directory of your
|
||||
friendica installation
|
||||
|
||||
2. Execute the po2php script, which will place the translation
|
||||
2. Execute the po2php command, which will place the translation
|
||||
in the strings.php file that is used by friendica.
|
||||
|
||||
$> php util/po2php.php view/lang/de/messages.po
|
||||
$> php bin/console po2php view/lang/de/messages.po
|
||||
|
||||
The output of the script will be placed at view/lang/de/strings.php where
|
||||
friendica is expecting it, so you can test your translation immediately.
|
||||
|
@ -64,7 +64,7 @@ Otherwise your work might get lost, when the translation from Transifex is inclu
|
|||
Utilities
|
||||
---------
|
||||
|
||||
Additional to the po2php script there are some more utilities for translation in the "util" directory of the friendica source tree.
|
||||
Additional to the po2php command there are some more utilities for translation in the console.
|
||||
If you only want to translate friendica into another language you wont need any of these tools most likely but it gives you an idea how the translation process of friendica works.
|
||||
|
||||
For further information see the utils/README file.
|
||||
|
@ -92,9 +92,9 @@ To update the translation files after you have translated strings of e.g. Espera
|
|||
|
||||
$> tx pull -l eo
|
||||
|
||||
And then use the `po2php` utility described above to convert the `messages.po` file to the `strings.php` file Friendica is loading.
|
||||
And then use the `po2php` command described above to convert the `messages.po` file to the `strings.php` file Friendica is loading.
|
||||
|
||||
$> php util/po2php.php view/lang/eo/messages.po
|
||||
$> php bin/console po2php view/lang/eo/messages.po
|
||||
|
||||
Afterwards, just commit the two changed files to a feature branch of your Friendica repository, push the changes to github and open a pull request for your changes.
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ use Friendica\Util\DateTimeFormat;
|
|||
*/
|
||||
|
||||
class dba {
|
||||
public static $connected = true;
|
||||
public static $connected = false;
|
||||
|
||||
private static $_server_info = '';
|
||||
private static $db;
|
||||
|
@ -48,8 +48,6 @@ class dba {
|
|||
$db = trim($db);
|
||||
|
||||
if (!(strlen($server) && strlen($user))) {
|
||||
self::$connected = false;
|
||||
self::$db = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -57,8 +55,6 @@ class dba {
|
|||
if (strlen($server) && ($server !== 'localhost') && ($server !== '127.0.0.1')) {
|
||||
if (! dns_get_record($server, DNS_A + DNS_CNAME + DNS_PTR)) {
|
||||
self::$error = L10n::t('Cannot locate DNS info for database server \'%s\'', $server);
|
||||
self::$connected = false;
|
||||
self::$db = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +75,6 @@ class dba {
|
|||
self::$db = @new PDO($connect, $user, $pass);
|
||||
self::$connected = true;
|
||||
} catch (PDOException $e) {
|
||||
self::$connected = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,13 +93,10 @@ class dba {
|
|||
// No suitable SQL driver was found.
|
||||
if (!self::$connected) {
|
||||
self::$db = null;
|
||||
if (!$install) {
|
||||
System::unavailable();
|
||||
}
|
||||
}
|
||||
$a->save_timestamp($stamp1, "network");
|
||||
|
||||
return true;
|
||||
return self::$connected;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,9 +51,13 @@ if (!$install) {
|
|||
require_once "include/dba.php";
|
||||
|
||||
if (!$install) {
|
||||
dba::connect($db_host, $db_user, $db_pass, $db_data, $install);
|
||||
$result = dba::connect($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
|
||||
if (!$result) {
|
||||
System::unavailable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load configs from db. Overwrite configs from .htconfig.php
|
||||
*/
|
||||
|
|
|
@ -718,7 +718,7 @@ function admin_page_summary(App $a)
|
|||
$warningtext = [];
|
||||
if (DBM::is_result($r)) {
|
||||
$showwarning = true;
|
||||
$warningtext[] = L10n::t('Your DB still runs with MyISAM tables. You should change the engine type to InnoDB. As Friendica will use InnoDB only features in the future, you should change this! See <a href="%s">here</a> for a guide that may be helpful converting the table engines. You may also use the command <tt>php scripts/dbstructure.php toinnodb</tt> of your Friendica installation for an automatic conversion.<br />', 'https://dev.mysql.com/doc/refman/5.7/en/converting-tables-to-innodb.html');
|
||||
$warningtext[] = L10n::t('Your DB still runs with MyISAM tables. You should change the engine type to InnoDB. As Friendica will use InnoDB only features in the future, you should change this! See <a href="%s">here</a> for a guide that may be helpful converting the table engines. You may also use the command <tt>php bin/console dbstructure toinnodb</tt> of your Friendica installation for an automatic conversion.<br />', 'https://dev.mysql.com/doc/refman/5.7/en/converting-tables-to-innodb.html');
|
||||
}
|
||||
// Check if github.com/friendica/master/VERSION is higher then
|
||||
// the local version of Friendica. Check is opt-in, source may be master or devel branch
|
||||
|
@ -735,7 +735,7 @@ function admin_page_summary(App $a)
|
|||
}
|
||||
if (Config::get('system', 'dbupdate') == DB_UPDATE_FAILED) {
|
||||
$showwarning = true;
|
||||
$warningtext[] = L10n::t('The database update failed. Please run "php scripts/dbstructure.php update" from the command line and have a look at the errors that might appear.');
|
||||
$warningtext[] = L10n::t('The database update failed. Please run "php bin/console dbstructure update" from the command line and have a look at the errors that might appear.');
|
||||
}
|
||||
|
||||
$last_worker_call = Config::get('system', 'last_poller_execution', false);
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* @file scripts/dbstructure.php
|
||||
* @brief Does database updates from the command line
|
||||
*/
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Database\DBStructure;
|
||||
|
||||
require_once "boot.php";
|
||||
require_once "include/dba.php";
|
||||
|
||||
$a = new App(dirname(__DIR__));
|
||||
BaseObject::setApp($a);
|
||||
|
||||
@include ".htconfig.php";
|
||||
dba::connect($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
|
||||
if ($_SERVER["argc"] == 2) {
|
||||
switch ($_SERVER["argv"][1]) {
|
||||
case "dryrun":
|
||||
DBStructure::update(true, false);
|
||||
return;
|
||||
case "update":
|
||||
DBStructure::update(true, true);
|
||||
|
||||
$build = Config::get('system','build');
|
||||
if (!x($build)) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Config::set('system','build',DB_UPDATE_VERSION);
|
||||
return;
|
||||
case "dumpsql":
|
||||
DBStructure::printStructure();
|
||||
return;
|
||||
case "toinnodb":
|
||||
DBStructure::convertToInnoDB();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// print help
|
||||
echo $_SERVER["argv"][0]." <command>\n";
|
||||
echo "\n";
|
||||
echo "Commands:\n";
|
||||
echo "dryrun show database update schema queries without running them\n";
|
||||
echo "update update database schema\n";
|
||||
echo "dumpsql dump database schema\n";
|
||||
echo "toinnodb convert all tables from MyISAM to InnoDB\n";
|
||||
killme();
|
||||
|
123
src/Core/Console.php
Normal file
123
src/Core/Console.php
Normal file
|
@ -0,0 +1,123 @@
|
|||
<?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;
|
||||
}
|
||||
|
||||
}
|
135
src/Core/Console/Config.php
Normal file
135
src/Core/Console/Config.php
Normal file
|
@ -0,0 +1,135 @@
|
|||
<?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;
|
||||
}
|
||||
|
||||
}
|
148
src/Core/Console/CreateDoxygen.php
Normal file
148
src/Core/Console/CreateDoxygen.php
Normal file
|
@ -0,0 +1,148 @@
|
|||
<?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;
|
||||
}
|
||||
|
||||
}
|
110
src/Core/Console/DatabaseStructure.php
Normal file
110
src/Core/Console/DatabaseStructure.php
Normal file
|
@ -0,0 +1,110 @@
|
|||
<?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;
|
||||
}
|
||||
|
||||
}
|
192
src/Core/Console/DocBloxErrorChecker.php
Normal file
192
src/Core/Console/DocBloxErrorChecker.php
Normal file
|
@ -0,0 +1,192 @@
|
|||
<?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 [];
|
||||
}
|
||||
|
||||
}
|
140
src/Core/Console/Extract.php
Normal file
140
src/Core/Console/Extract.php
Normal file
|
@ -0,0 +1,140 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
77
src/Core/Console/GlobalCommunityBlock.php
Normal file
77
src/Core/Console/GlobalCommunityBlock.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
94
src/Core/Console/GlobalCommunitySilence.php
Normal file
94
src/Core/Console/GlobalCommunitySilence.php
Normal file
|
@ -0,0 +1,94 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
105
src/Core/Console/Maintenance.php
Normal file
105
src/Core/Console/Maintenance.php
Normal file
|
@ -0,0 +1,105 @@
|
|||
<?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;
|
||||
}
|
||||
|
||||
}
|
234
src/Core/Console/PhpToPo.php
Normal file
234
src/Core/Console/PhpToPo.php
Normal file
|
@ -0,0 +1,234 @@
|
|||
<?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;
|
||||
}
|
||||
|
||||
}
|
197
src/Core/Console/PoToPhp.php
Normal file
197
src/Core/Console/PoToPhp.php
Normal file
|
@ -0,0 +1,197 @@
|
|||
<?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]);
|
||||
}
|
||||
}
|
119
src/Core/Console/Typo.php
Normal file
119
src/Core/Console/Typo.php
Normal file
|
@ -0,0 +1,119 @@
|
|||
<?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.');
|
||||
}
|
||||
}
|
||||
}
|
18
util/README
18
util/README
|
@ -1,6 +1,6 @@
|
|||
Utilities
|
||||
|
||||
typo.php - is a crude syntax checker to avoid checking in files with simple
|
||||
php bin/console typo - is a crude syntax checker to avoid checking in files with simple
|
||||
typos. It basically just loads each of our project files at once. Run from
|
||||
cmdline and see if any parsing errors are reported.
|
||||
|
||||
|
@ -8,7 +8,7 @@ cmdline and see if any parsing errors are reported.
|
|||
|
||||
Internationalisation
|
||||
|
||||
extract.php - extracts translatable strings from our project files. It
|
||||
php bin/console extract - extracts translatable strings from our project files. It
|
||||
currently doesn't pick up strings in other libraries we might be using such as
|
||||
the HTML parsers.
|
||||
|
||||
|
@ -61,7 +61,7 @@ e.g.
|
|||
|
||||
Plural
|
||||
|
||||
The L10n::tt() function supports plural form. Script extract.php write this in
|
||||
The L10n::tt() function supports plural form. The extract command writes this in
|
||||
strings.php as an array, one string for every plural form language supports:
|
||||
|
||||
$a->string["%d message sent"] = Array(
|
||||
|
@ -72,7 +72,7 @@ $a->string["%d message sent"] = Array(
|
|||
The function string_plural_select($n) defined in strings.php, return the string
|
||||
index to use, related to the numbers of item (value of $n).
|
||||
|
||||
This is modelled after ngettext function of GNU gettext.
|
||||
This is modeled after ngettext function of GNU gettext.
|
||||
More info at http://www.gnu.org/software/hello/manual/gettext/Plural-forms.html
|
||||
|
||||
|
||||
|
@ -107,7 +107,7 @@ Xgettext and .po workflow
|
|||
of the many .po editors out there, like QtLinguist
|
||||
|
||||
5. run
|
||||
$ php util/po2php.php view/lang/<language>/messages.po
|
||||
$ php bin/console po2php view/lang/<language>/messages.po
|
||||
to create the strings.php file
|
||||
|
||||
When strings are added or modified in source, you could run
|
||||
|
@ -117,10 +117,4 @@ When strings are added or modified in source, you could run
|
|||
|
||||
If you already translated Friendica using strings.php, you could import your old
|
||||
translation to messages.po. Run:
|
||||
$ php util/php2po.php view/lang/<language>/strings.php
|
||||
|
||||
|
||||
You may also use the util/string_translator.php web interface to translate the string file, but it is disabled for website security reasons. The web server will need write permission to your language directories and the "Deny ..." line in util/.htaccess will need to be modified or commented to use the utility.
|
||||
|
||||
|
||||
|
||||
$ php bin/console php2po view/lang/<language>/strings.php
|
||||
|
|
65
util/config
65
util/config
|
@ -1,65 +0,0 @@
|
|||
#!/usr/bin/env php
|
||||
<?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 scipt will list all config variables
|
||||
* defined in this section of the configuration (e.g. "system").
|
||||
*
|
||||
* If you specify two parameters, the scipt 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)
|
||||
**/
|
||||
|
||||
use Friendica\Core\Config;
|
||||
|
||||
require_once 'boot.php';
|
||||
require_once 'include/dba.php';
|
||||
require_once 'include/text.php';
|
||||
$a = get_app();
|
||||
require_once '.htconfig.php';
|
||||
|
||||
dba::connect($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
|
||||
if($argc > 3) {
|
||||
Config::set($argv[1],$argv[2],$argv[3]);
|
||||
echo "config[{$argv[1]}][{$argv[2]}] = " . Config::get($argv[1],$argv[2]) . "\n";
|
||||
}
|
||||
|
||||
if($argc == 3) {
|
||||
echo "config[{$argv[1]}][{$argv[2]}] = " . Config::get($argv[1],$argv[2]) . "\n";
|
||||
}
|
||||
|
||||
if($argc == 2) {
|
||||
Config::load($argv[1]);
|
||||
if (!is_null($a->config[$argv[1]])) {
|
||||
foreach($a->config[$argv[1]] as $k => $x) {
|
||||
echo "config[{$argv[1]}][{$k}] = " . $x . "\n";
|
||||
}
|
||||
} else {
|
||||
echo "config section '$argv[1]' returned nothing.\n";
|
||||
}
|
||||
}
|
||||
|
||||
if($argc == 1) {
|
||||
$r = q("select * from config where 1");
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
echo "config[{$rr['cat']}][{$rr['k']}] = " . $rr['v'] . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
CLI config utility
|
||||
==================
|
||||
|
||||
Usage:
|
||||
|
||||
|
||||
config
|
||||
displays all config entries
|
||||
|
||||
|
||||
config family
|
||||
displays all config entries for family (system, database, etc)
|
||||
|
||||
|
||||
config family key
|
||||
displays single config entry for specified family and key
|
||||
|
||||
config family key value
|
||||
set config entry for specified family and key to value and display result
|
||||
|
||||
|
||||
|
||||
Notes:
|
||||
Setting config entries which are manually set in .htconfig.php may result in
|
||||
conflict between database settings and the manual startup settings.
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
#!/usr/bin/php
|
||||
<?php
|
||||
/**
|
||||
* @file util/createdoxygen.php
|
||||
* @brief Adds a doxygen header to functions
|
||||
*/
|
||||
|
||||
if (count($_SERVER["argv"]) < 2)
|
||||
die("usage: createdoxygen.php file\n");
|
||||
|
||||
$file = $_SERVER["argv"][1];
|
||||
$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, 17) == "private function ")
|
||||
$found = true;
|
||||
|
||||
if (substr($detect, 0, 23) == "public static function ")
|
||||
$found = true;
|
||||
|
||||
if (substr($detect, 0, 10) == "function (")
|
||||
$found = false;
|
||||
|
||||
if ($found and (trim($previous) == "*/"))
|
||||
$found = false;
|
||||
|
||||
if ($found and !strstr($detect, "{"))
|
||||
$found = false;
|
||||
|
||||
if ($found) {
|
||||
echo add_documentation($line);
|
||||
}
|
||||
}
|
||||
echo $line."\n";
|
||||
$previous = $line;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adds a doxygen header
|
||||
*
|
||||
* @param string $line The current line of the document
|
||||
*
|
||||
* @return string added doxygen header
|
||||
*/
|
||||
function add_documentation($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;
|
||||
}
|
|
@ -1,145 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* 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 errorneous files.
|
||||
* This is done for all files, so, in the end removing one file leads to a working doc build.
|
||||
*
|
||||
* @package util
|
||||
* @author Alexander Kampmann
|
||||
*/
|
||||
|
||||
/**
|
||||
* This function generates a comma seperated list of file names.
|
||||
*
|
||||
* @package util
|
||||
*
|
||||
* @param array $fileset Set of file names
|
||||
*
|
||||
* @return string comma-seperated list of the file names
|
||||
*/
|
||||
function namesList($fileset) {
|
||||
$fsparam="";
|
||||
foreach($fileset as $file) {
|
||||
$fsparam=$fsparam.",".$file;
|
||||
}
|
||||
return $fsparam;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
function runs($fileset) {
|
||||
$fsParam=namesList($fileset);
|
||||
exec('docblox -t phpdoc_out -f '.$fsParam);
|
||||
if(file_exists("phpdoc_out/index.html")) {
|
||||
echo "\n Subset ".$fsParam." is okay. \n";
|
||||
exec('rm -r phpdoc_out');
|
||||
return true;
|
||||
} else {
|
||||
echo "\n Subset ".$fsParam." failed. \n";
|
||||
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
|
||||
*/
|
||||
function reduce($fileset, $ps) {
|
||||
//split array...
|
||||
$parts=array_chunk($fileset, $ps);
|
||||
//filter working subsets...
|
||||
$parts=array_filter($parts, "runs");
|
||||
//melt remaining parts together
|
||||
if(is_array($parts)) {
|
||||
return array_reduce($parts, "array_merge", []);
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
//return from util folder to frindica base dir
|
||||
$dir='..';
|
||||
|
||||
//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($file!=".." && $file!=".") {
|
||||
array_push($dirstack, $dir."/".$file);
|
||||
echo "dir ".$dir."/".$file."\n";
|
||||
}
|
||||
} else {
|
||||
//test if it is a source file and add to filelist
|
||||
if(substr($file, strlen($file)-4)==".php") {
|
||||
array_push($filelist, $dir."/".$file);
|
||||
echo $dir."/".$file."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
//look at the next dir
|
||||
$dir=array_pop($dirstack);
|
||||
}
|
||||
|
||||
//check the entire set
|
||||
if(runs($filelist)) {
|
||||
echo "I can not detect a problem. \n";
|
||||
exit;
|
||||
}
|
||||
|
||||
//check half of the set and discard if that half is okay
|
||||
$res=$filelist;
|
||||
$i=0;
|
||||
do {
|
||||
$i=count($res);
|
||||
echo $i."/".count($fileset)." elements remaining. \n";
|
||||
$res=reduce($res, count($res)/2);
|
||||
shuffle($res);
|
||||
} while(count($res)<$i);
|
||||
|
||||
//check one file after another
|
||||
$needed=[];
|
||||
|
||||
while(count($res)!=0) {
|
||||
$file=array_pop($res);
|
||||
|
||||
if(runs(array_merge($res, $needed))) {
|
||||
echo "needs: ".$file." and file count ".count($needed);
|
||||
array_push($needed, $file);
|
||||
}
|
||||
}
|
||||
|
||||
echo "\nSmallest Set is: ".namesList($needed)." with ".count($needed)." files. ";
|
100
util/extract.php
100
util/extract.php
|
@ -1,100 +0,0 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file util/extract.php
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
$s = '<?php' . PHP_EOL;
|
||||
$s .= '
|
||||
function string_plural_select($n){
|
||||
return ($n != 1);
|
||||
}
|
||||
|
||||
';
|
||||
|
||||
$arr = [];
|
||||
|
||||
$files = ['index.php', 'boot.php'];
|
||||
$files = array_merge(
|
||||
$files,
|
||||
glob('mod/*'),
|
||||
glob('include/*'),
|
||||
glob('addon/*/*'),
|
||||
glob_recursive('src')
|
||||
);
|
||||
|
||||
foreach ($files as $file) {
|
||||
$str = file_get_contents($file);
|
||||
|
||||
$pat = '|L10n::t\(([^\)]*+)[\)]|';
|
||||
$patt = '|L10n::tt\(([^\)]*+)[\)]|';
|
||||
|
||||
preg_match_all($pat, $str, $matches);
|
||||
preg_match_all($patt, $str, $matchestt);
|
||||
|
||||
if (count($matches) || count($matchestt)) {
|
||||
$s .= '// ' . $file . PHP_EOL;
|
||||
}
|
||||
|
||||
if (count($matches)) {
|
||||
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 (count($matchestt)) {
|
||||
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";
|
||||
}
|
||||
|
||||
echo $s;
|
||||
|
||||
function glob_recursive($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;
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
* Usage: pass the URL of the to be blocked account as only parameter
|
||||
* at the command line when running this tool. E.g.
|
||||
*
|
||||
* $> util/global_community_block.php http://example.com/profile/bob
|
||||
*
|
||||
* will block bob@example.com.
|
||||
*
|
||||
* Author: Tobias Diekershoff
|
||||
*
|
||||
* License: AGPLv3 or later, same as Friendica
|
||||
*/
|
||||
if ($argc != 2 || $argv[1] == "-h" || $argv[1] == "--help" || $argv[1] == "-?") {
|
||||
echo "Usage: " . $argv[0] . " [-h|profile_url]\r\n";
|
||||
echo " -h, -?, --help ... show this help\r\n";
|
||||
echo " profile_url ...... The URL of the profile you want to silence\r\n";
|
||||
echo "\r\n";
|
||||
echo "Example: block bob@example.com\r\n";
|
||||
echo "$> " . $argv[0] . " https://example.com/profiles/bob\r\n";
|
||||
echo "\r\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
use Friendica\BaseObject;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Model\Contact;
|
||||
|
||||
require_once 'boot.php';
|
||||
require_once 'include/dba.php';
|
||||
require_once 'include/text.php';
|
||||
|
||||
$a = get_app();
|
||||
BaseObject::setApp($a);
|
||||
|
||||
require_once '.htconfig.php';
|
||||
dba::connect($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
|
||||
$contact_id = Contact::getIdForURL($argv[1]);
|
||||
if (!$contact_id) {
|
||||
echo L10n::t('Could not find any contact entry for this URL (%s)', $nurl);
|
||||
echo "\r\n";
|
||||
exit(1);
|
||||
}
|
||||
Contact::block($contact_id);
|
||||
echo L10n::t('The contact has been blocked from the node');
|
||||
echo "\r\n";
|
||||
exit(0);
|
|
@ -1,68 +0,0 @@
|
|||
#!/usr/bin/env php
|
||||
<?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.
|
||||
*
|
||||
* Usage: pass the URL of the profile to be silenced account as only parameter
|
||||
* at the command line when running this tool. E.g.
|
||||
*
|
||||
* $> util/global_community_silence.php http://example.com/profile/bob
|
||||
*
|
||||
* will silence bob@example.com so that his postings won't appear at
|
||||
* the global community page.
|
||||
*
|
||||
* Author: Tobias Diekershoff
|
||||
*
|
||||
* License: AGPLv3 or later, same as Friendica
|
||||
**/
|
||||
|
||||
if ($argc != 2 || $argv[1] == "-h" || $argv[1] == "--help" || $argv[1] == "-?") {
|
||||
echo "Usage: ".$argv[0]." [-h|profile_url]\r\n";
|
||||
echo " -h, -?, --help ... show this help\r\n";
|
||||
echo " profile_url ...... The URL of the profile you want to silence\r\n";
|
||||
echo "\r\n";
|
||||
echo "Example: Silence bob@example.com\r\n";
|
||||
echo "$> ".$argv[0]." https://example.com/profiles/bob\r\n";
|
||||
echo "\r\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
use Friendica\Database\DBM;
|
||||
use Friendica\Network\Probe;
|
||||
|
||||
require_once 'boot.php';
|
||||
require_once 'include/dba.php';
|
||||
require_once 'include/text.php';
|
||||
$a = get_app();
|
||||
require_once '.htconfig.php';
|
||||
|
||||
dba::connect($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
|
||||
/**
|
||||
* 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($argv[1]);
|
||||
if (in_array($net['network'], [NETWORK_PHANTOM, NETWORK_MAIL])) {
|
||||
echo "This account seems not to exist.";
|
||||
echo "\r\n";
|
||||
exit(1);
|
||||
}
|
||||
$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"]]);
|
||||
echo "NOTICE: The account should be silenced from the global community page\r\n";
|
||||
} else {
|
||||
echo "NOTICE: Could not find any entry for this URL (".$nurl.")\r\n";
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,70 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @file util/maintenance.php
|
||||
*/
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseObject;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\L10n;
|
||||
|
||||
require_once 'boot.php';
|
||||
require_once 'include/dba.php';
|
||||
|
||||
$a = new App(dirname(__DIR__));
|
||||
BaseObject::setApp($a);
|
||||
|
||||
@include(".htconfig.php");
|
||||
|
||||
$lang = L10n::getBrowserLanguage();
|
||||
L10n::loadTranslationTable($lang);
|
||||
|
||||
dba::connect($db_host, $db_user, $db_pass, $db_data, false);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
|
||||
Config::load();
|
||||
|
||||
$maint_mode = 1;
|
||||
if ($argc > 1) {
|
||||
$maint_mode = intval($argv[1]);
|
||||
}
|
||||
|
||||
Config::set('system', 'maintenance', $maint_mode);
|
||||
|
||||
if ($maint_mode && ($argc > 2)) {
|
||||
$reason_arr = $argv;
|
||||
array_shift($reason_arr);
|
||||
array_shift($reason_arr);
|
||||
|
||||
$reason = implode(' ', $reason_arr);
|
||||
Config::set('system', 'maintenance_reason', $reason);
|
||||
} else {
|
||||
Config::set('system', 'maintenance_reason', '');
|
||||
}
|
||||
|
||||
if ($maint_mode) {
|
||||
$mode_str = "maintenance mode";
|
||||
} else {
|
||||
$mode_str = "normal mode";
|
||||
}
|
||||
|
||||
echo "\n\tSystem set in $mode_str\n";
|
||||
|
||||
if ($reason != '') {
|
||||
echo "\tMaintenance reason: $reason\n\n";
|
||||
} else {
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
echo "Usage:\n\n";
|
||||
echo "\tphp {$argv[0]} [1] [Maintenance reason|redirection url]\n";
|
||||
echo "\t\tSet the system in maintenance mode\n\n";
|
||||
echo "\t\tIf the optionally entered maintenance reason is an url\n";
|
||||
echo "\t\tthe visitor is redirected to that page.\n";
|
||||
echo "\n";
|
||||
echo "\t\tExamples:\n";
|
||||
echo "\t\t\tphp {$argv[0]} 1 System upgrade\n";
|
||||
echo "\t\t\tphp {$argv[0]} 1 http://domain.tld/downtime\n";
|
||||
echo "\n";
|
||||
echo "\tphp {$argv[0]} 0\n";
|
||||
echo "\t\tSet the system in normal mode\n\n";
|
204
util/php2po.php
204
util/php2po.php
|
@ -1,204 +0,0 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* Read strings.php file and create messages.po
|
||||
*
|
||||
* php utils/php2po.php <path/to/strings.php>
|
||||
*
|
||||
* Output to <path/to/messages.po>
|
||||
*/
|
||||
|
||||
DEFINE("NORM_REGEXP", "|[\\\]|");
|
||||
|
||||
$a = new stdClass();
|
||||
|
||||
if ($argc<2 || in_array('-h', $argv) || in_array('--h', $argv)) {
|
||||
print "Usage: ".$argv[0]." [-p <n>] <strings.php>\n\n";
|
||||
print "Options:\n";
|
||||
print "p\tNumber of plural forms. Default: 2\n";
|
||||
print "\n";
|
||||
return;
|
||||
}
|
||||
|
||||
$phpfile = $argv[1];
|
||||
$pofile = dirname($phpfile)."/messages.po";
|
||||
|
||||
if (!file_exists($phpfile)){
|
||||
print "Unable to find '$phpfile'\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// utility functions
|
||||
function startsWith($haystack, $needle) {
|
||||
// search backwards starting from haystack length characters from the end
|
||||
return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE;
|
||||
}
|
||||
|
||||
|
||||
// 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 = 2;
|
||||
|
||||
$_idx = array_search('-p', $argv);
|
||||
if ($_idx !== false) {
|
||||
$lang_pnum = $argv[$_idx+1];
|
||||
}
|
||||
|
||||
$infile = file($phpfile);
|
||||
foreach($infile as $l) {
|
||||
$l = trim($l);
|
||||
if (startsWith($l, 'function string_plural_select_')) {
|
||||
$lang = str_replace( 'function string_plural_select_' , '', str_replace( '($n){','', $l) );
|
||||
}
|
||||
if (startsWith($l, 'return')) {
|
||||
$lang_logic = str_replace( '$', '', trim( str_replace( 'return ' , '', $l) , ';') );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
echo "Language: $lang\n";
|
||||
echo "Plural forms: $lang_pnum\n";
|
||||
echo "Plural logic: $lang_logic;\n";
|
||||
|
||||
$out .= sprintf('"Language: %s\n"', $lang) ."\n";
|
||||
$out .= sprintf('"Plural-Forms: nplurals=%s; plural=%s;\n"', $lang_pnum, $lang_logic) ."\n";
|
||||
$out .= "\n";
|
||||
|
||||
print "\nLoading base message.po...";
|
||||
|
||||
// load base messages.po and extract msgids
|
||||
$base_msgids = [];
|
||||
$norm_base_msgids = [];
|
||||
$base_f = file("util/messages.po");
|
||||
if (!$base_f) {
|
||||
die("No base messages.po\n");
|
||||
}
|
||||
|
||||
$_f = 0;
|
||||
$_mid = "";
|
||||
$_mids = [];
|
||||
foreach( $base_f as $l) {
|
||||
$l = trim($l);
|
||||
//~ print $l."\n";
|
||||
|
||||
if (startsWith($l, 'msgstr')) {
|
||||
if ($_mid != '""') {
|
||||
$base_msgids[$_mid] = $_mids;
|
||||
$norm_base_msgids[preg_replace(NORM_REGEXP, "", $_mid)] = $_mid;
|
||||
//~ print "\t\t\t".$_mid. print_r($base_msgids[$_mid], true);
|
||||
}
|
||||
|
||||
$_f = 0;
|
||||
$_mid = "";
|
||||
$_mids = [];
|
||||
|
||||
}
|
||||
|
||||
if (startsWith($l, '"') && $_f==2) {
|
||||
$_mids[count($_mids)-1] .= "\n".$l;
|
||||
//~ print "\t\t+mids: ".print_t($_mids, true);
|
||||
}
|
||||
if (startsWith($l, 'msgid_plural ')) {
|
||||
$_f = 2;
|
||||
$_mids[] = str_replace('msgid_plural ', '' , $l);
|
||||
//~ print "\t\t mids: ".print_r($_mids, true);
|
||||
}
|
||||
|
||||
if (startsWith($l, '"') && $_f==1) {
|
||||
$_mid .= "\n".$l;
|
||||
$_mids[count($_mids)-1] .= "\n".$l;
|
||||
//~ print "\t+mid: $_mid \n";
|
||||
}
|
||||
if (startsWith($l, 'msgid ')) {
|
||||
$_f = 1;
|
||||
$_mid = str_replace('msgid ', '' , $l);
|
||||
$_mids = [$_mid];
|
||||
//~ print "\t mid: $_mid \n";
|
||||
}
|
||||
//~ print "\t\t\t\t$_f\n\n";
|
||||
}
|
||||
|
||||
print " done\n";
|
||||
print "Creating '$pofile'...";
|
||||
// create msgid and msgstr
|
||||
|
||||
/**
|
||||
* Get a string and retun a message.po ready text
|
||||
* - replace " with \"
|
||||
* - replace tab char with \t
|
||||
* - manage multiline strings
|
||||
*/
|
||||
function massage_string($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);
|
||||
}
|
||||
|
||||
function find_original_msgid($str) {
|
||||
global $norm_base_msgids;
|
||||
$norm_str = preg_replace(NORM_REGEXP, "", $str);
|
||||
if (array_key_exists($norm_str, $norm_base_msgids)) {
|
||||
return $norm_base_msgids[$norm_str];
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
$warnings = "";
|
||||
foreach($a->strings as $key=>$str) {
|
||||
$msgid = massage_string($key);
|
||||
|
||||
if (preg_match("|%[sd0-9](\$[sn])*|", $msgid)) {
|
||||
$out .= "#, php-format\n";
|
||||
}
|
||||
$msgid = find_original_msgid($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.'] '. massage_string($msgstr) . "\n";
|
||||
}
|
||||
} else {
|
||||
$out .= 'msgstr '. massage_string($str) . "\n";
|
||||
}
|
||||
|
||||
$out .= "\n";
|
||||
|
||||
}
|
||||
|
||||
file_put_contents($pofile, $out);
|
||||
|
||||
print " done\n";
|
||||
|
||||
if ($warnings=="") {
|
||||
print "No warnings.\n";
|
||||
} else {
|
||||
print $warnings;
|
||||
}
|
151
util/po2php.php
151
util/po2php.php
|
@ -1,151 +0,0 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
define("DQ_ESCAPE", "__DQ__");
|
||||
|
||||
function po2php_run(&$argv, &$argc) {
|
||||
|
||||
if ($argc!=2) {
|
||||
print "Usage: ".$argv[0]." <file.po>\n\n";
|
||||
return;
|
||||
}
|
||||
|
||||
$pofile = $argv[1];
|
||||
$outfile = dirname($pofile)."/strings.php";
|
||||
|
||||
if (strstr($outfile, 'util')) {
|
||||
$lang = 'en';
|
||||
} else {
|
||||
$lang = str_replace('-','_',basename(dirname($pofile)));
|
||||
}
|
||||
|
||||
if (!file_exists($pofile)) {
|
||||
print "Unable to find '$pofile'\n";
|
||||
return;
|
||||
}
|
||||
|
||||
print "Out to '$outfile'\n";
|
||||
|
||||
$out = "<?php\n\n";
|
||||
|
||||
$infile = file($pofile);
|
||||
$k = "";
|
||||
$v = "";
|
||||
$arr = false;
|
||||
$ink = false;
|
||||
$inv = false;
|
||||
$escape_s_exp = '|[^\\\\]\$[a-z]|';
|
||||
function escape_s($match) {
|
||||
return str_replace('$','\$',$match[0]);
|
||||
}
|
||||
foreach ($infile as $l) {
|
||||
$l = str_replace('\"', 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 - 10);
|
||||
$v = preg_replace_callback($escape_s_exp, 'escape_s', $v);
|
||||
$inv = true;
|
||||
//$out .= $v;
|
||||
}
|
||||
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, 'escape_s', $match[1])
|
||||
. " => "
|
||||
. preg_replace_callback($escape_s_exp, 'escape_s', $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, 'escape_s', $k);
|
||||
//$out .= '$a->strings['.$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, 'escape_s', $k);
|
||||
$ink = true;
|
||||
}
|
||||
|
||||
if ($inv && substr($l, 0, 6) != "msgstr") {
|
||||
$v .= trim($l, "\"\r\n");
|
||||
$v = preg_replace_callback($escape_s_exp, 'escape_s', $v);
|
||||
//$out .= '$a->strings['.$k.'] = ';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if ($inv) {
|
||||
$inv = false;
|
||||
$out .= '"' . $v . '"';
|
||||
}
|
||||
if ($k != "") {
|
||||
$out .= ($arr ? "];\n" : ";\n");
|
||||
}
|
||||
|
||||
$out = str_replace(DQ_ESCAPE, '\"', $out);
|
||||
file_put_contents($outfile, $out);
|
||||
|
||||
}
|
||||
|
||||
if (array_search(__FILE__, get_included_files()) === 0) {
|
||||
po2php_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
// Tired of chasing typos and finding them after a commit.
|
||||
// Run this from cmdline in basedir and quickly see if we've
|
||||
// got any parse errors in our application files.
|
||||
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseObject;
|
||||
|
||||
error_reporting(E_ERROR | E_WARNING | E_PARSE);
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('log_errors', '0');
|
||||
|
||||
include 'boot.php';
|
||||
|
||||
$a = new App(dirname(__DIR__));
|
||||
BaseObject::setApp($a);
|
||||
|
||||
@include '.htconfig.php';
|
||||
|
||||
$phpath = $a->getConfigValue('config', 'php_path', 'php');
|
||||
|
||||
echo 'Directory: src' . PHP_EOL;
|
||||
$Iterator = new RecursiveDirectoryIterator('src');
|
||||
|
||||
foreach (new RecursiveIteratorIterator($Iterator) as $file) {
|
||||
if (substr($file, -4) === '.php') {
|
||||
passthru("$phpath -l $file", $ret);
|
||||
$ret === 0 || die();
|
||||
}
|
||||
}
|
||||
|
||||
echo "Directory: mod\n";
|
||||
$files = glob('mod/*.php');
|
||||
foreach ($files as $file) {
|
||||
passthru("$phpath -l $file", $ret);
|
||||
$ret === 0 || die();
|
||||
}
|
||||
|
||||
echo "Directory: include\n";
|
||||
$files = glob('include/*.php');
|
||||
foreach ($files as $file) {
|
||||
passthru("$phpath -l $file", $ret);
|
||||
$ret === 0 || die();
|
||||
}
|
||||
|
||||
echo "Directory: object\n";
|
||||
$files = glob('object/*.php');
|
||||
foreach ($files as $file) {
|
||||
passthru("$phpath -l $file", $ret);
|
||||
$ret === 0 || die();
|
||||
}
|
||||
|
||||
echo "Directory: addon\n";
|
||||
$dirs = glob('addon/*');
|
||||
|
||||
foreach ($dirs as $dir) {
|
||||
$addon = basename($dir);
|
||||
$files = glob($dir . '/' . $addon . '.php');
|
||||
foreach ($files as $file) {
|
||||
passthru("$phpath -l $file", $ret);
|
||||
$ret === 0 || die();
|
||||
}
|
||||
}
|
||||
|
||||
echo "String files\n";
|
||||
|
||||
echo 'util/strings.php' . "\n";
|
||||
passthru("$phpath -l util/strings.php", $ret);
|
||||
$ret === 0 || die();
|
||||
|
||||
$files = glob('view/lang/*/strings.php');
|
||||
foreach ($files as $file) {
|
||||
passthru("$phpath -l $file", $ret);
|
||||
$ret === 0 || die();
|
||||
}
|
Loading…
Reference in a new issue