/**
  * Renders the output
  */
 public function Render()
 {
     if ($this->config->GetValue('cache') == true && $this->config->GetValue('cacheexpire') === true) {
         $this->CacheExpire();
     }
     $log = GitPHP_DebugLog::GetInstance();
     if (!$this->tpl->isCached($this->GetTemplate(), $this->GetFullCacheKey())) {
         $this->tpl->clearAllAssign();
         $log->TimerStart();
         $this->LoadCommonData();
         $log->TimerStop('Common data');
         $log->TimerStart();
         $this->LoadData();
         $log->TimerStop('Data');
     }
     if (!$this->preserveWhitespace) {
         //$this->tpl->loadFilter('output', 'trimwhitespace');
     }
     $log->TimerStart();
     $this->tpl->display($this->GetTemplate(), $this->GetFullCacheKey());
     $log->TimerStop('Render');
     $this->tpl->clearAllAssign();
     if ($this->projectList) {
         $log->Log('MemoryCache', 'Count: ' . $this->projectList->GetMemoryCache()->GetCount());
     }
     if ($log->GetEnabled()) {
         $this->tpl->assign('debuglog', $log);
         $this->tpl->display('debug.tpl');
     }
 }
Example #2
0
 /**
  * Clear all assigned variables
  *
  * Clears all variables assigned to Zend_View either via {@link assign()} or property
  * overloading ({@link __get()}/{@link __set()}).
  *
  * Both Zend_View_Helper_Action::cloneView() and Zend_View_Helper_Partial::cloneView()
  * executes a "$view->clearVars();" line after a "$view = clone $this->view;" . Because
  * of how the "clone" operator works internally (object references are also copied, so a
  * clone of this object will point to the same Smarty object instance as this, the
  * "$view->clearVars();" unsets all the Smarty template variables. To solve this,
  * there is the {@link __clone()} method in this class which is called by the "clone"
  * operator just after it did it's cloning job.
  *
  * This sets a flag ($this->_isBeingCloned) for use below to avoid clearing the template
  * variables in the cloned object.
  *
  * If for any reason this doesn't work, neither after amending {@link __clone()}, an
  * other "solution" is in the method, but commented out. That will also work, but it is
  * relatively slow and, not nice at all. That takes a look on it's backtrace, and if
  * finds a function name "cloneView" then does NOT execute Smarty's clearAllAssign().
  *
  * Or just make this an empty function if neither the above works.
  *
  * @param void
  */
 public function clearVars()
 {
     //if (in_array('cloneView', OSS_Utils::filterFieldFromResult(OSS_Debug::compact_debug_backtrace(), 'function', false, false)) == false) $this->_smarty->clear_all_assign();
     if (!$this->_isBeingCloned) {
         $this->_smarty->clearAllAssign();
     } else {
         $this->_isBeingCloned = false;
     }
 }
Example #3
0
 /**
  * {@inheritDoc}
  *
  * @see PhpRenderer::render
  */
 public function render($nameOrModel, $values = null)
 {
     if ($nameOrModel instanceof ModelInterface) {
         $model = $nameOrModel;
         $nameOrModel = $model->getTemplate();
         if (empty($nameOrModel)) {
             $msg = '%s: received View Model argument, but template is empty';
             throw new Exception\DomainException(sprintf($msg, __METHOD__));
         }
         $values = $model->getVariables();
         if ($values instanceof \ArrayObject) {
             $values = $values->getArrayCopy();
         }
     }
     $tpl = $this->resolver->resolve($nameOrModel);
     $this->smarty->clearAllAssign();
     $this->smarty->assign($values);
     if ($this->config->enable_helper_object) {
         $this->smarty->assign($this->config->assigning_helper_name, new HelperProxy($this->helpers));
     }
     $content = $this->smarty->fetch($tpl);
     return $content;
 }
 /**
  * Generate the application based on the selected tables and options
  */
 public function Generate()
 {
     // check for all required fields
     if (empty($_REQUEST["table_name"])) {
         throw new Exception("Please select at least one table to generate");
     }
     $cstring = $this->GetConnectionString();
     // initialize the database connection
     $handler = new DBEventHandler();
     $connection = new DBConnection($cstring, $handler);
     $server = new DBServer($connection);
     $dbSchema = new DBSchema($server);
     $debug = isset($_REQUEST["debug"]) && $_REQUEST["debug"] == "1";
     $parameters = array();
     $tableNames = $_REQUEST["table_name"];
     $packageName = $_REQUEST["package"];
     $debug_output = "";
     $selectedTables = array();
     foreach ($tableNames as $tableName) {
         $selectedTables[] = $dbSchema->Tables[$tableName];
     }
     // see if arbitrary parameters were passed in - in which case they will be passed through to the templates
     $tmp = RequestUtil::Get('parameters');
     if ($tmp) {
         $pairs = explode("\n", str_replace("\r", "", $tmp));
         foreach ($pairs as $pair) {
             list($key, $val) = explode("=", $pair, 2);
             $parameters[$key] = $val;
         }
     }
     // check for required parameters
     if (!array_key_exists('max_items_in_topnav', $parameters)) {
         $parameters['max_items_in_topnav'] = self::$DEFAULT_MAX_ITEMS_IN_TOPNAV;
     }
     $zipFile = new zipfile();
     $codeRoot = GlobalConfig::$APP_ROOT . '/code/';
     $tempRoot = GlobalConfig::$APP_ROOT . '/temp/';
     // initialize smarty
     $smarty = new Smarty();
     $smarty->template_dir = $codeRoot;
     $smarty->compile_dir = $tempRoot;
     $smarty->config_dir = $tempRoot;
     $smarty->cache_dir = $tempRoot;
     $smarty->caching = false;
     $appname = RequestUtil::Get("appname");
     $appRoot = RequestUtil::Get("appRoot");
     $includePath = RequestUtil::Get("includePath");
     $includePhar = RequestUtil::Get("includePhar");
     $enableLongPolling = RequestUtil::Get("enableLongPolling");
     $config = new AppConfig($codeRoot . $packageName);
     foreach ($config->GetTemplateFiles() as $templateFile) {
         if ($templateFile->generate_mode == 3) {
             if ($includePhar == '1') {
                 // proceed, copy the phar file
                 $templateFile->generate_mode = 2;
             } else {
                 // skip the phar file
                 continue;
             }
         }
         if ($templateFile->generate_mode == 2) {
             // this is a template that is copied without parsing to the project (ie images, static files, etc)
             $templateFilename = str_replace(array('{$appname}', '{$appname|lower}', '{$appname|upper}'), array($appname, strtolower($appname), strtoupper($appname)), $templateFile->destination);
             $contents = file_get_contents($codeRoot . $templateFile->source);
             // this is a direct copy
             if ($debug) {
                 $debug_output .= "\r\n###############################################################\r\n" . "# {$templateFilename}\r\n###############################################################\r\n" . "(contents of " . $codeRoot . $templateFile->source . ")\r\n";
             } else {
                 $zipFile->addFile($contents, $templateFilename);
             }
         } elseif ($templateFile->generate_mode == 1) {
             // single template where one is generated for the entire project instead of one for each selected table
             $templateFilename = str_replace(array('{$appRoot}', '{$appRoot|lower}', '{$appRoot|upper}'), array($appRoot, strtolower($appRoot), strtoupper($appRoot)), $templateFile->destination);
             $smarty->clearAllAssign();
             foreach ($parameters as $key => $val) {
                 $smarty->assign($key, $val);
             }
             $smarty->assign("tableNames", $tableNames);
             $smarty->assign("templateFilename", $templateFilename);
             $smarty->assign("schema", $dbSchema);
             $smarty->assign("tables", $dbSchema->Tables);
             $smarty->assign("connection", $cstring);
             $smarty->assign("appname", $appname);
             $smarty->assign("appRoot", $appRoot);
             $smarty->assign("includePath", $includePath);
             $smarty->assign("includePhar", $includePhar);
             $smarty->assign("enableLongPolling", $enableLongPolling);
             $smarty->assign("PHREEZE_VERSION", Phreezer::$Version);
             $tableInfos = array();
             // add all tables to a tableInfos array that can be used for cross-referencing by table name
             foreach ($dbSchema->Tables as $table) {
                 if ($table->GetPrimaryKeyName()) {
                     $tableName = $table->Name;
                     $tableInfos[$tableName] = array();
                     $tableInfos[$tableName]['table'] = $dbSchema->Tables[$tableName];
                     $tableInfos[$tableName]['singular'] = $_REQUEST[$tableName . "_singular"];
                     $tableInfos[$tableName]['plural'] = $_REQUEST[$tableName . "_plural"];
                     $tableInfos[$tableName]['prefix'] = $_REQUEST[$tableName . "_prefix"];
                     $tableInfos[$tableName]['templateFilename'] = $templateFilename;
                 }
             }
             $smarty->assign("tableInfos", $tableInfos);
             $smarty->assign("selectedTables", $selectedTables);
             if ($debug) {
                 $debug_output .= "\r\n###############################################################\r\n" . "# {$templateFilename}\r\n###############################################################\r\n" . $smarty->fetch($templateFile->source) . "\r\n";
             } else {
                 // we don't like bare linefeed characters
                 $content = $body = preg_replace("/^(?=\n)|[^\r](?=\n)/", "\\0\r", $smarty->fetch($templateFile->source));
                 $zipFile->addFile($content, $templateFilename);
             }
         } else {
             // enumerate all selected tables and merge them with the selected template
             // append each to the zip file for output
             foreach ($tableNames as $tableName) {
                 $singular = $_REQUEST[$tableName . "_singular"];
                 $plural = $_REQUEST[$tableName . "_plural"];
                 $prefix = $_REQUEST[$tableName . "_prefix"];
                 $templateFilename = str_replace(array('{$singular}', '{$plural}', '{$table}', '{$appname}', '{$singular|lower}', '{$plural|lower}', '{$table|lower}', '{$appname|lower}', '{$singular|upper}', '{$plural|upper}', '{$table|upper}', '{$appname|upper}'), array($singular, $plural, $tableName, $appname, strtolower($singular), strtolower($plural), strtolower($tableName), strtolower($appname), strtoupper($singular), strtoupper($plural), strtoupper($tableName), strtoupper($appname)), $templateFile->destination);
                 $smarty->clearAllAssign();
                 $smarty->assign("appname", $appname);
                 $smarty->assign("singular", $singular);
                 $smarty->assign("plural", $plural);
                 $smarty->assign("prefix", $prefix);
                 $smarty->assign("templateFilename", $templateFilename);
                 $smarty->assign("table", $dbSchema->Tables[$tableName]);
                 $smarty->assign("connection", $cstring);
                 $smarty->assign("appRoot", $appRoot);
                 $smarty->assign("includePath", $includePath);
                 $smarty->assign("includePhar", $includePhar);
                 $smarty->assign("enableLongPolling", $enableLongPolling);
                 $smarty->assign("PHREEZE_VERSION", Phreezer::$Version);
                 $tableInfos = array();
                 // add all tables to a tableInfos array that can be used for cross-referencing by table name
                 foreach ($dbSchema->Tables as $table) {
                     if ($table->GetPrimaryKeyName()) {
                         $tableName = $table->Name;
                         $tableInfos[$tableName] = array();
                         $tableInfos[$tableName]['table'] = $dbSchema->Tables[$tableName];
                         $tableInfos[$tableName]['singular'] = $_REQUEST[$tableName . "_singular"];
                         $tableInfos[$tableName]['plural'] = $_REQUEST[$tableName . "_plural"];
                         $tableInfos[$tableName]['prefix'] = $_REQUEST[$tableName . "_prefix"];
                         $tableInfos[$tableName]['templateFilename'] = $templateFilename;
                     }
                 }
                 $smarty->assign("tableInfos", $tableInfos);
                 $smarty->assign("selectedTables", $selectedTables);
                 foreach ($parameters as $key => $val) {
                     $smarty->assign($key, $val);
                 }
                 //print "<pre>"; print_r($dbSchema->Tables[$tableName]->PrimaryKeyIsAutoIncrement()); die();
                 if ($debug) {
                     $debug_output .= "\r\n###############################################################\r\n" . "# {$templateFilename}\r\n###############################################################\r\n" . $smarty->fetch($templateFile->source) . "\r\n";
                 } else {
                     $zipFile->addFile($smarty->fetch($templateFile->source), $templateFilename);
                 }
             }
         }
     }
     if ($debug) {
         header("Content-type: text/plain");
         print $debug_output;
     } else {
         // now output the zip as binary data to the browser
         header("Content-type: application/force-download");
         // laplix 2007-11-02.
         // Use the application name provided by the user in show_tables.
         //header("Content-disposition: attachment; filename=".str_replace(" ","_",$G_CONNSTR->DBName).".zip");
         header("Content-disposition: attachment; filename=" . str_replace(" ", "_", strtolower(str_replace("/", "", $appRoot))) . ".zip");
         header("Content-Transfer-Encoding: Binary");
         header('Content-Type: application/zip');
         print $zipFile->file();
     }
 }
Example #5
0
 /**
  * @see IRenderEngine::clearAll()
  */
 function clearAll()
 {
     $this->smarty->clearAllAssign();
 }
Example #6
0
 /**
  * Clear all assigned variables
  *
  * Clears all variables assigned to Zend_View either via {@link assign()} or
  * property overloading ({@link __get()}/{@link __set()}).
  *
  * @return void
  */
 public function clearVars()
 {
     $this->_smarty->clearAllAssign();
 }
Example #7
0
 /**
  * Zend_View compatibility. Removes all template vars
  *
  * @see View/Zend_View_Abstract::clearVars()
  * @return Ext_View_Smarty
  */
 public function clearVars()
 {
     $this->_smarty->clearAllAssign();
     $this->assign('this', $this);
     return $this;
 }
Example #8
0
 /**
  * Clear all assigned values
  *
  * @return void
  */
 public function clearValues()
 {
     parent::clearValues();
     $this->_smarty->clearAllAssign();
 }