欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

一个template的例子

shiping1 的头像
<?php
 
 
/**
 * Implementation of HOOK_theme().
 */
function shipingzhong_theme(& $existing, $type, $theme, $path) {
$hooks = zen_theme($existing, $type, $theme, $path);
// Add your theme hooks like this:
/*
$hooks['hook_name_here'] = array( // Details go here );
*/
// @TODO: Needs detailed comments. Patches welcome!
return $hooks;
}
 
/**
 * Override or insert variables into all templates.
 *
 * @param $vars
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered (name of the .tpl.php file.)
 */
/* -- Delete this line if you want to use this function
function shipingzhong_preprocess(&$vars, $hook) {
  $vars['sample_variable'] = t('Lorem ipsum.');
}
// */
 
/**
 * Override or insert variables into the page templates.
 *
 * @param $vars
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered ("page" in this case.)
 */
/* -- Delete this line if you want to use this function
function shipingzhong_preprocess_page(&$vars, $hook) {
  $vars['sample_variable'] = t('Lorem ipsum.');
 
  // To remove a class from $classes_array, use array_diff().
  //$vars['classes_array'] = array_diff($vars['classes_array'], array('class-to-remove'));
}
// */
 
/**
 * 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.)
 */
/* -- Delete this line if you want to use this function
function shipingzhong_preprocess_node(&$vars, $hook) {
  $vars['sample_variable'] = t('Lorem ipsum.');
 
  // Optionally, run node-type-specific preprocess functions, like
  // shipingzhong_preprocess_node_page() or shipingzhong_preprocess_node_story().
  $function = __FUNCTION__ . '_' . $vars['node']->type;
  if (function_exists($function)) {
    $function($vars, $hook);
  }
}
// */
 
/**
 * Override or insert variables into the comment templates.
 *
 * @param $vars
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered ("comment" in this case.)
 */
/* -- Delete this line if you want to use this function
function shipingzhong_preprocess_comment(&$vars, $hook) {
  $vars['sample_variable'] = t('Lorem ipsum.');
}
// */
 
/**
 * Override or insert variables into the block templates.
 *
 * @param $vars
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered ("block" in this case.)
 */
 
function shipingzhong_preprocess_block(&$vars, $hook) {
 
// dpr($vars['block']->bid);
// dpr($vars['block_id']);
//   dpr($vars['block_html_id']);
//   var_dump("AAAAAAAAAA");
//var_dump(get_defined_vars());
// var_dump("BBBBBBBBBBB");
// dpr($vars);
// var_dump("CCCCCCCC");
// dpr($vars['block']);
// dpr($vars);exit;
 
if ($vars['block_html_id'] == 'block-uc_cart-0') {
//var_dump(get_defined_vars());
//dpr($vars);
//dpr($vars['block']);
//dpr($vars);exit;
//unset($vars['block']);
 
}
 
 
}
 
function shipingzhong_uc_cart_block_content($help_text, $items, $item_count, $item_text, $total, $summary_links) {
//  $output = '';
//
//  // Add the help text if enabled.
//  if ($help_text) {
//    $output .= '<span class="cart-help-text">'. $help_text .'</span>';
//  }
//
//  // Add a wrapper div for use when collapsing the block.
//  $output .= '<div id="cart-block-contents">';
//
//  // Add a table of items in the cart or the empty message.
//  $output .= theme('uc_cart_block_items', $items);
//
//  $output .= '</div>';
 
// Add the summary section beneath the items table.
 
$output = theme('uc_cart_block_summary', $item_count, $item_text, $total, $summary_links);
 
return $output;
}
 
function shipingzhong_uc_cart_block_summary($item_count, $item_text, $total, $summary_links) {
 
$context = array (
'revision' => 'themed-original',
'type' => 'amount',
 
);
$output = '<div class="cart-block-summary">';
// If there are products in the cart...
if ($item_count > 0) {
unset ($summary_links['cart-block-checkout']);
// Add a view cart link.
 
}
$output .= l('购物车', $summary_links['cart-block-view-cart']['href'], array (
'attributes' => array (
'rel' => $summary_links['cart-block-view-cart']['attributes']['rel']
)
)) . '';
// Build the basic div with the number of items in the cart and total.
$output .= '(<span style="color:#FF0000;"> ' . $item_count . ' </span>)';
 
$output .= '</div>';
 
return $output;
}
 
//重写分页
function shipingzhong_item_list($items = array (), $title = NULL, $type = 'ul', $attributes = NULL) {
$output = '<li class="item-list">';
if (isset ($title)) {
$output .= '<h3>' . $title . '</h3>';
}
 
if (!empty ($items)) {
$output .= "<$type" . drupal_attributes($attributes) . '>';
$num_items = count($items);
foreach ($items as $i => $item) {
$attributes = array ();
$children = array ();
if (is_array($item)) {
foreach ($item as $key => $value) {
if ($key == 'data') {
$data = $value;
}
elseif ($key == 'children') {
$children = $value;
} else {
$attributes[$key] = $value;
}
}
} else {
$data = $item;
}
if (count($children) > 0) {
$data .= theme_item_list($children, NULL, $type, $attributes); // Render nested list
}
if ($i == 0) {
$attributes['class'] = empty ($attributes['class']) ? 'first' : ($attributes['class'] . ' first');
}
if ($i == $num_items -1) {
$attributes['class'] = empty ($attributes['class']) ? 'last' : ($attributes['class'] . ' last');
}
$output .= '<li' . drupal_attributes($attributes) . '>' . $data . "</li>\n";
}
$output .= "</$type>";
}
$output .= '</li>';
return $output;
}
 
//node.tpl.php预处理
function shipingzhong_preprocess_node(& $vars) {
 
global $links;
$links = $vars['links'];
$node = $vars['node'];
// if $vars['teaser'] 是什么意思 是概要吧
if ($node->type == 'kecheng' || $node->type == 'jiaocheng') {
$taxonomys = $vars['node']->taxonomy;
$vars['node']->currJiaoChenKecheng = _getCurrJiaoChenKecheng($taxonomys);
$vars['node']->jiaoChenKechengDesc = _getJiaoChenKechengDesc($taxonomys);
if ($vars['teaser']) {
$vars['node']->field_jiao_chen_desc[0][value] = truncate_utf8($vars['node']->field_jiao_chen_desc[0][value], 100);
}
if ($vars['page']) {
$vars['node']->field_jiao_chen_desc[0][value] = truncate_utf8($vars['node']->field_jiao_chen_desc[0][value], 150);
}
$laoshis = $vars['node']->field_laoshi;
 
if (!empty ($laoshis)) {
foreach ($laoshis as $oneKey => $oneValue) {
$uid = $oneValue['uid'];
$laoshiInfo = user_load($uid);
$laoshis[$oneKey]['laoshiInfo'] = $laoshiInfo;
//$laoshis[$oneKey]['laoshiInfohtml'] = _htmlLaoshiInfo($laoshiInfo);
}
}
 
$vars['node']->field_laoshi = $laoshis;
$vars['down_comments_links'] = "<a href=\"/node/" . $vars['node']->nid . "#comments\">相关评论</a>";
if (empty ($vars['node']->comment_count)) {
$vars['node']->nocomment = '暂无评论';
}
}
 
if ($node->type == 'question' || $node->type == 'answer') {
$vars['node']->content['body']['#value'] = strip_tags($vars['node']->content['body']['#value']);
 
}
if ($node->type == 'answer') {
//echo dsm($vars['node']);
//var_dump($vars['node']->links['vud_node_votes_count']['title']);exit;
if (strpos($vars['node']->links['vud_node_votes_count']['title'], "total\">-1") > 0) {
$vars['node']->links['vud_node_votes_count']['title'] = str_replace('votes', '反对', $vars['node']->links['vud_node_votes_count']['title']);
$vars['node']->links['vud_node_votes_count']['title'] = str_replace('-', '', $vars['node']->links['vud_node_votes_count']['title']);
} else {
$vars['node']->links['vud_node_votes_count']['title'] = str_replace('votes', '支持', $vars['node']->links['vud_node_votes_count']['title']);
}
$vars['node']->links['vud_node_votes_count']['title'] = str_replace("total\">", "total\">计", $vars['node']->links['vud_node_votes_count']['title']);
}
$vars['created'] = format_date($vars['created'], 'custom', 'Y年m月d日 H:i:s');
}
 
//page.tpl.php 预处理
function shipingzhong_preprocess_page(&$variables, $hook) {
 
$css = $variables['css'];
 
if ((!_startWith($_GET['q'], 'admin/build/block')) && (!_startWith($_GET['q'], 'advupload'))
&& ((!_startWith($_GET['q'], 'taxonomy')) && (!_startWith($_GET['q'], 'order'))) && (!_endWith($_GET['q'], 'batchUpdateUsersRole'))) {
unset ($css['all']['module']['modules/system/system.css']);
unset ($css['all']['module']['modules/system/system-menus.css']);
}
$variables['styles'] = drupal_get_css($css);
if((_startWith($_GET['q'], 'laoshiupload')))
{
 
$scripts = drupal_add_js();
unset($scripts['core']['misc/tabledrag.js']);
 
$variables['scripts']=drupal_get_js('header', $scripts);
$variables['scripts_custom']=drupal_get_js('header', $scripts);
 
}
 
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nodeObj = node_load(arg(1));
 
if ($nodeObj->type == 'kecheng') {
$variables['template_files'][] = 'page-node-kecheng';
else if ($nodeObj->type == 'jiaocheng') {
$variables['template_files'][] = 'page-node-jiaocheng';
}
   else if ($nodeObj->type == 'question') {
$variables['template_files'][] = 'page-node-tiwen';
}
   else if ($nodeObj->type == 'jiaochengshipingobj') {
$variables['template_files'][] = 'page-node-jiaochengshipingobj';
}
else if ($nodeObj->type == 'youkushiping') {
$variables['template_files'][] = 'page-node-youkushiping';
}
 
}
if (arg(0) == 'taxonomy' && arg(1) == 'term') {
if (is_numeric(arg(2))) {
$tid = intval(arg(2));
//假如 是 4 是课程 或者培养模式(我们认为属于课程)
if (_getVocabularyIdByTid($tid) == 4 || _getVocabularyIdByTid($tid) == 5) {
 
$variables['template_files'][] = 'page-taxonomy-term-kecheng';
}
//假如 是 3 是教程
else
if (_getVocabularyId($tid) == 3) {
$variables['template_files'][] = 'page-taxonomy-term-jiaocheng';
}
}
}
if(arg(0)=='jifenshangcheng' || arg(0)=='jifenshangchengasc' || arg(0)=='jifenshangchengdesc'){
$variables['template_files'][] = 'page-jifenshangcheng';
 
}
if (arg(0) == 'nodeorder' && arg(1) == 'term') {
if (is_numeric(arg(2))) {
$tid = intval(arg(2));
//假如 是 4 是课程 或者培养模式(我们认为属于课程)
if (_getVocabularyIdByTid($tid) == 4 || _getVocabularyIdByTid($tid) == 5) {
 
$variables['template_files'][] = 'page-nodeorder-term-kecheng';
}
//假如 是 3 是教程
else
if (_getVocabularyId($tid) == 3) {
$variables['template_files'][] = 'page-nodeorder-term-jiaocheng';
}
}
}
if (arg(0) == 'user') {
 
 
preg_match_all('/<li(.*?)>(.*?)<\/li>/ism',$variables['tabs'],$outLi,PREG_PATTERN_ORDER);
$variablestabs='<ul class="tabs primary clearfix mytab usertabs">';
foreach($outLi[0] as $key=>$value){
 
if(!$variables['is_admin']){//假如不是管理员的时候 只用  用户个人资料 和 编辑 两个tab
if(!strrpos($value,'用户个人资料')>0 && !strrpos($value,'编辑')&& !strrpos($value,'查看')>0  ){
continue;
}
}
// if(!empty($_GET['destination'])){
// $value = preg_replace('/href="(.*)"/misU','href="$1?destination='.$_GET['destination'].'"',$value);
//
// }
 
 
$variablestabs .= $value;
}
 
$variablestabs .='</ul>';
$variables['tabs'] = $variablestabs;
 
 
}
if(arg(0)=='user' && arg(1)=='batchUpdateUsersRole')
{
$variables['template_files'][] = 'page-mybiji';
 
}
 
 
}
 
function shipingzhong_taxonomy_term_page($tids, $result) {
//drupal_add_css(drupal_get_path('module', 'taxonomy') .'/taxonomy.css');
$output = '';
$output .= taxonomy_render_nodes($result);
return $output;
}
 
function shipingzhong_preprocess_comment(& $vars, $hook) {
//$vars['classes_array'][]='mycomment';
$created = $vars['comment']->timestamp;
$vars['created'] = format_date($created, 'custom', 'Y-m-d H:i:s');
//不能对评论进行回复 删除Drupal评论中的Reply链接
$links = $vars['links'];
 
$links = preg_replace("#(<a href=\"/comment/reply(.*)>回复</a>)#iUs", "", $links);
 
$vars['links'] = $links;
 
}
 
function shipingzhong_preprocess_comment_wrapper(& $vars) {
global $links;
$vars['links'] = $links;
 
$vars['classes_array'][] = 'mycommentcontainer';
 
}
 
//添加新评论
function shipingzhong_links($links, $attributes = array (
'class' => 'links'
), $heading = '') {
global $language;
$output = '';
 
if (count($links) > 0) {
// Treat the heading first if it is present to prepend it to the
// list of links.
if (!empty ($heading)) {
if (is_string($heading)) {
// Prepare the array that will be used when the passed heading
// is a string.
$heading = array (
'text' => $heading,
// Set the default level of the heading.
'level' => 'h2',
 
);
}
$output .= '<' . $heading['level'];
if (!empty ($heading['class'])) {
$output .= drupal_attributes(array (
'class' => $heading['class']
));
}
$output .= '>' . check_plain($heading['text']) . '</' . $heading['level'] . '>';
}
 
$output .= '<ul' . drupal_attributes($attributes) . '>';
 
$num_links = count($links);
$i = 1;
 
foreach ($links as $key => $link) {
$class = $key;
 
// Add first, last and active classes to the list of links to help out themers.
if ($i == 1) {
$class .= ' first';
}
if ($i == $num_links) {
$class .= ' last';
}
if (isset ($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page())) && (empty ($link['language']) || $link['language']->language == $language->language)) {
$class .= ' active';
}
$output .= '<li' . drupal_attributes(array (
'class' => $class
)) . '>';
 
if (isset ($link['href'])) {
// Pass in $link as $options, they share the same keys.
$output .= l($link['title'], $link['href'], $link);
} else
if (!empty ($link['title'])) {
// Some links are actually not links, but we wrap these in <span> for adding title and class attributes
if (empty ($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$span_attributes = '';
if (isset ($link['attributes'])) {
$span_attributes = drupal_attributes($link['attributes']);
}
$output .= '<span' . $span_attributes . '>' . $link['title'] . '</span>';
}
 
$i++;
$output .= "</li>\n";
}
 
$output .= '</ul>';
}
 
return $output;
}
 
function shipingzhong_preprocess(& $vars, $hook) {
//var_dump($vars['template_files']);
}
 
/**
 * Implements theme_menu_item_link()
 */
function shipingzhong_menu_item_link($link) {
 
if (empty ($link['localized_options'])) {
$link['localized_options'] = array ();
}
 
// If an item is a LOCAL TASK, render it as a tab
if ($link['type'] & MENU_IS_LOCAL_TASK) {
 
$link['title'] = '<span class="tab">' . check_plain($link['title']) . '</span>';
$link['localized_options']['html'] = TRUE;
}
 
return l($link['title'], $link['href'], $link['localized_options']);
}
 
/**
 * Duplicate of theme_menu_local_tasks() but adds clearfix to tabs.
 */
function shipingzhong_menu_local_tasks() {
$output = '';
 
// CTools requires a different set of local task functions.
if (module_exists('ctools')) {
ctools_include('menu');
 
$primary = ctools_menu_primary_local_tasks();
 
$secondary = ctools_menu_secondary_local_tasks();
} else {
 
$primary = menu_primary_local_tasks();
$secondary = menu_secondary_local_tasks();
}
 
if ($primary) {
$output .= '<ul class="tabs primary clearfix mytab">' . $primary . '</ul>';
}
if ($secondary) {
$output .= '<ul class="tabs secondary clearfix">' . $secondary . '</ul>';
}
 
return $output;
}
 
function shipingzhong_menu_local_task($link, $active = FALSE) {
return '<li ' . ($active ? 'class="active w140" ' : 'class="w140" ') . '>' . $link . "</li>\n";
}
 
//覆写面包屑
function shipingzhong_breadcrumb_bak($breadcrumb) {
// Determine if we are to display the breadcrumb.
$show_breadcrumb = theme_get_setting('zen_breadcrumb');
if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') {
 
// Optionally get rid of the homepage link.
$show_breadcrumb_home = theme_get_setting('zen_breadcrumb_home');
if (!$show_breadcrumb_home) {
array_shift($breadcrumb);
}
 
// Return the breadcrumb with separators.
if (!empty ($breadcrumb)) {
$breadcrumb_separator = theme_get_setting('zen_breadcrumb_separator');
$trailing_separator = $title = '';
if (theme_get_setting('zen_breadcrumb_title')) {
if ($title = drupal_get_title()) {
$trailing_separator = $breadcrumb_separator;
}
}
elseif (theme_get_setting('zen_breadcrumb_trailing')) {
$trailing_separator = $breadcrumb_separator;
}
 
//var_dump($breadcrumb);var_dump(drupal_get_title());exit;
//drupal6 current   drupal7 current_path();
 
$breadcrumb[] = l(drupal_get_title(), $_GET['q']);
return '<li class="fl">' . implode($breadcrumb_separator, $breadcrumb) . "$trailing_separator$title</li>";
}
}
// Otherwise, return an empty string.
return '';
}
 
function shipingzhong_breadcrumb($breadcrumb) {
 
// Determine if we are to display the breadcrumb.
$show_breadcrumb = theme_get_setting('zen_breadcrumb');
if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') {
 
// Optionally get rid of the homepage link.
$show_breadcrumb_home = theme_get_setting('zen_breadcrumb_home');
if (!$show_breadcrumb_home) {
array_shift($breadcrumb);
}
 
// Return the breadcrumb with separators.
if (!empty ($breadcrumb)) {
$breadcrumb_separator = theme_get_setting('zen_breadcrumb_separator');
$trailing_separator = $title = '';
if (theme_get_setting('zen_breadcrumb_title')) {
if ($title = drupal_get_title()) {
$trailing_separator = $breadcrumb_separator;
}
}
elseif (theme_get_setting('zen_breadcrumb_trailing')) {
$trailing_separator = $breadcrumb_separator;
}
 
//var_dump($breadcrumb);exit;
//$breadcrumb[]= l(drupal_get_title(),$_GET['q']);
return '<span class="breadcrumb">' . implode($breadcrumb_separator, $breadcrumb) . "$trailing_separator$title</span>";
}
}
// Otherwise, return an empty string.
return '';
}
 
//这个函数为什么不起作用 难道没有注册
function shipingzhong_node_created($created) {
//return  format_date($created,'custom','Y年m月d日 H:i:s');
}
 
function shipingzhong_views_mini_pager__all_questions__block_1($tags = array (), $limit = 10, $element = 0, $parameters = array (), $quantity = 9) {
global $pager_page_array, $pager_total;
 
// Calculate various markers within this pager piece:
// Middle is used to "center" pages around the current page.
$pager_middle = ceil($quantity / 2);
// current is the page we are currently paged to
$pager_current = $pager_page_array[$element] + 1;
// max is the maximum page number
$pager_max = $pager_total[$element];
// End of marker calculations.
 
$li_previous = theme('pager_previous', (isset ($tags[1]) ? $tags[1] : t('‹‹')), $limit, $element, 1, $parameters);
if (empty ($li_previous)) {
$li_previous = "&nbsp;";
}
 
$li_next = theme('pager_next', (isset ($tags[3]) ? $tags[3] : t('››')), $limit, $element, 1, $parameters);
if (empty ($li_next)) {
$li_next = "&nbsp;";
}
 
if ($pager_total[$element] > 1) {
$items[] = array (
'class' => 'pager-previous',
'data' => $li_previous,
 
);
 
//    $items[] = array(
//      'class' => 'pager-current',
//      'data' => t('@current of @max', array('@current' => $pager_current, '@max' => $pager_max)),
//    );
 
$items[] = array (
'class' => 'pager-next',
'data' => $li_next,
 
);
$items[0]['data'] = str_replace('‹‹', '上页', $items[0]['data']);
$items[1]['data'] = str_replace('››', '下页', $items[1]['data']);
return "<div class='minipager'>" . $items[0]['data'] . $items[1]['data'] . "</div>";
//return theme('item_list', $items, NULL, 'ul', array('class' => 'pager'));
}
}
 
function shipingzhong_views_mini_pager__all_questions__block_2($tags = array (), $limit = 10, $element = 0, $parameters = array (), $quantity = 9) {
global $pager_page_array, $pager_total;
 
// Calculate various markers within this pager piece:
// Middle is used to "center" pages around the current page.
$pager_middle = ceil($quantity / 2);
// current is the page we are currently paged to
$pager_current = $pager_page_array[$element] + 1;
// max is the maximum page number
$pager_max = $pager_total[$element];
// End of marker calculations.
 
$li_previous = theme('pager_previous', (isset ($tags[1]) ? $tags[1] : t('‹‹')), $limit, $element, 1, $parameters);
if (empty ($li_previous)) {
$li_previous = "&nbsp;";
}
 
$li_next = theme('pager_next', (isset ($tags[3]) ? $tags[3] : t('››')), $limit, $element, 1, $parameters);
if (empty ($li_next)) {
$li_next = "&nbsp;";
}
 
if ($pager_total[$element] > 1) {
$items[] = array (
'class' => 'pager-previous',
'data' => $li_previous,
 
);
 
//    $items[] = array(
//      'class' => 'pager-current',
//      'data' => t('@current of @max', array('@current' => $pager_current, '@max' => $pager_max)),
//    );
 
$items[] = array (
'class' => 'pager-next',
'data' => $li_next,
 
);
 
$items[0]['data'] = str_replace('‹‹', '上页', $items[0]['data']);
$items[1]['data'] = str_replace('››', '下页', $items[1]['data']);
 
return "<div class='minipager'>" . $items[0]['data'] . $items[1]['data'] . "</div>";
//return theme('item_list', $items, NULL, 'ul', array('class' => 'pager'));
}
}
 
//重写到购物车表单(这是商品)
function shipingzhong_uc_product_add_to_cart($node, $teaser = 0, $page = 0) {
//假如是列表页
if ($teaser == '1') {
$output = '<div class="add-to-cart-shipingzhonglist">';
if ($node->nid) {
$output .= drupal_get_form('uc_product_add_to_cart_form_' . $node->nid, $node);
} else {
$output .= drupal_get_form('uc_product_add_to_cart_form', $node);
}
$output .= '</div>';
return $output;
else if ($teaser == '2') {
$node->zhijietianjia = true;
$output = '<div class="add-to-cart-shipingzhonglist2">';
if ($node->nid) {
$output .= drupal_get_form('uc_product_add_to_cart2_form_' . $node->nid, $node);
} else {
$output .= drupal_get_form('uc_product_add_to_cart_form', $node);
}
$output .= '</div>';
return $output;
   } 
   else {
$output = '<div class="add-to-cart-shipingzhong">';
if ($node->nid) {
$output .= drupal_get_form('uc_product_add_to_cart_form_' . $node->nid, $node);
} else {
$output .= drupal_get_form('uc_product_add_to_cart_form', $node);
}
$output .= '</div>';
return $output;
}
}
 
//重写到购物车表单(这是商品包)
function shipingzhong_uc_product_kit_add_to_cart($node, $teaser = 0, $page = 0) {
//假如是列表页
if ($teaser == '1') {
$output = '<div class="add-to-cart-shipingzhonglist">';
if ($node->nid) {
$output .= drupal_get_form('uc_product_kit_add_to_cart_form_' . $node->nid, $node);
} else {
$output .= drupal_get_form('uc_product_kit_add_to_cart_form', $node);
}
$output .= '</div>';
return $output;
} else
if ($teaser == '2') {
$node->zhijietianjia = true;
$output = '<div class="add-to-cart-shipingzhonglist2">';
if ($node->nid) {
$output .= drupal_get_form('uc_product_kit_add_to_cart2_form_' . $node->nid, $node);
} else {
$output .= drupal_get_form('uc_product_kit_add_to_cart_form', $node);
}
$output .= '</div>';
return $output;
} else {
$output = '<div class="add-to-cart-shipingzhong" title="' . t('Click to add to cart.') . '">';
if ($node->nid) {
$output .= drupal_get_form('uc_product_kit_add_to_cart_form_' . $node->nid, $node);
} else {
$output .= drupal_get_form('uc_product_kit_add_to_cart_form', $node);
}
$output .= '</div>';
return $output;
}
}
 
function shipingzhong_tapir_table($element) {
$header = array ();
$rows = array ();
 
// First sort the columns by weight.
uasort($element['#columns'], 'uc_weight_sort');
 
// Loop through the columns and create the header array.
foreach ($element['#columns'] as $col_id => $col_data) {
// Add the cell if available.
if (!isset ($col_data['access']) || $col_data['access'] !== FALSE) {
$header[] = $col_data['cell'];
}
}
 
// Loop through the row data and create rows with the data in the right order.
foreach ($element['#rows'] as $data) {
$attributes = array ();
$row = array ();
 
/* // If the row combines cell data with attributes...
if (isset($data['data'])) {
 // Set the attributes array to be everything in the row array except the
 // data array.
 $attributes = $data;
 unset($attributes['data']);
 
 // Filter the data array down to just the cell data.
 $data = $data['data'];
} */
 
// Loop through each column in the header.
foreach ($element['#columns'] as $col_id => $col_data) {
// If this row defines cell data for the current column...
if ((!isset ($col_data['access']) || $col_data['access'] !== FALSE) && isset ($data[$col_id])) {
$cell = array ();
if (isset ($data[$col_id]['#cell_attributes']) && is_array($data[$col_id]['#cell_attributes'])) {
foreach ($data[$col_id]['#cell_attributes'] as $property => $value) {
if ($property == 'colspan' && $value == 'full') {
// Extend full-width cells to the number of columns actually
// displayed.
$value = count($header);
}
$cell[$property] = $value;
}
$cell['data'] = drupal_render($data[$col_id]);
} else {
 
$cell = drupal_render($data[$col_id]);
}
// Add it to the row array.
$row[] = $cell;
}
}
 
// Merge the row data into a single row array along with the attributes.
if (isset ($data['#attributes'])) {
$row = array_merge(array (
'data' => $row
), (array) $data['#attributes']);
}
 
// Add the current row to the table rows array.
$rows[] = $row;
}
foreach ($rows as $key => $value) {
if (count($value['data']) <= 1 && empty ($value['data'][0])) {
unset ($rows[$key]);
}
}
$rows = array_values($rows);
 
// Return the rendered table.
return theme('table', $header, $rows, (array) $element['#attributes'], $element['#title']) . (isset ($element['#children']) ? $element['#children'] : '');
}
 
//重写quicktabs 目的是为了增加表单
function shipingzhong_quicktabs($quicktabs) {
  return quicktabs_render_shipingzhong($quicktabs);
}
 
function quicktabs_render_shipingzhong($quicktabs) {
 
  // Allow other modules to alter the Quicktabs instance before it gets output.
  drupal_alter('quicktabs', $quicktabs);
  // convert views arguments to an array, retrieving %-style args from url
  $quicktabs['tabs'] = _quicktabs_prepare_views_args($quicktabs['tabs']);
 
  if ($quicktabs['hide_empty_tabs'] && !$quicktabs['ajax']) {
    // Remove empty tabpgages.
    foreach ($quicktabs['tabs'] as $key => $tab) {
      $contents = quicktabs_render_tabpage_shipingzhong($tab, TRUE);
      if (empty($contents)) {
        $quicktabs['tabs'][$key] = NULL;
      }
      else {
        $quicktabs['tabs'][$key]['rendered'] = $contents;
      }
    }
  }
 
  $tabs_count = count($quicktabs['tabs']);
  if ($tabs_count <= 0) {
    return '';
  }
 
  if ($quicktabs['style'] == 'default') {
    $quicktabs['style'] = variable_get('quicktabs_tabstyle', 'nostyle');
  }
 
  quicktabs_add_css($quicktabs['style']);
  $javascript = drupal_add_js('misc/progress.js', 'core');
  if (!isset($javascript['setting'][1]['quicktabs']) || !array_key_exists('qt_'. $quicktabs['machine_name'], $javascript['setting'][1]['quicktabs'])) {
    // Only the tabs are used in quicktabs.js
    $settings = array(
      'tabs' => $quicktabs['ajax'] ? $quicktabs['tabs'] : quicktabs_array_fill_keys(array_keys(array_filter($quicktabs['tabs'])), 0),
    );
    drupal_add_js(array('quicktabs' => array('qt_'. $quicktabs['machine_name'] => $settings)), 'setting');
  }
  drupal_add_js(drupal_get_path('module', 'quicktabs') .'/js/quicktabs.js');
 
  $attributes = drupal_attributes(array(
    'id' => 'quicktabs-'. $quicktabs['machine_name'],
    'class' => 'quicktabs_wrapper quicktabs-style-'. drupal_strtolower($quicktabs['style']),
  ));
  $output = '<div'. $attributes .'>';
  $active_tab = _quicktabs_get_active_tab($quicktabs);
  $output .= theme('quicktabs_tabs', $quicktabs, $active_tab);
 
  // The main content area, each quicktab container needs a unique id.
  $attributes = drupal_attributes(array(
    'id' => 'quicktabs_container_'. $quicktabs['machine_name'],
    'class' => 'quicktabs_main quicktabs-style-'. drupal_strtolower($quicktabs['style']),
  ));
  $output .= '<div'. $attributes .'>';
 
  if ($quicktabs['ajax']) {
 
    // Prepare ajax views.
    _quicktabs_prepare_views($quicktabs['tabs']);
    // Render only the active tabpage.
    if (isset($active_tab)) {
      $attributes = drupal_attributes(array(
        'id' => 'quicktabs_tabpage_'. $quicktabs['machine_name'] .'_'. $active_tab,
        'class' => 'quicktabs_tabpage',
      ));
      $output .= '<div'. $attributes .'>'. quicktabs_render_tabpage_shipingzhong($quicktabs['tabs'][$active_tab]) .'</div>';
      
      
    }
    // We need page preprocessing to populate Drupal.quicktabs.scripts when js aggregation is on.
    quicktabs_has_rendered_ajax_tab(TRUE);
  }
  else {
 
    // Render all tabpgages.
    foreach ($quicktabs['tabs'] as $key => $tab) {
      $attributes = drupal_attributes(array(
        'id' => 'quicktabs_tabpage_'. $quicktabs['machine_name'] .'_'. $key,
        'class' => 'quicktabs_tabpage'. ($active_tab == $key ? '' : ' quicktabs-hide'),
      ));
      $tab_content = isset($tab['rendered']) ? $tab['rendered'] : quicktabs_render_tabpage_shipingzhong($tab);
         //$tab_content = $tab['rendered'];
//      if($tab['machine_name']=='jiaochengbiji'){
//      
//       $output .= '<div'. $attributes .'>'.drupal_get_form('biji_form') .$tab_content .'</div>';
//      }else if($tab['machine_name']=='jiaochengwenda'){
//       $output .= '<div'. $attributes .'>'. drupal_get_form('tiwen_form') .$tab_content .'</div>';
//      }else{
//       $output .= '<div'. $attributes .'>'. $tab_content .'</div>';
//      }
      $output .= '<div'. $attributes .'>'. $tab_content .'</div>';
    }
  }
 
  $output .= '</div></div>';
 
  return $output;
}
 
 
function quicktabs_render_tabpage_shipingzhong($tab, $hide_empty = FALSE) {
  static $cache;
 
  $cachekey = md5(serialize($tab));
  if (isset($cache[$cachekey])) {
    return $cache[$cachekey];
  }
 
  $output = '';
  switch ($tab['type']) {
    case 'qtabs':
      if (isset($tab['machine_name'])) {
        if ($quicktabs = quicktabs_load($tab['machine_name'])) {
          $output = theme('quicktabs', $quicktabs);
        }
      }
      break;
 
    case 'view':
      if (isset($tab['vid'])) {
        if (module_exists('views')) {
          if ($view = views_get_view($tab['vid'])) {
            if ($view->access($tab['display'])) {
              $view->set_display($tab['display']);
              $view->set_arguments($tab['args']);
              $view_output = $view->preview();
              if (!empty($view->result) || $view->display_handler->get_option('empty') || !empty($view->style_plugin->definition['even empty'])) {
                $output = $view_output;
              }
              else {
                $output = '';
              }
              $arg0 = arg(0);$arg1 = arg(1);
              $obj=node_load($arg1);
              if($obj->type=='jiaochengshipingobj'){
               if($tab['vid']=='bijibyjiaocheng' && $tab['display']=='block_1'){
              $output = drupal_get_form('biji_form').$output;
             }
             if($tab['vid']=='tiwenbyjiaocheng' && $tab['display']=='block_1'){
              $output = drupal_get_form('tiwen_shiping_form').$output;
             }
              }
             
              
            }
            elseif (!$hide_empty) {
              $output = theme('quicktabs_tab_access_denied', $tab);
            }
            $view->destroy();
          }
        }
        elseif (!$hide_empty) {
          $output = t('Views module not enabled, cannot display tab content.');
        }
      }
      break;
 
    case 'block':
      if (isset($tab['bid'])) {
        // Ensure the block is assigned to the requested quicktabs block. This test prevents
        // AJAX access to blocks that have not been added to an AJAX-enabled quicktabs block.
        // The qt_name key is set only for AJAX requests.
        if (isset($tab['qt_name'])) {
          $break = TRUE;
          $quicktabs = quicktabs_load($tab['qt_name']);
          // Ensure AJAX is enabled for the quicktabs block.
          if (!empty($quicktabs) && $quicktabs['ajax'] == 1) {
            // Ensure the requested tab has been added to the quicktabs block.
            foreach ($quicktabs['tabs'] as $quicktab) {
              if (isset($quicktab['bid']) && ($quicktab['bid'] == $tab['bid'])) {
                $break = FALSE;
                break;
              }
            }
          }
          if ($break == TRUE) {
            if (!$hide_empty) {
              $output = theme('quicktabs_tab_access_denied', $tab);
            }
            break;
          }
        }
        $pos = strpos($tab['bid'], '_delta_');
        $blockmodule = substr($tab['bid'], 0, $pos);
        $blockdelta = substr($tab['bid'], $pos + 7);
        $access = _quictabs_access_block($blockmodule, $blockdelta);
        if ($access) {
          $block = (object) module_invoke($blockmodule, 'block', 'view', $blockdelta);
          if (isset($block->content)) {
            $block->module = $blockmodule;
            $block->delta = $blockdelta;
            $block->region = 'quicktabs_tabpage';
            if ($tab['hide_title'] || !isset($block->subject)) {
              $block->subject = FALSE;
            }
            $output = theme('block', $block);
          }
        }
        else {
          $output = theme('quicktabs_tab_access_denied', $tab);
        }
      }
      break;
 
    case 'node':
      if (isset($tab['nid'])) {
        $node = node_load($tab['nid']);
        if (!empty($node)) {
          if (node_access('view', $node)) {
            $output = node_view($node, $tab['teaser'], $tab['hide_title'], TRUE);
          }
          elseif (!$hide_empty) {
            $output = theme('quicktabs_tab_access_denied', $tab);
          }
        }
      }
      break;
 
    case 'freetext':
      $output = $tab['text'];
      break;
    case 'callback':
      $output = menu_execute_active_handler($tab['path']);
      break;
  }
 
  $cache[$cachekey] = $output;
 
  return $output;
}
普通分类: