Various improvements #51
10
bin/console
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
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
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
@echo OFF
|
||||||
|
:: in case DelayedExpansion is on and a path contains !
|
||||||
|
setlocal DISABLEDELAYEDEXPANSION
|
||||||
|
php "%~dp0console.php" %*
|
6
bin/console.php
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
include_once dirname(__DIR__) . '/boot.php';
|
||||||
|
|
||||||
|
(new Friendica\Directory\Core\Console($argv))->execute();
|
|
@ -1,11 +1,21 @@
|
||||||
{
|
{
|
||||||
"name": "friendica/dir",
|
"name": "friendica/dir",
|
||||||
"description": "The internet is our social network",
|
"description": "The internet is our social network",
|
||||||
"license": "AGPL3",
|
"license": "AGPL3",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {"Friendica\\Directory\\": "src"}
|
"psr-4": {
|
||||||
},
|
"Friendica\\Directory\\": "src"
|
||||||
"require": {
|
}
|
||||||
"php": ">=5.3"
|
},
|
||||||
}
|
"require": {
|
||||||
|
"php": ">=5.3",
|
||||||
|
"pear/Net_Ping": "dev-master",
|
||||||
|
"asika/simple-console": "^1.0"
|
||||||
|
},
|
||||||
|
"repositories": [
|
||||||
|
{
|
||||||
|
"type": "vcs",
|
||||||
|
"url": "https://github.com/pear/Net_Ping"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
171
composer.lock
generated
Normal file
|
@ -0,0 +1,171 @@
|
||||||
|
{
|
||||||
|
"_readme": [
|
||||||
|
"This file locks the dependencies of your project to a known state",
|
||||||
|
"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": "f330bced2cb3855635512ca74f0fa779",
|
||||||
|
"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": "pear/net_ping",
|
||||||
|
"version": "dev-master",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/pear/Net_Ping.git",
|
||||||
|
"reference": "d1f370b3a6072e5a493ed855804d98aadf818fa7"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/pear/Net_Ping/zipball/d1f370b3a6072e5a493ed855804d98aadf818fa7",
|
||||||
|
"reference": "d1f370b3a6072e5a493ed855804d98aadf818fa7",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"pear/pear_exception": "*"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "*"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-0": {
|
||||||
|
"Net": "./"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"include-path": [
|
||||||
|
"./"
|
||||||
|
],
|
||||||
|
"license": [
|
||||||
|
"PHP License"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"email": "cconstantine@php.net",
|
||||||
|
"name": "Craig Constantine",
|
||||||
|
"role": "Lead"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"email": "mj@php.net",
|
||||||
|
"name": "Martin Jansen",
|
||||||
|
"role": "Developer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"email": "jan@php.net",
|
||||||
|
"name": "Jan Lehnardt",
|
||||||
|
"role": "Developer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"email": "cox@php.net",
|
||||||
|
"name": "Thomas V.V.Cox",
|
||||||
|
"role": "Developer"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "More info available on: http://pear.php.net/package/Net_Ping",
|
||||||
|
"support": {
|
||||||
|
"issues": "http://pear.php.net/bugs/search.php?cmd=display&package_name[]=Net_Ping",
|
||||||
|
"source": "https://github.com/pear/Net_Ping"
|
||||||
|
},
|
||||||
|
"time": "2014-02-20T19:24:17+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "pear/pear_exception",
|
||||||
|
"version": "v1.0.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/pear/PEAR_Exception.git",
|
||||||
|
"reference": "8c18719fdae000b690e3912be401c76e406dd13b"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/pear/PEAR_Exception/zipball/8c18719fdae000b690e3912be401c76e406dd13b",
|
||||||
|
"reference": "8c18719fdae000b690e3912be401c76e406dd13b",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=4.4.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "*"
|
||||||
|
},
|
||||||
|
"type": "class",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "1.0.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-0": {
|
||||||
|
"PEAR": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"include-path": [
|
||||||
|
"."
|
||||||
|
],
|
||||||
|
"license": [
|
||||||
|
"BSD-2-Clause"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Helgi Thormar",
|
||||||
|
"email": "dufuz@php.net"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Greg Beaver",
|
||||||
|
"email": "cellog@php.net"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "The PEAR Exception base class.",
|
||||||
|
"homepage": "https://github.com/pear/PEAR_Exception",
|
||||||
|
"keywords": [
|
||||||
|
"exception"
|
||||||
|
],
|
||||||
|
"time": "2015-02-10T20:07:52+00:00"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"packages-dev": [],
|
||||||
|
"aliases": [],
|
||||||
|
"minimum-stability": "stable",
|
||||||
|
"stability-flags": {
|
||||||
|
"pear/net_ping": 20
|
||||||
|
},
|
||||||
|
"prefer-stable": false,
|
||||||
|
"prefer-lowest": false,
|
||||||
|
"platform": {
|
||||||
|
"php": ">=5.3"
|
||||||
|
},
|
||||||
|
"platform-dev": []
|
||||||
|
}
|
17
dfrndir.sql
|
@ -146,6 +146,8 @@ CREATE TABLE IF NOT EXISTS `site-probe` (
|
||||||
`site_health_id` int(10) UNSIGNED NOT NULL,
|
`site_health_id` int(10) UNSIGNED NOT NULL,
|
||||||
`dt_performed` datetime NOT NULL,
|
`dt_performed` datetime NOT NULL,
|
||||||
`request_time` int(10) UNSIGNED NOT NULL,
|
`request_time` int(10) UNSIGNED NOT NULL,
|
||||||
|
`avg_ping` int(11) DEFAULT NULL,
|
||||||
|
`speed_score` int(11) DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `site_health_id` (`site_health_id`),
|
KEY `site_health_id` (`site_health_id`),
|
||||||
KEY `dt_performed` (`dt_performed`)
|
KEY `dt_performed` (`dt_performed`)
|
||||||
|
@ -188,8 +190,10 @@ CREATE TABLE IF NOT EXISTS `sync-pull-queue` (
|
||||||
--
|
--
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `sync-push-queue` (
|
CREATE TABLE IF NOT EXISTS `sync-push-queue` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`url` varchar(255) CHARACTER SET utf8 NOT NULL,
|
`url` varchar(255) CHARACTER SET utf8 NOT NULL,
|
||||||
PRIMARY KEY (`url`)
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE KEY `url` (`url`) USING BTREE
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
-- --------------------------------------------------------
|
||||||
|
@ -228,13 +232,10 @@ CREATE TABLE IF NOT EXISTS `sync-timestamps` (
|
||||||
--
|
--
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `tag` (
|
CREATE TABLE IF NOT EXISTS `tag` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`term` varchar(50) NOT NULL,
|
||||||
`term` char(255) NOT NULL,
|
`profile_id` int(11) NOT NULL,
|
||||||
`nurl` char(255) NOT NULL,
|
PRIMARY KEY (`term`,`profile_id`) USING BTREE
|
||||||
PRIMARY KEY (`id`),
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
KEY `term` (`term`(250)),
|
|
||||||
KEY `nurl` (`nurl`(250))
|
|
||||||
) ENGINE=MyISAM AUTO_INCREMENT=101679 DEFAULT CHARSET=utf8mb4;
|
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -11,22 +11,38 @@ function attribute_contains($attr,$s) {
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
|
||||||
if(! function_exists('noscrape_dfrn')) {
|
if (!function_exists('noscrape_dfrn')) {
|
||||||
function noscrape_dfrn($url) {
|
|
||||||
|
function noscrape_dfrn($url)
|
||||||
|
{
|
||||||
$submit_noscrape_start = microtime(true);
|
$submit_noscrape_start = microtime(true);
|
||||||
$data = fetch_url($url);
|
$data = fetch_url($url);
|
||||||
$submit_noscrape_request_end = microtime(true);
|
$submit_noscrape_request_end = microtime(true);
|
||||||
if(empty($data)) return false;
|
if (empty($data)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$parms = json_decode($data, true);
|
$parms = json_decode($data, true);
|
||||||
if(!$parms || !count($parms)) return false;
|
if (!$parms || !count($parms)) {
|
||||||
$parms['tags'] = implode(' ', (array)$parms['tags']);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($parms['tags'])) {
|
||||||
|
$parms['tags'] = implode(' ', (array) $parms['tags']);
|
||||||
|
} else {
|
||||||
|
$parms['tags'] = '';
|
||||||
|
}
|
||||||
|
|
||||||
$submit_noscrape_end = microtime(true);
|
$submit_noscrape_end = microtime(true);
|
||||||
$parms['_timings'] = array(
|
$parms['_timings'] = array(
|
||||||
'fetch' => round(($submit_noscrape_request_end - $submit_noscrape_start) * 1000),
|
'fetch' => round(($submit_noscrape_request_end - $submit_noscrape_start) * 1000),
|
||||||
'scrape' => round(($submit_noscrape_end - $submit_noscrape_request_end) * 1000)
|
'scrape' => round(($submit_noscrape_end - $submit_noscrape_request_end) * 1000)
|
||||||
);
|
);
|
||||||
|
|
||||||
return $parms;
|
return $parms;
|
||||||
}}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if(! function_exists('scrape_dfrn')) {
|
if(! function_exists('scrape_dfrn')) {
|
||||||
function scrape_dfrn($url, $max_nodes=3500) {
|
function scrape_dfrn($url, $max_nodes=3500) {
|
||||||
|
|
|
@ -40,8 +40,8 @@ class dba
|
||||||
if ($this->debug) {
|
if ($this->debug) {
|
||||||
$mesg = '';
|
$mesg = '';
|
||||||
|
|
||||||
if ($this->db->mysqli->errno) {
|
if ($this->db->errno) {
|
||||||
$debug_text .= $this->db->mysqli->error . EOL;
|
$debug_text .= $this->db->error . EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
|
|
|
@ -110,6 +110,16 @@ if (!function_exists('run_site_probe')) {
|
||||||
$base_url = $entry['base_url'];
|
$base_url = $entry['base_url'];
|
||||||
$probe_location = $base_url . '/friendica/json';
|
$probe_location = $base_url . '/friendica/json';
|
||||||
|
|
||||||
|
$net_ping = Net_Ping::factory();
|
||||||
|
$net_ping->setArgs(['count' => 5]);
|
||||||
|
$result = $net_ping->ping(parse_url($base_url, PHP_URL_HOST));
|
||||||
|
|
||||||
|
if (is_a($result, 'Net_Ping_Result')) {
|
||||||
|
$avg_ping = $result->getAvg();
|
||||||
|
} else {
|
||||||
|
$avg_ping = null;
|
||||||
|
}
|
||||||
|
|
||||||
//Prepare the CURL call.
|
//Prepare the CURL call.
|
||||||
$handle = curl_init();
|
$handle = curl_init();
|
||||||
$options = array(
|
$options = array(
|
||||||
|
@ -172,6 +182,12 @@ if (!function_exists('run_site_probe')) {
|
||||||
//Done with CURL now.
|
//Done with CURL now.
|
||||||
curl_close($handle);
|
curl_close($handle);
|
||||||
|
|
||||||
|
if ($time && $avg_ping) {
|
||||||
|
$speed_score = max(1, $avg_ping > 10 ? $time / $avg_ping : $time / 50);
|
||||||
|
} else {
|
||||||
|
$speed_score = null;
|
||||||
|
}
|
||||||
|
|
||||||
#TODO: if the site redirects elsewhere, notice this site and record an issue.
|
#TODO: if the site redirects elsewhere, notice this site and record an issue.
|
||||||
$effective_base_url = parse_site_from_url($info['url']);
|
$effective_base_url = parse_site_from_url($info['url']);
|
||||||
$wrong_base_url = $effective_base_url !== $entry['base_url'];
|
$wrong_base_url = $effective_base_url !== $entry['base_url'];
|
||||||
|
@ -202,10 +218,12 @@ if (!function_exists('run_site_probe')) {
|
||||||
|
|
||||||
//Record the probe speed in a probes table.
|
//Record the probe speed in a probes table.
|
||||||
q(
|
q(
|
||||||
"INSERT INTO `site-probe` (`site_health_id`, `dt_performed`, `request_time`)" .
|
"INSERT INTO `site-probe` (`site_health_id`, `dt_performed`, `request_time`, `avg_ping`, `speed_score`)" .
|
||||||
"VALUES (%u, NOW(), %u)",
|
"VALUES (%u, NOW(), %u, %u, %u)",
|
||||||
$entry['id'],
|
$entry['id'],
|
||||||
$time
|
$time,
|
||||||
|
$avg_ping,
|
||||||
|
$speed_score
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isset($data->addons)) {
|
if (isset($data->addons)) {
|
||||||
|
@ -322,7 +340,7 @@ if (!function_exists('health_score_after_probe')) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Older than 3.3.x?
|
//Older than 3.3.x?
|
||||||
elseif (intval($versionParts[1] < 3)) {
|
elseif (!empty($versionParts[1]) && intval($versionParts[1] < 3)) {
|
||||||
$current -= 5; //Somewhat outdated.
|
$current -= 5; //Somewhat outdated.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,8 @@ function run_submit($url)
|
||||||
`updated` = '%s'
|
`updated` = '%s'
|
||||||
WHERE `id` = %d LIMIT 1", dbesc(datetime_convert()), intval($profile_id)
|
WHERE `id` = %d LIMIT 1", dbesc(datetime_convert()), intval($profile_id)
|
||||||
);
|
);
|
||||||
$r = q("DELETE FROM `tag` WHERE `nurl` = '%s'",
|
$r = q("DELETE FROM `tag` WHERE `profile_id` = %d",
|
||||||
dbesc($r[0]['nurl'])
|
intval($profile_id)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,11 +131,11 @@ function run_submit($url)
|
||||||
`updated` = '%s'
|
`updated` = '%s'
|
||||||
WHERE `id` = %d LIMIT 1",
|
WHERE `id` = %d LIMIT 1",
|
||||||
$params['fn'],
|
$params['fn'],
|
||||||
$params['pdesc'],
|
isset($params['pdesc']) ? $params['pdesc'] : '',
|
||||||
$params['locality'],
|
isset($params['locality']) ? $params['locality'] : '',
|
||||||
$params['region'],
|
isset($params['region']) ? $params['region'] : '',
|
||||||
$params['postal-code'],
|
isset($params['postal-code']) ? $params['postal-code'] : '',
|
||||||
$params['country-name'],
|
isset($params['country-name']) ? $params['country-name'] : '',
|
||||||
dbesc($url),
|
dbesc($url),
|
||||||
dbesc($nurl),
|
dbesc($nurl),
|
||||||
intval($params['comm']),
|
intval($params['comm']),
|
||||||
|
@ -188,9 +188,9 @@ function run_submit($url)
|
||||||
$t = substr($t, 0, 254);
|
$t = substr($t, 0, 254);
|
||||||
|
|
||||||
if (strlen($t)) {
|
if (strlen($t)) {
|
||||||
$r = q("INSERT INTO `tag` (`term`, `nurl`) VALUES ('%s', '%s') ",
|
$r = q("INSERT INTO `tag` (`term`, `profile_id`) VALUES ('%s', %d) ",
|
||||||
dbesc($t),
|
dbesc($t),
|
||||||
dbesc($nurl)
|
intval($profile_id)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ function sync_pull($url)
|
||||||
|
|
||||||
//If we support it that is.
|
//If we support it that is.
|
||||||
if ($a->config['syncing']['enable_pulling']) {
|
if ($a->config['syncing']['enable_pulling']) {
|
||||||
q("INSERT INTO `sync-pull-queue` (`url`) VALUES ('%s')", dbesc($url));
|
q("REPLACE INTO `sync-pull-queue` (`url`) VALUES ('%s')", dbesc($url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ function sync_push($url)
|
||||||
|
|
||||||
//If we support it that is.
|
//If we support it that is.
|
||||||
if ($a->config['syncing']['enable_pushing']) {
|
if ($a->config['syncing']['enable_pushing']) {
|
||||||
q("INSERT INTO `sync-push-queue` (`url`) VALUES ('%s')", dbesc($url));
|
q("REPLACE INTO `sync-push-queue` (`url`) VALUES ('%s')", dbesc($url));
|
||||||
}
|
}
|
||||||
|
|
||||||
sync_mark($url);
|
sync_mark($url);
|
||||||
|
@ -96,7 +96,7 @@ function get_push_targets()
|
||||||
*/
|
*/
|
||||||
function get_push_batch(App $a)
|
function get_push_batch(App $a)
|
||||||
{
|
{
|
||||||
return q("SELECT * FROM `sync-push-queue` LIMIT %u", intval($a->config['syncing']['max_push_items']));
|
return q("SELECT * FROM `sync-push-queue` ORDER BY `id` LIMIT %u", intval($a->config['syncing']['max_push_items']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,12 +18,9 @@ function photo_init(App $a)
|
||||||
$profile_id = str_replace('.jpg', '', $photo);
|
$profile_id = str_replace('.jpg', '', $photo);
|
||||||
|
|
||||||
$r = q('SELECT * FROM `photo` WHERE `profile-id` = %d LIMIT 1', intval($profile_id));
|
$r = q('SELECT * FROM `photo` WHERE `profile-id` = %d LIMIT 1', intval($profile_id));
|
||||||
|
|
||||||
if (count($r)) {
|
if (count($r)) {
|
||||||
$data = $r[0]['data'];
|
$data = $r[0]['data'];
|
||||||
}
|
} else {
|
||||||
|
|
||||||
if (x($data) === false || (!strlen($data))) {
|
|
||||||
$data = file_get_contents('images/default-profile-sm.jpg');
|
$data = file_get_contents('images/default-profile-sm.jpg');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ function servers_content(&$a) {
|
||||||
'HTTPS' => $site['ssl_state'] == 1,
|
'HTTPS' => $site['ssl_state'] == 1,
|
||||||
'Twitter' => $hasAddon(array('buffer', 'twitter')),
|
'Twitter' => $hasAddon(array('buffer', 'twitter')),
|
||||||
'Facebook' => $hasAddon(array('buffer')),
|
'Facebook' => $hasAddon(array('buffer')),
|
||||||
'Google+' => $hasAddon(array('buffer', 'gpluspost')),
|
'Google+' => $hasAddon(array('buffer', 'fromgplus')),
|
||||||
'RSS/Atom' => true, //Built-in.
|
'RSS/Atom' => true, //Built-in.
|
||||||
'Diaspora*' => $hasAddon(array('diaspora')),
|
'Diaspora*' => $hasAddon(array('diaspora')),
|
||||||
'pump.io' => $hasAddon(array('pumpio')),
|
'pump.io' => $hasAddon(array('pumpio')),
|
||||||
|
|
15
src/App.php
|
@ -34,17 +34,20 @@ class App
|
||||||
$this->pager = array();
|
$this->pager = array();
|
||||||
|
|
||||||
$this->scheme = ((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'])) ? 'https' : 'http');
|
$this->scheme = ((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'])) ? 'https' : 'http');
|
||||||
$this->hostname = str_replace('www.', '', $_SERVER['SERVER_NAME']);
|
if (!empty($_SERVER['SERVER_NAME'])) {
|
||||||
|
$this->hostname = str_replace('www.', '', $_SERVER['SERVER_NAME']);
|
||||||
|
}
|
||||||
set_include_path(get_include_path()
|
set_include_path(get_include_path()
|
||||||
. PATH_SEPARATOR . "include/$this->hostname"
|
|
||||||
. PATH_SEPARATOR . 'include'
|
. PATH_SEPARATOR . 'include'
|
||||||
. PATH_SEPARATOR . '.');
|
. PATH_SEPARATOR . '.');
|
||||||
|
|
||||||
if (substr($_SERVER['QUERY_STRING'], 0, 2) == "q=") {
|
if (!empty($_SERVER['QUERY_STRING'])) {
|
||||||
$_SERVER['QUERY_STRING'] = substr($_SERVER['QUERY_STRING'], 2);
|
if (substr($_SERVER['QUERY_STRING'], 0, 2) == "q=") {
|
||||||
}
|
$_SERVER['QUERY_STRING'] = substr($_SERVER['QUERY_STRING'], 2);
|
||||||
|
}
|
||||||
|
|
||||||
$this->query_string = $_SERVER['QUERY_STRING'];
|
$this->query_string = $_SERVER['QUERY_STRING'];
|
||||||
|
}
|
||||||
|
|
||||||
$q = isset($_GET['q']) ? $_GET['q'] : '';
|
$q = isset($_GET['q']) ? $_GET['q'] : '';
|
||||||
$this->cmd = trim($q, '/');
|
$this->cmd = trim($q, '/');
|
||||||
|
|
106
src/Core/Console.php
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Directory\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',
|
||||||
|
'probe' => __NAMESPACE__ . '\Console\Probe',
|
||||||
|
'po2php' => __NAMESPACE__ . '\Console\PoToPhp',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected function getHelp()
|
||||||
|
{
|
||||||
|
$help = <<<HELP
|
||||||
|
Usage: bin/console [--version] [-h|--help|-?] <command> [<args>] [-v]
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
config Edit site config
|
||||||
|
probe Probe a single site
|
||||||
|
po2php Generate a strings.php file from a messages.po file
|
||||||
|
|
||||||
|
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 ' . BUILD_ID);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
131
src/Core/Console/Config.php
Normal file
|
@ -0,0 +1,131 @@
|
||||||
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
<?php
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
namespace Friendica\Directory\Core\Console;
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
use Asika\SimpleConsole\CommandArgsException;
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
use dba;
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
use Friendica\Core;
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
require_once 'include/dba.php';
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
require_once 'include/text.php';
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
/**
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
* @brief tool to access the system config from the CLI
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
*
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
* With this script you can access the system configuration of your node from
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
* the CLI. You can do both, reading current values stored in the database and
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
* set new values to config variables.
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
*
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
* Usage:
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
* If you specify no parameters at the CLI, the script will list all config
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
* variables defined.
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
*
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
* If you specify one parameter, the script will list all config variables
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
* defined in this section of the configuration (e.g. "system").
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
*
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
* If you specify two parameters, the script will show you the current value
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
* of the named configuration setting. (e.g. "system loglevel")
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
*
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
* If you specify three parameters, the named configuration setting will be
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
* set to the value of the last parameter. (e.g. "system loglevel 0" will
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
* disable logging)
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
*
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
* @author Tobias Diekershoff
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
* @author Hypolite Petovan <mrpetovan@gmail.com>
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
*/
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
class Config extends \Asika\SimpleConsole\Console
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
{
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
protected $helpOptions = ['h', 'help', '?'];
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
protected function getHelp()
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
{
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
$help = <<<HELP
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
console config - Manage site configuration
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
Synopsis
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
bin/console config [-h|--help|-?] [-v]
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
bin/console config <category> [-h|--help|-?] [-v]
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
bin/console config <category> <key> [-h|--help|-?] [-v]
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
bin/console config <category> <key> <value> [-h|--help|-?] [-v]
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
Description
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
bin/console config
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
Lists all config values
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
bin/console config <category>
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
Lists all config values in the provided category
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
bin/console config <category> <key>
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
Shows the value of the provided key in the category
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
bin/console config <category> <key> <value>
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
Sets the value of the provided key in the category
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
Notes:
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
Setting config entries which are manually set in .htconfig.php may result in
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
conflict between database settings and the manual startup settings.
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
Options
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
-h|--help|-? Show help information
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
-v Show more debug information.
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
HELP;
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
return $help;
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
}
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
protected function doExecute()
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
{
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
$a = get_app();
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
if ($this->getOption('v')) {
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
$this->out('Executable: ' . $this->executable);
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
$this->out('Class: ' . __CLASS__);
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
$this->out('Arguments: ' . var_export($this->args, true));
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
$this->out('Options: ' . var_export($this->options, true));
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
}
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
if (count($this->args) > 3) {
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
throw new CommandArgsException('Too many arguments');
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
}
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
require_once '.htconfig.php';
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
unset($db_host, $db_user, $db_pass, $db_data);
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
if (!$result) {
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
throw new \RuntimeException('Unable to connect to database');
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
}
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
if (count($this->args) == 3) {
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
Core\Config::set($this->getArgument(0), $this->getArgument(1), $this->getArgument(2));
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
$this->out("config[{$this->getArgument(0)}][{$this->getArgument(1)}] = " . Core\Config::get($this->getArgument(0),
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
$this->getArgument(1)));
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
}
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
if (count($this->args) == 2) {
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
$this->out("config[{$this->getArgument(0)}][{$this->getArgument(1)}] = " . Core\Config::get($this->getArgument(0),
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
$this->getArgument(1)));
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
}
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
if (count($this->args) == 1) {
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
Core\Config::load($this->getArgument(0));
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
$a = get_app();
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
if (!is_null($a->config[$this->getArgument(0)])) {
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
foreach ($a->config[$this->getArgument(0)] as $k => $x) {
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
$this->out("config[{$this->getArgument(0)}][{$k}] = " . $x);
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
}
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
} else {
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
$this->out('Config section ' . $this->getArgument(0) . ' returned nothing');
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
}
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
}
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
if (count($this->args) == 0) {
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
$configs = dba::select('config');
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
foreach ($configs as $config) {
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
$this->out("config[{$config['cat']}][{$config['k']}] = " . $config['v']);
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
}
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
}
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
return 0;
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
}
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
|||||||
|
}
|
||||||
Should this be changed? Should this be changed?
Totally, this is added by my IDE and has no business in the repo. Totally, this is added by my IDE and has no business in the repo.
|
201
src/Core/Console/PoToPhp.php
Normal file
|
@ -0,0 +1,201 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Directory\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 - 10);
|
||||||
|
$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]);
|
||||||
|
}
|
||||||
|
}
|
114
src/Core/Console/Probe.php
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Directory\Core\Console;
|
||||||
|
|
||||||
|
use Asika\SimpleConsole\CommandArgsException;
|
||||||
|
use Asika\SimpleConsole\Console;
|
||||||
|
use dba;
|
||||||
|
use Net_Ping;
|
||||||
|
|
||||||
|
require_once 'include/dba.php';
|
||||||
|
require_once 'include/site-health.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Probe a single site
|
||||||
|
*
|
||||||
|
* License: AGPLv3 or later, same as Friendica
|
||||||
|
*
|
||||||
|
* @author Hypolite Petovan <mrpetovan@gmail.com>
|
||||||
|
*/
|
||||||
|
class Probe extends 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()
|
||||||
|
{
|
||||||
|
global $db, $a;
|
||||||
|
|
||||||
|
$a = new \Friendica\Directory\App();
|
||||||
|
|
||||||
|
if ($this->getOption('v')) {
|
||||||
|
$this->out('Class: ' . __CLASS__);
|
||||||
|
$this->out('Arguments: ' . var_export($this->args, true));
|
||||||
|
$this->out('Options: ' . var_export($this->options, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once '.htconfig.php';
|
||||||
|
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||||
|
unset($db_host, $db_user, $db_pass, $db_data);
|
||||||
|
|
||||||
|
if ($this->getOption('all')) {
|
||||||
|
$sites = q('SELECT * FROM `site-health` WHERE `health_score` >= 0');
|
||||||
|
if (is_bool($sites)) {
|
||||||
|
throw new \RuntimeException('SQL Error');
|
||||||
|
} elseif (!count($sites)) {
|
||||||
|
throw new \RuntimeException('No sites to probe ' . intval($this->getArgument(0)));
|
||||||
|
} else {
|
||||||
|
foreach($sites as $site) {
|
||||||
|
$this->out('Running probe for site ID ' . $site['id']);
|
||||||
|
run_site_probe($site['id'], $site);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($this->args) == 0) {
|
||||||
|
$this->out($this->getHelp());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($this->args) > 1) {
|
||||||
|
throw new CommandArgsException('Too many arguments');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_numeric($this->getArgument(0))) {
|
||||||
|
$site_health = q('SELECT * FROM `site-health` WHERE `id` = %u LIMIT 1', intval($this->getArgument(0)));
|
||||||
|
|
||||||
|
if (is_bool($site_health)) {
|
||||||
|
throw new \RuntimeException('SQL Error');
|
||||||
|
} elseif (!count($site_health)) {
|
||||||
|
throw new \RuntimeException('Unknown site with ID ' . intval($this->getArgument(0)));
|
||||||
|
} else {
|
||||||
|
$site_health = $site_health[0];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$site_health = q('SELECT * FROM `site-health` WHERE `base_url` LIKE "%%%s%%" OR `effective_base_url` LIKE "%%%s%%" LIMIT 1',
|
||||||
|
$this->getArgument(0), $this->getArgument(0));
|
||||||
|
|
||||||
|
if (is_bool($site_health)) {
|
||||||
|
throw new \RuntimeException('SQL Error');
|
||||||
|
} elseif (!count($site_health)) {
|
||||||
|
throw new \RuntimeException('Unknown site with base URL ' . $this->getArgument(0));
|
||||||
|
} else {
|
||||||
|
$site_health = $site_health[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->out(var_export($site_health, true));
|
||||||
|
|
||||||
|
$this->out('Running probe for site ID ' . $site_health['id']);
|
||||||
|
run_site_probe($site_health['id'], $site_health);
|
||||||
|
|
||||||
|
$this->out(var_export($site_health, true));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
122
util/po2php.php
|
@ -1,122 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
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) {
|
|
||||||
$len = strlen($l);
|
|
||||||
if ($l[0]=="#") $l="";
|
|
||||||
if (substr($l,0,15)=='"Plural-Forms: '){
|
|
||||||
$match=Array();
|
|
||||||
preg_match("|nplurals=([0-9]*); *plural=(.*)[;\\\\]|", $l, $match);
|
|
||||||
$cond = str_replace('n','$n',$match[2]);
|
|
||||||
$out .= 'function string_plural_select_' . $lang . '($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 .= "array(\n";
|
|
||||||
}
|
|
||||||
$match=Array();
|
|
||||||
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";
|
|
||||||
|
|
||||||
file_put_contents($outfile, $out);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (array_search(__file__,get_included_files())===0){
|
|
||||||
po2php_run($argv,$argc);
|
|
||||||
}
|
|
Should this be changed?