Move App to src
This commit is contained in:
parent
68c1939d12
commit
f297c670b3
14 changed files with 166 additions and 134 deletions
122
boot.php
122
boot.php
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require_once 'vendor/autoload.php';
|
||||||
|
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
define('BUILD_ID', 1000);
|
define('BUILD_ID', 1000);
|
||||||
|
@ -32,126 +34,6 @@ define('LOGGER_DEBUG', 2);
|
||||||
define('LOGGER_DATA', 3);
|
define('LOGGER_DATA', 3);
|
||||||
define('LOGGER_ALL', 4);
|
define('LOGGER_ALL', 4);
|
||||||
|
|
||||||
class App
|
|
||||||
{
|
|
||||||
public $module_loaded = false;
|
|
||||||
public $query_string;
|
|
||||||
public $config;
|
|
||||||
public $page;
|
|
||||||
public $profile;
|
|
||||||
public $user;
|
|
||||||
public $cid;
|
|
||||||
public $contact;
|
|
||||||
public $content;
|
|
||||||
public $data;
|
|
||||||
public $error = false;
|
|
||||||
public $cmd;
|
|
||||||
public $argv;
|
|
||||||
public $argc;
|
|
||||||
public $module;
|
|
||||||
public $pager;
|
|
||||||
public $strings;
|
|
||||||
public $path;
|
|
||||||
|
|
||||||
private $scheme;
|
|
||||||
private $hostname;
|
|
||||||
private $baseurl;
|
|
||||||
private $db;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->config = array();
|
|
||||||
$this->page = array();
|
|
||||||
$this->pager = array();
|
|
||||||
|
|
||||||
$this->scheme = ((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'])) ? 'https' : 'http');
|
|
||||||
$this->hostname = str_replace('www.', '', $_SERVER['SERVER_NAME']);
|
|
||||||
set_include_path("include/$this->hostname"
|
|
||||||
. PATH_SEPARATOR . 'include'
|
|
||||||
. PATH_SEPARATOR . '.');
|
|
||||||
|
|
||||||
if (substr($_SERVER['QUERY_STRING'], 0, 2) == "q=") {
|
|
||||||
$_SERVER['QUERY_STRING'] = substr($_SERVER['QUERY_STRING'], 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->query_string = $_SERVER['QUERY_STRING'];
|
|
||||||
|
|
||||||
$q = isset($_GET['q']) ? $_GET['q'] : '';
|
|
||||||
$this->cmd = trim($q, '/');
|
|
||||||
|
|
||||||
$this->argv = explode('/', $this->cmd);
|
|
||||||
$this->argc = count($this->argv);
|
|
||||||
if ((array_key_exists('0', $this->argv)) && strlen($this->argv[0])) {
|
|
||||||
$this->module = $this->argv[0];
|
|
||||||
} else {
|
|
||||||
$this->module = 'directory';
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->pager['page'] = ((x($_GET, 'page')) ? $_GET['page'] : 1);
|
|
||||||
$this->pager['itemspage'] = 50;
|
|
||||||
$this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
|
|
||||||
$this->pager['total'] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_baseurl($ssl = false)
|
|
||||||
{
|
|
||||||
if (strlen($this->baseurl)) {
|
|
||||||
return $this->baseurl;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->baseurl = (($ssl) ? 'https' : $this->scheme) . "://" . $this->hostname
|
|
||||||
. ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '');
|
|
||||||
return $this->baseurl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set_baseurl($url)
|
|
||||||
{
|
|
||||||
$this->baseurl = $url;
|
|
||||||
$this->hostname = basename($url);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_hostname()
|
|
||||||
{
|
|
||||||
return $this->hostname;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set_hostname($h)
|
|
||||||
{
|
|
||||||
$this->hostname = $h;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set_path($p)
|
|
||||||
{
|
|
||||||
$this->path = ltrim(trim($p), '/');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_path()
|
|
||||||
{
|
|
||||||
return $this->path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set_pager_total($n)
|
|
||||||
{
|
|
||||||
$this->pager['total'] = intval($n);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set_pager_itemspage($n)
|
|
||||||
{
|
|
||||||
$this->pager['itemspage'] = intval($n);
|
|
||||||
$this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function init_pagehead()
|
|
||||||
{
|
|
||||||
if (file_exists("view/head.tpl")) {
|
|
||||||
$s = file_get_contents("view/head.tpl");
|
|
||||||
}
|
|
||||||
$this->page['htmlhead'] = replace_macros($s, array(
|
|
||||||
'$baseurl' => $this->get_baseurl()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!function_exists('x')) {
|
if (!function_exists('x')) {
|
||||||
function x($s, $k = null)
|
function x($s, $k = null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
//Startup.
|
||||||
|
require_once 'boot.php';
|
||||||
|
|
||||||
|
use Friendica\Directory\App;
|
||||||
|
|
||||||
// Debug stuff.
|
// Debug stuff.
|
||||||
// ini_set('display_errors', 1);
|
// ini_set('display_errors', 1);
|
||||||
// ini_set('log_errors','0');
|
// ini_set('log_errors','0');
|
||||||
|
@ -9,9 +14,6 @@ $start_maintain = time();
|
||||||
|
|
||||||
$verbose = $argv[1] === 'verbose';
|
$verbose = $argv[1] === 'verbose';
|
||||||
|
|
||||||
//Startup.
|
|
||||||
require_once 'boot.php';
|
|
||||||
|
|
||||||
$a = new App;
|
$a = new App;
|
||||||
|
|
||||||
//Config and DB.
|
//Config and DB.
|
||||||
|
|
|
@ -40,6 +40,11 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//Startup.
|
||||||
|
require_once 'boot.php';
|
||||||
|
|
||||||
|
use Friendica\Directory\App;
|
||||||
|
|
||||||
// Debug stuff.
|
// Debug stuff.
|
||||||
ini_set('display_errors', 1);
|
ini_set('display_errors', 1);
|
||||||
ini_set('log_errors', '0');
|
ini_set('log_errors', '0');
|
||||||
|
@ -47,8 +52,6 @@ error_reporting(E_ALL ^ E_NOTICE);
|
||||||
|
|
||||||
$start_syncing = time();
|
$start_syncing = time();
|
||||||
|
|
||||||
//Startup.
|
|
||||||
require_once 'boot.php';
|
|
||||||
$a = new App;
|
$a = new App;
|
||||||
|
|
||||||
//Create a simple log function for CLI use.
|
//Create a simple log function for CLI use.
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
//Startup.
|
||||||
require_once 'boot.php';
|
require_once 'boot.php';
|
||||||
|
|
||||||
|
use Friendica\Directory\App;
|
||||||
|
|
||||||
$a = new App;
|
$a = new App;
|
||||||
|
|
||||||
@include '.htconfig.php';
|
@include '.htconfig.php';
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
//Startup.
|
||||||
require_once 'boot.php';
|
require_once 'boot.php';
|
||||||
|
|
||||||
|
use Friendica\Directory\App;
|
||||||
|
|
||||||
$a = new App;
|
$a = new App;
|
||||||
|
|
||||||
@include '.htconfig.php';
|
@include '.htconfig.php';
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
//Startup.
|
||||||
require_once 'boot.php';
|
require_once 'boot.php';
|
||||||
|
|
||||||
|
use Friendica\Directory\App;
|
||||||
|
|
||||||
$a = new App;
|
$a = new App;
|
||||||
|
|
||||||
@include('.htconfig.php');
|
@include('.htconfig.php');
|
||||||
|
@ -57,7 +60,7 @@ foreach ($contacts as $contact) {
|
||||||
}
|
}
|
||||||
if (!$update) {
|
if (!$update) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = q("SELECT * FROM `contact` WHERE `self` = 1 LIMIT 1");
|
$r = q("SELECT * FROM `contact` WHERE `self` = 1 LIMIT 1");
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
//Startup.
|
||||||
require_once 'boot.php';
|
require_once 'boot.php';
|
||||||
|
|
||||||
|
use Friendica\Directory\App;
|
||||||
|
|
||||||
$a = new App;
|
$a = new App;
|
||||||
|
|
||||||
@include(".htconfig.php");
|
@include(".htconfig.php");
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Friendica\Directory\App;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pull this URL to our pulling queue.
|
* Pull this URL to our pulling queue.
|
||||||
* @param string $url
|
* @param string $url
|
||||||
|
@ -92,7 +94,7 @@ function get_push_targets()
|
||||||
* @param object $a The App instance.
|
* @param object $a The App instance.
|
||||||
* @return array Batch of URL's.
|
* @return array Batch of URL's.
|
||||||
*/
|
*/
|
||||||
function get_push_batch($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` LIMIT %u", intval($a->config['syncing']['max_push_items']));
|
||||||
}
|
}
|
||||||
|
@ -102,7 +104,7 @@ function get_push_batch($a)
|
||||||
* @param object $a The App instance.
|
* @param object $a The App instance.
|
||||||
* @return list($targets, $batch) A list of both the targets array and batch array.
|
* @return list($targets, $batch) A list of both the targets array and batch array.
|
||||||
*/
|
*/
|
||||||
function get_pushing_job($a)
|
function get_pushing_job(App $a)
|
||||||
{
|
{
|
||||||
//When pushing is requested...
|
//When pushing is requested...
|
||||||
if (!!$a->config['syncing']['enable_pushing']) {
|
if (!!$a->config['syncing']['enable_pushing']) {
|
||||||
|
@ -221,7 +223,7 @@ function run_pushing_job($targets, $batch, $db_host, $db_user, $db_pass, $db_dat
|
||||||
* @param object $a The App instance.
|
* @param object $a The App instance.
|
||||||
* @return array Batch of URL's.
|
* @return array Batch of URL's.
|
||||||
*/
|
*/
|
||||||
function get_queued_pull_batch($a)
|
function get_queued_pull_batch(App $a)
|
||||||
{
|
{
|
||||||
//Randomize this, to prevent scraping the same servers too much or dead URL's.
|
//Randomize this, to prevent scraping the same servers too much or dead URL's.
|
||||||
$batch = q("SELECT * FROM `sync-pull-queue` ORDER BY RAND() LIMIT %u", intval($a->config['syncing']['max_pull_items']));
|
$batch = q("SELECT * FROM `sync-pull-queue` ORDER BY RAND() LIMIT %u", intval($a->config['syncing']['max_pull_items']));
|
||||||
|
@ -243,7 +245,7 @@ function get_pull_targets()
|
||||||
* @param object $a The App instance.
|
* @param object $a The App instance.
|
||||||
* @return array Batch of URL's.
|
* @return array Batch of URL's.
|
||||||
*/
|
*/
|
||||||
function get_remote_pull_batch($a)
|
function get_remote_pull_batch(App $a)
|
||||||
{
|
{
|
||||||
//Find our targets.
|
//Find our targets.
|
||||||
$targets = get_pull_targets();
|
$targets = get_pull_targets();
|
||||||
|
@ -305,7 +307,7 @@ function get_remote_pull_batch($a)
|
||||||
* @param object $a The App instance.
|
* @param object $a The App instance.
|
||||||
* @return array URL's to scrape.
|
* @return array URL's to scrape.
|
||||||
*/
|
*/
|
||||||
function get_pulling_job($a)
|
function get_pulling_job(App $a)
|
||||||
{
|
{
|
||||||
//No pulling today...
|
//No pulling today...
|
||||||
if (!$a->config['syncing']['enable_pulling']) {
|
if (!$a->config['syncing']['enable_pulling']) {
|
||||||
|
@ -375,7 +377,7 @@ function pull_worker($i, $threadc, $pull_batch, $db_host, $db_user, $db_pass, $d
|
||||||
* @param mixed $install Maybe a boolean.
|
* @param mixed $install Maybe a boolean.
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function run_pulling_job($a, $pull_batch, $db_host, $db_user, $db_pass, $db_data, $install)
|
function run_pulling_job(App $a, $pull_batch, $db_host, $db_user, $db_pass, $db_data, $install)
|
||||||
{
|
{
|
||||||
//We need the scraper.
|
//We need the scraper.
|
||||||
require_once 'include/submit.php';
|
require_once 'include/submit.php';
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once 'vendor/autoload.php';
|
|
||||||
require_once 'boot.php';
|
require_once 'boot.php';
|
||||||
|
|
||||||
|
use Friendica\Directory\App;
|
||||||
|
|
||||||
$a = new App;
|
$a = new App;
|
||||||
|
|
||||||
error_reporting(E_ERROR | E_WARNING | E_PARSE);
|
error_reporting(E_ERROR | E_WARNING | E_PARSE);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Friendica\Directory\App;
|
||||||
|
|
||||||
require_once 'include/widget.php';
|
require_once 'include/widget.php';
|
||||||
|
|
||||||
function directory_init(App $a)
|
function directory_init(App $a)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Friendica\Directory\App;
|
||||||
|
|
||||||
require_once 'datetime.php';
|
require_once 'datetime.php';
|
||||||
|
|
||||||
function photo_init(App $a)
|
function photo_init(App $a)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Friendica\Directory\App;
|
||||||
use Friendica\Directory\Rendering\View;
|
use Friendica\Directory\Rendering\View;
|
||||||
use Friendica\Directory\Helper\Search as SearchHelper;
|
use Friendica\Directory\Helper\Search as SearchHelper;
|
||||||
use Friendica\Directory\Helper\Profile as ProfileHelper;
|
use Friendica\Directory\Helper\Profile as ProfileHelper;
|
||||||
|
|
123
src/App.php
Normal file
123
src/App.php
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Directory;
|
||||||
|
|
||||||
|
class App
|
||||||
|
{
|
||||||
|
public $module_loaded = false;
|
||||||
|
public $query_string;
|
||||||
|
public $config;
|
||||||
|
public $page;
|
||||||
|
public $profile;
|
||||||
|
public $user;
|
||||||
|
public $cid;
|
||||||
|
public $contact;
|
||||||
|
public $content;
|
||||||
|
public $data;
|
||||||
|
public $error = false;
|
||||||
|
public $cmd;
|
||||||
|
public $argv;
|
||||||
|
public $argc;
|
||||||
|
public $module;
|
||||||
|
public $pager;
|
||||||
|
public $strings;
|
||||||
|
public $path;
|
||||||
|
|
||||||
|
private $scheme;
|
||||||
|
private $hostname;
|
||||||
|
private $baseurl;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->config = array();
|
||||||
|
$this->page = array();
|
||||||
|
$this->pager = array();
|
||||||
|
|
||||||
|
$this->scheme = ((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'])) ? 'https' : 'http');
|
||||||
|
$this->hostname = str_replace('www.', '', $_SERVER['SERVER_NAME']);
|
||||||
|
set_include_path(get_include_path()
|
||||||
|
. PATH_SEPARATOR . "include/$this->hostname"
|
||||||
|
. PATH_SEPARATOR . 'include'
|
||||||
|
. PATH_SEPARATOR . '.');
|
||||||
|
|
||||||
|
if (substr($_SERVER['QUERY_STRING'], 0, 2) == "q=") {
|
||||||
|
$_SERVER['QUERY_STRING'] = substr($_SERVER['QUERY_STRING'], 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->query_string = $_SERVER['QUERY_STRING'];
|
||||||
|
|
||||||
|
$q = isset($_GET['q']) ? $_GET['q'] : '';
|
||||||
|
$this->cmd = trim($q, '/');
|
||||||
|
|
||||||
|
$this->argv = explode('/', $this->cmd);
|
||||||
|
$this->argc = count($this->argv);
|
||||||
|
if ((array_key_exists('0', $this->argv)) && strlen($this->argv[0])) {
|
||||||
|
$this->module = $this->argv[0];
|
||||||
|
} else {
|
||||||
|
$this->module = 'directory';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->pager['page'] = ((x($_GET, 'page')) ? $_GET['page'] : 1);
|
||||||
|
$this->pager['itemspage'] = 50;
|
||||||
|
$this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
|
||||||
|
$this->pager['total'] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_baseurl($ssl = false)
|
||||||
|
{
|
||||||
|
if (strlen($this->baseurl)) {
|
||||||
|
return $this->baseurl;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->baseurl = (($ssl) ? 'https' : $this->scheme) . "://" . $this->hostname
|
||||||
|
. ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '');
|
||||||
|
return $this->baseurl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_baseurl($url)
|
||||||
|
{
|
||||||
|
$this->baseurl = $url;
|
||||||
|
$this->hostname = basename($url);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_hostname()
|
||||||
|
{
|
||||||
|
return $this->hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_hostname($h)
|
||||||
|
{
|
||||||
|
$this->hostname = $h;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_path($p)
|
||||||
|
{
|
||||||
|
$this->path = ltrim(trim($p), '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_path()
|
||||||
|
{
|
||||||
|
return $this->path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_pager_total($n)
|
||||||
|
{
|
||||||
|
$this->pager['total'] = intval($n);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_pager_itemspage($n)
|
||||||
|
{
|
||||||
|
$this->pager['itemspage'] = intval($n);
|
||||||
|
$this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function init_pagehead()
|
||||||
|
{
|
||||||
|
if (file_exists("view/head.tpl")) {
|
||||||
|
$s = file_get_contents("view/head.tpl");
|
||||||
|
}
|
||||||
|
$this->page['htmlhead'] = replace_macros($s, array(
|
||||||
|
'$baseurl' => $this->get_baseurl()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace Friendica\Directory\Helper;
|
namespace Friendica\Directory\Helper;
|
||||||
|
|
||||||
|
use Friendica\Directory\App;
|
||||||
|
|
||||||
use \OutOfBoundsException;
|
use \OutOfBoundsException;
|
||||||
use \ReflectionMethod;
|
use \ReflectionMethod;
|
||||||
|
|
||||||
|
@ -12,7 +14,7 @@ abstract class BaseHelper
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* A reference to the global App.
|
* A reference to the global App.
|
||||||
* @var \App
|
* @var Friendica\Directory\App
|
||||||
*/
|
*/
|
||||||
protected $app;
|
protected $app;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue