function widget($args, $instance) { extract($args); $howmany = empty($instance['howmany']) || 0 == intval($instance['howmany']) ? 5 : intval($instance['howmany']); $which = in_array($instance['which'], array("edits", "pages")) ? $instance['which'] : "pages"; $all_names = wkwMediaWiki::get_all_names(); /* sort for page additions */ usort($all_names, wkwMediaWiki::sort('timestamp', 'time', 'DESC')); /* get latest $howmany */ $page_additions = array_slice($all_names, 0, $howmany); if ($which == "pages") { $this->render_widget($args, $instance, $page_additions); } else { /* store urltitles */ $addition_urltitles = array(); foreach ($page_additions as $addition) { $addition_urltitles[] = $addition->urltitle; } /* sort for page edits */ usort($all_names, wkwMediaWiki::sort('touched', 'time', 'DESC')); /* get latest $howmany which aren't additions */ $page_edits = array(); foreach ($all_names as $edit) { if (!in_array($edit->urltitle, $addition_urltitles)) { $page_edits[] = $edit; } if (count($page_edits) < $howmany) { continue; } else { break; } } $this->render_widget($args, $instance, $page_edits); } }
* @subpackage WKW */ /* where are we redirecting searches to? (interface or wiki) */ $redirect_to = "interface"; $search_results = array(); global $wp_query; $all_names = wkwMediaWiki::get_all_names(); /* now handle non-searches */ if (!isset($_REQUEST["wkw_search"]) || trim($_REQUEST["wkw_search"]) == "") { /* no search terms - I'm feeling lucky */ $rand_index = array_rand($all_names); header("Location: " . get_bloginfo("url") . "/names/" . $all_names[$rand_index]->urltitle); exit; } else { /* search requested from search form with non-empty term */ $search_results = wkwMediaWiki::search(trim($_REQUEST["wkw_search"])); /* redirect for a single result */ if (count($search_results) == 1) { header("Location: " . get_bloginfo("url") . "/names/" . $search_results[0]->urltitle); exit; } } get_header(); ?> <div id="container" class="clearfix page search-page"> <header class="main"> <?php wp_nav_menu(array('theme-location' => 'main-menu', 'container' => 'nav', 'fallback_cb' => false));
/** * creates the image management page */ public static function datascape_options_page() { $datascape_options = self::get_datascape_options(); print '<div class="wrap"><div class="icon32" id="icon-tools"><br /></div><h2>Datascape Options</h2>'; self::process_datascape_options(); /* cache management buttons */ print '<h3>Cache management</h3><p>'; $settings_url = admin_url('themes.php?page=datascape_options'); $actions = array("refreshDataCache" => "Refresh data cache", "refreshBiogCache" => "Refresh biography cache", "refreshLinkCache" => "Refresh links cache", "refreshImageCache" => "Refresh Image cache"); foreach ($actions as $slug => $title) { $action_url = $settings_url . '&action=' . $slug . '&wkw_nonce=' . wp_create_nonce($slug); printf('<a class="button-primary" style="margin:0 2em 1em 0" id="%s" href="%s">%s</a>', $slug, $action_url, $title); } print '</p>'; /* datascape options */ print '<form method="post" action="options.php">'; settings_fields('wkw_datascape_options'); do_settings_sections('wkw-datascape'); print self::get_palette(); print '<p><input type="submit" class="button-primary" name="submit" value="Save settings" /><input type="reset" id="hide_datascape_options" class="button-secondary" value="Cancel" /></p></div></form>'; /* names management */ print '<h3 id="wkw_manage_names">Manage names</h3>'; $all_names = wkwMediaWiki::get_all_names(); $total_names = count($all_names); $page = isset($_REQUEST["wkw_name"]) ? $_REQUEST["wkw_name"] : 'a'; $ud = wp_upload_dir(); print '<p>There are currently <strong>' . count($all_names) . "</strong> names in the Wiki.</p>"; /* make navigation */ $nav = '<div class="atoz"><ul>'; $abc = range("a", "z"); $abc[] = 'unlinked'; $abc[] = 'imagedata'; foreach ($abc as $letter) { $cls = $page == $letter ? ' class="active"' : ''; $nav .= sprintf('<li><a href="%s"%s#wkw_manage_names>%s</a></li>', admin_url("themes.php?page=datascape_options&wkw_name=" . $letter), $cls, strtoupper($letter)); } $nav .= '</ul></div>'; $headers = '<tr><th>Name</th><th>added</th><th>last edited</th><th>image</th></tr>'; $table_top = sprintf('%s<table class="widefat"><thead>%s</thead><tfoot>%s</tfoot><tbody>', $nav, $headers, $headers); $table_end = sprintf('</tbody></table>%s<br style="clear:both;" />', $nav); switch ($page) { case "unlinked": $cachedir = $ud["basedir"] . '/wkw-cache/names'; if ($dh = opendir($cachedir)) { print $table_top; while (($file = readdir($dh)) !== false) { if (!is_dir($cachedir . '/' . $file) && !preg_match('/^[0-9]+\\.png$/', $file) && !preg_match('/.*\\.txt$/', $file)) { $imageurl = $ud["baseurl"] . '/wkw-cache/names/' . $file . '?mtime=' . filemtime($ud["basedir"] . '/wkw-cache/names/' . $file); $fname = $cachedir . "/" . substr($file, 0, -3) . 'txt'; $name = file_get_contents($fname); printf('<tr><td colspan="3">%s<br /><a href="/wiki/index.php?title=%s&action=edit" class="button-secondary" target="wiki">create page in wiki</a> <a class="button-secondary" href="%s%s#wkw_manage_names">regenerate image</a></td><td><img src="%s" /></td></tr>', $name, str_replace(' ', '_', $name), admin_url('themes.php?page=datascape_options&action=refreshImage&wkw_linkid='), substr($file, 0, -3), $imageurl); } } print $table_end; closedir($dh); } break; case 'imagedata': $datacsv = '"width","height","name","surname","filesize","url"' . "\n"; $cachedir = $ud["basedir"] . '/wkw-cache/names'; $total_width = $total_size = $no_images = 0; if ($dh = opendir($cachedir)) { $stats = array('largest' => '', 'smallest' => ''); $largest = 0; $smallest = 100000000; while (($file = readdir($dh)) !== false) { $fn = $cachedir . '/' . $file; if (!is_dir($fn) && preg_match('/.*png$/', $fn)) { $imginfo = @getimagesize($fn); if ($imginfo !== false) { $no_images++; $name = ''; $surname = ''; if (file_exists($cachedir . "/" . substr($file, 0, -3) . 'txt')) { $name = file_get_contents($cachedir . "/" . substr($file, 0, -3) . 'txt'); $surname = wkwMediaWiki::get_unlinked_surname($name); } else { for ($i = 0; $i < $total_names; $i++) { if (substr($file, 0, -4) == $all_names[$i]->pageid) { $name = $all_names[$i]->sortkeyprefix; $surname = wkwFontImage::get_surname($all_names[$i]->sortkeyprefix, false); break; } } } $imginfo[2] = '"' . str_replace('"', '\\"', $name) . '"'; $imginfo[3] = '"' . str_replace('"', '\\"', $surname) . '"'; $imginfo[4] = filesize($fn); $imginfo[5] = $ud["baseurl"] . '/wkw-cache/names/' . $file; unset($imginfo['mime']); unset($imginfo['bits']); $datacsv .= implode(',', $imginfo) . "\n"; $area = intval($imginfo[0] * $imginfo[1]); if ($area > 0) { if ($area > $largest) { $stats["largest"] = $imginfo; $largest = $area; } if ($area < $smallest) { $stats["smallest"] = $imginfo; $smallest = $area; } $total_width += $imginfo[0]; $total_size += $imginfo[4]; } } } } } print $nav; print '<h3 style="clear:both;">Image stats</h3>'; printf('<p>Largest image (%spx x %spx, %s bytes):<br /><img src="%s" /></p>', $stats["largest"][0], $stats["largest"][1], $stats["largest"][4], $stats["largest"][5]); //printf('<p>Smallest image (%spx x %spx, %s bytes):<br /><img src="%s" /></p>', $stats["smallest"][0], $stats["smallest"][1], $stats["smallest"][4], $stats["smallest"][5]); printf('<p>Average width of images: %spx</p><p>Average size of images: %s bytes - current settings indicate a download of %s Kb to reach name saturation</p>', floor($total_width / $no_images), floor($total_size / $no_images), floor(floor($total_size / $no_images) * $datascape_options["img_max"] / 1024)); print '<h3>All image data</h3>'; printf('<div style="clear:both"><textarea cols="100" rows="100">%s</textarea></div>', $datacsv); print $nav; break; default: print $table_top; for ($i = 0; $i < $total_names; $i++) { if (stripos($all_names[$i]->sortkeyprefix, $page) === 0) { $imageurl = $ud["baseurl"] . '/wkw-cache/names/' . $all_names[$i]->pageid . '.png?mtime=' . filemtime($ud["basedir"] . '/wkw-cache/names/' . $all_names[$i]->pageid . '.png'); printf('<tr><td><strong>Name:</strong> %s<br /><strong>Sortkey:</strong> %s<br /><strong>Surname:</strong> %s<br /><a href="%s" class="button-secondary" target="wiki">view in wiki</a> <a href="%s" class="button-secondary" target="wiki">edit in wiki</a> <a class="button-secondary" href="%s%s#wkw_manage_names">regenerate image</a></td><td>%s</td><td>%s</td><td><img src="%s" title="%s" /></td></tr>', $all_names[$i]->title, $all_names[$i]->sortkeyprefix, wkwFontImage::get_surname($all_names[$i]->sortkeyprefix, false), $all_names[$i]->fullurl, $all_names[$i]->editurl, admin_url('themes.php?page=datascape_options&action=refreshImage&wkw_pageid='), $all_names[$i]->pageid, date("d/m/Y", strtotime($all_names[$i]->timestamp)), date("d/m/Y", strtotime($all_names[$i]->touched)), $imageurl, esc_attr($all_names[$i]->title)); } } print $table_end; break; } print '</div>'; }
$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'])) { foreach ($all_names as $name) { if ($name->urltitle == $wp_query->query_vars['wkw_name']) { $pageid = $name->pageid; $title = $name->title; $urltitle = $name->urltitle; $surname = $name->surname; $lastmod = $name->lastmod; break; } } } if (!$pageid) { /* get a random page if none specified */
?> "> <img class="header-image" src="<?php echo get_stylesheet_directory_uri(); ?> /img/titles/main.gif" /> </a> <?php echo get_search_form(); ?> </header> <section class="page-content"> <?php $names = wkwMediaWiki::get_all_names(); $interfaceURI = home_url() . "/names/"; $atoz = array(); $az = range("A", "Z"); foreach ($az as $l) { $atoz[$l] = false; } $currentletter = 0; $nameslist = ""; if (count($names)) { foreach ($names as $name) { $letter = strtoupper(substr($name->sortkeyprefix, 0, 1)); if (isset($atoz[$letter]) && $atoz[$letter] == false) { $atoz[$letter] = '<li><a href="#' . $letter . '" class="atoz-key-link">' . $letter . '</a></li>'; $anchor = ' name="' . $letter . '" id="' . $letter . '"'; } else {
/** * 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; } } }