アマゾンの設定画面・グッズメモ アフィリエイト

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

AmazonSettingSection.php

アマゾンの設定画面を表示します。

namespace goodsmemo\option\amazon;

use goodsmemo\option\AbstractSettingSection;
use goodsmemo\option\PageInfo;
use goodsmemo\option\SettingSection;
use goodsmemo\option\SectionInfo;
use goodsmemo\option\paragraph\URLParagraph;
use goodsmemo\option\paragraph\ItemHTMLParagraph;
use goodsmemo\option\paragraph\ReviewParagraph;
use goodsmemo\option\amazon\URLParagraphUtils;
use goodsmemo\option\amazon\CommonRESTParagraph;
use goodsmemo\option\amazon\CommonRESTParagraphUtils;
use goodsmemo\option\amazon\ItemHTMLParagraphUtils;
use goodsmemo\option\amazon\ReviewParagraphUtils;
use goodsmemo\option\amazon\ProductTypeParagraph;
use goodsmemo\option\amazon\ProductTypeParagraphUtils;
use goodsmemo\option\amazon\RESTParagraph;
use goodsmemo\option\amazon\RESTParagraphUtils;

require_once GOODS_MEMO_DIR . "option/AbstractSettingSection.php";
require_once GOODS_MEMO_DIR . "option/PageInfo.php";
require_once GOODS_MEMO_DIR . "option/SettingSection.php";
require_once GOODS_MEMO_DIR . "option/SectionInfo.php";
require_once GOODS_MEMO_DIR . "option/paragraph/URLParagraph.php";
require_once GOODS_MEMO_DIR . "option/paragraph/ItemHTMLParagraph.php";
require_once GOODS_MEMO_DIR . "option/paragraph/ReviewParagraph.php";
require_once GOODS_MEMO_DIR . "option/amazon/URLParagraphUtils.php";
require_once GOODS_MEMO_DIR . "option/amazon/CommonRESTParagraph.php";
require_once GOODS_MEMO_DIR . "option/amazon/CommonRESTParagraphUtils.php";
require_once GOODS_MEMO_DIR . "option/amazon/ItemHTMLParagraphUtils.php";
require_once GOODS_MEMO_DIR . "option/amazon/ReviewParagraphUtils.php";
require_once GOODS_MEMO_DIR . "option/amazon/ProductTypeParagraph.php";
require_once GOODS_MEMO_DIR . "option/amazon/ProductTypeParagraphUtils.php";
require_once GOODS_MEMO_DIR . "option/amazon/RESTParagraph.php";
require_once GOODS_MEMO_DIR . "option/amazon/RESTParagraphUtils.php";

/**
 * Description of AmazonSettionSection
 *
 * @author Goods Memo
 */
class AmazonSettingSection extends AbstractSettingSection {

    const ID_PREFIX = "amazon";

    public function initSection(PageInfo $pageInfo) {

	$sectionInfo = new SectionInfo();
	$sectionInfo->setSectionID("amazon_section_id");
	$sectionInfo->setSectionTitle("アマゾンの設定");

	add_settings_section(
		$sectionInfo->getSectionID(), // ID
		$sectionInfo->getSectionTitle(), // Title
		array($this, SettingSection::PRINT_SECTION_INFO_FUNCTION_NAME), // Callback
		$pageInfo->getSettingMenuSlug() //設定ページのslug。メニューのslugと同じもの。
	);

	$urlParagraph = new URLParagraph();
	$urlFieldInfoArray = URLParagraphUtils::makeFieldInfoArray();
	$urlParagraph->initParagraph($pageInfo, $sectionInfo, $urlFieldInfoArray);
	parent::addParagraph($urlParagraph);

	$commonRESTParagraph = new CommonRESTParagraph();
	$commonRESTFieldInfoArray = CommonRESTParagraphUtils::makeFieldInfoArray();
	$commonRESTParagraph->initParagraph($pageInfo, $sectionInfo, $commonRESTFieldInfoArray);
	parent::addParagraph($commonRESTParagraph);

	$itemHTMLParagraph = new ItemHTMLParagraph();
	$itemHTMLFieldInfoArray = ItemHTMLParagraphUtils::makeFieldInfoArray();
	$itemHTMLParagraph->initParagraph($pageInfo, $sectionInfo, $itemHTMLFieldInfoArray);
	parent::addParagraph($itemHTMLParagraph);

	$reviewParagraph = new ReviewParagraph();
	$reviewFieldInfoArray = ReviewParagraphUtils::makeFieldInfoArray();
	$reviewParagraph->initParagraph($pageInfo, $sectionInfo, $reviewFieldInfoArray);
	parent::addParagraph($reviewParagraph);

	$productTypeParagraph = new ProductTypeParagraph();
	$productTypeFieldInfoArray = ProductTypeParagraphUtils::makeFieldInfoArray();
	$productTypeParagraph->initParagraph($pageInfo, $sectionInfo, $productTypeFieldInfoArray);
	parent::addParagraph($productTypeParagraph);

	$restParagraph = new RESTParagraph();
	$restFieldInfoArray = RESTParagraphUtils::makeFieldInfoArray();
	$restParagraph->initParagraph($pageInfo, $sectionInfo, $restFieldInfoArray);
	parent::addParagraph($restParagraph);
    }

    public function printSectionInfo() {
	print 'アマゾンアフィリエイトの設定を入力してください。未入力の場合、初期値を表示します。';
    }

}

CommonRESTParagraph.php

namespace goodsmemo\option\amazon;

use goodsmemo\option\paragraph\AbstractParagraph;
use goodsmemo\option\paragraph\AbstractTextParagraph;
use goodsmemo\option\PageInfo;
use goodsmemo\option\SectionInfo;
use goodsmemo\option\field\TextField;

require_once GOODS_MEMO_DIR . "option/paragraph/AbstractParagraph.php";
require_once GOODS_MEMO_DIR . "option/paragraph/AbstractTextParagraph.php";
require_once GOODS_MEMO_DIR . "option/PageInfo.php";
require_once GOODS_MEMO_DIR . "option/SectionInfo.php";
require_once GOODS_MEMO_DIR . "option/field/TextField.php";

/**
 * Description of CommonRESTParagraph
 *
 * @author Goods Memo
 */
class CommonRESTParagraph extends AbstractParagraph {

    use AbstractTextParagraph;

    public function initParagraph(PageInfo $pageInfo, SectionInfo $sectionInfo, $fieldInfoArray) {

	parent::setOptionGroup($pageInfo->getOptionGroup());
	parent::setSectionTitle($sectionInfo->getSectionTitle());
	parent::setFieldInfoArray($fieldInfoArray);

	$paaAccessKeyTextField = new TextField($pageInfo->getOptionNameOfDatabase(), $fieldInfoArray[0]);
	parent::addField($pageInfo, $sectionInfo, $paaAccessKeyTextField);

	$paaAssociateTagTextField = new TextField($pageInfo->getOptionNameOfDatabase(), $fieldInfoArray[1]);
	parent::addField($pageInfo, $sectionInfo, $paaAssociateTagTextField);

	$paaSecretKeyTextField = new TextField($pageInfo->getOptionNameOfDatabase(), $fieldInfoArray[2]);
	parent::addField($pageInfo, $sectionInfo, $paaSecretKeyTextField);
    }

    public function sanitizeParagraphValue($inputedValueMap, &$sanitizedValueMap) {
	//sanitizedValueMap:変更するため、配列の参照渡しとする。

	$this->validateExistence($inputedValueMap);
	parent::sanitizeParagraphValue($inputedValueMap, $sanitizedValueMap);
    }

}

CommonRESTParagraphUtils.php

namespace goodsmemo\option\amazon;

use goodsmemo\option\field\FieldInfo;
use goodsmemo\option\amazon\AmazonSettingSection;

require_once GOODS_MEMO_DIR . "option/field/FieldInfo.php";
require_once GOODS_MEMO_DIR . "option/amazon/AmazonSettingSection.php";

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

    const DEFAULT_SERVICE = "AWSECommerceService";
    //
    const PAA_ACCESS_KEY_ID = AmazonSettingSection::ID_PREFIX . "_paa_access_key_id";
    const PAA_ASSOCIATE_TAG_ID = AmazonSettingSection::ID_PREFIX . "_paa_associate_tag_id";
    const PAA_SECRET_KEY_ID = AmazonSettingSection::ID_PREFIX . "_paa_secret_key_id";

    public static function makeFieldInfoArray() {

	$fieldInfoArray = array();

	$paaAccessKeyFieldInfo = new FieldInfo();
	$paaAccessKeyFieldInfo->setFieldID(CommonRESTParagraphUtils::PAA_ACCESS_KEY_ID);
	$paaAccessKeyFieldInfo->setFieldLabel('Product Advertising API アクセスキー');
	$paaAccessKeyFieldInfo->setDefaultFieldValue("");
	array_push($fieldInfoArray, $paaAccessKeyFieldInfo);

	$paaAssociateTagFieldInfo = new FieldInfo();
	$paaAssociateTagFieldInfo->setFieldID(CommonRESTParagraphUtils::PAA_ASSOCIATE_TAG_ID);
	$paaAssociateTagFieldInfo->setFieldLabel('Product Advertising API アソシエイトタグ');
	$paaAssociateTagFieldInfo->setDefaultFieldValue("");
	array_push($fieldInfoArray, $paaAssociateTagFieldInfo);

	$paaSecretKeyFieldInfo = new FieldInfo();
	$paaSecretKeyFieldInfo->setFieldID(CommonRESTParagraphUtils::PAA_SECRET_KEY_ID);
	$paaSecretKeyFieldInfo->setFieldLabel('Product Advertising API シークレットキー');
	$paaSecretKeyFieldInfo->setDefaultFieldValue("");
	array_push($fieldInfoArray, $paaSecretKeyFieldInfo);

	return $fieldInfoArray;
    }

}

ItemHTMLParagraphUtils.php

namespace goodsmemo\option\amazon;

use goodsmemo\option\field\FieldInfo;
use goodsmemo\option\paragraph\ItemHTMLParagraph;
use goodsmemo\option\amazon\AmazonSettingSection;

require_once GOODS_MEMO_DIR . "option/field/FieldInfo.php";
require_once GOODS_MEMO_DIR . "option/paragraph/ItemHTMLParagraph.php";
require_once GOODS_MEMO_DIR . "option/amazon/AmazonSettingSection.php";

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

    const DEFAULT_NUMBER_TO_DISPLAY = 1;
    //
    const TITLE_LENGTH_ID = AmazonSettingSection::ID_PREFIX . "_title_length_id";
    const CACHE_EXPIRATION_IN_SECONDS_ID = AmazonSettingSection::ID_PREFIX . "_cache_expiration_in_seconds_id";

    public static function makeFieldInfoArray() {

	$fieldInfoArray = array();

	$titleLengthFieldInfo = new FieldInfo();
	$titleLengthFieldInfo->setFieldID(ItemHTMLParagraphUtils::TITLE_LENGTH_ID);
	$titleLengthFieldInfo->setFieldLabel(ItemHTMLParagraph::DEFAULT_TITLE_LENGTH_LABEL);
	$titleLengthFieldInfo->setDefaultFieldValue(ItemHTMLParagraph::DEFAULT_TITLE_LENGTH_VALUE);
	$titleLengthFieldInfo->setNumericalVerificationEnabled(true);
	array_push($fieldInfoArray, $titleLengthFieldInfo);

	$cacheExpirationInSecondsFieldInfo = new FieldInfo();
	$cacheExpirationInSecondsFieldInfo->setFieldID(ItemHTMLParagraphUtils::CACHE_EXPIRATION_IN_SECONDS_ID);
	$cacheExpirationInSecondsFieldInfo->setFieldLabel(
		ItemHTMLParagraph::DEFAULT_CACHE_EXPIRATION_IN_SECONDS_LABEL);
	//Product Advertising APIの場合、初期リクエスト可能数 : 1日あたり 8,640リクエスト(API利用開始より60日間)
	$cacheExpirationInSecondsFieldInfo->setDefaultFieldValue(21600); //例:6時間の場合、3600 * 6 = 21600秒
	$cacheExpirationInSecondsFieldInfo->setNumericalVerificationEnabled(true);
	array_push($fieldInfoArray, $cacheExpirationInSecondsFieldInfo);

	return $fieldInfoArray;
    }

}

PriceParagraphUtils.php

namespace goodsmemo\option\amazon;

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

    const DEFAULT_PRICE_TIME_LINK_VISIBLE = true;
    const DEFAULT_PRICE_TIME_FOOTER_TEXT = "価格の詳細:価格および発送可能時期は表示された日付/時刻の時点のものであり、変更される場合があります。本商品の購入においては、購入の時点でAmazon.co.jpに表示されている価格および発送可能時期の情報が適用されます。";

}

ProductTypeParagraph.php

namespace goodsmemo\option\amazon;

use goodsmemo\option\paragraph\AbstractParagraph;
use goodsmemo\option\PageInfo;
use goodsmemo\option\SectionInfo;
use goodsmemo\option\field\CheckboxField;

require_once GOODS_MEMO_DIR . "option/paragraph/AbstractParagraph.php";
require_once GOODS_MEMO_DIR . "option/PageInfo.php";
require_once GOODS_MEMO_DIR . "option/SectionInfo.php";
require_once GOODS_MEMO_DIR . "option/field/CheckboxField.php";

/**
 * Description of ProductTypeParagraph
 *
 * @author Goods Memo
 */
class ProductTypeParagraph extends AbstractParagraph {

    const ADULT_PRODUCT_CHECKED_VALUE = "adultProductChecked";
    const ADULT_PRODUCT_LABEL_FOR_CHECKBOX = "表示する";

    public function initParagraph(PageInfo $pageInfo, SectionInfo $sectionInfo, $fieldInfoArray) {

	parent::setOptionGroup($pageInfo->getOptionGroup());
	parent::setSectionTitle($sectionInfo->getSectionTitle());
	parent::setFieldInfoArray($fieldInfoArray);

	$adultProductCheckboxField = new CheckboxField(
		$pageInfo->getOptionNameOfDatabase(), $fieldInfoArray[0], //
		ProductTypeParagraph::ADULT_PRODUCT_CHECKED_VALUE, //
		ProductTypeParagraph::ADULT_PRODUCT_LABEL_FOR_CHECKBOX
	);
	parent::addField($pageInfo, $sectionInfo, $adultProductCheckboxField);
    }

}

ProductTypeParagraphUtils.php

namespace goodsmemo\option\amazon;

use goodsmemo\option\field\FieldInfo;
use goodsmemo\option\amazon\AmazonSettingSection;

require_once GOODS_MEMO_DIR . "option/field/FieldInfo.php";
require_once GOODS_MEMO_DIR . "option/amazon/AmazonSettingSection.php";

/**
 * Description of ProductTypeFieldUtils
 *
 * @author Goods Memo
 */
class ProductTypeParagraphUtils {

    const ADULT_PRODUCT_ID = AmazonSettingSection::ID_PREFIX . "_adult_product_id";

    public static function makeFieldInfoArray() {

	$fieldInfoArray = array();

	$adultProductFieldInfo = new FieldInfo();
	$adultProductFieldInfo->setFieldID(ProductTypeParagraphUtils::ADULT_PRODUCT_ID);
	$adultProductFieldInfo->setFieldLabel('アダルト商品(例:MediumのItemAttributes->IsAdultProductで判断)');
	$adultProductFieldInfo->setDefaultFieldValue("");
	array_push($fieldInfoArray, $adultProductFieldInfo);

	return $fieldInfoArray;
    }

}

RESTParagraph.php


namespace goodsmemo\option\amazon;

use goodsmemo\option\paragraph\AbstractParagraph;
use goodsmemo\option\PageInfo;
use goodsmemo\option\SectionInfo;
use goodsmemo\option\field\SelectField;

require_once GOODS_MEMO_DIR . "option/paragraph/AbstractParagraph.php";
require_once GOODS_MEMO_DIR . "option/PageInfo.php";
require_once GOODS_MEMO_DIR . "option/SectionInfo.php";
require_once GOODS_MEMO_DIR . "option/field/SelectField.php";

/**
 * Description of RESTParagraph
 *
 * @author Goods Memo
 */
class RESTParagraph extends AbstractParagraph {

    const RESPONSE_GROUP_VALUE_TITLE_MAP = ['Large' => 'Large', 'Medium' => 'Medium', 'Small' => 'Small'];

    public function initParagraph(PageInfo $pageInfo, SectionInfo $sectionInfo, $fieldInfoArray) {

	parent::setOptionGroup($pageInfo->getOptionGroup());
	parent::setSectionTitle($sectionInfo->getSectionTitle());
	parent::setFieldInfoArray($fieldInfoArray);

	$responseGroupSelectField = new SelectField(
		$pageInfo->getOptionNameOfDatabase(), $fieldInfoArray[0], //
		RESTParagraph::RESPONSE_GROUP_VALUE_TITLE_MAP
	);
	parent::addField($pageInfo, $sectionInfo, $responseGroupSelectField);
    }

}

RESTParagraphUtils.php

namespace goodsmemo\option\amazon;

use goodsmemo\option\field\FieldInfo;
use goodsmemo\option\amazon\AmazonSettingSection;

require_once GOODS_MEMO_DIR . "option/field/FieldInfo.php";
require_once GOODS_MEMO_DIR . "option/amazon/AmazonSettingSection.php";

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

    const ITEM_SEARCH_OPERATION = "ItemSearch"; //TODO Choice部品
    const ALL_SEARCH_INDEX = "All"; //TODO Choice部品
    const OFFERFULL_RESPONSE_GROUP = "OfferFull "; //TODO Checkbox部品
    //
    const RESPONSE_GROUP_ID = AmazonSettingSection::ID_PREFIX . "_response_group_id";

    public static function makeFieldInfoArray() {

	$fieldInfoArray = array();

	$responseGroupFieldInfo = new FieldInfo();
	$responseGroupFieldInfo->setFieldID(RESTParagraphUtils::RESPONSE_GROUP_ID);
	$responseGroupFieldInfo->setFieldLabel('レスポンスグループ(開発用:初期値 Medium)');
	$responseGroupFieldInfo->setDefaultFieldValue("Medium");
	array_push($fieldInfoArray, $responseGroupFieldInfo);

	return $fieldInfoArray;
    }

}

ReviewParagraphUtils.php

namespace goodsmemo\option\amazon;

use goodsmemo\option\field\FieldInfo;
use goodsmemo\option\paragraph\ReviewParagraph;
use goodsmemo\option\amazon\AmazonSettingSection;

require_once GOODS_MEMO_DIR . "option/field/FieldInfo.php";
require_once GOODS_MEMO_DIR . "option/paragraph/ReviewParagraph.php";
require_once GOODS_MEMO_DIR . "option/amazon/AmazonSettingSection.php";

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

    const EDITORIAL_REVIEW_LENGTH_ID = AmazonSettingSection::ID_PREFIX . "_editorial_review_length_id";
    const ARRAY_OF_STRING_TO_DELETE_ID = AmazonSettingSection::ID_PREFIX . "_array_of_string_to_delete_id";
    const ARRAY_OF_STRING_TO_BREAK_ID = AmazonSettingSection::ID_PREFIX . "_array_of_string_to_break_id";

    public static function makeFieldInfoArray() {

	$fieldInfoArray = array();

	$editorialReviewLengthFieldInfo = new FieldInfo();
	$editorialReviewLengthFieldInfo->setFieldID(ReviewParagraphUtils::EDITORIAL_REVIEW_LENGTH_ID);
	$editorialReviewLengthFieldInfo->setFieldLabel(ReviewParagraph::DEFAULT_EDITORIAL_REVIEW_LENGTH_LABEL);
	$editorialReviewLengthFieldInfo->setDefaultFieldValue(ReviewParagraph::DEFAULT_EDITORIAL_REVIEW_LENGTH_VALUE);
	$editorialReviewLengthFieldInfo->setNumericalVerificationEnabled(true);
	array_push($fieldInfoArray, $editorialReviewLengthFieldInfo);

	$arrayOfStringToDeleteFieldInfo = new FieldInfo();
	$arrayOfStringToDeleteFieldInfo->setFieldID(ReviewParagraphUtils::ARRAY_OF_STRING_TO_DELETE_ID);
	$arrayOfStringToDeleteFieldInfo->setFieldLabel(ReviewParagraph::DEFAULT_ARRAY_OF_STRING_TO_DELETE_LABEL);
	$arrayOfStringToDeleteFieldInfo->setDefaultFieldValue(ReviewParagraph::DEFAULT_ARRAY_OF_STRING_TO_DELETE_VALUE); //削除する文字列の配列
	array_push($fieldInfoArray, $arrayOfStringToDeleteFieldInfo);

	$arrayOfStringToBreakFieldInfo = new FieldInfo();
	$arrayOfStringToBreakFieldInfo->setFieldID(ReviewParagraphUtils::ARRAY_OF_STRING_TO_BREAK_ID);
	$arrayOfStringToBreakFieldInfo->setFieldLabel(ReviewParagraph::DEFAULT_ARRAY_OF_STRING_TO_BREAK_LABEL);
	$arrayOfStringToBreakFieldInfo->setDefaultFieldValue(ReviewParagraph::DEFAULT_ARRAY_OF_STRING_TO_BREAK_VALUE); //改行する文字列の配列
	array_push($fieldInfoArray, $arrayOfStringToBreakFieldInfo);

	return $fieldInfoArray;
    }

}

URLParagraphUtils.php

namespace goodsmemo\option\amazon;

use goodsmemo\option\field\FieldInfo;
use goodsmemo\option\amazon\AmazonSettingSection;

require_once GOODS_MEMO_DIR . "option/field/FieldInfo.php";
require_once GOODS_MEMO_DIR . "option/amazon/AmazonSettingSection.php";

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

    const HOSTNAME_ID = AmazonSettingSection::ID_PREFIX . "_hostname_id";
    const PATH_ID = AmazonSettingSection::ID_PREFIX . "_path_id";

    public static function makeFieldInfoArray() {

	$fieldInfoArray = array();

	$hostnameFieldInfo = new FieldInfo();
	$hostnameFieldInfo->setFieldID(URLParagraphUtils::HOSTNAME_ID);
	$hostnameFieldInfo->setFieldLabel('Product Advertising API エンドポイント');
	$hostnameFieldInfo->setDefaultFieldValue("ecs.amazonaws.jp");
	array_push($fieldInfoArray, $hostnameFieldInfo);

	$pathFieldInfo = new FieldInfo();
	$pathFieldInfo->setFieldID(URLParagraphUtils::PATH_ID);
	$pathFieldInfo->setFieldLabel('Product Advertising API URI(パス部分)');
	$pathFieldInfo->setDefaultFieldValue("/onca/xml");
	array_push($fieldInfoArray, $pathFieldInfo);

	return $fieldInfoArray;
    }

}