Version Description
Download this release
Release Info
Developer | poporon |
Plugin | Pz-LinkCard |
Version | 2.0.0.2 |
Comparing to | |
See all releases |
Code changes from version 2.0.0.1 to 2.0.0.2
- js/mce-pz-lkc.js +1 -1
- lib/pz-linkcard-cacheman-edit.php +40 -1
- lib/pz-linkcard-cacheman-list.php +18 -3
- lib/pz-linkcard-init.php +45 -2
- pz-linkcard.php +225 -209
- readme.txt +4 -0
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, '[blogcard url="' + insert_tag + '"]');
|
13 |
}
|
14 |
});
|
15 |
},
|
lib/pz-linkcard-cacheman-edit.php
CHANGED
@@ -54,9 +54,48 @@
|
|
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[
|
|
|
|
|
|
|
|
|
|
|
60 |
</tr>
|
61 |
<tr>
|
62 |
<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 |
+
<?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[use_post_id1]" type="text" id="inputtext" value="<?php echo $data['use_post_id1']; ?>" size="5" readonly="readonly" ondblclick="this.readOnly=false;" />
|
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>
|
lib/pz-linkcard-cacheman-list.php
CHANGED
@@ -14,7 +14,12 @@ case 'title':
|
|
14 |
case 'excerpt':
|
15 |
case 'result_code':
|
16 |
case 'alive_result':
|
17 |
-
case '
|
|
|
|
|
|
|
|
|
|
|
18 |
case 'sns_twitter':
|
19 |
case 'sns_facebook':
|
20 |
case 'sns_hatena':
|
@@ -199,7 +204,7 @@ echo '</div>';
|
|
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('
|
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>
|
@@ -295,7 +300,17 @@ foreach ($data_all as $data) {
|
|
295 |
echo '</td>';
|
296 |
|
297 |
echo ' <td>'.$data->regist.'</td>';
|
298 |
-
echo ' <td style="word-break: break-all;"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
299 |
echo ' <td>'.$data->result_code.($data->result_code <> $data->alive_result ? '<br><span style="color:#f00;">('.$data->alive_result.')</span>' : '').'</td>';
|
300 |
echo '</tr>';
|
301 |
}
|
14 |
case 'excerpt':
|
15 |
case 'result_code':
|
16 |
case 'alive_result':
|
17 |
+
case 'use_post_id1':
|
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 |
<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('use_post_id1', __('Post ID', $this->text_domain) ); ?></th>
|
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>
|
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 |
}
|
lib/pz-linkcard-init.php
CHANGED
@@ -22,9 +22,10 @@
|
|
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,7 +37,13 @@
|
|
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,6 +90,42 @@
|
|
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");
|
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 |
sns_twitter INT DEFAULT -1,
|
38 |
sns_facebook INT DEFAULT -1,
|
39 |
sns_hatena INT DEFAULT -1,
|
40 |
+
post_id INT UNSIGNED DEFAULT 0,
|
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 |
}
|
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");
|
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
|
@@ -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,15 +225,13 @@ class Pz_LinkCard {
|
|
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 |
-
//
|
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,7 +245,7 @@ class Pz_LinkCard {
|
|
247 |
// ショートコード処理
|
248 |
public function shortcode($atts, $content = null, $shortcode) {
|
249 |
// 実行時間
|
250 |
-
if (
|
251 |
$start_time = microtime(true);
|
252 |
}
|
253 |
|
@@ -295,7 +293,7 @@ class Pz_LinkCard {
|
|
295 |
$data = $this->pz_GetHTML ( $atts );
|
296 |
|
297 |
// 実行時間
|
298 |
-
if (
|
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,16 +304,8 @@ class Pz_LinkCard {
|
|
306 |
|
307 |
// キャッシュやリンク先からリンクカードのHTMLを生成
|
308 |
function pz_GetHTML($atts, $content = null) {
|
309 |
-
if (
|
310 |
-
echo
|
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,22 +314,28 @@ class Pz_LinkCard {
|
|
324 |
} else {
|
325 |
$is_mobile = false;
|
326 |
}
|
327 |
-
if (
|
328 |
-
echo
|
329 |
}
|
330 |
|
331 |
-
//
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
}
|
336 |
-
|
337 |
-
|
338 |
-
$error = true;
|
339 |
}
|
340 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
341 |
// 自サイトチェック
|
342 |
-
if (
|
343 |
if ($this->pz_TrimURL(get_permalink()) == $url) {
|
344 |
$link_type = 1; // 自ページ
|
345 |
} else {
|
@@ -348,15 +344,15 @@ class Pz_LinkCard {
|
|
348 |
} else {
|
349 |
$link_type = 0; // 外部サイト
|
350 |
}
|
351 |
-
if (
|
352 |
-
echo
|
353 |
}
|
354 |
|
355 |
// モバイルかPCかのクラス名を追加
|
356 |
$class_id = 'linkcard';
|
357 |
-
if ($is_mobile &&
|
358 |
$class_id .= ' '.$this->options['class-mobile'];
|
359 |
-
} elseif (
|
360 |
$class_id .= ' '.$this->options['class-pc'];
|
361 |
}
|
362 |
|
@@ -370,57 +366,58 @@ class Pz_LinkCard {
|
|
370 |
$data_id = $data['id'];
|
371 |
$url = $data['url'];
|
372 |
}
|
373 |
-
if (
|
374 |
-
echo
|
375 |
}
|
376 |
|
377 |
// 内部リンクの処理
|
378 |
if ( $link_type ) {
|
379 |
-
|
|
|
380 |
if (isset($this->options['in-target'])) {
|
381 |
if ($this->options['in-target'] == '1' || ($this->options['in-target'] == '2' && !$is_mobile)) {
|
382 |
-
$target =
|
383 |
}
|
384 |
}
|
385 |
-
$nofollow = '';
|
386 |
|
387 |
// キャッシュが無い、もしくは常に最新を取得する、もしくは強制取得
|
388 |
if ( is_null($data_id) || ( isset($atts['force']) && $atts['force'] == true ) ) {
|
389 |
-
if (
|
390 |
-
echo
|
391 |
}
|
392 |
-
$data
|
393 |
-
$data['link_type'] =
|
394 |
-
if (
|
395 |
-
echo
|
396 |
}
|
397 |
-
$result
|
398 |
} elseif ($this->options['in-get'] <> 2) {
|
399 |
-
if (
|
400 |
-
echo
|
401 |
}
|
402 |
-
$data
|
403 |
-
$data['link_type'] =
|
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 (
|
421 |
-
echo
|
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,6 +426,7 @@ class Pz_LinkCard {
|
|
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,24 +476,24 @@ class Pz_LinkCard {
|
|
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,14 +508,14 @@ class Pz_LinkCard {
|
|
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,8 +526,6 @@ class Pz_LinkCard {
|
|
528 |
}
|
529 |
}
|
530 |
|
531 |
-
// データベースへの保存が終わったので、表示用の編集
|
532 |
-
|
533 |
// タイトル
|
534 |
if (!isset($title) || $title == '') {
|
535 |
$title = esc_html($url); // タイトル取得できていなかったらURLをセットする
|
@@ -560,8 +556,7 @@ class Pz_LinkCard {
|
|
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,8 +585,8 @@ class Pz_LinkCard {
|
|
590 |
// 日本語ドメイン対応
|
591 |
if (isset($this->options['flg-idn']) ? true : false) {
|
592 |
if (function_exists('idn_to_utf8')) {
|
593 |
-
if (substr( $
|
594 |
-
$site_name = idn_to_utf8( $
|
595 |
}
|
596 |
}
|
597 |
}
|
@@ -600,6 +595,7 @@ class Pz_LinkCard {
|
|
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,6 +603,7 @@ class Pz_LinkCard {
|
|
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,6 +611,7 @@ class Pz_LinkCard {
|
|
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,7 +650,6 @@ class Pz_LinkCard {
|
|
652 |
}
|
653 |
}
|
654 |
$sns .= '</span>';
|
655 |
-
|
656 |
if ($this->options['sns-position'] == '1') {
|
657 |
$sns_title = $sns;
|
658 |
} else {
|
@@ -664,16 +661,15 @@ class Pz_LinkCard {
|
|
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 |
if (function_exists('idn_to_utf8')) {
|
673 |
-
|
674 |
-
|
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,8 +678,8 @@ class Pz_LinkCard {
|
|
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 |
-
|
686 |
-
|
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,7 +705,7 @@ class Pz_LinkCard {
|
|
709 |
return $tag;
|
710 |
}
|
711 |
|
712 |
-
// URL
|
713 |
function pz_TrimURL($url = null) {
|
714 |
if (!isset($url) || $url == '') {
|
715 |
$url = null;
|
@@ -718,8 +714,8 @@ class Pz_LinkCard {
|
|
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,7 +802,7 @@ class Pz_LinkCard {
|
|
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,7 +853,7 @@ class Pz_LinkCard {
|
|
857 |
if (is_wp_error($data)) {
|
858 |
return null;
|
859 |
}
|
860 |
-
return (array) $data;
|
861 |
}
|
862 |
|
863 |
// キャッシュデータを保存
|
@@ -874,7 +870,15 @@ class Pz_LinkCard {
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
878 |
|
879 |
// 更新してみる
|
880 |
if ( isset($data['id']) ) {
|
@@ -902,9 +906,30 @@ class Pz_LinkCard {
|
|
902 |
$this->db_name,
|
903 |
$data
|
904 |
);
|
905 |
-
// 挿入できなかったらエラー終了
|
906 |
if (!$result) {
|
907 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
908 |
}
|
909 |
}
|
910 |
return $this->pz_GetCache($data);
|
@@ -933,47 +958,45 @@ class Pz_LinkCard {
|
|
933 |
// サイト名取得
|
934 |
$site_name = get_bloginfo('name');
|
935 |
|
936 |
-
//
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
$domain = null;
|
943 |
-
}
|
944 |
|
945 |
// サイトアイコン
|
946 |
if (function_exists('has_site_icon') && has_site_icon()) {
|
947 |
-
$favicon
|
948 |
} else {
|
949 |
-
$favicon
|
950 |
}
|
951 |
|
952 |
-
$title =
|
953 |
-
$excerpt =
|
954 |
-
$thumbnail =
|
955 |
|
956 |
// 記事内容
|
957 |
-
$post_id
|
958 |
-
if (
|
959 |
-
echo
|
960 |
}
|
961 |
-
if ( $
|
962 |
-
$result_code =
|
963 |
-
$post =
|
964 |
if ( $this->options['in-get'] ) {
|
965 |
-
$title =
|
966 |
-
$excerpt =
|
967 |
} else {
|
968 |
-
$title =
|
969 |
-
$excerpt =
|
970 |
if ($excerpt == '') {
|
971 |
-
$excerpt =
|
972 |
}
|
973 |
}
|
974 |
$thumbnail_id = get_post_thumbnail_id( $post_id ); // サムネイル
|
975 |
-
if (
|
976 |
-
echo
|
977 |
}
|
978 |
$attach = wp_get_attachment_image_src( $thumbnail_id, 'thumbnail', true );
|
979 |
if (isset($attach) && count($attach) > 3 && isset($attach[0])) {
|
@@ -981,8 +1004,8 @@ class Pz_LinkCard {
|
|
981 |
}
|
982 |
} else {
|
983 |
// カテゴリページ等は内部取得できないので外部取得する
|
984 |
-
//if (
|
985 |
-
// echo
|
986 |
//}
|
987 |
//$data = $this->pz_GetCURL( $data );
|
988 |
//$title = $data['title'];
|
@@ -1021,25 +1044,30 @@ class Pz_LinkCard {
|
|
1021 |
}
|
1022 |
|
1023 |
// データセット
|
1024 |
-
if ($data['title']
|
1025 |
-
$before['mod_title']
|
1026 |
} else {
|
1027 |
-
$before['mod_title']
|
1028 |
}
|
1029 |
-
if ($data['excerpt']
|
1030 |
-
$before['mod_excerpt']
|
1031 |
} else {
|
1032 |
-
$before['mod_excerpt']
|
1033 |
-
}
|
1034 |
-
$data['
|
1035 |
-
|
1036 |
-
|
1037 |
-
$data['
|
1038 |
-
$data['
|
1039 |
-
$data['
|
1040 |
-
$data['
|
1041 |
-
$data['
|
1042 |
-
$data['
|
|
|
|
|
|
|
|
|
|
|
1043 |
|
1044 |
return $data;
|
1045 |
}
|
@@ -1062,29 +1090,12 @@ class Pz_LinkCard {
|
|
1062 |
$charset = null;
|
1063 |
$result_code = null;
|
1064 |
|
1065 |
-
|
1066 |
-
$
|
1067 |
-
$
|
1068 |
-
$
|
1069 |
-
$
|
1070 |
-
$
|
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,10 +1106,9 @@ class Pz_LinkCard {
|
|
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,30 +1117,30 @@ class Pz_LinkCard {
|
|
1107 |
} else {
|
1108 |
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, false ); // リダイレクトを処理しない
|
1109 |
}
|
1110 |
-
curl_setopt( $ch, CURLOPT_COOKIESESSION,
|
1111 |
-
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER,
|
1112 |
$html = curl_exec($ch);
|
1113 |
-
$errno = intval( curl_errno( $ch ) );
|
1114 |
if ( $errno ) {
|
1115 |
-
$html =
|
1116 |
-
$result_code =
|
1117 |
-
$error =
|
1118 |
} else {
|
1119 |
-
$header =
|
1120 |
-
$result_code =
|
1121 |
-
$error =
|
1122 |
}
|
1123 |
curl_close($ch);
|
1124 |
-
} else {
|
1125 |
-
$result = wp_remote_get( $url );
|
1126 |
if ( is_wp_error( $result ) ) {
|
1127 |
-
$html =
|
1128 |
-
$result_code =
|
1129 |
-
$error =
|
1130 |
} else {
|
1131 |
-
$html =
|
1132 |
-
$result_code =
|
1133 |
-
$error =
|
1134 |
}
|
1135 |
}
|
1136 |
|
@@ -1141,7 +1151,6 @@ class Pz_LinkCard {
|
|
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,6 +1158,7 @@ class Pz_LinkCard {
|
|
1149 |
break;
|
1150 |
}
|
1151 |
}
|
|
|
1152 |
}
|
1153 |
if (is_null($charset)) {
|
1154 |
$charset = 'auto';
|
@@ -1157,7 +1167,7 @@ class Pz_LinkCard {
|
|
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,28 +1232,34 @@ class Pz_LinkCard {
|
|
1222 |
if (isset($url_key) && !is_null($url_key)) {
|
1223 |
$data['url_key'] = $url_key;
|
1224 |
}
|
1225 |
-
$data['site_name'] =
|
1226 |
-
$data['title'] =
|
1227 |
-
$data['excerpt'] =
|
1228 |
-
$data['
|
1229 |
-
|
1230 |
-
|
1231 |
-
|
1232 |
-
|
1233 |
-
|
1234 |
-
|
1235 |
-
$data['
|
1236 |
-
$data['
|
1237 |
-
$data['
|
1238 |
-
$data['
|
1239 |
-
|
1240 |
-
|
1241 |
-
|
1242 |
-
|
1243 |
-
|
1244 |
-
$data['
|
1245 |
-
}
|
1246 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1247 |
return $data;
|
1248 |
}
|
1249 |
|
@@ -1317,8 +1333,8 @@ class Pz_LinkCard {
|
|
1317 |
public function enqueue_admin($hook) {
|
1318 |
wp_enqueue_style ('wp-color-picker');
|
1319 |
wp_enqueue_script ('colorpicker-script', plugins_url('color-picker.js', __FILE__), array('wp-color-picker'), false, true);
|
1320 |
-
wp_enqueue_media();
|
1321 |
-
wp_enqueue_script ('media-uploader', plugins_url("media-uploader.js", __FILE__), array('jquery'), false, false);
|
1322 |
}
|
1323 |
|
1324 |
// 管理画面時のスタイルシート、スクリプト設定
|
@@ -1397,20 +1413,20 @@ class Pz_LinkCard {
|
|
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']
|
1401 |
-
$before['mod_title']
|
1402 |
} else {
|
1403 |
-
$before['mod_title']
|
1404 |
}
|
1405 |
-
if ($before['excerpt']
|
1406 |
-
$before['mod_excerpt']
|
1407 |
} else {
|
1408 |
-
$before['mod_excerpt']
|
1409 |
}
|
1410 |
-
$before['alive_result'] =
|
1411 |
-
$before['alive_time'] =
|
1412 |
-
$before['thumbnail'] =
|
1413 |
-
$before['favicon'] =
|
1414 |
$before = $this->pz_SetCache( $before );
|
1415 |
}
|
1416 |
}
|
3 |
Plugin Name: Pz-LinkCard
|
4 |
Plugin URI: http://poporon.poponet.jp/pz-linkcard
|
5 |
Description: リンクをカード形式で表示します。
|
6 |
+
Version: 2.0.0.2
|
7 |
Author: poporon
|
8 |
Author URI: http://poporon.poponet.jp
|
9 |
License: GPLv2 or later
|
134 |
'thumbnail-url' => null,
|
135 |
'plugin-link' => null,
|
136 |
'plugin-name' => 'Pz-LinkCard',
|
137 |
+
'plugin-version' => '2.0.0.2',
|
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 |
}
|
229 |
if (!wp_next_scheduled('pz_linkcard_alive')) {
|
230 |
wp_schedule_event ( time() + 1800 , 'daily', 'pz_linkcard_alive');
|
|
|
231 |
}
|
232 |
}
|
233 |
|
234 |
+
// テキストリンクの行とURLのみの行をリンクカードへ置き換える処理(コードが単純になるので、直接HTMLタグにするのでは無くショートコードに変換する。)
|
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 |
// ショートコード処理
|
246 |
public function shortcode($atts, $content = null, $shortcode) {
|
247 |
// 実行時間
|
248 |
+
if ($this->options['debug-time']) {
|
249 |
$start_time = microtime(true);
|
250 |
}
|
251 |
|
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 |
|
305 |
// キャッシュやリンク先からリンクカードのHTMLを生成
|
306 |
function pz_GetHTML($atts, $content = null) {
|
307 |
+
if ($this->options['debug-time']) {
|
308 |
+
echo '<!-- Pz-LkC [DEBUG INFORMATION] /-->'.PHP_EOL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
309 |
}
|
310 |
|
311 |
// モバイルチェック
|
314 |
} else {
|
315 |
$is_mobile = false;
|
316 |
}
|
317 |
+
if ($this->options['debug-time']) {
|
318 |
+
echo '<!-- Pz-LkC [MOBILE='.$is_mobile.'] /-->'.PHP_EOL;
|
319 |
}
|
320 |
|
321 |
+
// URLエンティティ化など(無害化?)
|
322 |
+
$url = $this->pz_TrimURL( $atts['url'] );
|
323 |
+
if (!isset($url) || $url == '' ) {
|
324 |
+
return null;
|
325 |
+
}
|
326 |
+
if ($this->options['debug-time']) {
|
327 |
+
echo '<!-- Pz-LkC [URL='.$url.'] /-->'.PHP_EOL;
|
|
|
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 (substr($url, 0, mb_strlen(home_url() ) ) == home_url() ) {
|
339 |
if ($this->pz_TrimURL(get_permalink()) == $url) {
|
340 |
$link_type = 1; // 自ページ
|
341 |
} else {
|
344 |
} else {
|
345 |
$link_type = 0; // 外部サイト
|
346 |
}
|
347 |
+
if ($this->options['debug-time']) {
|
348 |
+
echo '<!-- Pz-LkC [TYPE='.$link_type.'] /-->'.PHP_EOL;
|
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 |
$data_id = $data['id'];
|
367 |
$url = $data['url'];
|
368 |
}
|
369 |
+
if ($this->options['debug-time']) {
|
370 |
+
echo '<!-- Pz-LkC [CACHE='.$data_id.'] /-->'.PHP_EOL;
|
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 = ' target="_blank"'; // 新しいページで開く
|
380 |
}
|
381 |
}
|
382 |
+
$nofollow = ''; // 内部サイトにnoflollowは付けない
|
383 |
|
384 |
// キャッシュが無い、もしくは常に最新を取得する、もしくは強制取得
|
385 |
if ( is_null($data_id) || ( isset($atts['force']) && $atts['force'] == true ) ) {
|
386 |
+
if ($this->options['debug-time']) {
|
387 |
+
echo '<!-- Pz-LkC [IN-POST] /-->'.PHP_EOL;
|
388 |
}
|
389 |
+
$data = $this->pz_GetPost( $data ); // 最新記事内容を取得
|
390 |
+
$data['link_type'] = 1;
|
391 |
+
if ($this->options['debug-time']) {
|
392 |
+
echo '<!-- Pz-LkC [IN-SET] /-->'.PHP_EOL;
|
393 |
}
|
394 |
+
$result = $this->pz_SetCache( $data ); // 保存
|
395 |
} elseif ($this->options['in-get'] <> 2) {
|
396 |
+
if ($this->options['debug-time']) {
|
397 |
+
echo '<!-- Pz-LkC [IN-POST] /-->'.PHP_EOL;
|
398 |
}
|
399 |
+
$data = $this->pz_GetPost( $data ); // 最新記事内容を取得
|
400 |
+
$data['link_type'] = 1;
|
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"' : ''; // nofollow指定。趣味の問題?
|
414 |
|
415 |
// キャッシュが無い、もしくは強制取得
|
416 |
if ( is_null($data_id) || ( isset($atts['force']) && $atts['force'] == true ) ) {
|
417 |
+
if ($this->options['debug-time']) {
|
418 |
+
echo '<!-- Pz-LkC [OUT-CURL] /-->'.PHP_EOL;
|
419 |
}
|
420 |
+
$result = $this->pz_GetCURL( $data ); // cURLで記事内容を取得
|
421 |
if ( isset($result) && is_array($result) && isset($result['url']) ) {
|
422 |
$data = $result;
|
423 |
$data['link_type'] = 0;
|
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 |
} 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') { // WebAPIを利用
|
497 |
// 画像取得(WebAPI)
|
498 |
if (isset($this->options['thumbnail-api'])) {
|
499 |
$thumbnail = preg_replace('/%DOMAIN_URL%/', $domain_url, $this->options['thumbnail-api'] );
|
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') { // WebAPIを利用
|
519 |
// サイトアイコン取得(WebAPI)
|
520 |
if (isset($this->options['favicon-api'])) {
|
521 |
$favicon = preg_replace('/%DOMAIN_URL%/', $domain_url, $this->options['favicon-api'] );
|
526 |
}
|
527 |
}
|
528 |
|
|
|
|
|
529 |
// タイトル
|
530 |
if (!isset($title) || $title == '') {
|
531 |
$title = esc_html($url); // タイトル取得できていなかったらURLをセットする
|
556 |
$title = $str;
|
557 |
}
|
558 |
|
559 |
+
// 抜粋文整形(抜粋文非表示の場合、空欄にする)
|
|
|
560 |
if (!isset($this->options['display-excerpt']) || is_null($this->options['display-excerpt'])) {
|
561 |
$excerpt = '';
|
562 |
} else {
|
585 |
// 日本語ドメイン対応
|
586 |
if (isset($this->options['flg-idn']) ? true : false) {
|
587 |
if (function_exists('idn_to_utf8')) {
|
588 |
+
if (substr( $domain, 0, 4 ) == 'xn--') {
|
589 |
+
$site_name = idn_to_utf8( $domain );
|
590 |
}
|
591 |
}
|
592 |
}
|
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 |
$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 |
$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 |
}
|
651 |
}
|
652 |
$sns .= '</span>';
|
|
|
653 |
if ($this->options['sns-position'] == '1') {
|
654 |
$sns_title = $sns;
|
655 |
} else {
|
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( $domain, 0, 4 ) == 'xn--') {
|
672 |
+
$url = $scheme.'://'.idn_to_utf8( $domain ).$location;
|
|
|
|
|
673 |
}
|
674 |
}
|
675 |
}
|
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) && (preg_match('{/amp/?$}i', $_SERVER["REQUEST_URI"]) || (function_exists('is_amp_endpoint') && is_amp_endpoint()) ) ) {
|
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 |
return $tag;
|
706 |
}
|
707 |
|
708 |
+
// URLのエンティティ化など(無害化?)
|
709 |
function pz_TrimURL($url = null) {
|
710 |
if (!isset($url) || $url == '') {
|
711 |
$url = null;
|
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 |
}
|
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 |
if (is_wp_error($data)) {
|
854 |
return null;
|
855 |
}
|
856 |
+
return (array) $data; // Arrayに直して返す
|
857 |
}
|
858 |
|
859 |
// キャッシュデータを保存
|
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 |
$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 |
// サイト名取得
|
959 |
$site_name = get_bloginfo('name');
|
960 |
|
961 |
+
// URLパース(ドメイン名などを抽出)
|
962 |
+
$url_m = parse_url( $url );
|
963 |
+
$scheme = $url_m['scheme']; // スキーム
|
964 |
+
$domain = $url_m['host']; // ドメイン名
|
965 |
+
$domain_url = $scheme.'://'.$url_m['host']; // ドメインURL
|
966 |
+
$location = substr($url, mb_strlen($domain_url)); // ドメイン名以降
|
|
|
|
|
967 |
|
968 |
// サイトアイコン
|
969 |
if (function_exists('has_site_icon') && has_site_icon()) {
|
970 |
+
$favicon = get_site_icon_url(16, '', 0);
|
971 |
} else {
|
972 |
+
$favicon = null;
|
973 |
}
|
974 |
|
975 |
+
$title = null;
|
976 |
+
$excerpt = null;
|
977 |
+
$thumbnail = null;
|
978 |
|
979 |
// 記事内容
|
980 |
+
$post_id = url_to_postid( $data['url'] ); // 記事IDを取得
|
981 |
+
if ($this->options['debug-time']) {
|
982 |
+
echo '<!-- Pz-LkC [PID='.$use_post_id1.'] /-->'.PHP_EOL;
|
983 |
}
|
984 |
+
if ( $use_post_id1 ) {
|
985 |
+
$result_code = 200; // 外部取得と同じコードをセット
|
986 |
+
$post = get_post($post_id); // 記事情報
|
987 |
if ( $this->options['in-get'] ) {
|
988 |
+
$title = $post->post_title; // 記事タイトル
|
989 |
+
$excerpt = $post->post_content; // 記事内容から抜粋
|
990 |
} else {
|
991 |
+
$title = $post->post_title; // 記事タイトル
|
992 |
+
$excerpt = $post->post_excerpt; // 抜粋文優先
|
993 |
if ($excerpt == '') {
|
994 |
+
$excerpt = $post->post_content; // 抜粋文が無かったら記事
|
995 |
}
|
996 |
}
|
997 |
$thumbnail_id = get_post_thumbnail_id( $post_id ); // サムネイル
|
998 |
+
if ($this->options['debug-time']) {
|
999 |
+
echo '<!-- Pz-LkC [TID='.$thumbnail_id.'] /-->'.PHP_EOL;
|
1000 |
}
|
1001 |
$attach = wp_get_attachment_image_src( $thumbnail_id, 'thumbnail', true );
|
1002 |
if (isset($attach) && count($attach) > 3 && isset($attach[0])) {
|
1004 |
}
|
1005 |
} else {
|
1006 |
// カテゴリページ等は内部取得できないので外部取得する
|
1007 |
+
//if ($this->options['debug-time']) {
|
1008 |
+
// echo '<!-- Pz-LkC [IN-CURL] /-->'.PHP_EOL;
|
1009 |
//}
|
1010 |
//$data = $this->pz_GetCURL( $data );
|
1011 |
//$title = $data['title'];
|
1044 |
}
|
1045 |
|
1046 |
// データセット
|
1047 |
+
if ($data['title'] == $title ) {
|
1048 |
+
$before['mod_title'] = 0;
|
1049 |
} else {
|
1050 |
+
$before['mod_title'] = 1;
|
1051 |
}
|
1052 |
+
if ($data['excerpt'] == $excerpt ) {
|
1053 |
+
$before['mod_excerpt'] = 0;
|
1054 |
} else {
|
1055 |
+
$before['mod_excerpt'] = 1;
|
1056 |
+
}
|
1057 |
+
if (empty($data['use_post_id1'])) {
|
1058 |
+
$data['use_post_id1'] = get_the_ID();
|
1059 |
+
}
|
1060 |
+
$data['scheme'] = $scheme;
|
1061 |
+
$data['domain'] = $domain;
|
1062 |
+
$data['location'] = $location;
|
1063 |
+
$data['site_name'] = $site_name;
|
1064 |
+
$data['title'] = $title;
|
1065 |
+
$data['excerpt'] = $excerpt;
|
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 |
$charset = null;
|
1091 |
$result_code = null;
|
1092 |
|
1093 |
+
// URLパース(ドメイン名などを抽出)
|
1094 |
+
$url_m = parse_url( $url );
|
1095 |
+
$scheme = $url_m['scheme']; // スキーム
|
1096 |
+
$domain = $url_m['host']; // ドメイン名
|
1097 |
+
$domain_url = $scheme.'://'.$url_m['host']; // ドメインURL
|
1098 |
+
$location = substr($url, mb_strlen($domain_url)); // ドメイン名以降
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1099 |
|
1100 |
if ( function_exists( 'curl_init' ) ) { // cURLを使用する
|
1101 |
$result_code = 0;
|
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'] ); // ユーザーエージェントにPz-LinkCard-Crawlerを使う
|
|
|
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 |
} else {
|
1118 |
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, false ); // リダイレクトを処理しない
|
1119 |
}
|
1120 |
+
curl_setopt( $ch, CURLOPT_COOKIESESSION, true ); // セッションCOOKIEを使用する
|
1121 |
+
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, (isset($this->options['flg-ssl']) ? false : true) ); // SSL検証
|
1122 |
$html = curl_exec($ch);
|
1123 |
+
$errno = intval( curl_errno( $ch ) ); // cURL実行
|
1124 |
if ( $errno ) {
|
1125 |
+
$html = ''; // cURLエラー
|
1126 |
+
$result_code = $errno;
|
1127 |
+
$error = true;
|
1128 |
} else {
|
1129 |
+
$header = curl_getinfo($ch);
|
1130 |
+
$result_code = $header['http_code']; // HTTPステータス
|
1131 |
+
$error = false;
|
1132 |
}
|
1133 |
curl_close($ch);
|
1134 |
+
} else { // cURLが使用できない場合
|
1135 |
+
$result = wp_remote_get( $url ); //wp_remote_get実行
|
1136 |
if ( is_wp_error( $result ) ) {
|
1137 |
+
$html = '';
|
1138 |
+
$result_code = -1; // wp_remote_getエラー
|
1139 |
+
$error = true;
|
1140 |
} else {
|
1141 |
+
$html = $result['body'];
|
1142 |
+
$result_code = $result['response']['code']; // HTTPステータス
|
1143 |
+
$error = false;
|
1144 |
}
|
1145 |
}
|
1146 |
|
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 |
break;
|
1159 |
}
|
1160 |
}
|
1161 |
+
// $charset = mb_detect_encoding( $html ); // PHPに判定をまかせたい人向け
|
1162 |
}
|
1163 |
if (is_null($charset)) {
|
1164 |
$charset = 'auto';
|
1167 |
$html = mb_convert_encoding($html, $this->charset, $charset);
|
1168 |
}
|
1169 |
|
1170 |
+
// HEADタグ(METAタグ解析)
|
1171 |
$head = null;
|
1172 |
$tags = null;
|
1173 |
if (preg_match('/<\s*head\s*[^>]*>(.*)<\s*\/head\s*>/si', $html, $m)) {
|
1232 |
if (isset($url_key) && !is_null($url_key)) {
|
1233 |
$data['url_key'] = $url_key;
|
1234 |
}
|
1235 |
+
$data['site_name'] = $site_name;
|
1236 |
+
$data['title'] = $title;
|
1237 |
+
$data['excerpt'] = $excerpt;
|
1238 |
+
$data['mod_title'] = 0;
|
1239 |
+
$data['mod_excerpt'] = 0;
|
1240 |
+
$data['charset'] = $charset;
|
1241 |
+
// if (isset($atts['force']) && $atts['force'] == true) {
|
1242 |
+
// $data['regist'] = $this->now_mysql; // 登録日
|
1243 |
+
// }
|
1244 |
+
}
|
1245 |
+
$data['url'] = $url;
|
1246 |
+
$data['thumbnail'] = ( isset($thumbnail_url) ? $thumbnail_url : null );
|
1247 |
+
$data['result_code'] = $result_code;
|
1248 |
+
$data['alive_result'] = $result_code;
|
1249 |
+
$data['scheme'] = $scheme;
|
1250 |
+
$data['domain'] = $domain;
|
1251 |
+
$data['location'] = $location;
|
1252 |
+
$data['favicon'] = ( isset($favicon_url) ? $favicon_url : null );
|
1253 |
+
if (empty($data['use_post_id1'])) {
|
1254 |
+
$data['use_post_id1'] = get_the_ID();
|
1255 |
+
}
|
1256 |
+
$data['sns_twitter'] = (isset( $data['sns_twitter'] ) ? $data['sns_twitter'] : -1 );
|
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 |
|
1333 |
public function enqueue_admin($hook) {
|
1334 |
wp_enqueue_style ('wp-color-picker');
|
1335 |
wp_enqueue_script ('colorpicker-script', plugins_url('color-picker.js', __FILE__), array('wp-color-picker'), false, true);
|
1336 |
+
// wp_enqueue_media();
|
1337 |
+
// wp_enqueue_script ('media-uploader', plugins_url("media-uploader.js", __FILE__), array('jquery'), false, false);
|
1338 |
}
|
1339 |
|
1340 |
// 管理画面時のスタイルシート、スクリプト設定
|
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'] == $after['title'] ) {
|
1417 |
+
$before['mod_title'] = 0;
|
1418 |
} else {
|
1419 |
+
$before['mod_title'] = 1;
|
1420 |
}
|
1421 |
+
if ($before['excerpt'] == $after['excerpt'] ) {
|
1422 |
+
$before['mod_excerpt'] = 0;
|
1423 |
} else {
|
1424 |
+
$before['mod_excerpt'] = 1;
|
1425 |
}
|
1426 |
+
$before['alive_result'] = $after['result_code'];
|
1427 |
+
$before['alive_time'] = $this->now;
|
1428 |
+
$before['thumbnail'] = $after['thumbnail'];
|
1429 |
+
$before['favicon'] = $after['favicon'];
|
1430 |
$before = $this->pz_SetCache( $before );
|
1431 |
}
|
1432 |
}
|
readme.txt
CHANGED
@@ -155,6 +155,10 @@ A5.
|
|
155 |
5. "Write shortcode and url"
|
156 |
|
157 |
== Changelog ==
|
|
|
|
|
|
|
|
|
158 |
Ver2.0.0.1
|
159 |
* idn_to_utf8()が実装されていない環境でエラーが出ていたので対応しました。
|
160 |
Fixed: Fixed a bug.
|
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.
|