Пример #1
0
 private static function _AtResponse(Typeframe_Response $response)
 {
     $settings = $response->page()->settings();
     if (!empty($settings['skin'])) {
         return $settings['skin'];
     }
     $uri = $response->applicationUri();
     $admin_root = TYPEF_WEB_DIR . '/admin';
     if (Typeframe::CurrentPage()->siteid() != 0) {
         $site = Model_Site::Get(Typeframe::CurrentPage()->siteid());
         if ($site['directory']) {
             $admin_root = TYPEF_WEB_DIR . '/' . $site['directory'] . '/admin';
         }
     }
     if ($uri == $admin_root || substr($uri, 0, strlen($admin_root . '/')) == $admin_root . '/') {
         if (TYPEF_USE_MOBILE_SKINS && self::_IsMobile()) {
             return TYPEF_MOBILE_ADMIN_SKIN;
         }
         if (TYPEF_ADMIN_SKIN) {
             return TYPEF_ADMIN_SKIN;
         }
     }
     if (TYPEF_USE_MOBILE_SKINS && self::_IsMobile()) {
         return TYPEF_MOBILE_SITE_SKIN;
     }
     return TYPEF_SITE_SKIN ? TYPEF_SITE_SKIN : 'default';
 }
Пример #2
0
 /**
  * Get a reference to the current page (response).
  * @return Typeframe_Response
  */
 public static function CurrentPage()
 {
     return Typeframe_Response::Current();
 }
Пример #3
0
 /**
  * Get the Typeframe_Response object for the specified URL.
  * @param string $url
  * @return \Typeframe_Response
  */
 public static function At($url)
 {
     $response = new Typeframe_Response();
     if ($url == '') {
         $url = '/';
     }
     if (substr($url, 0, 1) == '/') {
         if (isset($_SERVER['HTTP_HOST']) && defined('TYPEF_HOST')) {
             $url = $_SERVER['HTTP_HOST'] . $url;
         } else {
             $url = (defined('TYPEF_HOST') ? TYPEF_HOST : '') . $url;
         }
     } else {
         if (substr($url, 0, 7) == 'http://' || substr($url, 0, 8) == 'https://') {
             $parts = parse_url($url);
             $url = $parts['domain'] . $parts['path'] . (!empty($parts['query']) ? '?' . $parts['query'] : '');
         }
     }
     if ($url != '/' && substr($url, -1, 1) == '/') {
         $url = substr($url, 0, -1);
     }
     $response->_url = $url;
     if (substr($response->_url, -1) == '/') {
         $response->_url = substr($response->_url, 0, -1);
     }
     $pages = Typeframe::Registry()->pages();
     /*if (substr($url, 0, 1) != '/') {
     			$host = substr($url, 0, strpos($url, '/'));
     		} else {
     			$host = '';
     		}*/
     $host = defined('TYPEF_HOST') ? @$_SERVER['HTTP_HOST'] : '';
     $uri = strpos($url, '?') !== false ? substr($url, 0, strlen(strpos($url, '?'))) : $url;
     $uri = preg_replace('/\\/+/', '/', $uri);
     if (substr($uri, 0, -1) == '/') {
         $uri = substr($uri, 0, -1);
     }
     $relativeUri = substr($uri, strlen(TYPEF_WEB_DIR) + (defined('TYPEF_HOST') ? strlen($host ? $host : TYPEF_HOST) : 0));
     $dirs = explode('/', $relativeUri);
     while (count($dirs)) {
         $uri = strpos($url, '?') !== false ? substr($url, 0, strlen(strpos($url, '?'))) : $url;
         $uri = preg_replace('/\\/+/', '/', $uri);
         if (substr($uri, 0, -1) == '/') {
             $uri = substr($uri, 0, -1);
         }
         $relativeUri = substr($uri, strpos($uri, '/') + strlen(TYPEF_WEB_DIR));
         $currentPath = $host . TYPEF_WEB_DIR . '/' . implode('/', $dirs);
         $currentPath = preg_replace('/\\/+/', '/', $currentPath);
         if (substr($currentPath, -1) == '/') {
             $currentPath = substr($currentPath, 0, -1);
         }
         if (!isset($pages[$currentPath]) && substr($currentPath, 0, strlen($host)) == $host) {
             $currentPath = substr($currentPath, strlen($host));
             $uri = substr($uri, strlen($host));
         }
         if (isset($pages[$currentPath])) {
             $currentPage = $pages[$currentPath];
             $uriWithoutDomain = substr($uri, 0, 1) == '/' ? $uri : substr($uri, strlen($host));
             $controllerPath = null;
             if ($currentPath && strlen($uri) > strlen($currentPath) && strpos($uri, $currentPath) === 0) {
                 $controllerPath = TYPEF_SOURCE_DIR . '/controllers' . $currentPage->application()->base() . substr($uriWithoutDomain, strlen($currentPage->uri()));
                 if (file_exists($controllerPath . '.php') && is_file($controllerPath . '.php')) {
                     $response->_controller = $controllerPath . '.php';
                     $response->_page = $currentPage;
                     break;
                 } else {
                     if (file_exists($controllerPath . '/index.php') && is_file($controllerPath . '/index.php')) {
                         $response->_controller = $controllerPath . '/index.php';
                         $response->_page = $currentPage;
                         break;
                     } else {
                         $controllerPath = null;
                         foreach ($currentPage->extenders() as $extender) {
                             if (defined('TYPEF_HOST') && substr($uri, 0, strlen($host)) == $host) {
                                 $pathinfo = substr($uri, strlen($host) + strlen($extender->path()));
                             } else {
                                 $pathinfo = substr($uri, strlen($extender->path()));
                             }
                             //if (substr($uri, strlen($host), strlen($extender->path())) == $extender->path()) {
                             //$extended = substr($uri, strlen($host) + strlen($extender->path()));
                             //if (preg_match($extender->preg(), $extended)) {
                             if (preg_match($extender->preg(), $pathinfo)) {
                                 $response->_pathInfo = substr($pathinfo, 1);
                                 if ($extender->redirect()) {
                                     $controllerPath = TYPEF_SOURCE_DIR . '/controllers' . $extender->redirect();
                                 } else {
                                     $controllerPath = TYPEF_SOURCE_DIR . '/controllers' . $currentPage->application()->base();
                                 }
                                 break;
                             }
                             //}
                         }
                     }
                 }
             } else {
                 if ($currentPath == $uri) {
                     $controllerPath = TYPEF_SOURCE_DIR . '/controllers' . $currentPage->application()->base();
                     if (file_exists($controllerPath . '.php') && is_file($controllerPath . '.php')) {
                         $response->_controller = $controllerPath . '.php';
                         $response->_page = $currentPage;
                         break;
                     } else {
                         if (file_exists($controllerPath . '/index.php') && is_file($controllerPath . '/index.php')) {
                             $response->_controller = $controllerPath . '/index.php';
                             $response->_page = $currentPage;
                             break;
                         }
                     }
                 } else {
                     $controllerPath = TYPEF_SOURCE_DIR . '/controllers' . $currentPage->application()->base();
                     $response->_pathInfo = substr($uri, strlen($currentPath) + 1);
                 }
             }
             if (!is_null($controllerPath)) {
                 if (file_exists($controllerPath . '.php') && is_file($controllerPath . '.php')) {
                     $response->_controller = $controllerPath . '.php';
                 } else {
                     if (file_exists($controllerPath . '/index.php') && is_file($controllerPath . '/index.php')) {
                         $response->_controller = $controllerPath . '/index.php';
                     }
                 }
             }
             if ($response->_controller) {
                 $response->_page = $currentPage;
                 break;
             }
         }
         array_pop($dirs);
     }
     if ($response->_controller && $response->_page) {
         $response->_controller = preg_replace('/\\/+/', '/', $response->_controller);
         if (!$response->_page->allow()) {
             $response->_return403();
         }
     } else {
         $response->_return404();
     }
     return $response;
 }
Пример #4
0
 /**
  * Get the Typeframe response for the specified path.
  * @param string $uri
  * @return \Typeframe_Response
  */
 public function responseAt($uri)
 {
     return Typeframe_Response::At($uri);
 }
Пример #5
0
//if (!$page->exists() || ('Content' != $page->get('application')) || $page['siteid'] != Typeframe::CurrentPage()->siteid())
if (!$page->exists() || $page['siteid'] != Typeframe::CurrentPage()->siteid()) {
    Typeframe::Redirect('Invalid page.', $typef_app_dir, -1);
    return;
}
if ($page['application'] == 'Content') {
    // get template from settings; expand to its full value
    $settings = $page['settings'];
    $template = @$settings['template'];
    if (!$template) {
        $template = 'generic.html';
    }
    $template = "/content/{$template}";
    $full_template = TYPEF_SOURCE_DIR . "/templates{$template}";
} else {
    $response = Typeframe_Response::At(TYPEF_WEB_DIR . $page['uri']);
    $template = $response->getPageTemplate();
    $full_template = Typeframe_Skin::TemplatePath($template, $response->applicationUri());
}
// cannot edit content if template does not exist
if (!file_exists($full_template)) {
    Typeframe::Redirect("Unable to find page template ({$template}).", $typef_app_dir, -1);
    return;
}
$skin = Typeframe_Skin::At(TYPEF_WEB_DIR . $page['uri']);
$stylesheets = Typeframe_Skin::StylesheetsFor($template, TYPEF_WEB_DIR . $page['uri']);
$pm->setVariable('stylesheets', $stylesheets);
// load inserts and groups for template
$inserts = Insertable::ElementsFrom($full_template, TYPEF_WEB_DIR . $page['uri']);
$groups = Insertable::GroupsFrom($full_template, null, $skin);
// get revision id, if any