Exemplo n.º 1
0
/**
 * @param $params
 * @param $template
 * @return bool|mixed|string
 */
function smarty_function_flink($params, $template)
{
    $file = $params['file'];
    /** @var $front Enlight_Controller_Front */
    $front = Enlight_Application::Instance()->Front();
    $request = $front->Request();
    // check if we got an URI or a local link
    if (!empty($file) && strpos($file, '/') !== 0 && strpos($file, '://') === false) {
        $useIncludePath = $template->smarty->getUseIncludePath();
        // try to find the file on the filesystem
        foreach ($template->smarty->getTemplateDir() as $dir) {
            if (file_exists($dir . $file)) {
                $file = realpath($dir) . DS . str_replace('/', DS, $file);
                break;
            }
            if ($useIncludePath) {
                if ($dir === '.' . DS) {
                    $dir = '';
                }
                if (($result = Enlight_Loader::isReadable($dir . $file)) !== false) {
                    $file = $result;
                    break;
                }
            }
        }
        if (method_exists(Enlight_Application::Instance(), 'DocPath')) {
            $docPath = Enlight_Application::Instance()->DocPath();
        } else {
            $docPath = getcwd() . DIRECTORY_SEPARATOR;
        }
        // some clean up code
        if (strpos($file, $docPath) === 0) {
            $file = substr($file, strlen($docPath));
        }
        // make sure we have the right separator for the web context
        if (DIRECTORY_SEPARATOR !== '/') {
            $file = str_replace(DIRECTORY_SEPARATOR, '/', $file);
        }
        if (strpos($file, './') === 0) {
            $file = substr($file, 2);
        }
        // if we did not find the file, we are returning a false
        if (strpos($file, '/') !== 0) {
            if (!file_exists($docPath . $file)) {
                //return false;
            }
            if ($request !== null) {
                $file = $request->getBasePath() . '/' . $file;
            }
        }
    }
    if (empty($file) && $request !== null) {
        $file = $request->getBasePath() . '/';
    }
    if ($request !== null && strpos($file, '/') === 0 && !empty($params['fullPath'])) {
        $file = $request->getScheme() . '://' . $request->getHttpHost() . $file;
    }
    return $file;
}
Exemplo n.º 2
0
 /**
  * @param   string $templateDir
  * @param   int|null $key
  * @return  string
  */
 public function resolveTemplateDir($templateDir, $key = null)
 {
     if ($this->eventManager !== null) {
         $templateDir = $this->eventManager->filter(__CLASS__ . '_ResolveTemplateDir', $templateDir, array('subject' => $this, 'key' => $key));
     }
     $templateDir = Enlight_Loader::isReadable($templateDir);
     return $templateDir;
 }
Exemplo n.º 3
0
 /**
  * Returns whether the given request object is dispatchable.
  * Checks first if the controller class of the request object exists.
  * If the controller class exists, the enlight loader class checks if the controller path is readable.
  *
  * @param Enlight_Controller_Request_Request $request
  * @return bool|string
  */
 public function isDispatchable(Enlight_Controller_Request_Request $request)
 {
     $className = $this->getControllerClass($request);
     if (!$className) {
         return false;
     }
     if (class_exists($className, false)) {
         return true;
     }
     $path = $this->getControllerPath($request);
     return Enlight_Loader::isReadable($path);
 }