CONTEXT
We have created a custom taxonomy that is to be displayed as a search filter parameter in third party plugin (in the form of a checkbox). However, we want the list of taxonomies to be displayed ordered by slug.
This is the function that generates the checkbox and outputs the taxonomy - the part that we customized starts at " //create the attributes" .
public function checkbox($args)
{
//init defaults & vars
$input_args = $this->prepare_input_args($args, "checkbox");
$input_name = $input_args['attributes']['name'];
unset($input_args['attributes']['name']);
//filter the input arguments before the html is generated - allowing almost all options to be modified
if(has_filter('sf_input_object_pre')) {
$input_args = apply_filters('sf_input_object_pre', $input_args, $this->sfid);
}
//prepare html
$attibutes_html = $this->convert_attributes_to_html($input_args['attributes']);
$open_child_count = 0;
ob_start();
?>
<ul<?php echo $attibutes_html; ?>>
<?php
$last_option_depth = 0;
$option_count = count($input_args['options']);
$current_depth = 0;
$is_li_open = array();
//echo "<ul>";
for($i=0; $i<$option_count; $i++)
{
$option = &$input_args['options'][$i];
if(!isset($option->attributes))
{
$option->attributes = array(
'class' => '',
'id' => ''
);
}
//check a default has been set and set it
$option->attributes['type'] = "checkbox";
$option->attributes['value'] = $option->value;
$option->attributes['name'] = $input_name;
$option->attributes['html'] = '';
$container_attributes = array();
if($this->is_option_selected($option, $input_args['defaults']))
{
$option->attributes['checked'] = 'checked';
$option->attributes['class'] = trim($option->attributes['class']).' sf-option-active';
}
else
{
if(isset($option->attributes['checked']))
{
unset($option->attributes['checked']);
}
}
//now we want to put the class attribute on the LI, and remove from input
$option_class = $option->attributes['class'];
$option->attributes['class'] = $input_args['input_class'];
$input_id = $this->generate_input_id($input_name."_".$option->value);
$option->attributes['id'] = $input_id;
$container_attibutes_html = "";
if(isset($option->count))
{
$container_attributes['data-sf-count'] = $option->count;
$container_attibutes_html = $this->convert_attributes_to_html($container_attributes);
}
//create the attributes
$input_attibutes_html = $this->convert_attributes_to_html($option->attributes);
$option_label = $option->label;
$option_html = $option->attributes['value'];
if($input_name == "_sft_module_authors[]"){
$tax_name = "module_authors";
} else if ($input_name == "_sft_module_mindset[]") {
$tax_name = "module_mindset";
} else if ($input_name == "_sft_module_language[]") {
$tax_name = "module_language";
} else if ($input_name == "_sft_management_levels[]") {
$tax_name = "management_levels";
} else{
$tax_name = "wpdmcategory";
}
// Get the ID of a given category
$my_term = get_term_by('slug',$option->value,$tax_name);
$category_id = $my_term->term_id;
$category_desc = $my_term->description;
$category_name = $my_term->name;
$meta_image = get_wp_term_image($category_id);
// Get the URL of this category
$category_link = get_category_link( $category_id );
if ($input_name == "_sft_module_authors[]") {
echo '<li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'><input '.$input_attibutes_html.'><label class="sf-label-checkbox" for="'.$input_id.'">' . $category_name . '</label><a class="eModal-post-'.$category_id.'" href="'.$category_link.'"><i class="fa fa-info-circle"></i></a>';
echo do_shortcode("[modal id='post-". $category_id ."' size='small' title='". $category_name ."']". "<div class='col-md-8'>" . $category_desc . "</div>" . "<div class='col-md-4'>" . "<div class='img-wrap'><img src='".$meta_image."'></div></div>" . "[/modal]");
} else if ($input_name == "_sft_module_mindset[]") {
echo '<li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'><input '.$input_attibutes_html.'><label class="sf-label-checkbox" for="'.$input_id.'">' . $category_name . '</label><a class="eModal-post-'.$category_id.'" href="'.$category_link.'"><i class="fa fa-info-circle"></i></a>';
echo do_shortcode("[modal id='post-". $category_id ."' size='small' title='". $category_name ."']". "<div class='col-md-12'>" . $category_desc . "</div>" . "[/modal]");
} else if ($input_name == "_sft_module_language[]") {
echo '<li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'><input '.$input_attibutes_html.'><label class="sf-label-checkbox" for="'.$input_id.'">' . $category_name;
} else if ($input_name == "_sft_management_level[]") {
echo '<li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'><input '.$input_attibutes_html.'><label class="sf-label-checkbox" for="'.$input_id.'">' . $category_name;
} else {
echo '<li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'><input '.$input_attibutes_html.'><label class="sf-label-checkbox" for="'.$input_id.'">' . $category_name . '</label><a class="eModal-post-'.$category_id.'" href="'.$category_link.'"><i class="fa fa-info-circle"></i></a>';
echo do_shortcode("[modal id='post-". $category_id ."' size='small' title='". $category_name ."']". "<div class='col-md-12'>" . $category_desc . "</div>" . "[/modal]");
}
if(isset($option->depth))
{//then we do depth calculations
$current_depth = $option->depth;
$close_li = true;
$open_child_list = false;
$close_ul = false;
$next_depth = -1;
if(isset($input_args['options'][$i+1]))
{
$next_option = $input_args['options'][$i+1];
$next_depth = $next_option->depth;
}
if($next_depth!=-1)
{
if($next_depth!=$current_depth)
{//there is a change in depth
if($next_depth>$current_depth)
{//then we need to open a child list
//and, not close the current li
$open_child_list = true;
$close_li = false;
}
else
{
$close_ul = true;
}
}
}
if($open_child_list)
{
$open_child_count++;
echo '<ul class="children">';
}
if($close_li)
{
echo "</li>";
}
if($close_ul)
{
$diff = $current_depth - $next_depth;
$open_child_count = $open_child_count - $diff;
$str_repeat = str_repeat("</ul></li>", $diff);
echo $str_repeat;
}
}
}
$str_repeat = str_repeat("</ul></li>", (int)$open_child_count);
echo $str_repeat;
?>
</ul>
<?php
$output = ob_get_clean();
return $output;
}
Related
I'm using php CRM that the following code exports the list of all users in database (this list is shown by admin users)
foreach ($rResult as $aRow) {
$row = array();
for ($i = 0; $i < count($aColumns); $i++) {
if (strpos($aColumns[$i], 'as') !== false && !isset($aRow[$aColumns[$i]])) {
$_data = $aRow[strafter($aColumns[$i], 'as ')];
} else {
$_data = $aRow[$aColumns[$i]];
}
if ($aColumns[$i] == 'last_login') {
if ($_data != null) {
$_data = time_ago($_data);
} else {
$_data = 'Never';
}
} elseif ($aColumns[$i] == 'active') {
$checked = '';
if ($aRow['active'] == 1) {
$checked = 'checked';
}
$_data = '<div class="onoffswitch">
<input type="checkbox" data-switch-url="'.admin_url().'staff/change_staff_status" name="onoffswitch" class="onoffswitch-checkbox" id="c_'.$aRow['staffid'].'" data-id="'.$aRow['staffid'].'" ' . $checked . '>
<label class="onoffswitch-label" for="c_'.$aRow['staffid'].'"></label>
</div>';
// For exporting
$_data .= '<span class="hide">' . ($checked == 'checked' ? _l('is_active_export') : _l('is_not_active_export')) . '</span>';
} elseif ($aColumns[$i] == 'firstname') {
$_data = '<a href="' . admin_url('staff/profile/' . $aRow['staffid']) . '">' . staff_profile_image($aRow['staffid'], array(
'staff-profile-image-small'
)) . '</a>';
$_data .= ' ' . $aRow['firstname'] . ' ' . $aRow['lastname'] . '';
} elseif ($aColumns[$i] == 'email') {
$_data = '' . $_data . '';
} else {
if (strpos($aColumns[$i], 'date_picker_') !== false) {
$_data = (strpos($_data, ' ') !== false ? _dt($_data) : _d($_data));
}
}
$row[] = $_data;
}
$options = icon_btn('staff/member/' . $aRow['staffid'], 'pencil-square-o');
if (has_permission('staff', '', 'delete') && $output['iTotalRecords'] > 1 && $aRow['staffid'] != get_staff_user_id()) {
$options .= icon_btn('#', 'remove', 'btn-danger', array(
'onclick'=>'delete_staff_member('.$aRow['staffid'].'); return false;',
));
}
$row[] = $options;
$output['aaData'][] = $row;
}
Ther are 5 admin in the database;
I want to hide one user with staffid = 1 as a backdoor.
How can I delete row with this staffid ?
(I'm not familiar with PHP coding)
Thanks
You can add an if() condition like below:-
foreach ($rResult as $aRow) {
if($aRow['staffid'] !=1){
//complete code inside if
}
}
Note:- I assume that $aRow have staffid as an index
This code is in php file. How I will style tag with "Select Size" and customize the drop down section. Below is one div which i want to style but ht class is created dynamically. And here div drop box are created dynamically and the data entered is also been done dynamically. HELP
$i = 0;
$attribArr = array();
$sizeArr = array();
$colorArr = array();
$colorStr = "color";
$sizeStr = "size";
$phpArray = array(
0 => 001 - 1234567,
1 => 1234567,
2 => 12345678,
3 => 12345678,
4 => 12345678
);
foreach ($order['cart_items'] as $item) {
$i++;
$cssNo = $i % 5;
if ($cssNo == 0) {
$cssNo = 5;
}
$giftcss = "gift-info gift" . $cssNo;
// Get products description
$presult = array();
$productId = $item['product_id'];
$reslt = getProductOptions($productId);
$values = $reslt['values'];
info('option type=' . $reslt['type'] . ' Name=' . $reslt['name']);
$sizeOptionValues = '<option>';
$colorOptionValues = '<option>';
if ($reslt['name'] == 'Size') {
foreach ($values as $value) {
info('vl=' . $value['options_value_name']);
$sizeOptionValues.= str_replace(' ', '', $value['options_value_name']) . '</option><option>';
}
}
if ($reslt['name'] == 'Color') {
foreach ($values as $value) {
info('vl=' . $value['options_value_name']);
$colorOptionValues.= $value['options_value_name'] . '</option><option>';
}
}
$pquery = "SELECT products_description, pr.products_image, products_name FROM "
. TABLE_PRODUCTS_DESCRIPTION . " AS pd JOIN " . TABLE_PRODUCTS . " as pr ON pr.products_id = pd.products_id WHERE pd.products_id=" . $productId;
$presult = $db->Execute($pquery);
$product_name = $presult->fields['products_name'];
$product_image = $presult->fields['products_image'];
$product_desc = $presult->fields['products_description'];
$prodImgs = explode(".", $product_image);
$prodImg0 = $prodImgs[0];
$prodImgExt = $prodImgs[1];
$prod_img_name = $prodImg0 . 'v.' . $prodImgExt;
info("getOrder", "Product Name=" . $product_name . " prod image=" . $prod_img_name);
$prod_desc_url = EL_PROD_DESC_PATH . $productId;
$prodAttrQry = "SELECT * FROM " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " WHERE products_prid = " . $productId . " AND orders_id = " . $orderId;
$attrReslt = $db->Execute($prodAttrQry);
$color = false;
$colorValue = '';
$size = false;
$sizeValue = '';
$personalised = false;
$attr = false;
$personalisedMsg = '';
if ($attrReslt->RecordCount() > 0) {
$attr = true;
$attrArr = array();
while (!$attrReslt->EOF) {
$optName = $attrReslt->fields['products_options'];
$optValue = $attrReslt->fields['products_options_values'];
if ($optName == 'Size') {
$size = true;
$sizeValue = $optValue;
} else if ($optName == 'Color') {
$color = true;
$colorValue = $optValue;
} else if ($optName == '') {
$personalised = true;
$rslt = explode(".", $optValue);
if ((isset($rslt[1]) && $rslt[1] == 'jpg') || (isset($rslt[1]) && $rslt[1] == 'png')) {
$personalisedMsg = "<b>Uploaded Image</b> " . "<br><img style = 'width:200px; height:200px;'src = '$optValue'/>";
} else {
$personalisedMsg = '<b>Personal Message</b><br>' . $optValue;
}
}
$sizeArr[$i] = $sizeValue;
$colorArr[$i] = $colorValue;
$attribArr['personalise_val' . $i] = $personalisedMsg;
$attrReslt->MoveNext();
}
}
$colorVisibility = 'none';
$sizeVisibility = 'none';
$personalisedVisib = 'none';
$headlineVisib = 'none';
if ($color) {
$colorVisibility = 'inline';
$headlineVisib = 'inline';
}
if ($size) {
$sizeVisibility = 'inline';
$headlineVisib = 'inline';
}
if ($personalised) {
$personalisedVisib = 'inline';
}
$secondScreen .= <<
<div class="{$giftcss}">
<input type="hidden" name= "product_id{$i}" value="{$productId}"/>
<div class="gift-img"><img src="http://{$domainName}/gifts/images/{$prod_img_name}" height="250"></div>
<div class="divider"></div><div class="gift-desc"><h3>{$product_name}</h3><span>{$product_desc}</span></div>
<div style="width:100%;"><h3 style="display:{$headlineVisib}">Customize your gift</h3><br>
<p style="display:{$sizeVisibility};">Select Size<select id = "prod_size{$i}" name="prod_size{$i}" >{$sizeOptionValues}</select></p>
<p style="display:{$colorVisibility};">Select Color<select id = "prod_color{$i}" name="prod_color{$i}" >{$colorOptionValues}</select></p>
<p style="display:{$personalisedVisib};">{$personalisedMsg}</p></div>
MARKUP;
$secondScreen .= <<<MARKUP
Im not entirely sure what you mean? But if it's what I think you mean. To print out your php values into the class='' attribute you would:
<div class="<?php echo $giftcss; ?>">
<input type="hidden" name= "product_id<?php echo $i; ?>" value="{$productId}"/>
<div class="gift-img">
<img src="http://<?php echo $domainName; ?>/gifts/images/<?php echo $prod_img_name; ?>" height="250"></div>
Simply <?php echo $variable; ?> into each html attribute.
I have no idea where to get size value and input it to my database
this is my database table called transaksi with these column
idtransaksi, noinvoice, idproduk, size, jumlah
and here is my script
chart.php
<?php
if (!isset($_SESSION)) {
session_start();
}
cek_status_login($_SESSION['idpelanggan']);
include ('chart.inc.php');
// Process actions
$chart = isset ($_SESSION['chart']) ? $_SESSION['chart'] : '';
$action = isset($_GET['action']) ? $_GET['action'] : '';
switch ($action) {
case 'add' :
if ($chart) {
$chart .= ',' . $_GET['id'];
} else {
$chart = $_GET['id'];
}
break;
//
//B002,5,S,B003,10,M
case 'delete' :
if ($chart) {
$items = explode(',', $chart);
$newchart = '';
foreach ($items as $item) {
if ($_GET['id'] != $item) {
if ($newchart != '') {
$newchart .= ',' . $item;
} else {
$newchart = $item;
}
}
}
$chart = $newchart;
}
break;
case 'update' :
if ($chart) {
$newchart = '';
foreach ($_POST as $key => $value) {
if (stristr($key, 'qty')) {
$id = str_replace('qty', '', $key);
$items = ($newchart != '') ? explode(',', $newchart) : explode(',', $chart);
$newchart = '';
foreach ($items as $item) {
if ($id != $item) {
if ($newchart != '') {
$newchart .= ',' . $item;
} else {
$newchart = $item;
}
}
}
for ($i = 1; $i <= $value; $i++) {
if ($newchart != '') {
$newchart .= ',' . $id;
} else {
$newchart = $id;
}
}
}
}
}
$chart = $newchart;
break;
}
$_SESSION['chart'] = $chart;
?>
<section class="main-content">
<div class="row">
<div class="span9">
<?php echo writeShoppingchart();
echo showchart();
if (isset($_GET['s'])) {
if ($_GET['status'] == OK) {
echo "proses pembelian berhasil dilakukan sudah selesai";
} else {
echo "operasi gagal";
}
}
?>
</div>
<script type="text/javascript">
$('.input').on('input',function(e){
if($(this).data("lastval")!= $(this).val()){
$(this).data("lastval",$(this).val());
//change action
alert('Anda Mengubah Jumlah SubTotal barang, Silahkan Update Keranjang Belanja');
};
});
</script>
<?php
include ('inc/sidebar-front.php');
?>
</div>
</section>
chart.inc.php
<?php
function kd_transaksi() {
$kode_temp = fetch_row("SELECT noinvoice FROM invoice ORDER BY noinvoice DESC LIMIT 0,1");
if ($kode_temp == '')
$kode = "E00001";
else {
$jum = substr($kode_temp, 1, 6);
$jum++;
if ($jum <= 9)
$kode = "E0000" . $jum;
elseif ($jum <= 99)
$kode = "E000" . $jum;
elseif ($jum <= 999)
$kode = "E00" . $jum;
elseif ($jum <= 9999)
$kode = "E0" . $jum;
elseif ($jum <= 99999)
$kode = "E" . $jum;
else
die("Kode pemesanan melebihi batas");
}
return $kode;
}
function writeShoppingchart() {
$chart = $_SESSION['chart'];
if (!$chart) {
return '<h4 class="title"><span class="text pull-left"><strong>Keranjang Belanja Masih Kosong</strong></span></h4>';
} else {
// Parse the chart session variable
$items = explode(',', $chart);
$s = (count($items) > 1) ? 's' : '';
return '<h4 class="title"><span class="text pull-left"><strong>Periksa Jumlah Pesanan Anda Sebelum Check Out</strong></span></h4>';
}
}
function chartNotification() {
$chart = $_SESSION['chart'];
if (!$chart) {
return '0';
} else {
// Parse the chart session variable
$items = explode(',', $chart);
return count($items);
}
}
function getQty() {
$chart = $_SESSION['chart'];
if (!$chart) {
return 0;
} else {
// Parse the chart session variable
$items = explode(',', $chart);
$s = (count($items) > 1) ? 's' : '';
return count($items);
}
}
function showchart() {
$chart = $_SESSION['chart'];
// print_r($chart);
if ($chart) {
$items = explode(',', $chart);
$contents = array();
$total='';
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
$output[] = "<table class=\"table table-striped \">";
$output[] = "<th><td>Nama</td><td>size</td><td> Harga</td><td>jumlah</td><td>diskon</td><td>subtotal</td><td>Aksi</td></th>";
$output[] = '<form action="index.php?mod=chart&pg=chart&action=update" method="post" id="chart">';
$no = 1;
foreach ($contents as $id => $qty) {
$sql = "SELECT produk.*, stok.harga_barang, stok.harga_jual, stok.jumlah, stok.ext_disc, stok.disc, stok.size FROM stok LEFT OUTER JOIN produk ON stok.idproduk = produk.idproduk WHERE produk.idproduk = '$id'";
$result = mysql_query($sql);
$row = mysql_fetch_object($result);
$size = explode(',', $row->size);
$quantity = ($row->jumlah);
$diskonext =(($row->harga_jual)*($row->ext_disc)/100);
$output[] = '<tr><td>' . $no . '</td>';
$output[] = '<td>'.$row ->nama_produk. '<br /><img src=\'upload/produk/' . $row ->foto .' \' width=\'100px\' height=\'100px\'></td>';
$output[] = '<td><select name="size" style="width:50px;">';
for ($i = 0; $i < count($size); $i++){
$output[] = '<option value="'. $size[$i] .'">'. $size[$i] .'</option>';
}
$output[] = '</select></td>';
$output[] = '<td>' . format_rupiah($row -> harga_barang) . '</td>';
if ($qty >= 10){
$total += (($row -> harga_jual) - $diskonext) * $qty;
}else {
$total += $row -> harga_jual * $qty;
}
if ($qty > $quantity){
$output[] = '<td><input type="text" class="input-mini" name="qty' . $id . '" value="'.$quantity.'"/><br /><span class="label label-warning pull-right">Stok hanya '.$quantity.'</span></td>';
} else {
$output[] = '<td><input type="text" onkeypress="alert(\'jumlah barang terganti, silahkan Update Keranjang belanja anda sebelum chekout\');" class="input-mini" name="qty' . $id . '" value="' . $qty . '"/></td>';
}
if ($qty >= 10){
$output[] = '<td>' . $row->disc . ' % + '. $row -> ext_disc .'% </td>';
} else {
$output[] = '<td>' . $row->disc . ' %</td>';
}
if ($qty >= 10){
if ($qty > $quantity){
$output[] = '<td>'.format_rupiah(($row->harga_jual - $diskonext)*$quantity).'</td>';
} else {
$output[] = '<td>'.format_rupiah(($row->harga_jual - $diskonext)*$qty).'</td>';
}
}else{
if ($qty >= $quantity){
$output[] = '<td>'.format_rupiah($row->harga_jual*$quantity).'</td>';
} else {
$output[] = '<td>'.format_rupiah($row->harga_jual*$qty).'</td>';
}
}
$output[] = '<td>Hapus</td></tr>';
$no++;
}
$output[] = '<tr><td colspan=\'6\' ><h4>Total Belanja Anda</h4></td><td colspan=\'2\'><h4>'. format_rupiah($total) .'</h4></td></tr>';
$output[] = "</table>";
$qty = getQty();
$_SESSION['totalbayar'] = $total;
$output[] = '<button type="submit" class=\'btn btn-primary\'>Update Keranjang Belanja</button>';
if ($qty >= ($row->jumlah)){
$output[] ='<button type="submit" class=\'btn btn-success pull-right\'>Update Keranjang Belanja Anda</button>';
} else {
$output[] ='<a href=\'chart/chart_action.php\' class=\'btn btn-success pull-right\'>Check out</a>';
}
$output[] = '</form>';
} else {
$output[] = '<p>Keranjang belanja masih kosong.</p>';
}
return join('', $output);
}
function insertToDB($kd_transaksi, $idpelanggan, $totalbayar, $sizes) {
$chart = isset($_SESSION['chart'])? $_SESSION['chart']: '';
if ($chart) {
$items = explode(',', $chart);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
$sql_transaksi = "insert into invoice (noinvoice,tanggal,totalbayar,idpelanggan)
values( '$kd_transaksi', now(),'$totalbayar','$idpelanggan')";
//echo "SQL transaksi:".$sql_transaksi;
mysql_query($sql_transaksi) or die(mysql_error());
foreach ($contents as $id => $qty) {
$sql = "insert into transaksi(noinvoice,idproduk,size,jumlah)
values('$kd_transaksi','$id','$sizes','$qty')";
// echo "SQL transaksi:".$sql;
$result = mysql_query($sql) or die(mysql_error());
}
} else {
$output[] = '<p>Keranjang belanja masih kosong.</p>';
}
}
?>
and chart.action.php
<?php
session_start();
require_once ('../inc/config.php');
require_once ('../inc/function.php');
require_once ('../chart/chart.inc.php');
$idpelanggan=$_SESSION['idpelanggan'];
/* menambahkan kode pesan dan detail pesan kedalam database*/
$kd_transaksi = kd_transaksi();
$total_bayar = $_SESSION['totalbayar'];
insertToDB($kd_transaksi,$idpelanggan,$total_bayar);
//check if query successful
$link="location:../index.php?mod=chart&pg=chart_ship&total_bayar=$total_bayar&kd_transaksi=$kd_transaksi";
header($link);
?>
Still get confused how to input size value to database. and if you need more information to help me just tell me what I have to do
Thanks
The function insertToDB is defined with 4 parameters in the code above:
function insertToDB($kd_transaksi, $idpelanggan, $totalbayar, $sizes) {
But it is called with only 3 values:
insertToDB($kd_transaksi,$idpelanggan,$total_bayar);
So I suggest passing the value posted for variable size when calling the function:
insertToDB($kd_transaksi,$idpelanggan,$total_bayar,$_POST["size"]);
Btw: commenter #giraff is absolutely right when meaning the SQL injection. Your scripts are vulnerable to it. You should definitely check and sanitize user-submitted data!
I what to put a span element for $term['nodes']
I have tried to put after bracket and between but nothing works for me
if (isset($term['nodes'])) {
$term['name'] = $term['name'] . ' (' . $term['nodes'] . ')';
}
here is the all functin
function bootstrap_taxonomy_menu_block($variables) {
$tree = $variables['items'];
$config = $variables['config'];
$num_items = count($tree);
$i = 0;
$output = '<ul class="nav nav-pills nav-stacked">';
foreach ($tree as $tid => $term) {
$i++;
// Add classes.
$attributes = array();
if ($i == 1) {
$attributes['class'][] = '';
}
if ($i == $num_items) {
$attributes['class'][] = '';
}
if ($term['active_trail'] == '1') {
$attributes['class'][] = 'active-trail';
}
if ($term['active_trail'] == '2') {
$attributes['class'][] = 'active';
}
// Alter link text if we have to display the nodes attached.
if (isset($term['nodes']))
{
$term['name'] = $term['name'] . ' (<span>' . $term['nodes'] . '</span>)';
}
// Set alias option to true so we don't have to query for the alias every
// time, as this is cached anyway.
$output .= '<li' . drupal_attributes($attributes) . '>' . l($term['name'], $term['path'], $options = array('alias' => TRUE));
if (!empty($term['children'])) {
$output .= theme('taxonomy_menu_block__' . $config['delta'], (array('items' => $term['children'], 'config' => $config)));
}
$output .= '</li>';
}
$output .= '</ul>';
return $output;
}
i what this for the bootstrap cdn class , i have move the function on template.php , of drupal theme , but the span element is in plain text in browser
Try this:
if (isset($term['nodes']))
{
$term['name'] = $term['name'] . ' (<span>' . $term['nodes'] . '</span>)';
echo $term['name']; // To see the output
}
Hi I am try to display icecat product data and I am a complete php newbie, I have tracked down a code snippet that I believe should do the job, It says that It requires that you feed the function with an EAN product number.
Could someone please give me an example of what this means as I have no idea, here is a EAN Product number EAN/UPC code:0885909481842
Here is the snippet code I am trying to use.
function getICEcatProductSpecs($ean, $drawdescription = 0, $drawpicture = 0)
{
// Username and password for usage with ICEcat
$username = "Your ICEcat username goes here";
$password = "Your ICEcat password goes here";
// Return 0 and exit function if no EAN available
if($ean == null)
{
return 0;
}
// Get the product specifications in XML format
$context = stream_context_create(array(
'http' => array(
'header' => "Authorization: Basic " . base64_encode($username.":".$password)
)
));
$data = file_get_contents('http://data.icecat.biz/xml_s3/xml_server3.cgi?ean_upc='.$ean.';lang=nl;output=productxml', false, $context);
$xml = new SimpleXMLElement($data);
// Create arrays of item elements from the XML feed
$productPicture = $xml->xpath("//Product");
$productDescription = $xml->xpath("//ProductDescription");
$categories = $xml->xpath("//CategoryFeatureGroup");
$spec_items = $xml->xpath("//ProductFeature");
//Draw product specifications table if any specs available for the product
if($spec_items != null)
{
$categoryList = array();
foreach($categories as $categoryitem) {
$catId = intval($categoryitem->attributes());
$titleXML = new SimpleXMLElement($categoryitem->asXML());
$title = $titleXML->xpath("//Name");
$catName = $title[0]->attributes();
//echo $catId . $catName['Value']. "<br />";
$categoryList[$catId] = $catName['Value'];
}
$specs = "<table class='productspecs'>";
$i = 0;
$drawnCategories = array();
foreach($spec_items as $item) {
$specValue = $item->attributes();
$titleXML = new SimpleXMLElement($item->asXML());
$title = $titleXML->xpath("//Name");
$specName = $title[0]->attributes();
$specCategoryId = intval($specValue['CategoryFeatureGroup_ID']);
if($specName['Value'] != "Source data-sheet")
{
$class = $i%2==0?"odd":"even";
$specs .= "<tr class='".$class."'>
<td>
<table>";
if(!in_array($specCategoryId, $drawnCategories))
{
$specs .= " <tr class='speccategory'>
<th><h3>".$categoryList[$specCategoryId]."</h3></th>
</tr>";
$drawnCategories[$i] = $specCategoryId;
}
$specs .= " <tr>
<th>".utf8_decode($specName['Value']).":</th>
</tr>
<tr>
<td>";
if($specValue['Presentation_Value'] == "Y")
{
$specs .= "Ja <img src='".SCRIPT_ROOT."images/check_green.png' alt='Ja' />";
}
else if($specValue['Presentation_Value'] == "N")
{
$specs .= "Nee <img src='".SCRIPT_ROOT."images/check_red.png' alt='Nee' />";
}
else
{
$specs .= str_replace('\n', '<br />', utf8_decode($specValue['Presentation_Value']));
}
$specs .= "</td>
</tr>
</table>
</td>
</tr>";
}
$i++;
}
$specs .= "</table>";
//Draw product description and link to manufacturer if available
if( $drawdescription != 0)
{
foreach($productDescription as $item) {
$productValues = $item->attributes();
if($productValues['URL'] != null)
{
$specs .= "<p id='manufacturerlink'><a href='".$productValues['URL']."'>Productinformation from manufacturer</a></p>";
}
if($productValues['LongDesc'] != null)
{
$description = utf8_decode(str_replace('\n', '', $productValues['LongDesc']));
$description = str_replace('<b>', '<strong>', $description);
$description = str_replace('<B>', '<strong>', $description);
$description = str_replace('</b>', '</strong>', $description);
$specs .= "<p id='manudescription'>".$description."</p>";
}
}
}
//Draw product picture if available
if( $drawdescription != 0)
{
foreach($productPicture as $item) {
$productValues = $item->attributes();
if($productValues['HighPic'] != null)
{
$specs .= "<div id='manuprodpic'><img src='".$productValues['HighPic']."' alt='' /></div>";
}
}
}
return $specs;
}
else
{
return 0;
}
}
Any advice will be very appreciated thx in advance Peter
My understanding is that it's saying that if you call this function you should pass EAN parameter to it, like this:
getICEcatProductSpecs("0885909481842", 0, 0);