]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/QnA/QnAPlugin.php
Moved functions into ActivityHandlerPlugin from MicroAppPlugin
[quix0rs-gnu-social.git] / plugins / QnA / QnAPlugin.php
index 4908e93dd0e250caa7326e4911b2a67fcb937d92..beae1cb6b20a0381fbca794d2ad0f636a42bbbaf 100644 (file)
@@ -65,46 +65,8 @@ class QnAPlugin extends MicroAppPlugin
         return true;
     }
 
-    /**
-     * Load related modules when needed
-     *
-     * @param string $cls Name of the class to be loaded
-     *
-     * @return boolean hook value; true means continue processing, false means stop.
-     */
-    function onAutoload($cls)
-    {
-        $dir = dirname(__FILE__);
-
-        switch ($cls)
-        {
-        case 'QnanewquestionAction':
-        case 'QnanewanswerAction':
-        case 'QnashowquestionAction':
-        case 'QnaclosequestionAction':
-        case 'QnashowanswerAction':
-        case 'QnareviseanswerAction':
-        case 'QnavoteAction':
-            include_once $dir . '/actions/'
-                . strtolower(mb_substr($cls, 0, -6)) . '.php';
-            return false;
-        case 'QnanewquestionForm':
-        case 'QnashowquestionForm':
-        case 'QnanewanswerForm':
-        case 'QnashowanswerForm':
-        case 'QnareviseanswerForm':
-        case 'QnavoteForm':
-            include_once $dir . '/lib/' . strtolower($cls).'.php';
-            break;
-        case 'QnA_Question':
-        case 'QnA_Answer':
-        case 'QnA_Vote':
-            include_once $dir . '/classes/' . $cls.'.php';
-            return false;
-            break;
-        default:
-            return true;
-        }
+    public function newFormAction() {
+        return 'qnanewquestion';
     }
 
     /**
@@ -163,7 +125,7 @@ class QnAPlugin extends MicroAppPlugin
     {
         $versions[] = array(
             'name'        => 'QnA',
-            'version'     => STATUSNET_VERSION,
+            'version'     => GNUSOCIAL_VERSION,
             'author'      => 'Zach Copley',
             'homepage'    => 'http://status.net/wiki/Plugin:QnA',
             'description' =>
@@ -199,7 +161,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.
@@ -225,7 +187,7 @@ class QnAPlugin extends MicroAppPlugin
             );
             break;
         case Answer::ObjectType:
-            $question = QnA_Question::staticGet('uri', $questionObj->id);
+            $question = QnA_Question::getKV('uri', $questionObj->id);
             if (empty($question)) {
                 // FIXME: save the question
                 // TRANS: Exception thrown when answering a non-existing question.
@@ -249,7 +211,7 @@ class QnAPlugin extends MicroAppPlugin
      * @return ActivityObject
      */
 
-    function activityObjectFromNotice($notice)
+    function activityObjectFromNotice(Notice $notice)
     {
         $question = null;
 
@@ -280,7 +242,7 @@ class QnAPlugin extends MicroAppPlugin
         $obj->id      = $question->uri;
         $obj->type    = QnA_Question::OBJECT_TYPE;
         $obj->title   = $question->title;
-        $obj->link    = $notice->bestUrl();
+        $obj->link    = $notice->getUrl();
 
         // XXX: probably need other stuff here
 
@@ -303,12 +265,12 @@ 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';
             }
 
-            $question = QnA_Question::staticGet('uri', $nli->notice->uri);
+            $question = QnA_Question::getKV('uri', $nli->notice->uri);
 
             if (!empty($question->closed)) {
                 $class .= ' closed';
@@ -326,9 +288,9 @@ 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::staticGet('uri', $nli->notice->uri);
+            $answer = QnA_Answer::getKV('uri', $nli->notice->uri);
 
             if (!empty($answer) && !empty($answer->best)) {
                 $cls[] = 'best';
@@ -357,7 +319,7 @@ class QnAPlugin extends MicroAppPlugin
      * @param Notice $notice
      * @param HTMLOutputter $out
      */
-    function showNotice($notice, $out)
+    function showNotice(Notice $notice, $out)
     {
         switch ($notice->object_type) {
         case QnA_Question::OBJECT_TYPE:
@@ -375,7 +337,7 @@ class QnAPlugin extends MicroAppPlugin
         }
     }
 
-    function showNoticeQuestion($notice, $out)
+    function showNoticeQuestion(Notice $notice, $out)
     {
         $user = common_current_user();
 
@@ -383,7 +345,7 @@ class QnAPlugin extends MicroAppPlugin
         $nli = new NoticeListItem($notice, $out);
         $nli->showNotice();
 
-        $out->elementStart('div', array('class' => 'entry-content question-description'));
+        $out->elementStart('div', array('class' => 'e-content question-description'));
 
         $question = QnA_Question::getByNotice($notice);
 
@@ -399,7 +361,7 @@ class QnAPlugin extends MicroAppPlugin
         $out->elementEnd('div');
 
         // @fixme
-        $out->elementStart('div', array('class' => 'entry-content'));
+        $out->elementStart('div', array('class' => 'e-content'));
     }
 
     /**
@@ -436,7 +398,7 @@ class QnAPlugin extends MicroAppPlugin
             $user = common_current_user();
             $question = QnA_Question::getByNotice($notice);
 
-            if (!empty($user)) {
+            if (!empty($user) and !empty($question)) {
                 $profile = $user->getProfile();
                 $answer = $question->getAnswer($profile);
 
@@ -465,7 +427,7 @@ class QnAPlugin extends MicroAppPlugin
         return false;
     }
 
-    function showNoticeAnswer($notice, $out)
+    function showNoticeAnswer(Notice $notice, $out)
     {
         $user = common_current_user();
 
@@ -475,7 +437,7 @@ class QnAPlugin extends MicroAppPlugin
         $nli = new NoticeListItem($notice, $out);
         $nli->showNotice();
 
-        $out->elementStart('div', array('class' => 'entry-content answer-content'));
+        $out->elementStart('div', array('class' => 'e-content answer-content'));
 
         if (!empty($answer)) {
             $form = new QnashowanswerForm($out, $answer);
@@ -488,7 +450,7 @@ class QnAPlugin extends MicroAppPlugin
         $out->elementEnd('div');
 
         // @todo FIXME
-        $out->elementStart('div', array('class' => 'entry-content'));
+        $out->elementStart('div', array('class' => 'e-content'));
     }
 
     static function shorten($content, $notice)
@@ -503,7 +465,7 @@ class QnAPlugin extends MicroAppPlugin
             $ellipsis = _m('…');
             $short = mb_substr($content, 0, $max - 1);
             $short .= sprintf('<a href="%1$s" rel="more" title="%2$s">%3$s</a>',
-                              $notice->uri,
+                              $notice->getUrl(),
                               // TRANS: Title for link that is an ellipsis in English.
                               _m('more...'),
                               $ellipsis);
@@ -530,7 +492,7 @@ class QnAPlugin extends MicroAppPlugin
      *
      * @param Notice $notice
      */
-    function deleteRelated($notice)
+    function deleteRelated(Notice $notice)
     {
         switch ($notice->object_type) {
         case QnA_Question::OBJECT_TYPE: