smartifying: template.inc.php, category.inc.php
This commit is contained in:
@ -11,12 +11,12 @@ if (!serendipity_checkPermission('adminCategories')) {
|
||||
}
|
||||
|
||||
$admin_category = (!serendipity_checkPermission('adminCategoriesMaintainOthers') ? "AND (authorid = 0 OR authorid = " . (int)$serendipity['authorid'] . ")" : '');
|
||||
|
||||
$data = array();
|
||||
/* Add a new category */
|
||||
if (isset($_POST['SAVE']) && serendipity_checkFormToken()) {
|
||||
$name = $serendipity['POST']['cat']['name'];
|
||||
$desc = $serendipity['POST']['cat']['description'];
|
||||
|
||||
$data['post_save'] = true;
|
||||
if (is_array($serendipity['POST']['cat']['write_authors']) && in_array(0, $serendipity['POST']['cat']['write_authors'])) {
|
||||
$authorid = 0;
|
||||
} else {
|
||||
@ -27,6 +27,7 @@ if (isset($_POST['SAVE']) && serendipity_checkFormToken()) {
|
||||
$parentid = (isset($serendipity['POST']['cat']['parent_cat']) && is_numeric($serendipity['POST']['cat']['parent_cat'])) ? $serendipity['POST']['cat']['parent_cat'] : 0;
|
||||
|
||||
if ($serendipity['GET']['adminAction'] == 'new') {
|
||||
$data['new'] = true;
|
||||
if ($parentid != 0) {
|
||||
// TODO: This doesn't seem to work as expected, serendipity_rebuildCategoryTree(); is still needed! Only activate this optimization function when it's really working :)
|
||||
// TODO: This works if only one subcategory exists. Otherwise, the first query will return an array.
|
||||
@ -39,12 +40,10 @@ if (isset($_POST['SAVE']) && serendipity_checkFormToken()) {
|
||||
$catid = serendipity_addCategory($name, $desc, $authorid, $icon, $parentid);
|
||||
serendipity_ACLGrant($catid, 'category', 'read', $serendipity['POST']['cat']['read_authors']);
|
||||
serendipity_ACLGrant($catid, 'category', 'write', $serendipity['POST']['cat']['write_authors']);
|
||||
|
||||
echo '<div class="serendipityAdminMsgSuccess"><img style="height: 22px; width: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_success.png') . '" alt="" />' . CATEGORY_SAVED .'</div>';
|
||||
|
||||
} elseif ($serendipity['GET']['adminAction'] == 'edit') {
|
||||
$data['edit'] = true;
|
||||
if (!serendipity_checkPermission('adminCategoriesMaintainOthers') && !serendipity_ACLCheck($serendipity['authorid'], $serendipity['GET']['cid'], 'category', 'write')) {
|
||||
echo '<div class="serendipityAdminMsgError"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_error.png') . '" alt="" />'. PERM_DENIED .'</div>';
|
||||
$data['editPermission'] = false;
|
||||
} else {
|
||||
/* Check to make sure parent is not a child of self */
|
||||
$r = serendipity_db_query("SELECT categoryid FROM {$serendipity['dbPrefix']}category c
|
||||
@ -53,12 +52,11 @@ if (isset($_POST['SAVE']) && serendipity_checkFormToken()) {
|
||||
if (is_array($r)) {
|
||||
$r = serendipity_db_query("SELECT category_name FROM {$serendipity['dbPrefix']}category
|
||||
WHERE categoryid = ". (int)$parentid);
|
||||
echo sprintf(ALREADY_SUBCATEGORY, htmlspecialchars($r[0]['category_name']), htmlspecialchars($name));
|
||||
$data['subcat'] = sprintf(ALREADY_SUBCATEGORY, htmlspecialchars($r[0]['category_name']), htmlspecialchars($name));
|
||||
} else {
|
||||
serendipity_updateCategory($serendipity['GET']['cid'], $name, $desc, $authorid, $icon, $parentid, $serendipity['POST']['cat']['sort_order'], $serendipity['POST']['cat']['hide_sub']);
|
||||
serendipity_ACLGrant($serendipity['GET']['cid'], 'category', 'read', $serendipity['POST']['cat']['read_authors']);
|
||||
serendipity_ACLGrant($serendipity['GET']['cid'], 'category', 'write', $serendipity['POST']['cat']['write_authors']);
|
||||
echo '<div class="serendipityAdminMsgSuccess"><img style="height: 22px; width: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_success.png') . '" alt="" />' . CATEGORY_SAVED .'</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -69,6 +67,7 @@ if (isset($_POST['SAVE']) && serendipity_checkFormToken()) {
|
||||
|
||||
/* Delete a category */
|
||||
if ($serendipity['GET']['adminAction'] == 'doDelete' && serendipity_checkFormToken()) {
|
||||
$data['doDelete'] = true;
|
||||
if ($serendipity['GET']['cid'] != 0) {
|
||||
$remaining_cat = (int)$serendipity['POST']['cat']['remaining_catid'];
|
||||
$category_ranges = serendipity_fetchCategoryRange((int)$serendipity['GET']['cid']);
|
||||
@ -103,192 +102,112 @@ if ($serendipity['GET']['adminAction'] == 'doDelete' && serendipity_checkFormTok
|
||||
serendipity_ACLGrant($cid, 'category', 'write', array());
|
||||
}
|
||||
}
|
||||
|
||||
echo '<div class="serendipityAdminMsgSuccess"><img style="height: 22px; width: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_success.png') . '" alt="" />' . ($remaining_cat ? sprintf(CATEGORY_DELETED_ARTICLES_MOVED, (int)$serendipity['GET']['cid'], $remaining_cat) : sprintf(CATEGORY_DELETED,(int)$serendipity['GET']['cid'])) .'</div>';
|
||||
$data['deleteSuccess'] = true;
|
||||
$data['remaining_cat'] = $remaining_cat;
|
||||
$data['cid'] = (int)$serendipity['GET']['cid'];
|
||||
$serendipity['GET']['adminAction'] = 'view';
|
||||
}
|
||||
} else {
|
||||
echo '<div class="serendipityAdminMsgError"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_error.png') . '" alt="" />'. INVALID_CATEGORY .'</div>';
|
||||
$data['deleteSuccess'] = false;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
if ( $serendipity['GET']['adminAction'] == 'delete' ) {
|
||||
$this_cat = serendipity_fetchCategoryInfo($serendipity['GET']['cid']);
|
||||
if ( (serendipity_checkPermission('adminCategoriesDelete') && serendipity_checkPermission('adminCategoriesMaintainOthers'))
|
||||
|| (serendipity_checkPermission('adminCategoriesDelete') && ($serendipity['authorid'] == $this_cat['authorid'] || $this_cat['authorid'] == '0'))
|
||||
|| (serendipity_checkPermission('adminCategoriesDelete') && serendipity_ACLCheck($serendipity['authorid'], $serendipity['GET']['cid'], 'category', 'write'))) {
|
||||
?>
|
||||
<form method="POST" name="serendipityCategory" action="?serendipity[adminModule]=category&serendipity[adminAction]=doDelete&serendipity[cid]=<?php echo (int)$serendipity['GET']['cid'] ?>">
|
||||
<?php echo serendipity_setFormToken(); ?>
|
||||
<h3><?php echo htmlspecialchars($this_cat['category_name']); ?></h3>
|
||||
<?php echo CATEGORY_REMAINING ?>:
|
||||
<select name="serendipity[cat][remaining_catid]">
|
||||
<option value="0">- <?php echo NO_CATEGORY ?> -</option>
|
||||
<?php
|
||||
$cats = serendipity_fetchCategories('all');
|
||||
/* TODO, show dropdown as nested categories */
|
||||
foreach ($cats as $cat_data) {
|
||||
if ($cat_data['categoryid'] != $serendipity['GET']['cid'] && (serendipity_checkPermission('adminCategoriesMaintainOthers') || $cat_data['authorid'] == '0' || $cat_data['authorid'] == $serendipity['authorid'])) {
|
||||
echo '<option value="' . $cat_data['categoryid'] . '">' . htmlspecialchars($cat_data['category_name']) . '</option>' . "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<input type="submit" name="REMOVE" value="<?php echo GO ?>" class="serendipityPrettyButton input_button">
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
|
||||
<?php if ( $serendipity['GET']['adminAction'] == 'edit' || $serendipity['GET']['adminAction'] == 'new' ) {
|
||||
if ( $serendipity['GET']['adminAction'] == 'edit' ) {
|
||||
$cid = (int)$serendipity['GET']['cid'];
|
||||
$this_cat = serendipity_fetchCategoryInfo($cid);
|
||||
echo '<strong>'. sprintf(EDIT_THIS_CAT, htmlspecialchars($this_cat['category_name'])) .'</strong>';
|
||||
$save = SAVE;
|
||||
$read_groups = serendipity_ACLGet($cid, 'category', 'read');
|
||||
$write_groups = serendipity_ACLGet($cid, 'category', 'write');
|
||||
} else {
|
||||
$cid = false;
|
||||
$this_cat = array();
|
||||
echo '<strong>'. CREATE_NEW_CAT .'</strong>';
|
||||
$save = CREATE;
|
||||
$read_groups = array(0 => 0);
|
||||
$write_groups = array(0 => 0);
|
||||
}
|
||||
|
||||
$groups = serendipity_getAllGroups();
|
||||
?>
|
||||
<form method="POST" name="serendipityCategory">
|
||||
<?php echo serendipity_setFormToken(); ?>
|
||||
<table cellpadding="5" width="100%">
|
||||
<tr>
|
||||
<td><?php echo NAME; ?></td>
|
||||
<td><input class="input_textbox" type="text" name="serendipity[cat][name]" value="<?php echo isset($this_cat['category_name']) ? htmlspecialchars($this_cat['category_name']) : ''; ?>" /></td>
|
||||
<td rowspan="5" align="center" valign="middle" width="200" style="border: 1px solid #ccc"><img src="<?php echo isset($this_cat['category_icon']) ? htmlspecialchars($this_cat['category_icon']) : '' ?>" id="imagepreview" <?php echo empty($this_cat['category_icon']) ? 'style="display: none"' : '' ?> /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><?php echo DESCRIPTION; ?></td>
|
||||
<td><input class="input_textbox" type="text" name="serendipity[cat][description]" value="<?php echo isset($this_cat['category_description']) ? htmlspecialchars($this_cat['category_description']) : ''; ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><?php echo IMAGE; ?></td>
|
||||
<td>
|
||||
<script type="text/javascript" language="JavaScript" src="serendipity_editor.js"></script>
|
||||
<input class="input_textbox" type="text" id="img_icon" name="serendipity[cat][icon]" value="<?php echo isset($this_cat['category_icon']) ? htmlspecialchars($this_cat['category_icon']) : ''; ?>" onchange="document.getElementById('imagepreview').src = this.value; document.getElementById('imagepreview').style.display = '';" />
|
||||
<script type="text/javascript" language="JavaScript">document.write('<input type="button" name="insImage" value="<?php echo IMAGE ; ?>" onclick="window.open(\'serendipity_admin_image_selector.php?serendipity[htmltarget]=img_icon&serendipity[filename_only]=true\', \'ImageSel\', \'width=800,height=600,toolbar=no,scrollbars=1,scrollbars,resize=1,resizable=1\');" class="serendipityPrettyButton input_button" />');</script><!-- noscript>FIXXME: Emit a warning if JS is disabled</noscript -->
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><label for="read_authors"><?php echo PERM_READ; ?></label></td>
|
||||
<td>
|
||||
<select size="6" id="read_authors" multiple="multiple" name="serendipity[cat][read_authors][]">
|
||||
<option value="0" <?php echo (!is_array($this_cat) || (isset($this_cat['authorid']) && $this_cat['authorid'] == '0') || isset($read_groups[0])) ? 'selected="selected"' : ''; ?>><?php echo ALL_AUTHORS; ?></option>
|
||||
<?php
|
||||
foreach($groups AS $group) {
|
||||
echo '<option value="' . $group['confkey'] . '" ' . (isset($read_groups[$group['confkey']]) ? 'selected="selected"' : '') . '>' . htmlspecialchars($group['confvalue']) . '</option>' . "\n";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><label for="write_authors"><?php echo PERM_WRITE; ?></label></td>
|
||||
<td>
|
||||
<select size="6" id="write_authors" multiple="multiple" name="serendipity[cat][write_authors][]">
|
||||
<option value="0" <?php echo (!is_array($this_cat) || (isset($this_cat['authorid']) && $this_cat['authorid'] == '0') || isset($write_groups[0])) ? 'selected="selected"' : ''; ?>><?php echo ALL_AUTHORS; ?></option>
|
||||
<?php
|
||||
foreach($groups AS $group) {
|
||||
echo '<option value="' . $group['confkey'] . '" ' . (isset($write_groups[$group['confkey']]) ? 'selected="selected"' : '') . '>' . htmlspecialchars($group['confvalue']) . '</option>' . "\n";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><label for="parent_cat"><?php echo PARENT_CATEGORY; ?></label></td>
|
||||
<td>
|
||||
<select id="parent_cat" name="serendipity[cat][parent_cat]">
|
||||
<option value="0"<?php if ( (int)$serendipity['GET']['cid'] == 0 ) echo ' selected="selected"'; ?>>[ <?php echo NO_CATEGORY; ?> ]</option>
|
||||
<?php
|
||||
$categories = serendipity_fetchCategories('all');
|
||||
$categories = serendipity_walkRecursive($categories, 'categoryid', 'parentid', VIEWMODE_THREADED);
|
||||
foreach ( $categories as $cat ) {
|
||||
/* We can't be our own parent, the universe will collapse */
|
||||
if ( $cat['categoryid'] == $serendipity['GET']['cid'] ) {
|
||||
continue;
|
||||
if ( $serendipity['GET']['adminAction'] == 'delete' ) {
|
||||
$data['delete'] = true;
|
||||
$this_cat = serendipity_fetchCategoryInfo($serendipity['GET']['cid']);
|
||||
if ( (serendipity_checkPermission('adminCategoriesDelete') && serendipity_checkPermission('adminCategoriesMaintainOthers'))
|
||||
|| (serendipity_checkPermission('adminCategoriesDelete') && ($serendipity['authorid'] == $this_cat['authorid'] || $this_cat['authorid'] == '0'))
|
||||
|| (serendipity_checkPermission('adminCategoriesDelete') && serendipity_ACLCheck($serendipity['authorid'], $serendipity['GET']['cid'], 'category', 'write'))) {
|
||||
$data['deletePermission'] = true;
|
||||
$data['cid'] = (int)$serendipity['GET']['cid'];
|
||||
$data['formToken'] = serendipity_setFormToken();
|
||||
$data['categoryName'] = $this_cat['category_name'];
|
||||
$cats = serendipity_fetchCategories('all');
|
||||
$data['cats'] = array();
|
||||
/* TODO, show dropdown as nested categories */
|
||||
foreach ($cats as $cat_data) {
|
||||
if ($cat_data['categoryid'] != $serendipity['GET']['cid'] && (serendipity_checkPermission('adminCategoriesMaintainOthers') || $cat_data['authorid'] == '0' || $cat_data['authorid'] == $serendipity['authorid'])) {
|
||||
$data['cats'][] = $cat_data;
|
||||
|
||||
}
|
||||
echo '<option value="'. $cat['categoryid'] .'"'. ($this_cat['parentid'] == $cat['categoryid'] ? ' selected="selected"' : '') .'>'. str_repeat(' ', $cat['depth']) . $cat['category_name'] .'</option>' . "\n";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><?php echo CATEGORY_HIDE_SUB ?><br /><em><?php echo CATEGORY_HIDE_SUB_DESC; ?></em></td>
|
||||
<td valign="top">
|
||||
<input class="input_radio" type="radio" name="serendipity[cat][hide_sub]" value="0" <?php echo ($this_cat['hide_sub'] == 0 ? 'checked="checked"' : ''); ?> id="hide_sub_no" /> <label for="hide_sub_no"><?php echo NO; ?></label>
|
||||
<input class="input_radio" type="radio" name="serendipity[cat][hide_sub]" value="1" <?php echo ($this_cat['hide_sub'] == 1 ? 'checked="checked"' : ''); ?> id="hide_sub_yes" /> <label for="hide_sub_yes"><?php echo YES; ?></label>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php serendipity_plugin_api::hook_event('backend_category_showForm', $cid, $this_cat); ?>
|
||||
</table>
|
||||
<div><input type="submit" name="SAVE" value="<?php echo $save; ?>" class="serendipityPrettyButton input_button" /></div>
|
||||
</form>
|
||||
<?php } ?>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ( $serendipity['GET']['adminAction'] == 'edit' || $serendipity['GET']['adminAction'] == 'new' ) {
|
||||
if ( $serendipity['GET']['adminAction'] == 'edit' ) {
|
||||
$data['edit'] = true;
|
||||
$cid = (int)$serendipity['GET']['cid'];
|
||||
$this_cat = serendipity_fetchCategoryInfo($cid);
|
||||
$data['category_name'] = $this_cat['category_name'];
|
||||
$save = SAVE;
|
||||
$read_groups = serendipity_ACLGet($cid, 'category', 'read');
|
||||
$write_groups = serendipity_ACLGet($cid, 'category', 'write');
|
||||
} else {
|
||||
$data['new'] = true;
|
||||
$cid = false;
|
||||
$this_cat = array();
|
||||
echo '<strong>'. CREATE_NEW_CAT .'</strong>';
|
||||
$save = CREATE;
|
||||
$read_groups = array(0 => 0);
|
||||
$write_groups = array(0 => 0);
|
||||
}
|
||||
$data['cid'] = $cid;
|
||||
$data['this_cat'] = $this_cat;
|
||||
$data['save'] = $save;
|
||||
|
||||
$groups = serendipity_getAllGroups();
|
||||
$data['groups'] = $groups;
|
||||
$data['read_groups'] = $read_groups;
|
||||
$data['write_groups'] = $write_groups;
|
||||
|
||||
$data['formToken'] = serendipity_setFormToken();
|
||||
$data['cat'] = $this_cat;
|
||||
if (!is_array($this_cat) || (isset($this_cat['authorid']) && $this_cat['authorid'] == '0') || isset($read_groups[0])) {
|
||||
$data['selectAllReadAuthors'] = true;
|
||||
}
|
||||
if (!is_array($this_cat) || (isset($this_cat['authorid']) && $this_cat['authorid'] == '0') || isset($write_groups[0])) {
|
||||
$data['selectAllWriteAuthors'] = true;
|
||||
}
|
||||
|
||||
$categories = serendipity_fetchCategories('all');
|
||||
$categories = serendipity_walkRecursive($categories, 'categoryid', 'parentid', VIEWMODE_THREADED);
|
||||
$data['categories'] = $categories;
|
||||
serendipity_plugin_api::hook_event('backend_category_showForm', $cid, $this_cat);
|
||||
}
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
if ( $serendipity['GET']['adminAction'] == 'view' ) {
|
||||
if (empty($admin_category)) {
|
||||
$cats = serendipity_fetchCategories('all');
|
||||
} else {
|
||||
$cats = serendipity_fetchCategories(null, null, null, 'write');
|
||||
}
|
||||
$data['view'] = true;
|
||||
$data['viewCats'] = $cats;
|
||||
|
||||
if ( is_array($cats) && sizeof($cats) > 0 ) {
|
||||
echo CATEGORY_INDEX .':';
|
||||
} else {
|
||||
echo '<div align="center">- '. NO_CATEGORIES .' -</div>';
|
||||
if ( is_array($cats) ) {
|
||||
$categories = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
|
||||
$data['viewCategories'] = $categories;
|
||||
}
|
||||
?>
|
||||
<br /><br />
|
||||
<table cellspacing="0" cellpadding="4" width="100%" border=0>
|
||||
<?php
|
||||
if ( is_array($cats) ) {
|
||||
$categories = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
|
||||
foreach ( $categories as $category ) {
|
||||
?>
|
||||
<tr>
|
||||
<td width="16"><a title="<?php echo EDIT ?>" href="?serendipity[adminModule]=category&serendipity[adminAction]=edit&serendipity[cid]=<?php echo $category['categoryid'] ?>"><img src="<?php echo serendipity_getTemplateFile('admin/img/edit.png') ?>" border="0" alt="<?php echo EDIT ?>" /></a></td>
|
||||
<td width="16"><a title="<?php echo DELETE ?>" href="?serendipity[adminModule]=category&serendipity[adminAction]=delete&serendipity[cid]=<?php echo $category['categoryid'] ?>"><img src="<?php echo serendipity_getTemplateFile('admin/img/delete.png') ?>" border="0" alt="<?php echo DELETE ?>" /></a></td>
|
||||
<td width="16"><?php if ( !empty($category['category_icon']) ) {?><img src="<?php echo serendipity_getTemplateFile('admin/img/thumbnail.png') ?>" alt="" /><?php } else echo ' ' ?></td>
|
||||
<td width="300" style="padding-left: <?php echo ($category['depth']*15)+20 ?>px"><img src="<?php echo serendipity_getTemplateFile('admin/img/folder.png') ?>" style="vertical-align: bottom;"> <?php echo htmlspecialchars($category['category_name']) ?></td>
|
||||
<td><?php echo htmlspecialchars($category['category_description']) ?></td>
|
||||
<td align="right"><?php echo ($category['authorid'] == '0' ? ALL_AUTHORS : htmlspecialchars($category['realname'])); ?></td>
|
||||
</tr>
|
||||
<?php }
|
||||
} ?>
|
||||
<tr>
|
||||
<td colspan="6" align="right">
|
||||
<a href="?serendipity[adminModule]=category&serendipity[adminAction]=new" class="serendipityPrettyButton input_button"><?php echo CREATE_NEW_CAT ?></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php }
|
||||
}
|
||||
|
||||
if (!is_object($serendipity['smarty'])) {
|
||||
serendipity_smarty_init();
|
||||
}
|
||||
|
||||
$serendipity['smarty']->assign($data);
|
||||
|
||||
$tfile = dirname(__FILE__) . "/category.inc.tpl";
|
||||
|
||||
$inclusion = $serendipity['smarty']->security_settings[INCLUDE_ANY];
|
||||
$serendipity['smarty']->security_settings[INCLUDE_ANY] = true;
|
||||
$content = $serendipity['smarty']->fetch('file:'. $tfile);
|
||||
$serendipity['smarty']->security_settings[INCLUDE_ANY] = $inclusion;
|
||||
|
||||
echo $content;
|
||||
|
||||
/* vim: set sts=4 ts=4 expandtab : */
|
||||
|
Reference in New Issue
Block a user