X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FQnA%2FQnAPlugin.php;h=ad0541a71cf1f08d34787261ba6e7e6e87ee9d8f;hb=bc66211565035ed5986390fdecd089cbbb8db959;hp=cc70cb7aeb46ed59ebf974e22b0503907bcb3d85;hpb=747748a0faf8cccb780cf8b09941119e0a38cc29;p=quix0rs-gnu-social.git diff --git a/plugins/QnA/QnAPlugin.php b/plugins/QnA/QnAPlugin.php index cc70cb7aeb..ad0541a71c 100644 --- a/plugins/QnA/QnAPlugin.php +++ b/plugins/QnA/QnAPlugin.php @@ -205,7 +205,7 @@ class QnAPlugin extends MicroAppPlugin $questionObj = $activity->objects[0]; - if ($questinoObj->type != QnA_Question::OBJECT_TYPE) { + if ($questionObj->type != QnA_Question::OBJECT_TYPE) { throw new Exception('Wrong type for object.'); } @@ -279,24 +279,6 @@ class QnAPlugin extends MicroAppPlugin return $obj; } - /** - * Change the verb on Answer notices - * - * @param Notice $notice - * - * @return ActivityObject - */ - - function onEndNoticeAsActivity($notice, &$act) { - switch ($notice->object_type) { - case Answer::NORMAL: - case Answer::ANONYMOUS: - $act->verb = $notice->object_type; - break; - } - return true; - } - /** * Output our CSS class for QnA notice list elements * @@ -313,9 +295,20 @@ class QnAPlugin extends MicroAppPlugin { case QnA_Question::OBJECT_TYPE: $id = (empty($nli->repeat)) ? $nli->notice->id : $nli->repeat->id; + $class = 'hentry notice question'; + if ($nli->notice->scope != 0 && $nli->notice->scope != 1) { + $class .= ' limited-scope'; + } + + $question = QnA_Question::staticGet('uri', $nli->notice->uri); + + if (!empty($question->closed)) { + $class .= ' closed'; + } + $nli->out->elementStart( 'li', array( - 'class' => 'hentry notice question', + 'class' => $class, 'id' => 'notice-' . $id ) ); @@ -327,7 +320,7 @@ class QnAPlugin extends MicroAppPlugin $cls = array('hentry', 'notice', 'answer'); - $answer = QnA_Answer::staticGet('uri', $notice->uri); + $answer = QnA_Answer::staticGet('uri', $nli->notice->uri); if (!empty($answer) && !empty($answer->best)) { $cls[] = 'best'; @@ -356,7 +349,7 @@ class QnAPlugin extends MicroAppPlugin * @param Notice $notice * @param HTMLOutputter $out */ - + function showNotice($notice, $out) { switch ($notice->object_type) { @@ -384,25 +377,15 @@ class QnAPlugin extends MicroAppPlugin $nli = new NoticeListItem($notice, $out); $nli->showNotice(); - $out->elementStart('div', array('class' => 'entry-content question-desciption')); + $out->elementStart('div', array('class' => 'entry-content question-description')); $question = QnA_Question::getByNotice($notice); if (!empty($question)) { - if (empty($user)) { - $form = new QnashowquestionForm($out, $question); - $form->show(); - } else { - $profile = $user->getProfile(); - $answer = $question->getAnswer($profile); - if (empty($answer)) { - $form = new QnanewanswerForm($out, $question); - $form->show(); - } else { - $form = new QnashowquestionForm($out, $question); - $form->show(); - } - } + + $form = new QnashowquestionForm($out, $question); + $form->show(); + } else { $out->text(_m('Question data is missing.')); } @@ -412,10 +395,75 @@ class QnAPlugin extends MicroAppPlugin $out->elementStart('div', array('class' => 'entry-content')); } + + /** + * Output the HTML for this kind of object in a list + * + * @param NoticeListItem $nli The list item being shown. + * + * @return boolean hook value + * + * @fixme WARNING WARNING WARNING this closes a 'div' that is implicitly opened in BookmarkPlugin's showNotice implementation + */ + function onStartShowNoticeItem($nli) + { + if (!$this->isMyNotice($nli->notice)) { + return true; + } + + $out = $nli->out; + $notice = $nli->notice; + + $this->showNotice($notice, $out); + + $nli->showNoticeLink(); + $nli->showNoticeSource(); + $nli->showNoticeLocation(); + $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)) { + + $profile = $user->getProfile(); + $answer = $question->getAnswer($profile); + + // Output a placeholder input -- clicking on it will + // bring up a real answer form + + // NOTE: this whole ul is just a placeholder + if (empty($question->closed) && empty($answer)) { + $out->elementStart('ul', 'notices qna-dummy'); + $out->elementStart('li', 'qna-dummy-placeholder'); + $out->element( + 'input', + array( + 'class' => 'placeholder', + 'value' => _m('Your answer...') + ) + ); + $out->elementEnd('li'); + $out->elementEnd('ul'); + } + } + } + + return false; + } + + function showNoticeAnswer($notice, $out) { $user = common_current_user(); - + $answer = QnA_Answer::getByNotice($notice); $question = $answer->getQuestion(); @@ -496,7 +544,8 @@ class QnAPlugin extends MicroAppPlugin function onEndShowScripts($action) { - // XXX maybe some cool shiz here + $action->script($this->path('js/qna.js')); + return true; } function onEndShowStyles($action)