Commit | Line | Data |
---|---|---|
2be9fe58 NI |
1 | <?php |
2 | /*************************************************************************** | |
c441aabe | 3 | * Copyright (C) 2003-2014 Polytechnique.org * |
2be9fe58 NI |
4 | * http://opensource.polytechnique.org/ * |
5 | * * | |
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. * | |
10 | * * | |
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. * | |
15 | * * | |
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 * | |
18 | * Foundation, Inc., * | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | ***************************************************************************/ | |
21 | ||
22 | // {{{ class ComLArticle | |
23 | ||
24 | class ComLArticle | |
25 | { | |
60b19854 | 26 | // Maximum number of lines per article, as wanted by the NL master |
37b9ab30 | 27 | const MAX_LINES_PER_ARTICLE = 8; |
60b19854 NI |
28 | const MAX_CHARACTERS_PER_LINE = 68; |
29 | ||
2be9fe58 NI |
30 | // {{{ properties |
31 | ||
32 | public $aid; | |
33 | public $cid; | |
34 | public $pos; | |
35 | public $title; | |
36 | public $body; | |
37 | public $append; | |
38 | ||
39 | // }}} | |
40 | // {{{ constructor | |
41 | ||
42 | function __construct($title='', $body='', $append='', $aid=-1, $cid=0, $pos=0) | |
43 | { | |
44 | $this->body = $body; | |
45 | $this->title = $title; | |
46 | $this->append = $append; | |
47 | $this->aid = $aid; | |
48 | $this->cid = $cid; | |
49 | $this->pos = $pos; | |
50 | } | |
51 | ||
52 | // }}} | |
53 | // {{{ function title() | |
54 | ||
55 | public function title() | |
56 | { return trim($this->title); } | |
57 | ||
58 | // }}} | |
59 | // {{{ function body() | |
60 | ||
61 | public function body() | |
62 | { return trim($this->body); } | |
63 | ||
64 | // }}} | |
65 | // {{{ function append() | |
66 | ||
67 | public function append() | |
68 | { return trim($this->append); } | |
69 | ||
70 | // }}} | |
71 | // {{{ function toText() | |
72 | ||
73 | public function toText($hash = null, $login = null) | |
74 | { | |
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); | |
81 | } else { | |
82 | $text = str_replace('%HASH%', '', $text); | |
83 | } | |
84 | return $text; | |
85 | } | |
86 | ||
87 | // }}} | |
88 | // {{{ function toHtml() | |
89 | ||
90 | public function toHtml($hash = null, $login = null) | |
91 | { | |
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); | |
95 | ||
96 | $art = "$title\n"; | |
97 | $art .= "<div class='art'>\n$body\n"; | |
98 | if ($app) { | |
99 | $art .= "<div class='app'>$app</div>"; | |
100 | } | |
101 | $art .= "</div>\n"; | |
102 | if (!is_null($hash) && !is_null($login)) { | |
103 | $art = str_replace('%HASH%', "$hash/$login", $art); | |
104 | } else { | |
105 | $art = str_replace('%HASH%', '', $art); | |
106 | } | |
107 | ||
108 | return $art; | |
109 | } | |
110 | ||
111 | // }}} | |
60b19854 NI |
112 | // {{{ function check() |
113 | ||
114 | public function check() | |
115 | { | |
116 | $rest = $this->remain(); | |
117 | ||
118 | return $rest['remaining_lines'] >= 0; | |
119 | } | |
120 | ||
121 | // }}} | |
122 | // {{{ function remain() | |
123 | ||
124 | public function remain() | |
125 | { | |
126 | $text = MiniWiki::WikiToText($this->body); | |
127 | $array = explode("\n", wordwrap($text, self::MAX_CHARACTERS_PER_LINE)); | |
128 | $lines_count = 0; | |
129 | foreach ($array as $line) { | |
130 | if (trim($line) != '') { | |
131 | ++$lines_count; | |
132 | } | |
133 | } | |
134 | ||
135 | return array( | |
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]) | |
138 | ); | |
139 | } | |
140 | // }}} | |
2be9fe58 NI |
141 | } |
142 | ||
143 | // }}} | |
144 | ||
448c8cdc | 145 | // vim:set et sw=4 sts=4 sws=4 fenc=utf-8: |
2be9fe58 | 146 | ?> |