/** * Add a menu to the Shopp menu area * * @api * @since 1.3 * * @param string $label The translated label to use for the menu * @param string $page The Shopp-internal menu page name (plugin prefix will be automatically added) * @param integer $position The index position of where to add the menu * @param mixed $handler The callback handler to use to handle the page * @param string $access The access capability required to see the menu * @param string $icon The URL for the icon to use for the menu * @return integer The position the menu was added **/ function shopp_admin_add_menu($label, $page, $position = null, $handler = false, $access = null, $icon = null) { global $menu; $AdminPages = ShoppAdminPages(); if (is_null($position)) { $position = 35; } if (is_null($access)) { $access = 'manage_options'; } // Restrictive access by default (for admins only) if (false === $handler) { $handler = array(Shopp::object()->Flow, 'parse'); } if (!is_callable($handler)) { shopp_debug(__FUNCTION__ . " failed: The specified callback handler is not valid."); return false; } while (isset($menu[$position])) { $position++; } $menupage = add_menu_page($label, $label, $access, ShoppAdmin::pagename($page), $handler, $icon, $position); $AdminPages->menu($page, $menupage); do_action_ref_array("shopp_add_topmenu_{$page}", array($menupage)); // @deprecated do_action_ref_array("shopp_add_menu_{$page}", array($menupage)); return $position; }
/** * Registers a new page to the Shopp admin pages * * @author Jonathan Davis * @since 1.1 * * @param string $name The internal reference name for the page. * @param string $label The label displayed in the WordPress admin menu. * @param string $controller The name of the controller to use for the page. * @param string $parent The internal reference for the parent page. * @param string $icon The Shopp icon CSS class name. * @return void **/ private function add($name, $label, $controller = null, $parent = null, $icon = null) { $page = ShoppAdmin::pagename($name); if (isset($parent)) { $parent = ShoppAdmin::pagename($parent); } $capability = isset($this->caps[$name]) ? $this->caps[$name] : 'shopp_menu'; $this->pages[$page] = new ShoppAdminPage($name, $page, $label, $capability, $controller, $parent, $icon); }
public function screen() { global $wpdb; $defaults = array('page' => false, 'deleting' => false, 'selected' => false, 'update' => false, 'newstatus' => false, 'pagenum' => 1, 'paged' => false, 'per_page' => 20, 'start' => '', 'end' => '', 'status' => false, 's' => '', 'range' => '', 'startdate' => '', 'enddate' => ''); $args = array_merge($defaults, $_GET); extract($args, EXTR_SKIP); if ($page == ShoppAdmin::pagename('customers') && !empty($deleting) && !empty($selected) && is_array($selected) && current_user_can('shopp_delete_customers')) { foreach ($selected as $deletion) { $Customer = new ShoppCustomer($deletion); $Billing = new BillingAddress($Customer->id, 'customer'); $Billing->delete(); $Shipping = new ShippingAddress($Customer->id, 'customer'); $Shipping->delete(); $Customer->delete(); } } $updated = false; // if (!empty($_POST['save'])) { // check_admin_referer('shopp-save-customer'); // $wp_integration = ('wordpress' === shopp_setting( 'account_system' )); // // if ($_POST['id'] !== 'new') { // $Customer = new ShoppCustomer($_POST['id']); // $Billing = new BillingAddress($Customer->id, 'customer'); // $Shipping = new ShippingAddress($Customer->id, 'customer'); // } else $Customer = new ShoppCustomer(); // // if (!empty($Customer->wpuser)) $user = get_user_by('id',$Customer->wpuser); // $new_customer = empty( $Customer->id ); // // $Customer->updates($_POST); // // // Reassign WordPress login // if ($wp_integration && isset($_POST['userlogin']) && $_POST['userlogin'] != $user->user_login) { // $newlogin = get_user_by('login', $_POST['userlogin']); // if ( ! empty($newlogin->ID) ) { // if (sDB::query("SELECT count(*) AS used FROM $Customer->_table WHERE wpuser=$newlogin->ID",'auto','col','used') == 0) { // $Customer->wpuser = $newlogin->ID; // $updated = sprintf(__('Updated customer login to %s.','Shopp'),"<strong>$newlogin->user_login</strong>"); // } else $updated = sprintf(__('Could not update customer login to "%s" because that user is already assigned to another customer.','Shopp'),'<strong>'.sanitize_user($_POST['userlogin']).'</strong>'); // // } else $updated = sprintf(__('Could not update customer login to "%s" because the user does not exist in WordPress.','Shopp'),'<strong>'.sanitize_user($_POST['userlogin']).'</strong>'); // if ( empty($_POST['userlogin']) ) $Customer->wpuser = 0; // } // // if ( ! empty($_POST['new-password']) && !empty($_POST['confirm-password']) // && $_POST['new-password'] == $_POST['confirm-password']) { // $Customer->password = wp_hash_password($_POST['new-password']); // if (!empty($Customer->wpuser)) wp_set_password($_POST['new-password'], $Customer->wpuser); // } // // $valid_email = filter_var( $_POST['email'], FILTER_VALIDATE_EMAIL ); // $password = !empty( $_POST['new_password'] ); // // if ($wp_integration && $new_customer && $valid_email && $password) { // $Customer->loginname = $_POST['userlogin']; // $Customer->email = $_POST['email']; // $Customer->firstname = $_POST['firstname']; // $Customer->lastname = $_POST['lastname']; // // $return = $Customer->create_wpuser(); // // if ( $return ) { // $updated = sprintf( __( 'The Shopp and WordPress accounts have been created with the username "%s".', 'Shopp'), '<strong>'.sanitize_user($_POST['userlogin']).'</strong>'); // } else { // $updated = sprintf( __( 'Could not create a WordPress account for customer "%s".','Shopp'), '<strong>'.sanitize_user($_POST['userlogin']).'</strong>'); // } // } // elseif ($new_customer && ( !$valid_email || !$password ) ) { // $updated = __( 'Could not create new user. You must enter a valid email address and a password first.', 'Shopp' ); // $no_save = true; // } // // if ( !isset( $new_save ) ) { // $Customer->info = false; // No longer used from DB // $Customer->save(); // } // // // if (isset($_POST['info']) && !empty($_POST['info'])) { // foreach ((array)$_POST['info'] as $id => $info) { // $Meta = new ShoppMetaObject($id); // $Meta->value = $info; // $Meta->save(); // } // } // // if (isset($Customer->id)) $Billing->customer = $Customer->id; // $Billing->updates($_POST['billing']); // $Billing->save(); // // if (isset($Customer->id)) $Shipping->customer = $Customer->id; // $Shipping->updates($_POST['shipping']); // $Shipping->save(); // if (!$updated) __('Customer updated.','Shopp'); // $Customer = false; // // } $pagenum = absint($paged); if (empty($pagenum)) { $pagenum = 1; } if (!$per_page || $per_page < 0) { $per_page = 20; } $index = $per_page * ($pagenum - 1); if (!empty($start)) { $startdate = $start; list($month, $day, $year) = explode("/", $startdate); $starts = mktime(0, 0, 0, $month, $day, $year); } if (!empty($end)) { $enddate = $end; list($month, $day, $year) = explode("/", $enddate); $ends = mktime(23, 59, 59, $month, $day, $year); } $customer_table = ShoppDatabaseObject::tablename(Customer::$table); $billing_table = ShoppDatabaseObject::tablename(BillingAddress::$table); $purchase_table = ShoppDatabaseObject::tablename(ShoppPurchase::$table); $users_table = $wpdb->users; $where = array(); if (!empty($s)) { $s = stripslashes($s); if (preg_match_all('/(\\w+?)\\:(?="(.+?)"|(.+?)\\b)/', $s, $props, PREG_SET_ORDER)) { foreach ($props as $search) { $keyword = !empty($search[2]) ? $search[2] : $search[3]; switch (strtolower($search[1])) { case "company": $where[] = "c.company LIKE '%{$keyword}%'"; break; case "login": $where[] = "u.user_login LIKE '%{$keyword}%'"; break; case "address": $where[] = "(b.address LIKE '%{$keyword}%' OR b.xaddress='%{$keyword}%')"; break; case "city": $where[] = "b.city LIKE '%{$keyword}%'"; break; case "province": case "state": $where[] = "b.state='{$keyword}'"; break; case "zip": case "zipcode": case "postcode": $where[] = "b.postcode='{$keyword}'"; break; case "country": $where[] = "b.country='{$keyword}'"; break; } } } elseif (strpos($s, '@') !== false) { $where[] = "c.email='{$s}'"; } elseif (is_numeric($s)) { $where[] = "c.id='{$s}'"; } else { $where[] = "(CONCAT(c.firstname,' ',c.lastname) LIKE '%{$s}%' OR c.company LIKE '%{$s}%')"; } } if (!empty($starts) && !empty($ends)) { $where[] = ' (UNIX_TIMESTAMP(c.created) >= ' . $starts . ' AND UNIX_TIMESTAMP(c.created) <= ' . $ends . ')'; } $select = array('columns' => 'SQL_CALC_FOUND_ROWS c.*,city,state,country,user_login', 'table' => "{$customer_table} as c", 'joins' => array($billing_table => "LEFT JOIN {$billing_table} AS b ON b.customer=c.id AND b.type='billing'", $users_table => "LEFT JOIN {$users_table} AS u ON u.ID=c.wpuser AND (c.wpuser IS NULL OR c.wpuser != 0)"), 'where' => $where, 'groupby' => "c.id", 'orderby' => "c.created DESC", 'limit' => "{$index},{$per_page}"); $query = sDB::select($select); $Customers = sDB::query($query, 'array', 'index', 'id'); $total = sDB::found(); // Add order data to customer records in this view $orders = sDB::query("SELECT customer,SUM(total) AS total,count(id) AS orders FROM {$purchase_table} WHERE customer IN (" . join(',', array_keys($Customers)) . ") GROUP BY customer", 'array', 'index', 'customer'); foreach ($Customers as &$record) { $record->total = 0; $record->orders = 0; if (!isset($orders[$record->id])) { continue; } $record->total = $orders[$record->id]->total; $record->orders = $orders[$record->id]->orders; } $num_pages = ceil($total / $per_page); $ListTable = ShoppUI::table_set_pagination(ShoppAdmin::screen(), $total, $num_pages, $per_page); $ranges = array('all' => __('Show New Customers', 'Shopp'), 'today' => __('Today', 'Shopp'), 'week' => __('This Week', 'Shopp'), 'month' => __('This Month', 'Shopp'), 'quarter' => __('This Quarter', 'Shopp'), 'year' => __('This Year', 'Shopp'), 'yesterday' => __('Yesterday', 'Shopp'), 'lastweek' => __('Last Week', 'Shopp'), 'last30' => __('Last 30 Days', 'Shopp'), 'last90' => __('Last 3 Months', 'Shopp'), 'lastmonth' => __('Last Month', 'Shopp'), 'lastquarter' => __('Last Quarter', 'Shopp'), 'lastyear' => __('Last Year', 'Shopp'), 'lastexport' => __('Last Export', 'Shopp'), 'custom' => __('Custom Dates', 'Shopp')); $exports = array('tab' => __('Tab-separated.txt', 'Shopp'), 'csv' => __('Comma-separated.csv', 'Shopp'), 'xls' => __('Microsoft® Excel.xls', 'Shopp')); $formatPref = shopp_setting('customerexport_format'); if (!$formatPref) { $formatPref = 'tab'; } $columns = array_merge(Customer::exportcolumns(), BillingAddress::exportcolumns(), ShippingAddress::exportcolumns()); $selected = shopp_setting('customerexport_columns'); if (empty($selected)) { $selected = array_keys($columns); } $authentication = shopp_setting('account_system'); $action = add_query_arg(array('page' => ShoppAdmin::pagename('customers')), admin_url('admin.php')); include $this->ui('customers.php'); }
?> ', fileverify_url = '<?php echo wp_nonce_url(admin_url() . "admin-ajax.php", "wp_ajax_shopp_verify_file"); ?> ', fileimport_url = '<?php echo wp_nonce_url(admin_url() . "admin-ajax.php", "wp_ajax_shopp_import_file"); ?> ', imageul_url = '<?php echo wp_nonce_url(admin_url() . "admin-ajax.php", "wp_ajax_shopp_upload_image"); ?> ', adminpage = '<?php echo ShoppAdmin::pagename('products'); ?> ', request = <?php echo json_encode(stripslashes_deep($_GET)); ?> , filesizeLimit = <?php echo wp_max_upload_size(); ?> , weightUnit = '<?php echo shopp_setting('weight_unit'); ?> ', dimensionUnit = '<?php
/** * Renders the bestselling products dashboard widget * * @author Jonathan Davis * @since 1.0 * * @return void **/ public static function inventory_widget($args = false) { $warnings = array('none' => __('OK', 'Shopp'), 'warning' => __('warning', 'Shopp'), 'critical' => __('critical', 'Shopp'), 'backorder' => __('backorder', 'Shopp')); $defaults = array('before_widget' => '', 'before_title' => '', 'widget_name' => '', 'after_title' => '', 'after_widget' => ''); $args = array_merge($defaults, (array) $args); extract($args, EXTR_SKIP); $pt = ShoppDatabaseObject::tablename(ShoppPrice::$table); $setting = shopp_setting('lowstock_level'); $where = array(); $where[] = "pt.stock < pt.stocked AND pt.stock/pt.stocked < {$setting}"; $where[] = "(pt.context='product' OR pt.context='variation') AND pt.type != 'N/A'"; $loading = array('columns' => "pt.id AS stockid,IF(pt.context='variation',CONCAT(p.post_title,': ',pt.label),p.post_title) AS post_title,pt.sku AS sku,pt.stock,pt.stocked", 'joins' => array($pt => "LEFT JOIN {$pt} AS pt ON p.ID=pt.product"), 'where' => $where, 'groupby' => 'pt.id', 'orderby' => '(pt.stock/pt.stocked) ASC', 'published' => false, 'pagination' => false, 'limit' => 25); $Collection = new ProductCollection(); $Collection->load($loading); $productscreen = add_query_arg(array('page' => ShoppAdmin::pagename('products')), admin_url('admin.php')); echo $before_widget; echo $before_title; echo $widget_name; echo $after_title; ?> <table><tbody> <?php foreach ($Collection->products as $product) { $product->lowstock($product->stock, $product->stocked); ?> <tr> <td class="amount"><?php echo abs($product->stock); ?> </td> <td><span class="stock lowstock <?php echo $product->lowstock; ?> "><?php echo $warnings[$product->lowstock]; ?> </span></td> <td><a href="<?php echo esc_url(add_query_arg('id', $product->id, $productscreen)); ?> "><?php echo $product->name; ?> </a></td> <td><a href="<?php echo esc_url(add_query_arg('view', 'inventory', $productscreen)); ?> "><?php echo $product->sku; ?> </a></td> </tr> <?php } ?> </tbody></table> <?php echo $after_widget; }
foreach ($columns as $column => $column_title) { $classes = array($column, "column-{$column}"); if (in_array($column, $hidden)) { $classes[] = 'hidden'; } switch ($column) { case 'cb': ?> <th scope='row' class='check-column'><input type='checkbox' name='selected[]' value='<?php echo esc_attr($Category->id); ?> ' /></th> <?php break; case 'name': $adminurl = add_query_arg(array_merge($_GET, array('page' => ShoppAdmin::pagename('categories'))), admin_url('admin.php')); $editurl = wp_nonce_url(add_query_arg('id', $Category->id, $adminurl), 'shopp_categories_manager'); $deleteurl = wp_nonce_url(add_query_arg('action', 'delete', $editurl), 'shopp_categories_manager'); $CategoryName = empty($Category->name) ? '(' . Shopp::__('no category name') . ')' : $Category->name; ?> <td class="<?php echo esc_attr(join(' ', $classes)); ?> "><a class='row-title' href='<?php echo $editurl; ?> ' title='<?php _e('Edit', 'Shopp'); ?> "<?php echo esc_attr($CategoryName);
/** * Interface processor for the product editor * * @author Jonathan Davis * @return void **/ public function screen() { $Shopp = Shopp::object(); if (!current_user_can('shopp_products')) { wp_die(__('You do not have sufficient permissions to access this page.')); } if (empty($Shopp->Product)) { $Product = new ShoppProduct(); $Product->status = "publish"; } else { $Product = $Shopp->Product; } $Product->slug = apply_filters('editable_slug', $Product->slug); $permalink = trailingslashit(Shopp::url()); $Price = new ShoppPrice(); $priceTypes = ShoppPrice::types(); $billPeriods = ShoppPrice::periods(); $workflows = array('continue' => Shopp::__('Continue Editing'), 'close' => Shopp::__('Products Manager'), 'new' => Shopp::__('New Product'), 'next' => Shopp::__('Edit Next'), 'previous' => Shopp::__('Edit Previous')); $taglist = array(); foreach ($Product->tags as $tag) { $taglist[] = $tag->name; } if ($Product->id && !empty($Product->images)) { $ids = join(',', array_keys($Product->images)); $CoverImage = reset($Product->images); $image_table = $CoverImage->_table; $Product->cropped = sDB::query("SELECT * FROM {$image_table} WHERE context='image' AND type='image' AND '2'=SUBSTRING_INDEX(SUBSTRING_INDEX(name,'_',4),'_',-1) AND parent IN ({$ids})", 'array', 'index', 'parent'); } $shiprates = shopp_setting('shipping_rates'); if (!empty($shiprates)) { ksort($shiprates); } $uploader = shopp_setting('uploader_pref'); if (!$uploader) { $uploader = 'flash'; } $process = empty($Product->id) ? 'new' : $Product->id; $_POST['action'] = add_query_arg(array_merge($_GET, array('page' => ShoppAdmin::pagename('products'))), admin_url('admin.php')); $post_type = ShoppProduct::posttype(); // Re-index menu options to maintain order in JS #2930 if (isset($Product->options['v']) || isset($Product->options['a'])) { $options = array_keys($Product->options); foreach ($options as $type) { foreach ($Product->options[$type] as $id => $menu) { $Product->options[$type][$type . $id] = $menu; $Product->options[$type][$type . $id]['options'] = array_values($menu['options']); unset($Product->options[$type][$id]); } } } else { foreach ($Product->options as &$menu) { $menu['options'] = array_values($menu['options']); } } do_action('add_meta_boxes', ShoppProduct::$posttype, $Product); do_action('add_meta_boxes_' . ShoppProduct::$posttype, $Product); do_action('do_meta_boxes', ShoppProduct::$posttype, 'normal', $Product); do_action('do_meta_boxes', ShoppProduct::$posttype, 'advanced', $Product); do_action('do_meta_boxes', ShoppProduct::$posttype, 'side', $Product); include $this->ui('editor.php'); }
/** * Adds a maintenance mode notice to every admin screen * * @since 1.3 * * @return void **/ public function maintenance() { if (ShoppLoader::is_activating() || Shopp::upgradedb()) { return; } $setting = isset($_POST['settings']['maintenance']) ? $_POST['settings']['maintenance'] : false; $nonce = isset($_POST['_wpnonce']) ? $_POST['_wpnonce'] : false; if (false !== $setting && wp_verify_nonce($nonce, 'shopp-setup')) { shopp_set_setting('maintenance', $setting); } if (!Shopp::maintenance()) { return; } if (wp_verify_nonce($this->request('_wpnonce'), 'shopp_disable_maintenance')) { shopp_set_setting('maintenance', 'off'); } else { $url = wp_nonce_url(add_query_arg('page', ShoppAdmin::pagename('settings'), admin_url('admin.php')), 'shopp_disable_maintenance'); $this->Screen->notice(Shopp::__('Shopp is currently in maintenance mode. %sDisable Maintenance Mode%s', '<a href="' . $url . '" class="button">', '</a>'), 'error', 1); } }
public function categories() { if (!current_user_can('shopp_categories')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $per_page_option = get_current_screen()->get_option('per_page'); $defaults = array('paged' => 1, 'per_page' => 20, 's' => '', 'a' => ''); $args = array_merge($defaults, $_GET); if (false !== ($user_per_page = get_user_option($per_page_option['option']))) { $args['per_page'] = $user_per_page; } extract($args, EXTR_SKIP); if ('arrange' == $a) { $this->init_positions(); $per_page = 300; } $paged = absint($paged); $start = $per_page * ($paged - 1); $end = $start + $per_page; $url = add_query_arg(array_merge($_GET, array('page' => ShoppAdmin::pagename('categories'))), admin_url('admin.php')); $taxonomy = 'shopp_category'; $filters = array('hide_empty' => 0, 'fields' => 'id=>parent'); add_filter('get_shopp_category', array($this, 'load_category'), 10, 2); // $filters['limit'] = "$start,$per_page"; if (!empty($s)) { $filters['search'] = $s; } $Categories = array(); $count = 0; $terms = get_terms($taxonomy, $filters); if (empty($s)) { $children = _get_term_hierarchy($taxonomy); ProductCategory::tree($taxonomy, $terms, $children, $count, $Categories, $paged, $per_page); $this->categories = $Categories; } else { foreach ($terms as $id => $parent) { $Categories[$id] = get_term($id, $taxonomy); } } $ids = array_keys($Categories); return $ids; }
', ajaxurl = adminurl+'admin-ajax.php', addcategory_url = '<?php echo wp_nonce_url(admin_url() . "admin-ajax.php", "shopp-ajax_add_category"); ?> ', editslug_url = '<?php echo wp_nonce_url(admin_url() . "admin-ajax.php", "wp_ajax_shopp_edit_slug"); ?> ', fileverify_url = '<?php echo wp_nonce_url(admin_url() . "admin-ajax.php", "shopp-ajax_verify_file"); ?> ', adminpage = '<?php echo ShoppAdmin::pagename('categories'); ?> ', request = <?php echo json_encode(stripslashes_deep($_GET)); ?> , worklist = <?php echo json_encode($this->categories()); ?> , filesizeLimit = <?php echo wp_max_upload_size(); ?> , priceTypes = <?php
<?php if ($Products->size() > 0) { ?> <tbody id="products" class="list products"> <?php $columns = get_column_headers($this->id); $hidden = get_hidden_columns($this->id); $even = false; foreach ($Products as $key => $Product) { $editor_url = remove_query_arg(array('s', 'cat', 'sl'), $url); $editurl = esc_url(add_query_arg(array('id' => $Product->id, 'view' => null), $editor_url)); $trashurl = esc_url(add_query_arg(array('selected' => $Product->id, 'action' => 'trash'), $editor_url)); $dupurl = esc_url(add_query_arg(array('duplicate' => $Product->id), $editor_url)); $restoreurl = esc_url(add_query_arg(array('selected' => $Product->id, 'action' => 'restore'), $editor_url)); $delurl = esc_url(add_query_arg(array('selected' => $Product->id, 'action' => 'delete'), $editor_url)); $category_url = add_query_arg(array('page' => ShoppAdmin::pagename('categories')), admin_url('admin.php')); ?> <tr<?php if (!$even) { echo " class='alternate'"; } $even = !$even; ?> > <?php foreach ($columns as $column => $column_title) { $classes = array($column, "column-{$column}"); if (in_array($column, $hidden)) { $classes[] = 'hidden'; } switch ($column) {
?> " class="moveto shoppui-step-top"><span class="hidden"><?php echo $title; ?> </span></button><button type="button" name="bottom" alt="<?php $title = Shopp::__('Move to the bottom…'); echo $title; ?> " class="moveto shoppui-step-bottom"><span class="hidden"><?php echo $title; ?> </span></button></th> <?php break; case 'title': $editurl = esc_url(esc_attr(add_query_arg(array_merge(stripslashes_deep($_GET), array('page' => ShoppAdmin::pagename('products'), 'id' => $Product->id)), admin_url('admin.php')))); $ProductName = empty($Product->name) ? '(' . __('no product name', 'Shopp') . ')' : $Product->name; ?> <td class="<?php echo esc_attr(join(' ', $classes)); ?> "><a class='row-title' href='<?php echo $editurl; ?> ' title='<?php _e('Edit', 'Shopp'); ?> "<?php echo esc_attr($ProductName); ?> "'><?php