Exemplo n.º 1
0
/**
 * culturalcartography.net interface template
 * @author Peter Edwards <*****@*****.**>
 * @package WordPress
 * @subpackage WKW
 */
$search_results = array();
$ud = wp_upload_dir();
global $wp_query;
$all_names = wkwMediaWiki::get_all_names();
/* handle AJAX requests from animated interface */
if (isset($_REQUEST["wkw_search"]) && isset($_REQUEST["pageid"])) {
    if ($_REQUEST["wkw_search"] == "links") {
        $search_results = wkwMediaWiki::get_linked_names($_REQUEST["pageid"]);
    } elseif ($_REQUEST["wkw_search"] == "page") {
        $search_results = wkwMediaWiki::get_page_data($_REQUEST["pageid"]);
    }
    if (count($search_results)) {
        echo json_encode($search_results);
        exit;
    }
}
/* load the interface script */
wp_enqueue_script('wkw_interface', get_template_directory_uri() . '/js/wkw-interface.js', array("jquery"), "0.2.1", true);
$pageid = false;
/* see if we arrived here with a page id or name */
if (isset($_REQUEST["wkw_pageid"])) {
    $pageid = $_REQUEST["wkw_pageid"];
    $url = get_bloginfo("url") . '/names/' . wkwMediaWiki::getUrlTitle($pageid);
    header("Location: " . $url);
} elseif (isset($wp_query->query_vars['wkw_name'])) {
Exemplo n.º 2
0
 /**
  * cron job to refresh image and data caches
  */
 public static function refresh_caches()
 {
     set_time_limit(0);
     self::clear_data_cache();
     /* store IDs for names to get data */
     $namedata = array();
     /* number of names to get data for in one hit */
     $namedata_limit = 20;
     $all_names = wkwMediaWiki::get_all_names();
     if ($all_names && count($all_names)) {
         $cacheDir = self::get_cache_dir("images");
         $logtxt = sprintf("\n============================\nCRON JOB STARTED %s\n============================\n", date("r"));
         foreach ($all_names as $name) {
             $filename = $cacheDir . "/" . $name->pageid . ".png";
             $touched = strtotime($name->touched);
             $since = time() - 60 * 60 * 24;
             $refresh = false;
             if (file_exists($filename)) {
                 /* see if there is an old image */
                 $linkimg = $cacheDir . "/" . md5($name->title) . ".png";
                 $linkname = $cacheDir . "/" . md5($name->title) . ",txt";
                 if (file_exists($linkimg) || file_exists($linkname)) {
                     @unlink($linkimg);
                     @unlink($linkname);
                 }
                 /* see if the page has been touched since the image was generated */
                 if (filemtime($filename) < $touched) {
                     $logtxt .= sprintf("%s: file exists but wiki page was touched more recently than the image was generated (filemtime: %s, touched: %s).\n", $name->title, date("d/m/Y H:i:s", filemtime($filename)), date("d/m/Y H:i:s", $touched));
                     $refresh = true;
                 }
             } else {
                 $logtxt .= sprintf("%s: cache file doesn't exist\n", $name->title);
                 $refresh = true;
             }
             if ($refresh) {
                 wkwFontImage::generate($name);
                 wkwCache::clearCacheFor($name);
                 $namedata[] = $name->pageid;
             }
         }
         foreach ($all_names as $name) {
             $bio = wkwCache::get_cache_dir('bios') . $name->pageid . '.json';
             if (!file_exists($bio) && count($namedata) <= $namedata_limit && !in_array($name->pageid, $namedata)) {
                 $namedata[] = $name->pageid;
             }
         }
         if (count($namedata)) {
             foreach ($namedata as $pageid) {
                 $logtxt .= "\nGetting links and biographical data for name " . $pageid . "\n";
                 wkwMediaWiki::get_linked_names($pageid);
                 wkwMediaWiki::get_page_data($nameid);
             }
         }
         $logtxt .= sprintf("\n============================\nCRON JOB FINISHED %s\n============================\n", date("r"));
         self::log($logtxt, "cron_log.txt");
     }
 }