/** * gets pages from the wiki which are linked to the given page */ public static function get_linked_names($page_id = false) { if ($page_id === false) { return array(); } $cache_key = "links/" . $page_id; $linked_names = json_decode(wkwCache::get_cache($cache_key)); if (!$linked_names) { $results = self::query(array('query' => 'links', 'term' => $page_id)); $linked_names = array(); if ($results && $results->query && $results->query->pages) { $all_names = self::get_all_names(); foreach ($results->query->pages as $id => $name) { if (isset($name->missing)) { /* no page in wiki yet for this name */ $surname = self::get_unlinked_surname($name->title); $id = md5($name->title); $p = array('pageid' => $id, 'title' => $name->title, 'surname' => $surname, 'sortkeyprefix' => $surname, 'urltitle' => false, 'hasDetail' => false); $po = (object) $p; /* generate image for name */ $ud = wp_upload_dir(); $nametxt = $ud["basedir"] . '/wkw-cache/names/' . $id . '.txt'; $nameimg = $ud["basedir"] . '/wkw-cache/names/' . $id . '.png'; if (!file_exists($nametext)) { file_put_contents($nametxt, $name->title); } wkwFontImage::generate($po); $po->lastmod = wkwCache::get_last_modified($id); $linked_names[] = $po; } else { /* page exists - get details from $all_names */ foreach ($all_names as $n) { if ($n->pageid == $id) { $p = array('pageid' => $n->pageid, 'title' => $n->title, 'surname' => $n->surname, 'urltitle' => $n->urltitle, 'hasDetail' => true, 'lastmod' => wkwCache::get_last_modified($n->pageid)); $linked_names[] = (object) $p; break; } } } } wkwCache::save_cache($cache_key, json_encode($linked_names)); } } return $linked_names; }
/** * processes any changes from the datascape options page */ public static function process_datascape_options() { /* first display any messages from Wordpress */ if (isset($_REQUEST['settings-updated']) && $_REQUEST['settings-updated'] == "true") { echo '<div id="message" class="updated"><p><strong>Settings saved.</strong></p></div>'; } settings_errors('wkw_datascape_options'); /* process cache refresh actions */ if (isset($_REQUEST["action"])) { switch ($_REQUEST["action"]) { case "refreshDataCache": /* refreshes just the data cache */ if (isset($_REQUEST["wkw_nonce"]) && wp_verify_nonce($_REQUEST["wkw_nonce"], 'refreshDataCache')) { wkwCache::force_refresh("data"); echo '<div class="updated"><p>Primary data cache refreshed</p></div>'; } break; case "refreshBiogCache": /* refreshes just the data cache */ if (isset($_REQUEST["wkw_nonce"]) && wp_verify_nonce($_REQUEST["wkw_nonce"], 'refreshBiogCache')) { wkwCache::force_refresh("bios"); echo '<div class="updated"><p>Biography data cache refreshed</p></div>'; } break; case "refreshLinkCache": /* refreshes just the data cache */ if (isset($_REQUEST["wkw_nonce"]) && wp_verify_nonce($_REQUEST["wkw_nonce"], 'refreshLinkCache')) { wkwCache::force_refresh("links"); echo '<div class="updated"><p>link data cache refreshed</p></div>'; } break; case "refreshImageCache": /* refreshesimage cache */ if (isset($_REQUEST["wkw_nonce"]) && wp_verify_nonce($_REQUEST["wkw_nonce"], 'refreshImageCache')) { wkwCache::force_refresh("images"); echo '<div class="updated"><p>Image cache cleared - new images generated</p></div>'; } break; case "refreshImage": /* refreshes a single image */ $cacheDir = wkwCache::get_cache_dir("names"); if (isset($_REQUEST["wkw_pageid"])) { $all_names = wkwMediaWiki::get_all_names(); foreach ($all_names as $name) { if ($name->pageid == $_REQUEST["wkw_pageid"]) { wkwFontImage::generate($name, true); echo '<div class="updated"><p>New image generated for ' . $name->title . '</p></div>'; break; } } } elseif (isset($_REQUEST["wkw_linkid"])) { $f_img = $cacheDir . '/' . $_REQUEST["wkw_linkid"] . '.png'; $f_name = $cacheDir . '/' . $_REQUEST["wkw_linkid"] . '.txt'; if (file_exists($f_name)) { $name = file_get_contents($f_name); if (!empty($name)) { $surname = wkwFontImage::get_unlinked_surname($name); $n = (object) array('pageid' => $_REQUEST["wkw_linkid"], 'title' => $name, 'surname' => $surname, 'sortkeyprefix' => $surname, 'urltitle' => false, 'hasDetail' => false); /* generate image for name */ wkwFontImage::generate($n); echo '<div class="updated"><p>New image generated for ' . $name . '</p></div>'; } } } break; } } }
/** * cache freshener - called from theme option screen */ public static function force_refresh($which = "data") { set_time_limit(0); $all_names = wkwMediaWiki::get_all_names(); if ($all_names && count($all_names)) { switch ($which) { case "images": self::clear_image_cache(); foreach ($all_names as $name) { wkwFontImage::generate($name); } break; case "bios": case "links": foreach ($all_names as $name) { $getdata = true; $data = wkwCache::get_cache_dir($which) . $name->pageid . '.json'; $touched = strtotime($name->touched); if (file_exists($data) && filemtime($data) >= $touched) { $getdata = false; } if ($getdata) { @unlink($data); $method = $which == "bios" ? "get_page_data" : "get_linked_names"; wkwMediaWiki::$method($name->pageid); } } break; default: self::clear_data_cache(); $all_names = wkwMediaWiki::get_all_names(true); break; } } }