function eshop_downloads_manager() { global $wpdb, $eshopoptions; $table = $wpdb->prefix . "eshop_downloads"; $ordertable = $wpdb->prefix . "eshop_download_orders"; $dir_upload = eshop_download_directory(); $atitle = ''; if (isset($_POST['up'])) { //borrowed this bit from wordpress $file_error_strings = array(false, __("The uploaded file exceeds the <code>upload_max_filesize</code> directive in <code>php.ini</code>."), __("The uploaded file exceeds the <em>MAX_FILE_SIZE</em> directive that was specified in the HTML form."), __("The uploaded file was only partially uploaded."), __("No file was uploaded."), __("Missing a temporary folder."), __("Failed to write file to disk.")); $error = ''; $new_name = ""; if ($_POST['title'] != '') { if (function_exists('check_upload_size')) { //for MU check_upload_size($_FILES["upfile"]); } $replace = array("'", "\"", "&", " "); $file_name = str_replace($replace, "_", $_FILES["upfile"]["name"]); if (trim($_FILES["upfile"]["name"]) == "") { $error .= "<p>" . __('No file indicated', 'eshop') . "</p>"; } if (!file_exists($dir_upload . $file_name) || $_POST['overwrite'] == 'yes') { if (@is_uploaded_file($_FILES["upfile"]["tmp_name"])) { if (!file_exists($dir_upload . $file_name)) { $newfile = 'y'; } if (move_uploaded_file($_FILES["upfile"]["tmp_name"], $dir_upload . $file_name)) { $success = '<p>' . __('File moved', 'eshop') . '</p>'; } else { $error .= '<p>' . __('Failed to move file', 'eshop') . '</p>'; } } else { $error .= "<p>" . __('Error uploading file', 'eshop') . " " . $_FILES["upfile"]["name"] . " <strong>" . $file_error_strings[$_FILES["upfile"]["error"]] . "</strong></p>"; } } else { $error .= "<p>" . __('Error uploading file', 'eshop') . " " . $_FILES["upfile"]["name"] . " " . __('it <strong>already exists!</strong>', 'eshop') . "</p>"; } } else { $error .= '<p>' . __('A title must be provided.', 'eshop') . '</p>'; } if (isset($success) && !isset($newfile)) { $entfile = $wpdb->escape($file_name); $dafile = $wpdb->get_var("SELECT id FROM {$table} WHERE files='{$entfile}'"); $enttitle = $wpdb->escape($_POST['title']); $wpdb->query("UPDATE {$table} SET title='{$enttitle}',added=NOW() WHERE id={$dafile}"); echo '<div id="message" class="updated fade"><p>' . $_FILES["upfile"]["name"] . " " . __('has successfully overwritten existing file', 'eshop') . '</p></div>'; do_action('eshop_file_upload', $dafile, $_POST); //file id & post variables } elseif ($error == '') { //ie a successful upload $enttitle = $wpdb->escape($_POST['title']); $entfile = $wpdb->escape($file_name); $wpdb->query("INSERT INTO {$table} (title,added,files) VALUES ('{$enttitle}',NOW(),'{$entfile}')"); $dafile = $wpdb->get_var("SELECT id FROM {$table} WHERE files='{$entfile}'"); do_action('eshop_file_upload', $dafile, $_POST); //file id & post variables echo '<div id="message" class="updated fade"><p>' . $_FILES["upfile"]["name"] . " " . __('has successfully uploaded', 'eshop') . '</p></div>'; } else { //ie a failed upload echo '<div id="message" class="error fade">' . $error . '</div>'; $atitle = $_POST['title']; } unset($_GET['edit']); } if (isset($_POST['editdelete'])) { // deleting entry $delid = $wpdb->escape($_POST['delid']); $delfile = $wpdb->get_var("SELECT files FROM {$table} WHERE id ={$delid}"); $filepath = $dir_upload . $delfile; @unlink($filepath); $wpdb->query("DELETE FROM {$table} WHERE id = {$delid}"); echo '<div id="message" class="updated fade"><p>' . __('File deleted successfully', 'eshop') . '</p></div>'; unset($_GET['edit']); } //when edit a file this is the bit that gets used. if (isset($_POST['editamend'])) { if (is_numeric($_POST['downloads']) && is_numeric($_POST['purchases']) && $_POST['title'] != '') { //add in mysql update here $query = 'UPDATE ' . $table . ' SET title = "' . $wpdb->escape($_POST['title']) . '", downloads = "' . $wpdb->escape($_POST['downloads']) . '", purchases = "' . $wpdb->escape($_POST['purchases']) . '" WHERE id = "' . $wpdb->escape($_POST['id']) . '"'; $wpdb->query("{$query}"); do_action('eshop_file_upload_amend', $_POST['id'], $_POST); //file id & post variables echo '<div id="message" class="updated fade"><p>' . __('File updated successfully', 'eshop') . '</p></div>'; } else { //error handling if ($_POST['title'] == '') { $error .= '<li>' . __('The title for the file cannot be blank!', 'eshop') . '</li>'; } if (!is_numeric($_POST['downloads'])) { $error .= '<li>' . __('Downloads should to be a number!', 'eshop') . '</li>'; } if (!is_numeric($_POST['purchases'])) { $error .= '<li>' . __('Purchases should to be a number!', 'eshop') . '</li>'; } echo '<div id="message" class="error fade"><p>' . __('Some errors were found:', 'eshop') . '</p><ul>' . $error . '</ul></div>'; } } if (isset($_GET['eshop_orphan'])) { if (is_array(eshop_contains_files())) { foreach (eshop_contains_files() as $filename) { $file = $wpdb->escape($filename); list($title, $ext) = explode('.', $filename); $title = $wpdb->escape($title); $wpdb->query("INSERT INTO {$table} (title,added,files) VALUES ('{$title}',NOW(),'{$file}')"); } } } if (isset($_GET['edit'])) { $id = $wpdb->escape($_GET['edit']); if ($wpdb->get_var("SELECT title FROM {$table} WHERE id ={$id}") != '') { //ie exists //echo '<div id="message" class="updated fade"><p>found it</p></div>'; $row = $wpdb->get_row("SELECT * FROM {$table} WHERE id ={$id}"); ?> <div class="wrap"> <div id="eshopicon" class="icon32"></div><h2><?php _e('Edit File details', 'eshop'); ?> </h2> <?php eshop_admin_mode(); ?> <table class="widefat" summary="<?php _e('downloadable file details', 'eshop'); ?> "> <caption><?php _e('File details', 'eshop'); ?> </caption> <thead> <tr> <th id="edid"><?php _e('ID', 'eshop'); ?> </th> <th id="edtitle"><?php _e('Title', 'eshop'); ?> </th> <th id="edsize"><?php _e('Size', 'eshop'); ?> </th> <th id="edfile"><?php _e('File name', 'eshop'); ?> </th> <th id="eddate"><?php _e('Upload Date', 'eshop'); ?> </th> <th id="eddown"><?php _e('Downloads', 'eshop'); ?> </th> <th id="edpurc"><?php _e('Purchases', 'eshop'); ?> </th> <?php $echo = ''; echo apply_filters('eshop_download_table_extrahead', $echo); ?> </tr> </thead> <tbody> <?php $size = eshop_filesize($row->files); $label = strlen($row->title) >= 20 ? substr($row->title, 0, 20) . "…" : $row->title; echo "<tr>\n"; echo '<td id="redid' . $row->id . '" headers="edid">#' . $row->id . "</td>\n"; echo '<td headers="edtitle redid' . $row->id . '">' . $label . "</td>\n"; echo '<td headers="edsize redid' . $row->id . '">' . eshop_read_filesize($size) . "</td>\n"; echo '<td headers="edfile redid' . $row->id . '">' . $row->files . "</td>\n"; echo '<td headers="eddate redid' . $row->id . '">' . $row->added . "</td>\n"; echo '<td headers="eddown redid' . $row->id . '">' . $row->downloads . "</td>\n"; echo '<td headers="edpurc redid' . $row->id . '">' . $row->purchases . "</td>\n"; $echo = ''; echo apply_filters('eshop_download_table_extracell', $echo, $row); echo "</tr>\n"; ?> </tbody> </table> <?php $pchk = checkfordownloads($id); if ($pchk['0'] == '1') { echo '<p class="productassociation">' . __('This file is associated with the following product pages:', 'eshop') . '</p>'; echo '<ul class="productpages">'; foreach ($pchk['1'] as $myrow) { echo '<li><a href="post.php?action=edit&post=' . $myrow . '" title="edit ' . get_the_title($myrow) . '">' . get_the_title($myrow) . '</a></li>'; } echo '</ul>'; ?> <p><?php _e('You can only delete this file if it is <strong>not</strong> associated with a product page.', 'eshop'); ?> </p> <?php } ?> <form method="post" action="" id="downloadedit"> <fieldset><legend><?php _e('Amend File details', 'eshop'); ?> </legend> <input type="hidden" name="id" value="<?php echo $row->id; ?> " /> <label for="filetitle"><?php _e('Title', 'eshop'); ?> </label><input type="text" name="title" id="filetitle" size="35" value="<?php echo $row->title; ?> " /><br /> <label for="downloads"><?php _e('Downloads', 'eshop'); ?> </label><input type="text" name="downloads" id="downloads" size="5" value="<?php echo $row->downloads; ?> " /><br /> <label for="purchases"><?php _e('Purchases', 'eshop'); ?> </label><input type="text" name="purchases" id="purchases" size="5" value="<?php echo $row->purchases; ?> " /><br /> <?php $echo = ''; echo apply_filters('eshop_downloads_form_amend', $echo, $row); ?> </fieldset> <p class="submit"><input type="submit" name="editamend" value="<?php _e('Amend details', 'eshop'); ?> " class="button" /></p> </form> </div> <?php if ($pchk['0'] == '0') { ?> <div class="wrap"> <h2><?php _e('Delete', 'eshop'); ?> </h2> <form method="post" action="" id="downloaddelete"> <input type="hidden" name="delid" value="<?php echo $row->id; ?> " /> <p class="submit"><input type="submit" name="editdelete" value="<?php _e('Delete File', 'eshop'); ?> '<?php echo $row->title; ?> '" class="button" /></p> </form> </div> <?php } } else { //ie does not exist echo '<div id="message" class="error fade"><p>' . __('Product not found', 'eshop') . '.</p></div>'; } } else { //first page you see $cda = $cdd = $cta = $cdwa = $cpa = $cia = ''; if (isset($_GET['by'])) { switch ($_GET['by']) { case 'dd': //date descending $sortby = 'ORDER BY added DESC'; $cdd = ' class="current"'; break; case 'da': //date ascending $sortby = 'ORDER BY added ASC'; $cda = ' class="current"'; break; case 'ta': //title alphabetically $sortby = 'ORDER BY title ASC'; $cta = ' class="current"'; break; case 'dwa': //number of downloads $sortby = 'ORDER BY downloads ASC'; $cdwa = ' class="current"'; break; case 'pa': //number of purchases $sortby = 'ORDER BY purchases ASC'; $cpa = ' class="current"'; break; case 'ia': //id //id default: $sortby = 'ORDER BY id ASC'; $cia = ' class="current"'; } } else { $cia = ' class="current"'; $sortby = 'ORDER BY id ASC'; } $range = 10; $max = $wpdb->get_var("SELECT COUNT(id) FROM {$table} WHERE id > 0"); if ($eshopoptions['records'] != '' && is_numeric($eshopoptions['records'])) { $records = $eshopoptions['records']; } else { $records = '10'; } if (isset($_GET['_p']) && is_numeric($_GET['_p'])) { $epage = $_GET['_p']; } else { $epage = '1'; } if (!isset($_GET['eshopall'])) { $page_links = paginate_links(array('base' => add_query_arg('_p', '%#%'), 'format' => '', 'total' => ceil($max / $records), 'current' => $epage, 'type' => 'array')); $offset = $epage * $records - $records; } else { $page_links = paginate_links(array('base' => add_query_arg('_p', '%#%'), 'format' => '', 'total' => ceil($max / $records), 'current' => $epage, 'type' => 'array', 'show_all' => true)); $offset = '0'; $records = $max; } if ($max > 0) { $myrowres = $wpdb->get_results("Select * From {$table} {$sortby} LIMIT {$offset}, {$records}"); //work out totals for quick stats $total = 0; $purchased = 0; $mycounts = $wpdb->get_row("Select SUM(downloads) as dlcount, SUM(purchases) as pucount From {$table}"); $total = $mycounts->dlcount; $purchased = $mycounts->pucount; ?> <div class="wrap"> <div id="eshopicon" class="icon32"></div><h2><?php _e('Downloadable Products', 'eshop'); ?> </h2> <?php eshop_admin_mode(); ?> <?php $apge = get_admin_url() . 'admin.php?page=eshop-downloads.php'; echo '<ul id="eshopsubmenu" class="stuffbox">'; echo '<li><span>' . __('Sort Orders by »', 'eshop') . '</span></li>'; echo '<li><a href="' . $apge . '&by=ia"' . $cia . '>' . __('ID Number', 'eshop') . '</a></li>'; echo '<li><a href="' . $apge . '&by=ta"' . $cta . '>' . __('Title', 'eshop') . '</a></li>'; echo '<li><a href="' . $apge . '&by=da"' . $cda . '>' . __('Date Ascending', 'eshop') . '</a></li>'; echo '<li><a href="' . $apge . '&by=dd"' . $cdd . '>' . __('Date Descending', 'eshop') . '</a></li>'; echo '<li><a href="' . $apge . '&by=dwa"' . $cdwa . '>' . __('Downloads', 'eshop') . '</a></li>'; echo '<li><a href="' . $apge . '&by=pa"' . $cpa . '>' . __('Purchases', 'eshop') . '</a></li>'; echo '</ul>'; ?> <p><strong><?php _e('Total Downloads:', 'eshop'); ?> </strong><?php echo $total; ?> <br /> <strong><?php _e('Total Purchases:', 'eshop'); ?> </strong><?php echo $purchased; ?> <br /> </p> <table class="widefat" summary="<?php _e('download listing', 'eshop'); ?> "> <caption><?php _e('Available downloads', 'eshop'); ?> </caption> <thead> <tr> <th id="edid"><?php _e('ID', 'eshop'); ?> </th> <th id="edtitle"><?php _e('Title', 'eshop'); ?> </th> <th id="edsize"><?php _e('Size', 'eshop'); ?> </th> <th id="edstatus"><?php _e('Status', 'eshop'); ?> </th> <th id="eddate"><?php _e('Upload Date', 'eshop'); ?> </th> <th id="eddown"><?php _e('Downloads', 'eshop'); ?> </th> <th id="edpurch"><?php _e('Purchases', 'eshop'); ?> </th> <?php $echo = ''; echo apply_filters('eshop_download_table_extrahead', $echo); ?> </tr> </thead> <tbody> <?php $calt = 0; foreach ($myrowres as $row) { $size = eshop_filesize($row->files); $label = strlen($row->title) >= 20 ? substr($row->title, 0, 20) . "…" : $row->title; $calt++; $alt = $calt % 2 ? '' : ' class="alternate"'; echo "<tr" . $alt . ">\n"; echo '<td id="redid' . $row->id . '" headers="edid">#' . $row->id . "</td>\n"; echo '<td headers="edtitle redid' . $row->id . '"><a href="?page=eshop-downloads.php&edit=' . $row->id . '" title="' . __('edit details for', 'eshop') . ' ' . $row->title . '">' . $label . "</a></td>\n"; echo '<td headers="edsize redid' . $row->id . '">' . eshop_read_filesize($size) . "</td>\n"; echo '<td headers="edstatus redid' . $row->id . '">' . eshop_check_brokenlink($row->files) . "</td>\n"; echo '<td headers="eddate redid' . $row->id . '">' . $row->added . "</td>\n"; echo '<td headers="eddown redid' . $row->id . '">' . $row->downloads . "</td>\n"; echo '<td headers="edpurch redid' . $row->id . '">' . $row->purchases . "</td>\n"; $echo = ''; echo apply_filters('eshop_download_table_extracell', $echo, $row); echo "</tr>\n"; } ?> </tbody> </table> <?php //paginate echo '<div class="paginate tablenav-pages stuffbox">'; if ($records != $max) { $eecho = $page_links; } echo sprintf('<span class="displaying-num">' . __('Displaying %s–%s of %s') . '</span>', number_format_i18n(($epage - 1) * $records + 1), number_format_i18n(min($epage * $records, $max)), number_format_i18n($max)); if (isset($eecho)) { $thispage = esc_url(add_query_arg('eshopall', 'yes', $_SERVER['REQUEST_URI'])); echo "<ul class='page-numbers'>\n\t<li>" . join("</li>\n\t<li>", $eecho) . "</li>\n<li>" . '<a href="' . $thispage . '">' . __('View All', 'eshop') . '</a>' . "</li>\n</ul>\n"; } echo '<br /></div>'; //end } else { ?> <div class="wrap"> <div id="eshopicon" class="icon32"></div><h2><?php _e('Downloadable Products', 'eshop'); ?> </h2> <?php eshop_admin_mode(); ?> <p><?php _e('You currently have no downloadable products', 'eshop'); ?> .</p> <?php } ?> </div> <?php $dirpath = eshop_download_directory(); if (!is_writeable($dirpath)) { echo ' <div id="message" class="error fade"> <p>' . __('<strong>Warning!</strong>The download directory is not currently writable! File permissions must first be changed.', 'eshop') . ' </p> </div>' . "\n"; } else { // only displayed if the directory is writable to. $eshopmaxupload = ini_get("upload_max_filesize") * 1048576; ?> <div class="wrap"> <h2><?php _e('Upload a File', 'eshop'); ?> </h2> <?php $eshopmaxfilesize = ini_get("upload_max_filesize"); //if mu use this if (function_exists('check_upload_size')) { $eshopmaxfilesize = eshop_read_filesize(1024 * get_site_option('fileupload_maxk', 1500)); } ?> <p><?php _e('Use this to upload your local file. Max file size is ', 'eshop'); echo $eshopmaxfilesize; ?> </p> <form action="" method="post" id="eshopup" enctype="multipart/form-data"> <fieldset><legend><?php _e('Upload', 'eshop'); ?> </legend> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $eshopmaxupload; ?> " /> <label for="filetitle" class="lab"><?php _e('Title', 'eshop'); ?> </label><input type="text" name="title" id="filetitle" size="35" value="<?php echo $atitle; ?> " /><br /> <label for="upfile" class="lab"><?php _e('Local File', 'eshop'); ?> </label> <input name="upfile" type="file" id="upfile" size="45" /> <fieldset><legend><?php _e('Overwrite file if it exists', 'eshop'); ?> </legend> <input name="overwrite" type="radio" id="overwrite" value="no" checked="checked" /><label for="overwrite"><?php _e('No', 'eshop'); ?> </label> <input name="overwrite" type="radio" id="yesoverwrite" value="yes" /><label for="yesoverwrite"><?php _e('Yes', 'eshop'); ?> </label> <?php $echo = ''; echo apply_filters('eshop_downloads_form', $echo); ?> </fieldset> </fieldset> <p class="submit"><input type="submit" name="up" value="<?php _e('Upload File', 'eshop'); ?> " class="button-primary" /></p> </form> </div> <?php } //check for downloads that were uploaded via FTP. if (is_array(eshop_contains_files())) { ?> <div class="wrap"> <h2><?php _e('Unknown Download Files', 'eshop'); ?> </h2> <ul> <?php foreach (eshop_contains_files() as $contains) { echo '<li>' . $contains . '</li>'; } ?> </ul> <p><a href="<?php echo esc_url($_SERVER['REQUEST_URI']) . '&eshop_orphan'; ?> "><?php _e('Add all unknown download files', 'eshop'); ?> </a></p> </div> <?php } } }
function eshop_downloads($_POST, $images, $content) { global $wpdb, $eshopoptions; //cache eshop_cache(); $table = $wpdb->prefix . "eshop_downloads"; $ordertable = $wpdb->prefix . "eshop_download_orders"; $dir_upload = eshop_download_directory(); $echo = ''; //download is handled via cart functions as it needs to //be accessible before anything is printed on the page if (isset($_POST['code']) && isset($_POST['email'])) { /* Need to add in check about number of downloads here, including unlimited! */ $code = $wpdb->escape($_POST['code']); $email = $wpdb->escape($_POST['email']); $dlcount = $wpdb->get_var("SELECT COUNT(id) FROM {$ordertable} where email='{$email}' && code='{$code}' && downloads!='0'"); if ($dlcount > 0) { $echo .= $content; $tsize = 0; $x = 0; if ($dlcount > 1 && $eshopoptions['downloads_hideall'] != 'yes') { $echo .= '<p class="jdl"><a href="#dlall">' . __('Download all files', 'eshop') . '</a></p>'; } $dlresult = $wpdb->get_results("Select * from {$ordertable} where email='{$email}' && code='{$code}' && downloads!='0'"); foreach ($dlresult as $dlrow) { //download single items. $filepath = $dir_upload . $dlrow->files; $dlfilesize = eshop_filesize($dlrow->files); $tsize = $tsize + $dlfilesize; if ($dlrow->downloads == 1) { $dlword = __('download', 'eshop'); } else { $dlword = __('downloads', 'eshop'); } $imagetoadd = ''; if ($images == 'add') { $checkit = wp_check_filetype($filepath); $eshopext = wp_ext2type($checkit['ext']); $eshopfiletypeimgurl = wp_mime_type_icon($eshopext); $eshophead = wp_remote_head($eshopfiletypeimgurl); $eshophresult = wp_remote_retrieve_response_code($eshophead); if ($eshophresult == '200' || $eshophresult == '302') { $dims = getimagesize($eshopfiletypeimgurl); } if (is_array($dims)) { $dimensions = $dims[3]; } else { $dimensions = ''; } $imagetoadd = apply_filters('eshop_download_imgs', '<img class="eshop-download-icon" src="' . $eshopfiletypeimgurl . '" ' . $dimensions . ' alt="" />', $checkit['ext']); } $dltitle = strlen($dlrow->title) >= 20 ? substr($dlrow->title, 0, 20) . "…" : $dlrow->title; $echo .= ' <form method="post" action="" class="eshop dlproduct"><fieldset> <legend>' . $dltitle . ' (' . check_filesize($dlfilesize) . ')</legend> ' . $imagetoadd . ' <input name="email" type="hidden" value="' . $_POST['email'] . '" /> <input name="code" type="hidden" value="' . $_POST['code'] . '" /> <input name="id" type="hidden" value="' . $dlrow->id . '" /> <input name="eshoplongdownloadname" type="hidden" value="yes" /> <label for="ro' . $x . '">' . __('Number of downloads remaining', 'eshop') . '</label> <input type="text" readonly="readonly" name="ro" class="ro" id="ro' . $x . '" value="' . $dlrow->downloads . '" /> <span class="buttonwrap"><input type="submit" class="button" id="submit' . $x . '" name="Submit" value="' . __('Download', 'eshop') . ' ' . $dltitle . '" /></span> </fieldset></form>'; $x++; $size = 0; } if ($dlcount > 1 && $eshopoptions['downloads_hideall'] != 'yes') { //download all form. $echo .= ' <form method="post" action="" id="dlall" class="eshop"><fieldset> <legend>' . __('Download all files', 'eshop') . ' (' . check_filesize($tsize) . ') ' . __('in one zip file.', 'eshop') . '</legend> <input name="email" type="hidden" value="' . $_POST['email'] . '" /> <input name="code" type="hidden" value="' . $_POST['code'] . '" /> <input name="id" type="hidden" value="all" /> <input name="eshoplongdownloadname" type="hidden" value="yes" /> <p><span class="buttonwrap"><input class="button" type="submit" id="submit" name="Submit" value="' . __('Download All Files', 'eshop') . '" /></span></p> </fieldset></form> '; } //allow plugin to change output, validated email/passcode already $echo = apply_filters('eshop_download_page', $echo, $code, $email); } else { $prevdlcount = $wpdb->get_var("SELECT COUNT(id) FROM {$ordertable} where email='{$email}' && code='{$code}'"); if ($dlcount == $prevdlcount) { $error = '<p class="eshoperror error">' . __('Either your email address or code is incorrect, please try again.', 'eshop') . '</p>'; } else { $error = '<p class="eshoperror error">' . __('Your email address and code are correct, however you have no downloads remaining.', 'eshop') . '</p>'; } $echo .= eshop_dloadform($email, $code, $error); } } else { $echo .= eshop_dloadform('', ''); } return $echo; }
function eshop_details($atts) { global $wpdb, $post, $wp_query, $eshopoptions; eshop_cache(); extract(shortcode_atts(array('class' => 'eshopdetails', 'show' => '', 'options_hide' => '', 'etax_page' => ''), $atts)); $echo = ''; $allowedtoshow = array('sku', 'description', 'options', 'optionset', 'shipping'); $willshow = array(); if ($show != '') { $wanttoshow = explode(",", $show); foreach ($wanttoshow as $showit) { $showit = trim($showit); if (in_array($showit, $allowedtoshow)) { $willshow[] = $showit; } } } else { $willshow = $allowedtoshow; } $allowedtohide = array('price', 'saleprice', 'tax', 'download', 'weight', 'stockqty', 'filesize'); $willhide = array(); if ($options_hide != '') { $wanttohide = explode(",", $options_hide); foreach ($wanttohide as $hideit) { $hideit = trim($hideit); if (in_array($hideit, $allowedtohide)) { $willhide[] = $hideit; } } } else { $willhide = array(); } $listed = ''; $producttable = $wpdb->prefix . "eshop_downloads"; $eshop_product = maybe_unserialize(get_post_meta($post->ID, '_eshop_product', 'true')); $eshopdlavail = $wpdb->get_var("SELECT COUNT(id) FROM {$producttable} WHERE id > 0"); $numoptions = $eshopoptions['options_num']; $currsymbol = $eshopoptions['currency_symbol']; if (!empty($eshopoptions['weight_unit'])) { $weightsymbol = $eshopoptions['weight_unit']; } else { $weightsymbol = ''; } $eshopletter = "A"; $stocktable = $wpdb->prefix . "eshop_stock"; foreach ($willshow as $listit) { switch ($listit) { case 'sku': if (isset($eshop_product['sku'])) { $listed .= '<dt>' . __('Sku', 'eshop') . "</dt>\n"; $listed .= '<dd>' . $eshop_product['sku'] . "</dd>\n"; } break; case 'description': if (isset($eshop_product['description'])) { $listed .= '<dt>' . __('Description', 'eshop') . "</dt>\n"; $listed .= '<dd>' . $eshop_product['description'] . "</dd>\n"; } break; case 'options': if (isset($eshop_product['products'])) { $thclass = ''; $listed .= '<dt>' . __('Product Options', 'eshop') . "</dt>\n"; $listed .= '<dd>'; $listed .= '<table class="eshop"> <thead> <tr>'; if (!in_array('option', $willhide)) { $listed .= '<th id="' . $eshopletter . 'eshopnum">#</th><th id="' . $eshopletter . 'eshopoption">' . __('Option', 'eshop') . '</th>'; } if (!in_array('price', $willhide)) { $thprice = __('Price', 'eshop'); $listed .= '<th id="' . $eshopletter . 'eshopprice"' . $thclass . '>' . $thprice . '</th>'; } if (!in_array('saleprice', $willhide) && isset($eshopoptions['sale_prices']) && $eshopoptions['sale_prices'] == 1 && isset($eshopoptions['sale']) && 'yes' == $eshopoptions['sale']) { $thprice = __('Sale Price', 'eshop'); if (isset($eshop_product['sale']) && $eshop_product['sale'] == 'yes') { $thprice = __('Sale Price', 'eshop'); } $listed .= '<th id="' . $eshopletter . 'eshopsaleprice" class="sale">' . $thprice . '</th>'; } if (!in_array('tax', $willhide) && isset($eshopoptions['tax']) && $eshopoptions['tax'] == '1') { $listed .= '<th id="' . $eshopletter . 'eshoptax">' . __('Sales Tax', 'eshop') . '</th>'; } if ($eshopdlavail > 0 && !in_array('download', $willhide)) { $listed .= '<th id="' . $eshopletter . 'eshopdownload">' . __('Download', 'eshop') . '</th>'; } if ($eshopdlavail > 0 && !in_array('filesize', $willhide)) { $listed .= '<th id="' . $eshopletter . 'eshopdownloadsize">' . __('File Size', 'eshop') . '</th>'; } if ($eshopoptions['shipping'] == '4' && !in_array('weight', $willhide)) { $listed .= '<th id="' . $eshopletter . 'eshopweight">' . __('Weight', 'eshop') . '</th>'; } if (!in_array('stockqty', $willhide) && 'yes' == $eshopoptions['stock_control']) { $listed .= '<th id="' . $eshopletter . 'eshopstk">' . __('Stock', 'eshop') . '</th>'; } $listed .= '</tr></thead> <tbody>' . "\n"; if ('yes' == $eshopoptions['stock_control']) { $stkq = $wpdb->get_results("SELECT option_id, available from {$stocktable} where post_id={$post->ID}"); foreach ($stkq as $thisstk) { if ($thisstk->available < 0) { $thisstk->available = 0; } $stkarr[$thisstk->option_id] = $thisstk->available; } } for ($i = 1; $i <= $numoptions; $i++) { $thclass = ''; if (isset($eshop_product['products'][$i]) && is_array($eshop_product['products'][$i])) { $opt = $eshop_product['products'][$i]['option']; $price = $eshop_product['products'][$i]['price']; $downl = ''; if (isset($eshop_product['products'][$i]['download'])) { $downl = $eshop_product['products'][$i]['download']; } if (isset($eshop_product['products'][$i]['weight']) && $eshop_product['products'][$i]['weight'] != '') { $weight = $eshop_product['products'][$i]['weight']; } else { $weight = '0'; } if (isset($eshop_product['products'][$i]['stkqty']) && $eshop_product['products'][$i]['stkqty'] != '' && 'yes' == $eshopoptions['stock_control']) { $stklvl = $stkarr[$i]; } else { $stklvl = '0'; } if (isset($eshop_product['products'][$i]['tax'])) { $eshoptaxband = $eshop_product['products'][$i]['tax']; } else { $eshoptaxband = '0'; } } else { $opt = $price = $downl = ''; $stklvl = $weight = $price = '0'; $eshoptaxband = ''; } if ($opt == '') { break; } $alt = $i % 2 ? '' : ' class="alt"'; $listed .= '<tr' . $alt . '>'; $listed .= '<th id="' . $eshopletter . 'eshopnumrow' . $i . '" headers="' . $eshopletter . 'eshopnum">' . $i . '</th>'; if (!in_array('option', $willhide)) { $listed .= '<td headers="' . $eshopletter . 'eshopoption ' . $eshopletter . 'eshopnumrow' . $i . '">' . stripslashes(esc_attr($opt)) . '</td>'; } if (!in_array('price', $willhide)) { if (isset($eshop_product['products'][$i]['saleprice']) && $eshop_product['products'][$i]['saleprice'] != '' && isset($eshop_product['sale']) && $eshop_product['sale'] == 'yes') { $thclass = ' class="onsale"'; } if ($price != '') { $listed .= '<td headers="' . $eshopletter . 'eshopprice ' . $eshopletter . 'eshopnumrow' . $i . '"' . $thclass . '>' . sprintf(__('%1$s%2$s', 'eshop'), $currsymbol, number_format_i18n($price, __('2', 'eshop'))) . '</td>'; } else { $listed .= '<td headers="' . $eshopletter . 'eshopprice ' . $eshopletter . 'eshopnumrow' . $i . '"' . $thclass . '> </td>'; } } if (!in_array('saleprice', $willhide) && isset($eshopoptions['sale_prices']) && $eshopoptions['sale_prices'] == 1 && isset($eshopoptions['sale']) && 'yes' == $eshopoptions['sale']) { $thprice = __('Sale Price', 'eshop'); $sprice = ''; if (isset($eshop_product['products'][$i]['saleprice']) && $eshop_product['products'][$i]['saleprice'] != '' && isset($eshop_product['sale']) && $eshop_product['sale'] == 'yes') { $sprice = $eshop_product['products'][$i]['saleprice']; $sprice = sprintf(__('%1$s%2$s', 'eshop'), $currsymbol, number_format_i18n($sprice, __('2', 'eshop'))); } $listed .= '<td headers="' . $eshopletter . 'eshopsaleprice ' . $eshopletter . 'eshopnumrow' . $i . '" class="saleprice">' . $sprice . '</td>'; } //tax if (!in_array('tax', $willhide) && isset($eshopoptions['tax']) && $eshopoptions['tax'] == '1') { if ($eshoptaxband != '' && $eshoptaxband != '0') { $tzone = sprintf(__('Band %1$d', 'eshop'), $eshoptaxband); $disptzone = apply_filters('eshop_rename_tax_zone', array()); if (isset($disptzone[$eshoptaxband])) { $tzone = $disptzone[$eshoptaxband]; } } else { $tzone = ''; } $listed .= '<td headers="' . $eshopletter . 'eshoptax ' . $eshopletter . 'eshopnumrow' . $i . '"' . $thclass . '>' . $tzone . '</td>'; } if ($eshopdlavail > 0 && !in_array('download', $willhide)) { $myrowres = $wpdb->get_results("Select * From {$producttable}"); $listed .= '<td headers="' . $eshopletter . 'eshopdownload ' . $eshopletter . 'eshopnumrow' . $i . '">'; foreach ($myrowres as $prow) { if (trim($prow->id) == trim($downl)) { $listed .= stripslashes(esc_attr($prow->title)) . "\n"; } } $listed .= "</td>"; } if ($eshopdlavail > 0 && !in_array('filesize', $willhide)) { $downlsize = ''; $myrowres = $wpdb->get_results("Select * From {$producttable}"); foreach ($myrowres as $prow) { if (trim($prow->id) == trim($downl)) { $filepath = eshop_download_directory() . $prow->files; $size = eshop_filesize($prow->files); $downlsize = eshop_read_filesize($size); } } $listed .= '<td headers="' . $eshopletter . 'eshopdownloadsize ' . $eshopletter . 'eshopnumrow' . $i . '">'; $listed .= $downlsize . "\n"; $listed .= "</td>"; } if ($eshopoptions['shipping'] == '4' && !in_array('weight', $willhide)) { //shipping by weight /* ,'1- weight 2-weight symbol' */ $listed .= '<td headers="' . $eshopletter . 'eshopweight ' . $eshopletter . 'eshopnumrow' . $i . '">' . sprintf(__('%1$s %2$s', 'eshop'), number_format_i18n($weight, __('2', 'eshop')), $weightsymbol) . '</td>'; } if (!in_array('stockqty', $willhide) && 'yes' == $eshopoptions['stock_control']) { //stock if (isset($stkarr[$i])) { $dstk = $stkarr[$i]; } else { $dstk = 0; } $listed .= '<td headers="' . $eshopletter . 'eshopstk ' . $eshopletter . 'eshopnumrow' . $i . '">' . $dstk . '</td>'; } $listed .= "</tr>\n"; } $eshopletter++; $listed .= '</tbody></table>' . "\n"; if (!in_array('tax', $willhide) && isset($eshopoptions['tax']) && $eshopoptions['tax'] == '1' && $etax_page != '') { $listed .= '<p><a href="' . get_permalink($etax_page) . '#eshoptaxtable">' . __('Sales tax rates', 'eshop') . '</a></p>'; } $listed .= "</dd>\n"; } break; case 'optionset': if (isset($eshop_product['optset'])) { $osets = $eshop_product['optset']; $thclass = ''; $thprice = __('Price', 'eshop'); if (isset($eshop_product['sale']) && $eshop_product['sale'] == 'yes') { $thprice = __('Sale Price', 'eshop'); $thclass = ' class="sale"'; } if (is_array($osets)) { $listed .= '<dt>' . __('Additional Options', 'eshop') . "</dt>\n"; $listed .= '<dd>'; $opttable = $wpdb->prefix . 'eshop_option_names'; $optsettable = $wpdb->prefix . 'eshop_option_sets'; foreach ($osets as $optid) { $myrowres = $wpdb->get_results($wpdb->prepare("select name as optname, price,weight from {$optsettable} where optid='%d' ORDER by id ASC", $optid)); $egrab = $wpdb->get_row($wpdb->prepare("select * from {$opttable} where optid='%d' LIMIT 1", $optid)); if (isset($egrab->name)) { $ename = $egrab->name; $etype = $egrab->type; $edesc = $egrab->description; $checkrows = sizeof($myrowres); $i = 1; $tbody = ''; foreach ($myrowres as $myrow) { if ($myrow->weight == '') { $myrow->weight = '0'; } $alt = $i % 2 ? '' : ' class="alt"'; $tbody .= "<tr" . $alt . ">\n" . '<th id="' . $eshopletter . 'eshopnumrow' . $i . '" headers="' . $eshopletter . 'eshopnum">' . $i . '</th>'; if (!in_array('option', $willhide)) { $tbody .= '<td headers="' . $eshopletter . 'eshopoption ' . $eshopletter . 'eshopnumrow' . $i . '">' . stripslashes(esc_attr($myrow->optname)) . '</td>'; } if (!in_array('price', $willhide)) { $tbody .= '<td headers="' . $eshopletter . 'eshopprice ' . $eshopletter . 'eshopnumrow' . $i . '"' . $thclass . '>' . sprintf(__('%1$s%2$s', 'eshop'), $currsymbol, number_format_i18n($myrow->price, __('2', 'eshop'))) . '</td>'; } if ($eshopoptions['shipping'] == '4' && !in_array('weight', $willhide)) { /* ,'1- weight 2-weight symbol' */ $tbody .= '<td headers="' . $eshopletter . 'eshopweight ' . $eshopletter . 'eshopnumrow' . $i . '">' . sprintf(__('%1$s %2$s', 'eshop'), number_format_i18n($myrow->weight, __('2', 'eshop')), $weightsymbol) . '</td>'; } $tbody .= "</tr>\n"; $i++; } $listed .= '<strong>' . stripslashes(esc_attr($ename)) . '</strong><br />'; $listed .= nl2br(stripslashes(esc_attr($edesc))); $listed .= '<table class="eshop"> <thead><tr> <th id="' . $eshopletter . 'eshopnum">#</th>'; if (!in_array('option', $willhide)) { $listed .= '<th id="' . $eshopletter . 'eshopoption">' . __('Option', 'eshop') . '</th>'; } if (!in_array('price', $willhide)) { $listed .= '<th id="' . $eshopletter . 'eshopprice"' . $thclass . '>' . $thprice . '</th>'; } if ($eshopoptions['shipping'] == '4' && !in_array('weight', $willhide)) { $listed .= '<th id="' . $eshopletter . 'eshopweight">' . __('Weight', 'eshop') . '</th>'; } $listed .= '</tr></thead><tbody>' . "\n"; $listed .= $tbody; $listed .= '</tbody></table>' . "\n"; $eshopletter++; } } $listed .= "</dd>\n"; } } break; case 'shipping': if (isset($eshop_product['shiprate']) && $eshopoptions['shipping'] != '4') { $listed .= '<dt>' . __('Shipping', 'eshop') . "</dt>\n"; if ($eshopoptions['cart_shipping'] != '') { $replace = '<a href="' . get_permalink($eshopoptions['cart_shipping']) . '#eshopshiprates"><span>' . __('Shipping Rate:', 'eshop') . '</span> ' . $eshop_product['shiprate'] . '</a>'; } else { $replace = '<span>' . __('Shipping Rate:', 'eshop') . '</span> ' . $eshop_product['shiprate']; } $listed .= '<dd>' . $replace . "</dd>\n"; } elseif (isset($eshop_product['shiprate']) && $eshopoptions['shipping'] == '4') { unset($weight); $listed .= '<dt>' . __('Shipping', 'eshop') . "</dt>\n"; //only for ship by weight need to grab weights for ($i = 1; $i <= $numoptions; $i++) { if (isset($eshop_product['products']) && is_array($eshop_product['products'])) { if (isset($eshop_product['products'][$i]['weight']) && $eshop_product['products'][$i]['weight'] != '') { $weight[] = $eshop_product['products'][$i]['weight']; } else { $weight[] = 0; } } else { $weight[] = 0; } } //expand $weight $cartweight = "weight<='" . implode("' || weight<='", $weight) . "'"; $typearr = explode("\n", $eshopoptions['ship_types']); $eshopshiptable = ''; $dtable = $wpdb->prefix . 'eshop_rates'; foreach ($typearr as $k => $type) { $k++; $eshopshiptabletop = '<table class="eshopshiprates eshop"> <thead> <tr> <th id="' . $eshopletter . 'wt">' . __('Weight', 'eshop') . '</th>'; for ($z = 1; $z <= $eshopoptions['numb_shipzones']; $z++) { $y = 'zone' . $z; $echozone = sprintf(__('Zone %1$d', 'eshop'), $z); $dispzone = apply_filters('eshop_rename_ship_zone', array()); if (isset($dispzone[$z])) { $echozone = $dispzone[$z]; } $eshopshiptabletop .= '<th id="' . $eshopletter . $y . '">' . $echozone . '</th>'; } $eshopshiptabletop .= '</tr> </thead> <tbody>'; $x = 1; $query = $wpdb->get_results("SELECT * from {$dtable} where ({$cartweight}) && class='{$k}' && rate_type='ship_weight' order by weight ASC"); if (count($query) == 0) { break; } $eshopshiptableinner = ''; foreach ($query as $row) { $alt = $x % 2 ? ' class="row' . $x . '"' : ' class="alt row' . $x . '"'; /* ,'1- weight 2-weight symbol' */ $cols = $eshopoptions['numb_shipzones'] + 1; $eshopshiptableinner .= ' <tr' . $alt . '> <th headers="' . $eshopletter . 'wt">' . sprintf(__('%1$s %2$s', 'eshop'), number_format_i18n($row->weight, __('2', 'eshop')), $weightsymbol) . '</th>'; for ($z = 1; $z <= $eshopoptions['numb_shipzones']; $z++) { $y = 'zone' . $z; $eshopshiptableinner .= '<td headers="' . $eshopletter . $y . '">' . sprintf(__('%1$s%2$s', 'eshop'), $currsymbol, $row->{$y}) . '</td>'; } $eshopshiptableinner .= '</tr>'; $x++; } $eshopletter++; $eshopshiptablefoot = '</tbody></table>' . "\n"; if ($row->area == 'country') { $eshopshiptableheader = '<span class="eshopshiphead">' . sprintf(__('%1$s <small>%2$s</small>', 'eshop'), stripslashes(esc_attr($type)), __('(Shipping Zones by Country)', 'eshop')); } else { $eshopshiptableheader = '<span class="eshopshiphead">' . sprintf(__('%1$s <small>%2$s</small>', 'eshop'), stripslashes(esc_attr($type)), __('(Shipping Zones by State/County/Province)', 'eshop')); } $eshopshiptable .= $eshopshiptableheader . $eshopshiptabletop . $eshopshiptableinner . $eshopshiptablefoot; } $listed .= '<dd>' . $eshopshiptable . '</dd>'; } break; } } if ($listed != '') { $addclass = ''; } if ($class != '' && $class != 'eshopdetails') { $addclass = ' ' . $class; } $echo = '<div class="eshopdetails' . $addclass . '"><dl>' . "\n" . $listed . '</dl></div>'; return $echo; }