[0] | 1 | <?php |
---|
[3731] | 2 | /** |
---|
| 3 | * @brief blogroll, a plugin for Dotclear 2 |
---|
| 4 | * |
---|
| 5 | * @package Dotclear |
---|
| 6 | * @subpackage Plugins |
---|
| 7 | * |
---|
| 8 | * @copyright Olivier Meunier & Association Dotclear |
---|
| 9 | * @copyright GPL-2.0-only |
---|
| 10 | */ |
---|
| 11 | |
---|
[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 |
---|
[3874] | 127 | $order = []; |
---|
[0] | 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( |
---|
[3874] | 180 | [ |
---|
[3707] | 181 | html::escapeHTML($core->blog->name) => '', |
---|
| 182 | __('Blogroll') => '' |
---|
[3874] | 183 | ]) . |
---|
[3707] | 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 . '">' . |
---|
[3902] | 210 | '<td class="handle minimal">' . form::number(['order[' . $rs->link_id . ']'], [ |
---|
| 211 | 'min' => 1, |
---|
| 212 | 'max' => $rs->count(), |
---|
[3725] | 213 | 'default' => $position, |
---|
| 214 | 'class' => 'position', |
---|
| 215 | 'extra_html' => 'title="' . __('position') . '"' |
---|
[3874] | 216 | ]) . |
---|
[3725] | 217 | '</td>' . |
---|
[3874] | 218 | '<td class="minimal">' . form::checkbox(['remove[]'], $rs->link_id, |
---|
| 219 | [ |
---|
[3707] | 220 | 'extra_html' => 'title="' . __('select this link') . '"' |
---|
[3874] | 221 | ] |
---|
[3707] | 222 | ) . '</td>'; |
---|
[2566] | 223 | |
---|
[3707] | 224 | if ($rs->is_cat) { |
---|
| 225 | echo |
---|
| 226 | '<td colspan="5"><strong><a href="' . $p_url . '&edit=1&id=' . $rs->link_id . '">' . |
---|
| 227 | html::escapeHTML($rs->link_desc) . '</a></strong></td>'; |
---|
| 228 | } else { |
---|
| 229 | echo |
---|
| 230 | '<td><a href="' . $p_url . '&edit=1&id=' . $rs->link_id . '">' . |
---|
| 231 | html::escapeHTML($rs->link_title) . '</a></td>' . |
---|
| 232 | '<td>' . html::escapeHTML($rs->link_desc) . '</td>' . |
---|
| 233 | '<td>' . html::escapeHTML($rs->link_href) . '</td>' . |
---|
| 234 | '<td>' . html::escapeHTML($rs->link_lang) . '</td>'; |
---|
| 235 | } |
---|
[2566] | 236 | |
---|
[3707] | 237 | echo '</tr>'; |
---|
| 238 | } |
---|
| 239 | ?> |
---|
[0] | 240 | </tbody> |
---|
[2002] | 241 | </table></div> |
---|
[1504] | 242 | |
---|
| 243 | <div class="two-cols"> |
---|
| 244 | <p class="col"> |
---|
[0] | 245 | <?php |
---|
[3707] | 246 | echo |
---|
| 247 | form::hidden('links_order', '') . |
---|
[3874] | 248 | form::hidden(['p'], 'blogroll') . |
---|
[3707] | 249 | $core->formNonce(); |
---|
| 250 | ?> |
---|
[1504] | 251 | <input type="submit" name="saveorder" value="<?php echo __('Save order'); ?>" /></p> |
---|
[3182] | 252 | <p class="col right"><input id="remove-action" type="submit" class="delete" name="removeaction" |
---|
[3707] | 253 | value="<?php echo __('Delete selected links'); ?>" |
---|
| 254 | onclick="return window.confirm(<?php echo html::escapeJS(__('Are you sure you want to delete selected links?')); ?>');" /></p> |
---|
[1504] | 255 | </div> |
---|
[0] | 256 | </form> |
---|
[1504] | 257 | |
---|
| 258 | <?php |
---|
| 259 | } else { |
---|
[3707] | 260 | echo '<div><p>' . __('The link list is empty.') . '</p></div>'; |
---|
[1504] | 261 | } |
---|
| 262 | ?> |
---|
| 263 | |
---|
[0] | 264 | </div> |
---|
| 265 | |
---|
| 266 | <?php |
---|
| 267 | echo |
---|
[3707] | 268 | '<div class="multi-part clear" id="add-link" title="' . __('Add a link') . '">' . |
---|
| 269 | '<form action="' . $core->adminurl->get('admin.plugin') . '" method="post" id="add-link-form">' . |
---|
| 270 | '<h3>' . __('Add a new link') . '</h3>' . |
---|
| 271 | '<p class="col"><label for="link_title" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Title:') . '</label> ' . |
---|
[3874] | 272 | form::field('link_title', 30, 255, [ |
---|
[3725] | 273 | 'default' => $link_title, |
---|
| 274 | 'extra_html' => 'required placeholder="' . __('Title') . '"' |
---|
[3874] | 275 | ]) . |
---|
[3707] | 276 | '</p>' . |
---|
[0] | 277 | |
---|
[3707] | 278 | '<p class="col"><label for="link_href" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('URL:') . '</label> ' . |
---|
[3874] | 279 | form::field('link_href', 30, 255, [ |
---|
[3725] | 280 | 'default' => $link_href, |
---|
| 281 | 'extra_html' => 'required placeholder="' . __('URL') . '"' |
---|
[3874] | 282 | ]) . |
---|
[3707] | 283 | '</p>' . |
---|
[0] | 284 | |
---|
[3707] | 285 | '<p class="col"><label for="link_desc">' . __('Description:') . '</label> ' . |
---|
| 286 | form::field('link_desc', 30, 255, $link_desc) . |
---|
| 287 | '</p>' . |
---|
[0] | 288 | |
---|
[3707] | 289 | '<p class="col"><label for="link_lang">' . __('Language:') . '</label> ' . |
---|
| 290 | form::field('link_lang', 5, 5, $link_lang) . |
---|
| 291 | '</p>' . |
---|
[3874] | 292 | '<p>' . form::hidden(['p'], 'blogroll') . |
---|
[3707] | 293 | $core->formNonce() . |
---|
| 294 | '<input type="submit" name="add_link" value="' . __('Save') . '" /></p>' . |
---|
| 295 | '</form>' . |
---|
| 296 | '</div>'; |
---|
[0] | 297 | |
---|
| 298 | echo |
---|
[3707] | 299 | '<div class="multi-part" id="add-cat" title="' . __('Add a category') . '">' . |
---|
| 300 | '<form action="' . $core->adminurl->get('admin.plugin') . '" method="post" id="add-category-form">' . |
---|
| 301 | '<h3>' . __('Add a new category') . '</h3>' . |
---|
| 302 | '<p><label for="cat_title" class=" classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Title:') . '</label> ' . |
---|
[3874] | 303 | form::field('cat_title', 30, 255, [ |
---|
[3725] | 304 | 'default' => $cat_title, |
---|
| 305 | 'extra_html' => 'required placeholder="' . __('Title') . '"' |
---|
[3874] | 306 | ]) . |
---|
[3725] | 307 | ' ' . |
---|
[3874] | 308 | form::hidden(['p'], 'blogroll') . |
---|
[3707] | 309 | $core->formNonce() . |
---|
| 310 | '<input type="submit" name="add_cat" value="' . __('Save') . '" /></p>' . |
---|
| 311 | '</form>' . |
---|
| 312 | '</div>'; |
---|
[0] | 313 | |
---|
| 314 | echo |
---|
[3707] | 315 | '<div class="multi-part" id="import-links" title="' . __('Import links') . '">'; |
---|
[0] | 316 | if (!isset($imported)) { |
---|
[3707] | 317 | echo |
---|
| 318 | '<form action="' . $core->adminurl->get('admin.plugin') . '" method="post" id="import-links-form" enctype="multipart/form-data">' . |
---|
| 319 | '<h3>' . __('Import links') . '</h3>' . |
---|
| 320 | '<p><label for="links_file" class=" classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('OPML or XBEL File:') . '</label> ' . |
---|
| 321 | '<input type="file" id="links_file" name="links_file" required /></p>' . |
---|
[3874] | 322 | '<p>' . form::hidden(['p'], 'blogroll') . |
---|
[3707] | 323 | $core->formNonce() . |
---|
| 324 | '<input type="submit" name="import_links" value="' . __('Import') . '" /></p>' . |
---|
| 325 | '</form>'; |
---|
| 326 | } else { |
---|
| 327 | echo |
---|
| 328 | '<form action="' . $core->adminurl->get('admin.plugin') . '" method="post" id="import-links-form">' . |
---|
| 329 | '<h3>' . __('Import links') . '</h3>'; |
---|
| 330 | if (empty($imported)) { |
---|
| 331 | echo '<p>' . __('Nothing to import') . '</p>'; |
---|
| 332 | } else { |
---|
| 333 | echo |
---|
| 334 | '<table class="clear maximal"><tr>' . |
---|
| 335 | '<th colspan="2">' . __('Title') . '</th>' . |
---|
| 336 | '<th>' . __('Description') . '</th>' . |
---|
| 337 | '</tr>'; |
---|
[2566] | 338 | |
---|
[3707] | 339 | $i = 0; |
---|
| 340 | foreach ($imported as $entry) { |
---|
| 341 | $url = html::escapeHTML($entry->link); |
---|
| 342 | $title = html::escapeHTML($entry->title); |
---|
| 343 | $desc = html::escapeHTML($entry->desc); |
---|
[2566] | 344 | |
---|
[3707] | 345 | echo |
---|
[3874] | 346 | '<tr><td>' . form::checkbox(['entries[]'], $i) . '</td>' . |
---|
[3709] | 347 | '<td nowrap><a href="' . $url . '">' . $title . '</a>' . |
---|
| 348 | '<input type="hidden" name="url[' . $i . ']" value="' . $url . '" />' . |
---|
| 349 | '<input type="hidden" name="title[' . $i . ']" value="' . $title . '" />' . |
---|
| 350 | '</td>' . |
---|
| 351 | '<td>' . $desc . |
---|
| 352 | '<input type="hidden" name="desc[' . $i . ']" value="' . $desc . '" />' . |
---|
| 353 | '</td></tr>' . "\n"; |
---|
[3707] | 354 | $i++; |
---|
| 355 | } |
---|
| 356 | echo |
---|
| 357 | '</table>' . |
---|
| 358 | '<div class="two-cols">' . |
---|
| 359 | '<p class="col checkboxes-helpers"></p>' . |
---|
[2566] | 360 | |
---|
[3707] | 361 | '<p class="col right">' . |
---|
[3874] | 362 | form::hidden(['p'], 'blogroll') . |
---|
[3707] | 363 | $core->formNonce() . |
---|
| 364 | '<input type="submit" name="cancel_import" value="' . __('Cancel') . '" /> ' . |
---|
| 365 | '<input type="submit" name="import_links_do" value="' . __('Import') . '" /></p>' . |
---|
| 366 | '</div>'; |
---|
| 367 | } |
---|
| 368 | echo |
---|
| 369 | '</form>'; |
---|
[0] | 370 | } |
---|
| 371 | echo '</div>'; |
---|
[215] | 372 | |
---|
| 373 | dcPage::helpBlock('blogroll'); |
---|
[0] | 374 | ?> |
---|
| 375 | |
---|
| 376 | </body> |
---|
[2566] | 377 | </html> |
---|