/var/www/vhosts/divinut.com.br/httpdocs/site/controllers/NoticiaEventoController.php
$posts = \Lib\Util::Busca2($posts,$keyword);
}
}
$itensPagina = 10;
$sort = $req->Get('sort', 'destaque_desc,data_desc,ordenamento_desc');
$rows = (int)$req->Get('rows', $itensPagina);
$page = (int)$req->Get('page', 1);
if ('' == $sort) {
$sort = 'destaque_desc,data_desc,ordenamento_desc';
}
if (1 > $rows) {
$rows = $itensPagina;
}
if (1 > $page) {
$page = 1;
}
$total = count($posts);
$pages = ceil($total / $rows);
if ($page > $pages) {
$page = $pages;
}
$offset = ($page - 1) * $rows;
$posts = Util::Sort($posts,$sort);
$posts = array_slice($posts, $offset, $rows);
$extras['posts'] = $posts;
if (isset($categoria->id)) {
$categoria->url = $req->controller.'/'.$categoria->slug;
$req->uri = $categoria->url;
/* METATAG */
/var/www/vhosts/divinut.com.br/httpdocs/site/controllers/NoticiaEventoController.php
$posts = \Lib\Util::Busca2($posts,$keyword);
}
}
$itensPagina = 10;
$sort = $req->Get('sort', 'destaque_desc,data_desc,ordenamento_desc');
$rows = (int)$req->Get('rows', $itensPagina);
$page = (int)$req->Get('page', 1);
if ('' == $sort) {
$sort = 'destaque_desc,data_desc,ordenamento_desc';
}
if (1 > $rows) {
$rows = $itensPagina;
}
if (1 > $page) {
$page = 1;
}
$total = count($posts);
$pages = ceil($total / $rows);
if ($page > $pages) {
$page = $pages;
}
$offset = ($page - 1) * $rows;
$posts = Util::Sort($posts,$sort);
$posts = array_slice($posts, $offset, $rows);
$extras['posts'] = $posts;
if (isset($categoria->id)) {
$categoria->url = $req->controller.'/'.$categoria->slug;
$req->uri = $categoria->url;
/* METATAG */
/var/www/vhosts/divinut.com.br/httpdocs/site/controllers/NoticiaEventoController.php
parent::IndexAction($req, $res, $extras);
}
public static function PostAction($req, $res, $extras = array()) {
$req->controller = 'posts';
$req->method = 'interna';
static::InternaAction($req, $res, $extras);
}
public static function CategoriaAction($req, $res, $extras = array()) {
list($categoria_slug) = $req->params;
$categoria = \Models\Blog\Categorias::getBySlug($categoria_slug);
$req->method = $categoria->slug;
static::IndexAction($req, $res, $extras);
}
public static function ImportarAction($req, $res, $extras = array()) {
\Models\Blog\Importador::Importar();
parent::IndexAction($req, $res, $extras);
}
}
/var/www/vhosts/divinut.com.br/httpdocs/site/controllers/DefaultController.php
return $res->redirect('404');
}
//$req->params = array($slug);
$req->params_old = $req->params;
//trigger_error('1:' .print_r($req->params,1));
$req->params = array();
$req->params[] = $slug;
if (!in_array($req->method, array('index'))) {
$req->params[] = $req->method;
}
$req->params = array_merge($req->params, $req->params_old);
$req->controller = static::Pascal2KebabCase($matches['controller']);
$req->method = static::Pascal2KebabCase($matches['method']);
return call_user_func_array('\\Controller\\'.$modulo->site_controller, array($req, $res, $extras));
}
}
/var/www/vhosts/divinut.com.br/httpdocs/site/controllers/DefaultController.php
return $res->redirect('404');
}
//$req->params = array($slug);
$req->params_old = $req->params;
//trigger_error('1:' .print_r($req->params,1));
$req->params = array();
$req->params[] = $slug;
if (!in_array($req->method, array('index'))) {
$req->params[] = $req->method;
}
$req->params = array_merge($req->params, $req->params_old);
$req->controller = static::Pascal2KebabCase($matches['controller']);
$req->method = static::Pascal2KebabCase($matches['method']);
return call_user_func_array('\\Controller\\'.$modulo->site_controller, array($req, $res, $extras));
}
}
/var/www/vhosts/divinut.com.br/httpdocs/site/controllers/DefaultController.php
<?php
namespace Controller;
use Lib\Config;
use Lib\View;
class DefaultController {
public static function IndexAction($req,$res, $extraArgs = array()) {
$tpl = $req->controller.'/'.$req->method.'.twig';
$view_dir = dirname(__DIR__).'/views';
if (!file_exists($view_dir.'/'.$tpl)) {
$tpl = 'home/index.twig';
//$res->redirect('404');
return static::ResolveSlug($req, $res, $extraArgs);
}
$defaultArgs = array(
'req' => $req,
'res' => $res
);
$args = $defaultArgs + $extraArgs;
$res->render($tpl,$args);
}
public static function Pascal2KebabCase($input) {
//return strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $input));
return strtolower(preg_replace('/(?<!^)[A-Z]/', '-$0', $input));
}
/*
public static function ResolveSlug($req, $res, $extras = array()) {
$slug = $req->controller;
$record = \R::findOne('slugs','deleted = 0 and slug = ? limit 1', array($slug));
/var/www/vhosts/divinut.com.br/httpdocs/lib/Router.php
if ($cacheTime !== 0 && !isset($req->get->noCache) && in_array($req->type, array('GET'))) {
//CacheManager::setup($cache['config']);
//$cache = phpFastCache();
$cache_key = sha1($req->base_url.$req->controller.'/'.$req->method.'/'.join('/',$req->params).'?'.http_build_query((array)$req->get));
if (\Lib\Cache::exists($cache_key)) {
$cached = \Lib\Cache::get($cache_key,function() {});
}
//$cached = $cache->get($cache_key);
}
if (!$cached) {
$res->header('X-Cache','miss');
Hooks::call('before-action',array(&$req,&$res));
call_user_func_array(array($classname,$method), array($req,&$res));
Hooks::call('after-action',array(&$req,&$res));
if ($cacheTime !== 0 && !isset($req->get->noCache) && in_array($req->type, array('GET'))) {
\Lib\Cache::set($cache_key, $res->export());
/*
$res->on('background',function($cache,$cache_key,$res,$cacheTime){
$cache->set($cache_key,$res->export(),$cacheTime);
},array($cache,$cache_key,$res,$cacheTime));
*/
}
} else {
$res->import($cached);
$res->header('X-Cache','hit');
}
}
$req->end_time = microtime(true);
/var/www/vhosts/divinut.com.br/httpdocs/lib/Router.php
if ($cacheTime !== 0 && !isset($req->get->noCache) && in_array($req->type, array('GET'))) {
//CacheManager::setup($cache['config']);
//$cache = phpFastCache();
$cache_key = sha1($req->base_url.$req->controller.'/'.$req->method.'/'.join('/',$req->params).'?'.http_build_query((array)$req->get));
if (\Lib\Cache::exists($cache_key)) {
$cached = \Lib\Cache::get($cache_key,function() {});
}
//$cached = $cache->get($cache_key);
}
if (!$cached) {
$res->header('X-Cache','miss');
Hooks::call('before-action',array(&$req,&$res));
call_user_func_array(array($classname,$method), array($req,&$res));
Hooks::call('after-action',array(&$req,&$res));
if ($cacheTime !== 0 && !isset($req->get->noCache) && in_array($req->type, array('GET'))) {
\Lib\Cache::set($cache_key, $res->export());
/*
$res->on('background',function($cache,$cache_key,$res,$cacheTime){
$cache->set($cache_key,$res->export(),$cacheTime);
},array($cache,$cache_key,$res,$cacheTime));
*/
}
} else {
$res->import($cached);
$res->header('X-Cache','hit');
}
}
$req->end_time = microtime(true);
/var/www/vhosts/divinut.com.br/httpdocs/index.php
$regex = '#^http[s]?:\/\/(www\.)?(' . join("|", $hosts) . ')(\/' . preg_quote($request_uri) . ')?(\/)?(index\.php)?(\/)?#';
//trigger_error($regex);
$de = preg_replace('#^http[s]?:\/\/(www\.)?(' . join("|", $hosts) . ')(\/' . preg_quote($request_uri) . ')?(\/)?(index\.php)?(\/)?#', '', $de);
$para = preg_replace('#^http[s]?:\/\/(www\.)?(' . join("|", $hosts) . ')?(\/)?(index\.php)?(\/)?#', '', $para);
if ($request_uri == $de) {
$base_url = \Lib\Request::getBaseUrl();
$url = $base_url . $para;
//Header( “HTTP/1.1 301 Moved Permanently” );
header("Location: {$url}");
exit;
}
}
}
Router::init();