Exemplo n.º 1
0
 /**
  * load template from any input 
  *
  * If the a template is loaded, the content will not get
  * analyzed but the whole content is returned as a string.
  *
  * @abstract	must be implemented in the template readers
  * @param	mixed	input to load from.
  *					This can be a string, a filename, a resource or whatever the derived class needs to read from
  * @return	string  template content
  */
 function loadTemplate($input)
 {
     $fullPath = $this->_resolveFullPath($input);
     if (patErrorManager::isError($fullPath)) {
         return $fullPath;
     }
     return $this->_getFileContents($fullPath);
 }
Exemplo n.º 2
0
 /**
  * fetch the template data from the database
  *
  * @access   protected
  * @param    string      input to read from
  */
 function getDataFromDb($input)
 {
     // check for PEAR DB
     if (!class_exists('DB')) {
         @(include_once 'DB.php');
         if (!class_exists('DB')) {
             return patErrorManager::raiseError(PATTEMPLATE_READER_DB_ERROR_CLASS_NOT_FOUND, 'This reader requires PEAR::DB which could not be found on your system.');
         }
     }
     // establish connection
     $db =& DB::connect($this->getTemplateRoot());
     if (PEAR::isError($db)) {
         return patErrorManager::raiseError(PATTEMPLATE_READER_DB_ERROR_NO_CONNECTION, 'Could not establish database connection: ' . $db->getMessage());
     }
     $input = $this->parseInputStringToQuery($input, $db);
     if (patErrorManager::isError($input)) {
         return $input;
     }
     $content = $db->getOne($input);
     if (PEAR::isError($content)) {
         return patErrorManager::raiseError(PATTEMPLATE_READER_DB_ERROR_NO_INPUT, 'Could not fetch template: ' . $content->getMessage());
     }
     return $content;
 }
Exemplo n.º 3
0
 /**
  * compile a template
  *
  * @access	public
  * @param	string	name of the template
  */
 function compileTemplate($template)
 {
     $name = strtolower($template);
     if (!isset($this->_templates[$template])) {
         return patErrorManager::raiseWarning(PATTEMPLATE_WARNING_NO_TEMPLATE, "Template '{$name}' does not exist.");
     }
     /**
      * check, if the template has been loaded
      * and load it if necessary.
      */
     if ($this->_templates[$template]['loaded'] !== true) {
         if ($this->_templates[$template]['attributes']['parse'] == 'on') {
             $result = $this->readTemplatesFromInput($this->_templates[$template]['attributes']['src'], $this->_templates[$template]['attributes']['reader'], null, $template);
         } else {
             $result = $this->loadTemplateFromInput($this->_templates[$template]['attributes']['src'], $this->_templates[$template]['attributes']['reader'], $template);
         }
         if (patErrorManager::isError($result)) {
             return $result;
         }
     }
     $this->_addToCode('');
     $this->_addToCode('/**');
     $this->_addToCode(' * Compiled version of ' . $template);
     $this->_addToCode(' *');
     $this->_addToCode(' * Template type is ' . $this->_templates[$template]['attributes']['type']);
     $this->_addToCode(' */');
     /**
      * start the output
      */
     $this->_addToCode('function ' . $template . '()');
     $this->_addToCode('{');
     $this->_addToCode('$this->_prepareCompiledTemplate( "' . $template . '" );', 1);
     $this->_addToCode('$this->prepareTemplate( "' . $template . '" );', 1);
     /**
      * attributes
      */
     $this->_addToCode('$this->_templates["' . $template . '"]["attributes"] = unserialize( \'' . serialize($this->_templates[$template]['attributes']) . '\' );', 1, 'Read the attributes');
     /**
      * copyVars
      */
     $this->_addToCode('$this->_templates["' . $template . '"]["copyVars"] = unserialize( \'' . serialize($this->_templates[$template]['copyVars']) . '\' );', 1, 'Read the copyVars');
     /**
      * check visibility
      */
     $this->_addToCode('if( $this->_templates["' . $template . '"]["attributes"]["visibility"] != "hidden" ) {', 1, 'Check, whether template is hidden');
     /**
      * autoloop the template
      */
     $this->_addToCode('$this->_templates["' . $template . '"]["iteration"] = 0;', 2, 'Reset the iteration');
     $this->_addToCode('$loop = count( $this->_vars["' . $template . '"]["rows"] );', 2, 'Get the amount of loops');
     $this->_addToCode('$loop = max( $loop, 1 );', 2);
     $this->_addToCode('$this->_templates["' . $template . '"]["loop"] = $loop;', 2);
     $this->_addToCode('for( $i = 0; $i < $loop; $i++ ) {', 2, 'Traverse all variables.');
     /**
      * fetch the variables
      */
     $this->_addToCode('unset( $this->_templates["' . $template . '"]["vars"] );', 3);
     $this->_addToCode('$this->_fetchVariables("' . $template . '");', 3);
     /**
      * different templates have to be compiled differently
      */
     switch ($this->_templates[$template]['attributes']['type']) {
         /**
          * modulo template
          */
         case 'modulo':
             $this->_compileModuloTemplate($template);
             break;
             /**
              * simple condition template
              */
         /**
          * simple condition template
          */
         case 'simplecondition':
             $this->_compileSimpleConditionTemplate($template);
             break;
             /**
              * condition template
              */
         /**
          * condition template
          */
         case 'condition':
             $this->_compileConditionTemplate($template);
             break;
             /**
              * standard template
              */
         /**
          * standard template
          */
         default:
             $this->_compileStandardTemplate($template);
             break;
     }
     $this->_addToCode('$this->_templates["' . $template . '"]["iteration"]++;', 3);
     $this->_addToCode('}', 2);
     $this->_addToCode('}', 1);
     $this->_addToCode('}');
     /**
      * remember this template
      */
     array_push($this->_compiledTemplates, $template);
 }
Exemplo n.º 4
0
 /**
  * Returns a parsed template
  *
  * @access public
  * @param string 	$name		The name of the template
  */
 function fetch($name)
 {
     $result = $this->getParsedTemplate($name, true);
     /**
      * error happened
      */
     if (patErrorManager::isError($result)) {
         return $result;
     }
     return $result;
 }
Exemplo n.º 5
0
 /**
  * load configuration from a file
  *
  * @access	public
  * @param	string	$configFile		full path of the config file
  * @param	array	$options		various options, depending on the reader
  * @return	array	$config			complete configuration
  */
 function loadConfigFile($configFile, $options = array())
 {
     $this->path = array();
     $this->conf = array();
     $result = $this->parseXMLFile($configFile);
     if (patErrorManager::isError($result)) {
         return $result;
     }
     return array('config' => $this->conf, 'externalFiles' => $this->externalFiles, 'cacheAble' => true);
 }
Exemplo n.º 6
0
 /**
  * Displays useful information about all or named templates
  *
  * This method breaks BC, as it now awaits an array instead of
  * unlimited parameters.
  *
  * @param	mixed	array of templates that should be dumped, or null if you
  *					want all templates to be dumped
  * @param	string	dumper
  * @access	public
  */
 function dump($restrict = null, $dumper = 'Html')
 {
     if (is_string($restrict)) {
         $restrict = array($restrict);
     }
     $dumper =& $this->loadModule('Dump', $dumper);
     if (patErrorManager::isError($dumper)) {
         return $dumper;
     }
     if (is_null($restrict)) {
         $templates = $this->_templates;
         $vars = $this->_vars;
     } else {
         $restrict = array_map('strtolower', $restrict);
         $templates = array();
         $vars = array();
         foreach ($this->_templates as $name => $spec) {
             if (!in_array($name, $restrict)) {
                 continue;
             }
             $templates[$name] = $spec;
             $vars[$name] = $this->_vars[$name];
         }
     }
     $dumper->displayHeader();
     $dumper->dumpGlobals($this->_globals);
     $dumper->dumpTemplates($templates, $vars);
     $dumper->displayFooter();
     return true;
 }
Exemplo n.º 7
0
 /**
  * Serializes the form's start element for html format, in readonly mode.
  *
  * @access     private
  * @return     mixed	$formStart	The serialized start content, or a patError object.
  */
 function serializeStartHtmlReadonly()
 {
     $attributes = $this->getAttributesFor($this->format);
     if (patErrorManager::isError($attributes)) {
         return $attributes;
     }
     return patForms_Element::createTag('form', 'opening', $attributes);
 }
Exemplo n.º 8
0
 /**
  * load template from any input
  *
  * If the a template is loaded, the content will not get
  * analyzed but the whole content is returned as a string.
  *
  * @abstract	must be implemented in the template readers
  * @param	mixed	input to load from.
  *					This can be a string, a filename, a resource or whatever the derived class needs to read from
  * @return	string  template content
  */
 function loadTemplate($input)
 {
     if (isset($this->_rootAtts['relative'])) {
         $relative = $this->_rootAtts['relative'];
     } else {
         $relative = false;
     }
     $fullPath = $this->_resolveFullPath($input, $relative);
     if (patErrorManager::isError($fullPath)) {
         return $fullPath;
     }
     return $this->_getFileContents($fullPath);
 }
Exemplo n.º 9
0
 /**
  * load configuration from a file
  *
  * @access	public
  * @param	string	$configFile		full path of the config file
  * @param	array	$options		various options, depending on the reader
  * @return	array	$config			complete configuration
  */
 function loadConfigFile($configFile, $options = array())
 {
     $this->path = array();
     $this->conf = array();
     /*
     		//	check, whether extension have been supplied
     		if( isset( $options['extensions'] ) && is_array( $options['extensions'] ) )
     		{
     			foreach( $options['extension'] as $ns => $extension )
     				$this->addExtension( $extension, $ns );
     		}
     		
     		//	check, whether defined tags have been supplied
     		if( isset( $options['definedTags'] ) && is_array( $options['definedTags'] ) )
     		{
     			foreach( $options['extension'] as $ns => $extension )
     		}
     */
     $result = $this->parseXMLFile($configFile);
     if (patErrorManager::isError($result)) {
         return $result;
     }
     return array('config' => $this->conf, 'externalFiles' => $this->externalFiles, 'cacheAble' => true);
 }
Exemplo n.º 10
0
 /**
  * handle end element
  *
  * @access	private
  * @param	string		element name
  */
 function _endElement($ns, $name)
 {
     $el = array_pop($this->_elStack);
     $data = $this->_getCData();
     $this->_depth--;
     if ($el['name'] != $name || $el['ns'] != $ns) {
         return patErrorManager::raiseError(PATTEMPLATE_READER_ERROR_INVALID_CLOSING_TAG, $this->_createErrorMessage("Invalid closing tag {$ns}:{$name}, {$el['ns']}:{$el['name']} expected"));
     }
     $tmpl = array_pop($this->_tmplStack);
     /**
      * handle tag
      */
     switch ($name) {
         /**
          * template
          */
         case 'tmpl':
             $this->_closeTemplate($tmpl, $data);
             break;
             /**
              * sub-template
              */
         /**
          * sub-template
          */
         case 'sub':
             $this->_closeSubTemplate($tmpl, $data);
             break;
             /**
              * link
              */
         /**
          * link
          */
         case 'link':
             $this->_closeLink($tmpl);
             break;
             /**
              * variable
              */
         /**
          * variable
          */
         case 'var':
             $this->_handleVariable($el['attributes'], $data);
             break;
             /**
              * instance
              */
         /**
          * instance
          */
         case 'instance':
             break;
             /**
              * comment
              */
         /**
          * comment
          */
         case 'comment':
             $this->_handleComment($el['attributes'], $data);
             break;
             /**
              * custom function
              */
         /**
          * custom function
          */
         default:
             if (isset($this->_funcAliases[strtolower($name)])) {
                 $name = $this->_funcAliases[strtolower($name)];
             }
             $name = ucfirst($name);
             if (!isset($this->_functions[$name])) {
                 $this->_functions[$name] = $this->_tmpl->loadModule('Function', $name);
                 $this->_functions[$name]->setReader($this);
             }
             $result = $this->_functions[$name]->call($tmpl['attributes'], $data);
             if (patErrorManager::isError($result)) {
                 return $result;
             }
             if (is_string($result)) {
                 $this->_characterData($result, false);
             }
             break;
     }
 }
Exemplo n.º 11
0
 /**
  * [helper method] wrapper for the {@link createTag()} method which automates the tag
  * creation by creating the tag from the current attribute collection and element type.
  *
  * @access     protected
  * @return     mixed	$result	The created tag, or false if failed.
  * @see        elementType
  * @see        attributes
  * @see        createTag()
  */
 function toHtml()
 {
     $attributes = $this->getAttributesFor($this->getFormat());
     if (patErrorManager::isError($attributes)) {
         return $attributes;
     }
     return $this->createTag($this->elementType[$this->getFormat()], "full", $attributes);
 }
Exemplo n.º 12
0
 /**
  * write a configfile
  *
  *
  * @access	public
  * @param	string	$filename	name of the configfile
  * @param	string	$format		format of the config file
  * @param	array	$options	options, see the writer driver for details
  */
 function writeConfigFile($filename, $options = NULL, $oldOptions = NULL)
 {
     //	older versions needed the filetype as secand parameter
     if (!is_array($options)) {
         $options = array('filetype' => $options);
     }
     //	options had to be specified as third param prior to version 2.0
     if (is_array($oldOptions)) {
         $options = array_merge($oldOptions, $options);
     }
     //	no filetype given, extract from filename
     if (isset($options['filetype']) && !empty($options['filetype'])) {
         $filetype = $options['filetype'];
     } else {
         $filetype = $this->_getFiletype($filename);
     }
     $writer =& $this->_getDriver($filetype, 'Writer');
     if (!is_object($writer)) {
         return $writer;
     }
     //	seriaize the content
     $content = $writer->serializeConfig($this->conf, $options);
     if ($content) {
         $file = $this->getFullPath($filename, NULL, false);
         if (patErrorManager::isError($file)) {
             return $file;
         }
         $fp = @fopen($file, 'w');
         if ($fp) {
             flock($fp, LOCK_EX);
             fputs($fp, $content);
             flock($fp, LOCK_UN);
             fclose($fp);
             $oldMask = umask(00);
             chmod($file, 0666);
             umask($oldMask);
         }
     }
 }
 /**
  * write a configfile
  *
  *
  * @access	public
  * @param	string	$filename	name of the configfile
  * @param	string	$format		format of the config file
  * @param	array	$options	options, see the writer driver for details
  */
 function writeConfigFile($filename, $options = NULL, $oldOptions = NULL)
 {
     //	older versions needed the filetype as secand parameter
     if (!is_array($options)) {
         $options = array('filetype' => $options);
     }
     //	options had to be specified as third param prior to version 2.0
     if (is_array($oldOptions)) {
         $options = array_merge($oldOptions, $options);
     }
     //	no filetype given, extract from filename
     if (isset($options['filetype']) && !empty($options['filetype'])) {
         $filetype = $options['filetype'];
     } else {
         $filetype = $this->_getFiletype($filename);
     }
     $writer =& $this->_getDriver($filetype, 'Writer');
     if (patErrorManager::isError($writer)) {
         return $writer;
     }
     //	serialize the content
     $content = $writer->serializeConfig($this->conf, $options);
     if (patErrorManager::isError($content)) {
         return $content;
     }
     $file = $this->getFullPath($filename, NULL, false);
     if (patErrorManager::isError($file)) {
         return $file;
     }
     $fp = @fopen($file, 'w');
     if (!$fp) {
         return patErrorManager::raiseError(PATCONFIGURATION_ERROR_FILE_NOT_WRITABLE, 'Could not write configuration to file [' . $file . '], file could not be opened.');
     }
     flock($fp, LOCK_EX);
     fputs($fp, $content);
     flock($fp, LOCK_UN);
     fclose($fp);
     $oldMask = umask(00);
     chmod($file, 0666);
     umask($oldMask);
     return true;
 }