source of /modules/HomePage/Controllers/HomePageController.php<?php /* * Copyright (C) 2017 Karmabunny Pty Ltd. * * This file is a part of SproutCMS. * * SproutCMS is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Foundation, either * version 2 of the License, or (at your option) any later version. * * For more information, visit <http://getsproutcms.com>. */ namespace SproutModules\Karmabunny\HomePage\Controllers; use Kohana; use SproutModules\Karmabunny\HarborAndSprout\Helpers\GoogleDriveApi; use SproutModules\Karmabunny\HomePage\Helpers\HomePages; use Sprout\Controllers\Controller; use Sprout\Helpers\Needs; use Sprout\Helpers\View; /** * Handles requests for the home page */ class HomePageController extends Controller { /** * Renders the home page * * @return void Outputs HTML directly */ public function index() { $page = HomePages::getForSubSite(0); $browser_title = Kohana::config('sprout.site_title'); $icons = ['application/vnd.google-apps.folder' => 'folder2-open', 'application/pdf' => 'file-earmark-pdf']; $files = []; if (!empty($page['alt_browser_title'])) $browser_title = $page['alt_browser_title']; if (!empty($page['meta_keywords'])) Needs ::addMeta('keywords', $page['meta_keywords']); if (!empty($page['meta_description'])) Needs ::addMeta('description', $page['meta_description']); if (empty($_GET['folder'])) $_GET['folder'] = '1gj7YMz4oiYr59wILrNiVeSnwM0vt5Dos'; $params = ['q' => sprintf("'%s' in parents", $_GET['folder'])]; $response = GoogleDriveApi::apiRequest('GET', GoogleDriveApi::$domain . '/files', $params); if (!empty($response['files']) and count($response['files'])) { foreach ($response['files'] as $file) { { $files[] = [ 'id' => $file['id'], 'icon' => $icons[$file['mimeType']], 'name' => $file['name'], 'url' => $file['mimeType'] == 'application/vnd.google-apps.folder' ? sprintf('?folder=%s', $file['id']): null, ]; } } } $view = new View('skin/home'); $view->browser_title = $browser_title; $view->page = $page; $view->files = $files; echo $view->render(); } }
|