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