Permalink
Browse files

Add authors to news articles

Add author Open Graph and Twitter Card html header tags to news articles
Add ability to add template html tags (in <html>)
Add ability to add template html header tags (inside <head>)
  • Loading branch information...
1 parent f7ce884 commit d5b478f2ccdda78746adce9d5c749e8dd519aa51 @haraldpdl committed Dec 2, 2013
@@ -2,13 +2,14 @@
/**
* osCommerce Website
*
- * @copyright Copyright (c) 2012 osCommerce; http://www.oscommerce.com
+ * @copyright Copyright (c) 2013 osCommerce; http://www.oscommerce.com
* @license BSD License; http://www.oscommerce.com/bsdlicense.txt
*/
namespace osCommerce\OM\Core\Site\Website\Application\Us\Action;
use osCommerce\OM\Core\ApplicationAbstract;
+ use osCommerce\OM\Core\HTML;
use osCommerce\OM\Core\OSCOM;
use osCommerce\OM\Core\Registry;
use osCommerce\OM\Core\Site\Website\News as NewsClass;
@@ -18,10 +19,62 @@ public static function execute(ApplicationAbstract $application) {
$OSCOM_Template = Registry::get('Template');
if ( !empty($_GET['News']) && is_numeric($_GET['News']) && NewsClass::exists($_GET['News']) ) {
+ $news_entry = NewsClass::get($_GET['News']);
+
$application->setPageContent('news_entry.html');
- $application->setPageTitle(OSCOM::getDef('news_entry_html_page_title', array(':news_title' => NewsClass::get($_GET['News'], 'title'))));
+ $application->setPageTitle(OSCOM::getDef('news_entry_html_page_title', array(':news_title' => $news_entry['title'])));
+
+ $OSCOM_Template->setValue('news_entry', $news_entry);
+
+ $OSCOM_Template->addHtmlHeaderTag('<link rel="canonical" href="' . HTML::outputProtected(OSCOM::getLink(null, null, 'News=' . $news_entry['id'])) . '" />');
+
+ $body_raw = wordwrap(str_replace("\n", '', strip_tags($news_entry['body'])), 200, "\n");
+ $short_body = substr($body_raw, 0, strpos($body_raw, "\n")) . '...';
+
+ $OSCOM_Template->addHtmlHeaderTag('<meta name="description" content="' . HTML::outputProtected($short_body) . '" />');
+
+/* Twitter Card - Summary */
+
+ $OSCOM_Template->addHtmlHeaderTag('<meta name="twitter:card" content="summary" />');
+ $OSCOM_Template->addHtmlHeaderTag('<meta name="twitter:site" content="@osCommerce" />');
+
+ if ( !empty($news_entry['author_twitter_id']) ) {
+ $OSCOM_Template->addHtmlHeaderTag('<meta name="twitter:creator" content="@' . HTML::outputProtected($news_entry['author_twitter_id']) . '" />');
+ }
+
+// The following are taken care of by Open Graph
+// $OSCOM_Template->addHtmlHeaderTag('<meta name="twitter:title" content="' . HTML::outputProtected($news_entry['title']) . '" />');
+// $OSCOM_Template->addHtmlHeaderTag('<meta name="twitter:description" content="' . HTML::outputProtected($short_body) . '" />');
+
+// if ( !empty($news_entry['image']) ) {
+// $OSCOM_Template->addHtmlHeaderTag('<meta name="twitter:image:src" content="' . HTML::outputProtected($OSCOM_Template->getBaseUrl() . OSCOM::getPublicSiteLink('images/news/' . $news_entry['image'])) . '" />');
+// }
+
+/* Open Graph */
+
+ $OSCOM_Template->addHtmlTag('prefix', 'og: http://ogp.me/ns#');
+ $OSCOM_Template->addHtmlTag('prefix', 'article: http://ogp.me/ns/article#');
+ $OSCOM_Template->addHtmlTag('prefix', 'profile: http://ogp.me/ns/profile#');
+
+ $OSCOM_Template->addHtmlHeaderTag('<meta property="og:type" content="article" />');
+ $OSCOM_Template->addHtmlHeaderTag('<meta property="og:site_name" content="osCommerce" />');
+ $OSCOM_Template->addHtmlHeaderTag('<meta property="og:title" content="' . HTML::outputProtected($news_entry['title']) . '" />');
+ $OSCOM_Template->addHtmlHeaderTag('<meta property="og:description" content="' . HTML::outputProtected($short_body) . '" />');
+ $OSCOM_Template->addHtmlHeaderTag('<meta property="og:url" content="' . HTML::outputProtected(OSCOM::getLink(null, null, 'News=' . $news_entry['id'])) . '" />');
+
+ if ( !empty($news_entry['image']) ) {
+ $OSCOM_Template->addHtmlHeaderTag('<meta property="og:image" content="' . HTML::outputProtected($OSCOM_Template->getBaseUrl() . OSCOM::getPublicSiteLink('images/news/' . $news_entry['image'])) . '" />');
+ }
+
+ $OSCOM_Template->addHtmlHeaderTag('<meta property="article:author" content="http://forums.oscommerce.com/index.php?showuser=' . HTML::outputProtected($news_entry['author_id']) . '" />');
+
+ $author_name_array = explode(' ', $news_entry['author_name'], 2);
+
+ $OSCOM_Template->addHtmlHeaderTag('<meta property="profile:first_name" content="' . HTML::outputProtected($author_name_array[0]) . '" />');
- $OSCOM_Template->setValue('news_entry', NewsClass::get($_GET['News']));
+ if ( isset($author_name_array[1]) && !empty($author_name_array[1]) ) {
+ $OSCOM_Template->addHtmlHeaderTag('<meta property="profile:last_name" content="' . HTML::outputProtected($author_name_array[1]) . '" />');
+ }
} else {
$application->setPageContent('news.html');
$application->setPageTitle(OSCOM::getDef('news_html_page_title'));
@@ -7,7 +7,7 @@
<div id="maincontent">
<h1>News</h1>
- <h2>{value}news_entry title{value}<br /><small>{value}news_entry date_added_formatted{value}</small></h2>
+ <h2>{value}news_entry title{value}<br /><small>{value}news_entry date_added_formatted{value} {lang}news_entry_author_by{lang} <a id="newsAuthorLink" title="{lang}news_entry_author_profiles_title{lang}">{value}news_entry author_name{value}</a></small></h2>
{ifvalue news_entry image}
<img src="{publiclink}images/news/{raw}news_entry image{raw}{publiclink}" class="thumbnail" style="float: right; margin-left: 10px; margin-bottom: 10px;" />
@@ -21,3 +21,34 @@
{widget}us_sidebar_nav{widget}
</div>
+
+<script>
+$(function() {
+ $('#newsAuthorLink').popover({
+ html: true,
+ content: function() {
+ return $('#newsAuthorContent').html();
+ }
+ });
+});
+</script>
+
+<div id="newsAuthorContent" style="display: none">
+ <a href="http://forums.oscommerce.com/index.php?showuser={value}news_entry author_id{value}"><img src="{publiclink}images/social/oscommerce.png{publiclink}" width="32" height="32" alt="osCommerce" title="osCommerce" /></a>
+
+ {ifvalue news_entry author_google_plus_id}
+ <a href="https://plus.google.com/{value}news_entry author_google_plus_id{value}?rel=author" target="_blank"><img src="{publiclink}images/social/googleplus.png{publiclink}" width="32" height="32" alt="Google+" title="Google+" /></a>
+ {ifvalue}
+
+ {ifvalue news_entry author_twitter_id}
+ <a href="https://twitter.com/{value}news_entry author_twitter_id{value}" target="_blank"><img src="{publiclink}images/social/twitter.png{publiclink}" width="32" height="32" alt="Twitter" title="Twitter" /></a>
+ {ifvalue}
+
+ {ifvalue news_entry author_facebook_id}
+ <a href="https://www.facebook.com/{value}news_entry author_facebook_id{value}" target="_blank"><img src="{publiclink}images/social/facebook.png{publiclink}" width="32" height="32" alt="Facebook" title="Facebook" /></a>
+ {ifvalue}
+
+ {ifvalue news_entry author_github_id}
+ <a href="https://github.com/{value}news_entry author_github_id{value}" target="_blank"><img src="{publiclink}images/social/github.png{publiclink}" width="32" height="32" alt="GitHub" title="GitHub" /></a>
+ {ifvalue}
+</div>
@@ -2,13 +2,14 @@
/**
* osCommerce Website
*
- * @copyright Copyright (c) 2012 osCommerce; http://www.oscommerce.com
+ * @copyright Copyright (c) 2013 osCommerce; http://www.oscommerce.com
* @license BSD License; http://www.oscommerce.com/bsdlicense.txt
*/
namespace osCommerce\OM\Core\Site\Website;
use osCommerce\OM\Core\Cache;
+ use osCommerce\OM\Core\HTML;
use osCommerce\OM\Core\OSCOM;
use osCommerce\OM\Core\PDO;
use osCommerce\OM\Core\Registry;
@@ -23,21 +24,24 @@ public static function initialize() {
Registry::set('Language', new Language());
Registry::set('Template', new Template());
- $application = 'osCommerce\\OM\\Core\\Site\\Website\\Application\\' . OSCOM::getSiteApplication() . '\\Controller';
- Registry::set('Application', new $application());
-
$OSCOM_Template = Registry::get('Template');
+ $OSCOM_Language = Registry::get('Language');
- $OSCOM_Template->setApplication(Registry::get('Application'));
+ $OSCOM_Template->addHtmlTag('dir', $OSCOM_Language->getTextDirection());
+ $OSCOM_Template->addHtmlTag('lang', OSCOM::getDef('html_lang_code')); // HPDL A better solution is to define the ISO 639-1 value at the language level
- $OSCOM_Language = Registry::get('Language');
+ $OSCOM_Template->addHtmlHeaderTag('<meta name="generator" content="osCommerce Website v' . HTML::outputProtected(OSCOM::getVersion(OSCOM::getSite())) . '" />');
+
+ $application = 'osCommerce\\OM\\Core\\Site\\Website\\Application\\' . OSCOM::getSiteApplication() . '\\Controller';
+ Registry::set('Application', new $application());
+ $OSCOM_Template->setApplication(Registry::get('Application'));
- $OSCOM_Template->setValue('html_text_direction', $OSCOM_Language->getTextDirection());
- $OSCOM_Template->setValue('html_lang', OSCOM::getDef('html_lang_code')); // HPDL A better solution is to define the ISO 639-1 value at the language level
+ $OSCOM_Template->setValue('html_tags', $OSCOM_Template->getHtmlTags());
$OSCOM_Template->setValue('html_character_set', $OSCOM_Language->getCharacterSet());
$OSCOM_Template->setValue('html_page_title', $OSCOM_Template->getPageTitle());
$OSCOM_Template->setValue('html_page_contents_file', $OSCOM_Template->getPageContentsFile());
$OSCOM_Template->setValue('html_base_href', $OSCOM_Template->getBaseUrl());
+ $OSCOM_Template->setValue('html_header_tags', $OSCOM_Template->getHtmlHeaderTags());
$OSCOM_Template->setValue('current_site_application', OSCOM::getSiteApplication());
$OSCOM_Template->setValue('current_site_application_action', Registry::get('Application')->getCurrentAction());
$OSCOM_Template->setValue('site_version', OSCOM::getVersion(OSCOM::getSite()));
@@ -2,7 +2,7 @@
/**
* osCommerce Website
*
- * @copyright Copyright (c) 2012 osCommerce; http://www.oscommerce.com
+ * @copyright Copyright (c) 2013 osCommerce; http://www.oscommerce.com
* @license BSD License; http://www.oscommerce.com/bsdlicense.txt
*/
@@ -14,7 +14,7 @@ class GetNews {
public static function execute($data) {
$OSCOM_PDO = Registry::get('PDO');
- $Qnews = $OSCOM_PDO->prepare('select id, title, body, date_added, date_format(date_added, "%D %M %Y") as date_added_formatted, image from :table_website_news where id = :id and status = 1');
+ $Qnews = $OSCOM_PDO->prepare('select n.id, n.title, n.body, n.date_added, date_format(n.date_added, "%D %M %Y") as date_added_formatted, n.image, u.id as author_id, u.display_name as author_name, u.twitter_id as author_twitter_id, u.google_plus_id as author_google_plus_id, u.facebook_id as author_facebook_id, u.github_id as author_github_id from :table_website_news n left join :table_website_user_profiles u on (n.author_id = u.id) where n.id = :id and n.status = 1');
$Qnews->bindInt(':id', $data['id']);
$Qnews->setCache('website-news-' . $data['id']);
$Qnews->execute();
@@ -28,10 +28,12 @@ CREATE TABLE osc_website_news (
date_added datetime NOT NULL,
status int NOT NULL,
image varchar(255),
+ author_id int unsigned,
PRIMARY KEY (id),
KEY idx_ws_news_title (title),
KEY idx_ws_news_date_added (date_added),
- KEY idx_ws_news_status (status)
+ KEY idx_ws_news_status (status),
+ KEY idx_ws_news_author_id (author_id)
) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci;
DROP TABLE IF EXISTS osc_website_partner_category;
@@ -173,3 +175,14 @@ CREATE TABLE osc_website_user_server_info (
PRIMARY KEY (id),
KEY idx_ws_user_server_info_ip (submit_ip)
) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci;
+
+DROP TABLE IF EXISTS osc_website_user_profiles;
+CREATE TABLE osc_website_user_profiles (
+ id int unsigned NOT NULL,
+ display_name varchar(255) NOT NULL,
+ twitter_id varchar(255),
+ google_plus_id varchar(255),
+ facebook_id varchar(255),
+ github_id varchar(255),
+ PRIMARY KEY (id)
+) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci;
@@ -2,13 +2,112 @@
/**
* osCommerce Website
*
- * @copyright Copyright (c) 2012 osCommerce; http://www.oscommerce.com
+ * @copyright Copyright (c) 2013 osCommerce; http://www.oscommerce.com
* @license BSD License; http://www.oscommerce.com/bsdlicense.txt
*/
namespace osCommerce\OM\Core\Site\Website;
class Template extends \osCommerce\OM\Core\Site\Admin\Template {
+
+/**
+ * Holds the template name value
+ *
+ * @var string
+ * @access protected
+ */
+
protected $_default_template = 'Amy';
+
+/**
+ * Holds the html tags of the page
+ *
+ * @var array
+ * @access protected
+ */
+
+ protected $_html_tags = array();
+
+/**
+ * Holds the html header tags of the page
+ *
+ * @var array
+ * @access protected
+ */
+
+ protected $_html_header_tags = array();
+
+/**
+ * Returns the html tags of the page
+ *
+ * @access public
+ * @return string
+ */
+
+ public function getHtmlTags() {
+ $tag_string = '';
+
+ foreach ( $this->_html_tags as $key => $values) {
+ $tag_string .= $key . '="' . implode(' ', $values) . '" ';
+ }
+
+ return trim($tag_string);
+ }
+
+/**
+ * Checks if html tags exists for the page
+ *
+ * @access public
+ * @return boolean
+ */
+
+ public function hasHtmlTags() {
+ return !empty($this->_html_tags);
+ }
+
+/**
+ * Adds a html tag to the page
+ *
+ * @access public
+ * @param string $key The key of the html tag
+ * @param string $value The value of the html tag
+ */
+
+ public function addHtmlTag($key, $value) {
+ $this->_html_tags[$key][] = $value;
+ }
+
+/**
+ * Returns the html header tags of the page
+ *
+ * @access public
+ * @return string
+ */
+
+ public function getHtmlHeaderTags() {
+ return implode("\n", $this->_html_header_tags);
+ }
+
+/**
+ * Checks if html header tags exists for the page
+ *
+ * @access public
+ * @return boolean
+ */
+
+ public function hasHtmlHeaderTags() {
+ return !empty($this->_html_header_tags);
+ }
+
+/**
+ * Adds a html header tag to the page
+ *
+ * @access public
+ * @param string $tag The value of the header tag
+ */
+
+ public function addHtmlHeaderTag($tag) {
+ $this->_html_header_tags[] = $tag;
+ }
}
?>
@@ -1,17 +1,17 @@
<!doctype html>
-<html dir="{value}html_text_direction{value}" lang="{value}html_lang{value}">
+<html {ifvalue html_tags}{raw}html_tags{raw}{ifvalue}>
<head>
<!--
- ,‒‒‒‒‒‒‒.‒‒‒‒‒‒‒‒,,‒‒‒‒‒‒‒‒‒. ,‒‒‒‒‒‒,‒‒‒‒‒.‒‒‒‒‒‒‒‒‒.‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒.‒‒‒‒‒‒‒‒‒.‒‒‒‒‒‒‒‒‒,
- _\__, | ___/_| , ⸣|_\__, \____ ' _______ ' ____ ,_________, | , | ,___/
- | | ,‒‒‒‒‒. | |‒‒‒‒'‒, | | \ / | \ / | ,_/‒‒+‒, _ ‒+‒, |‒‒‒‒'‒, ,_/‒‒‒‒,
+ ________ ________ _________ ______________ _________ ________________________ _________ _________
+ _\___ | ___/_| _ | _ \____ ' _______ ' ____ ___________ | _ | ____/
+ | | _|_____ | |____|_ | | \ / | \ / | __/__|_ _ _|_ |____|_ __/____
| | \_ | | | _/ | | V | V | | _/ | _/ | _/ | _/
| | | | | | | | | | | | | | | | | | | | |
| ' | ' | ' | ' | | |_ | |_ ' | | | ' | ' |
- `‒‒‒‒‒‒‒‒‒|____|‒‒‒‒'‒‒‒‒‒‒‒‒‒'‒‒‒‒‒‒‒‒‒'‒‒‒‒|___, /‒‒‒|___, /‒‒‒‒‒‒‒‒'‒‒‒‒|____|‒‒‒‒‒‒‒‒‒'‒‒‒‒‒‒ᏲᎮ‒'
+ |_________|_________|_________|_________|____|____ /___|____ /________|____|____|_________|______hp_|
|/ |/
C R E A T I N G O N L I N E S T O R E S W O R L D W I D E S I N C E 2 0 0 0 !
//-->
@@ -24,8 +24,6 @@
<link rel="icon" type="image/png" href="{publiclink}images/favicon.ico{publiclink}" />
- <meta name="generator" content="osCommerce Website v{value}site_version{value}" />
-
<script type="text/javascript" src="public/external/jquery/jquery-1.7.1.min.js"></script>
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
@@ -37,6 +35,11 @@
<link rel="stylesheet" type="text/css" href="{publiclink}templates/default/stylesheets/general.css{publiclink}" />
<link rel="alternate" type="application/rss+xml" href="http://www.oscommerce.com/oscommerce.rdf" title="osCommerce News" />
+
+{ifvalue html_header_tags}
+ {raw}html_header_tags{raw}
+{ifvalue}
+
</head>
<body>
@@ -49,6 +49,9 @@
news_entry_html_page_title = :news_title | osCommerce
+news_entry_author_by = by
+news_entry_author_profiles_title = Author Profiles
+
link_back_to_listing = Back to listing
marketing_html_page_title = Marketing Material | osCommerce
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d5b478f

Please sign in to comment.