Version Description
Download this release
Release Info
Developer | poporon |
Plugin | Pz-LinkCard |
Version | 2.0.0.3 |
Comparing to | |
See all releases |
Code changes from version 2.0.0.2 to 2.0.0.3
- js/mce-pz-lkc.js +1 -1
- lib/pz-linkcard-cacheman-edit.php +1 -40
- lib/pz-linkcard-cacheman-list.php +8 -25
- lib/pz-linkcard-init.php +2 -45
- pz-linkcard.php +208 -224
- readme.txt +0 -8
js/mce-pz-lkc.js
CHANGED
@@ -9,7 +9,7 @@
|
|
9 |
ed.addCommand('insert_pz_linkcard', function() {
|
10 |
var insert_tag = window.prompt('Input URL', 'http://');
|
11 |
if (insert_tag !== null) {
|
12 |
-
ed.execCommand('mceInsertContent', 0, '[
|
13 |
}
|
14 |
});
|
15 |
},
|
9 |
ed.addCommand('insert_pz_linkcard', function() {
|
10 |
var insert_tag = window.prompt('Input URL', 'http://');
|
11 |
if (insert_tag !== null) {
|
12 |
+
ed.execCommand('mceInsertContent', 0, '[link url="' + insert_tag + '"]');
|
13 |
}
|
14 |
});
|
15 |
},
|
lib/pz-linkcard-cacheman-edit.php
CHANGED
@@ -54,48 +54,9 @@
|
|
54 |
<th><?php _e('Result code', $this->text_domain) ?></th>
|
55 |
<td><input name="data[result_code]" type="text" id="inputtext" value="<?php echo $data['result_code']; ?>" size="5" readonly="readonly" ondblclick="this.readOnly=false;" /></td>
|
56 |
</tr>
|
57 |
-
<?php
|
58 |
-
// 記事IDの再取得(時間がかかるので未実行)
|
59 |
-
$use_post_id_t = array();
|
60 |
-
if ($data['use_post_id1'] > 0) {
|
61 |
-
$use_post_id_t[] = $data['use_post_id1'];
|
62 |
-
}
|
63 |
-
if ($data['use_post_id2'] > 0) {
|
64 |
-
$use_post_id_t[] = $data['use_post_id2'];
|
65 |
-
}
|
66 |
-
if ($data['use_post_id3'] > 0) {
|
67 |
-
$use_post_id_t[] = $data['use_post_id3'];
|
68 |
-
}
|
69 |
-
if ($data['use_post_id4'] > 0) {
|
70 |
-
$use_post_id_t[] = $data['use_post_id4'];
|
71 |
-
}
|
72 |
-
if ($data['use_post_id5'] > 0) {
|
73 |
-
$use_post_id_t[] = $data['use_post_id5'];
|
74 |
-
}
|
75 |
-
if ($data['use_post_id6'] > 0) {
|
76 |
-
$use_post_id_t[] = $data['use_post_id6'];
|
77 |
-
}
|
78 |
-
$use_post_id_m = $wpdb->get_results($wpdb->prepare("SELECT id FROM $wpdb->prefix"."posts WHERE post_type = 'post' AND post_content LIKE '%%\"%s\"%%' ORDER BY id ASC", '"'.$data['url'].'"' ));
|
79 |
-
foreach($use_post_id_m as $use_post_id) {
|
80 |
-
$use_post_id_t[] = $use_post_id->id;
|
81 |
-
}
|
82 |
-
$use_post_id_t = array_unique($use_post_id_t);
|
83 |
-
$use_post_id_t = array_values($use_post_id_t);
|
84 |
-
$data['use_post_id1'] = $use_post_id_t[0];
|
85 |
-
$data['use_post_id2'] = $use_post_id_t[1];
|
86 |
-
$data['use_post_id3'] = $use_post_id_t[2];
|
87 |
-
$data['use_post_id4'] = $use_post_id_t[3];
|
88 |
-
$data['use_post_id5'] = $use_post_id_t[4];
|
89 |
-
$data['use_post_id6'] = $use_post_id_t[5];
|
90 |
-
?>
|
91 |
<tr>
|
92 |
<th><?php _e('Post ID', $this->text_domain) ?></th>
|
93 |
-
<td><input name="data[
|
94 |
-
<input name="data[use_post_id2]" type="text" id="inputtext" value="<?php echo $data['use_post_id2']; ?>" size="5" readonly="readonly" ondblclick="this.readOnly=false;" />
|
95 |
-
<input name="data[use_post_id3]" type="text" id="inputtext" value="<?php echo $data['use_post_id3']; ?>" size="5" readonly="readonly" ondblclick="this.readOnly=false;" />
|
96 |
-
<input name="data[use_post_id4]" type="text" id="inputtext" value="<?php echo $data['use_post_id4']; ?>" size="5" readonly="readonly" ondblclick="this.readOnly=false;" />
|
97 |
-
<input name="data[use_post_id5]" type="text" id="inputtext" value="<?php echo $data['use_post_id5']; ?>" size="5" readonly="readonly" ondblclick="this.readOnly=false;" />
|
98 |
-
<input name="data[use_post_id6]" type="text" id="inputtext" value="<?php echo $data['use_post_id6']; ?>" size="5" readonly="readonly" ondblclick="this.readOnly=false;" /></td>
|
99 |
</tr>
|
100 |
<tr>
|
101 |
<th><?php _e('SNS', $this->text_domain) ?></th>
|
54 |
<th><?php _e('Result code', $this->text_domain) ?></th>
|
55 |
<td><input name="data[result_code]" type="text" id="inputtext" value="<?php echo $data['result_code']; ?>" size="5" readonly="readonly" ondblclick="this.readOnly=false;" /></td>
|
56 |
</tr>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
<tr>
|
58 |
<th><?php _e('Post ID', $this->text_domain) ?></th>
|
59 |
+
<td><input name="data[post_id]" type="text" id="inputtext" value="<?php echo $data['post_id']; ?>" size="5" readonly="readonly" /></td>
|
|
|
|
|
|
|
|
|
|
|
60 |
</tr>
|
61 |
<tr>
|
62 |
<th><?php _e('SNS', $this->text_domain) ?></th>
|
lib/pz-linkcard-cacheman-list.php
CHANGED
@@ -14,12 +14,7 @@ case 'title':
|
|
14 |
case 'excerpt':
|
15 |
case 'result_code':
|
16 |
case 'alive_result':
|
17 |
-
case '
|
18 |
-
case 'use_post_id2':
|
19 |
-
case 'use_post_id3':
|
20 |
-
case 'use_post_id4':
|
21 |
-
case 'use_post_id5':
|
22 |
-
case 'use_post_id6':
|
23 |
case 'sns_twitter':
|
24 |
case 'sns_facebook':
|
25 |
case 'sns_hatena':
|
@@ -204,7 +199,7 @@ echo '</div>';
|
|
204 |
<th scope="col" class="domain" style="min-width: 6em;"> <?php echo_THC('domain', __('Domain', $this->text_domain) ); ?></th>
|
205 |
<th scope="col" class="sns" style="width: 2.5em;"> <?php echo_THC('sns_twitter', __('Tw', $this->text_domain)); echo '<br>'; echo_THC('sns_facebook', __('fb', $this->text_domain)); echo '<br>'; echo_THC('sns_hatena', __('B!', $this->text_domain)); ?></th>
|
206 |
<th scope="col" class="regist" style="width: 5em;"> <?php echo_THC('regist', __('Regist', $this->text_domain) ); ?></th>
|
207 |
-
<th scope="col" class="postid" style="width: 3em;"> <?php echo_THC('
|
208 |
<th scope="col" class="result" style="width: 2.5em;"> <?php echo_THC('result_code', __('Result code', $this->text_domain) ); ?><br><?php echo_THC('alive_result', __('(last)', $this->text_domain) ); ?></th>
|
209 |
</tr>
|
210 |
</thead>
|
@@ -248,13 +243,11 @@ foreach ($data_all as $data) {
|
|
248 |
$domain = $data->domain;
|
249 |
// 日本語ドメイン対応
|
250 |
if (isset($this->options['flg-idn']) ? true : false) {
|
251 |
-
if (
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
$disp_url = $url_m['scheme'].'://'.$url_m['host'].$url_m['path'].$url_m['query'].$url_m['fragment'];
|
257 |
-
}
|
258 |
}
|
259 |
}
|
260 |
$title = htmlspecialchars($data->title);
|
@@ -300,17 +293,7 @@ foreach ($data_all as $data) {
|
|
300 |
echo '</td>';
|
301 |
|
302 |
echo ' <td>'.$data->regist.'</td>';
|
303 |
-
echo ' <td style="word-break: break-all;">';
|
304 |
-
if ($data->use_post_id1 > 0 ) {
|
305 |
-
echo '<a href="'.get_permalink($data->use_post_id1).'" target="_blank" title="'.get_the_title($data->use_post_id1).'">'.$data->use_post_id1;
|
306 |
-
}
|
307 |
-
if ($data->use_post_id2 > 0 ) {
|
308 |
-
echo '<br><a href="'.get_permalink($data->use_post_id2).'" target="_blank" title="'.get_the_title($data->use_post_id2).'">'.$data->use_post_id2;
|
309 |
-
}
|
310 |
-
if ($data->use_post_id3 > 0 ) {
|
311 |
-
echo '<br><a href="'.get_permalink($data->use_post_id3).'" target="_blank" title="'.get_the_title($data->use_post_id3).'">'.$data->use_post_id3;
|
312 |
-
}
|
313 |
-
echo '</td>';
|
314 |
echo ' <td>'.$data->result_code.($data->result_code <> $data->alive_result ? '<br><span style="color:#f00;">('.$data->alive_result.')</span>' : '').'</td>';
|
315 |
echo '</tr>';
|
316 |
}
|
14 |
case 'excerpt':
|
15 |
case 'result_code':
|
16 |
case 'alive_result':
|
17 |
+
case 'post_id':
|
|
|
|
|
|
|
|
|
|
|
18 |
case 'sns_twitter':
|
19 |
case 'sns_facebook':
|
20 |
case 'sns_hatena':
|
199 |
<th scope="col" class="domain" style="min-width: 6em;"> <?php echo_THC('domain', __('Domain', $this->text_domain) ); ?></th>
|
200 |
<th scope="col" class="sns" style="width: 2.5em;"> <?php echo_THC('sns_twitter', __('Tw', $this->text_domain)); echo '<br>'; echo_THC('sns_facebook', __('fb', $this->text_domain)); echo '<br>'; echo_THC('sns_hatena', __('B!', $this->text_domain)); ?></th>
|
201 |
<th scope="col" class="regist" style="width: 5em;"> <?php echo_THC('regist', __('Regist', $this->text_domain) ); ?></th>
|
202 |
+
<th scope="col" class="postid" style="width: 3em;"> <?php echo_THC('post_id', __('Post ID', $this->text_domain) ); ?></th>
|
203 |
<th scope="col" class="result" style="width: 2.5em;"> <?php echo_THC('result_code', __('Result code', $this->text_domain) ); ?><br><?php echo_THC('alive_result', __('(last)', $this->text_domain) ); ?></th>
|
204 |
</tr>
|
205 |
</thead>
|
243 |
$domain = $data->domain;
|
244 |
// 日本語ドメイン対応
|
245 |
if (isset($this->options['flg-idn']) ? true : false) {
|
246 |
+
if ( substr( $domain, 0, 4 ) == 'xn--') {
|
247 |
+
$domain = idn_to_utf8( $domain );
|
248 |
+
$url_m = parse_url( $url );
|
249 |
+
$url_m['host'] = idn_to_utf8( $url_m[host] );
|
250 |
+
$disp_url = $url_m['scheme'].'://'.$url_m['host'].$url_m['path'].$url_m['query'].$url_m['fragment'];
|
|
|
|
|
251 |
}
|
252 |
}
|
253 |
$title = htmlspecialchars($data->title);
|
293 |
echo '</td>';
|
294 |
|
295 |
echo ' <td>'.$data->regist.'</td>';
|
296 |
+
echo ' <td style="word-break: break-all;"><a href="'.get_permalink($data->post_id).'" target="_blank" title="'.get_the_title($data->post_id).'">'.$data->post_id.'</td>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
297 |
echo ' <td>'.$data->result_code.($data->result_code <> $data->alive_result ? '<br><span style="color:#f00;">('.$data->alive_result.')</span>' : '').'</td>';
|
298 |
echo '</tr>';
|
299 |
}
|
lib/pz-linkcard-init.php
CHANGED
@@ -22,10 +22,9 @@
|
|
22 |
url VARCHAR(2048) DEFAULT '',
|
23 |
url_key VARBINARY(255) NOT NULL,
|
24 |
scheme VARCHAR(16) DEFAULT '',
|
25 |
-
domain VARCHAR(253) DEFAULT '',
|
26 |
-
location VARCHAR(2048) DEFAULT '',
|
27 |
address VARCHAR(2048) DEFAULT '',
|
28 |
site_name VARCHAR(100) DEFAULT '',
|
|
|
29 |
title VARCHAR(200) DEFAULT '',
|
30 |
excerpt VARCHAR(500) DEFAULT '',
|
31 |
thumbnail VARCHAR(2048) DEFAULT '',
|
@@ -37,13 +36,7 @@
|
|
37 |
sns_twitter INT DEFAULT -1,
|
38 |
sns_facebook INT DEFAULT -1,
|
39 |
sns_hatena INT DEFAULT -1,
|
40 |
-
post_id INT UNSIGNED
|
41 |
-
use_post_id1 INT UNSIGNED,
|
42 |
-
use_post_id2 INT UNSIGNED,
|
43 |
-
use_post_id3 INT UNSIGNED,
|
44 |
-
use_post_id4 INT UNSIGNED,
|
45 |
-
use_post_id5 INT UNSIGNED,
|
46 |
-
use_post_id6 INT UNSIGNED,
|
47 |
regist_title VARCHAR(200) DEFAULT '',
|
48 |
regist_excerpt VARCHAR(500) DEFAULT '',
|
49 |
regist_charset VARCHAR(32) DEFAULT '',
|
@@ -90,42 +83,6 @@
|
|
90 |
}
|
91 |
}
|
92 |
|
93 |
-
// 記事IDの再取得
|
94 |
-
$result = $wpdb->get_results("UPDATE $this->db_name SET use_post_id1 = post_id , post_id = 0 WHERE (use_post_id1 IS NULL OR result_code = 0) AND post_id > 0");
|
95 |
-
|
96 |
-
// // 記事IDの再取得(時間がかかるので未実行)
|
97 |
-
// $result = (array) $wpdb->get_results("SELECT id,url,use_post_id1,use_post_id2,use_post_id3,use_post_id4,use_post_id5,use_post_id6 FROM $this->db_name ORDER BY id");
|
98 |
-
// if (isset($result) && is_array($result) && count($result) > 0) {
|
99 |
-
// foreach($result as $data) {
|
100 |
-
// $use_post_id_t = array();
|
101 |
-
// if ($data->use_post_id1 > 0) {
|
102 |
-
// $use_post_id_t[] = $data->use_post_id1;
|
103 |
-
// }
|
104 |
-
// if ($data->use_post_id2 > 0) {
|
105 |
-
// $use_post_id_t[] = $data->use_post_id2;
|
106 |
-
// }
|
107 |
-
// if ($data->use_post_id3 > 0) {
|
108 |
-
// $use_post_id_t[] = $data->use_post_id3;
|
109 |
-
// }
|
110 |
-
// if ($data->use_post_id4 > 0) {
|
111 |
-
// $use_post_id_t[] = $data->use_post_id4;
|
112 |
-
// }
|
113 |
-
// if ($data->use_post_id5 > 0) {
|
114 |
-
// $use_post_id_t[] = $data->use_post_id5;
|
115 |
-
// }
|
116 |
-
// if ($data->use_post_id6 > 0) {
|
117 |
-
// $use_post_id_t[] = $data->use_post_id6;
|
118 |
-
// }
|
119 |
-
// $use_post_id_m = $wpdb->get_results($wpdb->prepare("SELECT id FROM $wpdb->prefix"."posts WHERE post_type = 'post' AND post_content LIKE '%%\"%s\"%%' ORDER BY id ASC", '"'.$data->url.'"' ));
|
120 |
-
// foreach($use_post_id_m as $use_post_id) {
|
121 |
-
// $use_post_id_t[] = $use_post_id->id;
|
122 |
-
// }
|
123 |
-
// $use_post_id_t = array_unique($use_post_id_t);
|
124 |
-
// $use_post_id_t = array_values($use_post_id_t);
|
125 |
-
// $wpdb->update($this->db_name, array('use_post_id1' => $use_post_id_m[0]->id, 'use_post_id2' => $use_post_id_m[1]->id, 'use_post_id3' => $use_post_id_m[2]->id, 'use_post_id4' => $use_post_id_m[3]->id, 'use_post_id5' => $use_post_id_m[4]->id, 'use_post_id6' => $use_post_id_m[5]->id ) , array('id' => $data->id ) );
|
126 |
-
// }
|
127 |
-
// }
|
128 |
-
|
129 |
// 過去バージョンからのコンバート(生存確認用のデータ作成)
|
130 |
$result = $wpdb->get_results("UPDATE $this->db_name SET result_code = 200 WHERE result_code IS NULL OR result_code = 0");
|
131 |
$result = $wpdb->get_results("UPDATE $this->db_name SET alive_result = result_code , alive_time = uptime WHERE alive_result IS NULL OR alive_result = 0 OR alive_time = 0");
|
22 |
url VARCHAR(2048) DEFAULT '',
|
23 |
url_key VARBINARY(255) NOT NULL,
|
24 |
scheme VARCHAR(16) DEFAULT '',
|
|
|
|
|
25 |
address VARCHAR(2048) DEFAULT '',
|
26 |
site_name VARCHAR(100) DEFAULT '',
|
27 |
+
domain VARCHAR(253) DEFAULT '',
|
28 |
title VARCHAR(200) DEFAULT '',
|
29 |
excerpt VARCHAR(500) DEFAULT '',
|
30 |
thumbnail VARCHAR(2048) DEFAULT '',
|
36 |
sns_twitter INT DEFAULT -1,
|
37 |
sns_facebook INT DEFAULT -1,
|
38 |
sns_hatena INT DEFAULT -1,
|
39 |
+
post_id INT UNSIGNED,
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
regist_title VARCHAR(200) DEFAULT '',
|
41 |
regist_excerpt VARCHAR(500) DEFAULT '',
|
42 |
regist_charset VARCHAR(32) DEFAULT '',
|
83 |
}
|
84 |
}
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
// 過去バージョンからのコンバート(生存確認用のデータ作成)
|
87 |
$result = $wpdb->get_results("UPDATE $this->db_name SET result_code = 200 WHERE result_code IS NULL OR result_code = 0");
|
88 |
$result = $wpdb->get_results("UPDATE $this->db_name SET alive_result = result_code , alive_time = uptime WHERE alive_result IS NULL OR alive_result = 0 OR alive_time = 0");
|
pz-linkcard.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Pz-LinkCard
|
4 |
Plugin URI: http://poporon.poponet.jp/pz-linkcard
|
5 |
Description: リンクをカード形式で表示します。
|
6 |
-
Version: 2.0.0.
|
7 |
Author: poporon
|
8 |
Author URI: http://poporon.poponet.jp
|
9 |
License: GPLv2 or later
|
@@ -114,7 +114,7 @@ class Pz_LinkCard {
|
|
114 |
'flg-alive' => '1',
|
115 |
'flg-ssl' => '1',
|
116 |
'flg-amp' => '1',
|
117 |
-
'flg-idn' => '',
|
118 |
'style-reset-img' => '1',
|
119 |
'style' => null,
|
120 |
'css-file' => null,
|
@@ -134,7 +134,7 @@ class Pz_LinkCard {
|
|
134 |
'thumbnail-url' => null,
|
135 |
'plugin-link' => null,
|
136 |
'plugin-name' => 'Pz-LinkCard',
|
137 |
-
'plugin-version' => '2.0.0.
|
138 |
'plugin-url' => 'http://poporon.poponet.jp/pz-linkcard',
|
139 |
'pz-hbc-options' => null,
|
140 |
'debug-time' => null
|
@@ -179,16 +179,16 @@ class Pz_LinkCard {
|
|
179 |
add_filter ('the_content', array($this, 'auto_replace') ); // 自動置き換え
|
180 |
add_shortcode ('pz-linkcard-auto-replace', array($this, 'shortcode') ); // 自動置き換え専用ショートコード
|
181 |
}
|
182 |
-
if ($this->options['code1']) {
|
183 |
add_shortcode($this->options['code1'], array($this, 'shortcode'));
|
184 |
}
|
185 |
-
if ($this->options['code2']) {
|
186 |
add_shortcode($this->options['code2'], array($this, 'shortcode'));
|
187 |
}
|
188 |
-
if ($this->options['code3']) {
|
189 |
add_shortcode($this->options['code3'], array($this, 'shortcode'));
|
190 |
}
|
191 |
-
if ($this->options['code4']) {
|
192 |
add_shortcode($this->options['code4'], array($this, 'shortcode'));
|
193 |
}
|
194 |
|
@@ -225,13 +225,15 @@ class Pz_LinkCard {
|
|
225 |
|
226 |
if (!wp_next_scheduled('pz_linkcard_check')) {
|
227 |
wp_schedule_event ( time() + 10 , 'hourly', 'pz_linkcard_check');
|
|
|
228 |
}
|
229 |
if (!wp_next_scheduled('pz_linkcard_alive')) {
|
230 |
wp_schedule_event ( time() + 1800 , 'daily', 'pz_linkcard_alive');
|
|
|
231 |
}
|
232 |
}
|
233 |
|
234 |
-
//
|
235 |
public function auto_replace($contents) {
|
236 |
if (isset($this->options['auto-atag']) && $this->options['auto-atag']) {
|
237 |
$contents = preg_replace( '/(^|<br ?\/?>)(<p.*>)?<a .*href=[\'"](https?:\/\/[-_\.!~*()a-zA-Z0-9;\/?:\@&=+\$,%#]+)[\'"]((?!<IMG).)*<\/a>(<\/p>)?$/im', '[pz-linkcard-auto-replace url="$3"]', $contents);
|
@@ -245,7 +247,7 @@ class Pz_LinkCard {
|
|
245 |
// ショートコード処理
|
246 |
public function shortcode($atts, $content = null, $shortcode) {
|
247 |
// 実行時間
|
248 |
-
if ($this->options['debug-time']) {
|
249 |
$start_time = microtime(true);
|
250 |
}
|
251 |
|
@@ -293,7 +295,7 @@ class Pz_LinkCard {
|
|
293 |
$data = $this->pz_GetHTML ( $atts );
|
294 |
|
295 |
// 実行時間
|
296 |
-
if ($this->options['debug-time']) {
|
297 |
$end_time = microtime(true);
|
298 |
$elasped_time = number_format($end_time - $start_time, 8, '.', ',');
|
299 |
$data = PHP_EOL.'<!-- Pz-LkC -->'.PHP_EOL.$data.PHP_EOL.'<!-- /Pz-LkC ('.$elasped_time.'sec) -->'.PHP_EOL;
|
@@ -304,8 +306,16 @@ class Pz_LinkCard {
|
|
304 |
|
305 |
// キャッシュやリンク先からリンクカードのHTMLを生成
|
306 |
function pz_GetHTML($atts, $content = null) {
|
307 |
-
if ($this->options['debug-time']) {
|
308 |
-
echo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
309 |
}
|
310 |
|
311 |
// モバイルチェック
|
@@ -314,28 +324,22 @@ class Pz_LinkCard {
|
|
314 |
} else {
|
315 |
$is_mobile = false;
|
316 |
}
|
317 |
-
if ($this->options['debug-time']) {
|
318 |
-
echo
|
319 |
}
|
320 |
|
321 |
-
// URL
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
}
|
326 |
-
|
327 |
-
|
|
|
328 |
}
|
329 |
|
330 |
-
// URLパース(ドメイン名などを抽出)
|
331 |
-
$url_m = parse_url( $url );
|
332 |
-
$scheme = $url_m['scheme']; // スキーム
|
333 |
-
$domain = $url_m['host']; // ドメイン名
|
334 |
-
$domain_url = $scheme.'://'.$url_m['host']; // ドメインURL
|
335 |
-
$location = substr($url, mb_strlen($domain_url)); // ドメイン名以降
|
336 |
-
|
337 |
// 自サイトチェック
|
338 |
-
if (
|
339 |
if ($this->pz_TrimURL(get_permalink()) == $url) {
|
340 |
$link_type = 1; // 自ページ
|
341 |
} else {
|
@@ -344,15 +348,15 @@ class Pz_LinkCard {
|
|
344 |
} else {
|
345 |
$link_type = 0; // 外部サイト
|
346 |
}
|
347 |
-
if ($this->options['debug-time']) {
|
348 |
-
echo
|
349 |
}
|
350 |
|
351 |
// モバイルかPCかのクラス名を追加
|
352 |
$class_id = 'linkcard';
|
353 |
-
if ($is_mobile && $this->options['class-mobile']) {
|
354 |
$class_id .= ' '.$this->options['class-mobile'];
|
355 |
-
} elseif ($this->options['class-pc']) {
|
356 |
$class_id .= ' '.$this->options['class-pc'];
|
357 |
}
|
358 |
|
@@ -366,58 +370,57 @@ class Pz_LinkCard {
|
|
366 |
$data_id = $data['id'];
|
367 |
$url = $data['url'];
|
368 |
}
|
369 |
-
if ($this->options['debug-time']) {
|
370 |
-
echo
|
371 |
}
|
372 |
|
373 |
// 内部リンクの処理
|
374 |
if ( $link_type ) {
|
375 |
-
//
|
376 |
-
$target = ''; // 同ページに開く
|
377 |
if (isset($this->options['in-target'])) {
|
378 |
if ($this->options['in-target'] == '1' || ($this->options['in-target'] == '2' && !$is_mobile)) {
|
379 |
-
$target =
|
380 |
}
|
381 |
}
|
382 |
-
$nofollow = '';
|
383 |
|
384 |
// キャッシュが無い、もしくは常に最新を取得する、もしくは強制取得
|
385 |
if ( is_null($data_id) || ( isset($atts['force']) && $atts['force'] == true ) ) {
|
386 |
-
if ($this->options['debug-time']) {
|
387 |
-
echo
|
388 |
}
|
389 |
-
$data
|
390 |
-
$data['link_type'] =
|
391 |
-
if ($this->options['debug-time']) {
|
392 |
-
echo
|
393 |
}
|
394 |
-
$result
|
395 |
} elseif ($this->options['in-get'] <> 2) {
|
396 |
-
if ($this->options['debug-time']) {
|
397 |
-
echo
|
398 |
}
|
399 |
-
$data
|
400 |
-
$data['link_type'] =
|
401 |
}
|
402 |
}
|
403 |
|
404 |
// 外部リンクの処理
|
405 |
if ( !$link_type ) {
|
406 |
// リンクターゲットの設定
|
407 |
-
$target =
|
408 |
if (isset($this->options['ex-target'])) {
|
409 |
if ($this->options['ex-target'] == '1' || ($this->options['ex-target'] == '2' && !$is_mobile)) {
|
410 |
$target = ' target="_blank"'; // 新しいページで開く
|
411 |
}
|
412 |
}
|
413 |
-
$nofollow = isset($this->options['nofollow']) ? ' rel="nofollow"' : '';
|
414 |
|
415 |
// キャッシュが無い、もしくは強制取得
|
416 |
if ( is_null($data_id) || ( isset($atts['force']) && $atts['force'] == true ) ) {
|
417 |
-
if ($this->options['debug-time']) {
|
418 |
-
echo
|
419 |
}
|
420 |
-
$result = $this->pz_GetCURL( $data );
|
421 |
if ( isset($result) && is_array($result) && isset($result['url']) ) {
|
422 |
$data = $result;
|
423 |
$data['link_type'] = 0;
|
@@ -426,7 +429,6 @@ class Pz_LinkCard {
|
|
426 |
}
|
427 |
}
|
428 |
|
429 |
-
// 念のため初期化
|
430 |
$data_id = (isset($data['id']) ? $data['id'] : null);
|
431 |
$site_name = (isset($data['site_name']) ? $data['site_name'] : null);
|
432 |
$title = (isset($data['title']) ? $data['title'] : null);
|
@@ -476,24 +478,24 @@ class Pz_LinkCard {
|
|
476 |
} else {
|
477 |
$tag = '<div class="'.$class_id.'">'.$tag.'</div>';
|
478 |
}
|
479 |
-
return $tag;
|
480 |
}
|
481 |
|
482 |
// サムネイル取得
|
483 |
if ( !$this->options['thumbnail-position'] || ( $result_code <> 0 && $result_code <> 200 ) ) {
|
484 |
$thumbnail = null;
|
485 |
} else {
|
486 |
-
if ($sw_thumbnail == '1' || $sw_thumbnail == '13') {
|
487 |
if ( !$link_type ) {
|
488 |
-
$thumbnail_url = $this->pz_GetThumbnail($thumbnail_url);
|
489 |
}
|
490 |
if ( isset($thumbnail_url) && $thumbnail_url <> '' ) {
|
491 |
$thumbnail = '<img class="lkc-thumbnail-img" src="'.$thumbnail_url.'" alt="" />';
|
492 |
-
} elseif ($sw_thumbnail == '13') {
|
493 |
$sw_thumbnail = '3';
|
494 |
}
|
495 |
}
|
496 |
-
if ($sw_thumbnail == '3') {
|
497 |
// 画像取得(WebAPI)
|
498 |
if (isset($this->options['thumbnail-api'])) {
|
499 |
$thumbnail = preg_replace('/%DOMAIN_URL%/', $domain_url, $this->options['thumbnail-api'] );
|
@@ -508,14 +510,14 @@ class Pz_LinkCard {
|
|
508 |
if (!isset($this->options['info-position'])) {
|
509 |
$favicon = null;
|
510 |
} else{
|
511 |
-
if ($sw_favicon == '1' || $sw_favicon == '13') {
|
512 |
if ( !is_null($favicon_url ) ) {
|
513 |
$favicon = '<img class="lkc-favicon" src="'.$favicon_url.'" alt="" width=16 height=16 />';
|
514 |
-
} elseif ($sw_favicon == '13') {
|
515 |
$sw_favicon == '3';
|
516 |
}
|
517 |
}
|
518 |
-
if ($sw_favicon == '3') {
|
519 |
// サイトアイコン取得(WebAPI)
|
520 |
if (isset($this->options['favicon-api'])) {
|
521 |
$favicon = preg_replace('/%DOMAIN_URL%/', $domain_url, $this->options['favicon-api'] );
|
@@ -526,6 +528,8 @@ class Pz_LinkCard {
|
|
526 |
}
|
527 |
}
|
528 |
|
|
|
|
|
529 |
// タイトル
|
530 |
if (!isset($title) || $title == '') {
|
531 |
$title = esc_html($url); // タイトル取得できていなかったらURLをセットする
|
@@ -556,7 +560,8 @@ class Pz_LinkCard {
|
|
556 |
$title = $str;
|
557 |
}
|
558 |
|
559 |
-
//
|
|
|
560 |
if (!isset($this->options['display-excerpt']) || is_null($this->options['display-excerpt'])) {
|
561 |
$excerpt = '';
|
562 |
} else {
|
@@ -585,8 +590,8 @@ class Pz_LinkCard {
|
|
585 |
// 日本語ドメイン対応
|
586 |
if (isset($this->options['flg-idn']) ? true : false) {
|
587 |
if (function_exists('idn_to_utf8')) {
|
588 |
-
if (substr( $
|
589 |
-
$site_name = idn_to_utf8( $
|
590 |
}
|
591 |
}
|
592 |
}
|
@@ -595,7 +600,6 @@ class Pz_LinkCard {
|
|
595 |
// リンク先URL
|
596 |
$not_allow_code = array('403','404','410');
|
597 |
if (array_search($alive_result, $not_allow_code)) {
|
598 |
-
// Not found の時は見え消ししてリンクしない
|
599 |
$a_op_all = '<span style="cursor: not-allowed;" title="">';
|
600 |
$a_cl_all = '</span>';
|
601 |
$a_op = '';
|
@@ -603,7 +607,6 @@ class Pz_LinkCard {
|
|
603 |
$st_op = '<strike>';
|
604 |
$st_cl = '</strike>';
|
605 |
} elseif ((isset($this->options['link-all']) ? $this->options['link-all'] : null) == '1') {
|
606 |
-
// カード全体をリンク(どこをクリックしても良いのが分かり易い)
|
607 |
$a_op_all = '<a class="no_icon" href="'.$url.'"'.$target.$nofollow.'>';
|
608 |
$a_cl_all = '</a>';
|
609 |
$a_op = '';
|
@@ -611,7 +614,6 @@ class Pz_LinkCard {
|
|
611 |
$st_op = '';
|
612 |
$st_cl = '';
|
613 |
} else {
|
614 |
-
// タイトルとかURLとかを個別でリンク(タイトルや抜粋文などの文字を範囲指定をしてコピー等がし易い)
|
615 |
$a_op_all = '';
|
616 |
$a_cl_all = '';
|
617 |
$a_op = '<a class="no_icon" href="'.$url.'"'.$target.$nofollow.'>';
|
@@ -650,6 +652,7 @@ class Pz_LinkCard {
|
|
650 |
}
|
651 |
}
|
652 |
$sns .= '</span>';
|
|
|
653 |
if ($this->options['sns-position'] == '1') {
|
654 |
$sns_title = $sns;
|
655 |
} else {
|
@@ -661,15 +664,16 @@ class Pz_LinkCard {
|
|
661 |
if ($thumbnail) {
|
662 |
$thumbnail = '<span class="lkc-thumbnail">'.$thumbnail.'</span>';
|
663 |
}
|
664 |
-
|
665 |
// サイト情報
|
666 |
$domain_info = '<div class="lkc-info">'.$a_op.'<span class="lkc-domain"'.$site_title.'>'.$favicon.' '.$site_name.$info.'</span>'.$a_cl.' '.$sns_info.$this->plugin_link.'</div>';
|
667 |
|
668 |
// 日本語ドメイン対応
|
669 |
if (isset($this->options['flg-idn']) ? true : false) {
|
|
|
670 |
if (function_exists('idn_to_utf8')) {
|
671 |
-
if (substr( $
|
672 |
-
$
|
|
|
673 |
}
|
674 |
}
|
675 |
}
|
@@ -678,8 +682,8 @@ class Pz_LinkCard {
|
|
678 |
$content = '<div class="lkc-content">'.$a_op.$thumbnail.'<span class="lkc-title">'.$title.'</span>'.$a_cl.$sns_title.'<div class="lkc-url"><cite>'.$st_op.$a_op.$url.$st_cl.$a_cl.'</cite></div><div class="lkc-excerpt">'.$excerpt.'</div></div>';
|
679 |
|
680 |
// Google AMPに暫定対応
|
681 |
-
if ( (isset($this->options['flg-amp']) ? true : false) &&
|
682 |
-
|
683 |
$tag = '<table border="1" cellspacing="0" cellpadding="4"><tbody></tr><tr><td>'.$excerpt.'<br>'.$a_op_all.$a_op.$title.$a_cl.$a_cl_all.' - '.$site_name.'</td></tr></tbody></table>';
|
684 |
} else {
|
685 |
// HTMLタグ作成
|
@@ -705,7 +709,7 @@ class Pz_LinkCard {
|
|
705 |
return $tag;
|
706 |
}
|
707 |
|
708 |
-
// URL
|
709 |
function pz_TrimURL($url = null) {
|
710 |
if (!isset($url) || $url == '') {
|
711 |
$url = null;
|
@@ -714,8 +718,8 @@ class Pz_LinkCard {
|
|
714 |
|
715 |
if (isset($url) && $url <> '') {
|
716 |
$url = html_entity_decode($url);
|
717 |
-
$url = preg_replace('/^[\s \'\"‘’“”″]*(.*?)[\s \'\"‘’“”″]*$/u', '\1', $url);
|
718 |
-
$url = esc_url($url);
|
719 |
switch (isset($this->options['trail-slash']) ? $this->options['trail-slash'] : null) {
|
720 |
case '1': // URLがドメイン名だけの場合、最後のスラッシュを除外する
|
721 |
$array_url = parse_url($url);
|
@@ -802,7 +806,7 @@ class Pz_LinkCard {
|
|
802 |
}
|
803 |
}
|
804 |
|
805 |
-
//
|
806 |
if ($update_cnt || ($this->now - strtotime($data['regist']) < WEEK_IN_SECONDS)) {
|
807 |
$sns_nexttime = $this->now + DAY_IN_SECONDS + rand(0, DAY_IN_SECONDS); // 1day + 0-24h
|
808 |
} else {
|
@@ -853,7 +857,7 @@ class Pz_LinkCard {
|
|
853 |
if (is_wp_error($data)) {
|
854 |
return null;
|
855 |
}
|
856 |
-
return (array) $data;
|
857 |
}
|
858 |
|
859 |
// キャッシュデータを保存
|
@@ -870,15 +874,7 @@ class Pz_LinkCard {
|
|
870 |
if (!isset($data['url_key']) || is_null($data['url_key']) || $data['url_key'] == '' ) {
|
871 |
$data['url_key'] = hash( 'sha256', esc_url( $url ), true);
|
872 |
}
|
873 |
-
|
874 |
-
if (!$data['regist_result']) { // 最初登録時情報
|
875 |
-
$data['regist_title'] = $data['title'];
|
876 |
-
$data['regist_excerpt'] = $data['excerpt'];
|
877 |
-
$data['regist_charset'] = $data['charset'];
|
878 |
-
$data['regist_result'] = $data['result_code'];
|
879 |
-
$data['regist_time'] = $this->now;
|
880 |
-
}
|
881 |
-
$data['uptime'] = $this->now; // 最終更新日時
|
882 |
|
883 |
// 更新してみる
|
884 |
if ( isset($data['id']) ) {
|
@@ -906,30 +902,9 @@ class Pz_LinkCard {
|
|
906 |
$this->db_name,
|
907 |
$data
|
908 |
);
|
|
|
909 |
if (!$result) {
|
910 |
-
|
911 |
-
unset($data['site_name']);
|
912 |
-
$result = $wpdb->insert(
|
913 |
-
$this->db_name,
|
914 |
-
$data
|
915 |
-
);
|
916 |
-
if (!$result) {
|
917 |
-
unset($data['excerpt']);
|
918 |
-
$result = $wpdb->insert(
|
919 |
-
$this->db_name,
|
920 |
-
$data
|
921 |
-
);
|
922 |
-
if (!$result) {
|
923 |
-
unset($data['title']);
|
924 |
-
$result = $wpdb->insert(
|
925 |
-
$this->db_name,
|
926 |
-
$data
|
927 |
-
);
|
928 |
-
if (!$result) {
|
929 |
-
return $data;
|
930 |
-
}
|
931 |
-
}
|
932 |
-
}
|
933 |
}
|
934 |
}
|
935 |
return $this->pz_GetCache($data);
|
@@ -958,45 +933,47 @@ class Pz_LinkCard {
|
|
958 |
// サイト名取得
|
959 |
$site_name = get_bloginfo('name');
|
960 |
|
961 |
-
//
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
|
|
|
|
967 |
|
968 |
// サイトアイコン
|
969 |
if (function_exists('has_site_icon') && has_site_icon()) {
|
970 |
-
$favicon
|
971 |
} else {
|
972 |
-
$favicon
|
973 |
}
|
974 |
|
975 |
-
$title =
|
976 |
-
$excerpt =
|
977 |
-
$thumbnail =
|
978 |
|
979 |
// 記事内容
|
980 |
-
$post_id
|
981 |
-
if ($this->options['debug-time']) {
|
982 |
-
echo
|
983 |
}
|
984 |
-
if ( $
|
985 |
-
$result_code =
|
986 |
-
$post =
|
987 |
if ( $this->options['in-get'] ) {
|
988 |
-
$title =
|
989 |
-
$excerpt =
|
990 |
} else {
|
991 |
-
$title =
|
992 |
-
$excerpt =
|
993 |
if ($excerpt == '') {
|
994 |
-
$excerpt =
|
995 |
}
|
996 |
}
|
997 |
$thumbnail_id = get_post_thumbnail_id( $post_id ); // サムネイル
|
998 |
-
if ($this->options['debug-time']) {
|
999 |
-
echo
|
1000 |
}
|
1001 |
$attach = wp_get_attachment_image_src( $thumbnail_id, 'thumbnail', true );
|
1002 |
if (isset($attach) && count($attach) > 3 && isset($attach[0])) {
|
@@ -1004,8 +981,8 @@ class Pz_LinkCard {
|
|
1004 |
}
|
1005 |
} else {
|
1006 |
// カテゴリページ等は内部取得できないので外部取得する
|
1007 |
-
//if ($this->options['debug-time']) {
|
1008 |
-
// echo
|
1009 |
//}
|
1010 |
//$data = $this->pz_GetCURL( $data );
|
1011 |
//$title = $data['title'];
|
@@ -1044,30 +1021,25 @@ class Pz_LinkCard {
|
|
1044 |
}
|
1045 |
|
1046 |
// データセット
|
1047 |
-
if ($data['title']
|
1048 |
-
$before['mod_title']
|
1049 |
} else {
|
1050 |
-
$before['mod_title']
|
1051 |
}
|
1052 |
-
if ($data['excerpt']
|
1053 |
-
$before['mod_excerpt']
|
1054 |
} else {
|
1055 |
-
$before['mod_excerpt']
|
1056 |
-
}
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
$data['
|
1061 |
-
$data['
|
1062 |
-
$data['
|
1063 |
-
$data['
|
1064 |
-
$data['
|
1065 |
-
$data['
|
1066 |
-
$data['thumbnail'] = $thumbnail;
|
1067 |
-
$data['favicon'] = $favicon;
|
1068 |
-
$data['result_code'] = $result_code;
|
1069 |
-
$data['alive_result'] = $result_code;
|
1070 |
-
$data['favicon'] = $favicon;
|
1071 |
|
1072 |
return $data;
|
1073 |
}
|
@@ -1090,12 +1062,29 @@ class Pz_LinkCard {
|
|
1090 |
$charset = null;
|
1091 |
$result_code = null;
|
1092 |
|
1093 |
-
|
1094 |
-
$
|
1095 |
-
$
|
1096 |
-
$
|
1097 |
-
$
|
1098 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1099 |
|
1100 |
if ( function_exists( 'curl_init' ) ) { // cURLを使用する
|
1101 |
$result_code = 0;
|
@@ -1106,9 +1095,10 @@ class Pz_LinkCard {
|
|
1106 |
curl_setopt( $ch, CURLOPT_REFERER, get_permalink() ); // リファラ
|
1107 |
}
|
1108 |
if (isset($this->options['flg-agent']) ? true : false) {
|
1109 |
-
curl_setopt( $ch, CURLOPT_USERAGENT, $this->options['user-agent'] ); //
|
|
|
1110 |
} else {
|
1111 |
-
curl_setopt( $ch, CURLOPT_USERAGENT, esc_html( $_SERVER['HTTP_USER_AGENT'] ) ); //
|
1112 |
}
|
1113 |
if (isset($this->options['flg-redir']) ? true : false) {
|
1114 |
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true ); // リダイレクトを処理する
|
@@ -1117,30 +1107,30 @@ class Pz_LinkCard {
|
|
1117 |
} else {
|
1118 |
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, false ); // リダイレクトを処理しない
|
1119 |
}
|
1120 |
-
curl_setopt( $ch, CURLOPT_COOKIESESSION,
|
1121 |
-
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER,
|
1122 |
$html = curl_exec($ch);
|
1123 |
-
$errno = intval( curl_errno( $ch ) );
|
1124 |
if ( $errno ) {
|
1125 |
-
$html =
|
1126 |
-
$result_code =
|
1127 |
-
$error =
|
1128 |
} else {
|
1129 |
-
$header =
|
1130 |
-
$result_code =
|
1131 |
-
$error =
|
1132 |
}
|
1133 |
curl_close($ch);
|
1134 |
-
} else {
|
1135 |
-
$result = wp_remote_get( $url );
|
1136 |
if ( is_wp_error( $result ) ) {
|
1137 |
-
$html =
|
1138 |
-
$result_code =
|
1139 |
-
$error =
|
1140 |
} else {
|
1141 |
-
$html =
|
1142 |
-
$result_code =
|
1143 |
-
$error =
|
1144 |
}
|
1145 |
}
|
1146 |
|
@@ -1151,6 +1141,7 @@ class Pz_LinkCard {
|
|
1151 |
$m[1] = trim(trim($m[1]), '\'\"');
|
1152 |
$charset = $m[1];
|
1153 |
} else {
|
|
|
1154 |
foreach(array('UTF-8','SJIS','EUC-JP','eucJP-win','ASCII','JIS','SJIS-win') as $c_charset) {
|
1155 |
// 文字コード変換してみて内容が変わらないものを文字セットと判断する
|
1156 |
if (mb_convert_encoding($html, $this->charset, $c_charset) == $html) {
|
@@ -1158,7 +1149,6 @@ class Pz_LinkCard {
|
|
1158 |
break;
|
1159 |
}
|
1160 |
}
|
1161 |
-
// $charset = mb_detect_encoding( $html ); // PHPに判定をまかせたい人向け
|
1162 |
}
|
1163 |
if (is_null($charset)) {
|
1164 |
$charset = 'auto';
|
@@ -1167,7 +1157,7 @@ class Pz_LinkCard {
|
|
1167 |
$html = mb_convert_encoding($html, $this->charset, $charset);
|
1168 |
}
|
1169 |
|
1170 |
-
// HEAD
|
1171 |
$head = null;
|
1172 |
$tags = null;
|
1173 |
if (preg_match('/<\s*head\s*[^>]*>(.*)<\s*\/head\s*>/si', $html, $m)) {
|
@@ -1232,34 +1222,28 @@ class Pz_LinkCard {
|
|
1232 |
if (isset($url_key) && !is_null($url_key)) {
|
1233 |
$data['url_key'] = $url_key;
|
1234 |
}
|
1235 |
-
$data['site_name'] =
|
1236 |
-
$data['title'] =
|
1237 |
-
$data['excerpt'] =
|
1238 |
-
$data['
|
1239 |
-
$
|
1240 |
-
|
1241 |
-
|
1242 |
-
|
1243 |
-
|
1244 |
-
|
1245 |
-
$data['
|
1246 |
-
$data['
|
1247 |
-
$data['
|
1248 |
-
$data['
|
1249 |
-
|
1250 |
-
|
1251 |
-
|
1252 |
-
|
1253 |
-
|
1254 |
-
$data['
|
1255 |
-
}
|
1256 |
-
|
1257 |
-
$data['sns_facebook'] = (isset( $data['sns_facebook'] ) ? $data['sns_facebook'] : -1 );
|
1258 |
-
$data['sns_hatena'] = (isset( $data['sns_hatena'] ) ? $data['sns_hatena'] : -1 );
|
1259 |
-
$data['sns_nexttime'] = (isset( $data['sns_nexttime'] ) ? $data['sns_nexttime'] : 0 );
|
1260 |
-
$data['uptime'] = $this->now;
|
1261 |
-
$data['alive_time'] = $this->now;
|
1262 |
-
$data['alive_result'] = $result_code;
|
1263 |
return $data;
|
1264 |
}
|
1265 |
|
@@ -1413,20 +1397,20 @@ class Pz_LinkCard {
|
|
1413 |
if (isset($data) && isset($data->url)) {
|
1414 |
$before = $this->pz_GetCache( array( 'url' => $data->url ) );
|
1415 |
$after = $this->pz_GetCURL( $before );
|
1416 |
-
if ($before['title']
|
1417 |
-
$before['mod_title']
|
1418 |
} else {
|
1419 |
-
$before['mod_title']
|
1420 |
}
|
1421 |
-
if ($before['excerpt']
|
1422 |
-
$before['mod_excerpt']
|
1423 |
} else {
|
1424 |
-
$before['mod_excerpt']
|
1425 |
}
|
1426 |
-
$before['alive_result'] =
|
1427 |
-
$before['alive_time'] =
|
1428 |
-
$before['thumbnail'] =
|
1429 |
-
$before['favicon'] =
|
1430 |
$before = $this->pz_SetCache( $before );
|
1431 |
}
|
1432 |
}
|
3 |
Plugin Name: Pz-LinkCard
|
4 |
Plugin URI: http://poporon.poponet.jp/pz-linkcard
|
5 |
Description: リンクをカード形式で表示します。
|
6 |
+
Version: 2.0.0.3
|
7 |
Author: poporon
|
8 |
Author URI: http://poporon.poponet.jp
|
9 |
License: GPLv2 or later
|
114 |
'flg-alive' => '1',
|
115 |
'flg-ssl' => '1',
|
116 |
'flg-amp' => '1',
|
117 |
+
'flg-idn' => '1',
|
118 |
'style-reset-img' => '1',
|
119 |
'style' => null,
|
120 |
'css-file' => null,
|
134 |
'thumbnail-url' => null,
|
135 |
'plugin-link' => null,
|
136 |
'plugin-name' => 'Pz-LinkCard',
|
137 |
+
'plugin-version' => '2.0.0.3',
|
138 |
'plugin-url' => 'http://poporon.poponet.jp/pz-linkcard',
|
139 |
'pz-hbc-options' => null,
|
140 |
'debug-time' => null
|
179 |
add_filter ('the_content', array($this, 'auto_replace') ); // 自動置き換え
|
180 |
add_shortcode ('pz-linkcard-auto-replace', array($this, 'shortcode') ); // 自動置き換え専用ショートコード
|
181 |
}
|
182 |
+
if ($this->options['code1'] <> '') {
|
183 |
add_shortcode($this->options['code1'], array($this, 'shortcode'));
|
184 |
}
|
185 |
+
if ($this->options['code2'] <> '') {
|
186 |
add_shortcode($this->options['code2'], array($this, 'shortcode'));
|
187 |
}
|
188 |
+
if ($this->options['code3'] <> '') {
|
189 |
add_shortcode($this->options['code3'], array($this, 'shortcode'));
|
190 |
}
|
191 |
+
if ($this->options['code4'] <> '') {
|
192 |
add_shortcode($this->options['code4'], array($this, 'shortcode'));
|
193 |
}
|
194 |
|
225 |
|
226 |
if (!wp_next_scheduled('pz_linkcard_check')) {
|
227 |
wp_schedule_event ( time() + 10 , 'hourly', 'pz_linkcard_check');
|
228 |
+
// wp_schedule_single_event( time() + 10 , 'pz_linkcard_check');
|
229 |
}
|
230 |
if (!wp_next_scheduled('pz_linkcard_alive')) {
|
231 |
wp_schedule_event ( time() + 1800 , 'daily', 'pz_linkcard_alive');
|
232 |
+
// wp_schedule_single_event( time() + 30 , 'pz_linkcard_alive');
|
233 |
}
|
234 |
}
|
235 |
|
236 |
+
// ショートコード処理(コードが単純になるので、直接HTMLタグにするのでは無くショートコードに変換する。)
|
237 |
public function auto_replace($contents) {
|
238 |
if (isset($this->options['auto-atag']) && $this->options['auto-atag']) {
|
239 |
$contents = preg_replace( '/(^|<br ?\/?>)(<p.*>)?<a .*href=[\'"](https?:\/\/[-_\.!~*()a-zA-Z0-9;\/?:\@&=+\$,%#]+)[\'"]((?!<IMG).)*<\/a>(<\/p>)?$/im', '[pz-linkcard-auto-replace url="$3"]', $contents);
|
247 |
// ショートコード処理
|
248 |
public function shortcode($atts, $content = null, $shortcode) {
|
249 |
// 実行時間
|
250 |
+
if (isset($this->options['debug-time']) && $this->options['debug-time']) {
|
251 |
$start_time = microtime(true);
|
252 |
}
|
253 |
|
295 |
$data = $this->pz_GetHTML ( $atts );
|
296 |
|
297 |
// 実行時間
|
298 |
+
if (isset($this->options['debug-time']) && $this->options['debug-time']) {
|
299 |
$end_time = microtime(true);
|
300 |
$elasped_time = number_format($end_time - $start_time, 8, '.', ',');
|
301 |
$data = PHP_EOL.'<!-- Pz-LkC -->'.PHP_EOL.$data.PHP_EOL.'<!-- /Pz-LkC ('.$elasped_time.'sec) -->'.PHP_EOL;
|
306 |
|
307 |
// キャッシュやリンク先からリンクカードのHTMLを生成
|
308 |
function pz_GetHTML($atts, $content = null) {
|
309 |
+
if (isset($this->options['debug-time']) && $this->options['debug-time']) {
|
310 |
+
echo PHP_EOL.'<!-- Pz-LkC [DEBUG INFORMATION] /-->'.PHP_EOL;
|
311 |
+
}
|
312 |
+
|
313 |
+
$url = $this->pz_TrimURL( $atts['url'] );
|
314 |
+
if (!isset($url) || $url == '' ) {
|
315 |
+
return null;
|
316 |
+
}
|
317 |
+
if (isset($this->options['debug-time']) && $this->options['debug-time']) {
|
318 |
+
echo '<!-- Pz-LkC [URL='.$url.'] /-->'.PHP_EOL;
|
319 |
}
|
320 |
|
321 |
// モバイルチェック
|
324 |
} else {
|
325 |
$is_mobile = false;
|
326 |
}
|
327 |
+
if (isset($this->options['debug-time']) && $this->options['debug-time']) {
|
328 |
+
echo '<!-- Pz-LkC [MOBILE='.$is_mobile.'] /-->'.PHP_EOL;
|
329 |
}
|
330 |
|
331 |
+
// リンク先URLからドメイン名を抽出
|
332 |
+
if (preg_match('{https?://(.+?)/}i', $url.'/',$m)) {
|
333 |
+
$domain_url = $m[0];
|
334 |
+
$domain = $m[1];
|
335 |
+
} else {
|
336 |
+
$domain_url = null;
|
337 |
+
$domain = null;
|
338 |
+
$error = true;
|
339 |
}
|
340 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
341 |
// 自サイトチェック
|
342 |
+
if (preg_match('{'.home_url().'\/.*?}', $url.'/')) {
|
343 |
if ($this->pz_TrimURL(get_permalink()) == $url) {
|
344 |
$link_type = 1; // 自ページ
|
345 |
} else {
|
348 |
} else {
|
349 |
$link_type = 0; // 外部サイト
|
350 |
}
|
351 |
+
if (isset($this->options['debug-time']) && $this->options['debug-time']) {
|
352 |
+
echo '<!-- Pz-LkC [TYPE='.$link_type.'] /-->'.PHP_EOL;
|
353 |
}
|
354 |
|
355 |
// モバイルかPCかのクラス名を追加
|
356 |
$class_id = 'linkcard';
|
357 |
+
if ($is_mobile && isset($this->options['class-mobile']) && $this->options['class-mobile'] <> '') {
|
358 |
$class_id .= ' '.$this->options['class-mobile'];
|
359 |
+
} elseif (isset($this->options['class-pc']) && $this->options['class-pc'] <> '') {
|
360 |
$class_id .= ' '.$this->options['class-pc'];
|
361 |
}
|
362 |
|
370 |
$data_id = $data['id'];
|
371 |
$url = $data['url'];
|
372 |
}
|
373 |
+
if (isset($this->options['debug-time']) && $this->options['debug-time']) {
|
374 |
+
echo '<!-- Pz-LkC [CACHE='.$data_id.'] /-->'.PHP_EOL;
|
375 |
}
|
376 |
|
377 |
// 内部リンクの処理
|
378 |
if ( $link_type ) {
|
379 |
+
$target = ''; // 同ページに開く
|
|
|
380 |
if (isset($this->options['in-target'])) {
|
381 |
if ($this->options['in-target'] == '1' || ($this->options['in-target'] == '2' && !$is_mobile)) {
|
382 |
+
$target = ' target="_blank"'; // 新しいページで開く
|
383 |
}
|
384 |
}
|
385 |
+
$nofollow = '';
|
386 |
|
387 |
// キャッシュが無い、もしくは常に最新を取得する、もしくは強制取得
|
388 |
if ( is_null($data_id) || ( isset($atts['force']) && $atts['force'] == true ) ) {
|
389 |
+
if (isset($this->options['debug-time']) && $this->options['debug-time']) {
|
390 |
+
echo '<!-- Pz-LkC [IN-POST] /-->'.PHP_EOL;
|
391 |
}
|
392 |
+
$data = $this->pz_GetPost( $data );
|
393 |
+
$data['link_type'] = 1;
|
394 |
+
if (isset($this->options['debug-time']) && $this->options['debug-time']) {
|
395 |
+
echo '<!-- Pz-LkC [IN-SET] /-->'.PHP_EOL;
|
396 |
}
|
397 |
+
$result = $this->pz_SetCache( $data );
|
398 |
} elseif ($this->options['in-get'] <> 2) {
|
399 |
+
if (isset($this->options['debug-time']) && $this->options['debug-time']) {
|
400 |
+
echo '<!-- Pz-LkC [IN-POST] /-->'.PHP_EOL;
|
401 |
}
|
402 |
+
$data = $this->pz_GetPost( $data );
|
403 |
+
$data['link_type'] = 1;
|
404 |
}
|
405 |
}
|
406 |
|
407 |
// 外部リンクの処理
|
408 |
if ( !$link_type ) {
|
409 |
// リンクターゲットの設定
|
410 |
+
$target = ''; // 同ページに開く
|
411 |
if (isset($this->options['ex-target'])) {
|
412 |
if ($this->options['ex-target'] == '1' || ($this->options['ex-target'] == '2' && !$is_mobile)) {
|
413 |
$target = ' target="_blank"'; // 新しいページで開く
|
414 |
}
|
415 |
}
|
416 |
+
$nofollow = isset($this->options['nofollow']) ? ' rel="nofollow"' : '';
|
417 |
|
418 |
// キャッシュが無い、もしくは強制取得
|
419 |
if ( is_null($data_id) || ( isset($atts['force']) && $atts['force'] == true ) ) {
|
420 |
+
if (isset($this->options['debug-time']) && $this->options['debug-time']) {
|
421 |
+
echo '<!-- Pz-LkC [OUT-CURL] /-->'.PHP_EOL;
|
422 |
}
|
423 |
+
$result = $this->pz_GetCURL( $data );
|
424 |
if ( isset($result) && is_array($result) && isset($result['url']) ) {
|
425 |
$data = $result;
|
426 |
$data['link_type'] = 0;
|
429 |
}
|
430 |
}
|
431 |
|
|
|
432 |
$data_id = (isset($data['id']) ? $data['id'] : null);
|
433 |
$site_name = (isset($data['site_name']) ? $data['site_name'] : null);
|
434 |
$title = (isset($data['title']) ? $data['title'] : null);
|
478 |
} else {
|
479 |
$tag = '<div class="'.$class_id.'">'.$tag.'</div>';
|
480 |
}
|
481 |
+
return $tag;
|
482 |
}
|
483 |
|
484 |
// サムネイル取得
|
485 |
if ( !$this->options['thumbnail-position'] || ( $result_code <> 0 && $result_code <> 200 ) ) {
|
486 |
$thumbnail = null;
|
487 |
} else {
|
488 |
+
if ($sw_thumbnail == '1' || $sw_thumbnail == '13') {
|
489 |
if ( !$link_type ) {
|
490 |
+
$thumbnail_url = $this->pz_GetThumbnail($thumbnail_url);
|
491 |
}
|
492 |
if ( isset($thumbnail_url) && $thumbnail_url <> '' ) {
|
493 |
$thumbnail = '<img class="lkc-thumbnail-img" src="'.$thumbnail_url.'" alt="" />';
|
494 |
+
} elseif ($sw_thumbnail == '13') {
|
495 |
$sw_thumbnail = '3';
|
496 |
}
|
497 |
}
|
498 |
+
if ($sw_thumbnail == '3') {
|
499 |
// 画像取得(WebAPI)
|
500 |
if (isset($this->options['thumbnail-api'])) {
|
501 |
$thumbnail = preg_replace('/%DOMAIN_URL%/', $domain_url, $this->options['thumbnail-api'] );
|
510 |
if (!isset($this->options['info-position'])) {
|
511 |
$favicon = null;
|
512 |
} else{
|
513 |
+
if ($sw_favicon == '1' || $sw_favicon == '13') {
|
514 |
if ( !is_null($favicon_url ) ) {
|
515 |
$favicon = '<img class="lkc-favicon" src="'.$favicon_url.'" alt="" width=16 height=16 />';
|
516 |
+
} elseif ($sw_favicon == '13') {
|
517 |
$sw_favicon == '3';
|
518 |
}
|
519 |
}
|
520 |
+
if ($sw_favicon == '3') {
|
521 |
// サイトアイコン取得(WebAPI)
|
522 |
if (isset($this->options['favicon-api'])) {
|
523 |
$favicon = preg_replace('/%DOMAIN_URL%/', $domain_url, $this->options['favicon-api'] );
|
528 |
}
|
529 |
}
|
530 |
|
531 |
+
// データベースへの保存が終わったので、表示用の編集
|
532 |
+
|
533 |
// タイトル
|
534 |
if (!isset($title) || $title == '') {
|
535 |
$title = esc_html($url); // タイトル取得できていなかったらURLをセットする
|
560 |
$title = $str;
|
561 |
}
|
562 |
|
563 |
+
// 抜粋文整形
|
564 |
+
// 抜粋文非表示の場合、空欄にする
|
565 |
if (!isset($this->options['display-excerpt']) || is_null($this->options['display-excerpt'])) {
|
566 |
$excerpt = '';
|
567 |
} else {
|
590 |
// 日本語ドメイン対応
|
591 |
if (isset($this->options['flg-idn']) ? true : false) {
|
592 |
if (function_exists('idn_to_utf8')) {
|
593 |
+
if ( substr( $site_name, 0, 4 ) == 'xn--') {
|
594 |
+
$site_name = idn_to_utf8( $site_name );
|
595 |
}
|
596 |
}
|
597 |
}
|
600 |
// リンク先URL
|
601 |
$not_allow_code = array('403','404','410');
|
602 |
if (array_search($alive_result, $not_allow_code)) {
|
|
|
603 |
$a_op_all = '<span style="cursor: not-allowed;" title="">';
|
604 |
$a_cl_all = '</span>';
|
605 |
$a_op = '';
|
607 |
$st_op = '<strike>';
|
608 |
$st_cl = '</strike>';
|
609 |
} elseif ((isset($this->options['link-all']) ? $this->options['link-all'] : null) == '1') {
|
|
|
610 |
$a_op_all = '<a class="no_icon" href="'.$url.'"'.$target.$nofollow.'>';
|
611 |
$a_cl_all = '</a>';
|
612 |
$a_op = '';
|
614 |
$st_op = '';
|
615 |
$st_cl = '';
|
616 |
} else {
|
|
|
617 |
$a_op_all = '';
|
618 |
$a_cl_all = '';
|
619 |
$a_op = '<a class="no_icon" href="'.$url.'"'.$target.$nofollow.'>';
|
652 |
}
|
653 |
}
|
654 |
$sns .= '</span>';
|
655 |
+
|
656 |
if ($this->options['sns-position'] == '1') {
|
657 |
$sns_title = $sns;
|
658 |
} else {
|
664 |
if ($thumbnail) {
|
665 |
$thumbnail = '<span class="lkc-thumbnail">'.$thumbnail.'</span>';
|
666 |
}
|
|
|
667 |
// サイト情報
|
668 |
$domain_info = '<div class="lkc-info">'.$a_op.'<span class="lkc-domain"'.$site_title.'>'.$favicon.' '.$site_name.$info.'</span>'.$a_cl.' '.$sns_info.$this->plugin_link.'</div>';
|
669 |
|
670 |
// 日本語ドメイン対応
|
671 |
if (isset($this->options['flg-idn']) ? true : false) {
|
672 |
+
$url_m = parse_url( $url );
|
673 |
if (function_exists('idn_to_utf8')) {
|
674 |
+
if ( substr( $url_m['host'], 0, 4 ) == 'xn--') {
|
675 |
+
$url_m['host'] = idn_to_utf8( $url_m[host] );
|
676 |
+
$url = $url_m['scheme'].'://'.$url_m['host'].$url_m['path'].$url_m['query'].$url_m['fragment'];
|
677 |
}
|
678 |
}
|
679 |
}
|
682 |
$content = '<div class="lkc-content">'.$a_op.$thumbnail.'<span class="lkc-title">'.$title.'</span>'.$a_cl.$sns_title.'<div class="lkc-url"><cite>'.$st_op.$a_op.$url.$st_cl.$a_cl.'</cite></div><div class="lkc-excerpt">'.$excerpt.'</div></div>';
|
683 |
|
684 |
// Google AMPに暫定対応
|
685 |
+
// if ( (isset($this->options['flg-amp']) ? true : false) && function_exists('is_amp_endpoint') && is_amp_endpoint() ) {
|
686 |
+
if ( (isset($this->options['flg-amp']) ? true : false) && preg_match('{/amp/?$}i', $_SERVER["REQUEST_URI"]) ) {
|
687 |
$tag = '<table border="1" cellspacing="0" cellpadding="4"><tbody></tr><tr><td>'.$excerpt.'<br>'.$a_op_all.$a_op.$title.$a_cl.$a_cl_all.' - '.$site_name.'</td></tr></tbody></table>';
|
688 |
} else {
|
689 |
// HTMLタグ作成
|
709 |
return $tag;
|
710 |
}
|
711 |
|
712 |
+
// URL
|
713 |
function pz_TrimURL($url = null) {
|
714 |
if (!isset($url) || $url == '') {
|
715 |
$url = null;
|
718 |
|
719 |
if (isset($url) && $url <> '') {
|
720 |
$url = html_entity_decode($url);
|
721 |
+
$url = preg_replace('/^[\s \'\"‘’“”″]*(.*?)[\s \'\"‘’“”″]*$/u', '\1', $url);
|
722 |
+
$url = esc_url($url); // プロトコル除外など
|
723 |
switch (isset($this->options['trail-slash']) ? $this->options['trail-slash'] : null) {
|
724 |
case '1': // URLがドメイン名だけの場合、最後のスラッシュを除外する
|
725 |
$array_url = parse_url($url);
|
806 |
}
|
807 |
}
|
808 |
|
809 |
+
// 登録してから一週間までは毎日、それ以降は週一回更新
|
810 |
if ($update_cnt || ($this->now - strtotime($data['regist']) < WEEK_IN_SECONDS)) {
|
811 |
$sns_nexttime = $this->now + DAY_IN_SECONDS + rand(0, DAY_IN_SECONDS); // 1day + 0-24h
|
812 |
} else {
|
857 |
if (is_wp_error($data)) {
|
858 |
return null;
|
859 |
}
|
860 |
+
return (array) $data; // Arrayに直して戻す
|
861 |
}
|
862 |
|
863 |
// キャッシュデータを保存
|
874 |
if (!isset($data['url_key']) || is_null($data['url_key']) || $data['url_key'] == '' ) {
|
875 |
$data['url_key'] = hash( 'sha256', esc_url( $url ), true);
|
876 |
}
|
877 |
+
$data['uptime'] = $this->now; // 最終更新日時
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
878 |
|
879 |
// 更新してみる
|
880 |
if ( isset($data['id']) ) {
|
902 |
$this->db_name,
|
903 |
$data
|
904 |
);
|
905 |
+
// 挿入できなかったらエラー終了
|
906 |
if (!$result) {
|
907 |
+
return null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
908 |
}
|
909 |
}
|
910 |
return $this->pz_GetCache($data);
|
933 |
// サイト名取得
|
934 |
$site_name = get_bloginfo('name');
|
935 |
|
936 |
+
// ドメイン名
|
937 |
+
if (preg_match('{https?://(.*)/}i', home_url().'/',$m)) {
|
938 |
+
$domain_url = $m[0];
|
939 |
+
$domain = $m[1];
|
940 |
+
} else {
|
941 |
+
$domain_url = null;
|
942 |
+
$domain = null;
|
943 |
+
}
|
944 |
|
945 |
// サイトアイコン
|
946 |
if (function_exists('has_site_icon') && has_site_icon()) {
|
947 |
+
$favicon = get_site_icon_url(16, '', 0);
|
948 |
} else {
|
949 |
+
$favicon = null;
|
950 |
}
|
951 |
|
952 |
+
$title = null;
|
953 |
+
$excerpt = null;
|
954 |
+
$thumbnail = null;
|
955 |
|
956 |
// 記事内容
|
957 |
+
$post_id = url_to_postid( $data['url'] ); // 記事IDを取得
|
958 |
+
if (isset($this->options['debug-time']) && $this->options['debug-time']) {
|
959 |
+
echo '<!-- Pz-LkC [PID='.$post_id.'] /-->'.PHP_EOL;
|
960 |
}
|
961 |
+
if ( $post_id ) {
|
962 |
+
$result_code = 200; // 外部取得と同じコードをセット
|
963 |
+
$post = get_post($post_id); // 記事情報
|
964 |
if ( $this->options['in-get'] ) {
|
965 |
+
$title = $post->post_title; // 記事タイトル
|
966 |
+
$excerpt = $post->post_content; // 記事内容から抜粋
|
967 |
} else {
|
968 |
+
$title = $post->post_title; // 記事タイトル
|
969 |
+
$excerpt = $post->post_excerpt; // 抜粋文優先
|
970 |
if ($excerpt == '') {
|
971 |
+
$excerpt = $post->post_content; // 抜粋文が無かったら記事
|
972 |
}
|
973 |
}
|
974 |
$thumbnail_id = get_post_thumbnail_id( $post_id ); // サムネイル
|
975 |
+
if (isset($this->options['debug-time']) && $this->options['debug-time']) {
|
976 |
+
echo '<!-- Pz-LkC [TID='.$thumbnail_id.'] /-->'.PHP_EOL;
|
977 |
}
|
978 |
$attach = wp_get_attachment_image_src( $thumbnail_id, 'thumbnail', true );
|
979 |
if (isset($attach) && count($attach) > 3 && isset($attach[0])) {
|
981 |
}
|
982 |
} else {
|
983 |
// カテゴリページ等は内部取得できないので外部取得する
|
984 |
+
//if (isset($this->options['debug-time']) && $this->options['debug-time']) {
|
985 |
+
// echo '<!-- Pz-LkC [IN-CURL] /-->'.PHP_EOL;
|
986 |
//}
|
987 |
//$data = $this->pz_GetCURL( $data );
|
988 |
//$title = $data['title'];
|
1021 |
}
|
1022 |
|
1023 |
// データセット
|
1024 |
+
if ($data['title'] == $title ) {
|
1025 |
+
$before['mod_title'] = 0;
|
1026 |
} else {
|
1027 |
+
$before['mod_title'] = 1;
|
1028 |
}
|
1029 |
+
if ($data['excerpt'] == $excerpt ) {
|
1030 |
+
$before['mod_excerpt'] = 0;
|
1031 |
} else {
|
1032 |
+
$before['mod_excerpt'] = 1;
|
1033 |
+
}
|
1034 |
+
$data['title'] = $title;
|
1035 |
+
$data['excerpt'] = $excerpt;
|
1036 |
+
$data['thumbnail'] = $thumbnail;
|
1037 |
+
$data['favicon'] = $favicon;
|
1038 |
+
$data['result_code'] = $result_code;
|
1039 |
+
$data['alive_result'] = $result_code;
|
1040 |
+
$data['domain'] = $domain;
|
1041 |
+
$data['site_name'] = $site_name;
|
1042 |
+
$data['favicon'] = $favicon;
|
|
|
|
|
|
|
|
|
|
|
1043 |
|
1044 |
return $data;
|
1045 |
}
|
1062 |
$charset = null;
|
1063 |
$result_code = null;
|
1064 |
|
1065 |
+
$data['post_id'] = (isset( $data['post_id'] ) ? $data['post_id'] : get_the_ID() );
|
1066 |
+
$data['sns_twitter'] = (isset( $data['sns_twitter'] ) ? $data['sns_twitter'] : -1 );
|
1067 |
+
$data['sns_facebook'] = (isset( $data['sns_facebook'] ) ? $data['sns_facebook'] : -1 );
|
1068 |
+
$data['sns_hatena'] = (isset( $data['sns_hatena'] ) ? $data['sns_hatena'] : -1 );
|
1069 |
+
$data['sns_nexttime'] = (isset( $data['sns_nexttime'] ) ? $data['sns_nexttime'] : 0 );
|
1070 |
+
$data['uptime'] = (isset( $data['uptime'] ) ? $data['uptime'] : 0 );
|
1071 |
+
$data['alive_time'] = (isset( $data['alive_time'] ) ? $data['alive_time'] : 0 );
|
1072 |
+
$data['alive_result'] = (isset( $data['alive_result'] ) ? $data['alive_result'] : 0 );
|
1073 |
+
$data['mod_title'] = 0;
|
1074 |
+
$data['mod_excerpt'] = 0;
|
1075 |
+
|
1076 |
+
if ( isset( $data['domain'] ) ) {
|
1077 |
+
$domain_url = $data['domain'];
|
1078 |
+
$domain = $data['domain'];
|
1079 |
+
} else {
|
1080 |
+
if (preg_match('{https?://(.+?)/}i', $url.'/',$m)) {
|
1081 |
+
$domain_url = $m[0];
|
1082 |
+
$domain = $m[1];
|
1083 |
+
} else {
|
1084 |
+
$domain_url = null;
|
1085 |
+
$domain = null;
|
1086 |
+
}
|
1087 |
+
}
|
1088 |
|
1089 |
if ( function_exists( 'curl_init' ) ) { // cURLを使用する
|
1090 |
$result_code = 0;
|
1095 |
curl_setopt( $ch, CURLOPT_REFERER, get_permalink() ); // リファラ
|
1096 |
}
|
1097 |
if (isset($this->options['flg-agent']) ? true : false) {
|
1098 |
+
curl_setopt( $ch, CURLOPT_USERAGENT, $this->options['user-agent'] ); // ユーザーエージェント
|
1099 |
+
// curl_setopt( $ch, CURLOPT_USERAGENT, 'Pz-LinkCard-Crawler/'.$this->options['plugin-version'].' WordPress/'.get_bloginfo('version').' cURL/'.curl_version()['version'].' PHP/'.phpversion() );
|
1100 |
} else {
|
1101 |
+
curl_setopt( $ch, CURLOPT_USERAGENT, esc_html( $_SERVER['HTTP_USER_AGENT'] ) ); // ユーザーエージェント
|
1102 |
}
|
1103 |
if (isset($this->options['flg-redir']) ? true : false) {
|
1104 |
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true ); // リダイレクトを処理する
|
1107 |
} else {
|
1108 |
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, false ); // リダイレクトを処理しない
|
1109 |
}
|
1110 |
+
curl_setopt( $ch, CURLOPT_COOKIESESSION, true ); // セッションCOOKIEを使用する
|
1111 |
+
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, (isset($this->options['flg-ssl']) ? false : true) ); // SSL検証
|
1112 |
$html = curl_exec($ch);
|
1113 |
+
$errno = intval( curl_errno( $ch ) );
|
1114 |
if ( $errno ) {
|
1115 |
+
$html = ''; // cURLエラー
|
1116 |
+
$result_code = 0 - $errno;
|
1117 |
+
$error = true;
|
1118 |
} else {
|
1119 |
+
$header = curl_getinfo($ch);
|
1120 |
+
$result_code = $header['http_code']; // HTTPステータス
|
1121 |
+
$error = false;
|
1122 |
}
|
1123 |
curl_close($ch);
|
1124 |
+
} else { // cURLを使用しない
|
1125 |
+
$result = wp_remote_get( $url );
|
1126 |
if ( is_wp_error( $result ) ) {
|
1127 |
+
$html = '';
|
1128 |
+
$result_code = -1; // wp_remote_getエラー
|
1129 |
+
$error = true;
|
1130 |
} else {
|
1131 |
+
$html = $result['body'];
|
1132 |
+
$result_code = $result['response']['code']; // HTTPステータス
|
1133 |
+
$error = false;
|
1134 |
}
|
1135 |
}
|
1136 |
|
1141 |
$m[1] = trim(trim($m[1]), '\'\"');
|
1142 |
$charset = $m[1];
|
1143 |
} else {
|
1144 |
+
// $charset = mb_detect_encoding( $html );
|
1145 |
foreach(array('UTF-8','SJIS','EUC-JP','eucJP-win','ASCII','JIS','SJIS-win') as $c_charset) {
|
1146 |
// 文字コード変換してみて内容が変わらないものを文字セットと判断する
|
1147 |
if (mb_convert_encoding($html, $this->charset, $c_charset) == $html) {
|
1149 |
break;
|
1150 |
}
|
1151 |
}
|
|
|
1152 |
}
|
1153 |
if (is_null($charset)) {
|
1154 |
$charset = 'auto';
|
1157 |
$html = mb_convert_encoding($html, $this->charset, $charset);
|
1158 |
}
|
1159 |
|
1160 |
+
// HEADタグ
|
1161 |
$head = null;
|
1162 |
$tags = null;
|
1163 |
if (preg_match('/<\s*head\s*[^>]*>(.*)<\s*\/head\s*>/si', $html, $m)) {
|
1222 |
if (isset($url_key) && !is_null($url_key)) {
|
1223 |
$data['url_key'] = $url_key;
|
1224 |
}
|
1225 |
+
$data['site_name'] = $site_name;
|
1226 |
+
$data['title'] = $title;
|
1227 |
+
$data['excerpt'] = $excerpt;
|
1228 |
+
$data['charset'] = $charset;
|
1229 |
+
if (isset($atts['force']) && $atts['force'] == true) {
|
1230 |
+
$data['regist'] = $this->now_mysql; // 登録日
|
1231 |
+
}
|
1232 |
+
}
|
1233 |
+
$data['url'] = $url;
|
1234 |
+
$data['thumbnail'] = ( isset($thumbnail_url) ? $thumbnail_url : null );
|
1235 |
+
$data['result_code'] = $result_code;
|
1236 |
+
$data['alive_result'] = $result_code;
|
1237 |
+
$data['domain'] = $domain;
|
1238 |
+
$data['favicon'] = ( isset($favicon_url) ? $favicon_url : null );
|
1239 |
+
if (!$data['regist_result']) {
|
1240 |
+
$data['regist_title'] = $title;
|
1241 |
+
$data['regist_excerpt'] = $excerpt;
|
1242 |
+
$data['regist_charset'] = $charset;
|
1243 |
+
$data['regist_result'] = $result_code;
|
1244 |
+
$data['regist_time'] = $this->now;
|
1245 |
+
}
|
1246 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
1247 |
return $data;
|
1248 |
}
|
1249 |
|
1397 |
if (isset($data) && isset($data->url)) {
|
1398 |
$before = $this->pz_GetCache( array( 'url' => $data->url ) );
|
1399 |
$after = $this->pz_GetCURL( $before );
|
1400 |
+
if ($before['title'] == $after['title'] ) {
|
1401 |
+
$before['mod_title'] = 0;
|
1402 |
} else {
|
1403 |
+
$before['mod_title'] = 1;
|
1404 |
}
|
1405 |
+
if ($before['excerpt'] == $after['excerpt'] ) {
|
1406 |
+
$before['mod_excerpt'] = 0;
|
1407 |
} else {
|
1408 |
+
$before['mod_excerpt'] = 1;
|
1409 |
}
|
1410 |
+
$before['alive_result'] = $after['result_code'];
|
1411 |
+
$before['alive_time'] = $this->now;
|
1412 |
+
$before['thumbnail'] = $after['thumbnail'];
|
1413 |
+
$before['favicon'] = $after['favicon'];
|
1414 |
$before = $this->pz_SetCache( $before );
|
1415 |
}
|
1416 |
}
|
readme.txt
CHANGED
@@ -155,14 +155,6 @@ A5.
|
|
155 |
5. "Write shortcode and url"
|
156 |
|
157 |
== Changelog ==
|
158 |
-
Ver2.0.0.2
|
159 |
-
* 未実装のJavaScriptの呼び出しがあったので修正しました。
|
160 |
-
Fixed: Fixed a bug.
|
161 |
-
|
162 |
-
Ver2.0.0.1
|
163 |
-
* idn_to_utf8()が実装されていない環境でエラーが出ていたので対応しました。
|
164 |
-
Fixed: Fixed a bug.
|
165 |
-
|
166 |
Ver2.0.0
|
167 |
* URL指定に「href」も使用できるように変更しました。(Thanks @weblearninglog)
|
168 |
Modefied: "href" was added to the parameter that specifies the URL.
|
155 |
5. "Write shortcode and url"
|
156 |
|
157 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
Ver2.0.0
|
159 |
* URL指定に「href」も使用できるように変更しました。(Thanks @weblearninglog)
|
160 |
Modefied: "href" was added to the parameter that specifies the URL.
|