グッズメモ アフィリエイト・WordPressプラグイン

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

goodsmemo-affiliate.php

「Plugin Name」などの「プラグイン情報ヘッダー」を記述したPHPソースコードです。WordPressは、このソースコードをプラグインと認識します。


/*
  Plugin Name: Goods Memo Affiliate
  Plugin URI:
  Description: アフィリエイトの商品を表示します。
  Version: 0.0.8
  Author:Goods Memo
  Author URI: https://www.goods-memo.net/goods-memo-affiliate/
  License: GPL v2 or later
 */

/*
 * Copyright (C) 2018 Goods Memo.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 */


define("GOODS_MEMO_DIR", __DIR__ . "/");
define("GOODS_MEMO_PREFIX", "goodsmemo");

function goodsmemo_affiliate_uninstall() {
	// データベースからオプションを削除する
	delete_option("goodsmemo_option_name");
}

register_uninstall_hook(__FILE__, "goodsmemo_affiliate_uninstall");

function addGoodsMemoAffiliateStyles() {

	$styleSheetUniqueName = GOODS_MEMO_PREFIX . "-affiliateStyles";
	$pluginCssURL = plugins_url('gma-style.css', __FILE__);
	//var_dump($pluginCssURL);

	wp_register_style($styleSheetUniqueName, $pluginCssURL);
	wp_enqueue_style($styleSheetUniqueName);
}

if (is_admin()) {

	//ダッシュボードまたは管理画面を表示中
	require_once(GOODS_MEMO_DIR . "option/AffiliateSettingPage.php");
	$settingPage = new goodsmemo\option\AffiliateSettingPage();
} else {
	//テーマを使って表示中
	require_once(GOODS_MEMO_DIR . "shortcode/Shortcode.php");

	//テスト環境にて、ショートコードの属性の値が壊れていた場合があった。
	//例:keyword="ダイエット"が、$attsにて、keyword=「class="marker_pink">ダイエット」という値になった。
	//add_shortcode(GOODS_MEMO_PREFIX . "_affiliate", "\goodsmemo\shortcode\Shortcode::makeAffiliateHTML");
	//
    //以下の書き方にしてみる。参考:http://wpdocs.osdn.jp/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/add_shortcode
	add_shortcode(GOODS_MEMO_PREFIX . "_affiliate", array('goodsmemo\shortcode\Shortcode', 'makeAffiliateHTML'));

	//ヘッダにCSSを追加する
	add_action('wp_enqueue_scripts', 'addGoodsMemoAffiliateStyles');
}

/*
 * デバッグの例:
 * var_dump($val);
 * print_r($val);
 */

gma-style.css


.goodsmemo-amazon-items div,
.goodsmemo-amazon-items span,
.goodsmemo-amazon-items p,
.goodsmemo-amazon-items img,
.goodsmemo-amazon-items .footer,
.goodsmemo-rakuten-items div,
.goodsmemo-rakuten-items span,
.goodsmemo-rakuten-items p,
.goodsmemo-rakuten-items img,
.goodsmemo-rakuten-items .footer
{
    margin: 0;
    padding: 0;
    border: 0;
}

.goodsmemo-amazon-items.goodsmemo-items,
.goodsmemo-rakuten-items.goodsmemo-items
{
    border-bottom: 1px #ddd solid;
}

.goodsmemo-amazon-items .goodsmemo-oneItem,
.goodsmemo-rakuten-items .goodsmemo-oneItem
{
    clear: both;

    padding-top: 20px;
    padding-bottom: 20px;

    border-top: 1px #ddd solid;
}

.goodsmemo-amazon-items .goodsmemo-oneItem .imageArea,
.goodsmemo-rakuten-items .goodsmemo-oneItem .imageArea
{
    float: left;
    width: 160px;
    margin-right: 10px;
}

.goodsmemo-rakuten-items .goodsmemo-oneItem .imageArea img
{
    /* 幅が128よりも狭い画像があった。 */
    width : auto;/* imgタグのwidth値を解除 */
    height: auto;
}

.goodsmemo-amazon-items .goodsmemo-oneItem .areaNotToWrapAround,
.goodsmemo-amazon-items .goodsmemo-oneItem .review,
.goodsmemo-rakuten-items .goodsmemo-oneItem .areaNotToWrapAround,
.goodsmemo-rakuten-items .goodsmemo-oneItem .review
{
    overflow: hidden;/* 画像の下に回り込むことを防ぐ */
}

/* 商品詳細テーブル */
.goodsmemo-amazon-items .goodsmemo-oneItem .itemDetailsTable,
.goodsmemo-rakuten-items .goodsmemo-oneItem .itemDetailsTable
{
    display: table;
    border-collapse: separate;  /* セルの間隔を空ける */
    border-spacing: 5px 0;  /* 左右 上下で記述。上 下 右 左と指定できない */
}
.goodsmemo-amazon-items .goodsmemo-oneItem .itemDetailsTable .tableRow,
.goodsmemo-rakuten-items .goodsmemo-oneItem .itemDetailsTable .tableRow
{
    display: table-row;
}
.goodsmemo-amazon-items .goodsmemo-oneItem .itemDetailsTable .tableRow p,
.goodsmemo-rakuten-items .goodsmemo-oneItem .itemDetailsTable .tableRow p
{
    display: table-cell;
}
.goodsmemo-amazon-items .goodsmemo-oneItem .itemDetailsTable .tableRow p.rowLabel,
.goodsmemo-rakuten-items .goodsmemo-oneItem .itemDetailsTable .tableRow p.rowLabel
{
    text-align: right;/* インラインブロックのspanに対して、右寄せ指定。*/
    min-width: 4.6em;
    /*margin-right: 5px;*/ /* table-cell に margin は無効です。display: table; で余白を指定する。*/
}

/* 価格 */
.goodsmemo-amazon-items .goodsmemo-oneItem .priceValue,
.goodsmemo-rakuten-items .goodsmemo-oneItem .priceValue
{
    font-size: 115%;
    color: #b12704;
}
.goodsmemo-amazon-items .goodsmemo-oneItem .priceTime,
.goodsmemo-rakuten-items .goodsmemo-oneItem .priceTime
{
    margin-left: 10px;
}
.goodsmemo-amazon-items .goodsmemo-oneItem a.priceTimeLink,
.goodsmemo-rakuten-items .goodsmemo-oneItem a.priceTimeLink
{
    color: #333;
    margin-left: 10px;
}
.goodsmemo-amazon-items .goodsmemo-oneItem a:hover.priceTimeLink,
.goodsmemo-rakuten-items .goodsmemo-oneItem a:hover.priceTimeLink
{
    color: #e53900;
}

/* ポイント倍率 */
.goodsmemo-amazon-items .goodsmemo-oneItem .pointRate,
.goodsmemo-rakuten-items .goodsmemo-oneItem .pointRate
{
    font-size: 115%;
    color: #b12704;
    margin-left: 5px;
}

.goodsmemo-amazon-items .footer,
.goodsmemo-rakuten-items .footer
{
    clear: both;
    font-size: small;

    padding-top: 20px;
    padding-bottom: 20px;

    border-top: 1px #ddd solid;
}

.goodsmemo-amazon-search-widget
{
    padding-top: 20px;
    padding-bottom: 20px;

    min-width:336px;
    min-height: 320px;/* 20px + 280px + 20px */

    border-top: 1px #ddd solid;
    border-bottom: 1px #ddd solid;
}

p.gma-error-message
{
    max-height: 4em;/* 大体2行ほどの高さ */
    overflow: auto;
}

/*480px以下*/
@media screen and (max-width: 480px) {

    .goodsmemo-amazon-items .goodsmemo-oneItem .imageArea,
    .goodsmemo-rakuten-items .goodsmemo-oneItem .imageArea
    {
	width: 25%;
    }

}