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