| <?php |
| /******************************************************************************* |
| * Copyright (c) 2011 Eclipse Foundation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Wayne Beaton (Eclipse Foundation)- initial API and implementation |
| *******************************************************************************/ |
| require_once(dirname(__FILE__) . "/../../eclipse.org-common/system/app.class.php"); |
| $App = new App(); |
| |
| require_once(dirname(__FILE__) . "/../classes/common.php"); |
| require_once(dirname(__FILE__) . "/../classes/debug.php"); |
| require_once(dirname(__FILE__) . "/../classes/Project.class.php"); |
| |
| header("Content-type: application/json"); |
| |
| echo json_encode(projectsAsArray(getTopLevelProjects())); |
| echo get_trace_text(); |
| |
| function projectsAsArray($projects) { |
| $all = array(); |
| foreach($projects as $project) { |
| $all[$project->getId()] = projectAsArray($project); |
| } |
| return $all; |
| } |
| |
| function projectAsArray($project) { |
| return array( |
| 'id' => $project->getId(), |
| 'name' => $project->getName(), |
| 'shortname' => $project->getShortName(), |
| 'projecturl' => $project->getProjectUrl(), |
| 'description' => $project->getDescription(), |
| 'scope' => $project->getScope(), |
| 'planurl' => $project->getPlanUrl(), |
| 'bugzillaproduct' => $project->getBugzillaProduct(), |
| 'wikiurl' => $project->getWikiUrl(), |
| 'documentationurl' => normalizeHttpUrl($project->getDocumentationUrl()), |
| 'downloadsurl' => normalizeHttpUrl($project->getDownloadsUrl()), |
| 'gettingstartedurl' => normalizeHttpUrl($project->getGettingStartedUrl()), |
| 'sourcerepositories' => sourceRepositoriesAsArray($project), |
| 'releases' => releasesAsArray($project), |
| 'children' => projectsAsArray($project->getChildren()) |
| ); |
| |
| } |
| |
| function sourceRepositoriesAsArray($project) { |
| $repositories = array(); |
| foreach($project->getSourceRepositories() as $repository) { |
| $repositories[] = $repository->getPath(); |
| } |
| return $repositories; |
| } |
| |
| function releasesAsArray($project) { |
| $releases = array(); |
| foreach($project->getReleases() as $release) { |
| $releases[] = releaseAsArray($release); |
| } |
| |
| return $releases; |
| } |
| |
| function releaseAsArray($release) { |
| $values = array(); |
| $values['name'] = $release->getName(); |
| $values['date'] = date('Y-m-d', $release->getDate()); |
| $values['noteworthy'] = $release->getNoteworthyUrl(); |
| $values['planurl'] = $release->getPlan(); |
| addPlanItems($values, $release->getPlan()); |
| return $values; |
| } |
| |
| function addPlanItems(&$values, $planUrl) { |
| if (!$planUrl) return; |
| if (!preg_match('/\.xml$/', $planUrl)) return; |
| |
| $file = dirname(__FILE__) . '/../../' . $planUrl; |
| |
| //$xml = simplexml_load_file($file, 'SimpleXMLElement', null, 'http://www.eclipse.org/project/plan'); |
| $xml = simplexml_load_file($file); |
| if (!$xml) return; |
| |
| addPlanItem($values, 'introduction', $xml->introduction); |
| addPlanItem($values, 'deliverables', $xml->release_deliverables); |
| addPlanItem($values, 'milestones', $xml->release_milestones); |
| addPlanItem($values, 'environment', $xml->target_environments); |
| addPlanItem($values, 'internationalization', $xml->target_environments->internationalization); |
| addPlanItem($values, 'compatibility', $xml->compatibility_with_previous_releases); |
| addThemes($values, $xml->themes_and_priorities); |
| } |
| |
| function addPlanItem(&$values, $name, $xml) { |
| if (!$xml) return; |
| $value = flattenHTML($xml); |
| if (!$value) return; |
| |
| $values[$name] = $value; |
| } |
| |
| function addThemes(&$values, &$xml) { |
| $themes = array(); |
| foreach($xml->theme as $theme) { |
| $value = array(); |
| $value['name'] = (string)$theme['name']; |
| $value['description'] = flattenHTML($theme->description); |
| $themes[] = $value; |
| } |
| if ($themes) $values['themes'] = $themes; |
| } |
| |
| function flattenHTML($xml) { |
| if (!$xml) return; |
| $text = ''; |
| foreach($xml->getNamespaces(true) as $namespace => $url) { |
| if (!preg_match('/html/', $url)) continue; // Ignore non-HTML namespaces |
| $value = $xml->children($namespace, true)->asXML(); |
| $value = preg_replace('/(<\/?)\w+:/','$1',$value); |
| $text .= $value; |
| } |
| return $text; |
| } |
| ?> |