From 4a3c6d969b86a83361255f835a44e4424ed94ba7 Mon Sep 17 00:00:00 2001
From: Jean-Christian Denis '.__('There is no link').' ' . __('No link matches the filter') . ' ' . __('No link') . ' '.__('Page(s)').' : '.$pager->getLinks().' '.__('Page(s)').' : '.$pager->getLinks().' '.__('There is no link').' '.__('There is no link').''.
- ''.
- '
';
+ ''.
- ' '.
- ''.
- '%s'.
- ''.__('Title').' '.
- ''.__('Author').' '.
- ''.__('Description').' '.
- ''.__('Links').' '.
- ''.__('Category').' '.
- ''.__('My rating').' '.
- ''.__('Date').' '.
- '' .
+ '
' .
+ '%s' .
+ ' ' .
+ '' .
+ '%s' .
+ '' . __('Title') . ' ' .
+ '' . __('Author') . ' ' .
+ '' . __('Description') . ' ' .
+ '' . __('Links') . ' ' .
+ '' . __('Category') . ' ' .
+ '' . __('Rating') . ' ' .
+ '' . __('Date') . ' ' .
+ ''."\n".
- ' '."\n";
+ ''.
- form::checkbox(array('links[]'), $this->rs->link_id, 0).
- ' '.
- ''.
- ''.
- html::escapeHTML($this->rs->link_title).
- ''.
- " \n".
- ''.
- html::escapeHTML($this->rs->link_author).
- " \n".
- ''.
- html::escapeHTML($this->rs->link_desc).
- " \n".
- ''.
- ''.__('URL').' '.
- ''.__('image').' '.
- " \n".
- ''.
- html::escapeHTML($this->rs->cat_title).
- " \n".
- ''.
- html::escapeHTML($this->rs->link_note).'/20'.
- " \n".
- ''.
- dt::dt2str($GLOBALS['core']->blog->settings->system->date_format.', '.$GLOBALS['core']->blog->settings->system->time_format,$this->rs->link_upddt,$GLOBALS['core']->auth->getInfo('user_tz')).
- " \n".
- '' .
+ ' ' . "\n";
}
}
\ No newline at end of file
diff --git a/index.php b/index.php
index a371946..8786108 100644
--- a/index.php
+++ b/index.php
@@ -17,39 +17,322 @@ if (!defined('DC_CONTEXT_ADMIN')) {
dcPage::check('contentadmin');
-$C2 = new cinecturlink2($core);
-
+$linkid = $_REQUEST['linkid'] ?? '';
+$linktitle = $_POST['linktitle'] ?? '';
+$linkdesc = $_POST['linkdesc'] ?? '';
+$linkauthor = $_POST['linkauthor'] ?? '';
+$linkurl = $_POST['linkurl'] ?? '';
+$linkcat = $_POST['linkcat'] ?? null;
+$linklang = $_POST['linklang'] ?? $core->auth->getInfo('user_lang');
+$linkimage = $_POST['linkimage'] ?? '';
+$linknote = $_POST['linknote'] ?? '';
$catid = $_REQUEST['catid'] ?? '';
$cattitle = $_POST['cattitle'] ?? '';
$catdesc = $_POST['catdesc'] ?? '';
-$part = $_REQUEST['part'] ?? '';
-if (!in_array($part, ['links', 'link', 'cats', 'cat'])) {
- $part = 'links';
-}
+$redir = $_REQUEST['redir'] ?? '';
+$part = $_REQUEST['part'] ?? 'links';
+$entries = $_POST['entries'] ?? [];
$headers = '';
-
-$categories = $C2->getCategories();
-
$breadcrumb = [
html::escapeHTML($core->blog->name) => '',
- __('My cinecturlink') => $part != 'links' ? $core->adminurl->get('admin.plugin.cinecturlink2', ['part' => 'links']) : ''
+ __('My cinecturlink') => $core->adminurl->get('admin.plugin.cinecturlink2', ['part' => 'links'])
];
+if (!in_array($part, ['links', 'link', 'cats', 'cat', 'dellinks', 'updlinksnote', 'updlinkscat'])) {
+ $part = 'links';
+}
+if (!is_array($entries)) {
+ $entries == [];
+}
+
+try {
+ $C2 = new cinecturlink2($core);
+ $categories = $C2->getCategories();
+ $categories_combo = ['-' => ''];
+ while($categories->fetch()) {
+ $cat_title = html::escapeHTML($categories->cat_title);
+ $categories_combo[$cat_title] = $categories->cat_id;
+ }
+} catch (Exception $e) {
+ $core->error->add($e->getMessage());
+}
+
+if ($part == 'dellinks') {
+ try {
+ // delete group of links
+ if (!empty($entries)) {
+ foreach ($entries as $id) {
+ $C2->delLink($id);
+ }
+ dcPage::addSuccessNotice(
+ __('Links successfully deleted.')
+ );
+ $core->adminurl->redirect('admin.plugin.cinecturlink2', ['part' => 'links']);
+ }
+ } catch (Exception $e) {
+ $core->error->add($e->getMessage());
+ }
+ $breadcrumb[__('Delete links')] = '';
+}
+
+// get list of secleted links
+if (in_array($part, ['updlinksnote', 'updlinkscat'])) {
+ try {
+ $links = $C2->getLinks(['link_id' => $entries]);
+ } catch (Exception $e) {
+ $core->error->add($e->getMessage());
+ }
+}
+
+if ($part == 'updlinksnote') {
+ try {
+ // update group of links note
+ if (!empty($entries) && isset($_POST['newlinknote'])) {
+ while($links->fetch()) {
+ if (in_array($links->link_id, $entries)) {
+ $cur = $core->con->openCursor($C2->table);
+ $cur->link_note = (integer) $_POST['newlinknote'];
+ $C2->updLink($links->link_id, $cur);
+ }
+ }
+ dcPage::addSuccessNotice(
+ __('Links successfully updated.')
+ );
+ if (!empty($_POST['redir'])) {
+ http::redirect($redir);
+ } else {
+ $core->adminurl->redirect('admin.plugin.cinecturlink2', ['part' => 'links']);
+ }
+ }
+ } catch (Exception $e) {
+ $core->error->add($e->getMessage());
+ }
+ $breadcrumb[__('Update links rating')] = '';
+}
+
+if ($part == 'updlinkscat') {
+ try {
+ // update group of links category
+ if (!empty($entries) && !empty($_POST['newcatid'])) {
+ while($links->fetch()) {
+ if (in_array($links->link_id, $entries)) {
+ $cur = $core->con->openCursor($C2->table);
+ $cur->cat_id = (integer) $_POST['newcatid'];
+ $C2->updLink($links->link_id, $cur);
+ }
+ }
+ dcPage::addSuccessNotice(
+ __('Links successfully updated.')
+ );
+ if (!empty($_POST['redir'])) {
+ http::redirect($redir);
+ } else {
+ $core->adminurl->redirect('admin.plugin.cinecturlink2', ['part' => 'links']);
+ }
+ }
+ } catch (Exception $e) {
+ $core->error->add($e->getMessage());
+ }
+ $breadcrumb[__('Update links category')] = '';
+}
+
+if ($part == 'links') {
+ $sortby_combo = [
+ __('Date') => 'link_upddt',
+ __('Title') => 'link_title',
+ __('Category') => 'cat_title',
+ __('Rating') => 'link_note',
+ ];
+ $order_combo = [
+ __('Descending') => 'desc',
+ __('Ascending') => 'asc'
+ ];
+ $action_combo = [
+ __('Delete') => 'dellinks',
+ __('Change category') => 'updlinkscat',
+ __('Change rating') => 'updlinksnote'
+ ];
+
+ $show_filters = false;
+ $page = !empty($_GET['page']) ? max(1, (integer) $_GET['page']) : 1;
+ $nb_per_page = $core->auth->user_prefs->interface->nb_posts_per_page ?: 30;
+ $default_sortby = 'link_upddt';
+ $default_order = 'desc';
+ $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : $default_sortby;
+ $order = !empty($_GET['order']) ? $_GET['order'] : $default_order;
+
+ if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) {
+ if ($nb_per_page != (integer) $_GET['nb']) {
+ $show_filters = true;
+ }
+ $nb_per_page = (integer) $_GET['nb'];
+ }
+ if (!in_array($sortby, $sortby_combo)) {
+ $sortby = $default_sortby;
+ }
+ if (!in_array($order, $order_combo)) {
+ $order = $default_order;
+ }
+ if ($sortby != $default_sortby || $order != $default_order) {
+ $show_filters = true;
+ }
+
+ $params = [];
+ $params['link_type'] = 'cinecturlink';
+ $params['limit'] = [(($page - 1) * $nb_per_page), $nb_per_page];
+ $params['no_content'] = true;
+ $params['order'] = $sortby . ' ' . $order;
+
+ if ($catid !== '' && in_array($catid, $categories_combo)) {
+ $params['cat_id'] = $catid;
+ $show_filters = true;
+ } else {
+ $catid = '';
+ }
+
+ $links_list = null;
+
+ try {
+ $links = $C2->getLinks($params);
+ $links_counter = $C2->getLinks($params,true)->f(0);
+ $links_list = new adminlistCinecturlink2($core, $links, $links_counter);
+ } catch (Exception $e) {
+ $core->error->add($e->getMessage());
+ }
+
+ $breadcrumb[__('My cinecturlink')] = '';
+ $headers .=
+ dcPage::jsVars(['dotclear.filter_reset_url' => $core->adminurl->get('admin.plugin.cinecturlink2', ['part' => 'links'])]) .
+ dcPage::jsFilterControl($show_filters) .
+ dcPage::jsLoad(dcPage::getPF('cinecturlink2/js/c2links.js'));
+}
if ($part == 'link') {
- $breadcrumb[__('Link')] = '';
+ $langs_combo = l10n::getISOcodes(true);
+ $notes_combo = range(0, 20);
+ $media_combo = $tmp_media_combo = $dir = null;
+ try {
+ $allowed_media = ['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;
+
+ foreach($dir['files'] as $file) {
+ if (!in_array(files::getExtension($file->relname), $allowed_media)) {
+ continue;
+ }
+ $tmp_media_combo[$file->media_title] = $file->file_url;
+ }
+ if (!empty($tmp_media_combo)) {
+ $media_combo = array_merge(['-' => ''], $tmp_media_combo);
+ }
+ } catch (Exception $e) {
+ //$core->error->add($e->getMessage());
+ }
+
+ if (!empty($_POST['save'])) {
+ try {
+ cinecturlink2::test_folder(
+ DC_ROOT . '/' .$core->blog->settings->system->public_path,
+ $core->blog->settings->cinecturlink2->cinecturlink2_folder
+ );
+ if (empty($linktitle)) {
+ throw new Exception(__('You must provide a title.'));
+ }
+ if (empty($linkauthor)) {
+ throw new Exception(__('You must provide an author.'));
+ }
+ if (!preg_match('/https?:\/\/.+/', $linkimage)) {
+ throw new Exception(__('You must provide a link to an image.'));
+ }
+
+ $cur = $core->con->openCursor($C2->table);
+ $cur->link_title = $linktitle;
+ $cur->link_desc = $linkdesc;
+ $cur->link_author = $linkauthor;
+ $cur->link_url = $linkurl;
+ $cur->cat_id = $linkcat == '' ? null : $linkcat;
+ $cur->link_lang = $linklang;
+ $cur->link_img = $linkimage;
+ $cur->link_note = $linknote;
+
+ // create a link
+ if (empty($linkid)) {
+ $exists = $C2->getLinks(['link_title' => $linktitle], true)->f(0);
+ if ($exists) {
+ throw new Exception(__('Link with same name already exists.'));
+ }
+ $linkid = $C2->addLink($cur);
+
+ dcPage::addSuccessNotice(
+ __('Link successfully created.')
+ );
+ // update a link
+ } else {
+ $exists = $C2->getLinks(['link_id' => $linkid], true)->f(0);
+ if (!$exists) {
+ throw new Exception(__('Unknown link.'));
+ }
+ $C2->updLink($linkid, $cur);
+
+ dcPage::addSuccessNotice(
+ __('Link successfully updated.')
+ );
+ }
+ $core->adminurl->redirect('admin.plugin.cinecturlink2',
+ [
+ 'part' => 'link',
+ 'linkid' => $linkid,
+ 'redir' => $redir
+ ]
+ );
+ } catch (Exception $e) {
+ $core->error->add($e->getMessage());
+ }
+ }
+
+ if (!empty($_POST['delete']) && !empty($linkid)) {
+ try {
+ $C2->delLink($linkid);
+
+ dcPage::addSuccessNotice(
+ __('Link successfully deleted.')
+ );
+ if (!empty($_POST['redir'])) {
+ http::redirect($redir);
+ } else {
+ $core->adminurl->redirect('admin.plugin.cinecturlink2', ['part' => 'links']);
+ }
+ } catch (Exception $e) {
+ $core->error->add($e->getMessage());
+ }
+ }
+
+ if (!empty($linkid)) {
+ $link = $C2->getLinks(['link_id' => $linkid]);
+ if (!$link->isEmpty()) {
+ $linktitle = $link->link_title;
+ $linkdesc = $link->link_desc;
+ $linkauthor = $link->link_author;
+ $linkurl = $link->link_url;
+ $linkcat = $link->cat_id;
+ $linklang = $link->link_lang;
+ $linkimage = $link->link_img;
+ $linknote = $link->link_note;
+ }
+ }
+ $breadcrumb[(empty($linkid) ? __('New link') : __('Edit link'))] = '';
+ $headers .=
+ "\n" .
+ dcPage::jsLoad(dcPage::getPF('cinecturlink2/js/c2link.js'));
}
if ($part == 'cats') {
- $breadcrumb[__('Categories')] = '';
-
- $core->auth->user_prefs->addWorkspace('accessibility');
- if (!$core->auth->user_prefs->accessibility->nodragdrop) {
- $headers .=
- dcPage::jsLoad('js/jquery/jquery-ui.custom.js') .
- dcPage::jsLoad('js/jquery/jquery.ui.touch-punch.js') .
- dcPage::jsLoad(dcPage::getPF('cinecturlink2/js/cinecturlink2.js'));
- }
-
try {
// reorder categories
if (!empty($_POST['save'])) {
@@ -83,7 +366,7 @@ if ($part == 'cats') {
$C2->delCategory($id);
}
dcPage::addSuccessNotice(
- __('Category successfully deleted.')
+ __('Categories successfully deleted.')
);
$core->adminurl->redirect('admin.plugin.cinecturlink2', ['part' => 'cats']);
}
@@ -91,12 +374,19 @@ if ($part == 'cats') {
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
+
+ $breadcrumb[__('Categories')] = '';
+
+ $core->auth->user_prefs->addWorkspace('accessibility');
+ if (!$core->auth->user_prefs->accessibility->nodragdrop) {
+ $headers .=
+ dcPage::jsLoad('js/jquery/jquery-ui.custom.js') .
+ dcPage::jsLoad('js/jquery/jquery.ui.touch-punch.js') .
+ dcPage::jsLoad(dcPage::getPF('cinecturlink2/js/c2cats.js'));
+ }
}
if ($part == 'cat') {
- $breadcrumb[__('Categories')] = $core->adminurl->get('admin.plugin.cinecturlink2', ['part' => 'cats']);
- $breadcrumb[__('Category')] = '';
-
try {
// create category
if (!empty($_POST['save']) && empty($catid) && !empty($cattitle) && !empty($catdesc)) {
@@ -144,9 +434,10 @@ if ($part == 'cat') {
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
+ $breadcrumb[__('Categories')] = $core->adminurl->get('admin.plugin.cinecturlink2', ['part' => 'cats']);
+ $breadcrumb[(empty($catid) ? __('New category') : __('Edit category'))] = '';
}
-
echo
'' .
+ form::checkbox(['entries[]'], $this->rs->link_id, ['checked' => $checked]) .
+ ' ' .
+ '' .
+ '' .
+ html::escapeHTML($this->rs->link_title) . '' .
+ ' ' .
+ '' .
+ html::escapeHTML($this->rs->link_author) .
+ ' ' .
+ '' .
+ html::escapeHTML($this->rs->link_desc) .
+ ' ' .
+ '' .
+ '' . __('URL') . ' ' .
+ '' . __('image') . ' ' .
+ ' ' .
+ '' .
+ '' .
+ html::escapeHTML($this->rs->cat_title) . '' .
+ ' ' .
+ '' .
+ html::escapeHTML($this->rs->link_note) . '/20' .
+ ' ' .
+ '' .
+ dt::dt2str(
+ $this->core->blog->settings->system->date_format . ', ' . $this->core->blog->settings->system->time_format,
+ $this->rs->link_upddt,
+ $this->core->auth->getInfo('user_tz')
+ ) .
+ ' ' .
+ '' . $title . '
';
+}
+if ($part == 'updlinksnote') {
+ if ($links->isEmpty()) {
+ echo '' . __('Links') . '
';
+ while($links->fetch()) {
+ echo '
';
+
+ echo '' . __('Rating') . '
+ ';
+ }
+}
+
+if ($part == 'updlinkscat') {
+ if ($links->isEmpty()) {
+ echo '' . __('Links') . '
';
+ while($links->fetch()) {
+ echo '
';
+
+ echo '' . __('Category') . '
+
' . + '' . __('Edit categories') .' ' . + '
' . + '' . __('New Link') .' ' . __('New Category') .'
'; + + if ($links->isEmpty()) { + echo ''.__('There is no link').'
'; + } else { + echo + ''; + + $links_list->display($page, $nb_per_page, + '', + $show_filters, + $links_redir + ); + } } if ($part == "link") { + echo ' + '; } if ($part == "cats") { echo ''; if ($categories->isEmpty()) { @@ -180,8 +693,7 @@ if ($part == "cats") { } else { echo ' -