示例#1
0
 public function buildCompleteMenuArraysData()
 {
     $allMenusArray = array();
     $allEventsArray = array();
     $wiki2id = array();
     $wikiid2paths = array();
     $agid2path = array();
     $path2agid = array();
     $now2agid = array("current" => array(), "future" => array(), "past" => array());
     $menuFiles = array();
     $all_wikipages = array();
     $jointEvents = array();
     // --------------------
     // -- (1) SUBSITES
     //    Fetch all names of subsites (from $this->allSitesArray, directories in PATH_SITES)
     //    and possible common menus (from '_classes/config/layout/<nr>/common_menus.php')
     //    --> $menuFiles
     // --------------------
     // -- We need the menus for all subsites
     $menuFiles = $this->allSitesArray;
     // -- There might be common menu files, like 'm_main_nonmenu' and 'm_event', for this layout
     if (file_exists(INCLEVEL . PATH_LAYOUT . "/" . DEFAULT_VERSION . "/common_menus.php")) {
         require_once PATH_LAYOUT . "/" . DEFAULT_VERSION . "/common_menus.php";
         if (!empty($common_menus)) {
             $menuFiles = array_unique(array_merge($menuFiles, $common_menus));
         }
     }
     // -- We don't need the menu of any test subsite:
     foreach ($menuFiles as $key => $menu) {
         if (in_array($menu, array("index.php", DOCROOT_PREFIX))) {
             unset($menuFiles[$key]);
         }
     }
     // --------------------
     // -- (2) WEB PAGES
     //    Load menu file for each SUBSITE and copy menu elements.
     //    --> $allMenusArray
     // --------------------
     foreach ($menuFiles as $menu) {
         if (file_exists(INCLEVEL . PATH_SITES . "/" . $menu . "/menu_" . $menu . ".php")) {
             // subsite menu path
             if (!function_exists("menu_" . $menu)) {
                 require_once PATH_SITES . "/" . $menu . "/menu_" . $menu . ".php";
             }
         } elseif (file_exists(INCLEVEL . PATH_MENU . "/m_" . $menu . ".php")) {
             // common menu path (there are still some files here!)
             if (!function_exists("menu_" . $menu)) {
                 require_once PATH_MENU . "/m_" . $menu . ".php";
             }
         }
         if (function_exists("menu_" . $menu)) {
             $thisMenuRecords = call_user_func("menu_" . $menu);
             foreach ($thisMenuRecords as $thisPath => $thisRecord) {
                 if (!isset($allMenusArray[$thisPath])) {
                     $thisRecord["path"] = $thisPath;
                     $thisRecord["subsite"] = $menu;
                     $allMenusArray[$thisPath] = $thisRecord;
                 }
             }
         }
     }
     // -- Sort and save
     // DON'T do this: "ksort($allMenusArray)" since it will reshuffle all menus!
     $this->allMenusArray = $allMenusArray;
     // --------------------
     // -- (3) WEB PAGES
     //    Create convenience lookup tables.
     //    --> $wiki2id
     //    --> $agid2path
     //    --> $path2agid
     //    --> $wikiid2paths
     // --------------------
     foreach ($allMenusArray as $path => $arr) {
         // --------------------
         // Conversion from path to wiki title
         if (!empty($arr["wikiid"])) {
             $wiki2id[$arr["wikititle"]] = $arr["wikiid"];
         }
         if (!empty($arr["wikiid"]) && !is_numeric($path)) {
             $wikiid2paths[$arr["wikiid"]]["name"] = empty($arr["wiki"]) ? "" : $arr["wiki"];
             $wikiid2paths[$arr["wikiid"]]["path"][] = $path;
         }
         // --------------------
         // Conversion from path to agenda index for programs
         // NB. The 'url' field is typically not present in the menu file 'm_events' but
         // is constructed in XXX from the 'confid' field.
         if (preg_match("~^events/([^/]+)\$~imU", $path, $subpath) && !empty($arr["confid"])) {
             $agid2path[$arr["confid"]] = $subpath[1];
         }
     }
     // end foreach
     $path2agid = array_flip($agid2path);
     // -- Obtain $all_wikipages[] from wiki DB
     $dbWiki = new fromdb_nwwiki();
     $all_wikipages = $dbWiki->get_listAllPages();
     $GLOBALS["dbWikiSql"] = $dbWiki->DBq;
     if (!isset($all_wikipages)) {
         return BLURB_SORRY_DB_CONNECT;
     }
     // array();
     // -- Update $wikiid2paths[] with pages in wiki DB but not in menus
     foreach ($all_wikipages as $namespace => $wps) {
         foreach ($wps as $wp) {
             $wikiid2paths[$wp["page_id"]]["name"] = empty($wp['title']) ? "" : $wp['title'];
             $wikiid2paths[$wp["page_id"]]["timestamp"] = empty($wp["timestamp"]) ? "" : date("Y-m-d", $wp['timestamp']);
         }
     }
     // -- Sort and save
     ksort($wiki2id);
     ksort($agid2path);
     ksort($path2agid);
     ksort($wikiid2paths);
     $this->wiki2id = $wiki2id;
     $this->agid2path = $agid2path;
     $this->path2agid = $path2agid;
     $this->wikiid2paths = $wikiid2paths;
     // --------------------
     // -- (4) EVENTS
     //    Create event tables sorted in different ways for convenience.
     //    --> $allEventsArray[$confId] = array("date"=>array("starttime"=<record>)
     //    --> $now2agid[past|current|future][startdate][] = $confId
     // --------------------
     $eventArray = $oneEvent = $jointEvents = array();
     //    if (!class_exists("fromdb_agenda",FALSE)) require_once PATH_CLASSES . "/fromdb/agenda.php";
     //
     //    if (!isset($dbVm) || !is_object($dbVm)) {
     //      require_once PATH_CLASSES . "/fromdb/vm.php";
     //      $dbVm = new fromdb_vm();
     //    }
     //
     //    if (!isset($dbEv) || !is_object($dbEv)) {
     //      require_once PATH_CLASSES . "/fromdb/nwevents.php";
     //      $dbEv = new fromdb_nwevents();
     //    }
     // -- Obtain list of Agenda id:s for Nordita events
     //    --> $allConfids
     $allConfids = functions::callMethod('fromdb_nwevents', 'fromdb/nwevents', 'getAgendaConferenceIdsForNorditaEvents');
     // -- Fetch data for each Nordita event from various sources
     $jointEvents = functions::callMethod('fromdb_nwevents', 'fromdb/nwevents', 'getEventsJoint');
     //TODO: if (OK_TO_CALL_EVENTS), fetch all data from nwevents at once, rather than for each event in a loop
     if (IS_TESTSERVER || isInPath("_admin")) {
         echo "Reading event data from source " . (OK_TO_CALL_EVENTS ? "<em>DB nwevents</em> to DOC-&gt;\$menus:" : "<em>Agenda</em>");
     }
     foreach ($allConfids as $confId) {
         // -- (i) Fetch data for event $confId from the Agenda database, by way of local nwevents database
         $oneEvent = functions::callMethod('fromdb_nwevents', 'fromdb/nwevents', 'getOneEvent', $confId, TRUE);
         if (IS_TESTSERVER || isInPath("_admin")) {
             echo " #" . $confId;
         }
         if (!empty($oneEvent)) {
             if (isset($oneEvent["contribution"])) {
                 unset($oneEvent["contribution"]);
             }
             if (isset($oneEvent["startdate"]) && substr($oneEvent["startdate"], -5) != "01-01" && isset($agid2path[$confId])) {
                 // -- (ii) Add event data from menu file
                 $path = $agid2path[$confId];
                 $oneEvent["subpath"] = $path;
                 if (isset($allMenusArray["events/" . $path])) {
                     foreach (array("blurb", "path", "url", "etype", "confid_parent", "surveyid", "surveyresponse") as $field) {
                         if (isset($allMenusArray["events/" . $path][$field])) {
                             $oneEvent[$field] = $allMenusArray["events/" . $path][$field];
                         }
                     }
                     if (!empty($allMenusArray["events/" . $path]["youtube"])) {
                         $oneEvent["videos"] = "video/index.php?ev=" . $path;
                         // ."&amp;cl=".$theevent["youtube"];
                         $oneEvent["youtubeid"] = $allMenusArray["events/" . $path]["youtube"];
                     }
                 }
                 // -- (iii) Add event data from VM
                 $budget = functions::callMethod('fromdb_vm', 'fromdb/vm', 'getEventBudgetsources', $confId, TRUE);
                 //$budget = $dbVm->getEventBudgetsources($confId,1);
                 if ($budget && !empty($budget)) {
                     $oneEvent["budgetsources"] = $budget;
                 }
                 // -- Save event data into array $allEventsArray
                 $allEventsArray[$confId] = $oneEvent;
                 if (!empty($oneEvent["current"]) && !empty($oneEvent["startdate"])) {
                     $now2agid[$oneEvent["current"]][$oneEvent["startdate"]][] = $oneEvent["id"];
                 }
             }
             // end if
         }
         // end if
     }
     // end foreach
     // -- Sort and save
     //ksort($allEventsArray); // don't do this: waste of time
     $this->allEventsArray = $allEventsArray;
     $this->now2agid = $now2agid;
     // -- Return calculated arrays to be saved in cache file
     return array("allMenusArray" => $allMenusArray, "allEventsArray" => $allEventsArray, "wiki2id" => $wiki2id, "agid2path" => $agid2path, "path2agid" => $path2agid, "now2agid" => $now2agid, "wikiid2paths" => $wikiid2paths, "jointEvents" => $jointEvents);
 }
示例#2
0
 public static function AwikiLinks()
 {
     $stdout = "";
     // ----
     if (empty($GLOBALS["documentClass"]->wikiid2paths)) {
         $GLOBALS["documentClass"]->buildCompleteMenuArrays();
     }
     // ---- Build from wiki DB $all_wikipages[0][] = array(<page_id>,<title>)
     $dbWiki = new fromdb_nwwiki();
     $all_wikipages = $dbWiki->get_listAllPages();
     if (!isset($all_wikipages) || !is_array($all_wikipages)) {
         return "";
     }
     ksort($all_wikipages[0]);
     // ---- Build $inNoMenu[<title>] = <page_id>
     // ---- Build $allwiki2wikiid[<title>] = <page_id>
     $inNoMenu = array();
     foreach ($all_wikipages[0] as $idx => $val) {
         if (!isset($GLOBALS["documentClass"]->wikiid2paths[$val["page_id"]]["path"])) {
             $inNoMenu[$val["title"]] = $val["page_id"];
         }
         $allwiki2wikiid[$val["title"]] = $val["page_id"];
     }
     ksort($inNoMenu);
     // ---- Build $all_wikiid[<id>] = array(<title>,<wikilinks>[],<paths>[])
     foreach ($all_wikipages[0] as $idx => $val) {
         if (isset($dbWiki->wikipage_wikilinks)) {
             unset($dbWiki->wikipage_wikilinks);
         }
         $dbWiki->get_wikilinks($val["page_id"]);
         // --> $dbWiki->wikipage_wikilinks[]
         $tmparr = array();
         if (isset($dbWiki->wikipage_wikilinks) && is_array($dbWiki->wikipage_wikilinks)) {
             foreach ($dbWiki->wikipage_wikilinks as $id => $va) {
                 $tmparr[$va["txt"]] = isset($allwiki2wikiid[$va["txt"]]) ? 1 : 0;
             }
         }
         $all_wikiid[$val["page_id"]]["title"] = $val["title"];
         $all_wikiid[$val["page_id"]]["wikilinks"] = count($tmparr) > 0 ? $tmparr : array();
         $all_wikiid[$val["page_id"]]["paths"] = isset($GLOBALS["documentClass"]->wikiid2paths[$val["page_id"]]["path"]) ? $GLOBALS["documentClass"]->wikiid2paths[$val["page_id"]]["path"] : array();
     }
     krsort($all_wikiid);
     // ----
     foreach ($all_wikiid as $id => $arr) {
         if (!empty($arr["title"])) {
             $stdout .= "<dt><strong" . (empty($arr["paths"]) ? " class='red'" : "") . ">[" . $id . "]</strong>&nbsp;" . "<a href='" . WIKI_URI . "/index.php/" . $arr["title"] . "'>" . "<strong>" . $arr["title"] . "</strong></a>" . "</dt>\r\n";
             if (isset($arr["paths"])) {
                 foreach ($arr["paths"] as $path) {
                     $stdout .= !empty($path) ? "<dd><span style='font-family:monospace'>" . $path . "</span></dd>\r\n" : "";
                 }
             }
             if (isset($arr["wikilinks"]) && count($arr["wikilinks"]) > 0) {
                 $stdout .= "<dd><ul>\r\n";
                 foreach ($arr["wikilinks"] as $wikilink => $isWiki) {
                     $stdout .= $isWiki ? "<li style='color:green'>" . $wikilink . "</li>" : "<li style='color:red'>" . $wikilink . "</li>";
                 }
                 $stdout .= "</ul></dd>\r\n";
             }
         }
     }
     return $stdout;
 }