Exemplo n.º 1
0
 public function loadFrom($type, $name)
 {
     $base = $type == 'theme' ? DIR_THEME . '/' . $name : findExt($type, $name);
     $path = $base . '/languages/' . $this->locale . '.php';
     if (!file_exists($path)) {
         $path = $base . '/languages/en.php';
         if (!file_exists($path)) {
             return;
         }
     }
     $arr = (include $path);
     $this->container[$this->locale] = isset($this->container[$this->locale]) ? array_merge($this->container[$this->locale], $arr) : $arr;
 }
Exemplo n.º 2
0
/**
 * Loads view of some module
 *
 * @param string $template String like module_name/view_name
 * @param array  $data
 * @return string
 */
function view($template, $data = [])
{
    $part = explode('/', $template);
    if (count($part) != 2) {
        throw new \RuntimeException(t('error_view_argument'));
    }
    app('event')->trigger('before.render.partial', [$template, $data], $template);
    $file_override = DIR_THEME . '/' . app('config')['site']['theme'] . '/module/' . $template . '.php';
    $file = findExt('module', $part[0]) . '/views/' . $part[1] . '.php';
    if (file_exists($file_override)) {
        $html = render($file_override, $data);
    } elseif (file_exists($file)) {
        $html = render($file, $data);
    } else {
        throw new \RuntimeException(sprintf(t('error_file_not_found'), $file));
    }
    app('event')->trigger('after.render.partial', [$html], $template);
    return $html;
}
Exemplo n.º 3
0
Arquivo: App.php Projeto: sydes/sydes
 private function sendRequestThroughRouter($request)
 {
     $dispatcher = \FastRoute\cachedDispatcher(function (\FastRoute\RouteCollector $r) {
         $r->addRoute('GET', '/page/{id:[0-9]+}', 'test/page');
         $r->addRoute('GET', '/notfound', 'test/notfound');
         $r->addRoute('GET', '/forbidden', 'test/forbidden');
         $r->addRoute('GET', '/ajax', 'test/ajax');
         $r->addRoute('GET', '/string.txt', 'test/string');
         $r->addRoute('GET', '/export', 'test/export');
         $r->addRoute('GET', '/html', 'test/html');
         $r->addRoute('GET', '/nool', 'test/nool');
         $r->addRoute('GET', '/moved', 'test/moved');
         $r->addRoute('GET', '/update', 'test/notifyAfterRedirect');
         $r->addRoute('GET', '/store', 'test/alertAfterRedirect');
         $r->addRoute('GET', '/ajaxupdate', 'test/ajaxNotify');
         $r->addRoute('GET', '/ajaxstore', 'test/ajaxAlert');
         $r->addRoute('GET', '/refresh', 'test/ajaxRefresh');
         $r->addRoute('GET', '/refresh2', 'test/refreshAndNotify');
         $r->addRoute('GET', '/random', 'test/random');
         $r->addRoute('GET', '/', 'test/index');
         $r->addRoute('GET', '/admin', 'test/adminMain');
         $r->addRoute('GET', '/admin/pages', 'test/adminPages');
         $r->addRoute('GET', '/login', 'user/loginForm');
         $r->addRoute('POST', '/login', 'user/login');
         $r->addRoute('GET', '/install', 'utils/signUpForm');
         $r->addRoute('POST', '/install', 'utils/signUp');
         $r->addRoute('GET', '/admin/sites/add', 'sites/addForm');
         $r->addRoute('POST', '/admin/sites/add', 'sites/add');
     }, ['cacheFile' => DIR_CACHE . '/routes.cache']);
     $routeInfo = $dispatcher->dispatch($request->method, $request->url);
     if ($routeInfo[0] == \FastRoute\Dispatcher::FOUND) {
         $parts = explode('/', $routeInfo[1]);
         $vars = $routeInfo[2];
     } else {
         //TODO try to find predefined urls in database
         if (1) {
             throw new NotFoundHttpException();
         }
         $parts = explode('/', 'test/page/42');
         $vars = array_slice($parts, 2);
     }
     $name = $parts[0];
     $class = ucfirst($parts[0]) . 'Controller';
     $method = $parts[1];
     if (null === ($path = findExt('module', $name))) {
         trigger_error(sprintf(t('module_folder_not_found'), $name), E_USER_ERROR);
     }
     include $path . '/index.php';
     $instance = new $class();
     return call_user_func_array([$instance, $method], $vars);
 }
Exemplo n.º 4
0
 private function iblock($name, $params = false)
 {
     $iblockDir = findExt('iblock', $name);
     if (!$iblockDir) {
         return sprintf(t('error_iblock_not_found'), $name);
     }
     $args = ['template' => 'default'];
     if ($params) {
         $args = array_merge($args, $params);
     }
     if (strpos($args['template'], '.') !== false) {
         return '';
     }
     $page = $this->document->data;
     ob_start();
     $out = (include $iblockDir . '/index.php');
     if (!is_null($out)) {
         $tplOverride = DIR_THEME . '/' . $this->theme . '/iblock/' . $name . '/' . $args['template'] . '.php';
         $tplOriginal = $iblockDir . '/views/' . $args['template'] . '.php';
         if (is_file($tplOverride)) {
             include $tplOverride;
         } elseif (is_file($tplOriginal)) {
             include $tplOriginal;
         } elseif ($args['template'] != 'default') {
             ob_end_clean();
             return sprintf(t('error_iblock_template_not_found'), $args['template'], $name);
         }
     }
     return ob_get_clean();
 }