Skip to content
Permalink
Browse files

カテゴリの並び替え機能(categoryテーブルにcorderを追加)

  • Loading branch information...
piyoyo
piyoyo committed Mar 23, 2015
1 parent 63b24f9 commit 4972c468c8184eb69337048f747b9318551f1da4
11 install/install.sql 100755 → 100644
@@ -69,10 +69,13 @@ CREATE TABLE `nucleus_category` (
`cblog` int(11) NOT NULL default '0',
`cname` varchar(200) default NULL,
`cdesc` varchar(200) default NULL,
PRIMARY KEY (`catid`)
`corder` int(11) NOT NULL default '100',
PRIMARY KEY (`catid`),
INDEX `cblog` (`cblog`),
INDEX `corder` (`corder`)
) ENGINE=MyISAM;

INSERT INTO `nucleus_category` VALUES (1, 1, 'General', 'Items that do not fit in other categories');
INSERT INTO `nucleus_category` VALUES (1, 1, 'General', 'Items that do not fit in other categories',100);

CREATE TABLE `nucleus_comment` (
`cnumber` int(11) NOT NULL auto_increment,
@@ -151,8 +154,8 @@ CREATE TABLE `nucleus_item` (
`iposted` tinyint(2) NOT NULL default '1',
PRIMARY KEY (`inumber`),
KEY `itime` (`itime`),
INDEX `iblog` (`iblog`),
INDEX `idraft` (`idraft`),
INDEX `iblog` (`iblog`),
INDEX `idraft` (`idraft`),
INDEX `icat` (`icat`),
FULLTEXT KEY `ibody` (`ibody`, `ititle`, `imore`)
) ENGINE=MyISAM PACK_KEYS=0;
@@ -360,6 +360,11 @@ <h1><a id="nucleus_category" name="nucleus_category">nucleus_categoryテーブ
<td>varchar(200)</td>
<td>NULL</td>
<td>カテゴリーの説明</td>
</tr><tr>
<td class="notnull">corder</td>
<td>int(11)</td>
<td>100</td>
<td>カテゴリが表示される順番。数字が小さいほどリストの上になります。</td>
</tr></table>


@@ -17,6 +17,19 @@
// Note for Japanese users
// このファイルは Nucleus の UTF-8 版日本語ランゲージファイルです。
define('_LISTS_ITEM_COUNT', 'アイテム数');
define('_LISTS_ORDER', '並び順');
define('_EBLOG_CAT_ORDER', "カテゴリーの並び順です。<br />\n入力値は、数字(標準 100)で小さいほど上になります");
define('_EBLOG_CAT_ORDER_DESC2', "入力値は、数字(標準 100)で小さいほど上になります");
// category order changes (batch)
define('_BATCH_CAT_CAHANGE_ORDER', '並び順を変更する');
define('_ERROR_CAHANGE_CATEGORY_ORDER', '並びを変更できません');
define('_CAHANGE_CATEGORY_ORDER_TITLE', 'カテゴリーの並び順を指定してください');
define('_CAHANGE_CATEGORY_ORDER_CONFIRM_DESC', '以下のカテゴリーの並び順が一括で変更されます。よろしければ、ボタンを押してください。');
define('_CAHANGE_CATEGORY_ORDER_BTN_TITLE', '並び順を変更する');
define('_ADD_DATEINPUTNOW', '現在時刻');
define('_ADD_DATEINPUTRESET', 'リセット');
212 nucleus/libs/ADMIN.php 100755 → 100644
@@ -655,10 +655,17 @@ function action_batchcategory() {
if (($action == 'delete') && (requestVar('confirmation') != 'yes'))
$this->batchAskDeleteConfirmation('category',$selected);
if ($action == 'change_corder')
{
if ( (!isset($_POST['new_corder']))
|| (!is_numeric($_POST['new_corder'])) )
$this->batchChangeCategorySelectOrder('category' , $selected );
}
$this->pagehead();
echo '<a href="index.php?action=overview">(',_BACKHOME,')</a>';
echo '<h2>',BATCH_CATEGORIES,'</h2>';
echo '<h2>',_BATCH_CATEGORIES,'</h2>';
echo '<p>',_BATCH_EXECUTING,' <b>',hsc($action),'</b></p>';
echo '<ul>';
@@ -675,6 +682,10 @@ function action_batchcategory() {
case 'move':
$error = $this->moveOneCategory($catid, $destBlogId);
break;
case 'change_corder':
$new_corder = intRequestVar('new_corder');
$error = $this->changeOneCategoryOrder($catid, $new_corder);
break;
default:
$error = _BATCH_UNKNOWN . hsc($action);
}
@@ -756,6 +767,88 @@ function batchMoveCategorySelectDestination($type, $ids) {
exit;
}
function batchChangeCategorySelectOrder($type, $ids)
{
global $manager , $member , $CONF;
$this->pagehead();
if ($CONF['debug'])
{
echo "<!-- ". __CLASS__ . '::' . __FUNCTION__ . " -->\n";
//var_dump($ids);
}
?>
<h2><?php echo _CAHANGE_CATEGORY_ORDER_TITLE ?></h2>
<form method="post" action="index.php"><div>

<input type="hidden" name="action" value="batch<?php echo $type?>" />
<input type="hidden" name="batchaction" value="change_corder" />
<?php
$manager->addTicketHidden();
// insert selected Category numbers
$idx = 0;
foreach ($ids as $id)
echo '<input type="hidden" name="batch[',($idx++),']" value="',intval($id),'" />';
$def_oder = 100;
if ( isset($ids[0]) && ( intval($ids[0]) > 0 ) )
{
$ids[0] = intval($ids[0]);
// $manager->existsCategory
$bid = getBlogIDFromCatID($ids[0]);
if ($member->blogAdminRights($bid))
{
$b = $manager->getBlog($bid);
$def_oder = $b->getCategoryOrder($ids[0]);
}
}
echo sprintf('<input type="text" name="new_corder" value="%d" />', $def_oder);
?>
<input type="submit" value="<?php echo _CAHANGE_CATEGORY_ORDER_BTN_TITLE ?>" onclick="return checkSubmit();" />

</div></form>
<?php
$s = '';
foreach ($ids as $id)
{
$bid = getBlogIDFromCatID($id);
if ($member->blogAdminRights($bid))
{
unset($b , $o);
$b = $manager->getBlog($bid);
$res = sql_query('SELECT * FROM ' . sql_table('category')
. ' WHERE cblog=' . $bid . ' and catid=' . intval($id));
$o = sql_fetch_object($res);
if (isset($o) && is_object($o))
{
$s .= sprintf('<tr><td>%s</td><td>%s</td><td>%s</td></tr>'
, hsc($o->corder), hsc($o->cname), hsc($o->cdesc)
);
continue;
}
}
$s .= sprintf('<tr><td>error</td><td>catid:%d</td><td></td></tr>' , $id);
}
if ($s)
{
echo "<p>". _CAHANGE_CATEGORY_ORDER_CONFIRM_DESC . "</p>\n";
echo "<table>"
. sprintf('<tr><td>%s</td><td>%s</td><td>%s</td></tr>'
, hsc( _LISTS_ORDER ), hsc( _LISTS_NAME ), hsc( _LISTS_DESC )
)
. $s . "</table>\n";
}
$this->pagefoot();
exit;
}
/**
* @todo document this
*/
@@ -859,7 +952,7 @@ function selectBlog($name, $mode='blog', $selected = 0, $tabindex = 0, $showNewC
}
// 2. for each category in that blog
$categories = sql_query('SELECT cname, catid FROM '.sql_table('category').' WHERE cblog=' . $oBlog->bnumber . ' ORDER BY cname ASC');
$categories = sql_query('SELECT cname, catid FROM '.sql_table('category').' WHERE cblog=' . $oBlog->bnumber . ' ORDER BY corder ASC, cname ASC');
while ($oCat = sql_fetch_object($categories)) {
if ($oCat->catid == $selected)
$selectText = ' selected="selected" ';
@@ -2202,7 +2295,7 @@ function action_activatesetpwd() {
$password = postVar('password');
$repeatpassword = postVar('repeatpassword');
if (!$password) {
if (!$password) {
return $this->_showActivationPage($key, _ERROR_PASSWORDMISSING);
}
@@ -2627,7 +2720,14 @@ function action_blogsettings() {


<?php
$query = 'SELECT * FROM '.sql_table('category').' WHERE cblog='.$blog->getID().' ORDER BY cname';
$query = 'SELECT c.* , count(i.icat) as icount '
. ' FROM ' . sql_table('category') . ' c '
. ' LEFT JOIN ' . sql_table('item') . ' i '
. ' ON c . catid = i . icat '
. ' WHERE cblog=' . $blog->getID()
. ' GROUP BY c . catid '
. ' ORDER BY c.corder ASC , c.cname ASC ';
$template['content'] = 'categorylist';
$template['tabindex'] = 200;
@@ -2651,6 +2751,9 @@ function action_blogsettings() {
</tr><tr>
<td><?php echo _EBLOG_CAT_DESC?></td>
<td><input name="cdesc" size="40" maxlength="200" tabindex="310" /></td>
</tr><tr>
<td><?php echo _EBLOG_CAT_ORDER ?></td>
<td><input name="corder" size="40" maxlength="200" tabindex="320" value="100" /></td>
</tr><tr>
<td><?php echo _EBLOG_CAT_CREATE?></td>
<td><input type="submit" value="<?php echo _EBLOG_CAT_CREATE?>" tabindex="320" /></td>
@@ -2687,6 +2790,18 @@ function action_categorynew() {
$cname = postVar('cname');
$cdesc = postVar('cdesc');
$corder = null;
if ( isset($_POST['corder']) )
{
$corder =& $_POST['corder'];
if ( (!is_null($corder))
&& (is_numeric($corder))
)
$corder = intval($corder);
else
$corder = null;
}
if (!isValidCategoryName($cname))
$this->error(_ERROR_BADCATEGORYNAME);
@@ -2696,7 +2811,7 @@ function action_categorynew() {
$this->error(_ERROR_DUPCATEGORYNAME);
$blog =& $manager->getBlog($blogid);
$newCatID = $blog->createNewCategory($cname, $cdesc);
$newCatID = $blog->createNewCategory($cname, $cdesc, $corder);
$this->action_blogsettings();
}
@@ -2723,6 +2838,7 @@ function action_categoryedit($catid = '', $blogid = '', $desturl = '') {
$cname = $obj->cname;
$cdesc = $obj->cdesc;
$corder = $obj->corder;
$extrahead = '<script type="text/javascript" src="javascript/numbercheck.js"></script>';
$this->pagehead($extrahead);
@@ -2747,6 +2863,10 @@ function action_categoryedit($catid = '', $blogid = '', $desturl = '') {
<td><?php echo _EBLOG_CAT_DESC?></td>
<td><input type="text" name="cdesc" value="<?php echo hsc($cdesc)?>" size="40" maxlength="200" /></td>
</tr>
<tr>
<td><?php echo _EBLOG_CAT_ORDER?></td>
<td><input type="text" name="corder" value="<?php echo hsc($corder)?>" size="40" maxlength="200" /></td>
</tr>
<?php
// insert plugin options
$this->_insertPluginOptions('category',$catid);
@@ -2775,6 +2895,18 @@ function action_categoryupdate() {
$cdesc = postVar('cdesc');
$desturl = postVar('desturl');
$corder = null;
if ( isset($_POST['corder']) )
{
$corder =& $_POST['corder'];
if ( (!is_null($corder))
&& (is_numeric($corder))
)
$corder = intval($corder);
else
$corder = null;
}
$member->blogAdminRights($blogid) or $this->disallow();
if (!isValidCategoryName($cname))
@@ -2787,9 +2919,12 @@ function action_categoryupdate() {
$query = 'UPDATE '.sql_table('category').' SET'
. " cname='" . sql_real_escape_string($cname) . "',"
. " cdesc='" . sql_real_escape_string($cdesc) . "'"
. " WHERE catid=" . $catid;
. " cdesc='" . sql_real_escape_string($cdesc) . "'";
if ( ! is_null( $corder) )
$query .= sprintf(' , corder=%d' , $corder );
$query .= " WHERE catid=" . $catid;
sql_query($query);
// store plugin options
@@ -2990,6 +3125,53 @@ function moveOneCategory($catid, $destblogid) {
}
function changeOneCategoryOrder($catid, $new_corder)
{
global $manager, $member;
$catid = intval($catid);
$new_corder = intval($new_corder);
$blogid = intval(getBlogIDFromCatID($catid));
// mover should have admin rights on both blogs
if ( !$blogid || !$member->blogAdminRights($blogid) )
return _ERROR_DISALLOWED;
// get blogs
$blog =& $manager->getBlog($blogid);
// check if the category is valid
if (!$blog || !$blog->isValidCategory($catid))
return _ERROR_NOSUCHCATEGORY;
$old_corder = $blog->getCategoryOrder($catid);
$param = array(
'catid' => $catid,
'blog' => $blog ,
'old_corder' => $old_corder ,
'new_corder' => &$new_corder
);
$manager->notify('PreChangeCategoryOrder', $param);
// update category corder
$query = 'UPDATE '.sql_table('category')
. ' SET corder=' . intval($new_corder)
. ' WHERE cblog='.$blogid.' AND catid='.$catid;
sql_query($query);
$param = array(
'catid' => $catid ,
'blog' => $blog ,
'old_corder' => $old_corder ,
'new_corder' => $new_corder
);
$manager->notify('PostChangeCategoryOrder', $param);
}
/**
* @todo document this
*/
@@ -5290,7 +5472,7 @@ function pagehead($extrahead = '') {
<html <?php echo _HTML_XML_NAME_SPACE_AND_LANG_CODE; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo _CHARSET ?>" />
<meta name="robots" content="noindex, nofollow" />
<meta name="robots" content="noindex, nofollow" />
<title><?php echo hsc($CONF['SiteName'])?> - Admin</title>
<link rel="stylesheet" title="Nucleus Admin Default" type="text/css" href="<?php echo $baseUrl?>styles/admin_<?php echo $CONF["AdminCSS"]?>.css" />
<link rel="stylesheet" title="Nucleus Admin Default" type="text/css"
@@ -5300,9 +5482,9 @@ function pagehead($extrahead = '') {
<script type="text/javascript" src="<?php echo $baseUrl?>javascript/admin.js"></script>
<script type="text/javascript" src="<?php echo $baseUrl?>javascript/compatibility.js"></script>

<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
<meta http-equiv="Expires" content="-1" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
<meta http-equiv="Expires" content="-1" />

<?php echo $extrahead?>
</head>
@@ -6093,10 +6275,10 @@ function action_pluginhelp() {
elseif(is_file("{$cplugindir}help/index.html"))
$helpFile = "{$cplugindir}help/index.html";
if ($plug->supportsFeature('HelpPage') > 0 && isset($helpFile)) {
if(substr($helpFile,-4)==='.php') include_once($helpFile);
else @readfile($helpFile);
} else {
if ($plug->supportsFeature('HelpPage') > 0 && isset($helpFile)) {
if(substr($helpFile,-4)==='.php') include_once($helpFile);
else @readfile($helpFile);
} else {
echo '<p>' . _ERROR .': ', _ERROR_PLUGNOHELPFILE,'</p>';
echo '<p><a href="index.php?action=pluginlist">(',_BACK,')</a></p>';
}

0 comments on commit 4972c46

Please sign in to comment.
You can’t perform that action at this time.