コード例 #1
0
ファイル: eshop.php プロジェクト: stdex/ngcms_eshop
function show_eshop($params)
{
    global $tpl, $template, $twig, $mysql, $SYSTEM_FLAGS, $config, $userROW, $CurrentHandler, $lang;
    //var_dump($SYSTEM_FLAGS["eshop"]["catz"]);
    $id = isset($params['id']) ? abs(intval($params['id'])) : abs(intval($_REQUEST['id']));
    $alt = preg_match('#^[A-Za-z0-9\\.\\_\\-]+$#s', $params['alt']) ? input_filter_com(convert($params['alt'])) : '';
    $url = pluginGetVariable('eshop', 'url');
    switch ($CurrentHandler['handlerParams']['value']['pluginName']) {
        case 'core':
            if (isset($url) && !empty($url)) {
                return redirect_eshop(generateLink('eshop', 'show', array('alt' => $alt)));
            }
            break;
        case 'eshop':
            if (empty($url)) {
                return redirect_eshop(generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'show'), array('alt' => $alt)));
            }
            break;
    }
    $conditions = array();
    if (isset($alt) && !empty($alt)) {
        array_push($conditions, "p.url = " . db_squote($alt) . " ");
    } else {
        redirect_eshop(link_eshop());
    }
    array_push($conditions, "p.active = 1 ");
    $tpath = locatePluginTemplates(array('show_eshop'), 'eshop', pluginGetVariable('eshop', 'localsource'), pluginGetVariable('eshop', 'localskin'));
    $xt = $twig->loadTemplate($tpath['show_eshop'] . 'show_eshop.tpl');
    $fSort = " GROUP BY p.id ORDER BY p.id DESC LIMIT 1";
    $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 LEFT JOIN " . prefix . "_eshop_variants v ON p.id = v.product_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.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;
    $row = $mysql->record($sqlQ);
    if (isset($row) && !empty($row)) {
        $qid = $row['id'];
        $fulllink = checkLinkAvailable('eshop', 'show') ? generateLink('eshop', 'show', array('alt' => $row['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'show'), array('alt' => $row['url']));
        $cat_ids = $row['cid'];
        $i = 0;
        $location_tmp = array();
        $location = array();
        $location_tmp[] = array('text' => $row['name'], 'link' => $fulllink);
        if ($cat_ids != "") {
            do {
                $result_cat = array();
                getCatFromTreeByID($SYSTEM_FLAGS["eshop"]["catz"]["tree"], $cat_ids, $result_cat);
                $bcat_row = $result_cat;
                $cat_ids = $bcat_row['parent_id'];
                $catlink = checkLinkAvailable('eshop', '') ? generateLink('eshop', '', array('alt' => $bcat_row['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop'), array('alt' => $bcat_row['url']));
                $location_tmp[] = array('text' => $bcat_row['name'], 'link' => $catlink);
                $i += 1;
            } while ($cat_ids != 0);
            /*
            do {
                $bcat_row = $mysql->record("SELECT * FROM ".prefix."_eshop_categories c WHERE c.id IN (".$cat_ids.")");
                $cat_ids = $bcat_row['parent_id'];
                $catlink = checkLinkAvailable('eshop', '')?
                    generateLink('eshop', '', array('alt' => $bcat_row['url'])):
                    generateLink('core', 'plugin', array('plugin' => 'eshop'), array('alt' => $bcat_row['url']));
                
                $location_tmp[] = array('text' => $bcat_row['name'],
                                        'link' => $catlink,
                );
                $i += 1;
                
            }
            while($cat_ids != 0);
            */
        }
        $location = array_merge($location, array_reverse($location_tmp));
        foreach ($location as $loc_k => $loc) {
            $SYSTEM_FLAGS['info']['breadcrumbs'][$loc_k]['text'] = $loc['text'];
            $SYSTEM_FLAGS['info']['breadcrumbs'][$loc_k]['link'] = $loc['link'];
        }
        $entriesImg = array();
        foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_images WHERE product_id = ' . $row['id'] . ' ORDER BY position, id ') as $row2) {
            $entriesImg[] = $row2;
        }
        $entriesVariants = array();
        foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_variants WHERE product_id = ' . $row['id'] . ' ORDER BY position, id ') as $vrow) {
            $entriesVariants[] = $vrow;
        }
        $features_array = array();
        foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_options LEFT JOIN ' . prefix . '_eshop_features ON ' . prefix . '_eshop_features.id=' . prefix . '_eshop_options.feature_id WHERE ' . prefix . '_eshop_options.product_id = ' . $row['id'] . ' ORDER BY position, id') as $orow) {
            if ($orow['ftype'] == 2) {
                $foptions = json_decode($orow['foptions'], true);
                $orow['value'] = iconv("utf-8", "windows-1251", $foptions[$orow['value']]);
            }
            $features_array[] = $orow;
        }
        foreach ($mysql->select('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.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 FROM ' . prefix . '_eshop_related_products rp LEFT JOIN ' . prefix . '_eshop_products p ON p.id=rp.related_id WHERE rp.product_id = ' . $row['id'] . ' AND p.active = 1 ORDER BY rp.position') as $rrow) {
            $fulllink = checkLinkAvailable('eshop', 'show') ? generateLink('eshop', 'show', array('alt' => $rrow['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'show'), array('alt' => $rrow['url']));
            $rrow['fulllink'] = $fulllink;
            $related_array[$rrow['id']] = $rrow;
        }
        $related_array_ids = array_keys($related_array);
        if (isset($related_array_ids) && !empty($related_array_ids)) {
            $related_string_ids = implode(',', $related_array_ids);
            foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_images i WHERE i.product_id IN (' . $related_string_ids . ') ORDER BY i.position, i.id') as $irow) {
                $related_array[$irow['product_id']]['images'][] = $irow;
            }
            foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_variants v WHERE v.product_id IN (' . $related_string_ids . ') ORDER BY v.position, v.id') as $vrow) {
                $related_array[$vrow['product_id']]['variants'][] = $vrow;
            }
        }
        $SYSTEM_FLAGS['info']['title']['others'] = $row['meta_title'];
        $SYSTEM_FLAGS['info']['title']['group'] = $lang['eshop']['name_plugin'];
        $SYSTEM_FLAGS['meta']['description'] = $row['meta_description'] ? $row['meta_description'] : '';
        $SYSTEM_FLAGS['meta']['keywords'] = $row['meta_keywords'] ? $row['meta_keywords'] : '';
        $cmode = intval(pluginGetVariable('eshop', 'views_count'));
        if ($cmode > 1) {
            // Delayed update of counters
            $mysql->query("insert into " . prefix . "_eshop_products_view (id, cnt) values (" . db_squote($row['id']) . ", 1) on duplicate key update cnt = cnt + 1");
        } else {
            if ($cmode > 0) {
                $mysql->query("update " . prefix . "_eshop_products set views=views+1 where id = " . db_squote($row['id']));
            }
        }
        $cmp_array = array();
        foreach ($SYSTEM_FLAGS["eshop"]["compare"]["entries"] as $cmp_row) {
            $cmp_array[] = $cmp_row['linked_fld'];
        }
        $cmp_flag = in_array($qid, $cmp_array);
        $likes_tpath = locatePluginTemplates(array('likes_eshop'), 'eshop', pluginGetVariable('eshop', 'localsource'), pluginGetVariable('eshop', 'localskin'));
        $likes_xt = $twig->loadTemplate($likes_tpath['likes_eshop'] . 'likes_eshop.tpl');
        $likes = $mysql->record("SELECT COUNT(*) as count FROM " . prefix . "_eshop_products_likes l WHERE l.product_id='" . $qid . "'");
        $likes_tVars = array('count' => $likes['count'], 'id' => $qid);
        $comments_tpath = locatePluginTemplates(array('comments.form_eshop'), 'eshop', pluginGetVariable('eshop', 'localsource'), pluginGetVariable('eshop', 'localskin'));
        $comments_xt = $twig->loadTemplate($comments_tpath['comments.form_eshop'] . 'comments.form_eshop.tpl');
        $comments_tVars = array('id' => $qid);
        $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']));
        $tVars = 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'], 'full_link' => $fulllink, 'edit_link' => admin_url . "/admin.php?mod=extra-config&plugin=eshop&action=edit_product&id=" . $row['id'] . "", 'date' => empty($row['date']) ? '' : $row['date'], 'editdate' => empty($row['editdate']) ? '' : $row['editdate'], 'views' => $row['views'] + 1, 'cat_name' => $row['category'], 'cid' => $row['cid'], 'catlink' => $catlink, 'home' => home, 'tpl_url' => home . '/templates/' . $config['theme'], 'entriesImg' => isset($entriesImg) ? $entriesImg : '', 'entriesVariants' => isset($entriesVariants) ? $entriesVariants : '', 'entriesFeatures' => isset($features_array) ? $features_array : '', 'entriesRelated' => isset($related_array) ? $related_array : '', 'compare' => $cmp_flag, 'likes_form' => $likes_xt->render($likes_tVars), 'comments_form' => $comments_xt->render($comments_tVars));
        $template['vars']['mainblock'] .= $xt->render($tVars);
    } else {
        error404();
    }
}
コード例 #2
0
ファイル: cache.php プロジェクト: stdex/ngcms_eshop
function getCatFromTreeByAlt($arr, $url, &$result_cat)
{
    foreach ($arr as $v) {
        if ($v['url'] == $url) {
            $result_cat = $v;
        }
        if (!empty($v['children'])) {
            getCatFromTreeByID($v['children'], $url, $result_cat);
        }
    }
}