]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/QnA/actions/qnanewanswer.php
Trying to debug some stuff regarding oEmbed
[quix0rs-gnu-social.git] / plugins / QnA / actions / qnanewanswer.php
index e94b86fb3874cdedd5264d515cd5e4404734307a..0cdaa62f1935ac5c7e7f7d1fe466ffe89f9d748d 100644 (file)
@@ -74,14 +74,14 @@ class QnanewanswerAction extends Action
     {
         parent::prepare($argarray);
         if ($this->boolean('ajax')) {
-            StatusNet::setApi(true);
+            GNUsocial::setApi(true);
         }
-
+        common_debug("in qnanewanswer");
         $this->user = common_current_user();
 
         if (empty($this->user)) {
-            // TRANS: Client exception thrown trying to answer a question while not logged in.
             throw new ClientException(
+                // TRANS: Client exception thrown trying to answer a question while not logged in.
                 _m("You must be logged in to answer to a question."),
                 403
             );
@@ -93,11 +93,11 @@ class QnanewanswerAction extends Action
 
         $id = substr($this->trimmed('id'), 9);
 
-        $this->question = QnA_Question::staticGet('id', $id);
+        $this->question = QnA_Question::getKV('id', $id);
 
         if (empty($this->question)) {
-            // TRANS: Client exception thrown trying to respond to a non-existing question.
             throw new ClientException(
+                // TRANS: Client exception thrown trying to respond to a non-existing question.
                 _m('Invalid or missing question.'),
                 404
             );
@@ -151,10 +151,8 @@ class QnanewanswerAction extends Action
         if ($this->boolean('ajax')) {
             common_debug("ajaxy part");
             $answer = $this->question->getAnswer($profile);
-            header('Content-Type: text/xml;charset=utf-8');
-            $this->xw->startDocument('1.0', 'UTF-8');
 
-            $this->elementStart('html');
+            $this->startHTML('text/xml;charset=utf-8');
             $this->elementStart('head');
             // TRANS: Page title after sending an answer.
             $this->element('title', null, _m('Answers'));
@@ -162,14 +160,14 @@ class QnanewanswerAction extends Action
 
             $this->elementStart('body');
 
-            
-            $nli = new NoticeAnswerListItem($notice, $this);
+            $nli = new NoticeAnswerListItem($notice, $this, $this->question, $answer);
             $nli->show();
-  
+
             $this->elementEnd('body');
-            $this->elementEnd('html');
+            $this->endHTML();
         } else {
-            common_redirect($this->question->bestUrl(), 303);
+            common_debug("not ajax");
+            common_redirect($this->question->getUrl(), 303);
         }
     }
 
@@ -223,12 +221,12 @@ class QnanewanswerAction extends Action
         $this->startHTML('text/xml;charset=utf-8', true);
         $this->elementStart('head');
         // TRANS: Page title after an AJAX error occurs on the post answer page.
-        $this->element('title', null, _('Ajax Error'));
+        $this->element('title', null, _m('Ajax Error'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $this->element('p', array('id' => 'error'), $msg);
         $this->elementEnd('body');
-        $this->elementEnd('html');
+        $this->endHTML();
     }
 
     /**
@@ -254,7 +252,7 @@ class QnanewanswerAction extends Action
         $form->show();
 
         $this->elementEnd('body');
-        $this->elementEnd('html');
+        $this->endHTML();
     }
 
     /**
@@ -277,13 +275,12 @@ class QnanewanswerAction extends Action
         $this->msg = $msg;
         $this->showPage();
     }
-
 }
 
 class NoticeAnswerListItem extends NoticeListItem
 {
-
     protected $question;
+    protected $answer;
 
     /**
      * constructor
@@ -292,10 +289,12 @@ class NoticeAnswerListItem extends NoticeListItem
      *
      * @param Notice $notice The notice we'll display
      */
-    function __construct($notice, $out=null)
+    function __construct($notice, $out=null, $question, $answer)
     {
         parent::__construct($notice, $out);
-        $this->question = $out->question;
+        $this->question = $question;
+        $this->answer   = $answer;
+
     }
 
     function show()
@@ -316,4 +315,28 @@ class NoticeAnswerListItem extends NoticeListItem
         $this->showEnd();
     }
 
-}
\ No newline at end of file
+    /**
+     * show the content of the notice
+     *
+     * Shows the content of the notice. This is pre-rendered for efficiency
+     * at save time. Some very old notices might not be pre-rendered, so
+     * they're rendered on the spot.
+     *
+     * @return void
+     */
+    function showContent()
+    {
+        $this->out->elementStart('p', array('class' => 'e-content answer-content'));
+        $this->out->raw($this->notice->getRendered());
+
+        if (!empty($this->answer)) {
+            $form = new QnashowanswerForm($this->out, $this->answer);
+            $form->show();
+        } else {
+            // TRANS: Error message displayed when an answer has no content.
+            $out->text(_m('Answer data is missing.'));
+        }
+
+        $this->out->elementEnd('p');
+    }
+}