Skip to content

Commit

Permalink
Modernize split page results
Browse files Browse the repository at this point in the history
Migrate function calls in splitPageResults class to use new methods.

Eliminate tep_get_all_get_params in calls to display_links.

Migrate the product listing to use the new Product class.

Move language constants for Product and splitPageResults classes
out of the english.php file.

Modernize all affected files.
  • Loading branch information
ecartz committed May 14, 2021
1 parent bf1d565 commit 51b2e13
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 249 deletions.
55 changes: 0 additions & 55 deletions includes/languages/english.php
Expand Up @@ -22,7 +22,6 @@
const DATE_FORMAT_LONG = '%A %d %B, %Y'; // this is used for strftime()
const DATE_FORMAT = 'm/d/Y'; // this is used for date()
const DATE_TIME_FORMAT = DATE_FORMAT_SHORT . ' %H:%M:%S';
const JQUERY_DATEPICKER_FORMAT = 'mm/dd/yy'; // see http://docs.jquery.com/UI/Datepicker/formatDate

// if USE_DEFAULT_LANGUAGE_CURRENCY is true, use the following currency, instead of the application's default currency (used when changing language)
const LANGUAGE_CURRENCY = 'USD';
Expand Down Expand Up @@ -54,22 +53,6 @@

const ERROR_NO_PAYMENT_MODULE_SELECTED = 'Please select a payment method for your order.';

// constants for use in tep_prev_next_display function
const TEXT_RESULT_PAGE = 'Result Pages:';
const TEXT_DISPLAY_NUMBER_OF_PRODUCTS = 'Displaying <strong>%d</strong> to <strong>%d</strong> (of <strong>%d</strong> products)';

const PREVNEXT_TITLE_FIRST_PAGE = 'First Page';
const PREVNEXT_TITLE_PREVIOUS_PAGE = 'Previous Page';
const PREVNEXT_TITLE_NEXT_PAGE = 'Next Page';
const PREVNEXT_TITLE_LAST_PAGE = 'Last Page';
const PREVNEXT_TITLE_PAGE_NO = 'Page %d';
const PREVNEXT_TITLE_PREV_SET_OF_NO_PAGE = 'Previous Set of %d Pages';
const PREVNEXT_TITLE_NEXT_SET_OF_NO_PAGE = 'Next Set of %d Pages';
const PREVNEXT_BUTTON_FIRST = '&lt;&lt;FIRST';
const PREVNEXT_BUTTON_PREV = '[&lt;&lt;&nbsp;Prev]';
const PREVNEXT_BUTTON_NEXT = '[Next&nbsp;&gt;&gt;]';
const PREVNEXT_BUTTON_LAST = 'LAST&gt;&gt;';

const IMAGE_BUTTON_ADD_ADDRESS = 'Add Address';
const IMAGE_BUTTON_BACK = 'Back';
const IMAGE_BUTTON_BUY_NOW = 'Buy Now';
Expand All @@ -89,43 +72,16 @@
const SMALL_IMAGE_BUTTON_VIEW = 'View';
const SMALL_IMAGE_BUTTON_BUY = 'Buy';

const ICON_ARROW_RIGHT = 'more';

const TEXT_SORT_PRODUCTS = 'Sort products ';
const TEXT_DESCENDINGLY = 'descendingly';
const TEXT_ASCENDINGLY = 'ascendingly';
const TEXT_BY = ' by ';

const TEXT_CCVAL_ERROR_INVALID_DATE = 'The expiry date entered for the credit card is invalid. Please check the date and try again.';
const TEXT_CCVAL_ERROR_INVALID_NUMBER = 'The credit card number entered is invalid. Please check the number and try again.';
const TEXT_CCVAL_ERROR_UNKNOWN_CARD = 'The first four digits of the number entered are: %s. If that number is correct, we do not accept that type of credit card. If it is wrong, please try again.';

// category views
const TEXT_VIEW = 'View: ';
const TEXT_VIEW_LIST = ' List';
const TEXT_VIEW_GRID = ' Grid';

// search placeholder
const TEXT_SEARCH_PLACEHOLDER = 'Search';

// message for required inputs
const FORM_REQUIRED_INFORMATION = '<i class="fas fa-asterisk text-danger"></i> Required information';
const FORM_REQUIRED_INPUT = '<span class="form-control-feedback text-danger"><i class="fas fa-asterisk"></i></span>';

// grid/list
const TEXT_SORT_BY = 'Sort By ';
// moved from index
const TABLE_HEADING_IMAGE = '';
const TABLE_HEADING_MODEL = 'Model';
const TABLE_HEADING_PRODUCTS = 'Product Name';
const TABLE_HEADING_MANUFACTURER = 'Manufacturer';
const TABLE_HEADING_QUANTITY = 'Stock';
const TABLE_HEADING_PRICE = 'Price';
const TABLE_HEADING_WEIGHT = 'Weight';
const TABLE_HEADING_BUY_NOW = 'Buy Now';
const TABLE_HEADING_LATEST_ADDED = 'Date Added';
const TABLE_HEADING_ORDERED = 'Most Popular';

// product notifications
const PRODUCT_SUBSCRIBED = '%s has been added to your Notification List';
const PRODUCT_UNSUBSCRIBED = '%s has been removed from your Notification List';
Expand All @@ -142,21 +98,10 @@
<a class="alert-link" href="https://www.enable-javascript.com/" target="_blank" rel="noreferrer">Click here for instructions on enabling javascript in your browser</a>.</p>
EOT;

// sitewide is-product
const IS_PRODUCT_SHOW_PRICE = '%s';
const IS_PRODUCT_SHOW_PRICE_SPECIAL = '<del>%s</del> <span class="text-danger">now %s</span>';
const IS_PRODUCT_BUTTON_BUY = '<i class="fas fa-shopping-cart"></i>';
const IS_PRODUCT_BUTTON_VIEW = '<i class="fas fa-eye"></i> View';

// sitewide product listing
const LISTING_SORT_DOWN = '<i class="fas fa-level-down-alt text-primary"></i>';
const LISTING_SORT_UP = '<i class="fas fa-level-up-alt text-primary"></i>';
const LISTING_SORT_UNSELECTED = '<i class="fas fa-level-up-alt text-black-50"></i>';
// for new style internal pages
const LINK_TEXT_EDIT = '<small><a class="%s" href="%s">Edit</a></small>';
const SHIPPING_FA_ICON = '<i class="fas fa-shipping-fast fa-fw fa-3x float-right text-black-50"></i>';
const PAYMENT_FA_ICON = '<i class="fas fa-file-invoice-dollar fa-fw fa-3x float-right text-black-50"></i>';

const ENTRY_COMMENTS = 'Anything we need to know?';
const ENTRY_COMMENTS_PLACEHOLDER = 'Comment here...';
const TABLE_HEADING_OR = '-or-';
@@ -0,0 +1,16 @@
<?php
/*
$Id$
CE Phoenix, E-Commerce made Easy
https://phoenixcart.org
Copyright (c) 2021 Phoenix Cart
Released under the GNU General Public License
*/

const IS_PRODUCT_SHOW_PRICE = '%s';
const IS_PRODUCT_SHOW_PRICE_SPECIAL = '<del>%s</del> <span class="text-danger">now %s</span>';
const IS_PRODUCT_BUTTON_BUY = '<i class="fas fa-shopping-cart"></i>';
const IS_PRODUCT_BUTTON_VIEW = '<i class="fas fa-eye"></i> View';
@@ -0,0 +1,47 @@
<?php
/*
$Id$
CE Phoenix, E-Commerce made Easy
https://phoenixcart.org
Copyright (c) 2021 Phoenix Cart
Released under the GNU General Public License
*/

const TEXT_DISPLAY_NUMBER_OF_PRODUCTS = 'Displaying <strong>%d</strong> to <strong>%d</strong> (of <strong>%d</strong> products)';

const PREVNEXT_TITLE_FIRST_PAGE = 'First Page';
const PREVNEXT_TITLE_PREVIOUS_PAGE = 'Previous Page';
const PREVNEXT_TITLE_NEXT_PAGE = 'Next Page';
const PREVNEXT_TITLE_LAST_PAGE = 'Last Page';
const PREVNEXT_TITLE_PAGE_NO = 'Page %d';
const PREVNEXT_TITLE_PREV_SET_OF_NO_PAGE = 'Previous Set of %d Pages';
const PREVNEXT_TITLE_NEXT_SET_OF_NO_PAGE = 'Next Set of %d Pages';
const PREVNEXT_BUTTON_FIRST = '&lt;&lt;FIRST';
const PREVNEXT_BUTTON_PREV = '[&lt;&lt;&nbsp;Prev]';
const PREVNEXT_BUTTON_NEXT = '[Next&nbsp;&gt;&gt;]';
const PREVNEXT_BUTTON_LAST = 'LAST&gt;&gt;';

const TEXT_DESCENDINGLY = 'Sort products descendingly by %s';
const TEXT_ASCENDINGLY = 'Sort products ascendingly by %s';

const TABLE_HEADING_IMAGE = '';
const TABLE_HEADING_MODEL = 'Model';
const TABLE_HEADING_PRODUCTS = 'Product Name';
const TABLE_HEADING_MANUFACTURER = 'Manufacturer';
const TABLE_HEADING_QUANTITY = 'Stock';
const TABLE_HEADING_PRICE = 'Price';
const TABLE_HEADING_WEIGHT = 'Weight';
const TABLE_HEADING_BUY_NOW = 'Buy Now';
const TABLE_HEADING_LATEST_ADDED = 'Date Added';
const TABLE_HEADING_ORDERED = 'Most Popular';

// grid/list
const TEXT_SORT_BY = 'Sort By ';

// sitewide product listing
const LISTING_SORT_DOWN = '%s <i class="fas fa-level-down-alt text-primary"></i>';
const LISTING_SORT_UP = '%s <i class="fas fa-level-up-alt text-primary"></i>';
const LISTING_SORT_UNSELECTED = '%s <i class="fas fa-level-up-alt text-black-50"></i>';
21 changes: 9 additions & 12 deletions includes/modules/content/testimonials/cm_t_list.php
Expand Up @@ -19,19 +19,16 @@ function __construct() {
}

function execute() {
$content_width = MODULE_CONTENT_TESTIMONIALS_LIST_CONTENT_WIDTH;
$item_width = MODULE_CONTENT_TESTIMONIALS_LIST_CONTENT_WIDTH_EACH;

$testimonials_query_raw = "SELECT t.*, td.* FROM testimonials t, testimonials_description td WHERE t.testimonials_id = td.testimonials_id";
$testimonials_sql = "SELECT t.*, td.* FROM testimonials t, testimonials_description td WHERE t.testimonials_id = td.testimonials_id";
if (MODULE_CONTENT_TESTIMONIALS_LIST_ALL != 'All') {
$testimonials_query_raw .= " AND td.languages_id = " . (int)$_SESSION['languages_id'];
$testimonials_sql .= " AND td.languages_id = " . (int)$_SESSION['languages_id'];
}
$testimonials_query_raw .= " AND t.testimonials_status = 1 order by t.testimonials_id DESC";
$testimonials_sql .= " AND t.testimonials_status = 1 ORDER BY t.testimonials_id DESC";

$testimonials_split = new splitPageResults($testimonials_query_raw, MODULE_CONTENT_TESTIMONIALS_LIST_PAGING);
$testimonials_split = new splitPageResults($testimonials_sql, MODULE_CONTENT_TESTIMONIALS_LIST_PAGING);

if ($testimonials_split->number_of_rows > 0) {
$testimonials_query = tep_db_query($testimonials_split->sql_query);
$testimonials_query = $GLOBALS['db']->query($testimonials_split->sql_query);
}

$tpl_data = [ 'group' => $this->group, 'file' => __FILE__ ];
Expand All @@ -44,19 +41,19 @@ protected function get_parameters() {
'title' => 'Enable List Module',
'value' => 'True',
'desc' => 'Do you want to enable this module?',
'set_func' => "tep_cfg_select_option(['True', 'False'], ",
'set_func' => "Config::select_one(['True', 'False'], ",
],
'MODULE_CONTENT_TESTIMONIALS_LIST_CONTENT_WIDTH' => [
'title' => 'Content Width',
'value' => '12',
'desc' => 'What width container should the content be shown in? (12 = full width, 6 = half width).',
'set_func' => "tep_cfg_select_option(['12', '11', '10', '9', '8', '7', '6', '5', '4', '3', '2', '1'], ",
'set_func' => "Config::select_one(['12', '11', '10', '9', '8', '7', '6', '5', '4', '3', '2', '1'], ",
],
'MODULE_CONTENT_TESTIMONIALS_LIST_ALL' => [
'title' => 'View Testimonials',
'value' => 'All',
'desc' => 'Do you want to show all Testimonials or language specific Testimonials?',
'set_func' => "tep_cfg_select_option(['All', 'Language Specific'], ",
'set_func' => "Config::select_one(['All', 'Language Specific'], ",
],
'MODULE_CONTENT_TESTIMONIALS_LIST_PAGING' => [
'title' => 'Number of Testimonials',
Expand All @@ -67,7 +64,7 @@ protected function get_parameters() {
'title' => 'Item Width',
'value' => '6',
'desc' => 'What width container should the each Testimonial be shown in? (12 = full width, 6 = half width).',
'set_func' => "tep_cfg_select_option(['12', '11', '10', '9', '8', '7', '6', '5', '4', '3', '2', '1'], ",
'set_func' => "Config::select_one(['12', '11', '10', '9', '8', '7', '6', '5', '4', '3', '2', '1'], ",
],
'MODULE_CONTENT_TESTIMONIALS_LIST_SORT_ORDER' => [
'title' => 'Sort Order',
Expand Down
Expand Up @@ -10,7 +10,7 @@
echo '<blockquote class="blockquote">' . PHP_EOL;
echo nl2br($testimonials['testimonials_text']) . PHP_EOL;
echo '<footer class="blockquote-footer">',
sprintf(MODULE_CONTENT_TESTIMONIALS_LIST_WRITERS_NAME_DATE, htmlspecialchars($testimonials['customers_name']), tep_date_short($testimonials['date_added'])),
sprintf(MODULE_CONTENT_TESTIMONIALS_LIST_WRITERS_NAME_DATE, htmlspecialchars($testimonials['customers_name']), Date::abridge($testimonials['date_added'])),
'</footer>' . PHP_EOL;
echo '</blockquote>' . PHP_EOL;
echo '</div>' . PHP_EOL;
Expand All @@ -22,7 +22,7 @@
<?= $testimonials_split->display_count(MODULE_CONTENT_TESTIMONIALS_DISPLAY_NUMBER) ?>
</div>
<div class="col-sm-6">
<?= $testimonials_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(['page', 'info'])) ?>
<?= $testimonials_split->display_links(MAX_DISPLAY_PAGE_LINKS) ?>
</div>
</div>
</div>
Expand Down
92 changes: 63 additions & 29 deletions includes/system/segments/sortable_product_columns.php
Expand Up @@ -14,52 +14,86 @@
$default_column = 'PRODUCT_LIST_NAME';
}

$column_orderings = array_filter([
'PRODUCT_LIST_MODEL' => " ORDER BY p.products_model%s, pd.products_name",
'PRODUCT_LIST_NAME' => " ORDER BY pd.products_name%s",
'PRODUCT_LIST_MANUFACTURER' => " ORDER BY m.manufacturers_name%s, pd.products_name",
'PRODUCT_LIST_QUANTITY' => " ORDER BY p.products_quantity%s, pd.products_name",
'PRODUCT_LIST_IMAGE' => " ORDER BY pd.products_name",
'PRODUCT_LIST_WEIGHT' => " ORDER BY p.products_weight%s, pd.products_name",
'PRODUCT_LIST_PRICE' => " ORDER BY final_price%s, pd.products_name",
'PRODUCT_LIST_ID' => " ORDER BY p.products_id%s, pd.products_name",
'PRODUCT_LIST_ORDERED' => " ORDER BY p.products_ordered%s, pd.products_name",
$column_specifications = array_filter([
'PRODUCT_LIST_MODEL' => [
'order_by' => " ORDER BY p.products_model%s, pd.products_name",
'heading' => TABLE_HEADING_MODEL,
'sortable' => true,
],
'PRODUCT_LIST_NAME' => [
'order_by' => " ORDER BY pd.products_name%s",
'heading' => TABLE_HEADING_PRODUCTS,
'sortable' => true,
],
'PRODUCT_LIST_MANUFACTURER' => [
'order_by' => " ORDER BY m.manufacturers_name%s, pd.products_name",
'heading' => TABLE_HEADING_MANUFACTURER,
'sortable' => true,
],
'PRODUCT_LIST_QUANTITY' => [
'order_by' => " ORDER BY p.products_quantity%s, pd.products_name",
'heading' => TABLE_HEADING_QUANTITY,
'sortable' => true,
],
'PRODUCT_LIST_IMAGE' => [
'order_by' => " ORDER BY pd.products_name",
'heading' => TABLE_HEADING_IMAGE,
'sortable' => false,
],
'PRODUCT_LIST_WEIGHT' => [
'order_by' => " ORDER BY p.products_weight%s, pd.products_name",
'heading' => TABLE_HEADING_WEIGHT,
'sortable' => true,
],
'PRODUCT_LIST_PRICE' => [
'order_by' => " ORDER BY final_price%s, pd.products_name",
'heading' => TABLE_HEADING_PRICE,
'sortable' => true,
],
'PRODUCT_LIST_ID' => [
'order_by' => " ORDER BY p.products_id%s, pd.products_name",
'heading' => TABLE_HEADING_LATEST_ADDED,
'sortable' => true,
],
'PRODUCT_LIST_ORDERED' => [
'order_by' => " ORDER BY p.products_ordered%s, pd.products_name",
'heading' => TABLE_HEADING_ORDERED,
'sortable' => true,
],
], function ($k) use ($default_column) {
return ((constant($k) > 0) || ($k === $default_column));
}, ARRAY_FILTER_USE_KEY);

uksort($column_orderings, function ($a, $b) {
uksort($column_specifications, function ($a, $b) {
return (constant($a) <=> constant($b));
});

$column_list = array_keys($column_orderings);
$num_list = (isset($_GET['view']) && ($_GET['view'] === 'all') ) ? 999999 : MAX_DISPLAY_SEARCH_RESULTS;
$parameters = [
'column_specifications' => &$column_specifications,
'default_column' => &$default_column,
'direction' => &$direction,
'listing_sql' => &$listing_sql,
'num_list' => &$num_list,
'sort_order' => &$sort_order,
];
$GLOBALS['hooks']->register_pipeline('filter', $parameters);
$column_list = array_keys($column_specifications);

if ( (isset($_GET['sort'])) && (preg_match('/^[1-9][ad]$/', $_GET['sort'])) && (substr($_GET['sort'], 0, -1) <= count($column_list)) ) {
$sort_column = intval(substr($_GET['sort'], 0 , -1)) - 1;
if ( (isset($_GET['sort'])) && (preg_match('{\A[1-9]\d*[ad]\z}', $_GET['sort'])) && (substr($_GET['sort'], 0, -1) <= count($column_list)) ) {
$sort_column = (int)(substr($_GET['sort'], 0 , -1)) - 1;
} else {
$sort_column = array_search($default_column, $column_list, true);
if (false === $sort_column) {
$sort_column = 0;
error_log(sprintf(
'Cannot find default sort column: [%s]',
$default_column));
error_log("Can't find default sort column: [$default_column]");
}

$_GET['sort'] = ($sort_column + 1) . ($sort_order ?? 'a');
}

$direction = ('d' === substr($_GET['sort'], -1)) ? ' DESC' : '';

$parameters = [
'column_list' => &$column_list,
'column_orderings' => &$column_orderings,
'default_column' => &$default_column,
'direction' => &$direction,
'listing_sql' => &$listing_sql,
'sort_column' => &$sort_column,
];
$GLOBALS['hooks']->register_pipeline('filter', $parameters);

if (isset($column_orderings[$column_list[$sort_column]])) {
$listing_sql .= sprintf($column_orderings[$column_list[$sort_column]], $direction);
if (isset($column_specifications[$column_list[$sort_column]]['order_by'])) {
$listing_sql .= sprintf($column_specifications[$column_list[$sort_column]]['order_by'], $direction);
}
Expand Up @@ -22,9 +22,13 @@ class product_builder extends product_loader {
IF(COALESCE(a.attribute_count, 0) > 0, 1, 0) AS has_attributes
EOSQL;

public static function build_link($product, $parameters = '') {
public static function build_link($product, $parameters = []) {
if (is_string($parameters)) {
$parameters = phoenix_parameterize($parameters);
}

$product_id = is_numeric($product) ? $product : $product->get('id');
return tep_href_link('product_info.php', "{$parameters}products_id=" . (int)$product_id);
return $GLOBALS['Linker']->build('product_info.php', $parameters)->set_parameter('products_id', (int)$product_id);
}

public static function build_data_attributes($product, $data = []) {
Expand Down Expand Up @@ -85,10 +89,8 @@ public static function fetch_name($product_id, $language_id = null) {
$language_id = $_SESSION['languages_id'];
}

$product_query = tep_db_query("SELECT products_name FROM products_description WHERE products_id = " . (int)$product_id . " AND language_id = " . (int)$language_id);
$product = tep_db_fetch_array($product_query);

return $product['products_name'];
$sql = sprintf("SELECT products_name FROM products_description WHERE products_id = %d AND language_id = %d", (int)$product_id, (int)$language_id);
return $GLOBALS['db']->query($sql)->fetch_assoc()['products_name'];
}

}

0 comments on commit 51b2e13

Please sign in to comment.