Beispiel #1
0
	/**
	 * Set
	 *
	 * @since 1.1
	 *
	 * @return void Description...
	 **/
	function init_positions () {
		$db =& DB::get();
		// Load the entire catalog structure and update the category positions
		$Catalog = new Catalog();
		$Catalog->outofstock = true;

		$filters['columns'] = "cat.id,cat.parent,cat.priority";
		$Catalog->load_categories($filters);

		foreach ($Catalog->categories as $Category)
			if (!isset($Category->_priority) // Check previous priority and only save changes
					|| (isset($Category->_priority) && $Category->_priority != $Category->priority))
				$db->query("UPDATE $Category->_table SET priority=$Category->priority WHERE id=$Category->id");

	}
Beispiel #2
0
	/**
	 * Updates category slug and rebuilds changed URIs
	 *
	 * Generates the slug if empty. Checks for duplicate slugs
	 * and adds a numeric suffix to ensure a unique slug.
	 *
	 * If the slug changes, the category uri is rebuilt and
	 * and all descendant category uri's are rebuilt and updated.
	 * 
	 * @since 1.1
	 *
	 * @return boolean successfully updated
	 **/
	function update_slug () {
		$db = DB::get();

		if (empty($this->slug)) {
			$name = !empty($_POST['name'])?$_POST['name']:$this->name;
			$this->slug = sanitize_title_with_dashes($name);
		}

		if (empty($this->slug)) return false; // No slug for this category, bail

		$uri = $this->uri;
		$parent = !empty($_POST['parent'])?$_POST['parent']:$this->parent;
		if ($parent > 0) {

			$Catalog = new Catalog();
			$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
			));

			$paths = array();
			if (!empty($this->slug)) $paths = array($this->slug);  // Include self

			$parentkey = -1;
			// If we're saving a new category, lookup the parent
			if ($parent > 0) {
				array_unshift($paths,$Catalog->categories['_'.$parent]->slug);
				$parentkey = $Catalog->categories['_'.$parent]->parent;
			}

			while (isset($Catalog->categories['_'.$parentkey])
					&& $category_tree = $Catalog->categories['_'.$parentkey]) {
				array_unshift($paths,$category_tree->slug);
				$parentkey = '_'.$category_tree->parent;
			}
			if (count($paths) > 1) $this->uri = join("/",$paths);
			else $this->uri = $paths[0];
		} else $this->uri = $this->slug; // end if ($parent > 0)

		// Check for an existing category uri
		$exclude_category = !empty($this->id)?"AND id != $this->id":"";
		$existing = $db->query("SELECT uri FROM $this->_table WHERE uri='$this->uri' $exclude_category LIMIT 1");
		if ($existing) {
			$suffix = 2;
			while($existing) {
				$altslug = preg_replace('/\-\d+$/','',$this->slug)."-".$suffix++;
				$uris = explode('/',$this->uri);
				array_splice($uris,-1,1,$altslug);
				$alturi = join('/',$uris);
				$existing = $db->query("SELECT uri FROM $this->_table WHERE uri='$alturi' $exclude_category LIMIT 1");
			}
			$this->slug = $altslug;
			$this->uri = $alturi;
		}

		if ($uri == $this->uri) return true;

		// Update children uris
		$this->load_children(array(
			'columns' 	=> 'cat.id,cat.parent,cat.uri',
			'where' 	=> array("(cat.uri like '%$uri%' OR cat.parent='$this->id')","cat.id <> '$this->id'")
		));
		if (empty($this->children)) return true;

		$categoryuri = explode('/',$this->uri);
		foreach ($this->children as $child) {
			$childuri = explode('/',$child->uri);
			$changed = reset(array_diff($childuri,$categoryuri));
			array_splice($childuri,array_search($changed,$childuri),1,end($categoryuri));
			$updateduri = join('/',$childuri);
			$db->query("UPDATE $this->_table SET uri='$updateduri' WHERE id='$child->id' LIMIT 1");
		}

	}
 /**
  * ajax ()
  * Handles AJAX request processing */
 function ajax()
 {
     if (!isset($_REQUEST['action']) || !defined('DOING_AJAX')) {
         return;
     }
     if (isset($_POST['action'])) {
         switch ($_POST['action']) {
             // Upload an image in the product editor
             case "shopp_add_image":
                 $this->Flow->add_images();
                 exit;
                 break;
                 // Upload a product download file in the product editor
             // Upload a product download file in the product editor
             case "shopp_add_download":
                 $this->Flow->product_downloads();
                 exit;
                 break;
         }
     }
     if ((!is_user_logged_in() || !current_user_can('manage_options')) && strpos($_GET['action'], 'wp_ajax_shopp_') !== false) {
         die('-1');
     }
     if (empty($_GET['action'])) {
         return;
     }
     switch ($_GET['action']) {
         // Add a category in the product editor
         case "wp_ajax_shopp_add_category":
             check_admin_referer('shopp-ajax_add_category');
             if (!empty($_GET['name'])) {
                 $Catalog = new Catalog();
                 $Catalog->load_categories();
                 $Category = new Category();
                 $Category->name = $_GET['name'];
                 $Category->slug = sanitize_title_with_dashes($Category->name);
                 $Category->parent = $_GET['parent'];
                 // Work out pathing
                 $paths = array();
                 if (!empty($Category->slug)) {
                     $paths = array($Category->slug);
                 }
                 // Include self
                 $parentkey = -1;
                 // If we're saving a new category, lookup the parent
                 if ($Category->parent > 0) {
                     array_unshift($paths, $Catalog->categories[$Category->parent]->slug);
                     $parentkey = $Catalog->categories[$Category->parent]->parent;
                 }
                 while ($category_tree = $Catalog->categories[$parentkey]) {
                     array_unshift($paths, $category_tree->slug);
                     $parentkey = $category_tree->parent;
                 }
                 if (count($paths) > 1) {
                     $Category->uri = join("/", $paths);
                 } else {
                     $Category->uri = $paths[0];
                 }
                 $Category->save();
                 echo json_encode($Category);
             }
             exit;
             break;
         case "wp_ajax_shopp_edit_slug":
             check_admin_referer('shopp-ajax_edit_slug');
             if (!current_user_can('manage_options')) {
                 die("-1");
             }
             switch ($_REQUEST['type']) {
                 case "category":
                     $Category = new Category($_REQUEST['id']);
                     if (empty($_REQUEST['slug'])) {
                         $_REQUEST['slug'] = $Category->name;
                     }
                     $Category->slug = sanitize_title_with_dashes($_REQUEST['slug']);
                     if ($Category->save()) {
                         echo apply_filters('editable_slug', $Category->slug);
                     } else {
                         echo '-1';
                     }
                     break;
                 case "product":
                     $Product = new Product($_REQUEST['id']);
                     if (empty($_REQUEST['slug'])) {
                         $_REQUEST['slug'] = $Product->name;
                     }
                     $Product->slug = sanitize_title_with_dashes($_REQUEST['slug']);
                     if ($Product->save()) {
                         echo apply_filters('editable_slug', $Product->slug);
                     } else {
                         echo '-1';
                     }
                     break;
             }
             exit;
             break;
             // Upload a product download file in the product editor
         // Upload a product download file in the product editor
         case "wp_ajax_shopp_verify_file":
             check_admin_referer('shopp-ajax_verify_file');
             if (!current_user_can('manage_options')) {
                 exit;
             }
             $target = trailingslashit($this->Settings->get('products_path')) . $_POST['filepath'];
             if (!file_exists($target)) {
                 die("NULL");
             }
             if (is_dir($target)) {
                 die("ISDIR");
             }
             if (!is_readable($target)) {
                 die("READ");
             }
             die("OK");
             break;
             // Perform a version check for any updates
         // Perform a version check for any updates
         case "wp_ajax_shopp_version_check":
             check_admin_referer('shopp-wp_ajax_shopp_update');
             $request = array("ShoppServerRequest" => "version-check", "ver" => '1.0');
             $data = array('core' => SHOPP_VERSION, 'addons' => join("-", $this->Flow->validate_addons()));
             echo $this->Flow->callhome($request, $data);
             exit;
         case "wp_ajax_shopp_verify":
             if ($this->Settings->get('maintenance') == "on") {
                 echo "1";
             }
             exit;
             // Perform an update process
         // Perform an update process
         case "wp_ajax_shopp_update":
             check_admin_referer('shopp-wp_ajax_shopp_update');
             $this->Flow->update();
             exit;
         case "wp_ajax_shopp_setftp":
             check_admin_referer('shopp-wp_ajax_shopp_update');
             $this->Flow->settings_save();
             $updates = $this->Settings->get('ftp_credentials');
             exit;
     }
 }
 /**
  * Category flow handlers
  **/
 function categories_list($workflow = false)
 {
     global $Shopp;
     $db = DB::get();
     if (!current_user_can(SHOPP_USERLEVEL)) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     $defaults = array('pagenum' => 1, 'per_page' => 20, 's' => '');
     $args = array_merge($defaults, $_GET);
     extract($args, EXTR_SKIP);
     $pagenum = absint($pagenum);
     if (empty($pagenum)) {
         $pagenum = 1;
     }
     if (!$per_page || $per_page < 0) {
         $per_page = 20;
     }
     $start = $per_page * ($pagenum - 1);
     $filters = array();
     // $filters['limit'] = "$start,$per_page";
     if (!empty($s)) {
         $filters['where'] = "cat.name LIKE '%{$s}%'";
     } else {
         $filters['where'] = "true";
     }
     $table = DatabaseObject::tablename(Category::$table);
     $Catalog = new Catalog();
     $Catalog->outofstock = true;
     if ($workflow) {
         $filters['columns'] = "cat.id,cat.parent";
         $results = $Catalog->load_categories($filters, false, true);
         return array_slice($results, $start, $per_page);
     } else {
         $filters['columns'] = "cat.id,cat.parent,cat.name,cat.description,cat.uri,cat.slug,cat.spectemplate,cat.facetedmenus,count(DISTINCT pd.id) AS total";
         $Catalog->load_categories($filters);
         $Categories = array_slice($Catalog->categories, $start, $per_page);
     }
     $count = $db->query("SELECT count(*) AS total FROM {$table}");
     $num_pages = ceil($count->total / $per_page);
     $page_links = paginate_links(array('base' => add_query_arg(array('edit' => null, 'pagenum' => '%#%')), 'format' => '', 'total' => $num_pages, 'current' => $pagenum));
     include "{$this->basepath}/core/ui/categories/categories.php";
 }
Beispiel #5
0
	function category_children () {
		check_admin_referer('wp_ajax_ecart_category_children');

		if (empty($_GET['parent'])) die('0');
		$parent = $_GET['parent'];

		$columns = array('id','parent','priority','name','uri','slug');

		$filters['columns'] = 'cat.'.join(',cat.',$columns);
		$filters['parent'] = $parent;

		$Catalog = new Catalog();
		$Catalog->outofstock = true;
		$Catalog->load_categories($filters);

		$columns[] = 'depth';
		foreach ($Catalog->categories as &$Category) {
			$properties = get_object_vars($Category);
			foreach ($properties as $property => $value)
				if (!in_array($property,$columns)) unset($Category->$property);
		}

		die(json_encode($Catalog->categories));
	}