Exemplo n.º 1
0
Arquivo: Skin.php Projeto: ssrsfs/blg
 public static function BodySelectorFor($skin = null)
 {
     if (is_null($skin)) {
         $skin = self::Current();
     }
     if (file_exists(TYPEF_DIR . "/skins/{$skin}/skin.html")) {
         $skinfile = TYPEF_DIR . "/skins/{$skin}/skin.html";
     } else {
         $skinfile = TYPEF_DIR . "/skins/default/skin.html";
     }
     $source = file_get_contents($skinfile);
     $xml = Pagemill_SimpleXmlElement::LoadString($source);
     $body = $xml->xpath('//pm:import[@name="pm:body"]');
     $parent = $body[0]->xpath('parent::*');
     $selector = '';
     while (isset($parent[0])) {
         if ($parent[0]->getName() == 'body') {
             break;
         }
         $ns = $parent[0]->getNamespaces();
         if (key($ns) == '') {
             $here = $parent[0]->getName();
             if ($parent[0]['id']) {
                 $here .= '#' . $parent[0]['id'];
             }
             if ($parent[0]['class']) {
                 $here .= '.' . str_replace(' ', '.', $parent[0]['class']);
             }
             $selector = $here . ' ' . $selector;
         }
         $parent = $parent[0]->xpath('parent::*');
     }
     $selector = trim($selector);
     return $selector;
 }
Exemplo n.º 2
0
Arquivo: unit.php Projeto: ssrsfs/blg
 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");
 }
Exemplo n.º 3
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();
             }
         }
     }));
 }
Exemplo n.º 4
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);
     }
 }
Exemplo n.º 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();
}
Exemplo n.º 6
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;
 }
Exemplo n.º 7
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);
        }
    }
}
Exemplo n.º 8
0
Arquivo: unit.php Projeto: ssrsfs/blg
 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");
 }
Exemplo n.º 9
0
Arquivo: index.php Projeto: ssrsfs/blg
$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);
}
Exemplo n.º 10
0
 public static function GroupsFrom($template, $groupMap = null, $skin = 'default')
 {
     $groups = array();
     if (file_exists($template) && is_file($template)) {
         $source = file_get_contents($template);
         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);
         if ($groupMap) {
             if (is_array($groupMap)) {
                 $xpath = '//*[name() != \'pm:group\']';
                 foreach ($groupMap as $g) {
                     $xpath .= '/pm:group[@name=\'' . $g . '\']';
                 }
                 $elements = $xml->xpath($xpath);
             } else {
                 $elements = $xml->xpath('//*[name() != \'pm:group\']/pm:group[name=\'' . $groupMap . '\']');
             }
         } else {
             $elements = $xml->xpath('//*[name() != \'pm:group\']/pm:group | //*[name() != \'pm:group\']/pm:include');
         }
         foreach ($elements as $e) {
             if ($e->getName() == 'group') {
                 $groups[] = self::RecurseGroups($e, $xml, $skin);
             } else {
                 $included = Insertable::GroupsFrom(TYPEF_DIR . '/source/templates/' . $e['template'], $groupMap, $skin);
                 if (is_array($included)) {
                     $groups = array_merge($groups, $included);
                 }
             }
         }
     } else {
         trigger_error("File '{$template}' does not exist");
     }
     return $groups;
 }