Category::Plugin

links プラグインの暫定的な代替プラグイン(案)

メッセージ

とりあえず、 ref がないと #related がまともに働かないので、無理やり生成します*1

負荷はかかると思いますが、生成自体はできるはずです。 official の rel・ref が更新不能な状態が続いた場合の最終手段の一つとしてどうぞ。

リードオンリーのチェックなどはしていません。

<?php
define('PLUGIN_LINKS2_MAX', 100);
define('PLUGIN_LINKS2_REFRESH', 2);


function plugin_links2_action()
{
  global $script, $get, $post, $head_tags, $whatsnew;

  if (ini_get('safe_mode') == '0') {
    set_time_limit(0);
  }

  $filename = CACHE_DIR . 'links.tmp';
  $exists = file_exists($filename);

  if (! $exists && ! (isset($post['adminpass']) && pkwk_login($post['adminpass']))) {
    $id = '_p_links2_adminpass';
    $form[] = '<form method="post" action="' . $script . '">';
    $form[] = ' <div>';
    $form[] = '  <input type="hidden" name="plugin" value="links2" />';
    $form[] = '  <input type="hidden" name="make"   value="true" />';
    $form[] = '  <label for="' . $id . '">pass: </label>';
    $form[] = '  <input type="password" name="adminpass" id="' . $id . '" size="20" value="" />';
    $form[] = ' </div>';
    $form[] = '</form>';
    return array('body' => implode("\n", $form));
  } elseif (isset($post['make'])) {
    foreach (get_existfiles(CACHE_DIR, '.ref') as $cache) {
      unlink($cache);
    }
    foreach (get_existfiles(CACHE_DIR, '.rel') as $cache) {
      unlink($cache);
    }
    $pages = get_existpages();
    unset($pages[encode($whatsnew) . '.txt']);
    plugin_links2_makefile($filename, $pages);
  }

  $count = plugin_links2_update($filename);
  if ($count) {
    $head_tags[] = '<meta http-equiv="refresh" content="' . PLUGIN_LINKS2_REFRESH . ';url=' . $script . '?cmd=links2" />';
    $msg  = $body = '更新中...(残り' . $count . 'ページ)';
  } else {
    $msg  = $body = '終了';
  }

  return array('msg' => $msg,'body' => '<p>' . $body . '</p>');
}


function plugin_links2_makefile($filename, $pages)
{
  $handle = fopen($filename, 'w');
  flock($handle, LOCK_EX);
  foreach ($pages as $page) {
    fwrite($handle, $page . "\n");
  }
  flock($handle, LOCK_UN);
  fclose($handle);
}


function plugin_links2_update($filename)
{
  $pages = str_replace("\n", '', file($filename));
  $i = 0;
  while (! empty($pages) && ++$i <= PLUGIN_LINKS2_MAX) {
    $page = array_shift($pages);
    links_update($page);
  }

  if (! empty($pages)) {
    plugin_links2_makefile($filename, $pages);
    return count($pages);
  } else {
    unlink($filename);
    return false;
  }
}
?>



*1 全ページに対し links_update() をかけるだけです

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2006-01-15 (日) 08:07:25
Site admin: PukiWiki Development Team

PukiWiki 1.5.4+ © 2001-2022 PukiWiki Development Team. Powered by PHP 8.2.12. HTML convert time: 0.212 sec.

SourceForge