X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FQnA%2FQnAPlugin.php;h=67806370090f32b6ed35d68d5d48a8be23d4789f;hb=8c9efff1ace2d5e466691abf038f096eb5dd5f51;hp=f6381792707e7c1d7ca65fc29043722254d9a2ce;hpb=0d892e7610166e0d028138f498f188fde7f5b229;p=quix0rs-gnu-social.git diff --git a/plugins/QnA/QnAPlugin.php b/plugins/QnA/QnAPlugin.php index f638179270..6780637009 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,57 +68,19 @@ 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'; } /** * 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}'; @@ -159,13 +124,13 @@ class QnAPlugin extends MicroAppPlugin return true; } - function onPluginVersion(&$versions) + function onPluginVersion(array &$versions) { $versions[] = array( 'name' => 'QnA', - 'version' => STATUSNET_VERSION, + 'version' => GNUSOCIAL_VERSION, 'author' => 'Zach Copley', - 'homepage' => 'http://status.net/wiki/Plugin:QnA', + 'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/QnA', 'description' => // TRANS: Plugin description. _m('Question and Answers micro-app.') @@ -175,7 +140,7 @@ class QnAPlugin extends MicroAppPlugin function appTitle() { // TRANS: Application title. - return _m('Question'); + return _m('TITLE','Question'); } function tag() { @@ -199,15 +164,17 @@ 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. throw new Exception(_m('Too many activity objects.')); } $questionObj = $activity->objects[0]; 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.')); } @@ -223,15 +190,17 @@ 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. throw new Exception(_m('Answer to unknown question.')); } $notice = QnA_Answer::saveNew($actor, $question, $options); break; default: - throw new Exception(_m('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; @@ -245,7 +214,7 @@ class QnAPlugin extends MicroAppPlugin * @return ActivityObject */ - function activityObjectFromNotice($notice) + function activityObjectFromNotice(Notice $notice) { $question = null; @@ -260,12 +229,14 @@ class QnAPlugin extends MicroAppPlugin } if (empty($question)) { + // 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)) { + // TRANS: Exception thrown when requesting a non-existing question notice. throw new Exception(_m('Unknown question notice.')); } @@ -274,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 @@ -289,7 +260,7 @@ class QnAPlugin extends MicroAppPlugin * @return boolean hook value */ - function onStartOpenNoticeListItemElement($nli) + function onStartOpenNoticeListItemElement(NoticeListItem $nli) { $type = $nli->notice->object_type; @@ -297,12 +268,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'; @@ -320,9 +291,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'; @@ -345,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 { - $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 * @@ -403,9 +323,9 @@ class QnAPlugin extends MicroAppPlugin * * @return boolean hook value * - * @fixme WARNING WARNING WARNING this closes a 'div' that is implicitly opened in BookmarkPlugin's showNotice implementation + * @todo FIXME: WARNING WARNING WARNING this closes a 'div' that is implicitly opened in BookmarkPlugin's showNotice implementation */ - function onStartShowNoticeItem($nli) + function onStartShowNoticeItem(NoticeListItem $nli) { if (!$this->isMyNotice($nli->notice)) { return true; @@ -414,25 +334,20 @@ 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->showRepeat(); - - $out->elementEnd('div'); + $nli->showPermalink(); $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); @@ -447,6 +362,8 @@ class QnAPlugin extends MicroAppPlugin 'input', array( 'class' => 'placeholder', + // TRANS: Placeholder value for a possible answer to a question + // TRANS: by the logged in user. 'value' => _m('Your answer...') ) ); @@ -459,30 +376,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 { - $out->text(_m('Answer data is missing.')); - } - - $out->elementEnd('div'); - - // @fixme - $out->elementStart('div', array('class' => 'entry-content')); + function adaptNoticeListItem($nli) { + return new QnAListItem($nli); } static function shorten($content, $notice) @@ -492,14 +387,15 @@ class QnAPlugin extends MicroAppPlugin 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( - // TRANS: Link to full notice text if it is longer than what will be dispplayed. - // TRANS: %s a notice URI. - _m('…'), - $notice->uri, - _m('more...') - ); + $short .= sprintf('%3$s', + $notice->getUrl(), + // TRANS: Title for link that is an ellipsis in English. + _m('more...'), + $ellipsis); } else { $short = $content; } @@ -513,7 +409,6 @@ class QnAPlugin extends MicroAppPlugin * @param HTMLOutputter $out * @return Widget */ - function entryForm($out) { return new QnanewquestionForm($out); @@ -524,8 +419,7 @@ class QnAPlugin extends MicroAppPlugin * * @param Notice $notice */ - - function deleteRelated($notice) + function deleteRelated(Notice $notice) { switch ($notice->object_type) { case QnA_Question::OBJECT_TYPE: