Пример #1
0
 public function testRenderPlugin()
 {
     $plugin = new Plugin_News_Feed('');
     $data = new Pagemill_Data();
     $stream = new Pagemill_Stream(true);
     $plugin->output($data, $stream);
     $html = $stream->peek();
     // Parse output to check for well-formed XML
     $xml = Pagemill_SimpleXmlElement::LoadString("<body>{$html}</body>");
     $this->assertTrue(strpos($html, 'Article One') !== false, "Article title was not found in News Feed output");
 }
Пример #2
0
 public function __construct()
 {
     parent::__construct();
     $this->innerJoin('urlmeta', 'Model_UrlMeta', 'urlmeta.id = urlmetaid');
     $this->attach(Dbi_Model::EVENT_BEFORESAVE, new ModelEvent_Callback(function ($record) {
         if ($record['extra']) {
             $xml = @Pagemill_SimpleXmlElement::LoadString($record['extra']);
             if (!$xml) {
                 $xml = Pagemill_SimpleXmlElement::LoadHtml('<html><head>' . $record['extra'] . '</head><body></body></html>');
                 $record['extra'] = $xml->head->innerXml();
             }
         }
     }));
 }
Пример #3
0
 public function output(\Pagemill_Data $data, \Pagemill_Stream $stream)
 {
     if ($this->hasAttribute('template')) {
         $template = Typeframe_Skin::TemplatePath($data->parseVariables($this->getAttribute('template')));
         $this->setAttribute('file', $template);
     }
     if ($this->getAttribute('select')) {
         $select = $this->getAttribute('select');
         $temp = new Pagemill_Stream(true);
         parent::output($data, $temp);
         $xml = Pagemill_SimpleXmlElement::LoadString($temp->clean());
         $parts = $xml->select($select);
         foreach ($parts as $part) {
             $stream->puts($part->asXml());
         }
     } else {
         parent::output($data, $stream);
     }
 }
Пример #4
0
 public function output(Pagemill_Data $data, Pagemill_Stream $stream)
 {
     // Create the element and attribute arrays
     if ($this->hasAttribute('elements')) {
         $elements = $data->parseVariables($this->getAttribute('elements'));
     } else {
         $elements = self::ELEMENTS;
     }
     if ($this->hasAttribute('attributes')) {
         $attributes = $data->parseVariables($this->getAttribute('attributes'));
     } else {
         $attributes = self::ATTRIBUTES;
     }
     if ($this->hasAttribute('xelements')) {
         $elements .= ($elements ? ',' : '') . $this->getAttribute('xelements');
     }
     if ($this->hasAttribute('xattributes')) {
         $attributes .= ($attributes ? ',' : '') . $this->getAttribute('xattributes');
     }
     $elementArray = array_unique(preg_split('/ *, */', $elements));
     $attributeArray = array_unique(preg_split('/ *, */', $attributes));
     if (in_array('*', $elementArray)) {
         $elementArray = array('*');
     }
     if (in_array('*', $attributeArray) || in_array('*.*', $attributeArray)) {
         $attributeArray = array('*');
     }
     $buffer = new Pagemill_Stream(true);
     foreach ($this->children() as $child) {
         $child->rawOutput($buffer, false);
     }
     $source = $buffer->clean();
     $source = $data->parseVariables($source);
     if (!trim($source)) {
         return;
     }
     if ($this->getAttribute('use') == 'markdown') {
         require_once TYPEF_SOURCE_DIR . '/libraries/markdown.php';
         $source = Markdown($source);
     }
     try {
         $parser = new Pagemill_Parser();
         $doctype = new Pagemill_Doctype_Html('');
         // Register the href and src attribute processors for URL shortcuts
         $doctype->registerAttribute('/href', 'Typeframe_Attribute_Url');
         $doctype->registerAttribute('/src', 'Typeframe_Attribute_Url');
         $tree = $parser->parse($source, $doctype);
     } catch (Exception $e) {
         $lastError = $e->getMessage();
         //$stream->puts(htmlentities($source));
         //$stream->puts($source);
         try {
             $xml = @Pagemill_SimpleXmlElement::LoadHtml("<div id=\"codeblock__\">{$source}</div>");
             $select = $xml->select('#codeblock__');
             $inner = $select[0]->innerXml();
             $parser = new Pagemill_Parser();
             $doctype = new Pagemill_Doctype_Html('');
             $doctype->registerAttribute('/href', 'Typeframe_Attribute_Url');
             $doctype->registerAttribute('/src', 'Typeframe_Attribute_Url');
             $tree = $parser->parse('<pm:template>' . trim($inner) . '</pm:template>', $doctype);
         } catch (Exception $e) {
             trigger_error($lastError);
             trigger_error($e->getMessage());
             $stream->puts(htmlentities($source));
             return;
         }
     }
     $this->_recurseInput($tree, $stream, $elementArray, $attributeArray, $data);
 }
Пример #5
0
<?php

$article->setArray($_POST, false);
if (!empty($_POST['autosummary'])) {
    $article['autosummary'] = 1;
    $xml = Pagemill_SimpleXmlElement::LoadString($_POST['article']);
    if ($xml->p) {
        $summary = trim($xml->p[0]->innerXml());
    } else {
        $summary = trim(Bam_Functions::GetIntro($_POST['article']));
    }
    $article['summary'] = $summary;
} else {
    $article['autosummary'] = 0;
}
$article['image'] = basename(FileManager::GetPostedOrUploadedFile('image', TYPEF_DIR . '/files/public/news', 'jpg,jpeg,png,gif'));
if (FileManager::Error()) {
    $pm->addLoop('errors', array('message' => FileManager::Error()));
} else {
    $article->save();
}
Пример #6
0
<?php

/**
 * Download tests for all installed packages.
 */
$dir = scandir(TYPEF_SOURCE_DIR . '/packages');
foreach ($dir as $file) {
    if (substr($file, 0, 1) != '.' && pathinfo($file, PATHINFO_EXTENSION) == 'xml') {
        $package = pathinfo($file, PATHINFO_FILENAME);
        $xml = Pagemill_SimpleXmlElement::LoadFile(TYPEF_SOURCE_DIR . "/packages/{$file}");
        $version = $xml['version'];
        // Ignore packages without tests (required for backwards compatibility)
        $buffer = @file_get_contents(TYPEF_PROVIDER . '/download/' . $package . '-' . $version . '-test.tar.gz');
        if ($buffer) {
            echo "Installing tests for {$package}\n";
            file_put_contents('test.tar.gz', $buffer);
            exec('tar -zxvf test.tar.gz');
            exec('rm test.tar.gz');
        }
    }
}
Пример #7
0
 /**
  * Get URL metadata for a URL.
  * @param string $url The URL. If null, use the current page.
  * @param boolean $create Create a new record if the URL is valid.
  * @param string $newLabel The label for the URL if it doesn't exist.
  * @return Dbi_Record The URL metadata record.
  */
 public static function GetUrl($url = null, $create = true, $newLabel = '')
 {
     if (is_null($url)) {
         //$url = Typeframe::CurrentPage()->uri();
         //$app = Typeframe::CurrentPage()->application();
         $url = Typeframe::CurrentPage()->uri();
         if (substr($url, 0, -1) == '/') {
             $url = substr($url, -1);
         }
         $response = Typeframe::CurrentPage();
     } else {
         $url = parse_url($url, PHP_URL_PATH);
         if (substr($url, 0, -1) == '/') {
             $url = substr($url, -1);
         }
         $url = preg_replace('/\\/+/', '/', $url);
         //$app = Typeframe::Registry()->applicationAt($url);
         $response = Typeframe::Registry()->responseAt($url);
     }
     $app = $response->application();
     // Return a blank (nonexistent) Dbi_Record for invalid URLs
     if (!$app) {
         return Model_UrlMeta::Create();
     }
     $model = new Model_UrlMeta();
     $model->where('pageid = ?', $response->pageid());
     if ($response->pageid()) {
         $pathinfo = substr($url, strlen($response->applicationUri()));
     } else {
         $pathinfo = substr($response->applicationUri(), strlen(TYPEF_WEB_DIR));
     }
     if ($pathinfo == '/') {
         $pathinfo = '';
     }
     $model->where('pathinfo = ?', $pathinfo);
     $urlmeta = $model->getFirst();
     if (!$urlmeta->exists() && $create) {
         // Record does not exist. Generate a label and save it.
         $urlmeta['pageid'] = $response->pageid();
         $urlmeta['pathinfo'] = $pathinfo;
         if (!$newLabel) {
             // We need to save the metadata before we request the URL by proxy. Otherwise it's hammers all the way down.
             $urlmeta->save();
             // Create a label for the URL metadata
             $html = Typeframe::GetByProxy($url);
             if (!$html) {
                 return Model_UrlMeta::Create();
             } else {
                 $xml = @Pagemill_SimpleXmlElement::LoadString($html);
                 if ($xml) {
                     $selector = URLMETA_LABEL_SELECTOR ? URLMETA_LABEL_SELECTOR : 'title';
                     $parts = explode(',', $selector);
                     foreach ($parts as $part) {
                         if (trim($part)) {
                             $elements = $xml->select(trim($part));
                             if ($elements) {
                                 $urlmeta['label'] = trim($elements[0]->innerXml());
                                 break;
                             }
                         }
                     }
                 }
             }
             if (!$urlmeta['label']) {
                 $urlmeta['label'] = $app->title();
             }
         } else {
             $urlmeta['label'] = $newLabel;
         }
         $urlmeta->save();
     }
     return $urlmeta;
 }
Пример #8
0
 public static function StylesheetsFor($template, $uri = null)
 {
     $stylesheets = array();
     $tmplXml = Pagemill_SimpleXmlElement::LoadFile(Typeframe_Skin::TemplatePath($template, $uri));
     if (strpos($tmplXml->asXml(), '<pm:html') !== false) {
         if (is_null($uri)) {
             $skin = self::Current();
         } else {
             $skin = self::At($uri);
         }
         $skinXml = Pagemill_SimpleXmlElement::LoadFile(TYPEF_DIR . '/skins/' . $skin . '/skin.html');
         self::_GetStylesheetsFromElement($skinXml, $stylesheets);
     }
     self::_GetStylesheetsFromElement($tmplXml, $stylesheets);
     return $stylesheets;
 }
Пример #9
0
<?php

function _DownloadToBuffer($url)
{
    // TODO: Throw exceptions for invalid requests
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $buffer = curl_exec($curl);
    curl_close($curl);
    return $buffer;
}
$pages = new Model_Page();
foreach ($pages as $page) {
    $uri = TYPEF_WEB_DIR . $page['uri'];
    Model_UrlMeta::GetUrl($uri);
    $buffer = _DownloadToBuffer("http://{$_SERVER['HTTP_HOST']}{$uri}");
    $xml = Pagemill_SimpleXmlElement::LoadString($buffer);
    $links = $xml->select('a');
    foreach ($links as $link) {
        $uri = (string) $link['href'];
        if (substr($uri, 0, strlen(TYPEF_WEB_DIR)) == TYPEF_WEB_DIR) {
            Model_UrlMeta::GetUrl($uri);
        }
    }
}
Пример #10
0
 /**
  * Download package dependencies from the specified package in a temporary isntallation directory.
  * @param string $directory The temporary directory.
  * @param string $package The name of the package.
  * @param array $dependencies An array of package names that have already been downloaded.
  */
 private static function _GetDependencies($directory, $package, &$dependencies)
 {
     if (!file_exists("{$directory}/source/packages/{$package}.xml")) {
         $buffer = self::_DownloadToBuffer(TYPEF_PROVIDER . '/download/newest?package=' . $package);
         $tarball = "{$directory}/{$package}.tar.gz";
         file_put_contents($tarball, $buffer);
         exec('tar --directory=' . $directory . ' -zxf ' . $tarball);
         exec('rm ' . $tarball);
     }
     $xml = Pagemill_SimpleXmlElement::LoadFile("{$directory}/source/packages/{$package}.xml");
     foreach ($xml->require as $require) {
         $require = trim("{$require}");
         if (!in_array($require, $dependencies)) {
             $dependencies[] = $require;
             if (file_exists(TYPEF_SOURCE_DIR . "/packages/{$require}.xml")) {
                 // Dependency is already installed. Check if a newer version
                 // is available.
                 $installedXml = Pagemill_SimpleXmlElement::LoadFile(TYPEF_SOURCE_DIR . "/packages/{$require}.xml");
                 $latest = self::_DownloadToBuffer(TYPEF_PROVIDER . '/newest?package=' . $require);
                 if (self::EnumerateVersion($installedXml['version']) >= self::EnumerateVersion($latest)) {
                     continue;
                 }
             }
             $buffer = self::_DownloadToBuffer(TYPEF_PROVIDER . '/download/newest?package=' . $require);
             $tarball = "{$directory}/{$require}.tar.gz";
             file_put_contents($tarball, $buffer);
             exec('tar --directory=' . $directory . ' -zxf ' . $tarball, $output);
             exec('rm ' . $tarball);
             self::_GetDependencies($directory, $require, $dependencies);
         }
     }
 }
Пример #11
0
 public function testRenderTag()
 {
     $data = new Pagemill_Data();
     $data['my_variable'] = 'my_value';
     $stream = new Pagemill_Stream(true);
     $tag = new Typeframe_Tag_Debug('debug', array(), null, new Typeframe_Doctype('pm'));
     $tag->process($data, $stream);
     $output = $stream->clean();
     $xml = Pagemill_SimpleXmlElement::LoadString($output);
     $this->assertTrue(strpos($output, 'my_variable') !== false && strpos($output, 'my_value') !== false, "Data variables not found in debug output");
 }
Пример #12
0
<?php

/**
 * Check for customized files in packages
 * Syntax: compare-local [package]
 */
if (empty($argv[2])) {
    echo "No package specified.\n";
    exit;
}
$xml = Pagemill_SimpleXmlElement::LoadFile(TYPEF_SOURCE_DIR . '/packages/' . $argv[2] . '.xml');
foreach ($xml->file as $file) {
    if (file_exists(TYPEF_DIR . "/{$file}")) {
        $md5 = md5_file(TYPEF_DIR . "/{$file}");
        if ($md5 != "{$file['md5']}") {
            echo "Local version of {$file} is different.\n";
        }
    } else {
        echo "Local version of {$file} does not exist.\n";
    }
}
Пример #13
0
$sockets->where('plugin.siteid = ?', Typeframe::CurrentPage()->siteid());
$sockets->order('socket, sortnum');
foreach ($sockets->getAll() as $socket) {
    if (!isset($plugins[$socket->get('socket')])) {
        $plugins[$socket->get('socket')] = array();
    }
    $plugins[$socket->get('socket')][] = $socket;
}
// define skin file
$skinfile = TYPEF_DIR . '/skins/' . $skin . '/skin.html';
if (!file_exists($skinfile)) {
    $skinfile = TYPEF_DIR . '/skins/default/skin.html';
}
// load sockets for skin file
$source = file_get_contents($skinfile);
foreach (get_html_translation_table() as $character => $entity) {
    if ($entity != '&amp;' && $entity != '&quot;' && $entity != '&gt;' && $entity != '&lt;') {
        $source = str_replace($entity, ' ', $source);
    }
}
$xml = Pagemill_SimpleXmlElement::LoadString($source);
$sockets = $xml->xpath('//pm:socket');
// add sockets to template
foreach ($sockets as $socket) {
    $name = "{$socket['for']}";
    $socket = array('socket' => $name);
    if (isset($plugins[$name])) {
        $socket['plugins'] = $plugins[$name];
    }
    $pm->addLoop('sockets', $socket);
}
Пример #14
0
 private static function _InsertSelector($element, $skin)
 {
     static $ignore = array('if', 'loop', 'insert', 'codeblock');
     $selector = '';
     $current = $element;
     while ($current) {
         if ($current->getName() == 'body') {
             break;
         }
         if (!in_array($current->getName(), $ignore)) {
             $class = trim("{$current['class']}");
             $id = trim("{$current['id']}");
             $part = $current->getName();
             if ($id) {
                 $part .= '#' . $id;
             }
             if ($class) {
                 $class = preg_replace('/ +/', '.', $class);
                 $part .= '.' . $class;
             }
             $selector = $part . ' ' . $selector;
         }
         $stack = $current->xpath('parent::*');
         if (count($stack)) {
             $current = array_pop($stack);
         } else {
             $current = null;
         }
     }
     $skinXml = Pagemill_SimpleXmlElement::LoadFile(TYPEF_DIR . '/skins/' . $skin . '/skin.html');
     $xpath = $skinXml->xpath('//pm:import[@name=\'body\']');
     if (count($xpath)) {
         $current = $xpath[0];
         $stack = $current->xpath('parent::*');
         while (count($stack)) {
             $current = array_pop($stack);
             if ($current->getName() == 'body' || $current->getName == 'html') {
                 break;
             }
             if (!in_array($current->getName(), $ignore)) {
                 $id = '';
                 $class = '';
                 if ($current['id']) {
                     $id = '#' . $current['id'];
                 }
                 if ($current['class']) {
                     $class = '.' . preg_replace('/ +/', '.', $class);
                 }
                 //if ($id || $class) {
                 $selector = $current->getName() . $id . $class . ' ' . $selector;
                 //}
             }
             $stack = $current->xpath('parent::*');
         }
     }
     // Selectors should never contain Pagemill expressions
     if (strpos($selector, '@{') !== false) {
         $selector = '';
     }
     return trim($selector);
 }