Browse the code
| Differences between 152 and 153 on /trunk/inc/modules/paste. | |||||||
|---|---|---|---|---|---|---|---|
| Number of edited files: | 7 (0 added, 0 deleted and 7 modified) | ||||||
| Author: | xbright | ||||||
| Log message: | * New way to use gettext (with our i18n function rather than sprintf/gettext) |
||||||
| Date: | 2008-06-08 14:20:46 | ||||||
|
|||||||
| Old | New | Code |
|---|---|---|
| 1 | 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 | 2 |
<module active="TRUE"> |
| 3 |
<name version="0.1" license="AGPLv3" name="Notepad"/> | |
| 4 |
<author url="http://www.codingteam.net" mail="webmaster@codingteam.net" author="CodingTeam"/> | |
| 3 |
<name name="Notepad"/>
| |
| 5 | 4 |
<description> |
| 6 | 5 |
A module for pasting texts and code. |
| 7 | 6 |
</description> |
| 8 | 7 |
| Old | New | Code |
|---|---|---|
| 36 | 36 |
$views[(string) $view['name']] = (string) $view['active']; |
| 37 | 37 | |
| 38 | 38 |
// Notepad menu |
| 39 |
$this->notepadmenu = array('module' => 'paste', 'link' => 'paste', 'title' => _('Notepad'), 'position' => 3);
| |
| 39 |
$this->notepadmenu = array('module' => 'paste', 'link' => 'paste', 'title' => i18n('Notepad'), 'position' => 3);
| |
| 40 | 40 | |
| 41 | 41 |
// Page menu |
| 42 | 42 |
$this->pagemenu = '<ul id="rootmenu">'; |
| 43 | 43 | |
| 44 | 44 |
if ($views['default'] == 'TRUE') |
| 45 |
$this->pagemenu .= '<li '.( (!isset($this->page[2])) ? 'class="current" style="background-image: url(\'public/images/icons/stock/form/stock_form-time-field.png\');"' : '' ).'> | |
| 46 |
<a href="paste">'._('Latest entries').'</a></li>';
| |
| 45 |
$this->pagemenu .= '<li '.( (!isset($this->page[2])) ?
| |
| 46 |
'class="current"><a href="paste"><img src="public/images/icons/stock/form/stock_form-time-field.png" style="float: left;padding-right: 5px;">' : | |
| 47 |
'><a href="paste">' ).i18n('Latest entries').'</a></li>';
| |
| 47 | 48 | |
| 48 | 49 |
if ($views['new'] == 'TRUE') |
| 49 |
$this->pagemenu .= '<li '.( ($this->page[2] == 'new') ? 'class="current" style="background-image: url(\'public/images/icons/actions/list-add.png\');"' : '' ).'> | |
| 50 |
<a href="paste/new">'._('Paste!').'</a></li>';
| |
| 50 |
$this->pagemenu .= '<li '.( ($this->page[2] == 'new') ?
| |
| 51 |
'class="current"><a href="paste/new"><img src="public/images/icons/actions/list-add.png" style="float: left;padding-right: 5px;" />' : | |
| 52 |
'><a href="paste/new">' ).i18n('Paste!').'</a></li>';
| |
| 51 | 53 | |
| 52 | 54 |
$this->pagemenu .= '</ul> |
| 53 | 55 |
<div style="margin-bottom: 3.0em;"> </div>'; |
| 54 | 56 |
| Old | New | Code |
|---|---|---|
| 35 | 35 |
$this->maincontent = ''; |
| 36 | 36 | |
| 37 | 37 |
// Meta tags |
| 38 |
$this->metatags = array('title' => _('Notepad'),
| |
| 38 |
$this->metatags = array('title' => i18n('Notepad'),
| |
| 39 | 39 |
'feed' => 'paste', |
| 40 | 40 |
'description' => '', |
| 41 | 41 |
'keywords' => '' |
| 72 | 72 |
function showFeed() |
| 73 | 73 |
{
|
| 74 | 74 |
global $baseurl; |
| 75 |
$feed_array['title'] = _('Notepad');
| |
| 75 |
$feed_array['title'] = i18n('Notepad');
| |
| 76 | 76 |
$feed_array['link'] = $baseurl.'paste'; |
| 77 |
$feed_array['description'] = _('Latest pastes in the notepad.');
| |
| 77 |
$feed_array['description'] = i18n('Latest pastes in the notepad.');
| |
| 78 | 78 | |
| 79 | 79 |
$list = $this->paste->getLastPaste(5); |
| 80 | 80 | |
| 129 | 129 |
function showPage() |
| 130 | 130 |
{
|
| 131 | 131 |
$list = $this->paste->getLastPaste(20); |
| 132 |
$this->maincontent .= '<h1 style="margin-bottom: 20px;">'._('Notepad').'</h1>';
| |
| 132 |
$this->maincontent .= '<h1 style="margin-bottom: 20px;">'.i18n('Notepad').'</h1>';
| |
| 133 | 133 | |
| 134 | 134 |
if (!$list) |
| 135 |
$this->maincontent .= '<em>'._('Not yet.').'</em>';
| |
| 135 |
$this->maincontent .= '<em>'.i18n('Not yet.').'</em>';
| |
| 136 | 136 |
else |
| 137 | 137 |
{
|
| 138 |
$this->maincontent .= '<h2>'._('Last 20 pastes').'</h2>
| |
| 138 |
$this->maincontent .= '<h2>'.i18n('Last 20 pastes').'</h2>
| |
| 139 | 139 | |
| 140 | 140 |
<table style="width: 100%;"> |
| 141 | 141 |
<thead> |
| 142 | 142 |
<tr> |
| 143 |
<th>'._('Snippet title').'</th>
| |
| 144 |
<th>'._('Author').'</th>
| |
| 145 |
<th>'._('Language').'</th>
| |
| 143 |
<th>'.i18n('Snippet title').'</th>
| |
| 144 |
<th>'.i18n('Author').'</th>
| |
| 145 |
<th>'.i18n('Language').'</th>
| |
| 146 | 146 |
</tr> |
| 147 | 147 |
</thead> |
| 148 | 148 |
<tbody>'; |
| 175 | 175 |
</table> |
| 176 | 176 | |
| 177 | 177 |
<div class="feed" style="background-image: url(\'public/images/feed.png\');"> |
| 178 |
'.sprintf( | |
| 179 |
_('Feed subscription: %s or %s.'), '<a href="rss/paste">'._('RSS').'</a>',
| |
| 180 |
'<a href="atom/paste">'._('Atom').'</a>').'
| |
| 181 |
</div>'; | |
| 178 |
'.i18n('Feed subscription: %(rss)s or %(atom)s.',
| |
| 179 |
array('rss' => '<a href="rss/paste">'.i18n('RSS').'</a>',
| |
| 180 |
'atom' => '<a href="atom/paste">'.i18n('Atom').'</a>'
| |
| 181 |
)).'</div>'; | |
| 182 | 182 |
} |
| 183 | 183 | |
| 184 | 184 |
return $this->maincontent; |
| 185 | 185 |
| Old | New | Code |
|---|---|---|
| 42 | 42 |
exit('Error.');
|
| 43 | 43 | |
| 44 | 44 |
// Meta tags |
| 45 |
$this->metatags = array('title' => sprintf(_('Differences %s - Paste'), $this->page[3]),
| |
| 45 |
$this->metatags = array('title' => i18n('Differences %(id)s - Paste', array('id' => $this->page[3])),
| |
| 46 | 46 |
'feed' => '', |
| 47 | 47 |
'description' => '', |
| 48 | 48 |
'keywords' => '' |
| 82 | 82 |
$diff = new Diff(explode("\n", $first_text), explode("\n", $second_text), 1);
|
| 83 | 83 | |
| 84 | 84 |
$this->maincontent .= '<h1>'.htmlspecialchars($this->paste->getTitle()).'</h1> |
| 85 |
<h2>'.sprintf(_('Differences between revision %s and %s'), '<a href="paste/show/'.$this->firstpaste.'">'.$this->firstpaste.'</a>', '<a href="paste/show/'.$this->secondpaste.'">'.$this->secondpaste.'</a>').'</h2>'.$diff->output;
| |
| 85 |
<h2>'.i18n('Differences between revision %(first)s and %(second)s',
| |
| 86 |
array('first' => '<a href="paste/show/'.$this->firstpaste.'">'.$this->firstpaste.'</a>',
| |
| 87 |
'second' => '<a href="paste/show/'.$this->secondpaste.'">'.$this->secondpaste.'</a>' | |
| 88 |
)).'</h2>'.$diff->output; | |
| 86 | 89 | |
| 87 | 90 |
return $this->maincontent; |
| 88 | 91 |
} |
| 89 | 92 |
| Old | New | Code |
|---|---|---|
| 53 | 53 |
$ext = $this->paste->getLanguage(); |
| 54 | 54 |
|
| 55 | 55 |
if (!$this->paste) |
| 56 |
exit(_('Error: paste not found.'));
| |
| 56 |
exit(i18n('Error: paste not found.'));
| |
| 57 | 57 |
else |
| 58 | 58 |
{
|
| 59 | 59 |
Header('Content-Type: application/force-download');
|
| 60 | 60 |
| Old | New | Code |
|---|---|---|
| 35 | 35 |
$this->maincontent = ''; |
| 36 | 36 | |
| 37 | 37 |
// Meta tags |
| 38 |
$this->metatags = array('title' => _('Paste to the notepad'),
| |
| 38 |
$this->metatags = array('title' => i18n('Paste to the notepad'),
| |
| 39 | 39 |
'feed' => '', |
| 40 | 40 |
'description' => '', |
| 41 | 41 |
'keywords' => '' |
| 86 | 86 | |
| 87 | 87 |
// Test |
| 88 | 88 |
if (empty($this->form_title) OR empty($this->form_code) OR empty($this->form_language)) |
| 89 |
$this->form_error = _('You need to choose a title, a language and you have to enter the text to paste.');
| |
| 89 |
$this->form_error = i18n('You need to choose a title, a language and you have to enter the text to paste.');
| |
| 90 | 90 |
} |
| 91 | 91 |
else |
| 92 | 92 |
{
|
| 93 | 93 |
// No special chars in the nickname |
| 94 | 94 |
if (!ereg("^[0-9A-Za-z_-]+$", $this->form_nickname))
|
| 95 |
$this->form_error = _('No special characters in nickname (Authorized characters are 0-9, A-Z and a-z).');
| |
| 95 |
$this->form_error = i18n('No special characters in nickname (Authorized characters are 0-9, A-Z and a-z).');
| |
| 96 | 96 |
|
| 97 | 97 |
$unregistered_nick = $this->form_nickname; |
| 98 | 98 |
|
| 102 | 102 |
|
| 103 | 103 |
// Test |
| 104 | 104 |
if (empty($this->form_title) OR empty($this->form_nickname) OR empty($this->form_code) OR empty($this->form_language)) |
| 105 |
$this->form_error = _('You need to choose a title, a nickname, a language and you have to enter the text to paste.');
| |
| 105 |
$this->form_error = i18n('You need to choose a title, a nickname, a language and you have to enter the text to paste.');
| |
| 106 | 106 |
|
| 107 | 107 |
// Check captcha |
| 108 | 108 |
if (!ereg("^([0-9a-z]{40})$" , $captcha_))
|
| 109 | 109 |
exit('Error.');
|
| 110 | 110 |
if (sha1($captcha + $_SESSION['alea']) != $captcha_) |
| 111 |
$this->form_error = _('Please verify the captcha.');
| |
| 111 |
$this->form_error = i18n('Please verify the captcha.');
| |
| 112 | 112 |
} |
| 113 | 113 | |
| 114 | 114 |
if (!$this->form_error) |
| 148 | 148 | |
| 149 | 149 |
function showPage() |
| 150 | 150 |
{
|
| 151 |
$this->maincontent .= '<h1 style="margin-bottom: 20px;">'._('Notepad').'</h1>
| |
| 152 |
<h2>'._('Add a new entrie').'</h2>';
| |
| 151 |
$this->maincontent .= '<h1 style="margin-bottom: 20px;">'.i18n('Notepad').'</h1>
| |
| 152 |
<h2>'.i18n('Add a new entrie').'</h2>';
| |
| 153 | 153 | |
| 154 | 154 |
global $basedir; |
| 155 | 155 |
$captcha = generateCaptcha(); |
| 167 | 167 |
$pid_form_source = $this->paste->getSource(); |
| 168 | 168 |
} |
| 169 | 169 |
elseif (isset($this->page[3])) |
| 170 |
exit(_('Error: paste not found.'));
| |
| 170 |
exit(i18n('Error: paste not found.'));
| |
| 171 | 171 |
} |
| 172 | 172 | |
| 173 | 173 |
function show_time_available_request ($pstform, $tag) |
| 174 | 174 |
{
|
| 175 |
$return = '<strong>'._('Time available:').'</strong><br />'."\n";
| |
| 175 |
$return = '<strong>'.i18n('Time available:').'</strong><br />'."\n";
| |
| 176 | 176 |
|
| 177 | 177 |
if ($tag) |
| 178 | 178 |
{
|
| 182 | 182 |
else |
| 183 | 183 |
if ($pstform == 'd') |
| 184 | 184 |
$return .= ' checked="checked"'; |
| 185 |
$return .= '/>'._('A day').'</label>
| |
| 185 |
$return .= '/>'.i18n('A day').'</label>
| |
| 186 | 186 |
<label><input type="radio" name="time" value="1"'; |
| 187 | 187 |
if (!empty($pstform)) |
| 188 | 188 |
if ($pstform == 'm') |
| 189 | 189 |
$return .= ' checked="checked"'; |
| 190 |
$return .= '/>'._('A month').'</label>
| |
| 190 |
$return .= '/>'.i18n('A month').'</label>
| |
| 191 | 191 |
<label><input type="radio" name="time" value="2"'; |
| 192 | 192 |
if (!empty($pstform)) |
| 193 | 193 |
if ($pstform == 'f') |
| 194 | 194 |
$return .= ' checked="checked"'; |
| 195 |
$return .= '/>'._('Forever').'</label><br /><br />'."\n";
| |
| 195 |
$return .= '/>'.i18n('Forever').'</label><br /><br />'."\n";
| |
| 196 | 196 |
} |
| 197 | 197 |
else |
| 198 | 198 |
{
|
| 199 |
$return .= '<em>'._('Not available when editing.').'</em><br /><br />';
| |
| 199 |
$return .= '<em>'.i18n('Not available when editing.').'</em><br /><br />';
| |
| 200 | 200 |
$return .= '<input type="hidden" name="time" value="2" />'; |
| 201 | 201 |
} |
| 202 | 202 |
|
| 219 | 219 |
else |
| 220 | 220 |
$this->maincontent .= show_time_available_request($this->form_time, 1); |
| 221 | 221 |
|
| 222 |
$this->maincontent .= '<strong>'._('Captcha security:').'</strong><br />
| |
| 223 |
'._('In order to check you are not a robot, please answer to that simple question:').'<br />
| |
| 222 |
$this->maincontent .= '<strong>'.i18n('Captcha security:').'</strong><br />
| |
| 223 |
'.i18n('In order to check you are not a robot, please answer to that simple question:').'<br />
| |
| 224 | 224 |
<div class="justify">'.$captcha[0].' + '.$captcha[1].' |
| 225 | 225 |
<input type="text" style="width:40px;" maxlength="255" name="'.$_SESSION['captcha'].'" value="" /> |
| 226 | 226 |
<input type="text" name="captcha_" value="'.$captcha[2].'" class="captcha" /></div><br /><br />'."\n"; |
| 227 | 227 |
} |
| 228 | 228 |
$this->maincontent .= '</div><p> |
| 229 |
<strong>'._('Snippet title:').'</strong><br />
| |
| 229 |
<strong>'.i18n('Snippet title:').'</strong><br />
| |
| 230 | 230 |
<input type="text" style="width:200px;" maxlength="255" name="title" value="'; |
| 231 | 231 |
|
| 232 | 232 |
if (!empty($this->form_title)) |
| 245 | 245 |
} |
| 246 | 246 |
else |
| 247 | 247 |
{
|
| 248 |
$this->maincontent .= '<strong>'._('Nickname:').'</strong><br />
| |
| 248 |
$this->maincontent .= '<strong>'.i18n('Nickname:').'</strong><br />
| |
| 249 | 249 |
<input type="text" style="width:200px;" maxlength="255" name="nickname" value="'; |
| 250 | 250 |
if (!empty($this->form_nickname)) |
| 251 | 251 |
echo htmlspecialchars($this->form_nickname); |
| 252 | 252 |
$this->maincontent .= '" /><br /><br />'."\n"; |
| 253 | 253 |
} |
| 254 | 254 |
|
| 255 |
$this->maincontent .= '<strong>'._('Language:').'</strong><br />
| |
| 255 |
$this->maincontent .= '<strong>'.i18n('Language:').'</strong><br />
| |
| 256 | 256 |
<select name="language" style="width:205px;">'; |
| 257 | 257 |
|
| 258 | 258 |
require($basedir.'/inc/data/language.php'); |
| 267 | 267 |
$this->maincontent .= '<option value="'.$key.'">'.$value.'</option>'; |
| 268 | 268 | |
| 269 | 269 |
$this->maincontent .= '</select><br /><br /> |
| 270 |
<strong>'._('Code:').'</strong><br />
| |
| 270 |
<strong>'.i18n('Code:').'</strong><br />
| |
| 271 | 271 |
<textarea name="code" cols="100" rows="20" style="width: 98%;">'; |
| 272 | 272 |
|
| 273 | 273 |
if (!empty($this->form_code)) |
| 276 | 276 |
$this->maincontent .= htmlspecialchars($pid_form_source); |
| 277 | 277 | |
| 278 | 278 |
$this->maincontent .= '</textarea><br /><br /> |
| 279 |
<input class="submit" style="width:100px;" type="submit" value="'._('Paste!').'" />
| |
| 279 |
<input class="submit" style="width:100px;" type="submit" value="'.i18n('Paste!').'" />
| |
| 280 | 280 |
</p> |
| 281 | 281 |
</form>'; |
| 282 | 282 | |
| 283 | 283 |
| Old | New | Code |
|---|---|---|
| 44 | 44 |
$this->object = $this->paste->load_by_id($id); |
| 45 | 45 | |
| 46 | 46 |
if ($this->object) |
| 47 |
$title = sprintf(_('%s - Paste'), map_str(htmlspecialchars($this->paste->getTitle()), 50));
| |
| 47 |
$title = i18n('%(title)s - Paste', array('title' => map_str(htmlspecialchars($this->paste->getTitle()), 50)));
| |
| 48 | 48 |
else |
| 49 |
$title = _('Not found');
| |
| 49 |
$title = i18n('Not found');
| |
| 50 | 50 | |
| 51 | 51 |
// Meta tags |
| 52 | 52 |
$this->metatags = array('title' => $title,
|
| 74 | 74 |
border-left: 1px #8e8e8e dashed;background: #FFFAFA;"> |
| 75 | 75 |
<a href="paste/download/'.$id.'"> |
| 76 | 76 |
<span style="background-image: url(\'public/images/icons/actions/document-save.png\');" class="button"> |
| 77 |
'._('Download').'</span></a>
| |
| 77 |
'.i18n('Download').'</span></a>
| |
| 78 | 78 |
<a href="paste/new/'.$id; |
| 79 | 79 |
if ($this->paste->getPid() != 0) |
| 80 | 80 |
$this->maincontent .= '/'.$this->paste->getPid(); |
| 81 | 81 |
$this->maincontent .= '"> |
| 82 | 82 |
<span style="background-image: url(\'public/images/icons/actions/document-new.png\');" class="button"> |
| 83 |
'._('Edit').'</span></a></div>
| |
| 83 |
'.i18n('Edit').'</span></a></div>
| |
| 84 | 84 |
|
| 85 | 85 |
<h1>'.htmlspecialchars($this->paste->getTitle()).'</h1>'; |
| 86 | 86 | |
| 87 | 87 |
$this->maincontent .= '<table style="width: 100%;"><tr><td style="width: 20%;"> |
| 88 | 88 |
'.show_user_infos($this->paste->getUnregistered_nick(), $this->paste->getRegistered_id(), $this->ct_db, $this->lang, FALSE).'</td> |
| 89 |
<td style="vertical-align: top;"><em>'.sprintf(_('Added on %s'), i18nDate($this->paste->getDate(), $this->lang)).'</em>';
| |
| 89 |
<td style="vertical-align: top;"><em>'.i18n('Added on %(date)s', array('date' => i18nDate($this->paste->getDate(), $this->lang))).'</em>';
| |
| 90 | 90 | |
| 91 | 91 |
if ($this->ct_session->isLogged()) |
| 92 | 92 |
if (is_level($_SESSION['id'], 'administrator', $this->ct_db)) |
| 93 |
$this->maincontent .= '<br /><a href="paste/delete/'.$id.'">'._('Delete this paste').'</a>';
| |
| 93 |
$this->maincontent .= '<br /><a href="paste/delete/'.$id.'">'.i18n('Delete this paste').'</a>';
| |
| 94 | 94 | |
| 95 | 95 |
$this->maincontent .= '</td></tr></table>'; |
| 96 | 96 | |
| 98 | 98 |
if ($parent_req) |
| 99 | 99 |
{
|
| 100 | 100 |
$this->maincontent .= '<div style="background-image: url(\'public/images/icons/places/user-home.png\');" class="button"> |
| 101 |
<strong>'.map_str(htmlspecialchars($parent_req['title']), 60).'</strong> - <a href="paste/show/'.$parent_req['id'].'">'._('Show').'</a> -
| |
| 102 |
<a href="paste/new/'.$parent_req['id'].'">'._('Edit').'</a> -
| |
| 103 |
<a href="paste/download/'.$parent_req['id'].'">'._('Download').'</a></div>';
| |
| 101 |
<strong>'.map_str(htmlspecialchars($parent_req['title']), 60).'</strong> - <a href="paste/show/'.$parent_req['id'].'">'.i18n('Show').'</a> -
| |
| 102 |
<a href="paste/new/'.$parent_req['id'].'">'.i18n('Edit').'</a> -
| |
| 103 |
<a href="paste/download/'.$parent_req['id'].'">'.i18n('Download').'</a></div>';
| |
| 104 | 104 |
} |
| 105 | 105 |
|
| 106 | 106 |
$req = $this->paste->getChildsByPid(); |
| 120 | 120 |
$this->maincontent .= '\'); |
| 121 | 121 |
margin-left: 20px;border-left: 1px #8e8e8e dashed;background-position: 5px top;" class="button"> |
| 122 | 122 |
<strong>'.map_str(htmlspecialchars($req[$i]['title']), 60).'</strong> - |
| 123 |
<a href="paste/show/'.$req[$i]['id'].'">'._('Show').'</a> -
| |
| 124 |
<a href="paste/new/'.$req[$i]['id'].'/'.$req[$i]['pid'].'">'._('Edit').'</a> -
| |
| 125 |
<a href="paste/download/'.$req[$i]['id'].'">'._('Download').'</a>';
| |
| 123 |
<a href="paste/show/'.$req[$i]['id'].'">'.i18n('Show').'</a> -
| |
| 124 |
<a href="paste/new/'.$req[$i]['id'].'/'.$req[$i]['pid'].'">'.i18n('Edit').'</a> -
| |
| 125 |
<a href="paste/download/'.$req[$i]['id'].'">'.i18n('Download').'</a>';
| |
| 126 | 126 | |
| 127 | 127 |
if (isset($precedent)) |
| 128 |
$this->maincontent .= ' - <a href="paste/diff/'.$precedent.':'.$req[$i]['id'].'">'._('Differences').'</a>';
| |
| 128 |
$this->maincontent .= ' - <a href="paste/diff/'.$precedent.':'.$req[$i]['id'].'">'.i18n('Differences').'</a>';
| |
| 129 | 129 | |
| 130 | 130 |
$this->maincontent .='</div>'; |
| 131 | 131 |
|
| 159 | 159 |
$this->maincontent .= $code; |
| 160 | 160 |
} |
| 161 | 161 |
else |
| 162 |
$this->maincontent .= _('Error: paste not found.');
| |
| 162 |
$this->maincontent .= i18n('Error: paste not found.');
| |
| 163 | 163 | |
| 164 | 164 |
return $this->maincontent; |
| 165 | 165 |
} |
| 166 | 166 |

CodingTeam