From: sakamocchi Date: Thu, 7 Jun 2012 15:53:55 +0000 (+0900) Subject: CHANGE: Adminクラスのスキン関係メソッドの整理・統合 X-Git-Url: http://git.osdn.net/view?p=nucleus-jp%2Fnucleus-next.git;a=commitdiff_plain;h=eb080ad31a3105dac5cb1ba827ca2475df51b205 CHANGE: Adminクラスのスキン関係メソッドの整理・統合 管理画面/通常画面用ページアクションにおいて同じ処理をしている箇所がある。 コードのメンテナンスを簡便にするため、それらの処理を独立した以下のメソッドに集約した。 Admin::skinclone() Admin::skindeleteconfirm() Admin::skineditgeneral()Admin::skiniedoimport() Admin::skinieexport() Admin::skinieimport() Admin::skinremovetypeconfirm() --- diff --git a/nucleus/libs/ADMIN.php b/nucleus/libs/ADMIN.php index 766b4ed..839a8db 100644 --- a/nucleus/libs/ADMIN.php +++ b/nucleus/libs/ADMIN.php @@ -2905,54 +2905,14 @@ class Admin */ static private function action_skinieimport() { - global $member, $DIR_LIBS, $DIR_SKINS, $manager; + global $member; $member->isAdmin() or self::disallow(); - // load skinie class - include_once($DIR_LIBS . 'skinie.php'); - - $skinFileRaw = postVar('skinfile'); - $mode = postVar('mode'); - - $importer = new SkinImport(); - - // get full filename - if ( $mode == 'file' ) - { - $skinFile = $DIR_SKINS . $skinFileRaw . '/skinbackup.xml'; - - /* TODO: remove this - // backwards compatibilty (in v2.0, exports were saved as skindata.xml) - if ( !file_exists($skinFile) ) - { - $skinFile = $DIR_SKINS . $skinFileRaw . '/skindata.xml'; - } - */ - } - else - { - $skinFile = $skinFileRaw; - } - - // read only metadata - $error = $importer->readFile($skinFile, 1); - - /* TODO: we should consider to use the other way insterad of this */ - $_REQUEST['skininfo'] = $importer->getInfo(); - $_REQUEST['skinnames'] = $importer->getSkinNames(); - $_REQUEST['tpltnames'] = $importer->getTemplateNames(); - - // clashes - $skinNameClashes = $importer->checkSkinNameClashes(); - $templateNameClashes = $importer->checkTemplateNameClashes(); - $hasNameClashes = (count($skinNameClashes) > 0) || (count($templateNameClashes) > 0); - - /* TODO: we should consider to use the other way insterad of this */ - $_REQUEST['skinclashes'] = $skinNameClashes; - $_REQUEST['tpltclashes'] = $templateNameClashes; - $_REQUEST['nameclashes'] = $hasNameClashes ? 1 : 0; + $skinFileRaw = postVar('skinfile'); + $mode = postVar('mode'); + $error = self::skinieimport($mode, $skinFileRaw); if ( $error ) { self::error($error); @@ -2978,56 +2938,21 @@ class Admin // load skinie class include_once($DIR_LIBS . 'skinie.php'); - $skinFileRaw = postVar('skinfile'); - $mode = postVar('mode'); - + $mode = postVar('mode'); + $skinFileRaw = postVar('skinfile'); $allowOverwrite = intPostVar('overwrite'); - // get full filename - if ( $mode == 'file' ) - { - $skinFile = $DIR_SKINS . $skinFileRaw . '/skinbackup.xml'; - - /* TODO: remove this - // backwards compatibilty (in v2.0, exports were saved as skindata.xml) - if ( !file_exists($skinFile) ) - { - $skinFile = $DIR_SKINS . $skinFileRaw . '/skindata.xml'; - } - */ - } - else - { - $skinFile = $skinFileRaw; - } - - $importer = new SkinImport(); - - $error = $importer->readFile($skinFile); - + $error = self::skinieedoimport($mode, $skinFileRaw, $allowOverwrite); if ( $error ) { - self::error($error); + self::error($msg); return; } - $error = $importer->writeToDatabase($allowOverwrite); - - if ( $error ) - { - self::error($error); - return; - } - - /* TODO: we should consider to use the other way insterad of this */ - $_REQUEST['skininfo'] = $importer->getInfo(); - $_REQUEST['skinnames'] = $importer->getSkinNames(); - $_REQUEST['tpltnames'] = $importer->getTemplateNames(); - self::$skin->parse('skiniedoimport'); return; } - + /** * Admin::action_skinieexport() * @@ -3036,42 +2961,16 @@ class Admin */ static private function action_skinieexport() { - global $member, $DIR_LIBS; + global $member; $member->isAdmin() or self::disallow(); - // load skinie class - include_once($DIR_LIBS . 'skinie.php'); - - $aSkins = requestIntArray('skin'); - $aTemplates = requestIntArray('template'); - - if ( !is_array($aTemplates) ) - { - $aTemplates = array(); - } - if ( !is_array($aSkins) ) - { - $aSkins = array(); - } - - $skinList = array_keys($aSkins); - $templateList = array_keys($aTemplates); - + $aSkins = requestIntArray('skin'); + $aTemplates = requestIntArray('template'); $info = postVar('info'); - $exporter = new SkinExport(); - foreach ( $skinList as $skinId ) - { - $exporter->addSkin($skinId); - } - foreach ($templateList as $templateId) - { - $exporter->addTemplate($templateId); - } - $exporter->setInfo($info); + self::skinieexport($aSkins, $aTemplates, $info); - $exporter->export(); return; } @@ -3751,14 +3650,13 @@ class Admin self::error(_ERROR_BADSKINNAME); return; } - - if ( SKIN::exists($name) ) + else if ( SKIN::exists($name) ) { self::error(_ERROR_DUPSKINNAME); return; } - $newId = SKIN::createNew($name, $desc); + SKIN::createNew($name, $desc); self::action_skinoverview(); return; @@ -3772,7 +3670,7 @@ class Admin */ static private function action_skinedit() { - global $member, $manager; + global $member; $member->isAdmin() or self::disallow(); @@ -3788,52 +3686,26 @@ class Admin */ static private function action_skineditgeneral() { - global $manager, $member; + global $member; $skinid = intRequestVar('skinid'); $member->isAdmin() or self::disallow(); - $name = postVar('name'); - $desc = postVar('desc'); - $type = postVar('type'); - $inc_mode = postVar('inc_mode'); - $inc_prefix = postVar('inc_prefix'); - - $skin =& $manager->getSkin($skinid); - - // 1. Some checks - if ( !isValidSkinName($name) ) - { - self::error(_ERROR_BADSKINNAME); - return; - } - - if ( ($skin->getName() != $name) && SKIN::exists($name) ) + $error = self::skineditgeneral($skinid); + if ( $error ) { - self::error(_ERROR_DUPSKINNAME); + self::error($error); return; } - if ( !$type ) - { - $type = 'text/html'; - } - if ( !$inc_mode ) - { - $inc_mode = 'normal'; - } - - // 2. Update description - $skin->updateGeneralInfo($name, $desc, $type, $inc_mode, $inc_prefix); - self::action_skinedit(); return; } static private function action_skinedittype($msg = '') { - global $member, $manager; + global $member; $member->isAdmin() or self::disallow(); @@ -3842,10 +3714,9 @@ class Admin self::$headMess = $msg; } - $skinid = intRequestVar('skinid'); - $type = requestVar('type'); - $type = trim($type); - $type = strtolower($type); + $type = requestVar('type'); + $type = trim($type); + $type = strtolower($type); if ( !isValidShortName($type) ) { @@ -3888,12 +3759,12 @@ class Admin */ static private function action_skindelete() { - global $manager, $member, $CONF; - - $skinid = intRequestVar('skinid'); + global $CONF, $member; $member->isAdmin() or self::disallow(); + $skinid = intRequestVar('skinid'); + // don't allow default skin to be deleted if ( $skinid == $CONF['BaseSkin'] ) { @@ -3924,12 +3795,12 @@ class Admin */ static private function action_skindeleteconfirm() { - global $member, $CONF, $manager; - - $skinid = intRequestVar('skinid'); + global $member, $CONF; $member->isAdmin() or self::disallow(); + $skinid = intRequestVar('skinid'); + // don't allow default skin to be deleted if ( $skinid == $CONF['BaseSkin'] ) { @@ -3948,21 +3819,7 @@ class Admin return; } - $data = array('skinid' => $skinid); - $manager->notify('PreDeleteSkin', $data); - - // 1. delete description - $query = "DELETE FROM %s WHERE sdnumber=%d;"; - $query = sprintf($query, sql_table('skin_desc'), (integer) $skinid); - DB::execute($query); - - // 2. delete parts - $query = "DELETE FROM %s WHERE sdesc=%d;"; - $query = sprintf($query, sql_table('skin'), (integer) $skinid); - DB::execute($query); - - $data = array('skinid' => $skinid); - $manager->notify('PostDeleteSkin', $data); + self::skindeleteconfirm($skinid); self::action_skinoverview(); return; @@ -3976,7 +3833,7 @@ class Admin */ static private function action_skinremovetype() { - global $member, $manager, $CONF; + global $member, $CONF; $member->isAdmin() or self::disallow(); @@ -3989,14 +3846,6 @@ class Admin return; } - // don't allow default skinparts to be deleted - /* TODO: this array should be retrieved from Action class */ - if ( in_array($skintype, array('index', 'item', 'archivelist', 'archive', 'search', 'error', 'member', 'imagepopup')) ) - { - self::error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); - return; - } - self::$skin->parse('skinremovetype'); return; } @@ -4009,47 +3858,24 @@ class Admin */ static private function action_skinremovetypeconfirm() { - global $member, $CONF, $manager; + global $member; $member->isAdmin() or self::disallow(); $skinid = intRequestVar('skinid'); $skintype = requestVar('type'); - if ( !isValidShortName($skintype) ) - { - self::error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); - return; - } - - // don't allow default skinparts to be deleted - /* TODO: this array should be retrieved from Action class */ - if ( in_array($skintype, array('index', 'item', 'archivelist', 'archive', 'search', 'error', 'member', 'imagepopup')) ) + $error = self::skinremovetypeconfirm($skinid, $skintype); + if ( $error ) { - self::error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); + self::error($error); return; } - $data = array( - 'skinid' => $skinid, - 'skintype' => $skintype - ); - $manager->notify('PreDeleteSkinPart', $data); - // delete part - $query = "DELETE FROM %s WHERE sdesc=%d AND stype=%s;"; - $query = sprintf($query, sql_table('skin'), (integer) $skinid, DB::quoteValue($skintype) ); - DB::execute($query); - - $data = array( - 'skinid' => $skinid, - 'skintype' => $skintype - ); - $manager->notify('PostDeleteSkinPart', $data); - self::action_skinedit(); return; } - + /** * Admin::action_skinclone() * @@ -4058,74 +3884,19 @@ class Admin */ static private function action_skinclone() { - global $manager, $member; + global $member; $member->isAdmin() or self::disallow(); $skinid = intRequestVar('skinid'); - // 1. read skin to clone - $skin =& $manager->getSkin($skinid); - - $name = "{$skin->getName()}_clone"; - - // if a skin with that name already exists: - if ( Skin::exists($name) ) - { - $i = 1; - while ( Skin::exists($name . $i) ) - { - $i++; - } - $name .= $i; - } - - // 2. create skin desc - $newid = Skin::createNew( - $name, - $skin->getDescription(), - $skin->getContentType(), - $skin->getIncludeMode(), - $skin->getIncludePrefix() - ); - - // 3. clone - $query = "SELECT stype FROM %s WHERE sdesc=%d;"; - $query = sprintf($query, sql_table('skin'), (integer) $skinid); - - $res = DB::getResult($query); - foreach ( $res as $row ) - { - self::skinclonetype($skin, $newid, $row['stype']); - } + self::skinclone($skinid); self::action_skinoverview(); return; } /** - * Admin::skinclonetype() - * - * @param String $skin Skin object - * @param Integer $newid ID for this clone - * @param String $type type of skin - * @return Void - */ - static private function skinclonetype($skin, $newid, $type) - { - $newid = intval($newid); - $content = $skin->getContentFromDB($type); - - if ( $content ) - { - $query = "INSERT INTO %s (sdesc, scontent, stype) VALUES (%d, %s, %s)"; - $query = sprintf($query, sql_table('skin'), (integer) $newid, DB::quoteValue($content), DB::quoteValue($type)); - DB::execute($query); - } - return; - } - - /** * Admin::action_adminskinoverview() * * @param void @@ -4133,7 +3904,7 @@ class Admin */ static private function action_adminskinoverview() { - global $member, $manager; + global $member; $member->isAdmin() or self::disallow(); @@ -4150,7 +3921,9 @@ class Admin static private function action_adminskinnew() { global $member; + $member->isAdmin() or self::disallow(); + $name = trim(postVar('name')); $desc = trim(postVar('desc')); @@ -4169,8 +3942,9 @@ class Admin self::error(_ERROR_DUPSKINNAME); return; } - /* TODO: $newId is not reused... */ - $newId = Skin::createNew($name, $desc); + + Skin::createNew($name, $desc); + self::action_adminskinoverview(); return; } @@ -4183,10 +3957,12 @@ class Admin */ static private function action_adminskinedit() { - global $member, $manager; + global $member; $member->isAdmin() or self::disallow(); + self::$skin->parse('adminskinedit'); + return; } @@ -4198,41 +3974,19 @@ class Admin */ static private function action_adminskineditgeneral() { - global $manager, $member; + global $member; $skinid = intRequestVar('skinid'); $member->isAdmin() or self::disallow(); - $name = postVar('name'); - $desc = postVar('desc'); - $type = postVar('type'); - $inc_mode = postVar('inc_mode'); - $inc_prefix = postVar('inc_prefix'); - - $skin =& $manager->getSkin($skinid, 'AdminActions', 'AdminSkin'); - - // 1. Some checks - if ( !isValidSkinName($name) ) - { - self::error(_ERROR_BADSKINNAME); - return; - } - if ( ($skin->getName() != $name) && Skin::exists($name) ) + $error = self::skineditgeneral($skinid, 'AdminActions'); + if ( $error ) { - self::error(_ERROR_DUPSKINNAME); + self::error($error); return; } - if ( !$type ) - { - $type = 'text/html'; - } - if ( !$inc_mode ) - { - $inc_mode = 'normal'; - } - // 2. Update description - $skin->updateGeneralInfo($name, $desc, $type, $inc_mode, $inc_prefix); + self::action_adminskinedit(); return; } @@ -4245,7 +3999,7 @@ class Admin */ static private function action_adminskinedittype($msg = '') { - global $member, $manager; + global $member; $member->isAdmin() or self::disallow(); @@ -4285,6 +4039,7 @@ class Admin $skin =& $manager->getSkin($skinid, 'AdminActions', 'AdminSkin'); $skin->update($type, $content); + self::action_adminskinedittype(_SKIN_UPDATED); return; } @@ -4297,11 +4052,33 @@ class Admin */ static private function action_adminskindelete() { - global $member, $manager, $CONF; + global $CONF, $member; + $member->isAdmin() or self::disallow(); - /* TODO: needless variable $skinid... */ $skinid = intRequestVar('skinid'); + + // don't allow default skin to be deleted + if ( $skinid == $CONF['AdminSkin'] || $skinid == $CONF['BookmarkletSkin'] ) + { + self::error(_ERROR_DEFAULTSKIN); + return; + } + + /* don't allow if someone use it as a default*/ + $query = 'SELECT * FROM %s WHERE madminskin = %d or mbkmklt = %d;'; + $res = DB::getResult(sprintf($query, sql_table('member'), $skinid, $skinid)); + + $members = array(); + while ( $row = $res->fetch() ) { + $members[] = $row['mrealname']; + } + if ( count($members) ) + { + self::error(_ERROR_SKINDEFDELETE . implode(' ' . _AND . ' ', $members)); + return; + } + self::$skin->parse('adminskindelete'); return; } @@ -4314,25 +4091,24 @@ class Admin */ static private function action_adminskindeleteconfirm() { - global $member, $CONF, $manager; + global $member, $CONF; $member->isAdmin() or self::disallow(); + $skinid = intRequestVar('skinid'); // don't allow default skin to be deleted - if ( $skinid == $CONF['AdminSkin'] ) + if ( $skinid == $CONF['AdminSkin'] || $skinid == $CONF['BookmarkletSkin'] ) { self::error(_ERROR_DEFAULTSKIN); return; } - /* - * TODO: NOT Implemented - * don't allow deletion of default skins for members - */ - $query = 'SELECT * FROM %s WHERE madminskin = %d or mbkmklt = %d'; - $res = DB::getResult(sprintf($query, sql_table('member'), $skinid, $skinid)); - $members = array(); + /* don't allow if someone use it as a default*/ + $query = 'SELECT * FROM %s WHERE madminskin = %d or mbkmklt = %d;'; + $res = DB::getResult(sprintf($query, sql_table('member'), $skinid, $skinid)); + + $members = array(); while ( $row = $res->fetch() ) { $members[] = $row['mrealname']; } @@ -4342,20 +4118,8 @@ class Admin return; } - $manager->notify('PreDeleteAdminSkin', array('skinid' => (integer) $skinid)); - - // 1. delete description - $query = "DELETE FROM %s WHERE sdnumber=%d;"; - $query = sprintf($query, sql_table('skin_desc'), (integer) $skinid); - DB::execute($query); - - // 2. delete parts - $query = "DELETE FROM %s WHERE sdesc=%d;"; - $query = sprintf($query, sql_table('skin'), (integer) $skinid); + self::skindeleteconfirm($skinid); - DB::execute($query); - - $manager->notify('PostDeleteAdminSkin', array('skinid' => (integer) $skinid)); self::action_adminskinoverview(); return; } @@ -4368,12 +4132,12 @@ class Admin */ static private function action_adminskinremovetype() { - global $member, $manager, $CONF; + global $member, $CONF; $member->isAdmin() or self::disallow(); - $skinid = intRequestVar('skinid'); - $skintype = requestVar('type'); + $skinid = intRequestVar('skinid'); + $skintype = requestVar('type'); if ( !isValidShortName($skintype) ) { @@ -4393,36 +4157,20 @@ class Admin */ static private function action_adminskinremovetypeconfirm() { - global $member, $CONF, $manager; + global $member; $member->isAdmin() or self::disallow(); - $skinid = intRequestVar('skinid'); - $skintype = requestVar('type'); + $skinid = intRequestVar('skinid'); + $skintype = requestVar('type'); - if ( !isValidShortName($skintype) ) + $error = self::skinremovetypeconfirm($skinid, $skintype); + if ( $error ) { - self::error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); + self::error($error); return; } - $data =array( - 'skinid' => $skinid, - 'skintype' => $skintype - ); - $manager->notify('PreDeleteAdminSkinPart', $data); - - // delete part - $query = 'DELETE FROM %s WHERE sdesc = %d AND stype = %s ;'; - $query = sprintf($query, sql_table('skin'), (integer) $skinid, DB::quoteValue($skintype) ); - DB::execute($query); - - $data = array( - 'skinid' => $skinid, - 'skintype' => $skintype - ); - $manager->notify('PostDeleteAdminSkinPart', $data); - self::action_adminskinedit(); return; } @@ -4435,71 +4183,19 @@ class Admin */ static private function action_adminskinclone() { - global $manager, $member; + global $member; $member->isAdmin() or self::disallow(); $skinid = intRequestVar('skinid'); - // 1. read skin to clone - $skin =& $manager->getSkin($skinid, 'AdminActions', 'AdminSkin'); - $name = "{$skin->getName()}_clone"; + self::skinclone($skinid, 'AdminActions'); - // if a skin with that name already exists: - if ( Skin::exists($name) ) - { - $i = 1; - while ( Skin::exists($name . $i) ) - { - $i++; - } - $name .= $i; - } - - // 2. create skin desc - $newid = Skin::createNew( - $name, - $skin->getDescription(), - $skin->getContentType(), - $skin->getIncludeMode(), - $skin->getIncludePrefix() - ); - - // 3. clone - $query = "SELECT stype FROM %s WHERE sdesc=%d;"; - $query = sprintf($query, sql_table('skin'), (integer) $skinid); - - $res = DB::getResult($query); - foreach ( $res as $row ) - { - self::skinclonetype($skin, $newid, $row['stype']); - } self::action_adminskinoverview(); return; } /** - * Admin::adminskinclonetype() - * - * @param string $skin an instance of Skin class - * @param integer $newid ID for new skin - * @param string $type skin type - * @return void - */ - static private function adminskinclonetype($skin, $newid, $type) - { - $content = $skin->getContentFromDB($type); - - if ( $content ) - { - $query = "INSERT INTO %s (sdesc, scontent, stype) VALUES (%d, %s, %s)"; - $query = sprintf($query, sql_table('skin'), (integer) $newid, DB::quoteValue($content), DB::quoteValue($type)); - DB::execute($query); - } - return; - } - - /** * Admin::action_adminskinieoverview() * * @param void @@ -4507,19 +4203,15 @@ class Admin */ static private function action_adminskinieoverview() { - global $member, $DIR_LIBS, $manager; + global $member; $member->isAdmin() or self::disallow(); - // load skinie class - include_once($DIR_LIBS . 'skinie.php'); - self::$skin->parse('adminskinieoverview'); return; } /** - * FIXME: DUPLICATION, NO NEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEED!!!!!! * Admin::action_adminskinieimport() * * @param void @@ -4527,56 +4219,20 @@ class Admin */ static private function action_adminskinieimport() { - global $DIR_LIBS, $DIR_SKINS, $manager, $member; + global $member; $member->isAdmin() or self::disallow(); - // load skinie class - include_once($DIR_LIBS . 'skinie.php'); - - $skinFileRaw = postVar('skinfile'); - $mode = postVar('mode'); - - $importer = new SKINIMPORT(); - - // get full filename - if ( $mode == 'file' ) - { - $skinFile = "{$DIR_SKINS}admin/{$skinFileRaw}/skinbackup.xml"; - - // backwards compatibilty (in v2.0, exports were saved as skindata.xml) - if ( !file_exists($skinFile) ) - { - $skinFile = "{$DIR_SKINS}admin/{$skinFileRaw}/skindata.xml"; - } - } - else - { - $skinFile = $skinFileRaw; - } + $skinFileRaw = postVar('skinfile'); + $mode = postVar('mode'); - // read only metadata - $error = $importer->readFile($skinFile, 1); + $error = self::skinieimport($mode, $skinFileRaw); if ( $error ) { self::error($error); return; } - /* TODO: we should consider to use the other way instead of this */ - $_REQUEST['skininfo'] = $importer->getInfo(); - $_REQUEST['skinnames'] = $importer->getSkinNames(); - $_REQUEST['tpltnames'] = $importer->getTemplateNames(); - - // clashes - $skinNameClashes = $importer->checkSkinNameClashes(); - $templateNameClashes = $importer->checkTemplateNameClashes(); - $hasNameClashes = (count($skinNameClashes) > 0) || (count($templateNameClashes) > 0); - /* TODO: we should consider to use the other way instead of this */ - $_REQUEST['skinclashes'] = $skinNameClashes; - $_REQUEST['tpltclashes'] = $templateNameClashes; - $_REQUEST['nameclashes'] = $hasNameClashes ? 1 : 0; - if ( !is_object(self::$skin) ) { self::action_adminskiniedoimport(); @@ -4589,7 +4245,6 @@ class Admin } /** - * FIXME: DUPLICATION, NO NEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEED!!!!!! * Admin::action_adminskiniedoimport() * * @param void @@ -4597,53 +4252,21 @@ class Admin */ static private function action_adminskiniedoimport() { - global $DIR_LIBS, $DIR_SKINS, $manager, $member; + global $DIR_SKINS, $member; $member->isAdmin() or self::disallow(); - // load skinie class - include_once($DIR_LIBS . 'skinie.php'); - - $skinFileRaw = postVar('skinfile'); - $mode = postVar('mode'); + $mode = postVar('mode'); + $skinFileRaw = postVar('skinfile'); $allowOverwrite = intPostVar('overwrite'); - // get full filename - if ( $mode == 'file' ) - { - $skinFile = "{$DIR_SKINS}admin/{$skinFileRaw}/skinbackup.xml"; - // backwards compatibilty (in v2.0, exports were saved as skindata.xml) - if ( !file_exists($skinFile) ) - { - $skinFile = "{$DIR_SKINS}admin/{$skinFileRaw}/skindata.xml"; - } - } - else - { - $skinFile = $skinFileRaw; - } - - $importer = new SKINIMPORT(); - - $error = $importer->readFile($skinFile); - if ( $error ) - { - self::error($error); - return; - } - - $error = $importer->writeToDatabase($allowOverwrite); + $error = self::skiniedoimport($mode, $skinFileRaw, $allowOverwrite); if ( $error ) { self::error($error); return; } - /* TODO: we should consider to use the other way instead of this */ - $_REQUEST['skininfo'] = $importer->getInfo(); - $_REQUEST['skinnames'] = $importer->getSkinNames(); - $_REQUEST['tpltnames'] = $importer->getTemplateNames(); - if ( !is_object(self::$skin) ) { global $DIR_SKINS; @@ -4671,38 +4294,17 @@ class Admin */ static private function action_adminskinieexport() { - global $member, $DIR_PLUGINS; + global $member; $member->isAdmin() or self::disallow(); // load skinie class $aSkins = requestIntArray('skin'); - if (!is_array($aSkins)) { - $aSkins = array(); - } - $skinList = array_keys($aSkins); - $aTemplates = requestIntArray('template'); - if (!is_array($aTemplates)) - { - $aTemplates = array(); - } - $templateList = array_keys($aTemplates); - $info = postVar('info'); - include_libs('skinie.php'); - $exporter = new SkinExport(); - foreach ( $skinList as $skinId ) - { - $exporter->addSkin($skinId); - } - foreach ( $templateList as $templateId ) - { - $exporter->addTemplate($templateId); - } - $exporter->setInfo($info); - $exporter->export(); + self::skinieexport($aSkins, $aTemplates, $info); + return; } @@ -5650,6 +5252,327 @@ class Admin } /** + * Admin::skineditgeneral() + * + * @param integer $skinid + * @param string $handler + * @return string empty or message if failed + */ + static private function skineditgeneral($skinid, $handler='') + { + $name = postVar('name'); + $desc = postVar('desc'); + $type = postVar('type'); + $inc_mode = postVar('inc_mode'); + $inc_prefix = postVar('inc_prefix'); + + $skin =& $manager->getSkin($skinid, $handler); + + // 1. Some checks + if ( !isValidSkinName($name) ) + { + return _ERROR_BADSKINNAME; + } + + if ( ($skin->getName() != $name) && SKIN::exists($name) ) + { + return _ERROR_DUPSKINNAME; + } + + if ( !$type ) + { + $type = 'text/html'; + } + + if ( !$inc_mode ) + { + $inc_mode = 'normal'; + } + + // 2. Update description + $skin->updateGeneralInfo($name, $desc, $type, $inc_mode, $inc_prefix); + + return ''; + } + /** + * Admin::skindeleteconfirm() + * + * @param integer $skinid + * @return void + */ + static private function skindeleteconfirm($skinid) + { + global $manager; + + if ( !preg_match('#^admin/#', self::$action) ) + { + $event_identifier = 'Skin'; + } + else + { + $event_identifier = 'AdminSkin'; + } + + $manager->notify("PreDelete{$event_identifier}", array('skinid' => $skinid)); + + // 1. delete description + $query = "DELETE FROM %s WHERE sdnumber=%d;"; + $query = sprintf($query, sql_table('skin_desc'), (integer) $skinid); + DB::execute($query); + + // 2. delete parts + $query = "DELETE FROM %s WHERE sdesc=%d;"; + $query = sprintf($query, sql_table('skin'), (integer) $skinid); + DB::execute($query); + + $manager->notify("PostDelete{$event_identifier}", array('skinid' => $skinid)); + + return; + } + + /** + * Admin::skinremovetypeconfirm() + * + * @param integer $skinid + * @param string $skintype + * @return string empty or message if failed + */ + static private function skinremovetypeconfirm($skinid, $skintype) + { + if ( !preg_match('#^admin/#', self::$action) ) + { + $event_identifier = 'Skin'; + } + else + { + $event_identifier = 'AdminSkin'; + } + + if ( !isValidShortName($skintype) ) + { + return _ERROR_SKIN_PARTS_SPECIAL_DELETE; + } + + $data =array( + 'skinid' => $skinid, + 'skintype' => $skintype + ); + $manager->notify("PreDelete{$event_identifier}Part", $data); + + // delete part + $query = 'DELETE FROM %s WHERE sdesc = %d AND stype = %s;'; + $query = sprintf($query, sql_table('skin'), (integer) $skinid, DB::quoteValue($skintype) ); + DB::execute($query); + + $data = array( + 'skinid' => $skinid, + 'skintype' => $skintype + ); + $manager->notify("PostDelete{$event_identifier}Part", $data); + + return ''; + } + + /** + * Admin::skinclone() + * + * @param integer $skinid + * @param string $handler + * @return void + */ + static private function skinclone($skinid, $handler='') + { + global $manager; + + // 1. read skin to clone + $skin =& $manager->getSkin($skinid, $handler); + $name = "{$skin->getName()}_clone"; + + // if a skin with that name already exists: + if ( Skin::exists($name) ) + { + $i = 1; + while ( Skin::exists($name . $i) ) + { + $i++; + } + $name .= $i; + } + + // 2. create skin desc + $newid = Skin::createNew( + $name, + $skin->getDescription(), + $skin->getContentType(), + $skin->getIncludeMode(), + $skin->getIncludePrefix() + ); + + // 3. clone + $query = "SELECT stype FROM %s WHERE sdesc=%d;"; + $query = sprintf($query, sql_table('skin'), (integer) $skinid); + + $res = DB::getResult($query); + foreach ( $res as $row ) + { + $content = $skin->getContentFromDB($row['stype']); + if ( $content ) + { + $query = "INSERT INTO %s (sdesc, scontent, stype) VALUES (%d, %s, %s)"; + $query = sprintf($query, sql_table('skin'), (integer) $newid, DB::quoteValue($content), DB::quoteValue($type)); + DB::execute($query); + } + } + return; + } + + /** + * Admin::skinieimport() + * + * @param string $mode + * @param string $skinFileRaw + * @return string empty or message if failed + */ + static private function skinieimport($mode, $skinFileRaw) + { + global $DIR_LIBS, $DIR_SKINS; + + // load skinie class + include_once($DIR_LIBS . 'skinie.php'); + + $importer = new SkinImport(); + + // get full filename + if ( $mode == 'file' ) + { + $skinFile = $DIR_SKINS . $skinFileRaw . '/skinbackup.xml'; + } + else + { + $skinFile = $skinFileRaw; + } + + // read only metadata + $error = $importer->readFile($skinFile, 1); + if ( $error ) + { + unset($importer); + return $error; + } + + /* TODO: we should consider to use the other way insterad of this */ + $_REQUEST['skininfo'] = $importer->getInfo(); + $_REQUEST['skinnames'] = $importer->getSkinNames(); + $_REQUEST['tpltnames'] = $importer->getTemplateNames(); + + // clashes + $skinNameClashes = $importer->checkSkinNameClashes(); + $templateNameClashes = $importer->checkTemplateNameClashes(); + $hasNameClashes = (count($skinNameClashes) > 0) || (count($templateNameClashes) > 0); + + /* TODO: we should consider to use the other way insterad of this */ + $_REQUEST['skinclashes'] = $skinNameClashes; + $_REQUEST['tpltclashes'] = $templateNameClashes; + $_REQUEST['nameclashes'] = $hasNameClashes ? 1 : 0; + + unset($importer); + return ''; + } + + /** + * Admin::skinieedoimport() + * + * @param string $mode + * @param string $skinFileRaw + * @param boolean $allowOverwrite + * @return string empty or message if failed + */ + static private function skiniedoimport($mode, $skinFileRaw, $allowOverwrite) + { + global $DIR_LIBS, $DIR_SKINS; + + // load skinie class + include_once($DIR_LIBS . 'skinie.php'); + + $importer = new SkinImport(); + + // get full filename + if ( $mode == 'file' ) + { + $skinFile = $DIR_SKINS . $skinFileRaw . '/skinbackup.xml'; + } + else + { + $skinFile = $skinFileRaw; + } + + $error = $importer->readFile($skinFile); + if ( $error ) + { + unset($importer); + return $error; + } + + $error = $importer->writeToDatabase($allowOverwrite); + if ( $error ) + { + unset($importer); + return $error; + } + + /* TODO: we should consider to use the other way insterad of this */ + $_REQUEST['skininfo'] = $importer->getInfo(); + $_REQUEST['skinnames'] = $importer->getSkinNames(); + $_REQUEST['tpltnames'] = $importer->getTemplateNames(); + + unset($importer); + return ''; + } + + /** + * Admin::skinieexport() + * + * @param array $aSkins + * @param array $aTemplates + * @param string $info + * @return void + */ + static private function skinieexport($aSkins, $aTemplates, $info) + { + global $DIR_LIBS; + + // load skinie class + include_once($DIR_LIBS . 'skinie.php'); + + if ( !is_array($aSkins) ) + { + $aSkins = array(); + } + + if (!is_array($aTemplates)) + { + $aTemplates = array(); + } + + $skinList = array_keys($aSkins); + $templateList = array_keys($aTemplates); + + $exporter = new SkinExport(); + foreach ( $skinList as $skinId ) + { + $exporter->addSkin($skinId); + } + foreach ( $templateList as $templateId ) + { + $exporter->addTemplate($templateId); + } + $exporter->setInfo($info); + $exporter->export(); + + return; + } + + /** * Admin::action_parseSpecialskin() * * @param void @@ -5778,9 +5701,9 @@ class Admin $member->isAdmin() or self::disallow(); include_once($DIR_LIBS . 'Skinie.php'); - $skinFileRaw = postVar('skinfile'); - $mode = postVar('mode'); - $allowOverwrite = intPostVar('overwrite'); + $skinFileRaw = postVar('skinfile'); + $mode = postVar('mode'); + $allowOverwrite = intPostVar('overwrite'); if ( $mode == 'file' ) { diff --git a/nucleus/libs/AdminActions.php b/nucleus/libs/AdminActions.php index 4977d78..c3f2da1 100644 --- a/nucleus/libs/AdminActions.php +++ b/nucleus/libs/AdminActions.php @@ -1974,7 +1974,7 @@ class AdminActions extends BaseActions } $template['tabindex'] = 10; - $template['skinid'] = $skin->getID(); + $template['skinid'] = intRequestVar('skinid'); $template['skinname'] = $skin->getName(); $this->parser->parse(showlist($normal_skintype, 'list_normalskinlist', $template, $template_name)); @@ -4033,7 +4033,7 @@ class AdminActions extends BaseActions { include_libs('skinie.php'); } - + if ( !preg_match('#^admin#', $this->skintype) && $this->skintype != 'importAdmin' ) { $skindir = $DIR_SKINS; @@ -4046,8 +4046,15 @@ class AdminActions extends BaseActions $candidates = SkinImport::searchForCandidates($skindir); foreach ( $candidates as $skinname => $skinfile ) { - $skinfile = Entity::hsc($skinfile); $skinname = Entity::hsc($skinname); + if ( !preg_match('#^admin#', $this->skintype) && $this->skintype != 'importAdmin' ) + { + $skinfile = Entity::hsc($skinfile); + } + else + { + $skinfile = Entity::hsc("admin/$skinfile"); + } echo "\n"; }