Permalink
Browse files

Update Pinterest Header Tag Module

  • Loading branch information...
1 parent 0155e6d commit 836e41808a1e6737ff9f286849da41946e9574c5 @haraldpdl haraldpdl committed Aug 4, 2012
@@ -6,12 +6,11 @@
http://www.oscommerce.com
Copyright (c) 2012 osCommerce
- Copyright (c) 2012 Club osCommerce www.clubosc.com
Released under the GNU General Public License
*/
define('MODULE_SOCIAL_BOOKMARKS_PINTEREST_TITLE', 'Pinterest');
define('MODULE_SOCIAL_BOOKMARKS_PINTEREST_DESCRIPTION', 'Share on Pinterest');
-
+ define('MODULE_SOCIAL_BOOKMARKS_PINTEREST_PUBLIC_TITLE', 'Pin It');
?>
@@ -6,7 +6,6 @@
http://www.oscommerce.com
Copyright (c) 2012 osCommerce
- Copyright (c) 2012 Club osCommerce www.clubosc.com
Released under the GNU General Public License
*/
@@ -16,10 +15,12 @@ class sb_pinterest {
var $title;
var $description;
var $sort_order;
+ var $icon;
var $enabled = false;
-
+
function sb_pinterest() {
$this->title = MODULE_SOCIAL_BOOKMARKS_PINTEREST_TITLE;
+ $this->public_title = MODULE_SOCIAL_BOOKMARKS_PINTEREST_PUBLIC_TITLE;
$this->description = MODULE_SOCIAL_BOOKMARKS_PINTEREST_DESCRIPTION;
if ( defined('MODULE_SOCIAL_BOOKMARKS_PINTEREST_STATUS') ) {
@@ -29,45 +30,51 @@ function sb_pinterest() {
}
function getOutput() {
- global $HTTP_GET_VARS;
- global $languages_id;
- global $oscTemplate;
-
- // add the js in the footer
+ global $HTTP_GET_VARS, $oscTemplate;
+
+// add the js in the footer
$oscTemplate->addBlock('<script type="text/javascript" src="//assets.pinterest.com/js/pinit.js"></script>', 'footer_scripts');
- // grab the product name (used for description)
- $product_name = tep_get_products_name($HTTP_GET_VARS['products_id'], $languages_id);
+ $params = array();
+
+// grab the product name (used for description)
+ $params['description'] = tep_get_products_name($HTTP_GET_VARS['products_id']);
- // and image (used for media)
+// and image (used for media)
$image_query = tep_db_query("select products_image from " . TABLE_PRODUCTS . " where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "'");
$image = tep_db_fetch_array($image_query);
- // url
- $params = array('url=' . urlencode(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['products_id'], 'NONSSL', false)));
-
- // image
- $params[] = 'media=' . urlencode(HTTP_SERVER . DIR_WS_HTTP_CATALOG . DIR_WS_IMAGES . $image['products_image']);
-
- // count layout
- switch(MODULE_SOCIAL_BOOKMARKS_PINTEREST_BUTTON_COUNT_POSITION) {
- case "Horizontal":
- $layout = 'count-layout="horizontal"';
- break;
- case "Vertical":
- $layout = 'count-layout="vertical"';
- break;
- default:
- $layout = 'count-layout="none"';
- break;
+ if (tep_not_null($image['products_image'])) {
+ $image_file = $image['products_image'];
+
+ $pi_query = tep_db_query("select image from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' order by sort_order");
+
+ if (tep_db_num_rows($pi_query) > 0) {
+ while ($pi = tep_db_fetch_array($pi_query)) {
+ if (tep_not_null($pi['image'])) {
+ $image_file = $pi['image']; // overwrite image with first multiple product image
+ break;
+ }
+ }
+ }
+
+ $params['media'] = tep_href_link(DIR_WS_IMAGES . $image_file, '', 'NONSSL', false);
}
-
- // description
- $params[] = 'description=' . urlencode($product_name);
- $params = implode('&', $params);
+// url
+ $params['url'] = tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['products_id'], 'NONSSL', false);
+
+ $output = '<a href="http://pinterest.com/pin/create/button/?';
+
+ foreach ($params as $key => $value) {
+ $output .= $key . '=' . urlencode($value) . '&';
+ }
+
+ $output = substr($output, 0, -1); //remove last & from the url
+
+ $output .= '" class="pin-it-button" count-layout="' . strtolower(MODULE_SOCIAL_BOOKMARKS_PINTEREST_BUTTON_COUNT_POSITION) . '"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="' . $this->public_title . '" /></a>';
- return '<a href="http://pinterest.com/pin/create/button/?' . $params . '" class="pin-it-button" ' . $layout . '><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a>';
+ return $output;
}
function isEnabled() {
@@ -84,16 +91,16 @@ function check() {
function install() {
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Pinterest Module', 'MODULE_SOCIAL_BOOKMARKS_PINTEREST_STATUS', 'True', 'Do you want to allow Pinterest Button?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
- tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SOCIAL_BOOKMARKS_PINTEREST_SORT_ORDER', '90', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Layout Position', 'MODULE_SOCIAL_BOOKMARKS_PINTEREST_BUTTON_COUNT_POSITION', 'None', 'Horizontal or Vertical or None', '6', '2', 'tep_cfg_select_option(array(\'Horizontal\', \'Vertical\', \'None\'), ', now())");
+ tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SOCIAL_BOOKMARKS_PINTEREST_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
}
function remove() {
tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}
function keys() {
- return array('MODULE_SOCIAL_BOOKMARKS_PINTEREST_STATUS', 'MODULE_SOCIAL_BOOKMARKS_PINTEREST_SORT_ORDER', 'MODULE_SOCIAL_BOOKMARKS_PINTEREST_BUTTON_COUNT_POSITION');
+ return array('MODULE_SOCIAL_BOOKMARKS_PINTEREST_STATUS', 'MODULE_SOCIAL_BOOKMARKS_PINTEREST_BUTTON_COUNT_POSITION', 'MODULE_SOCIAL_BOOKMARKS_PINTEREST_SORT_ORDER');
}
}
?>

0 comments on commit 836e418

Please sign in to comment.