auth->makePermissions([ dcAuth::PERMISSION_CONTENT_ADMIN, initTemplator::PERMISSION_TEMPLATOR, ])); $p_url = dcCore::app()->admin->getPageURL(); if ((!empty($_REQUEST['m'])) && ($_REQUEST['m'] = 'template_posts')) { require dirname(__FILE__) . '/' . $_REQUEST['m'] . '.php'; return; } if (!empty($_REQUEST['edit'])) { require dirname(__FILE__) . '/edit.php'; return; } if (!empty($_REQUEST['database']) && $_REQUEST['database'] = 'on') { require dirname(__FILE__) . '/advanced.php'; return; } $file_default = $file = ['c' => null, 'w' => false, 'type' => null, 'f' => null, 'default_file' => false]; $page = !empty($_GET['page']) ? $_GET['page'] : 1; $nb_per_page = 20; $msg = ''; $remove_confirm = false; // Load infos. $ressources = dcCore::app()->templator->canUseRessources(true); $files = dcCore::app()->templator->tpl; // Media $media = new dcMedia(); $media->chdir(dcCore::app()->templator->template_dir_name); // For users with only templator permission, we use sudo. dcCore::app()->auth->sudo([$media,'getDir']); $dir = & $media->dir; //if files did not appear in this list, check blog->settings->media_exclusion $items = array_values($dir['files']); // Categories try { $categories = dcCore::app()->blog->getCategories(['post_type' => 'post']); $categories_combo = []; $l = $categories->level; $full_name = [$categories->cat_title]; while ($categories->fetch()) { if ($categories->level < $l) { $full_name = []; } elseif ($categories->level == $l) { array_pop($full_name); } $full_name[] = html::escapeHTML($categories->cat_title); $categories_combo[implode(' › ', $full_name)] = $categories->cat_id; $l = $categories->level; } } catch (Exception $e) { } $hasCategories = ($categories->isEmpty()) ? false : true; $combo_source = [ 'post.html' => 'post', ]; if (dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcPages::PERMISSION_PAGES]), dcCore::app()->blog->id) && dcCore::app()->plugins->moduleExists('pages')) { $combo_source['page.html'] = 'page'; } if (!$categories->isEmpty()) { $combo_source['category.html'] = 'category'; } $combo_source[' — '] = 'empty'; $add_template = $copy_confirm = $copycat_confirm = false; if (!$ressources) { dcCore::app()->error->add(__('The plugin is unusable with your configuration. You have to change file permissions.')); } if (!empty($_POST['filesource'])) { try { $source = $_POST['filesource']; if (empty($_POST['filename']) && $source != 'category') { throw new Exception(__('Filename is empty.')); } $name = files::tidyFileName($_POST['filename']) . '.html'; if ($source == 'category') { $name = 'category-' . $_POST['filecat'] . '.html'; } dcCore::app()->templator->initializeTpl($name, $source); if (!dcCore::app()->error->flag()) { dcAdminNotices::addSuccessNotice(__('The new template has been successfully created.')); dcCore::app()->adminurl->redirect('admin.plugin.templator'); } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } } if (!empty($_POST['rmyes']) && !empty($_POST['remove'])) { try { $file = rawurldecode($_POST['remove']); $media->removeItem($file); dcCore::app()->meta->delMeta($file, 'template'); if (!dcCore::app()->error->flag()) { dcAdminNotices::addSuccessNotice(__('The template has been successfully removed.')); dcCore::app()->adminurl->redirect('admin.plugin.templator'); } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } } if (!empty($_POST['cpyes']) && !empty($_POST['copy']) && !empty($_POST['newfile'])) { try { $file = rawurldecode($_POST['copy']); $newfile = rawurldecode($_POST['newfile']) . '.html'; dcCore::app()->templator->copypasteTpl($newfile, $file); if (!dcCore::app()->error->flag()) { dcAdminNotices::addSuccessNotice(__('The template has been successfully copied.')); dcCore::app()->adminurl->redirect('admin.plugin.templator'); } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } } if (!empty($_POST['cpyes']) && !empty($_POST['copycat']) && !empty($_POST['copcat'])) { try { $file = rawurldecode($_POST['copycat']); $newfile = 'category-' . rawurldecode($_POST['copcat']) . '.html'; dcCore::app()->templator->copypasteTpl($newfile, $file); if (!dcCore::app()->error->flag()) { dcAdminNotices::addSuccessNotice(__('The template has been successfully copied.')); dcCore::app()->adminurl->redirect('admin.plugin.templator'); } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } } if (!empty($_GET['remove'])) { $remove_confirm = true; } if (!empty($_GET['copy'])) { $copy_confirm = true; } if (!empty($_GET['copycat'])) { $copycat_confirm = true; } echo '' . __('Templator') . '' . dcPage::cssLoad(dcPage::getPF('templator/style/style.css')) . (!$add_template ? dcPage::jsLoad(dcPage::getPF('templator/js/form.js')) : '') . dcPage::jsLoad(dcPage::getPF('templator/js/script.js')) . '' . dcPage::breadcrumb([ html::escapeHTML(dcCore::app()->blog->name) => '', __('Additional templates') => '', ]) . dcPage::notices(); if ($remove_confirm) { echo '
' . '

' . sprintf( __('Are you sure you want to remove the template "%s"?'), html::escapeHTML($_GET['remove']) ) . '

' . '

' . '   ' . dcCore::app()->formNonce() . form::hidden('remove', html::escapeHTML($_GET['remove'])) . '

' . '
'; } if ($copy_confirm) { echo '
' . '

' . sprintf( __('To copy the template %s, you need to fill a new filename.'), html::escapeHTML($_GET['copy']) ) . '

' . '

' . html::escapeHTML('.html') . '  ' . '  ' . dcCore::app()->formNonce() . form::hidden('copy', html::escapeHTML($_GET['copy'])) . '

' . '
'; } if ($copycat_confirm) { $category_id = str_replace('category-', '', $_GET['copycat']); $category_id = str_replace('.html', '', $category_id); $cat_parents = dcCore::app()->blog->getCategoryParents($category_id); $full_name = ''; while ($cat_parents->fetch()) { $full_name = $cat_parents->cat_title . ' › '; }; $name = $full_name . dcCore::app()->blog->getCategory($category_id)->cat_title; echo '
' . '

' . sprintf( __('To copy the template %s (%s), you need to choose a category.'), html::escapeHTML($_GET['copycat']), $name ) . '

' . '

' . '  ' . $dcCore::app()->formNonce() . form::hidden('copycat', html::escapeHTML($_GET['copycat'])) . '
'; } if (!$add_template) { echo '

' . __('New template') . '

'; } echo '
' . '

' . __('New template') . '

' . '

' . '


' . __('Extension .html is automatically added to filename') . '

'; if ($hasCategories) { echo '

'; } echo '

' . form::hidden(['p'], 'templator') . dcCore::app()->formNonce() . '

' . '
'; if (count($items) == 0) { echo '

' . __('No template.') . '

'; } else { $pager = new pager($page, count($items), $nb_per_page, 10); $pager->html_prev = __('«prev.'); $pager->html_next = __('next»'); echo '
' . '
' . '
' . '

' . __('Page(s)') . ' : ' . $pager->getLinks() . '

'; for ($i = $pager->index_start, $j = 0; $i <= $pager->index_end; $i++, $j++) { echo pagerTemplator::templatorItemLine($items[$i], $j); } echo '

' . __('Page(s)') . ' : ' . $pager->getLinks() . '

' . '
'; } echo '

' . __('Display templates used for entries in base') . '

'; ?>