Version Description
- Fixed: debug.
*
Download this release
Release Info
Developer | poporon |
Plugin | Pz-LinkCard |
Version | 1.7.1 |
Comparing to | |
See all releases |
Code changes from version 1.7.0 to 1.7.1
- pz-linkcard-cacheman.php +8 -5
- pz-linkcard.php +360 -334
- readme.txt +7 -2
- uninstall.php +4 -0
pz-linkcard-cacheman.php
CHANGED
@@ -1,5 +1,5 @@
|
|
|
|
1 |
<?php
|
2 |
-
if (!function_exists('get_option')) die;
|
3 |
if (!is_user_logged_in()) die;
|
4 |
|
5 |
echo '<div class="wrap">';
|
@@ -37,6 +37,7 @@ $link_type = isset($_REQUEST['link_type'] ) ? $_REQUEST['link_type'] : null;
|
|
37 |
$cache_id = isset($_REQUEST['cache_id'] ) ? $_REQUEST['cache_id'] : null;
|
38 |
$confirm = isset($_REQUEST['confirm'] ) ? $_REQUEST['confirm'] : null;
|
39 |
$result_code = isset($_REQUEST['result_code'] ) ? $_REQUEST['result_code'] : null;
|
|
|
40 |
$paged = (isset($_REQUEST['paged'] ) ? $_REQUEST['paged'] : 1) - 0;
|
41 |
|
42 |
|
@@ -86,14 +87,16 @@ if (isset($action)) {
|
|
86 |
break;
|
87 |
case 'renew':
|
88 |
if (isset($bulk_id) && is_array($bulk_id)) {
|
89 |
-
echo '<div class="updated fade"><p><strong>'.__('Cache renew', $this->text_domain).'
|
90 |
foreach ($bulk_id as $data_id) {
|
|
|
91 |
$data = $this->pz_GetCache(array('id' => $data_id));
|
92 |
if (isset($data) && is_array($data)) {
|
93 |
-
$this->
|
|
|
94 |
}
|
95 |
-
echo '..';
|
96 |
}
|
|
|
97 |
echo __('completed', $this->text_domain).'</strong></p></div>';
|
98 |
}
|
99 |
break;
|
@@ -281,7 +284,7 @@ echo '</div>';
|
|
281 |
<th class="hb" style="width: 2em;"><?php echo_THC('sns_hatena', __('B!', $this->text_domain) ); ?></th>
|
282 |
<th class="regist" style="width: 5em;"><?php echo_THC('regist', __('Regist', $this->text_domain) ); ?></th>
|
283 |
<th class="postid" style="width: 3em;"><?php echo_THC('post_id', __('Post ID', $this->text_domain) ); ?></th>
|
284 |
-
<th class="result" style="width: 2em;"><?php echo_THC('result_code', __('Result code', $this->text_domain) ); ?></th>
|
285 |
</tr>
|
286 |
</thead>
|
287 |
<tbody>
|
1 |
+
<?php if (!function_exists("get_option")) die; ?>
|
2 |
<?php
|
|
|
3 |
if (!is_user_logged_in()) die;
|
4 |
|
5 |
echo '<div class="wrap">';
|
37 |
$cache_id = isset($_REQUEST['cache_id'] ) ? $_REQUEST['cache_id'] : null;
|
38 |
$confirm = isset($_REQUEST['confirm'] ) ? $_REQUEST['confirm'] : null;
|
39 |
$result_code = isset($_REQUEST['result_code'] ) ? $_REQUEST['result_code'] : null;
|
40 |
+
$alive_result = isset($_REQUEST['alive_result'] ) ? $_REQUEST['alive_result'] : null;
|
41 |
$paged = (isset($_REQUEST['paged'] ) ? $_REQUEST['paged'] : 1) - 0;
|
42 |
|
43 |
|
87 |
break;
|
88 |
case 'renew':
|
89 |
if (isset($bulk_id) && is_array($bulk_id)) {
|
90 |
+
echo '<div class="updated fade"><p><strong>'.__('Cache renew', $this->text_domain).'..';
|
91 |
foreach ($bulk_id as $data_id) {
|
92 |
+
echo '.('.$data_id.').';
|
93 |
$data = $this->pz_GetCache(array('id' => $data_id));
|
94 |
if (isset($data) && is_array($data)) {
|
95 |
+
$data = $this->pz_GetHTML( array('url' => $data['url'], 'force' => true ) );
|
96 |
+
$data = $this->pz_SetCache( $data );
|
97 |
}
|
|
|
98 |
}
|
99 |
+
echo '..';
|
100 |
echo __('completed', $this->text_domain).'</strong></p></div>';
|
101 |
}
|
102 |
break;
|
284 |
<th class="hb" style="width: 2em;"><?php echo_THC('sns_hatena', __('B!', $this->text_domain) ); ?></th>
|
285 |
<th class="regist" style="width: 5em;"><?php echo_THC('regist', __('Regist', $this->text_domain) ); ?></th>
|
286 |
<th class="postid" style="width: 3em;"><?php echo_THC('post_id', __('Post ID', $this->text_domain) ); ?></th>
|
287 |
+
<th class="result" style="width: 2em;"><?php echo_THC('result_code', __('Result code', $this->text_domain) ); ?><br><?php echo_THC('alive_result', __('(last)', $this->text_domain) ); ?></th>
|
288 |
</tr>
|
289 |
</thead>
|
290 |
<tbody>
|
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: 1.7.
|
7 |
Author: poporon
|
8 |
Author URI: http://poporon.poponet.jp
|
9 |
License: GPLv2 or later
|
@@ -83,7 +83,7 @@ class Pz_LinkCard {
|
|
83 |
'th-info' => null,
|
84 |
'in-target' => null,
|
85 |
'ex-target' => '2',
|
86 |
-
'ex-thumbnail' => '
|
87 |
'in-thumbnail' => '1',
|
88 |
'ex-favicon' => '3',
|
89 |
'in-favicon' => '1',
|
@@ -94,7 +94,7 @@ class Pz_LinkCard {
|
|
94 |
'thumbnail-resize' => '1',
|
95 |
'cache-time' => 31536000,
|
96 |
'flg-alive' => null,
|
97 |
-
'flg-ssl' =>
|
98 |
'style-reset-img' => '1',
|
99 |
'style' => null,
|
100 |
'css-file' => null,
|
@@ -112,7 +112,7 @@ class Pz_LinkCard {
|
|
112 |
'presence' => null,
|
113 |
'plugin-link' => null,
|
114 |
'plugin-name' => 'Pz-LinkCard',
|
115 |
-
'plugin-version' => '1.7.
|
116 |
'plugin-url' => 'http://poporon.poponet.jp/pz-linkcard',
|
117 |
'pz-hbc-options' => null,
|
118 |
'debug-time' => null
|
@@ -129,13 +129,18 @@ class Pz_LinkCard {
|
|
129 |
$this->plugin_dir_url = plugin_dir_url (__FILE__);
|
130 |
|
131 |
$this->options = get_option('Pz_LinkCard_options', $this->defaults );
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
// DB
|
134 |
global $wpdb;
|
135 |
$this->db_name = $wpdb->prefix.'pz_linkcard';
|
136 |
|
137 |
-
//
|
138 |
-
if ($this->options['plugin-version']
|
139 |
$this->activation();
|
140 |
}
|
141 |
|
@@ -180,16 +185,27 @@ class Pz_LinkCard {
|
|
180 |
}
|
181 |
add_action('wp_enqueue_scripts', array($this, 'enqueue'));
|
182 |
}
|
183 |
-
|
184 |
-
// if (!wp_next_scheduled('pz_linkcard_check')) {
|
185 |
-
// wp_schedule_event( time(), 'hourly', 'pz_linkcard_check');
|
186 |
-
// wp_schedule_single_event( time() + 10, 'pz_linkcard_check');
|
187 |
-
// }
|
188 |
add_action('pz_linkcard_check', array($this, 'schedule_hook_sns'));
|
189 |
-
// add_action('
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
}
|
191 |
|
|
|
192 |
public function shortcode($atts, $content = null, $shortcode) {
|
|
|
|
|
|
|
|
|
|
|
193 |
// URL
|
194 |
$url = isset($atts['url']) ? $this->pz_TrimURL($atts['url']) : null;
|
195 |
// 密かに記述ミス対応(URIでもUR1でもURLとして判定する)
|
@@ -198,8 +214,12 @@ class Pz_LinkCard {
|
|
198 |
if (is_null($url)) {
|
199 |
$url = isset($atts['uri']) ? $this->pz_TrimURL($atts['uri']) : null;
|
200 |
}
|
|
|
201 |
}
|
202 |
-
|
|
|
|
|
|
|
203 |
// パラメータ
|
204 |
$s_title = isset($atts['title']) ? $atts['title'] : null;
|
205 |
if (isset($atts['content'])) {
|
@@ -211,7 +231,7 @@ class Pz_LinkCard {
|
|
211 |
} else {
|
212 |
$s_excerpt = null;
|
213 |
}
|
214 |
-
|
215 |
// 囲まれ文字(ショートコード1のみ有効)
|
216 |
if ($shortcode == $this->options['code1']) {
|
217 |
switch (isset($this->options['use-inline']) ? $this->options['use-inline'] : null) {
|
@@ -223,51 +243,31 @@ class Pz_LinkCard {
|
|
223 |
break;
|
224 |
}
|
225 |
}
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
// URL
|
232 |
-
function pz_TrimURL($url = null) {
|
233 |
-
if (!isset($url) || $url == '') {
|
234 |
-
$url = null;
|
235 |
-
return $url;
|
236 |
-
}
|
237 |
-
|
238 |
-
if (isset($url) && $url <> '') {
|
239 |
-
$url = html_entity_decode($url);
|
240 |
-
$url = preg_replace('/^[\s \'\"‘’“”″]*(.*?)[\s \'\"‘’“”″]*$/u', '\1', $url);
|
241 |
-
$url = strip_tags($url);
|
242 |
-
$url = htmlentities($url);
|
243 |
-
$url = esc_url($url); // プロトコル除外など
|
244 |
-
$array_url = parse_url($url);
|
245 |
-
if ((isset($this->options['trail-slash']) ? $this->options['trail-slash'] : null) && (!isset($array_url['path']) || $array_url['path'] == '/')) {
|
246 |
-
// URLがドメイン名だけの場合、最後のスラッシュを除外する
|
247 |
-
$url = preg_replace('/\/$/u', '', $url);
|
248 |
-
}
|
249 |
-
}
|
250 |
-
return $url;
|
251 |
}
|
252 |
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
|
|
|
|
|
|
266 |
}
|
267 |
-
|
268 |
-
// URLエンコード
|
269 |
-
$url_esc = urlencode($url);
|
270 |
-
|
271 |
// リンク先URLからドメイン名を抽出
|
272 |
if (preg_match('{https?://(.+?)/}i', $url.'/',$m)) {
|
273 |
$domain_url = $m[0];
|
@@ -277,14 +277,14 @@ class Pz_LinkCard {
|
|
277 |
$domain = null;
|
278 |
$error = true;
|
279 |
}
|
280 |
-
|
281 |
// モバイルチェック
|
282 |
if (function_exists('wp_is_mobile') && wp_is_mobile()) {
|
283 |
$is_mobile = true;
|
284 |
} else {
|
285 |
$is_mobile = false;
|
286 |
}
|
287 |
-
|
288 |
// 自サイトチェック
|
289 |
if (preg_match('{'.home_url().'\/.*?}', $url.'/')) {
|
290 |
if (get_permalink() == $url) {
|
@@ -309,40 +309,38 @@ class Pz_LinkCard {
|
|
309 |
}
|
310 |
$nofollow = isset($this->options['nofollow']) ? ' rel="nofollow"' : '';
|
311 |
}
|
312 |
-
|
313 |
-
//
|
314 |
$class_id = 'linkcard';
|
315 |
if ($is_mobile && isset($this->options['class-mobile']) && $this->options['class-mobile'] <> '') {
|
316 |
$class_id .= ' '.$this->options['class-mobile'];
|
317 |
} elseif (isset($this->options['class-pc']) && $this->options['class-pc'] <> '') {
|
318 |
$class_id .= ' '.$this->options['class-pc'];
|
319 |
}
|
320 |
-
|
321 |
-
|
322 |
-
$data
|
323 |
-
$data['
|
324 |
-
$
|
325 |
-
$
|
326 |
-
|
327 |
-
|
328 |
-
$data['
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
// $data['psc_last'] = 0;
|
339 |
-
if (isset($url) && $url) {
|
340 |
-
$data['url'] = $url;
|
341 |
-
$result = $this->pz_GetCache($data);
|
342 |
if (isset($result) && is_array($result) && isset($result['url'])) {
|
343 |
-
$data
|
|
|
344 |
}
|
345 |
}
|
|
|
346 |
$data_id = $data['id'];
|
347 |
$url_key = $data['url_key'];
|
348 |
$site_name = $data['site_name'];
|
@@ -358,200 +356,97 @@ class Pz_LinkCard {
|
|
358 |
$sns_hb = $data['sns_hatena'];
|
359 |
$uptime = $data['uptime'];
|
360 |
$nexttime = $data['nexttime'];
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
$thumbnail = null;
|
365 |
$favicon = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
366 |
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
$
|
376 |
-
|
377 |
-
|
378 |
-
$wrap_op = '<div class="lkc-internal-wrap">';
|
379 |
-
$wrap_cl = '</div>';
|
380 |
-
}
|
381 |
-
$site_name = get_bloginfo('name'); // サイト名
|
382 |
-
$id = url_to_postid($url); // 記事ID
|
383 |
-
if ($id) {
|
384 |
-
$post = get_post($id); // 記事情報
|
385 |
-
} else {
|
386 |
-
$post = null;
|
387 |
-
}
|
388 |
-
|
389 |
-
// タイトル取得
|
390 |
-
if ($id) {
|
391 |
-
switch (isset($this->options['in-get']) ? $this->options['in-get'] : null) {
|
392 |
-
case null:
|
393 |
$title = $post->post_title; // 記事タイトル
|
394 |
$excerpt = $post->post_content; // 記事内容から抜粋
|
395 |
-
|
396 |
-
case '1':
|
397 |
$title = $post->post_title; // 記事タイトル
|
398 |
$excerpt = $post->post_excerpt; // 抜粋文優先
|
399 |
if ($excerpt == '') {
|
400 |
$excerpt = $post->post_content; // 抜粋文が無かったら記事
|
401 |
}
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
406 |
}
|
407 |
} else {
|
408 |
-
$result_code =
|
409 |
if (!$title) {
|
410 |
$title = get_bloginfo('name'); // サイト名
|
411 |
if (!$excerpt) {
|
412 |
$excerpt = get_bloginfo('description'); // サイト概要
|
413 |
}
|
414 |
}
|
|
|
|
|
415 |
}
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
if (function_exists('has_site_icon') && has_site_icon()) {
|
427 |
-
$favicon = '<img class="lkc-favicon" src="'.get_site_icon_url(16, '', 0).'" alt="" />';
|
428 |
-
} else {
|
429 |
-
$sw_favicon = isset($this->options['ex-favicon']) ? $this->options['ex-favicon'] : '0' ;
|
430 |
-
}
|
431 |
-
}
|
432 |
-
|
433 |
-
} else { // 外部サイト
|
434 |
-
$wrap_op = '<div class="lkc-external-wrap">'; // ラッピング
|
435 |
-
$wrap_cl = '</div>';
|
436 |
-
$info = isset($this->options['ex-info']) ? $this->options['ex-info'] : '' ;
|
437 |
-
$sw_thumbnail = isset($this->options['ex-thumbnail']) ? $this->options['ex-thumbnail'] : '0' ;
|
438 |
-
$sw_favicon = isset($this->options['ex-favicon']) ? $this->options['ex-favicon'] : '0' ;
|
439 |
-
|
440 |
-
if (isset($this->options['use-hatena']) && !is_null($this->options['use-hatena'])) {
|
441 |
-
// 「はてなブログカード」をそのまま利用する
|
442 |
-
$tag = '<div class="lkc-iframe-wrap"><iframe src="http://hatenablog.com/embed?url='.$url.'" class="lkc-iframe" scrolling="no" frameborder="0"></iframe></div>';
|
443 |
-
if (isset($this->options['blockquote']) ? $this->options['blockquote'] : null == '1') {
|
444 |
-
$tag = '<div class="'.$class_id.'"><blockquote class="lkc-quote">'.$tag.'</blockquote></div>';
|
445 |
-
} else {
|
446 |
-
$tag = '<div class="'.$class_id.'">'.$tag.'</div>';
|
447 |
-
}
|
448 |
-
return $tag;
|
449 |
-
|
450 |
-
} elseif (is_null($data_id) || (isset($atts['force']) && $atts['force'] == true)) { // キャッシュ無、または前回エラー
|
451 |
-
// リンク先サイト取得
|
452 |
-
$html = null;
|
453 |
-
$error = true;
|
454 |
-
|
455 |
-
if (function_exists('curl_init')) {
|
456 |
-
$ch = curl_init($url);
|
457 |
-
// curl_setopt($ch, CURLOPT_TIMEOUT, 8);
|
458 |
-
curl_setopt($ch, CURLOPT_USERAGENT, esc_html($_SERVER['HTTP_USER_AGENT']));
|
459 |
-
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
460 |
-
curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
|
461 |
-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
462 |
-
if (isset($this->options['flg-ssl']) ? $this->options['flg-ssl'] : null) {
|
463 |
-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // SSL検証なし
|
464 |
-
} else {
|
465 |
-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // SSL検証あり
|
466 |
-
}
|
467 |
-
$html = curl_exec($ch);
|
468 |
-
if (curl_errno($ch)) {
|
469 |
-
$html = '';
|
470 |
-
$result_code = 0 - intval(curl_errno($ch));
|
471 |
-
} else {
|
472 |
-
$header = curl_getinfo($ch);
|
473 |
-
$result_code = $header['http_code'];
|
474 |
-
}
|
475 |
-
curl_close($ch);
|
476 |
-
} else {
|
477 |
-
$result = wp_remote_get($url);
|
478 |
-
if (!is_wp_error($result)) {
|
479 |
-
$html = $result['body'];
|
480 |
-
$result_code = $result['response']['code'];
|
481 |
-
} else {
|
482 |
-
$html = '';
|
483 |
-
$result_code = -1;
|
484 |
-
}
|
485 |
-
}
|
486 |
-
$charset = null;
|
487 |
-
if ($html <> '') {
|
488 |
-
if (preg_match('/charset\s*=\s*([^>\/\s]*).*<\/head/si', $html, $m)) {
|
489 |
-
$m[1] = trim(trim($m[1]), '\'\"');
|
490 |
-
$charset = $m[1];
|
491 |
-
} else {
|
492 |
-
foreach(array('UTF-8','SJIS','EUC-JP','eucJP-win','ASCII','JIS','SJIS-win') as $c_charset) {
|
493 |
-
if (mb_convert_encoding($html, $this->charset, $c_charset) == $html) {
|
494 |
-
$charset = $c_charset;
|
495 |
-
break;
|
496 |
-
}
|
497 |
-
}
|
498 |
-
}
|
499 |
-
if (is_null($charset)) {
|
500 |
-
$charset = 'auto';
|
501 |
-
$html = mb_convert_encoding($html, $this->charset, 'ASCII,JIS,UTF-7,EUC-JP,SJIS,UTF-8');
|
502 |
-
} elseif ($this->charset <> $charset) {
|
503 |
-
$html = mb_convert_encoding($html, $this->charset, $charset);
|
504 |
-
}
|
505 |
-
}
|
506 |
-
|
507 |
-
if ($result_code < 0) {
|
508 |
-
$error = false;
|
509 |
-
$update = true;
|
510 |
-
} else {
|
511 |
-
$error = false;
|
512 |
-
$update = true;
|
513 |
-
|
514 |
-
$tags = null;
|
515 |
-
// HEADタグ
|
516 |
-
$head = null;
|
517 |
-
$tags = null;
|
518 |
-
if (preg_match('/<\s*head\s*[^>]*>(.*)<\s*\/head\s*>/si', $html, $m)) {
|
519 |
-
$head = $m[1];
|
520 |
-
$tags = $this->pz_GetMeta($head);
|
521 |
-
}
|
522 |
-
|
523 |
-
// タイトル
|
524 |
-
if (isset( $tags['og:title'] ) && $tags['og:title'] ) {
|
525 |
-
$title = $tags['og:title'] ;
|
526 |
-
} elseif (isset( $tags['title'] ) && $tags['title'] ) {
|
527 |
-
$title = $tags['title'] ;
|
528 |
-
}
|
529 |
-
|
530 |
-
// 抜粋文・概要文
|
531 |
-
if (isset( $tags['og:description'] ) && $tags['og:description'] ) {
|
532 |
-
$excerpt = $tags['og:description'] ;
|
533 |
-
} elseif (isset( $tags['description'] ) && $tags['description'] ) {
|
534 |
-
$excerpt = $tags['description'] ;
|
535 |
-
}
|
536 |
-
|
537 |
-
// // OGPから画像URL取得
|
538 |
-
// if ($sw_thumbnail == '1' && isset($tags['og:image'])) {
|
539 |
-
// $thumbnail_url = $tags['og:image'];
|
540 |
-
// $thumbnail = '<img class="lkc-thumbnail-img" src="'.$thumbnail_url.'" alt="" />';
|
541 |
-
// }
|
542 |
-
|
543 |
-
// サイト名
|
544 |
-
if (isset( $tags['og:site_name'] ) && $tags['og:site_name'] ) {
|
545 |
-
$site_name = $tags['og:site_name'] ;
|
546 |
-
}
|
547 |
-
|
548 |
-
if ($result_code <> 200) {
|
549 |
-
$title = null;
|
550 |
-
}
|
551 |
-
}
|
552 |
}
|
|
|
553 |
}
|
554 |
-
|
555 |
// タイトル整形
|
556 |
if (isset($title)) {
|
557 |
$str = $title;
|
@@ -561,6 +456,7 @@ class Pz_LinkCard {
|
|
561 |
$str = mb_strimwidth($str, 0, 200, '...'); // 保管用のタイトルは200文字で切る
|
562 |
$title = $str;
|
563 |
}
|
|
|
564 |
// 抜粋文整形
|
565 |
if (isset($excerpt)) {
|
566 |
$str = $excerpt;
|
@@ -572,46 +468,19 @@ class Pz_LinkCard {
|
|
572 |
$str = mb_strimwidth($str, 0, 500, '...'); // 保管用の記事内容は500文字で切る
|
573 |
$excerpt = $str;
|
574 |
}
|
575 |
-
|
576 |
-
//
|
577 |
-
if (
|
578 |
-
|
579 |
-
|
580 |
-
}
|
581 |
-
if (isset($url_key) && !is_null($url_key)) {
|
582 |
-
$data['url_key'] = $url_key;
|
583 |
-
}
|
584 |
-
$data['url'] = $url;
|
585 |
-
$data['link_type'] = $link_type;
|
586 |
-
$data['site_name'] = $site_name;
|
587 |
-
$data['domain'] = $domain;
|
588 |
-
$data['title'] = $title;
|
589 |
-
$data['excerpt'] = $excerpt;
|
590 |
-
$data['charset'] = $charset;
|
591 |
-
$data['thumbnail'] = $thumbnail_url;
|
592 |
-
$data['favicon'] = $favicon_url;
|
593 |
-
$data['result_code'] = $result_code;
|
594 |
-
$data['sns_twitter'] = $sns_tw;
|
595 |
-
$data['sns_facebook'] = $sns_fb;
|
596 |
-
$data['sns_hatena'] = $sns_hb;
|
597 |
-
$data['uptime'] = $uptime;
|
598 |
-
$data['nexttime'] = $nexttime;
|
599 |
-
// $data['psc_code'] = $result_code;
|
600 |
-
// $data['psc_last'] = $uptime;
|
601 |
-
if (isset($atts['force']) && $atts['force'] == true) {
|
602 |
-
$data['regist'] = current_time('mysql'); // 登録日
|
603 |
-
}
|
604 |
-
|
605 |
-
$data = $this->pz_SetCache($data);
|
606 |
-
wp_schedule_single_event(time() + 10, 'pz_linkcard_check');
|
607 |
|
608 |
if (isset($data['id'])) {
|
609 |
-
$update
|
610 |
}
|
611 |
}
|
612 |
|
613 |
// サムネイル取得
|
614 |
-
if (!$this->options['thumbnail-position'] || $
|
615 |
$thumbnail = null;
|
616 |
} else {
|
617 |
if ($sw_thumbnail == '3') {
|
@@ -718,7 +587,7 @@ class Pz_LinkCard {
|
|
718 |
$sns = null;
|
719 |
$sns_info = null;
|
720 |
$sns_title = null;
|
721 |
-
if (
|
722 |
$sns = '<span class="lkc-share">';
|
723 |
if ((isset($this->options['link-all']) ? $this->options['link-all'] : null) == '1') {
|
724 |
if (isset($this->options['sns-tw']) && !is_null($this->options['sns-tw']) && $sns_tw > 0) {
|
@@ -790,7 +659,30 @@ class Pz_LinkCard {
|
|
790 |
return $tag;
|
791 |
}
|
792 |
|
793 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
794 |
if (!isset($this->options['sns-position']) || $this->options['sns-position'] == '') {
|
795 |
return null;
|
796 |
}
|
@@ -897,11 +789,11 @@ class Pz_LinkCard {
|
|
897 |
}
|
898 |
global $wpdb;
|
899 |
if (isset($data['url']) && !is_null($data['url'])) {
|
900 |
-
$url
|
901 |
-
$data
|
902 |
} elseif (isset($data['id']) && !is_null($data['id'])) {
|
903 |
-
$
|
904 |
-
$data
|
905 |
} else {
|
906 |
return null;
|
907 |
}
|
@@ -920,32 +812,21 @@ class Pz_LinkCard {
|
|
920 |
if (!isset($data['url']) || is_null($data['url'])) {
|
921 |
return null;
|
922 |
}
|
923 |
-
$url
|
924 |
-
$data['url']
|
925 |
-
|
926 |
if (!isset($data['url_key']) || is_null($data['url_key']) || $data['url_key'] == '' ) {
|
927 |
-
$data['url_key'] = hash('sha256', esc_url($url), true);
|
928 |
}
|
929 |
-
|
930 |
-
|
931 |
// 更新してみる
|
932 |
-
|
933 |
-
$
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
);
|
940 |
-
} else {
|
941 |
-
$result = $wpdb->update(
|
942 |
-
$this->db_name,
|
943 |
-
$data,
|
944 |
-
array(
|
945 |
-
'url_key' => $data['url_key']
|
946 |
-
)
|
947 |
-
);
|
948 |
-
}
|
949 |
if (!$result) {
|
950 |
$data['regist'] = current_time('mysql'); // 登録日
|
951 |
// 更新できなかったら挿入
|
@@ -1002,6 +883,150 @@ class Pz_LinkCard {
|
|
1002 |
return $tags;
|
1003 |
}
|
1004 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1005 |
// 管理画面時のスタイルシート、スクリプト設定
|
1006 |
public function enqueue_admin($hook) {
|
1007 |
wp_enqueue_style ('wp-color-picker');
|
@@ -1049,34 +1074,33 @@ class Pz_LinkCard {
|
|
1049 |
}
|
1050 |
}
|
1051 |
|
1052 |
-
|
1053 |
// WP-CRONスケジュール(存在チェック)
|
1054 |
public function schedule_hook_alive() {
|
1055 |
if (!isset($this->options['flg-alive']) || $this->options['flg-alive'] == '') {
|
1056 |
return null;
|
1057 |
}
|
1058 |
|
1059 |
-
// result_code
|
1060 |
-
// new_code
|
1061 |
-
|
1062 |
-
// (まだ作ってない)
|
1063 |
global $wpdb;
|
1064 |
$now = current_time('timestamp');
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
$i = 0;
|
1071 |
if (isset($result) && is_array($result) && count($result) > 0) {
|
1072 |
-
foreach($result as $
|
1073 |
$i++;
|
1074 |
-
if ($i >
|
1075 |
-
|
1076 |
break;
|
1077 |
}
|
1078 |
-
if (isset($
|
1079 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
1080 |
}
|
1081 |
}
|
1082 |
}
|
@@ -1132,6 +1156,8 @@ class Pz_LinkCard {
|
|
1132 |
sns_twitter INT ,
|
1133 |
sns_facebook INT ,
|
1134 |
sns_hatena INT ,
|
|
|
|
|
1135 |
uptime BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
1136 |
nexttime BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
1137 |
regist DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
|
3 |
Plugin Name: Pz-LinkCard
|
4 |
Plugin URI: http://poporon.poponet.jp/pz-linkcard
|
5 |
Description: リンクをカード形式で表示します。
|
6 |
+
Version: 1.7.1
|
7 |
Author: poporon
|
8 |
Author URI: http://poporon.poponet.jp
|
9 |
License: GPLv2 or later
|
83 |
'th-info' => null,
|
84 |
'in-target' => null,
|
85 |
'ex-target' => '2',
|
86 |
+
'ex-thumbnail' => '3',
|
87 |
'in-thumbnail' => '1',
|
88 |
'ex-favicon' => '3',
|
89 |
'in-favicon' => '1',
|
94 |
'thumbnail-resize' => '1',
|
95 |
'cache-time' => 31536000,
|
96 |
'flg-alive' => null,
|
97 |
+
'flg-ssl' => '1',
|
98 |
'style-reset-img' => '1',
|
99 |
'style' => null,
|
100 |
'css-file' => null,
|
112 |
'presence' => null,
|
113 |
'plugin-link' => null,
|
114 |
'plugin-name' => 'Pz-LinkCard',
|
115 |
+
'plugin-version' => '1.7.1',
|
116 |
'plugin-url' => 'http://poporon.poponet.jp/pz-linkcard',
|
117 |
'pz-hbc-options' => null,
|
118 |
'debug-time' => null
|
129 |
$this->plugin_dir_url = plugin_dir_url (__FILE__);
|
130 |
|
131 |
$this->options = get_option('Pz_LinkCard_options', $this->defaults );
|
132 |
+
foreach ($this->defaults as $key => $value) {
|
133 |
+
if (!isset($this->options[$key])) {
|
134 |
+
$this->options[$key] = null;
|
135 |
+
}
|
136 |
+
}
|
137 |
|
138 |
// DB
|
139 |
global $wpdb;
|
140 |
$this->db_name = $wpdb->prefix.'pz_linkcard';
|
141 |
|
142 |
+
// バージョンが違っていたら、DBとオプションを更新する
|
143 |
+
if ($this->options['plugin-version'] <> $this->defaults['plugin-version']) {
|
144 |
$this->activation();
|
145 |
}
|
146 |
|
185 |
}
|
186 |
add_action('wp_enqueue_scripts', array($this, 'enqueue'));
|
187 |
}
|
188 |
+
|
|
|
|
|
|
|
|
|
189 |
add_action('pz_linkcard_check', array($this, 'schedule_hook_sns'));
|
190 |
+
// add_action('pz_linkcard_alive', array($this, 'schedule_hook_alive'));
|
191 |
+
|
192 |
+
if (!wp_next_scheduled('pz_linkcard_check')) {
|
193 |
+
wp_schedule_event( time(), 'hourly', 'pz_linkcard_check');
|
194 |
+
wp_schedule_single_event( time() + 15, 'pz_linkcard_check');
|
195 |
+
}
|
196 |
+
// if (!wp_next_scheduled('pz_linkcard_alive')) {
|
197 |
+
// wp_schedule_event( time(), 'hourly', 'pz_linkcard_alive');
|
198 |
+
// wp_schedule_single_event( time() + 10, 'pz_linkcard_alive');
|
199 |
+
// }
|
200 |
}
|
201 |
|
202 |
+
// ショートコード処理
|
203 |
public function shortcode($atts, $content = null, $shortcode) {
|
204 |
+
// 時間計測
|
205 |
+
if (is_user_logged_in()) {
|
206 |
+
$start_time = microtime(true);
|
207 |
+
}
|
208 |
+
|
209 |
// URL
|
210 |
$url = isset($atts['url']) ? $this->pz_TrimURL($atts['url']) : null;
|
211 |
// 密かに記述ミス対応(URIでもUR1でもURLとして判定する)
|
214 |
if (is_null($url)) {
|
215 |
$url = isset($atts['uri']) ? $this->pz_TrimURL($atts['uri']) : null;
|
216 |
}
|
217 |
+
$atts['url'] = $url;
|
218 |
}
|
219 |
+
if (is_null($url)) {
|
220 |
+
return 'Pz-LinkCard: URLの指定が誤っています';
|
221 |
+
}
|
222 |
+
|
223 |
// パラメータ
|
224 |
$s_title = isset($atts['title']) ? $atts['title'] : null;
|
225 |
if (isset($atts['content'])) {
|
231 |
} else {
|
232 |
$s_excerpt = null;
|
233 |
}
|
234 |
+
|
235 |
// 囲まれ文字(ショートコード1のみ有効)
|
236 |
if ($shortcode == $this->options['code1']) {
|
237 |
switch (isset($this->options['use-inline']) ? $this->options['use-inline'] : null) {
|
243 |
break;
|
244 |
}
|
245 |
}
|
246 |
+
|
247 |
+
// 記事内容取得
|
248 |
+
$data = $this->pz_GetHTML ( $atts );
|
249 |
+
|
250 |
+
return $data;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
}
|
252 |
|
253 |
+
// $data['domain'] = $domain;
|
254 |
+
// $data['thumbnail'] = $thumbnail_url;
|
255 |
+
// $data['favicon'] = $favicon_url;
|
256 |
+
// $data['sns_twitter'] = $sns_tw;
|
257 |
+
// $data['sns_facebook'] = $sns_fb;
|
258 |
+
// $data['sns_hatena'] = $sns_hb;
|
259 |
+
// $data['uptime'] = $uptime;
|
260 |
+
// $data['nexttime'] = $nexttime;
|
261 |
+
// $data['alive_time'] = $alive_time;
|
262 |
+
// $data['alive_result'] = $alive_result;
|
263 |
+
|
264 |
+
|
265 |
+
function pz_GetHTML($atts, $content = null) {
|
266 |
+
$url = $this->pz_TrimURL( $atts['url'] );
|
267 |
+
if (!isset($url) || $url == '' ) {
|
268 |
+
return null;
|
269 |
}
|
270 |
+
|
|
|
|
|
|
|
271 |
// リンク先URLからドメイン名を抽出
|
272 |
if (preg_match('{https?://(.+?)/}i', $url.'/',$m)) {
|
273 |
$domain_url = $m[0];
|
277 |
$domain = null;
|
278 |
$error = true;
|
279 |
}
|
280 |
+
|
281 |
// モバイルチェック
|
282 |
if (function_exists('wp_is_mobile') && wp_is_mobile()) {
|
283 |
$is_mobile = true;
|
284 |
} else {
|
285 |
$is_mobile = false;
|
286 |
}
|
287 |
+
|
288 |
// 自サイトチェック
|
289 |
if (preg_match('{'.home_url().'\/.*?}', $url.'/')) {
|
290 |
if (get_permalink() == $url) {
|
309 |
}
|
310 |
$nofollow = isset($this->options['nofollow']) ? ' rel="nofollow"' : '';
|
311 |
}
|
312 |
+
|
313 |
+
// モバイルかPCかのクラス名を追加
|
314 |
$class_id = 'linkcard';
|
315 |
if ($is_mobile && isset($this->options['class-mobile']) && $this->options['class-mobile'] <> '') {
|
316 |
$class_id .= ' '.$this->options['class-mobile'];
|
317 |
} elseif (isset($this->options['class-pc']) && $this->options['class-pc'] <> '') {
|
318 |
$class_id .= ' '.$this->options['class-pc'];
|
319 |
}
|
320 |
+
|
321 |
+
$update = false;
|
322 |
+
$data = array();
|
323 |
+
$data['url'] = $url;
|
324 |
+
$result = $this->pz_GetCache( $data );
|
325 |
+
if (isset($result) && is_array($result) && isset($result['url'])) {
|
326 |
+
$data = $result;
|
327 |
+
if (isset($atts['force']) && $atts['force'] == true) {
|
328 |
+
$data_id = $data['id'];
|
329 |
+
$result = $this->pz_GetCURL( $data );
|
330 |
+
if (isset($result) && is_array($result) && isset($result['url'])) {
|
331 |
+
$data = $result;
|
332 |
+
$data['id'] = $data_id;
|
333 |
+
$update = true;
|
334 |
+
}
|
335 |
+
}
|
336 |
+
} else {
|
337 |
+
$result = $this->pz_GetCURL( $data );
|
|
|
|
|
|
|
|
|
338 |
if (isset($result) && is_array($result) && isset($result['url'])) {
|
339 |
+
$data = $result;
|
340 |
+
$update = true;
|
341 |
}
|
342 |
}
|
343 |
+
|
344 |
$data_id = $data['id'];
|
345 |
$url_key = $data['url_key'];
|
346 |
$site_name = $data['site_name'];
|
356 |
$sns_hb = $data['sns_hatena'];
|
357 |
$uptime = $data['uptime'];
|
358 |
$nexttime = $data['nexttime'];
|
359 |
+
$alive_time = $data['alive_time'];
|
360 |
+
$alive_result = $data['alive_result'];
|
361 |
+
|
362 |
$thumbnail = null;
|
363 |
$favicon = null;
|
364 |
+
|
365 |
+
// ラッピング
|
366 |
+
switch ($link_type) {
|
367 |
+
case '1':
|
368 |
+
$wrap_op = '<div class="lkc-this-wrap">';
|
369 |
+
$wrap_cl = '</div>';
|
370 |
+
$info = isset($this->options['th-info']) ? $this->options['th-info'] : '' ;
|
371 |
+
$sw_thumbnail = isset($this->options['th-thumbnail']) ? $this->options['th-thumbnail'] : '0' ;
|
372 |
+
$sw_favicon = isset($this->options['th-favicon']) ? $this->options['th-favicon'] : '0' ;
|
373 |
+
break;
|
374 |
+
case '2':
|
375 |
+
$wrap_op = '<div class="lkc-internal-wrap">';
|
376 |
+
$wrap_cl = '</div>';
|
377 |
+
$info = isset($this->options['in-info']) ? $this->options['in-info'] : '' ;
|
378 |
+
$sw_thumbnail = isset($this->options['in-thumbnail']) ? $this->options['in-thumbnail'] : '0' ;
|
379 |
+
$sw_favicon = isset($this->options['in-favicon']) ? $this->options['in-favicon'] : '0' ;
|
380 |
+
break;
|
381 |
+
default:
|
382 |
+
$wrap_op = '<div class="lkc-external-wrap">';
|
383 |
+
$wrap_cl = '</div>';
|
384 |
+
$info = isset($this->options['ex-info']) ? $this->options['ex-info'] : '' ;
|
385 |
+
$sw_thumbnail = isset($this->options['ex-thumbnail']) ? $this->options['ex-thumbnail'] : '0' ;
|
386 |
+
$sw_favicon = isset($this->options['ex-favicon']) ? $this->options['ex-favicon'] : '0' ;
|
387 |
+
break;
|
388 |
+
}
|
389 |
|
390 |
+
// 内部リンクかつ、キャッシュが無いもしくは内部リンクは最新優先の場合
|
391 |
+
if ( $link_type && ( is_null($data_id) || $this->options['in-get'] <> 2 ) ) {
|
392 |
+
$site_name = get_bloginfo('name'); // サイト名
|
393 |
+
$post_id = url_to_postid($url); // 記事ID
|
394 |
+
if ($post_id) {
|
395 |
+
if (is_null($data_id)) {
|
396 |
+
$update = true;
|
397 |
+
}
|
398 |
+
$result_code = 200; // 外部取得と同じコードをセット
|
399 |
+
$post = get_post($post_id); // 記事情報
|
400 |
+
if ( $this->options['in-get'] ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
401 |
$title = $post->post_title; // 記事タイトル
|
402 |
$excerpt = $post->post_content; // 記事内容から抜粋
|
403 |
+
} else {
|
|
|
404 |
$title = $post->post_title; // 記事タイトル
|
405 |
$excerpt = $post->post_excerpt; // 抜粋文優先
|
406 |
if ($excerpt == '') {
|
407 |
$excerpt = $post->post_content; // 抜粋文が無かったら記事
|
408 |
}
|
409 |
+
}
|
410 |
+
$sw_thumbnail = isset($this->options['in-thumbnail']) ? $this->options['in-thumbnail'] : '0' ;
|
411 |
+
if ($sw_thumbnail == '1' || $sw_thumbnail == '13') {
|
412 |
+
$thumbnail = get_the_post_thumbnail($post_id, 'thumbnail' , array('class' => 'lkc-thumbnail-img'));
|
413 |
+
if ($sw_thumbnail == '13' && $thumbnail == '') {
|
414 |
+
$sw_thumbnail = '3';
|
415 |
+
}
|
416 |
+
}
|
417 |
+
$sw_favicon = isset($this->options['in-favicon']) ? $this->options['in-favicon'] : '0' ;
|
418 |
+
if ($sw_favicon == '1') {
|
419 |
+
if (function_exists('has_site_icon') && has_site_icon()) {
|
420 |
+
$favicon = '<img class="lkc-favicon" src="'.get_site_icon_url(16, '', 0).'" alt="" />';
|
421 |
+
} else {
|
422 |
+
$sw_favicon = isset($this->options['ex-favicon']) ? $this->options['ex-favicon'] : '0' ;
|
423 |
+
}
|
424 |
}
|
425 |
} else {
|
426 |
+
$result_code = 404; // 404 Not Found
|
427 |
if (!$title) {
|
428 |
$title = get_bloginfo('name'); // サイト名
|
429 |
if (!$excerpt) {
|
430 |
$excerpt = get_bloginfo('description'); // サイト概要
|
431 |
}
|
432 |
}
|
433 |
+
$sw_thumbnail = 0;
|
434 |
+
$sw_favicon = 0;
|
435 |
}
|
436 |
+
}
|
437 |
+
|
438 |
+
// 外部リンクの処理
|
439 |
+
if ( !$link_type && isset($this->options['use-hatena']) && !is_null($this->options['use-hatena'] ) ) {
|
440 |
+
// 「はてなブログカード」をそのまま利用する
|
441 |
+
$tag = '<div class="lkc-iframe-wrap"><iframe src="http://hatenablog.com/embed?url='.$url.'" class="lkc-iframe" scrolling="no" frameborder="0"></iframe></div>';
|
442 |
+
if (isset($this->options['blockquote']) ? $this->options['blockquote'] : null == '1') {
|
443 |
+
$tag = '<div class="'.$class_id.'"><blockquote class="lkc-quote">'.$tag.'</blockquote></div>';
|
444 |
+
} else {
|
445 |
+
$tag = '<div class="'.$class_id.'">'.$tag.'</div>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
446 |
}
|
447 |
+
return $tag;
|
448 |
}
|
449 |
+
|
450 |
// タイトル整形
|
451 |
if (isset($title)) {
|
452 |
$str = $title;
|
456 |
$str = mb_strimwidth($str, 0, 200, '...'); // 保管用のタイトルは200文字で切る
|
457 |
$title = $str;
|
458 |
}
|
459 |
+
|
460 |
// 抜粋文整形
|
461 |
if (isset($excerpt)) {
|
462 |
$str = $excerpt;
|
468 |
$str = mb_strimwidth($str, 0, 500, '...'); // 保管用の記事内容は500文字で切る
|
469 |
$excerpt = $str;
|
470 |
}
|
471 |
+
|
472 |
+
// 更新あり
|
473 |
+
if ( $update ) {
|
474 |
+
$data = $this->pz_SetCache( $data );
|
475 |
+
//wp_schedule_single_event(time() + 10, 'pz_linkcard_check');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
476 |
|
477 |
if (isset($data['id'])) {
|
478 |
+
$update = false;
|
479 |
}
|
480 |
}
|
481 |
|
482 |
// サムネイル取得
|
483 |
+
if ( !$this->options['thumbnail-position'] || $result_code <> 200) {
|
484 |
$thumbnail = null;
|
485 |
} else {
|
486 |
if ($sw_thumbnail == '3') {
|
587 |
$sns = null;
|
588 |
$sns_info = null;
|
589 |
$sns_title = null;
|
590 |
+
if ( isset($this->options['sns-position']) ? $this->options['sns-position'] : null ) {
|
591 |
$sns = '<span class="lkc-share">';
|
592 |
if ((isset($this->options['link-all']) ? $this->options['link-all'] : null) == '1') {
|
593 |
if (isset($this->options['sns-tw']) && !is_null($this->options['sns-tw']) && $sns_tw > 0) {
|
659 |
return $tag;
|
660 |
}
|
661 |
|
662 |
+
// URL
|
663 |
+
function pz_TrimURL($url = null) {
|
664 |
+
if (!isset($url) || $url == '') {
|
665 |
+
$url = null;
|
666 |
+
return $url;
|
667 |
+
}
|
668 |
+
|
669 |
+
if (isset($url) && $url <> '') {
|
670 |
+
$url = html_entity_decode($url);
|
671 |
+
$url = preg_replace('/^[\s \'\"‘’“”″]*(.*?)[\s \'\"‘’“”″]*$/u', '\1', $url);
|
672 |
+
$url = strip_tags($url);
|
673 |
+
$url = htmlentities($url);
|
674 |
+
$url = esc_url($url); // プロトコル除外など
|
675 |
+
$array_url = parse_url($url);
|
676 |
+
if ((isset($this->options['trail-slash']) ? $this->options['trail-slash'] : null) && (!isset($array_url['path']) || $array_url['path'] == '/')) {
|
677 |
+
// URLがドメイン名だけの場合、最後のスラッシュを除外する
|
678 |
+
$url = preg_replace('/\/$/u', '', $url);
|
679 |
+
}
|
680 |
+
}
|
681 |
+
return $url;
|
682 |
+
}
|
683 |
+
|
684 |
+
// ソーシャルカウント取得
|
685 |
+
public function pz_RenewSNSCount( $data ) {
|
686 |
if (!isset($this->options['sns-position']) || $this->options['sns-position'] == '') {
|
687 |
return null;
|
688 |
}
|
789 |
}
|
790 |
global $wpdb;
|
791 |
if (isset($data['url']) && !is_null($data['url'])) {
|
792 |
+
$url = $this->pz_TrimURL($data['url']);
|
793 |
+
$data = $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->db_name WHERE url=%s", $url));
|
794 |
} elseif (isset($data['id']) && !is_null($data['id'])) {
|
795 |
+
$data_id = intval($data['id']);
|
796 |
+
$data = $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->db_name WHERE id=%d", $data_id));
|
797 |
} else {
|
798 |
return null;
|
799 |
}
|
812 |
if (!isset($data['url']) || is_null($data['url'])) {
|
813 |
return null;
|
814 |
}
|
815 |
+
$url = $this->pz_TrimURL($data['url']);
|
816 |
+
$data['url'] = $url;
|
|
|
817 |
if (!isset($data['url_key']) || is_null($data['url_key']) || $data['url_key'] == '' ) {
|
818 |
+
$data['url_key'] = hash( 'sha256', esc_url( $url ), true);
|
819 |
}
|
820 |
+
$data['uptime'] = current_time('timestamp'); // 最終更新日時
|
821 |
+
|
822 |
// 更新してみる
|
823 |
+
$result = $wpdb->update(
|
824 |
+
$this->db_name,
|
825 |
+
$data,
|
826 |
+
array(
|
827 |
+
'url_key' => $data['url_key']
|
828 |
+
)
|
829 |
+
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
830 |
if (!$result) {
|
831 |
$data['regist'] = current_time('mysql'); // 登録日
|
832 |
// 更新できなかったら挿入
|
883 |
return $tags;
|
884 |
}
|
885 |
|
886 |
+
// 外部サイト取得
|
887 |
+
public function pz_GetCURL( $data ) {
|
888 |
+
$url = $this->pz_TrimURL( $data['url'] );
|
889 |
+
if (!isset( $url ) || $url == '') {
|
890 |
+
return null;
|
891 |
+
}
|
892 |
+
|
893 |
+
// リンク先サイト取得
|
894 |
+
$html = null;
|
895 |
+
$error = true;
|
896 |
+
|
897 |
+
$site_name = null;
|
898 |
+
$title = null;
|
899 |
+
$excerpt = null;
|
900 |
+
$charset = null;
|
901 |
+
$result_code = null;
|
902 |
+
|
903 |
+
$data['id'] = null;
|
904 |
+
$data['url_key'] = null;
|
905 |
+
$data['site_name'] = null;
|
906 |
+
$data['title'] = null;
|
907 |
+
$data['excerpt'] = null;
|
908 |
+
$data['charset'] = null;
|
909 |
+
$data['thumbnail'] = null;
|
910 |
+
$data['favicon'] = null;
|
911 |
+
$data['result_code'] = null;
|
912 |
+
$data['post_id'] = get_the_ID();
|
913 |
+
$data['sns_twitter'] = -1;
|
914 |
+
$data['sns_facebook'] = -1;
|
915 |
+
$data['sns_hatena'] = -1;
|
916 |
+
$data['uptime'] = null;
|
917 |
+
$data['nexttime'] = 0;
|
918 |
+
$data['alive_time'] = 0;
|
919 |
+
$data['alive_result'] = 0;
|
920 |
+
|
921 |
+
if (function_exists('curl_init')) { // cURLを使用する
|
922 |
+
$result_code = 0;
|
923 |
+
$ch = curl_init($url);
|
924 |
+
curl_setopt($ch, CURLOPT_TIMEOUT, 8);
|
925 |
+
curl_setopt($ch, CURLOPT_USERAGENT, esc_html($_SERVER['HTTP_USER_AGENT']));
|
926 |
+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
927 |
+
curl_setopt($ch, CURLOPT_MAXREDIRS, 8);
|
928 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
929 |
+
if (isset($this->options['flg-ssl']) ? $this->options['flg-ssl'] : null) {
|
930 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // SSL検証なし
|
931 |
+
} else {
|
932 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // SSL検証あり
|
933 |
+
}
|
934 |
+
$html = curl_exec($ch);
|
935 |
+
if (curl_errno($ch)) {
|
936 |
+
$html = ''; // cURLエラー
|
937 |
+
$result_code = 0 - intval(curl_errno($ch));
|
938 |
+
} else {
|
939 |
+
$header = curl_getinfo($ch);
|
940 |
+
$result_code = $header['http_code']; // HTTPステータス
|
941 |
+
$error = false;
|
942 |
+
}
|
943 |
+
curl_close($ch);
|
944 |
+
} else { // cURLを使用しない
|
945 |
+
$result = wp_remote_get($url);
|
946 |
+
if (!is_wp_error($result)) {
|
947 |
+
$html = $result['body'];
|
948 |
+
$result_code = $result['response']['code']; // HTTPステータス
|
949 |
+
$error = false;
|
950 |
+
} else {
|
951 |
+
$html = '';
|
952 |
+
$result_code = -1; // wp_remote_getエラー
|
953 |
+
}
|
954 |
+
}
|
955 |
+
|
956 |
+
// 文字コード判定
|
957 |
+
$charset = null;
|
958 |
+
if ($html <> '') {
|
959 |
+
if (preg_match('/charset\s*=\s*([^>\/\s]*).*<\/head/si', $html, $m)) {
|
960 |
+
$m[1] = trim(trim($m[1]), '\'\"');
|
961 |
+
$charset = $m[1];
|
962 |
+
} else {
|
963 |
+
foreach(array('UTF-8','SJIS','EUC-JP','eucJP-win','ASCII','JIS','SJIS-win') as $c_charset) {
|
964 |
+
if (mb_convert_encoding($html, $this->charset, $c_charset) == $html) {
|
965 |
+
$charset = $c_charset;
|
966 |
+
break;
|
967 |
+
}
|
968 |
+
}
|
969 |
+
}
|
970 |
+
if (is_null($charset)) {
|
971 |
+
$charset = 'auto';
|
972 |
+
$html = mb_convert_encoding($html, $this->charset, 'ASCII,JIS,UTF-7,EUC-JP,SJIS,UTF-8');
|
973 |
+
} elseif ($this->charset <> $charset) {
|
974 |
+
$html = mb_convert_encoding($html, $this->charset, $charset);
|
975 |
+
}
|
976 |
+
|
977 |
+
// HEADタグ
|
978 |
+
$head = null;
|
979 |
+
$tags = null;
|
980 |
+
if (preg_match('/<\s*head\s*[^>]*>(.*)<\s*\/head\s*>/si', $html, $m)) {
|
981 |
+
$head = $m[1];
|
982 |
+
$tags = $this->pz_GetMeta($head);
|
983 |
+
}
|
984 |
+
|
985 |
+
// タイトル
|
986 |
+
if (isset( $tags['og:title'] ) && $tags['og:title'] ) {
|
987 |
+
$title = $tags['og:title'] ;
|
988 |
+
} elseif (isset( $tags['title'] ) && $tags['title'] ) {
|
989 |
+
$title = $tags['title'] ;
|
990 |
+
}
|
991 |
+
|
992 |
+
// 抜粋文・概要文
|
993 |
+
if (isset( $tags['og:description'] ) && $tags['og:description'] ) {
|
994 |
+
$excerpt = $tags['og:description'] ;
|
995 |
+
} elseif (isset( $tags['description'] ) && $tags['description'] ) {
|
996 |
+
$excerpt = $tags['description'] ;
|
997 |
+
}
|
998 |
+
|
999 |
+
// // OGPから画像URL取得
|
1000 |
+
// if ($sw_thumbnail == '1' && isset($tags['og:image'])) {
|
1001 |
+
// $thumbnail_url = $tags['og:image'];
|
1002 |
+
// $thumbnail = '<img class="lkc-thumbnail-img" src="'.$thumbnail_url.'" alt="" />';
|
1003 |
+
// }
|
1004 |
+
|
1005 |
+
// サイト名
|
1006 |
+
if (isset( $tags['og:site_name'] ) && $tags['og:site_name'] ) {
|
1007 |
+
$site_name = $tags['og:site_name'] ;
|
1008 |
+
}
|
1009 |
+
|
1010 |
+
// データセット
|
1011 |
+
if (isset($data_id) && !is_null($data_id)) {
|
1012 |
+
$data['id'] = $data_id;
|
1013 |
+
}
|
1014 |
+
if (isset($url_key) && !is_null($url_key)) {
|
1015 |
+
$data['url_key'] = $url_key;
|
1016 |
+
}
|
1017 |
+
$data['url'] = $url;
|
1018 |
+
$data['site_name'] = $site_name;
|
1019 |
+
$data['title'] = $title;
|
1020 |
+
$data['excerpt'] = $excerpt;
|
1021 |
+
$data['charset'] = $charset;
|
1022 |
+
$data['result_code'] = $result_code;
|
1023 |
+
if (isset($atts['force']) && $atts['force'] == true) {
|
1024 |
+
$data['regist'] = current_time('mysql'); // 登録日
|
1025 |
+
}
|
1026 |
+
}
|
1027 |
+
return $data;
|
1028 |
+
}
|
1029 |
+
|
1030 |
// 管理画面時のスタイルシート、スクリプト設定
|
1031 |
public function enqueue_admin($hook) {
|
1032 |
wp_enqueue_style ('wp-color-picker');
|
1074 |
}
|
1075 |
}
|
1076 |
|
|
|
1077 |
// WP-CRONスケジュール(存在チェック)
|
1078 |
public function schedule_hook_alive() {
|
1079 |
if (!isset($this->options['flg-alive']) || $this->options['flg-alive'] == '') {
|
1080 |
return null;
|
1081 |
}
|
1082 |
|
|
|
|
|
|
|
|
|
1083 |
global $wpdb;
|
1084 |
$now = current_time('timestamp');
|
1085 |
+
|
1086 |
+
$result = (array) $wpdb->get_results($wpdb->prepare("SELECT url,alive_time FROM $this->db_name WHERE alive_time<%d ORDER BY alive_time ASC", $now));
|
1087 |
+
|
|
|
|
|
1088 |
$i = 0;
|
1089 |
if (isset($result) && is_array($result) && count($result) > 0) {
|
1090 |
+
foreach($result as $check_data) {
|
1091 |
$i++;
|
1092 |
+
if ($i > 5) {
|
1093 |
+
wp_schedule_single_event(time() + 10, 'pz_linkcard_alive');
|
1094 |
break;
|
1095 |
}
|
1096 |
+
if (isset($check_data) && isset($check_data->url)) {
|
1097 |
+
$before = array( 'url' => $check_data->url );
|
1098 |
+
$after = $before;
|
1099 |
+
$before = $this->pz_GetCache( $before );
|
1100 |
+
$after = $this->pz_GetCURL ( $after );
|
1101 |
+
$before['alive_result'] = $after['result_code'];
|
1102 |
+
$before['alive_time'] = $now;
|
1103 |
+
$after = $this->pz_pz_SetCache( $before );
|
1104 |
}
|
1105 |
}
|
1106 |
}
|
1156 |
sns_twitter INT ,
|
1157 |
sns_facebook INT ,
|
1158 |
sns_hatena INT ,
|
1159 |
+
alive_time BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
1160 |
+
alive_result INT ,
|
1161 |
uptime BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
1162 |
nexttime BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
1163 |
regist DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
|
readme.txt
CHANGED
@@ -72,13 +72,13 @@ WordPress.org からのダウンロードおよびインストール
|
|
72 |
|
73 |
1. WordPress.orgのプラグイン一覧から「Pz-LinkCard」を検索します
|
74 |
|
75 |
-
(Download ZIP file from http://poporon.poponet.jp/pz-
|
76 |
|
77 |
2. プラグイン名と作者を確認していただき、ダウンロードします
|
78 |
|
79 |
3. WordPressをインストールしているディレクトリ配下の、「/wp-content/plugins」ディレクトリ配下に「pz-linkcard」ディレクトリを作成します
|
80 |
|
81 |
-
(Upload pz-
|
82 |
|
83 |
4. ダウンロードしたZIPファイルを展開します
|
84 |
|
@@ -171,6 +171,11 @@ A5.
|
|
171 |
|
172 |
== Changelog ==
|
173 |
|
|
|
|
|
|
|
|
|
|
|
174 |
= 1.7.0 =
|
175 |
* Added: Added setting. `In the case of domain names, to ignore the trailing-slash`.
|
176 |
* Added: Added border `Wheat'.
|
72 |
|
73 |
1. WordPress.orgのプラグイン一覧から「Pz-LinkCard」を検索します
|
74 |
|
75 |
+
(Download ZIP file from http://poporon.poponet.jp/pz-linkcard )
|
76 |
|
77 |
2. プラグイン名と作者を確認していただき、ダウンロードします
|
78 |
|
79 |
3. WordPressをインストールしているディレクトリ配下の、「/wp-content/plugins」ディレクトリ配下に「pz-linkcard」ディレクトリを作成します
|
80 |
|
81 |
+
(Upload pz-linkcard directory to the /wp-content/plugins/ directory)
|
82 |
|
83 |
4. ダウンロードしたZIPファイルを展開します
|
84 |
|
171 |
|
172 |
== Changelog ==
|
173 |
|
174 |
+
= 1.7.1 =
|
175 |
+
* Fixed: debug.
|
176 |
+
|
177 |
+
* 不具合を修正。
|
178 |
+
|
179 |
= 1.7.0 =
|
180 |
* Added: Added setting. `In the case of domain names, to ignore the trailing-slash`.
|
181 |
* Added: Added border `Wheat'.
|
uninstall.php
CHANGED
@@ -7,6 +7,10 @@ $css_dir = $wp_upload_dir['basedir'].'/'.$slug;
|
|
7 |
$css_path1 = $css_dir.'/style.css';
|
8 |
$css_path2 = $css_dir.'/'.$slug.'-style.css';
|
9 |
|
|
|
|
|
|
|
|
|
10 |
// Delete options
|
11 |
delete_option('Pz_LinkCard_options');
|
12 |
|
7 |
$css_path1 = $css_dir.'/style.css';
|
8 |
$css_path2 = $css_dir.'/'.$slug.'-style.css';
|
9 |
|
10 |
+
// Clear Schedule
|
11 |
+
wp_clear_scheduled_hook('pz_linkcard_alive');
|
12 |
+
wp_clear_scheduled_hook('pz_linkcard_check');
|
13 |
+
|
14 |
// Delete options
|
15 |
delete_option('Pz_LinkCard_options');
|
16 |
|