X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FQnA%2FQnAPlugin.php;h=1cbab3b60b30d19ce9b98e3b2b89185476b771f9;hb=78781050b33df2bfcbfb14916013d06e25f19ea7;hp=a4709df462e6f97ce92e4e37f863c1fab320b991;hpb=f110fc5c9a61ac666d88714b170b12f99d911b11;p=quix0rs-gnu-social.git diff --git a/plugins/QnA/QnAPlugin.php b/plugins/QnA/QnAPlugin.php index a4709df462..1cbab3b60b 100644 --- a/plugins/QnA/QnAPlugin.php +++ b/plugins/QnA/QnAPlugin.php @@ -46,6 +46,9 @@ if (!defined('STATUSNET')) { */ class QnAPlugin extends MicroAppPlugin { + + var $oldSaveNew = true; + /** * Set up our tables (question and answer) * @@ -65,6 +68,10 @@ class QnAPlugin extends MicroAppPlugin return true; } + public function newFormAction() { + return 'qnanewquestion'; + } + /** * Map URLs to actions * @@ -157,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. @@ -207,7 +214,7 @@ class QnAPlugin extends MicroAppPlugin * @return ActivityObject */ - function activityObjectFromNotice($notice) + function activityObjectFromNotice(Notice $notice) { $question = null; @@ -238,7 +245,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 @@ -261,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'; } @@ -284,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); @@ -309,57 +316,6 @@ class QnAPlugin extends MicroAppPlugin return true; } - /** - * Custom HTML output for our notices - * - * @param Notice $notice - * @param HTMLOutputter $out - */ - function showNotice($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, $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 * @@ -378,7 +334,7 @@ class QnAPlugin extends MicroAppPlugin $out = $nli->out; $notice = $nli->notice; - $this->showNotice($notice, $out); + $nli->showNotice($notice, $out); $nli->showNoticeLink(); $nli->showNoticeSource(); @@ -386,15 +342,13 @@ class QnAPlugin extends MicroAppPlugin $nli->showContext(); $nli->showRepeat(); - $out->elementEnd('div'); - $nli->showNoticeOptions(); if ($notice->object_type == QnA_Question::OBJECT_TYPE) { $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); @@ -423,30 +377,8 @@ class QnAPlugin extends MicroAppPlugin return false; } - function showNoticeAnswer($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) @@ -461,7 +393,7 @@ class QnAPlugin extends MicroAppPlugin $ellipsis = _m('…'); $short = mb_substr($content, 0, $max - 1); $short .= sprintf('%3$s', - $notice->uri, + $notice->getUrl(), // TRANS: Title for link that is an ellipsis in English. _m('more...'), $ellipsis); @@ -488,7 +420,7 @@ class QnAPlugin extends MicroAppPlugin * * @param Notice $notice */ - function deleteRelated($notice) + function deleteRelated(Notice $notice) { switch ($notice->object_type) { case QnA_Question::OBJECT_TYPE: