[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[270] | 6 | # Copyright (c) 2003-2011 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> |
---|
| 165 | <title>Blogroll</title> |
---|
| 166 | <?php echo dcPage::jsToolMan(); ?> |
---|
| 167 | <?php echo dcPage::jsConfirmClose('links-form','add-link-form','add-category-form'); ?> |
---|
[161] | 168 | <?php |
---|
| 169 | $core->auth->user_prefs->addWorkspace('accessibility'); |
---|
| 170 | $user_dm_nodragdrop = $core->auth->user_prefs->accessibility->nodragdrop; |
---|
| 171 | ?> |
---|
| 172 | <?php if (!$user_dm_nodragdrop) : ?> |
---|
[0] | 173 | <script type="text/javascript"> |
---|
| 174 | //<![CDATA[ |
---|
| 175 | |
---|
| 176 | var dragsort = ToolMan.dragsort(); |
---|
| 177 | $(function() { |
---|
| 178 | dragsort.makeTableSortable($("#links-list").get(0), |
---|
| 179 | dotclear.sortable.setHandle,dotclear.sortable.saveOrder); |
---|
| 180 | |
---|
| 181 | $('.checkboxes-helpers').each(function() { |
---|
| 182 | dotclear.checkboxesHelpers(this); |
---|
| 183 | }); |
---|
| 184 | }); |
---|
| 185 | |
---|
| 186 | dotclear.sortable = { |
---|
| 187 | setHandle: function(item) { |
---|
| 188 | var handle = $(item).find('td.handle').get(0); |
---|
| 189 | while (handle.firstChild) { |
---|
| 190 | handle.removeChild(handle.firstChild); |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | item.toolManDragGroup.setHandle(handle); |
---|
| 194 | handle.className = handle.className+' handler'; |
---|
| 195 | }, |
---|
| 196 | |
---|
| 197 | saveOrder: function(item) { |
---|
| 198 | var group = item.toolManDragGroup; |
---|
| 199 | var order = document.getElementById('links_order'); |
---|
| 200 | group.register('dragend', function() { |
---|
| 201 | order.value = ''; |
---|
| 202 | items = item.parentNode.getElementsByTagName('tr'); |
---|
| 203 | |
---|
| 204 | for (var i=0; i<items.length; i++) { |
---|
| 205 | order.value += items[i].id.substr(2)+','; |
---|
| 206 | } |
---|
| 207 | }); |
---|
| 208 | } |
---|
| 209 | }; |
---|
| 210 | //]]> |
---|
| 211 | </script> |
---|
[161] | 212 | <?php endif; ?> |
---|
[0] | 213 | <?php echo dcPage::jsPageTabs($default_tab); ?> |
---|
| 214 | </head> |
---|
| 215 | |
---|
| 216 | <body> |
---|
| 217 | <h2><?php echo html::escapeHTML($core->blog->name); ?> › Blogroll</h2> |
---|
| 218 | |
---|
| 219 | <?php |
---|
| 220 | if (!empty($_GET['neworder'])) { |
---|
| 221 | echo '<p class="message">'.__('Items order has been successfully updated').'</p>'; |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | if (!empty($_GET['removed'])) { |
---|
| 225 | echo '<p class="message">'.__('Items have been successfully removed.').'</p>'; |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | if (!empty($_GET['addlink'])) { |
---|
| 229 | echo '<p class="message">'.__('Link has been successfully created.').'</p>'; |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | if (!empty($_GET['addcat'])) { |
---|
| 233 | echo '<p class="message">'.__('category has been successfully created.').'</p>'; |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | if (!empty($_GET['importlinks'])) { |
---|
| 237 | echo '<p class="message">'.__('links have been successfully imported.').'</p>'; |
---|
| 238 | } |
---|
| 239 | ?> |
---|
| 240 | |
---|
| 241 | <div class="multi-part" title="<?php echo __('Blogroll'); ?>"> |
---|
| 242 | <form action="plugin.php" method="post" id="links-form"> |
---|
| 243 | <table class="maximal dragable"> |
---|
| 244 | <thead> |
---|
| 245 | <tr> |
---|
| 246 | <th colspan="3"><?php echo __('Title'); ?></th> |
---|
| 247 | <th><?php echo __('Description'); ?></th> |
---|
| 248 | <th><?php echo __('URL'); ?></th> |
---|
| 249 | <th><?php echo __('Lang'); ?></th> |
---|
| 250 | </tr> |
---|
| 251 | </thead> |
---|
| 252 | <tbody id="links-list"> |
---|
| 253 | <?php |
---|
| 254 | while ($rs->fetch()) |
---|
| 255 | { |
---|
| 256 | $position = (string) $rs->index()+1; |
---|
| 257 | |
---|
| 258 | echo |
---|
| 259 | '<tr class="line" id="l_'.$rs->link_id.'">'. |
---|
[74] | 260 | '<td class="handle minimal">'.form::field(array('order['.$rs->link_id.']'),2,5,$position,'','',false,'title="'.__('position').'"').'</td>'. |
---|
| 261 | '<td class="minimal">'.form::checkbox(array('remove[]'),$rs->link_id,'','','',false,'title="'.__('select this link').'"').'</td>'; |
---|
[0] | 262 | |
---|
| 263 | |
---|
| 264 | if ($rs->is_cat) |
---|
| 265 | { |
---|
| 266 | echo |
---|
| 267 | '<td colspan="5"><strong><a href="'.$p_url.'&edit=1&id='.$rs->link_id.'">'. |
---|
| 268 | html::escapeHTML($rs->link_desc).'</a></strong></td>'; |
---|
| 269 | } |
---|
| 270 | else |
---|
| 271 | { |
---|
| 272 | echo |
---|
| 273 | '<td><a href="'.$p_url.'&edit=1&id='.$rs->link_id.'">'. |
---|
| 274 | html::escapeHTML($rs->link_title).'</a></td>'. |
---|
| 275 | '<td>'.html::escapeHTML($rs->link_desc).'</td>'. |
---|
| 276 | '<td>'.html::escapeHTML($rs->link_href).'</td>'. |
---|
| 277 | '<td>'.html::escapeHTML($rs->link_lang).'</td>'; |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | echo '</tr>'; |
---|
| 281 | } |
---|
| 282 | ?> |
---|
| 283 | </tbody> |
---|
| 284 | </table> |
---|
| 285 | <?php |
---|
| 286 | if (!$rs->isEmpty()) { |
---|
| 287 | echo |
---|
| 288 | '<div class="two-cols">'. |
---|
| 289 | '<p class="col">'.form::hidden('links_order',''). |
---|
| 290 | form::hidden(array('p'),'blogroll'). |
---|
| 291 | $core->formNonce(). |
---|
[123] | 292 | '<input type="submit" name="saveorder" value="'.__('Save order').'" /></p>'. |
---|
[0] | 293 | |
---|
[3] | 294 | '<p class="col right"><input type="submit" class="delete" name="removeaction"'. |
---|
[123] | 295 | ' value="'.__('Delete selected links').'" '. |
---|
[0] | 296 | 'onclick="return window.confirm(\''.html::escapeJS( |
---|
| 297 | __('Are you sure you want to delete selected links?')).'\');" /></p>'. |
---|
| 298 | '</div>'; |
---|
| 299 | } else { |
---|
| 300 | echo |
---|
| 301 | '<div><p>'.__('The link list is empty.').'</p></div>'; |
---|
| 302 | } |
---|
| 303 | ?> |
---|
| 304 | </form> |
---|
| 305 | </div> |
---|
| 306 | |
---|
| 307 | <?php |
---|
| 308 | echo |
---|
[3] | 309 | '<div class="multi-part clear" id="add-link" title="'.__('Add a link').'">'. |
---|
[0] | 310 | '<form action="plugin.php" method="post" id="add-link-form">'. |
---|
| 311 | '<fieldset class="two-cols"><legend>'.__('Add a new link').'</legend>'. |
---|
[74] | 312 | '<p class="col"><label for="link_title" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').' '. |
---|
[454] | 313 | form::field('link_title',30,255,$link_title). |
---|
[0] | 314 | '</label></p>'. |
---|
| 315 | |
---|
[74] | 316 | '<p class="col"><label for="link_href" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('URL:').' '. |
---|
[454] | 317 | form::field('link_href',30,255,$link_href). |
---|
[0] | 318 | '</label></p>'. |
---|
| 319 | |
---|
[74] | 320 | '<p class="col"><label for="link_desc">'.__('Description:').' '. |
---|
[454] | 321 | form::field('link_desc',30,255,$link_desc). |
---|
[0] | 322 | '</label></p>'. |
---|
| 323 | |
---|
[74] | 324 | '<p class="col"><label for="link_lang">'.__('Language:').' '. |
---|
[454] | 325 | form::field('link_lang',5,5,$link_lang). |
---|
[0] | 326 | '</label></p>'. |
---|
| 327 | '<p>'.form::hidden(array('p'),'blogroll'). |
---|
| 328 | $core->formNonce(). |
---|
[454] | 329 | '<input type="submit" name="add_link" value="'.__('Save').'" /></p>'. |
---|
[0] | 330 | '</fieldset>'. |
---|
| 331 | '</form>'. |
---|
| 332 | '</div>'; |
---|
| 333 | |
---|
| 334 | echo |
---|
| 335 | '<div class="multi-part" id="add-cat" title="'.__('Add a category').'">'. |
---|
| 336 | '<form action="plugin.php" method="post" id="add-category-form">'. |
---|
| 337 | '<fieldset><legend>'.__('Add a new category').'</legend>'. |
---|
[74] | 338 | '<p><label for="cat_title" class=" classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').' '. |
---|
[454] | 339 | form::field('cat_title',30,255,$cat_title).'</label> '. |
---|
[0] | 340 | form::hidden(array('p'),'blogroll'). |
---|
| 341 | $core->formNonce(). |
---|
[454] | 342 | '<input type="submit" name="add_cat" value="'.__('Save').'" /></p>'. |
---|
[0] | 343 | '</fieldset>'. |
---|
| 344 | '</form>'. |
---|
| 345 | '</div>'; |
---|
| 346 | |
---|
| 347 | echo |
---|
| 348 | '<div class="multi-part" id="import-links" title="'.__('Import links').'">'; |
---|
| 349 | if (!isset($imported)) { |
---|
| 350 | echo |
---|
| 351 | '<form action="plugin.php" method="post" id="import-links-form" enctype="multipart/form-data">'. |
---|
| 352 | '<fieldset><legend>'.__('Import links').'</legend>'. |
---|
[74] | 353 | '<p><label for="links_file" class=" classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('OPML or XBEL File:').' '. |
---|
| 354 | '<input type="file" id="links_file" name="links_file" /></label></p>'. |
---|
[0] | 355 | '<p>'.form::hidden(array('p'),'blogroll'). |
---|
| 356 | $core->formNonce(). |
---|
[454] | 357 | '<input type="submit" name="import_links" value="'.__('import').'" /></p>'. |
---|
[0] | 358 | '</fieldset>'. |
---|
| 359 | '</form>'; |
---|
| 360 | } |
---|
| 361 | else { |
---|
| 362 | echo |
---|
| 363 | '<form action="plugin.php" method="post" id="import-links-form">'. |
---|
| 364 | '<fieldset><legend>'.__('Import links').'</legend>'; |
---|
| 365 | if (empty($imported)) { |
---|
| 366 | echo '<p>'.__('Nothing to import').'</p>'; |
---|
| 367 | } |
---|
| 368 | else { |
---|
| 369 | echo |
---|
| 370 | '<table class="clear maximal"><tr>'. |
---|
| 371 | '<th colspan="2">'.__('Title').'</th>'. |
---|
| 372 | '<th>'.__('Description').'</th>'. |
---|
| 373 | '</tr>'; |
---|
| 374 | |
---|
| 375 | $i = 0; |
---|
| 376 | foreach ($imported as $entry) { |
---|
| 377 | $url = html::escapeHTML($entry->link); |
---|
| 378 | $title = html::escapeHTML($entry->title); |
---|
| 379 | $desc = html::escapeHTML($entry->desc); |
---|
| 380 | |
---|
| 381 | echo |
---|
| 382 | '<tr><td>'.form::checkbox(array('entries[]'),$i,'','','').'</td>'. |
---|
| 383 | '<td nowrap><a href="'.$url.'">'.$title.'</a>'. |
---|
| 384 | '<input type="hidden" name="url['.$i.']" value="'.$url.'" />'. |
---|
| 385 | '<input type="hidden" name="title['.$i.']" value="'.$title.'" />'. |
---|
| 386 | '</td>'. |
---|
| 387 | '<td>'.$desc. |
---|
| 388 | '<input type="hidden" name="desc['.$i.']" value="'.$desc.'" />'. |
---|
| 389 | '</td></tr>'."\n"; |
---|
| 390 | $i++; |
---|
| 391 | } |
---|
| 392 | echo |
---|
| 393 | '</table>'. |
---|
| 394 | '<div class="two-cols">'. |
---|
| 395 | '<p class="col checkboxes-helpers"></p>'. |
---|
| 396 | |
---|
| 397 | '<p class="col right">'. |
---|
| 398 | form::hidden(array('p'),'blogroll'). |
---|
| 399 | $core->formNonce(). |
---|
[454] | 400 | '<input type="submit" name="cancel_import" value="'.__('cancel').'" /> '. |
---|
| 401 | '<input type="submit" name="import_links_do" value="'.__('import').'" /></p>'. |
---|
[0] | 402 | '</div>'; |
---|
| 403 | } |
---|
| 404 | echo |
---|
| 405 | '</fieldset>'. |
---|
| 406 | '</form>'; |
---|
| 407 | } |
---|
| 408 | echo '</div>'; |
---|
[215] | 409 | |
---|
| 410 | dcPage::helpBlock('blogroll'); |
---|
[0] | 411 | ?> |
---|
| 412 | |
---|
| 413 | </body> |
---|
| 414 | </html> |
---|