Esempio 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;
}
Esempio n. 2
0
function plugin_gsmg_screen()
{
    global $config, $mysql, $catz, $catmap, $SUPRESS_TEMPLATE_SHOW, $SYSTEM_FLAGS, $PFILTERS;
    $SUPRESS_TEMPLATE_SHOW = 1;
    $SUPRESS_MAINBLOCK_SHOW = 1;
    @header('Content-type: text/xml; charset=utf-8');
    $SYSTEM_FLAGS['http.headers'] = array('content-type' => 'application/xml; charset=charset=utf-8', 'cache-control' => 'private');
    if (extra_get_param('gsmg', 'cache')) {
        $cacheData = cacheRetrieveFile('gsmg.txt', extra_get_param('gsmg', 'cacheExpire'), 'gsmg');
        if ($cacheData != false) {
            // We got data from cache. Return it and stop
            print $cacheData;
            return;
        }
    }
    $output = '<?xml version="1.0" encoding="UTF-8"?>';
    $output .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
    // Настройки постранички
    if ($config['number'] < 1) {
        $config['number'] = 5;
    }
    // Надо ли выводить данные с головной страницы
    if (extra_get_param('gsmg', 'main')) {
        $output .= "<url>";
        $output .= "<loc>" . generateLink('news', 'main', array(), array(), false, true) . "</loc>";
        $output .= "<priority>" . floatval(extra_get_param('gsmg', 'main_pr')) . "</priority>";
        $lm = $mysql->record("select date(from_unixtime(max(postdate))) as pd from " . prefix . "_news");
        $output .= "<lastmod>" . $lm['pd'] . "</lastmod>";
        $output .= "<changefreq>daily</changefreq>";
        $output .= "</url>";
        if (extra_get_param('gsmg', 'mainp')) {
            $cnt = $mysql->record("select count(*) as cnt from " . prefix . "_news");
            $pages = ceil($cnt['cnt'] / $config['number']);
            for ($i = 2; $i <= $pages; $i++) {
                $output .= "<url>";
                $output .= "<loc>" . generateLink('news', 'main', array('page' => $i), array(), false, true) . "</loc>";
                $output .= "<priority>" . floatval(extra_get_param('gsmg', 'mainp_pr')) . "</priority>";
                $output .= "<lastmod>" . $lm['pd'] . "</lastmod>";
                $output .= "<changefreq>daily</changefreq>";
                $output .= "</url>";
            }
        }
    }
    // Надо ли выводить данные по категориям
    if (extra_get_param('gsmg', 'cat')) {
        foreach ($catmap as $id => $altname) {
            $output .= "<url>";
            $output .= "<loc>" . generateLink('news', 'by.category', array('category' => $altname, 'catid' => $id), array(), false, true) . "</loc>";
            $output .= "<priority>" . floatval(extra_get_param('gsmg', 'cat_pr')) . "</priority>";
            $output .= "<lastmod>" . $lm['pd'] . "</lastmod>";
            $output .= "<changefreq>daily</changefreq>";
            $output .= "</url>";
            if (extra_get_param('gsmg', 'catp')) {
                $cn = $catz[$altname]['number'] > 0 ? $catz[$altname]['number'] : $config['number'];
                $pages = ceil($catz[$altname]['posts'] / $cn);
                for ($i = 2; $i <= $pages; $i++) {
                    $output .= "<url>";
                    $output .= "<loc>" . generateLink('news', 'by.category', array('category' => $altname, 'catid' => $id, 'page' => $i), array(), false, true) . "</loc>";
                    $output .= "<priority>" . floatval(extra_get_param('gsmg', 'catp_pr')) . "</priority>";
                    $output .= "<lastmod>" . $lm['pd'] . "</lastmod>";
                    $output .= "<changefreq>daily</changefreq>";
                    $output .= "</url>";
                }
            }
        }
    }
    // Надо ли выводить данные по новостям
    if (extra_get_param('gsmg', 'news')) {
        $query = "select id, postdate, author, author_id, alt_name, editdate, catid from " . prefix . "_news where approve = 1 order by id desc";
        foreach ($mysql->select($query, 1) as $rec) {
            $link = newsGenerateLink($rec, false, 0, true);
            $output .= "<url>";
            $output .= "<loc>" . $link . "</loc>";
            $output .= "<priority>" . floatval(extra_get_param('gsmg', 'news_pr')) . "</priority>";
            $output .= "<lastmod>" . strftime("%Y-%m-%d", max($rec['editdate'], $rec['postdate'])) . "</lastmod>";
            $output .= "<changefreq>daily</changefreq>";
            $output .= "</url>";
        }
    }
    // Надо ли выводить данные по статическим страницам
    if (extra_get_param('gsmg', 'static')) {
        $query = "select id, alt_name from " . prefix . "_static where approve = 1";
        foreach ($mysql->select($query, 1) as $rec) {
            $link = generatePluginLink('static', '', array('altname' => $rec['alt_name'], 'id' => $rec['id']), array(), false, true);
            $output .= "<url>";
            $output .= "<loc>" . $link . "</loc>";
            $output .= "<priority>" . floatval(extra_get_param('gsmg', 'static_pr')) . "</priority>";
            $output .= "<lastmod>" . $lm['pd'] . "</lastmod>";
            $output .= "<changefreq>weekly</changefreq>";
            $output .= "</url>";
        }
    }
    if (is_array($PFILTERS['gsmg'])) {
        foreach ($PFILTERS['gsmg'] as $k => $v) {
            $v->onShow($output);
        }
    }
    $output .= "</urlset>";
    print $output;
    cacheStoreFile('gsmg.txt', $output, 'gsmg');
}