From: Zach Copley Date: Tue, 5 Apr 2011 00:04:13 +0000 (-0700) Subject: QnA - truncate long question titles in notice content X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=92156317b6410b64f7667e9b14b8ebde91db151d;p=quix0rs-gnu-social.git QnA - truncate long question titles in notice content --- diff --git a/plugins/QnA/QnAPlugin.php b/plugins/QnA/QnAPlugin.php index 35811a309a..5b6c1eb91c 100644 --- a/plugins/QnA/QnAPlugin.php +++ b/plugins/QnA/QnAPlugin.php @@ -356,7 +356,7 @@ class QnAPlugin extends MicroAppPlugin * @param Notice $notice * @param HTMLOutputter $out */ - + function showNotice($notice, $out) { switch ($notice->object_type) { @@ -415,7 +415,7 @@ class QnAPlugin extends MicroAppPlugin function showNoticeAnswer($notice, $out) { $user = common_current_user(); - + $answer = QnA_Answer::getByNotice($notice); $question = $answer->getQuestion(); diff --git a/plugins/QnA/actions/qnanewquestion.php b/plugins/QnA/actions/qnanewquestion.php index 8682f8dd47..561b11575a 100644 --- a/plugins/QnA/actions/qnanewquestion.php +++ b/plugins/QnA/actions/qnanewquestion.php @@ -88,6 +88,7 @@ class QnanewquestionAction extends Action } $this->title = $this->trimmed('title'); + common_debug("TITLE = " . $this->title); $this->description = $this->trimmed('description'); return true; diff --git a/plugins/QnA/classes/QnA_Question.php b/plugins/QnA/classes/QnA_Question.php index ed1757e989..7055876369 100644 --- a/plugins/QnA/classes/QnA_Question.php +++ b/plugins/QnA/classes/QnA_Question.php @@ -273,15 +273,17 @@ class QnA_Question extends Managed_DataObject common_log(LOG_DEBUG, "Saving question: $q->id $q->uri"); $q->insert(); - // TRANS: Notice content creating a question. - // TRANS: %1$s is the title of the question, %2$s is a link to the question. - $content = sprintf( - _m('question: %1$s %2$s'), - $title, - $q->uri - ); + if (Notice::contentTooLong($q->title . ' ' . $q->uri)) { + $max = Notice::maxContent(); + $uriLen = mb_strlen($q->uri); + $targetLen = $max - ($uriLen + 15); + $title = mb_substr($q->title, 0, $targetLen) . '…'; + + } + + $content = $title . ' ' . $q->uri; - $link = '' . htmlspecialchars($title) . ''; + $link = '' . htmlspecialchars($q->title) . ''; // TRANS: Rendered version of the notice content creating a question. // TRANS: %s a link to the question as link description. $rendered = sprintf(_m('Question: %s'), $link);