protected function returnResult()
 {
     if (Request::isAjax()) {
         Responder::sendJSON(array());
     }
     Responder::redirectToPage();
 }
 protected function main()
 {
     d('cp');
     $o = new RegBlockQuickReg($this->Registry);
     $s = $o->getBlock();
     $aRet = array('quickreg' => $s);
     Responder::sendJSON($aRet);
 }
 protected function returnResult()
 {
     if (Request::isAjax()) {
         $ret = array('alert' => '@@Approved@@');
         $ret['reload'] = 1000;
         Responder::sendJSON($ret);
         exit;
     }
     Responder::redirectToPage();
 }
Exemple #4
0
 protected function setReturn()
 {
     if (Request::isAjax()) {
         $ret = array('alert' => 'User group updated', 'reload' => 1000);
         Responder::sendJSON($ret);
     }
     Responder::redirectToPage();
 }
Exemple #5
0
 /**
  * Validates the value of form token
  * passed in form against the one stored in SESSION
  *
  * @todo validate (store it first) IP address
  * of request that it must match ip when token is validate
  * and throw special type of Exception so that a user will
  * get explanation that IP address has changed
  *
  * @param string $token value as passed in the submitted form
  * @return true of success
  * @throws LampcmsException if validation fails
  */
 protected function validateToken($token = null)
 {
     $message = '';
     $token = null === $token && !empty($this->Request['token']) ? $this->Request['token'] : $token;
     if (empty($_SESSION['secret'])) {
         d("No token in SESSION ");
         /**
          * @todo
          * Translate String
          */
         $message = 'Form_token_missing';
     } elseif ($_SESSION['secret'] !== $token) {
         d('session token: ' . $_SESSION['secret'] . ' supplied token: ' . $token);
         $message = 'wrong form token';
     }
     if (!empty($message)) {
         if (Request::isAjax()) {
             Responder::sendJSON(array('exception' => $message));
         }
         throw new TokenException($message);
     }
     return true;
 }
 /**
  *
  */
 protected function validateCaptcha()
 {
     if (!empty($_SESSION['reg_captcha'])) {
         return $this;
     }
     $oCaptcha = Captcha::factory($this->Registry->Ini);
     $res = $oCaptcha->validate_submit();
     /**
      * If validation good then
      * all is OK
      */
     if (1 === $res) {
         $_SESSION['reg_captcha'] = true;
         return $this;
     }
     /**
      * If 3 then reached the limit of attempts
      */
     if (3 === $res) {
         throw new \Lampcms\CaptchaLimitException('@@You have reached the limit of image verification attempts@@');
     }
     $aRet = array('exception' => '@@Incorrect image verification text@@<br/>@@Please try again@@', 'fields' => array('private_key'), 'captcha' => $oCaptcha->getCaptchaArray());
     Responder::sendJSON($aRet);
 }
 protected function returnResult()
 {
     $message = '@@Thank you for caring!<br>Moderators have been notified@@';
     if (Request::isAjax()) {
         Responder::sendJSON(array('alert' => $message));
     }
     Responder::redirectToPage($this->Resource->getUrl());
 }
Exemple #8
0
    protected function returnResult()
    {
        /**
         * @todo translate string
         */
        $message = '@@Question closed@@';
        $requested = 'A request to close
		this question has been sent to moderators<br>
		The final decision about closing the question or leaving it open will be up to moderators';
        if (Request::isAjax()) {
            $res = !$this->requested ? $message : $requested;
            $ret = array('alert' => $res);
            /**
             * If item was actually deleted then
             * add 'reload' => 2 to return
             * which will cause page reload
             * in 1.5 seconds.
             */
            if (!$this->requested) {
                $ret['reload'] = 1500;
            }
            Responder::sendJSON($ret);
        }
        Responder::redirectToPage($this->Resource->getUrl());
    }
 protected function handleReturn()
 {
     $isAjax = Request::isAjax();
     d('$isAjax: ' . $isAjax);
     if ($isAjax) {
         $ret = array('vote' => array('v' => $this->Resource->getScore(), 't' => $this->resType, 'rid' => $this->resID));
         Responder::sendJSON($ret);
     }
     Responder::redirectToPage($this->Resource->getUrl());
 }
 protected function processForm()
 {
     $formData = $this->Registry->Request->getArray();
     if (!empty($_FILES)) {
         $formData['files'] = $_FILES;
     }
     $Notification = $this->Registry->Dispatcher->post($this, 'onBeforeCategoryEdit', array('data' => $formData));
     if (!$Notification->isNotificationCancelled()) {
         try {
             $this->checkAccessPermission('edit_category');
             $canEdit = true;
         } catch (\Exception $e) {
             $canEdit = false;
         }
         /**
          * @todo when YUI 3.5.0 is released with fixed
          * upload-iframe or even better with XHR2 with upload support
          * we will either return a page with json here (in case of iframe)
          * or just add processing of uploaded file.
          */
         d('before start of Editor');
         if (Request::isAjax()) {
             d('sending out ajax');
             $Editor = new \Lampcms\Category\Editor($this->Registry);
             $aRes = $Editor->saveCategory(new \Lampcms\Category\SubmittedWWW($this->Registry->Request), $canEdit);
             $aRes = \array_diff_key($aRes, array('i_parent' => 1, 'a_subs' => 1));
             d('aRes: ' . print_r($aRes, 1));
             Responder::sendJSON(array('category' => $aRes));
         }
     } else {
         $message = '@@One of the Observers cancelled the onBeforeCategoryEdit event@@';
         d($message);
         Responder::sendJSON(array('alert' => $message));
     }
     return '@@Category data saved@@';
 }
Exemple #11
0
 /**
  * No cache headers for this page but
  * if this is an ajax request then return
  * the html we have so far as it does not make
  * sense to process any further methods
  *
  * @see wwwViewquestions::sendCacheHeaders()
  */
 protected function sendCacheHeaders()
 {
     if (Request::isAjax()) {
         $sQdivs = \tplTagslist::loop($this->Cursor);
         Responder::sendJSON(array('paginated' => '<div class="tags_wrap">' . $sQdivs . $this->pagerLinks . '</div>'));
     }
     return $this;
 }
Exemple #12
0
 public function main()
 {
     /**
      * Will not check for the valid 'form token'
      * in this form because potential
      * hacher has nothing to gain by
      * exploiting CSRF of a login form because
      * the user using this form is be definition
      * 'not yet logged in', so there is really
      * nothing to gain by tricking someonw to login
      */
     $bRemember = isset($this->Request['chkRemember']) ? (bool) $this->Request['chkRemember'] : false;
     d('$bRemember ' . $bRemember . ' $this->Request ' . print_r($this->Request->getArrayCopy(), 1));
     try {
         $oCheckLogin = new UserAuth($this->Registry);
         $User = $oCheckLogin->validateLogin($this->Request['login'], $this->Request['pwd']);
         /**
          * If user logged in that means he got the email
          * with password,
          * thus we confirmed email address
          * and can activate user
          */
         $User->activate();
     } catch (\Lampcms\LoginException $e) {
         /**
          * @todo may add extra setting to !config.ini to send login errors
          * to special dedicated email address that will receive all security (hacking attempts)
          * related errors.
          */
         d('Login error: ' . $e->getMessage() . ' in file: ' . $e->getFile() . ' on line: ' . $e->getLine());
         if (Request::isAjax()) {
             Responder::sendJSON(array('error' => $e->getMessage()));
         }
         $_SESSION['login_error'] = $e->getMessage();
         d('$_SESSION[login_error] ' . $_SESSION['login_error']);
         Responder::redirectToPage();
     }
     d('User: '******'onUserLogin');
     if ($bRemember) {
         \Lampcms\Cookie::sendLoginCookie($User->getUid(), $User['rs']);
     }
     Responder::redirectToPage();
 }
Exemple #13
0
 protected function returnErrors()
 {
     d('cp');
     if (Request::isAjax()) {
         d('cp');
         $aErrors = $this->Form->getErrors();
         Responder::sendJSON(array('formErrors' => $aErrors));
     }
     $this->makeTopTabs()->makeMemo()->setForm();
 }
 /**
  * Sends out json-encoded array of answers to browser
  */
 protected function setReturn()
 {
     Responder::sendJSON(array('paginated' => $this->answers));
 }
Exemple #15
0
    protected function returnResult()
    {
        /**
         * @todo translate string
         */
        $message = '@@Item deleted@@';
        $requested = 'You cannot delete question that already has answers.<br>A request to delete
		this question has been sent to moderators<br>
		It will be up to moderators to either delete or edit or close the question';
        if (Request::isAjax()) {
            $res = !$this->requested ? $message : $requested;
            $ret = array('alert' => $res);
            if (!empty($this->posterDetails)) {
                $ret['alert'] .= $this->posterDetails;
            } else {
                /**
                 * If item was actually deleted then
                 * add 'reload' => 2 to return
                 * which will cause page reload
                 * in 1.5 seconds.
                 */
                if (!$this->requested) {
                    $ret['reload'] = 1500;
                }
            }
            Responder::sendJSON($ret);
        }
        Responder::redirectToPage($this->Resource->getUrl());
    }
Exemple #16
0
 protected function returnResult()
 {
     if (Request::isAjax()) {
         $message = '@@User Shredded@@<hr>@@Banned IPs@@:' . implode('<br>', array_keys($this->aIPs)) . '<hr><br>@@Countries@@: ' . implode('<br>', array_keys($this->aCountries));
         Responder::sendJSON(array('alert' => $message));
     }
     Responder::redirectToPage();
 }
Exemple #17
0
 /**
  *
  */
 protected function validateCaptcha()
 {
     if (!empty($_SESSION['reg_captcha'])) {
         return $this;
     }
     $oCaptcha = Captcha::factory($this->Registry->Ini);
     $res = $oCaptcha->validate_submit();
     /**
      * If validation good then
      * all is OK
      */
     if (1 === $res) {
         $_SESSION['reg_captcha'] = true;
         return $this;
     }
     /**
      * If 3 then reached the limit of attampts
      */
     if (3 === $res) {
         throw new \Lampcms\CaptchaLimitException('You have reached the limit of image verification attempts');
     }
     if (Request::isAjax()) {
         $aRet = array('exception' => self::CAPTCHA_ERROR, 'fields' => array('private_key'), 'captcha' => $oCaptcha->getCaptchaArray());
         \Lampcms\Responder::sendJSON($aRet);
     }
     /**
      * @todo translate string
      */
     $this->setFormError(self::CAPTCHA_ERROR);
     return $this;
 }
 /**
  * Get paginated and sorted block with user
  * Answers and returl via XHR
  *
  */
 protected function getAnswers()
 {
     d('getting answers block');
     $s = \Lampcms\UserAnswers::get($this->Registry, $this->User);
     Responder::sendJSON(array('replace' => array('target' => 'useranswers', 'content' => $s)));
 }
Exemple #19
0
 protected function main()
 {
     $this->pageID = $this->Registry->Router->getPageID();
     $this->init()->getCursor()->paginate()->renderUsersHtml();
     /**
      * In case of Ajax request, just return
      * the content of the usersHtml
      * and don't proceed any further
      */
     if (Request::isAjax()) {
         Responder::sendJSON(array('paginated' => $this->usersHtml));
     }
     $this->setTitle()->makeSortTabs()->makeTopTabs()->setUsers();
 }
Exemple #20
0
 /**
  * Set error message for the form as a whole.
  * This error message is not specific to any form field,
  * it usually appears on top of form as a general error message
  *
  * For example: You must wait 5 minutes between posting
  * This is not due to any element error, just a general error
  * message.
  *
  * The form template MUST have 'formError' variable in it!
  *
  * @param string $errMessage
  *
  * @return \Lampcms\Forms\Form
  */
 public function setFormError($errMessage)
 {
     if (Request::isAjax()) {
         \Lampcms\Responder::sendJSON(array('formError' => $errMessage));
     } else {
         $this->aErrors['formError'][] = $errMessage;
     }
     return $this;
 }
Exemple #21
0
 /**
  * Main entry point
  * (non-PHPdoc)
  *
  * @see WebPage::main()
  */
 protected function main()
 {
     $this->qid = $this->Router->getNumber(1, null, $this->Registry->Ini['URI_PARTS']['QID_PREFIX']);
     if (Request::isAjax()) {
         $this->getQuestion()->getAnswers();
         Responder::sendJSON(array('paginated' => $this->answers));
     }
     $this->pageID = $this->Router->getPageID();
     $this->tab = $this->Registry->Request->get('sort', 's', 'i_lm_ts');
     $this->Registry->registerObservers();
     $this->getQuestion()->validateSlug()->addMetas()->sendCacheHeaders()->configureEditor()->setTitle()->addMetaTags()->setAnswersHeader()->getAnswers()->setAnswers()->setSimilar()->makeForm()->setAnswerForm()->makeFollowButton()->setFollowersBlock()->setQuestionInfo()->setFooter()->increaseView()->makeTopTabs();
     $this->Registry->Dispatcher->post($this->Question, 'onQuestionView');
 }
Exemple #22
0
 /**
  * Return array of resourceID, type (A or Q)
  * and parsed div with comment
  *
  *
  */
 protected function returnResult()
 {
     $aComment = $this->CommentParser->getArrayCopy();
     /**
      * Add edit and delete tools because
      * Viewer already owns this comment and is
      * allowed to edit or delete it right away.
      * Javascript that usually dynamically adds these tools
      * is not going to be fired, so these tools
      * must alreayd be included in the returned html
      *
      */
     $aComment['edit_delete'] = '  <span class="ico del ajax" title="Delete">delete</span> <span class="ico edit ajax" title="Edit">edit</span>';
     /**
      * Important to add owner_id key
      * because it's not in the comment array
      * It is used when creating the 'reply' link
      * in the tplComment
      * That ID is then used when figuring out if
      * viewer has permission to add comment.
      * Users with low reputation still always have
      * premission to add comments to own resources.
      * 
      */
     $aComment['owner_id'] = $this->Resource->getOwnerId();
     $aRet = array('comment' => array('id' => $aComment['_id'], 'res' => $aComment['i_res'], 'parent' => $aComment['i_prnt'], 'html' => \tplComment::parse($aComment)));
     Responder::sendJSON($aRet);
 }
 protected function returnResult()
 {
     /**
      * @todo translate string
      */
     $message = 'Topic retagged successfully';
     if (Request::isAjax()) {
         $ret = array('reload' => 100);
         //'alert' => $message,
         Responder::sendJSON($ret);
     }
     Responder::redirectToPage($this->Question->getUrl());
 }
 /**
  * Main entry point
  * (non-PHPdoc)
  * @see WebPage::main()
  */
 protected function main()
 {
     if (Request::isAjax()) {
         $this->getQuestion()->getAnswers();
         Responder::sendJSON(array('paginated' => $this->answers));
     }
     $this->pageID = $this->Registry->Request->get('pageID', 'i', 1);
     $this->tab = $this->Registry->Request->get('sort', 's', 'i_lm_ts');
     $this->Registry->registerObservers();
     $this->getQuestion()->addMetas()->sendCacheHeaders()->configureEditor()->setTitle()->addMetaTags()->setAnswersHeader()->getAnswers()->setAnswers()->setSimilar()->makeForm()->setAnswerForm()->makeFollowButton()->setFollowersBlock()->setQuestionInfo()->setFooter()->increaseView()->makeTopTabs();
     $this->Registry->Dispatcher->post($this->Question, 'onQuestionView');
 }
Exemple #25
0
 /**
  * Send Ajax based reponse
  * 
  */
 protected function respond()
 {
     $aRet = array('setmeta' => array('key' => 'fb', 'val' => '1'), 'replace' => array('target' => 'my_fb', 'content' => $this->Registry->Viewer->getFacebookUrl()));
     d('sending out JSON: ' . print_r($aRet, 1));
     Responder::sendJSON($aRet);
 }
 /**
  * Main entry point
  * (non-PHPdoc)
  * @see WebPage::main()
  */
 protected function main()
 {
     if (Request::isAjax()) {
         $this->getQuestion()->getAnswers();
         Responder::sendJSON(array('paginated' => $this->answers));
     }
     $this->pageID = $this->Registry->Request->get('pageID', 'i', 1);
     $this->Registry->registerObservers();
     $this->getQuestion();
     /**
      * Make sorting order: oldest=>newest for topics
      * without tag `question'
      */
     if (!in_array('question', $this->Question['a_tags'])) {
         $this->Registry->Request['sort'] = 'i_ts';
         $this->withQuestionTag = false;
     }
     $this->tab = $this->Registry->Request->get('sort', 's', 'i_lm_ts');
     $this->addMetas()->sendCacheHeaders()->configureEditor()->setTitle()->addMetaTags()->setAnswersHeader()->getAnswers()->setAnswers()->setSimilar()->makeForm()->setAnswerForm()->makeFollowButton()->setFollowersBlock()->setQuestionInfo()->setFooter()->increaseView()->makeTopTabs();
     $this->Registry->Dispatcher->post($this->Question, 'onQuestionView');
 }
Exemple #27
0
 /**
  * Process submitted Answer
  *
  * @return void
  */
 protected function process()
 {
     $formVals = $this->Form->getSubmittedValues();
     d('formVals: ' . print_r($formVals, 1));
     $oAdapter = new AnswerParser($this->Registry);
     try {
         $Answer = $oAdapter->parse(new SubmittedAnswerWWW($this->Registry, $formVals));
         d('cp created new answer: ' . \print_r($Answer->getArrayCopy(), 1));
         d('ans id: ' . $Answer->getResourceId());
         /**
          * In case of ajax we need to send out a
          * parsed html block with one answer
          * under the 'answer' key
          *
          * In case of non-ajax redirect back to question page,
          * hopefully the new answer will show up there too
          */
         if (Request::isAjax()) {
             $aAnswer = $Answer->getArrayCopy();
             /**
              * Add edit and delete tools because
              * Viewer already owns this comment and is
              * allowed to edit or delete it right away.
              * Javascript that usually dynamically adds these tools
              * is not going to be fired, so these tools
              * must already be included in the returned html
              *
              */
             $aAnswer['edit_delete'] = ' <span class="ico del ajax" title="@@Delete@@">@@delete@@</span>  <span class="ico edit ajax" title="@@Edit@@">@@edit@@</span>';
             $a = array('answer' => \tplAnswer::parse($aAnswer));
             d('before sending out $a: ' . print_r($a, 1));
             Responder::sendJSON($a);
         } else {
             Responder::redirectToPage($this->Question->getUrl());
         }
     } catch (\Lampcms\AnswerParserException $e) {
         d('Got AnswerParserException ' . $e->getMessage());
         /**
          * The setFormError in Form sends our json in
          * case of Ajax request, so we don't have to
          * worry about it here
          */
         $this->Form->setFormError($e->getMessage());
         $this->showFormWithErrors();
     }
 }
Exemple #28
0
 /**
  *
  */
 protected function main()
 {
     if (!Request::isAjax()) {
         e('Tweet called as non-ajax');
         throw new \Lampcms\Exception('This page can only be accessed using XHR request (ajax)');
     }
     try {
         $oTwitter = new Twitter($this->Registry);
         $aResponse = $oTwitter->prepareAndPost($this->Request->getUTF8('tweet'));
         Responder::sendJSON(array('tweet' => 'done'));
     } catch (\Lampcms\Exception $e) {
         e('Unable to post message to Twitter: ' . $e->getFile() . ' line: ' . $e->getLine() . ' ' . $e->getMessage());
         Responder::sendJSON(array('tweet' => 'error'));
     }
 }
Exemple #29
0
    /**
     * For Ajax based submission
     * send back Ajax object
     * For regular form submission
     * set the main element
     *
     * @todo When we have email newsletters collection form
     *       we will need to send action: modal
     *       and send html for that form!
     *
     */
    protected function setReturn()
    {
        /**
         * @todo
         * Translate string - get string from Translation object
         */
        $tpl = '
	<h1>Welcome to %s!</h1>
	<p class="larger">We have just emailed you 
	a temporary password and an account activation link</p>
	<p>Please make sure to follow instructions in that email and
	activate your new account</p>
	<p>We hope you will enjoy being a member of our site!</p>
	<br/>
	<p>
	<a class="regok" href="#" onClick="oSL.hideRegForm()">&lt;-- @@Return to site@@</a>&nbsp;
	<a class="regok" href="{_WEB_ROOT_}/settings/"> @@Edit profile@@ --&gt;</a>
	</p> ';
        $ret = \sprintf($tpl, $this->Registry->Ini->SITE_NAME);
        d('ret: ' . $ret);
        if (Request::isAjax()) {
            $a = array('action' => 'done', 'body' => $ret, 'uid' => $this->Registry->Viewer->getUid());
            Responder::sendJSON($a);
        }
    }