Advertisement
Tsimi

cm_pi_reviews.php

May 1st, 2015
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.98 KB | None | 0 0
  1. <?php
  2. /*
  3.   $Id$
  4.  
  5.   osCommerce, Open Source E-Commerce Solutions
  6.   http://www.oscommerce.com
  7.  
  8.   Copyright (c) 2014 osCommerce
  9.  
  10.   Released under the GNU General Public License
  11. */
  12.  
  13.   class cm_pi_reviews {
  14.     var $code;
  15.     var $group;
  16.     var $title;
  17.     var $description;
  18.     var $sort_order;
  19.     var $enabled = false;
  20. // BOF TSIMI
  21.     var $delete_tables = false;
  22. // EOF TSIMI
  23.  
  24.     function cm_pi_reviews() {
  25.       $this->code = get_class($this);
  26.       $this->group = basename(dirname(__FILE__));
  27.  
  28.       $this->title = MODULE_CONTENT_PRODUCT_INFO_REVIEWS_TITLE;
  29.       $this->description = MODULE_CONTENT_PRODUCT_INFO_REVIEWS_DESCRIPTION;
  30.  
  31.       if ( defined('MODULE_CONTENT_PRODUCT_INFO_REVIEWS_STATUS') ) {
  32.         $this->sort_order = MODULE_CONTENT_PRODUCT_INFO_REVIEWS_SORT_ORDER;
  33.         $this->enabled = (MODULE_CONTENT_PRODUCT_INFO_REVIEWS_STATUS == 'True');
  34. // BOF TSIMI       
  35.         $this->delete_tables = (MODULE_CONTENT_PRODUCT_INFO_REVIEWS_DELETE_TABLES == 'True');
  36. // EOF TSIMI       
  37.       }
  38.     }
  39.  
  40.     function execute() {
  41.       global $oscTemplate, $_GET, $languages_id;
  42.      
  43.       $content_width = (int)MODULE_CONTENT_PRODUCT_INFO_REVIEWS_CONTENT_WIDTH;
  44.  
  45.       $review_query = tep_db_query("select SUBSTRING_INDEX(rd.reviews_text, ' ', 20) as reviews_text, r.reviews_rating, r.reviews_id, r.customers_name, r.date_added, r.reviews_read, p.products_id, p.products_price, p.products_tax_class_id, p.products_image, p.products_model, pd.products_name from reviews r, reviews_description rd, products p, products_description pd where r.products_id = '" . (int)$_GET['products_id'] . "' and r.reviews_id = rd.reviews_id and rd.languages_id = '" . (int)$languages_id . "' and r.products_id = p.products_id and p.products_status = '1' and r.reviews_status = '1' and p.products_id = pd.products_id and pd.language_id = '". (int)$languages_id . "' order by r.reviews_rating DESC limit " . (int)MODULE_CONTENT_PRODUCT_INFO_REVIEWS_CONTENT_LIMIT);
  46.       $review_data = NULL;
  47.  
  48.       if (tep_db_num_rows($review_query) > 0) {
  49.         while ($review = tep_db_fetch_array($review_query)) {
  50.           $review_data .=  '<blockquote class="col-sm-6">';
  51.           $review_data .=   '  <p>' . tep_output_string_protected($review['reviews_text']) . ' ... </p>';
  52.           $review_name = tep_output_string_protected($review['customers_name']);
  53.           $review_data .=   '  <footer>' . sprintf(MODULE_CONTENT_PRODUCT_INFO_REVIEWS_TEXT_RATED, tep_draw_stars($review['reviews_rating']), $review_name, $review_name) . '</footer>';
  54.           $review_data .=   '</blockquote>';
  55.         }
  56.        
  57.         ob_start();
  58.         include(DIR_WS_MODULES . 'content/' . $this->group . '/templates/reviews.php');
  59.         $template = ob_get_clean();
  60.  
  61.         $oscTemplate->addContent($template, $this->group);
  62.       }
  63.     }
  64.  
  65.     function isEnabled() {
  66.       return $this->enabled;
  67.     }
  68.  
  69.     function check() {
  70.       return defined('MODULE_CONTENT_PRODUCT_INFO_REVIEWS_STATUS');
  71.     }
  72.  
  73.     function install() {
  74.       tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Reviews Module', 'MODULE_CONTENT_PRODUCT_INFO_REVIEWS_STATUS', 'True', 'Should the reviews block be shown on the product info page?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
  75.       tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Content Width', 'MODULE_CONTENT_PRODUCT_INFO_REVIEWS_CONTENT_WIDTH', '6', 'What width container should the content be shown in?', '6', '1', 'tep_cfg_select_option(array(\'12\', \'11\', \'10\', \'9\', \'8\', \'7\', \'6\', \'5\', \'4\', \'3\', \'2\', \'1\'), ', now())");
  76.       tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Number of Reviews', 'MODULE_CONTENT_PRODUCT_INFO_REVIEWS_CONTENT_LIMIT', '4', 'How many reviews should be shown?', '6', '1', now())");
  77. // BOF TSIMI
  78.       tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Delete auto created tables on module Remove', 'MODULE_CONTENT_PRODUCT_INFO_REVIEWS_DELETE_TABLES', 'False', 'Do you want to remove the tables that where created during installing this module?<br><i>Note: all the created data will be deleted</i>.', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
  79. // EOF TISMI
  80.       tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_CONTENT_PRODUCT_INFO_REVIEWS_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
  81. // BOF TSIMI     
  82.        //CREATE NEEDED TABLES INTO DB
  83.       tep_db_query("
  84.      CREATE TABLE IF NOT EXISTS `test_table1` (
  85.        `field1` int(11) NOT NULL AUTO_INCREMENT,
  86.        `field2` tinyint(1) NOT NULL DEFAULT '0',
  87.        `field3` int(11) NOT NULL DEFAULT '0',
  88.        PRIMARY KEY (`field1`)
  89.      ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
  90.      ");
  91.       tep_db_query("
  92.      CREATE TABLE IF NOT EXISTS `test_table2` (
  93.        `field4` int(11) NOT NULL AUTO_INCREMENT,
  94.        `field5` tinyint(1) NOT NULL DEFAULT '0',
  95.        `field6` int(11) NOT NULL DEFAULT '0',
  96.        PRIMARY KEY (`field4`)
  97.      ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
  98.      ");
  99.       tep_db_query("
  100.      CREATE TABLE IF NOT EXISTS `test_table3` (
  101.        `field7` int(11) NOT NULL AUTO_INCREMENT,
  102.        `field8` tinyint(1) NOT NULL DEFAULT '0',
  103.        `field9` int(11) NOT NULL DEFAULT '0',
  104.        PRIMARY KEY (`field7`)
  105.      ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
  106.      ");
  107.      
  108. // BOF TSIMI     
  109.     }
  110.  
  111.     function remove() {
  112.       tep_db_query("delete from configuration where configuration_key in ('" . implode("', '", $this->keys()) . "')");
  113. // BOF TSIMI     
  114.        if($this->delete_tables){ //drop tables if delete_tables option is true
  115.      
  116.         tep_db_query("DROP TABLE IF EXISTS `test_table1`");
  117.         tep_db_query("DROP TABLE IF EXISTS `test_table2`");
  118.         tep_db_query("DROP TABLE IF EXISTS `test_table3`");
  119.       }
  120. // EOF TSIMI     
  121.     }
  122.  
  123.     function keys() {
  124.       return array('MODULE_CONTENT_PRODUCT_INFO_REVIEWS_STATUS',
  125.                    'MODULE_CONTENT_PRODUCT_INFO_REVIEWS_CONTENT_WIDTH',
  126.                    'MODULE_CONTENT_PRODUCT_INFO_REVIEWS_CONTENT_LIMIT',
  127.                 // BOF TSIMI
  128.                    'MODULE_CONTENT_PRODUCT_INFO_REVIEWS_DELETE_TABLES',
  129.                 // EOF TSIMI  
  130.                    'MODULE_CONTENT_PRODUCT_INFO_REVIEWS_SORT_ORDER');
  131.     }
  132.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement