| Total Complexity | 87 |
| Total Lines | 608 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like SectionView often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use SectionView, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 6 | class SectionView { |
||
| 7 | public $major; |
||
| 8 | protected $class; |
||
| 9 | protected $list; |
||
| 10 | private $major_data; |
||
| 11 | private $page_base; |
||
| 12 | protected $index_template = ''; |
||
| 13 | |||
| 14 | public function __construct() { |
||
| 15 | global $hansardmajors; |
||
| 16 | $this->major_data = $hansardmajors[$this->major]; |
||
| 17 | $this->page_base = str_replace('year', '', $this->major_data['page_year']); |
||
| 18 | if (!$this->list) { |
||
| 19 | $this->class = "\\" . $this->class; |
||
| 20 | $this->list = new $this->class(); |
||
| 21 | } |
||
| 22 | } |
||
| 23 | |||
| 24 | public function display() { |
||
| 25 | if ($year = get_http_var('y')) { |
||
| 26 | $data = $this->display_year($year); |
||
| 27 | $data['year'] = $year; |
||
| 28 | $data['template'] = 'section/year'; |
||
| 29 | $data = $this->addCommonData($data); |
||
| 30 | } elseif (($date = get_http_var('d')) && ($column = get_http_var('c'))) { |
||
| 31 | $data = $this->display_column($date, $column); |
||
| 32 | $data = $this->addCommonData($data); |
||
| 33 | } elseif ($date = get_http_var('d')) { |
||
| 34 | $data = $this->display_day($date); |
||
| 35 | if ( !isset($data['template']) ) { |
||
| 36 | $data['template'] = 'section/day'; |
||
| 37 | } |
||
| 38 | $data = $this->addCommonData($data); |
||
| 39 | } elseif (get_http_var('id')) { |
||
| 40 | $data = $this->display_section_or_speech(); |
||
| 41 | } else { |
||
| 42 | $data = $this->display_front(); |
||
| 43 | if ( !isset($data['template']) ) { |
||
| 44 | $data['template'] = 'section/recent'; |
||
| 45 | } |
||
| 46 | $data['search_sections'] = $this->getSearchSections(); |
||
| 47 | $data = $this->addCommonData($data); |
||
| 48 | } |
||
| 49 | |||
| 50 | return $data; |
||
| 51 | } |
||
| 52 | |||
| 53 | protected function addCommonData($data) { |
||
| 54 | global $DATA, $this_page; |
||
| 55 | |||
| 56 | $common = new \MySociety\TheyWorkForYou\Common; |
||
| 57 | $data['urls'] = $this->getURLs($data); |
||
| 58 | $data['popular_searches'] = $common->getPopularSearches(); |
||
| 59 | $data['recess_major'] = $this->getRecessMajor(); |
||
| 60 | |||
| 61 | $nextprev = $DATA->page_metadata($this_page, 'nextprev'); |
||
| 62 | if ( isset($nextprev['next']['url']) ) { |
||
| 63 | $data['next'] = $nextprev['next']; |
||
| 64 | } |
||
| 65 | if ( isset($nextprev['prev']['url']) ) { |
||
| 66 | $data['prev'] = $nextprev['prev']; |
||
| 67 | } |
||
| 68 | |||
| 69 | $parent_page = $DATA->page_metadata($this_page, 'parent'); |
||
| 70 | $data['title'] = $DATA->page_metadata($this_page, 'title'); |
||
| 71 | if (!isset($data['title']) && $parent_page != '') { |
||
| 72 | $data['title'] = $DATA->page_metadata($parent_page, 'title'); |
||
| 73 | } |
||
| 74 | if ( $parent_page ) { |
||
| 75 | $data['parent_title'] = $DATA->page_metadata($parent_page, 'title'); |
||
| 76 | } |
||
| 77 | |||
| 78 | $data['section'] = $this->pageToSection(); |
||
| 79 | |||
| 80 | return $data; |
||
| 81 | } |
||
| 82 | |||
| 83 | protected function getURLs($data) { |
||
| 84 | global $DATA, $this_page; |
||
| 85 | |||
| 86 | $urls = array(); |
||
| 87 | |||
| 88 | $urls = array_merge($urls, $this->getViewUrls()); |
||
| 89 | |||
| 90 | if ( isset($data['info']['page']) ) { |
||
| 91 | $day = new \MySociety\TheyWorkForYou\Url($data['info']['page']); |
||
| 92 | $urls['day'] = $day; |
||
| 93 | } |
||
| 94 | |||
| 95 | return $urls; |
||
| 96 | } |
||
| 97 | |||
| 98 | protected function getViewUrls() { |
||
| 99 | $urls = array(); |
||
| 100 | $day = new \MySociety\TheyWorkForYou\Url('debates'); |
||
| 101 | $urls['debatesday'] = $day; |
||
| 102 | $urls['day'] = $day; |
||
| 103 | $day = new \MySociety\TheyWorkForYou\Url('whall'); |
||
| 104 | $urls['whallday'] = $day; |
||
| 105 | $day = new \MySociety\TheyWorkForYou\Url('lordsdebates'); |
||
| 106 | $urls['lordsday'] = $day; |
||
| 107 | return $urls; |
||
| 108 | } |
||
| 109 | |||
| 110 | protected function getSearchSections() { |
||
| 112 | } |
||
| 113 | |||
| 114 | protected function getRecessMajor() { |
||
| 115 | global $hansardmajors; |
||
| 116 | |||
| 117 | $recess_major = 1; # For all of UK Parliament |
||
| 118 | if ($hansardmajors[$this->major]['location'] == 'NI') { |
||
| 119 | $recess_major = 5; |
||
| 120 | } elseif ($hansardmajors[$this->major]['location'] == 'Scotland') { |
||
| 121 | $recess_major = 4; # For all of Scotland |
||
| 122 | } elseif ($this->major == 101) { |
||
| 123 | $recess_major = 101; # Lords slightly different |
||
| 124 | } |
||
| 125 | |||
| 126 | return $recess_major; |
||
| 127 | } |
||
| 128 | |||
| 129 | protected function display_year($year) { |
||
| 130 | global $this_page, $PAGE, $DATA; |
||
| 131 | $this_page = $this->page_base . 'year'; |
||
| 132 | if (is_numeric($year)) { |
||
| 133 | $DATA->set_page_metadata($this_page, 'title', $year); |
||
| 134 | } |
||
| 135 | |||
| 136 | $args = array ( 'year' => $year ); |
||
| 137 | $data = $this->list->display('calendar', $args, 'none'); |
||
| 138 | return $data; |
||
| 139 | } |
||
| 140 | |||
| 141 | protected function display_column($date, $column) { |
||
| 164 | } |
||
| 165 | |||
| 166 | protected function display_day($date) { |
||
| 178 | } |
||
| 179 | |||
| 180 | protected function display_section_or_speech($args = array()) { |
||
| 181 | global $DATA, $this_page, $THEUSER; |
||
| 182 | |||
| 183 | # += as we *don't* want to override any already supplied argument |
||
| 184 | $args += array ( |
||
| 185 | 'gid' => get_http_var('id'), |
||
| 186 | 's' => get_http_var('s'), // Search terms to be highlighted. |
||
| 187 | 'member_id' => get_http_var('m'), // Member's speeches to be highlighted. |
||
| 188 | ); |
||
| 189 | |||
| 190 | if (preg_match('/speaker:(\d+)/', get_http_var('s'), $mmm)) { |
||
|
|
|||
| 191 | $args['person_id'] = $mmm[1]; |
||
| 192 | } |
||
| 193 | |||
| 194 | try { |
||
| 195 | $data = $this->list->display('gid', $args, 'none'); |
||
| 196 | } catch (\RedirectException $e) { |
||
| 197 | $URL = new \MySociety\TheyWorkForYou\Url($this->major_data['page_all']); |
||
| 198 | if ($this->major == 6) { |
||
| 199 | # Magically (as in I can't remember quite why), pbc_clause will |
||
| 200 | # contain the new URL without any change... |
||
| 201 | $URL->remove( array('id') ); |
||
| 202 | } else { |
||
| 203 | $URL->insert( array('id'=>$e->getMessage()) ); |
||
| 204 | } |
||
| 205 | # put the search term back in so highlighting works. |
||
| 206 | # NB: as we don't see the # part of the URL we lose this :( |
||
| 207 | if ( $args['s'] !== '' ) { |
||
| 208 | $URL->insert( array('s'=>$args['s']) ); |
||
| 209 | } |
||
| 210 | redirect($URL->generate('none')); |
||
| 211 | } |
||
| 212 | |||
| 213 | $data['individual_item'] = ($this->list->commentspage == $this_page); |
||
| 214 | |||
| 215 | if ($data['individual_item']) { |
||
| 216 | $COMMENTLIST = new \COMMENTLIST; |
||
| 217 | $args['user_id'] = get_http_var('u'); |
||
| 218 | $args['epobject_id'] = $this->list->epobject_id(); |
||
| 219 | $data['comments']['object'] = $COMMENTLIST; |
||
| 220 | $data['comments']['args'] = $args; |
||
| 221 | $data['comments']['commentdata'] = array( |
||
| 222 | 'epobject_id' => $this->list->epobject_id(), |
||
| 223 | 'gid' => get_http_var('id'), # wrans is LIST->gid? |
||
| 224 | 'return_page' => $this_page |
||
| 225 | ); |
||
| 226 | } |
||
| 227 | |||
| 228 | if (!isset($data['info'])) { |
||
| 229 | header("HTTP/1.0 404 Not Found"); |
||
| 230 | $data['template'] = 'error'; |
||
| 231 | return $data; |
||
| 232 | } |
||
| 233 | |||
| 234 | # Okay, let's set up highlighting and glossarisation |
||
| 235 | |||
| 236 | list($bodies, $speeches) = $this->highlightSpeeches($data); |
||
| 237 | |||
| 238 | list($data, $first_speech, $subsection_title) = $this->annotateSpeeches($data, $bodies, $speeches); |
||
| 239 | |||
| 240 | |||
| 241 | list($country, $location, $assembly) = $this->getCountryDetails(); |
||
| 242 | $data['location'] = $location; |
||
| 243 | $data['current_assembly'] = $assembly; |
||
| 244 | |||
| 245 | $data = $this->setTitleAndAlertText($data, $subsection_title); |
||
| 246 | |||
| 247 | $data['debate_time_human'] = format_time($first_speech['htime'], 'g:i a'); |
||
| 248 | $data['debate_day_human'] = format_date($first_speech['hdate'], 'jS F Y'); |
||
| 249 | |||
| 250 | $URL = new \MySociety\TheyWorkForYou\Url($this->list->listpage); |
||
| 251 | $URL->insert(array('d' => $first_speech['hdate'])); |
||
| 252 | $URL->remove(array('id')); |
||
| 253 | $data['debate_day_link'] = $URL->generate(); |
||
| 254 | |||
| 255 | $data['nextprev'] = $DATA->page_metadata($this_page, 'nextprev'); |
||
| 256 | |||
| 257 | if (isset($THEUSER) && $THEUSER->postcode_is_set()) { |
||
| 258 | $user = new \MySociety\TheyWorkForYou\User(); |
||
| 259 | $data['mp_data'] = $user->getRep($this->majorToConsType(), $this->majorToHouse()[0]); |
||
| 260 | } |
||
| 261 | |||
| 262 | |||
| 263 | return $data; |
||
| 264 | } |
||
| 265 | |||
| 266 | private function setTitleAndAlertText($data, $subsection_title) { |
||
| 267 | if ($subsection_title) { |
||
| 268 | $data['heading'] = $subsection_title; |
||
| 269 | } else { |
||
| 270 | $data['heading'] = $data['section_title']; |
||
| 271 | } |
||
| 272 | |||
| 273 | if ($subsection_title) { |
||
| 274 | $data['intro'] = "$data[section_title]"; |
||
| 275 | } else { |
||
| 276 | $data['intro'] = ""; |
||
| 277 | } |
||
| 278 | |||
| 279 | if (array_key_exists('text_heading', $data['info'])) { |
||
| 280 | // avoid having Clause 1 etc as the alert text search string on PBC pages as it's |
||
| 281 | // almost certainly not what the person wants |
||
| 282 | if ( $this->major == 6 ) { |
||
| 283 | $data['email_alert_text'] = $data['section_title']; |
||
| 284 | } else { |
||
| 285 | $data['email_alert_text'] = $data['info']['text_heading']; |
||
| 286 | } |
||
| 287 | } else { |
||
| 288 | // The user has requested only part of a debate, so find a suitable title |
||
| 289 | if ($subsection_title) { |
||
| 290 | $data['intro'] = "Part of $data[section_title]"; |
||
| 291 | } else { |
||
| 292 | $data['intro'] = "Part of the debate"; |
||
| 293 | } |
||
| 294 | foreach ($data['rows'] as $row) { |
||
| 295 | if ($row['htype'] == 10 || $row['htype'] == 11) { |
||
| 296 | $data['email_alert_text'] = $row['body']; |
||
| 297 | $data['full_debate_url'] = $row['listurl']; |
||
| 298 | break; |
||
| 299 | } |
||
| 300 | } |
||
| 301 | } |
||
| 302 | // strip a couple of common characters that result in encode junk in the |
||
| 303 | // search string |
||
| 304 | $data['email_alert_text'] = preg_replace('/(?:[:()\[\]]|&#\d+;)/', '', $data['email_alert_text']); |
||
| 305 | |||
| 306 | return $data; |
||
| 307 | } |
||
| 308 | |||
| 309 | private function highlightSpeeches($data) { |
||
| 310 | $SEARCHENGINE = null; |
||
| 311 | if (isset($data['info']['searchstring']) && $data['info']['searchstring'] != '') { |
||
| 312 | $SEARCHENGINE = new \SEARCHENGINE($data['info']['searchstring']); |
||
| 313 | } |
||
| 314 | |||
| 315 | // Before we print the body text we need to insert glossary links |
||
| 316 | // and highlight search string words. |
||
| 317 | |||
| 318 | $speeches = 0; |
||
| 319 | $bodies = array(); |
||
| 320 | foreach ($data['rows'] as $row) { |
||
| 321 | $htype = $row['htype']; |
||
| 322 | if ($htype == 12 || $htype == 13 || $htype == 14) { |
||
| 323 | $speeches++; |
||
| 324 | } |
||
| 325 | $body = $row['body']; |
||
| 326 | $body = preg_replace('#<phrase class="honfriend" id="uk.org.publicwhip/member/(\d+)" name="([^"]*?)">(.*?\s*\((.*?)\))</phrase>#', '<a href="/mp/?m=$1" title="Our page on $2 - \'$3\'">$4</a>', $body); |
||
| 327 | $body = preg_replace('#<phrase class="honfriend" name="([^"]*?)" person_id="uk.org.publicwhip/person/(\d+)">(.*?\s*\((.*?)\))</phrase>#', '<a href="/mp/?p=$2" title="Our page on $1 - \'$3\'">$4</a>', $body); |
||
| 328 | $body = preg_replace_callback('#<phrase class="offrep" id="(.*?)/(\d+)-(\d+)-(\d+)\.(.*?)">(.*?)</phrase>#', function($matches) { |
||
| 329 | return '<a href="/search/?pop=1&s=date:' . $matches[2] . $matches[3] . $matches[4] . '+column:' . $matches[5] . '+section:' . $matches[1] .'">' . str_replace("Official Report", "Hansard", $matches[6]) . '</a>'; |
||
| 330 | }, $body); |
||
| 331 | #$body = preg_replace('#<phrase class="offrep" id="((.*?)/(\d+)-(\d+)-(\d+)\.(.*?))">(.*?)</phrase>#e', "\"<a href='/search/?pop=1&s=date:$3$4$5+column:$6+section:$2&match=$1'>\" . str_replace('Official Report', 'Hansard', '$7') . '</a>'", $body); |
||
| 332 | $bodies[] = $body; |
||
| 333 | } |
||
| 334 | |||
| 335 | if ($SEARCHENGINE) { |
||
| 336 | // We have some search terms to highlight. |
||
| 337 | twfy_debug_timestamp('Before highlight'); |
||
| 338 | $bodies = $SEARCHENGINE->highlight($bodies); |
||
| 339 | twfy_debug_timestamp('After highlight'); |
||
| 340 | } |
||
| 341 | // Do all this unless the glossary is turned off in the URL |
||
| 342 | if (get_http_var('ug') != 1) { |
||
| 343 | // And glossary phrases |
||
| 344 | twfy_debug_timestamp('Before glossarise'); |
||
| 345 | |||
| 346 | $args['sort'] = "regexp_replace"; |
||
| 347 | $GLOSSARY = new \GLOSSARY($args); |
||
| 348 | $bodies = $GLOSSARY->glossarise($bodies, 1); |
||
| 349 | |||
| 350 | twfy_debug_timestamp('After glossarise'); |
||
| 351 | } |
||
| 352 | |||
| 353 | return array($bodies, $speeches); |
||
| 354 | } |
||
| 355 | |||
| 356 | private function annotateSpeeches($data, $bodies, $speeches) { |
||
| 357 | global $THEUSER; |
||
| 358 | $first_speech = null; |
||
| 359 | $data['section_title'] = ''; |
||
| 360 | $subsection_title = ''; |
||
| 361 | $rows = count($data['rows']); |
||
| 362 | for ($i=0; $i<$rows; $i++) { |
||
| 363 | $row = $data['rows'][$i]; |
||
| 364 | $htype = $row['htype']; |
||
| 365 | // HPOS should be defined below if it's needed; otherwise default to 0 |
||
| 366 | $heading_hpos = 0; |
||
| 367 | if ($htype == 10) { |
||
| 368 | $data['section_title'] = $row['body']; |
||
| 369 | $heading_hpos = $row['hpos']; |
||
| 370 | } elseif ($htype == 11) { |
||
| 371 | $subsection_title = $row['body']; |
||
| 372 | $heading_hpos = $row['hpos']; |
||
| 373 | } elseif ($htype == 12) { |
||
| 374 | # Splitting out highlighting results back into individual bits |
||
| 375 | $data['rows'][$i]['body'] = $bodies[$i]; |
||
| 376 | } |
||
| 377 | if ($htype == 12 || $htype == 13 || $htype == 14) { |
||
| 378 | if (!$first_speech) { |
||
| 379 | $first_speech = $data['rows'][$i]; |
||
| 380 | } |
||
| 381 | |||
| 382 | # Voting links |
||
| 383 | $data['rows'][$i]['voting_data'] = ''; |
||
| 384 | if (isset($row['votes'])) { |
||
| 385 | $data['rows'][$i]['voting_data'] = $this->generate_votes( $row['votes'], $row['epobject_id'], $row['gid'] ); |
||
| 386 | } |
||
| 387 | |||
| 388 | # Annotation link |
||
| 389 | if ($this->is_debate_section_page()) { |
||
| 390 | $data['rows'][$i]['commentteaser'] = $this->generate_commentteaser($row); |
||
| 391 | } |
||
| 392 | |||
| 393 | if (isset($row['mentions'])) { |
||
| 394 | $data['rows'][$i]['mentions'] = $this->get_question_mentions_html($row['mentions']); |
||
| 395 | } |
||
| 396 | |||
| 397 | if ($this->major == 1) { |
||
| 398 | $data['rows'][$i]['video'] = $this->get_video_html($row, $heading_hpos, $speeches); |
||
| 399 | } |
||
| 400 | |||
| 401 | if (array_key_exists('name', $data['rows'][$i]['speaker'])) { |
||
| 402 | $data['rows'][$i]['socialteaser'] = sprintf( |
||
| 403 | '%s on %s, at TheyWorkForYou', |
||
| 404 | ucfirst($data['rows'][$i]['speaker']['name']), |
||
| 405 | $data['section_title'] |
||
| 406 | ); |
||
| 407 | } else { |
||
| 408 | $data['rows'][$i]['socialteaser'] = sprintf( |
||
| 409 | '%s on TheyWorkForYou', |
||
| 410 | $data['section_title'] |
||
| 411 | ); |
||
| 412 | } |
||
| 413 | |||
| 414 | $data['rows'][$i]['socialurl'] = sprintf( |
||
| 415 | 'https://www.theyworkforyou.com%s', |
||
| 416 | $row['commentsurl'] |
||
| 417 | ); |
||
| 418 | } |
||
| 419 | } |
||
| 420 | |||
| 421 | return array($data, $first_speech, $subsection_title); |
||
| 422 | } |
||
| 423 | |||
| 424 | private function getCountryDetails() { |
||
| 475 | } |
||
| 476 | |||
| 477 | private function majorToHouse() { |
||
| 478 | $major_to_house = array( |
||
| 479 | 1 => array(1), |
||
| 480 | 2 => array(1), |
||
| 481 | 3 => array(1, 2), |
||
| 482 | 4 => array(1, 2), |
||
| 483 | 5 => array(3), |
||
| 484 | 6 => array(1), |
||
| 485 | 7 => array(4), |
||
| 486 | 8 => array(4), |
||
| 487 | 101 => array(2), |
||
| 488 | ); |
||
| 489 | |||
| 490 | return $major_to_house[$this->major]; |
||
| 491 | } |
||
| 492 | |||
| 493 | private function majorToConsType() { |
||
| 494 | $major_to_cons_type = array( |
||
| 495 | 1 => 'WMC', |
||
| 496 | 2 => 'WMC', |
||
| 497 | 3 => 'WMC', |
||
| 498 | 4 => 'WMC', |
||
| 499 | 5 => 'NIE', |
||
| 500 | 6 => 'WMC', |
||
| 501 | 7 => 'SPC', |
||
| 502 | 8 => 'SPC', |
||
| 503 | 101 => '', |
||
| 504 | ); |
||
| 505 | |||
| 506 | return $major_to_cons_type[$this->major]; |
||
| 507 | } |
||
| 508 | |||
| 509 | protected function display_front() { |
||
| 510 | global $DATA, $this_page; |
||
| 511 | $this_page = $this->page_base . 'front'; |
||
| 512 | $data = array(); |
||
| 513 | if ( $this->index_template ) { |
||
| 514 | $data['template'] = $this->index_template; |
||
| 515 | } |
||
| 516 | |||
| 517 | $class = new $this->class; |
||
| 518 | $content = array(); |
||
| 519 | $content['data'] = $this->front_content(); |
||
| 520 | |||
| 521 | $content['calendar'] = $class->display('calendar', array('months' => 1), 'none'); |
||
| 522 | |||
| 523 | if ( $rssurl = $DATA->page_metadata($this_page, 'rss') ) { |
||
| 524 | $content['rssurl'] = $rssurl; |
||
| 525 | } |
||
| 526 | |||
| 527 | $data['content'] = $content; |
||
| 528 | return $this->addCommonData($data); |
||
| 529 | |||
| 530 | } |
||
| 531 | |||
| 532 | public function is_debate_section_page() { |
||
| 533 | global $this_page; |
||
| 534 | return ($this->major_data['type'] == 'debate' && $this->major_data['page_all'] == $this_page); |
||
| 535 | } |
||
| 536 | |||
| 537 | //$totalcomments, $comment, $commenturl |
||
| 538 | function generate_commentteaser ($row) { |
||
| 539 | // Returns HTML for the one fragment of comment and link for the sidebar. |
||
| 540 | // $totalcomments is the number of comments this item has on it. |
||
| 541 | // $comment is an array like: |
||
| 542 | /* $comment = array ( |
||
| 543 | 'comment_id' => 23, |
||
| 544 | 'user_id' => 34, |
||
| 545 | 'body' => 'Blah blah...', |
||
| 546 | 'posted' => '2004-02-24 23:45:30', |
||
| 547 | 'username' => 'phil' |
||
| 548 | ) |
||
| 549 | */ |
||
| 550 | // $url is the URL of the item's page, which contains comments. |
||
| 551 | |||
| 552 | if ($row['totalcomments'] == 0) { |
||
| 553 | return; |
||
| 554 | } |
||
| 555 | |||
| 556 | //Add existing annotations |
||
| 557 | $comment = $row['comment']; |
||
| 558 | |||
| 559 | // If the comment is longer than the speech body, we want to trim it |
||
| 560 | // to be the same length so they fit next to each other. |
||
| 561 | // But the comment typeface is smaller, so we scale things slightly too... |
||
| 562 | $targetsize = round(strlen($row['body']) * 0.6); |
||
| 563 | |||
| 564 | $linktext = ''; |
||
| 565 | if ($targetsize > strlen($comment['body'])) { |
||
| 566 | // This comment will fit in its entirety. |
||
| 567 | $commentbody = $comment['body']; |
||
| 568 | |||
| 569 | if ($row['totalcomments'] > 1) { |
||
| 570 | $morecount = $row['totalcomments'] - 1; |
||
| 571 | $plural = $morecount == 1 ? 'annotation' : 'annotations'; |
||
| 572 | $linktext = "Read $morecount more $plural"; |
||
| 573 | } |
||
| 574 | |||
| 575 | } else { |
||
| 576 | // This comment needs trimming. |
||
| 577 | $commentbody = trim_characters($comment['body'], 0, $targetsize, 1000); |
||
| 578 | if ($row['totalcomments'] > 1) { |
||
| 579 | $morecount = $row['totalcomments'] - 1; |
||
| 580 | $plural = $morecount == 1 ? 'annotation' : 'annotations'; |
||
| 581 | $linktext = "Continue reading (and $morecount more $plural)"; |
||
| 582 | } else { |
||
| 583 | $linktext = 'Continue reading'; |
||
| 584 | } |
||
| 585 | } |
||
| 586 | |||
| 587 | return array( |
||
| 588 | 'body' => prepare_comment_for_display($commentbody), |
||
| 589 | 'username' => _htmlentities($comment['username']), |
||
| 590 | 'linktext' => $linktext, |
||
| 591 | 'commentsurl' => $row['commentsurl'], |
||
| 592 | 'comment_id' => $comment['comment_id'], |
||
| 593 | ); |
||
| 594 | } |
||
| 595 | |||
| 596 | protected function get_question_mentions_html($row_data) { |
||
| 598 | } |
||
| 599 | |||
| 600 | private function pageToSection() { |
||
| 601 | $sections = array( |
||
| 602 | 1 => 'debates', |
||
| 603 | 2 => 'whall', |
||
| 604 | 3 => 'wrans', |
||
| 605 | 4 => 'wms', |
||
| 606 | 5 => 'ni', |
||
| 617 |