/** * 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; }