| 1 | <?php |
|---|
| 2 | // wcf imports |
|---|
| 3 | require_once(WCF_DIR.'lib/page/util/menu/HeaderMenuContainer.class.php'); |
|---|
| 4 | require_once(WCF_DIR.'lib/page/util/menu/UserCPMenuContainer.class.php'); |
|---|
| 5 | |
|---|
| 6 | /** |
|---|
| 7 | * This class extends the main WCF class by gewinnspiel specific functions. |
|---|
| 8 | * |
|---|
| 9 | * @author Robert "Tatzelwurm" Hempel |
|---|
| 10 | * @copyright 2007/2008 INSIDE das Hrspiel |
|---|
| 11 | * @license GNU LGPL http://www.gnu.org/licenses/lgpl.txt |
|---|
| 12 | * @package de.inside.Gewinnspiel |
|---|
| 13 | */ |
|---|
| 14 | class GWSPCore extends WCF implements HeaderMenuContainer, UserCPMenuContainer { |
|---|
| 15 | |
|---|
| 16 | protected $games = array(); |
|---|
| 17 | |
|---|
| 18 | protected static $headerMenuObj = null; |
|---|
| 19 | protected static $userCPMenuObj = null; |
|---|
| 20 | protected static $styleObj; |
|---|
| 21 | |
|---|
| 22 | public static $availablePagesDuringOfflineMode = array( |
|---|
| 23 | 'page' => array('Captcha', 'LegalNotice', 'Help'), |
|---|
| 24 | 'form' => array('UserLogin'), |
|---|
| 25 | 'action' => array()); |
|---|
| 26 | |
|---|
| 27 | /** |
|---|
| 28 | * @see WCF::initTPL() |
|---|
| 29 | */ |
|---|
| 30 | protected function initTPL() { |
|---|
| 31 | // init style to get template pack id |
|---|
| 32 | $this->initStyle(); |
|---|
| 33 | |
|---|
| 34 | global $packageDirs; |
|---|
| 35 | require_once(WCF_DIR.'lib/system/template/StructuredTemplate.class.php'); |
|---|
| 36 | self::$tplObj = new StructuredTemplate(self::getStyle()->templatePackID, self::getLanguage()->getLanguageID(), ArrayUtil::appendSuffix($packageDirs, 'templates/')); |
|---|
| 37 | $this->assignDefaultTemplateVariables(); |
|---|
| 38 | |
|---|
| 39 | // init cronjobs |
|---|
| 40 | $this->initCronjobs(); |
|---|
| 41 | |
|---|
| 42 | // check offline mode |
|---|
| 43 | if (OFFLINE && !self::getUser()->getPermission('user.gewinnspiel.canViewGWSOffline')) { |
|---|
| 44 | $showOfflineError = true; |
|---|
| 45 | foreach (self::$availablePagesDuringOfflineMode as $type => $names) { |
|---|
| 46 | if (isset($_REQUEST[$type])) { |
|---|
| 47 | foreach ($names as $name) { |
|---|
| 48 | if ($_REQUEST[$type] == $name) { |
|---|
| 49 | $showOfflineError = false; |
|---|
| 50 | break 2; |
|---|
| 51 | } |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | break; |
|---|
| 55 | } |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | if ($showOfflineError) { |
|---|
| 59 | self::getTPL()->display('offline'); |
|---|
| 60 | exit; |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | // user ban |
|---|
| 65 | if (self::getUser()->banned && (!isset($_REQUEST['page']) || $_REQUEST['page'] != 'LegalNotice')) { |
|---|
| 66 | require_once(WCF_DIR.'lib/system/exception/PermissionDeniedException.class.php'); |
|---|
| 67 | throw new PermissionDeniedException(); |
|---|
| 68 | } |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | /** |
|---|
| 72 | * Initialises the cronjobs. |
|---|
| 73 | */ |
|---|
| 74 | protected function initCronjobs() { |
|---|
| 75 | self::getTPL()->assign('executeCronjobs', WCF::getCache()->get('cronjobs-'.PACKAGE_ID, 'nextExec') < TIME_NOW); |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | /** |
|---|
| 79 | * @see WCF::loadDefaultCacheResources() |
|---|
| 80 | */ |
|---|
| 81 | protected function loadDefaultCacheResources() { |
|---|
| 82 | parent::loadDefaultCacheResources(); |
|---|
| 83 | WCF::getCache()->addResource('pageLocations-'.PACKAGE_ID, WCF_DIR.'cache/cache.pageLocations-'.PACKAGE_ID.'.php', WCF_DIR.'lib/system/cache/CacheBuilderPageLocations.class.php'); |
|---|
| 84 | WCF::getCache()->addResource('bbcodes', WCF_DIR.'cache/cache.bbcodes.php', WCF_DIR.'lib/system/cache/CacheBuilderBBCodes.class.php'); |
|---|
| 85 | WCF::getCache()->addResource('smilies', WCF_DIR.'cache/cache.smilies.php', WCF_DIR.'lib/system/cache/CacheBuilderSmilies.class.php'); |
|---|
| 86 | WCF::getCache()->addResource('cronjobs-'.PACKAGE_ID, WCF_DIR.'cache/cache.cronjobs-'.PACKAGE_ID.'.php', WCF_DIR.'lib/system/cache/CacheBuilderCronjobs.class.php'); |
|---|
| 87 | WCF::getCache()->addResource('help-'.PACKAGE_ID, WCF_DIR.'cache/cache.help-'.PACKAGE_ID.'.php', WCF_DIR.'lib/system/cache/CacheBuilderHelp.class.php'); |
|---|
| 88 | WCF::getCache()->addResource('competition-user-'.PACKAGE_ID, GWSP_DIR.'cache/competition.user-'.PACKAGE_ID.'.php', GWSP_DIR.'lib/system/cache/CacheBuilderGWSPUser.class.php'); |
|---|
| 89 | WCF::getCache()->addResource('competition-games-'.PACKAGE_ID, GWSP_DIR.'cache/competition.games-'.PACKAGE_ID.'.php', GWSP_DIR.'lib/system/cache/CacheBuilderGWSPGames.class.php'); |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | /** |
|---|
| 93 | * Initialises the page header menu. |
|---|
| 94 | */ |
|---|
| 95 | protected static function initHeaderMenu() { |
|---|
| 96 | require_once(WCF_DIR.'lib/page/util/menu/HeaderMenu.class.php'); |
|---|
| 97 | self::$headerMenuObj = new HeaderMenu(); |
|---|
| 98 | if (HeaderMenu::getActiveMenuItem() == '') HeaderMenu::setActiveMenuItem('gws.header.menu.gamemenue'); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | /** |
|---|
| 102 | * Initialises the page header menu. |
|---|
| 103 | */ |
|---|
| 104 | protected static function initUserCPMenu() { |
|---|
| 105 | require_once(WCF_DIR.'lib/page/util/menu/UserCPMenu.class.php'); |
|---|
| 106 | self::$userCPMenuObj = UserCPMenu::getInstance(); |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | /** |
|---|
| 110 | * @see WCF::getOptionsFilename() |
|---|
| 111 | */ |
|---|
| 112 | protected function getOptionsFilename() { |
|---|
| 113 | return GWSP_DIR.'options.inc.php'; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | /** |
|---|
| 117 | * Initialises the style system. |
|---|
| 118 | */ |
|---|
| 119 | protected function initStyle() { |
|---|
| 120 | if (isset($_GET['styleID'])) { |
|---|
| 121 | self::getSession()->setStyleID(intval($_GET['styleID'])); |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | $this->changeStyle(self::getSession()->getStyleID()); |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | /** |
|---|
| 128 | * Changes the active style. |
|---|
| 129 | * |
|---|
| 130 | * @param integer $styleID |
|---|
| 131 | */ |
|---|
| 132 | public static final function changeStyle($styleID) { |
|---|
| 133 | require_once(WCF_DIR.'lib/system/style/Style.class.php'); |
|---|
| 134 | self::$styleObj = new Style($styleID); |
|---|
| 135 | |
|---|
| 136 | if (self::getTPL()) { |
|---|
| 137 | self::getTPL()->setTemplatePackID(self::getStyle()->templatePackID); |
|---|
| 138 | } |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | /** |
|---|
| 142 | * @see HeaderMenuContainer::getHeaderMenu() |
|---|
| 143 | */ |
|---|
| 144 | public static final function getHeaderMenu() { |
|---|
| 145 | if (self::$headerMenuObj === null) { |
|---|
| 146 | self::initHeaderMenu(); |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | return self::$headerMenuObj; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | /** |
|---|
| 153 | * @see UserCPMenuContainer::getUserCPMenu() |
|---|
| 154 | */ |
|---|
| 155 | public static final function getUserCPMenu() { |
|---|
| 156 | if (self::$userCPMenuObj === null) { |
|---|
| 157 | self::initUserCPMenu(); |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | return self::$userCPMenuObj; |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | /** |
|---|
| 164 | * Returns the active style object. |
|---|
| 165 | * |
|---|
| 166 | * @return Style |
|---|
| 167 | */ |
|---|
| 168 | public static final function getStyle() { |
|---|
| 169 | return self::$styleObj; |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | /** |
|---|
| 173 | * @see WCF::initSession() |
|---|
| 174 | */ |
|---|
| 175 | protected function initSession() { |
|---|
| 176 | // start session |
|---|
| 177 | require_once(GWSP_DIR.'lib/system/session/GWSPSessionFactory.class.php'); |
|---|
| 178 | $factory = new GWSPSessionFactory(); |
|---|
| 179 | self::$sessionObj = $factory->get(); |
|---|
| 180 | self::$userObj = self::getSession()->getUser(); |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | /** |
|---|
| 184 | * @see WCF::assignDefaultTemplateVariables() |
|---|
| 185 | */ |
|---|
| 186 | protected function assignDefaultTemplateVariables() { |
|---|
| 187 | parent::assignDefaultTemplateVariables(); |
|---|
| 188 | self::getTPL()->assign('timezone', DateUtil::getTimezone()); |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | } |
|---|
| 192 | ?> |
|---|