function render() { # Make sure the result is set to 'not comitted' per default $result = new Dto_FormResult('notsubmitted'); # Validate proper permissions $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_post_comment, ''); $spotParseUtil = new Services_Format_Util(); $spotSigning = Services_Signing_Base::factory(); $svcUserRecord = new Services_User_Record($this->_daoFactory, $this->_settings); /* * Make sure we have the template for the comment form * so our view can always render properties */ $comment = array('body' => '', 'rating' => 0, 'inreplyto' => $this->_inReplyTo, 'newmessageid' => '', 'randomstr' => ''); # set the page title $this->_pageTitle = "spot: post comment"; /* * bring the forms' action into the local scope for * easier access */ $formAction = $this->_commentForm['action']; if ($formAction == 'post') { # Make sure we use valid forms $comment = array_merge($comment, $this->_commentForm); # validate whether we can post comments, if so, do this $svcPostComment = new Services_Posting_Comment($this->_daoFactory, $this->_settings); $result = $svcPostComment->postComment($svcUserRecord, $this->_currentSession['user'], $comment); if ($result->isSuccess()) { /* Format the body so we can have smilies and stuff be shown in the template */ $tmpBody = $this->_tplHelper->formatContent($comment['body']); /* Try to create the avatar */ if (!empty($this->_currentSession['user']['avatar'])) { $comment['user-avatar'] = $this->_currentSession['user']['avatar']; } else { $comment['user-key'] = $spotSigning->getPublicKey($this->_currentSession['user']['publickey']); } # else $commentImage = $this->_tplHelper->makeCommenterImageUrl($comment); /* and return the result to the system */ $result->addData('user', $this->_currentSession['user']['username']); $result->addData('spotterid', $spotParseUtil->calculateSpotterId($comment['user-key']['modulo'])); $result->addData('rating', $comment['rating']); $result->addData('body', $tmpBody); $result->addData('commentimage', $commentImage); } # if } # if #- display stuff -# $this->template('postcomment', array('postcommentform' => $comment, 'result' => $result)); }
function render() { # Make sure the result is set to 'not comited' per default $result = new Dto_FormResult('notsubmitted'); # Validate proper permissions $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_post_spot, ''); # Sportparser is nodig voor het escapen van de random string $spotParseUtil = new Services_Format_Util(); # we need the spotuser system $svcUserRecord = new Services_User_Record($this->_daoFactory, $this->_settings); /* * Create a default form so we can be sure to always be able * to render the form without notices or whatever */ $spot = array('title' => '', 'body' => '', 'category' => 0, 'subcata' => '', 'subcatb' => array(), 'subcatc' => array(), 'subcatd' => array(), 'subcatz' => '', 'tag' => '', 'website' => '', 'newmessageid' => '', 'randomstr' => ''); /* * bring the forms' action into the local scope for * easier access */ $formAction = $this->_spotForm['action']; # set the page title $this->_pageTitle = "spot: post"; # Make sure all variables are merged with the default form $spot = array_merge($spot, $this->_spotForm); # If user tried to submit, validate the file uploads $nzbFilename = ''; $imgFilename = ''; if ($formAction == 'post') { $result->setResult('success'); # Make sure an NZB file was provided $uploadHandler = new Services_Providers_FileUpload('newspotform', 'nzbfile'); if (!$uploadHandler->isUploaded()) { $result->addError(_('Please select NZB file')); } elseif (!$uploadHandler->success()) { $result->addError(_('Invalid NZB file') . ' (' . $uploadHandler->errorText() . ')'); } else { $nzbFilename = $uploadHandler->getTempName(); } # if # Make sure an picture was provided $uploadHandler = new Services_Providers_FileUpload('newspotform', 'imagefile'); if (!$uploadHandler->isUploaded()) { $result->addError(_('Please select a picture')); } elseif (!$uploadHandler->success()) { $result->addError(_('Invalid picture') . ' (' . $uploadHandler->errorText() . ')'); } else { $imgFilename = $uploadHandler->getTempName(); } # if } # if if ($formAction == 'post' && $result->isSuccess()) { # Initialize notificatiesystem $spotsNotifications = new SpotNotifications($this->_daoFactory, $this->_settings, $this->_currentSession); # Make sure we can post this spot, if so, make it happen $svcPostSpot = new Services_Posting_Spot($this->_daoFactory, $this->_settings); $result = $svcPostSpot->postSpot($svcUserRecord, $this->_currentSession['user'], $spot, $imgFilename, $nzbFilename); if ($result->isSuccess()) { $result->addData('user', $this->_currentSession['user']['username']); $result->addData('spotterid', $spotParseUtil->calculateSpotterId($this->_currentSession['user']['publickey']['modulo'])); # en send a notification $spotsNotifications->sendSpotPosted($spot); } # if } # if #- display stuff -# $this->template('newspot', array('postspotform' => $spot, 'result' => $result)); }
function getCleanRandomString($len) { $spotParseUtil = new Services_Format_Util(); $spotSigning = Services_Signing_Base::factory(); return substr($spotParseUtil->spotPrepareBase64(base64_encode($spotSigning->makeRandomStr($len))), 0, $len); }