#0 | PDOStatement->execute() |
#1 | Phalcon\Db\Adapter\Pdo->executePrepared(Object(PDOStatement), Array(), Array()) |
#2 | Phalcon\Db\Adapter\Pdo->query(DESCRIBE `_etiketler`, null, null) |
#3 | Phalcon\Db\Adapter->fetchAll(DESCRIBE `_etiketler`, 3) |
#4 | Phalcon\Db\Adapter\Pdo\Mysql->describeColumns(_etiketler, ) |
#5 | Phalcon\Mvc\Model\MetaData\Strategy\Introspection->getMetaData(Object(News\Model\Etiketler: 21), Object(Phalcon\Di\FactoryDefault)) |
#6 | Phalcon\Mvc\Model\MetaData->_initialize(Object(News\Model\Etiketler: 21), news\model\etiketler-_etiketler, _etiketler, ) |
#7 | Phalcon\Mvc\Model\MetaData->readMetaDataIndex(Object(News\Model\Etiketler: 21), 4) |
#8 | Phalcon\Mvc\Model\MetaData->getDataTypes(Object(News\Model\Etiketler: 21)) |
#9 | Phalcon\Mvc\Model::_invokeFinder(findFirstBySlug, Array([0] => lucky)) |
#10 | Phalcon\Mvc\Model::__callStatic(findFirstBySlug, Array([0] => lucky))
/var/www/vhosts/denizliyeniolay.com/httpdocs/app/modules/News/Controller/IndexController.php (194) <?php
namespace News\Controller;
use Application\Mvc\Controller;
use Application\Mvc\Helper\CmsCache;
use Application\Mvc\Helper\Meta;
use Konsol\Model\Language;
use Konsol\Model\Options;
use KoseYazilari\Model\KoseYazilari;
use News\Helper\HaberFinder;
use News\Model\Etiketler;
use News\Model\Haberler;
use News\Model\Kategoriler;
use Posts\Helper\PostsFinder;
use Posts\Helper\TermsFinder;
use Posts\Model\Posts;
use Posts\Model\Terms;
class IndexController extends Controller
{
public function homeAction()
{
$manset_kose_yazisi = KoseYazilari::findFirst([
'conditions' => 'konum_1 = :slider_active:',
'bind' => ['slider_active' => '1'],
'order' => 'id DESC',
'cache' => ['key' => md5("manset-kose-yazilari")]
]);
$this->view->manset = $this->getManset();
$this->view->manset_kose_yazisi = $manset_kose_yazisi;
$this->view->kose_yazilari = $this->getKoseYazilari();
$title = $this->helper->getOption("site_title");
$description = $this->helper->getOption("site_desc");
$keywords = $this->helper->getOption("site_keywords");
$this->setMeta($title, $description, $keywords);
$this->helper->title("Yeni Olay");
}
public function home2Action()
{
$finder = new HaberFinder();
$items = $finder->getKategoriByResmiIlan();
var_dump($items);
exit;
}
public function yonlendirmeAction($haber_id)
{
$haber = Haberler::findFirst([
"columns" => "url",
"conditions" => "id = :haber_id:",
"bind" => ["haber_id" => $haber_id]
]);
if (!$haber) {
$this->redirect($this->url->get('hata/404?utm_source=yonlendirme'));
die();
}
$this->redirect($this->url->get($haber->url));
die();
}
public function kyonlendirmeAction($yazi_id)
{
$yazi = KoseYazilari::findFirst([
"columns" => "url",
"conditions" => "id = :yazi_id:",
"bind" => ["yazi_id" => $yazi_id]
]);
if (!$yazi) {
$this->redirect($this->url->get('hata/404?utm_source=yonlendirme'));
die();
}
$this->redirect($this->url->get("kose-yazilari/" . $yazi->url));
die();
}
private function getKoseYazilari()
{
/*
* Her yazardan 1 tane olmak üzere köşe yazısı çeker
*/
$records = $this->modelsManager->createBuilder()
->from(['y' => 'KoseYazilari\Model\Yazarlar'])
->columns('ky.id,concat("kose-yazilari/",y.slug,"/",ky.slug) as url,ky.baslik,ky.tarih,y.slug as yazar_slug,y.baslik as yazar_adi,y.resim as yazar_resim')
->where("y.status = :status_active: and sy.tarih is null", [
"status_active" => "active"
])
->innerJoin('KoseYazilari\Model\KoseYazilari', 'ky.yazar_id = y.id and ky.status = :status_active:', 'ky')
->leftJoin('KoseYazilari\Model\KoseYazilari', 'y.id = sy.yazar_id and ky.tarih < sy.tarih', 'sy')
//->groupBy('y.id')
->orderBy('ky.tarih DESC')
->limit(20)
->getQuery()
->cache(array("key" => md5("anasayfa_kose_yazilari"), "lifetime" => 28800))//(60*60)*8 //8saat;
->execute()
->toArray();
return $records;
}
public function aramaAction()
{
$query = $this->request->get('q');
$finder = new HaberFinder();
$haberler = $finder->search($query);
$this->view->query = $query;
$this->view->haberler = $haberler;
$this->view->page_url = $this->url->get('arama?q=' . $query);
$this->setMeta("Arama Sonuçları", sprintf('%s için arama sonuçları', $query));
$this->helper->meta()->setProperty('robots', 'noindex');//arama motorlarından gizle
}
public function mansetlerAction()
{
$finder = new HaberFinder();
$haberler = $finder->getSliderByPagination(20);
$this->view->haberler = $haberler;
$this->view->page_url = $this->url->get('mansetler');
$this->setMeta("Tüm Manşetler", "Öne çıkan manşet haberleri");
}
public function kategoriAction($kategori_slug)
{
$kategori = Kategoriler::getBySlug($kategori_slug);
if (!$kategori) $this->redirect($this->url->get('hata/404?utm_source=category'));
$haberler = $kategori->getHaberler();
$this->view->kategori = $kategori;
$this->view->haberler = $haberler;
$this->view->tarih = $this->request->get('tarih') ? $this->request->get('tarih') : null;
$this->view->page_url = $kategori->getUrl();
if ($kategori->slug == "life")
$this->view->pick("index/kategori_blog");
$this->setMeta($kategori->getBaslik(), $kategori->getMetaDescription(), $kategori->getMetaKeywords());
}
public function etiketAction($etiket_slug)
{
$etiket = Etiketler::findFirstBySlug($etiket_slug);
if (!$etiket) $this->redirect($this->url->get('hata/404?utm_source=etiket'));
$haberler = $etiket->getHaberler();
$this->view->etiket = $etiket;
$this->view->haberler = $haberler;
$this->view->page_url = $etiket->getUrl();
$this->setMeta($etiket->getBaslik(), $etiket->getAciklama());
}
public function detayAction($category, $haber_slug, $haber_id = null)
{
if (is_numeric($haber_id)) {
$haber = Haberler::getById($haber_id);
} else {
$haber = Haberler::getBySlug($haber_slug);
}
if (!$haber) $this->redirect($this->url->get('hata/404?utm_source=haber_detay'));
if (!$haber->checkUrl()) $this->redirect($haber->getUrl());
$this->view->haber = $haber;
$this->view->kategori = $kategori = $haber->getKategori();
if ($kategori->slug == "resmi-ilan")
$this->view->pick("index/detay_resmiilan");
$this->setMeta($haber->getBaslik(), $haber->getOzet(), null, $haber);
}
public function infinityAction($category, $haber_slug)
{
$this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
$newsId = $this->request->getPost('newsId');
$haber = Haberler::findFirst([
'conditions' => 'id < :newsId:',
'bind' => ['newsId' => $newsId],
'order' => 'id DESC'
]);
if (!$haber) $this->output(false, null, "Kayıt bulunamadı");
$this->view->haber = $haber;
$this->view->kategori = $haber->getKategori();
$this->setMeta($haber->getBaslik(), $haber->getOzet(), null, $haber);
}
public function cacheclearrAction()
{
/*
* Cache temizleme
*/
\Konsol\Controller\IndexController::cacheClear();
exit('OK');
}
private function setMeta($title, $description = null, $keywords = null, $model = null)
{
try {
$site_url = $this->url->get();
$url = $this->page_url;
$site_name = $this->helper->getOption('site_name');
$lang = $this->lang;
$created_at = false;
$updated_at = false;
$image = false;
if ($model):
//$image = $model->getMediaUrl("image");
$created_at = $model->getCreatedAt();
$updated_at = $model->getUpdatedAt();
$image = $this->helper->timthumb($model->getResimUrl(), 1200, 630, 1);
$url = $model->getUrl();
endif;
$meta = Meta::getInstance();
$this->helper->title($title, true);
$meta->setName("title", $title);
$meta->setName("description", $description);
if ($model) $meta->setName("url", $url);
if ($model) $meta->setName("datePublished", date('c', strtotime($created_at)));
if ($model) $meta->setName("dateModified", date('c', strtotime($updated_at)));
if ($model) $meta->setName("articleSection", $model->getVideoId() ? "vide0" : "news");
if ($model) $meta->setName("articleAuthor", $model->getYazar());
$meta->setName("keywords", $keywords);
$meta->setProperty("robots", "index, follow, max-snippet:20, max-image-preview:large");
$meta->setName("link", $this->page_url);
//article
$meta->setProperty("article:publisher", $site_name);
$meta->setProperty("article:tag", $site_name);
$meta->setProperty("article:published_time", $created_at);
$meta->setProperty("article:modified_time", $updated_at);
//og
$meta->setProperty("og:site_name", $site_name);
$meta->setProperty("og:type", "article");
$meta->setProperty("og:locale", 'tr_TR');
$meta->setProperty("og:title", $title);
$meta->setProperty("og:description", $description);
$meta->setProperty("og:url", $url);
$meta->setProperty("og:site_name", $site_name);
$meta->setProperty("og:image", $image);
$meta->setProperty("og:image:width", 1200);
$meta->setProperty("og:image:height", 630);
$meta->setProperty("og:image:alt", $title);
$meta->setProperty("og:updated_time", $updated_at);
//twitter
$twitter_username = Options::getOption('social_twitter');
$meta->setProperty("twitter:card", "summary_large_image");
$meta->setProperty("twitter:title", $title);
$meta->setProperty("twitter:description", $description);
$meta->setProperty("twitter:image", $image);
$meta->setProperty("twitter:domain", $site_url);
if ($twitter_username):
$meta->setProperty("twitter:creator", "@$twitter_username");
$meta->setProperty("twitter:site", "@$twitter_username");
endif;
//integrations
$meta->setName("google-site-verification", Options::getOption("google-site-verification"));
$meta->setName("yandex-verification", Options::getOption("yandex-verification"));
$this->di->get('positions')->add("head_tag_end", Options::getOption("google_analytics"));
$this->di->get('positions')->add("head_tag_end", Options::getOption("facebook_pixel"));
} catch (\Throwable $e) {
$this->flash->error("Hata! " . $e->getMessage());
exit();
}
}
private function getMansetOLD()
{
if ($_GET['profiler']) {
return $this->getMansetCache();
}
$manset_data = CmsCache::getInstance()->get('manset_data');
if (!$manset_data) {
$limit = !empty($this->helper->getOption('manset_sayi')) ? $this->helper->getOption('manset_sayi') : 25;
$db = \Phalcon\DI::getDefault()->get('db');
$stmt = $db->prepare("select id,baslik,tarih,url,manset_tasarim,resim,tur,target_url from _haberler where konum_2='1' and tarih <= :today and status = 'active' union all select id,baslik,tarih,url,manset_tasarim,resim,tur,target_url from _kose_yazilari where konum_1='1' and tarih <= :today and status = 'active' order by tarih desc limit " . $limit);
$stmt->execute(['today' => date("Y-m-d H:i:s")]);
$manset_data = $stmt->fetchAll(\PDO::FETCH_ASSOC);
CmsCache::getInstance()->save('manset_data', $manset_data);
}
return $manset_data;
}
private function getManset()
{
$cacheKey = md5("manset_data");
$cache = $this->di->get('cache');
if ($cache->exists($cacheKey)) {
//exit('aa');
return $cache->get($cacheKey);
}
// Önbellekte yoksa, veritabanı sorgusunu yap
$db = $this->di->get('db');
$limit = !empty($this->helper->getOption('manset_sayi')) ? $this->helper->getOption('manset_sayi') : 25;
$stmt = $db->prepare("select id,baslik,tarih,url,manset_tasarim,resim,tur,target_url from _haberler where konum_2=:konum and tarih <= :today and status = :status_active union all select id,baslik,tarih,url,manset_tasarim,resim,tur,target_url from _kose_yazilari where konum_1 = :konum and tarih <= :today and status = :status_active ORDER BY tarih desc limit {$limit}");
$stmt->execute(['konum' => '1', 'status_active' => 'active', 'today' => date("Y-m-d H:i:s")]);
$manset_data = $stmt->fetchAll(\PDO::FETCH_ASSOC);
// Sonuçları önbelleğe ekle
$cache->save($cacheKey, $manset_data);
return $manset_data;
}
}
|
#11 | News\Controller\IndexController->etiketAction(lucky, tr) |
#12 | Phalcon\Dispatcher->callActionMethod(Object(News\Controller\IndexController), etiketAction, Array([0] => lucky, [lang] => tr)) |
#13 | Phalcon\Dispatcher->dispatch()
/var/www/vhosts/denizliyeniolay.com/httpdocs/app/Bootstrap.php (418) <?php
namespace App;
use Application\Cache\Manager as CacheManager;
use Application\Mvc\Helper\CmsCache;
use Konsol\Model\Options;
class Bootstrap{
public function run(){
try {
$this->initDefined();
$di = new \Phalcon\DI\FactoryDefault();
$loader = new \Phalcon\Loader();
// Config
$config = require_once PATHS['APPS'] . '/config/application.php';
$config = new \Phalcon\Config($config);
$loader->registerDirs([PATHS['APPS'] . "/plugins/"]);
$loader->registerNamespaces($config->loader->namespaces->toArray());
$loader->registerFiles([PATHS['APPS'] . '/../vendor/autoload.php']);
$loader->register();
$di->set('config', $config);
// URL
$url = new \Phalcon\Mvc\Url();
$url->setBasePath($config->base_path);
$url->setBaseUri($config->base_path);
$di->set('url', $url);
// Database
$di->set('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,
"port" => $config->database->port,
]));
//SET MODULES
$this->getModules($di);
// Loader
$loader->registerDirs([PATHS['APPS'] . "/plugins/"]);
$loader->registerNamespaces($config->loader->namespaces->toArray());
$loader->registerFiles([PATHS['APPS'] . '/../vendor/autoload.php']);
$loader->register();
// View
$this->initView($di,$config);
// Cache
$this->initCache($di);
// Application
$application = new \Phalcon\Mvc\Application();
$application->registerModules($config->modules->toArray());
// Events Manager, Dispatcher
$this->initEventManager($di);
$di->set('session', function () use ($di) {
$session = new \Phalcon\Session\Adapter\Files();
session_name(HOST_HASH);
$session->start();
return $session;
});
$di->set('cookie', function () {
$cookies = new \Phalcon\Http\Response\Cookies();
$cookies->useEncryption(true);
return $cookies;
});
$di->set('crypt', function () {
$crypt = new \Phalcon\Crypt();
$crypt->setCipher('aes-256-ctr');
$crypt->setKey("T4\xb1\x8d\xa9\x98\x05\\\x8c\xbe\x1d\x07&[\x99\x18\xa4~Lc1\xbeW\xb3");
return $crypt;
});
$di->set('localization', new \YobisiKonsol\Plugin\Localization());
$di->set('helper', new \Application\Mvc\Helper());
$di->set('auth', new \Konsol\Model\Auth());
$di->set('acl', new \YobisiKonsol\Plugin\Acl());
// JS Assets
$this->initAssetsManager($di);
// Toast helper
$di->set('toast', new \Application\Mvc\Helper\Toast());
// Flash helper
$di->set('flash', new \Phalcon\Flash\Session());
// Routing
$this->initRouting($application, $di);
$application->setDI($di);
// Main dispatching process
$response = $this->dispatch($di);
$response->send();
} catch (\Exception $e) {
return $this->initCatch($di, $e,[
"code" => "bootstrap_initCatch",
"message" => "Uygulama çalıştırılırken hata oluştu"
]);
}
}
private function initRouting($application, $di){
foreach ($application->getModules() as $module) {
try {
$initClassName = str_replace('\Module', '\Init', $module['className']);
if (class_exists($initClassName)) {
new $initClassName();
}
}catch (\Throwable $exception){
$this->initCatch($di,$exception,[
"code" => "init_routing",
"message" => sprintf('%s modülünün Init.php dosyasında hata !',$module['className']),
"error_code" => $exception->getCode(),
"error_message" => $exception->getMessage(),
"file" => $exception->getFile(),
"line" => $exception->getLine()
]);
}
}
$router = new \Application\Mvc\Router\DefaultRouter();
$router->setDi($di);
foreach ($application->getModules() as $module) {
try {
$routesClassName = str_replace('\Module', '\Routes', $module['className']);
if (class_exists($routesClassName)) {
$routesClass = new $routesClassName();
$router = $routesClass->init($router);
}
}catch (\Throwable $exception){
$this->initCatch($di,$exception,[
"code" => "init_routing",
"message" => sprintf('%s modülünün Routes.php dosyasında hata !',$module['className']),
"error_code" => $exception->getCode(),
"error_message" => $exception->getMessage(),
"file" => $exception->getFile(),
"line" => $exception->getLine()
]);
}
}
$di->set('router', $router);
}
private function initAssetsManager($di){
$assetsManager = new \Application\Assets\Manager();
$di->set('assets', $assetsManager);
}
private function initEventManager($di)
{
$eventsManager = new \Phalcon\Events\Manager();
$dispatcher = new \Phalcon\Mvc\Dispatcher();
$eventsManager->attach("dispatch", function ($event, $dispatcher, $exception) use ($di) {
if ($event->getType() == 'beforeException') {
switch ($exception->getCode()) {
case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
return $this->initCatch($di, $exception,[
"code" => "dispatch:beforeException",
"message" => "Sayfa çalıştırılırken beklenmedik hata oluştu"
]);
}
}//error pages redirect
});
/*
* Plugins
*/
$events = [];
$plugins = glob(PATHS['APPS'] .'plugins/*.php');
foreach ($plugins as $plugin_path):
$plugin_name = rtrim(basename($plugin_path), ".php");
$namespace = "YobisiKonsol\Plugin\\" . $plugin_name;
$variables = get_class_vars($namespace);
if(!$event_type = $variables['event_type']) continue;
$events[$event_type][] = $namespace;//plugin
endforeach;
foreach ($events as $event_type => $namespaces):
$eventsManager->attach($event_type, function ($event, $dispatcher) use ($di, $namespaces) {
foreach ($namespaces as $namespace):
$item = new $namespace();
if(method_exists($item,"execute")) $item->execute();
endforeach;
});
endforeach;
// Profiler
//$is_profiler = Options::findFirstByKey('profiler');
$is_profiler = @$_GET['profiler'] ?? false;
if ($is_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();
}
});
$di->get('view')->setVar('profiler',$di->get('profiler'));
}
$db = $di->get('db');
$db->setEventsManager($eventsManager);
$dispatcher->setEventsManager($eventsManager);
$di->set('dispatcher', $dispatcher);
}
private function initView($di,$config = [])
{
$view = new \Phalcon\Mvc\View();
define('MAIN_VIEW_PATH', PATHS['MODULES'] . "Konsol/Views/");
$view->setViewsDir(MAIN_VIEW_PATH);
$view->setMainView(MAIN_VIEW_PATH . '/konsol');
$view->setLayoutsDir(MAIN_VIEW_PATH . '/layouts/');
$view->setLayout('/konsol');
$view->setPartialsDir(MAIN_VIEW_PATH . '/partials/');
// Volt
$volt = new \Application\Mvc\View\Engine\Volt($view, $di);
$volt->setOptions([
'compiledPath' => PATHS['APPS'] . '/../data/cache/volt/',
'compileAlways' => (DEBUG_MODE) ? true : false
]);
$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);
$view->setVar('config',$config);
$di->set('view', $view);
return $view;
}
private function initCache($di)
{
$config = $di->get('config');
$cacheFrontend = new \Phalcon\Cache\Frontend\Data([
"lifetime" => 60,
"prefix" => HOST_HASH,
]);
$cache = null;
switch ($config->cache) {
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;
case 'redis':
$cache = new \Phalcon\Cache\Backend\Redis(
$cacheFrontend, [
"host" => $config->redis->host,
"port" => $config->redis->port,
"auth" => $config->redis->auth,
"statsKey" => $config->redis->statsKey,
"persistent" => $config->redis->persistent,
"index" => $config->redis->index
]);
break;
default:
$cache = new \Phalcon\Cache\Backend\File($cacheFrontend, [
"cacheDir" => PATHS['APPS'] . "/../data/cache/backend/",
'lifetime' => 172800
]);
}
\Application\Widget\Proxy::$cache = $cache; // Modules Widget System
$modelsMetadata = new \Phalcon\Mvc\Model\Metadata\Memory();
$di->set('cache', $cache, true);
$di->set('modelsCache', $cache, true);
$di->set('modelsMetadata', $modelsMetadata);
$di->set('cacheManager', new CacheManager());
}
private function dispatch($di){
$router = $di->get('router');
$router->handle();
$view = $di->get('view');
$dispatcher = $di->get('dispatcher');
$response = $di->get('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();
try {
$dispatcher->dispatch();
} catch (\Phalcon\Exception $error) {
return $this->initCatch($di, $error,[
"code" => "dispatch:catch",
"message" => "Uygulama çalıştırılırken beklenmedik hata oluştu"
]);
}
$view->render(
$dispatcher->getControllerName(),
$dispatcher->getActionName(),
$dispatcher->getParams()
);
$view->finish();
// AJAX
$request = $di['request'];
$_ajax = $request->getQuery('_ajax');
if ($_ajax) {
$view->setLayout('ajax');
$contents = $view->getContent();
$return = new \stdClass();
$return->status = true;
$return->title = $di->get('helper')->title()->get();
$return->html = $contents;
$headers = $response->getHeaders()->toArray();
if (isset($headers[404]) || isset($headers[503])) {
$return->status = false;
}
$response->setContentType('application/json', 'UTF-8');
$response->setContent(json_encode($return));
} else {
$response->setContent($view->getContent());
}
return $response;
}
private function getModules($di){
try {
$config = $di->get('config');
$db = $di->get('db');
$cache = new \Application\Mvc\Helper\CmsCache();
if (APPLICATION_ENV == "development") $db->query("SET @@GLOBAL.sql_mode=''");//fix group_by error
$user_modules = $cache::getInstance()->get('modules');
if (!$user_modules):
//GET_MODULES
$statement = $db->prepare('SELECT * FROM modules WHERE status = ? order by priority ASC');
$statement->execute(array("active"));
$user_modules = $statement->fetchAll(\Phalcon\Db::FETCH_ASSOC);
$cache::getInstance()->save('modules', $user_modules);
endif;
//SET_MODULES
require_once PATHS['APPS'] . '/modules/Application/Loader/Modules.php';
$modules = new \Application\Loader\Modules();
$modules_config = $modules->modulesConfig($user_modules);
foreach ($modules_config['loader']['namespaces'] as $key => $module)
$config->loader->namespaces[$key] = $module;
foreach ($modules_config['modules'] as $key => $module)
$config->modules[$key] = $module;
return $config;
}catch (\Throwable $e){
$params = [
"code" => "bootstrap_modules_catch",
"message" => $e->getMessage(),
"file" => $e->getFile(),
"line" => $e->getLine(),
];
return $di->get('response')->redirect('public/error.php?' . http_build_query($params))->send();
}
}
private function initDefined(){
/*
* geliştirici modunu açar
*/
$root_dir = rtrim(__DIR__,'app');
define('PATHS',[
"ROOT" => $root_dir,
"APPS" => $root_dir . 'app/',
"MODULES" => $root_dir . "app/modules/",
"PLUGINS" => $root_dir . "app/plugins/",
"DATA" => $root_dir . "data/",
"CACHE" => $root_dir . "data/cache/",
"PUBLIC" => $root_dir . 'public/',
"MEDIA" => $root_dir . "public/media/",
"ASSETS" => $root_dir . "public/assets/",
]);
}
private function initCatch($di, $exception = null,$params = []){
$debug = new \Phalcon\Debug();
$debug->listen()->onUncaughtException($exception);
if (DEBUG_MODE):
if($exception):
try {
$debug = new \Phalcon\Debug();
$debug->listen()->onUncaughtException($exception);
return true;
}catch (\Throwable $e){
}
endif;
endif;
/*
$redirect_url = "./hata/500?" . http_build_query($params);
header("HTTP/1.0 404 Not Found");
header('Location: '.$redirect_url);
die();
*/
//return $di->get('response')->redirect('hata/404?' . http_build_query($params))->send();
return $di->get('response')->redirect('public/error.php?' . http_build_query($params))->send();
}
}
|
#14 | App\Bootstrap->dispatch(Object(Phalcon\Di\FactoryDefault))
/var/www/vhosts/denizliyeniolay.com/httpdocs/app/Bootstrap.php (129) <?php
namespace App;
use Application\Cache\Manager as CacheManager;
use Application\Mvc\Helper\CmsCache;
use Konsol\Model\Options;
class Bootstrap{
public function run(){
try {
$this->initDefined();
$di = new \Phalcon\DI\FactoryDefault();
$loader = new \Phalcon\Loader();
// Config
$config = require_once PATHS['APPS'] . '/config/application.php';
$config = new \Phalcon\Config($config);
$loader->registerDirs([PATHS['APPS'] . "/plugins/"]);
$loader->registerNamespaces($config->loader->namespaces->toArray());
$loader->registerFiles([PATHS['APPS'] . '/../vendor/autoload.php']);
$loader->register();
$di->set('config', $config);
// URL
$url = new \Phalcon\Mvc\Url();
$url->setBasePath($config->base_path);
$url->setBaseUri($config->base_path);
$di->set('url', $url);
// Database
$di->set('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,
"port" => $config->database->port,
]));
//SET MODULES
$this->getModules($di);
// Loader
$loader->registerDirs([PATHS['APPS'] . "/plugins/"]);
$loader->registerNamespaces($config->loader->namespaces->toArray());
$loader->registerFiles([PATHS['APPS'] . '/../vendor/autoload.php']);
$loader->register();
// View
$this->initView($di,$config);
// Cache
$this->initCache($di);
// Application
$application = new \Phalcon\Mvc\Application();
$application->registerModules($config->modules->toArray());
// Events Manager, Dispatcher
$this->initEventManager($di);
$di->set('session', function () use ($di) {
$session = new \Phalcon\Session\Adapter\Files();
session_name(HOST_HASH);
$session->start();
return $session;
});
$di->set('cookie', function () {
$cookies = new \Phalcon\Http\Response\Cookies();
$cookies->useEncryption(true);
return $cookies;
});
$di->set('crypt', function () {
$crypt = new \Phalcon\Crypt();
$crypt->setCipher('aes-256-ctr');
$crypt->setKey("T4\xb1\x8d\xa9\x98\x05\\\x8c\xbe\x1d\x07&[\x99\x18\xa4~Lc1\xbeW\xb3");
return $crypt;
});
$di->set('localization', new \YobisiKonsol\Plugin\Localization());
$di->set('helper', new \Application\Mvc\Helper());
$di->set('auth', new \Konsol\Model\Auth());
$di->set('acl', new \YobisiKonsol\Plugin\Acl());
// JS Assets
$this->initAssetsManager($di);
// Toast helper
$di->set('toast', new \Application\Mvc\Helper\Toast());
// Flash helper
$di->set('flash', new \Phalcon\Flash\Session());
// Routing
$this->initRouting($application, $di);
$application->setDI($di);
// Main dispatching process
$response = $this->dispatch($di);
$response->send();
} catch (\Exception $e) {
return $this->initCatch($di, $e,[
"code" => "bootstrap_initCatch",
"message" => "Uygulama çalıştırılırken hata oluştu"
]);
}
}
private function initRouting($application, $di){
foreach ($application->getModules() as $module) {
try {
$initClassName = str_replace('\Module', '\Init', $module['className']);
if (class_exists($initClassName)) {
new $initClassName();
}
}catch (\Throwable $exception){
$this->initCatch($di,$exception,[
"code" => "init_routing",
"message" => sprintf('%s modülünün Init.php dosyasında hata !',$module['className']),
"error_code" => $exception->getCode(),
"error_message" => $exception->getMessage(),
"file" => $exception->getFile(),
"line" => $exception->getLine()
]);
}
}
$router = new \Application\Mvc\Router\DefaultRouter();
$router->setDi($di);
foreach ($application->getModules() as $module) {
try {
$routesClassName = str_replace('\Module', '\Routes', $module['className']);
if (class_exists($routesClassName)) {
$routesClass = new $routesClassName();
$router = $routesClass->init($router);
}
}catch (\Throwable $exception){
$this->initCatch($di,$exception,[
"code" => "init_routing",
"message" => sprintf('%s modülünün Routes.php dosyasında hata !',$module['className']),
"error_code" => $exception->getCode(),
"error_message" => $exception->getMessage(),
"file" => $exception->getFile(),
"line" => $exception->getLine()
]);
}
}
$di->set('router', $router);
}
private function initAssetsManager($di){
$assetsManager = new \Application\Assets\Manager();
$di->set('assets', $assetsManager);
}
private function initEventManager($di)
{
$eventsManager = new \Phalcon\Events\Manager();
$dispatcher = new \Phalcon\Mvc\Dispatcher();
$eventsManager->attach("dispatch", function ($event, $dispatcher, $exception) use ($di) {
if ($event->getType() == 'beforeException') {
switch ($exception->getCode()) {
case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
return $this->initCatch($di, $exception,[
"code" => "dispatch:beforeException",
"message" => "Sayfa çalıştırılırken beklenmedik hata oluştu"
]);
}
}//error pages redirect
});
/*
* Plugins
*/
$events = [];
$plugins = glob(PATHS['APPS'] .'plugins/*.php');
foreach ($plugins as $plugin_path):
$plugin_name = rtrim(basename($plugin_path), ".php");
$namespace = "YobisiKonsol\Plugin\\" . $plugin_name;
$variables = get_class_vars($namespace);
if(!$event_type = $variables['event_type']) continue;
$events[$event_type][] = $namespace;//plugin
endforeach;
foreach ($events as $event_type => $namespaces):
$eventsManager->attach($event_type, function ($event, $dispatcher) use ($di, $namespaces) {
foreach ($namespaces as $namespace):
$item = new $namespace();
if(method_exists($item,"execute")) $item->execute();
endforeach;
});
endforeach;
// Profiler
//$is_profiler = Options::findFirstByKey('profiler');
$is_profiler = @$_GET['profiler'] ?? false;
if ($is_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();
}
});
$di->get('view')->setVar('profiler',$di->get('profiler'));
}
$db = $di->get('db');
$db->setEventsManager($eventsManager);
$dispatcher->setEventsManager($eventsManager);
$di->set('dispatcher', $dispatcher);
}
private function initView($di,$config = [])
{
$view = new \Phalcon\Mvc\View();
define('MAIN_VIEW_PATH', PATHS['MODULES'] . "Konsol/Views/");
$view->setViewsDir(MAIN_VIEW_PATH);
$view->setMainView(MAIN_VIEW_PATH . '/konsol');
$view->setLayoutsDir(MAIN_VIEW_PATH . '/layouts/');
$view->setLayout('/konsol');
$view->setPartialsDir(MAIN_VIEW_PATH . '/partials/');
// Volt
$volt = new \Application\Mvc\View\Engine\Volt($view, $di);
$volt->setOptions([
'compiledPath' => PATHS['APPS'] . '/../data/cache/volt/',
'compileAlways' => (DEBUG_MODE) ? true : false
]);
$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);
$view->setVar('config',$config);
$di->set('view', $view);
return $view;
}
private function initCache($di)
{
$config = $di->get('config');
$cacheFrontend = new \Phalcon\Cache\Frontend\Data([
"lifetime" => 60,
"prefix" => HOST_HASH,
]);
$cache = null;
switch ($config->cache) {
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;
case 'redis':
$cache = new \Phalcon\Cache\Backend\Redis(
$cacheFrontend, [
"host" => $config->redis->host,
"port" => $config->redis->port,
"auth" => $config->redis->auth,
"statsKey" => $config->redis->statsKey,
"persistent" => $config->redis->persistent,
"index" => $config->redis->index
]);
break;
default:
$cache = new \Phalcon\Cache\Backend\File($cacheFrontend, [
"cacheDir" => PATHS['APPS'] . "/../data/cache/backend/",
'lifetime' => 172800
]);
}
\Application\Widget\Proxy::$cache = $cache; // Modules Widget System
$modelsMetadata = new \Phalcon\Mvc\Model\Metadata\Memory();
$di->set('cache', $cache, true);
$di->set('modelsCache', $cache, true);
$di->set('modelsMetadata', $modelsMetadata);
$di->set('cacheManager', new CacheManager());
}
private function dispatch($di){
$router = $di->get('router');
$router->handle();
$view = $di->get('view');
$dispatcher = $di->get('dispatcher');
$response = $di->get('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();
try {
$dispatcher->dispatch();
} catch (\Phalcon\Exception $error) {
return $this->initCatch($di, $error,[
"code" => "dispatch:catch",
"message" => "Uygulama çalıştırılırken beklenmedik hata oluştu"
]);
}
$view->render(
$dispatcher->getControllerName(),
$dispatcher->getActionName(),
$dispatcher->getParams()
);
$view->finish();
// AJAX
$request = $di['request'];
$_ajax = $request->getQuery('_ajax');
if ($_ajax) {
$view->setLayout('ajax');
$contents = $view->getContent();
$return = new \stdClass();
$return->status = true;
$return->title = $di->get('helper')->title()->get();
$return->html = $contents;
$headers = $response->getHeaders()->toArray();
if (isset($headers[404]) || isset($headers[503])) {
$return->status = false;
}
$response->setContentType('application/json', 'UTF-8');
$response->setContent(json_encode($return));
} else {
$response->setContent($view->getContent());
}
return $response;
}
private function getModules($di){
try {
$config = $di->get('config');
$db = $di->get('db');
$cache = new \Application\Mvc\Helper\CmsCache();
if (APPLICATION_ENV == "development") $db->query("SET @@GLOBAL.sql_mode=''");//fix group_by error
$user_modules = $cache::getInstance()->get('modules');
if (!$user_modules):
//GET_MODULES
$statement = $db->prepare('SELECT * FROM modules WHERE status = ? order by priority ASC');
$statement->execute(array("active"));
$user_modules = $statement->fetchAll(\Phalcon\Db::FETCH_ASSOC);
$cache::getInstance()->save('modules', $user_modules);
endif;
//SET_MODULES
require_once PATHS['APPS'] . '/modules/Application/Loader/Modules.php';
$modules = new \Application\Loader\Modules();
$modules_config = $modules->modulesConfig($user_modules);
foreach ($modules_config['loader']['namespaces'] as $key => $module)
$config->loader->namespaces[$key] = $module;
foreach ($modules_config['modules'] as $key => $module)
$config->modules[$key] = $module;
return $config;
}catch (\Throwable $e){
$params = [
"code" => "bootstrap_modules_catch",
"message" => $e->getMessage(),
"file" => $e->getFile(),
"line" => $e->getLine(),
];
return $di->get('response')->redirect('public/error.php?' . http_build_query($params))->send();
}
}
private function initDefined(){
/*
* geliştirici modunu açar
*/
$root_dir = rtrim(__DIR__,'app');
define('PATHS',[
"ROOT" => $root_dir,
"APPS" => $root_dir . 'app/',
"MODULES" => $root_dir . "app/modules/",
"PLUGINS" => $root_dir . "app/plugins/",
"DATA" => $root_dir . "data/",
"CACHE" => $root_dir . "data/cache/",
"PUBLIC" => $root_dir . 'public/',
"MEDIA" => $root_dir . "public/media/",
"ASSETS" => $root_dir . "public/assets/",
]);
}
private function initCatch($di, $exception = null,$params = []){
$debug = new \Phalcon\Debug();
$debug->listen()->onUncaughtException($exception);
if (DEBUG_MODE):
if($exception):
try {
$debug = new \Phalcon\Debug();
$debug->listen()->onUncaughtException($exception);
return true;
}catch (\Throwable $e){
}
endif;
endif;
/*
$redirect_url = "./hata/500?" . http_build_query($params);
header("HTTP/1.0 404 Not Found");
header('Location: '.$redirect_url);
die();
*/
//return $di->get('response')->redirect('hata/404?' . http_build_query($params))->send();
return $di->get('response')->redirect('public/error.php?' . http_build_query($params))->send();
}
}
|
#15 | App\Bootstrap->run()
/var/www/vhosts/denizliyeniolay.com/httpdocs/public/index.php (29) <?php
/*
* Yobisi.Konsol
*
*/
//session_name('subdomain_session');
error_reporting(@$_GET['debug'] ? E_ALL : 1);
define('APPLICATION_ENV', ($_SERVER['HTTP_HOST'] == "localhost") ? "development" : "production");
if (isset($_GET['debug_mode'])):
define('DEBUG_MODE', $_SESSION['DEBUG_MODE'] = (bool) $_GET['debug_mode']);
elseif (isset($_SESSION['DEBUG_MODE'])):
define('DEBUG_MODE', (bool)$_SESSION['DEBUG_MODE']);
else:
define('DEBUG_MODE', (APPLICATION_ENV == "development") ? true : false);
endif;
try {
require_once '../app/Bootstrap.php';
$bootstrap = new App\Bootstrap();
$bootstrap->run();
} catch (Exception $e) {
if (DEBUG_MODE):
$debug = new \Phalcon\Debug();
die($debug->listen()->onUncaughtException($e));
else:
/*
$params = ["message" => $e->getMessage(), "file" => $e->getFile(), "line" => $e->getLine(),];
$redirect_url = "hata/500?" . http_build_query([
"message" => $e->getMessage(),
"file" => $e->getFile(),
"line" => $e->getLine()
]);
header("HTTP/1.0 404 Not Found");
header('Location: '.$redirect_url);
die();
*/
include "error.php";
endif;
} |