示例#1
0
 /**
  * Loads the Twig instance and registers the autoloader.
  */
 public function configure()
 {
     parent::configure();
     $this->configuration = $this->context->getConfiguration();
     // template name
     $template = sfConfig::get('sf_template');
     $templateDir = sfConfig::get('sf_template_dir') . '/' . $template;
     if (!file_exists($templateDir)) {
         throw new sfException(__METHOD__ . ": Couldn't find template " . $template);
     }
     // decorator template path
     $layoutTemplateDir = $templateDir . '/global';
     if (is_readable($layoutTemplateDir . '/' . $this->getDecoratorTemplate())) {
         $this->setDecoratorDirectory($layoutTemplateDir);
     }
     // module template path
     $moduleTemplateDir = $templateDir . '/modules/' . $this->moduleName;
     if (is_readable($moduleTemplateDir . '/' . $this->getTemplate())) {
         $this->setDirectory($moduleTemplateDir);
     }
     // init twig engine
     // empty array becuase it changes based on the rendering context
     $this->loader = new Twig_Loader_Filesystem(array());
     $this->twig = new sfTwigEnvironment($this->loader, array('cache' => sfConfig::get('sf_template_cache_dir') . '/' . $template, 'debug' => sfConfig::get('sf_debug', false), 'sf_context' => $this->context));
     if ($this->twig->isDebug()) {
         $this->twig->setAutoReload(true);
     }
     $this->loadExtensions();
 }
示例#2
0
 /**
  * Configures template for this view.
  *
  * @throws <b>sfActionException</b> If the configure fails
  */
 public function configure()
 {
     // view.yml configure
     parent::configure();
     // require our configuration
     $moduleName = $this->moduleName;
     require $this->context->getConfigCache()->checkConfig('modules/' . $this->moduleName . '/config/mailer.yml');
 }
 public function initialize($context, $moduleName, $actionName, $viewName)
 {
     $this->nameSuffix = sfSmartphoneViewToolKit::getViewNameSuffixFromUA($this, $context, $moduleName, $actionName, $viewName, false);
     if ($this->nameSuffix) {
         $this->enableNameSuffix = sfSmartphoneViewToolKit::getViewNameSuffixFromUA($this, $context, $moduleName, $actionName, $viewName);
     }
     parent::initialize($context, $moduleName, $actionName, $viewName . sfInflector::camelize($this->enableNameSuffix));
 }
示例#4
0
 /**
  * Configures template for this view.
  *
  * @throws <b>sfActionException</b> If the configure fails
  */
 public function configure()
 {
     // view.yml configure
     parent::configure();
     // require our configuration
     $moduleName = $this->moduleName;
     require sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name') . '/' . $this->moduleName . '/' . sfConfig::get('sf_app_module_config_dir_name') . '/mailer.yml');
 }
示例#5
0
 /**
  * Constructor.
  * 
  * @see sfView
  */
 public function initialize($context, $moduleName, $actionName, $viewName)
 {
     $ret = parent::initialize($context, $moduleName, $actionName, $viewName);
     $this->viewCache = $this->context->getViewCacheManager();
     if (sfConfig::get('sf_cache')) {
         $this->checkCache = $this->viewCache->isActionCacheable($moduleName, $actionName);
     }
     return $ret;
 }
 /**
  * Initializes this view.
  *
  * @param  sfContext $context     The current application context
  * @param  string    $moduleName  The module name for this view
  * @param  string    $actionName  The action name for this view
  * @param  string    $viewName    The view name
  * @return bool  true, if initialization completes successfully, otherwise false
  */
 public function initialize($context, $moduleName, $actionName, $viewName)
 {
     parent::initialize($context, $moduleName, $actionName, $viewName);
     $config = $context->getConfiguration();
     //sets up a Twig_Loader_Array with directories
     $this->twig_loaders['decorator'] = new Twig_Loader_FileSystem($config->getDecoratorDirs(), sfConfig::get('sf_template_cache_dir'));
     $this->twig_loaders['module'] = new Twig_Loader_FileSystem($config->getTemplateDirs($this->getModuleName()), sfConfig::get('sf_template_cache_dir'));
     //Setting the $loader to null lets us swap the loader out as we need it on the same instance.
     $this->twig = new Twig_Environment(null);
 }
示例#7
0
 /**
  * sfSmartyView::renderFile()
  * this method is unsed instead of sfPHPView::renderFile()
  *
  * @param mixed $file
  * @return
  * @access protected
  **/
 protected function renderFile($file)
 {
     if ($this->getExtension() == '.php' && $this->getAttribute('sf_type') != 'layout') {
         return parent::renderFile($file);
     }
     if (sfConfig::get('sf_logging_enabled')) {
         $this->dispatcher->notify(new sfEvent($this, 'application.log', array('{sfSmartyView} renderFile ' . $file)));
     }
     return $this->getEngine()->renderFile($this, $file);
 }
示例#8
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;
 }
示例#9
0
 /**
  * Loads the Twig instance and registers the autoloader.
  *
  * @return void
  */
 public function configure()
 {
     parent::configure();
     $this->configuration = $this->context->getConfiguration();
     //Empty array becuase it changes based on the rendering context
     $this->loader = new Twig_Loader_Filesystem(array());
     $this->twig = new Twig_Environment($this->loader, array('cache' => sfConfig::get('sf_template_cache_dir'), 'debug' => sfConfig::get('sf_debug', false)));
     if ($this->twig->isDebug()) {
         $this->twig->setCache(null);
         $this->twig->setAutoReload(true);
     }
     $this->loadExtensions();
 }
 protected function renderFile($_sfFile)
 {
     $info = pathinfo($_sfFile);
     $base = "{$info['dirname']}/{$info['filename']}";
     $filename = $base . ucfirst(strtolower(sfJpMobile::getCarrierName())) . '.' . $info['extension'];
     if (!is_readable($filename)) {
         $filename = "{$base}Mobile.{$info['extension']}";
         if (!sfJpMobile::isMobile() || !is_readable($filename)) {
             $filename = $_sfFile;
         }
     }
     return parent::renderFile($filename);
 }
示例#11
0
 /**
  * Rendering file
  * 
  * @param   string  $file   Template filename
  * @return  void
  */
 protected function renderFile($file)
 {
     if (!$this->isHaml) {
         return parent::renderFile($file);
     }
     if (sfConfig::get('sf_logging_enabled', false)) {
         $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Render "%s"', $file))));
     }
     $this->loadCoreAndStandardHelpers();
     $this->parser->setFile($file);
     $this->parser->append($this->attributeHolder->toArray());
     return $this->parser->render();
 }
 /**
  * Loads the Twig instance and registers the autoloader.
  */
 public function configure()
 {
     parent::configure();
     $this->configuration = $this->context->getConfiguration();
     require_once sfConfig::get('sf_twig_lib_dir', dirname(__FILE__) . '/../lib/vendor/Twig/lib') . '/Twig/Autoloader.php';
     Twig_Autoloader::register();
     // empty array becuase it changes based on the rendering context
     $this->loader = new Twig_Loader_Filesystem(array());
     $this->twig = new sfTwigEnvironment($this->loader, array('cache' => sfConfig::get('sf_template_cache_dir'), 'debug' => sfConfig::get('sf_debug', false), 'sf_context' => $this->context));
     if ($this->twig->isDebug()) {
         $this->twig->enableAutoReload();
         $this->twig->setCache(null);
     }
     $this->loadExtensions();
 }
示例#13
0
 public function configure()
 {
     parent::configure();
     if (!is_readable($this->getDirectory() . '/' . $this->getTemplate()) || !$this->directory) {
         $this->setDirectory($this->getTemplateDir($this->moduleName, $this->getTemplate()));
         // require our configuration
         $viewConfigFile = ncFlavorFlavors::getModulePath($this->moduleName) . '/config/view.yml';
         if (sfContext::getInstance()->getConfigCache()->checkConfig($viewConfigFile, true)) {
             require $config;
         }
     }
     if (!is_readable($this->getDecoratorDirectory() . '/' . $this->getDecoratorTemplate())) {
         $this->decoratorDirectory = $this->getGlobalTemplateDir($this->getDecoratorTemplate());
     }
 }
示例#14
0
 /**
  * Render the presentation.
  *
  * When the controller render mode is sfView::RENDER_CLIENT, this method will
  * render the presentation directly to the client and null will be returned.
  *
  * @return string A string representing the rendered presentation, if
  *                the controller render mode is sfView::RENDER_VAR, otherwise null.
  */
 public function render($templateVars = null)
 {
     $template = $this->getDirectory() . '/' . $this->getTemplate();
     $actionStackEntry = $this->getContext()->getActionStack()->getLastEntry();
     $actionInstance = $actionStackEntry->getActionInstance();
     $moduleName = $actionInstance->getModuleName();
     $actionName = $actionInstance->getActionName();
     $retval = null;
     $context = $this->getContext();
     //exception, if template is missing
     $this->preRenderCheck();
     // get the render mode
     $mode = $context->getController()->getRenderMode();
     // template variables
     if ($templateVars === null) {
         $actionStackEntry = $context->getActionStack()->getLastEntry();
         $actionInstance = $actionStackEntry->getActionInstance();
         $templateVars = $actionInstance->getVarHolder()->getAll();
     }
     // assigns some variables to the template
     $this->attributeHolder->add($this->getGlobalVars());
     $this->attributeHolder->add(array('dir' => $this->getDirectory()));
     $this->attributeHolder->add($retval !== null ? $vars : $templateVars);
     try {
         $content = $this->renderFile($template);
         $filename = array_key_exists('filename', $templateVars) && $templateVars['filename'] !== null ? $templateVars['filename'] : $actionStackEntry->getModuleName() . '_' . $actionStackEntry->getActionName();
         $orientation = array_key_exists('orientation', $templateVars) && $templateVars['orientation'] !== null ? $templateVars['orientation'] : 'portrait';
         $papersize = array_key_exists('papersize', $templateVars) && $templateVars['papersize'] !== null ? $templateVars['papersize'] : 'a4';
         //			$q = new sfDomPDFPlugin($content);
         //			$q->execute();
         //			$q->getPDF()->stream($filename.'.pdf');
         $q = new sfDomPDFPlugin($content);
         $q->setPaper($papersize, $orientation);
         if ($pdf = $q->execute()) {
             $response = $this->getContext()->getResponse();
             $response->setHttpHeader('Pragma', '');
             $response->setHttpHeader('Cache-Control', '');
             $response->setHttpHeader('Content-Type', 'application/pdf');
             $response->setHttpHeader('Content-Disposition', 'attachment; filename="' . $filename . '.pdf"');
             $response->setContent($pdf);
         }
     } catch (Exception $e) {
         $context->getResponse()->addHttpMeta('Content-Disposition', '');
         //fixme
         return parent::render();
     }
 }
示例#15
0
 public function configure()
 {
     parent::configure();
     // Grab the theme from the user (of from anywhere else)
     $theme = $this->getContext()->getUser()->getTheme();
     // If there is a theme and if the theme feature is enabled
     if ($theme && sfConfig::get('app_theme')) {
         // Look for templates in a $theme/ subdirectory of the usual template location
         if (is_readable($this->getDirectory() . '/' . $theme . '/' . $this->getTemplate())) {
             $this->setDirectory($this->getDirectory() . '/' . $theme);
         }
         // Look for a layout in a $theme/ subdirectory of the usual layout location
         if (is_readable($this->getDecoratorDirectory() . '/' . $theme . '/' . $this->getDecoratorTemplate())) {
             $this->setDecoratorDirectory($this->getDecoratorDirectory() . '/' . $theme);
         }
     }
 }
示例#16
0
 /**
  * Render the presentation.
  *
  * When the controller render mode is sfView::RENDER_CLIENT, this method will
  * render the presentation directly to the client and null will be returned.
  *
  * @return string A string representing the rendered presentation, if
  *                the controller render mode is sfView::RENDER_VAR, otherwise null.
  */
 public function render($templateVars = null)
 {
     $template = $this->getDirectory() . '/' . $this->getTemplate();
     $actionStackEntry = $this->getContext()->getActionStack()->getLastEntry();
     $actionInstance = $actionStackEntry->getActionInstance();
     $moduleName = $actionInstance->getModuleName();
     $actionName = $actionInstance->getActionName();
     $retval = null;
     $context = $this->getContext();
     //exception, if template is missing
     $this->preRenderCheck();
     // get the render mode
     $mode = $context->getController()->getRenderMode();
     // template variables
     if ($templateVars === null) {
         $actionStackEntry = $context->getActionStack()->getLastEntry();
         $actionInstance = $actionStackEntry->getActionInstance();
         $templateVars = $actionInstance->getVarHolder()->getAll();
     }
     // assigns some variables to the template
     $this->attributeHolder->add($this->getGlobalVars());
     $this->attributeHolder->add(array('dir' => $this->getDirectory()));
     $this->attributeHolder->add($retval !== null ? $vars : $templateVars);
     $retval = null;
     try {
         $retval = $this->renderFile($template);
     } catch (Exception $e) {
         $context->getResponse()->addHttpMeta('Content-Disposition', '');
         //fixme
         return parent::render();
     }
     if ($mode == sfView::RENDER_CLIENT) {
         //TODO: use cache instead of /tmp
         if ($sf_logging_active = sfConfig::get('sf_logging_enabled')) {
             $context->getLogger()->info('{sfPDFView} render to client "' . $template . '"');
             $tempfile = "/tmp/texDebug";
             exec("rm {$tempfile}*");
         } else {
             $tempfile = tempnam("/tmp", "tex");
         }
         $fp = fopen($tempfile . '.tex', "w");
         if (!$fp) {
             die("Could not open " . $tempfile);
         }
         fwrite($fp, $retval);
         fclose($fp);
         ob_start();
         $dir = $this->getDirectory();
         passthru("cd {$dir}; pdflatex -output-directory /tmp -interaction nonstopmode {$tempfile}.tex 2>&1");
         if (file_exists($tempfile . '.log')) {
             $log = file_get_contents("{$tempfile}.log");
             if (strpos($log, 'Fatal error')) {
                 unlink($tempfile . '.pdf');
                 // rerun, if Bookmarksfile (.out) exists
             } elseif (file_exists($tempfile . '.out') || strpos($log, 'Rerun LaTeX')) {
                 passthru("cd /tmp; pdflatex -interaction nonstopmode {$tempfile}.tex 2>&1");
             }
         }
         $err = '<pre>' . ob_get_contents() . '</pre>';
         ob_end_clean();
         if (file_exists($tempfile . '.pdf')) {
             $context->getResponse()->setContentType('application/pdf');
             $context->getResponse()->addHttpMeta('cache-control', 'no-cache');
             $context->getResponse()->addHttpMeta('Expires', gmdate("D, d M Y H:i:s") . " GMT", time());
             $context->getResponse()->setContent(file_get_contents("{$tempfile}.pdf"));
             if (!$sf_logging_active) {
                 unlink($tempfile);
                 exec("rm {$tempfile}*");
             }
         } else {
             if ($sf_logging_active) {
                 $context->getLogger()->info('{sfPDFView} mode ' . $mode . ' render "' . $template . '" error"' . $err . '"');
             }
             ob_start();
             readfile($tempfile . '.tex');
             $msg = '<h2>Log</h2><pre>' . $log . '</pre>';
             $msg .= '<h2>Tex-Source:</h2><pre>' . ob_get_contents() . '</pre>';
             ob_end_clean();
             throw new sfRenderException($err . $msg);
             return parent::render();
         }
     }
     return $retval;
 }
public function render($templateVars = null)
{
  $template = $this->getDirectory().'/'.$this->getTemplate();
  $response = $this->context->getResponse();

if (sfConfig::get("sf_logging_enabled"))
{
  $this->context->getLogger()->info("{sfPdfView} render &quot;".$template."&quot;");
}
 
// disable layout
//$response->setParameter($this->moduleName."_".$this->actionName."_layout", null);

sfConfig::set($this->moduleName."_".$this->actionName."_layout", null);

// backup render mode
$renderMode = $this->context->getController()->getRenderMode();
 
// override render mode : We dont want sfPHPView to render directly to the client
$this->context->getController()->setRenderMode(sfView::RENDER_VAR);
 
// let sfPHPView render our template to $retval
$retval = parent::render($templateVars);
 
// saved render mode
$this->context->getController()->setRenderMode($renderMode);
 
// get PDF data
$pdf = $this->initPDF();
$pdf->AddPage();
$pdf->writeHTML($retval, true, 0);
$pdfcontent = $pdf->Output("nowhere.pdf", "s");          // get output as string
 
// $response->setContentType("application/pdf");
 
// render to client
// if ($renderMode == sfView::RENDER_CLIENT)
// {
//      $response->setContent($pdfcontent);
// }

  return $pdfcontent;
 
  //$response->setContent($pdfcontent);
 
}
示例#18
0
 public function configure()
 {
     $this->setExtension('.php');
     parent::configure();
 }
示例#19
0
 public function configure()
 {
     $this->setExtension('.php');
     $this->setDecorator(false);
     parent::configure();
 }