auth->makePermissions([ dcAuth::PERMISSION_CONTENT_ADMIN, initTemplator::PERMISSION_TEMPLATOR, ])); $part = $_REQUEST['part'] ?? ''; ### grab info ### if (in_array($part, ['files', 'delete'])) { $page = !empty($_GET['page']) ? $_GET['page'] : 1; $nb_per_page = 20; $media = new templatorMedia(); $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']); } if (in_array($part, ['new', 'copycat'])) { $has_categories = false; 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; } $has_categories = !$categories->isEmpty(); } catch (Exception $e) { } $combo_source = [ ' — ' => 'empty', '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 ($has_categories) { $combo_source['category.html'] = 'category'; } } ### Action ### /** * Duplicate dc template */ if ('new' == $part && !empty($_POST['filesource'])) { try { if ('category' == $_POST['filesource']) { $name = 'category-' . $_POST['filecat'] . '.html'; } elseif (!empty($_POST['filename'])) { $name = files::tidyFileName($_POST['filename']) . '.html'; } else { throw new Exception(__('Filename is empty.')); } dcCore::app()->templator->initializeTpl($name, $_POST['filesource']); 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()); } } /** * Copy tempaltor template */ if ('copy' == $part && !empty($_POST['filename'])) { try { dcCore::app()->templator->copypasteTpl( rawurldecode($_POST['filename']) . '.html', rawurldecode($_POST['file']) ); if (!dcCore::app()->error->flag()) { dcAdminNotices::addSuccessNotice(__('The template has been successfully copied.')); dcCore::app()->adminurl->redirect('admin.plugin.templator', ['part' => 'files']); } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } } /** * Copy templator category template */ if ('copycat' == $part && !empty($_POST['filecat'])) { try { dcCore::app()->templator->copypasteTpl( 'category-' . rawurldecode($_POST['filecat']) . '.html', rawurldecode($_POST['file']) ); if (!dcCore::app()->error->flag()) { dcAdminNotices::addSuccessNotice(__('The template has been successfully copied.')); dcCore::app()->adminurl->redirect('admin.plugin.templator', ['part' => 'files']); } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } } /** * Delete tempaltor template */ if ('delete' == $part && !empty($_POST['file'])) { try { $file = rawurldecode($_POST['file']); $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', ['part' => 'files']); } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } } ### Display ### /** * Check */ if (!dcCore::app()->templator->canUseRessources(true)) { dcCore::app()->error->add(__('The plugin is unusable with your configuration. You have to change file permissions.')); echo '' . __('Templator') . '' . '' . dcPage::breadcrumb([ __('Plugins') => '', __('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'), __('New template') => '', ]) . dcPage::notices(); /** * Duplicate dotclear template */ } elseif ('new' == $part) { echo '' . __('Templator') . '' . '' . dcPage::breadcrumb([ __('Plugins') => '', __('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'), __('New template') => '', ]) . dcPage::notices() . '
' . '

' . __('New template') . '

' . '

' . form::combo('filesource', $combo_source) . '

' . '

' . form::field('filename', 25, 255) . '

' . '

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

'; if ($has_categories) { echo '

' . form::combo('filecat', $categories_combo, '') . '

' . '

' . __('Required only for category template.') . '

'; } echo '

' . dcCore::app()->formNonce() . '

' . '
'; /** * Copy templator template */ } elseif ('copy' == $part && !empty($_REQUEST['file'])) { echo '' . __('Templator') . '' . '' . dcPage::breadcrumb([ __('Plugins') => '', __('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'), __('Copy available template') => '', ]) . dcPage::notices() . '
' . '

' . __('Copy available template') . '

' . '

' . form::field('filename', 25, 255) . '' . html::escapeHTML('.html') . '

' . '

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

' . '

' . ' ' . '' . __('Cancel') . '' . dcCore::app()->formNonce() . form::hidden('file', html::escapeHTML($_REQUEST['file'])) . '

' . '
'; /** * Copy templator category template */ } elseif ('copycat' == $part && !empty($_REQUEST['file'])) { $category_id = str_replace(['category-','.html'], '', $_REQUEST['file']); $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 '' . __('Templator') . '' . '' . dcPage::breadcrumb([ __('Plugins') => '', __('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'), __('Copy available template') => '', ]) . dcPage::notices() . '
' . '

' . __('Copy available template') . '

' . '

' . form::combo('filecat', $categories_combo, '') . '

' . '

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

' . ' ' . '' . __('Cancel') . '' . dcCore::app()->formNonce() . form::hidden('file', html::escapeHTML($_REQUEST['file'])) . '

' . '
'; /** * Delete templator template */ } elseif ('delete' == $part && !empty($_REQUEST['file'])) { echo '' . __('Templator') . '' . '' . dcPage::breadcrumb([ __('Plugins') => '', __('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'), __('Delete available template') => '', ]) . dcPage::notices() . '
' . '

' . __('Delete available template') . '

' . '

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

' . '

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

' . '
'; /** * List templator templates */ } elseif ('files' == $part) { echo '' . __('Templator') . '' . '' . dcPage::breadcrumb([ __('Plugins') => '', __('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'), __('Available templates') => '', ]) . dcPage::notices() . '

' . __('Available templates') . '

'; 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() . '

' . '
'; } /** * List Used templator template */ } elseif ('used' == $part) { $tags = dcCore::app()->meta->getMetadata(['meta_type' => 'template']); $tags = dcCore::app()->meta->computeMetaStats($tags); $tags->sort('meta_id_lower', 'asc'); $last_letter = null; $cols = ['','']; $col = 0; while ($tags->fetch()) { $letter = mb_strtoupper(mb_substr($tags->meta_id, 0, 1)); if ($last_letter != $letter) { if ($tags->index() >= round($tags->count() / 2)) { $col = 1; } $cols[$col] .= '' . $letter . ''; } $img = '%1$s'; if (array_key_exists($tags->meta_id, dcCore::app()->templator->tpl)) { $img_status = sprintf($img, __('available template'), 'check-on.png'); } else { $img_status = sprintf($img, __('missing template'), 'check-off.png'); } $cols[$col] .= '' . '' . $tags->meta_id . ' ' . $img_status . '' . '' . $tags->count . ' ' . (($tags->count == 1) ? __('entry') : __('entries')) . '' . ''; $last_letter = $letter; } $table = '
%s
'; echo '' . __('Templator') . '' . dcPage::cssLoad(dcPage::getPF('tags/style.css')) . '' . dcPage::breadcrumb([ __('Plugins') => '', __('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'), __('Used templates') => '', ]) . dcPage::notices() . '

' . __('Used templates') . '

'; if ($cols[0]) { echo '
'; printf($table, $cols[0]); if ($cols[1]) { printf($table, $cols[1]); } echo '
'; } else { echo '

' . __('No specific templates on this blog.') . '

'; } /** * Edit emplator template */ } elseif ('edit' == $part && !empty($_REQUEST['file'])) { try { try { $name = rawurldecode($_REQUEST['file']); $file = dcCore::app()->templator->getSourceContent($name); $name = $file['f']; if (preg_match('/^category-(.+).html$/', $name, $cat_id)) { $category = dcCore::app()->blog->getCategory($cat_id[1]); $full_name = ''; $cat_parents = dcCore::app()->blog->getCategoryParents($cat_id[1]); while ($cat_parents->fetch()) { $full_name = $cat_parents->cat_title . ' › '; }; $full_name = $full_name . dcCore::app()->blog->getCategory($cat_id)->cat_title; $name .= ' (' . $full_name . $category->cat_title . ')'; } } catch (Exception $e) { $file = $file_default; throw $e; } # Write file if (!empty($_POST['write'])) { $file['c'] = $_POST['file_content']; dcCore::app()->templator->writeTpl($file['f'], $file['c']); } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } dcCore::app()->auth->user_prefs->addWorkspace('interface'); echo '' . __('Templator') . ''; if (dcCore::app()->auth->user_prefs->interface->colorsyntax) { echo dcPage::jsJson('dotclear_colorsyntax', ['colorsyntax' => dcCore::app()->auth->user_prefs->interface->colorsyntax]); } echo dcPage::jsJson('theme_editor_msg', [ 'saving_document' => __('Saving document...'), 'document_saved' => __('Document saved'), 'error_occurred' => __('An error occurred:'), 'confirm_reset_file' => __('Are you sure you want to reset this file?'), ]) . dcPage::jsModuleLoad('themeEditor/js/script.js') . dcPage::jsConfirmClose('file-form'); if (dcCore::app()->auth->user_prefs->interface->colorsyntax) { echo dcPage::jsLoadCodeMirror(dcCore::app()->auth->user_prefs->interface->colorsyntax_theme); } echo dcPage::cssModuleLoad('themeEditor/style.css') . '' . dcPage::breadcrumb([ __('Plugins') => '', __('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'), __('Edit template') => '', ]) . dcPage::notices(); if (($file['c'] !== null)) { echo '
' . '

' . '

' . form::textarea('file_content', 72, 25, [ 'default' => html::escapeHTML($file['c']), 'class' => 'maximal', 'disabled' => !$file['w'], ]) . '

'; if ($file['w']) { echo '

' . '' . __('Cancel') . '' . dcCore::app()->formNonce() . form::hidden(['file_id'], html::escapeHTML($file['f'])) . '

'; } else { echo '

' . __('This file is not writable. Please check your files permissions.') . '

'; } echo '
'; if (dcCore::app()->auth->user_prefs->interface->colorsyntax) { echo dcPage::jsJson('theme_editor_mode', ['mode' => 'html']) . dcPage::jsModuleLoad('themeEditor/js/mode.js') . dcPage::jsRunCodeMirror('editor', 'file_content', 'dotclear', dcCore::app()->auth->user_prefs->interface->colorsyntax_theme); } } /** * Edit posts options linked to a template */ } elseif ('posts' == $part && (!empty($_REQUEST['file']) || $_REQUEST['file'] == '0')) { $file = $_REQUEST['file']; $redir = $_REQUEST['redir'] ?? dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'used']); # Unselect the template if (!empty($_POST['action']) && 'unselecttpl' == $_POST['action'] && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ dcAuth::PERMISSION_PUBLISH, dcAuth::PERMISSION_CONTENT_ADMIN, ]), dcCore::app()->blog->id)) { try { dcCore::app()->meta->delMeta($file, 'template'); dcCore::app()->adminurl->redirect('admin.plugin.templator', ['part' => 'posts', 'file' => $file]); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } } $filter = new adminGenericFilterV2('templator'); $filter->add(dcAdminFilters::getPageFilter()); $filter->add('part', 'posts'); $filter->add('file', $file); $filter->add('post_type', ''); $params = $filter->params(); $params['no_content'] = true; $params['meta_id'] = $file; $params['meta_type'] = 'template'; # Get posts try { $posts = dcCore::app()->meta->getPostsByMeta($params); $counter = dcCore::app()->meta->getPostsByMeta($params, true); $post_list = new adminPostList($posts, $counter->f(0)); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } echo '' . __('Templator') . '' . dcPage::jsFilterControl($filter->show()) . dcPage::jsLoad(dcPage::getPF('templator/js/posts.js')) . $filter->js(dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'posts', 'file' => $file])) . '' . dcPage::breadcrumb([ __('Plugins') => '', __('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'), __('Unselect template') => '', ]) . dcPage::notices() . '

' . __('Unselect template') . '

' . '

' . __('Back') . '

'; if (!dcCore::app()->error->flag()) { if ($posts->isEmpty() && !$filter->show()) { echo '

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

'; } else { $filter->display( 'admin.plugin.templator', form::hidden('p', 'templator') . form::hidden('part', 'posts') . form::hidden('file', $file) ); # Show posts $post_list->display( $filter->page, $filter->nb, '
' . '%s' . '
' . '

' . '

' . '

' . form::hidden('action', 'unselecttpl') . dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.templator', $filter->values()) . form::hidden('redir', $redir) . dcCore::app()->formNonce() . '
' . '
', $filter->show(), dcCore::app()->adminurl->get('admin.plugin.templator', $filter->values()) ); } } /** * Default page */ } else { echo '' . __('Templator') . '' . '' . dcPage::breadcrumb([ __('Plugins') => '', __('Templates engine') => '', ]) . dcPage::notices(); $line = '
  • %s
  • '; echo '

    ' . __('Manage additional templates') . '

    ' . sprintf( '

    ', sprintf( $line, dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'files']), __('Available templates') ) . sprintf( $line, dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'used']), __('Used templates') ) . sprintf( $line, dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'new']), __('New template') ) ); } dcPage::helpBlock('templator'); echo '';