$content = implode("\n", $pagehash['text']); $content = str_replace("[", "[[", $content); $newhash['content'] = explode("\n", $content); InsertPage($dbi, $pagename, $newhash); } echo "opening dbm file: {$portdbmfile} ... \n"; if (!file_exists($portdbmfile)) { echo "File '{$portdbmfile}' does not exist.<br>\n"; exit; } if (!($dbmh = dbmopen($portdbmfile, "r"))) { echo "Cannot open '{$portdbmfile}'<br>\n"; exit; } echo " ok ({$dbmh})<p>\n"; $namelist = array(); $ctr = 0; $namelist[$ctr] = $key = dbmfirstkey($dbmh); port1_0renderhash($dbi, $dbmh, $key); while ($key = dbmnextkey($dbmh, $key)) { $ctr++; $namelist[$ctr] = $key; port1_0renderhash($dbi, $dbmh, $key); } dbmclose($dbmh); ?> <p><b>Done.</b> </body> </html>
function dba_firstkey($handle) { return $GLOBALS["dbm_lastkey"] = dbmfirstkey($handle); }
function SetWikiPageLinks($dbi, $pagename, $linklist) { $cache = array(); // Phase 1: fetch the relevant pairs from 'wikilinks' into $cache // --------------------------------------------------------------- // first the info for $pagename $linkinfo = RetrievePage($dbi, $pagename, 'wikilinks'); if (is_array($linkinfo)) { // page exists? $cache[$pagename] = $linkinfo; } else { // create info for page $cache[$pagename] = array('fromlinks' => array(), 'tolinks' => array()); // look up pages that link to $pagename $pname = dbmfirstkey($dbi['wikilinks']); while ($pname) { $linkinfo = RetrievePage($dbi, $pname, 'wikilinks'); if ($linkinfo['tolinks'][$pagename]) { $cache[$pagename]['fromlinks'][$pname] = 1; } $pname = dbmnextkey($dbi['wikilinks'], $pname); } } // then the info for the pages that $pagename used to point to $oldTolinks = $cache[$pagename]['tolinks']; reset($oldTolinks); while (list($link, $dummy) = each($oldTolinks)) { $linkinfo = RetrievePage($dbi, $link, 'wikilinks'); if (is_array($linkinfo)) { $cache[$link] = $linkinfo; } } // finally the info for the pages that $pagename will point to reset($linklist); while (list($link, $dummy) = each($linklist)) { $linkinfo = RetrievePage($dbi, $link, 'wikilinks'); if (is_array($linkinfo)) { $cache[$link] = $linkinfo; } } // Phase 2: delete the old links // --------------------------------------------------------------- // delete the old tolinks for $pagename // $cache[$pagename]['tolinks'] = array(); // (overwritten anyway in Phase 3) // remove $pagename from the fromlinks of pages in $oldTolinks reset($oldTolinks); while (list($oldTolink, $dummy) = each($oldTolinks)) { if ($cache[$oldTolink]) { // links to existing page? $oldFromlinks = $cache[$oldTolink]['fromlinks']; $cache[$oldTolink]['fromlinks'] = array(); // erase fromlinks reset($oldFromlinks); // comp. new fr.links while (list($fromlink, $dummy) = each($oldFromlinks)) { if ($fromlink != $pagename) { $cache[$oldTolink]['fromlinks'][$fromlink] = 1; } } } } // Phase 3: add the new links // --------------------------------------------------------------- // set the new tolinks for $pagename $cache[$pagename]['tolinks'] = $linklist; // add $pagename to the fromlinks of pages in $linklist reset($linklist); while (list($link, $dummy) = each($linklist)) { if ($cache[$link]) { // existing page? $cache[$link]['fromlinks'][$pagename] = 1; } } // Phase 4: write $cache back to 'wikilinks' // --------------------------------------------------------------- reset($cache); while (list($link, $fromAndTolinks) = each($cache)) { InsertPage($dbi, $link, $fromAndTolinks, 'wikilinks'); } }
function InitMostPopular($dbi, $limit) { return; $pagename = dbmfirstkey($dbi['hitcount']); $res[$pagename] = dbmfetch($dbi['hitcount'], $pagename); while ($pagename = dbmnextkey($dbi['hitcount'], $pagename)) { $res[$pagename] = dbmfetch($dbi['hitcount'], $pagename); echo "got {$pagename} with value " . $res[$pagename] . "<br>\n"; } rsort($res); reset($res); return $res; }