]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/QnA/QnAPlugin.php
Merge branch 'master' into social-master
[quix0rs-gnu-social.git] / plugins / QnA / QnAPlugin.php
index 8aa3247f9ae9ba4b52535d765b583ecef80db9dd..7c6c3e00e355fd6367c604ba64be127d71b063da 100644 (file)
@@ -46,6 +46,9 @@ if (!defined('STATUSNET')) {
  */
 class QnAPlugin extends MicroAppPlugin
 {
+
+    var $oldSaveNew = true;
+
     /**
      * Set up our tables (question and answer)
      *
@@ -72,12 +75,12 @@ class QnAPlugin extends MicroAppPlugin
     /**
      * Map URLs to actions
      *
-     * @param Net_URL_Mapper $m path-to-action mapper
+     * @param URLMapper $m path-to-action mapper
      *
      * @return boolean hook value; true means continue processing, false means stop.
      */
 
-    function onRouterInitialized($m)
+    public function onRouterInitialized(URLMapper $m)
     {
         $UUIDregex = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}';
 
@@ -121,7 +124,7 @@ class QnAPlugin extends MicroAppPlugin
         return true;
     }
 
-    function onPluginVersion(&$versions)
+    function onPluginVersion(array &$versions)
     {
         $versions[] = array(
             'name'        => 'QnA',
@@ -161,7 +164,7 @@ class QnAPlugin extends MicroAppPlugin
      *
      * @return Notice the resulting notice
      */
-    function saveNoticeFromActivity($activity, $actor, $options=array())
+    function saveNoticeFromActivity(Activity $activity, Profile $actor, array $options=array())
     {
         if (count($activity->objects) != 1) {
             // TRANS: Exception thrown when there are too many activity objects.
@@ -211,7 +214,7 @@ class QnAPlugin extends MicroAppPlugin
      * @return ActivityObject
      */
 
-    function activityObjectFromNotice($notice)
+    function activityObjectFromNotice(Notice $notice)
     {
         $question = null;
 
@@ -265,7 +268,7 @@ class QnAPlugin extends MicroAppPlugin
         {
         case QnA_Question::OBJECT_TYPE:
             $id = (empty($nli->repeat)) ? $nli->notice->id : $nli->repeat->id;
-            $class = 'hentry notice question';
+            $class = 'h-entry notice question';
             if ($nli->notice->scope != 0 && $nli->notice->scope != 1) {
                 $class .= ' limited-scope';
             }
@@ -288,7 +291,7 @@ class QnAPlugin extends MicroAppPlugin
         case QnA_Answer::OBJECT_TYPE:
             $id = (empty($nli->repeat)) ? $nli->notice->id : $nli->repeat->id;
 
-            $cls = array('hentry', 'notice', 'answer');
+            $cls = array('h-entry', 'notice', 'answer');
 
             $answer = QnA_Answer::getKV('uri', $nli->notice->uri);
 
@@ -313,57 +316,6 @@ class QnAPlugin extends MicroAppPlugin
         return true;
     }
 
-    /**
-     * Custom HTML output for our notices
-     *
-     * @param Notice $notice
-     * @param HTMLOutputter $out
-     */
-    function showNotice(Notice $notice, $out)
-    {
-        switch ($notice->object_type) {
-        case QnA_Question::OBJECT_TYPE:
-            return $this->showNoticeQuestion($notice, $out);
-        case QnA_Answer::OBJECT_TYPE:
-            return $this->showNoticeAnswer($notice, $out);
-        default:
-            throw new Exception(
-                // TRANS: Exception thrown when performing an unexpected action on a question.
-                // TRANS: %s is the unpexpected object type.
-                sprintf(_m('Unexpected type for QnA plugin: %s.'),
-                        $notice->object_type
-                )
-            );
-        }
-    }
-
-    function showNoticeQuestion(Notice $notice, $out)
-    {
-        $user = common_current_user();
-
-        // @hack we want regular rendering, then just add stuff after that
-        $nli = new NoticeListItem($notice, $out);
-        $nli->showNotice();
-
-        $out->elementStart('div', array('class' => 'entry-content question-description'));
-
-        $question = QnA_Question::getByNotice($notice);
-
-        if (!empty($question)) {
-
-            $form = new QnashowquestionForm($out, $question);
-            $form->show();
-
-        } else {
-            // TRANS: Error message displayed when question data is not present.
-            $out->text(_m('Question data is missing.'));
-        }
-        $out->elementEnd('div');
-
-        // @fixme
-        $out->elementStart('div', array('class' => 'entry-content'));
-    }
-
     /**
      * Output the HTML for this kind of object in a list
      *
@@ -382,16 +334,14 @@ class QnAPlugin extends MicroAppPlugin
         $out = $nli->out;
         $notice = $nli->notice;
 
-        $this->showNotice($notice, $out);
+        $nli->showNotice($notice, $out);
 
         $nli->showNoticeLink();
         $nli->showNoticeSource();
         $nli->showNoticeLocation();
-        $nli->showContext();
+        $nli->showPermalink();
         $nli->showRepeat();
 
-        $out->elementEnd('div');
-
         $nli->showNoticeOptions();
 
         if ($notice->object_type == QnA_Question::OBJECT_TYPE) {
@@ -427,30 +377,8 @@ class QnAPlugin extends MicroAppPlugin
         return false;
     }
 
-    function showNoticeAnswer(Notice $notice, $out)
-    {
-        $user = common_current_user();
-
-        $answer   = QnA_Answer::getByNotice($notice);
-        $question = $answer->getQuestion();
-
-        $nli = new NoticeListItem($notice, $out);
-        $nli->showNotice();
-
-        $out->elementStart('div', array('class' => 'entry-content answer-content'));
-
-        if (!empty($answer)) {
-            $form = new QnashowanswerForm($out, $answer);
-            $form->show();
-        } else {
-            // TRANS: Error message displayed when answer data is not present.
-            $out->text(_m('Answer data is missing.'));
-        }
-
-        $out->elementEnd('div');
-
-        // @todo FIXME
-        $out->elementStart('div', array('class' => 'entry-content'));
+    function adaptNoticeListItem($nli) {
+        return new QnAListItem($nli);
     }
 
     static function shorten($content, $notice)
@@ -492,22 +420,22 @@ class QnAPlugin extends MicroAppPlugin
      *
      * @param Notice $notice
      */
-    function deleteRelated($notice)
+    function deleteRelated(Notice $notice)
     {
         switch ($notice->object_type) {
         case QnA_Question::OBJECT_TYPE:
-            common_log(LOG_DEBUG, "Deleting question from notice...");
+            common_debug("Deleting question from notice...");
             $question = QnA_Question::fromNotice($notice);
             $question->delete();
             break;
         case QnA_Answer::OBJECT_TYPE:
-            common_log(LOG_DEBUG, "Deleting answer from notice...");
+            common_debug("Deleting answer from notice...");
             $answer = QnA_Answer::fromNotice($notice);
-            common_log(LOG_DEBUG, "to delete: $answer->id");
+            common_debug("to delete: $answer->id");
             $answer->delete();
             break;
         default:
-            common_log(LOG_DEBUG, "Not deleting related, wtf...");
+            common_debug("Not deleting related, wtf...");
         }
     }