#0 | Application\Mvc\Helper\Breadcrumbs->add(Thông tin liên hệ)
/home/picture/public_html/app/modules/Photo/Controller/IndexController.php (209) <?php
namespace Photo\Controller;
use Application\Mvc\Controller;
use Photo\Model\Photo360;
use Photo\Model\Album;
use Google_Client;
use Google_Service_Drive;
use Google_Service_Exception;
use Phalcon\Mvc\View;
class IndexController extends Controller {
private static $album_slug_session = 'view_album_slug';
public function initialize() {
$moduleName = $this->helper->translate('Photo');
$this->helper->title($moduleName);
$this->helper->bc()->add($moduleName, '#');
}
public function indexAction() {
}
public function photo360Action() {
$slug = $this->dispatcher->getParam('uri');
$model = Photo360::findFirst(["uri='$slug'"]);
if (!$model || $model->getStatus() == Photo360::$DISABLE) {
$this->flash->warning($this->helper->translate("Data not found"));
return $this->response->redirect($this->url->get());
}
$this->helper->title()->prepend($model->getName());
$this->view->setMainView(MAIN_VIEW_PATH . 'photo360');
$this->view->setLayout("");
$this->view->bodyClass = "photo360-page photo360-page-{$model->getId()}";
if ($model->getNavbar() == 'none') {
$this->view->extra_style = ".psv-navbar{display:none;}";
}
$this->view->photo360_data = $model->buildScript();
}
public function albumAction() {
$slug = $this->dispatcher->getParam('uri');
$model = Album::findFirst(["uri='$slug'"]);
if (!$model || $model->getStatus() == Album::$DISABLE) {
$this->flash->warning($this->helper->translate("Data not found"));
return $this->response->redirect($this->url->get());
}
if ($model->getRequiredSession()) {
if (!$this->auth->isViewer()) {
$this->session->set(self::$album_slug_session, $model->getUri());
return $this->response->redirect($this->url->get(['for' => 'album_view_required']));
}
}
$this->helper->title()->prepend($model->getName());
$this->helper->bc()->add($model->getNamePath(), true);
/* $key = 'album-' . $slug;
$exists = $this->view->getCache()->exists($key);
if (!$exists) { */
$albumcachekey = HOST_HASH . md5("Album::find(parent={$model->getId()})");
$album_childs = $this->cache->get($albumcachekey);
if ($album_childs === null) {
$album_child = Album::find([
"status=:status: AND parent=:parent:",
"bind" => [
"status" => Album::$ACTIVE,
"parent" => $model->getId()
],
"order" => "sticky DESC"
]);
$album_childs = array();
foreach($album_child as $al){
$image = $this->helper->iTool()->resize($al->getFeatureImage(), 500, 310);
$al->setFeatureImage($image);
$album_childs[] = $al;
}
$this->cache->save($albumcachekey, $album_childs);
}
if (count($album_childs)) {
$this->view->album_child = $album_childs;
}
if ($model->getParent()) {
$parentAlbum = Album::findFirst($model->getParent());
$this->view->album_parent = $parentAlbum;
}
if ($model->getDriveId()) {
$client = $this->getGoogleClient();
$service = new Google_Service_Drive($client);
$optParams = array(
'q' => "'{$model->getDriveId()}' in parents AND mimeType contains 'image/'",
'pageSize' => $this->registry->cms['PAGE_SIZE'],
'fields' => 'nextPageToken, files(id, name, spaces, hasThumbnail,thumbnailLink)'
);
try {
$results = $service->files->listFiles($optParams);
} catch (Google_Service_Exception $exc) {
$errors = json_decode($exc->getMessage());
foreach ($errors as $e) {
$this->flash->error("{$e->code} - {$e->message}");
break;
}
}
$this->view->results = $results;
}
$this->view->album = $model;
/* }
$this->view->cache(array("key" => $key)); */
}
public function loadmoreAction() {
$this->view->disable();
$data = array(
"status" => 0,
"data" => "",
);
if ($this->request->isPost()) {
$album_id = $this->request->getPost("album_id");
$pageToken = $this->request->getPost("next_page_token");
$model = Album::findFirst("id={$album_id}");
if ($model) {
$client = $this->getGoogleClient();
$service = new Google_Service_Drive($client);
$optParams = array(
'q' => "'{$model->getDriveId()}' in parents AND mimeType contains 'image/'",
'pageSize' => $this->registry->cms['PAGE_SIZE'],
'fields' => 'nextPageToken, files(id, name, spaces, hasThumbnail,thumbnailLink)',
'pageToken' => $pageToken
);
try {
$results = $service->files->listFiles($optParams);
$this->view->setPartialsDir("");
$imageContainer = \Application\Utils\Hash::generateHash(8);
$this->view->partial("index/loadmore", ['results' => $results, 'album' => $model, 'imageContainer' => $imageContainer]);
$html = ob_get_contents();
$this->view->finish();
$data = array(
'status' => 1,
'data' => $html,
'imageContainer' => $imageContainer,
'nextPageToken' => $results->nextPageToken
);
} catch (Google_Service_Exception $exc) {
$errors = json_decode($exc->getMessage());
foreach ($errors as $e) {
$data["data"] = "{$e->code} - {$e->message}";
break;
}
}
}
}
echo json_encode($data);
}
public function photoAction() {
$file_id = $this->dispatcher->getParam('id');
if (!$file_id) {
$this->flash->warning($this->helper->translate("Data not found"));
return $this->response->redirect($this->url->get());
}
$key = 'photo-' . $file_id;
$exists = $this->view->getCache()->exists($key);
/* Check cache */
if (!$exists) {
/*$client = $this->getGoogleClient();
$service = new Google_Service_Drive($client);
$optParams = array(
'fields' => "*",
);
try {
$file = $service->files->get($file_id, $optParams);
} catch (Google_Service_Exception $exc) {
$errors = json_decode($exc->getMessage());
foreach ($errors as $e) {
$this->flash->error("{$e->code} - {$e->message}");
break;
}
}*/
$this->view->imagesrc = "https://drive.google.com/thumbnail?id={$file_id}&sz=s5000";
//$this->view->result = $file;
$this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
}
/* Store cache for 2 days */
$this->view->cache(array(
"key" => $key,
'lifetime' => 86400,
'level' => View::LEVEL_ACTION_VIEW
));
}
private function getGoogleClient() {
$client = new Google_Client();
$client->setAuthConfig(CREDENTIALS_FILE_PATH);
$client->setScopes([
Google_Service_Drive::DRIVE,
Google_Service_Drive::DRIVE_PHOTOS_READONLY
]);
return $client;
}
public function contactAction() {
$this->helper->bc()->add("Thông tin liên hệ");
$album_slug = $this->session->get(self::$album_slug_session);
$album = Album::findFirst(["uri='$album_slug'"]);
$url_redirect = $this->url->get();
if (!$album || $album->getStatus() == Album::$DISABLE) {
$this->flash->warning($this->helper->translate("Data not found"));
return $this->response->redirect($this->url->get());
} else {
$url_redirect = $album->viewLink();
}
if ($this->auth->isViewer()) {
return $this->response->redirect($url_redirect);
}
$form = new \User\Form\ContactForm();
$form->initAdd();
if ($this->request->isPost()) {
$data = $this->request->getPost();
$contact = new \User\Model\ContactInfo();
$form->bind($data, $contact);
$contact->setAlbumId($album->getId());
if ($contact->save()) {
$this->auth->setAlbumSession($contact->getId());
return $this->response->redirect($url_redirect);
} else {
$this->flash->error("Không thể lưu thông tin");
}
}
$this->view->form = $form;
}
}
|
#3 | Phalcon\Dispatcher->dispatch()
/home/picture/public_html/app/Bootstrap.php (351) <?php
namespace TLMC;
use Application\Cache\Manager as CacheManager;
/**
* Bootstrap
*/
class Bootstrap {
public function run() {
$di = new \Phalcon\DI\FactoryDefault();
// Config
require_once APPLICATION_PATH . '/modules/Cms/Config.php';
$config = \Cms\Config::get();
$di->set('config', $config);
// Registry
$registry = new \Phalcon\Registry();
$di->set('registry', $registry);
// Loader
$loader = new \Phalcon\Loader();
$loader->registerNamespaces($config->loader->namespaces->toArray());
$loader->registerDirs([APPLICATION_PATH . "/plugins/"]);
//$loader->registerFiles([APPLICATION_PATH . '/../vendor/autoload.php']);
$loader->register();
require_once APPLICATION_PATH . '/../vendor/autoload.php';
// Database
$db = new \Phalcon\Db\Adapter\Pdo\Mysql([
"host" => $config->database->host,
"username" => $config->database->username,
"password" => $config->database->password,
"dbname" => $config->database->dbname,
"charset" => $config->database->charset,
]);
$di->set('db', $db);
//Connect Social Network
//$this->initRecaptcha($di);
// View
$this->initView($di);
// URL
$url = new \Phalcon\Mvc\Url();
$url->setBasePath($config->base_path);
$url->setBaseUri($config->base_path);
$di->set('url', $url);
// Cache
$this->initCache($di);
// CMS
$cmsModel = new \Cms\Model\Configuration();
$registry->cms = $cmsModel->getConfig(); // Отправляем в Registry
// Application
$application = new \Phalcon\Mvc\Application();
$application->registerModules($config->modules->toArray());
// Events Manager, Dispatcher
$this->initEventManager($di);
// Session
$session = new \Phalcon\Session\Adapter\Files();
$session->start();
$di->set('session', $session);
$acl = new \Application\Acl\DefaultAcl();
$di->set('acl', $acl);
// JS Assets
$this->initAssetsManager($di);
// Flash helper
$flash = new \Phalcon\Flash\Session([
'error' => 'alert alert-error',
'success' => 'alert alert-success',
'notice' => 'alert alert-notice',
'warning' => 'alert alert-warning',
]);
$di->set('flash', $flash);
$di->set('helper', new \Application\Mvc\Helper());
/* Mailing */
$di->set('mail', new Plugin\Mail());
/* Auth */
$di->set('auth', new Plugin\AuthInjection());
/* Queue */
/* $di->set('queue', new \Phalcon\Queue\Beanstalk([
"host" => $config->queue->host,
"port" => $config->queue->port
])); */
// Routing
$this->initRouting($application, $di);
//Check site maintenance
$this->checkSiteMaintain($di);
$application->setDI($di);
// Main dispatching process
$response = $this->dispatch($di);
$response->send();
}
private function initRouting($application, $di) {
$router = new \Application\Mvc\Router\DefaultRouter();
$router->setDi($di);
foreach ($application->getModules() as $module) {
$routesClassName = str_replace('Module', 'Routes', $module['className']);
if (class_exists($routesClassName)) {
$routesClass = new $routesClassName();
$router = $routesClass->init($router);
}
$initClassName = str_replace('Module', 'Init', $module['className']);
if (class_exists($initClassName)) {
new $initClassName();
}
}
$di->set('router', $router);
}
private function initAssetsManager($di) {
$config = $di->get('config');
$assetsManager = new \Application\Assets\Manager();
$js_collection = $assetsManager->collection('js')
->setLocal(true)
->addFilter(new \Phalcon\Assets\Filters\Jsmin())
->setTargetPath(ROOT . '/assets/js.js')
->setTargetUri('assets/js.js')
->join(true);
if ($config->assets->js) {
foreach ($config->assets->js as $js) {
$js_collection->addJs(ROOT . '/' . $js);
}
}
// Admin JS Assets
/* $assetsManager->collection('modules-admin-js')
->setLocal(true)
->addFilter(new \Phalcon\Assets\Filters\Jsmin())
->setTargetPath(ROOT . '/assets/modules-admin.js')
->setTargetUri('assets/modules-admin.js')
->join(true);
// Admin LESS Assets
$assetsManager->collection('modules-admin-less')
->setLocal(true)
->addFilter(new \Application\Assets\Filter\Less())
->setTargetPath(ROOT . '/assets/modules-admin.less')
->setTargetUri('assets/modules-admin.less')
->join(true)
->addCss(APPLICATION_PATH . '/modules/Admin/assets/admin.less'); */
$di->set('assets', $assetsManager);
}
private function initEventManager($di) {
$eventsManager = new \Phalcon\Events\Manager();
$dispatcher = new \Phalcon\Mvc\Dispatcher();
$eventsManager->attach("dispatch:beforeDispatchLoop", function ($event, $dispatcher) use ($di) {
new \TLMC\Plugin\Auth($dispatcher);
new \TLMC\Plugin\CheckPoint($di->get('request'));
new \TLMC\Plugin\Localization($di->get('config'));
new \TLMC\Plugin\AdminLocalization($di->get('config'));
new \TLMC\Plugin\Acl($di->get('acl'), $dispatcher, $di->get('view'));
//new \TLMC\Plugin\AccessLog($di);
});
$eventsManager->attach("dispatch:afterDispatchLoop", function ($event, $dispatcher) use ($di) {
//new \Seo\Plugin\SeoManager($dispatcher, $di->get('request'), $di->get('router'), $di->get('view'));
new \TLMC\Plugin\Title($di);
});
// Profiler
$registry = $di->get('registry');
if ($registry->cms['PROFILER']) {
$profiler = new \Phalcon\Db\Profiler();
$di->set('profiler', $profiler);
$eventsManager->attach('db', function ($event, $db) use ($profiler) {
if ($event->getType() == 'beforeQuery') {
$profiler->startProfile($db->getSQLStatement());
}
if ($event->getType() == 'afterQuery') {
$profiler->stopProfile();
}
});
}
$db = $di->get('db');
$db->setEventsManager($eventsManager);
$dispatcher->setEventsManager($eventsManager);
$di->set('dispatcher', $dispatcher);
}
private function initView($di) {
$view = new \Phalcon\Mvc\View();
define('MAIN_VIEW_PATH', '../../../views/');
$view->setMainView(MAIN_VIEW_PATH . 'main');
$view->setLayoutsDir(MAIN_VIEW_PATH . '/layouts/');
$view->setLayout('main');
$view->setPartialsDir(MAIN_VIEW_PATH . '/partials/');
// Volt
$volt = new \Application\Mvc\View\Engine\Volt($view, $di);
$volt->setOptions(['compiledPath' => APPLICATION_PATH . '/../data/cache/volt/']);
$volt->initCompiler();
$phtml = new \Phalcon\Mvc\View\Engine\Php($view, $di);
$viewEngines = [
".volt" => $volt,
".phtml" => $phtml,
];
$view->registerEngines($viewEngines);
$ajax = $di->get('request')->getQuery('_ajax');
if ($ajax) {
$view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_LAYOUT);
}
$di->set('view', $view);
return $view;
}
private function initCache($di) {
$config = $di->get('config');
$cacheFrontend = new \Phalcon\Cache\Frontend\Data([
"lifetime" => 120,
"prefix" => HOST_HASH,
]);
$viewCacheFrontend = new \Phalcon\Cache\Frontend\Output([
'lifetime' => 120,
]);
$cache = null;
switch ($config->cache) {
case 'file':
$cache = new \Phalcon\Cache\Backend\File($cacheFrontend, [
"cacheDir" => APPLICATION_PATH . "/../data/cache/backend/"
]);
break;
case 'memcache':
$cache = new \Phalcon\Cache\Backend\Memcache(
$cacheFrontend, [
"host" => $config->memcache->host,
"port" => $config->memcache->port,
]);
break;
case 'memcached':
$cache = new \Phalcon\Cache\Backend\Libmemcached(
$cacheFrontend, [
"host" => $config->memcached->host,
"port" => $config->memcached->port,
]);
break;
}
$di->set('cache', $cache, true);
$di->set('modelsCache', $cache, true);
$viewCache = new \Phalcon\Cache\Backend\File($viewCacheFrontend, [
"cacheDir" => APPLICATION_PATH . "/../data/cache/frontend/"
]);
$di->set('viewCache', $viewCache, true);
\Application\Widget\Proxy::$cache = $cache; // Modules Widget System
$modelsMetadata = new \Phalcon\Mvc\Model\Metadata\Memory();
$di->set('modelsMetadata', $modelsMetadata);
$di->set('cacheManager', new CacheManager());
}
private function initRecaptcha($di) {
$config = $di->get('config');
$recaptcha = new \ReCaptcha\ReCaptcha($config->recaptcha->private_key);
$di->set('recaptcha', $recaptcha);
}
private function checkSiteMaintain($di) {
$auth = $di->get('auth');
if ($auth && $auth->getUsername()) {
return;
}
$request = $di->get('request');
$uri = $request->getURI();
if (in_array($uri, ["/admin", "/dang-nhap"])) {
return;
}
$registry = $di->get('registry');
if ($registry->cms['TECHNICAL_WORKS']) {
$view = $di->get('view');
$view->setViewsDir(__DIR__ . '/modules/Index/views/');
$view->setPartialsDir(__DIR__ . '/views/partials/');
$view->start();
$view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
$view->message_contact = $registry->cms['ADMIN_EMAIL']." / ".$registry->cms['PHONE_NUMBER'];
$view->render('index', 'maintain');
$view->finish();
echo $view->getContent();
exit;
}
}
private function dispatch($di) {
$router = $di['router'];
$router->handle();
$view = $di['view'];
$dispatcher = $di['dispatcher'];
$response = $di['response'];
$dispatcher->setModuleName($router->getModuleName());
$dispatcher->setControllerName($router->getControllerName());
$dispatcher->setActionName($router->getActionName());
$dispatcher->setParams($router->getParams());
$moduleName = \Application\Utils\ModuleName::camelize($router->getModuleName());
$ModuleClassName = $moduleName . '\Module';
if (class_exists($ModuleClassName)) {
$module = new $ModuleClassName;
$module->registerAutoloaders();
$module->registerServices($di);
}
$view->start();
$registry = $di['registry'];
if ($registry->cms['DEBUG_MODE']) {
$debug = new \Phalcon\Debug();
$debug->listen();
$dispatcher->dispatch();
} else {
try {
$dispatcher->dispatch();
} catch (\Phalcon\Exception $e) {
// Errors catching
$view->setViewsDir(__DIR__ . '/modules/Index/views/');
$view->setPartialsDir(__DIR__ . '/views/partials/');
$view->e = $e;
if ($e instanceof \Phalcon\Mvc\Dispatcher\Exception) {
$response->setStatusCode(404, 'Not Found');
$view->render('error', 'error404');
} else {
$response->setStatusCode(503, 'Service Unavailable');
$view->render('error', 'error503');
}
$view->finish();
echo $view->getContent();
exit;
return $response;
}
}
$view->render(
$dispatcher->getControllerName(), $dispatcher->getActionName(), $dispatcher->getParams()
);
$view->finish();
// AJAX
$request = $di['request'];
$_ajax = $request->getQuery('_ajax');
if ($_ajax) {
$contents = $view->getContent();
$return = new \stdClass();
$return->html = $contents;
$return->title = $di->get('helper')->title()->get();
$return->success = true;
if ($view->bodyClass) {
$return->bodyClass = $view->bodyClass;
}
$headers = $response->getHeaders()->toArray();
if (isset($headers[404]) || isset($headers[503])) {
$return->success = false;
}
$response->setContentType('application/json', 'UTF-8');
$response->setContent(json_encode($return));
} else {
$response->setContent($view->getContent());
}
return $response;
}
}
|
#4 | TLMC\Bootstrap->dispatch(Object(Phalcon\Di\FactoryDefault))
/home/picture/public_html/app/Bootstrap.php (106) <?php
namespace TLMC;
use Application\Cache\Manager as CacheManager;
/**
* Bootstrap
*/
class Bootstrap {
public function run() {
$di = new \Phalcon\DI\FactoryDefault();
// Config
require_once APPLICATION_PATH . '/modules/Cms/Config.php';
$config = \Cms\Config::get();
$di->set('config', $config);
// Registry
$registry = new \Phalcon\Registry();
$di->set('registry', $registry);
// Loader
$loader = new \Phalcon\Loader();
$loader->registerNamespaces($config->loader->namespaces->toArray());
$loader->registerDirs([APPLICATION_PATH . "/plugins/"]);
//$loader->registerFiles([APPLICATION_PATH . '/../vendor/autoload.php']);
$loader->register();
require_once APPLICATION_PATH . '/../vendor/autoload.php';
// Database
$db = new \Phalcon\Db\Adapter\Pdo\Mysql([
"host" => $config->database->host,
"username" => $config->database->username,
"password" => $config->database->password,
"dbname" => $config->database->dbname,
"charset" => $config->database->charset,
]);
$di->set('db', $db);
//Connect Social Network
//$this->initRecaptcha($di);
// View
$this->initView($di);
// URL
$url = new \Phalcon\Mvc\Url();
$url->setBasePath($config->base_path);
$url->setBaseUri($config->base_path);
$di->set('url', $url);
// Cache
$this->initCache($di);
// CMS
$cmsModel = new \Cms\Model\Configuration();
$registry->cms = $cmsModel->getConfig(); // Отправляем в Registry
// Application
$application = new \Phalcon\Mvc\Application();
$application->registerModules($config->modules->toArray());
// Events Manager, Dispatcher
$this->initEventManager($di);
// Session
$session = new \Phalcon\Session\Adapter\Files();
$session->start();
$di->set('session', $session);
$acl = new \Application\Acl\DefaultAcl();
$di->set('acl', $acl);
// JS Assets
$this->initAssetsManager($di);
// Flash helper
$flash = new \Phalcon\Flash\Session([
'error' => 'alert alert-error',
'success' => 'alert alert-success',
'notice' => 'alert alert-notice',
'warning' => 'alert alert-warning',
]);
$di->set('flash', $flash);
$di->set('helper', new \Application\Mvc\Helper());
/* Mailing */
$di->set('mail', new Plugin\Mail());
/* Auth */
$di->set('auth', new Plugin\AuthInjection());
/* Queue */
/* $di->set('queue', new \Phalcon\Queue\Beanstalk([
"host" => $config->queue->host,
"port" => $config->queue->port
])); */
// Routing
$this->initRouting($application, $di);
//Check site maintenance
$this->checkSiteMaintain($di);
$application->setDI($di);
// Main dispatching process
$response = $this->dispatch($di);
$response->send();
}
private function initRouting($application, $di) {
$router = new \Application\Mvc\Router\DefaultRouter();
$router->setDi($di);
foreach ($application->getModules() as $module) {
$routesClassName = str_replace('Module', 'Routes', $module['className']);
if (class_exists($routesClassName)) {
$routesClass = new $routesClassName();
$router = $routesClass->init($router);
}
$initClassName = str_replace('Module', 'Init', $module['className']);
if (class_exists($initClassName)) {
new $initClassName();
}
}
$di->set('router', $router);
}
private function initAssetsManager($di) {
$config = $di->get('config');
$assetsManager = new \Application\Assets\Manager();
$js_collection = $assetsManager->collection('js')
->setLocal(true)
->addFilter(new \Phalcon\Assets\Filters\Jsmin())
->setTargetPath(ROOT . '/assets/js.js')
->setTargetUri('assets/js.js')
->join(true);
if ($config->assets->js) {
foreach ($config->assets->js as $js) {
$js_collection->addJs(ROOT . '/' . $js);
}
}
// Admin JS Assets
/* $assetsManager->collection('modules-admin-js')
->setLocal(true)
->addFilter(new \Phalcon\Assets\Filters\Jsmin())
->setTargetPath(ROOT . '/assets/modules-admin.js')
->setTargetUri('assets/modules-admin.js')
->join(true);
// Admin LESS Assets
$assetsManager->collection('modules-admin-less')
->setLocal(true)
->addFilter(new \Application\Assets\Filter\Less())
->setTargetPath(ROOT . '/assets/modules-admin.less')
->setTargetUri('assets/modules-admin.less')
->join(true)
->addCss(APPLICATION_PATH . '/modules/Admin/assets/admin.less'); */
$di->set('assets', $assetsManager);
}
private function initEventManager($di) {
$eventsManager = new \Phalcon\Events\Manager();
$dispatcher = new \Phalcon\Mvc\Dispatcher();
$eventsManager->attach("dispatch:beforeDispatchLoop", function ($event, $dispatcher) use ($di) {
new \TLMC\Plugin\Auth($dispatcher);
new \TLMC\Plugin\CheckPoint($di->get('request'));
new \TLMC\Plugin\Localization($di->get('config'));
new \TLMC\Plugin\AdminLocalization($di->get('config'));
new \TLMC\Plugin\Acl($di->get('acl'), $dispatcher, $di->get('view'));
//new \TLMC\Plugin\AccessLog($di);
});
$eventsManager->attach("dispatch:afterDispatchLoop", function ($event, $dispatcher) use ($di) {
//new \Seo\Plugin\SeoManager($dispatcher, $di->get('request'), $di->get('router'), $di->get('view'));
new \TLMC\Plugin\Title($di);
});
// Profiler
$registry = $di->get('registry');
if ($registry->cms['PROFILER']) {
$profiler = new \Phalcon\Db\Profiler();
$di->set('profiler', $profiler);
$eventsManager->attach('db', function ($event, $db) use ($profiler) {
if ($event->getType() == 'beforeQuery') {
$profiler->startProfile($db->getSQLStatement());
}
if ($event->getType() == 'afterQuery') {
$profiler->stopProfile();
}
});
}
$db = $di->get('db');
$db->setEventsManager($eventsManager);
$dispatcher->setEventsManager($eventsManager);
$di->set('dispatcher', $dispatcher);
}
private function initView($di) {
$view = new \Phalcon\Mvc\View();
define('MAIN_VIEW_PATH', '../../../views/');
$view->setMainView(MAIN_VIEW_PATH . 'main');
$view->setLayoutsDir(MAIN_VIEW_PATH . '/layouts/');
$view->setLayout('main');
$view->setPartialsDir(MAIN_VIEW_PATH . '/partials/');
// Volt
$volt = new \Application\Mvc\View\Engine\Volt($view, $di);
$volt->setOptions(['compiledPath' => APPLICATION_PATH . '/../data/cache/volt/']);
$volt->initCompiler();
$phtml = new \Phalcon\Mvc\View\Engine\Php($view, $di);
$viewEngines = [
".volt" => $volt,
".phtml" => $phtml,
];
$view->registerEngines($viewEngines);
$ajax = $di->get('request')->getQuery('_ajax');
if ($ajax) {
$view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_LAYOUT);
}
$di->set('view', $view);
return $view;
}
private function initCache($di) {
$config = $di->get('config');
$cacheFrontend = new \Phalcon\Cache\Frontend\Data([
"lifetime" => 120,
"prefix" => HOST_HASH,
]);
$viewCacheFrontend = new \Phalcon\Cache\Frontend\Output([
'lifetime' => 120,
]);
$cache = null;
switch ($config->cache) {
case 'file':
$cache = new \Phalcon\Cache\Backend\File($cacheFrontend, [
"cacheDir" => APPLICATION_PATH . "/../data/cache/backend/"
]);
break;
case 'memcache':
$cache = new \Phalcon\Cache\Backend\Memcache(
$cacheFrontend, [
"host" => $config->memcache->host,
"port" => $config->memcache->port,
]);
break;
case 'memcached':
$cache = new \Phalcon\Cache\Backend\Libmemcached(
$cacheFrontend, [
"host" => $config->memcached->host,
"port" => $config->memcached->port,
]);
break;
}
$di->set('cache', $cache, true);
$di->set('modelsCache', $cache, true);
$viewCache = new \Phalcon\Cache\Backend\File($viewCacheFrontend, [
"cacheDir" => APPLICATION_PATH . "/../data/cache/frontend/"
]);
$di->set('viewCache', $viewCache, true);
\Application\Widget\Proxy::$cache = $cache; // Modules Widget System
$modelsMetadata = new \Phalcon\Mvc\Model\Metadata\Memory();
$di->set('modelsMetadata', $modelsMetadata);
$di->set('cacheManager', new CacheManager());
}
private function initRecaptcha($di) {
$config = $di->get('config');
$recaptcha = new \ReCaptcha\ReCaptcha($config->recaptcha->private_key);
$di->set('recaptcha', $recaptcha);
}
private function checkSiteMaintain($di) {
$auth = $di->get('auth');
if ($auth && $auth->getUsername()) {
return;
}
$request = $di->get('request');
$uri = $request->getURI();
if (in_array($uri, ["/admin", "/dang-nhap"])) {
return;
}
$registry = $di->get('registry');
if ($registry->cms['TECHNICAL_WORKS']) {
$view = $di->get('view');
$view->setViewsDir(__DIR__ . '/modules/Index/views/');
$view->setPartialsDir(__DIR__ . '/views/partials/');
$view->start();
$view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
$view->message_contact = $registry->cms['ADMIN_EMAIL']." / ".$registry->cms['PHONE_NUMBER'];
$view->render('index', 'maintain');
$view->finish();
echo $view->getContent();
exit;
}
}
private function dispatch($di) {
$router = $di['router'];
$router->handle();
$view = $di['view'];
$dispatcher = $di['dispatcher'];
$response = $di['response'];
$dispatcher->setModuleName($router->getModuleName());
$dispatcher->setControllerName($router->getControllerName());
$dispatcher->setActionName($router->getActionName());
$dispatcher->setParams($router->getParams());
$moduleName = \Application\Utils\ModuleName::camelize($router->getModuleName());
$ModuleClassName = $moduleName . '\Module';
if (class_exists($ModuleClassName)) {
$module = new $ModuleClassName;
$module->registerAutoloaders();
$module->registerServices($di);
}
$view->start();
$registry = $di['registry'];
if ($registry->cms['DEBUG_MODE']) {
$debug = new \Phalcon\Debug();
$debug->listen();
$dispatcher->dispatch();
} else {
try {
$dispatcher->dispatch();
} catch (\Phalcon\Exception $e) {
// Errors catching
$view->setViewsDir(__DIR__ . '/modules/Index/views/');
$view->setPartialsDir(__DIR__ . '/views/partials/');
$view->e = $e;
if ($e instanceof \Phalcon\Mvc\Dispatcher\Exception) {
$response->setStatusCode(404, 'Not Found');
$view->render('error', 'error404');
} else {
$response->setStatusCode(503, 'Service Unavailable');
$view->render('error', 'error503');
}
$view->finish();
echo $view->getContent();
exit;
return $response;
}
}
$view->render(
$dispatcher->getControllerName(), $dispatcher->getActionName(), $dispatcher->getParams()
);
$view->finish();
// AJAX
$request = $di['request'];
$_ajax = $request->getQuery('_ajax');
if ($_ajax) {
$contents = $view->getContent();
$return = new \stdClass();
$return->html = $contents;
$return->title = $di->get('helper')->title()->get();
$return->success = true;
if ($view->bodyClass) {
$return->bodyClass = $view->bodyClass;
}
$headers = $response->getHeaders()->toArray();
if (isset($headers[404]) || isset($headers[503])) {
$return->success = false;
}
$response->setContentType('application/json', 'UTF-8');
$response->setContent(json_encode($return));
} else {
$response->setContent($view->getContent());
}
return $response;
}
}
|
#5 | TLMC\Bootstrap->run()
/home/picture/public_html/public/index.php (28) <?php
chdir(dirname(__DIR__));
define('ROOT', __DIR__);
define('HOST_HASH', substr(md5($_SERVER['HTTP_HOST']), 0, 12));
define('DIR_PATH', dirname(__FILE__). '/');
define('DIR_IMAGE', DIR_PATH . 'static/files/');
define('DIR_CACHE_IMAGE', DIR_PATH . 'img/');
define('DIR_TEMP_FILE', DIR_PATH . 'temp/');
define('DIR_DATA_FILE', DIR_PATH.'../data/files/');
define('CREDENTIALS_FILE_PATH', DIR_PATH . '../hou-image-8dba1fc7ea6a.json');
date_default_timezone_set('Asia/Ho_Chi_Minh');
if (isset($_SERVER['APPLICATION_ENV'])) {
$applicationEnv = ($_SERVER['APPLICATION_ENV'] ? $_SERVER['APPLICATION_ENV'] : 'production');
} else {
$applicationEnv = (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production');
}
define('APPLICATION_ENV', $applicationEnv);
define('APPLICATION_PATH', __DIR__ . '/../app');
require_once APPLICATION_PATH . '/Bootstrap.php';
$bootstrap = new TLMC\Bootstrap();
$bootstrap->run();
|