Exemplo n.º 1
0
function plugin_block_eshop($number, $mode, $cat, $overrideTemplateName, $cacheExpire)
{
    global $config, $mysql, $tpl, $template, $twig, $twigLoader, $langMonths, $lang, $TemplateCache;
    // Prepare keys for cacheing
    $cacheKeys = array();
    $cacheDisabled = false;
    $conditions = array();
    if (isset($cat) && !empty($cat)) {
        array_push($conditions, "c.id IN (" . $cat . ") ");
    }
    array_push($conditions, "p.active = 1");
    if ($number < 1 || $number > 100) {
        $number = 5;
    }
    switch ($mode) {
        case 'view':
            $orderby = " ORDER BY p.view DESC ";
            break;
        case 'last':
            $orderby = " ORDER BY p.editdate DESC ";
            break;
        case 'stocked':
            array_push($conditions, "p.stocked = 1");
            $orderby = " ORDER BY p.editdate DESC ";
            break;
        case 'featured':
            array_push($conditions, "p.featured = 1");
            $orderby = " ORDER BY p.editdate DESC ";
            break;
        case 'rnd':
            $cacheDisabled = true;
            $orderby = " ORDER BY RAND() DESC ";
            break;
        default:
            $mode = 'last';
            $orderby = " ORDER BY p.editdate DESC ";
            break;
    }
    $fSort = " GROUP BY p.id " . $orderby . " LIMIT " . $number;
    $sqlQPart = "FROM " . prefix . "_eshop_products p LEFT JOIN " . prefix . "_eshop_products_categories pc ON p.id = pc.product_id LEFT JOIN " . prefix . "_eshop_categories c ON pc.category_id = c.id " . (count($conditions) ? "WHERE " . implode(" AND ", $conditions) : '') . $fSort;
    $sqlQ = "SELECT p.id AS id, p.url as url, p.code AS code, p.name AS name, p.annotation AS annotation, p.body AS body, p.active AS active, p.featured AS featured, p.stocked AS stocked, p.position AS position, p.meta_title AS meta_title, p.meta_keywords AS meta_keywords, p.meta_description AS meta_description, p.date AS date, p.editdate AS editdate, p.views AS views, c.id AS cid, c.url as curl, c.name AS category " . $sqlQPart;
    $tEntries = array();
    foreach ($mysql->select($sqlQ) as $row) {
        $view_link = checkLinkAvailable('eshop', 'show') ? generateLink('eshop', 'show', array('alt' => $row['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'show'), array('alt' => $row['url']));
        $tEntries[$row['id']] = array('id' => $row['id'], 'code' => $row['code'], 'name' => $row['name'], 'category' => $row['category'], 'active' => $row['active'], 'featured' => $row['featured'], 'stocked' => $row['stocked'], 'position' => $row['position'], 'date' => $row['date'], 'editdate' => $row['editdate'], 'edit_link' => "?mod=extra-config&plugin=eshop&action=edit_product&id=" . $row['id'] . "", 'view_link' => $view_link);
    }
    $entries_array_ids = array_keys($tEntries);
    if (isset($entries_array_ids) && !empty($entries_array_ids)) {
        $entries_string_ids = implode(',', $entries_array_ids);
        foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_images i WHERE i.product_id IN (' . $entries_string_ids . ') ORDER BY i.position, i.id') as $irow) {
            $tEntries[$irow['product_id']]['images'][] = $irow;
        }
        foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_variants v WHERE v.product_id IN (' . $entries_string_ids . ') ORDER BY v.position, v.id') as $vrow) {
            $tEntries[$vrow['product_id']]['variants'][] = $vrow;
        }
    }
    if ($overrideTemplateName) {
        $templateName = 'block/' . $overrideTemplateName;
    } else {
        $templateName = 'block/block_eshop';
    }
    // Determine paths for all template files
    $tpath = locatePluginTemplates(array($templateName), 'eshop', pluginGetVariable('eshop', 'localsource'));
    // Preload template configuration variables
    @templateLoadVariables();
    $cacheKeys[] = '|number=' . $number;
    $cacheKeys[] = '|mode=' . $mode;
    $cacheKeys[] = '|cat=' . $cat;
    $cacheKeys[] = '|templateName=' . $templateName;
    // Generate cache file name [ we should take into account SWITCHER plugin ]
    $cacheFileName = md5('eshop' . $config['theme'] . $templateName . $config['default_lang'] . join('', $cacheKeys)) . '.txt';
    if (!$cacheDisabled && $cacheExpire > 0) {
        $cacheData = cacheRetrieveFile($cacheFileName, $cacheExpire, 'eshop');
        if ($cacheData != false) {
            // We got data from cache. Return it and stop
            return $cacheData;
        }
    }
    $tVars['mode'] = $mode;
    $tVars['number'] = $number;
    $tVars['entries'] = $tEntries;
    $tVars['tpl_url'] = tpl_url;
    $tVars['home'] = home;
    $xt = $twig->loadTemplate($tpath[$templateName] . $templateName . '.tpl');
    $output = $xt->render($tVars);
    if (!$cacheDisabled && $cacheExpire > 0) {
        cacheStoreFile($cacheFileName, $output, 'eshop');
    }
    return $output;
}
Exemplo n.º 2
0
function main_prd($params)
{
    global $tpl, $template, $twig, $SYSTEM_FLAGS, $config, $userROW, $mysql, $twigLoader;
    $results = array();
    $params = arrayCharsetConvert(1, $params);
    $number = $params['number'];
    $mode = $params['mode'];
    $cat = $params['cat'];
    $overrideTemplateName = $params['template'];
    $prd_per_page = $number;
    $page = $params['page'];
    switch ($params['action']) {
        // **** ADD NEW ITEM INTO compare ****
        case 'show':
            $conditions = array();
            if (isset($cat) && !empty($cat)) {
                array_push($conditions, "c.id IN (" . $cat . ") ");
            }
            array_push($conditions, "p.active = 1");
            if ($number < 1 || $number > 100) {
                $number = 5;
            }
            switch ($mode) {
                case 'view':
                    $orderby = " ORDER BY p.view DESC ";
                    break;
                case 'last':
                    $orderby = " ORDER BY p.editdate DESC ";
                    break;
                case 'stocked':
                    array_push($conditions, "p.stocked = 1");
                    $orderby = " ORDER BY p.editdate DESC ";
                    break;
                case 'featured':
                    array_push($conditions, "p.featured = 1");
                    $orderby = " ORDER BY p.editdate DESC ";
                    break;
                case 'rnd':
                    $cacheDisabled = true;
                    $orderby = " ORDER BY RAND() DESC ";
                    break;
                default:
                    $mode = 'last';
                    $orderby = " ORDER BY p.editdate DESC ";
                    break;
            }
            $fSort = " " . $orderby;
            $sqlQPart = "FROM " . prefix . "_eshop_products p LEFT JOIN " . prefix . "_eshop_products_categories pc ON p.id = pc.product_id LEFT JOIN " . prefix . "_eshop_categories c ON pc.category_id = c.id " . (count($conditions) ? "WHERE " . implode(" AND ", $conditions) : '') . $fSort;
            $sqlQCount = "SELECT COUNT(p.id) " . $sqlQPart;
            $sqlQ = "SELECT p.id AS id, p.url as url, p.code AS code, p.name AS name, p.annotation AS annotation, p.body AS body, p.active AS active, p.featured AS featured, p.stocked AS stocked, p.position AS position, p.meta_title AS meta_title, p.meta_keywords AS meta_keywords, p.meta_description AS meta_description, p.date AS date, p.editdate AS editdate, p.views AS views, c.id AS cid, c.url as curl, c.name AS category " . $sqlQPart;
            $entries = array();
            $pageNo = intval($page) ? $page : 0;
            if ($pageNo < 1) {
                $pageNo = 1;
            }
            if (!$start_from) {
                $start_from = ($pageNo - 1) * $prd_per_page;
            }
            $count = $mysql->result($sqlQCount);
            $countPages = ceil($count / $prd_per_page);
            $cmp_array = array();
            foreach ($SYSTEM_FLAGS["eshop"]["compare"]["entries"] as $cmp_row) {
                $cmp_array[] = $cmp_row['linked_fld'];
            }
            foreach ($mysql->select($sqlQ . ' LIMIT ' . $start_from . ', ' . $prd_per_page) as $row) {
                $fulllink = checkLinkAvailable('eshop', 'show') ? generateLink('eshop', 'show', array('alt' => $row['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'show'), array('alt' => $row['url']));
                $catlink = checkLinkAvailable('eshop', '') ? generateLink('eshop', '', array('alt' => $row['curl'])) : generateLink('core', 'plugin', array('plugin' => 'eshop'), array('alt' => $row['curl']));
                $cmp_flag = in_array($row['id'], $cmp_array);
                $entries[$row['id']] = array('id' => $row['id'], 'code' => $row['code'], 'name' => $row['name'], 'annotation' => $row['annotation'], 'body' => $row['body'], 'active' => $row['active'], 'featured' => $row['featured'], 'meta_title' => $row['meta_title'], 'meta_keywords' => $row['meta_keywords'], 'meta_description' => $row['meta_description'], 'fulllink' => $fulllink, 'date' => empty($row['date']) ? '' : $row['date'], 'editdate' => empty($row['editdate']) ? '' : $row['editdate'], 'views' => $row['views'], 'cat_name' => $row['category'], 'cid' => $row['cid'], 'catlink' => $catlink, 'compare' => $cmp_flag, 'home' => home, 'tpl_url' => home . '/templates/' . $config['theme']);
            }
            $entries_array_ids = array_keys($entries);
            if (isset($entries_array_ids) && !empty($entries_array_ids)) {
                $entries_string_ids = implode(',', $entries_array_ids);
                foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_images i WHERE i.product_id IN (' . $entries_string_ids . ') ORDER BY i.position, i.id') as $irow) {
                    $entries[$irow['product_id']]['images'][] = $irow;
                }
                foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_variants v WHERE v.product_id IN (' . $entries_string_ids . ') ORDER BY v.position, v.id') as $vrow) {
                    $entries[$vrow['product_id']]['variants'][] = $vrow;
                }
            }
            $tVars = array('info' => isset($info) ? $info : '', 'entries' => isset($entries) ? $entries : '', 'tpl_url' => home . '/templates/' . $config['theme'], 'tpl_home' => admin_url);
            if ($overrideTemplateName) {
                $templateName = 'block/' . $overrideTemplateName;
            } else {
                $templateName = 'block/main_block_eshop';
            }
            // Determine paths for all template files
            $tpath = locatePluginTemplates(array($templateName), 'eshop', pluginGetVariable('eshop', 'localsource'));
            // Preload template configuration variables
            @templateLoadVariables();
            $tVars['mode'] = $mode;
            $tVars['number'] = $number;
            $tVars['tpl_url'] = tpl_url;
            $tVars['home'] = home;
            $tVars['pagesss'] = generateLP(array('current' => $pageNo, 'count' => $countPages, 'url' => '#', 'tpl' => $templateName . '_pages'));
            $xt = $twig->loadTemplate($tpath[$templateName] . $templateName . '.tpl');
            if (empty($row)) {
                $results = array('prd_main' => 2, 'prd_main_text' => iconv('Windows-1251', 'UTF-8', 'Нет продукции!'), 'prd_main_pages_text' => iconv('Windows-1251', 'UTF-8', ''));
            } else {
                $results = array('prd_main' => 100, 'prd_main_text' => iconv('Windows-1251', 'UTF-8', $xt->render($tVars)), 'prd_main_pages_text' => iconv('Windows-1251', 'UTF-8', $tVars['pagesss']));
            }
            break;
    }
    return array('status' => 1, 'errorCode' => 0, 'data' => $results);
}
Exemplo n.º 3
0
function generateLP($param)
{
    global $tpl, $TemplateCache, $twig;
    if ($param['count'] < 2) {
        return '';
    }
    templateLoadVariables(true, 1);
    $nav = LoadVariables_eshop();
    #$nav = $TemplateCache['site']['#variables']['navigation'];
    /*
    $nav = array(
        "prevlink" => "<a class='item' style='cursor:pointer;' data-page='%page%' class='prev' data-page='prev'>%page%</a> ",
        "nextlink" => "<a class='item' style='cursor:pointer;' data-page='%page%' class='next' data-page='next'>%page%</a> ",
        "current_page" => "<a style='cursor:pointer;' class='item active current' data-page='%page%'>%page%</a> ",
        "link_page" => "<a class='item' style='cursor:pointer;' data-page='%page%'>%page%</a> ",
        "dots" => "<a class='item'>...</a> "
    );
    */
    if ($param['current'] > 1) {
        $prev = $param['current'] - 1;
        $prev_link = str_replace('%page%', "\$1", str_replace('%link%', str_replace('%page%', $prev, $param['url']), $nav['prevlink']));
    } else {
        $prev_link = "";
        $no_prev = true;
    }
    // ===[ TO PUT INTO CONFIG ]===
    $pages = '';
    if (isset($param['maxNavigations']) && $param['maxNavigations'] > 3 && $param['maxNavigations'] < 500) {
        $maxNavigations = intval($param['maxNavigations']);
    } else {
        $maxNavigations = 10;
    }
    $sectionSize = floor($maxNavigations / 3);
    if ($param['count'] > $maxNavigations) {
        // We have more than 10 pages. Let's generate 3 parts
        // Situation #1: 1,2,3,4,[5],6 ... 128
        if ($param['current'] < $sectionSize * 2) {
            $pages .= generateNavi($param['current'], 1, $sectionSize * 2, $param['url'], $nav);
            $pages .= $nav['dots'];
            $pages .= generateNavi($param['current'], $param['count'] - $sectionSize, $param['count'], $param['url'], $nav);
        } elseif ($param['current'] > $param['count'] - $sectionSize * 2 + 1) {
            $pages .= generateNavi($param['current'], 1, $sectionSize, $param['url'], $nav);
            $pages .= $nav['dots'];
            $pages .= generateNavi($param['current'], $param['count'] - $sectionSize * 2 + 1, $param['count'], $param['url'], $nav);
        } else {
            $pages .= generateNavi($param['current'], 1, $sectionSize, $param['url'], $nav);
            $pages .= $nav['dots'];
            $pages .= generateNavi($param['current'], $param['current'] - 1, $param['current'] + 1, $param['url'], $nav);
            $pages .= $nav['dots'];
            $pages .= generateNavi($param['current'], $param['count'] - $sectionSize, $param['count'], $param['url'], $nav);
        }
    } else {
        // If we have less then 10 pages
        $pages .= generateNavi($param['current'], 1, $param['count'], $param['url'], $nav);
    }
    $tvars['vars']['pages'] = $pages;
    if ($prev + 2 <= $param['count']) {
        $next = $prev + 2;
        $next_link = str_replace('%page%', "\$1", str_replace('%link%', str_replace('%page%', $next, $param['url']), $nav['nextlink']));
    } else {
        $next_link = "";
        $no_next = true;
    }
    $tpl_name = $param['tpl'];
    $tpath = locatePluginTemplates(array($tpl_name), 'eshop', pluginGetVariable('eshop', 'localsource'));
    $xt = $twig->loadTemplate($tpath[$tpl_name] . $tpl_name . '.tpl');
    $tpl->template($tpl_name, $tpath[$tpl_name]);
    $tVars = array('current' => $param['current'], 'prev' => $param['current'] - 1, 'prev_link' => $prev_link, 'pages' => $pages, 'next' => $prev + 2, 'next_link' => $next_link, 'no_prev' => $no_prev, 'no_next' => $no_next);
    return $xt->render($tVars);
}
Exemplo n.º 4
0
function comments_show_handler($params)
{
    global $mysql, $tpl, $template, $config, $userROW, $parse, $lang, $PFILTERS, $TemplateCache, $twig, $mysql;
    // Preload template configuration variables
    templateLoadVariables();
    // Use default <noavatar> file
    // - Check if noavatar is defined on template level
    $tplVars = $TemplateCache['site']['#variables'];
    $noAvatarURL = isset($tplVars['configuration']) && is_array($tplVars['configuration']) && isset($tplVars['configuration']['noAvatarImage']) && $tplVars['configuration']['noAvatarImage'] ? tpl_url . "/" . $tplVars['configuration']['noAvatarImage'] : avatars_url . "/noavatar.gif";
    $tpath = locatePluginTemplates(array('comments.show_eshop'), 'eshop', pluginGetVariable('eshop', 'localsource'));
    $xt = $twig->loadTemplate($tpath['comments.show_eshop'] . 'comments.show_eshop.tpl');
    $conditions = array();
    if ($params['product_id']) {
        array_push($conditions, "c.product_id = " . db_squote($params['product_id']));
    }
    $approve_comments = pluginGetVariable('eshop', 'approve_comments');
    if ($approve_comments == "1") {
        array_push($conditions, "c.status = 1");
    }
    $sort_comments = pluginGetVariable('eshop', 'sort_comments');
    if ($sort_comments == "0") {
        $dSort = " ASC";
    } else {
        $dSort = " DESC";
    }
    $fSort = "ORDER BY c.postdate" . $dSort;
    $sqlQPart = "from " . prefix . "_eshop_products_comments c LEFT JOIN " . prefix . "_users u ON c.author_id = u.id " . (count($conditions) ? "where " . implode(" AND ", $conditions) : '') . ' ' . $fSort;
    $sqlQ = "select *, c.id as cid, u.id as uid, u.name as uname, c.name as name " . $sqlQPart;
    $output = '';
    foreach ($mysql->select($sqlQ) as $row) {
        // Add [hide] tag processing
        $text = $row['text'];
        if ($config['use_bbcodes']) {
            $text = $parse->bbcodes($text);
        }
        if ($config['use_htmlformatter']) {
            $text = $parse->htmlformatter($text);
        }
        if ($config['use_smilies']) {
            $text = $parse->smilies($text);
        }
        if ($config['use_avatars']) {
            if ($row['avatar']) {
                $avatar = avatars_url . "/" . $row['avatar'];
            } else {
                $avatar = $noAvatarURL;
            }
        } else {
            $avatar = '';
        }
        $Entries[] = array('id' => $row['cid'], 'mail' => $row['mail'], 'author' => $row['name'], 'date' => $row['postdate'], 'profile_link' => checkLinkAvailable('uprofile', 'show') ? generateLink('uprofile', 'show', array('name' => $row['author'], 'id' => $row['author_id'])) : generateLink('core', 'plugin', array('plugin' => 'uprofile', 'handler' => 'show'), array('id' => $row['author_id'])), 'avatar' => $avatar, 'name' => $row['uname'], 'commenttext' => $text);
        //$output .= $xt->render($tVars);
    }
    $tVars = array('entries' => isset($Entries) ? $Entries : '', 'tpl_url' => home . '/templates/' . $config['theme'], 'tpl_home' => admin_url);
    $output .= $xt->render($tVars);
    return $output;
}