| <?php |
| |
| /** |
| * Copyright (c) 2022 Eclipse Foundation. |
| * |
| * This program and the accompanying materials are made |
| * available under the terms of the Eclipse Public License 2.0 |
| * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * Contributors: |
| * Christopher Guindon (Eclipse Foundation) - Initial implementation |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| */ |
| |
| require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/classes/friends/payment.class.php"); |
| require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/app.class.php"); |
| |
| /** |
| * Donate View |
| * |
| * @author Christopher Guindon |
| */ |
| class Donate { |
| |
| /** |
| * Instance of App() |
| * |
| * @var object |
| */ |
| protected $App; |
| |
| /** |
| * Instance of Paypal() |
| * |
| * @var object |
| */ |
| protected $Paypal; |
| |
| /** |
| * Donation Layout |
| * |
| * @var string |
| */ |
| protected $layout = ''; |
| |
| |
| /** |
| * Download Information |
| * |
| * @var array |
| */ |
| protected $download_info = array(); |
| |
| /** |
| * Class constructor |
| */ |
| public function __construct() { |
| // Initialize required helper classes |
| $this->App = new App(); |
| $this->Paypal = new Paypal(); |
| |
| // Set default layout |
| $this->setLayout('eclipsefdn-layout_a'); |
| |
| // Initialize $download_info |
| $this->download_info = array( |
| 'url' => '', |
| 'file_id' => '', |
| 'title' => '' |
| ); |
| } |
| |
| /** |
| * Set the desired layout |
| * |
| * A layout is always associated to a WG or foundation. |
| * This allows us to track where the donation money should go. |
| * |
| * @param string $layout The layout key |
| * |
| * @return string |
| */ |
| public function setLayout($layout = '') { |
| // layout_key|name => working group (donation tracking) |
| $valid_layouts = array( |
| 'eclipsefdn-layout_a' => 'eclipsefdn', |
| 'eclipsefdn-layout_b' => 'eclipsefdn', |
| 'eclipse_ide' => 'eclipse_ide', |
| 'ecdtools' => 'ecdtools', |
| 'adoptium' => 'adoptium', |
| 'openvsx' => 'openvsx', |
| ); |
| |
| // Standardize layout names without changing /downloads |
| if ($layout === 'layout_a' || $layout === 'layout_b') { |
| $layout = 'eclipsefdn-' . $layout; |
| } |
| |
| // Update layout if the value is valid |
| if (!empty($layout) && !empty($valid_layouts[$layout])) { |
| $this->layout = array($layout => $valid_layouts[$layout]); |
| } |
| return $this->layout; |
| } |
| |
| /** |
| * Get the desired layout |
| * |
| * @return array The key is the layout name and |
| * value is landing_page/wg for tracking purposes. |
| */ |
| public function getLayout() { |
| return $this->layout; |
| } |
| |
| /** |
| * Set Download Title |
| * |
| * @param string $title The download title |
| * |
| * @return string |
| */ |
| public function setDownloadTitle($title = '') { |
| if (!empty($title) && is_string($title)) { |
| $this->download_info['title'] = $title; |
| } |
| return $this->download_info['title']; |
| } |
| |
| /** |
| * Get Download Title |
| * |
| * @return string |
| */ |
| public function getDownloadTitle() { |
| return $this->download_info['title']; |
| } |
| |
| /** |
| * Set Download URL |
| * |
| * @param string $url The downloaded file |
| * |
| * @return string |
| */ |
| public function setDownloadUrl($url = '') { |
| if (!empty($url) && is_string($url)) { |
| $this->download_info['url'] = $url; |
| } |
| |
| return $this->download_info['url']; |
| } |
| |
| /** |
| * Get Download URL |
| * |
| * @return string |
| */ |
| public function getDownloadUrl() { |
| return $this->download_info['url']; |
| } |
| |
| /** |
| * Set Download file_id |
| * |
| * @param string $file_id The downloaded file id |
| * |
| * @return string |
| */ |
| public function setDownloadFileId($file_id = 0) { |
| if (!empty($file_id) && is_numeric($file_id)) { |
| $this->download_info['file_id'] = (string)$file_id; |
| } |
| |
| return $this->download_file_id; |
| } |
| |
| /** |
| * Get Download File ID |
| * |
| * @return string |
| */ |
| public function getDownloadFileId() { |
| return (string)$this->download_info['file_id']; |
| } |
| |
| /** |
| * Detect if this is a donation from our download page |
| * |
| * @return boolean |
| */ |
| public function isDownloadPage() { |
| // @todo: Consider including file_id |
| if (!empty($this->download_info['title']) && !empty($this->download_info['url'])) { |
| return TRUE; |
| } |
| return FALSE; |
| } |
| |
| /** |
| * Build the thank you for downloading section |
| * |
| * @return string |
| */ |
| public function getThankYouOutput() { |
| $html = ''; |
| if ($this->isDownloadPage()) { |
| $html = '<div class="container-thankyou"><div class="row thankyou text-center">'; |
| if ($title = $this->getDownloadTitle()) { |
| $html .= '<p class="thankyou-title">' . $title . '</p>'; |
| } |
| if ($url = $this->getDownloadUrl()) { |
| $html .= '<span class="direct-link">' . $url . '</span>'; |
| } |
| $html .= '</div></div>'; |
| } |
| return $html; |
| } |
| |
| /** |
| * Fetch content from template file |
| * |
| * @return string |
| */ |
| public function getLayoutTemplatePage($suffix = '') { |
| $layout = $this->getLayout(); |
| $current_layout = key($layout); |
| $path = realpath(dirname(__FILE__) . '/tpl/pages/' . $current_layout . $suffix . '.tpl.php'); |
| $html = ''; |
| if (file_exists($path)) { |
| ob_start(); |
| require_once($path); |
| $html = ob_get_clean(); |
| } |
| return $html; |
| } |
| |
| /** |
| * Build HTML for donation page |
| * |
| * @return string |
| */ |
| public function output() { |
| $html = $this->getThankYouOutput(); |
| ob_start(); |
| include('tpl/slider.tpl.php'); |
| include('tpl/modal.tpl.php'); |
| $html .= ob_get_clean(); |
| return $html; |
| } |
| |
| /** |
| * Get landing_page hidden input |
| * |
| * @return string |
| */ |
| public function getLandingPageInput() { |
| |
| $layout_info = $this->getLayout(); |
| $value = current($layout_info); |
| |
| if ($this->isDownloadPage()) { |
| $value = 'download'; |
| } |
| |
| return $this->_createHiddenInput("landing_page", $value); |
| } |
| |
| /** |
| * Get file_id hidden input |
| * |
| * @return string |
| */ |
| public function getFileIdInput() { |
| return $this->_createHiddenInput("file_id", $this->getDownloadFileId()); |
| } |
| |
| /** |
| * Get scope hidden input |
| * |
| * @return string |
| */ |
| public function getScopeInput() { |
| $value = ''; |
| |
| if (!empty($_GET['scope'])) { |
| $value = $_GET['scope']; |
| } |
| |
| if ($this->isDownloadPage()) { |
| $layout = $this->getLayout(); |
| $value = key($layout); |
| } |
| |
| return $this->_createHiddenInput("scope", $value); |
| } |
| |
| /** |
| * Get campaign hidden input |
| * |
| * @return string |
| */ |
| public function getCampaignInput() { |
| $value = ''; |
| |
| if (!empty($_GET['campaign'])) { |
| $value = $_GET['campaign']; |
| } |
| |
| // Override campaign value for our downloads section |
| if ($this->isDownloadPage()) { |
| $value = 'ab_testing'; |
| } |
| |
| return $this->_createHiddenInput("campaign", $value); |
| } |
| |
| /** |
| * Build hidden input field |
| * |
| * @return string |
| */ |
| private function _createHiddenInput($name = '', $value = '') { |
| $html = ''; |
| if (!empty($name) && !empty($value) && is_string($name) && is_string($value)) { |
| $html = '<input type="hidden" name="' . $this->App->checkPlain($name) . '" value="' . $this->App->checkPlain($value) . '">'; |
| } |
| return $html; |
| } |
| } |