Skip to content

Commit

Permalink
Merge pull request #59 from utahta/fix-pinterest
Browse files Browse the repository at this point in the history
Fix pinterest
  • Loading branch information
utahta authored Feb 5, 2018
2 parents 104226e + b419607 commit 3100781
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 50 deletions.
4 changes: 1 addition & 3 deletions src/WpSocialBookmarkingLight/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ public function save(array $data)
'type' => $data['pinterest_type'],
'shape' => $data['pinterest_shape'],
'size' => $data['pinterest_size'],
'color' => $data['pinterest_color'],
'lang' => $data['pinterest_lang'],
),
);
Expand Down Expand Up @@ -243,10 +242,9 @@ private function defaultOption()
),
'pocket' => array('button_type' => 'none'),
'pinterest' => array(
'type' => 'all',
'type' => 'any',
'shape' => 'rect',
'size' => 'small',
'color' => 'gray',
'lang' => 'en',
),
);
Expand Down
15 changes: 3 additions & 12 deletions src/WpSocialBookmarkingLight/Resources/views/Admin/page.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,9 @@
<th scope="row">Type: <br> <span style="font-size:10px"></span></th>
<td>
<select name='pinterest_type'>
<option value='all' {{ option.pinterest.type == 'all' ? 'selected' : '' }}>All</option>
<option value='hover' {{ option.pinterest.type == 'hover' ? 'selected' : '' }}>Hover</option>
<option value='all' {{ option.pinterest.type == 'all' ? 'selected' : '' }}>Any Image & Hover</option>
<option value='any' {{ option.pinterest.type == 'any' ? 'selected' : '' }}>Any Image</option>
<option value='hover' {{ option.pinterest.type == 'hover' ? 'selected' : '' }}>Image Hover</option>
</select>
</td>
</tr>
Expand All @@ -626,16 +627,6 @@
</select>
</td>
</tr>
<tr>
<th scope="row">Color: <br> <span style="font-size:10px"></span></th>
<td>
<select name='pinterest_color'>
<option value='red' {{ option.pinterest.color == 'red' ? 'selected' : '' }}>Red</option>
<option value='gray' {{ option.pinterest.color == 'gray' ? 'selected' : '' }}>Gray</option>
<option value='white' {{ option.pinterest.color == 'white' ? 'selected' : '' }}>White</option>
</select>
</td>
</tr>
<tr>
<th scope="row">Language:</th>
<td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@
{% endif %}

{% if pinterest %}
{% set data_pin_shape = pinterest.shape == 'round' ? 'data-pin-shape=true' : '' %}

{% if pinterest.size == 'large' %}
{% set data_pin_height = pinterest.shape == 'round' ? 'data-pin-height="32"' : 'data-pin-height="28"' %}
{% else %}
{% set data_pin_height = '' %}
{% endif %}
{% set data_pin_hover = pinterest.type == 'all' or pinterest.type == 'hover' ? 'data-pin-hover="true"' : '' %}
{% set data_pin_round = pinterest.shape == 'round' ? 'data-pin-round="true"' : '' %}
{% set data_pin_lang = pinterest.lang != '' ? 'data-pin-lang="'+pinterest.lang+'"' : '' %}
{% set data_pin_tall = pinterest.size == 'large' ? 'data-pin-tall="true"' : '' %}

<script type="text/javascript" async defer
data-pin-hover=true
{{ data_pin_shape }}
data-pin-color="{{ pinterest.color }}"
data-pin-lang="{{ pinterest.lang }}"
{{ data_pin_height | raw }}
{{ data_pin_hover }}
{{ data_pin_round }}
{{ data_pin_lang }}
{{ data_pin_tall }}
src="//assets.pinterest.com/js/pinit.js"></script>
{% endif %}
<!-- END: WP Social Bookmarking Light FOOTER -->
40 changes: 17 additions & 23 deletions src/WpSocialBookmarkingLight/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,46 +646,40 @@ public function pinterest()
if ($pinterest['type'] === 'hover') {
return '';
}
$data_pin_shape = '';
$data_pin_color = '';
$data_pin_round = '';
$data_pin_tall = '';
$data_pin_lang = '';
$img = '';

if ($pinterest['shape'] === 'round') {
// 円形ボタン
$data_pin_shape = 'data-pin-shape="round"';
$data_pin_round = 'data-pin-round="true"';

if ($pinterest['size'] === 'large') {
$data_pin_height = 'data-pin-height="32"';
$img_src = "//assets.pinterest.com/images/pidgets/pinit_fg_en_round_red_32.png";
$data_pin_tall = 'data-pin-tall="true"';
$img = "<img src='//assets.pinterest.com/images/pidgets/pinit_fg_en_round_red_32.png' />";
} else {
$data_pin_height = '';
$img_src = '//assets.pinterest.com/images/pidgets/pinit_fg_en_round_red_16.png';
$img = "<img src='//assets.pinterest.com/images/pidgets/pinit_fg_en_round_red_16.png' />";
}
} else {
// 長方形ボタン
$color = $pinterest['color'];
$lang = $pinterest['lang'];
$data_pin_color = 'data-pin-color="' . $color . '"';
$data_pin_lang = 'data-pin-lang="' . $lang . '"';
// rectangle button
if ($pinterest['lang'] !== '') {
$data_pin_lang = 'data-pin-lang="' . $pinterest['lang'] . '"';
}

if ($pinterest['size'] === 'large') {
$data_pin_height = 'data-pin-height="28"';
$img_src = "//assets.pinterest.com/images/pidgets/pinit_fg_${lang}_rect_${color}_28.png";
} else {
$data_pin_height = '';
$img_src = "//assets.pinterest.com/images/pidgets/pinit_fg_${lang}_round_${$color}_16.png";
$data_pin_tall = 'data-pin-tall="true"';
}
}

return $this->linkRaw(
'<a href="//jp.pinterest.com/pin/create/button/"'
'<a href="//www.pinterest.com/pin/create/button/"'
. ' data-pin-do="buttonBookmark"'
. ' ' . $data_pin_color
. ' ' . $data_pin_lang
. ' ' . $data_pin_shape
. ' ' . $data_pin_height
. ' ' . $data_pin_tall
. ' ' . $data_pin_round
. '>'
. '<img src="' . $img_src . '" /></a>'
. $img
. '</a>'
);
}
}

0 comments on commit 3100781

Please sign in to comment.