<commit_before><?php
/**
 *                    Jojo CMS
 *                ================
 *
 * Copyright 2008 <NAME> <<EMAIL>>
 * Copyright 2008 <NAME> <<EMAIL>>
 *
 * See the enclosed file license.txt for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * @author  <NAME> <<EMAIL>>
 * @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License
 * @link    http://www.jojocms.org JojoCMS
 */

class Jojo_Plugin_Jojo_cart_product_award extends JOJO_Plugin
{

    /* Gets $num awards/reviews sorted by date (desc) for use on homepages and sidebars */
    public static function getProductAwards($num=false, $start = 0, $productid = false, $order = false) {

        global $page, $cart;
        if (_MULTILANGUAGE) $language = !empty($page->page['pg_language']) ? $page->page['pg_language'] : Jojo::getOption('multilanguage-default', 'en');
        $limit = ($num) ? " LIMIT $start,$num" : '';

        $now    = time();
        $query  = "SELECT * FROM {product_award}";
        $query .= " WHERE productid AND pa_livedate<$now AND (pa_expirydate<=0 OR pa_expirydate>$now)";
        $query .= (_MULTILANGUAGE) ? " AND (pa_language = '$language')" : '';
        $query .= ($productid) ? " AND (productid = '$productid')" : '';
        $query .= ($order=='product') ? " ORDER BY productid DESC, pa_date DESC $limit" : " ORDER BY pa_date DESC $limit" ;
        $productawards = Jojo::selectQuery($query);
        foreach ($productawards as $k => &$a){
            $a['reviewer']     = htmlspecialchars($a['pa_author'], ENT_COMPAT, 'UTF-8', false);
            $a['title']     = htmlspecialchars($a['pa_organisation'], ENT_COMPAT, 'UTF-8', false);
            $a['award']        = htmlspecialchars($a['pa_name'], ENT_COMPAT, 'UTF-8', false);
            $a['link']        = !empty($a['pa_organisationlink']) ? $a['pa_organisationlink'] : '';
            $a['rating']     = htmlspecialchars($a['pa_rating'], ENT_COMPAT, 'UTF-8', false);
            $a['bodyplain']    = strip_tags($a['pa_body']);
            unset($a['pa_body_code']);
            $a['date']         = $a['pa_date'];
            if ($a['productid'] && class_exists('JOJO_Plugin_Jojo_cart')) {
                foreach (JOJO_Plugin_Jojo_cart::getProductHandlers() as $productHandler) {
                    if (method_exists($productHandler, 'getItemsbyId')) {
                        $item = call_user_func($productHandler .'::getItemsById', $a['productid']);
                        if ($item) {
                            $a['product'] = $item;
                            break;
                        }
                    }
                }
            }
            if (!($productid || Jojo::getOption('productaward_currentonly', 'yes')=='no' || (isset($a['product']['pr_price']) && $a['product']['pr_price']!=0) )) {
                unset($productawards[$k]);
            }
        }
        return $productawards;<commit_msg>Product Awards: Fix infinite loop issue with products calling the function for award info<commit_after><?php
/**
 *                    Jojo CMS
 *                ================
 *
 * Copyright 2008 <NAME> <<EMAIL>>
 * Copyright 2008 <NAME> <<EMAIL>>
 *
 * See the enclosed file license.txt for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * @author  <NAME> <<EMAIL>>
 * @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License
 * @link    http://www.jojocms.org JojoCMS
 */

class Jojo_Plugin_Jojo_cart_product_award extends JOJO_Plugin
{

    /* Gets $num awards/reviews sorted by date (desc) for use on homepages and sidebars */
    public static function getProductAwards($num=false, $start = 0, $productid = false, $order = false, $product=true) {

        global $page, $cart;
        if (_MULTILANGUAGE) $language = !empty($page->page['pg_language']) ? $page->page['pg_language'] : Jojo::getOption('multilanguage-default', 'en');
        $limit = ($num) ? " LIMIT $start,$num" : '';

        $now    = time();
        $query  = "SELECT * FROM {product_award}";
        $query .= " WHERE productid AND pa_livedate<$now AND (pa_expirydate<=0 OR pa_expirydate>$now)";
        $query .= (_MULTILANGUAGE) ? " AND (pa_language = '$language')" : '';
        $query .= ($productid) ? " AND (productid = '$productid')" : '';
        $query .= ($order=='product') ? " ORDER BY productid DESC, pa_date DESC $limit" : " ORDER BY pa_date DESC $limit" ;
        $productawards = Jojo::selectQuery($query);
        foreach ($productawards as $k => &$a){
            $a['reviewer']     = htmlspecialchars($a['pa_author'], ENT_COMPAT, 'UTF-8', false);
            $a['title']     = htmlspecialchars($a['pa_organisation'], ENT_COMPAT, 'UTF-8', false);
            $a['award']        = htmlspecialchars($a['pa_name'], ENT_COMPAT, 'UTF-8', false);
            $a['link']        = !empty($a['pa_organisationlink']) ? $a['pa_organisationlink'] : '';
            $a['rating']     = htmlspecialchars($a['pa_rating'], ENT_COMPAT, 'UTF-8', false);
            $a['bodyplain']    = strip_tags($a['pa_body']);
            unset($a['pa_body_code']);
            $a['date']         = $a['pa_date'];
            if ($product && $a['productid'] && class_exists('JOJO_Plugin_Jojo_cart')) {
                foreach (JOJO_Plugin_Jojo_cart::getProductHandlers() as $productHandler) {
                    if (method_exists($productHandler, 'getItemsbyId')) {
                        $item = call_user_func($productHandler .'::getItemsById', $a['productid']);
                        if ($item) {
                            $a['product'] = $item;
                            break;
                        }
                    }
                }
            }
            if (!($productid || Jojo::getOption('productaward_currentonly', 'yes')=='no' || (isset($a['product']['pr_price']) && $a['product']['pr_price']!=0) )) {
                unset($productawards[$k]);
            }
        }
        return $productawards;
{'fraction_non_alphanumeric': 0.1748805010713697, 'fraction_numerical': 0.004944783253667381, 'mean_word_length': 2.441860465116279, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7290955', 'n_tokens_mistral': 1913, 'n_tokens_neox': 1837, 'n_words': 384}