Overview

Packages

  • Horde
    • Form
    • MIME
      • Viewer
    • Scheduler
  • None
  • Whups
    • UnitTests

Classes

  • Horde_Core_Ui_VarRenderer_whups
  • Whups
  • Whups_Ajax_Imple_ContactAutoCompleter
  • Whups_Api
  • Whups_Driver
  • Whups_Driver_Sql
  • Whups_Form_AddComment
  • Whups_Form_Admin_AddAttribute
  • Whups_Form_Admin_AddPriority
  • Whups_Form_Admin_AddQueue
  • Whups_Form_Admin_AddReply
  • Whups_Form_Admin_AddState
  • Whups_Form_Admin_AddType
  • Whups_Form_Admin_AddUser
  • Whups_Form_Admin_AddVersion
  • Whups_Form_Admin_CloneType
  • Whups_Form_Admin_DefaultPriority
  • Whups_Form_Admin_DefaultState
  • Whups_Form_Admin_DeleteAttribute
  • Whups_Form_Admin_DeletePriority
  • Whups_Form_Admin_DeleteQueue
  • Whups_Form_Admin_DeleteReply
  • Whups_Form_Admin_DeleteState
  • Whups_Form_Admin_DeleteType
  • Whups_Form_Admin_DeleteVersion
  • Whups_Form_Admin_EditAttributeStepOne
  • Whups_Form_Admin_EditAttributeStepTwo
  • Whups_Form_Admin_EditPriorityStepOne
  • Whups_Form_Admin_EditPriorityStepTwo
  • Whups_Form_Admin_EditQueueStepOne
  • Whups_Form_Admin_EditQueueStepTwo
  • Whups_Form_Admin_EditReplyStepOne
  • Whups_Form_Admin_EditReplyStepTwo
  • Whups_Form_Admin_EditStateStepOne
  • Whups_Form_Admin_EditStateStepTwo
  • Whups_Form_Admin_EditTypeStepOne
  • Whups_Form_Admin_EditTypeStepTwo
  • Whups_Form_Admin_EditUser
  • Whups_Form_Admin_EditVersionStepOne
  • Whups_Form_Admin_EditVersionStepTwo
  • Whups_Form_InsertBranch
  • Whups_Form_Query_AttributeCriterion
  • Whups_Form_Query_ChooseNameForLoad
  • Whups_Form_Query_ChooseNameForSave
  • Whups_Form_Query_DateCriterion
  • Whups_Form_Query_Delete
  • Whups_Form_Query_GroupCriterion
  • Whups_Form_Query_Parameter
  • Whups_Form_Query_PropertyCriterion
  • Whups_Form_Query_TextCriterion
  • Whups_Form_Query_UserCriterion
  • Whups_Form_Renderer_Comment
  • Whups_Form_Search
  • Whups_Form_SendReminder
  • Whups_Form_Ticket_CreateStepFour
  • Whups_Form_Ticket_CreateStepOne
  • Whups_Form_Ticket_CreateStepThree
  • Whups_Form_Ticket_CreateStepTwo
  • Whups_Form_Ticket_Edit
  • Whups_Form_TicketDetails
  • Whups_LoginTasks_SystemTask_Upgrade
  • Whups_Mail
  • Whups_Query
  • Whups_Query_Manager
  • Whups_Reports
  • Whups_Ticket
  • Whups_View_Base
  • Whups_View_Results
  • Whups_View_SavedQueries
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Copyright 2001-2002 Robert E. Coyle <robertecoyle@hotmail.com>
  4:  * Copyright 2001-2012 Horde LLC (http://www.horde.org/)
  5:  *
  6:  * See the enclosed file LICENSE for license information (BSD). If you
  7:  * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
  8:  *
  9:  * @package Whups
 10:  */
 11: class Whups_Form_Renderer_Comment extends Horde_Form_Renderer
 12: {
 13:     /**
 14:      * Intermediate storage for links during comment formatting.
 15:      *
 16:      * @var array
 17:      */
 18:     protected $_tokens = array();
 19: 
 20:     public function begin($title)
 21:     {
 22:         $this->_sectionHeader($title);
 23:         echo '<div id="comments">';
 24:     }
 25: 
 26:     public function render($transaction, &$vars)
 27:     {
 28:         global $prefs, $conf, $registry;
 29:         static $canUpdate, $comment_count = 0;
 30: 
 31:         if (!isset($canUpdate)) {
 32:             $canUpdate = $GLOBALS['registry']->getAuth() &&
 33:                 Whups::hasPermission($vars->get('queue'), 'queue', 'update');
 34:         }
 35: 
 36:         $comment = '';
 37:         $private = false;
 38:         $changes = array();
 39: 
 40:         $changelist = $vars->get('changes');
 41:         if (!$changelist) {
 42:             return '';
 43:         }
 44: 
 45:         /* Format each change in this history entry, including comments,
 46:          * etc. */
 47:         foreach ($changelist as $change) {
 48:             switch ($change['type']) {
 49:             case 'summary':
 50:                 $changes[] = sprintf(
 51:                     _("Summary &rArr; %s"), htmlspecialchars($change['value']));
 52:                 break;
 53: 
 54:             case 'attachment':
 55:                 $ticket = $vars->get('ticket_id');
 56:                 try {
 57:                     if ($file = Whups::getAttachments($ticket, $change['value'])) {
 58:                         $changes[] = sprintf(
 59:                             _("New Attachment: %s"),
 60:                             Whups::attachmentUrl($ticket, $file, $vars->get('queue')));
 61:                     } else {
 62:                         $changes[] = sprintf(
 63:                             _("New Attachment: %s"),
 64:                             htmlspecialchars($change['value']));
 65:                     }
 66:                 } catch (Whups_Exception $e) {
 67:                     $changes[] = sprintf(
 68:                         _("New Attachment: %s"),
 69:                         htmlspecialchars($change['value']));
 70:                 }
 71:                 break;
 72: 
 73:             case 'delete-attachment':
 74:                 $changes[] = sprintf(
 75:                     _("Deleted Attachment: %s"),
 76:                     htmlspecialchars($change['value']));
 77:                 break;
 78: 
 79:             case 'assign':
 80:                 $changes[] = sprintf(
 81:                     _("Assigned to %s"),
 82:                     Whups::formatUser($change['value'], false, true, true));
 83:                 break;
 84: 
 85:             case 'unassign':
 86:                 $changes[] = sprintf(
 87:                     _("Taken from %s"),
 88:                     Whups::formatUser($change['value'], false, true, true));
 89:                 break;
 90: 
 91:             case 'comment':
 92:                 $comment = $change['comment'];
 93:                 $private = !empty($change['private']);
 94:                 if ($comment) {
 95:                     $reply =
 96:                         Horde::link(
 97:                             Horde::url(
 98:                                 Horde_Util::addParameter(
 99:                                     $canUpdate ? 'ticket/update.php' : 'ticket/comment.php',
100:                                     array('id' => $vars->get('ticket_id'),
101:                                           'transaction' => $transaction))))
102:                         . _("Reply to this comment") . '</a>';
103:                 }
104:                 break;
105: 
106:             case 'queue':
107:                 $changes[] = sprintf(
108:                     _("Queue &rArr; %s"), htmlspecialchars($change['label']));
109:                 break;
110: 
111:             case 'version':
112:                 $changes[] = sprintf(
113:                     _("Version &rArr; %s"), htmlspecialchars($change['label']));
114:                 break;
115: 
116:             case 'type':
117:                 $changes[] = sprintf(
118:                     _("Type &rArr; %s"), htmlspecialchars($change['label']));
119:                 break;
120: 
121:             case 'state':
122:                 $changes[] = sprintf(
123:                     _("State &rArr; %s"), htmlspecialchars($change['label']));
124:                 break;
125: 
126:             case 'priority':
127:                 $changes[] = sprintf(
128:                     _("Priority &rArr; %s"), htmlspecialchars($change['label']));
129:                 break;
130: 
131:             case 'attribute':
132:                 $changes[] = sprintf(
133:                     _("%s &rArr; %s"),
134:                     htmlspecialchars($change['label']),
135:                     htmlspecialchars($change['human']));
136:                 break;
137: 
138:             case 'due':
139:                 if ($change['label']) {
140:                     $changes[] = sprintf(
141:                         _("Due &rArr; %s"),
142:                         strftime($prefs->getValue('date_format'), $change['label']));
143:                 }
144:                 break;
145:             }
146:         }
147: 
148:         if ($comment) {
149:             $flowed = new Horde_Text_Flowed($comment, 'UTF-8');
150:             $flowed->setDelSp(true);
151:             $comment = $flowed->toFlowed(false);
152:             $comment = $GLOBALS['injector']
153:                 ->getInstance('Horde_Core_Factory_TextFilter')
154:                 ->filter(
155:                     $comment,
156:                     array('text2html', 'simplemarkup', 'highlightquotes'),
157:                     array(
158:                         array('parselevel' => Horde_Text_Filter_Text2html::MICRO),
159:                         array(),
160:                         array()));
161:             if ($prefs->getValue('autolink_tickets') &&
162:                 $conf['prefs']['autolink_terms']) {
163:                 // Replace existing links by tokens to avoid double linking.
164:                 $comment = preg_replace_callback(
165:                     '/<a.*?<\/a>/', array($this, '_writeTokens'), $comment);
166:                 $comment = preg_replace_callback(
167:                     '/(' . $conf['prefs']['autolink_terms'] . ')\s*#?(\d+)/i',
168:                     array($this, '_autolink'), $comment);
169:                 $comment = preg_replace_callback(
170:                     '/\0/', array($this, '_readTokens'), $comment);
171:             }
172: 
173:             $comment_count++;
174:             if ($private) {
175:                 $comment_label = Horde::img('locked.png')
176:                     . sprintf(_("Comment #%d (Private)"), $comment_count);
177:             } else {
178:                 $comment_label = sprintf(_("Comment #%d"), $comment_count);
179:             }
180:             array_unshift($changes, '<a href="#c' . $comment_count . '" id="c'
181:                                     . $comment_count . '">'
182:                                     . $comment_label
183:                                     . '</a>');
184:         }
185: 
186:         if (count($changes)) {
187:             // Admins can delete entries.
188:             $delete_link = '';
189:             if (Whups::hasPermission($vars->get('queue'), 'queue', Horde_Perms::DELETE)) {
190:                 $delete_link = Horde::url('ticket/delete_history.php')
191:                     ->add(array('transaction' => $transaction,
192:                                 'id' => $vars->get('ticket_id'),
193:                                 'url' => Whups::urlFor('ticket', $vars->get('ticket_id'), true)))
194:                     ->link(array('title' => _("Delete entry"), 'onclick' => 'return window.confirm(\'' . addslashes(_("Permanently delete entry?")) . '\');'))
195:                     . Horde::img('delete.png', _("Delete entry"))
196:                     . '</a>';
197:             }
198: 
199:             Horde::startBuffer();
200:             $class = $private ? 'pc' : 'c';
201: ?>
202: <div id="t<?php echo (int)$transaction ?>">
203: <table cellspacing="0" width="100%">
204:  <tr>
205:   <td width="20%" class="<?php echo $class ?>_l nowrap" valign="top"><?php echo strftime($prefs->getValue('date_format') . ' ' . $prefs->getValue('time_format'), $vars->get('timestamp')) ?></td>
206:   <td width="20%" class="<?php echo $class ?>_m" valign="top"><?php echo $vars->get('user_id') ? Whups::formatUser($vars->get('user_id'), false, true, true) : '&nbsp;' ?></td>
207:   <td width="30%" class="<?php echo $class ?>_m" valign="top"><?php echo implode('<br />', $changes) ?></td>
208:   <td width="30%" class="<?php echo $class ?>_r rightAlign" valign="top"><?php if ($comment && !$private) echo $reply . ' '; echo $delete_link; ?></td>
209:  </tr>
210: <?php if ($comment): ?>
211:  <tr><td colspan="4" class="<?php echo $class ?>_b">
212:   <div class="comment-body">
213:    <?php echo $comment ?>
214:   </div>
215:  </td></tr>
216: <?php else: ?>
217:  <tr><td colspan="4" class="c_b">&nbsp;</td></tr>
218: <?php endif; ?>
219: </table>
220: </div>
221: <?php
222:             $html = Horde::endBuffer();
223:             return $html;
224:         }
225: 
226:         return '';
227:     }
228: 
229:     /**
230:      * Replaces links with tokens and stores them for later _readTokens() calls.
231:      *
232:      * @param array $matches  Match from preg_replace_callback().
233:      *
234:      * @return string  NUL character.
235:      */
236:     protected function _writeTokens($matches)
237:     {
238:         $this->_tokens[] = $matches[0];
239:         return chr(0);
240:     }
241: 
242:     /**
243:      * Replaces tokens with links stored earlier during _writeTokens() calls.
244:      *
245:      * @param array $matches  Match from preg_replace_callback().
246:      *
247:      * @return string  The first available link.
248:      */
249:     protected function _readTokens($matches)
250:     {
251:         return array_shift($this->_tokens);
252:     }
253: 
254:     protected function _autolink($matches)
255:     {
256:         $url = Whups::urlFor('ticket', $matches[2]);
257:         $link = '<strong>' . Horde::link($url, 'View ' . $matches[0])
258:             . $matches[0] . '</a></strong>';
259:         $state = $GLOBALS['whups_driver']->getTicketState($matches[2]);
260:         if ($state['state_category'] == 'resolved') {
261:             $link = '<del>' . $link . '</del>';
262:         }
263:         return $link;
264:     }
265: 
266:     public function end()
267:     {
268:         echo '</div>';
269:     }
270: 
271: }
272: 
API documentation generated by ApiGen