当前位置: 首页>>代码示例>>PHP>>正文


PHP ProductDownload::readmeta方法代码示例

本文整理汇总了PHP中ProductDownload::readmeta方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductDownload::readmeta方法的具体用法?PHP ProductDownload::readmeta怎么用?PHP ProductDownload::readmeta使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProductDownload的用法示例。


在下文中一共展示了ProductDownload::readmeta方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: shopp_add_product_download

/**
 * shopp_add_product_download
 *
 * Add product download file to a product/variation.
 *
 * @api
 * @since 1.2
 *
 * @param int $product id of the product the download asset will be added to
 * @param string $file full or correct relative path to the download file asset.
 * @param int $variant id of the variant the download asset will be attached to.  For products with variants, this is a required parameter.
 * @return mixed false of failure, the new download asset id on success
 **/
function shopp_add_product_download($product, $file, $variant = false)
{
    if (empty($product) || empty($file)) {
        shopp_debug(__FUNCTION__ . ' failed: One or more missing parameters.');
        return false;
    }
    $File = new ProductDownload();
    $instore = $File->found($file);
    if (!$instore && (!is_file($file) || !is_readable($file))) {
        shopp_debug(__FUNCTION__ . " failed for file {$file}: File missing or unreadable.");
        return false;
    }
    $Product = new ShoppProduct($product);
    if (empty($Product->id)) {
        shopp_debug(__FUNCTION__ . " failed for file {$file}: No such product with id {$product}.");
        return false;
    }
    $Product->load_data(array('summary', 'prices'));
    if ("on" == $Product->variants && false === $variant) {
        shopp_debug(__FUNCTION__ . " failed for file {$file}: You must specify the variant id parameter for product {$product}.");
        return false;
    }
    $Price = reset($Product->prices);
    if (empty($Price->id)) {
        shopp_debug(__FUNCTION__ . " failed for file {$file}: Failed to load product variants.");
        return false;
    }
    if ($variant) {
        $Price = false;
        foreach ($Product->prices as $Price) {
            if ($variant == $Price->id) {
                break;
            }
        }
        if (false === $Price) {
            shopp_debug(__FUNCTION__ . " failed for file {$file}: You must specify a valid variant id parameter for product {$product}.");
            return false;
        }
    }
    // Save the uploaded file
    $File->load(array('type' => 'download', 'parent' => $Price->id));
    $File->parent = $Price->id;
    $File->context = "price";
    $File->type = "download";
    $File->name = basename($file);
    $File->filename = $File->name;
    if (!$instore) {
        $File->mime = file_mimetype($file, $File->name);
        $File->size = filesize($file);
        $File->store($file, 'file');
    } else {
        $File->uri = $file;
        $File->readmeta();
    }
    $File->save();
    if ($File->id) {
        return $File->id;
    }
    shopp_debug(__FUNCTION__ . " failed for file {$file}");
    return false;
}
开发者ID:forthrobot,项目名称:inuvik,代码行数:74,代码来源:asset.php

示例2: save


//.........这里部分代码省略.........
                 shopp_set_meta($Price->id, 'price', 'settings', $priceline['settings']);
             }
             if (!empty($priceline['options'])) {
                 shopp_set_meta($Price->id, 'price', 'options', $priceline['options']);
             }
             $Product->sumprice($Price);
             if (!empty($priceline['download'])) {
                 $Price->attach_download($priceline['download']);
             }
             if (!empty($priceline['downloadpath'])) {
                 // Attach file specified by URI/path
                 if (!empty($Price->download->id) || empty($Price->download) && $Price->load_download()) {
                     $File = $Price->download;
                 } else {
                     $File = new ProductDownload();
                 }
                 $stored = false;
                 $tmpfile = sanitize_path($priceline['downloadpath']);
                 $File->storage = false;
                 $Engine = $File->engine();
                 // Set engine from storage settings
                 $File->parent = $Price->id;
                 $File->context = "price";
                 $File->type = "download";
                 $File->name = !empty($priceline['downloadfile']) ? $priceline['downloadfile'] : basename($tmpfile);
                 $File->filename = $File->name;
                 if ($File->found($tmpfile)) {
                     $File->uri = $tmpfile;
                     $stored = true;
                 } else {
                     $stored = $File->store($tmpfile, 'file');
                 }
                 if ($stored) {
                     $File->readmeta();
                     $File->save();
                 }
             }
             // END attach file by path/uri
         }
         // END foreach()
         unset($Price);
     }
     // END if (!empty($_POST['price']))
     $Product->load_sold($Product->id);
     // Refresh accurate product sales stats
     $Product->sumup();
     // Update taxonomies after pricing summary is generated
     // Summary table entry is needed for ProductTaxonomy::recount() to
     // count properly based on aggregate product inventory, see #2968
     foreach (get_object_taxonomies(Product::$posttype) as $taxonomy) {
         $tags = '';
         $taxonomy_obj = get_taxonomy($taxonomy);
         if (isset($_POST['tax_input']) && isset($_POST['tax_input'][$taxonomy])) {
             $tags = $_POST['tax_input'][$taxonomy];
             if (is_array($tags)) {
                 // array = hierarchical, string = non-hierarchical.
                 $tags = array_filter($tags);
             }
         }
         if (current_user_can($taxonomy_obj->cap->assign_terms)) {
             wp_set_post_terms($Product->id, $tags, $taxonomy);
         }
     }
     // Ensure taxonomy counts are updated on status changes, see #2968
     if ($status != $_POST['status']) {
         $Post = new StdClass();
开发者ID:forthrobot,项目名称:inuvik,代码行数:67,代码来源:Warehouse.php

示例3: import_file

 public function import_file()
 {
     check_admin_referer('wp_ajax_shopp_import_file');
     $Shopp = Shopp::object();
     $Engine =& $Shopp->Storage->engines['download'];
     $error = create_function('$s', 'die(json_encode(array("error" => $s)));');
     if (empty($_REQUEST['url'])) {
         $error(__('No file import URL was provided.', 'Shopp'));
     }
     $url = $_REQUEST['url'];
     $request = parse_url($url);
     $headers = array();
     $filename = basename($request['path']);
     $_ = new StdClass();
     $_->name = $filename;
     $_->stored = false;
     $File = new ProductDownload();
     $stored = false;
     $File->engine();
     // Set engine from storage settings
     $File->uri = sanitize_path($url);
     $File->type = "download";
     $File->name = $filename;
     $File->filename = $filename;
     if ($File->found()) {
         // File in storage, look up meta from storage engine
         $File->readmeta();
         $_->stored = true;
         $_->path = $File->uri;
         $_->size = $File->size;
         $_->mime = $File->mime;
         if ($_->mime == "application/octet-stream" || $_->mime == "text/plain") {
             $mime = file_mimetype($File->name);
         }
         if ($mime == "application/octet-stream" || $mime == "text/plain") {
             $_->mime = $mime;
         }
     } else {
         if (!($importfile = @tempnam(sanitize_path(realpath(SHOPP_TEMP_PATH)), 'shp'))) {
             $error(sprintf(__('A temporary file could not be created for importing the file.', 'Shopp'), $importfile));
         }
         if (!($incoming = @fopen($importfile, 'w'))) {
             $error(sprintf(__('A temporary file at %s could not be opened for importing.', 'Shopp'), $importfile));
         }
         if (!($file = @fopen(linkencode($url), 'rb'))) {
             $error(sprintf(__('The file at %s could not be opened for importing.', 'Shopp'), $url));
         }
         $data = @stream_get_meta_data($file);
         if (isset($data['timed_out']) && $data['timed_out']) {
             $error(__('The connection timed out while trying to get information about the target file.', 'Shopp'));
         }
         if (isset($data['wrapper_data'])) {
             foreach ($data['wrapper_data'] as $d) {
                 if (strpos($d, ':') === false) {
                     continue;
                 }
                 list($name, $value) = explode(': ', $d);
                 if ($rel = strpos($value, ';')) {
                     $headers[$name] = substr($value, 0, $rel);
                 } else {
                     $headers[$name] = $value;
                 }
             }
         }
         $tmp = basename($importfile);
         // $Settings =& ShoppSettings();
         $_->path = $importfile;
         if (empty($headers)) {
             // Stat file data directly if no stream data available
             $_->size = filesize($url);
             $_->mime = file_mimetype($url);
         } else {
             // Use the stream data
             $_->size = $headers['Content-Length'];
             $_->mime = $headers['Content-Type'] == 'text/plain' ? file_mimetype($_->name) : $headers['Content-Type'];
         }
     }
     // Mimetype must be set or we'll have problems in the UI
     if (!$_->mime) {
         $_->mime = "application/octet-stream";
     }
     echo str_repeat(' ', 1024);
     // Minimum browser data
     echo '<script type="text/javascript">var importFile = ' . json_encode($_) . ';</script>' . "\n";
     echo '<script type="text/javascript">var importProgress = 0;</script>' . "\n";
     if ($_->stored) {
         exit;
     }
     @ob_flush();
     @flush();
     $progress = 0;
     $bytesread = 0;
     fseek($file, 0);
     $packet = 1024 * 1024;
     set_time_limit(0);
     // Prevent timeouts
     while (!feof($file)) {
         if (connection_status() !== 0) {
             return false;
         }
//.........这里部分代码省略.........
开发者ID:msigley,项目名称:shopp,代码行数:101,代码来源:Ajax.php

示例4: substr


//.........这里部分代码省略.........
				$option['weight'] = floatvalue($option['weight']);
				if (isset($options['dimensions']) && is_array($options['dimensions']))
					foreach ($option['dimensions'] as &$dimension)
						$dimension = floatvalue($dimension);

				$Price->updates($option);
				$Price->save();

				if (!empty($option['download'])) $Price->attach_download($option['download']);

				if (!empty($option['downloadpath'])) { // Attach file specified by URI/path
					if (!empty($Price->download->id) || (empty($Price->download) && $Price->load_download())) {
						$File = $Price->download;
					} else $File = new ProductDownload();

					$stored = false;
					$tmpfile = sanitize_path($option['downloadpath']);

					$File->storage = false;
					$Engine = $File->_engine(); // Set engine from storage settings

					$File->parent = $Price->id;
					$File->context = "price";
					$File->type = "download";
					$File->name = !empty($option['downloadfile'])?$option['downloadfile']:basename($tmpfile);
					$File->filename = $File->name;

					if ($File->found($tmpfile)) {
						$File->uri = $tmpfile;
						$stored = true;
					} else $stored = $File->store($tmpfile,'file');

					if ($stored) {
						$File->readmeta();
						$File->save();
					}

				} // END attach file by path/uri
			}
			unset($Price);
		}

		// No variation options at all, delete all variation-pricelines
		if (!empty($Product->prices) && is_array($Product->prices)
				&& (empty($_POST['options']['v']) || empty($_POST['options']['a']))) {
			foreach ($Product->prices as $priceline) {
				// Skip if not tied to variation options
				if ($priceline->optionkey == 0) continue;
				if ((empty($_POST['options']['v']) && $priceline->context == "variation")
					|| (empty($_POST['options']['a']) && $priceline->context == "addon")) {
						$Price = new Price($priceline->id);
						$Price->delete();
				}
			}
		}

		if (!empty($_POST['details']) || !empty($_POST['deletedSpecs'])) {
			$deletes = array();
			if (!empty($_POST['deletedSpecs'])) {
				if (strpos($_POST['deletedSpecs'],","))	$deletes = explode(',',$_POST['deletedSpecs']);
				else $deletes = array($_POST['deletedSpecs']);
				foreach($deletes as $option) {
					$Spec = new Spec($option);
					$Spec->delete();
				}
				unset($Spec);
开发者ID:robbiespire,项目名称:paQui,代码行数:67,代码来源:Warehouse.php

示例5: array

	function import_file () {
		check_admin_referer('wp_ajax_ecart_import_file');
		global $Ecart;
		$Engine =& $Ecart->Storage->engines['download'];

		$error = create_function('$s', 'die(json_encode(array("error" => $s)));');
		if (empty($_REQUEST['url'])) $error(__('No file import URL was provided.','Ecart'));
		$url = $_REQUEST['url'];
		$request = parse_url($url);
		$headers = array();
		$filename = basename($request['path']);

		$_ = new StdClass();
		$_->name = $filename;
		$_->stored = false;


		$File = new ProductDownload();
		$stored = false;
		$File->_engine(); // Set engine from storage settings
		$File->uri = sanitize_path($url);
		$File->type = "download";
		$File->name = $filename;
		$File->filename = $filename;

		if ($File->found()) {
			// File in storage, look up meta from storage engine
			$File->readmeta();
			$_->stored = true;
			$_->path = $File->uri;
			$_->size = $File->size;
			$_->mime = $File->mime;
			if ($_->mime == "application/octet-stream" || $_->mime == "text/plain")
				$mime = file_mimetype($File->name);
			if ($mime == "application/octet-stream" || $mime == "text/plain")
				$_->mime = $mime;
		} else {
			if (!$importfile = @tempnam(sanitize_path(realpath(ECART_TEMP_PATH)), 'shp')) $error(sprintf(__('A temporary file could not be created for importing the file.','Ecart'),$importfile));
			if (!$incoming = @fopen($importfile,'w')) $error(sprintf(__('A temporary file at %s could not be opened for importing.','Ecart'),$importfile));

			if (!$file = @fopen(linkencode($url), 'rb')) $error(sprintf(__('The file at %s could not be opened for importing.','Ecart'),$url));
			$data = @stream_get_meta_data($file);

			if (isset($data['timed_out']) && $data['timed_out']) $error(__('The connection timed out while trying to get information about the target file.','Ecart'));

			if (isset($data['wrapper_data'])) {
				foreach ($data['wrapper_data'] as $d) {
					if (strpos($d,':') === false) continue;
					list($name,$value) = explode(': ',$d);
					if ($rel = strpos($value,';')) $headers[$name] = substr($value,0,$rel);
					else $headers[$name] = $value;
				}
			}

			$tmp = basename($importfile);
			$Settings =& EcartSettings();

			$_->path = $importfile;
			if (empty($headers)) {
				// Stat file data directly if no stream data available
				$_->size = filesize($url);
				$_->mime = file_mimetype($url);
			} else {
				// Use the stream data
				$_->size = $headers['Content-Length'];
				$_->mime = $headers['Content-Type'] == 'text/plain'?file_mimetype($_->name):$headers['Content-Type'];
			}
		}

		// Mimetype must be set or we'll have problems in the UI
		if (!$_->mime) $_->mime = "application/octet-stream";

		ob_end_clean();
		header("Connection: close");
		header("Content-Encoding: none");
		ob_start();
	 	echo json_encode($_);
		$size = ob_get_length();
		header("Content-Length: $size");
		ob_end_flush();
		flush();
		ob_end_clean();

		if ($_->stored) return;

		$progress = 0;
		fseek($file, 0);
		$packet = 1024*1024;
		while(!feof($file)) {
			if (connection_status() !== 0) return false;
			$buffer = fread($file,$packet);
			if (!empty($buffer)) {
				fwrite($incoming, $buffer);
				$progress += strlen($buffer);
				$Settings->save($tmp.'_import_progress',$progress);
			}
		}
		fclose($file);
		fclose($incoming);

//.........这里部分代码省略.........
开发者ID:robbiespire,项目名称:paQui,代码行数:101,代码来源:Ajax.php


注:本文中的ProductDownload::readmeta方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。