| <?php |
| /******************************************************************************* |
| * Copyright (c) 2015 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: |
| * Christopher Guindon (Eclipse Foundation) - initial API and implementation |
| *******************************************************************************/ |
| |
| //if name of the file requested is the same as the current file, the script will exit directly. |
| if(basename(__FILE__) == basename($_SERVER['PHP_SELF'])){exit();} |
| |
| class EclipseInstaller { |
| |
| public $platform = array(); |
| |
| /** |
| * Constructor |
| */ |
| function EclipseInstaller() { |
| $this->addPlaform('Mac OS X'); |
| $this->addPlaform('Windows'); |
| $this->addPlaform('Linux'); |
| } |
| |
| /** |
| * Add a link to the Eclipse Installer |
| * |
| * @param string $platform |
| * @param string $url |
| * @param string $text |
| * @return boolean |
| */ |
| public function addlink($platform = '', $url = '', $text = '') { |
| if(!isset($this->platform[$this->_getSafeName($platform)])) { |
| return FALSE; |
| } |
| $count = count($this->platform[$this->_getSafeName($platform)]['links']); |
| $this->platform[$this->_getSafeName($platform)]['links'][] = '<li class="download-link-' . $count . '"><a href="' . $url .'" title="' . $text . ' Download">' . $text .'</a></li>' . PHP_EOL; |
| } |
| |
| private function _getSafeName($str = '') { |
| return str_replace(' ', '', strtolower($str)); |
| } |
| |
| /** |
| * Add a platform to the Eclipse Installer |
| * |
| * @param string $label |
| */ |
| private function addPlaform($label = '') { |
| $safe_label = $this->_getSafeName($label); |
| $this->platform[$safe_label] = array( |
| 'label' => $label, |
| 'icon' => '<img src="/downloads/assets/public/images/icon-' . $safe_label . '.png"/>', |
| 'links' => array(), |
| ); |
| } |
| |
| /** |
| * Output of the Eclipse Installer HTML |
| * |
| * @return string |
| */ |
| public function output(){ |
| $html = ""; |
| $platforms = $this->platform; |
| if (!empty($platforms)) { |
| ob_start(); |
| include("views/view.eclipse_installer.php"); |
| $html = ob_get_clean(); |
| } |
| return $html; |
| } |
| } |