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 = $core->templator->canUseRessources(true); $files= $core->templator->tpl; // Media $media = new dcMedia($core); $media->chdir($core->templator->template_dir_name); // For users with only templator permission, we use sudo. $core->auth->sudo(array($media,'getDir')); $dir =& $media->dir; $items = array_values($dir['files']); // Categories try { $categories = $core->blog->getCategories(array('post_type'=>'post')); $categories_combo = array(); $l = $categories->level; $full_name = array($categories->cat_title); while ($categories->fetch()) { if ($categories->level < $l) { $full_name = array(); } 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 = array( 'post.html' => 'post' ); if ($core->auth->check('pages',$core->blog->id) && $core->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) { $core->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'; } $core->templator->initializeTpl($name,$source); } catch (Exception $e) { $core->error->add($e->getMessage()); } if (!$core->error->flag()) { http::redirect($p_url.'&msg=new'); } } if (!empty($_POST['rmyes']) && !empty($_POST['remove']) ) { try { $file = rawurldecode($_POST['remove']); $media->removeItem($file); $core->meta->delMeta($file,'template'); } catch (Exception $e) { $core->error->add($e->getMessage()); } if (!$core->error->flag()) { http::redirect($p_url.'&msg=del'); } } if (!empty($_POST['cpyes']) && !empty($_POST['copy']) && !empty($_POST['newfile'])) { try { $file = rawurldecode($_POST['copy']); $newfile = rawurldecode($_POST['newfile']).'.html'; $core->templator->copypasteTpl($newfile,$file); } catch (Exception $e) { $core->error->add($e->getMessage()); } if (!$core->error->flag()) { http::redirect($p_url.'&msg=cpy'); } } if (!empty($_POST['cpyes']) && !empty($_POST['copycat']) && !empty($_POST['copcat'])) { try { $file = rawurldecode($_POST['copycat']); $newfile = 'category-'.rawurldecode($_POST['copcat']).'.html'; $core->templator->copypasteTpl($newfile,$file); } catch (Exception $e) { $core->error->add($e->getMessage()); } if (!$core->error->flag()) { http::redirect($p_url.'&msg=cpy'); } } if (!empty($_GET['remove'])) { $remove_confirm = true; } if (!empty($_GET['copy'])) { $copy_confirm = true; } if (!empty($_GET['copycat'])) { $copycat_confirm = true; } $msg = isset($_REQUEST['msg']) ? $_REQUEST['msg'] : ''; $msg_list = array( 'new' => __('The new template has been successfully created.'), 'del' => __('The template has been successfully removed.'), 'cpy' => __('The template has been successfully copied.') ); if (isset($msg_list[$msg])) { $msg = sprintf('

%s

',$msg_list[$msg]); } ?> <?php echo __('Templator'); ?> '.html::escapeHTML($core->blog->name).' › '.__('Supplementary templates').''; if ($remove_confirm) { echo '
'. '

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

'. '

'. '   '. $core->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').'  '. '  '. $core->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 = $core->blog->getCategoryParents($category_id); $full_name = ''; while ($cat_parents->fetch()) {$full_name = $cat_parents->cat_title.' › ';}; $name = $full_name.$core->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).'

'. '

'. '  '. $core->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(array('p'),'templator'). $core->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').'

'; ?>