SproutCMS

This is the code documentation for the SproutCMS project

source of /modules/HomePage/Controllers/HomePageController.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace SproutModules\Karmabunny\HomePage\Controllers;
  15.  
  16. use Kohana;
  17.  
  18. use SproutModules\Karmabunny\HarborAndSprout\Helpers\GoogleDriveApi;
  19. use SproutModules\Karmabunny\HomePage\Helpers\HomePages;
  20. use Sprout\Controllers\Controller;
  21. use Sprout\Helpers\Needs;
  22. use Sprout\Helpers\View;
  23.  
  24.  
  25. /**
  26.  * Handles requests for the home page
  27.  */
  28. class HomePageController extends Controller
  29. {
  30. /**
  31.   * Renders the home page
  32.   *
  33.   * @return void Outputs HTML directly
  34.   */
  35. public function index()
  36. {
  37. $page = HomePages::getForSubSite(0);
  38. $browser_title = Kohana::config('sprout.site_title');
  39. $icons = ['application/vnd.google-apps.folder' => 'folder2-open', 'application/pdf' => 'file-earmark-pdf'];
  40. $files = [];
  41.  
  42. if (!empty($page['alt_browser_title'])) $browser_title = $page['alt_browser_title'];
  43. if (!empty($page['meta_keywords'])) Needs::addMeta('keywords', $page['meta_keywords']);
  44. if (!empty($page['meta_description'])) Needs::addMeta('description', $page['meta_description']);
  45.  
  46. if (empty($_GET['folder'])) $_GET['folder'] = '1gj7YMz4oiYr59wILrNiVeSnwM0vt5Dos';
  47.  
  48. $params = ['q' => sprintf("'%s' in parents", $_GET['folder'])];
  49.  
  50. $response = GoogleDriveApi::apiRequest('GET', GoogleDriveApi::$domain . '/files', $params);
  51.  
  52. if (!empty($response['files']) and count($response['files']))
  53. {
  54. foreach ($response['files'] as $file)
  55. {
  56. if (array_key_exists($file['mimeType'], $icons))
  57. {
  58. $files[] = [
  59. 'id' => $file['id'],
  60. 'icon' => $icons[$file['mimeType']],
  61. 'name' => $file['name'],
  62. 'url' => $file['mimeType'] == 'application/vnd.google-apps.folder' ? sprintf('?folder=%s', $file['id']): null,
  63. ];
  64. }
  65. }
  66. }
  67.  
  68. $view = new View('skin/home');
  69. $view->browser_title = $browser_title;
  70. $view->page = $page;
  71. $view->files = $files;
  72.  
  73. echo $view->render();
  74. }
  75. }
  76.