First commit

This commit is contained in:
Hypolite Petovan 2018-11-11 21:08:33 -05:00
commit 201edf2e4a
115 changed files with 29451 additions and 0 deletions

View file

@ -0,0 +1,86 @@
<?php
namespace Friendica\Directory\Controllers\Web;
use \Friendica\Directory\Content\Pager;
use \Friendica\Directory\Views\Widget\PopularCountries;
use \Friendica\Directory\Views\Widget\PopularTags;
use PDO;
use Slim\Http\Request;
use Slim\Http\Response;
/**
* @author Hypolite Petovan <mrpetovan@gmail.com>
*/
class Directory
{
/**
* @var \Atlas\Pdo\Connection
*/
private $atlas;
/**
* @var \Friendica\Directory\Models\Profile
*/
private $profileModel;
/**
* @var \Friendica\Directory\Views\Widget\AccountTypeTabs
*/
private $accountTypeTabs;
/**
* @var \Friendica\Directory\Views\PhpRenderer
*/
private $renderer;
/**
* @var \Friendica\Directory\Content\L10n
*/
private $l10n;
public function __construct(
\Atlas\Pdo\Connection $atlas,
\Friendica\Directory\Models\Profile $profileModel,
\Friendica\Directory\Views\Widget\AccountTypeTabs $accountTypeTabs,
\Friendica\Directory\Views\PhpRenderer $renderer,
\Friendica\Directory\Content\L10n $l10n
)
{
$this->atlas = $atlas;
$this->profileModel = $profileModel;
$this->accountTypeTabs = $accountTypeTabs;
$this->renderer = $renderer;
$this->l10n = $l10n;
}
public function render(Request $request, Response $response, array $args): Response
{
$popularTags = new PopularTags($this->atlas, $this->renderer);
$popularCountries = new PopularCountries($this->atlas, $this->renderer);
$pager = new Pager($this->l10n, $request, 20);
$condition = '';
$values = [];
if (!empty($args['account_type'])) {
$condition = '`account_type` = :account_type';
$values = ['account_type' => $args['account_type']];
}
$profiles = $this->profileModel->getListForDisplay($pager->getItemsPerPage(), $pager->getStart(), $condition, $values);
$count = $this->profileModel->getCountForDisplay($condition, $values);
$vars = [
'title' => $this->l10n->t('People'),
'profiles' => $profiles,
'pager_full' => $pager->renderFull($count),
'pager_minimal' => $pager->renderMinimal($count),
'accountTypeTabs' => $this->accountTypeTabs->render('directory', $args['account_type'] ?? ''),
'popularTags' => $popularTags->render(),
'popularCountries' => $popularCountries->render(),
];
$content = $this->renderer->fetch('directory.phtml', $vars);
// Render index view
return $this->renderer->render($response, 'layout.phtml', ['baseUrl' => $request->getUri()->getBaseUrl(), 'content' => $content]);
}
}

View file

@ -0,0 +1,54 @@
<?php
namespace Friendica\Directory\Controllers\Web;
use Slim\Http\Request;
use Slim\Http\Response;
/**
* @author Hypolite Petovan <mrpetovan@gmail.com>
*/
class Photo
{
/**
* @var \Atlas\Pdo\Connection
*/
private $atlas;
public function __construct(
\Atlas\Pdo\Connection $atlas
)
{
$this->atlas = $atlas;
}
public function render(Request $request, Response $response, array $args): Response
{
$data = $this->atlas->fetchValue(
'SELECT `data` FROM `photo` WHERE `profile_id` = :profile_id',
['profile_id' => $args['profile_id']]
);
if (!$data) {
$data = file_get_contents('public/images/default-profile-sm.jpg');
}
//Try and cache our result.
$etag = md5($data);
$response = $response
->withHeader('Etag', $etag)
->withHeader('Expires', date('D, d M Y H:i:s' . ' GMT', strtotime('now + 1 week')))
->withHeader('Cache-Control', 'max-age=' . intval(7 * 24 * 3600))
->withoutHeader('Pragma');
if ($request->getServerParam('HTTP_IF_NONE_MATCH') == $etag) {
$response = $response->withStatus(304, 'Not Modified');
} else {
$response = $response->withHeader('Content-type', 'image/jpeg');
$response->getBody()->write($data);
}
return $response;
}
}

View file

@ -0,0 +1,94 @@
<?php
namespace Friendica\Directory\Controllers\Web;
use \Friendica\Directory\Content\Pager;
use PDO;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
/**
* @author Hypolite Petovan <mrpetovan@gmail.com>
*/
class Search
{
/**
* @var \Atlas\Pdo\Connection
*/
private $atlas;
/**
* @var \Friendica\Directory\Models\Profile
*/
private $profileModel;
/**
* @var \Friendica\Directory\Views\PhpRenderer
*/
private $renderer;
/**
* @var \Friendica\Directory\Views\Widget\AccountTypeTabs
*/
private $accountTypeTabs;
/**
* @var \Friendica\Directory\Content\L10n
*/
private $l10n;
public function __construct(
\Atlas\Pdo\Connection $atlas,
\Friendica\Directory\Models\Profile $profileModel,
\Friendica\Directory\Views\Widget\AccountTypeTabs $accountTypeTabs,
\Friendica\Directory\Views\PhpRenderer $renderer,
\Friendica\Directory\Content\L10n $l10n
)
{
$this->atlas = $atlas;
$this->profileModel = $profileModel;
$this->accountTypeTabs = $accountTypeTabs;
$this->renderer = $renderer;
$this->l10n = $l10n;
}
public function render(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args): \Slim\Http\Response
{
$pager = new Pager($this->l10n, $request, 20);
$originalQuery = $query = filter_input(INPUT_GET, 'q');
$field = filter_input(INPUT_GET, 'field', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW & FILTER_FLAG_STRIP_HIGH);
if ($field) {
$query .= '%';
$sql_where = '`' . $field . '` LIKE :query';
} else {
$sql_where = "MATCH (p.`name`, p.`pdesc`, p.`profile_url`, p.`locality`, p.`region`, p.`country`, p.`tags` )
AGAINST (:query IN BOOLEAN MODE)";
}
$values = ['query' => $query];
$account_type = $args['account_type'] ?? '';
if ($account_type) {
$sql_where .= '
AND `account_type` = :account_type';
$values['account_type'] = $account_type;
}
$profiles = $this->profileModel->getListForDisplay($pager->getItemsPerPage(), $pager->getStart(), $sql_where, $values);
$count = $this->profileModel->getCountForDisplay($sql_where, $values);
$vars = [
'query' => $originalQuery,
'count' => $count,
'accountTypeTabs' => $this->accountTypeTabs->render('search', $account_type, ['q' => $originalQuery]),
'profiles' => $profiles,
'pager_full' => $pager->renderFull($count),
'pager_minimal' => $pager->renderMinimal($count),
];
$content = $this->renderer->fetch('search.phtml', $vars);
// Render index view
return $this->renderer->render($response, 'layout.phtml', ['baseUrl' => $request->getUri()->getBaseUrl(), 'content' => $content, 'noNavSearch' => true]);
}
}

View file

@ -0,0 +1,100 @@
<?php
namespace Friendica\Directory\Controllers\Web;
use \Friendica\Directory\Content\Pager;
use PDO;
use Slim\Http\Request;
use Slim\Http\Response;
/**
* @author Hypolite Petovan <mrpetovan@gmail.com>
*/
class Servers
{
/**
* @var \Atlas\Pdo\Connection
*/
private $atlas;
/**
* @var \Friendica\Directory\Views\PhpRenderer
*/
private $renderer;
/**
* @var \Friendica\Directory\Content\L10n
*/
private $l10n;
/**
* @var \Psr\SimpleCache\CacheInterface
*/
private $simplecache;
public function __construct(
\Atlas\Pdo\Connection $atlas,
\Friendica\Directory\Views\PhpRenderer $renderer,
\Friendica\Directory\Content\L10n $l10n,
\Psr\SimpleCache\CacheInterface $simplecache
)
{
$this->atlas = $atlas;
$this->renderer = $renderer;
$this->l10n = $l10n;
$this->simplecache = $simplecache;
}
public function render(Request $request, Response $response): Response
{
$stable_version = $this->simplecache->get('stable_version');
if (!$stable_version) {
$stable_version = trim(file_get_contents('https://git.friendi.ca/friendica/friendica/raw/branch/master/VERSION'));
$this->simplecache->set('stable_version', $stable_version);
}
$dev_version = $this->simplecache->get('dev_version');
if (!$dev_version) {
$dev_version = trim(file_get_contents('https://git.friendi.ca/friendica/friendica/raw/branch/develop/VERSION'));
$this->simplecache->set('dev_version', $dev_version);
}
$pager = new Pager($this->l10n, $request, 20);
$stmt = 'SELECT *
FROM `server` s
WHERE `reg_policy` = "REGISTER_OPEN"
AND `available`
AND NOT `hidden`
ORDER BY `health_score` DESC, `ssl_state` DESC, `info` != "" DESC, `dt_last_probed` DESC
LIMIT :start, :limit';
$servers = $this->atlas->fetchAll($stmt, [
'start' => [$pager->getStart(), PDO::PARAM_INT],
'limit' => [$pager->getItemsPerPage(), PDO::PARAM_INT]
]);
foreach ($servers as $key => $server) {
$servers[$key]['user_count'] = $this->atlas->fetchValue(
'SELECT COUNT(*) FROM `profile` WHERE `available` AND `server_id` = :server_id',
['server_id' => [$server['id'], PDO::PARAM_INT]]
);
}
$stmt = 'SELECT COUNT(*)
FROM `server` s
WHERE `reg_policy` = "REGISTER_OPEN"
AND `available`
AND NOT `hidden`';
$count = $this->atlas->fetchValue($stmt);
$vars = [
'title' => $this->l10n->t('Public Servers'),
'servers' => $servers,
'pager' => $pager->renderFull($count),
'stable_version' => $stable_version,
'dev_version' => $dev_version,
];
$content = $this->renderer->fetch('servers.phtml', $vars);
// Render index view
return $this->renderer->render($response, 'layout.phtml', ['baseUrl' => $request->getUri()->getBaseUrl(), 'content' => $content]);
}
}