public function output(\Pagemill_Data $data, \Pagemill_Stream $stream) { $this->_hasTitle = false; $this->_hasMetaDescription = false; $this->_hasMetaKeywords = false; $this->_recurseThroughChildren($this); if (!$this->_hasTitle) { new Typeframe_Tag_Seo_Title('title', array(), $this); } if (!$this->_hasMetaDescription) { new Typeframe_Tag_Seo_Meta('meta', array('name' => 'description'), $this); } if (!$this->_hasMetaKeywords) { new Typeframe_Tag_Seo_Meta('meta', array('name' => 'keywords'), $this); } $urlmeta = Model_UrlMeta::GetUrl(null, false); $tag = null; if ($urlmeta->exists()) { $seo = Model_SeoHead::Get($urlmeta['id']); if ($seo->exists()) { if ($seo['extra']) { $fragment = new Pagemill_Node_Frag($this->doctype()); $fragment->appendRawText($seo['extra']); $this->appendChild($fragment); } } } parent::output($data, $stream); // TODO: Do we need to detach the fragment? }
public function output(\Pagemill_Data $data, \Pagemill_Stream $stream) { if ($this->getAttribute('name') == 'keywords') { $name = 'keywords'; } else { if ($this->getAttribute('name') == 'description') { $name = 'description'; } else { parent::output($data, $stream); return; } } $urlmeta = Model_UrlMeta::GetUrl(null, false); if (!$urlmeta->exists()) { parent::output($data, $stream); return; } $seo = Model_SeoHead::Get($urlmeta['id']); if (!$seo->exists()) { parent::output($data, $stream); return; } if (!$seo['meta' . $name]) { parent::output($data, $stream); return; } $meta = new Pagemill_Tag('meta', $this->attributes, null, $this->doctype()); $meta->setAttribute('content', $seo['meta' . $name]); $meta->output($data, $stream); }
public function output(Pagemill_Data $data, Pagemill_Stream $stream) { if (self::$_loaded) { return ''; } self::$_loaded = true; if (defined('COMMENTS_DISABLED') && COMMENTS_DISABLED) { return ''; } $data = $data->fork(); $urlmeta = Model_UrlMeta::GetUrl(); if (!$urlmeta->exists()) { return ''; } $commeta = Model_Comment_Meta::Get($urlmeta['id']); if (!$commeta->exists()) { $commeta['urlmetaid'] = $urlmeta['id']; $commeta->save(); } else { if ($commeta['closed']) { $pm->setVariable('comments_closed', true); } } $data->set('meta', $commeta); $comments = new Model_Comment(); $comments->where('urlmetaid = ?', $urlmeta['id']); if (defined('COMMENTS_REQUIRE_APPROVAL') && 1 == COMMENTS_REQUIRE_APPROVAL) { $comments->where('approved = 1'); } $comments->order('datecreated ASC'); $data->set('comments', $comments); $data->set('comments_require_captcha', COMMENTS_REQUIRE_CAPTCHA); parent::output($data, $stream); }
protected function output(\Pagemill_Data $data, \Pagemill_Stream $stream) { $urlmeta = Model_UrlMeta::GetUrl(null, false); if (!$urlmeta->exists()) { parent::output($data, $stream); return; } $seo = Model_SeoHead::Get($urlmeta['id']); if (!$seo->exists()) { parent::output($data, $stream); return; } if (!$seo['title']) { parent::output($data, $stream); return; } $title = new Pagemill_Tag_AlwaysExpand('title', $this->attributes(), null, $this->doctype()); $title->appendText($seo['title']); $title->output($data, $stream); }
<?php /* * Return a list of URLs matching a query, separated by line feeds. */ header('Content-Type: text/plain'); if (empty($_REQUEST['q'])) { echo ''; } else { $results = array(); foreach (Typeframe::Registry()->pages() as $app) { if ($app->pageid()) { if (strpos($app->uri(), $_REQUEST['q']) !== false) { $results[] = $app->uri(); } } } $metas = new Model_UrlMeta(); $metas->where('CONCAT(?, page.uri, pathinfo) LIKE ?', TYPEF_WEB_DIR, "%{$_REQUEST['q']}%"); foreach ($metas as $meta) { $results[] = $meta['fullpath']; } sort($results); $results = array_unique($results); echo implode("\n", $results); } exit;
/** * 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; }
$badCaptcha = false; if (defined('COMMENTS_REQUIRE_CAPTCHA') && COMMENTS_REQUIRE_CAPTCHA && !Typeframe::User()->loggedIn()) { if (!isset($_SESSION['captcha']) || empty($_SESSION['captcha']) || !isset($_POST['captcha']) || $_POST['captcha'] != $_SESSION['captcha']) { $badCaptcha = true; } } if ($badCaptcha) { $pm->addLoop('errors', array('message' => 'Captcha code was incorrect.')); $pm->setVariable('comment', $_POST); } else { $comment = Model_Comment::Create(); $comment->setArray($form->input()); $comment['urlmetaid'] = $_POST['urlmetaid']; $comment['userid'] = Typeframe::User()->get('userid'); $comment->save(); // TODO: Redirect to the originating page. $urlmeta = Model_UrlMeta::Get($section['urlmetaid']); Typeframe::Redirect('Comment submitted.', $urlmeta['fullpath']); } } else { //$pm->setVariable('referer', $referer); // add user input (as comment) to template $pm->setVariable('comment', $_POST); // add section to template //$pm->setVariable('sectionid', $sectionid); // add require captcha flag to template $pm->setVariable('errors', $form->errors()); } } else { Typeframe::Redirect('Nothing to do.', TYPEF_WEB_DIR . '/', -1); }
<?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); } } }
<?php if ($_REQUEST['url']) { $parts = parse_url($_REQUEST['url']); $urlmeta = Model_UrlMeta::GetUrl($parts['path']); if (!$urlmeta->exists()) { Typeframe::Redirect('Invalid page specified: ' . $_REQUEST['url'], Typeframe::CurrentPage()->applicationUri(), -1); return; } $head = Model_SeoHead::Get($urlmeta['id']); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $head['title'] = $_POST['title']; $head['metakeywords'] = $_POST['metakeywords']; $head['metadescription'] = $_POST['metadescription']; $head['extra'] = $_POST['extra']; $head->save(); Typeframe::Redirect('Title and meta content updated.', Typeframe::CurrentPage()->applicationUri()); return; } $pm->setVariable('urlmeta_path', $parts['path']); $pm->setVariable('seo', $head); } else { Typeframe::Redirect('No page specified.', Typeframe::CurrentPage()->applicationUri(), -1); }
<?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { $urlmeta = Model_UrlMeta::GetUrl($_REQUEST['url']); $head = Model_SeoHead::Get($urlmeta['id']); $head->delete(); Typeframe::Redirect('SEO content reset.', Typeframe::CurrentPage()->applicationUri()); } else { Typeframe::Redirect('Nothing to do.', Typeframe::CurrentPage()->applicationUri()); }