All pastes #797919 Raw Edit

Vermischtes

public text v1 · immutable
#797919 ·published 2007-11-26 12:45 UTC
rendered paste body
<?php

function carmesin_menu($may_cache) {
	global $user;

	$links = array();

	if (!$may_cache) {
		if (arg(0) == 'user' && ($user->uid == arg(1))) {
			$links[] = array(
				'path' = 'user/' .$user->uid.'/cart',
				'title' => 'Mein Einkauf',
				'callback' => 'cart_view',
				'access' => true,
				'type' => MENU_LOCAL_TASK,
				'weight' => 10,
			);
		}
		
		if (arg(0) == 'shop') {
			$vocab = taxonomy_get_tree(1, 0, -1, 1);
			foreach ($vocab as $term) {
				$links[] = array(
					'path' => 'shop/' . $term->tid,
					'title' => $term->name,
				        'callback' => 'carmesin_shop',
					'access' => user_access('access content'),
					'type' => MENU_LOCAL_TASK,
					'weight' => $term->weight,
				);
			}
			
// 			$links[] = array(
// 			        'path' => 'shop',
// 				'title' => 'Alles',
// 				'callback' => 'carmesin_shop',
// 				'access' => user_access('access content'),
// 				'type' => MENU_LOCAL_TASK,
// 			        'weight' => -1,
// 			);
		}
		
		$links[] = array(
			'path' => 'shop',
		        'title' => 'Shop',
			'callback' => 'carmesin_shop',
		       	'access' => user_access('access content'),
		);
	}
	return $links;
}

function carmesin_shop() {
	$nodes_per_page = 5;
	$title = 'Shop';
	$term = array();
	if (arg(1) != '') {
		if (is_numeric(arg(1)) && ($term = taxonomy_get_term(arg(1)))) {
			$title = $term->name;
			$tjoin = 'INNER JOIN {term_node} t ON n.nid = t.nid';
			$twhere = "AND t.tid = {$term->tid}";
		} else {
			drupal_not_found();
			exit();
		}
	}
	
	drupal_set_title($title);
	
	$sql = db_rewrite_sql("SELECT n.nid FROM {node} n INNER JOIN {ec_product} p ON n.nid = p.nid $tjoin WHERE pparent = 0 $twhere ORDER BY n.title ASC");
	$result = pager_query($sql, $nodes_per_page);
	
	if (db_num_rows($result) == 0) {
		return "<p>Zur Zeit haben wir leider keine Produkte im Bereich »{$term->name}« im Angebot</p>";
	}
	
	while ($node = db_fetch_object($result)) {
		$o .= node_view(node_load($node->nid), TRUE);
	}
	
	$o .= theme('pager', NULL, $nodes_per_page);
	
	return $o;
}