Esempio n. 1
0
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $default_buttons = array('add_file' => 'Add files...', 'upload' => 'Start upload', 'cancel' => 'Cancel upload');
     $buttons = $this->getOption('buttons') + $default_buttons;
     $module_partial = $this->getOption('module_partial');
     if ($module_partial) {
         sfApplicationConfiguration::getActive()->loadHelpers('Partial');
         include_partial($module_partial, array('widget' => $this, 'name' => $name, 'value' => $value, 'attributes' => $attributes, 'errors' => $errors, 'buttons' => $buttons));
     } else {
         $context = sfContext::getInstance();
         $view = new sfPartialView($context, '', '', '');
         $plugin_path = sfConfig::get('sf_plugins_dir') . DIRECTORY_SEPARATOR . 'laWidgetFileUploadPlugin';
         $view->setTemplate($plugin_path . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . '_upload_widget.php');
         $view->setPartialVars(array('widget' => $this, 'buttons' => $buttons));
         echo $view->render();
     }
 }
 protected function renderFile($_sfFile)
 {
     $info = pathinfo($_sfFile);
     $base = "{$info['dirname']}/{$info['filename']}";
     $filename = $base . ucfirst(strtolower(sfJpMobile::getInstance()->getCarrierName())) . '.' . $info['extension'];
     if (!is_readable($filename)) {
         $filename = "{$base}Mobile.{$info['extension']}";
         if (!sfJpMobile::getInstance()->isMobile() || !is_readable($filename)) {
             $filename = $_sfFile;
         }
     }
     return parent::renderFile($filename);
 }
Esempio n. 3
0
 public function initialize($context, $moduleName, $actionName, $viewName)
 {
     parent::initialize($context, $moduleName, $actionName, $viewName);
     $format = $context->getRequest()->getRequestFormat();
     // make sure directory is set
     if (!$this->directory) {
         $this->setDirectory($this->context->getConfiguration()->getTemplateDir($this->moduleName, str_replace('.' . $format, '', $this->template)));
     }
     if ($format || $format != 'html') {
         $this->checkFallback($format);
     }
     return true;
 }
/**
 * Evaluates and returns a partial.
 * The syntax is similar to the one of include_partial
 *
 * <b>Example:</b>
 * <code>
 *  echo get_partial('mypartial', array('myvar' => 12345));
 * </code>
 *
 * @param  string partial name
 * @param  array variables to be made accessible to the partial
 * @return string result of the partial execution
 * @see    include_partial
 */
function get_partial($templateName, $vars = array())
{
    $context = sfContext::getInstance();
    // partial is in another module?
    if (false !== ($sep = strpos($templateName, '/'))) {
        $moduleName = substr($templateName, 0, $sep);
        $templateName = substr($templateName, $sep + 1);
    } else {
        $moduleName = $context->getActionStack()->getLastEntry()->getModuleName();
    }
    $actionName = '_' . $templateName;
    if ($cacheManager = $context->getViewCacheManager()) {
        if ($retval = _get_cache($cacheManager, $moduleName, $actionName, $vars)) {
            return $retval;
        }
    }
    $view = new sfPartialView();
    $view->initialize($context, $moduleName, $actionName, '');
    $retval = $view->render($vars);
    if ($cacheManager && (!sfConfig::get('sf_lazy_cache_key') || $cacheManager->isActionCacheable($moduleName, $actionName))) {
        $uri = _get_cache_uri($moduleName, $actionName, $vars);
        $retval = _set_cache($cacheManager, $uri, $retval);
    }
    return $retval;
}
Esempio n. 5
0
/**
 * Evaluates and returns a partial.
 * The syntax is similar to the one of include_partial
 *
 * <b>Example:</b>
 * <code>
 *  echo get_partial('mypartial', array('myvar' => 12345));
 * </code>
 *
 * @param  string $templateName  partial name
 * @param  array  $vars          variables to be made accessible to the partial
 *
 * @return string result of the partial execution
 * @see    include_partial
 */
function get_partial($templateName, $vars = array())
{
    $context = sfContext::getInstance();
    // partial is in another module?
    if (false !== ($sep = strpos($templateName, '/'))) {
        $moduleName = substr($templateName, 0, $sep);
        $templateName = substr($templateName, $sep + 1);
    } else {
        $moduleName = $context->getActionStack()->getLastEntry()->getModuleName();
    }
    $actionName = '_' . $templateName;
    $view = new sfPartialView($context, $moduleName, $actionName, '');
    $view->setPartialVars($vars);
    return $view->render();
}
 public function configure()
 {
     parent::configure();
     $this->setTemplate($this->actionName . $this->viewName . $this->getExtension());
 }
 /**
  * Renders the presentation.
  *
  * @return string Current template content
  */
 public function render()
 {
     if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) {
         $timer = sfTimerManager::getTimer(sprintf('Partial "%s/%s"', $this->moduleName, $this->actionName));
     }
     if ($retval = $this->getCache()) {
         return $retval;
     } else {
         if ($this->checkCache) {
             $mainResponse = $this->context->getResponse();
             $responseClass = get_class($mainResponse);
             $this->context->setResponse($response = new $responseClass($this->context->getEventDispatcher(), array_merge($mainResponse->getOptions(), array('content_type' => $mainResponse->getContentType()))));
         }
     }
     try {
         // PHP FALLBACK
         try {
             // execute pre-render check
             $this->preRenderCheck();
         } catch (sfRenderException $e) {
             if (null === $this->template) {
                 throw new sfRenderException('A template has not been set.');
             }
             $view = new sfPartialView($this->context, $this->moduleName, $this->actionName, $this->viewName);
             return $view->render();
         } catch (Exception $e) {
             throw $e;
         }
         $this->getAttributeHolder()->set('sf_type', 'partial');
         // render template
         $retval = $this->renderFile($this->getDirectory(), $this->getTemplate());
     } catch (Exception $e) {
         if ($this->checkCache) {
             $this->context->setResponse($mainResponse);
             $mainResponse->merge($response);
         }
         throw $e;
     }
     if ($this->checkCache) {
         $retval = $this->viewCache->setPartialCache($this->moduleName, $this->actionName, $this->cacheKey, $retval);
         $this->context->setResponse($mainResponse);
         $mainResponse->merge($response);
     }
     if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) {
         $timer->addTime();
     }
     return $retval;
 }
Esempio n. 8
0
/**
 * Evaluates and returns a partial.
 * The syntax is similar to the one of include_partial
 *
 * <b>Example:</b>
 * <code>
 *  echo get_partial('mypartial', array('myvar' => 12345));
 * </code>
 *
 * @param  string partial name
 * @param  array variables to be made accessible to the partial
 * @return string result of the partial execution
 * @see    include_partial
 */
function get_partial($templateName, $vars = array())
{
    $context = sfContext::getInstance();
    // partial is in another module?
    if (false !== ($sep = strpos($templateName, '/'))) {
        $moduleName = substr($templateName, 0, $sep);
        $templateName = substr($templateName, $sep + 1);
    } else {
        $moduleName = $context->getActionStack()->getLastEntry()->getModuleName();
    }
    $actionName = '_' . $templateName;
    if ($cacheManager = $context->getViewCacheManager()) {
        $cacheManager->registerConfiguration($moduleName);
        $uri = '@sf_cache_partial?module=' . $moduleName . '&action=' . $actionName . '&sf_cache_key=' . (isset($vars['sf_cache_key']) ? $vars['sf_cache_key'] : md5(serialize($vars)));
        if ($retval = _get_cache($cacheManager, $uri)) {
            return $retval;
        }
    }
    $view = new sfPartialView();
    $view->initialize($context, $moduleName, $actionName, '');
    $retval = $view->render($vars);
    if ($cacheManager) {
        $retval = _set_cache($cacheManager, $uri, $retval);
    }
    return $retval;
}