diff --git a/index.php b/index.php index 22b6e5f..a371946 100644 --- a/index.php +++ b/index.php @@ -12,667 +12,254 @@ */ if (!defined('DC_CONTEXT_ADMIN')) { - return null; } dcPage::check('contentadmin'); -# Class $C2 = new cinecturlink2($core); -require dirname(__FILE__).'/inc/lib.cinecturlink2.list.php'; -# Queries -$upd_link_id = isset($_REQUEST['link_id']) ? $_REQUEST['link_id'] : null; -$new_title = isset($_POST['new_title']) ? $_POST['new_title'] : ''; -$new_desc = isset($_POST['new_desc']) ? $_POST['new_desc'] : ''; -$new_author = isset($_POST['new_author']) ? $_POST['new_author'] : ''; -$new_url = isset($_POST['new_url']) ? $_POST['new_url'] : ''; -$new_category = isset($_POST['new_category']) ? $_POST['new_category'] : ''; -$new_lang = isset($_POST['new_lang']) ? $_POST['new_lang'] : $core->auth->getInfo('user_lang'); -$new_image = isset($_POST['new_image']) ? $_POST['new_image'] : ''; -$new_note = isset($_POST['new_note']) ? $_POST['new_note'] : 10; -$new_cattitle = isset($_POST['new_cattitle']) ? $_POST['new_cattitle'] : ''; -$new_catdesc = isset($_POST['new_catdesc']) ? $_POST['new_catdesc'] : ''; -$action = isset($_POST['action']) ? $_POST['action'] : ''; - -# Actions -try { - - # Update categories - if ($action == 'update_categories') { - - # Reorder categories - if (empty($_POST['cats_order']) - && !empty($_POST['catpos']) - ) { - $order = $_POST['catpos']; - asort($order); - $order = array_keys($order); - } - elseif (!empty($_POST['cats_order'])) { - $order = explode(',', $_POST['cats_order']); - } - - if (!empty($order)) { - - foreach ($order as $pos => $id) { - - $pos = ((integer) $pos)+1; - if (empty($pos) || empty($id)) { - continue; - } - - $cur = $core->con->openCursor($C2->table.'_cat'); - $cur->cat_pos = $pos; - $C2->updCategory($id, $cur); - } - - dcPage::addSuccessNotice( - __('Categories successfully reordered.') - ); - } - - # Delete categories - if (!empty($_POST['delcat'])) { - - foreach($_POST['delcat'] as $cat_id) { - $C2->delCategory($cat_id); - } - - dcPage::addSuccessNotice( - __('Categories successfully deleted.') - ); - } - - http::redirect(empty($_POST['redir']) ? - $p_url.'#cats' : $_POST['redir'] - ); - } - - # Create new category - if ($action == 'create_category') { - - if (empty($new_cattitle)) { - throw new Exception(__('You must provide a title.')); - } - - $exists = $C2->getCategories(array('cat_title' => $new_cattitle), true)->f(0); - if ($exists) { - throw new Exception(__('Category with same name already exists.')); - } - - $cur = $core->con->openCursor($C2->table.'_cat'); - $cur->cat_title = $new_cattitle; - $cur->cat_desc = $new_catdesc; - - $C2->addCategory($cur); - - dcPage::addSuccessNotice( - __('Category successfully created.') - ); - http::redirect(empty($_POST['redir']) ? - $p_url.'#cats' : $_POST['redir'] - ); - } - - # Delete links - if (!empty($_POST['links']) && $action == 'delete_links') { - - foreach($_POST['links'] as $link_id) { - $C2->delLink($link_id); - } - - dcPage::addSuccessNotice( - __('Links successfully deleted.') - ); - http::redirect(empty($_POST['redir']) ? - $p_url.'#links' : $_POST['redir'] - ); - } - - # Move to right tab - if (!empty($_POST['links']) && $action == 'moveto_change_links_category') { - // Nothing to do: show links action page - } - - # Update category for a group of links - if (!empty($_POST['links']) && $action == 'change_links_category') { - - foreach($_POST['links'] as $link_id) { - $cur = $core->con->openCursor($C2->table); - $cur->cat_id = abs((integer) $_POST['upd_category']); - $C2->updLink($link_id,$cur); - } - - dcPage::addSuccessNotice( - __('Links successfully updated.') - ); - http::redirect(empty($_POST['redir']) ? - $p_url.'#links' : $_POST['redir'] - ); - } - - # Move to right tab - if (!empty($_POST['links']) && $_POST['action'] == 'moveto_change_links_note') { - // Nothing to do: show links action page - } - - # Update note for a group of links - if (!empty($_POST['links']) && $action == 'change_links_note') { - - foreach($_POST['links'] as $link_id) { - $cur = $core->con->openCursor($C2->table); - $cur->link_note = abs((integer) $_POST['upd_note']); - $C2->updLink($link_id,$cur); - } - - dcPage::addSuccessNotice( - __('Links successfully updated.') - ); - http::redirect(empty($_POST['redir']) ? - $p_url.'#links' : $_POST['redir'] - ); - } - - # Create or update link - if (!empty($_POST['newlink'])) { - - cinecturlink2::test_folder( - DC_ROOT.'/'.$core->blog->settings->system->public_path, - $core->blog->settings->cinecturlink2->cinecturlink2_folder - ); - - if (empty($new_title)) { - throw new Exception(__('You must provide a title.')); - } - if (empty($new_author)) { - throw new Exception(__('You must provide an author.')); - } - if (!preg_match('/http:\/\/.+/',$new_image)) { - throw new Exception(__('You must provide a link to an image.')); - } - - $cur = $core->con->openCursor($C2->table); - $cur->link_title = $new_title; - $cur->link_desc = $new_desc; - $cur->link_author = $new_author; - $cur->link_url = $new_url; - $cur->cat_id = $new_category == '' ? null : $new_category; - $cur->link_lang = $new_lang; - $cur->link_img = $new_image; - $cur->link_note = $new_note; - - # Create link - if (empty($upd_link_id)) { - - $exists = $C2->getLinks(array('link_title'=>$new_title),true)->f(0); - if ($exists) { - throw new Exception(__('Link with same name already exists.')); - } - - $C2->addLink($cur); - - dcPage::addSuccessNotice( - __('Link successfully created.') - ); - } - - # Update link - else { - - $exists = $C2->getLinks(array('link_id'=>$upd_link_id),true)->f(0); - if (!$exists) { - throw new Exception(__('Unknown link.')); - } - - $C2->updLink($upd_link_id,$cur); - - dcPage::addSuccessNotice( - __('Link successfully updated.') - ); - } - - http::redirect(empty($_POST['redir']) ? - $p_url.'#links' : $_POST['redir'] - ); - } -} -catch(Exception $e) { - $core->error->add($e->getMessage()); -} - -# Construct lists -$show_filters = false; -$sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'link_upddt'; -$order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; -$page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; -$nb_per_page = 30; -if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { - if ($nb_per_page != $_GET['nb']) $show_filters = true; - $nb_per_page = (integer) $_GET['nb']; -} - -$sortby_combo = array( - __('Date') => 'link_upddt', - __('Title') => 'link_title', - __('Category') => 'cat_title', - __('My rating') => 'link_note', -); - -$order_combo = array( - __('Descending') => 'desc', - __('Ascending') => 'asc' -); - -$params = array(); -$params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); - -if ($sortby != '' && in_array($sortby,$sortby_combo)) { - if ($order != '' && in_array($order,$order_combo)) { - $params['order'] = $sortby.' '.$order; - } - if ($sortby != 'link_upddt' || $order != 'desc') { - $show_filters = true; - } +$catid = $_REQUEST['catid'] ?? ''; +$cattitle = $_POST['cattitle'] ?? ''; +$catdesc = $_POST['catdesc'] ?? ''; +$part = $_REQUEST['part'] ?? ''; +if (!in_array($part, ['links', 'link', 'cats', 'cat'])) { + $part = 'links'; } +$headers = ''; $categories = $C2->getCategories(); -$categories_combo = array('-'=> ''); -while($categories->fetch()) { - $cat_title = html::escapeHTML($categories->cat_title); - $categories_combo[$cat_title] = $categories->cat_id; +$breadcrumb = [ + html::escapeHTML($core->blog->name) => '', + __('My cinecturlink') => $part != 'links' ? $core->adminurl->get('admin.plugin.cinecturlink2', ['part' => 'links']) : '' +]; + +if ($part == 'link') { + $breadcrumb[__('Link')] = ''; } -$medias_combo = $tmp_medias_combo = $dir = null; -try { - $allowed_medias = array('png','jpg','gif','bmp','jpeg'); - $core->media = new dcMedia($core); - $core->media->chdir($core->blog->settings->cinecturlink2->cinecturlink2_folder); - $core->media->getDir(); - $dir =& $core->media->dir; +if ($part == 'cats') { + $breadcrumb[__('Categories')] = ''; - foreach($dir['files'] as $file) { - if (!in_array(files::getExtension($file->relname),$allowed_medias)) continue; - $tmp_medias_combo[$file->media_title] = $file->file_url; - } - if (!empty($tmp_medias_combo)) { - $medias_combo = array_merge(array('-'=>''),$tmp_medias_combo); - } -} -catch (Exception $e) { - //$core->error->add($e->getMessage()); -} - -$langs_combo = l10n::getISOcodes(true); -$links_action_combo = array( - __('delete') => 'delete_links', - __('change category') => 'moveto_change_links_category', - __('change my rating') => 'moveto_change_links_note' -); -$notes_combo = array(); -for ($i=0;$i<21;$i++) { - $notes_combo[$i.'/20'] = $i; -} - -$pager_base_url = $p_url. - '&sortby='.$sortby. - '&order='.$order. - '&nb='.$nb_per_page. - '&page=%s'; - -try { - $links = $C2->getLinks($params); - $links_counter = $C2->getLinks($params,true)->f(0); - $links_list = new adminListCinecturlink2($core,$links,$links_counter,$pager_base_url); -} -catch (Exception $e) { - $core->error->add($e->getMessage()); -} - -# Page headers -echo -''. -''.__('Cinecturlink 2').''. -dcPage::jsToolBar(). -dcPage::jsToolMan(). -dcPage::jsLoad('js/_posts_list.js'). -dcPage::jsLoad('index.php?pf=cinecturlink2/js/cinecturlink2.js'). -dcPage::jsPageTabs(). -"\n". -''. -''; - -# Change category for links -if (!empty($_POST['links']) && $action == 'moveto_change_links_category') { - - echo - dcPage::breadcrumb( - array( - html::escapeHTML($core->blog->name) => '', - __('Cinecturlink 2') => $p_url.'&move=1#links', - __('Change category of links') => '' - ) - ). - dcPage::notices(); - - echo ' - - - '; -} - -# Change note for links -elseif (!empty($_POST['links']) && $action == 'moveto_change_links_note') -{ - echo dcPage::breadcrumb( - array( - html::escapeHTML($core->blog->name) => '', - __('Cinecturlink 2') => $p_url.'&move=1#links', - __('Change note of links') => '' - ) - ). - dcPage::notices(); - - echo ' - - - '; -} - -# All other tabs -else { - - echo dcPage::breadcrumb( - array( - html::escapeHTML($core->blog->name) => '', - __('Cinecturlink 2') => '' - ) - ). - dcPage::notices(); - - # List links - echo ' - '; - - # Create/edit link - $title = __('New link'); - - if (null !== $upd_link_id) { - - $upd_rs = $C2->getLinks(array('link_id' => $upd_link_id)); - $upd_link_id = null; - if (!$upd_rs->isEmpty()) { - $new_title = $upd_rs->link_title; - $new_desc = $upd_rs->link_desc; - $new_author = $upd_rs->link_author; - $new_url = $upd_rs->link_url; - $new_category = $upd_rs->cat_id; - $new_lang = $upd_rs->link_lang; - $new_image = $upd_rs->link_img; - $new_note = $upd_rs->link_note; - $upd_link_id = $upd_rs->link_id; - $title = __('Edit link'); + try { + // reorder categories + if (!empty($_POST['save'])) { + $catorder = []; + if (empty($_POST['im_order']) && !empty($_POST['order'])) { + $catorder = $_POST['order']; + asort($catorder); + $catorder = array_keys($catorder); + } elseif (!empty($_POST['im_order'])) { + $catorder = $_POST['im_order']; + if (substr($catorder, -1) == ',') { + $catorder = substr($catorder, 0, strlen($catorder) - 1); + } + $catorder = explode(',', $catorder); + } + $i = 0; + foreach($catorder as $id) { + $i++; + $cur = $core->con->openCursor($C2->table . '_cat'); + $cur->cat_pos = $i; + $C2->updCategory($id, $cur); + } + dcPage::addSuccessNotice( + __('Categories successfully reordered.') + ); + $core->adminurl->redirect('admin.plugin.cinecturlink2', ['part' => 'cats']); } + // delete categories + if (!empty($_POST['delete']) && !empty($_POST['items_selected'])) { + foreach ($_POST['items_selected'] as $id) { + $C2->delCategory($id); + } + dcPage::addSuccessNotice( + __('Category successfully deleted.') + ); + $core->adminurl->redirect('admin.plugin.cinecturlink2', ['part' => 'cats']); + } + + } catch (Exception $e) { + $core->error->add($e->getMessage()); } +} - echo ' - '; - - # List categories - echo '
'; +if ($part == "cats") { + echo + '

' . __('New Category') .'

'; if ($categories->isEmpty()) { echo '

'.__('There is no category').'

'; } else { echo ' -
- - - '; + +
+
#'.__('name').''.__('description').'
+ + + + + + '; $i = 0; while($categories->fetch()) { - $i++; $id = $categories->cat_id; - $title = html::escapeHTML($categories->cat_title); - $desc = html::escapeHTML($categories->cat_desc); - echo ' - - - - - + echo + '' . + ' + + + '; + $i++; } echo '
' . __('Categories list') . '
'.__('name').''.__('description').'
'.form::field(array('catpos['.$id.']'),2,5,$i).''.form::checkbox(array('delcat[]'),$id).''.$title.''.$desc.'
' . + form::number(['order[' . $id . ']'], [ + 'min' => 1, + 'max' => $categories->count(), + 'default' => $i +1, + 'class' => 'position', + 'extra_html' => 'title="' . sprintf(__('position of %s'), html::escapeHTML($categories->cat_title)) . '"' + ]) . + form::hidden(['dynorder[]', 'dynorder-' . $i], $id) . '' . form::checkbox(['items_selected[]', 'ims-' . $i], $id) . '' . html::escapeHTML($categories->cat_title) . '' . html::escapeHTML($categories->cat_desc) . '
+

'.__('Check to delete').'

-

'. - form::hidden('cats_order', ''). - form::hidden(array('action'), 'update_categories'). - $core->formNonce().' - -

- '; +

' . + ' ' . + '' . __('Cancel') . ' (c) '. + '' . + form::hidden('im_order', '') . + $core->formNonce() . '

' . + ''; } +} +if ($part == 'cat') { + if (!empty($catid)) { + $category = $C2->getCategories(['cat_id' => $catid]); + if (!$category->isEmpty()) { + $cattitle = $category->cat_title; + $catdesc = $category->cat_desc; + } + } echo ' - '; - - # Create category - echo ' -
-
- -

' . (empty($catid) ? __('Add categorie') : __('Edit categorie')) . '

+ +

- -

- -

'. - form::hidden(array('action'), 'create_category'). - $core->formNonce().' - -

-
-
'; +

' . + ' ' . + '' . __('Cancel') . ' (c) '. + (!empty($catid) ? ' ' : '') . + form::hidden('catid', $catid) . + $core->formNonce() . '

' . + ''; } dcPage::helpBlock('cinecturlink2'); -# Page footer -echo -'

-'.__('Configuration').' - -cinecturlink2 - '.$core->plugins->moduleInfo('cinecturlink2', 'version').'  -'.__('cinecturlink2').' -

-'; \ No newline at end of file +echo ''; \ No newline at end of file diff --git a/js/cinecturlink2.js b/js/cinecturlink2.js index adba4de..7c1b22d 100644 --- a/js/cinecturlink2.js +++ b/js/cinecturlink2.js @@ -1,102 +1,31 @@ -/* -- BEGIN LICENSE BLOCK ---------------------------------- - * This file is part of cinecturlink2, a plugin for Dotclear 2. - * - * Copyright (c) 2009-2010 JC Denis and contributors - * jcdenis@gdwd.com - * - * Licensed under the GPL version 2.0 license. - * A copy of this license is available in LICENSE file or at - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * -- END LICENSE BLOCK ------------------------------------*/ +/*global $, dotclear */ +'use strict'; -;if(window.jQuery) (function($){ - $.fn.openGoogle = function(lang,target){ - return this.each(function(){ - $(this).click(function(){ - var val = $(target).attr('value'); - if (val!=''){ - searchwindow=window.open('http://www.google.com/search?hl='+lang+'&q='+val,'search','scrollbars=yes,width=800,height=600,resize=yes,toolbar=yes,menubar=yes'); - searchwindow.focus(); - } - return false; - }); - }); - } - $.fn.openAmazon = function(lang,target){ - return this.each(function(){ - $(this).click(function(){ - var val = $(target).attr('value'); - if (val!=''){ - searchwindow=window.open('http://www.amazon.fr/exec/obidos/external-search?keyword='+val+'&mode=blended','search','scrollbars=yes,width=800,height=600,resize=yes,toolbar=yes,menubar=yes'); - searchwindow.focus(); - } - return false; - }); - }); - } - $.fn.fillLink = function(target){ - return this.each(function(){ - $(this).change(function(){ - $(target).attr('value',$(this).attr('value')); - return false; - }); - }); - } -})(jQuery); - -var dragsort = ToolMan.dragsort(); -$(function(){ - dragsort.makeTableSortable($('#links-list-cat').get(0), - dotclear.sortable.setHandle,dotclear.sortable.saveOrder); -}); -dotclear.sortable = { - setHandle: function(item) { - var handle = $(item).find('td.handle').get(0); - while (handle.firstChild) { - handle.removeChild(handle.firstChild); - } - item.toolManDragGroup.setHandle(handle); - handle.className = handle.className+' handler'; - }, - saveOrder: function(item) { - var group = item.toolManDragGroup; - var order = document.getElementById('cats_order'); - group.register('dragend', function() { - order.value = ''; - items = item.parentNode.getElementsByTagName('tr'); - for (var i=0; i'+dotclear.msg.filter_posts_list+'

') - - if( dotclear.msg.show_filters == 'false' ) { - $filtersform.hide(); - } else { - $('#filter-control') - .addClass('open') - .text(dotclear.msg.cancel_the_filter); - } - - $('#filter-control').click(function() { - if( $(this).hasClass('open') ) { - if( dotclear.msg.show_filters == 'true' ) { - return true; - } else { - $filtersform.hide(); - $(this).removeClass('open') - .text(dotclear.msg.filter_posts_list); - } - } else { - $filtersform.show(); - $(this).addClass('open') - .text(dotclear.msg.cancel_the_filter); - } - return false; - }); +$(function () { + $('#c2itemslist').sortable({ + cursor: 'move', + }); + $('#c2itemslist tr') + .on('mouseenter', function () { + $(this).css({ + cursor: 'move', + }); + }) + .on('mouseleave', function () { + $(this).css({ + cursor: 'auto', + }); + }); + $('#c2items').on('submit', function () { + let order = []; + $('#c2itemslist tr td input.position').each(function () { + order.push(this.name.replace(/^order\[([^\]]+)\]$/, '$1')); + }); + $('input[name=im_order]')[0].value = order.join(','); + return true; + }); + $('#c2itemslist tr td input.position').hide(); + $('#c2itemslist tr td.handle').addClass('handler'); + dotclear.condSubmit('#c2items tr td input[name^=items_selected]', '#c2items #remove-action'); + dotclear.responsiveCellHeaders(document.querySelector('#c2items table'), '#c2items table', 2); }); \ No newline at end of file