コード例 #1
0
 protected function returnResult()
 {
     if (Request::isAjax()) {
         Responder::sendJSON(array());
     }
     Responder::redirectToPage();
 }
コード例 #2
0
ファイル: Approve.php プロジェクト: codigoirreverente/LampCMS
 protected function returnResult()
 {
     if (Request::isAjax()) {
         $ret = array('alert' => '@@Approved@@');
         $ret['reload'] = 1000;
         Responder::sendJSON($ret);
         exit;
     }
     Responder::redirectToPage();
 }
コード例 #3
0
ファイル: Tweet.php プロジェクト: netconstructor/LampCMS
 /**
  *
  */
 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'));
     }
 }
コード例 #4
0
ファイル: Form.php プロジェクト: codigoirreverente/LampCMS
 /**
  * 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;
 }
コード例 #5
0
 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());
 }
コード例 #6
0
ファイル: Close.php プロジェクト: codigoirreverente/LampCMS
    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());
    }
コード例 #7
0
 /**
  *
  * Add a small login block to the template
  * but ONLY for ajax based request
  *
  * for regular web page we don't need
  * to have yet another login block
  * in the registration block
  *
  * @return string html of login block
  * of empty string for non-ajax request
  */
 protected function makeLoginBlock()
 {
     if (Request::isAjax()) {
         return \tplLoginblock::parse(array());
     }
     return '';
 }
コード例 #8
0
ファイル: Shred.php プロジェクト: codex73/LampCMS
 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();
 }
コード例 #9
0
 /**
  * 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');
 }
コード例 #10
0
ファイル: Viewqtags.php プロジェクト: netconstructor/LampCMS
 /**
  * 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;
 }
コード例 #11
0
 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());
 }
コード例 #12
0
ファイル: WebPage.php プロジェクト: netconstructor/LampCMS
 /**
  * Add extra div with "Join" form
  * where we ask to provide email address
  * after user joins with external provider
  *
  * @return object $this
  */
 protected function addJoinForm()
 {
     if (!$this->bInitPageVars || !Request::isAjax() && 'remindpwd' !== $this->action && 'logout' !== $this->action) {
         /**
          * If user opted out of continuing
          * registration, the special 'dnd' or "Do not disturb"
          * cookie was set via Javascritp
          * We will respect that and will not show that same
          * nagging prompt again
          *
          * This cookie is deleted on Logout
          * @todo set ttl for this cookie to last only a couple of days
          * so we can keep nagging user again after awhile until user
          * finally enters email address
          * Also do not have to check if user is UserExternal - if user
          * does not have email address then keep nagging the user
          * The thing is - only external user can possibly be logged in without
          * any email address because normal user will not know their password
          * since temp passwords are sent to email.
          */
         $cookie = Cookie::get('dnd');
         d('dnd: ' . $cookie);
         if (!$cookie) {
             if ($this->Registry->Viewer instanceof UserExternal) {
                 $email = $this->Registry->Viewer->email;
                 d('email: ' . $email);
                 if (empty($email)) {
                     $sHtml = RegBlock::factory($this->Registry)->getBlock();
                     d('$sHtml: ' . $sHtml);
                     $this->aPageVars['extra_html'] = $sHtml;
                 }
             }
         }
     }
     return $this;
 }
コード例 #13
0
ファイル: Users.php プロジェクト: codigoirreverente/LampCMS
 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();
 }
コード例 #14
0
ファイル: Viewquestion.php プロジェクト: codex73/LampCMS
 /**
  * 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');
 }
コード例 #15
0
ファイル: Regform.php プロジェクト: codigoirreverente/LampCMS
 /**
  *
  */
 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;
 }
コード例 #16
0
 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@@';
 }
コード例 #17
0
ファイル: Editor.php プロジェクト: codigoirreverente/LampCMS
 protected function returnErrors()
 {
     d('cp');
     if (Request::isAjax()) {
         d('cp');
         $aErrors = $this->Form->getErrors();
         Responder::sendJSON(array('formErrors' => $aErrors));
     }
     $this->makeTopTabs()->makeMemo()->setForm();
 }
コード例 #18
0
    error_reporting(E_ALL ^ E_WARNING);
    ini_set('display_errors', 0);
    ini_set('display_startup_errors', 0);
    ini_set('warn_plus_overloading', 0);
}
define('LOG_FILE_PATH', $oINI->LOG_FILE_PATH);
/**
 * Empty the log file if
 * necessary
 */
/**
 * LOG_PER_SCRIPT
 * will return string '1' for true
 * or empty string for false
 */
if (true === LAMPCMS_DEBUG && '' !== LOG_FILE_PATH && true === (bool) $oINI->LOG_PER_SCRIPT && !\Lampcms\Request::isAjax()) {
    file_put_contents(LOG_FILE_PATH, PHP_SAPI . ' ' . print_r($_SERVER, 1), LOCK_EX);
}
/**
 * Shortcuts to log debug and log error
 * MUST BE CALLED after DEBUG MODE and LOG_FILE_PATH
 * has been defined
 */
function d($message)
{
    if (defined('LAMPCMS_DEBUG') && true === LAMPCMS_DEBUG) {
        \Lampcms\Log::d($message, 2);
    }
}
function e($message)
{
コード例 #19
0
ファイル: Usergroup.php プロジェクト: netconstructor/LampCMS
 protected function setReturn()
 {
     if (Request::isAjax()) {
         $ret = array('alert' => 'User group updated', 'reload' => 1000);
         Responder::sendJSON($ret);
     }
     Responder::redirectToPage();
 }
コード例 #20
0
ファイル: Flagger.php プロジェクト: codigoirreverente/LampCMS
 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());
 }
コード例 #21
0
ファイル: Delete.php プロジェクト: codigoirreverente/LampCMS
    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());
    }
コード例 #22
0
 /**
  * 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');
 }
コード例 #23
0
ファイル: Login.php プロジェクト: codigoirreverente/LampCMS
 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();
 }
コード例 #24
0
ファイル: Answer.php プロジェクト: codigoirreverente/LampCMS
 /**
  * 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();
     }
 }
コード例 #25
0
ファイル: Join.php プロジェクト: codigoirreverente/LampCMS
    /**
     * 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);
        }
    }