1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-02 20:57:26 +02:00

Meta-data clean-up and enhancements.

This commit is contained in:
CaMer0n
2012-05-11 03:52:57 +00:00
parent c244d683f8
commit 6ca55ce728
5 changed files with 204 additions and 11 deletions

View File

@@ -29,13 +29,13 @@ class e_bbcode
var $bbList; // Caches the file contents for each bbcode processed var $bbList; // Caches the file contents for each bbcode processed
var $bbLocation; // Location for each file - 'core' or a plugin name var $bbLocation; // Location for each file - 'core' or a plugin name
var $preProcess = FALSE; // Set when processing bbcodes prior to saving var $preProcess = FALSE; // Set when processing bbcodes prior to saving
var $core_bb = array();
function __construct() function __construct()
{ {
$pref = e107::getPref(); $pref = e107::getPref();
$core_bb = array( $this->core_bb = array(
'blockquote', 'img', 'i', 'u', 'center', 'blockquote', 'img', 'i', 'u', 'center',
'_br', 'color', 'size', 'code', '_br', 'color', 'size', 'code',
'html', 'flash', 'link', 'email', 'html', 'flash', 'link', 'email',
@@ -46,7 +46,7 @@ class e_bbcode
'p', 'h', 'nobr', 'block', 'p', 'h', 'nobr', 'block',
); );
foreach($core_bb as $c) foreach($this->core_bb as $c)
{ {
$this->bbLocation[$c] = 'core'; $this->bbLocation[$c] = 'core';
} }
@@ -377,6 +377,48 @@ class e_bbcode
} }
return $bbcode_output.$bbcode_return; return $bbcode_output.$bbcode_return;
} }
/** Grab a list of bbcode content . ie. all [img]xxxx[/img] within a block of text.
* @var string $type - bbcode eg. 'img' or 'youtube'
* @var string $text - text to be processed for bbcode content
* @var string $path - optional path to prepend to output if http or {e_xxxx} is not found.
* @return array
*/
function getContent($type,$text,$path='')
{
if(!in_array($type,$this->core_bb))
{
return;
}
preg_match_all("/\[".$type."(?:[^\]]*)?]([^\[]*)(?:\[\/".$type."])/im",$text,$mtch);
$ret = array();
if(is_array($mtch[1]))
{
$tp = e107::getParser();
foreach($mtch[1] as $i)
{
if(substr($i,0,4)=='http')
{
$ret[] = $i;
}
elseif(substr($i,0,3)=="{e_")
{
$ret[] = $tp->replaceConstants($i,'full');
}
else
{
$ret[] = $path.$i;
}
}
}
return $ret;
}
} }

View File

@@ -155,6 +155,7 @@ class e107
'e_admin_request' => '{e_HANDLER}admin_ui.php', 'e_admin_request' => '{e_HANDLER}admin_ui.php',
'e_admin_response' => '{e_HANDLER}admin_ui.php', 'e_admin_response' => '{e_HANDLER}admin_ui.php',
'e_admin_ui' => '{e_HANDLER}admin_ui.php', 'e_admin_ui' => '{e_HANDLER}admin_ui.php',
'e_bbcode' => '{e_HANDLER}bbcode_handler.php',
'e_file' => '{e_HANDLER}file_class.php', 'e_file' => '{e_HANDLER}file_class.php',
'e_form' => '{e_HANDLER}form_handler.php', 'e_form' => '{e_HANDLER}form_handler.php',
'e_jshelper' => '{e_HANDLER}js_helper.php', 'e_jshelper' => '{e_HANDLER}js_helper.php',
@@ -967,7 +968,7 @@ class e107
} }
/** /**
* Retrieve event singleton object * Retrieve cache singleton object
* *
* @return ecache * @return ecache
*/ */
@@ -976,6 +977,16 @@ class e107
return self::getSingleton('ecache', true); return self::getSingleton('ecache', true);
} }
/**
* Retrieve bbcode singleton object
*
* @return e_bbcode
*/
public static function getBB()
{
return self::getSingleton('e_bbcode', true);
}
/** /**
* Retrieve user-session singleton object * Retrieve user-session singleton object
* *

View File

@@ -99,6 +99,13 @@ class e_jsmanager
*/ */
protected $_e_css_src = array(); protected $_e_css_src = array();
/**
* Meta
*
* @var array
*/
protected $_e_meta = array();
/** /**
* Runtime location * Runtime location
* *
@@ -282,6 +289,19 @@ class e_jsmanager
return $this; return $this;
} }
/**
* Add Meta code to site header
*
* @param string $name
* @param string $content
* @return e_jsmanager
*/
public function coreMeta($name, $content = '')
{
$this->addJs('core_meta', $name, $content);
return $this;
}
/** /**
* Add Core JS library file(s) for inclusion from e_jslib routine * Add Core JS library file(s) for inclusion from e_jslib routine
* *
@@ -543,7 +563,7 @@ class e_jsmanager
return $this; return $this;
} }
if($type == 'core' && substr($file_path,0,4)=='http' ) // Core using CDN. if($type == 'core' && !is_array($file_path) && substr($file_path,0,4)=='http' ) // Core using CDN.
{ {
$type = 'header'; $type = 'header';
$runtime_location = 1; $runtime_location = 1;
@@ -619,6 +639,13 @@ class e_jsmanager
break; break;
break; break;
case 'core_meta':
$this->_e_meta['core'][] = $file_path."|".$runtime_location;
$registry = &$this->_e_meta['core'];
return $this;
break;
break;
case 'header': case 'header':
$file_path = $tp->createConstants($file_path, 'mix'); $file_path = $tp->createConstants($file_path, 'mix');
$zone = intval($runtime_location); $zone = intval($runtime_location);
@@ -753,6 +780,11 @@ class e_jsmanager
$this->_e_css_src = array(); $this->_e_css_src = array();
break; break;
case 'core_meta':
$this->renderMeta($this->_e_meta, 'Meta', 'core');
$this->_e_meta['core'] = array();
break;
case 'footer': case 'footer':
if(true === $zone) if(true === $zone)
{ {
@@ -929,6 +961,46 @@ class e_jsmanager
} }
} }
/**
* Render Meta source array
*
* @param array $js_content_array
* @param string $label added as comment if non-empty
* @return void
*/
function renderMeta($content_array, $label = '',$type = 'core')
{
if(empty($content_array))
{
return '';
}
$content_array[$type] = array_unique($content_array[$type]); //TODO quick fix, we need better control!
echo "\n";
if($label)
{
echo "<!-- [JSManager] ".$label." -->\n";
}
foreach($content_array[$type] as $met)
{
list($name,$content) = explode("|",$met);
echo "\n";
echo '<meta name="'.$name.'" content="'.$content.'" />';
}
echo "\n\n";
}
/** /**
* Returns true if currently running in * Returns true if currently running in
* administration area. * administration area.

View File

@@ -103,6 +103,10 @@ echo "<head>
<meta http-equiv='content-type' content='text/html; charset=utf-8' /> <meta http-equiv='content-type' content='text/html; charset=utf-8' />
<meta http-equiv='content-style-type' content='text/css' /> <meta http-equiv='content-style-type' content='text/css' />
"; ";
echo (defined("CORE_LC")) ? "<meta http-equiv='content-language' content='".CORE_LC."' />\n" : ""; echo (defined("CORE_LC")) ? "<meta http-equiv='content-language' content='".CORE_LC."' />\n" : "";
echo "<title>".(defined('e_PAGETITLE') ? e_PAGETITLE.' - ' : (defined('PAGE_NAME') ? PAGE_NAME.' - ' : "")).SITENAME."</title>\n\n"; echo "<title>".(defined('e_PAGETITLE') ? e_PAGETITLE.' - ' : (defined('PAGE_NAME') ? PAGE_NAME.' - ' : "")).SITENAME."</title>\n\n";
@@ -123,6 +127,8 @@ else
$e_js = e107::getJs(); $e_js = e107::getJs();
$e_pref = e107::getConfig('core'); $e_pref = e107::getConfig('core');
// Register Core CSS first, TODO - convert $no_core_css to constant, awaiting for path changes // Register Core CSS first, TODO - convert $no_core_css to constant, awaiting for path changes
// NOTE: PREVIEWTHEME check commented - It shouldn't break anything as it's overridden by theme CSS now // NOTE: PREVIEWTHEME check commented - It shouldn't break anything as it's overridden by theme CSS now
if (/*!defined("PREVIEWTHEME") && */!isset($no_core_css) || !$no_core_css) if (/*!defined("PREVIEWTHEME") && */!isset($no_core_css) || !$no_core_css)
@@ -150,6 +156,8 @@ unset($e_headers);
$e_js = e107::getJs(); $e_js = e107::getJs();
$e_pref = e107::getConfig('core'); $e_pref = e107::getConfig('core');
e107::getJS()->renderJs('core_meta',false);
// --- Load plugin Meta files - now possible to add to all zones! -------- // --- Load plugin Meta files - now possible to add to all zones! --------
$e_meta_content = ''; $e_meta_content = '';
if (is_array($pref['e_meta_list'])) if (is_array($pref['e_meta_list']))
@@ -168,6 +176,8 @@ if (is_array($pref['e_meta_list']))
ob_end_clean(); ob_end_clean();
} }
// Register Plugin specific CSS // Register Plugin specific CSS
// DEPRECATED, use $e_js->pluginCSS('myplug', 'style/myplug.css'[, $media = 'all|screen|...']); // DEPRECATED, use $e_js->pluginCSS('myplug', 'style/myplug.css'[, $media = 'all|screen|...']);
if (isset($eplug_css) && $eplug_css) if (isset($eplug_css) && $eplug_css)
@@ -384,6 +394,8 @@ e107::getJs()->renderJs('header_inline', 5);
// --- Send plugin Meta -------- // --- Send plugin Meta --------
echo $e_meta_content; // e_meta already loaded echo $e_meta_content; // e_meta already loaded
// //
// G: Send Theme Headers // G: Send Theme Headers
// //

View File

@@ -890,25 +890,78 @@ function render_newscats(){ // -- CNN Style Categories. ----
function setNewsFrontMeta($news, $type='news') function setNewsFrontMeta($news, $type='news')
{ {
$tp = e107::getParser();
if($type == 'news') if($type == 'news')
{ {
if($news['news_title'] && !defined('e_PAGETITLE')) if($news['news_title'] && !defined('e_PAGETITLE'))
{ {
define('e_PAGETITLE', $news['news_title']); define('e_PAGETITLE', $news['news_title']);
} e107::getJS()->coreMeta('og:title',$news['news_title']);
e107::getJS()->coreMeta('og:type','article');
if($news['news_meta_keywords'] && !defined('META_KEYWORDS'))
{
define('META_KEYWORDS', $news['news_meta_keywords']);
} }
if($news['news_meta_description'] && !defined('META_DESCRIPTION')) if($news['news_meta_description'] && !defined('META_DESCRIPTION'))
{ {
define('META_DESCRIPTION', $news['news_meta_description']); e107::getJS()->coreMeta('description',$news['news_meta_description']);
e107::getJS()->coreMeta('og:description',$news['news_meta_description']);
//define('META_DESCRIPTION', $news['news_meta_description']); // deprecated
} }
elseif($news['news_summary']) // BC compatibility
{
e107::getJS()->coreMeta('og:description',$news['news_summary']);
}
// grab all images in news-body and add to meta.
$images = e107::getBB()->getContent('img',$news['news_body'],SITEURL.e_IMAGE."newspost_images/");
foreach($images as $im)
{
e107::getJS()->coreMeta('og:image',$im);
}
// grab all youtube videos in news-body and add thumbnails to meta.
$youtube = e107::getBB()->getContent('youtube',$news['news_body']);
foreach($youtube as $yt)
{
list($img,$tmp) = explode("?",$yt);
e107::getJS()->coreMeta('og:image',"http://img.youtube.com/vi/".$img."/0.jpg");
}
// include news-thumbnail/image in meta.
if($news['news_thumbnail'])
{
$iurl = (substr($news['news_thumbnail'],0,3)=="{e_") ? $tp->replaceConstants($news['news_thumbnail'],'full') : SITEURL.e_IMAGE."newspost_images/".$news['news_thumbnail'];
e107::getJS()->coreMeta('og:image',$iurl);
}
$url = e107::getUrl()->create('news/view/item', $news,'full=1');
e107::getJS()->coreMeta('og:url',$url);
e107::getJS()->coreMeta('article:section',$news['category_name']);
if($news['news_meta_keywords'] && !defined('META_KEYWORDS'))
{
e107::getJS()->coreMeta('keywords',$news['news_meta_keywords']);
$tmp = explode(",",$news['news_meta_keywords']);
foreach($tmp as $t)
{
e107::getJS()->coreMeta('article:tag',$t);
}
// define('META_KEYWORDS', $news['news_meta_keywords']); // deprecated
}
/* Facebook reference.
* http://developers.facebook.com/docs/opengraph/objects/builtin/
*/
return; return;
} }
if($news['category_name'] && !defined('e_PAGETITLE')) if($news['category_name'] && !defined('e_PAGETITLE'))
{ {
define('e_PAGETITLE', $news['category_name']); define('e_PAGETITLE', $news['category_name']);
@@ -923,6 +976,9 @@ function setNewsFrontMeta($news, $type='news')
{ {
define('META_DESCRIPTION', $news['category_meta_description']); define('META_DESCRIPTION', $news['category_meta_description']);
} }
} }