/** * shopp_add_image * * Add an image by filename, and associate with a user defined context. Requires full path to the file on your filesystem, or a correct relative path for the scripts current working directory. * * @api * @since 1.2 * * @param int $id Object id to attach the image asset to. * @param string $context the object type the image asset will be attached to. This can be product or category * @param string $file Full or correct relative path to the image file. * @return mixed false on failure, int image asset id on success. **/ function shopp_add_image($id, $context, $file) { if (empty($id) || empty($context) || empty($file)) { shopp_debug(__FUNCTION__ . " failed: One or more missing parameters."); return false; } if (!is_file($file) || !is_readable($file)) { shopp_debug(__FUNCTION__ . " failed for file {$file}: File missing or unreadable."); } if ('product' == $context) { $Object = new ShoppProduct($id); $Image = new ProductImage(); } else { if ('category' == $context) { $Object = new ProductCategory($id); $Image = new CategoryImage(); } else { shopp_debug(__FUNCTION__ . " failed for file {$file}: Invalid context {$context}."); return false; } } if (empty($Object->id)) { shopp_debug(__FUNCTION__ . " failed for file {$file}: Unable to find a {$context} with id {$id}."); return false; } $Image->parent = $id; $Image->type = "image"; $Image->name = "original"; $Image->filename = basename($file); list($Image->width, $Image->height, $Image->mime, $Image->attr) = getimagesize($file); $Image->mime = image_type_to_mime_type($Image->mime); $Image->size = filesize($file); if (!$Image->unique()) { shopp_debug(__FUNCTION__ . " failed for file {$file}: Too many images exist with this name."); return false; } $Image->store($file, 'file'); $Image->save(); if ($Image->id) { return $Image->id; } shopp_debug(__FUNCTION__ . " failed for file {$file}."); return false; }
/** * Handles saving updated category information from the category editor * * @since 1.0 * @return void **/ function save ($Category) { global $Ecart; $Settings = &EcartSettings(); $db = DB::get(); check_admin_referer('ecart-save-category'); if ( !(is_ecart_userlevel() || current_user_can('ecart_categories')) ) wp_die(__('You do not have sufficient permissions to access this page.')); $Settings->saveform(); // Save workflow setting $Ecart->Catalog = new Catalog(); $Ecart->Catalog->load_categories(array( 'columns' => "cat.id,cat.parent,cat.name,cat.description,cat.uri,cat.slug", 'where' => array(), 'joins' => array(), 'orderby' => false, 'order' => false, 'outofstock' => true )); $Category->update_slug(); if (!empty($_POST['deleteImages'])) { $deletes = array(); if (strpos($_POST['deleteImages'],",")) $deletes = explode(',',$_POST['deleteImages']); else $deletes = array($_POST['deleteImages']); $Category->delete_images($deletes); } // Variation price templates if (!empty($_POST['price']) && is_array($_POST['price'])) { foreach ($_POST['price'] as &$pricing) { $pricing['price'] = floatvalue($pricing['price'],false); $pricing['saleprice'] = floatvalue($pricing['saleprice'],false); $pricing['shipfee'] = floatvalue($pricing['shipfee'],false); } $Category->prices = stripslashes_deep($_POST['price']); } else $Category->prices = array(); if (empty($_POST['specs'])) $Category->specs = array(); else $_POST['specs'] = stripslashes_deep($_POST['specs']); if (empty($_POST['options']) || (count($_POST['options']['v'])) == 1 && !isset($_POST['options']['v'][1]['options'])) { $_POST['options'] = $Category->options = array(); $_POST['prices'] = $Category->prices = array(); } else $_POST['options'] = stripslashes_deep($_POST['options']); if (isset($_POST['content'])) $_POST['description'] = $_POST['content']; $Category->updates($_POST); $Category->save(); if (!empty($_POST['images']) && is_array($_POST['images'])) { $Category->link_images($_POST['images']); $Category->save_imageorder($_POST['images']); if (!empty($_POST['imagedetails']) && is_array($_POST['imagedetails'])) { foreach($_POST['imagedetails'] as $i => $data) { $Image = new CategoryImage($data['id']); $Image->title = $data['title']; $Image->alt = $data['alt']; $Image->save(); } } } do_action_ref_array('ecart_category_saved',array(&$Category)); $updated = '<strong>'.$Category->name.'</strong> '.__('category saved.','Ecart'); }
/** * Handles saving updated category information from the category editor * * @author Jonathan Davis * @since 1.0 * @return void **/ public function save($Category) { $Shopp = Shopp::object(); check_admin_referer('shopp-save-category'); if (!current_user_can('shopp_categories')) { wp_die(__('You do not have sufficient permissions to access this page.')); } shopp_set_formsettings(); // Save workflow setting if (empty($Category->meta)) { $Category->load_meta(); } if (isset($_POST['content'])) { $_POST['description'] = $_POST['content']; } $Category->name = $_POST['name']; $Category->description = $_POST['description']; $Category->parent = $_POST['parent']; $Category->prices = array(); // Variation price templates if (!empty($_POST['price']) && is_array($_POST['price'])) { foreach ($_POST['price'] as &$pricing) { $pricing['price'] = Shopp::floatval($pricing['price'], false); $pricing['saleprice'] = Shopp::floatval($pricing['saleprice'], false); $pricing['shipfee'] = Shopp::floatval($pricing['shipfee'], false); $pricing['dimensions'] = array_map(array('Shopp', 'floatval'), $pricing['dimensions']); } } $_POST['prices'] = isset($_POST['price']) ? $_POST['price'] : array(); if (empty($_POST['specs'])) { $Category->specs = array(); } /* @todo Move the rest of category meta inputs to [meta] inputs eventually */ if (isset($_POST['meta']) && isset($_POST['meta']['options'])) { // Moves the meta options input to 'options' index for compatibility $_POST['options'] = $_POST['meta']['options']; } if (empty($_POST['meta']['options']) || count($_POST['meta']['options']['v']) == 1 && !isset($_POST['meta']['options']['v'][1]['options'])) { $_POST['options'] = $Category->options = array(); $_POST['prices'] = $Category->prices = array(); } $metaprops = array('spectemplate', 'facetedmenus', 'variations', 'pricerange', 'priceranges', 'specs', 'options', 'prices'); $metadata = array_filter_keys($_POST, $metaprops); // Update existing entries $updates = array(); foreach ($Category->meta as $id => $MetaObject) { $name = $MetaObject->name; if (isset($metadata[$name])) { $MetaObject->value = stripslashes_deep($metadata[$name]); $updates[] = $name; } } // Create any new missing meta entries $new = array_diff(array_keys($metadata), $updates); // Determine new entries from the exsting updates foreach ($new as $name) { if (!isset($metadata[$name])) { continue; } $Meta = new MetaObject(); $Meta->name = $name; $Meta->value = stripslashes_deep($metadata[$name]); $Category->meta[] = $Meta; } $Category->save(); if (!empty($_POST['deleteImages'])) { $deletes = array(); if (strpos($_POST['deleteImages'], ",")) { $deletes = explode(',', $_POST['deleteImages']); } else { $deletes = array($_POST['deleteImages']); } $Category->delete_images($deletes); } if (!empty($_POST['images']) && is_array($_POST['images'])) { $Category->link_images($_POST['images']); $Category->save_imageorder($_POST['images']); if (!empty($_POST['imagedetails']) && is_array($_POST['imagedetails'])) { foreach ($_POST['imagedetails'] as $i => $data) { $Image = new CategoryImage($data['id']); $Image->title = $data['title']; $Image->alt = $data['alt']; $Image->save(); } } } do_action_ref_array('shopp_category_saved', array($Category)); $this->notice(Shopp::__('%s category saved.', '<strong>' . $Category->name . '</strong>')); }