2 /***************************************************************************
3 * Copyright (C) 2003-2014 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 // {{{ class ComLArticle
26 // Maximum number of lines per article, as wanted by the NL master
27 const MAX_LINES_PER_ARTICLE
= 8;
28 const MAX_CHARACTERS_PER_LINE
= 68;
42 function __construct($title='', $body='', $append='', $aid=-1, $cid=0, $pos=0)
45 $this->title
= $title;
46 $this->append
= $append;
53 // {{{ function title()
55 public function title()
56 { return trim($this->title
); }
59 // {{{ function body()
61 public function body()
62 { return trim($this->body
); }
65 // {{{ function append()
67 public function append()
68 { return trim($this->append
); }
71 // {{{ function toText()
73 public function toText($hash = null
, $login = null
)
75 $title = '*'.$this->title().'*';
76 $body = MiniWiki
::WikiToText($this->body
, true
);
77 $app = MiniWiki
::WikiToText($this->append
, false
, 4);
78 $text = trim("$title\n\n$body\n\n$app")."\n";
79 if (!is_null($hash) && !is_null($login)) {
80 $text = str_replace('%HASH%', "$hash/$login", $text);
82 $text = str_replace('%HASH%', '', $text);
88 // {{{ function toHtml()
90 public function toHtml($hash = null
, $login = null
)
92 $title = "<h2 class='xorg_nl'><a id='art{$this->aid}'></a>".pl_entities($this->title()).'</h2>';
93 $body = MiniWiki
::WikiToHTML($this->body
);
94 $app = MiniWiki
::WikiToHTML($this->append
);
97 $art .= "<div class='art'>\n$body\n";
99 $art .= "<div class='app'>$app</div>";
102 if (!is_null($hash) && !is_null($login)) {
103 $art = str_replace('%HASH%', "$hash/$login", $art);
105 $art = str_replace('%HASH%', '', $art);
112 // {{{ function check()
114 public function check()
116 $rest = $this->remain();
118 return $rest['remaining_lines'] >= 0;
122 // {{{ function remain()
124 public function remain()
126 $text = MiniWiki
::WikiToText($this->body
);
127 $array = explode("\n", wordwrap($text, self
::MAX_CHARACTERS_PER_LINE
));
129 foreach ($array as $line) {
130 if (trim($line) != '') {
136 'remaining_lines' => self
::MAX_LINES_PER_ARTICLE
- $lines_count,
137 'remaining_characters_for_last_line' => self
::MAX_CHARACTERS_PER_LINE
- strlen($array[count($array) - 1])
145 // vim:set et sw=4 sts=4 sws=4 fenc=utf-8: