[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[1179] | 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
[0] | 7 | # Licensed under the GPL version 2.0 license. |
---|
| 8 | # See LICENSE file or |
---|
| 9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 10 | # |
---|
| 11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
| 12 | if (!defined('DC_CONTEXT_ADMIN')) { return; } |
---|
| 13 | |
---|
| 14 | $blogroll = new dcBlogroll($core->blog); |
---|
| 15 | |
---|
| 16 | if (!empty($_REQUEST['edit']) && !empty($_REQUEST['id'])) { |
---|
| 17 | include dirname(__FILE__).'/edit.php'; |
---|
| 18 | return; |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | $default_tab = ''; |
---|
| 22 | $link_title = $link_href = $link_desc = $link_lang = ''; |
---|
| 23 | $cat_title = ''; |
---|
| 24 | |
---|
| 25 | # Import links |
---|
| 26 | if (!empty($_POST['import_links']) && !empty($_FILES['links_file'])) |
---|
| 27 | { |
---|
| 28 | $default_tab = 'import-links'; |
---|
| 29 | |
---|
| 30 | try |
---|
| 31 | { |
---|
| 32 | files::uploadStatus($_FILES['links_file']); |
---|
| 33 | $ifile = DC_TPL_CACHE.'/'.md5(uniqid()); |
---|
| 34 | if (!move_uploaded_file($_FILES['links_file']['tmp_name'],$ifile)) { |
---|
| 35 | throw new Exception(__('Unable to move uploaded file.')); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | require_once dirname(__FILE__).'/class.dc.importblogroll.php'; |
---|
| 39 | try { |
---|
| 40 | $imported = dcImportBlogroll::loadFile($ifile); |
---|
| 41 | @unlink($ifile); |
---|
| 42 | } catch (Exception $e) { |
---|
| 43 | @unlink($ifile); |
---|
| 44 | throw $e; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | if (empty($imported)) { |
---|
| 49 | unset($imported); |
---|
| 50 | throw new Exception(__('Nothing to import')); |
---|
| 51 | } |
---|
| 52 | } |
---|
| 53 | catch (Exception $e) |
---|
| 54 | { |
---|
| 55 | $core->error->add($e->getMessage()); |
---|
| 56 | } |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | if (!empty($_POST['import_links_do'])) { |
---|
| 60 | foreach ($_POST['entries'] as $idx) { |
---|
| 61 | $link_title = $_POST['title'][$idx]; |
---|
| 62 | $link_href = $_POST['url'][$idx]; |
---|
| 63 | $link_desc = $_POST['desc'][$idx]; |
---|
| 64 | try { |
---|
| 65 | $blogroll->addLink($link_title,$link_href,$link_desc,''); |
---|
| 66 | } catch (Exception $e) { |
---|
| 67 | $core->error->add($e->getMessage()); |
---|
| 68 | $default_tab = 'import-links'; |
---|
| 69 | } |
---|
| 70 | } |
---|
| 71 | http::redirect($p_url.'&importlinks=1'); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | if (!empty($_POST['cancel_import'])) { |
---|
| 75 | $core->error->add(__('Import operation cancelled.')); |
---|
| 76 | $default_tab = 'import-links'; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | # Add link |
---|
| 80 | if (!empty($_POST['add_link'])) |
---|
| 81 | { |
---|
| 82 | $link_title = $_POST['link_title']; |
---|
| 83 | $link_href = $_POST['link_href']; |
---|
| 84 | $link_desc = $_POST['link_desc']; |
---|
| 85 | $link_lang = $_POST['link_lang']; |
---|
| 86 | |
---|
| 87 | try { |
---|
| 88 | $blogroll->addLink($link_title,$link_href,$link_desc,$link_lang); |
---|
| 89 | http::redirect($p_url.'&addlink=1'); |
---|
| 90 | } catch (Exception $e) { |
---|
| 91 | $core->error->add($e->getMessage()); |
---|
| 92 | $default_tab = 'add-link'; |
---|
| 93 | } |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | # Add category |
---|
| 97 | if (!empty($_POST['add_cat'])) |
---|
| 98 | { |
---|
| 99 | $cat_title = $_POST['cat_title']; |
---|
| 100 | |
---|
| 101 | try { |
---|
| 102 | $blogroll->addCategory($cat_title); |
---|
| 103 | http::redirect($p_url.'&addcat=1'); |
---|
| 104 | } catch (Exception $e) { |
---|
| 105 | $core->error->add($e->getMessage()); |
---|
| 106 | $default_tab = 'add-cat'; |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | # Delete link |
---|
| 111 | if (!empty($_POST['removeaction']) && !empty($_POST['remove'])) { |
---|
| 112 | foreach ($_POST['remove'] as $k => $v) |
---|
| 113 | { |
---|
| 114 | try { |
---|
| 115 | $blogroll->delItem($v); |
---|
| 116 | } catch (Exception $e) { |
---|
| 117 | $core->error->add($e->getMessage()); |
---|
| 118 | break; |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | if (!$core->error->flag()) { |
---|
| 123 | http::redirect($p_url.'&removed=1'); |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | # Order links |
---|
| 128 | $order = array(); |
---|
| 129 | if (empty($_POST['links_order']) && !empty($_POST['order'])) { |
---|
| 130 | $order = $_POST['order']; |
---|
| 131 | asort($order); |
---|
| 132 | $order = array_keys($order); |
---|
| 133 | } elseif (!empty($_POST['links_order'])) { |
---|
| 134 | $order = explode(',',$_POST['links_order']); |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | if (!empty($_POST['saveorder']) && !empty($order)) |
---|
| 138 | { |
---|
| 139 | foreach ($order as $pos => $l) { |
---|
| 140 | $pos = ((integer) $pos)+1; |
---|
| 141 | |
---|
| 142 | try { |
---|
| 143 | $blogroll->updateOrder($l,$pos); |
---|
| 144 | } catch (Exception $e) { |
---|
| 145 | $core->error->add($e->getMessage()); |
---|
| 146 | } |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | if (!$core->error->flag()) { |
---|
| 150 | http::redirect($p_url.'&neworder=1'); |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | |
---|
| 155 | # Get links |
---|
| 156 | try { |
---|
| 157 | $rs = $blogroll->getLinks(); |
---|
| 158 | } catch (Exception $e) { |
---|
| 159 | $core->error->add($e->getMessage()); |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | ?> |
---|
| 163 | <html> |
---|
| 164 | <head> |
---|
[717] | 165 | <title><?php echo __('Blogroll'); ?></title> |
---|
[0] | 166 | <?php echo dcPage::jsConfirmClose('links-form','add-link-form','add-category-form'); ?> |
---|
[161] | 167 | <?php |
---|
[1131] | 168 | $core->auth->user_prefs->addWorkspace('accessibility'); |
---|
| 169 | if (!$core->auth->user_prefs->accessibility->nodragdrop) { |
---|
| 170 | echo |
---|
| 171 | dcPage::jsLoad('js/jquery/jquery-ui.custom.js'). |
---|
| 172 | dcPage::jsLoad('index.php?pf=blogroll/blogroll.js'); |
---|
| 173 | } |
---|
[161] | 174 | ?> |
---|
[0] | 175 | <?php echo dcPage::jsPageTabs($default_tab); ?> |
---|
| 176 | </head> |
---|
| 177 | |
---|
| 178 | <body> |
---|
[1339] | 179 | <?php |
---|
[1358] | 180 | echo dcPage::breadcrumb( |
---|
[1339] | 181 | array( |
---|
| 182 | html::escapeHTML($core->blog->name) => '', |
---|
| 183 | '<span class="page-title">'.__('Blogroll').'</span>' => '' |
---|
| 184 | )); |
---|
| 185 | ?> |
---|
[0] | 186 | |
---|
| 187 | <?php |
---|
| 188 | if (!empty($_GET['neworder'])) { |
---|
[907] | 189 | dcPage::message(__('Items order has been successfully updated')); |
---|
[0] | 190 | } |
---|
| 191 | |
---|
| 192 | if (!empty($_GET['removed'])) { |
---|
[907] | 193 | dcPage::message(__('Items have been successfully removed.')); |
---|
[0] | 194 | } |
---|
| 195 | |
---|
| 196 | if (!empty($_GET['addlink'])) { |
---|
[907] | 197 | dcPage::message(__('Link has been successfully created.')); |
---|
[0] | 198 | } |
---|
| 199 | |
---|
| 200 | if (!empty($_GET['addcat'])) { |
---|
[907] | 201 | dcPage::message(__('category has been successfully created.')); |
---|
[0] | 202 | } |
---|
| 203 | |
---|
| 204 | if (!empty($_GET['importlinks'])) { |
---|
[907] | 205 | dcPage::message(__('links have been successfully imported.')); |
---|
[0] | 206 | } |
---|
| 207 | ?> |
---|
| 208 | |
---|
| 209 | <div class="multi-part" title="<?php echo __('Blogroll'); ?>"> |
---|
[1504] | 210 | |
---|
| 211 | <?php if (!$rs->isEmpty()) { ?> |
---|
| 212 | |
---|
[0] | 213 | <form action="plugin.php" method="post" id="links-form"> |
---|
| 214 | <table class="maximal dragable"> |
---|
| 215 | <thead> |
---|
| 216 | <tr> |
---|
| 217 | <th colspan="3"><?php echo __('Title'); ?></th> |
---|
| 218 | <th><?php echo __('Description'); ?></th> |
---|
| 219 | <th><?php echo __('URL'); ?></th> |
---|
| 220 | <th><?php echo __('Lang'); ?></th> |
---|
| 221 | </tr> |
---|
| 222 | </thead> |
---|
| 223 | <tbody id="links-list"> |
---|
| 224 | <?php |
---|
| 225 | while ($rs->fetch()) |
---|
| 226 | { |
---|
| 227 | $position = (string) $rs->index()+1; |
---|
| 228 | |
---|
| 229 | echo |
---|
| 230 | '<tr class="line" id="l_'.$rs->link_id.'">'. |
---|
[1131] | 231 | '<td class="handle minimal">'.form::field(array('order['.$rs->link_id.']'),2,5,$position,'position','',false,'title="'.__('position').'"').'</td>'. |
---|
[74] | 232 | '<td class="minimal">'.form::checkbox(array('remove[]'),$rs->link_id,'','','',false,'title="'.__('select this link').'"').'</td>'; |
---|
[0] | 233 | |
---|
| 234 | |
---|
| 235 | if ($rs->is_cat) |
---|
| 236 | { |
---|
| 237 | echo |
---|
| 238 | '<td colspan="5"><strong><a href="'.$p_url.'&edit=1&id='.$rs->link_id.'">'. |
---|
| 239 | html::escapeHTML($rs->link_desc).'</a></strong></td>'; |
---|
| 240 | } |
---|
| 241 | else |
---|
| 242 | { |
---|
| 243 | echo |
---|
| 244 | '<td><a href="'.$p_url.'&edit=1&id='.$rs->link_id.'">'. |
---|
| 245 | html::escapeHTML($rs->link_title).'</a></td>'. |
---|
| 246 | '<td>'.html::escapeHTML($rs->link_desc).'</td>'. |
---|
| 247 | '<td>'.html::escapeHTML($rs->link_href).'</td>'. |
---|
| 248 | '<td>'.html::escapeHTML($rs->link_lang).'</td>'; |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | echo '</tr>'; |
---|
| 252 | } |
---|
| 253 | ?> |
---|
| 254 | </tbody> |
---|
| 255 | </table> |
---|
[1504] | 256 | |
---|
| 257 | <div class="two-cols"> |
---|
| 258 | <p class="col"> |
---|
[0] | 259 | <?php |
---|
[1504] | 260 | echo |
---|
| 261 | form::hidden('links_order',''). |
---|
| 262 | form::hidden(array('p'),'blogroll'). |
---|
| 263 | $core->formNonce(); |
---|
[0] | 264 | ?> |
---|
[1504] | 265 | <input type="submit" name="saveorder" value="<?php echo __('Save order'); ?>" /></p> |
---|
| 266 | <p class="col right"><input type="submit" class="delete" name="removeaction" |
---|
| 267 | value="<?php echo __('Delete selected links'); ?>" |
---|
| 268 | onclick="return window.confirm(' |
---|
| 269 | <?php echo html::escapeJS(__('Are you sure you want to delete selected links?')); ?>');" /></p> |
---|
| 270 | </div> |
---|
[0] | 271 | </form> |
---|
[1504] | 272 | |
---|
| 273 | <?php |
---|
| 274 | } else { |
---|
| 275 | echo '<div><p>'.__('The link list is empty.').'</p></div>'; |
---|
| 276 | } |
---|
| 277 | ?> |
---|
| 278 | |
---|
[0] | 279 | </div> |
---|
| 280 | |
---|
| 281 | <?php |
---|
| 282 | echo |
---|
[3] | 283 | '<div class="multi-part clear" id="add-link" title="'.__('Add a link').'">'. |
---|
[0] | 284 | '<form action="plugin.php" method="post" id="add-link-form">'. |
---|
[1454] | 285 | '<h3>'.__('Add a new link').'</h3>'. |
---|
| 286 | '<p class="col"><label for="link_title" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').'</label> '. |
---|
[454] | 287 | form::field('link_title',30,255,$link_title). |
---|
[1454] | 288 | '</p>'. |
---|
[0] | 289 | |
---|
[1454] | 290 | '<p class="col"><label for="link_href" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('URL:').'</label> '. |
---|
[454] | 291 | form::field('link_href',30,255,$link_href). |
---|
[1454] | 292 | '</p>'. |
---|
[0] | 293 | |
---|
[1454] | 294 | '<p class="col"><label for="link_desc">'.__('Description:').'</label> '. |
---|
[454] | 295 | form::field('link_desc',30,255,$link_desc). |
---|
[1454] | 296 | '</p>'. |
---|
[0] | 297 | |
---|
[1454] | 298 | '<p class="col"><label for="link_lang">'.__('Language:').'</label> '. |
---|
[454] | 299 | form::field('link_lang',5,5,$link_lang). |
---|
[1454] | 300 | '</p>'. |
---|
[0] | 301 | '<p>'.form::hidden(array('p'),'blogroll'). |
---|
| 302 | $core->formNonce(). |
---|
[454] | 303 | '<input type="submit" name="add_link" value="'.__('Save').'" /></p>'. |
---|
[0] | 304 | '</form>'. |
---|
| 305 | '</div>'; |
---|
| 306 | |
---|
| 307 | echo |
---|
| 308 | '<div class="multi-part" id="add-cat" title="'.__('Add a category').'">'. |
---|
| 309 | '<form action="plugin.php" method="post" id="add-category-form">'. |
---|
[1454] | 310 | '<h3>'.__('Add a new category').'</h3>'. |
---|
| 311 | '<p><label for="cat_title" class=" classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').'</label> '. |
---|
| 312 | form::field('cat_title',30,255,$cat_title).' '. |
---|
[0] | 313 | form::hidden(array('p'),'blogroll'). |
---|
| 314 | $core->formNonce(). |
---|
[454] | 315 | '<input type="submit" name="add_cat" value="'.__('Save').'" /></p>'. |
---|
[0] | 316 | '</form>'. |
---|
| 317 | '</div>'; |
---|
| 318 | |
---|
| 319 | echo |
---|
| 320 | '<div class="multi-part" id="import-links" title="'.__('Import links').'">'; |
---|
| 321 | if (!isset($imported)) { |
---|
| 322 | echo |
---|
| 323 | '<form action="plugin.php" method="post" id="import-links-form" enctype="multipart/form-data">'. |
---|
[1454] | 324 | '<h3>'.__('Import links').'</h3>'. |
---|
| 325 | '<p><label for="links_file" class=" classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('OPML or XBEL File:').'</label> '. |
---|
| 326 | '<input type="file" id="links_file" name="links_file" /></p>'. |
---|
[0] | 327 | '<p>'.form::hidden(array('p'),'blogroll'). |
---|
| 328 | $core->formNonce(). |
---|
[557] | 329 | '<input type="submit" name="import_links" value="'.__('Import').'" /></p>'. |
---|
[0] | 330 | '</form>'; |
---|
| 331 | } |
---|
| 332 | else { |
---|
| 333 | echo |
---|
| 334 | '<form action="plugin.php" method="post" id="import-links-form">'. |
---|
[1454] | 335 | '<h3>'.__('Import links').'</h3>'; |
---|
[0] | 336 | if (empty($imported)) { |
---|
| 337 | echo '<p>'.__('Nothing to import').'</p>'; |
---|
| 338 | } |
---|
| 339 | else { |
---|
| 340 | echo |
---|
| 341 | '<table class="clear maximal"><tr>'. |
---|
| 342 | '<th colspan="2">'.__('Title').'</th>'. |
---|
| 343 | '<th>'.__('Description').'</th>'. |
---|
| 344 | '</tr>'; |
---|
| 345 | |
---|
| 346 | $i = 0; |
---|
| 347 | foreach ($imported as $entry) { |
---|
| 348 | $url = html::escapeHTML($entry->link); |
---|
| 349 | $title = html::escapeHTML($entry->title); |
---|
| 350 | $desc = html::escapeHTML($entry->desc); |
---|
| 351 | |
---|
| 352 | echo |
---|
| 353 | '<tr><td>'.form::checkbox(array('entries[]'),$i,'','','').'</td>'. |
---|
| 354 | '<td nowrap><a href="'.$url.'">'.$title.'</a>'. |
---|
| 355 | '<input type="hidden" name="url['.$i.']" value="'.$url.'" />'. |
---|
| 356 | '<input type="hidden" name="title['.$i.']" value="'.$title.'" />'. |
---|
| 357 | '</td>'. |
---|
| 358 | '<td>'.$desc. |
---|
| 359 | '<input type="hidden" name="desc['.$i.']" value="'.$desc.'" />'. |
---|
| 360 | '</td></tr>'."\n"; |
---|
| 361 | $i++; |
---|
| 362 | } |
---|
| 363 | echo |
---|
| 364 | '</table>'. |
---|
| 365 | '<div class="two-cols">'. |
---|
| 366 | '<p class="col checkboxes-helpers"></p>'. |
---|
| 367 | |
---|
| 368 | '<p class="col right">'. |
---|
| 369 | form::hidden(array('p'),'blogroll'). |
---|
| 370 | $core->formNonce(). |
---|
[557] | 371 | '<input type="submit" name="cancel_import" value="'.__('Cancel').'" /> '. |
---|
| 372 | '<input type="submit" name="import_links_do" value="'.__('Import').'" /></p>'. |
---|
[0] | 373 | '</div>'; |
---|
| 374 | } |
---|
| 375 | echo |
---|
| 376 | '</form>'; |
---|
| 377 | } |
---|
| 378 | echo '</div>'; |
---|
[215] | 379 | |
---|
| 380 | dcPage::helpBlock('blogroll'); |
---|
[0] | 381 | ?> |
---|
| 382 | |
---|
| 383 | </body> |
---|
| 384 | </html> |
---|