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 'QnaquestionForm':
- case 'QnaanswerForm':
+ case 'QnanewquestionForm':
+ case 'QnashowquestionForm':
+ case 'QnanewanswerForm':
+ case 'QnashowanswerForm':
case 'QnareviseanswerForm':
case 'QnavoteForm':
include_once $dir . '/lib/' . strtolower($cls).'.php';
'main/qna/newquestion',
array('action' => 'qnanewquestion')
);
+ $m->connect(
+ 'answer/qna/closequestion',
+ array('action' => 'qnaclosequestion')
+ );
$m->connect(
'main/qna/newanswer',
array('action' => 'qnanewanswer')
);
+ $m->connect(
+ 'main/qna/reviseanswer',
+ array('action' => 'qnareviseanswer')
+ );
$m->connect(
'question/vote/:id',
array('action' => 'qnavote', 'type' => 'question'),
'author' => 'Zach Copley',
'homepage' => 'http://status.net/wiki/Plugin:QnA',
'description' =>
+ // TRANS: Plugin description.
_m('Question and Answers micro-app.')
);
return true;
}
function appTitle() {
- return _m('Question');
+ // TRANS: Application title.
+ return _m('TITLE','Question');
}
function tag() {
function saveNoticeFromActivity($activity, $actor, $options=array())
{
if (count($activity->objects) != 1) {
- throw new Exception('Too many activity objects.');
+ // TRANS: Exception thrown when there are too many activity objects.
+ throw new Exception(_m('Too many activity objects.'));
}
$questionObj = $activity->objects[0];
- if ($questinoObj->type != QnA_Question::OBJECT_TYPE) {
- throw new Exception('Wrong type for object.');
+ if ($questionObj->type != QnA_Question::OBJECT_TYPE) {
+ // TRANS: Exception thrown when an incorrect object type is encountered.
+ throw new Exception(_m('Wrong type for object.'));
}
$notice = null;
$question = QnA_Question::staticGet('uri', $questionObj->id);
if (empty($question)) {
// FIXME: save the question
- throw new Exception("Answer to unknown question.");
+ // TRANS: Exception thrown when answering a non-existing question.
+ throw new Exception(_m('Answer to unknown question.'));
}
$notice = QnA_Answer::saveNew($actor, $question, $options);
break;
default:
- throw new Exception("Unknown object type received by QnA Plugin");
+ // TRANS: Exception thrown when an object type is encountered that cannot be handled.
+ throw new Exception(_m('Unknown object type.'));
}
return $notice;
}
if (empty($question)) {
- throw new Exception("Unknown object type.");
+ // TRANS: Exception thrown when an object type is encountered that cannot be handled.
+ throw new Exception(_m('Unknown object type.'));
}
$notice = $question->getNotice();
if (empty($notice)) {
- throw new Exception("Unknown question notice.");
+ // TRANS: Exception thrown when requesting a non-existing question notice.
+ throw new Exception(_m('Unknown question notice.'));
}
$obj = new ActivityObject();
}
/**
- * Change the verb on Answer notices
+ * Output our CSS class for QnA notice list elements
*
- * @param Notice $notice
+ * @param NoticeListItem $nli The item being shown
*
- * @return ActivityObject
+ * @return boolean hook value
*/
- function onEndNoticeAsActivity($notice, &$act) {
- switch ($notice->object_type) {
- case Answer::NORMAL:
- case Answer::ANONYMOUS:
- $act->verb = $notice->object_type;
+ function onStartOpenNoticeListItemElement($nli)
+ {
+ $type = $nli->notice->object_type;
+
+ switch($type)
+ {
+ 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' => $class,
+ 'id' => 'notice-' . $id
+ )
+ );
+ Event::handle('EndOpenNoticeListItemElement', array($nli));
+ return false;
break;
+ case QnA_Answer::OBJECT_TYPE:
+ $id = (empty($nli->repeat)) ? $nli->notice->id : $nli->repeat->id;
+
+ $cls = array('hentry', 'notice', 'answer');
+
+ $answer = QnA_Answer::staticGet('uri', $nli->notice->uri);
+
+ if (!empty($answer) && !empty($answer->best)) {
+ $cls[] = 'best';
+ }
+
+ $nli->out->elementStart(
+ 'li',
+ array(
+ 'class' => implode(' ', $cls),
+ 'id' => 'notice-' . $id
+ )
+ );
+ Event::handle('EndOpenNoticeListItemElement', array($nli));
+ return false;
+ break;
+ default:
+ return true;
}
+
return true;
}
case QnA_Answer::OBJECT_TYPE:
return $this->showNoticeAnswer($notice, $out);
default:
- // TRANS: Exception thrown when performing an unexpected action on a question.
- // TRANS: %s is the unpexpected object type.
throw new Exception(
- sprintf(
- _m('Unexpected type for QnA plugin: %s.'),
- $notice->object_type
+ // 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
)
);
}
$nli = new NoticeListItem($notice, $out);
$nli->showNotice();
- $out->elementStart('div', array('class' => 'entry-content question-content'));
+ $out->elementStart('div', array('class' => 'entry-content question-description'));
+
$question = QnA_Question::getByNotice($notice);
- if ($question) {
- if ($user) {
- $profile = $user->getProfile();
- $answer = $question->getAnswer($profile);
- if ($answer) {
- // User has already answer; show the results.
- $form = new QnareviseanswerForm($answer, $out);
- } else {
- $form = new QnaanswerForm($question, $out);
- }
- $form->show();
- }
+ if (!empty($question)) {
+
+ $form = new QnashowquestionForm($out, $question);
+ $form->show();
+
} else {
- $out->text(_m('Question data is missing'));
+ // TRANS: Error message displayed when question data is not present.
+ $out->text(_m('Question data is missing.'));
}
$out->elementEnd('div');
$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
+ *
+ * @todo 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',
+ // TRANS: Placeholder value for a possible answer to a question
+ // TRANS: by the logged in user.
+ 'value' => _m('Your answer...')
+ )
+ );
+ $out->elementEnd('li');
+ $out->elementEnd('ul');
+ }
+ }
+ }
+
+ return false;
+ }
+
function showNoticeAnswer($notice, $out)
{
$user = common_current_user();
- // @hack we want regular rendering, then just add stuff after that
+ $answer = QnA_Answer::getByNotice($notice);
+ $question = $answer->getQuestion();
+
$nli = new NoticeListItem($notice, $out);
$nli->showNotice();
- // @fixme
+ $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'));
}
+ static function shorten($content, $notice)
+ {
+ $short = null;
+
+ if (Notice::contentTooLong($content)) {
+ common_debug("content too long");
+ $max = Notice::maxContent();
+ // TRANS: Link description for link to full notice text if it is longer than
+ // TRANS: what will be dispplayed.
+ $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,
+ // TRANS: Title for link that is an ellipsis in English.
+ _m('more...'),
+ $ellipsis);
+ } else {
+ $short = $content;
+ }
+
+ return $short;
+ }
+
/**
* Form for our app
*
* @param HTMLOutputter $out
* @return Widget
*/
-
function entryForm($out)
{
- return new QnaquestionForm($out);
+ return new QnanewquestionForm($out);
}
/**
*
* @param Notice $notice
*/
-
function deleteRelated($notice)
{
switch ($notice->object_type) {
function onEndShowScripts($action)
{
- // XXX maybe some cool shiz here
+ $action->script($this->path('js/qna.js'));
+ return true;
}
function onEndShowStyles($action)