3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface EventListener { /** * Executes this action. * * @param object $eventObj * @param string $className * @param string $eventName */ public function execute($eventObj, $className, $eventName); } /** * Handles activation of the thank'o'mat in postcreation and editing * * @author Christian "Plunts" Grubert * @copyright 2010 Duetschi Kreativagentur * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> * @package de.wbb3mods.wbb.thankbot */ class ThreadAddFormThankBotListener implements EventListener { const THANKS_AUTOENABLE_NONE = 0; const THANKS_AUTOENABLE_THREAD = 1; const THANKS_AUTOENABLE_ALL = 2; protected $eventObj; protected $className; protected $hasThank = -1; protected $saveThankSetting = false; protected $autoEnableThankomat = -1; /** * @see EventListener::execute() */ public function execute($eventObj, $className, $eventName) { $this->eventObj = $eventObj; $this->className = $className; if ($this->autoEnableThankomat == -1) { $this->autoEnableThankomat = THANKS_AUTOENABLE; if ($this->autoEnableThankomat > 0) { // check if thankomat is only disabled for this forum! if (WCF::getUser()->getPermission('user.board.canActivateThank') && !$this->eventObj->board->getPermission('canActivateThank')) { // global right = true, board right = false $this->autoEnableThankomat = 0; } } if (THANKS_ALLOW_SAVE_AUTOENABLE) { $userOption = WCF::getUser()->autoEnableThankomat; if ($userOption > 0) { $this->autoEnableThankomat = $userOption - 1; } } } switch ($eventName) { case 'readData': $this->readData(); break; case 'readFormParameters': $this->readFormParameters(); break; case 'assignVariables': $this->assignVariables(); break; case 'saved': $this->saved(); break; } } private function checkHasThank() { if ($this->hasThank == -1) { if ($this->autoEnableThankomat == self::THANKS_AUTOENABLE_THREAD && ($this->className == 'ThreadAddForm' || (isset($this->eventObj->post, $this->eventObj->thread) && $this->eventObj->post->postID == $this->eventObj->thread->firstPostID))) $this->hasThank = 1; elseif ($this->autoEnableThankomat == self::THANKS_AUTOENABLE_ALL) $this->hasThank = 1; else $this->hasThank = 0; } } private function readData() { if (!count($_POST)) { $this->hasThank = $this->eventObj->post->hasThank; } } private function readFormParameters() { $this->checkHasThank(); if ($this->eventObj->board->getPermission('canActivateThank') && $this->className != 'PostQuickAddForm') { if (isset($_REQUEST['hasThank'])) $this->hasThank = intval($_REQUEST['hasThank']); else $this->hasThank = 0; } if (isset($_REQUEST['saveThankSetting'])) $this->saveThankSetting = (intval($_REQUEST['saveThankSetting']) != 0); } private function assignVariables() { if (THANKS_FIRSTPOSTONLY && $this->className != 'ThreadAddForm' && (!isset($this->eventObj->postID) || $this->eventObj->postID != $this->eventObj->thread->firstPostID)) { return; } if ($this->eventObj->board->getPermission('canActivateThank')) { $this->checkHasThank(); WCF::getTPL()->assign(array( 'hasThank' => $this->hasThank, 'saveThankSetting' => $this->saveThankSetting, 'autoEnableThankomat' => $this->autoEnableThankomat )); $additionalSettings = WCF::getTPL()->fetch('postThankSetting'); WCF::getTPL()->append(THANKS_POSITION, $additionalSettings); } } private function saved() { if (THANKS_FIRSTPOSTONLY && $this->className != 'ThreadAddForm' && (!isset($this->eventObj->postID) || $this->eventObj->postID != $this->eventObj->thread->firstPostID)) { return; } // Bedanko beim bearbeiten nicht deaktivieren, wenn die Rechte fehlen! if ($this->className == 'PostEditForm' && !$this->eventObj->board->getPermission('canActivateThank')) { return; } $postID = 0; switch ($this->className) { case 'ThreadAddForm': $postID = $this->eventObj->newThread->firstPostID; break; case 'PostAddForm': case 'PostQuickAddForm': $postID = $this->eventObj->newPost->postID; break; case 'PostEditForm': $postID = $this->eventObj->postID; break; } $sql = "UPDATE wbb" . WBB_N . "_post SET hasThank = " . intval($this->hasThank) . " WHERE postID = " . intval($postID); WCF::getDB()->sendQuery($sql); if (THANKS_ALLOW_SAVE_AUTOENABLE && $this->saveThankSetting) { WCF::getUser()->getEditor()->updateOptions(array( 'autoEnableThankomat' => $this->hasThank == 0 ? self::THANKS_AUTOENABLE_NONE + 1 : self::THANKS_AUTOENABLE_ALL + 1 )); } } } ?>
Output for git.master, git.master_jit, rfc.property-hooks

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
67.15 ms | 401 KiB | 8 Q