示例#1
0
文件: Html.php 项目: ssrsfs/blg
 public function __construct($nsPrefix)
 {
     $this->nsUri = 'http://www.w3.org/1999/xhtml';
     parent::__construct($nsPrefix);
     $this->registerTag('a', 'Pagemill_Tag_AlwaysExpand');
     $this->registerTag('b', 'Pagemill_Tag_AlwaysExpand');
     $this->registerTag('body', 'Pagemill_Tag_AlwaysExpand');
     $this->registerTag('div', 'Pagemill_Tag_AlwaysExpand');
     $this->registerTag('em', 'Pagemill_Tag_AlwaysExpand');
     $this->registerTag('head', 'Pagemill_Tag_AlwaysExpand');
     $this->registerTag('i', 'Pagemill_Tag_AlwaysExpand');
     $this->registerTag('iframe', 'Pagemill_Tag_AlwaysExpand');
     $this->registerTag('option', 'Pagemill_Tag_Html_Option');
     $this->registerTag('p', 'Pagemill_Tag_AlwaysExpand');
     $this->registerTag('script', 'Pagemill_Tag_Html_Script');
     $this->registerTag('select', 'Pagemill_Tag_Html_Select');
     $this->registerTag('span', 'Pagemill_Tag_AlwaysExpand');
     $this->registerTag('strong', 'Pagemill_Tag_AlwaysExpand');
     $this->registerTag('textarea', 'Pagemill_Tag_AlwaysExpand');
     $this->registerTag('title', 'Pagemill_Tag_AlwaysExpand');
     $this->registerTag('iframe', 'Pagemill_Tag_AlwaysExpand');
     $this->addEntityArray(get_html_translation_table(HTML_ENTITIES, ENT_COMPAT, 'UTF-8'));
 }
示例#2
0
文件: Template.php 项目: ssrsfs/blg
 public function __construct($nsPrefix)
 {
     $this->nsUri = 'http://typeframe.com/pagemill';
     parent::__construct($nsPrefix);
     $this->keepNamespaceDeclarationInOutput = false;
     $this->registerTag('template', 'Pagemill_Tag_Template');
     $this->registerTag('attribute', 'Pagemill_Tag_AttributeTag');
     $this->registerTag('loop', 'Pagemill_Tag_Loop');
     $this->registerTag('for-each', 'Pagemill_Tag_Loop');
     $this->registerTag('if', 'Pagemill_Tag_If');
     $this->registerTag('else', 'Pagemill_Tag_Else');
     $this->registerTag('choose', 'Pagemill_Tag_Choose');
     $this->registerTag('include', 'Pagemill_Tag_Include');
     $this->registerTag('recurse', 'Pagemill_Tag_Recurse');
     $this->registerTag('eval', 'Pagemill_Tag_Eval');
     $this->registerTag('element', 'Pagemill_Tag_Element');
     $this->registerAttribute('loop', 'Pagemill_Attribute_Loop');
     $this->registerAttribute('for-each', 'Pagemill_Attribute_Loop');
     $this->registerAttribute('checked', 'Pagemill_Attribute_Checked');
     $this->registerAttribute('selected', 'Pagemill_Attribute_Selected');
     $this->registerAttribute('if', 'Pagemill_Attribute_If');
     $this->registerAttribute('content', 'Pagemill_Attribute_Content');
     $this->registerAttribute('replace', 'Pagemill_Attribute_Replace');
 }
示例#3
0
文件: import.php 项目: ssrsfs/blg
<?php

date_default_timezone_set('America/New_York');
$mtime = microtime(true);
define('TYPEF_START_TIME', $mtime);
require_once TYPEF_SOURCE_DIR . '/autoload.php';
require_once TYPEF_SOURCE_DIR . '/libraries/functions.php';
Pagemill_Doctype::SetTemplateDoctypeClass('Typeframe_Doctype');
// TODO: Set up a way to make the framework database-independent.
$source = new Dbi_Source_MySql(TYPEF_DB_HOST, TYPEF_DB_USER, TYPEF_DB_PASS, TYPEF_DB_NAME);
Dbi_Source::SetGlobalSource($source);
// TODO: Find logical places to register the class handlers and expressions.
function useModel($model)
{
    return $model->select();
}
function useFormHandler($form)
{
    return array('fields' => $form->fields(), 'errors' => $form->errors());
}
function useFormField($field)
{
    return $field->data();
}
Pagemill_Data::ClassHandler('Dbi_Model', 'useModel');
Pagemill_Data::ClassHandler('Form_Handler', 'useFormHandler');
Pagemill_Data::ClassHandler('Form_Field', 'useFormField');
Pagemill_Data::RegisterExprFunc('default_date', 'Typeframe_ExprFunc::default_date');
Pagemill_Data::RegisterExprFunc('default_date_time', 'Typeframe_ExprFunc::default_date_time');
Pagemill_Data::RegisterExprFunc('default_date_time_w_seconds', 'Typeframe_ExprFunc::default_date_time_w_seconds');
Pagemill_Data::RegisterExprFunc('skin_path', 'Typeframe_Skin::SkinPath');
示例#4
0
文件: Doctype.php 项目: ssrsfs/blg
 public static function SetTemplateDoctypeClass($classname)
 {
     self::$_templateDoctypeClass = $classname;
     Pagemill_Doctype::RegisterNamespaceUri('http://typeframe.com/pagemill', $classname);
 }
示例#5
0
文件: Pagemill.php 项目: ssrsfs/blg
 /**
  * Parse a template file into a tag tree for processing.
  * @param string $file The filename.
  * @param Pagemill_Doctype $doctype The doctype. Inferred from file
  * extension or source if null.
  * @param boolean $useCache Read/write to cache if available.
  * @return Pagemill_Tag
  */
 public function parseFile($file, $doctype = null, $useCache = true)
 {
     self::$_processedTemplates[] = $file;
     if (is_null($file) || $file === '') {
         throw new Exception('File name required');
     }
     if (!file_exists($file)) {
         throw new Exception("File '{$file}' does not exist");
     }
     if (is_dir($file)) {
         throw new Exception("'{$file}' is a directory");
     }
     if (defined('PAGEMILL_CACHE_DIR') && $useCache) {
         $md5 = md5($file);
         $cacheFile = PAGEMILL_CACHE_DIR . "/{$md5}";
         if (file_exists($cacheFile)) {
             $cacheTime = filemtime($cacheFile);
             $tmplTime = filemtime($file);
             if ($tmplTime < $cacheTime) {
                 $serial = file_get_contents($cacheFile);
                 return unserialize($serial);
             }
         }
     }
     $source = file_get_contents($file);
     if (is_null($doctype)) {
         $doctype = Pagemill_Doctype::ForFile($file);
     }
     $tree = $this->parseString($source, $doctype);
     if (defined('PAGEMILL_CACHE_DIR')) {
         $serial = serialize($tree);
         file_put_contents($cacheFile, $serial);
         @chmod($cacheFile, 0666);
     }
     return $tree;
 }
示例#6
0
文件: Parser.php 项目: ssrsfs/blg
 private function _xmlStartElement($parser, $name, $attributes)
 {
     $last = null;
     if (count($this->_tagStack)) {
         $last =& $this->_tagStack[count($this->_tagStack) - 1];
         if ($this->_currentCharacterData) {
             $last->appendText($this->_currentCharacterData);
             $this->_currentCharacterData = '';
         }
     }
     if ($last) {
         $currentDoctype = $last->doctype();
     } else {
         $currentDoctype = $this->_doctype;
     }
     foreach ($attributes as $k => $v) {
         if ($k == 'xmlns' || substr($k, 0, 6) == 'xmlns:') {
             $doctype = Pagemill_Doctype::ForNamespaceUri($v, substr($k, 6));
             $currentDoctype->merge($doctype);
             if (!$doctype->keepNamespaceDeclarationInOutput()) {
                 unset($attributes[$k]);
             }
         } else {
             if (substr($k, 0, 3) == 'pm:' && !isset($this->_namespaces['pm'])) {
                 // Declare the Template doctype using the default pm prefix
                 $this->_namespaces['pm'] = 'http://typeframe.com/pagemill';
                 $pm = Pagemill_Doctype::GetTemplateDoctype('pm');
                 $currentDoctype->merge($pm);
             }
         }
     }
     if (substr($name, 0, 3) == 'pm:' && !isset($this->_namespaces['pm'])) {
         // Declare the Template doctype using the default pm prefix
         $this->_namespaces['pm'] = 'http://typeframe.com/pagemill';
         $pm = Pagemill_Doctype::GetTemplateDoctype('pm');
         $currentDoctype->merge($pm);
     }
     $tagRegistry = $currentDoctype->tagRegistry();
     if (isset($tagRegistry[$name])) {
         $cls = $tagRegistry[$name];
         $tag = new $cls($name, $attributes, $last, $currentDoctype);
     } else {
         $tag = new Pagemill_Tag($name, $attributes, $last, $currentDoctype);
     }
     if (!count($this->_tagStack)) {
         // This appears to be a root element, so append the headers.
         $header = trim("{$this->_xmlDeclString}\n{$this->_doctypeString}\n");
         $tag->header($header);
     }
     $this->_tagStack[] = $tag;
 }
示例#7
0
文件: Data.php 项目: ssrsfs/blg
 public function parseVariables($text, Pagemill_Doctype $encoder = null)
 {
     $result = $text;
     preg_match_all('/@{([\\w\\W\\s\\S]*?)}@/i', $text, $matches);
     foreach ($matches[0] as $index => $container) {
         $expression = $matches[1][$index];
         $evaluated = $this->evaluate($expression);
         if (!is_null($evaluated) && !is_scalar($evaluated)) {
             if (is_array($evaluated)) {
                 $evaluated = self::IsAssoc($evaluated) ? '(Object)' : '(Array)';
             } else {
                 if (is_a($evaluated, 'Pagemill_Data')) {
                     $evaluated = '(Object)';
                 } else {
                     if (Pagemill_Data::LikeArray($evaluated)) {
                         $evaluated = '(ArrayInterface)';
                     } else {
                         if (Pagemill_Data::LikeAssoc($evaluated)) {
                             $evaluated = '(Interface)';
                         } else {
                             $evaluated = '(Unknown)';
                         }
                     }
                 }
             }
         }
         if ($encoder) {
             $evaluated = $encoder->encodeEntities($evaluated);
         }
         $result = str_replace($container, $evaluated, $result);
     }
     preg_match_all('/#{([\\w\\W\\s\\S]*?)}#/i', $result, $matches);
     foreach ($matches[0] as $index => $container) {
         $expression = $matches[1][$index];
         $evaluated = $this->evaluate($expression);
         if (!is_null($evaluated) && !is_scalar($evaluated)) {
             if (is_array($evaluated)) {
                 $evaluated = self::IsAssoc($evaluated) ? '(Object)' : '(Array)';
             } else {
                 if (is_a($evaluated, 'Pagemill_Data')) {
                     $evaluated = '(Object)';
                 } else {
                     if (Pagemill_Data::LikeArray($evaluated)) {
                         $evaluated = '(ArrayInterface)';
                     } else {
                         if (Pagemill_Data::LikeAssoc($evaluated)) {
                             $evaluated = '(Interface)';
                         } else {
                             $evaluated = '(Unknown)';
                         }
                     }
                 }
             }
         }
         if ($encoder) {
             $evaluated = $encoder->encodeEntities($evaluated);
         }
         $result = str_replace($container, '@{' . $evaluated . '}@', $result);
     }
     return $result;
 }