/** * Override or insert variables into the node templates. * * @param $vars * An array of variables to pass to the theme template. * @param $hook * The name of the template being rendered ("node" in this case.) */ function THEMENAME_preprocess_node(&$vars, $hook) { $node = (object)$vars; if (uc_product_is_product($node->type) && variable_get('uc_catalog_breadcrumb', TRUE)) { $crumbs = array(); if (variable_get('site_frontpage', 'node') != 'catalog') { $crumbs[] = l(t('Home'), ''); } $terms = taxonomy_node_get_terms_by_vocabulary($node, variable_get('uc_catalog_vid', 0)); if (count($terms)) { //fix by alexku start //$crumbs[] = l(variable_get('uc_catalog_name', t('Catalog')), variable_get('uc_catalog_url', 'catalog')); global $language; $catalog_name = variable_get('uc_catalog_name', 'Catalog'); $catalog_id = variable_get('uc_catalog_vid', '1'); $translated_name = i18nstrings("taxonomy:vocabulary:$catalog_id:name", $catalog_name, $language->language, FALSE); $crumbs[] = l($translated_name, variable_get('uc_catalog_url', 'catalog')); //fix by alexku end $used_tids = array(); foreach ($terms as $term) { if (!isset($parents[$term->tid])) { $parents[$term->tid] = taxonomy_get_parents_all($term->tid); } //drupal_set_message('
'. print_r($parents[$term->tid], TRUE) .'
'); foreach (array_reverse($parents[$term->tid]) as $parent) { //fix by alexku start $parent->name = i18nstrings("taxonomy:term:$parent->tid:name", $parent->name, $language->language, FALSE); if ($parent->description) { $parent->description = i18nstrings("taxonomy:term:$parent->tid:description", $parent->description, $language->language, FALSE); } //fix by alexku end if (!in_array($parent->tid, $used_tids)) { $crumbs[] = l($parent->name, uc_catalog_path($parent)); $used_tids[] = $parent->tid; } } } } drupal_set_breadcrumb($crumbs); } } /** * Theme the catalog block. * * @ingroup themeable * @see theme_uc_catalog_item() */ function THEMENAME_uc_catalog_block($menu_tree) { $output = ''; return $output; } /** * Multilingual version. Emulate Drupal's menu system, but based soley on the structure of "Product Catalog". * * @param $branch * A treeNode object. Determines if the URL points to itself, * or possibly one of it's children, if present. * * If the URL points to itself or one of its products, it displays its name, and * expands to show its children, otherwise displays a link and a count of the products in it. * If the URL points to one of it's children, it still displays a link and product count, * but must still be expanded. * Otherwise, it is collapsed and a link. * @return * An array whose first element is true if the treeNode is in hierarchy of the URL path. * The second element is the HTML of the list item of itself and it's children. */ function _uc_catalog_navigation_multilingual($branch) { static $terms; static $breadcrumb; static $types; //fix by alexku start global $language; if ($branch->tid) { $branch->name = i18nstrings("taxonomy:term:$branch->tid:name", $branch->name, $language->language, TRUE); if ($branch->description) { $branch->description = i18nstrings("taxonomy:term:$branch->tid:description", $branch->description, $language->language, FALSE); } } //fix by alexku end if (empty($types)) { $types = uc_product_types(); } $num = 0; foreach ($types as $type) { $num += taxonomy_term_count_nodes($branch->tid, $type); } // No nodes in category or descendants. Not in path and display nothing. if (!$num) { return array(FALSE, ''); } $branch_path = uc_catalog_path($branch); if (!isset($breadcrumb)) { $breadcrumb = drupal_get_breadcrumb(); } $vid = variable_get('uc_catalog_vid', 0); if ($_GET['q'] == $branch_path) { // The URL points to this term. $here = TRUE; } else { $here = FALSE; } if (!isset($terms)) { $terms = taxonomy_node_get_terms_by_vocabulary(menu_get_object('node', 1), $vid); } // Determine whether to expand menu item. if ((arg(0) == 'node' && array_key_exists($branch->tid, $terms))) { $inpath = FALSE; foreach ($breadcrumb as $link) { if (strpos($link, drupal_get_path_alias($branch_path)) !== FALSE) { $inpath = TRUE; } } } else { $inpath = $here; } // Checks to see if node counts are desired in navigation $num_text = ''; if (variable_get('uc_catalog_block_nodecount', TRUE)) { $num_text = ' ('. $num .')'; } $lis = array(); $expand = variable_get('uc_catalog_expand_categories', FALSE); $link = l($branch->name . $num_text, $branch_path); if ($expand || count($branch->children)) { foreach ($branch->children as $twig) { // Expand if children are in the menu path. Capture their output. list($child_in_path, $lis[]) = _uc_catalog_navigation_multilingual($twig); if ($child_in_path) { $inpath = $child_in_path; } } } $output = theme("uc_catalog_item", $here, $link, $lis, $expand, $inpath, count($branch->children)); // Tell parent category your status, and pass on output. return array($inpath, $output); } /** * Implementation of hook_preprocess_block(). */ function THEMENAME_preprocess_block(&$variables, $hook) { if ($variables['block']->module == 'uc_catalog' && $variables['block']->delta == '0') { $subject = &$variables['block']->subject; global $language; $catalog_name = variable_get('uc_catalog_name', 'Catalog'); $catalog_id = variable_get('uc_catalog_vid', '1'); $subject = i18nstrings("taxonomy:vocabulary:$catalog_id:name", $catalog_name, $language->language, FALSE); if (variable_get('uc_catalog_block_title', FALSE)) { $subject = l($subject, 'catalog'); } } } function THEMENAME_uc_catalog_browse($tid = 0) { global $language; drupal_add_css(drupal_get_path('module', 'uc_catalog') .'/uc_catalog.css'); $output = ''; $catalog = uc_catalog_get_page((int)$tid); //fix by alexku start //check if we are on the catalog or on the category page if (!$catalog->tid) { //if on catalog page $catalog->name = i18nstrings("taxonomy:vocabulary:$catalog->vid:name", $catalog->name, $language->language, FALSE); if ($catalog->description) { $catalog->description = i18nstrings("taxonomy:vocabulary:$catalog->vid:description", $catalog->description, $language->language, FALSE); } } else { //if on category (term) page $catalog->name = i18nstrings("taxonomy:term:$catalog->tid:name", $catalog->name, $language->language, FALSE); if ($catalog->description) { $catalog->description = i18nstrings("taxonomy:term:$catalog->tid:description", $catalog->description, $language->language, FALSE); } } //fix by alexku end drupal_set_title(check_plain($catalog->name)); drupal_set_breadcrumb(uc_catalog_set_breadcrumb($catalog->tid)); $types = uc_product_types(); $links = array(); $child_list = array(); foreach ($catalog->children as $child) { //fix by alexku start $child->name = i18nstrings("taxonomy:term:$child->tid:name", $child->name, $language->language, FALSE); if ($child->description) { $child->description = i18nstrings("taxonomy:term:$child->tid:description", $child->description, $language->language, FALSE); } //fix by alexku end if (!empty($child->nodes)) { $links[] = array('title' => $child->name . (variable_get('uc_catalog_breadcrumb_nodecount', FALSE) ? ' ('. $child->nodes .')' : ''), 'href' => uc_catalog_path($child), 'attributes' => array('rel' => 'tag'), ); } if (!empty($child->image)) { $image = '
'; if (module_exists('imagecache')) { $image .= l(theme('imagecache', 'uc_category', $child->image['filepath']), uc_catalog_path($child), array('html' => TRUE)); } else { $image .= l(theme('image', $child->image['filepath']), uc_catalog_path($child), array('html' => TRUE)); } $image .= '
'; } else { $image = '
'; } $grandchildren = array(); $j = 0; $max_gc_display = 3; foreach ($child->children as $i => $grandchild) { if ($j > $max_gc_display) { break; } $g_child_nodes = 0; foreach ($types as $type) { $g_child_nodes += taxonomy_term_count_nodes($grandchild->tid, $type); } if ($g_child_nodes) { $grandchildren[$i] = l($grandchild->name, uc_catalog_path($grandchild), array('class' => 'subcategory')); $j++; } } //$grandchildren = array_slice($grandchildren, 0, intval(count($grandchildren) / 2) + 1, TRUE); if ($j > $max_gc_display) { array_push($grandchildren, l(t('More...'), uc_catalog_path($child), array('class' => 'subcategory'))); } if ($child->nodes) { $cell_link = $image .''. l($child->name, uc_catalog_path($child)) .''; if (variable_get('uc_catalog_show_subcategories', TRUE)) { $cell_link .= "
". implode(', ', $grandchildren) ."\n"; } $child_list[] = $cell_link; } } if (!empty($catalog->image)) { if (module_exists('imagecache')) { $output .= theme('imagecache', 'uc_thumbnail', $catalog->image['filepath'], $catalog->name, $catalog->name, array('class' => 'category')); } else { $output .= theme('image', $catalog->image['filepath'], $catalog->name, $catalog->name, array('class' => 'category')); } } // Build an ORDER BY clause for the SELECT query based on table sort info. if (empty($_REQUEST['order'])) { $order = 'ORDER BY p.ordering, n.title, n.nid'; } else { $order = tapirsort_sql(uc_product_table_header()); } $sql = "SELECT DISTINCT(n.nid), n.sticky, n.title, n.created, p.model, p.sell_price, p.ordering FROM {node} n INNER JOIN {term_node} tn ON n.vid = tn.vid INNER JOIN {uc_products} AS p ON n.vid = p.vid WHERE tn.tid = %d AND n.status = 1 AND n.type IN (". db_placeholders($types, 'varchar') .") ". $order; $sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {term_node} tn ON n.vid = tn.vid INNER JOIN {uc_products} AS p ON n.vid = p.vid WHERE tn.tid = %d AND n.status = 1 AND n.type IN (". db_placeholders($types, 'varchar') .")"; $sql = db_rewrite_sql($sql); $sql_count = db_rewrite_sql($sql_count); $sql_args = array($catalog->tid); foreach ($types as $type) { $sql_args[] = $type; } $catalog->products = array(); $result = pager_query($sql, variable_get('uc_product_nodes_per_page', 12), 0, $sql_count, $sql_args); while ($node = db_fetch_object($result)) { $catalog->products[] = $node->nid; } if (count($catalog->products)) { if (count($links)) { $output .= theme('links', $links, array('class' => 'links inline uc-categories')) ."
\n"; } $output .= $catalog->description; $output .= theme('uc_catalog_products', $catalog->products); $output .= theme('pager'); } else { // Display table of child categories similar to an osCommerce site's front page. $columns = variable_get('uc_catalog_category_columns', 3); $cat_rows = array(); $row = array(); $i = 1; foreach ($child_list as $cell) { $row[] = array('data' => $cell, 'class' => 'category'); if ($i % $columns == 0) { $cat_rows[] = $row; $row = array(); } $i++; } if (count($row) > 0 && count($row) < $columns) { if (count($cat_rows) >= 1) { $row = array_merge($row, array_fill(count($row), $columns - count($row), array('data' => ' ', 'class' => 'category'))); } $cat_rows[] = $row; } $output .= $catalog->description; $output .= theme('table', array(), $cat_rows, array('class' => 'category')); } return $output; } /** * The multilingual version of the uc_catalog_set_breadcrumb * Format the breadcrumb to the current term's ancestry. * * @param $tid * The currently viewed catalog term's id. * @param $is_node * If true, include the current category page in the breadcrumb. * @return * An array of breadcrumb links. */ function uc_catalog_set_breadcrumb_multilingual($tid) { static $breadcrumbs = array(); static $terms = array(); if (variable_get('uc_catalog_breadcrumb', TRUE)) { if (empty($breadcrumbs)) { if (variable_get('site_frontpage', 'node') != 'catalog') { $breadcrumbs[] = l(t('Home'), ''); } if ($tid != 0) { //fix by alexku start //$breadcrumbs[] = l(variable_get('uc_catalog_name', t('Catalog')), 'catalog'); global $language; $catalog_name = variable_get('uc_catalog_name', 'Catalog'); $catalog_id = variable_get('uc_catalog_vid', '1'); $translated_name = i18nstrings("taxonomy:vocabulary:$catalog_id:name", $catalog_name, $language->language, FALSE); $breadcrumbs[] = l($translated_name, variable_get('uc_catalog_url', 'catalog')); //fix by alexku end } } $parents = taxonomy_get_parents_all($tid); // Remove current term from the breadcrumb. array_shift($parents); $types = uc_product_types(); while (count($parents)) { $current = array_pop($parents); //fix by miraclegr start $current->name = tt("taxonomy:term:$current->tid:name", $current->name, NULL, FALSE); if ($current->description) { $current->description = tt("taxonomy:term:$current->tid:description", $current->description, NULL, FALSE); } //fix by miraclegr end if (!in_array($current->tid, $terms)) { $n = 0; foreach ($types as $type) { $n += taxonomy_term_count_nodes($current->tid, $type); } $current->nodes = $n; $breadcrumbs[] = l($current->name . (variable_get('uc_catalog_breadcrumb_nodecount', FALSE) && $current->nodes ? ' ('. $current->nodes .')' : ''), uc_catalog_path($current)); $terms[] = $current->tid; } } //print '
'. print_r($breadcrumbs, TRUE) .'
'; return $breadcrumbs; } else { return NULL; } }