| 1 | <?php |
|---|
| 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 | |
|---|
| 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 | $default_tab = 'import-links'; |
|---|
| 28 | |
|---|
| 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 | } |
|---|
| 36 | |
|---|
| 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 | } |
|---|
| 45 | |
|---|
| 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 | } |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | if (!empty($_POST['import_links_do'])) { |
|---|
| 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 | } |
|---|
| 67 | |
|---|
| 68 | dcPage::addSuccessNotice(__('links have been successfully imported.')); |
|---|
| 69 | http::redirect($p_url); |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | if (!empty($_POST['cancel_import'])) { |
|---|
| 73 | $core->error->add(__('Import operation cancelled.')); |
|---|
| 74 | $default_tab = 'import-links'; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | # Add link |
|---|
| 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']); |
|---|
| 83 | |
|---|
| 84 | try { |
|---|
| 85 | $blogroll->addLink($link_title, $link_href, $link_desc, $link_lang); |
|---|
| 86 | |
|---|
| 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 | } |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | # Add category |
|---|
| 96 | if (!empty($_POST['add_cat'])) { |
|---|
| 97 | $cat_title = html::escapeHTML($_POST['cat_title']); |
|---|
| 98 | |
|---|
| 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 | } |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | # Delete link |
|---|
| 110 | if (!empty($_POST['removeaction']) && !empty($_POST['remove'])) { |
|---|
| 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 | } |
|---|
| 119 | |
|---|
| 120 | if (!$core->error->flag()) { |
|---|
| 121 | dcPage::addSuccessNotice(__('Items have been successfully removed.')); |
|---|
| 122 | http::redirect($p_url); |
|---|
| 123 | } |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | # Order links |
|---|
| 127 | $order = []; |
|---|
| 128 | if (empty($_POST['links_order']) && !empty($_POST['order'])) { |
|---|
| 129 | $order = $_POST['order']; |
|---|
| 130 | asort($order); |
|---|
| 131 | $order = array_keys($order); |
|---|
| 132 | } elseif (!empty($_POST['links_order'])) { |
|---|
| 133 | $order = explode(',', $_POST['links_order']); |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | if (!empty($_POST['saveorder']) && !empty($order)) { |
|---|
| 137 | foreach ($order as $pos => $l) { |
|---|
| 138 | $pos = ((integer) $pos) + 1; |
|---|
| 139 | |
|---|
| 140 | try { |
|---|
| 141 | $blogroll->updateOrder($l, $pos); |
|---|
| 142 | } catch (Exception $e) { |
|---|
| 143 | $core->error->add($e->getMessage()); |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | if (!$core->error->flag()) { |
|---|
| 148 | dcPage::addSuccessNotice(__('Items order has been successfully updated')); |
|---|
| 149 | http::redirect($p_url); |
|---|
| 150 | } |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | # Get links |
|---|
| 154 | try { |
|---|
| 155 | $rs = $blogroll->getLinks(); |
|---|
| 156 | } catch (Exception $e) { |
|---|
| 157 | $core->error->add($e->getMessage()); |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | ?> |
|---|
| 161 | <html> |
|---|
| 162 | <head> |
|---|
| 163 | <title><?php echo __('Blogroll'); ?></title> |
|---|
| 164 | <?php echo dcPage::jsConfirmClose('links-form', 'add-link-form', 'add-category-form'); ?> |
|---|
| 165 | <?php |
|---|
| 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') . |
|---|
| 171 | dcPage::jsLoad(dcPage::getPF('blogroll/js/blogroll.js')); |
|---|
| 172 | } |
|---|
| 173 | ?> |
|---|
| 174 | <?php echo dcPage::jsPageTabs($default_tab); ?> |
|---|
| 175 | </head> |
|---|
| 176 | |
|---|
| 177 | <body> |
|---|
| 178 | <?php |
|---|
| 179 | echo dcPage::breadcrumb( |
|---|
| 180 | [ |
|---|
| 181 | html::escapeHTML($core->blog->name) => '', |
|---|
| 182 | __('Blogroll') => '' |
|---|
| 183 | ]) . |
|---|
| 184 | dcPage::notices(); |
|---|
| 185 | ?> |
|---|
| 186 | |
|---|
| 187 | <div class="multi-part" id="main-list" title="<?php echo __('Blogroll'); ?>"> |
|---|
| 188 | |
|---|
| 189 | <?php if (!$rs->isEmpty()) { |
|---|
| 190 | ?> |
|---|
| 191 | |
|---|
| 192 | <form action="<?php echo $core->adminurl->get('admin.plugin'); ?>" method="post" id="links-form"> |
|---|
| 193 | <div class="table-outer"> |
|---|
| 194 | <table class="dragable"> |
|---|
| 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 |
|---|
| 205 | while ($rs->fetch()) { |
|---|
| 206 | $position = (string) $rs->index() + 1; |
|---|
| 207 | |
|---|
| 208 | echo |
|---|
| 209 | '<tr class="line" id="l_' . $rs->link_id . '">' . |
|---|
| 210 | '<td class="handle minimal">' . form::number(['order[' . $rs->link_id . ']'], [ |
|---|
| 211 | 'min' => 1, |
|---|
| 212 | 'max' => $rs->count(), |
|---|
| 213 | 'default' => $position, |
|---|
| 214 | 'class' => 'position', |
|---|
| 215 | 'extra_html' => 'title="' . __('position') . '"' |
|---|
| 216 | ]) . |
|---|
| 217 | '</td>' . |
|---|
| 218 | '<td class="minimal">' . form::checkbox(['remove[]'], $rs->link_id, |
|---|
| 219 | [ |
|---|
| 220 | 'extra_html' => 'title="' . __('select this link') . '"' |
|---|
| 221 | ] |
|---|
| 222 | ) . '</td>'; |
|---|
| 223 | |
|---|
| 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 | } |
|---|
| 236 | |
|---|
| 237 | echo '</tr>'; |
|---|
| 238 | } |
|---|
| 239 | ?> |
|---|
| 240 | </tbody> |
|---|
| 241 | </table></div> |
|---|
| 242 | |
|---|
| 243 | <div class="two-cols"> |
|---|
| 244 | <p class="col"> |
|---|
| 245 | <?php |
|---|
| 246 | echo |
|---|
| 247 | form::hidden('links_order', '') . |
|---|
| 248 | form::hidden(['p'], 'blogroll') . |
|---|
| 249 | $core->formNonce(); |
|---|
| 250 | ?> |
|---|
| 251 | <input type="submit" name="saveorder" value="<?php echo __('Save order'); ?>" /></p> |
|---|
| 252 | <p class="col right"><input id="remove-action" type="submit" class="delete" name="removeaction" |
|---|
| 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> |
|---|
| 255 | </div> |
|---|
| 256 | </form> |
|---|
| 257 | |
|---|
| 258 | <?php |
|---|
| 259 | } else { |
|---|
| 260 | echo '<div><p>' . __('The link list is empty.') . '</p></div>'; |
|---|
| 261 | } |
|---|
| 262 | ?> |
|---|
| 263 | |
|---|
| 264 | </div> |
|---|
| 265 | |
|---|
| 266 | <?php |
|---|
| 267 | echo |
|---|
| 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> ' . |
|---|
| 272 | form::field('link_title', 30, 255, [ |
|---|
| 273 | 'default' => $link_title, |
|---|
| 274 | 'extra_html' => 'required placeholder="' . __('Title') . '"' |
|---|
| 275 | ]) . |
|---|
| 276 | '</p>' . |
|---|
| 277 | |
|---|
| 278 | '<p class="col"><label for="link_href" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('URL:') . '</label> ' . |
|---|
| 279 | form::field('link_href', 30, 255, [ |
|---|
| 280 | 'default' => $link_href, |
|---|
| 281 | 'extra_html' => 'required placeholder="' . __('URL') . '"' |
|---|
| 282 | ]) . |
|---|
| 283 | '</p>' . |
|---|
| 284 | |
|---|
| 285 | '<p class="col"><label for="link_desc">' . __('Description:') . '</label> ' . |
|---|
| 286 | form::field('link_desc', 30, 255, $link_desc) . |
|---|
| 287 | '</p>' . |
|---|
| 288 | |
|---|
| 289 | '<p class="col"><label for="link_lang">' . __('Language:') . '</label> ' . |
|---|
| 290 | form::field('link_lang', 5, 5, $link_lang) . |
|---|
| 291 | '</p>' . |
|---|
| 292 | '<p>' . form::hidden(['p'], 'blogroll') . |
|---|
| 293 | $core->formNonce() . |
|---|
| 294 | '<input type="submit" name="add_link" value="' . __('Save') . '" /></p>' . |
|---|
| 295 | '</form>' . |
|---|
| 296 | '</div>'; |
|---|
| 297 | |
|---|
| 298 | echo |
|---|
| 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> ' . |
|---|
| 303 | form::field('cat_title', 30, 255, [ |
|---|
| 304 | 'default' => $cat_title, |
|---|
| 305 | 'extra_html' => 'required placeholder="' . __('Title') . '"' |
|---|
| 306 | ]) . |
|---|
| 307 | ' ' . |
|---|
| 308 | form::hidden(['p'], 'blogroll') . |
|---|
| 309 | $core->formNonce() . |
|---|
| 310 | '<input type="submit" name="add_cat" value="' . __('Save') . '" /></p>' . |
|---|
| 311 | '</form>' . |
|---|
| 312 | '</div>'; |
|---|
| 313 | |
|---|
| 314 | echo |
|---|
| 315 | '<div class="multi-part" id="import-links" title="' . __('Import links') . '">'; |
|---|
| 316 | if (!isset($imported)) { |
|---|
| 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>' . |
|---|
| 322 | '<p>' . form::hidden(['p'], 'blogroll') . |
|---|
| 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>'; |
|---|
| 338 | |
|---|
| 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); |
|---|
| 344 | |
|---|
| 345 | echo |
|---|
| 346 | '<tr><td>' . form::checkbox(['entries[]'], $i) . '</td>' . |
|---|
| 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"; |
|---|
| 354 | $i++; |
|---|
| 355 | } |
|---|
| 356 | echo |
|---|
| 357 | '</table>' . |
|---|
| 358 | '<div class="two-cols">' . |
|---|
| 359 | '<p class="col checkboxes-helpers"></p>' . |
|---|
| 360 | |
|---|
| 361 | '<p class="col right">' . |
|---|
| 362 | form::hidden(['p'], 'blogroll') . |
|---|
| 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>'; |
|---|
| 370 | } |
|---|
| 371 | echo '</div>'; |
|---|
| 372 | |
|---|
| 373 | dcPage::helpBlock('blogroll'); |
|---|
| 374 | ?> |
|---|
| 375 | |
|---|
| 376 | </body> |
|---|
| 377 | </html> |
|---|