商品情報・グッズメモ アフィリエイト

グッズメモ アフィリエイト・WordPressプラグインのソースコード記事の目次WordPress

ImageItem.php

namespace goodsmemo\item;

/**
 * Description of ImageItem
 *
 * @author Goods Memo
 */
class ImageItem {

    private $imageURL = "";
    private $imageWidth = 0;
    private $imageHeight = 0;

    public function getImageURL() {
	return $this->imageURL;
    }

    public function getImageWidth() {
	return $this->imageWidth;
    }

    public function getImageHeight() {
	return $this->imageHeight;
    }

    public function setImageURL($imageURL) {
	$this->imageURL = $imageURL;
    }

    public function setImageWidth($imageWidth) {
	$this->imageWidth = $imageWidth;
    }

    public function setImageHeight($imageHeight) {
	$this->imageHeight = $imageHeight;
    }

}

Item.php

商品情報を保管します。

namespace goodsmemo\item;

use goodsmemo\item\ImageItem;
use goodsmemo\item\PriceItem;
use goodsmemo\item\PointItem;
use goodsmemo\item\ProductionItem;
use goodsmemo\item\ReviewItem;

require_once GOODS_MEMO_DIR . "item/ImageItem.php";
require_once GOODS_MEMO_DIR . "item/PriceItem.php";
require_once GOODS_MEMO_DIR . "item/PointItem.php";
require_once GOODS_MEMO_DIR . "item/ProductionItem.php";
require_once GOODS_MEMO_DIR . "item/ReviewItem.php";

/**
 * Description of Item
 *
 * @author Goods Memo
 */
class Item {

    private $pageURL = "";
    private $imageItem;
    private $title = "";
    private $priceItem;
    private $pointItem;
    private $productionItem;
    private $binding = ""; //装丁、形式、種別
    private $shop = "";
    private $reviewItem;

    function __construct() {
	$this->imageItem = new ImageItem();
	$this->priceItem = new PriceItem();
	$this->pointItem = new PointItem();
	$this->productionItem = new ProductionItem(); //例:楽天で設定しない場合、空のProductionItemオブジェクトを使う。nullエラーを防げる。
	$this->reviewItem = new ReviewItem();
    }

    public function getPageURL() {
	return $this->pageURL;
    }

    public function setPageURL($pageURL) {
	$this->pageURL = $pageURL;
    }

    public function getImageItem(): ImageItem {
	return $this->imageItem;
    }

    public function setImageItem(ImageItem $imageItem) {
	$this->imageItem = $imageItem;
    }

    public function getTitle() {
	return $this->title;
    }

    public function setTitle($title) {
	$this->title = $title;
    }

    public function getPriceItem(): PriceItem {
	return $this->priceItem;
    }

    public function setPriceItem(PriceItem $priceItem) {
	$this->priceItem = $priceItem;
    }

    public function getPointItem(): PointItem {
	return $this->pointItem;
    }

    public function setPointItem(PointItem $pointItem) {
	$this->pointItem = $pointItem;
    }

    public function getProductionItem(): ProductionItem {
	return $this->productionItem;
    }

    public function setProductionItem(ProductionItem $productionItem) {
	$this->productionItem = $productionItem;
    }

    public function getBinding() {
	return $this->binding;
    }

    public function setBinding($binding) {
	$this->binding = $binding;
    }

    public function getShop() {
	return $this->shop;
    }

    public function setShop($shop) {
	$this->shop = $shop;
    }

    public function getReviewItem(): ReviewItem {
	return $this->reviewItem;
    }

    public function setReviewItem(ReviewItem $reviewItem) {
	$this->reviewItem = $reviewItem;
    }

}

ItemSearchOperation.php

namespace goodsmemo\item;

use goodsmemo\network\URLInfo;
use goodsmemo\item\html\ItemHTMLOption;
use goodsmemo\item\ItemsHTMLInfoMaker;
use goodsmemo\item\html\ItemArrayHTMLMaking;

require_once GOODS_MEMO_DIR . "network/URLInfo.php";
require_once GOODS_MEMO_DIR . "item/html/ItemHTMLOption.php";
require_once GOODS_MEMO_DIR . "item/ItemsHTMLInfoMaker.php";
require_once GOODS_MEMO_DIR . "item/html/ItemArrayHTMLMaking.php";

/**
 * Description of KeywordSearchOperation
 *
 * @author Goods Memo
 */
class ItemSearchOperation {

    public static function makeItemsHTML(
    URLInfo $urlInfo, ItemHTMLOption $itemHTMLOption, ItemsHTMLInfoMaker $itemsHTMLInfoMaker) {

	$cacheExpirationInSeconds = $itemHTMLOption->getCacheExpirationInSeconds();

	if ($cacheExpirationInSeconds <= 0) {

	    $response = $itemsHTMLInfoMaker->requestItemSearch($urlInfo);
	    $itemArray = $itemsHTMLInfoMaker->makeItemArray($response, $itemHTMLOption); // var_dump($itemArray);
	    $itemsHtml = ItemArrayHTMLMaking::makeItemArrayHTML($itemArray, $itemHTMLOption);
	    return $itemsHtml;
	}

	$itemArray;

	$uniqueText = $itemsHTMLInfoMaker->makeUniqueText($itemHTMLOption);
	$transientID = GOODS_MEMO_PREFIX . md5($uniqueText); //var_dump($transientID);

	$cachedItemArray = get_transient($transientID);
	if ($cachedItemArray !== false) {

	    $itemArray = $cachedItemArray;
	} else {

	    $response = $itemsHTMLInfoMaker->requestItemSearch($urlInfo);
	    $itemArray = $itemsHTMLInfoMaker->makeItemArray($response, $itemHTMLOption); // var_dump($itemArray);
	    //一時的に商品情報をデータベースに保存する。有効期限後、削除される。
	    set_transient($transientID, $itemArray, $cacheExpirationInSeconds);
	}

	$itemsHtml = ItemArrayHTMLMaking::makeItemArrayHTML($itemArray, $itemHTMLOption);
	return $itemsHtml;
    }

}

ItemsHTMLInfoMaker.php

namespace goodsmemo\item;

use goodsmemo\network\URLInfo;
use goodsmemo\item\html\ItemHTMLOption;

require_once GOODS_MEMO_DIR . "network/URLInfo.php";
require_once GOODS_MEMO_DIR . "item/html/ItemHTMLOption.php";

/**
 *
 * @author Goods Memo
 */
interface ItemsHTMLInfoMaker {

    public function requestItemSearch(URLInfo $urlInfo);

    public function makeItemArray($response, ItemHTMLOption $itemHTMLOption);

    public function makeUniqueText(ItemHTMLOption $itemHTMLOption);
}

PointItem.php

namespace goodsmemo\item;

/**
 * Description of PointItem
 *
 * @author Goods Memo
 */
class PointItem {

    //今の所、楽天だけで使うアイテムクラス。
    private $pointRate = "";
    private $pointRateStartTime = "";
    private $pointRateEndTime = "";

    public function getPointRate() {
	return $this->pointRate;
    }

    public function getPointRateStartTime() {
	return $this->pointRateStartTime;
    }

    public function getPointRateEndTime() {
	return $this->pointRateEndTime;
    }

    public function setPointRate($pointRate) {
	$this->pointRate = $pointRate;
    }

    public function setPointRateStartTime($pointRateStartTime) {
	$this->pointRateStartTime = $pointRateStartTime;
    }

    public function setPointRateEndTime($pointRateEndTime) {
	$this->pointRateEndTime = $pointRateEndTime;
    }

}

PriceItem.php

namespace goodsmemo\item;

/**
 * Description of PriceItem
 *
 * @author Goods Memo
 */
class PriceItem {

    private $label = "";
    private $price = "";
    private $priceAddition = "";
    private $priceTime = 0;
    private $postageText = "";

    public function getLabel() {
	return $this->label;
    }

    public function setLabel($label) {
	$this->label = $label;
    }

    public function getPrice() {
	return $this->price;
    }

    public function setPrice($price) {
	$this->price = $price;
    }

    public function getPriceAddition() {
	return $this->priceAddition;
    }

    public function setPriceAddition($priceAddition) {
	$this->priceAddition = $priceAddition;
    }

    public function getPriceTime(): float {
	return $this->priceTime;
    }

    public function setPriceTime(float $priceTime) {
	$this->priceTime = $priceTime;
    }

    public function getPostageText() {
	return $this->postageText;
    }

    public function setPostageText($postageText) {
	$this->postageText = $postageText;
    }

}

ProductionItem.php

namespace goodsmemo\item;

/**
 * Description of ProductionItem
 *
 * @author Goods Memo
 */
class ProductionItem {

    private $authorArray = array(); //空のオブジェクト作成に対応するため、空の配列を設定する。
    //
    private $manufacturerLabel = "";
    private $manufacturer = ""; //製造元、メーカー

    public function getAuthorArray() {
	return $this->authorArray;
    }

    public function getManufacturerLabel() {
	return $this->manufacturerLabel;
    }

    public function getManufacturer() {
	return $this->manufacturer;
    }

    public function setAuthorArray($authorArray) {
	$this->authorArray = $authorArray;
    }

    public function setManufacturerLabel($manufacturerLabel) {
	$this->manufacturerLabel = $manufacturerLabel;
    }

    public function setManufacturer($manufacturer) {
	$this->manufacturer = $manufacturer;
    }

}

ReviewItem.php

namespace goodsmemo\item;

/**
 * Description of ReviewItem
 *
 * @author Goods Memo
 */
class ReviewItem {

    private $reviewLineArray = array();
    private $plainTextReview = "";

    public function getReviewLineArray() {
	return $this->reviewLineArray;
    }

    public function getPlainTextReview() {
	return $this->plainTextReview;
    }

    public function setReviewLineArray($reviewLineArray) {
	$this->reviewLineArray = $reviewLineArray;
    }

    public function setPlainTextReview($plainTextReview) {
	$this->plainTextReview = $plainTextReview;
    }

}