From: sakamocchi Date: Mon, 17 Sep 2012 11:10:23 +0000 (+0900) Subject: Merge branch 'skinnable-master' X-Git-Url: http://git.osdn.net/view?p=nucleus-jp%2Fnucleus-next.git;a=commitdiff_plain;h=c90b0980cfa3e79cd4bc7eed551a64a5e2b02a5c;hp=fe4e862f6b23596d657c5228588785dfe537fb8f Merge branch 'skinnable-master' Conflicts: action.php index.php install/index.php nucleus/bookmarklet.php nucleus/convert/functions.inc.php nucleus/convert/wordpress.php nucleus/index.php nucleus/libs/ACTION.php nucleus/libs/ACTIONLOG.php nucleus/libs/ACTIONS.php nucleus/libs/ADMIN.php nucleus/libs/BAN.php nucleus/libs/BLOG.php nucleus/libs/BODYACTIONS.php nucleus/libs/BaseActions.php nucleus/libs/COMMENT.php nucleus/libs/COMMENTACTIONS.php nucleus/libs/COMMENTS.php nucleus/libs/ITEM.php nucleus/libs/ITEMACTIONS.php nucleus/libs/KARMA.php nucleus/libs/MANAGER.php nucleus/libs/MEDIA.php nucleus/libs/MEMBER.php nucleus/libs/NOTIFICATION.php nucleus/libs/PAGEFACTORY.php nucleus/libs/PARSER.php nucleus/libs/PLUGIN.php nucleus/libs/PLUGINADMIN.php nucleus/libs/SEARCH.php nucleus/libs/SKIN.php nucleus/libs/TEMPLATE.php nucleus/libs/backup.php nucleus/libs/globalfunctions.php nucleus/libs/i18n.php nucleus/libs/include/admin-add.template nucleus/libs/include/admin-edit.template nucleus/libs/include/bookmarklet-add.template nucleus/libs/include/bookmarklet-edit.template nucleus/libs/showlist.php nucleus/libs/skinie.php nucleus/libs/sql/DB.php nucleus/libs/sql/MYSQLPDO.php nucleus/libs/sql/sql.php nucleus/locales/bg_Cyrl_BG.ISO-8859-5.php nucleus/locales/bg_Cyrl_BG.UTF-8.php nucleus/locales/ca_Latn_ES.ISO-8859-1.php nucleus/locales/ca_Latn_ES.UTF-8.php nucleus/locales/cs_Latn_CZ.UTF-8.php nucleus/locales/cs_Latn_CZ.WINDOWS-1250.php nucleus/locales/de_Latn_DE.ISO-8859-1.php nucleus/locales/de_Latn_DE.UTF-8.php nucleus/locales/en_Latn_US.ISO-8859-1.php nucleus/locales/en_Latn_US.UTF-8.php nucleus/locales/es_Latn_ES.ISO-8859-1.php nucleus/locales/es_Latn_ES.UTF-8.php nucleus/locales/fa_Arab_IR.UTF-8.php nucleus/locales/fi_Latn_FI.ISO-8859-1.php nucleus/locales/fi_Latn_FI.UTF-8.php nucleus/locales/fr_Latn_FR.ISO-8859-15.php nucleus/locales/fr_Latn_FR.UTF-8.php nucleus/locales/gl_Latn_ES.ISO-8859-1.php nucleus/locales/gl_Latn_ES.UTF-8.php nucleus/locales/hr_Latn_HR.UTF-8.php nucleus/locales/hr_Latn_HR.WINDOWS-1250.php nucleus/locales/hu_Latn_HU.ISO-8859-2.php nucleus/locales/hu_Latn_HU.UTF-8.php nucleus/locales/id_Latn_ID.ISO-8859-1.php nucleus/locales/id_Latn_ID.UTF-8.php nucleus/locales/it_Latn_IT.ISO-8859-1.php nucleus/locales/it_Latn_IT.UTF-8.php nucleus/locales/ja_Jpan_JP.EUC-JP.php nucleus/locales/ja_Jpan_JP.UTF-8.php nucleus/locales/ko_Kore_KR.EUC-KR.php nucleus/locales/ko_Kore_KR.UTF-8.php nucleus/locales/ku_Arab_TR.UTF-8.php nucleus/locales/lv_Latn_LV.ISO-8859-13.php nucleus/locales/lv_Latn_LV.UTF-8.php nucleus/locales/nl_Latn_NL.ISO-8859-15.php nucleus/locales/nl_Latn_NL.UTF-8.php nucleus/locales/pl_Latn_PL.UTF-8.php nucleus/locales/pt_Latn_BR.ISO-8859-1.php nucleus/locales/pt_Latn_BR.UTF-8.php nucleus/locales/ro_Latn_RO.ISO-8859-1.php nucleus/locales/ro_Latn_RO.UTF-8.php nucleus/locales/ru_Cyrl_RU.UTF-8.php nucleus/locales/ru_Cyrl_RU.WINDOWS-1251.php nucleus/locales/sk_Latn_SK.ISO-8859-2.php nucleus/locales/sk_Latn_SK.UTF-8.php nucleus/locales/sr_Cyrl_RS.UTF-8.php nucleus/locales/ur_Arab_PK.UTF-8.php nucleus/locales/vi_Latn_VN.UTF-8.php nucleus/locales/zh_Hans_CN.GB2312.php nucleus/locales/zh_Hans_CN.UTF-8.php nucleus/locales/zh_Hant_TW.UTF-8.php nucleus/media.php nucleus/plugins/NP_SecurityEnforcer.php nucleus/plugins/NP_SkinFiles.php nucleus/upgrades/upgrade.functions.php nucleus/upgrades/upgrade4.0.php nucleus/xmlrpc/server.php skins/admin/bookmarklet/styles/addedit.css skins/default/nicetitle.js --- diff --git a/.buildpath b/.buildpath new file mode 100644 index 0000000..8bcb4b5 --- /dev/null +++ b/.buildpath @@ -0,0 +1,5 @@ + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..7e1a46c --- /dev/null +++ b/.project @@ -0,0 +1,22 @@ + + + nucleus-next + + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.dltk.core.scriptbuilder + + + + + + org.eclipse.php.core.PHPNature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..730e5d2 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,24 @@ +eclipse.preferences.version=1 +encoding//nucleus/locales/bg_Cyrl_BG.ISO-8859-5.php=ISO-8859-5 +encoding//nucleus/locales/ca_Latn_ES.ISO-8859-1.php=ISO-8859-1 +encoding//nucleus/locales/cs_Latn_CZ.WINDOWS-1250.php=WINDOWS-1250 +encoding//nucleus/locales/de_Latn_DE.ISO-8859-1.php=ISO-8859-1 +encoding//nucleus/locales/el_Grek_GR.WINDOWS-1253.php=WINDOWS-1253 +encoding//nucleus/locales/en_Latn_US.ISO-8859-1.php=ISO-8859-1 +encoding//nucleus/locales/es_Latn_ES.ISO-8859-1.php=ISO-8859-1 +encoding//nucleus/locales/fi_Latn_FI.ISO-8859-1.php=ISO-8859-1 +encoding//nucleus/locales/fr_Latn_FR.ISO-8859-15.php=ISO-8859-15 +encoding//nucleus/locales/gl_Latn_ES.ISO-8859-1.php=ISO-8859-1 +encoding//nucleus/locales/hr_Latn_HR.WINDOWS-1250.php=WINDOWS-1250 +encoding//nucleus/locales/hu_Latn_HU.ISO-8859-2.php=ISO-8859-2 +encoding//nucleus/locales/id_Latn_ID.ISO-8859-1.php=ISO-8859-1 +encoding//nucleus/locales/it_Latn_IT.ISO-8859-1.php=ISO-8859-1 +encoding//nucleus/locales/ja_Jpan_JP.EUC-JP.php=EUC-JP +encoding//nucleus/locales/ko_Kore_KR.EUC-KR.php=EUC-KR +encoding//nucleus/locales/lv_Latn_LV.ISO-8859-13.php=ISO-8859-13 +encoding//nucleus/locales/nl_Latn_NL.ISO-8859-15.php=ISO-8859-15 +encoding//nucleus/locales/pt_Latn_BR.ISO-8859-1.php=ISO-8859-1 +encoding//nucleus/locales/ro_Latn_RO.ISO-8859-1.php=ISO-8859-1 +encoding//nucleus/locales/ru_Cyrl_RU.WINDOWS-1251.php=WINDOWS-1251 +encoding//nucleus/locales/sk_Latn_SK.ISO-8859-2.php=ISO-8859-2 +encoding//nucleus/locales/zh_Hans_CN.GB2312.php=GB2312 diff --git a/.settings/org.eclipse.php.core.prefs b/.settings/org.eclipse.php.core.prefs new file mode 100644 index 0000000..5f7d896 --- /dev/null +++ b/.settings/org.eclipse.php.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +include_path= diff --git a/action.php b/action.php index 6cf854a..33529ec 100644 --- a/action.php +++ b/action.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD doAction($action); + +if ( $errorInfo ) +{ + $skin =& $manager->getSkin($errorInfo['skinid']); + doError($errorInfo['message'], $skin); +} + +>>>>>>> skinnable-master exit; \ No newline at end of file diff --git a/atom.php b/atom.php index 5c013e7..9caf5a2 100644 --- a/atom.php +++ b/atom.php @@ -1,49 +1,49 @@ - - diff --git a/build/testcases/NP_ImageCreateThumbnail.php b/build/testcases/NP_ImageCreateThumbnail.php index e7cf179..a40a2c3 100644 --- a/build/testcases/NP_ImageCreateThumbnail.php +++ b/build/testcases/NP_ImageCreateThumbnail.php @@ -1,135 +1,135 @@ -createOption ('thumbsize', 'Maximal width (landscape format) or height (portrait format) for Thumbnails', 'text', '150'); - } - - function unInstall() { - } - - function getEventList() { - return array('PostMediaUpload'); - } - - - function event_PostMediaUpload(&$data) { - - $collection = $data['collection']; - $mediadir = $data['mediadir']; - $filename = $data['filename']; - $fullpath = $mediadir.$filename; - - // evaluate the filetype from the filename - $filetype = strtolower(substr($filename, strpos($filename, ".")+1)); - - // filetype is jpeg - if ($filetype=='jpg' || $filetype=='jpeg') { - - $size = getimagesize($fullpath); - - $ratio = $size[1]/$size[0]; // ratio = height / width - - if ($ratio < 1) { - $new_height = $this->getOption('thumbsize') * $size[1]/$size[0]; - $new_width = $this->getOption('thumbsize'); - } - else { - $new_height = $this->getOption('thumbsize'); - $new_width = $this->getOption('thumbsize') * $size[0]/$size[1]; - } - - $image_orig = imagecreatefromjpeg($fullpath); - $image_new = imagecreatetruecolor($new_width, $new_height); - - imagecopyresampled($image_new, $image_orig, 0, 0, 0, 0, $new_width, $new_height, $size[0], $size[1]); - - $thumbfilename = substr($fullpath, 0, strpos($fullpath, ".")).'_thumb.'.$filetype; - - imagejpeg ($image_new , $thumbfilename); - - // clear the memory - imagedestroy($image_orig); - imagedestroy($image_new); - } - - // filetype is png - if ($filetype=='png') { - - $size = getimagesize($fullpath); - - $ratio = $size[1]/$size[0]; // ratio = height / width - - if ($ratio < 1) { - $new_height = $this->getOption('thumbsize') * $size[1]/$size[0]; - $new_width = $this->getOption('thumbsize'); - } - else { - $new_height = $this->getOption('thumbsize'); - $new_width = $this->getOption('thumbsize') * $size[0]/$size[1]; - } - - $image_orig = imagecreatefrompng($fullpath); - $image_new = imagecreatetruecolor($new_width, $new_height); - - imagecopyresampled($image_new, $image_orig, 0, 0, 0, 0, $new_width, $new_height, $size[0], $size[1]); - - $thumbfilename = substr($fullpath, 0, strpos($fullpath, ".")).'_thumb.'.$filetype; - - imagepng ($image_new , $thumbfilename); - - // clear the memory - imagedestroy($image_orig); - imagedestroy($image_new); - } - } -} - -?> +createOption ('thumbsize', 'Maximal width (landscape format) or height (portrait format) for Thumbnails', 'text', '150'); + } + + function unInstall() { + } + + function getEventList() { + return array('PostMediaUpload'); + } + + + function event_PostMediaUpload(&$data) { + + $collection = $data['collection']; + $mediadir = $data['mediadir']; + $filename = $data['filename']; + $fullpath = $mediadir.$filename; + + // evaluate the filetype from the filename + $filetype = strtolower(substr($filename, strpos($filename, ".")+1)); + + // filetype is jpeg + if ($filetype=='jpg' || $filetype=='jpeg') { + + $size = getimagesize($fullpath); + + $ratio = $size[1]/$size[0]; // ratio = height / width + + if ($ratio < 1) { + $new_height = $this->getOption('thumbsize') * $size[1]/$size[0]; + $new_width = $this->getOption('thumbsize'); + } + else { + $new_height = $this->getOption('thumbsize'); + $new_width = $this->getOption('thumbsize') * $size[0]/$size[1]; + } + + $image_orig = imagecreatefromjpeg($fullpath); + $image_new = imagecreatetruecolor($new_width, $new_height); + + imagecopyresampled($image_new, $image_orig, 0, 0, 0, 0, $new_width, $new_height, $size[0], $size[1]); + + $thumbfilename = substr($fullpath, 0, strpos($fullpath, ".")).'_thumb.'.$filetype; + + imagejpeg ($image_new , $thumbfilename); + + // clear the memory + imagedestroy($image_orig); + imagedestroy($image_new); + } + + // filetype is png + if ($filetype=='png') { + + $size = getimagesize($fullpath); + + $ratio = $size[1]/$size[0]; // ratio = height / width + + if ($ratio < 1) { + $new_height = $this->getOption('thumbsize') * $size[1]/$size[0]; + $new_width = $this->getOption('thumbsize'); + } + else { + $new_height = $this->getOption('thumbsize'); + $new_width = $this->getOption('thumbsize') * $size[0]/$size[1]; + } + + $image_orig = imagecreatefrompng($fullpath); + $image_new = imagecreatetruecolor($new_width, $new_height); + + imagecopyresampled($image_new, $image_orig, 0, 0, 0, 0, $new_width, $new_height, $size[0], $size[1]); + + $thumbfilename = substr($fullpath, 0, strpos($fullpath, ".")).'_thumb.'.$filetype; + + imagepng ($image_new , $thumbfilename); + + // clear the memory + imagedestroy($image_orig); + imagedestroy($image_new); + } + } +} + +?> diff --git a/build/testcases/NP_ImageLimitSize.php b/build/testcases/NP_ImageLimitSize.php index 44793c6..4cf8034 100644 --- a/build/testcases/NP_ImageLimitSize.php +++ b/build/testcases/NP_ImageLimitSize.php @@ -1,97 +1,96 @@ -createOption('maxwidth', 'Maximal width for images', 'text', '450'); - } - - function unInstall() { - } - - function getEventList() { - return array('PreMediaUpload'); - } - - function event_PreMediaUpload(&$data) { - - $collection = $data['collection']; - $uploadfile = $data['uploadfile']; - $filename = $data['filename']; - - // evaluate the filetype from the filename - $filetype = strtolower(substr($filename, strpos($filename, ".")+1)); - - // filetype is jpeg - if ($filetype=='jpg' || $filetype=='jpeg') { - - $size=getimagesize($data['uploadfile']); - - // size[0] is the image width - if ($size[0]>$this->getOption('maxwidth')) { - - $newheight = $this->getOption('maxwidth') * $size[1]/$size[0]; - $image_orig = imagecreatefromjpeg($uploadfile); - $image_new = imagecreatetruecolor($this->getOption('maxwidth'), $newheight); - - imagecopyresampled($image_new, $image_orig, 0, 0, 0, 0, $this->getOption('maxwidth'), $newheight, $size[0], $size[1]); - - imagejpeg ($image_new , $uploadfile); - - // clear the memory - imagedestroy($image_orig); - imagedestroy($image_new); - - } - } - - // filetype is png - if ($filetype=='png') { - - $size=getimagesize($data['uploadfile']); - - // size[0] is the image width - if ($size[0]>$this->getOption('maxwidth')) { - - $newheight = $this->getOption('maxwidth') * $size[1]/$size[0]; - $image_orig = imagecreatefrompng($uploadfile); - $image_new = imagecreatetruecolor($this->getOption('maxwidth'), $newheight); - - imagecopyresampled($image_new, $image_orig, 0, 0, 0, 0, $this->getOption('maxwidth'), $newheight, $size[0], $size[1]); - - imagepng ( $image_new , $uploadfile); - - // clear the memory - imagedestroy($image_orig); - imagedestroy($image_new); - - } - } - } -} - -?> +createOption('maxwidth', 'Maximal width for images', 'text', '450'); + } + + function unInstall() { + } + + function getEventList() { + return array('PreMediaUpload'); + } + + function event_PreMediaUpload(&$data) { + + $collection = $data['collection']; + $uploadfile = $data['uploadfile']; + $filename = $data['filename']; + + // evaluate the filetype from the filename + $filetype = strtolower(substr($filename, strpos($filename, ".")+1)); + + // filetype is jpeg + if ($filetype=='jpg' || $filetype=='jpeg') { + + $size=getimagesize($data['uploadfile']); + + // size[0] is the image width + if ($size[0]>$this->getOption('maxwidth')) { + + $newheight = $this->getOption('maxwidth') * $size[1]/$size[0]; + $image_orig = imagecreatefromjpeg($uploadfile); + $image_new = imagecreatetruecolor($this->getOption('maxwidth'), $newheight); + + imagecopyresampled($image_new, $image_orig, 0, 0, 0, 0, $this->getOption('maxwidth'), $newheight, $size[0], $size[1]); + + imagejpeg ($image_new , $uploadfile); + + // clear the memory + imagedestroy($image_orig); + imagedestroy($image_new); + + } + } + + // filetype is png + if ($filetype=='png') { + + $size=getimagesize($data['uploadfile']); + + // size[0] is the image width + if ($size[0]>$this->getOption('maxwidth')) { + + $newheight = $this->getOption('maxwidth') * $size[1]/$size[0]; + $image_orig = imagecreatefrompng($uploadfile); + $image_new = imagecreatetruecolor($this->getOption('maxwidth'), $newheight); + + imagecopyresampled($image_new, $image_orig, 0, 0, 0, 0, $this->getOption('maxwidth'), $newheight, $size[0], $size[1]); + + imagepng ( $image_new , $uploadfile); + + // clear the memory + imagedestroy($image_orig); + imagedestroy($image_new); + + } + } + } +} + +?> diff --git a/createaccount.html b/createaccount.html deleted file mode 100644 index a06792d..0000000 --- a/createaccount.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - - Create Member Account - - - -

Create Account

- -

Sorry, the URL of the Create Account Form has changed.

-

If you are not redirected automatically please use this link: Create Member Account.

-

Thank you. :-)

- - - diff --git a/createaccount.php b/createaccount.php index adcc5a4..0cc16dd 100644 --- a/createaccount.php +++ b/createaccount.php @@ -1,109 +1,34 @@ -\n"; -echo "\n"; -echo "\n"; -echo "Create Member Account\n"; -echo "\n"; -echo "\n"; -echo "\n"; -echo "

Create Account

\n"; - -// show form only if Visitors are allowed to create a Member Account -if ( $CONF['AllowMemberCreate'] == 1 ) -{ - $name = ''; - $realname =''; - $email = ''; - $url = ''; - - /* already submit */ - if ( array_key_exists('showform', $_POST) && $_POST['showform'] == 1 ) - { - if ( array_key_exists('name', $_POST) ) - { - $name = $_POST['name']; - } - if ( array_key_exists('realname', $_POST) ) - { - $realname = $_POST['realname']; - } - if ( array_key_exists('email', $_POST) ) - { - $email = $_POST['email']; - } - if ( array_key_exists('url', $_POST) ) - { - $url = $_POST['url']; - } - // after the from is sent it will be validated - // POST data will be added as value to treat the user with care (;-)) - $a = new Action(); - - $message = $a->createAccount(); - if ( $message != 1 ) - { - echo '

' . $message . "

\n"; - } - else - { - echo '

' . _MSG_ACTIVATION_SENT . "

\n"; - echo "

Return to {$CONF['SiteName']}

\n"; - echo "\n"; - echo "\n"; - exit; - } - } - - echo "
\n"; - echo "
\n"; - echo "
\n"; - echo "
(only a-z, 0-9)
\n"; - echo "
\n"; - echo "
\n"; - echo "
\n"; - echo "
(must be valid, because an activation link will be sent over there)
\n"; - echo "
\n"; - echo "
\n"; - echo "\n"; - // add extra fields from Plugins, like NP_Profile - $manager->notify('RegistrationFormExtraFields', array('type' => 'createaccount.php', 'prelabel' => '', 'postlabel' => '
', 'prefield' => '', 'postfield' => '

')); - - // add a Captcha challenge or something else - global $manager; - $manager->notify('FormExtra', array('type' => 'membermailform-notloggedin')); - echo "\n"; - echo "
\n"; - echo "
\n"; -} -else -{ - echo "

\n"; - echo 'Visitors are not allowed to create a Member Account.

'; - echo 'Please contact the website administrator for more information.'; - echo "

\n"; -} - -echo "\n"; -echo "\n"; +>>>>>> skinnable-master diff --git a/install/index.php b/install/index.php index 17fb9a3..13fd7be 100644 --- a/install/index.php +++ b/install/index.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD Nucleus requires at least PHP version ' . $minimum_php_version . ''); +} + +// make sure there's no unnecessary escaping: # set_magic_quotes_runtime(0); +if ( version_compare(PHP_VERSION, '5.3.0', '<') ) +{ + ini_set('magic_quotes_runtime', '0'); +} + +/* default installed plugins and skins */ +$aConfPlugsToInstall = array('NP_SecurityEnforcer', 'NP_SkinFiles', 'NP_Medium'); +$aConfSkinsToImport = array('atom', 'rss2.0', 'rsd', 'default', 'admin/default', 'admin/bookmarklet'); + +// Check if some important files +do_check_files(); + +/* i18n class is needed for internationalization */ +include_once('../nucleus/libs/i18n.php'); +if ( !i18n::init('UTF-8', '../nucleus/locales') ) +{ + exit('
Failed to initialize iconv or mbstring extension. Would you please contact the administrator of your PHP server?
'); +} + +// include core classes that are needed for login & plugin handling + +// added for 3.5 sql_* wrapper +global $MYSQL_HANDLER; + +if ( !isset($MYSQL_HANDLER) ) +{ + $MYSQL_HANDLER = array('mysql', ''); + + // check if mysql support is installed; this check may not make sense, as is, in a version past 3.5x + if ( !function_exists('mysql_query') && !function_exists('mysqli_query') ) + { + exit('
Your PHP version does not have support for MySQL :(
'); +} +} +include_once('../nucleus/libs/sql/sql.php'); + +session_start(); +if ( count($_GET) == 0 && count($_POST) == 0 ) +{ + unset($_SESSION['param_manager']); +} + +// restore the $param from the session +if ( array_key_exists('param_manager', $_SESSION) ) +{ + $param = $_SESSION['param_manager']; +} +else +{ + $param = new ParamManager(); +} + +// include translation file +$param->set_locale(); + +do_action(); + +// $param is saved to the session +if ( isset($param) ) +{ + $_SESSION['param_manager'] = $param; +} +else +{ + unset($_SESSION['param_manager']); +} +exit; + +/** + * installer action + */ +function do_action() +{ + global $param; + + if ( array_key_exists('action', $_POST) ) + { + $isPostback = true; + } + else + { + $isPostback = false; + } + + // mode change + if ( array_key_exists('mode', $_REQUEST) ) + { + if ( $_REQUEST['mode'] == 'detail' ) + { + $param->set_state('detail'); + } + elseif ( $_REQUEST['mode'] == 'simple' ) + { + $param->set_state('mysql'); + } + } + + // input parameter check + if ( $isPostback ) + { + switch ( $param->state ) + { + case 'locale': + $param->set_state('mysql'); + $isPostback = false; + break; + case 'mysql': + if ( count($param->check_mysql_parameters()) == 0 ) + { + $param->set_state('weblog'); + $isPostback = false; + } + break; + case 'weblog': + if ( count($param->check_user_parameters()) == 0 + && count($param->check_weblog_parameters()) == 0 ) + { + $param->set_state('install'); + $isPostback = false; + } + break; + case 'detail': + if ( $param->check_all_parameters() ) + { + $param->set_state('install'); + $isPostback = false; + } + break; + } + } + + // page render + show_header(); + switch ( $param->state ) + { + case 'locale': + show_select_locale_form(); + break; + case 'mysql': + show_database_setting_form($isPostback); + break; + case 'weblog': + show_blog_setting_form($isPostback); + break; + case 'detail': + show_detail_setting_form($isPostback); + break; + case 'install': + show_install_complete_form(); + break; + } + show_footer(); +} + +/** + * header tag of the installation screens + **/ +function show_header() +{ + global $param; + + /* HTTP 1.1 application for no caching */ + header("Cache-Control: no-cache, must-revalidate"); + header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); + header('Content-Type: text/html; charset=' . i18n::get_current_charset()); +?> + + + + <?php echo _TITLE; ?> + + + + + + + + + + + +
+

+ +

+
+ +
+ +

+

+

+

+ +

+
+
+
+ +
+

+', $config_writable, ''; + } + if ( $mysql_version == '0.0.0' ) + { + echo '', _DBVERSION_UNKOWN, ''; + } + elseif ( version_compare($mysql_version, $minimum_mysql_version, '<') ) + { + echo '', sprintf(_DBVERSION_TOOLOW, $minimum_mysql_version), ''; + } +?> +

+
+
+

+

+check_mysql_parameters(); + if ( is_array($errors) ) + { + foreach ( $errors as $error ) + { + echo '', $error, "\n"; + } + } + } +?> +

+ + + + + + + + + + + + + + + + + +
+

+ + +

+

+ +

+
+
+
+ +
+

+ +

+
+
+

+

+check_weblog_parameters(); + if ( is_array($errors) ) + { + foreach ( $errors as $error ) + { + echo '', $error, "\n"; + } + } + } +?> +

+ + + + + + + + + +
+
+ +
+

+

+check_user_parameters(); + if ( is_array($errors) ) + { + foreach ( $errors as $error ) + { + echo '', $error, "\n"; + } + } + } +?> +

+ + + + + + + + + + + + + + + + + + + + + +
+

+ +

+
+
+
+ +
+

+ +check_all_parameters() ) + { + echo '', _VALID_ERROR, "\n"; + } +?> +

+
    +
  • PHP:
  • +
  • MySQL: +', sprintf(_DBVERSION_TOOLOW, $minimum_mysql_version), ''; + } +?>
  • +
+
+ +
+

+

+check_mysql_parameters(); + if ( is_array($errors) ) + { + foreach ( $errors as $error ) + { + echo '', $error, "\n"; + } + } + } +?> +

+ + + + + + + + + + + + + + + + + + + + + +
+ +

+

+check_uri_parameters(); + if ( is_array($errors) ) + { + foreach ( $errors as $error ) + { + echo '', $error, "\n"; + } + } + $errors = $param->check_path_parameters(); + if ( is_array($errors) ) + { + foreach ( $errors as $error ) + { + echo '', $error, "\n"; + } + } + } +?> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ +

+ +

+

+check_user_parameters(); + if ( is_array($errors) ) + { + foreach ( $errors as $error ) + { + echo '', $error, "\n"; + } + } + } +?> +

+ + + + + + + + + + + + + + + + + + + + + +
+ +

+

+check_weblog_parameters(); + if ( is_array($errors) ) + { + foreach ( $errors as $error ) + { + echo '', $error, "\n"; + } + } + } +?> +

+ + + + + + + + + +
+ +

+ +

+ +

+ +

+
+
+
+ +
+

+ 0 ) + { + echo _INST_ERROR; + foreach ( $errors as $error ) + { + echo '', $error, "\n"; + } + } + else + { + echo _INST_TEXT; + if ( array_key_exists('config_data', $_SESSION) ) + { + echo '', _INST_TEXT4, ''; +?> + +', _INST_TEXT5, ''; + } +?> +

+
+
+

+

+ blog_name); ?> +

+

+ +

+
+ +
+

+

+ +

+

+ +

+
+ +
+

+

+ +

+

+ +

+
+
+ +
+mysql_host; + $MYSQL_USER = $param->mysql_user; + $MYSQL_PASSWORD = $param->mysql_password; + $MYSQL_DATABASE = $param->mysql_database; + $MYSQL_PREFIX = $param->mysql_tablePrefix; + + $DIR_NUCLEUS = $param->AdminPath; + $DIR_MEDIA = $param->MediaPath; + $DIR_SKINS = $param->SkinsPath; + $DIR_PLUGINS = $DIR_NUCLEUS . 'plugins/'; + $DIR_LOCALES = $DIR_NUCLEUS . 'locales/'; + $DIR_LIBS = $DIR_NUCLEUS . 'libs/'; + + /* + * 2.open mySQL connection + */ + $MYSQL_CONN = @DB::setConnectionInfo($MYSQL_HANDLER[1], $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD); + if ( $MYSQL_CONN == FALSE ) + { + $errors[] = _DBCONNECT_ERROR; + return $errors; + } + + /* + * 3. try to create database if needed + */ + if ( DB::execute("CREATE DATABASE IF NOT EXISTS {$MYSQL_DATABASE}") === FALSE ) + { + $errinfo = DB::getError(); + $errors[] = _INST_ERROR1 . ': ' . $errinfo[2]; + } + + /* + * 4. try to select database + */ + $MYSQL_CONN = @DB::setConnectionInfo($MYSQL_HANDLER[1], $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE); + if ( !$MYSQL_CONN ) + { + $errors[] = _INST_ERROR2; + } + + if ( count($errors) > 0 ) + { + return $errors; + } + + /* + * 5. execute queries + */ + $table_names = array( + 'nucleus_actionlog', + 'nucleus_ban', + 'nucleus_blog', + 'nucleus_category', + 'nucleus_comment', + 'nucleus_config', + 'nucleus_item', + 'nucleus_karma', + 'nucleus_member', + 'nucleus_plugin', + 'nucleus_skin', + 'nucleus_template', + 'nucleus_team', + 'nucleus_activation', + 'nucleus_tickets' + ); + + $prefixed_table_names = array(); + foreach ( $table_names as $table_name ) + { + $prefixed_table_names[] = $MYSQL_PREFIX . $table_name; + } + + // table exists check + $result = DB::getResult('SHOW TABLES'); + foreach ( $result as $row ) + { + if ( in_array($row[0], $prefixed_table_names) ) + { + $errors[] = _INST_ERROR3; + break; + } + } + if ( count($errors) > 0 ) + { + return $errors; + } + + $filename = 'install.sql'; + $fd = fopen($filename, 'r'); + $queries = fread($fd, filesize($filename)); + fclose($fd); + + $queries = preg_split('#(;\n|;\r)#', $queries); + + foreach ( $queries as $query ) + { + if ( preg_match('/\w+/', $query) ) + { + if ( $MYSQL_PREFIX ) + { + $query = str_replace($table_names, $prefixed_table_names, $query); + } + + if ( DB::execute($query) === FALSE ) + { + $errinfo = DB::getError(); + $errors[] = _INST_ERROR4 . ' (' . $query . '): ' . $errinfo[2]; + } + } + } + + /* + * 6. put needed records + */ + /* push first post */ + $query = "INSERT INTO %s VALUES (1, %s, %s, %s, 1, 1, %s, 0, 0, 0, 1, 0, 1)"; + $query = sprintf($query, + tableName('nucleus_item'), + DB::quoteValue(_1ST_POST_TITLE), + DB::quoteValue(_1ST_POST), + DB::quoteValue(_1ST_POST2), + DB::formatDateTime() + ); + if ( DB::execute($query) === FALSE ) + { + $errinfo = DB::getError(); + $errors[] = _INST_ERROR4 . ' (' . $query . '): ' . $errinfo[2]; + } + + /* push configurations */ + array_merge($errors, updateConfig('IndexURL', $param->IndexURL)); + array_merge($errors, updateConfig('AdminURL', $param->AdminURL)); + array_merge($errors, updateConfig('MediaURL', $param->MediaURL)); + array_merge($errors, updateConfig('SkinsURL', $param->SkinsURL)); + array_merge($errors, updateConfig('PluginURL', $param->PluginURL)); + array_merge($errors, updateConfig('ActionURL', $param->ActionURL)); + array_merge($errors, updateConfig('AdminEmail', $param->user_email)); + array_merge($errors, updateConfig('SiteName', $param->blog_name)); + array_merge($errors, updateConfig('Locale', i18n::get_current_locale())); + + /* push super admin */ + $query = "UPDATE %s SET mname = %s, mrealname = %s, mpassword = %s, memail = %s, murl = %s, madmin = 1, mcanlogin = 1 WHERE mnumber = 1"; + $query = sprintf($query, + tableName('nucleus_member'), + DB::quoteValue($param->user_name), + DB::quoteValue($param->user_realname), + DB::quoteValue(md5($param->user_password)), + DB::quoteValue($param->user_email), + DB::quoteValue($param->IndexURL) + ); + if ( DB::execute($query) === FALSE ) + { + $errinfo = DB::getError(); + $errors[] = _INST_ERROR5 . ': ' . $errinfo[2]; + } + + /* push new weblog */ + $query = "UPDATE %s SET bname = %s, bshortname = %s, burl = %s WHERE bnumber = 1"; + $query = sprintf($query, + tableName('nucleus_blog'), + DB::quoteValue($param->blog_name), + DB::quoteValue($param->blog_shortname), + DB::quoteValue($param->IndexURL) + ); + if ( DB::execute($query) === FALSE ) + { + $errinfo = DB::getError(); + $errors[] = _INST_ERROR6 . ': ' . $errinfo[2]; + } + + /* push default category */ + $query = "UPDATE %s SET cname = %s, cdesc = %s WHERE catid = 1"; + $query = sprintf($query, + tableName('nucleus_category'), + DB::quoteValue(_GENERALCAT_NAME), + DB::quoteValue(_GENERALCAT_DESC) + ); + if ( DB::execute($query) === FALSE ) + { + $errinfo = DB::getError(); + $errors[] = _INST_ERROR6 . ': ' . $errinfo[2]; + } + + /* + * 7. install default plugins and skins + */ + global $aConfPlugsToInstall, $aConfSkinsToImport; + $aSkinErrors = array(); + $aPlugErrors = array(); + + if ( (count($aConfPlugsToInstall) > 0) || (count($aConfSkinsToImport) > 0) ) + { + include_once($DIR_LIBS . 'globalfunctions.php'); + global $manager; + if ( !isset($manager) ) + { + $manager = new Manager(); + } + + include_once($DIR_LIBS . 'skinie.php'); + + $aSkinErrors = installCustomSkins(); + if ( count($aSkinErrors) > 0 ) + { + array_merge($errors, $aSkinErrors); + } + + $query = "SELECT sdnumber FROM %s WHERE sdname='admin/default'"; + $query = sprintf($query, tableName('nucleus_skin_desc')); + $res = intval(DB::getValue($query)); + array_merge($errors, updateConfig('AdminSkin', $res)); + + $query = "SELECT sdnumber FROM %s WHERE sdname='admin/bookmarklet'"; + $query = sprintf($query, tableName('nucleus_skin_desc')); + $res = intval(DB::getValue($query)); + array_merge($errors, updateConfig('BookmarkletSkin', $res)); + + $query = "SELECT sdnumber FROM %s WHERE sdname='default'"; + $query = sprintf($query, tableName('nucleus_skin_desc')); + $defSkinID = intval(DB::getValue($query)); + + $query = "UPDATE %s SET bdefskin=%d WHERE bnumber=1"; + $query = sprintf($query, tableName('nucleus_blog'), $defSkinID); + DB::execute($query); + $query = "UPDATE %s SET value=%d WHERE name='BaseSkin'"; + $query = sprintf($query, tableName('nucleus_config'), $defSkinID); + DB::execute($query); + + $aPlugErrors = installCustomPlugs(); + if ( count($aPlugErrors) > 0 ) + { + array_merge($errors, $aPlugErrors); + } + } + + /* + * 8. Write config file ourselves (if possible) + */ + $config_data = '<' . '?php' . "\n"; + $config_data .= "// mySQL connection information\n"; + $config_data .= "\$MYSQL_HOST = '" . $MYSQL_HOST . "';\n"; + $config_data .= "\$MYSQL_USER = '" . $MYSQL_USER . "';\n"; + $config_data .= "\$MYSQL_PASSWORD = '" . $MYSQL_PASSWORD . "';\n"; + $config_data .= "\$MYSQL_DATABASE = '" . $MYSQL_DATABASE . "';\n"; + $config_data .= "\$MYSQL_PREFIX = '" . $MYSQL_PREFIX . "';\n"; + $config_data .= "// new in 3.50. first element is db handler, the second is the db driver used by the handler\n"; + $config_data .= "// default is \$MYSQL_HANDLER = array('mysql','mysql');\n"; + $config_data .= "//\$MYSQL_HANDLER = array('mysql','mysql');\n"; + $config_data .= "//\$MYSQL_HANDLER = array('pdo','mysql');\n"; + $config_data .= "\$MYSQL_HANDLER = array('" . $MYSQL_HANDLER[0] . "','" . $MYSQL_HANDLER[1] . "');\n"; + $config_data .= "\n"; + $config_data .= "// main nucleus directory\n"; + $config_data .= "\$DIR_NUCLEUS = '" . $DIR_NUCLEUS . "';\n"; + $config_data .= "\n"; + $config_data .= "// path to media dir\n"; + $config_data .= "\$DIR_MEDIA = '" . $DIR_MEDIA . "';\n"; + $config_data .= "\n"; + $config_data .= "// extra skin files for imported skins\n"; + $config_data .= "\$DIR_SKINS = '" . $DIR_SKINS . "';\n"; + $config_data .= "\n"; + $config_data .= "// these dirs are normally sub dirs of the nucleus dir, but \n"; + $config_data .= "// you can redefine them if you wish\n"; + $config_data .= "\$DIR_PLUGINS = \$DIR_NUCLEUS . 'plugins/';\n"; + $config_data .= "\$DIR_LOCALES = \$DIR_NUCLEUS . 'locales/';\n"; + $config_data .= "\$DIR_LIBS = \$DIR_NUCLEUS . 'libs/';\n"; + $config_data .= "\n"; + $config_data .= "// include libs\n"; + $config_data .= "include(\$DIR_LIBS.'globalfunctions.php');\n"; + $config_data .= "?" . ">"; + + $result = false; + if ( @!file_exists('../config.php') || is_writable('../config.php') ) + { + if ( $fp = @fopen('../config.php', 'w') ) + { + $result = @fwrite($fp, $config_data, i18n::strlen($config_data)); + fclose($fp); + } + } + + if ( $result ) + { + // try to change the read-only permission. + if ( strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' ) + { + @chmod('../config.php', 0444); + } + } + else + { + $_SESSION['config_data'] = $config_data; + } + + return $errors; +} + +/** + * Confirm that you can write to the configuration file + * @return string error message + */ +function canConfigFileWritable() +{ + if ( @file_exists('../config.php') && @!is_writable('../config.php') ) + { + // try to change the read-write permission. + if ( strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' ) + { + @chmod('../config.php', 0666); + } + + if ( @!is_writable('../config.php') ) + { + return _INST_ERROR8; + } + } + return ''; +} + +/** + * To obtain the version of MySQL + * @return string + */ +function getMySqlVersion() +{ + global $MYSQL_HANDLER, $minimum_mysql_version, $errors; + // Turn on output buffer + // Needed to repress the output of the sql function that are + // not part of php (in this case the @ operator doesn't work) + ob_start(); + + // note: this piece of code is taken from phpMyAdmin + $conn = @DB::setConnectionInfo($MYSQL_HANDLER[1], 'localhost', '', ''); + + if ( $conn ) + { + $row = DB::getAttribute(PDO::ATTR_SERVER_VERSION); + $match = preg_split('#\.#', $row); + } + else + { + $row = @DB::getRow('SHOW VARIABLES LIKE \'version\''); + + if ( $row ) + { + $match = preg_split('#\.#', $row[1]); + } + else + { + $output = (function_exists('shell_exec')) ? @shell_exec('mysql -V') : '0.0.0'; + preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version); + $match = preg_split('#\.#', $version[0]); + + if ( $match[0] == '' ) + { + $match = array('0', '0', '0'); + } + } + } + + @DB::disConnect(); + + //End and clean output buffer + ob_end_clean(); + + return implode($match, '.'); +} + +/** + * Add a table prefix if it is used + * + * @param string $input table name with prefix + * @return string + */ +function tableName($input) +{ + global $MYSQL_PREFIX; + if ( $MYSQL_PREFIX ) + { + return $MYSQL_PREFIX . $input; + } + else + { + return $input; + } +} + +/** + * Install custom plugins + */ +function installCustomPlugs() +{ + global $aConfPlugsToInstall, $DIR_LIBS, $manager; + + $aErrors = array(); + if ( count($aConfPlugsToInstall) == 0 ) + { + return $aErrors; + } + + $query = sprintf('SELECT * FROM %s', tableName('nucleus_plugin')); + $res = DB::getResult($query); + $numCurrent = $res->rowCount(); + + foreach ( $aConfPlugsToInstall as $plugName ) + { + $query = sprintf('INSERT INTO %s (porder, pfile) VALUES (%d, %s)', + tableName('nucleus_plugin'), + (++$numCurrent), + DB::quoteValue($plugName)); + DB::execute($query); + + $manager->clearCachedInfo('installedPlugins'); + $plugin =& $manager->getPlugin($plugName); + $plugin->setID($numCurrent); + + if ( !$plugin ) + { + $query = sprintf('DELETE FROM %s WHERE pfile = %s', + tableName('nucleus_plugin'), + DB::quoteValue($plugName)); + DB::execute($query); + $numCurrent--; + array_push($aErrors, sprintf(_INST_ERROR9, $plugName)); + continue; + } + $plugin->install(); + } + + $query = sprintf('DELETE FROM %s', tableName('nucleus_plugin_event')); + DB::execute($query); + $query = sprintf('SELECT pid, pfile FROM %s', tableName('nucleus_plugin')); + $res = DB::getResult($query); + + foreach ( $res as $row ) + { + $plug =& $manager->getPlugin($row['pfile']); + + if ( $plug ) + { + $eventList = $plug->getEventList(); + foreach ( $eventList as $eventName ) + { + $query = sprintf('INSERT INTO %s (pid, event) VALUES (%d, %s)', + tableName('nucleus_plugin_event'), + intval($row['pid']), + DB::quoteValue($eventName)); + DB::execute($query); + } + } + } + return $aErrors; +} + +/** + * Install custom skins + * Prepares the installation of custom skins + */ +function installCustomSkins() +{ + global $aConfSkinsToImport, $DIR_LIBS, $DIR_SKINS; + + $aErrors = array(); + if ( count($aConfSkinsToImport) == 0 ) + { + return $aErrors; + } + + $importer = new SkinImport(); + + foreach ( $aConfSkinsToImport as $skinName ) + { + $importer->reset(); + $skinFile = $DIR_SKINS . $skinName . '/skinbackup.xml'; + + if ( !@file_exists($skinFile) ) + { + array_push($aErrors, sprintf(_INST_ERROR10, $skinFile)); + continue; + } + + $error = $importer->readFile($skinFile); + + if ( $error ) + { + array_push($aErrors, sprintf(_INST_ERROR11, $skinName) . ' : ' . $error); + continue; + } + + $error = $importer->writeToDatabase(1); + + if ( $error ) + { + array_push($aErrors, sprintf(_INST_ERROR12, $skinName) . ' : ' . $error); + continue; + } + } + return $aErrors; +} + +/** + * Check if some important files of the Nucleus CMS installation are available + * Give an error if one or more files are not accessible + */ +function do_check_files() +{ + $missingfiles = array(); + $files = array( + './install.sql', + '../index.php', + '../action.php', + '../nucleus/index.php', + '../nucleus/libs/ACTION.php', + '../nucleus/libs/ACTIONLOG.php', + '../nucleus/libs/ACTIONS.php', + '../nucleus/libs/ADMIN.php', + '../nucleus/libs/BaseActions.php', + '../nucleus/libs/BLOG.php', + '../nucleus/libs/BODYACTIONS.php', + '../nucleus/libs/COMMENT.php', + '../nucleus/libs/COMMENTACTIONS.php', + '../nucleus/libs/COMMENTS.php', + '../nucleus/libs/ENTITY.php', + '../nucleus/libs/globalfunctions.php', + '../nucleus/libs/i18n.php', + '../nucleus/libs/ITEM.php', + '../nucleus/libs/ITEMACTIONS.php', + '../nucleus/libs/LINK.php', + '../nucleus/libs/MANAGER.php', + '../nucleus/libs/MEDIA.php', + '../nucleus/libs/MEMBER.php', + '../nucleus/libs/NOTIFICATION.php', + '../nucleus/libs/PARSER.php', + '../nucleus/libs/PLUGIN.php', + '../nucleus/libs/PLUGINADMIN.php', + '../nucleus/libs/SEARCH.php', + '../nucleus/libs/showlist.php', + '../nucleus/libs/SKIN.php', + '../nucleus/libs/TEMPLATE.php', + '../nucleus/libs/vars4.1.0.php', + '../nucleus/libs/xmlrpc.inc.php', + '../nucleus/libs/xmlrpcs.inc.php', + '../nucleus/libs/sql/DB.php', + '../nucleus/libs/sql/MYSQLPDO.php' + ); + + $count = count($files); + for ( $i = 0; $i < $count; $i++ ) + { + if ( !is_readable($files[$i]) ) + { + array_push($missingfiles, 'File ' . $files[$i] . ' is missing or not readable.
'); + } + } + + if ( count($missingfiles) > 0 ) + { + exit(implode("\n", $missingfiles)); + } +} + +/** + * Updates the configuration in the database + * + * @param string $name name of the config var + * @param string $value new value of the config var + * @return array + */ +function updateConfig($name, $value) +{ + $errors = array(); + + $query = "UPDATE %s SET value = %s WHERE name = %s"; + $query = sprintf($query, tableName('nucleus_config'), DB::quoteValue(trim($value)), DB::quoteValue($name)); + + if ( DB::execute($query) === FALSE ) + { + $errinfo = DB::getError(); + $errors[] = _INST_ERROR4 . ': ' . $errinfo[2]; + } + return $errors; +} + +class ParamManager +{ + /* process parameter */ + public $state; + public $locale; + + /* mysql connection parameters */ + public $mysql_host; + public $mysql_user; + public $mysql_password; + public $mysql_database; + public $mysql_tablePrefix; + + /* weblog configuration parameters */ + public $blog_name; + public $blog_shortname; + + /* member configuration parameters */ + public $user_name; + public $user_realname; + public $user_password; + private $user_password2; + public $user_email; + + /* URI parameters */ + private $root_url; + public $IndexURL; + public $AdminURL; + public $MediaURL; + public $SkinsURL; + public $PluginURL; + public $ActionURL; + + /* path parameters */ + private $root_path; + public $AdminPath; + public $MediaPath; + public $SkinsPath; + + /** + * constructor + */ + public function __construct() + { + $this->init(); + } + + public function init() + { + // set default values + $this->state = 'locale'; + $this->install_mode = 'simple'; + $this->locale = ''; + $this->mysql_host = @ini_get('mysql.default_host'); + $this->blog_name = 'My Nucleus CMS'; + $this->blog_shortname = 'mynucleuscms'; + + /* root path */ + $directory_separator = preg_quote(DIRECTORY_SEPARATOR, '|'); + $this->root_path = implode('/', preg_split("|$directory_separator|", realpath(dirname(__FILE__) . '/..'))); + if ( substr($this->root_path, -1, 1) !== '/' ) + { + $this->root_path .= '/'; + } + $base_path_pcre = preg_quote($this->root_path, '|'); + + /* current directry name */ + $directory_name = preg_replace("#{$base_path_pcre}#", '', implode('/', preg_split("#{$directory_separator}#", realpath(dirname(__FILE__))))); + $directory_name_pcre = preg_quote($directory_name, '|'); + + /* root uri */ + $root_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; + $this->root_url = preg_replace("|$directory_name_pcre(.*)$|", '', $root_url); + + $this->AdminPath = $this->root_path . 'nucleus/'; + $this->MediaPath = $this->root_path . 'media/'; + $this->SkinsPath = $this->root_path . 'skins/'; + + $this->IndexURL = $this->root_url; + $this->AdminURL = $this->root_url . 'nucleus/'; + $this->MediaURL = $this->root_url . 'media/'; + $this->SkinsURL = $this->root_url . 'skins/'; + $this->PluginURL = $this->root_url . 'nucleus/plugins/'; + $this->ActionURL = $this->root_url . 'action.php'; + } + + private function read_parameter($parameter) + { + foreach ( $parameter as $element ) + { + if ( array_key_exists($element, $_POST) ) + { + $this->$element = $_POST[$element]; + } + } + } + + public function set_state($state) + { + $states = array('locale', 'mysql', 'weblog', 'detail', 'install'); + if ( in_array($state, $states) ) + { + $this->state = $state; + } + } + + public function set_locale() + { + $this->read_parameter(array('locale')); + + if ( !$this->locale ) + { + /** + * default locale select simple implementation + * + * NOTE: + * RFC2616: Hypertext Transfer Protocol -- HTTP/1.1 + * http://www.ietf.org/rfc/rfc2616.txt + * + * 14.4 Accept-Language + * + * The Accept-Language request-header field is similar to Accept, but + * restricts the set of natural languages that are preferred as a + * response to the request. Language tags are defined in section 3.10. + * + * Accept-Language = "Accept-Language" ":" + * 1#( language-range [ ";" "q" "=" qvalue ] ) + * language-range = ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" ) + * + * Each language-range MAY be given an associated quality value which + * represents an estimate of the user's preference for the languages + * specified by that range. The quality value defaults to "q=1". For + * example, + * + * Accept-Language: da, en-gb;q=0.8, en;q=0.7 + * + * would mean: "I prefer Danish, but will accept British English and + * other types of English." A language-range matches a language-tag if + * it exactly equals the tag, or if it exactly equals a prefix of the + * tag such that the first tag character following the prefix is "-". + * The special range "*", if present in the Accept-Language field, + * matches every tag not matched by any other range present in the + * Accept-Language field. + * + * TODO: this is appropriate implement or not + */ + $languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); + + /* retrieve language token of language tag from first token */ + $language = ''; + if ( is_array($languages) && count($languages) > 0 ) + { + $language = preg_replace('#^([\w]+).*$#', '$1', $languages[0]); + } + + $locales = i18n::get_available_locale_list(); + foreach ( $locales as $locale ) + { + if ( i18n::strpos($locale, $language) === 0 ) + { + $this->locale = $locale; + break; + } + } + } + + /* include installer translation messages */ + $translation_file = "./locales/{$this->locale}." . i18n::get_current_charset() . '.php'; + if ( !file_exists($translation_file) ) + { + $translation_file = './locales/en_Latn_US.UTF-8.php'; + } + include($translation_file); + + /* include global translation messages */ + $translation_file = "../nucleus/locales/{$this->locale}." . i18n::get_current_charset() . '.php'; + if ( !file_exists($translation_file) ) + { + $translation_file = './locales/en_Latn_US.UTF-8.php'; + } + include($translation_file); + + i18n::set_current_locale($this->locale); + + return; + } + + public function check_mysql_parameters() + { + global $MYSQL_HANDLER; + + $parameters = array('mysql_host', 'mysql_user', 'mysql_password', 'mysql_database', 'mysql_tablePrefix'); + $this->read_parameter($parameters); + + $errors = array(); + if ( $this->mysql_host == '' ) + { + $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD1); + } + + if ( $this->mysql_user == '' ) + { + $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD2); + } + + if ( $this->mysql_user != '' + && !preg_match('/^[a-z0-9_\-]+$/i', $this->mysql_user) ) + { + $errors[] = sprintf(_VALID_ERROR2, _DB_FIELD2); + } + + if ( $this->mysql_database == '' ) + { + $errors[] = sprintf(_VALID_ERROR1, _DB_FIELD4); + } + + if ( $this->mysql_database != '' + && !preg_match('/^[a-z0-9_\-]+$/i', $this->mysql_database) ) + { + $errors[] = sprintf(_VALID_ERROR2, _DB_FIELD4); + } + + if ( $this->mysql_tablePrefix != '' + && !preg_match('/^[a-z0-9_]+$/i', $this->mysql_tablePrefix) ) + { + $errors[] = sprintf(_VALID_ERROR3, _DB_FIELD5); + } + + if ( count($errors) == 0 ) + { + $mysql_conn = @DB::setConnectionInfo($MYSQL_HANDLER[1], $this->mysql_host, $this->mysql_user, $this->mysql_password); + if ( $mysql_conn == false ) + { + $errors[] = _DBCONNECT_ERROR; + } + else + { + @DB::disConnect(); + } + } + + return $errors; + } + + public function check_user_parameters() + { + $parameters = array('user_name', 'user_realname', 'user_password', 'user_password2', 'user_email'); + $this->read_parameter($parameters); + + $errors = array(); + if ( $this->user_realname == '' ) + { + $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD1); + } + + if ( $this->user_name == '' ) + { + $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD2); + } + elseif ( !preg_match("/^[a-z0-9]+([ a-z0-9]*[a-z0-9]+)?$/i", $this->user_name) ) + { + $errors[] = _VALID_ERROR5; + } + + if ( $this->user_password == '' || $this->user_password2 == '' ) + { + $errors[] = sprintf(_VALID_ERROR1, _ADMIN_FIELD3); + $this->user_password = ''; + } + elseif ( $this->user_password != $this->user_password2 ) + { + $errors[] = _VALID_ERROR6; + $this->user_password = ''; + } + + if ( !preg_match("/^[a-z0-9\._+\-]+@[a-z0-9\._\-]+\.[a-z]{2,6}$/i", $this->user_email) ) + { + $errors[] = _VALID_ERROR7; + } + + return $errors; + } + + public function check_weblog_parameters() + { + $parameters = array('blog_name', 'blog_shortname'); + $this->read_parameter($parameters); + + $errors = array(); + if ( $this->blog_name == '' ) + { + $errors[] = sprintf(_VALID_ERROR1, _BLOG_FIELD1); + } + + if ( $this->blog_shortname == '' ) + { + $errors[] = sprintf(_VALID_ERROR1, _BLOG_FIELD2); + } + + if ( !preg_match("/^[a-z0-9]+$/i", $this->blog_shortname) ) + { + $errors[] = _VALID_ERROR4; + } + + return $errors; + } + + public function check_uri_parameters() + { + $parameters = array('IndexURL', 'AdminURL', 'MediaURL', 'SkinsURL', 'PluginURL', 'ActionURL'); + $this->read_parameter($parameters); + + $errors = array(); + if ( substr($this->IndexURL, -1, 1) !== '/' ) + { + $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD1); + } + + if ( substr($this->AdminURL, -1, 1) !== '/' ) + { + $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD2); + } + + if ( substr($this->MediaURL, -1, 1) !== '/' ) + { + $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD4); + } + + if ( substr($this->SkinsURL, -1, 1) !== '/' ) + { + $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD6); + } + + if ( substr($this->PluginURL, -1, 1) !== '/' ) + { + $errors[] = sprintf(_VALID_ERROR8, _PATH_FIELD8); + } + + if ( strrchr($this->ActionURL, '/') != '/action.php' ) + { + $errors[] = sprintf(_VALID_ERROR9, _PATH_FIELD9); + } + + return $errors; + } + + public function check_path_parameters() + { + $parameters = array('AdminPath', 'MediaPath', 'SkinsPath'); + $this->read_parameter($parameters); + + $separators = array('/', DIRECTORY_SEPARATOR); + $errors = array(); + if ( !in_array(substr($this->AdminPath, -1, 1), $separators) ) + { + $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD3); + } + elseif ( !file_exists($this->AdminPath) ) + { + $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD3); + } + + if ( !in_array(substr($this->MediaPath, -1, 1), $separators) ) + { + $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD5); + } + elseif ( !file_exists($this->MediaPath) ) + { + $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD5); + } + + if ( !in_array(substr($this->SkinsPath, -1, 1), $separators) ) + { + $errors[] = sprintf(_VALID_ERROR10, _PATH_FIELD7); + } + elseif ( !file_exists($this->SkinsPath) ) + { + $errors[] = sprintf(_VALID_ERROR11, _PATH_FIELD7); + } + + return $errors; + } + + /** + * check all parameters + * @return bool + */ + public function check_all_parameters() + { + $this->set_locale(); + + $isValid = true; + $isValid &= (count($this->check_mysql_parameters()) == 0); + $isValid &= (count($this->check_user_parameters()) == 0); + $isValid &= (count($this->check_weblog_parameters()) == 0); + $isValid &= (count($this->check_uri_parameters()) == 0); + $isValid &= (count($this->check_path_parameters()) == 0); + + return $isValid; + } +} +>>>>>>> skinnable-master diff --git a/install/install.sql b/install/install.sql index 8d0b892..0237635 100644 --- a/install/install.sql +++ b/install/install.sql @@ -1,279 +1,283 @@ -CREATE TABLE nucleus_actionlog ( - timestamp datetime NOT NULL default '0000-00-00 00:00:00', - message varchar(255) NOT NULL default '' -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - -CREATE TABLE nucleus_activation ( - vkey varchar(40) NOT NULL default '', - vtime datetime NOT NULL default '0000-00-00 00:00:00', - vmember int(11) NOT NULL default '0', - vtype varchar(15) NOT NULL default '', - vextra varchar(128) NOT NULL default '', - PRIMARY KEY (vkey) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - -CREATE TABLE nucleus_ban ( - iprange varchar(15) NOT NULL default '', - reason varchar(255) NOT NULL default '', - blogid int(11) NOT NULL default '0' -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - -CREATE TABLE nucleus_blog ( - bnumber int(11) NOT NULL auto_increment, - bname varchar(60) NOT NULL default '', - bshortname varchar(15) NOT NULL default '', - bdesc varchar(200) default NULL, - bcomments tinyint(2) NOT NULL default '1', - bmaxcomments int(11) NOT NULL default '0', - btimeoffset decimal(3,1) NOT NULL default '0.0', - bnotify varchar(128) default NULL, - burl varchar(100) default NULL, - bupdate varchar(60) default NULL, - bdefskin int(11) NOT NULL default '1', - bpublic tinyint(2) NOT NULL default '1', - bconvertbreaks tinyint(2) NOT NULL default '1', - bdefcat int(11) default NULL, - bnotifytype int(11) NOT NULL default '15', - ballowpast tinyint(2) NOT NULL default '0', - bincludesearch tinyint(2) NOT NULL default '0', - breqemail TINYINT( 2 ) DEFAULT '0' NOT NULL, - bfuturepost TINYINT(2) DEFAULT '0' NOT NULL, - PRIMARY KEY (bnumber), --- UNIQUE KEY bnumber (bnumber), - UNIQUE KEY bshortname (bshortname) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - -INSERT INTO nucleus_blog VALUES (1, 'My Nucleus CMS', 'mynucleuscms', '', 1, 0, 0.0, '', 'http://localhost:8080/nucleus/', '', 5, 1, 1, 1, 1, 1, 0, 0, 0); - -CREATE TABLE nucleus_category ( - catid int(11) NOT NULL auto_increment, - cblog int(11) NOT NULL default '0', - cname varchar(200) default NULL, - cdesc varchar(200) default NULL, - PRIMARY KEY (catid) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - -INSERT INTO nucleus_category VALUES (1, 1, 'General', 'Items that do not fit in other categories'); - -CREATE TABLE nucleus_comment ( - cnumber int(11) NOT NULL auto_increment, - cbody text NOT NULL, - cuser varchar(40) default NULL, - cmail varchar(100) default NULL, - cemail VARCHAR( 100 ), - cmember int(11) default NULL, - citem int(11) NOT NULL default '0', - ctime datetime NOT NULL default '0000-00-00 00:00:00', - chost varchar(60) default NULL, - cip varchar(15) NOT NULL default '', - cblog int(11) NOT NULL default '0', - PRIMARY KEY (cnumber), --- UNIQUE KEY cnumber (cnumber), - KEY citem (citem), - FULLTEXT KEY cbody (cbody), - INDEX cblog (cblog) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - -CREATE TABLE nucleus_config ( - name varchar(20) NOT NULL default '', - value varchar(128) default NULL, - PRIMARY KEY (name) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - -INSERT INTO nucleus_config VALUES ('DefaultBlog', '1'); -INSERT INTO nucleus_config VALUES ('AdminEmail', 'example@example.org'); -INSERT INTO nucleus_config VALUES ('IndexURL', 'http://localhost:8080/nucleus/'); -INSERT INTO nucleus_config VALUES ('Locale', 'en_Latn_US'); -INSERT INTO nucleus_config VALUES ('SessionCookie', ''); -INSERT INTO nucleus_config VALUES ('AllowMemberCreate', ''); -INSERT INTO nucleus_config VALUES ('AllowMemberMail', '1'); -INSERT INTO nucleus_config VALUES ('SiteName', 'My Nucleus CMS'); -INSERT INTO nucleus_config VALUES ('AdminURL', 'http://localhost:8080/nucleus/nucleus/'); -INSERT INTO nucleus_config VALUES ('NewMemberCanLogon', '1'); -INSERT INTO nucleus_config VALUES ('DisableSite', ''); -INSERT INTO nucleus_config VALUES ('DisableSiteURL', 'http://www.this-page-intentionally-left-blank.org/'); -INSERT INTO nucleus_config VALUES ('LastVisit', ''); -INSERT INTO nucleus_config VALUES ('MediaURL', 'http://localhost:8080/nucleus/media/'); -INSERT INTO nucleus_config VALUES ('AllowedTypes', 'jpg,jpeg,gif,mpg,mpeg,avi,mov,mp3,swf,png'); -INSERT INTO nucleus_config VALUES ('AllowLoginEdit', ''); -INSERT INTO nucleus_config VALUES ('AllowUpload', '1'); -INSERT INTO nucleus_config VALUES ('DisableJsTools', '2'); -INSERT INTO nucleus_config VALUES ('CookiePath', '/'); -INSERT INTO nucleus_config VALUES ('CookieDomain', ''); -INSERT INTO nucleus_config VALUES ('CookieSecure', ''); -INSERT INTO nucleus_config VALUES ('CookiePrefix', ''); -INSERT INTO nucleus_config VALUES ('MediaPrefix', '1'); -INSERT INTO nucleus_config VALUES ('MaxUploadSize', '1048576'); -INSERT INTO nucleus_config VALUES ('NonmemberMail', ''); -INSERT INTO nucleus_config VALUES ('PluginURL', 'http://localhost:8080/nucleus/nucleus/plugins/'); -INSERT INTO nucleus_config VALUES ('ProtectMemNames', '1'); -INSERT INTO nucleus_config VALUES ('BaseSkin', '5'); -INSERT INTO nucleus_config VALUES ('SkinsURL', 'http://localhost:8080/nucleus/skins/'); -INSERT INTO nucleus_config VALUES ('ActionURL', 'http://localhost:8080/nucleus/action.php'); -INSERT INTO nucleus_config VALUES ('URLMode', 'normal'); -INSERT INTO nucleus_config VALUES ('DatabaseVersion', '350'); -INSERT INTO nucleus_config VALUES ('DebugVars', '0'); -INSERT INTO nucleus_config VALUES ('DefaultListSize', '10'); -INSERT INTO nucleus_config VALUES ('AdminCSS', 'original'); - -CREATE TABLE nucleus_item ( - inumber int(11) NOT NULL auto_increment, - ititle varchar(160) default NULL, - ibody text NOT NULL, - imore text, - iblog int(11) NOT NULL default '0', - iauthor int(11) NOT NULL default '0', - itime datetime NOT NULL default '0000-00-00 00:00:00', - iclosed tinyint(2) NOT NULL default '0', - idraft tinyint(2) NOT NULL default '0', - ikarmapos int(11) NOT NULL default '0', - icat int(11) default NULL, - ikarmaneg int(11) NOT NULL default '0', - iposted tinyint(2) NOT NULL default '1', - PRIMARY KEY (inumber), --- UNIQUE KEY inumber (inumber), - KEY itime (itime), - INDEX iblog (iblog), - INDEX idraft (idraft), - INDEX icat (icat), - FULLTEXT KEY ibody (ibody,ititle,imore) -) ENGINE=MyISAM PACK_KEYS=0 DEFAULT CHARSET=utf8; - -CREATE TABLE nucleus_karma ( - itemid int(11) NOT NULL default '0', - ip char(15) NOT NULL default '' -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - -CREATE TABLE nucleus_member ( - mnumber int(11) NOT NULL auto_increment, - mname varchar(32) NOT NULL default '', - mrealname varchar(60) default NULL, - mpassword varchar(40) NOT NULL default '', - memail varchar(60) default NULL, - murl varchar(100) default NULL, - mnotes varchar(100) default NULL, - madmin tinyint(2) NOT NULL default '0', - mcanlogin tinyint(2) NOT NULL default '1', - mcookiekey varchar(40) default NULL, - mlocale varchar(20) NOT NULL default '', - mautosave tinyint(2) NOT NULL default '1', - PRIMARY KEY (mnumber), --- UNIQUE KEY mnumber (mnumber), - UNIQUE KEY mname (mname) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - -INSERT INTO nucleus_member VALUES (1, 'example', 'example', '1a79a4d60de6718e8e5b326e338ae533', 'example@example.org', 'http://localhost:8080/nucleus/', '', 1, 1, 'd767aefc60415859570d64c649257f19', '', 1); - -CREATE TABLE nucleus_plugin ( - pid int(11) NOT NULL auto_increment, - pfile varchar(40) NOT NULL default '', - porder int(11) NOT NULL default '0', - PRIMARY KEY (pid), --- KEY pid (pid), - KEY porder (porder) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - -CREATE TABLE nucleus_plugin_event ( - pid int(11) NOT NULL default '0', - event varchar(40) default NULL, - KEY pid (pid) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - -CREATE TABLE nucleus_plugin_option ( - ovalue text NOT NULL, - oid int(11) NOT NULL auto_increment, - ocontextid int(11) NOT NULL default '0', - PRIMARY KEY (oid,ocontextid) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - -CREATE TABLE nucleus_plugin_option_desc ( - oid int(11) NOT NULL auto_increment, - opid int(11) NOT NULL default '0', - oname varchar(20) NOT NULL default '', - ocontext varchar(20) NOT NULL default '', - odesc varchar(255) default NULL, - otype varchar(20) default NULL, - odef text, - oextra text, - PRIMARY KEY (opid,oname,ocontext), - UNIQUE KEY oid (oid) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - -CREATE TABLE nucleus_skin ( - sdesc int(11) NOT NULL default '0', - stype varchar(20) NOT NULL default '', - scontent text NOT NULL, - PRIMARY KEY (sdesc,stype) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - --- INSERT INTO nucleus_skin VALUES (2, 'index', '\"?>\n\n\n <%blogsetting(name)%>\n <%blogsetting(url)%>:<%blogsetting(id)%>\n\n \" />\n <%self%>\" />\n <%version%>\n <%blog(feeds/atom/modified,1)%>\n\n <%blog(feeds/atom/entries,10)%>\n'); --- INSERT INTO nucleus_skin VALUES (4, 'index', '\r\n\r\n \r\n <%version%>\r\n http://nucleuscms.org/\r\n <%sitevar(url)%>\r\n \r\n \r\n http://nucleuscms.org/documentation/devdocs/xmlrpc.html\r\n \r\n \r\n http://nucleuscms.org/documentation/devdocs/xmlrpc.html\r\n \r\n \r\n \r\n'); --- INSERT INTO nucleus_skin VALUES (3, 'index', '"?>\r\n\r\n \r\n <%blogsetting(name)%>\r\n <%blogsetting(url)%>\r\n <%blogsetting(desc)%>\r\n en-us \r\n <%version%>\r\n ? \r\n Weblog\r\n http://backend.userland.com/rss\r\n \r\n <%blogsetting(url)%>/nucleus/nucleus2.gif\r\n <%blogsetting(name)%>\r\n <%blogsetting(url)%>\r\n \r\n <%blog(feeds/rss20,10)%>\r\n \r\n'); - -CREATE TABLE nucleus_skin_desc ( - sdnumber int(11) NOT NULL auto_increment, - sdname varchar(20) NOT NULL default '', - sddesc varchar(200) default NULL, - sdtype varchar(40) NOT NULL default 'text/html', - sdincmode varchar(10) NOT NULL default 'normal', - sdincpref varchar(50) NOT NULL default '', - PRIMARY KEY (sdnumber), --- UNIQUE KEY sdnumber (sdnumber), - UNIQUE KEY sdname (sdname) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - --- INSERT INTO nucleus_skin_desc VALUES (2, 'feeds/atom', 'Atom 1.0 weblog syndication', 'application/atom+xml', 'normal', ''); --- INSERT INTO nucleus_skin_desc VALUES (3, 'feeds/rss20', 'RSS 2.0 syndication of weblogs', 'text/xml', 'normal', ''); --- INSERT INTO nucleus_skin_desc VALUES (4, 'xml/rsd', 'RSD (Really Simple Discovery) information for weblog clients', 'text/xml', 'normal', ''); --- INSERT INTO nucleus_skin_desc VALUES (5, 'default', 'Nucleus CMS default skin', 'text/html', 'skindir', 'default/'); - -CREATE TABLE nucleus_team ( - tmember int(11) NOT NULL default '0', - tblog int(11) NOT NULL default '0', - tadmin tinyint(2) NOT NULL default '0', - PRIMARY KEY (tmember,tblog) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - -INSERT INTO nucleus_team VALUES (1, 1, 1); - -CREATE TABLE nucleus_template ( - tdesc int(11) NOT NULL default '0', - tpartname varchar(64) NOT NULL default '', - tcontent text NOT NULL, - PRIMARY KEY (tdesc,tpartname) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - --- INSERT INTO nucleus_template VALUES (3, 'ITEM', '\r\n <%title(xml)%>\r\n <%blogurl%>index.php?itemid=<%itemid%>\r\n<%more%>]]>\r\n <%category%>\r\n<%blogurl%>index.php?itemid=<%itemid%>\r\n <%date(rfc822)%>\r\n'); --- INSERT INTO nucleus_template VALUES (3, 'EDITLINK', 'edit'); --- INSERT INTO nucleus_template VALUES (3, 'FORMAT_DATE', '%x'); --- INSERT INTO nucleus_template VALUES (3, 'FORMAT_TIME', '%X'); --- INSERT INTO nucleus_template VALUES (4, 'ITEM', '<%date(utc)%>'); --- INSERT INTO nucleus_template VALUES (5, 'ITEM', '\n <![CDATA[<%title%>]]>\n index.php?itemid=<%itemid%>\" />\n \n <%author%>\n \n <%date(utc)%>\n <%date(iso8601)%>\n <%more%>]]>\n <%blogurl%>:<%blogid%>:<%itemid%>\n'); --- INSERT INTO nucleus_template VALUES (5, 'POPUP_CODE', '<%media%>'); --- INSERT INTO nucleus_template VALUES (5, 'IMAGE_CODE', '<%image%>'); --- INSERT INTO nucleus_template VALUES (5, 'MEDIA_CODE', '<%media%>'); --- INSERT INTO nucleus_template VALUES (3, 'POPUP_CODE', '<%image%>'); --- INSERT INTO nucleus_template VALUES (3, 'MEDIA_CODE', '<%media%>'); --- INSERT INTO nucleus_template VALUES (3, 'IMAGE_CODE', '<%media%>'); - -CREATE TABLE nucleus_template_desc ( - tdnumber int(11) NOT NULL auto_increment, - tdname varchar(64) NOT NULL default '', - tddesc varchar(200) default NULL, - PRIMARY KEY (tdnumber), --- UNIQUE KEY tdnumber (tdnumber), - UNIQUE KEY tdname (tdname) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - --- INSERT INTO nucleus_template_desc VALUES (4, 'feeds/atom/modified', 'Atom feeds: Inserts last modification date'); --- INSERT INTO nucleus_template_desc VALUES (5, 'feeds/atom/entries', 'Atom feeds: Feed items'); --- INSERT INTO nucleus_template_desc VALUES (3, 'feeds/rss20', 'Used for RSS 2.0 syndication of your blog'); --- INSERT INTO nucleus_template_desc VALUES (8, 'default/index', 'Nucleus CMS default index template'); --- INSERT INTO nucleus_template_desc VALUES (9, 'default/item', 'Nucleus CMS default item template'); - -CREATE TABLE nucleus_tickets ( - ticket varchar(40) NOT NULL default '', - ctime datetime NOT NULL default '0000-00-00 00:00:00', - member int(11) NOT NULL default '0', - PRIMARY KEY (ticket,member) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; +CREATE TABLE nucleus_actionlog ( + timestamp datetime NOT NULL default '0000-00-00 00:00:00', + message varchar(255) NOT NULL default '' +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE nucleus_activation ( + vkey varchar(40) NOT NULL default '', + vtime datetime NOT NULL default '0000-00-00 00:00:00', + vmember int(11) NOT NULL default '0', + vtype varchar(15) NOT NULL default '', + vextra varchar(128) NOT NULL default '', + PRIMARY KEY (vkey) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE nucleus_ban ( + iprange varchar(15) NOT NULL default '', + reason varchar(255) NOT NULL default '', + blogid int(11) NOT NULL default '0' +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE nucleus_blog ( + bnumber int(11) NOT NULL auto_increment, + bname varchar(60) NOT NULL default '', + bshortname varchar(15) NOT NULL default '', + bdesc varchar(200) default NULL, + bcomments tinyint(2) NOT NULL default '1', + bmaxcomments int(11) NOT NULL default '0', + btimeoffset decimal(3,1) NOT NULL default '0.0', + bnotify varchar(128) default NULL, + burl varchar(100) default NULL, + bupdate varchar(60) default NULL, + bdefskin int(11) NOT NULL default '1', + bpublic tinyint(2) NOT NULL default '1', + bconvertbreaks tinyint(2) NOT NULL default '1', + bdefcat int(11) default NULL, + bnotifytype int(11) NOT NULL default '15', + ballowpast tinyint(2) NOT NULL default '0', + bincludesearch tinyint(2) NOT NULL default '0', + breqemail TINYINT( 2 ) DEFAULT '0' NOT NULL, + bfuturepost TINYINT(2) DEFAULT '0' NOT NULL, + PRIMARY KEY (bnumber), +-- UNIQUE KEY bnumber (bnumber), + UNIQUE KEY bshortname (bshortname) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +INSERT INTO nucleus_blog VALUES (1, 'My Nucleus CMS', 'mynucleuscms', '', 1, 0, 0.0, '', 'http://localhost:8080/nucleus/', '', 5, 1, 1, 1, 1, 1, 0, 0, 0); + +CREATE TABLE nucleus_category ( + catid int(11) NOT NULL auto_increment, + cblog int(11) NOT NULL default '0', + cname varchar(200) default NULL, + cdesc varchar(200) default NULL, + PRIMARY KEY (catid) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +INSERT INTO nucleus_category VALUES (1, 1, 'General', 'Items that do not fit in other categories'); + +CREATE TABLE nucleus_comment ( + cnumber int(11) NOT NULL auto_increment, + cbody text NOT NULL, + cuser varchar(40) default NULL, + cmail varchar(100) default NULL, + cemail VARCHAR( 100 ), + cmember int(11) default NULL, + citem int(11) NOT NULL default '0', + ctime datetime NOT NULL default '0000-00-00 00:00:00', + chost varchar(60) default NULL, + cip varchar(15) NOT NULL default '', + cblog int(11) NOT NULL default '0', + PRIMARY KEY (cnumber), +-- UNIQUE KEY cnumber (cnumber), + KEY citem (citem), + FULLTEXT KEY cbody (cbody), + INDEX cblog (cblog) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE nucleus_config ( + name varchar(20) NOT NULL default '', + value varchar(128) default NULL, + PRIMARY KEY (name) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +INSERT INTO nucleus_config VALUES ('DefaultBlog', '1'); +INSERT INTO nucleus_config VALUES ('AdminEmail', 'example@example.org'); +INSERT INTO nucleus_config VALUES ('IndexURL', 'http://localhost:8080/nucleus/'); +INSERT INTO nucleus_config VALUES ('Locale', 'en_Latn_US'); +INSERT INTO nucleus_config VALUES ('SessionCookie', ''); +INSERT INTO nucleus_config VALUES ('AllowMemberCreate', ''); +INSERT INTO nucleus_config VALUES ('AllowMemberMail', '1'); +INSERT INTO nucleus_config VALUES ('SiteName', 'My Nucleus CMS'); +INSERT INTO nucleus_config VALUES ('AdminURL', 'http://localhost:8080/nucleus/nucleus/'); +INSERT INTO nucleus_config VALUES ('NewMemberCanLogon', '1'); +INSERT INTO nucleus_config VALUES ('DisableSite', ''); +INSERT INTO nucleus_config VALUES ('DisableSiteURL', 'http://www.this-page-intentionally-left-blank.org/'); +INSERT INTO nucleus_config VALUES ('LastVisit', ''); +INSERT INTO nucleus_config VALUES ('MediaURL', 'http://localhost:8080/nucleus/media/'); +INSERT INTO nucleus_config VALUES ('AllowedTypes', 'jpg,jpeg,gif,mpg,mpeg,avi,mov,mp3,swf,png'); +INSERT INTO nucleus_config VALUES ('AllowLoginEdit', ''); +INSERT INTO nucleus_config VALUES ('AllowUpload', '1'); +INSERT INTO nucleus_config VALUES ('DisableJsTools', '2'); +INSERT INTO nucleus_config VALUES ('CookiePath', '/'); +INSERT INTO nucleus_config VALUES ('CookieDomain', ''); +INSERT INTO nucleus_config VALUES ('CookieSecure', ''); +INSERT INTO nucleus_config VALUES ('CookiePrefix', ''); +INSERT INTO nucleus_config VALUES ('MediaPrefix', '1'); +INSERT INTO nucleus_config VALUES ('MaxUploadSize', '1048576'); +INSERT INTO nucleus_config VALUES ('NonmemberMail', ''); +INSERT INTO nucleus_config VALUES ('PluginURL', 'http://localhost:8080/nucleus/nucleus/plugins/'); +INSERT INTO nucleus_config VALUES ('ProtectMemNames', '1'); +INSERT INTO nucleus_config VALUES ('BaseSkin', '5'); +INSERT INTO nucleus_config VALUES ('SkinsURL', 'http://localhost:8080/nucleus/skins/'); +INSERT INTO nucleus_config VALUES ('ActionURL', 'http://localhost:8080/nucleus/action.php'); +INSERT INTO nucleus_config VALUES ('URLMode', 'normal'); +INSERT INTO nucleus_config VALUES ('DatabaseVersion', '350'); +INSERT INTO nucleus_config VALUES ('DebugVars', '0'); +INSERT INTO nucleus_config VALUES ('DefaultListSize', '10'); +INSERT INTO nucleus_config VALUES ('AdminCSS', 'original'); +INSERT INTO nucleus_config VALUES ('AdminSkin', '0'); +INSERT INTO nucleus_config VALUES ('BookmarkletSkin', '0'); + +CREATE TABLE nucleus_item ( + inumber int(11) NOT NULL auto_increment, + ititle varchar(160) default NULL, + ibody text NOT NULL, + imore text, + iblog int(11) NOT NULL default '0', + iauthor int(11) NOT NULL default '0', + itime datetime NOT NULL default '0000-00-00 00:00:00', + iclosed tinyint(2) NOT NULL default '0', + idraft tinyint(2) NOT NULL default '0', + ikarmapos int(11) NOT NULL default '0', + icat int(11) default NULL, + ikarmaneg int(11) NOT NULL default '0', + iposted tinyint(2) NOT NULL default '1', + PRIMARY KEY (inumber), +-- UNIQUE KEY inumber (inumber), + KEY itime (itime), + INDEX iblog (iblog), + INDEX idraft (idraft), + INDEX icat (icat), + FULLTEXT KEY ibody (ibody,ititle,imore) +) ENGINE=MyISAM PACK_KEYS=0 DEFAULT CHARSET=utf8; + +CREATE TABLE nucleus_karma ( + itemid int(11) NOT NULL default '0', + ip char(15) NOT NULL default '' +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE nucleus_member ( + mnumber int(11) NOT NULL auto_increment, + mname varchar(32) NOT NULL default '', + mrealname varchar(60) default NULL, + mpassword varchar(40) NOT NULL default '', + memail varchar(60) default NULL, + murl varchar(100) default NULL, + mnotes varchar(100) default NULL, + madmin tinyint(2) NOT NULL default '0', + mcanlogin tinyint(2) NOT NULL default '1', + mcookiekey varchar(40) default NULL, + mlocale varchar(20) NOT NULL default '', + mautosave tinyint(2) NOT NULL default '1', + madminskin tinyint(2) NOT NULL default '0', + mbkmklt tinyint(2) NOT NULL default '0', + PRIMARY KEY (mnumber), +-- UNIQUE KEY mnumber (mnumber), + UNIQUE KEY mname (mname) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +INSERT INTO nucleus_member VALUES (1, 'example', 'example', '1a79a4d60de6718e8e5b326e338ae533', 'example@example.org', 'http://localhost:8080/nucleus/', '', 1, 1, 'd767aefc60415859570d64c649257f19', '', 1, 0, 0); + +CREATE TABLE nucleus_plugin ( + pid int(11) NOT NULL auto_increment, + pfile varchar(40) NOT NULL default '', + porder int(11) NOT NULL default '0', + PRIMARY KEY (pid), +-- KEY pid (pid), + KEY porder (porder) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE nucleus_plugin_event ( + pid int(11) NOT NULL default '0', + event varchar(40) default NULL, + KEY pid (pid) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE nucleus_plugin_option ( + ovalue text NOT NULL, + oid int(11) NOT NULL auto_increment, + ocontextid int(11) NOT NULL default '0', + PRIMARY KEY (oid,ocontextid) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE nucleus_plugin_option_desc ( + oid int(11) NOT NULL auto_increment, + opid int(11) NOT NULL default '0', + oname varchar(20) NOT NULL default '', + ocontext varchar(20) NOT NULL default '', + odesc varchar(255) default NULL, + otype varchar(20) default NULL, + odef text, + oextra text, + PRIMARY KEY (opid,oname,ocontext), + UNIQUE KEY oid (oid) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE nucleus_skin ( + sdesc int(11) NOT NULL default '0', + stype varchar(20) NOT NULL default '', + scontent text NOT NULL, + PRIMARY KEY (sdesc,stype) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +-- INSERT INTO nucleus_skin VALUES (2, 'index', '\"?>\n\n\n <%blogsetting(name)%>\n <%blogsetting(url)%>:<%blogsetting(id)%>\n\n \" />\n <%self%>\" />\n <%version%>\n <%blog(feeds/atom/modified,1)%>\n\n <%blog(feeds/atom/entries,10)%>\n'); +-- INSERT INTO nucleus_skin VALUES (4, 'index', '\r\n\r\n \r\n <%version%>\r\n http://nucleuscms.org/\r\n <%sitevar(url)%>\r\n \r\n \r\n http://nucleuscms.org/documentation/devdocs/xmlrpc.html\r\n \r\n \r\n http://nucleuscms.org/documentation/devdocs/xmlrpc.html\r\n \r\n \r\n \r\n'); +-- INSERT INTO nucleus_skin VALUES (3, 'index', '"?>\r\n\r\n \r\n <%blogsetting(name)%>\r\n <%blogsetting(url)%>\r\n <%blogsetting(desc)%>\r\n en-us \r\n <%version%>\r\n ? \r\n Weblog\r\n http://backend.userland.com/rss\r\n \r\n <%blogsetting(url)%>/nucleus/nucleus2.gif\r\n <%blogsetting(name)%>\r\n <%blogsetting(url)%>\r\n \r\n <%blog(feeds/rss20,10)%>\r\n \r\n'); + +CREATE TABLE nucleus_skin_desc ( + sdnumber int(11) NOT NULL auto_increment, + sdname varchar(20) NOT NULL default '', + sddesc varchar(200) default NULL, + sdtype varchar(40) NOT NULL default 'text/html', + sdincmode varchar(10) NOT NULL default 'normal', + sdincpref varchar(50) NOT NULL default '', + PRIMARY KEY (sdnumber), +-- UNIQUE KEY sdnumber (sdnumber), + UNIQUE KEY sdname (sdname) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +-- INSERT INTO nucleus_skin_desc VALUES (2, 'feeds/atom', 'Atom 1.0 weblog syndication', 'application/atom+xml', 'normal', ''); +-- INSERT INTO nucleus_skin_desc VALUES (3, 'feeds/rss20', 'RSS 2.0 syndication of weblogs', 'text/xml', 'normal', ''); +-- INSERT INTO nucleus_skin_desc VALUES (4, 'xml/rsd', 'RSD (Really Simple Discovery) information for weblog clients', 'text/xml', 'normal', ''); +-- INSERT INTO nucleus_skin_desc VALUES (5, 'default', 'Nucleus CMS default skin', 'text/html', 'skindir', 'default/'); + +CREATE TABLE nucleus_team ( + tmember int(11) NOT NULL default '0', + tblog int(11) NOT NULL default '0', + tadmin tinyint(2) NOT NULL default '0', + PRIMARY KEY (tmember,tblog) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +INSERT INTO nucleus_team VALUES (1, 1, 1); + +CREATE TABLE nucleus_template ( + tdesc int(11) NOT NULL default '0', + tpartname varchar(64) NOT NULL default '', + tcontent text NOT NULL, + PRIMARY KEY (tdesc,tpartname) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +-- INSERT INTO nucleus_template VALUES (3, 'ITEM', '\r\n <%title(xml)%>\r\n <%blogurl%>index.php?itemid=<%itemid%>\r\n<%more%>]]>\r\n <%category%>\r\n<%blogurl%>index.php?itemid=<%itemid%>\r\n <%date(rfc822)%>\r\n'); +-- INSERT INTO nucleus_template VALUES (3, 'EDITLINK', 'edit'); +-- INSERT INTO nucleus_template VALUES (3, 'FORMAT_DATE', '%x'); +-- INSERT INTO nucleus_template VALUES (3, 'FORMAT_TIME', '%X'); +-- INSERT INTO nucleus_template VALUES (4, 'ITEM', '<%date(utc)%>'); +-- INSERT INTO nucleus_template VALUES (5, 'ITEM', '\n <![CDATA[<%title%>]]>\n index.php?itemid=<%itemid%>\" />\n \n <%author%>\n \n <%date(utc)%>\n <%date(iso8601)%>\n <%more%>]]>\n <%blogurl%>:<%blogid%>:<%itemid%>\n'); +-- INSERT INTO nucleus_template VALUES (5, 'POPUP_CODE', '<%media%>'); +-- INSERT INTO nucleus_template VALUES (5, 'IMAGE_CODE', '<%image%>'); +-- INSERT INTO nucleus_template VALUES (5, 'MEDIA_CODE', '<%media%>'); +-- INSERT INTO nucleus_template VALUES (3, 'POPUP_CODE', '<%image%>'); +-- INSERT INTO nucleus_template VALUES (3, 'MEDIA_CODE', '<%media%>'); +-- INSERT INTO nucleus_template VALUES (3, 'IMAGE_CODE', '<%media%>'); + +CREATE TABLE nucleus_template_desc ( + tdnumber int(11) NOT NULL auto_increment, + tdname varchar(64) NOT NULL default '', + tddesc varchar(200) default NULL, + PRIMARY KEY (tdnumber), +-- UNIQUE KEY tdnumber (tdnumber), + UNIQUE KEY tdname (tdname) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +-- INSERT INTO nucleus_template_desc VALUES (4, 'feeds/atom/modified', 'Atom feeds: Inserts last modification date'); +-- INSERT INTO nucleus_template_desc VALUES (5, 'feeds/atom/entries', 'Atom feeds: Feed items'); +-- INSERT INTO nucleus_template_desc VALUES (3, 'feeds/rss20', 'Used for RSS 2.0 syndication of your blog'); +-- INSERT INTO nucleus_template_desc VALUES (8, 'default/index', 'Nucleus CMS default index template'); +-- INSERT INTO nucleus_template_desc VALUES (9, 'default/item', 'Nucleus CMS default item template'); + +CREATE TABLE nucleus_tickets ( + ticket varchar(40) NOT NULL default '', + ctime datetime NOT NULL default '0000-00-00 00:00:00', + member int(11) NOT NULL default '0', + PRIMARY KEY (ticket,member) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; diff --git a/install/locales/en_Latn_US.UTF-8.php b/install/locales/en_Latn_US.UTF-8.php index 9cedd5e..c05b7f3 100644 --- a/install/locales/en_Latn_US.UTF-8.php +++ b/install/locales/en_Latn_US.UTF-8.php @@ -1,139 +1,145 @@ -When I input detailed information and set it, please click "Detailed Setting".'); -define('_DB_HEADER', 'Check Database'); -define('_DB_TEXT1', '"Detailed setting" is recommended if used to Nucleus.'); -define('_DB_FIELD1', 'Hostname'); -define('_DB_FIELD1_DESC', '(It is usually localhost)'); -define('_DB_FIELD2', 'Username'); -define('_DB_FIELD2_DESC', '(alphabet, number, _, -)'); -define('_DB_FIELD3', 'Password'); -define('_DB_FIELD4', 'Database'); -define('_DB_FIELD4_DESC', '(alphabet, number, _, -)'); -define('_DB_FIELD5', 'Table Prefix'); -define('_DB_FIELD5_DESC', 'Don\'t usually set this.'); - -// blog settings -define('_SIMPLE_NAVI2', 'I was able to confirm the connection of the database.
Setting Blog and Information of the ADMIN, and please click to "NEXT".'); -define('_BLOG_HEADER', 'Weblog Data'); -define('_BLOG_FIELD1', 'Blog Name'); -define('_BLOG_FIELD2', 'Blog Short Name'); -define('_BLOG_FIELD2_DESC', '(alphabet, number)'); - -// admin settings -define('_ADMIN_HEADER', 'Administrator User'); -define('_ADMIN_FIELD1', 'Manager Name'); -define('_ADMIN_FIELD2', 'Login ID'); -define('_ADMIN_FIELD2_DESC', '(alphabet, number)'); -define('_ADMIN_FIELD3', 'Password'); -define('_ADMIN_FIELD4', 'Password Again'); -define('_ADMIN_FIELD5', 'E-mail Address'); - -// url/path settings -define('_PATH_FIELD1', 'Site URL'); -define('_PATH_FIELD2', 'Admin-area URL'); -define('_PATH_FIELD3', 'Admin-area path'); -define('_PATH_FIELD4', 'Media files URL'); -define('_PATH_FIELD5', 'Media dir path'); -define('_PATH_FIELD6', 'Skin files URL'); -define('_PATH_FIELD7', 'Skin files dir path'); -define('_PATH_FIELD8', 'Plugin files URL'); -define('_PATH_FIELD9', 'Action URL'); - -// detail -define('_DETAIL_NAVI1', 'All fields are mandatory. Optional information can be set from the Nucleus admin-area when installation is completed.'); -define('_DETAIL_HEADER1', 'MySQL Login Data'); -define('_DETAIL_TEXT1', 'Enter your MySQL data below. This install script needs it to be able to create and fill your database tables.'); -define('_DETAIL_HEADER2', 'Directories and URLs'); -define('_DETAIL_TEXT2', 'This install script has attempted to find out the directories and URLs in which Nucleus is installed. Please check the values below and correct if necessary. The URLs and file paths should end with a slash.'); -define('_DETAIL_TEXT3', 'Note: Use absolute paths instead of relative paths.'); -define('_DETAIL_HEADER3', 'Administrator User'); -define('_DETAIL_TEXT4', 'You need to enter some information to create the first user of your site.'); -define('_DETAIL_HEADER4', 'Weblog Data'); -define('_DETAIL_TEXT5', 'Below, you need to enter some information to create a default weblog. The name of this weblog will also be used as name for your site.'); -define('_DETAIL_TEXT6', 'Verify the data above, and click the button below to set up your database tables and initial data. This can take a while, so have patience. ONLY CLICK THE BUTTON ONCE !'); - -// install complete -define('_INST_TEXT', 'Congratulations. The installation was completed!'); -define('_INST_HEADER1', 'New Blog'); -define('_INST_TEXT1', 'Let\'s take a look at once you have created [%s].'); -define('_INST_BUTTON1', 'New Blog'); -define('_INST_HEADER2', 'Management page'); -define('_INST_TEXT2', 'A design change, user addition, the category setting to the management page.'); -define('_INST_BUTTON2', 'Management Page'); -define('_INST_HEADER3', 'Addition of the Blog'); -define('_INST_TEXT3', 'If necessary, you can even add a blog.'); -define('_INST_BUTTON3', 'Add Blog'); -define('_INST_TEXT4', 'Was unable to write to the config.php. Please replace with the following contents.'); -define('_INST_TEXT5', 'Please make sure the config.php permissions if it were a 444. If different, please change the "444".'); - -// errors -define('_DBCONNECT_ERROR', 'Could not connect to MySQL Server.'); -define('_DBVERSION_UNKOWN', 'Indeterminable'); -define('_DBVERSION_TOOLOW', 'You must have MySQL version %s or more at least in the Nucleus.'); - -define('_VALID_ERROR', 'There is an error in your input. Please re-look at the input value to see the error message for each section.'); -define('_VALID_ERROR1', '"%s" has not been entered.'); -define('_VALID_ERROR2', '"%s" character that can be used are A-Z, a-z ,0-9, _ and -.'); -define('_VALID_ERROR3', '"%s" character that can be used are A-Z, a-z ,0-9 and _.'); -define('_VALID_ERROR4', 'It contains characters that can not be used to "Blog Short Name". (Characters that can be used: A-Z, a-z and 0-9, blank can not be used)'); -define('_VALID_ERROR5', 'Contains characters that can not be used in "Login ID". (A-Z, a-z, 0-9 and the first and last non-blank characters that can be used)'); -define('_VALID_ERROR6', 'Passwords entered do not match.'); -define('_VALID_ERROR7', '"E-mail address" is incorrect.'); -define('_VALID_ERROR8', 'Does not end with a forward slash "/" is "%s".'); -define('_VALID_ERROR9', 'Does not end with "action.php" the URL of the "%s".'); -define('_VALID_ERROR10', 'Does not end with a forward slash "/" directory path of "%s".'); -define('_VALID_ERROR11', 'Directory path in the "%s" does not exist on the server.'); - -define('_INST_ERROR', 'Failed to install. Please run the installation script again to fix the cause of the following.'); -define('_INST_ERROR1', 'Could not create the database. Please make sure that there is a permission to create.'); -define('_INST_ERROR2', 'Could not find the database. Please make sure that the database exists.'); -define('_INST_ERROR3', 'Database table was trying to create already exists.'); -define('_INST_ERROR4', 'An error occurred execution of the query'); -define('_INST_ERROR5', 'An error occurred during the execution of the "Configuring Members"'); -define('_INST_ERROR6', 'An error occurred during the execution of the "Blog Settings"'); -define('_INST_ERROR7', 'An error occurred during the execution of the "Setting item"'); -define('_INST_ERROR8', 'can not write to the config.php. Once you have the permissions to 666 of config.php, the script will automatically write the configuration information. (Quick Guide to change permissions)'); -define('_INST_ERROR9', 'Could not install the plug-in "%s".'); -define('_INST_ERROR10', 'File "%s" can not be found.'); -define('_INST_ERROR11', 'Theme file "%s" could not be read.'); -define('_INST_ERROR12', 'Could not import the theme "%s".'); - - -// General category -define('_GENERALCAT_NAME', 'General'); -define('_GENERALCAT_DESC', 'Items that do not fit in other categories'); -define('_1ST_POST_TITLE', 'Welcome to Nucleus CMS v4.0'); -define('_1ST_POST', 'This is the first post on your Nucleus CMS. Nucleus offers you the building blocks you need to create a web presence. Whether you want to -create a personal blog, a family page, or an online business site, Nucleus CMS can help you achieve your goals.

We\\\'ve loaded this first entry with links and information to get you started. Though you can delete this entry, it will eventually scroll off the main page as you add content to your site. Add your comments while you learn to work with Nucleus CMS, or bookmark this page so you can come back to it when you need to.'); -define('_1ST_POST2', 'Home - nucleuscms.org
Welcome to the world of Nucleus CMS. In 2001 a set of PHP scripts were let loose on the open Internet. Those scripts, which took user-generated data and used it to dynamically create html pages, contained the ideas and the algorithms that are the core of today\\\'s Nucleus CMS. Though Nucleus CMS 3.5 is far more flexible and powerful than the scripts from which it emerged, it still expresses the values that guided its birth: flexibility, security, and computational elegance.

Thanks to an international community of sophisticated developers and designers, Nucleus CMS remains simple enough for anyone to learn, and expandable enough to allow you to build almost any website you can imagine. Nucleus CMS lets you integrate text, images, and user comments in a seamless package that will make your web presence as serious, professional, personal, or fun as you want it to be. We hope you enjoy its power.

Documentation - docs.nucleuscms.org
The install process places a user and a developer documentation on your web server. Pop-up help is available throughout the administration area to assist you in maintaining and customizing your site. When in the Nucleus CMS admin area, click on this symbol help icon for context-sensitive help. You can also read this documentation online under docs.nucleuscms.org.

Frequently Asked Questions - faq.nucleuscms.org
If you need more information about managing, extending or troubleshooting your Nucleus CMS the Nucleus FAQ is the first place to search information. Over 170 frequently asked questions are answered from experienced Nucleus users.

Support - forum.nucleuscms.org
Should you require assistance, please don\\\'t hesitate to join the 6,800+ registered users on our forums. With its built-in search capability of the 73,000+ posted articles, your answers are just a few clicks away. Remember: almost any question you think of has already been asked on the forums, and almost anything you want to do with Nucleus has been tried and explained there. Be sure to check them out.

Demonstration - demo.nucleuscms.org
Want to play around, test changes or tell a friend or relative about Nucleus CMS? Visit our live demo site.

Skins - skins.nucleuscms.org
The combination of multi-weblogs and skins/templates make for a powerful duo in personalizing your site or designing one for a friend, relative or business client. Import new skins to change the look of your website, or create your own skins and share them with the Nucleus community! Help designing or modifying skins is only a few clicks away in the Nucleus forums.

Plugins - plugins.nucleuscms.org
Looking to add some extra functionality to the base Nucleus CMS package? Our plugin repository gives you plenty of ways to extend and expand what Nucleus CMS can do; your imagination and creativity are the only limit on how Nucleus CMS can work for you.

Development - dev.nucleuscms.org
If you need more information about the Nucleus development you can find Informations in the developer documents at dev.nucleuscms.org or in the Support Forum. Sourceforge.net graciously hosts our Open Source project page which contains our software downloads and CVS repository.

Donators
We would like to thank these nice people for their support. Thanks all!

Vote for Nucleus CMS
Like Nucleus CMS? Vote for us at HotScripts and opensourceCMS.

License
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.'); +When I input detailed information and set it, please click "Detailed Setting".'); +define('_DB_HEADER', 'Check Database'); +define('_DB_TEXT1', '"Detailed setting" is recommended if used to Nucleus.'); +define('_DB_FIELD1', 'Hostname'); +define('_DB_FIELD1_DESC', '(It is usually localhost)'); +define('_DB_FIELD2', 'Username'); +define('_DB_FIELD2_DESC', '(alphabet, number, _, -)'); +define('_DB_FIELD3', 'Password'); +define('_DB_FIELD4', 'Database'); +define('_DB_FIELD4_DESC', '(alphabet, number, _, -)'); +define('_DB_FIELD5', 'Table Prefix'); +define('_DB_FIELD5_DESC', 'Don\'t usually set this.'); + +// blog settings +define('_SIMPLE_NAVI2', 'I was able to confirm the connection of the database.
Setting Blog and Information of the ADMIN, and please click to "NEXT".'); +define('_BLOG_HEADER', 'Weblog Data'); +define('_BLOG_FIELD1', 'Blog Name'); +define('_BLOG_FIELD2', 'Blog Short Name'); +define('_BLOG_FIELD2_DESC', '(alphabet, number)'); + +// admin settings +define('_ADMIN_HEADER', 'Administrator User'); +define('_ADMIN_FIELD1', 'Manager Name'); +define('_ADMIN_FIELD2', 'Login ID'); +define('_ADMIN_FIELD2_DESC', '(alphabet, number)'); +define('_ADMIN_FIELD3', 'Password'); +define('_ADMIN_FIELD4', 'Password Again'); +define('_ADMIN_FIELD5', 'E-mail Address'); + +// url/path settings +define('_PATH_FIELD1', 'Site URL'); +define('_PATH_FIELD2', 'Admin-area URL'); +define('_PATH_FIELD3', 'Admin-area path'); +define('_PATH_FIELD4', 'Media files URL'); +define('_PATH_FIELD5', 'Media dir path'); +define('_PATH_FIELD6', 'Skin files URL'); +define('_PATH_FIELD7', 'Skin files dir path'); +define('_PATH_FIELD8', 'Plugin files URL'); +define('_PATH_FIELD9', 'Action URL'); + +// detail +define('_DETAIL_NAVI1', 'All fields are mandatory. Optional information can be set from the Nucleus admin-area when installation is completed.'); +define('_DETAIL_HEADER1', 'MySQL Login Data'); +define('_DETAIL_TEXT1', 'Enter your MySQL data below. This install script needs it to be able to create and fill your database tables.'); +define('_DETAIL_HEADER2', 'Directories and URLs'); +define('_DETAIL_TEXT2', 'This install script has attempted to find out the directories and URLs in which Nucleus is installed. Please check the values below and correct if necessary. The URLs and file paths should end with a slash.'); +define('_DETAIL_TEXT3', 'Note: Use absolute paths instead of relative paths.'); +define('_DETAIL_HEADER3', 'Administrator User'); +define('_DETAIL_TEXT4', 'You need to enter some information to create the first user of your site.'); +define('_DETAIL_HEADER4', 'Weblog Data'); +define('_DETAIL_TEXT5', 'Below, you need to enter some information to create a default weblog. The name of this weblog will also be used as name for your site.'); +define('_DETAIL_TEXT6', 'Verify the data above, and click the button below to set up your database tables and initial data. This can take a while, so have patience. ONLY CLICK THE BUTTON ONCE !'); + +// install complete +define('_INST_TEXT', 'Congratulations. The installation was completed!'); +define('_INST_HEADER1', 'New Blog'); +define('_INST_TEXT1', 'Let\'s take a look at once you have created [%s].'); +define('_INST_BUTTON1', 'New Blog'); +define('_INST_HEADER2', 'Management page'); +define('_INST_TEXT2', 'A design change, user addition, the category setting to the management page.'); +define('_INST_BUTTON2', 'Management Page'); +define('_INST_HEADER3', 'Addition of the Blog'); +define('_INST_TEXT3', 'If necessary, you can even add a blog.'); +define('_INST_BUTTON3', 'Add Blog'); +define('_INST_TEXT4', 'Was unable to write to the config.php. Please replace with the following contents.'); +define('_INST_TEXT5', 'Please make sure the config.php permissions if it were a 444. If different, please change the "444".'); + +// errors +define('_DBCONNECT_ERROR', 'Could not connect to MySQL Server.'); +define('_DBVERSION_UNKOWN', 'Indeterminable'); +define('_DBVERSION_TOOLOW', 'You must have MySQL version %s or more at least in the Nucleus.'); + +define('_VALID_ERROR', 'There is an error in your input. Please re-look at the input value to see the error message for each section.'); +define('_VALID_ERROR1', '"%s" has not been entered.'); +define('_VALID_ERROR2', '"%s" character that can be used are A-Z, a-z ,0-9, _ and -.'); +define('_VALID_ERROR3', '"%s" character that can be used are A-Z, a-z ,0-9 and _.'); +define('_VALID_ERROR4', 'It contains characters that can not be used to "Blog Short Name". (Characters that can be used: A-Z, a-z and 0-9, blank can not be used)'); +define('_VALID_ERROR5', 'Contains characters that can not be used in "Login ID". (A-Z, a-z, 0-9 and the first and last non-blank characters that can be used)'); +define('_VALID_ERROR6', 'Passwords entered do not match.'); +define('_VALID_ERROR7', '"E-mail address" is incorrect.'); +define('_VALID_ERROR8', 'Does not end with a forward slash "/" is "%s".'); +define('_VALID_ERROR9', 'Does not end with "action.php" the URL of the "%s".'); +define('_VALID_ERROR10', 'Does not end with a forward slash "/" directory path of "%s".'); +define('_VALID_ERROR11', 'Directory path in the "%s" does not exist on the server.'); + +define('_INST_ERROR', 'Failed to install. Please run the installation script again to fix the cause of the following.'); +define('_INST_ERROR1', 'Could not create the database. Please make sure that there is a permission to create.'); +define('_INST_ERROR2', 'Could not find the database. Please make sure that the database exists.'); +define('_INST_ERROR3', 'Database table was trying to create already exists.'); +define('_INST_ERROR4', 'An error occurred execution of the query'); +define('_INST_ERROR5', 'An error occurred during the execution of the "Configuring Members"'); +define('_INST_ERROR6', 'An error occurred during the execution of the "Blog Settings"'); +define('_INST_ERROR7', 'An error occurred during the execution of the "Setting item"'); +define('_INST_ERROR8', 'can not write to the config.php. Once you have the permissions to 666 of config.php, the script will automatically write the configuration information. (Quick Guide to change permissions)'); +define('_INST_ERROR9', 'Could not install the plug-in "%s".'); +define('_INST_ERROR10', 'File "%s" can not be found.'); +define('_INST_ERROR11', 'Theme file "%s" could not be read.'); +define('_INST_ERROR12', 'Could not import the theme "%s".'); + + +// General category +define('_GENERALCAT_NAME', 'General'); +define('_GENERALCAT_DESC', 'Items that do not fit in other categories'); +define('_1ST_POST_TITLE', 'Welcome to Nucleus CMS v4.0'); +define('_1ST_POST', 'This is the first post on your Nucleus CMS. Nucleus offers you the building blocks you need to create a web presence. Whether you want to +create a personal blog, a family page, or an online business site, Nucleus CMS can help you achieve your goals.

We\\\'ve loaded this first entry with links and information to get you started. Though you can delete this entry, it will eventually scroll off the main page as you add content to your site. Add your comments while you learn to work with Nucleus CMS, or bookmark this page so you can come back to it when you need to.'); +define('_1ST_POST2', 'Home - nucleuscms.org
Welcome to the world of Nucleus CMS. In 2001 a set of PHP scripts were let loose on the open Internet. Those scripts, which took user-generated data and used it to dynamically create html pages, contained the ideas and the algorithms that are the core of today\\\'s Nucleus CMS. Though Nucleus CMS 3.5 is far more flexible and powerful than the scripts from which it emerged, it still expresses the values that guided its birth: flexibility, security, and computational elegance.

Thanks to an international community of sophisticated developers and designers, Nucleus CMS remains simple enough for anyone to learn, and expandable enough to allow you to build almost any website you can imagine. Nucleus CMS lets you integrate text, images, and user comments in a seamless package that will make your web presence as serious, professional, personal, or fun as you want it to be. We hope you enjoy its power.

Documentation - docs.nucleuscms.org
The install process places a user and a developer documentation on your web server. Pop-up help is available throughout the administration area to assist you in maintaining and customizing your site. When in the Nucleus CMS admin area, click on this symbol help icon for context-sensitive help. You can also read this documentation online under docs.nucleuscms.org.

Frequently Asked Questions - faq.nucleuscms.org
If you need more information about managing, extending or troubleshooting your Nucleus CMS the Nucleus FAQ is the first place to search information. Over 170 frequently asked questions are answered from experienced Nucleus users.

Support - forum.nucleuscms.org
Should you require assistance, please don\\\'t hesitate to join the 6,800+ registered users on our forums. With its built-in search capability of the 73,000+ posted articles, your answers are just a few clicks away. Remember: almost any question you think of has already been asked on the forums, and almost anything you want to do with Nucleus has been tried and explained there. Be sure to check them out.

Demonstration - demo.nucleuscms.org
Want to play around, test changes or tell a friend or relative about Nucleus CMS? Visit our live demo site.

Skins - skins.nucleuscms.org
The combination of multi-weblogs and skins/templates make for a powerful duo in personalizing your site or designing one for a friend, relative or business client. Import new skins to change the look of your website, or create your own skins and share them with the Nucleus community! Help designing or modifying skins is only a few clicks away in the Nucleus forums.

Plugins - plugins.nucleuscms.org
Looking to add some extra functionality to the base Nucleus CMS package? Our plugin repository gives you plenty of ways to extend and expand what Nucleus CMS can do; your imagination and creativity are the only limit on how Nucleus CMS can work for you.

Development - dev.nucleuscms.org
If you need more information about the Nucleus development you can find Informations in the developer documents at dev.nucleuscms.org or in the Support Forum. Sourceforge.net graciously hosts our Open Source project page which contains our software downloads and CVS repository.

Donators
We would like to thank these nice people for their support. Thanks all!

Vote for Nucleus CMS
Like Nucleus CMS? Vote for us at HotScripts and opensourceCMS.

License
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.'); diff --git a/install/locales/ja_Jpan_JP.UTF-8.php b/install/locales/ja_Jpan_JP.UTF-8.php index e3dfe38..8b09d9e 100644 --- a/install/locales/ja_Jpan_JP.UTF-8.php +++ b/install/locales/ja_Jpan_JP.UTF-8.php @@ -1,233 +1,239 @@ -詳細な情報を入力して設定する場合は「詳細情報」をクリックしてください。'); -define('_DB_HEADER', 'データベース接続'); -define('_DB_TEXT1', 'Nucleusになれているなら、詳細設定がおすすめです。'); -define('_DB_FIELD1', 'ホスト名'); -define('_DB_FIELD1_DESC', '(通常は localhost)'); -define('_DB_FIELD2', 'ユーザー名'); -define('_DB_FIELD2_DESC', '(半角英数 , _ , - )'); -define('_DB_FIELD3', 'パスワード'); -define('_DB_FIELD4', 'データベース名'); -define('_DB_FIELD4_DESC', '(半角英数 , _ , - )'); -define('_DB_FIELD5', 'プリフィックス'); -define('_DB_FIELD5_DESC', '通常は空白で結構です'); - -// blog settings -define('_SIMPLE_NAVI2', 'データベースの接続が確認できました。
ブログと管理者の設定をして「次へ」をクリックしてください。'); -define('_BLOG_HEADER', 'ブログ設定'); -define('_BLOG_FIELD1', 'ブログ名'); -define('_BLOG_FIELD2', 'ブログ短縮名'); -define('_BLOG_FIELD2_DESC', '(半角英数)'); - -// admin settings -define('_ADMIN_HEADER', '管理者の情報'); -define('_ADMIN_FIELD1', '管理者名'); -define('_ADMIN_FIELD2', 'ログインID'); -define('_ADMIN_FIELD2_DESC', '(半角英数)'); -define('_ADMIN_FIELD3', 'パスワード'); -define('_ADMIN_FIELD4', 'パスワード:確認'); -define('_ADMIN_FIELD5', 'メールアドレス'); - -// url/path settings -define('_PATH_FIELD1', 'サイトのURL'); -define('_PATH_FIELD2', '管理URL'); -define('_PATH_FIELD3', '管理パス'); -define('_PATH_FIELD4', 'メディアURL'); -define('_PATH_FIELD5', 'メディアパス'); -define('_PATH_FIELD6', 'スキンファイルURL'); -define('_PATH_FIELD7', 'スキンファイルパス'); -define('_PATH_FIELD8', 'プラグインURL'); -define('_PATH_FIELD9', 'アクションURL'); - -// detail -define('_DETAIL_NAVI1', 'すべての項目を入力してください。オプション設定は、インストール完了後Nucleusの管理ページから変更できます。'); -define('_DETAIL_HEADER1', 'MySQLのログイン情報'); -define('_DETAIL_TEXT1', 'データベースのログイン情報を入力してください。この情報が分からない場合は、システム管理者かホスティング元に確認をとってください。'); -define('_DETAIL_HEADER2', 'ディレクトリとURL'); -define('_DETAIL_TEXT2', 'ディレクトリとURLを下記の設定でインストールします。特殊なディレクトリ構成で運用したい場合は、ここで変更できます。
ディレクトリのパス及びURLはスラッシュ「/」で閉じてください。'); -define('_DETAIL_TEXT3', 'Note: パスは相対パスではなく絶対パスを使用してください。'); -define('_DETAIL_HEADER3', '管理権限をもつユーザー'); -define('_DETAIL_TEXT4', 'サイトの最初のユーザーを作成するための情報を入力してください。'); -define('_DETAIL_HEADER4', 'ブログ設定'); -define('_DETAIL_TEXT5', 'デフォルトのブログを作成するための情報を入力してください。このブログの名前は、サイト名としても利用されます。'); -define('_DETAIL_TEXT6', '上に書いてきたデータが正しいか確かめてください。よければデータベース・テーブルと最初のデータを設定するために下のボタンを押してください。少し時間がかかるかもしれませんがご辛抱を。ボタンをクリックするのは一回だけにしてください。'); - -// install complete -define('_INST_TEXT', 'おめでとうございます。インストールは完了しました!'); -define('_INST_HEADER1', '作成したブログ'); -define('_INST_TEXT1', 'さっそく作成した "%s" を見てみましょう。'); -define('_INST_BUTTON1', 'ブログへ'); -define('_INST_HEADER2', '管理ページ'); -define('_INST_TEXT2', 'デザイン変更、ユーザー追加、カテゴリ設定は管理ページへ。'); -define('_INST_BUTTON2', '管理ページ'); -define('_INST_HEADER3', 'ブログの追加'); -define('_INST_TEXT3', '必要であれば、さらにブログを追加できます。'); -define('_INST_BUTTON3', '追加作成'); -define('_INST_TEXT4', 'config.phpへの書き込みが行えませんでした。以下の内容で書き換えてください。'); -define('_INST_TEXT5', 'config.phpのパーミッションが"444"であるか確認してください。もし、違うならば"444"に変更してください。'); - -// errors -define('_DBCONNECT_ERROR', 'MySQL Serverに接続できませんでした。'); -define('_DBVERSION_UNKOWN', '判別不能'); -define('_DBVERSION_TOOLOW', 'Nucleusでは少なくともバージョン "%s" 以上のMySQLが必要です。'); - -define('_VALID_ERROR', '入力内容に誤りがあります。各セクションのエラーメッセージを確認して入力値を見なおしてください。'); -define('_VALID_ERROR1', '"%s" が入力されていません。'); -define('_VALID_ERROR2', '"%s" に使用できる文字は半角の A-Z、a-z、0-9、_(アンダーライン)、-(ハイフン)のみです。'); -define('_VALID_ERROR3', '"%s" に使用できる文字は半角の A-Z、a-z、0-9、_(アンダーライン)のみです。'); -define('_VALID_ERROR4', '"ブログの短縮名(略称)" に使用できる文字は A-Z、a-z、0-9(半角英数)のみです。'); -define('_VALID_ERROR5', '"ログインID" に使用できる文字は A-Z、a-z、0-9(半角英数)のみです。ただし、最初と最後以外では半角スペースも使用できます。'); -define('_VALID_ERROR6', '入力された二つのパスワードが一致しません。'); -define('_VALID_ERROR7', '"メールアドレス" が不正です。'); -define('_VALID_ERROR8', '"%s" が"/(スラッシュ)"で終わっていません。'); -define('_VALID_ERROR9', '"%s" のアドレスが"action.php"で終わっていません。'); -define('_VALID_ERROR10', '"%s" のディレクトリパスが"/(スラッシュ)"で終わっていません。'); -define('_VALID_ERROR11', '"%s" のディレクトリパスがサーバ上に存在しません。'); - -define('_INST_ERROR', 'インストールに失敗しました。以下の原因を解決して再度インストールスクリプトを実行してください。'); -define('_INST_ERROR1', 'データベースを作成できませんでした。作成の権限があるかどうか確認してください。'); -define('_INST_ERROR2', 'データベースを見つけられませんでした。データベースが存在するか確認してください。'); -define('_INST_ERROR3', '作成しようとしたテーブルが既に存在しています。'); -define('_INST_ERROR4', 'クエリの実行中にエラーが発生しました'); -define('_INST_ERROR5', '"メンバー設定" の実行中にエラーが発生しました'); -define('_INST_ERROR6', '"ブログ設定" の実行中にエラーが発生しました'); -define('_INST_ERROR7', '"アイテム設定" の実行中にエラーが発生しました'); -define('_INST_ERROR8', 'config.php への書き込みができません。config.php のパーミッションを666にしておけば、スクリプトが自動で設定情報を書き込みます。(パーミッション変更の簡易ガイド)。'); -define('_INST_ERROR9', 'プラグイン "%s" をインストールできませんでした。'); -define('_INST_ERROR10', 'ファイル "%s" が見つかりません。'); -define('_INST_ERROR11', 'テーマファイル "%s" が読み込めませんでした。'); -define('_INST_ERROR12', 'テーマ "%s" をインポートできませんでした。'); - - -// General category -define('_GENERALCAT_NAME', '総合'); -define('_GENERALCAT_DESC', '投稿した記事に合うカテゴリが無い時にこのカテゴリを使用すると良いでしょう'); -define('_1ST_POST_TITLE', 'Nucleus CMS バージョン4.00 へようこそ'); -define('_1ST_POST', 'ウェブサイトの作成を補助する積み木がここにあります。それは心躍るブログになるかもしれませんし、見る人を和ませる家族のサイトになるかもしれませんし、実り多い趣味のサイトになるかもしれません。あるいは現在のあなたには想像がつかないものになることだってあるでしょう。
-
用途が思いつきませんでしたか? それならここへ来て正解です。なぜならあなた同様私たちにもわからないのですから。'); -define('_1ST_POST2', 'これはサイトにおける最初のエントリーです。スタートを切りやすいように、リンクと情報を入れておきました。
-
-この記事を削除することもできますが、どちらにせよ記事を追加していくことによってやがてメインページからは見えなくなります。Nucleusを扱ううちに生じたメモをコメントとして追加し、将来アクセスできるようにこのページをブックマークしておくのも手です。
-
-リンク
-
-Nucleus CMSの本家と日本語公式ページ。
-
-Nucleus CMSのSourceForgeプロジェクト(日本版)ページ。
-
-Nucleus CMSのプラグイン倉庫と日本語のリストページ。
-
-ドキュメント - docs.nucleuscms.org
-
-NucleusのFAQ(よくある質問集)(原文)ページ。
-
-インストール方法等はユーザー向けと開発者向け文書がファイルに含まれています。
-
-ポップアップヘルプが管理エリアのいたるところにあり、サイトのカスタマイズやデザインを手助けしてくれることでしょう。
-
-一度用意されているドキュメントに目を通したら、Wiki(日本版)を訪れてください。ユーザーの書いたハウツーや小技が掲載されています。
-
-サポート
-
-forum.nucleuscms.org(本家)
-japan.nucleuscms.org/bb/(日本版)
-
-moderatorsとサポートフォーラムで活動する全てのボランティアに感謝します。
-
-- admun - Ottawa, ON, Canada
-- anand - Bangalore, India
-- hcgtv - Miami, Florida, USA
-- ikeizer - Maastricht
-- moraes - Brazil
-- roel - The Netherlands
-- TeRanEX - Ekeren, Antwerp, Belgium
-- Trent - Alberta, Canada
-- xiffy - Deventer
-
-もし手助けが必要なら、1400を超える登録ユーザーのいる私たちのフォーラムに参加してください。23,000を超える投稿された記事を検索できるようになっておりますので、求める答えに数回のクリックでたどり着けるかもしれません。
-
-カスタマイズ - skins.nucleuscms.org
-
-マルチウェブログとスキン/テンプレートの組み合わせは強力な相乗効果を生み出します。個人的なサイト作成、友人や親戚あるいはクライアントに対するサイトデザインいずれに対してもです。
-
-636の登録されたNucleusで運用されているサイト(日本版)の中から特色あるサイトをサンプルとしてご紹介します。
-
-個人サイト
-- bloggard.com - The Adventures of Bloggard
-- yetanotherblog.de - Yet Another Blog
-
-趣味、旅行、ニュースサイト
-- adrenalinsports.nl - Extreme sports
-- groningen-info.de - Neues aus Groningen. Fr Leute aus Duitsland.
-
-Nucleus Developer Network - dev.nucleuscms.org
-
-NUDNは、開発者サイトおよびプログラミングリソースのハブです。
-
-NUDN satellite sites, handles, location and UTC offset:
-- karma - Izegem +02
-- admun - Ottawa -04
-- TeRanEX - Ekeren +02
-
-Sourceforge.net には私たちの SVNリポジトリ をホストをして頂いています。
-
-遊んだり、テスト更新を行ってみたい場合は、demo.nucleuscms.orgにあるデモサイトを訪れてみてください。
-
-Not sure what plugins to use, visit the showcase site where you can see plugins at play in their native habitat.
-
-Then visit the plugin repository at plugins.nucleuscms.org for download and installation instructions.
-
-寄付者一覧
-
-素晴らしい人々による援助感謝を捧げます。ありがとう!
-
-Nucleus CMS への投票
-
-Nucleusが気に入りましたか? HotScriptsやopensourceCMSでの投票をお願いします。
-
-ライセンス
-
-私たちがフリー・ソフトウェアについて口にする場合は自由のことに言及しているのであって、価格のことではありません。私たちのGNU General Public Licenses(一般公有使用許諾書)(日本語訳(参考)と概要)は、フリー・ソフトウェアの複製物を自由に頒布できること(そして、望むならこのサービスに対して対価を請求できること)、ソース・コードを実際に受け取るか希望しさえすれば入手することが可能であること、入手したソフトウェアを変更したり新しいフリー・プログラムの一部として使用できること、以上の各内容を行なうことができるということをユーザ自身が知っていることを実現できるようにデザインされています。'); +詳細な情報を入力して設定する場合は「詳細情報」をクリックしてください。'); +define('_DB_HEADER', 'データベース接続'); +define('_DB_TEXT1', 'Nucleusになれているなら、詳細設定がおすすめです。'); +define('_DB_FIELD1', 'ホスト名'); +define('_DB_FIELD1_DESC', '(通常は localhost)'); +define('_DB_FIELD2', 'ユーザー名'); +define('_DB_FIELD2_DESC', '(半角英数 , _ , - )'); +define('_DB_FIELD3', 'パスワード'); +define('_DB_FIELD4', 'データベース名'); +define('_DB_FIELD4_DESC', '(半角英数 , _ , - )'); +define('_DB_FIELD5', 'プリフィックス'); +define('_DB_FIELD5_DESC', '通常は空白で結構です'); + +// blog settings +define('_SIMPLE_NAVI2', 'データベースの接続が確認できました。
ブログと管理者の設定をして「次へ」をクリックしてください。'); +define('_BLOG_HEADER', 'ブログ設定'); +define('_BLOG_FIELD1', 'ブログ名'); +define('_BLOG_FIELD2', 'ブログ短縮名'); +define('_BLOG_FIELD2_DESC', '(半角英数)'); + +// admin settings +define('_ADMIN_HEADER', '管理者の情報'); +define('_ADMIN_FIELD1', '管理者名'); +define('_ADMIN_FIELD2', 'ログインID'); +define('_ADMIN_FIELD2_DESC', '(半角英数)'); +define('_ADMIN_FIELD3', 'パスワード'); +define('_ADMIN_FIELD4', 'パスワード:確認'); +define('_ADMIN_FIELD5', 'メールアドレス'); + +// url/path settings +define('_PATH_FIELD1', 'サイトのURL'); +define('_PATH_FIELD2', '管理URL'); +define('_PATH_FIELD3', '管理パス'); +define('_PATH_FIELD4', 'メディアURL'); +define('_PATH_FIELD5', 'メディアパス'); +define('_PATH_FIELD6', 'スキンファイルURL'); +define('_PATH_FIELD7', 'スキンファイルパス'); +define('_PATH_FIELD8', 'プラグインURL'); +define('_PATH_FIELD9', 'アクションURL'); + +// detail +define('_DETAIL_NAVI1', 'すべての項目を入力してください。オプション設定は、インストール完了後Nucleusの管理ページから変更できます。'); +define('_DETAIL_HEADER1', 'MySQLのログイン情報'); +define('_DETAIL_TEXT1', 'データベースのログイン情報を入力してください。この情報が分からない場合は、システム管理者かホスティング元に確認をとってください。'); +define('_DETAIL_HEADER2', 'ディレクトリとURL'); +define('_DETAIL_TEXT2', 'ディレクトリとURLを下記の設定でインストールします。特殊なディレクトリ構成で運用したい場合は、ここで変更できます。
ディレクトリのパス及びURLはスラッシュ「/」で閉じてください。'); +define('_DETAIL_TEXT3', 'Note: パスは相対パスではなく絶対パスを使用してください。'); +define('_DETAIL_HEADER3', '管理権限をもつユーザー'); +define('_DETAIL_TEXT4', 'サイトの最初のユーザーを作成するための情報を入力してください。'); +define('_DETAIL_HEADER4', 'ブログ設定'); +define('_DETAIL_TEXT5', 'デフォルトのブログを作成するための情報を入力してください。このブログの名前は、サイト名としても利用されます。'); +define('_DETAIL_TEXT6', '上に書いてきたデータが正しいか確かめてください。よければデータベース・テーブルと最初のデータを設定するために下のボタンを押してください。少し時間がかかるかもしれませんがご辛抱を。ボタンをクリックするのは一回だけにしてください。'); + +// install complete +define('_INST_TEXT', 'おめでとうございます。インストールは完了しました!'); +define('_INST_HEADER1', '作成したブログ'); +define('_INST_TEXT1', 'さっそく作成した "%s" を見てみましょう。'); +define('_INST_BUTTON1', 'ブログへ'); +define('_INST_HEADER2', '管理ページ'); +define('_INST_TEXT2', 'デザイン変更、ユーザー追加、カテゴリ設定は管理ページへ。'); +define('_INST_BUTTON2', '管理ページ'); +define('_INST_HEADER3', 'ブログの追加'); +define('_INST_TEXT3', '必要であれば、さらにブログを追加できます。'); +define('_INST_BUTTON3', '追加作成'); +define('_INST_TEXT4', 'config.phpへの書き込みが行えませんでした。以下の内容で書き換えてください。'); +define('_INST_TEXT5', 'config.phpのパーミッションが"444"であるか確認してください。もし、違うならば"444"に変更してください。'); + +// errors +define('_DBCONNECT_ERROR', 'MySQL Serverに接続できませんでした。'); +define('_DBVERSION_UNKOWN', '判別不能'); +define('_DBVERSION_TOOLOW', 'Nucleusでは少なくともバージョン "%s" 以上のMySQLが必要です。'); + +define('_VALID_ERROR', '入力内容に誤りがあります。各セクションのエラーメッセージを確認して入力値を見なおしてください。'); +define('_VALID_ERROR1', '"%s" が入力されていません。'); +define('_VALID_ERROR2', '"%s" に使用できる文字は半角の A-Z、a-z、0-9、_(アンダーライン)、-(ハイフン)のみです。'); +define('_VALID_ERROR3', '"%s" に使用できる文字は半角の A-Z、a-z、0-9、_(アンダーライン)のみです。'); +define('_VALID_ERROR4', '"ブログの短縮名(略称)" に使用できる文字は A-Z、a-z、0-9(半角英数)のみです。'); +define('_VALID_ERROR5', '"ログインID" に使用できる文字は A-Z、a-z、0-9(半角英数)のみです。ただし、最初と最後以外では半角スペースも使用できます。'); +define('_VALID_ERROR6', '入力された二つのパスワードが一致しません。'); +define('_VALID_ERROR7', '"メールアドレス" が不正です。'); +define('_VALID_ERROR8', '"%s" が"/(スラッシュ)"で終わっていません。'); +define('_VALID_ERROR9', '"%s" のアドレスが"action.php"で終わっていません。'); +define('_VALID_ERROR10', '"%s" のディレクトリパスが"/(スラッシュ)"で終わっていません。'); +define('_VALID_ERROR11', '"%s" のディレクトリパスがサーバ上に存在しません。'); + +define('_INST_ERROR', 'インストールに失敗しました。以下の原因を解決して再度インストールスクリプトを実行してください。'); +define('_INST_ERROR1', 'データベースを作成できませんでした。作成の権限があるかどうか確認してください。'); +define('_INST_ERROR2', 'データベースを見つけられませんでした。データベースが存在するか確認してください。'); +define('_INST_ERROR3', '作成しようとしたテーブルが既に存在しています。'); +define('_INST_ERROR4', 'クエリの実行中にエラーが発生しました'); +define('_INST_ERROR5', '"メンバー設定" の実行中にエラーが発生しました'); +define('_INST_ERROR6', '"ブログ設定" の実行中にエラーが発生しました'); +define('_INST_ERROR7', '"アイテム設定" の実行中にエラーが発生しました'); +define('_INST_ERROR8', 'config.php への書き込みができません。config.php のパーミッションを666にしておけば、スクリプトが自動で設定情報を書き込みます。(パーミッション変更の簡易ガイド)。'); +define('_INST_ERROR9', 'プラグイン "%s" をインストールできませんでした。'); +define('_INST_ERROR10', 'ファイル "%s" が見つかりません。'); +define('_INST_ERROR11', 'テーマファイル "%s" が読み込めませんでした。'); +define('_INST_ERROR12', 'テーマ "%s" をインポートできませんでした。'); + + +// General category +define('_GENERALCAT_NAME', '総合'); +define('_GENERALCAT_DESC', '投稿した記事に合うカテゴリが無い時にこのカテゴリを使用すると良いでしょう'); +define('_1ST_POST_TITLE', 'Nucleus CMS バージョン4.00 へようこそ'); +define('_1ST_POST', 'ウェブサイトの作成を補助する積み木がここにあります。それは心躍るブログになるかもしれませんし、見る人を和ませる家族のサイトになるかもしれませんし、実り多い趣味のサイトになるかもしれません。あるいは現在のあなたには想像がつかないものになることだってあるでしょう。
+
用途が思いつきませんでしたか? それならここへ来て正解です。なぜならあなた同様私たちにもわからないのですから。'); +define('_1ST_POST2', 'これはサイトにおける最初のエントリーです。スタートを切りやすいように、リンクと情報を入れておきました。
+
+この記事を削除することもできますが、どちらにせよ記事を追加していくことによってやがてメインページからは見えなくなります。Nucleusを扱ううちに生じたメモをコメントとして追加し、将来アクセスできるようにこのページをブックマークしておくのも手です。
+
+リンク
+
+Nucleus CMSの本家と日本語公式ページ。
+
+Nucleus CMSのSourceForgeプロジェクト(日本版)ページ。
+
+Nucleus CMSのプラグイン倉庫と日本語のリストページ。
+
+ドキュメント - docs.nucleuscms.org
+
+NucleusのFAQ(よくある質問集)(原文)ページ。
+
+インストール方法等はユーザー向けと開発者向け文書がファイルに含まれています。
+
+ポップアップヘルプが管理エリアのいたるところにあり、サイトのカスタマイズやデザインを手助けしてくれることでしょう。
+
+一度用意されているドキュメントに目を通したら、Wiki(日本版)を訪れてください。ユーザーの書いたハウツーや小技が掲載されています。
+
+サポート
+
+forum.nucleuscms.org(本家)
+japan.nucleuscms.org/bb/(日本版)
+
+moderatorsとサポートフォーラムで活動する全てのボランティアに感謝します。
+
+- admun - Ottawa, ON, Canada
+- anand - Bangalore, India
+- hcgtv - Miami, Florida, USA
+- ikeizer - Maastricht
+- moraes - Brazil
+- roel - The Netherlands
+- TeRanEX - Ekeren, Antwerp, Belgium
+- Trent - Alberta, Canada
+- xiffy - Deventer
+
+もし手助けが必要なら、1400を超える登録ユーザーのいる私たちのフォーラムに参加してください。23,000を超える投稿された記事を検索できるようになっておりますので、求める答えに数回のクリックでたどり着けるかもしれません。
+
+カスタマイズ - skins.nucleuscms.org
+
+マルチウェブログとスキン/テンプレートの組み合わせは強力な相乗効果を生み出します。個人的なサイト作成、友人や親戚あるいはクライアントに対するサイトデザインいずれに対してもです。
+
+636の登録されたNucleusで運用されているサイト(日本版)の中から特色あるサイトをサンプルとしてご紹介します。
+
+個人サイト
+- bloggard.com - The Adventures of Bloggard
+- yetanotherblog.de - Yet Another Blog
+
+趣味、旅行、ニュースサイト
+- adrenalinsports.nl - Extreme sports
+- groningen-info.de - Neues aus Groningen. Fr Leute aus Duitsland.
+
+Nucleus Developer Network - dev.nucleuscms.org
+
+NUDNは、開発者サイトおよびプログラミングリソースのハブです。
+
+NUDN satellite sites, handles, location and UTC offset:
+- karma - Izegem +02
+- admun - Ottawa -04
+- TeRanEX - Ekeren +02
+
+Sourceforge.net には私たちの SVNリポジトリ をホストをして頂いています。
+
+遊んだり、テスト更新を行ってみたい場合は、demo.nucleuscms.orgにあるデモサイトを訪れてみてください。
+
+Not sure what plugins to use, visit the showcase site where you can see plugins at play in their native habitat.
+
+Then visit the plugin repository at plugins.nucleuscms.org for download and installation instructions.
+
+寄付者一覧
+
+素晴らしい人々による援助感謝を捧げます。ありがとう!
+
+Nucleus CMS への投票
+
+Nucleusが気に入りましたか? HotScriptsやopensourceCMSでの投票をお願いします。
+
+ライセンス
+
+私たちがフリー・ソフトウェアについて口にする場合は自由のことに言及しているのであって、価格のことではありません。私たちのGNU General Public Licenses(一般公有使用許諾書)(日本語訳(参考)と概要)は、フリー・ソフトウェアの複製物を自由に頒布できること(そして、望むならこのサービスに対して対価を請求できること)、ソース・コードを実際に受け取るか希望しさえすれば入手することが可能であること、入手したソフトウェアを変更したり新しいフリー・プログラムの一部として使用できること、以上の各内容を行なうことができるということをユーザ自身が知っていることを実現できるようにデザインされています。'); diff --git a/install/styles/inst.css b/install/styles/inst.css index c4c31df..8b74b5f 100644 --- a/install/styles/inst.css +++ b/install/styles/inst.css @@ -1,228 +1,228 @@ -/* - * style sheet for installer - * - * $Id: -*/ - -@charset 'UTF-8'; -/* CSS Document */ - -/* Layout */ -body{ - margin:0; - padding:0; - text-align:center; - color:#666; -} -#header{ - width: 100%; - height:40px; - background:#000; - position: fixed; - top:0; - left:0; -} -#container,#container_detailed,#footer,#navigation{ - margin:0 auto; - text-align:left; - border-width:0 1px; -} -#navigation{ - width:800px; - height:40px; -} -#container,#container_detailed{ - width:550px; - padding:40px 20px 0 30px; -} -#footer{ - width:600px; -} - -/* Common Settings */ -p{ - margin:20px 0; -} -img{ - border:none; -} -a{ - text-decoration:none; -} -pre{ - font-size: small; - line-height: 1em; - background-color:#eee; - border:1px solid gray; - padding: 2px; -} -.err{ - display:block; - color:#c00; -} - -/* Top navigation */ -#navigation h1{ - width:120px; - height:35px; - margin:0 30px 0 0; - padding:4px 0 1px 0; - float:left; -} -#navigation ul{ - margin:0 100px 0 0; - padding:18px 0 2px 0; - height:20px; - list-style-type:none; -} -#navigation li{ - float:left; - font-size:93%; - height:20px; -} -#navigation li.rightbox{ - float:right; -} -#navigation li,#navigation a{ - color:#dedede; -} -#navigation li.gry{ - color:#787878; -} -#navigation a:hover{ - color:#fff; -} - -/* Content */ -#container h2,#container_detailed h2{ - line-height:20px; - height:20px; - margin:0 -20px 0 -30px; - padding:6px 0 4px 35px; - background:url("nuc_h2_bk.png") 4px 4px no-repeat #d0d0d0; - font-size:136%; - color:#454545; -} - -/* Form table */ -.prt table{ - width: 100%; - margin-bottom:20px; -} -.prt table th{ - font-size:99%; - text-align:right; - width:135px; - height:40px; -} -.prt table th .nam{ - margin:5px 0 0 0; - padding:5px 0 0 0; - height:15px; - line-height:15px; - font-weight:bold; - color:#454545; -} -.prt table th .sub{ - display:block; - margin:0; - padding:0 0 5px 0; - height:10px; - line-height:10px; - font-size:65%; - font-weight:normal; - color:#666; -} -.prt table td input{ - width:390px; - height:35px; - margin:0 0 0 5px; - font-size:182%; - font-weight:bold; - color:#333; - background:url("nuc_input_bk.png") no-repeat; - border:1px solid #999; - border-right-color:#ccc; - border-bottom-color:#ccc; -} - -#container_detailed .prt table td input{ - height:25px; - margin:0 0 0 5px; - font-size:122%; - font-weight:normal; - color:#000; -} - -/* Select */ -.prt select{ - width:510px; - height:35px; - line-height:35px; - margin:0 20px 10px 0; - font-size:152%; - font-weight:bold; - color:#333; - border:1px solid #999; - border-left-color:#ccc; - border-top-color:#ccc; - background:url("nuc_input_bk.png") no-repeat; -} - -#container_detailed .prt select{ - height:25px; - line-height:25px; - margin:0 20px 10px 0; - font-size:122%; -} - -/* Button */ -.prt .sbt{ - height:40px; - margin:10px 0; - text-align:center; -} -.prt .sbt .sbt_sqr,.prt .sbt .sbt_arw{ - height:35px; - border:none; - background:#000; - color:#dedede; - font-size:136%; - font-weight:bold; -} -.prt .sbt .sbt_sqr{ - padding:0 20px; - margin-right:5px; - border-radius:5px; -} -.prt .sbt .sbt_arw{ - padding:0 30px 0 20px; - border-radius:5px 0 0 5px; - background:url("nuc_but_bk_03.png") right top no-repeat #000; -} -.prt .sbt .sbt_sqr:hover{ - color:#ffde00; - background:#292929; -} -.prt .sbt .sbt_arw:hover{ - color:#ffde00; - background:url("nuc_but_bk_03.png") right top no-repeat #292929; -} - -/* Text */ -#config_text{ - width:100%; - height:50px; - border:1px solid gray; -} - -/* Footer */ -#footer{ - border-top:1px solid #999; - text-align:right; - height:25px; - margin-top:10px; - padding:5px 10px 0 0; - font-size:77%; -} - +/* + * style sheet for installer + * + * $Id: +*/ + +@charset 'UTF-8'; +/* CSS Document */ + +/* Layout */ +body{ + margin:0; + padding:0; + text-align:center; + color:#666; +} +#header{ + width: 100%; + height:40px; + background:#000; + position: fixed; + top:0; + left:0; +} +#container,#container_detailed,#footer,#navigation{ + margin:0 auto; + text-align:left; + border-width:0 1px; +} +#navigation{ + width:800px; + height:40px; +} +#container,#container_detailed{ + width:550px; + padding:40px 20px 0 30px; +} +#footer{ + width:600px; +} + +/* Common Settings */ +p{ + margin:20px 0; +} +img{ + border:none; +} +a{ + text-decoration:none; +} +pre{ + font-size: small; + line-height: 1em; + background-color:#eee; + border:1px solid gray; + padding: 2px; +} +.err{ + display:block; + color:#c00; +} + +/* Top navigation */ +#navigation h1{ + width:120px; + height:35px; + margin:0 30px 0 0; + padding:4px 0 1px 0; + float:left; +} +#navigation ul{ + margin:0 100px 0 0; + padding:18px 0 2px 0; + height:20px; + list-style-type:none; +} +#navigation li{ + float:left; + font-size:93%; + height:20px; +} +#navigation li.rightbox{ + float:right; +} +#navigation li,#navigation a{ + color:#dedede; +} +#navigation li.gry{ + color:#787878; +} +#navigation a:hover{ + color:#fff; +} + +/* Content */ +#container h2,#container_detailed h2{ + line-height:20px; + height:20px; + margin:0 -20px 0 -30px; + padding:6px 0 4px 35px; + background:url("nuc_h2_bk.png") 4px 4px no-repeat #d0d0d0; + font-size:136%; + color:#454545; +} + +/* Form table */ +.prt table{ + width: 100%; + margin-bottom:20px; +} +.prt table th{ + font-size:99%; + text-align:right; + width:135px; + height:40px; +} +.prt table th .nam{ + margin:5px 0 0 0; + padding:5px 0 0 0; + height:15px; + line-height:15px; + font-weight:bold; + color:#454545; +} +.prt table th .sub{ + display:block; + margin:0; + padding:0 0 5px 0; + height:10px; + line-height:10px; + font-size:65%; + font-weight:normal; + color:#666; +} +.prt table td input{ + width:390px; + height:35px; + margin:0 0 0 5px; + font-size:182%; + font-weight:bold; + color:#333; + background:url("nuc_input_bk.png") no-repeat; + border:1px solid #999; + border-right-color:#ccc; + border-bottom-color:#ccc; +} + +#container_detailed .prt table td input{ + height:25px; + margin:0 0 0 5px; + font-size:122%; + font-weight:normal; + color:#000; +} + +/* Select */ +.prt select{ + width:510px; + height:35px; + line-height:35px; + margin:0 20px 10px 0; + font-size:152%; + font-weight:bold; + color:#333; + border:1px solid #999; + border-left-color:#ccc; + border-top-color:#ccc; + background:url("nuc_input_bk.png") no-repeat; +} + +#container_detailed .prt select{ + height:25px; + line-height:25px; + margin:0 20px 10px 0; + font-size:122%; +} + +/* Button */ +.prt .sbt{ + height:40px; + margin:10px 0; + text-align:center; +} +.prt .sbt .sbt_sqr,.prt .sbt .sbt_arw{ + height:35px; + border:none; + background:#000; + color:#dedede; + font-size:136%; + font-weight:bold; +} +.prt .sbt .sbt_sqr{ + padding:0 20px; + margin-right:5px; + border-radius:5px; +} +.prt .sbt .sbt_arw{ + padding:0 30px 0 20px; + border-radius:5px 0 0 5px; + background:url("nuc_but_bk_03.png") right top no-repeat #000; +} +.prt .sbt .sbt_sqr:hover{ + color:#ffde00; + background:#292929; +} +.prt .sbt .sbt_arw:hover{ + color:#ffde00; + background:url("nuc_but_bk_03.png") right top no-repeat #292929; +} + +/* Text */ +#config_text{ + width:100%; + height:50px; + border:1px solid gray; +} + +/* Footer */ +#footer{ + border-top:1px solid #999; + text-align:right; + height:25px; + margin-top:10px; + padding:5px 10px 0 0; + font-size:77%; +} + diff --git a/license.txt b/license.txt index 13a56b1..dcfa4c2 100644 --- a/license.txt +++ b/license.txt @@ -1,340 +1,340 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/nucleus/bookmarklet.php b/nucleus/bookmarklet.php index 6278c97..836b920 100644 --- a/nucleus/bookmarklet.php +++ b/nucleus/bookmarklet.php @@ -25,11 +25,32 @@ $CONF['UsingAdminArea'] = 1; // include all classes and config data include('../config.php'); +<<<<<<< HEAD +======= +// get skin object +$skinid = $member->bookmarklet; +if ( !Skin::existsID($skinid) ) +{ + $skinid = $CONF['BookmarkletSkin']; + if ( !Skin::existsID($skinid) ) + { + sendContentType('text/html'); + echo _ERROR_SKIN; + exit; + } +} +$skin =& $manager->getSkin($skinid, 'AdminActions', 'AdminSkin'); + +>>>>>>> skinnable-master // check logged-in or pass through $action = requestVar('action'); if ( !$member->isLoggedIn() ) { +<<<<<<< HEAD bm_loginAndPassThrough($action); +======= + bm_loginAndPassThrough($skin, $action); +>>>>>>> skinnable-master exit; } else if ( $action == 'login') @@ -49,16 +70,19 @@ else if ( $action == '' ) $action = 'add'; } +<<<<<<< HEAD // send HTTP 1.1 message header for Content-Type sendContentType('text/html', 'bookmarklet-' . $action); +======= +>>>>>>> skinnable-master // check ticket $aActionsNotToCheck = array('login', 'add', 'edit'); if ( !in_array($action, $aActionsNotToCheck) ) { if ( !$manager->checkTicket() ) { - bm_doError(_ERROR_BADTICKET); + bm_doError($skin, _ERROR_BADTICKET); } } @@ -67,32 +91,32 @@ switch ( $action ) { // adds the item for real case 'additem': - bm_doAddItem(); + bm_doAddItem($skin); break; // shows the edit item form case 'edit': - bm_doEditForm(); + bm_doEditForm($skin); break; // edits the item for real case 'edititem': - bm_doEditItem(); + bm_doEditItem($skin); break; // on login, 'action' gets changed to 'nextaction' case 'login': - bm_doError('Something went wrong'); + bm_doError($skin, 'Something went wrong'); break; // shows the fill in form case 'add': default: - bm_doShowForm(); + bm_doShowForm($skin); break; } -function bm_doAddItem() +function bm_doAddItem($skin) { global $member, $manager, $CONF; @@ -101,7 +125,7 @@ function bm_doAddItem() if ( $result['status'] == 'error' ) { - bm_doError($result['message']); + bm_doError($skin, $result['message']); } $blogid = getBlogIDFromItemID($result['itemid']); @@ -118,12 +142,16 @@ function bm_doAddItem() $extrahead = ''; } +<<<<<<< HEAD bm_message(_ITEM_ADDED, _ITEM_ADDED, $message,$extrahead); +======= + bm_message($skin, _ITEM_ADDED, $message,$extrahead); +>>>>>>> skinnable-master return; } -function bm_doEditItem() +function bm_doEditItem($skin) { global $member, $manager, $CONF; @@ -133,7 +161,7 @@ function bm_doEditItem() // only allow if user is allowed to alter item if ( !$member->canUpdateItem($itemid, $catid) ) { - bm_doError(_ERROR_DISALLOWED); + bm_doError($skin, _ERROR_DISALLOWED); } $body = postVar('body'); @@ -163,7 +191,7 @@ function bm_doEditItem() // show error when sth goes wrong if ( !$catid ) { - bm_doError('Could not create new category'); + bm_doError($skin, 'Could not create new category'); } } @@ -186,7 +214,7 @@ function bm_doEditItem() $timestamp = 0; break; default: - bm_doError('Something went wrong'); + bm_doError($skin, 'Something went wrong'); } // update item for real @@ -197,27 +225,42 @@ function bm_doEditItem() Item::delete($draftid); } - // show success message - if ( $catid != intPostVar('catid') ) + if ( $result['status'] == 'newcategory' ) { - bm_message(_ITEM_UPDATED, _ITEM_UPDATED, 'Item was added, and a new category was created. Click here to edit the name and description of the category.', ''); + $href = "index.php?action=categoryedit&blogid={$blogid}&catid={$result['catid']}"; + $onclick = 'if (event && event.preventDefault) event.preventDefault(); window.open(this.href); return false;'; + $title = _BOOKMARKLET_NEW_WINDOW; + $aTag = " "; + $message = _BOOKMARKLET_NEW_CATEGORY . $aTag . _BOOKMARKLET_NEW_CATEGORY_EDIT . ''; } else { - bm_message(_ITEM_UPDATED, _ITEM_UPDATED, _ITEM_UPDATED, ''); + $message = _ITEM_ADDED; } +<<<<<<< HEAD return; } function bm_loginAndPassThrough($action='add') +======= + // show success message + bm_message($skin, _ITEM_ADDED, $message, ''); + return; +} + +function bm_loginAndPassThrough($skin, $action='add') +>>>>>>> skinnable-master { + /* + * TODO: これを出力させる $blogid = intRequestVar('blogid'); $itemid = intRequestVar('itemid'); $log_text = requestVar('logtext'); $log_link = requestVar('loglink'); $log_linktitle = requestVar('loglinktitle'); +<<<<<<< HEAD echo "\n"; echo "\n"; echo "\n"; @@ -232,23 +275,31 @@ function bm_loginAndPassThrough($action='add') echo "

\n"; echo _LOGINFORM_NAME . "
\n"; echo _LOGINFORM_PWD . "
\n"; +======= +>>>>>>> skinnable-master echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo "\n"; +<<<<<<< HEAD echo '\n"; echo "

\n"; echo "\n"; echo '

' . _POPUP_CLOSE . "

\n"; echo "\n"; echo "\n"; +======= + */ + + $skin->parse('showlogin'); +>>>>>>> skinnable-master return; } -function bm_doShowForm() +function bm_doShowForm($skin) { global $manager, $member; @@ -259,18 +310,24 @@ function bm_doShowForm() if ( !Blog::existsID($blogid) ) { - bm_doError(_ERROR_NOSUCHBLOG); + bm_doError($skin, _ERROR_NOSUCHBLOG); } +<<<<<<< HEAD else { $blog =& $manager->getBlog($blogid); } if ( !$member->isTeamMember($blogid) ) +======= + else if ( !$member->isTeamMember($blogid) ) +>>>>>>> skinnable-master { - bm_doError(_ERROR_NOTONTEAM); + bm_doError($skin, _ERROR_NOTONTEAM); } + $blog =& $manager->getBlog($blogid); + $logje = ''; if ( $log_text ) @@ -288,6 +345,7 @@ function bm_doShowForm() $logje .= '' . Entity::hsc($log_linktitle) . ''; } +<<<<<<< HEAD $variables = array(); $variables['body'] = $logje; $variables['title'] = Entity::hsc($log_linktitle); @@ -301,10 +359,34 @@ function bm_doShowForm() $parser = new Parser($handler); $parser->parse($contents); +======= + $item = array(); + $item['body'] = $logje; + $item['title'] = Entity::hsc($log_linktitle); + + $data = array( + 'blog' => &$blog, + 'item' => &$item, + 'contents' => &$item + ); + $manager->notify('PreAddItemForm', $data); + + if ( $blog->convertBreaks() ) + { + $item['body'] = removeBreaks($item['body']); + } + + Admin::$blog = &$blog; + Admin::$contents = &$item; + + Admin::$action = 'createitem'; + $skin->parse('createitem'); + +>>>>>>> skinnable-master return; } -function bm_doEditForm() +function bm_doEditForm($skin) { global $member, $manager; @@ -312,18 +394,29 @@ function bm_doEditForm() if ( !$manager->existsItem($itemid, 0, 0) ) { - bm_doError(_ERROR_NOSUCHITEM); + bm_doError($skin, _ERROR_NOSUCHITEM); } - - if ( !$member->canAlterItem($itemid) ) + else if ( !$member->canAlterItem($itemid) ) { - bm_doError(_ERROR_DISALLOWED); + bm_doError($skin, _ERROR_DISALLOWED); } +<<<<<<< HEAD $variables =& $manager->getItem($itemid, 1, 1); +======= +>>>>>>> skinnable-master $blog =& $manager->getBlog(getBlogIDFromItemID($itemid) ); + $item =& $manager->getItem($itemid, 1, 1); +<<<<<<< HEAD $manager->notify('PrepareItemForEdit', array('item' => &$variables) ); +======= + $data = array( + 'blog' => &$blog, + 'item' => &$item + ); + $manager->notify('PrepareItemForEdit', $data); +>>>>>>> skinnable-master if ( $blog->convertBreaks() ) { @@ -331,6 +424,7 @@ function bm_doEditForm() $variables['more'] = removeBreaks($variables['more']); } +<<<<<<< HEAD $handler = new PageFactory($blog); $handler->setVariables($variables); @@ -341,15 +435,25 @@ function bm_doEditForm() return; } +======= + Admin::$blog = &$blog; + Admin::$contents = &$item; + + Admin::$action = 'itemedit'; + $skin->parse('itemedit'); + + return;} +>>>>>>> skinnable-master -function bm_doError($msg) +function bm_doError($skin, $msg) { - bm_message(_ERROR, _ERRORMSG, $msg); + bm_message($skin, _ERRORMSG, $msg); die; } -function bm_message($title, $head, $msg, $extrahead = '') +function bm_message($skin, $title, $msg, $extrahead = '') { +<<<<<<< HEAD echo "\n"; echo "\n"; echo "\n"; @@ -365,12 +469,18 @@ function bm_message($title, $head, $msg, $extrahead = '') echo '

' . _POPUP_CLOSE . "

\n"; echo "\n"; echo "\n"; +======= + Admin::$extrahead = $extrahead; + Admin::$headMess = $msg; + $skin->parse('adminerrorpage'); +>>>>>>> skinnable-master return; } -function bm_style() +function bm_doContextMenuCode($width=600, $height=500) { +<<<<<<< HEAD echo "\n"; echo "\n"; return; @@ -380,6 +490,9 @@ function bm_doContextMenuCode($width=600, $height=500) { global $CONF; +======= + global $CONF; +>>>>>>> skinnable-master $blogid = (integer) intGetVar('blogid'); echo " -
-
- <%ticket%> - - - - - -
- -
- -
- [ctrl+shift+A] = Link, [ctrl+shift+B] = Bold, [ctrl+shift+I] = Italic, [ctrl+shift+M] = Insert Media. - <%callback(FormExtra,additemform)%> -
+
+<%ticket%> + + + + +
+
+
+[ctrl+shift+A] = Link, [ctrl+shift+B] = Bold, [ctrl+shift+I] = Italic, [ctrl+shift+M] = Insert Media. +<%callback(FormExtra,additemform)%> +
diff --git a/nucleus/index.php b/nucleus/index.php index f3d70ec..fed8f8d 100644 --- a/nucleus/index.php +++ b/nucleus/index.php @@ -1,7 +1,7 @@ >>>>>> skinnable-master */ // we are using admin stuff: @@ -78,7 +83,27 @@ if ( $bNeedsLogin ) $action = 'showlogin'; } -sendContentType('text/html', 'admin-' . $action); +if ( !Admin::initialize() ) +{ + /* TODO: this is a bad way... */ + sendContentType('text/html', 'admin-' . $action); + + $skin =& $manager->getSkin(0, 'AdminActions', 'AdminSkin'); + if ( $bNeedsLogin ) + { + $skin->parse('fileparse', $DIR_SKINS . 'admin/showlogin.skn'); + } + else if ($action == 'adminskinieimport' ) + { + Admin::action($action); + } + else + { + $skin->parse('importAdmin', $DIR_SKINS . 'admin/defaultimporter.skn'); + } + /* TODO: something to handling errors */ + exit; +} -$admin = new Admin(); -$admin->action($action); +Admin::action($action); +exit; diff --git a/nucleus/libs/.htaccess b/nucleus/libs/.htaccess index 6b2c90b..7d3aaf1 100644 --- a/nucleus/libs/.htaccess +++ b/nucleus/libs/.htaccess @@ -1,2 +1,2 @@ -Order allow,deny -Deny from all +Order allow,deny +Deny from all \ No newline at end of file diff --git a/nucleus/libs/ACTION.php b/nucleus/libs/ACTION.php index 5ac9e75..a7b3363 100644 --- a/nucleus/libs/ACTION.php +++ b/nucleus/libs/ACTION.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD autoDraft(); + break; + case 'updateticket': + return $this->updateTicket(); + break; + case 'addcomment': + return $this->addComment(); + break; + case 'sendmessage': + return $this->sendMessage(); + break; + case 'createaccount': + return $this->createAccount(); + break; + case 'forgotpassword': + return $this->forgotPassword(); + break; + case 'votepositive': + return $this->doKarma('pos'); + break; + case 'votenegative': + return $this->doKarma('neg'); + break; + case 'plugin': + return $this->callPlugin(); + break; + default: + doError(_ERROR_BADACTION); + break; + } + return; + } + + /** + * Action::addComment() + * Adds a new comment to an item (if IP isn't banned) + * + * @param void + * @return void + */ + private function addComment() + { + global $CONF, $errormessage, $manager; + + $post['itemid'] = intPostVar('itemid'); + $post['user'] = postVar('user'); + $post['userid'] = postVar('userid'); + $post['email'] = postVar('email'); + $post['body'] = postVar('body'); + $post['remember'] = intPostVar('remember'); + + // begin if: "Remember Me" box checked + if ( $post['remember'] == 1 ) + { + $lifetime = time() + 2592000; + setcookie($CONF['CookiePrefix'] . 'comment_user', $post['user'], $lifetime, '/', '', 0); + setcookie($CONF['CookiePrefix'] . 'comment_userid', $post['userid'], $lifetime, '/', '', 0); + setcookie($CONF['CookiePrefix'] . 'comment_email', $post['email'], $lifetime, '/', '', 0); + } + + $item =& $manager->getItem($post['itemid'], 0, 0); + $this->checkban($item['blogid']); + $blog =& $manager->getBlog($item['blogid']); + + // note: PreAddComment and PostAddComment gets called somewhere inside addComment + $comments = new Comments($post['itemid']); + $errormessage = $comments->addComment($blog->getCorrectTime(), $post); + + if ( $errormessage != '1' ) + { + // show error message using default skin for blo + return array( + 'message' => $errormessage, + 'skinid' => $blog->getDefaultSkin() + ); + } + else + { + // redirect when adding comments succeeded + if ( postVar('url') ) + { + redirect(postVar('url') ); + } + else + { + $url = Link::create_item_link($post['itemid']); + redirect($url); + } + } + return; + } + + /** + * Action::sendMessage() + * Sends a message from the current member to the member given as argument + * + * @param void + * @return void + */ + private function sendMessage() + { + global $CONF, $member; + + $error = $this->validateMessage(); + + if ( $error != '' ) + { + return array('message' => $error); + } + + if ( !$member->isLoggedIn() ) + { + $fromMail = postVar('frommail'); + $fromName = _MMAIL_FROMANON; + } + else + { + $fromMail = $member->getEmail(); + $fromName = $member->getDisplayName(); + } + + /* TODO: validation */ + $memberid = postVar('memberid'); + $tomem = new Member(); + $tomem->readFromId($memberid); + + /* TODO: validation */ + $message = postVar('message'); + $message = _MMAIL_MSG . ' ' . $fromName . "\n" + . '(' . _MMAIL_FROMNUC. ' ' . $CONF['IndexURL'] .") \n\n" + . _MMAIL_MAIL . " \n\n" + . $message; + $message .= Notification::get_mail_footer(); + + $title = _MMAIL_TITLE . ' ' . $fromName; + Notification::mail($tomem->getEmail(), $title, $message, $fromMail, i18n::get_current_charset()); + + /* TODO: validation */ + $url = postVar('url'); + if ( empty($url) ) + { + $CONF['MemberURL'] = $CONF['IndexURL']; + + if ( $CONF['URLMode'] == 'pathinfo' ) + { + $data = array( + 'memberid' => $tomem->getID(), + 'name' => $tomem->getDisplayName() + ); + $url = Link::create_link('member', $data); + } + else + { + $url = $CONF['IndexURL'] . Link::create_member_link($tomem->getID()); + } + } + redirect($url ); + + return; + } + + /** + * Action::validateMessage() + * Checks if a mail to a member is allowed + * Returns a string with the error message if the mail is disallowed + * + * @param void + * @return String Null character string + */ + private function validateMessage() + { + global $CONF, $member, $manager; + + if ( !$CONF['AllowMemberMail'] ) + { + return _ERROR_MEMBERMAILDISABLED; + } + + if ( !$member->isLoggedIn() && !$CONF['NonmemberMail'] ) + { + return _ERROR_DISALLOWED; + } + + if ( !$member->isLoggedIn() && !Notification::address_validation(postVar('frommail')) ) + { + return _ERROR_BADMAILADDRESS; + } + + /* + * let plugins do verification (any plugin which thinks the comment is + * invalid can change 'error' to something other than '') + */ + $result = ''; + $data = array( + 'type' => 'membermail', + 'error' => &$result + ); + $manager->notify('ValidateForm', $data); + + return $result; + } + + /** + * Action::createAccount() + * Creates a new user account + * + * @param void + * @return mixed + */ + private function createAccount() + { + global $CONF, $manager; + + if ( array_key_exists('AllowMemberCreate', $CONF) && !$CONF['AllowMemberCreate'] ) + { + doError(_ERROR_MEMBERCREATEDISABLED); + return; + } + + // evaluate content from FormExtra + $result = 1; + $data = array( + 'type' => 'membermail', + 'error' => &$result + ); + $manager->notify('ValidateForm', $data); + + if ( $result != 1 ) + { + return $result; + } + + // even though the member can not log in, set some random initial password. One never knows. + srand((double) microtime() * 1000000); + $initialPwd = md5(uniqid(rand(), TRUE) ); + + // create member (non admin/can not login/no notes/random string as password) + $name = Entity::shorten(postVar('name'), 32, ''); + $relname = postVar('realname'); + $email = postVar('email'); + $url = postVar('url'); + + $r = Member::create($name, $realname, $initialPwd, $email, $url, 0, 0, ''); + + if ( $r != 1 ) + { + return $r; + } + + // send message containing password. + $newmem = new Member(); + $newmem->readFromName($name); + $newmem->sendActivationLink('register'); + + $data = array('member' => $newmem); + $manager->notify('PostRegister', $data); + + if ( postVar('desturl') ) + { + redirect(postVar('desturl') ); + } + + return 1; + } + + /** + * Action::forgotPassword() + * Sends a new password + * + * @param void + * @return void + */ + private function forgotPassword() + { + $membername = trim(postVar('name') ); + + if ( !Member::exists($membername) ) + { + doError(_ERROR_NOSUCHMEMBER); + return; + } + + $mem = Member::createFromName($membername); + + // check if e-mail address is correct + $email = postVar('email'); + if ( $mem->getEmail() != $email ) + { + doError(_ERROR_INCORRECTEMAIL); + return; + } + + // send activation link + $mem->sendActivationLink('forgot'); + + // redirection + $url = postVar('url'); + if ( !empty($url) ) + { + redirect(postVar('url') ); + } + else + { + echo _MSG_ACTIVATION_SENT; + echo "
" + . "
" + . "Return to {$CONF['SiteName']}\n"; + } + + return; + } + + /** + * Action::doKarma() + * Handle karma votes + * + * @param string $type pos or neg + * @return Void + */ + private function doKarma($type) + { + global $itemid, $member, $CONF, $manager; + + // check if itemid exists + if ( !$manager->existsItem($itemid, 0, 0) ) + { + doError(_ERROR_NOSUCHITEM); + return; + } + + $item =& $manager->getItem($itemid, 0, 0); + $this->checkban($item['blogid']); + + $karma =& $manager->getKarma($itemid); + + // check if not already voted + if ( !$karma->isVoteAllowed(serverVar('REMOTE_ADDR') ) ) + { + doError(_ERROR_VOTEDBEFORE); + return; + } + + // check if item does allow voting + $item =& $manager->getItem($itemid, 0, 0); + + if ( $item['closed'] ) + { + doError(_ERROR_ITEMCLOSED); + return; + } + + switch ( $type ) + { + case 'pos': + $karma->votePositive(); + break; + + case 'neg': + $karma->voteNegative(); + break; + } + + $blog =& $manager->getBlog($blogid); + + // send email to notification address, if any + if ( $blog->getNotifyAddress() && $blog->notifyOnVote() ) + { + $message = _NOTIFY_KV_MSG . ' ' . $itemid . "\n"; + $itemLink = Link::create_item_link((integer)$itemid); + $temp = parse_url($itemLink); + + if ( !$temp['scheme'] ) + { + $itemLink = $CONF['IndexURL'] . $itemLink; + } + + $message .= $itemLink . "\n\n"; + + if ( $member->isLoggedIn() ) + { + $message .= _NOTIFY_MEMBER . ' ' . $member->getDisplayName() . ' (ID=' . $member->getID() . ")\n"; + } + + $message .= _NOTIFY_IP . ' ' . serverVar('REMOTE_ADDR') . "\n"; + $message .= _NOTIFY_HOST . ' ' . gethostbyaddr(serverVar('REMOTE_ADDR')) . "\n"; + $message .= _NOTIFY_VOTE . "\n " . $type . "\n"; + $message .= Notification::get_mail_footer(); + + $subject = _NOTIFY_KV_TITLE . ' ' . strip_tags($item['title']) . ' (' . $itemid . ')'; + + $from = $member->getNotifyFromMailAddress(); + + Notification::mail($blog->getNotifyAddress(), $subject, $message, $from, i18n::get_current_charset()); + } + + $refererUrl = serverVar('HTTP_REFERER'); + + if ( !$refererUrl ) + { + $url = $itemLink; + } + else + { + $url = $refererUrl; + } + + redirect($url); + return; + } + + /** + * Action::callPlugin() + * Calls a plugin action + * + * @param void + * @return void + */ + private function callPlugin() + { + global $manager; + + $name = requestVar('name'); + $pluginName = "NP_{$name}"; + $actionType = requestVar('type'); + + // 1: check if plugin is installed + if ( !$manager->pluginInstalled($pluginName) ) + { + doError(_ERROR_NOSUCHPLUGIN); + return; + } + + // 2: call plugin + $pluginObject =& $manager->getPlugin($pluginName); + if ( !$pluginObject ) + { + $error = 'Could not load plugin (see actionlog)'; + } + else + { + $error = $pluginObject->doAction($actionType); + } + + /* + * doAction returns error when: + * - an error occurred (duh) + * - no actions are allowed (doAction is not implemented) + */ + if ( $error ) + { + doError($error); + return; + } + + return; + } + + /** + * Action::checkban() + * Checks if an IP or IP range is banned + * + * @param integer $blogid + * @return void + */ + private function checkban($blogid) + { + // check if banned + $ban = Ban::isBanned($blogid, serverVar('REMOTE_ADDR') ); + + if ( $ban != 0 ) + { + doError(_ERROR_BANNED1 . $ban->iprange . _ERROR_BANNED2 . $ban->message . _ERROR_BANNED3); + return; + } + + return; + } + + /** + * Action::updateTicket() + * Gets a new ticket + * + * @param void + * @return boolean FALSE + */ + private function updateTicket() + { + global $manager; + + if ( !$manager->checkTicket() ) + { + echo _ERROR . ':' . _ERROR_BADTICKET; + } + else + { + echo $manager->getNewTicket(); + } + + return FALSE; + } + + /** + * Action::autoDraft() + * Handles AutoSaveDraft + * + * @param void + * @return boolean FALSE + */ + private function autoDraft() + { + global $manager; + + if ( !$manager->checkTicket() ) + { + echo _ERROR . ':' . _ERROR_BADTICKET; + } + else + { + $manager->loadClass('ITEM'); + $info = Item::createDraftFromRequest(); + + if ( $info['status'] != 'error' ) + { + echo $info['draftid']; + } + else + { + echo $info['message']; + } + } + + return FALSE; + } +} + +>>>>>>> skinnable-master diff --git a/nucleus/libs/ACTIONLOG.php b/nucleus/libs/ACTIONLOG.php index a7c7055..8c4f1e0 100644 --- a/nucleus/libs/ACTIONLOG.php +++ b/nucleus/libs/ACTIONLOG.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD +======= +isLoggedIn() ) + { + $message = "[" . $member->getDisplayName() . "] " . $message; + } + + $query = "INSERT INTO %s (timestamp, message) VALUES (%s, %s)"; + $query = sprintf($query, sql_table('actionlog'), DB::formatDateTime(), DB::quoteValue($message)); + DB::execute($query); + + self::trimLog(); + return; + } + + /** + * (Static) Method to clear the whole action log + */ + function clear() { + global $manager; + + $query = sprintf('DELETE FROM %s', sql_table('actionlog')); + + $data = array(); + $manager->notify('ActionLogCleared', $data); + + return DB::execute($query) !== FALSE; + } + + /** + * (Static) Method to trim the action log (from over 500 back to 250 entries) + */ + function trimLog() { + static $checked = 0; + + // only check once per run + if ($checked) return; + + // trim + $checked = 1; + + $query = sprintf('SELECT COUNT(*) AS result FROM %s', sql_table('actionlog')); + $iTotal = DB::getValue($query); + + // if size > 500, drop back to about 250 + $iMaxSize = 500; + $iDropSize = 250; + if ($iTotal > $iMaxSize) { + $query = sprintf('SELECT timestamp as result FROM %s ORDER BY timestamp DESC LIMIT %d,1', + sql_table('actionlog'), intval($iDropSize)); + $tsChop = DB::getValue($query); + $query = sprintf("DELETE FROM %s WHERE timestamp < '%s'", sql_table('actionlog'), $tsChop); + DB::execute($query); + } + + } + +} + +?> +>>>>>>> skinnable-master diff --git a/nucleus/libs/ACTIONS.php b/nucleus/libs/ACTIONS.php index 37cc913..db41cfc 100644 --- a/nucleus/libs/ACTIONS.php +++ b/nucleus/libs/ACTIONS.php @@ -15,7 +15,11 @@ * * @license http://nucleuscms.org/license.txt GNU General Public License * @copyright Copyright (C) 2002-2012 The Nucleus Group +<<<<<<< HEAD * @version $Id: ACTIONS.php 1863 2012-05-19 10:50:27Z sakamocchi $ +======= + * @version $Id: ACTIONS.php 1886 2012-06-17 08:27:27Z sakamocchi $ +>>>>>>> skinnable-master */ class Actions extends BaseActions @@ -69,10 +73,17 @@ class Actions extends BaseActions ); /** +<<<<<<< HEAD * Actions::$skin_type_friendly_names * friendly name for wrapped page types */ static public $default_skin_types = array( +======= + * Actions::$normal_skin_types + * friendly name for wrapped page types + */ + static public $normal_skin_types = array( +>>>>>>> skinnable-master 'index' => _SKIN_PART_MAIN, 'item' => _SKIN_PART_ITEM, 'archivelist' => _SKIN_PART_ALIST, @@ -84,15 +95,25 @@ class Actions extends BaseActions ); /** +<<<<<<< HEAD * Actions::getAvailableSkinTypes() +======= + * Actions::getNormalSkinTypes() +>>>>>>> skinnable-master * * @static * @param void * @return array list of friendly names for page actions */ +<<<<<<< HEAD static public function getAvailableSkinTypes() { return self::$default_skin_types; +======= + static public function getNormalSkinTypes() + { + return self::$normal_skin_types; +>>>>>>> skinnable-master } /** @@ -405,7 +426,11 @@ class Actions extends BaseActions $params = func_get_args(); array_shift($params); +<<<<<<< HEAD return call_user_func_array(array(&$plugin, 'doIf'), $params); +======= + return call_user_func_array(array($plugin, 'doIf'), $params); +>>>>>>> skinnable-master } /** @@ -552,8 +577,13 @@ class Actions extends BaseActions // TODO: Move request uri to linkparams. this is ugly. sorry for that. $startpos = (integer) $startpos; $parsed = parse_url(serverVar('REQUEST_URI')); +<<<<<<< HEAD $path = $parsed['path']; $parsed = $parsed['query']; +======= + $path = ( in_array('path', $parsed) ) ? $parsed['path'] : ''; + $parsed = ( in_array('query', $parsed) ) ? $parsed['query'] : ''; +>>>>>>> skinnable-master $url = ''; if ( $direction == 'prev' ) @@ -709,7 +739,12 @@ class Actions extends BaseActions private function preBlogContent($type, &$blog) { global $manager; +<<<<<<< HEAD $manager->notify('PreBlogContent',array('blog' => &$blog, 'type' => $type)); +======= + $data = array('blog' => &$blog, 'type' => $type); + $manager->notify('PreBlogContent', $data); +>>>>>>> skinnable-master return; } @@ -724,7 +759,12 @@ class Actions extends BaseActions private function postBlogContent($type, &$blog) { global $manager; +<<<<<<< HEAD $manager->notify('PostBlogContent', array('blog' => &$blog, 'type' => $type)); +======= + $data = array('blog' => &$blog, 'type' => $type); + $manager->notify('PostBlogContent', $data); +>>>>>>> skinnable-master return; } @@ -813,6 +853,7 @@ class Actions extends BaseActions * Actions::parse_archivedate() * %archivedate(locale,date format)% * +<<<<<<< HEAD * @param string $locale * @return void */ @@ -832,6 +873,15 @@ class Actions extends BaseActions } */ +======= + * @param deprecated $locale + * @return void + */ + public function parse_archivedate($locale='') + { + global $archive; + +>>>>>>> skinnable-master // get archive date sscanf($archive,'%d-%d-%d',$y,$m,$d); @@ -1042,7 +1092,12 @@ class Actions extends BaseActions public function parse_callback($eventName, $type) { global $manager; +<<<<<<< HEAD $manager->notify($eventName, array('type' => $type)); +======= + $data = array('type' => $type); + $manager->notify($eventName, $data); +>>>>>>> skinnable-master return; } @@ -1221,7 +1276,11 @@ class Actions extends BaseActions global $manager, $blog, $highlight, $itemid; $template =& $manager->getTemplate($template); +<<<<<<< HEAD $item =& $manager->getItem($itemid, 0, 0); +======= + $item =& $manager->getitem($itemid, 0, 0); +>>>>>>> skinnable-master // create parser object & action handler $handler = new ItemActions($blog); @@ -1422,7 +1481,11 @@ class Actions extends BaseActions public function parse_itemtitle($format = '') { global $manager, $itemid; +<<<<<<< HEAD $item =& $manager->getItem($itemid,0,0); +======= + $item =& $manager->getItem($itemid, 1, 1); +>>>>>>> skinnable-master switch ( $format ) { @@ -1874,7 +1937,11 @@ class Actions extends BaseActions // add skin type on front array_unshift($params, $this->skintype); +<<<<<<< HEAD call_user_func_array(array(&$plugin,'doSkinVar'), $params); +======= + call_user_func_array(array($plugin,'doSkinVar'), $params); +>>>>>>> skinnable-master return; } @@ -2204,6 +2271,7 @@ class Actions extends BaseActions * @param string $template name of template * @return void */ +<<<<<<< HEAD public function parse_sticky($itemnumber = 0, $template = '') { global $manager; @@ -2215,6 +2283,21 @@ class Actions extends BaseActions $this->preBlogContent('sticky',$b); $this->amountfound = $b->readLogFromList($itemarray, $template); $this->postBlogContent('sticky',$b); +======= + public function parse_sticky($itemid = 0, $template = '') + { + global $manager; + + $itemid = (integer) $itemid; + $itemarray = array($itemid); + + $item =& $manager->getItem($post['itemid'], 1, 1); + $blog =& $manager->getBlog($item['blogid']); + + $this->preBlogContent('sticky', $blog); + $this->amountfound = $blog->readLogFromList($itemarray, $template); + $this->postBlogContent('sticky', $blog); +>>>>>>> skinnable-master return; } } diff --git a/nucleus/libs/ADMIN.php b/nucleus/libs/ADMIN.php index 747c599..2bbcc40 100644 --- a/nucleus/libs/ADMIN.php +++ b/nucleus/libs/ADMIN.php @@ -1,5 +1,5 @@ isLoggedIn() ) + { + $memskin = $member->getAdminSkin(); + if ( $memskin && Skin::existsID($memskin)) + { + $skinid = $memskin; + } + } + + /* NOTE: 2. make an instance of skin object */ + if ( !Skin::existsID($skinid) ) + { + return FALSE; + } + + /* NOTE: 3. initializing each members */ + self::$skin =& $manager->getSkin($skinid, 'AdminActions', 'AdminSkin'); + self::$action = ''; + self::$extrahead = ''; + self::$passvar = ''; + self::$headMess = ''; + self::$aOptions = ''; + return TRUE; + } + + /** + * Admin::action() + * Executes an action + * + * @param string $action action to be performed + * @return void + */ + static public function action($action) + { + global $CONF, $manager, $member; + + /* 1. decide action name */ + $customAction = postvar('customaction'); + if ( empty($customAction) ) + { + $alias = array( + 'login' => 'overview', + '' => 'overview', + ); + } + else + { + $alias = array( + 'login' => $customAction, + '' => $customAction + ); + } + if ( array_key_exists($action, $alias) && isset($alias[$action]) ) + { + $action = $alias[$action]; + } + $method_name = "action_{$action}"; + self::$action = strtolower($action); + + /* 2. check ticket-needed action */ + if ( !in_array(self::$action, self::$ticketless_actions) && !$manager->checkTicket() ) + { + self::error(_ERROR_BADTICKET); + return; + } + + /* 3. parse according to the action */ + else if ( method_exists('Admin', $method_name) ) + { + call_user_func(array(__CLASS__, $method_name)); + return; + } + /* 4. parse special admin skin */ + elseif ( in_array(self::$action, self::$skinless_actions) ) + { + /* TODO: need to be implemented or not? + self::action_parseSpecialskin(); + */ + } + else + { + self::error(_BADACTION . ENTITY::hsc($action)); + return; + } + + return; + } + + /** + * Action::action_showlogin() + * + * @param void + * @return void + */ + static private function action_showlogin() + { + global $error; + self::action_login($error); + return; + } + + /** + * Action::action_login() + * + * @param string $msg message for pageheader + * @param integer $passvars ??? + */ + static private function action_login($msg = '', $passvars = 1) + { + global $member; + + // skip to overview when allowed + if ( $member->isLoggedIn() && $member->canLogin() ) + { + self::action_overview(); + return; + } + + /* TODO: needless variable??? */ + self::$passvar = $passvars; + if ( $msg ) + { + self::$headMess = $msg; + } + + self::$skin->parse('showlogin'); + } + + /** + * Action::action_overview() + * provides a screen with the overview of the actions available + * + * @param string $msg message for pageheader + * @return void + */ + static private function action_overview($msg = '') + { + if ( $msg ) + { + self::$headMess = $msg; + } + + self::$skin->parse('overview'); + return; + } + + /** + * Admin::action_manage() + * + * @param string $msg message for pageheader + * @retrn void + */ + static private function action_manage($msg = '') + { + global $member; + + if ( $msg ) + { + self::$headMess = $msg; + } + $member->isAdmin() or self::disallow(); + + self::$skin->parse('manage'); + return; + } + + /** + * Action::action_itemlist() + * + * @param integer id for weblod + * @return void + */ + static private function action_itemlist($blogid = '') +>>>>>>> skinnable-master { global $member, $manager, $CONF; @@ -349,6 +695,7 @@ class Admin $blogid = intRequestVar('blogid'); } +<<<<<<< HEAD $member->teamRights($blogid) or $member->isAdmin() or $this->disallow(); $this->pagehead(); @@ -970,217 +1317,296 @@ class Admin } } echo "\n"; +======= + $member->teamRights($blogid) or $member->isAdmin() or self::disallow(); + + self::$skin->parse('itemlist'); return; } /** - * Admin::action_browseownitems() + * Action::action_batchitem() * * @param void * @return void */ - public function action_browseownitems() + static private function action_batchitem() { - global $member, $manager, $CONF; + global $member, $manager; - $this->pagehead(); + $member->isLoggedIn() or self::disallow(); - echo '

(' . _BACKHOME . ")

\n"; - echo '

' . _ITEMLIST_YOUR . "

\n"; + $selected = requestIntArray('batch'); + $action = requestVar('batchaction'); - // start index - if ( postVar('start') ) - { - $start = intPostVar('start'); - } - else + if ( !is_array($selected) || sizeof($selected) == 0 ) { - $start = 0; + self::error(_BATCH_NOSELECTION); + return; } - // amount of items to show - if ( postVar('amount') ) + // On move: when no destination blog/category chosen, show choice now + $destCatid = intRequestVar('destcatid'); + if ( ($action == 'move') && (!$manager->existsCategory($destCatid)) ) { - $amount = intPostVar('amount'); + self::batchMoveSelectDestination('item', $selected); } - else + + // On delete: check if confirmation has been given + if ( ($action == 'delete') && (requestVar('confirmation') != 'yes') ) { - $amount = (integer) $CONF['DefaultListSize']; - if ( $amount < 1 ) - { - $amount = 10; - } + self::batchAskDeleteConfirmation('item', $selected); } - $search = postVar('search'); // search through items + self::$skin->parse('batchitem'); + return; + } + + /** + * Action::action_batchcomment() + * + * @param void + * @return void + */ + static private function action_batchcomment() + { + global $member; - $query = 'SELECT bshortname, cname, mname, ititle, ibody, idraft, inumber, itime' - . ' FROM '.sql_table('item').', '.sql_table('blog') . ', '.sql_table('member') . ', '.sql_table('category') - . ' WHERE iauthor='. $member->getID() .' and iauthor=mnumber and iblog=bnumber and icat=catid'; + $member->isLoggedIn() or self::disallow(); - if ( $search ) + $selected = requestIntArray('batch'); + $action = requestVar('batchaction'); + + // Show error when no items were selected + if ( !is_array($selected) || sizeof($selected) == 0 ) { - $query .= " and ((ititle LIKE " . DB::quoteValue('%'.$search.'%') . ") or (ibody LIKE " . DB::quoteValue('%'.$search.'%') . ") or (imore LIKE " . DB::quoteValue('%'.$search.'%') . "))"; + self::error(_BATCH_NOSELECTION); + return; } - $query .= ' ORDER BY itime DESC' - . " LIMIT $start, $amount"; - - $template['content'] = 'itemlist'; - $template['now'] = time(); - - $manager->loadClass("ENCAPSULATE"); - $navList = new NavList('browseownitems', $start, $amount, 0, 1000, /*$blogid*/ 0, $search, 0); - $navList->showBatchList('item',$query,'table',$template); + // On delete: check if confirmation has been given + if ( ($action == 'delete') && (requestVar('confirmation') != 'yes') ) + { + self::batchAskDeleteConfirmation('comment', $selected); + } - $this->pagefoot(); + self::$skin->parse('batchcomment'); return; } /** - * Admin::action_itemcommentlist() + * Admin::action_batchmember() * - * Show all the comments for a given item - * @param integer $itemid ID for item + * @param void * @return void */ - public function action_itemcommentlist($itemid = '') + static private function action_batchmember() { - global $member, $manager, $CONF; - - if ( $itemid == '' ) - { - $itemid = intRequestVar('itemid'); - } - - // only allow if user is allowed to alter item - $member->canAlterItem($itemid) or $this->disallow(); + global $member; - $blogid = getBlogIdFromItemId($itemid); + ($member->isLoggedIn() && $member->isAdmin()) or self::disallow(); - $this->pagehead(); + $selected = requestIntArray('batch'); + $action = requestVar('batchaction'); - // start index - if ( postVar('start') ) - { - $start = intPostVar('start'); - } - else + // Show error when no members selected + if ( !is_array($selected) || sizeof($selected) == 0 ) { - $start = 0; + self::error(_BATCH_NOSELECTION); + return; } - // amount of items to show - if ( postVar('amount') ) - { - $amount = intPostVar('amount'); - } - else + // On delete: check if confirmation has been given + if ( ($action == 'delete') && (requestVar('confirmation') != 'yes') ) { - $amount = (integer) $CONF['DefaultListSize']; - if ( $amount < 1 ) - { - $amount = 10; - } + self::batchAskDeleteConfirmation('member',$selected); } - $search = postVar('search'); + self::$skin->parse('batchmember'); + return; + } + + /** + * Admin::action_batchteam() + * + * @param void + * @return void + */ + static private function action_batchteam() + { + global $member; - echo '

(' . _BACKTOOVERVIEW . ")

\n"; - echo '

',_COMMENTS,'

'; + $blogid = intRequestVar('blogid'); - $query = 'SELECT cbody, cuser, cmail, cemail, mname, ctime, chost, cnumber, cip, citem FROM ' . sql_table('comment') . ' LEFT OUTER JOIN ' . sql_table('member') . ' ON mnumber = cmember WHERE citem = ' . $itemid; + ($member->isLoggedIn() && $member->blogAdminRights($blogid)) or self::disallow(); - if ( $search ) + $selected = requestIntArray('batch'); + $action = requestVar('batchaction'); + + if ( !is_array($selected) || sizeof($selected) == 0 ) { - $query .= " and cbody LIKE " . DB::quoteValue('%'.$search.'%'); + self::error(_BATCH_NOSELECTION); + return; } - $query .= ' ORDER BY ctime ASC' - . " LIMIT $start,$amount"; - - $template['content'] = 'commentlist'; - $template['canAddBan'] = $member->blogAdminRights(getBlogIDFromItemID($itemid)); - - $manager->loadClass("ENCAPSULATE"); - $navList = new NavList('itemcommentlist', $start, $amount, 0, 1000, 0, $search, $itemid); - $navList->showBatchList('comment',$query,'table',$template,_NOCOMMENTS); + // On delete: check if confirmation has been given + if ( ($action == 'delete') && (requestVar('confirmation') != 'yes') ) + { + self::batchAskDeleteConfirmation('team',$selected); + } - $this->pagefoot(); + self::$skin->parse('batchteam'); return; } /** - * Admin::action_browseowncomments() - * Browse own comments + * Admin::action_batchcategory() * * @param void * @return void */ - public function action_browseowncomments() + static private function action_batchcategory() { - global $member, $manager, $CONF; + global $member, $manager; - // start index - if ( postVar('start') ) - { - $start = intPostVar('start'); - } - else + $member->isLoggedIn() or self::disallow(); + + $selected = requestIntArray('batch'); + $action = requestVar('batchaction'); + + if ( !is_array($selected) || sizeof($selected) == 0 ) { - $start = 0; + self::error(_BATCH_NOSELECTION); + return; } - // amount of items to show - if ( postVar('amount') ) + // On move: when no destination blog chosen, show choice now + $destBlogId = intRequestVar('destblogid'); + if ( ($action == 'move') && (!$manager->existsBlogID($destBlogId)) ) { - $amount = intPostVar('amount'); + self::batchMoveCategorySelectDestination('category', $selected); } - else + + // On delete: check if confirmation has been given + if ( ($action == 'delete') && (requestVar('confirmation') != 'yes') ) { - $amount = intval($CONF['DefaultListSize']); - if ( $amount < 1 ) - { - $amount = 10; - } + self::batchAskDeleteConfirmation('category', $selected); } - $search = postVar('search'); - - $query = 'SELECT cbody, cuser, cmail, mname, ctime, chost, cnumber, cip, citem FROM '.sql_table('comment').' LEFT OUTER JOIN '.sql_table('member').' ON mnumber=cmember WHERE cmember=' . $member->getID(); + self::$skin->parse('batchcategory'); + return; + } + + /** + * Admin::batchMoveSelectDestination() + * + * @param string $type type of batch action + * @param integer $ids needless??? + * @return void + * + * TODO: remove needless argument + */ + static private function batchMoveSelectDestination($type, $ids) + { + $_POST['batchmove'] = $type; + self::$skin->parse('batchmove'); + return; + } + + /** + * Admin::batchMoveCategorySelectDestination() + * + * @param string $type type of batch action + * @param integer $ids needless??? + * @return void + * + * TODO: remove needless argument + */ + static private function batchMoveCategorySelectDestination($type, $ids) + { + $_POST['batchmove'] = $type; + global $manager; + self::$skin->parse('batchmovecat'); + return; + } + + /** + * Admin::batchAskDeleteConfirmation() + * + * @param string $type type of batch action + * @param integer $ids needless??? + * @return void + * + * TODO: remove needless argument + */ + static private function batchAskDeleteConfirmation($type, $ids) + { + self::$skin->parse('batchdelete'); + return; + } + + /** + * Admin::action_browseownitems() + * + * @param void + * @return void + */ + static private function action_browseownitems() + { + global $member, $manager, $CONF; - if ( $search ) + self::$skin->parse('browseownitems'); + return; + } + + /** + * Admin::action_itemcommentlist() + * Show all the comments for a given item + * + * @param integer $itemid ID for item + * @return void + */ + static private function action_itemcommentlist($itemid = '') + { + global $member, $manager, $CONF; + + if ( $itemid == '' ) { - $query .= " and cbody LIKE " . DB::quoteValue('%'.$search.'%'); + $itemid = intRequestVar('itemid'); } - $query .= ' ORDER BY ctime DESC' - . " LIMIT $start,$amount"; - - $this->pagehead(); - - echo '

(' . _BACKHOME . ")

\n"; - echo '

' . _COMMENTS_YOUR . "

\n"; - - $template['content'] = 'commentlist'; - $template['canAddBan'] = 0; // doesn't make sense to allow banning yourself + // only allow if user is allowed to alter item + $member->canAlterItem($itemid) or self::disallow(); - $manager->loadClass("ENCAPSULATE"); - $navList = new NavList('browseowncomments', $start, $amount, 0, 1000, 0, $search, 0); - $navList->showBatchList('comment',$query,'table',$template,_NOCOMMENTS_YOUR); + $item =& $manager->getItem($itemid, 1, 1); + $_REQUEST['itemid'] = $item['itemid']; + $_REQUEST['blogid'] = $item['blogid']; - $this->pagefoot(); + self::$skin->parse('itemcommentlist'); return; } /** - * Admin::action_blogcommentlist() + * Admin::action_browseowncomments() + * Browse own comments * + * @param void + * @return void + */ + static private function action_browseowncomments() + { + self::$skin->parse('browseowncomments'); + return; + } + + /** + * Admin::action_blogcommentlist() * Browse all comments for a weblog + * * @param integer $blogid ID for weblog * @return void */ - function action_blogcommentlist($blogid = '') + static private function action_blogcommentlist($blogid = '') { global $member, $manager, $CONF; @@ -1193,59 +1619,77 @@ class Admin $blogid = intval($blogid); } - $member->teamRights($blogid) or $member->isAdmin() or $this->disallow(); + $member->teamRights($blogid) or $member->isAdmin() or self::disallow(); - // start index - if ( postVar('start') ) - { - $start = intPostVar('start'); - } - else - { - $start = 0; - } + /* TODO: we consider to use the other way insterad of this */ + $_REQUEST['blogid'] = $blogid; - // amount of items to show - if ( postVar('amount') ) - { - $amount = intPostVar('amount'); - } - else + self::$skin->parse('blogcommentlist'); + return; + } + + /** + * Admin::action_createaccount() + * + * @param void + * @return void + */ + static private function action_createaccount() + { + global $CONF; + + if ( $CONF['AllowMemberCreate'] != 1 ) { - $amount = intval($CONF['DefaultListSize']); - if ( $amount < 1 ) - { - $amount = 10; - } + self::$skin->parse('createaccountdisable'); + return; } - $search = postVar('search'); // search through comments + $name = ''; + $realname =''; + $email = ''; + $url = ''; - $query = 'SELECT cbody, cuser, cemail, cmail, mname, ctime, chost, cnumber, cip, citem FROM '.sql_table('comment').' LEFT OUTER JOIN '.sql_table('member').' ON mnumber=cmember WHERE cblog=' . intval($blogid); + $contents = array( + 'name' => '', + 'realname' => '', + 'email' => '', + 'url' => '' + ); - if ( $search != '' ) + if ( array_key_exists('showform', $_POST) && $_POST['showform'] == 1 ) { - $query .= " and cbody LIKE " . DB::quoteValue('%'.$search.'%'); + $action = new Action(); + $message = $action->createAccount(); + if ( $message === 1 ) + { + self::$headMess = $message; + self::$skin->parse('createaccountsuccess'); + return; + } + + /* TODO: validation */ + if ( array_key_exists('name', $_POST) ) + { + $contents['name'] = $_POST['name']; + } + if ( array_key_exists('realname', $_POST) ) + { + $contents['realname'] = $_POST['realname']; + } + if ( array_key_exists('email', $_POST) ) + { + $contents['email'] = $_POST['email']; + } + if ( array_key_exists('url', $_POST) ) + { + $contents['url'] = $_POST['url']; + } + + self::$contents = $contents; + } - $query .= ' ORDER BY ctime DESC' - . " LIMIT $start,$amount"; - - $blog =& $manager->getBlog($blogid); - - $this->pagehead(); - - echo '

(' . _BACKHOME . ")

\n"; - echo '

', _COMMENTS_BLOG , ' ' , $this->bloglink($blog), '

'; - - $template['content'] = 'commentlist'; - $template['canAddBan'] = $member->blogAdminRights($blogid); - - $manager->loadClass("ENCAPSULATE"); - $navList = new NavList('blogcommentlist', $start, $amount, 0, 1000, $blogid, $search, 0); - $navList->showBatchList('comment',$query,'table',$template, _NOCOMMENTS_BLOG); - - $this->pagefoot(); + self::$skin->parse('createaccountinput'); return; } @@ -1256,31 +1700,40 @@ class Admin * @param void * @return void */ - public function action_createitem() + static private function action_createitem() { global $member, $manager; $blogid = intRequestVar('blogid'); // check if allowed - $member->teamRights($blogid) or $this->disallow(); - - $memberid = $member->getID(); + $member->teamRights($blogid) or self::disallow(); $blog =& $manager->getBlog($blogid); + $contents = array(); - // generate the add-item form - $handler = new PageFactory($blog); - - $contents = $handler->getTemplateFor('admin', 'add'); - $manager->notify('PreAddItemForm', array('contents' => &$contents, 'blog' => &$blog)); + $data = array( + 'blog' => &$blog, + 'contents' => &$contents + ); + $manager->notify('PreAddItemForm', $data); - $parser = new Parser($handler); + if ( $blog->convertBreaks() ) + { + if ( array_key_exists('body', $contents) && !empty($contents['body']) ) + { + $contents['body'] = removeBreaks($contents['body']); + } + if ( array_key_exists('more', $contents) && !empty($contents['more']) ) + { + $contents['more'] = removeBreaks($contents['more']); + } + } - $this->pagehead(); - $parser->parse($contents); - $this->pagefoot(); + self::$blog = &$blog; + self::$contents = &$contents; + self::$skin->parse('createitem'); return; } @@ -1290,52 +1743,2422 @@ class Admin * @param void * @return void */ - public function action_itemedit() + static private function action_itemedit() { global $member, $manager; $itemid = intRequestVar('itemid'); // only allow if user is allowed to alter item - $member->canAlterItem($itemid) or $this->disallow(); - - $variables =& $manager->getItem($itemid, 1, 1); - $blog =& $manager->getBlog(getBlogIDFromItemID($itemid)); + $member->canAlterItem($itemid) or self::disallow(); - $manager->notify('PrepareItemForEdit', array('item' => &$variables)); + $item =& $manager->getItem($itemid, 1, 1); + $blog =& $manager->getBlog($item['blogid']); + $data = array('blog'=> &$blog, 'item' => &$item); + $manager->notify('PrepareItemForEdit', $data); if ( $blog->convertBreaks() ) { - $variables['body'] = removeBreaks($variables['body']); - $variables['more'] = removeBreaks($variables['more']); + if ( array_key_exists('body', $item) && !empty($item['body']) ) + { + $item['body'] = removeBreaks($item['body']); + } + if ( array_key_exists('more', $item) && !empty($item['more']) ) + { + $item['more'] = removeBreaks($item['more']); + } } - // form to edit blog items - $handler = new PageFactory($blog); - $handler->setVariables($variables); + self::$blog = &$blog; + self::$contents = &$item; - $content = $handler->getTemplateFor('admin', 'edit'); + self::$skin->parse('itemedit'); + return; + } + + /** + * Admin::action_itemupdate() + * + * @param void + * @return void + */ + static private function action_itemupdate() + { + global $member, $manager, $CONF; - $parser = new Parser($handler); + $itemid = intRequestVar('itemid'); + $catid = postVar('catid'); - $this->pagehead(); - $parser->parse($content); - $this->pagefoot(); + // only allow if user is allowed to alter item + $member->canUpdateItem($itemid, $catid) or self::disallow(); + + $actiontype = postVar('actiontype'); + + // delete actions are handled by itemdelete (which has confirmation) + if ( $actiontype == 'delete' ) + { + self::action_itemdelete(); + return; + } + + $body = postVar('body'); + $title = postVar('title'); + $more = postVar('more'); + $closed = intPostVar('closed'); + $draftid = intPostVar('draftid'); + + // default action = add now + if ( !$actiontype ) + { + $actiontype='addnow'; + } + + // create new category if needed + if ( i18n::strpos($catid,'newcat') === 0 ) + { + // get blogid + list($blogid) = sscanf($catid,"newcat-%d"); + + // create + $blog =& $manager->getBlog($blogid); + $catid = $blog->createNewCategory(); + + // show error when sth goes wrong + if ( !$catid ) + { + self::doError(_ERROR_CATCREATEFAIL); + } + } + + /** + * set some variables based on actiontype + * + * actiontypes: + * draft items -> addnow, addfuture, adddraft, delete + * non-draft items -> edit, changedate, delete + * + * variables set: + * $timestamp: set to a nonzero value for future dates or date changes + * $wasdraft: set to 1 when the item used to be a draft item + * $publish: set to 1 when the edited item is not a draft + */ + $blogid = getBlogIDFromItemID($itemid); + $blog =& $manager->getBlog($blogid); + + $wasdrafts = array('adddraft', 'addfuture', 'addnow'); + $wasdraft = in_array($actiontype, $wasdrafts) ? 1 : 0; + $publish = ($actiontype != 'adddraft' && $actiontype != 'backtodrafts') ? 1 : 0; + if ( $actiontype == 'addfuture' || $actiontype == 'changedate' ) + { + $timestamp = mktime(intPostVar('hour'), intPostVar('minutes'), 0, intPostVar('month'), intPostVar('day'), intPostVar('year')); + } + else + { + $timestamp =0; + } + + // edit the item for real + Item::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp); + + self::updateFuturePosted($blogid); + + if ( $draftid > 0 ) + { + // delete permission is checked inside Item::delete() + Item::delete($draftid); + } + + if ( $catid != intPostVar('catid') ) + { + self::action_categoryedit( + $catid, + $blog->getID(), + $CONF['AdminURL'] . 'index.php?action=itemlist&blogid=' . getBlogIDFromItemID($itemid) + ); + } + else + { + // TODO: set start item correctly for itemlist + $item =& $manager->getitem($itemid, 1, 1); + $query = "SELECT COUNT(*) FROM %s WHERE unix_timestamp(itime) <= '%s';"; + $query = sprintf($query, sql_table('item'), $item['timestamp']); + $cnt = DB::getValue($query); + $_REQUEST['start'] = $cnt + 1; + self::action_itemlist(getBlogIDFromItemID($itemid)); + } return; } - /** - * @todo document this - */ - function action_itemupdate() { - global $member, $manager, $CONF; - - $itemid = intRequestVar('itemid'); - $catid = postVar('catid'); - - // only allow if user is allowed to alter item - $member->canUpdateItem($itemid, $catid) or $this->disallow(); - + /** + * Admin::action_itemdelete() + * Delete item + * + * @param Void + * @return Void + */ + static private function action_itemdelete() + { + global $member, $manager; + + $itemid = intRequestVar('itemid'); + + // only allow if user is allowed to alter item + $member->canAlterItem($itemid) or self::disallow(); + + if ( !$manager->existsItem($itemid,1,1) ) + { + self::error(_ERROR_NOSUCHITEM); + return; + } + + self::$skin->parse('itemdelete'); + return; + } + + /** + * Admin::action_itemdeleteconfirm() + * + * @param void + * @return void + */ + static private function action_itemdeleteconfirm() + { + global $member, $manager; + + $itemid = intRequestVar('itemid'); + + // only allow if user is allowed to alter item + $member->canAlterItem($itemid) or self::disallow(); + + // get item first + $item =& $manager->getItem($itemid, 1, 1); + + // delete item (note: some checks will be performed twice) + self::deleteOneItem($item['itemid']); + + self::action_itemlist($item['blogid']); + return; + } + + /** + * Admin::deleteOneItem() + * Deletes one item and returns error if something goes wrong + * + * @param integer $itemid ID for item + * @return void + */ + static public function deleteOneItem($itemid) + { + global $member, $manager; + + // only allow if user is allowed to alter item (also checks if itemid exists) + if ( !$member->canAlterItem($itemid) ) + { + return _ERROR_DISALLOWED; + } + + // need to get blogid before the item is deleted + $item =& $manager->getItem($itemid, 1, 1); + + $manager->loadClass('ITEM'); + Item::delete($item['itemid']); + + // update blog's futureposted + self::updateFuturePosted($item['itemid']); + return; + } + + /** + * Admin::updateFuturePosted() + * Update a blog's future posted flag + * + * @param integer $blogid + * @return void + */ + static private function updateFuturePosted($blogid) + { + global $manager; + + $blogid = intval($blogid); + $blog =& $manager->getBlog($blogid); + $currenttime = $blog->getCorrectTime(time()); + + $query = "SELECT * FROM %s WHERE iblog=%d AND iposted=0 AND itime>'%s'"; + $query = sprintf($query, sql_table('item'), (integer) $blogid, i18n::formatted_datetime('mysql', $currenttime)); + $result = DB::getResult($query); + + if ( $result->rowCount() > 0 ) + { + $blog->setFuturePost(); + } + else + { + $blog->clearFuturePost(); + } + return; + } + + /** + * Admin::action_itemmove() + * + * @param void + * @return void + */ + static private function action_itemmove() + { + global $member, $manager; + + $itemid = intRequestVar('itemid'); + + $member->canAlterItem($itemid) or self::disallow(); + + self::$skin->parse('itemmove'); + return; + } + + /** + * Admin::action_itemmoveto() + * + * @param void + * @return void + */ + static private function action_itemmoveto() + { + global $member, $manager; + + $itemid = intRequestVar('itemid'); + $catid = requestVar('catid'); + + // create new category if needed + if ( i18n::strpos($catid,'newcat') === 0 ) + { + // get blogid + list($blogid) = sscanf($catid,'newcat-%d'); + + // create + $blog =& $manager->getBlog($blogid); + $catid = $blog->createNewCategory(); + + // show error when sth goes wrong + if ( !$catid ) + { + self::doError(_ERROR_CATCREATEFAIL); + } + } + + // only allow if user is allowed to alter item + $member->canUpdateItem($itemid, $catid) or self::disallow(); + + $old_blogid = getBlogIDFromItemId($itemid); + + Item::move($itemid, $catid); + + // set the futurePosted flag on the blog + self::updateFuturePosted(getBlogIDFromItemId($itemid)); + + // reset the futurePosted in case the item is moved from one blog to another + self::updateFuturePosted($old_blogid); + + if ( $catid != intRequestVar('catid') ) + { + self::action_categoryedit($catid, $blog->getID()); + } + else + { + self::action_itemlist(getBlogIDFromCatID($catid)); + } + return; + } + + /** + * Admin::moveOneItem() + * Moves one item to a given category (category existance should be checked by caller) + * errors are returned + * + * @param integer $itemid ID for item + * @param integer $destCatid ID for category to which the item will be moved + * @return void + */ + static public function moveOneItem($itemid, $destCatid) + { + global $member; + + // only allow if user is allowed to move item + if ( !$member->canUpdateItem($itemid, $destCatid) ) + { + return _ERROR_DISALLOWED; + } + + Item::move($itemid, $destCatid); + return; + } + + /** + * Admin::action_additem() + * Adds a item to the chosen blog + * + * @param void + * @return void + */ + static private function action_additem() + { + global $manager, $CONF; + + $manager->loadClass('ITEM'); + + $result = Item::createFromRequest(); + + if ( $result['status'] == 'error' ) + { + self::error($result['message']); + return; + } + + $item =& $manager->getItem($result['itemid'], 0, 0); + + if ( $result['status'] == 'newcategory' ) + { + $distURI = $manager->addTicketToUrl($CONF['AdminURL'] . 'index.php?action=itemList&blogid=' . $item['blogid']); + self::action_categoryedit($result['catid'], $item['blogid'], $distURI); + } + else + { + $methodName = 'action_itemlist'; + self::action_itemlist($item['blogid']); + } + return; + } + + /** + * Admin::action_commentedit() + * Allows to edit previously made comments + * + * @param void + * @return void + */ + static private function action_commentedit() + { + global $member, $manager; + + $commentid = intRequestVar('commentid'); + + $member->canAlterComment($commentid) or self::disallow(); + + $comment = Comment::getComment($commentid); + $data = array('comment' => &$comment); + $manager->notify('PrepareCommentForEdit', $data); + + self::$contents = $comment; + self::$skin->parse('commentedit'); + return; + } + + /** + * Admin::action_commentupdate() + * + * @param void + * @return void + */ + static private function action_commentupdate() + { + global $member, $manager; + + $commentid = intRequestVar('commentid'); + + $member->canAlterComment($commentid) or self::disallow(); + + $url = postVar('url'); + $email = postVar('email'); + $body = postVar('body'); + + // intercept words that are too long + if (preg_match('#[a-zA-Z0-9|\.,;:!\?=\/\\\\]{90,90}#', $body) != FALSE) + { + self::error(_ERROR_COMMENT_LONGWORD); + return; + } + + // check length + if ( i18n::strlen($body) < 3 ) + { + self::error(_ERROR_COMMENT_NOCOMMENT); + return; + } + + if ( i18n::strlen($body) > 5000 ) + { + self::error(_ERROR_COMMENT_TOOLONG); + return; + } + + // prepare body + $body = Comment::prepareBody($body); + + // call plugins + $data = array( + 'body' => &$body + ); + $manager->notify('PreUpdateComment', $data); + + $query = "UPDATE %s SET cmail=%s, cemail=%s, cbody=%s WHERE cnumber=%d;"; + $query = sprintf($query, sql_table('comment'), DB::quoteValue($url), DB::quoteValue($email), DB::quoteValue($body), (integer) $commentid); + DB::execute($query); + + // get itemid + $query = "SELECT citem FROM %s WHERE cnumber=%d;"; + $query = sprintf($query, sql_table('comment'), (integer) $commentid); + + $itemid = DB::getValue($query); + + if ( $member->canAlterItem($itemid) ) + { + self::action_itemcommentlist($itemid); + } + else + { + self::action_browseowncomments(); + } + return; + } + + /** + * Admin::action_commentdelete() + * Update comment + * + * @param void + * @return void + */ + static private function action_commentdelete() + { + global $member, $manager; + + $commentid = intRequestVar('commentid'); + $member->canAlterComment($commentid) or self::disallow(); + + self::$skin->parse('commentdelete'); + return; + } + + /** + * Admin::action_commentdeleteconfirm() + * + * @param void + * @return void + */ + static private function action_commentdeleteconfirm() + { + global $member; + + $commentid = intRequestVar('commentid'); + + // get item id first + $query = "SELECT citem FROM %s WHERE cnumber=%d;"; + $query = sprintf($query, sql_table('comment'), (integer) $commentid); + + $itemid = DB::getValue($query); + + $error = self::deleteOneComment($commentid); + if ( $error ) + { + self::doError($error); + } + + if ( $member->canAlterItem($itemid) ) + { + self::action_itemcommentlist($itemid); + } + else + { + self::action_browseowncomments(); + } + return; + } + + /** + * Admin::deleteOneComment() + * + * @param integer $commentid ID for comment + * @return void + */ + static public function deleteOneComment($commentid) + { + global $member, $manager; + + $commentid = (integer) $commentid; + + if ( !$member->canAlterComment($commentid) ) + { + return _ERROR_DISALLOWED; + } + + $data = array( + 'commentid' => $commentid + ); + + $manager->notify('PreDeleteComment', $data); + + // delete the comments associated with the item + $query = "DELETE FROM %s WHERE cnumber=%d;"; + $query = sprintf($query, sql_table('comment'), (integer) $commentid); + DB::execute($query); + + $data = array( + 'commentid' => $commentid + ); + + $manager->notify('PostDeleteComment', $data); + + return ''; + } + + /** + * Admin::action_usermanagement() + * Usermanagement main + * + * @param void + * @return void + */ + static private function action_usermanagement() + { + global $member, $manager; + + // check if allowed + $member->isAdmin() or self::disallow(); + + self::$skin->parse('usermanagement'); + return; + } + + /** + * Admin::action_memberedit() + * Edit member settings + * + * @param void + * @return void + */ + static private function action_memberedit() + { + self::action_editmembersettings(intRequestVar('memberid')); + return; + } + + /** + * Admin::action_editmembersettings() + * + * @param integer $memberid ID for member + * @return void + * + */ + static private function action_editmembersettings($memberid = '') + { + global $member, $manager, $CONF; + + if ( $memberid == '' ) + { + $memberid = $member->getID(); + } + + /* TODO: we should consider to use the other way insterad of this */ + $_REQUEST['memberid'] = $memberid; + + // check if allowed + ($member->getID() == $memberid) or $member->isAdmin() or self::disallow(); + + self::$extrahead .= "\n"; + + self::$skin->parse('editmembersettings'); + return; + } + + /** + * Admin::action_changemembersettings() + * + * @param void + * @return void + */ + static private function action_changemembersettings() + { + global $member, $CONF, $manager; + + $memberid = intRequestVar('memberid'); + + // check if allowed + ($member->getID() == $memberid) or $member->isAdmin() or self::disallow(); + + $name = trim(strip_tags(postVar('name'))); + $realname = trim(strip_tags(postVar('realname'))); + $password = postVar('password'); + $repeatpassword = postVar('repeatpassword'); + $email = strip_tags(postVar('email')); + $url = strip_tags(postVar('url')); + $adminskin = intPostVar('adminskin'); + $bookmarklet = intPostVar('bookmarklet'); + + // begin if: sometimes user didn't prefix the URL with http:// or https://, this cause a malformed URL. Let's fix it. + if ( !preg_match('#^https?://#', $url) ) + { + $url = 'http://' . $url; + } + + $admin = postVar('admin'); + $canlogin = postVar('canlogin'); + $notes = strip_tags(postVar('notes')); + $locale = postVar('locale'); + + $mem =& $manager->getMember($memberid); + + if ( $CONF['AllowLoginEdit'] || $member->isAdmin() ) + { + if ( !isValidDisplayName($name) ) + { + self::error(_ERROR_BADNAME); + return; + } + + if ( ($name != $mem->getDisplayName()) && Member::exists($name) ) + { + self::error(_ERROR_NICKNAMEINUSE); + return; + } + + if ( $password != $repeatpassword ) + { + self::error(_ERROR_PASSWORDMISMATCH); + return; + } + + if ( $password && (i18n::strlen($password) < 6) ) + { + self::error(_ERROR_PASSWORDTOOSHORT); + return; + } + + if ( $password ) + { + $pwdvalid = true; + $pwderror = ''; + + $data = array( + 'password' => $password, + 'errormessage' => &$pwderror, + 'valid' => &$pwdvalid + ); + $manager->notify('PrePasswordSet', $data); + + if ( !$pwdvalid ) + { + self::error($pwderror); + return; + } + } + } + + if ( !NOTIFICATION::address_validation($email) ) + { + self::error(_ERROR_BADMAILADDRESS); + return; + } + if ( !$realname ) + { + self::error(_ERROR_REALNAMEMISSING); + return; + } + if ( ($locale != '') && (!in_array($locale, i18n::get_available_locale_list())) ) + { + self::error(_ERROR_NOSUCHTRANSLATION); + return; + } + + // check if there will remain at least one site member with both the logon and admin rights + // (check occurs when taking away one of these rights from such a member) + if ( (!$admin && $mem->isAdmin() && $mem->canLogin()) + || (!$canlogin && $mem->isAdmin() && $mem->canLogin()) + ) + { + $r = DB::getResult('SELECT * FROM '.sql_table('member').' WHERE madmin=1 and mcanlogin=1'); + if ( $r->rowCount() < 2 ) + { + self::error(_ERROR_ATLEASTONEADMIN); + return; + } + } + + if ( $CONF['AllowLoginEdit'] || $member->isAdmin() ) + { + $mem->setDisplayName($name); + if ( $password ) + { + $mem->setPassword($password); + } + } + + $oldEmail = $mem->getEmail(); + + $mem->setRealName($realname); + $mem->setEmail($email); + $mem->setURL($url); + $mem->setNotes($notes); + $mem->setLocale($locale); + $mem->setAdminSkin($adminskin); + $mem->setBookmarklet($bookmarklet); + + // only allow super-admins to make changes to the admin status + if ( $member->isAdmin() ) + { + $mem->setAdmin($admin); + $mem->setCanLogin($canlogin); + } + + $autosave = postVar('autosave'); + $mem->setAutosave($autosave); + + $mem->write(); + + // store plugin options + $aOptions = requestArray('plugoption'); + NucleusPlugin::apply_plugin_options($aOptions); + $data = array( + 'context' => 'member', + 'memberid' => $memberid, + 'member' => &$mem + ); + $manager->notify('PostPluginOptionsUpdate', $data); + + // if email changed, generate new password + if ( $oldEmail != $mem->getEmail() ) + { + $mem->sendActivationLink('addresschange', $oldEmail); + // logout member + $mem->newCookieKey(); + + // only log out if the member being edited is the current member. + if ( $member->getID() == $memberid ) + { + $member->logout(); + } + self::action_login(_MSG_ACTIVATION_SENT, 0); + return; + } + + if ( ($mem->getID() == $member->getID()) + && ($mem->getDisplayName() != $member->getDisplayName()) ) + { + $mem->newCookieKey(); + $member->logout(); + self::action_login(_MSG_LOGINAGAIN, 0); + } + else + { + self::action_overview(_MSG_SETTINGSCHANGED); + } + return; + } + + /** + * Admin::action_memberadd() + * + * @param void + * @return void + * + */ + static private function action_memberadd() + { + global $member, $manager; + + // check if allowed + $member->isAdmin() or self::disallow(); + + if ( postVar('password') != postVar('repeatpassword') ) + { + self::error(_ERROR_PASSWORDMISMATCH); + return; + } + + if ( i18n::strlen(postVar('password')) < 6 ) + { + self::error(_ERROR_PASSWORDTOOSHORT); + return; + } + + $res = Member::create( + postVar('name'), + postVar('realname'), + postVar('password'), + postVar('email'), + postVar('url'), + postVar('admin'), + postVar('canlogin'), + postVar('notes') + ); + + if ( $res != 1 ) + { + self::error($res); + return; + } + + // fire PostRegister event + $newmem = new Member(); + $newmem->readFromName(postVar('name')); + $data = array( + 'member' => &$newmem + ); + $manager->notify('PostRegister', $data); + + self::action_usermanagement(); + return; + } + + /** + * Admin::action_forgotpassword() + * + * @param void + * @return void + */ + static private function action_forgotpassword() + { + self::$skin->parse('forgotpassword'); + return; + } + + /** + * Admin::action_activate() + * Account activation + * + * @param void + * @return void + */ + static private function action_activate() + { + $key = getVar('key'); + self::showActivationPage($key); + return; + } + + /** + * Admin::showActivationPage() + * + * @param void + * @return void + */ + static private function showActivationPage($key, $message = '') + { + global $manager; + + // clean up old activation keys + Member::cleanupActivationTable(); + + // get activation info + $info = Member::getActivationInfo($key); + + if ( !$info ) + { + self::error(_ERROR_ACTIVATE); + return; + } + + $mem =& $manager->getMember($info->vmember); + + if ( !$mem ) + { + self::error(_ERROR_ACTIVATE); + return; + } + + /* TODO: we should consider to use the other way insterad of this */ + $_POST['ackey'] = $key; + $_POST['bNeedsPasswordChange'] = TRUE; + + self::$headMess = $message; + self::$skin->parse('activate'); + return; + } + + /** + * Admin::action_activatesetpwd() + * Account activation - set password part + * + * @param void + * @return void + */ + static private function action_activatesetpwd() + { + global $manager; + $key = postVar('key'); + + // clean up old activation keys + Member::cleanupActivationTable(); + + // get activation info + $info = Member::getActivationInfo($key); + + if ( !$info || ($info->type == 'addresschange') ) + { + return self::showActivationPage($key, _ERROR_ACTIVATE); + } + + $mem =& $manager->getMember($info->vmember); + + if ( !$mem ) + { + return self::showActivationPage($key, _ERROR_ACTIVATE); + } + + $password = postVar('password'); + $repeatpassword = postVar('repeatpassword'); + + if ( $password != $repeatpassword ) + { + return self::showActivationPage($key, _ERROR_PASSWORDMISMATCH); + } + + if ( $password && (i18n::strlen($password) < 6) ) + { + return self::showActivationPage($key, _ERROR_PASSWORDTOOSHORT); + } + + if ( $password ) + { + $pwdvalid = true; + $pwderror = ''; + + $data = array( + 'password' => $password, + 'errormessage' => &$pwderror, + 'valid' => &$pwdvalid + ); + $manager->notify('PrePasswordSet', $data); + if ( !$pwdvalid ) + { + return self::showActivationPage($key,$pwderror); + } + } + + $error = ''; + + $data = array( + 'type' => 'activation', + 'member' => $mem, + 'error' => &$error + ); + $manager->notify('ValidateForm', $data); + if ( $error != '' ) + { + return self::showActivationPage($key, $error); + } + + // set password + $mem->setPassword($password); + $mem->write(); + + // do the activation + Member::activate($key); + + self::$skin->parse('activatesetpwd'); + return; + } + + /** + * Admin::action_manageteam() + * Manage team + * + * @param void + * @return void + */ + static private function action_manageteam() + { + global $member, $manager; + + $blogid = intRequestVar('blogid'); + + // check if allowed + $member->blogAdminRights($blogid) or self::disallow(); + + self::$skin->parse('manageteam'); + return; + } + + /** + * Admin::action_teamaddmember() + * Add member to team + * + * @param void + * @return void + */ + static private function action_teamaddmember() + { + global $member, $manager; + + $memberid = intPostVar('memberid'); + $blogid = intPostVar('blogid'); + $admin = intPostVar('admin'); + + // check if allowed + $member->blogAdminRights($blogid) or self::disallow(); + + $blog =& $manager->getBlog($blogid); + if ( !$blog->addTeamMember($memberid, $admin) ) + { + self::error(_ERROR_ALREADYONTEAM); + return; + } + + self::action_manageteam(); + return; + } + + /** + * Admin::action_teamdelete() + * + * @param void + * @return void + */ + static private function action_teamdelete() + { + global $member, $manager; + + $memberid = intRequestVar('memberid'); + $blogid = intRequestVar('blogid'); + + // check if allowed + $member->blogAdminRights($blogid) or self::disallow(); + + $teammem =& $manager->getMember($memberid); + $blog =& $manager->getBlog($blogid); + + self::$skin->parse('teamdelete'); + return; + } + + /** + * Admin::action_teamdeleteconfirm() + * + * @param void + * @return void + */ + static private function action_teamdeleteconfirm() + { + global $member; + + $memberid = intRequestVar('memberid'); + $blogid = intRequestVar('blogid'); + + $error = self::deleteOneTeamMember($blogid, $memberid); + if ( $error ) + { + self::error($error); + return; + } + self::action_manageteam(); + return; + } + + /** + * Admin::deleteOneTeamMember() + * + * @param void + * @return void + */ + static public function deleteOneTeamMember($blogid, $memberid) + { + global $member, $manager; + + $blogid = intval($blogid); + $memberid = intval($memberid); + + // check if allowed + if ( !$member->blogAdminRights($blogid) ) + { + return _ERROR_DISALLOWED; + } + + // check if: - there remains at least one blog admin + // - (there remains at least one team member) + $tmem =& $manager->getMember($memberid); + + + $data = array( + 'member' => &$tmem, + 'blogid' => $blogid + ); + $manager->notify('PreDeleteTeamMember', $data); + + if ( $tmem->isBlogAdmin($blogid) ) + { + /* TODO: why we did double check? */ + // check if there are more blog members left and at least one admin + // (check for at least two admins before deletion) + $query = "SELECT * FROM %s WHERE tblog=%d and tadmin=1;"; + $query = sprintf($query, sql_table('team'), (integer) $blogid); + $r = DB::getResult($query); + if ( $r->rowCount() < 2 ) + { + return _ERROR_ATLEASTONEBLOGADMIN; + } + } + + $query = "DELETE FROM %s WHERE tblog=%d AND tmember=%d;"; + $query = sprintf($query, sql_table('team'), (integer) $blogid, (integer) $memberid); + DB::execute($query); + + $data = array( + 'member' => &$tmem, + 'blogid' => $blogid + ); + $manager->notify('PostDeleteTeamMember', $data); + + return ''; + } + + /** + * Admin::action_teamchangeadmin() + * + * @param void + * @return void + */ + static private function action_teamchangeadmin() + { + global $manager, $member; + + $blogid = intRequestVar('blogid'); + $memberid = intRequestVar('memberid'); + + // check if allowed + $member->blogAdminRights($blogid) or self::disallow(); + + $mem =& $manager->getMember($memberid); + + // don't allow when there is only one admin at this moment + if ( $mem->isBlogAdmin($blogid) ) + { + $query = "SELECT * FROM %s WHERE tblog=%d AND tadmin=1;"; + $query = sprintf($query, sql_table('team'), (integer) $blogid); + $r = DB::getResult($query); + if ( $r->rowCount() == 1 ) + { + self::error(_ERROR_ATLEASTONEBLOGADMIN); + return; + } + } + + if ( $mem->isBlogAdmin($blogid) ) + { + $newval = 0; + } + else + { + $newval = 1; + } + + $query = "UPDATE %s SET tadmin=%d WHERE tblog=%d and tmember=%d;"; + $query = sprintf($query, (integer) $blogid, (integer) $newval, (integer) $blogid, (integer) $memberid); + DB::execute($query); + + // only show manageteam if member did not change its own admin privileges + if ( $member->isBlogAdmin($blogid) ) + { + self::action_manageteam(); + } + else + { + self::action_overview(_MSG_ADMINCHANGED); + } + return; + } + + /** + * Admin::action_blogsettings() + * + * @param void + * @return void + */ + static private function action_blogsettings() + { + global $member, $manager; + + $blogid = intRequestVar('blogid'); + + // check if allowed + $member->blogAdminRights($blogid) or self::disallow(); + + $blog =& $manager->getBlog($blogid); + + self::$extrahead .= "\n"; + + self::$skin->parse('blogsettings'); + return; + } + + /** + * Admin::action_categorynew() + * + * @param void + * @return void + */ + static private function action_categorynew() + { + global $member, $manager; + + $blogid = intRequestVar('blogid'); + + $member->blogAdminRights($blogid) or self::disallow(); + + $cname = postVar('cname'); + $cdesc = postVar('cdesc'); + + if ( !isValidCategoryName($cname) ) + { + self::error(_ERROR_BADCATEGORYNAME); + return; + } + + $query = "SELECT * FROM %s WHERE cname=%s AND cblog=%d;"; + $query = sprintf($query, sql_table('category'), DB::quoteValue($cname), (integer) $blogid); + $res = DB::getResult($query); + if ( $res->rowCount() > 0 ) + { + self::error(_ERROR_DUPCATEGORYNAME); + return; + } + + $blog =& $manager->getBlog($blogid); + $newCatID = $blog->createNewCategory($cname, $cdesc); + + self::action_blogsettings(); + return; + } + + /** + * Admin::action_categoryedit() + * + * @param void + * @return void + */ + static private function action_categoryedit($catid = '', $blogid = '', $desturl = '') + { + global $member, $manager; + + if ( $blogid == '' ) + { + $blogid = intGetVar('blogid'); + } + else + { + $blogid = intval($blogid); + } + if ( $catid == '' ) + { + $catid = intGetVar('catid'); + } + else + { + $catid = intval($catid); + } + + /* TODO: we should consider to use the other way insterad of this */ + $_REQUEST['blogid'] = $blogid; + $_REQUEST['catid'] = $catid; + $_REQUEST['desturl'] = $desturl; + $member->blogAdminRights($blogid) or self::disallow(); + + self::$extrahead .= "\n"; + + self::$skin->parse('categoryedit'); + return; + } + + /** + * Admin::action_categoryupdate() + * + * @param void + * @return void + */ + static private function action_categoryupdate() + { + global $member, $manager; + + $blogid = intPostVar('blogid'); + $catid = intPostVar('catid'); + $cname = postVar('cname'); + $cdesc = postVar('cdesc'); + $desturl = postVar('desturl'); + + $member->blogAdminRights($blogid) or self::disallow(); + + if ( !isValidCategoryName($cname) ) + { + self::error(_ERROR_BADCATEGORYNAME); + return; + } + + $query = "SELECT * FROM %s WHERE cname=%s AND cblog=%d AND not(catid=%d);"; + $query = sprintf($query, sql_table('category'), DB::quoteValue($cname), (integer) $blogid, (integer) $catid); + $res = DB::getResult($query); + if ( $res->rowCount() > 0 ) + { + self::error(_ERROR_DUPCATEGORYNAME); + return; + } + + $query = "UPDATE %s SET cname=%s, cdesc=%s WHERE catid=%d;"; + $query = sprintf($query, sql_table('category'), DB::quoteValue($cname), DB::quoteValue($cdesc), (integer) $catid); + DB::execute($query); + + // store plugin options + $aOptions = requestArray('plugoption'); + NucleusPlugin::apply_plugin_options($aOptions); + $data = array( + 'context' => 'category', + 'catid' => $catid + ); + $manager->notify('PostPluginOptionsUpdate', $data); + + if ( $desturl ) + { + redirect($desturl); + return; + } + + self::action_blogsettings(); + + return; + } + + /** + * Admin::action_categorydelete() + * + * @param void + * @return void + */ + static private function action_categorydelete() + { + global $member, $manager; + + $blogid = intRequestVar('blogid'); + $catid = intRequestVar('catid'); + + $member->blogAdminRights($blogid) or self::disallow(); + + $blog =& $manager->getBlog($blogid); + + // check if the category is valid + if ( !$blog->isValidCategory($catid) ) + { + self::error(_ERROR_NOSUCHCATEGORY); + return; + } + + // don't allow deletion of default category + if ( $blog->getDefaultCategory() == $catid ) + { + self::error(_ERROR_DELETEDEFCATEGORY); + return; + } + + // check if catid is the only category left for blogid + $query = "SELECT catid FROM %s WHERE cblog=%d;"; + $query = sprintf($query, sql_table('category'), $blogid); + $res = DB::getResult($query); + if ( $res->rowCount() == 1 ) + { + self::error(_ERROR_DELETELASTCATEGORY); + return; + } + + self::$skin->parse('categorydelete'); +>>>>>>> skinnable-master + return; + } + + /** +<<<<<<< HEAD + * Admin::action_browseownitems() +======= + * Admin::action_categorydeleteconfirm() +>>>>>>> skinnable-master + * + * @param void + * @return void + */ +<<<<<<< HEAD + public function action_browseownitems() + { + global $member, $manager, $CONF; + + $this->pagehead(); + + echo '

(' . _BACKHOME . ")

\n"; + echo '

' . _ITEMLIST_YOUR . "

\n"; + + // start index + if ( postVar('start') ) + { + $start = intPostVar('start'); + } + else + { + $start = 0; + } + + // amount of items to show + if ( postVar('amount') ) + { + $amount = intPostVar('amount'); + } + else + { + $amount = (integer) $CONF['DefaultListSize']; + if ( $amount < 1 ) + { + $amount = 10; + } + } + + $search = postVar('search'); // search through items + + $query = 'SELECT bshortname, cname, mname, ititle, ibody, idraft, inumber, itime' + . ' FROM '.sql_table('item').', '.sql_table('blog') . ', '.sql_table('member') . ', '.sql_table('category') + . ' WHERE iauthor='. $member->getID() .' and iauthor=mnumber and iblog=bnumber and icat=catid'; + + if ( $search ) + { + $query .= " and ((ititle LIKE " . DB::quoteValue('%'.$search.'%') . ") or (ibody LIKE " . DB::quoteValue('%'.$search.'%') . ") or (imore LIKE " . DB::quoteValue('%'.$search.'%') . "))"; + } + + $query .= ' ORDER BY itime DESC' + . " LIMIT $start, $amount"; + + $template['content'] = 'itemlist'; + $template['now'] = time(); + + $manager->loadClass("ENCAPSULATE"); + $navList = new NavList('browseownitems', $start, $amount, 0, 1000, /*$blogid*/ 0, $search, 0); + $navList->showBatchList('item',$query,'table',$template); + + $this->pagefoot(); +======= + static private function action_categorydeleteconfirm() + { + global $member, $manager; + + $blogid = intRequestVar('blogid'); + $catid = intRequestVar('catid'); + + $member->blogAdminRights($blogid) or self::disallow(); + + $error = self::deleteOneCategory($catid); + if ( $error ) + { + self::error($error); + return; + } + + self::action_blogsettings(); + return; + } + + /** + * Admin::deleteOneCategory() + * Delete a category by its id + * + * @param String $catid category id for deleting + * @return Void + */ + static public function deleteOneCategory($catid) + { + global $manager, $member; + + $catid = intval($catid); + $blogid = getBlogIDFromCatID($catid); + + if ( !$member->blogAdminRights($blogid) ) + { + return ERROR_DISALLOWED; + } + + // get blog + $blog =& $manager->getBlog($blogid); + + // check if the category is valid + if ( !$blog || !$blog->isValidCategory($catid) ) + { + return _ERROR_NOSUCHCATEGORY; + } + + $destcatid = $blog->getDefaultCategory(); + + // don't allow deletion of default category + if ( $blog->getDefaultCategory() == $catid ) + { + return _ERROR_DELETEDEFCATEGORY; + } + + // check if catid is the only category left for blogid + $query = "SELECT catid FROM %s WHERE cblog=%d;"; + $query = sprintf($query, sql_table('category'), (integer) $blogid); + + $res = DB::getResult($query); + if ( $res->rowCount() == 1 ) + { + return _ERROR_DELETELASTCATEGORY; + } + + $data = array('catid' => $catid); + $manager->notify('PreDeleteCategory', $data); + + // change category for all items to the default category + $query = "UPDATE %s SET icat=%d WHERE icat=%d;"; + $query =sprintf($query, sql_table('item'), (integer) $destcatid, (integer) $catid); + DB::execute($query); + + // delete all associated plugin options + NucleusPlugin::delete_option_values('category', (integer) $catid); + + // delete category + $query = "DELETE FROM %s WHERE catid=%d;"; + $query = sprintf($query, sql_table('category'), (integer) $catid); + DB::execute($query); + + $data = array('catid' => $catid); + $manager->notify('PostDeleteCategory', $data); +>>>>>>> skinnable-master + return; + } + + /** +<<<<<<< HEAD + * Admin::action_itemcommentlist() + * + * Show all the comments for a given item + * @param integer $itemid ID for item + * @return void + */ + public function action_itemcommentlist($itemid = '') + { + global $member, $manager, $CONF; + + if ( $itemid == '' ) + { + $itemid = intRequestVar('itemid'); + } + + // only allow if user is allowed to alter item + $member->canAlterItem($itemid) or $this->disallow(); + + $blogid = getBlogIdFromItemId($itemid); + + $this->pagehead(); + + // start index + if ( postVar('start') ) + { + $start = intPostVar('start'); + } + else + { + $start = 0; + } + + // amount of items to show + if ( postVar('amount') ) + { + $amount = intPostVar('amount'); + } + else + { + $amount = (integer) $CONF['DefaultListSize']; + if ( $amount < 1 ) + { + $amount = 10; + } + } + + $search = postVar('search'); + + echo '

(' . _BACKTOOVERVIEW . ")

\n"; + echo '

',_COMMENTS,'

'; + + $query = 'SELECT cbody, cuser, cmail, cemail, mname, ctime, chost, cnumber, cip, citem FROM ' . sql_table('comment') . ' LEFT OUTER JOIN ' . sql_table('member') . ' ON mnumber = cmember WHERE citem = ' . $itemid; + + if ( $search ) + { + $query .= " and cbody LIKE " . DB::quoteValue('%'.$search.'%'); + } + + $query .= ' ORDER BY ctime ASC' + . " LIMIT $start,$amount"; + + $template['content'] = 'commentlist'; + $template['canAddBan'] = $member->blogAdminRights(getBlogIDFromItemID($itemid)); + + $manager->loadClass("ENCAPSULATE"); + $navList = new NavList('itemcommentlist', $start, $amount, 0, 1000, 0, $search, $itemid); + $navList->showBatchList('comment',$query,'table',$template,_NOCOMMENTS); + + $this->pagefoot(); +======= + * Admin::moveOneCategory() + * Delete a category by its id + * + * @param int $catid category id for move + * @param int $destblogid blog id for destination + * @return void + */ + static public function moveOneCategory($catid, $destblogid) + { + global $manager, $member; + $catid = intval($catid); + $destblogid = intval($destblogid); + $blogid = getBlogIDFromCatID($catid); + // mover should have admin rights on both blogs + if (!$member->blogAdminRights($blogid)) { + return _ERROR_DISALLOWED; + } + if (!$member->blogAdminRights($destblogid)) { + return _ERROR_DISALLOWED; + } + // cannot move to self + if ($blogid == $destblogid) { + return _ERROR_MOVETOSELF; + } + // get blogs + $blog =& $manager->getBlog($blogid); + $destblog =& $manager->getBlog($destblogid); + // check if the category is valid + if (!$blog || !$blog->isValidCategory($catid)) { + return _ERROR_NOSUCHCATEGORY; + } + // don't allow default category to be moved + if ($blog->getDefaultCategory() == $catid) { + return _ERROR_MOVEDEFCATEGORY; + } + $data = array( + 'catid' => &$catid, + 'sourceblog' => &$blog, + 'destblog' => &$destblog + ); + $manager->notify('PreMoveCategory', $data); + // update comments table (cblog) + $query = 'SELECT ' + . ' inumber ' + . 'FROM ' + . sql_table('item') . ' ' + . 'WHERE ' + . ' icat = %d'; + $items = sql_query(sprintf($query, $catid)); + while ($oItem = sql_fetch_object($items)) { + $query = 'UPDATE ' + . sql_table('comment') . ' ' + . 'SET ' + . ' cblog = %d' . ' ' + . 'WHERE ' + . ' citem = %d'; + sql_query(sprintf($query, $destblogid, $oItem->inumber)); + } + + // update items (iblog) + $query = 'UPDATE ' + . sql_table('item') . ' ' + . 'SET ' + . ' iblog = %d ' + . 'WHERE ' + . ' icat = %d'; + sql_query(sprintf($query, $destblogid, $catid)); + + // move category + $query = 'UPDATE ' + . sql_table('category') . ' ' + . 'SET ' + . ' cblog = %d' . ' ' + . 'WHERE ' + . ' catid = %d'; + sql_query(sprintf($query, $destblogid, $catid)); + + $data = array( + 'catid' => &$catid, + 'sourceblog' => &$blog, + 'destblog' => $destblog + ); + $manager->notify('PostMoveCategory', $data); + return; + } + + /** + * Admin::action_blogsettingsupdate + * Updating blog settings + * + * @param Void + * @return Void + */ + static private function action_blogsettingsupdate() + { + global $member, $manager; + + $blogid = intRequestVar('blogid'); + + $member->blogAdminRights($blogid) or self::disallow(); + + $blog =& $manager->getBlog($blogid); + + $notify_address = trim(postVar('notify')); + $shortname = trim(postVar('shortname')); + $updatefile = trim(postVar('update')); + + $notifyComment = intPostVar('notifyComment'); + $notifyVote = intPostVar('notifyVote'); + $notifyNewItem = intPostVar('notifyNewItem'); + + if ( $notifyComment == 0 ) + { + $notifyComment = 1; + } + if ( $notifyVote == 0 ) + { + $notifyVote = 1; + } + if ( $notifyNewItem == 0 ) + { + $notifyNewItem = 1; + } + $notifyType = $notifyComment * $notifyVote * $notifyNewItem; + + if ( $notify_address && !NOTIFICATION::address_validation($notify_address) ) + { + self::error(_ERROR_BADNOTIFY); + return; + } + + if ( !isValidShortName($shortname) ) + { + self::error(_ERROR_BADSHORTBLOGNAME); + return; + } + + if ( ($blog->getShortName() != $shortname) && $manager->existsBlog($shortname) ) + { + self::error(_ERROR_DUPSHORTBLOGNAME); + return; + } + // check if update file is writable + if ( $updatefile && !is_writeable($updatefile) ) + { + self::error(_ERROR_UPDATEFILE); + return; + } + + $blog->setName(trim(postVar('name'))); + $blog->setShortName($shortname); + $blog->setNotifyAddress($notify_address); + $blog->setNotifyType($notifyType); + $blog->setMaxComments(postVar('maxcomments')); + $blog->setCommentsEnabled(postVar('comments')); + $blog->setTimeOffset(postVar('timeoffset')); + $blog->setUpdateFile($updatefile); + $blog->setURL(trim(postVar('url'))); + $blog->setDefaultSkin(intPostVar('defskin')); + $blog->setDescription(trim(postVar('desc'))); + $blog->setPublic(postVar('public')); + $blog->setConvertBreaks(intPostVar('convertbreaks')); + $blog->setAllowPastPosting(intPostVar('allowpastposting')); + $blog->setDefaultCategory(intPostVar('defcat')); + $blog->setSearchable(intPostVar('searchable')); + $blog->setEmailRequired(intPostVar('reqemail')); + $blog->writeSettings(); + + // store plugin options + $aOptions = requestArray('plugoption'); + NucleusPlugin::apply_plugin_options($aOptions); + + $data = array( + 'context' => 'blog', + 'blogid' => $blogid, + 'blog' => &$blog + ); + $manager->notify('PostPluginOptionsUpdate', $data); + + self::action_overview(_MSG_SETTINGSCHANGED); +>>>>>>> skinnable-master + return; + } + + /** +<<<<<<< HEAD + * Admin::action_browseowncomments() + * Browse own comments +======= + * Admin::action_deleteblog() +>>>>>>> skinnable-master + * + * @param void + * @return void + */ +<<<<<<< HEAD + public function action_browseowncomments() + { + global $member, $manager, $CONF; + + // start index + if ( postVar('start') ) + { + $start = intPostVar('start'); + } + else + { + $start = 0; + } + + // amount of items to show + if ( postVar('amount') ) + { + $amount = intPostVar('amount'); + } + else + { + $amount = intval($CONF['DefaultListSize']); + if ( $amount < 1 ) + { + $amount = 10; + } + } + + $search = postVar('search'); + + $query = 'SELECT cbody, cuser, cmail, mname, ctime, chost, cnumber, cip, citem FROM '.sql_table('comment').' LEFT OUTER JOIN '.sql_table('member').' ON mnumber=cmember WHERE cmember=' . $member->getID(); + + if ( $search ) + { + $query .= " and cbody LIKE " . DB::quoteValue('%'.$search.'%'); + } + + $query .= ' ORDER BY ctime DESC' + . " LIMIT $start,$amount"; + + $this->pagehead(); + + echo '

(' . _BACKHOME . ")

\n"; + echo '

' . _COMMENTS_YOUR . "

\n"; + + $template['content'] = 'commentlist'; + $template['canAddBan'] = 0; // doesn't make sense to allow banning yourself + + $manager->loadClass("ENCAPSULATE"); + $navList = new NavList('browseowncomments', $start, $amount, 0, 1000, 0, $search, 0); + $navList->showBatchList('comment',$query,'table',$template,_NOCOMMENTS_YOUR); + + $this->pagefoot(); +======= + static private function action_deleteblog() + { + global $member, $CONF, $manager; + + $blogid = intRequestVar('blogid'); + + $member->blogAdminRights($blogid) or self::disallow(); + + // check if blog is default blog + if ( $CONF['DefaultBlog'] == $blogid ) + { + self::error(_ERROR_DELDEFBLOG); + return; + } + + $blog =& $manager->getBlog($blogid); + + self::$skin->parse('deleteblog'); + return; + } + + /** + * Admin::action_deleteblogconfirm() + * Delete Blog + * + * @param Void + * @return Void + */ + static private function action_deleteblogconfirm() + { + global $member, $CONF, $manager; + + $blogid = intRequestVar('blogid'); + + $data = array('blogid' => $blogid); + $manager->notify('PreDeleteBlog', $data); + + $member->blogAdminRights($blogid) or self::disallow(); + + // check if blog is default blog + if ( $CONF['DefaultBlog'] == $blogid ) + { + self::error(_ERROR_DELDEFBLOG); + return; + } + + // delete all comments + $query = 'DELETE FROM ' . sql_table('comment') . ' WHERE cblog='.$blogid; + DB::execute($query); + + // delete all items + $query = 'DELETE FROM ' . sql_table('item') . ' WHERE iblog=' . $blogid; + DB::execute($query); + + // delete all team members + $query = 'DELETE FROM ' . sql_table('team') . ' WHERE tblog=' . $blogid; + DB::execute($query); + + // delete all bans + $query = 'DELETE FROM ' . sql_table('ban') . ' WHERE blogid=' . $blogid; + DB::execute($query); + + // delete all categories + $query = 'DELETE FROM ' . sql_table('category') . ' WHERE cblog=' . $blogid; + DB::execute($query); + + // delete all associated plugin options + NucleusPlugin::delete_option_values('blog', $blogid); + + // delete the blog itself + $query = 'DELETE FROM ' . sql_table('blog') . ' WHERE bnumber=' . $blogid; + DB::execute($query); + + $data = array('blogid' => $blogid); + $manager->notify('PostDeleteBlog', $data); + + self::action_overview(_DELETED_BLOG); +>>>>>>> skinnable-master + return; + } + + /** +<<<<<<< HEAD + * Admin::action_blogcommentlist() + * + * Browse all comments for a weblog + * @param integer $blogid ID for weblog + * @return void + */ + function action_blogcommentlist($blogid = '') + { + global $member, $manager, $CONF; + + if ( $blogid == '' ) + { + $blogid = intRequestVar('blogid'); + } + else + { + $blogid = intval($blogid); + } + + $member->teamRights($blogid) or $member->isAdmin() or $this->disallow(); + + // start index + if ( postVar('start') ) + { + $start = intPostVar('start'); + } + else + { + $start = 0; + } + + // amount of items to show + if ( postVar('amount') ) + { + $amount = intPostVar('amount'); + } + else + { + $amount = intval($CONF['DefaultListSize']); + if ( $amount < 1 ) + { + $amount = 10; + } + } + + $search = postVar('search'); // search through comments + + $query = 'SELECT cbody, cuser, cemail, cmail, mname, ctime, chost, cnumber, cip, citem FROM '.sql_table('comment').' LEFT OUTER JOIN '.sql_table('member').' ON mnumber=cmember WHERE cblog=' . intval($blogid); + + if ( $search != '' ) + { + $query .= " and cbody LIKE " . DB::quoteValue('%'.$search.'%'); + } + + $query .= ' ORDER BY ctime DESC' + . " LIMIT $start,$amount"; + + $blog =& $manager->getBlog($blogid); + + $this->pagehead(); + + echo '

(' . _BACKHOME . ")

\n"; + echo '

', _COMMENTS_BLOG , ' ' , $this->bloglink($blog), '

'; + + $template['content'] = 'commentlist'; + $template['canAddBan'] = $member->blogAdminRights($blogid); + + $manager->loadClass("ENCAPSULATE"); + $navList = new NavList('blogcommentlist', $start, $amount, 0, 1000, $blogid, $search, 0); + $navList->showBatchList('comment',$query,'table',$template, _NOCOMMENTS_BLOG); + + $this->pagefoot(); +======= + * Admin::action_memberdelete() + * + * @param void + * @return void + */ + static private function action_memberdelete() + { + global $member, $manager; + + $memberid = intRequestVar('memberid'); + + ($member->getID() == $memberid) or $member->isAdmin() or self::disallow(); + + $mem =& $manager->getMember($memberid); + + self::$skin->parse('memberdelete'); + return; + } + + /** + * Admin::action_memberdeleteconfirm() + * + * @param void + * @return void + */ + static private function action_memberdeleteconfirm() + { + global $member; + + $memberid = intRequestVar('memberid'); + + ($member->getID() == $memberid) or $member->isAdmin() or self::disallow(); + + $error = self::deleteOneMember($memberid); + if ( $error ) + { + self::error($error); + return; + } + + if ( $member->isAdmin() ) + { + self::action_usermanagement(); + return; + } + else + { + self::action_overview(_DELETED_MEMBER); + return; + } + return; + } + + /** + * Admin::deleteOneMember() + * Delete a member by id + * + * @static + * @params Integer $memberid member id + * @return String null string or error messages + */ + static public function deleteOneMember($memberid) + { + global $manager; + + $memberid = intval($memberid); + $mem =& $manager->getMember($memberid); + + if ( !$mem->canBeDeleted() ) + { + return _ERROR_DELETEMEMBER; + } + + $data = array('member' => &$mem); + $manager->notify('PreDeleteMember', $data); + + /* unlink comments from memberid */ + if ( $memberid ) + { + $query = "UPDATE %s SET cmember=0, cuser=%s WHERE cmember=%d;"; + $query = sprintf($query, sql_table('comment'), DB::quoteValue($mem->getDisplayName()), $memberid); + DB::execute($query); + } + + $query = 'DELETE FROM ' . sql_table('member') . ' WHERE mnumber=' . $memberid; + DB::execute($query); + + $query = 'DELETE FROM ' . sql_table('team') . ' WHERE tmember=' . $memberid; + DB::execute($query); + + $query = 'DELETE FROM ' . sql_table('activation') . ' WHERE vmember=' . $memberid; + DB::execute($query); + + // delete all associated plugin options + NucleusPlugin::delete_option_values('member', $memberid); + + $data = array('member' => &$mem); + $manager->notify('PostDeleteMember', $data); + + return ''; + } + + /** + * Admin::action_createnewlog() + * + * @param void + * @return void + */ + static private function action_createnewlog() + { + global $member, $CONF, $manager; + + // Only Super-Admins can do this + $member->isAdmin() or self::disallow(); + + self::$skin->parse('createnewlog'); + return; + } + + /** + * Admin::action_addnewlog() + * + * @param void + * @return void + */ + static private function action_addnewlog() + { + global $member, $manager, $CONF; + + // Only Super-Admins can do this + $member->isAdmin() or self::disallow(); + + $bname = trim(postVar('name')); + $bshortname = trim(postVar('shortname')); + $btimeoffset = postVar('timeoffset'); + $bdesc = trim(postVar('desc')); + $bdefskin = postVar('defskin'); + + if ( !isValidShortName($bshortname) ) + { + self::error(_ERROR_BADSHORTBLOGNAME); + return; + } + + if ( $manager->existsBlog($bshortname) ) + { + self::error(_ERROR_DUPSHORTBLOGNAME); + return; + } + + $data = array( + 'name' => &$bname, + 'shortname' => &$bshortname, + 'timeoffset' => &$btimeoffset, + 'description' => &$bdesc, + 'defaultskin' => &$bdefskin + ); + $manager->notify('PreAddBlog', $data); + + // add slashes for sql queries + $bname = DB::quoteValue($bname); + $bshortname = DB::quoteValue($bshortname); + $btimeoffset = DB::quoteValue($btimeoffset); + $bdesc = DB::quoteValue($bdesc); + $bdefskin = DB::quoteValue($bdefskin); + + // create blog + $query = "INSERT INTO %s (bname, bshortname, bdesc, btimeoffset, bdefskin) VALUES (%s, %s, %s, %s, %s);"; + $query = sprintf($query, sql_table('blog'), $bname, $bshortname, $bdesc, $btimeoffset, $bdefskin); + DB::execute($query); + + $blogid = DB::getInsertId(); + $blog =& $manager->getBlog($blogid); + + // create new category + $catdefname = (!defined('_EBLOGDEFAULTCATEGORY_NAME') ? 'General' : _EBLOGDEFAULTCATEGORY_NAME); + $catdefdesc = (!defined('_EBLOGDEFAULTCATEGORY_DESC') ? 'Items that do not fit in other categories' : _EBLOGDEFAULTCATEGORY_DESC); + + $query = 'INSERT INTO %s (cblog, cname, cdesc) VALUES (%d, %s, %s)'; + DB::execute(sprintf($query, sql_table('category'), (integer) $blogid, DB::quoteValue($catdefname), DB::quoteValue($catdefdesc))); + $catid = DB::getInsertId(); + + // set as default category + $blog->setDefaultCategory($catid); + $blog->writeSettings(); + + // create team member + $query = "INSERT INTO %s (tmember, tblog, tadmin) VALUES (%d, %d, 1);"; + $query = sprintf($query, sql_table('team'), (integer) $member->getID(), (integer) $blogid); + DB::execute($query); + + $itemdeftitle = (defined('_EBLOG_FIRSTITEM_TITLE') ? _EBLOG_FIRSTITEM_TITLE : 'First Item'); + $itemdefbody = (defined('_EBLOG_FIRSTITEM_BODY') ? _EBLOG_FIRSTITEM_BODY : 'This is the first item in your weblog. Feel free to delete it.'); + + $blog->additem( + $blog->getDefaultCategory(), + $itemdeftitle,$itemdefbody, + '', + $blogid, + $member->getID(), + $blog->getCorrectTime(), + 0, + 0, + 0 + ); + + $data = array('blog' => &$blog); + $manager->notify('PostAddBlog', $data); + + $data = array( + 'blog' => &$blog, + 'name' => _EBLOGDEFAULTCATEGORY_NAME, + 'description' => _EBLOGDEFAULTCATEGORY_DESC, + 'catid' => $catid + ); + $manager->notify('PostAddCategory', $data); + + /* TODO: we should consider to use the other way insterad of this */ + $_REQUEST['blogid'] = $blogid; + $_REQUEST['catid'] = $catid; + self::$skin->parse('addnewlog'); +>>>>>>> skinnable-master + return; + } + + /** +<<<<<<< HEAD + * Admin::action_createitem() + * Provide a page to item a new item to the given blog +======= + * Admin::action_addnewlog2() +>>>>>>> skinnable-master + * + * @param void + * @return void + */ +<<<<<<< HEAD + public function action_createitem() + { + global $member, $manager; + + $blogid = intRequestVar('blogid'); + + // check if allowed + $member->teamRights($blogid) or $this->disallow(); + + $memberid = $member->getID(); + + $blog =& $manager->getBlog($blogid); + + // generate the add-item form + $handler = new PageFactory($blog); + + $contents = $handler->getTemplateFor('admin', 'add'); + $manager->notify('PreAddItemForm', array('contents' => &$contents, 'blog' => &$blog)); + + $parser = new Parser($handler); + + $this->pagehead(); + $parser->parse($contents); + $this->pagefoot(); + +======= + static private function action_addnewlog2() + { + global $member, $manager; + $blogid = intRequestVar('blogid'); + + $member->blogAdminRights($blogid) or self::disallow(); + + $burl = requestVar('url'); + + $blog =& $manager->getBlog($blogid); + $blog->setURL(trim($burl)); + $blog->writeSettings(); + + self::action_overview(_MSG_NEWBLOG); + return; + } + + /** + * Admin::action_skinieoverview() + * + * @param void + * @return void + */ + static private function action_skinieoverview() + { + global $member, $DIR_LIBS, $manager; + + $member->isAdmin() or self::disallow(); + + include_once($DIR_LIBS . 'skinie.php'); + + self::$skin->parse('skinieoverview'); +>>>>>>> skinnable-master + return; + } + + /** +<<<<<<< HEAD + * Admin::action_itemedit() +======= + * Admin::action_skinieimport() +>>>>>>> skinnable-master + * + * @param void + * @return void + */ +<<<<<<< HEAD + public function action_itemedit() + { + global $member, $manager; + + $itemid = intRequestVar('itemid'); + + // only allow if user is allowed to alter item + $member->canAlterItem($itemid) or $this->disallow(); + + $variables =& $manager->getItem($itemid, 1, 1); + $blog =& $manager->getBlog(getBlogIDFromItemID($itemid)); + + $manager->notify('PrepareItemForEdit', array('item' => &$variables)); + + if ( $blog->convertBreaks() ) + { + $variables['body'] = removeBreaks($variables['body']); + $variables['more'] = removeBreaks($variables['more']); + } + + // form to edit blog items + $handler = new PageFactory($blog); + $handler->setVariables($variables); + + $content = $handler->getTemplateFor('admin', 'edit'); + + $parser = new Parser($handler); + + $this->pagehead(); + $parser->parse($content); + $this->pagefoot(); + return; + } + + /** + * @todo document this + */ + function action_itemupdate() { + global $member, $manager, $CONF; + + $itemid = intRequestVar('itemid'); + $catid = postVar('catid'); + + // only allow if user is allowed to alter item + $member->canUpdateItem($itemid, $catid) or $this->disallow(); + $actiontype = postVar('actiontype'); // delete actions are handled by itemdelete (which has confirmation) @@ -1415,123 +4238,327 @@ class Admin $this->action_itemlist(getBlogIDFromItemID($itemid)); } } +======= + static private function action_skinieimport() + { + global $member; + + $member->isAdmin() or self::disallow(); + + $skinFileRaw = postVar('skinfile'); + $mode = postVar('mode'); + + $error = self::skinieimport($mode, $skinFileRaw); + if ( $error ) + { + self::error($error); + return; + } + + self::$skin->parse('skinieimport'); + return; + } /** - * Admin::action_itemdelete() - * Delete item + * Admin::action_skiniedoimport() * - * @param Void - * @return Void + * @param void + * @return void + */ + static private function action_skiniedoimport() + { + global $member, $DIR_LIBS, $DIR_SKINS; + + $member->isAdmin() or self::disallow(); + + // load skinie class + include_once($DIR_LIBS . 'skinie.php'); + + $mode = postVar('mode'); + $skinFileRaw = postVar('skinfile'); + $allowOverwrite = intPostVar('overwrite'); + + $error = self::skiniedoimport($mode, $skinFileRaw, $allowOverwrite); + if ( $error ) + { + self::error($msg); + return; + } + + self::$skin->parse('skiniedoimport'); + return; + } + + /** + * Admin::action_skinieexport() + * + * @param void + * @return void */ - function action_itemdelete() + static private function action_skinieexport() + { + global $member; + + $member->isAdmin() or self::disallow(); + + $aSkins = requestIntArray('skin'); + $aTemplates = requestIntArray('template'); + $info = postVar('info'); + + self::skinieexport($aSkins, $aTemplates, $info); + + return; + } + + /** + * Admin::action_templateoverview() + * + * @param void + * @return void + */ + static private function action_templateoverview() { global $member, $manager; - $itemid = intRequestVar('itemid'); + $member->isAdmin() or self::disallow(); - // only allow if user is allowed to alter item - $member->canAlterItem($itemid) or $this->disallow(); + self::$skin->parse('templateoverview'); + return; + } + + /** + * Admin::action_templateedit() + * + * @param string $msg message for pageheader + * @return void + */ + static private function action_templateedit($msg = '') + { + global $member, $manager; + if ( $msg ) + { + self::$headMess = $msg; + } - if ( !$manager->existsItem($itemid,1,1) ) + $templateid = intRequestVar('templateid'); + + $member->isAdmin() or self::disallow(); + + self::$extrahead .= "\n"; + self::$extrahead .= "\n"; + + self::$skin->parse('templateedit'); + return; + } + + /** + * Admin::action_templateupdate() + * + * @param void + * @return void + */ + static private function action_templateupdate() + { + global $member,$manager; + + $templateid = intRequestVar('templateid'); + + $member->isAdmin() or self::disallow(); + + $name = postVar('tname'); + $desc = postVar('tdesc'); + + if ( !isValidTemplateName($name) ) + { + self::error(_ERROR_BADTEMPLATENAME); + return; + } + + if ( (Template::getNameFromId($templateid) != $name) && Template::exists($name) ) { - $this->error(_ERROR_NOSUCHITEM); + self::error(_ERROR_DUPTEMPLATENAME); + return; } - $item =& $manager->getItem($itemid,1,1); - $title = Entity::hsc(strip_tags($item['title'])); - $body = strip_tags($item['body']); - $body = Entity::hsc(Entity::shorten($body,300,'...')); + // 1. Remove all template parts + $query = "DELETE FROM %s WHERE tdesc=%d;"; + $query = sprintf($query, sql_table('template'), (integer) $templateid); + DB::execute($query); - $this->pagehead(); - echo '

' . _DELETE_CONFIRM . "

\n"; - echo '

' . _CONFIRMTXT_ITEM . "

\n"; - echo "
\n"; - echo "{$title}\n"; - echo "
\n"; - echo "{$body}\n"; - echo "
\n"; - echo "
\n"; - echo "
\n"; - echo "\n"; - echo $manager->addTicketHidden() . "\n"; - echo "\n"; - echo '\n"; - echo "
\n"; - echo "
\n"; - $this->pagefoot(); + // 2. Update description + $query = "UPDATE %s SET tdname=%s, tddesc=%s WHERE tdnumber=%d;"; + $query = sprintf($query, sql_table('template_desc'), DB::quoteValue($name), DB::quoteValue($desc), (integer) $templateid); + DB::execute($query); + + // 3. Add non-empty template parts + self::addToTemplate($templateid, 'ITEM_HEADER', postVar('ITEM_HEADER')); + self::addToTemplate($templateid, 'ITEM', postVar('ITEM')); + self::addToTemplate($templateid, 'ITEM_FOOTER', postVar('ITEM_FOOTER')); + self::addToTemplate($templateid, 'MORELINK', postVar('MORELINK')); + self::addToTemplate($templateid, 'EDITLINK', postVar('EDITLINK')); + self::addToTemplate($templateid, 'NEW', postVar('NEW')); + self::addToTemplate($templateid, 'COMMENTS_HEADER', postVar('COMMENTS_HEADER')); + self::addToTemplate($templateid, 'COMMENTS_BODY', postVar('COMMENTS_BODY')); + self::addToTemplate($templateid, 'COMMENTS_FOOTER', postVar('COMMENTS_FOOTER')); + self::addToTemplate($templateid, 'COMMENTS_CONTINUED', postVar('COMMENTS_CONTINUED')); + self::addToTemplate($templateid, 'COMMENTS_TOOMUCH', postVar('COMMENTS_TOOMUCH')); + self::addToTemplate($templateid, 'COMMENTS_AUTH', postVar('COMMENTS_AUTH')); + self::addToTemplate($templateid, 'COMMENTS_ONE', postVar('COMMENTS_ONE')); + self::addToTemplate($templateid, 'COMMENTS_MANY', postVar('COMMENTS_MANY')); + self::addToTemplate($templateid, 'COMMENTS_NONE', postVar('COMMENTS_NONE')); + self::addToTemplate($templateid, 'ARCHIVELIST_HEADER', postVar('ARCHIVELIST_HEADER')); + self::addToTemplate($templateid, 'ARCHIVELIST_LISTITEM', postVar('ARCHIVELIST_LISTITEM')); + self::addToTemplate($templateid, 'ARCHIVELIST_FOOTER', postVar('ARCHIVELIST_FOOTER')); + self::addToTemplate($templateid, 'BLOGLIST_HEADER', postVar('BLOGLIST_HEADER')); + self::addToTemplate($templateid, 'BLOGLIST_LISTITEM', postVar('BLOGLIST_LISTITEM')); + self::addToTemplate($templateid, 'BLOGLIST_FOOTER', postVar('BLOGLIST_FOOTER')); + self::addToTemplate($templateid, 'CATLIST_HEADER', postVar('CATLIST_HEADER')); + self::addToTemplate($templateid, 'CATLIST_LISTITEM', postVar('CATLIST_LISTITEM')); + self::addToTemplate($templateid, 'CATLIST_FOOTER', postVar('CATLIST_FOOTER')); + self::addToTemplate($templateid, 'DATE_HEADER', postVar('DATE_HEADER')); + self::addToTemplate($templateid, 'DATE_FOOTER', postVar('DATE_FOOTER')); + self::addToTemplate($templateid, 'FORMAT_DATE', postVar('FORMAT_DATE')); + self::addToTemplate($templateid, 'FORMAT_TIME', postVar('FORMAT_TIME')); + self::addToTemplate($templateid, 'SEARCH_HIGHLIGHT', postVar('SEARCH_HIGHLIGHT')); + self::addToTemplate($templateid, 'SEARCH_NOTHINGFOUND', postVar('SEARCH_NOTHINGFOUND')); + self::addToTemplate($templateid, 'POPUP_CODE', postVar('POPUP_CODE')); + self::addToTemplate($templateid, 'MEDIA_CODE', postVar('MEDIA_CODE')); + self::addToTemplate($templateid, 'IMAGE_CODE', postVar('IMAGE_CODE')); + + $data = array('fields' => array()); + $manager->notify('TemplateExtraFields', $data); + foreach ( $data['fields'] as $pfkey=>$pfvalue ) + { + foreach ( $pfvalue as $pffield => $pfdesc ) + { + self::addToTemplate($templateid, $pffield, postVar($pffield)); + } + } + + // jump back to template edit + self::action_templateedit(_TEMPLATE_UPDATED); return; } - /** - * @todo document this - */ - function action_itemdeleteconfirm() { - global $member; - - $itemid = intRequestVar('itemid'); - - // only allow if user is allowed to alter item - $member->canAlterItem($itemid) or $this->disallow(); - - // get blogid first - $blogid = getBlogIdFromItemId($itemid); - - // delete item (note: some checks will be performed twice) - $this->deleteOneItem($itemid); - - $this->action_itemlist($blogid); - } - - /** - * Deletes one item and returns error if something goes wrong - * @param int $itemid - */ - function deleteOneItem($itemid) { - global $member, $manager; - - // only allow if user is allowed to alter item (also checks if itemid exists) - if (!$member->canAlterItem($itemid)) - return _ERROR_DISALLOWED; - - // need to get blogid before the item is deleted - $blogid = getBlogIDFromItemId($itemid); - - $manager->loadClass('ITEM'); - Item::delete($itemid); - - // update blog's futureposted - $this->updateFuturePosted($blogid); - } - /** - * Admin::updateFuturePosted() - * Update a blog's future posted flag + * Admin::addToTemplate() * - * @param integer $blogid + * @param Integer $id ID for template + * @param String $partname parts name + * @param String $content template contents + * @return Integer record index + * + */ + static private function addToTemplate($id, $partname, $content) + { + // don't add empty parts: + if ( !trim($content) ) + { + return -1; + } + + $query = "INSERT INTO %s (tdesc, tpartname, tcontent) VALUES (%d, %s, %s);"; + $query = sprintf($query, sql_table('template'), (integer) $id, DB::quoteValue($partname), DB::quoteValue($content)); + if ( DB::execute($query) === FALSE ) + { + $err = DB::getError(); + exit(_ADMIN_SQLDIE_QUERYERROR . $err[2]); + } + return DB::getInsertId(); + } + + /** + * Admin::action_templatedelete() + * + * @param void + * @return void + */ + static private function action_templatedelete() + { + global $member, $manager; + + $member->isAdmin() or self::disallow(); + + $templateid = intRequestVar('templateid'); + // TODO: check if template can be deleted + + self::$skin->parse('templatedelete'); + return; + } +>>>>>>> skinnable-master + + /** + * Admin::action_templatedeleteconfirm() + * + * @param void * @return void + */ + static private function action_templatedeleteconfirm() + { + global $member, $manager; + + $templateid = intRequestVar('templateid'); + + $member->isAdmin() or self::disallow(); + + $data = array('templateid' => $templateid); + $manager->notify('PreDeleteTemplate', $data); + + // 1. delete description + DB::execute('DELETE FROM ' . sql_table('template_desc') . ' WHERE tdnumber=' . $templateid); + + // 2. delete parts + DB::execute('DELETE FROM ' . sql_table('template') . ' WHERE tdesc=' . $templateid); + + + $data = array('templateid' => $templateid); + $manager->notify('PostDeleteTemplate', $data); + + self::action_templateoverview(); + return; + } + + /** + * Admin::action_templatenew() * + * @param void + * @return void */ - function updateFuturePosted($blogid) + static private function action_templatenew() { - global $manager; + global $member; - $blog =& $manager->getBlog($blogid); - $currenttime = $blog->getCorrectTime(time()); + $member->isAdmin() or self::disallow(); +<<<<<<< HEAD $query = "SELECT * FROM %s WHERE iblog=%d AND iposted=0 AND itime>%s"; $query = sprintf($query, sql_table('item'), (integer) $blogid, DB::formatDateTime($currenttime)); $result = DB::getResult($query); if ( $result->rowCount() > 0 ) +======= + $name = postVar('name'); + $desc = postVar('desc'); + + if ( !isValidTemplateName($name) ) +>>>>>>> skinnable-master { - $blog->setFuturePost(); + self::error(_ERROR_BADTEMPLATENAME); + return; } - else + + if ( Template::exists($name) ) { - $blog->clearFuturePost(); + self::error(_ERROR_DUPTEMPLATENAME); + return; } + + $newTemplateId = Template::createNew($name, $desc); + + self::action_templateoverview(); return; } +<<<<<<< HEAD /** * @todo document this @@ -1746,20 +4773,86 @@ class Admin // intercept words that are too long if (preg_match('#[a-zA-Z0-9|\.,;:!\?=\/\\\\]{90,90}#', $body) != FALSE) +======= + + /** + * Admin::action_templateclone() + * + * @param void + * @return void + */ + static private function action_templateclone() + { + global $member; + + $templateid = intRequestVar('templateid'); + + $member->isAdmin() or self::disallow(); + + // 1. read old template + $name = Template::getNameFromId($templateid); + $desc = Template::getDesc($templateid); + + // 2. create desc thing + $name = "cloned" . $name; + + // if a template with that name already exists: + if ( Template::exists($name) ) +>>>>>>> skinnable-master { - $this->error(_ERROR_COMMENT_LONGWORD); + $i = 1; + while (Template::exists($name . $i)) + { + $i++; + } + $name .= $i; } - - // check length - if (i18n::strlen($body) < 3) + + $newid = Template::createNew($name, $desc); + + // 3. create clone + // go through parts of old template and add them to the new one + $query = "SELECT tpartname, tcontent FROM %s WHERE tdesc=%d;"; + $query = sprintf($query, sql_table('template'), (integer) $templateid); + + $res = DB::getResult($query); + foreach ( $res as $row) { - $this->error(_ERROR_COMMENT_NOCOMMENT); + self::addToTemplate($newid, $row['tpartname'], $row['tcontent']); } - - if (i18n::strlen($body) > 5000) + + self::action_templateoverview(); + return; + } + + /** + * Admin::action_admintemplateoverview() + * + * @param void + * @return void + */ + static private function action_admintemplateoverview() + { + global $member; + $member->isAdmin() or self::disallow(); + self::$skin->parse('admntemplateoverview'); + return; + } + + /** + * Admin::action_admintemplateedit() + * + * @param string $msg message for pageheader + * @return void + */ + static private function action_admintemplateedit($msg = '') + { + global $member, $manager; + if ( $msg ) { - $this->error(_ERROR_COMMENT_TOOLONG); + self::$headMess = $msg; } +<<<<<<< HEAD // prepare body $body = Comment::prepareBody($body); @@ -1782,54 +4875,193 @@ class Admin $this->action_browseowncomments(); } +======= + $member->isAdmin() or self::disallow(); + + self::$extrahead .= "\n"; + self::$extrahead .= '' . "\n"; + + self::$skin->parse('admintemplateedit'); + return; + } +>>>>>>> skinnable-master /** - * Admin::action_commentdelete() - * Update comment + * Admin::action_admintemplateupdate() * - * @param Void - * @return Void + * @param void + * @return void */ - function action_commentdelete() + static private function action_admintemplateupdate() { global $member, $manager; + $templateid = intRequestVar('templateid'); + $member->isAdmin() or self::disallow(); + $name = postVar('tname'); + $desc = postVar('tdesc'); - $commentid = intRequestVar('commentid'); - $member->canAlterComment($commentid) or $this->disallow(); - $comment = Comment::getComment($commentid); - - $body = strip_tags($comment['body']); - $body = Entity::hsc(Entity::shorten($body, 300, '...')); - - if ( $comment['member'] ) + if ( !isValidTemplateName($name) ) { - $author = $comment['member']; + self::error(_ERROR_BADTEMPLATENAME); + return; } - else + + if ( (Template::getNameFromId($templateid) != $name) && Template::exists($name) ) { - $author = $comment['user']; + self::error(_ERROR_DUPTEMPLATENAME); + return; } - $this->pagehead(); + // 1. Remove all template parts + $query = "DELETE FROM %s WHERE tdesc=%d;"; + $query = sprintf($query, sql_table('template'), (integer) $templateid); + DB::execute($query); - echo '

' . _DELETE_CONFIRM . "

\n"; - echo '

' . _CONFIRMTXT_COMMENT . "

\n"; - echo "
\n"; - echo '' . _EDITC_WHO . ":{$author}
\n"; - echo '' . _EDITC_TEXT . ":{$body}\n"; - echo "
\n"; - echo "
\n"; - echo "
\n"; - echo "\n"; - echo $manager->addTicketHidden() . "\n"; - echo "\n"; - echo '\n"; - echo "
\n"; - echo "
\n"; - $this->pagefoot(); + // 2. Update description + $query = "UPDATE %s SET tdname=%s, tddesc=%s WHERE tdnumber=%d;"; + $query = sprintf($query, sql_table('template_desc'), DB::quoteValue($name), DB::quoteValue($desc), (integer) $templateid); + DB::execute($query); + + // 3. Add non-empty template parts + self::addToTemplate($templateid, 'NORMALSKINLIST_HEAD', postVar('NORMALSKINLIST_HEAD')); + self::addToTemplate($templateid, 'NORMALSKINLIST_BODY', postVar('NORMALSKINLIST_BODY')); + self::addToTemplate($templateid, 'NORMALSKINLIST_FOOT', postVar('NORMALSKINLIST_FOOT')); + self::addToTemplate($templateid, 'ADMIN_CUSTOMHELPLINK_ICON', postVar('ADMIN_CUSTOMHELPLINK_ICON')); + self::addToTemplate($templateid, 'ADMIN_CUSTOMHELPLINK_ANCHOR', postVar('ADMIN_CUSTOMHELPLINK_ANCHOR')); + self::addToTemplate($templateid, 'ADMIN_BLOGLINK', postVar('ADMIN_BLOGLINK')); + self::addToTemplate($templateid, 'ADMIN_BATCHLIST', postVar('ADMIN_BATCHLIST')); + self::addToTemplate($templateid, 'ACTIVATE_FORGOT_TITLE', postVar('ACTIVATE_FORGOT_TITLE')); + self::addToTemplate($templateid, 'ACTIVATE_FORGOT_TEXT', postVar('ACTIVATE_FORGOT_TEXT')); + self::addToTemplate($templateid, 'ACTIVATE_REGISTER_TITLE', postVar('ACTIVATE_REGISTER_TITLE')); + self::addToTemplate($templateid, 'ACTIVATE_REGISTER_TEXT', postVar('ACTIVATE_REGISTER_TEXT')); + self::addToTemplate($templateid, 'ACTIVATE_CHANGE_TITLE', postVar('ACTIVATE_CHANGE_TITLE')); + self::addToTemplate($templateid, 'ACTIVATE_CHANGE_TEXT', postVar('ACTIVATE_CHANGE_TEXT')); + self::addToTemplate($templateid, 'TEMPLATE_EDIT_EXPLUGNAME', postVar('TEMPLATE_EDIT_EXPLUGNAME')); + self::addToTemplate($templateid, 'TEMPLATE_EDIT_ROW_HEAD', postVar('TEMPLATE_EDIT_ROW_HEAD')); + self::addToTemplate($templateid, 'TEMPLATE_EDIT_ROW_TAIL', postVar('TEMPLATE_EDIT_ROW_TAIL')); + self::addToTemplate($templateid, 'SPECIALSKINLIST_HEAD', postVar('SPECIALSKINLIST_HEAD')); + self::addToTemplate($templateid, 'SPECIALSKINLIST_BODY', postVar('SPECIALSKINLIST_BODY')); + self::addToTemplate($templateid, 'SPECIALSKINLIST_FOOT', postVar('SPECIALSKINLIST_FOOT')); + self::addToTemplate($templateid, 'SYSTEMINFO_GDSETTINGS', postVar('SYSTEMINFO_GDSETTINGS')); + self::addToTemplate($templateid, 'BANLIST_DELETED_LIST', postVar('BANLIST_DELETED_LIST')); + self::addToTemplate($templateid, 'INSERT_PLUGOPTION_TITLE', postVar('INSERT_PLUGOPTION_TITLE')); + self::addToTemplate($templateid, 'INSERT_PLUGOPTION_BODY', postVar('INSERT_PLUGOPTION_BODY')); + self::addToTemplate($templateid, 'INPUTYESNO_TEMPLATE_ADMIN', postVar('INPUTYESNO_TEMPLATE_ADMIN')); + self::addToTemplate($templateid, 'INPUTYESNO_TEMPLATE_NORMAL', postVar('INPUTYESNO_TEMPLATE_NORMAL')); + self::addToTemplate($templateid, 'ADMIN_SPECIALSKINLIST_HEAD', postVar('ADMIN_SPECIALSKINLIST_HEAD')); + self::addToTemplate($templateid, 'ADMIN_SPECIALSKINLIST_BODY', postVar('ADMIN_SPECIALSKINLIST_BODY')); + self::addToTemplate($templateid, 'ADMIN_SPECIALSKINLIST_FOOT', postVar('ADMIN_SPECIALSKINLIST_FOOT')); + self::addToTemplate($templateid, 'SKINIE_EXPORT_LIST', postVar('SKINIE_EXPORT_LIST')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_SELECT_HEAD', postVar('SHOWLIST_LISTPLUG_SELECT_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_SELECT_BODY', postVar('SHOWLIST_LISTPLUG_SELECT_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_SELECT_FOOT', postVar('SHOWLIST_LISTPLUG_SELECT_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_MEMBLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_MEMBLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_MEMBLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_MEMBLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_MEMBLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_MEMBLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TEAMLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_TEAMLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TEAMLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_TEAMLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TEAMLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_TEAMLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_GURL', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_GURL')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGEVENTLIST', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGEVENTLIST')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGNEDUPDATE', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGNEDUPDATE')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPEND', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPEND')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPREQ', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPREQ')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLISTFALSE', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLISTFALSE')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ACTN', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ACTN')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ADMN', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ADMN')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HELP', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HELP')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGOPTSETURL', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGOPTSETURL')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_POPTLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_POPTLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_POPTLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_POPTLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OYESNO', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OYESNO')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OPWORD', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OPWORD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEP', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEP')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEO', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEO')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEC', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEC')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OTAREA', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OTAREA')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLGOPT_OITEXT', postVar('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OITEXT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_PLUGOPTN_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_PLUGOPTN_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_POPTLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_POPTLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ITEMLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_ITEMLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ITEMLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_ITEMLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ITEMLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_ITEMLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CMNTLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_CMNTLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CMNTLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_CMNTLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CMNTLIST_ABAN', postVar('SHOWLIST_LISTPLUG_TABLE_CMNTLIST_ABAN')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CMNTLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_CMNTLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLIST_BD_TADM', postVar('SHOWLIST_LISTPLUG_TABLE_BLIST_BD_TADM')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLIST_BD_SADM', postVar('SHOWLIST_LISTPLUG_TABLE_BLIST_BD_SADM')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SHORTNAM_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_SHORTNAM_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SHORTNAM_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_SHORTNAM_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SHORTNAM_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_SHORTNAM_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CATELIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_CATELIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CATELIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_CATELIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_CATELIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_CATELIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TPLTLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_TPLTLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TPLTLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_TPLTLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_TPLTLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_TPLTLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SKINLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_SKINLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SKINLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_SKINLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_DRFTLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_DRFTLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_DRFTLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_DRFTLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_DRFTLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_DRFTLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ACTNLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_ACTNLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ACTNLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_ACTNLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_ACTNLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_ACTNLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_IBANLIST_HEAD', postVar('SHOWLIST_LISTPLUG_TABLE_IBANLIST_HEAD')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_IBANLIST_BODY', postVar('SHOWLIST_LISTPLUG_TABLE_IBANLIST_BODY')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_IBANLIST_FOOT', postVar('SHOWLIST_LISTPLUG_TABLE_IBANLIST_FOOT')); + self::addToTemplate($templateid, 'SHOWLIST_LISTPLUG_TABLE_NAVILIST', postVar('SHOWLIST_LISTPLUG_TABLE_NAVILIST')); + self::addToTemplate($templateid, 'PLUGIN_QUICKMENU_TITLE', postVar('PLUGIN_QUICKMENU_TITLE')); + self::addToTemplate($templateid, 'PLUGIN_QUICKMENU_HEAD', postVar('PLUGIN_QUICKMENU_HEAD')); + self::addToTemplate($templateid, 'PLUGIN_QUICKMENU_BODY', postVar('PLUGIN_QUICKMENU_BODY')); + self::addToTemplate($templateid, 'PLUGIN_QUICKMENU_FOOT', postVar('PLUGIN_QUICKMENU_FOOT')); + + $data = array('fields' => array()); + $manager->notify('AdminTemplateExtraFields', $data); + foreach ( $data['fields'] as $pfkey => $pfvalue ) + { + foreach ( $pfvalue as $pffield => $pfdesc ) + { + self::addToTemplate($templateid, $pffield, postVar($pffield)); + } + } + + // jump back to template edit + self::action_admintemplateedit(_TEMPLATE_UPDATED); + return; + } + + /** + * Admin::action_admintemplatedelete() + * + * @param void + * @return void + */ + static private function action_admintemplatedelete() + { + global $member, $manager; + $member->isAdmin() or self::disallow(); + + // TODO: check if template can be deleted + self::$skin->parse('admintemplatedelete'); return; } +<<<<<<< HEAD /** * @todo document this */ @@ -1981,23 +5213,30 @@ class Admin $this->action_editmembersettings(intRequestVar('memberid')); } +======= +>>>>>>> skinnable-master /** - * @todo document this + * Admin::action_admintemplatedeleteconfirm() + * + * @param void + * @return void */ - function action_editmembersettings($memberid = '') { - global $member, $manager, $CONF; + static private function action_admintemplatedeleteconfirm() + { + global $member, $manager; - if ($memberid == '') - { - $memberid = $member->getID(); - } + $templateid = intRequestVar('templateid'); + $member->isAdmin() or self::disallow(); - // check if allowed - ($member->getID() == $memberid) or $member->isAdmin() or $this->disallow(); + $data = array('templateid' => $templateid); + $manager->notify('PreDeleteAdminTemplate', $data); - $extrahead = ''; - $this->pagehead($extrahead); + // 1. delete description + $query = "DELETE FROM %s WHERE tdnumber=%s;"; + $query = sprintf($query, sql_table('template_desc'), (integer) $templateid); + DB::execute($query); +<<<<<<< HEAD // show message to go back to member overview (only for admins) if ($member->isAdmin()) { @@ -2124,32 +5363,36 @@ class Admin ) ); $this->pagefoot(); +======= + // 2. delete parts + $query = "DELETE FROM %s WHERE tdesc=%d;"; + $query = sprintf($query, sql_table('template'), (integer) $templateid); + DB::execute($query); + + $data = array('templateid' => $templateid); + $manager->notify('PostDeleteAdminTemplate', $data); + + self::action_admintemplateoverview(); + return; +>>>>>>> skinnable-master } - /** - * @todo document this - */ - function action_changemembersettings() { - global $member, $CONF, $manager; - - $memberid = intRequestVar('memberid'); - - // check if allowed - ($member->getID() == $memberid) or $member->isAdmin() or $this->disallow(); - - $name = trim(strip_tags(postVar('name'))); - $realname = trim(strip_tags(postVar('realname'))); - $password = postVar('password'); - $repeatpassword = postVar('repeatpassword'); - $email = strip_tags(postVar('email')); - $url = strip_tags(postVar('url')); - - # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0 - # original eregi: !eregi("^https?://", $url) - - // begin if: sometimes user didn't prefix the URL with http:// or https://, this cause a malformed URL. Let's fix it. - if (!preg_match('#^https?://#', $url) ) + /** + * Admin::action_admintemplatenew() + * + * @param void + * @return void + */ + static private function action_admintemplatenew() + { + global $member; + $member->isAdmin() or self::disallow(); + $name = postVar('name'); + $desc = postVar('desc'); + + if ( !isValidTemplateName($name) ) { +<<<<<<< HEAD $url = 'http://' . $url; } @@ -2182,16 +5425,22 @@ class Admin $this->error($pwderror); } } +======= + self::error(_ERROR_BADTEMPLATENAME); + return; +>>>>>>> skinnable-master } - - if ( !NOTIFICATION::address_validation($email) ) + else if ( !preg_match('#^admin/#', $name) ) { - $this->error(_ERROR_BADMAILADDRESS); + self::error(_ERROR_BADADMINTEMPLATENAME); + return; } - if ( !$realname ) + else if ( Template::exists($name) ) { - $this->error(_ERROR_REALNAMEMISSING); + self::error(_ERROR_DUPTEMPLATENAME); + return; } +<<<<<<< HEAD if ( ($locale != '') && (!in_array($locale, i18n::get_available_locale_list())) ) $this->error(_ERROR_NOSUCHTRANSLATION); @@ -2263,44 +5512,109 @@ class Admin } } +======= + + $newTemplateId = Template::createNew($name, $desc); + self::action_admintemplateoverview(); + return; + } + +>>>>>>> skinnable-master /** - * Admin::action_memberadd() + * Admin::action_admintemplateclone() * * @param void * @return void - * - */ - function action_memberadd() + */ + static private function action_admintemplateclone() { - global $member, $manager; + global $member; + $templateid = intRequestVar('templateid'); + $member->isAdmin() or self::disallow(); - // check if allowed - $member->isAdmin() or $this->disallow(); + // 1. read old template + $name = Template::getNameFromId($templateid); + $desc = Template::getDesc($templateid); - if ( postVar('password') != postVar('repeatpassword') ) + // 2. create desc thing + $name = $name . "cloned"; + + // if a template with that name already exists: + if ( Template::exists($name) ) { - $this->error(_ERROR_PASSWORDMISMATCH); + $i = 1; + while ( Template::exists($name . $i) ) + { + $i++; + } + $name .= $i; } - if ( i18n::strlen(postVar('password')) < 6 ) + $newid = Template::createNew($name, $desc); + + // 3. create clone + // go through parts of old template and add them to the new one + $query = "SELECT tpartname, tcontent FROM %s WHERE tdesc=%d;"; + $query = sprintf($query, sql_table('template'), (integer) $templateid); + + $res = DB::getResult($query); + foreach ( $res as $row ) { - $this->error(_ERROR_PASSWORDTOOSHORT); + self::addToTemplate($newid, $row['tpartname'], $row['tcontent']); } - $res = Member::create(postVar('name'), postVar('realname'), postVar('password'), postVar('email'), postVar('url'), postVar('admin'), postVar('canlogin'), postVar('notes')); - if ( $res != 1 ) + self::action_admintemplateoverview(); + return; + } + + /** + * Admin::action_skinoverview() + * + * @param void + * @return void + */ + static private function action_skinoverview() + { + global $member, $manager; + + $member->isAdmin() or self::disallow(); + + self::$skin->parse('skinoverview'); + return; + } + + /** + * Admin::action_skinnew() + * + * @param void + * @return void + */ + static private function action_skinnew() + { + global $member; + + $member->isAdmin() or self::disallow(); + + $name = trim(postVar('name')); + $desc = trim(postVar('desc')); + + if ( !isValidSkinName($name) ) + { + self::error(_ERROR_BADSKINNAME); + return; + } + else if ( SKIN::exists($name) ) { - $this->error($res); + self::error(_ERROR_DUPSKINNAME); + return; } - // fire PostRegister event - $newmem = new Member(); - $newmem->readFromName(postVar('name')); - $manager->notify('PostRegister',array('member' => &$newmem)); + SKIN::createNew($name, $desc); - $this->action_usermanagement(); + self::action_skinoverview(); return; } +<<<<<<< HEAD /** * Account activation @@ -3166,154 +6480,515 @@ class Admin $this->action_blogsettings(); } +======= /** - * Admin::deleteOneCategory() - * Delete a category by its id + * Admin::action_skinedit() * - * @param String $catid category id for deleting - * @return Void + * @param void + * @return void */ - function deleteOneCategory($catid) + static private function action_skinedit() + { + global $member; + + $member->isAdmin() or self::disallow(); + + self::$skin->parse('skinedit'); + return; + } + + /** + * Admin::action_skineditgeneral() + * + * @param void + * @return void + */ + static private function action_skineditgeneral() + { + global $member; + + $skinid = intRequestVar('skinid'); + + $member->isAdmin() or self::disallow(); + + $error = self::skineditgeneral($skinid); + if ( $error ) + { + self::error($error); + return; + } + + self::action_skinedit(); + return; + } + + static private function action_skinedittype($msg = '') + { + global $member; + + $member->isAdmin() or self::disallow(); + + if ( $msg ) + { + self::$headMess = $msg; + } + + $type = requestVar('type'); + $type = trim($type); + $type = strtolower($type); + + if ( !isValidShortName($type) ) + { + self::error(_ERROR_SKIN_PARTS_SPECIAL_FORMAT); + return; + } + + self::$skin->parse('skinedittype'); + return; + } +>>>>>>> skinnable-master + + /** + * Admin::action_skinupdate() + * + * @param void + * @return void + */ + static private function action_skinupdate() { global $manager, $member; - $catid = intval($catid); - $blogid = getBlogIDFromCatID($catid); + $skinid = intRequestVar('skinid'); + $content = trim(postVar('content')); + $type = postVar('type'); - if ( !$member->blogAdminRights($blogid) ) + $member->isAdmin() or self::disallow(); + + $skin =& $manager->getSKIN($skinid); + $skin->update($type, $content); + + self::action_skinedittype(_SKIN_UPDATED); + return; + } + + /** + * Admin::action_skindelete() + * + * @param void + * @return void + */ + static private function action_skindelete() + { + global $CONF, $member; + + $member->isAdmin() or self::disallow(); + + $skinid = intRequestVar('skinid'); + + // don't allow default skin to be deleted + if ( $skinid == $CONF['BaseSkin'] ) { - return ERROR_DISALLOWED; + self::error(_ERROR_DEFAULTSKIN); + return; } - // get blog - $blog =& $manager->getBlog($blogid); + // don't allow deletion of default skins for blogs + $query = "SELECT bname FROM %s WHERE bdefskin=%d"; + $query = sprintf($query, sql_table('blog'), (integer) $skinid); - // check if the category is valid - if ( !$blog || !$blog->isValidCategory($catid) ) + $name = DB::getValue($query); + if ( $name ) { - return _ERROR_NOSUCHCATEGORY; + self::error(_ERROR_SKINDEFDELETE . Entity::hsc($name)); + return; } - $destcatid = $blog->getDefaultCategory(); + self::$skin->parse('skindelete'); + return; + } + + /** + * Admin::action_skindeleteconfirm() + * + * @param void + * @return void + */ + static private function action_skindeleteconfirm() + { + global $member, $CONF; - // don't allow deletion of default category - if ( $blog->getDefaultCategory() == $catid ) + $member->isAdmin() or self::disallow(); + + $skinid = intRequestVar('skinid'); + + // don't allow default skin to be deleted + if ( $skinid == $CONF['BaseSkin'] ) { - return _ERROR_DELETEDEFCATEGORY; + self::error(_ERROR_DEFAULTSKIN); + return; } +<<<<<<< HEAD // check if catid is the only category left for blogid $query = 'SELECT catid FROM '.sql_table('category').' WHERE cblog=' . $blogid; $res = DB::getResult($query); if ( $res->rowCount() == 1 ) +======= + // don't allow deletion of default skins for blogs + $query = "SELECT bname FROM %s WHERE bdefskin=%d;"; + $query = sprintf($query, sql_table('blog'), (integer) $skinid); + + $name = DB::getValue($query); + if ( $name ) + { + self::error(_ERROR_SKINDEFDELETE . Entity::hsc($name)); + return; + } + + self::skindeleteconfirm($skinid); + + self::action_skinoverview(); + return; + } + + /** + * Admin::action_skinremovetype() + * + * @param void + * @return void + */ + static private function action_skinremovetype() + { + global $member, $CONF; + + $member->isAdmin() or self::disallow(); + + $skinid = intRequestVar('skinid'); + $skintype = requestVar('type'); + + if ( !isValidShortName($skintype) ) +>>>>>>> skinnable-master { - return _ERROR_DELETELASTCATEGORY; + self::error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); + return; } - $manager->notify('PreDeleteCategory', array('catid' => $catid)); + self::$skin->parse('skinremovetype'); + return; + } + + /** + * Admin::action_skinremovetypeconfirm() + * + * @param void + * @return void + */ + static private function action_skinremovetypeconfirm() + { + global $member; +<<<<<<< HEAD // change category for all items to the default category $query = 'UPDATE '.sql_table('item')." SET icat=$destcatid WHERE icat=$catid"; DB::execute($query); +======= + $member->isAdmin() or self::disallow(); +>>>>>>> skinnable-master - // delete all associated plugin options - NucleusPlugin::delete_option_values('category', $catid); + $skinid = intRequestVar('skinid'); + $skintype = requestVar('type'); +<<<<<<< HEAD // delete category $query = 'DELETE FROM '.sql_table('category').' WHERE catid=' .$catid; DB::execute($query); +======= + $error = self::skinremovetypeconfirm($skinid, $skintype); + if ( $error ) + { + self::error($error); + return; + } +>>>>>>> skinnable-master - $manager->notify('PostDeleteCategory', array('catid' => $catid)); + self::action_skinedit(); return; } /** - * Admin::action_blogsettingsupdate - * Updating blog settings + * Admin::action_skinclone() * - * @param Void - * @return Void + * @param void + * @return void */ - function action_blogsettingsupdate() + static private function action_skinclone() { - global $member, $manager; + global $member; - $blogid = intRequestVar('blogid'); + $member->isAdmin() or self::disallow(); - $member->blogAdminRights($blogid) or $this->disallow(); + $skinid = intRequestVar('skinid'); - $blog =& $manager->getBlog($blogid); + self::skinclone($skinid); - $notify_address = trim(postVar('notify')); - $shortname = trim(postVar('shortname')); - $updatefile = trim(postVar('update')); + self::action_skinoverview(); + return; + } + + /** + * Admin::action_adminskinoverview() + * + * @param void + * @return void + */ + static private function action_adminskinoverview() + { + global $member; - $notifyComment = intPostVar('notifyComment'); - $notifyVote = intPostVar('notifyVote'); - $notifyNewItem = intPostVar('notifyNewItem'); + $member->isAdmin() or self::disallow(); - if ( $notifyComment == 0 ) + self::$skin->parse('adminskinoverview'); + return; + } + + /** + * Admin::action_adminskinnew() + * + * @param void + * @return void + */ + static private function action_adminskinnew() + { + global $member; + + $member->isAdmin() or self::disallow(); + + $name = trim(postVar('name')); + $desc = trim(postVar('desc')); + + if ( !isValidSkinName($name) ) { - $notifyComment = 1; + self::error(_ERROR_BADSKINNAME); + return; } - if ( $notifyVote == 0 ) + else if ( !preg_match('#^admin/#', $name) ) { - $notifyVote = 1; + self::error(_ERROR_BADADMINSKINNAME); + return; } - if ( $notifyNewItem == 0 ) + else if ( Skin::exists($name) ) { - $notifyNewItem = 1; + self::error(_ERROR_DUPSKINNAME); + return; } - $notifyType = $notifyComment * $notifyVote * $notifyNewItem; - if ( $notify_address && !NOTIFICATION::address_validation($notify_address) ) + Skin::createNew($name, $desc); + + self::action_adminskinoverview(); + return; + } + + /** + * Admin::action_adminskinedit() + * + * @param void + * @return void + */ + static private function action_adminskinedit() + { + global $member; + + $member->isAdmin() or self::disallow(); + + self::$skin->parse('adminskinedit'); + + return; + } + + /** + * Admin::action_adminskineditgeneral() + * + * @param void + * @return void + */ + static private function action_adminskineditgeneral() + { + global $member; + + $skinid = intRequestVar('skinid'); + + $member->isAdmin() or self::disallow(); + + $error = self::skineditgeneral($skinid, 'AdminActions'); + if ( $error ) { - $this->error(_ERROR_BADNOTIFY); + self::error($error); + return; } - if ( !isValidShortName($shortname) ) + self::action_adminskinedit(); + return; + } + + /** + * Admin::action_adminskinedittype() + * + * @param string $msg message for pageheader + * @return void + */ + static private function action_adminskinedittype($msg = '') + { + global $member; + + $member->isAdmin() or self::disallow(); + + if ( $msg ) { - $this->error(_ERROR_BADSHORTBLOGNAME); + self::$headMess = $msg; } + $type = requestVar('type'); + $type = trim($type); + $type = strtolower($type); - if ( ($blog->getShortName() != $shortname) && $manager->existsBlog($shortname) ) + if ( !isValidShortName($type) ) { - $this->error(_ERROR_DUPSHORTBLOGNAME); + self::error(_ERROR_SKIN_PARTS_SPECIAL_FORMAT); + return; } - // check if update file is writable - if ( $updatefile && !is_writeable($updatefile) ) + + self::$skin->parse('adminskinedittype'); + return; + } + + /** + * Admin::action_adminskinupdate() + * + * @param void + * @return void + */ + static private function action_adminskinupdate() + { + global $manager, $member; + + $skinid = intRequestVar('skinid'); + $content = trim(postVar('content')); + $type = postVar('type'); + + $member->isAdmin() or self::disallow(); + + $skin =& $manager->getSkin($skinid, 'AdminActions', 'AdminSkin'); + $skin->update($type, $content); + + self::action_adminskinedittype(_SKIN_UPDATED); + return; + } + + /** + * Admin::action_adminskindelete() + * + * @param void + * @return void + */ + static private function action_adminskindelete() + { + global $CONF, $member; + + $member->isAdmin() or self::disallow(); + + $skinid = intRequestVar('skinid'); + + // don't allow default skin to be deleted + if ( $skinid == $CONF['AdminSkin'] || $skinid == $CONF['BookmarkletSkin'] ) { - $this->error(_ERROR_UPDATEFILE); + self::error(_ERROR_DEFAULTSKIN); + return; } - $blog->setName(trim(postVar('name'))); - $blog->setShortName($shortname); - $blog->setNotifyAddress($notify_address); - $blog->setNotifyType($notifyType); - $blog->setMaxComments(postVar('maxcomments')); - $blog->setCommentsEnabled(postVar('comments')); - $blog->setTimeOffset(postVar('timeoffset')); - $blog->setUpdateFile($updatefile); - $blog->setURL(trim(postVar('url'))); - $blog->setDefaultSkin(intPostVar('defskin')); - $blog->setDescription(trim(postVar('desc'))); - $blog->setPublic(postVar('public')); - $blog->setConvertBreaks(intPostVar('convertbreaks')); - $blog->setAllowPastPosting(intPostVar('allowpastposting')); - $blog->setDefaultCategory(intPostVar('defcat')); - $blog->setSearchable(intPostVar('searchable')); - $blog->setEmailRequired(intPostVar('reqemail')); - $blog->writeSettings(); + /* 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)); - // store plugin options - $aOptions = requestArray('plugoption'); - NucleusPlugin::apply_plugin_options($aOptions); - $manager->notify('PostPluginOptionsUpdate',array('context' => 'blog', 'blogid' => $blogid, 'blog' => &$blog)); + $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; + } + + /** + * Admin::action_adminskindeleteconfirm() + * + * @param void + * @return void + */ + static private function action_adminskindeleteconfirm() + { + global $member, $CONF; + + $member->isAdmin() or self::disallow(); + + $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::skindeleteconfirm($skinid); + + self::action_adminskinoverview(); + return; + } + + /** + * Admin::action_adminskinremovetype() + * + * @param void + * @return void + */ + static private function action_adminskinremovetype() + { + global $member, $CONF; + + $member->isAdmin() or self::disallow(); + + $skinid = intRequestVar('skinid'); + $skintype = requestVar('type'); - $this->action_overview(_MSG_SETTINGSCHANGED); + if ( !isValidShortName($skintype) ) + { + self::error(_ERROR_SKIN_PARTS_SPECIAL_DELETE); + return; + } + + self::$skin->parse('adminskinremovetype'); return; } +<<<<<<< HEAD /** * @todo document this @@ -3351,28 +7026,32 @@ class Admin pagefoot(); } +======= +>>>>>>> skinnable-master /** - * Admin::action_deleteblogconfirm() - * Delete Blog + * Admin::action_adminskinremovetypeconfirm() * - * @param Void - * @return Void + * @param void + * @return void */ - function action_deleteblogconfirm() + static private function action_adminskinremovetypeconfirm() { - global $member, $CONF, $manager; + global $member; - $blogid = intRequestVar('blogid'); - $manager->notify('PreDeleteBlog', array('blogid' => $blogid)); - $member->blogAdminRights($blogid) or $this->disallow(); + $member->isAdmin() or self::disallow(); - // check if blog is default blog - if ( $CONF['DefaultBlog'] == $blogid ) + $skinid = intRequestVar('skinid'); + $skintype = requestVar('type'); + + $error = self::skinremovetypeconfirm($skinid, $skintype); + if ( $error ) { - $this->error(_ERROR_DELDEFBLOG); + self::error($error); + return; } +<<<<<<< HEAD // delete all comments $query = 'DELETE FROM '.sql_table('comment').' WHERE cblog='.$blogid; DB::execute($query); @@ -3392,19 +7071,54 @@ class Admin // delete all categories $query = 'DELETE FROM '.sql_table('category').' WHERE cblog='.$blogid; DB::execute($query); +======= + self::action_adminskinedit(); + return; + } + + /** + * Admin::action_adminskinclone() + * + * @param void + * @return void + */ + static private function action_adminskinclone() + { + global $member; - // delete all associated plugin options - NucleusPlugin::delete_option_values('blog', $blogid); + $member->isAdmin() or self::disallow(); + + $skinid = intRequestVar('skinid'); +>>>>>>> skinnable-master + + self::skinclone($skinid, 'AdminActions'); +<<<<<<< HEAD // delete the blog itself $query = 'DELETE FROM '.sql_table('blog').' WHERE bnumber='.$blogid; DB::execute($query); +======= + self::action_adminskinoverview(); + return; + } + + /** + * Admin::action_adminskinieoverview() + * + * @param void + * @return void + */ + static private function action_adminskinieoverview() + { + global $member; +>>>>>>> skinnable-master - $manager->notify('PostDeleteBlog', array('blogid' => $blogid)); + $member->isAdmin() or self::disallow(); - $this->action_overview(_DELETED_BLOG); + self::$skin->parse('adminskinieoverview'); return; } +<<<<<<< HEAD /** * @todo document this @@ -3444,33 +7158,20 @@ class Admin */ function action_memberdeleteconfirm() { global $member; +======= +>>>>>>> skinnable-master - $memberid = intRequestVar('memberid'); - - ($member->getID() == $memberid) or $member->isAdmin() or $this->disallow(); - - $error = $this->deleteOneMember($memberid); - if ($error) - $this->error($error); - - if ($member->isAdmin()) - $this->action_usermanagement(); - else - $this->action_overview(_DELETED_MEMBER); - } - /** - * Admin::deleteOneMember() - * Delete a member by id + * Admin::action_adminskinieimport() * - * @static - * @params Integer $memberid member id - * @return String null string or error messages + * @param void + * @return void */ - function deleteOneMember($memberid) + static private function action_adminskinieimport() { - global $manager; + global $member; +<<<<<<< HEAD $memberid = intval($memberid); $mem =& $manager->getMember($memberid); @@ -3478,12 +7179,17 @@ class Admin { return _ERROR_DELETEMEMBER; } +======= + $member->isAdmin() or self::disallow(); +>>>>>>> skinnable-master - $manager->notify('PreDeleteMember', array('member' => &$mem)); + $skinFileRaw = postVar('skinfile'); + $mode = postVar('mode'); - /* unlink comments from memberid */ - if ( $memberid ) + $error = self::skinieimport($mode, $skinFileRaw); + if ( $error ) { +<<<<<<< HEAD $query = "UPDATE %s SET cmember=0, cuser=%s WHERE cmember=%d"; $query = sprintf($query, sql_table('comment'), DB::quoteValue($mem->getDisplayName()), $memberid); DB::execute($query); @@ -4327,23 +8033,47 @@ selector(); } +======= + self::error($error); + return; + } + + if ( !is_object(self::$skin) ) + { + self::action_adminskiniedoimport(); + } + else + { + self::$skin->parse('adminskinieimport'); + } + return; + } + +>>>>>>> skinnable-master /** - * Admin::addToTemplate() - * - * @param Integer $id ID for template - * @param String $partname parts name - * @param String $content template contents - * @return Integer record index + * Admin::action_adminskiniedoimport() * + * @param void + * @return void */ - function addToTemplate($id, $partname, $content) + static private function action_adminskiniedoimport() { - // don't add empty parts: - if ( !trim($content) ) + global $DIR_SKINS, $member, $CONF; + + $member->isAdmin() or self::disallow(); + + $mode = postVar('mode'); + $skinFileRaw = postVar('skinfile'); + $allowOverwrite = intPostVar('overwrite'); + + $error = self::skiniedoimport($mode, $skinFileRaw, $allowOverwrite); + if ( $error ) { - return -1; + self::error($error); + return; } +<<<<<<< HEAD $partname = DB::quoteValue($partname); $content = DB::quoteValue($content); @@ -5068,17 +8798,41 @@ selector(); $this->action_skinoverview(); } +======= + if ( !is_object(self::$skin) ) + { + global $DIR_SKINS; + $query = "SELECT min(sdnumber) FROM %s WHERE sdname != 'admin/bookmarklet' AND sdname LIKE 'admin/%%'"; + $query = sprintf($query, sql_table('skin_desc')); + $res = intval(DB::getValue($query)); + $query = "UPDATE %s SET value = %d WHERE name = 'AdminSkin'"; + $query = sprintf($query, sql_table('config'), $res); + DB::execute($query); + if ( $res ) + { + redirect($CONF['AdminURL']); + exit; + } + $skin = new Skin(0, 'AdminActions', 'AdminSkin'); + $skin->parse('importAdmin', $DIR_SKINS . 'admin/defaultimporter.skn'); + } + else + { + self::$skin->parse('adminskiniedoimport'); + } + return; + } +>>>>>>> skinnable-master /** - * Admin::skinclonetype() + * Admin::action_adminskinieexport() * - * @param String $skin Skin object - * @param Integer $newid ID for this clone - * @param String $type type of skin - * @return Void + * @param void + * @return void */ - function skinclonetype($skin, $newid, $type) + static private function action_adminskinieexport() { +<<<<<<< HEAD $newid = intval($newid); $content = $skin->getContentFromDB($type); @@ -5088,6 +8842,19 @@ selector(); $query = sprintf($query, sql_table('skin'), (integer) $newid, $content, $type); DB::execute($query); } +======= + global $member; + + $member->isAdmin() or self::disallow(); + + // load skinie class + $aSkins = requestIntArray('skin'); + $aTemplates = requestIntArray('template'); + $info = postVar('info'); + + self::skinieexport($aSkins, $aTemplates, $info); + +>>>>>>> skinnable-master return; } @@ -5097,8 +8864,10 @@ selector(); * @param Void * @return Void */ - function action_settingsedit() { + static private function action_settingsedit() + { global $member, $manager, $CONF, $DIR_NUCLEUS, $DIR_MEDIA; +<<<<<<< HEAD $member->isAdmin() or $this->disallow(); @@ -5428,6 +9197,13 @@ selector(); ); $this->pagefoot(); +======= + + $member->isAdmin() or self::disallow(); + + self::$skin->parse('settingsedit'); + return; +>>>>>>> skinnable-master } /** @@ -5437,61 +9213,65 @@ selector(); * @param void * @return void */ - function action_settingsupdate() { + static private function action_settingsupdate() + { global $member, $CONF; - $member->isAdmin() or $this->disallow(); + $member->isAdmin() or self::disallow(); // check if email address for admin is valid if ( !NOTIFICATION::address_validation(postVar('AdminEmail')) ) { - $this->error(_ERROR_BADMAILADDRESS); + self::error(_ERROR_BADMAILADDRESS); + return; } // save settings - $this->updateConfig('DefaultBlog', postVar('DefaultBlog')); - $this->updateConfig('BaseSkin', postVar('BaseSkin')); - $this->updateConfig('IndexURL', postVar('IndexURL')); - $this->updateConfig('AdminURL', postVar('AdminURL')); - $this->updateConfig('PluginURL', postVar('PluginURL')); - $this->updateConfig('SkinsURL', postVar('SkinsURL')); - $this->updateConfig('ActionURL', postVar('ActionURL')); - $this->updateConfig('Locale', postVar('Locale')); - $this->updateConfig('AdminEmail', postVar('AdminEmail')); - $this->updateConfig('SessionCookie', postVar('SessionCookie')); - $this->updateConfig('AllowMemberCreate',postVar('AllowMemberCreate')); - $this->updateConfig('AllowMemberMail', postVar('AllowMemberMail')); - $this->updateConfig('NonmemberMail', postVar('NonmemberMail')); - $this->updateConfig('ProtectMemNames', postVar('ProtectMemNames')); - $this->updateConfig('SiteName', postVar('SiteName')); - $this->updateConfig('NewMemberCanLogon',postVar('NewMemberCanLogon')); - $this->updateConfig('DisableSite', postVar('DisableSite')); - $this->updateConfig('DisableSiteURL', postVar('DisableSiteURL')); - $this->updateConfig('LastVisit', postVar('LastVisit')); - $this->updateConfig('MediaURL', postVar('MediaURL')); - $this->updateConfig('AllowedTypes', postVar('AllowedTypes')); - $this->updateConfig('AllowUpload', postVar('AllowUpload')); - $this->updateConfig('MaxUploadSize', postVar('MaxUploadSize')); - $this->updateConfig('MediaPrefix', postVar('MediaPrefix')); - $this->updateConfig('AllowLoginEdit', postVar('AllowLoginEdit')); - $this->updateConfig('DisableJsTools', postVar('DisableJsTools')); - $this->updateConfig('CookieDomain', postVar('CookieDomain')); - $this->updateConfig('CookiePath', postVar('CookiePath')); - $this->updateConfig('CookieSecure', postVar('CookieSecure')); - $this->updateConfig('URLMode', postVar('URLMode')); - $this->updateConfig('CookiePrefix', postVar('CookiePrefix')); - $this->updateConfig('DebugVars', postVar('DebugVars')); - $this->updateConfig('DefaultListSize', postVar('DefaultListSize')); - $this->updateConfig('AdminCSS', postVar('AdminCSS')); - + self::updateConfig('DefaultBlog', postVar('DefaultBlog')); + self::updateConfig('BaseSkin', postVar('BaseSkin')); + self::updateConfig('IndexURL', postVar('IndexURL')); + self::updateConfig('AdminURL', postVar('AdminURL')); + self::updateConfig('PluginURL', postVar('PluginURL')); + self::updateConfig('SkinsURL', postVar('SkinsURL')); + self::updateConfig('ActionURL', postVar('ActionURL')); + self::updateConfig('Locale', postVar('Locale')); + self::updateConfig('AdminEmail', postVar('AdminEmail')); + self::updateConfig('SessionCookie', postVar('SessionCookie')); + self::updateConfig('AllowMemberCreate', postVar('AllowMemberCreate')); + self::updateConfig('AllowMemberMail', postVar('AllowMemberMail')); + self::updateConfig('NonmemberMail', postVar('NonmemberMail')); + self::updateConfig('ProtectMemNames', postVar('ProtectMemNames')); + self::updateConfig('SiteName', postVar('SiteName')); + self::updateConfig('NewMemberCanLogon', postVar('NewMemberCanLogon')); + self::updateConfig('DisableSite', postVar('DisableSite')); + self::updateConfig('DisableSiteURL', postVar('DisableSiteURL')); + self::updateConfig('LastVisit', postVar('LastVisit')); + self::updateConfig('MediaURL', postVar('MediaURL')); + self::updateConfig('AllowedTypes', postVar('AllowedTypes')); + self::updateConfig('AllowUpload', postVar('AllowUpload')); + self::updateConfig('MaxUploadSize', postVar('MaxUploadSize')); + self::updateConfig('MediaPrefix', postVar('MediaPrefix')); + self::updateConfig('AllowLoginEdit', postVar('AllowLoginEdit')); + self::updateConfig('DisableJsTools', postVar('DisableJsTools')); + self::updateConfig('CookieDomain', postVar('CookieDomain')); + self::updateConfig('CookiePath', postVar('CookiePath')); + self::updateConfig('CookieSecure', postVar('CookieSecure')); + self::updateConfig('URLMode', postVar('URLMode')); + self::updateConfig('CookiePrefix', postVar('CookiePrefix')); + self::updateConfig('DebugVars', postVar('DebugVars')); + self::updateConfig('DefaultListSize', postVar('DefaultListSize')); + self::updateConfig('AdminCSS', postVar('AdminCSS')); + self::updateConfig('AdminSkin', postVar('adminskin')); + self::updateConfig('BookmarkletSkin', postVar('bookmarklet')); + // load new config and redirect (this way, the new locale will be used is necessary) // note that when changing cookie settings, this redirect might cause the user // to have to log in again. getConfig(); redirect($CONF['AdminURL'] . '?action=manage'); - exit; + return; } - + /** * Admin::action_systemoverview() * Output system overview @@ -5499,8 +9279,9 @@ selector(); * @param void * @return void */ - function action_systemoverview() + static private function action_systemoverview() { +<<<<<<< HEAD global $member, $nucleus, $CONF; $this->pagehead(); @@ -5679,8 +9460,12 @@ selector(); echo _ADMIN_SYSTEMOVERVIEW_NOT_ADMIN; } $this->pagefoot(); +======= + self::$skin->parse('systemoverview'); + return; +>>>>>>> skinnable-master } - + /** * Admin::updateConfig() * @@ -5688,8 +9473,9 @@ selector(); * @param string $val * @return integer return the ID in which the latest query posted */ - function updateConfig($name, $val) + static private function updateConfig($name, $val) { +<<<<<<< HEAD $name = DB::quoteValue($name); $val = DB::quoteValue(trim($val)); @@ -5699,24 +9485,30 @@ selector(); { $err = DB::getError(); die("Query error: " . $err[2]); +======= + $query = "UPDATE %s SET value=%s WHERE name=%s"; + $query = sprintf($query, sql_table('config'), DB::quoteValue($val), DB::quoteValue($name)); + if ( DB::execute($query) === FALSE ) + { + $err = DB::getError(); + die(_ADMIN_SQLDIE_QUERYERROR . $err[2]); +>>>>>>> skinnable-master } return DB::getInsertId(); } /** + * Admin::error() * Error message - * @param string $msg message that will be shown + * + * @param string $msg message that will be shown + * @return void */ - function error($msg) + static public function error($msg) { - $this->pagehead(); - - echo "

Error!

\n"; - echo $msg; - echo "
\n"; - echo '' . _BACK . "\n"; - $this->pagefoot(); - exit; + self::$headMess = $msg; + self::$skin->parse('adminerrorpage'); + return; } /** @@ -5726,19 +9518,35 @@ selector(); * @param void * @return void */ - function disallow() + static public function disallow() { ActionLog::add(WARNING, _ACTIONLOG_DISALLOWED . serverVar('REQUEST_URI')); - $this->error(_ERROR_DISALLOWED); + self::error(_ERROR_DISALLOWED); + return; + } + + /** + * Admin::action_PluginAdmin() + * Output pluginadmin + * + * @param string $skinContents + * @param string $extrahead + * @return void + */ + static public function action_PluginAdmin($skinContents, $extrahead = '') + { + self::$extrahead .= $extrahead; + self::$skin->parse('pluginadmin', $skinContents); + return; } /** - * Admin::pagehead() - * Output admin page head + * Admin::action_bookmarklet() * * @param void * @return void */ +<<<<<<< HEAD function pagehead($extrahead = '') { global $member, $nucleus, $CONF, $manager; @@ -5795,194 +9603,131 @@ selector(); } echo ""._YOURSITE."
\n"; echo '('; +======= + static private function action_bookmarklet() + { + global $member, $manager; +>>>>>>> skinnable-master - if (array_key_exists('codename', $nucleus) && $nucleus['codename'] != '' ) - { - $codenamestring = ' "' . $nucleus['codename'].'"'; - } - else - { - $codenamestring = ''; - } + $blogid = intRequestVar('blogid'); + $member->teamRights($blogid) or self::disallow(); - if ( $member->isLoggedIn() && $member->isAdmin() ) - { - $checkURL = sprintf(_ADMIN_SYSTEMOVERVIEW_VERSIONCHECK_URL, getNucleusVersion(), getNucleusPatchLevel()); - echo 'Nucleus CMS ' . $nucleus['version'] . $codenamestring . ''; - - $newestVersion = getLatestVersion(); - $newestCompare = str_replace('/','.',$newestVersion); - $currentVersion = str_replace(array('/','v'),array('.',''),$nucleus['version']); - if ( $newestVersion && version_compare($newestCompare, $currentVersion) > 0 ) - { - echo "
\n"; - echo ''; - echo _ADMIN_SYSTEMOVERVIEW_LATESTVERSION_TEXT . $newestVersion; - echo ""; - } - } - else - { - echo 'Nucleus CMS ' . $nucleus['version'] . $codenamestring; - } - echo ')'; - echo ''; + self::$skin->parse('bookmarklet'); + return; + } + + /** + * Admin::action_actionlog() + * + * @param void + * @return void + */ + static private function action_actionlog() + { + global $member, $manager; + + $member->isAdmin() or self::disallow(); + + self::$skin->parse('actionlog'); return; } /** - * Admin::pagefoot() - * Output admin page foot include quickmenu + * Admin::action_banlist() * * @param void * @return void */ - function pagefoot() + static private function action_banlist() { - global $action, $member, $manager; + global $member, $manager; - $manager->notify( - 'AdminPrePageFoot', - array('action' => $this->action) - ); + $blogid = intRequestVar('blogid'); + $member->blogAdminRights($blogid) or self::disallow(); - if ( $member->isLoggedIn() && ($action != 'showlogin') ) - { - echo '

' . _LOGOUT . "

\n"; - echo "\n"; - } + self::$skin->parse('banlist'); + return; + } + + /** + * Admin::action_banlistdelete() + * + * @param void + * @return void + */ + static private function action_banlistdelete() + { + global $member, $manager; - echo "
\n"; - echo 'Nucleus CMS © 2002-' . date('Y') . ' ' . _ADMINPAGEFOOT_COPYRIGHT; - echo '-'; - echo '' . _ADMINPAGEFOOT_DONATE . "\n"; - echo "
\n"; + $blogid = intRequestVar('blogid'); + $member->blogAdminRights($blogid) or self::disallow(); + + self::$skin->parse('banlistdelete'); + return; + } + + /** + * Admin::action_banlistdeleteconfirm() + * + * @param void + * @return void + */ + static private function action_banlistdeleteconfirm() + { + global $member, $manager; - echo "\n"; - echo "
\n"; + $blogid = intPostVar('blogid'); + $allblogs = postVar('allblogs'); + $iprange = postVar('iprange'); - if ( ($action != 'showlogin') && ($member->isLoggedIn()) ) + $member->blogAdminRights($blogid) or self::disallow(); + + $deleted = array(); + + if ( !$allblogs ) { - echo "\n"; - - echo '

' . _QMENU_ADD . "

\n"; - echo "
\n"; - echo "

\n"; - echo "\n"; - - $showAll = requestVar('showall'); - - if ( ($member->isAdmin()) && ($showAll == 'yes') ) - { - // Super-Admins have access to all blogs! (no add item support though) - $query = 'SELECT bnumber as value, bname as text' - . ' FROM ' . sql_table('blog') - . ' ORDER BY bname'; - } - else + if ( Ban::removeBan($blogid, $iprange) ) { - $query = 'SELECT bnumber as value, bname as text' - . ' FROM ' . sql_table('blog') . ', ' . sql_table('team') - . ' WHERE tblog=bnumber and tmember=' . $member->getID() - . ' ORDER BY bname'; + $deleted[] = $blogid; } - $template['name'] = 'blogid'; - $template['tabindex'] = 15000; - $template['extra'] = _QMENU_ADD_SELECT; - $template['selected'] = -1; - $template['shorten'] = 10; - $template['shortenel'] = ''; - $template['javascript'] = 'onchange="return form.submit()"'; - showlist($query,'select',$template); - - echo "

\n"; - echo "
\n"; - - echo "

{$member->getDisplayName()}

\n"; - echo "\n"; - - // ---- general settings ---- - if ( $member->isAdmin() ) - { - echo '

' . _QMENU_MANAGE . "

\n"; - echo "\n"; - - echo "

" . _QMENU_LAYOUT . "

\n"; - echo "\n"; - } - - $aPluginExtras = array(); - $manager->notify( - 'QuickMenu', - array( - 'options' => &$aPluginExtras)); - - if ( count($aPluginExtras) > 0 ) + } + else + { + // get blogs fot which member has admin rights + $adminblogs = $member->getAdminBlogs(); + foreach ($adminblogs as $blogje) { - echo "

" . _QMENU_PLUGINS . "

\n"; - echo "\n"; } } - else if ( ($action == 'activate') || ($action == 'activatesetpwd') ) - { - echo '

' . _QMENU_ACTIVATE . '

' . _QMENU_ACTIVATE_TEXT; - } - else + if ( sizeof($deleted) == 0 ) { - // introduction text on login screen - echo '

' . _QMENU_INTRO . '

' . _QMENU_INTRO_TEXT; + self::error(_ERROR_DELETEBAN); + return; } - echo "\n"; - echo "
\n"; - - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; + /* TODO: we should use other ways */ + $_REQUEST['delblogs'] = $deleted; - echo "\n"; - echo "\n"; + self::$skin->parse('banlistdeleteconfirm'); return; } /** +<<<<<<< HEAD * Admin::action_bookmarklet() +======= + * Admin::action_banlistnewfromitem() +>>>>>>> skinnable-master * * @param void * @return void */ +<<<<<<< HEAD public function action_bookmarklet() { global $member, $manager; @@ -6354,9 +10099,132 @@ selector();

+======= + static private function action_banlistnewfromitem() + { + global $manager; + + $itemid = intRequestVar('itemid'); + $item =& $manager->getItem($itemid, 1, 1); + self::action_banlistnew($item['blogid']); + return; + } + + /** + * Admin::action_banlistnew() + * + * @param integer $blogid ID for weblog + * @return void + */ + static private function action_banlistnew($blogid = '') + { + global $member, $manager; + + if ( $blogid == '' ) + { + $blogid = intRequestVar('blogid'); + } + + $ip = requestVar('ip'); + + $member->blogAdminRights($blogid) or self::disallow(); + + /* TODO: we should consider to use the other way instead of this */ + $_REQUEST['blogid'] = $blogid; + + self::$skin->parse('banlistnew'); + + return; + } +>>>>>>> skinnable-master - pagefoot(); - } + /** + * Admin::action_banlistadd() + * + * @param void + * @return void + */ + static private function action_banlistadd() + { + global $member; + + $blogid = intPostVar('blogid'); + $allblogs = postVar('allblogs'); + $iprange = postVar('iprange'); + + if ( $iprange == "custom" ) + { + $iprange = postVar('customiprange'); + } + $reason = postVar('reason'); + + $member->blogAdminRights($blogid) or self::disallow(); + + // TODO: check IP range validity + + if ( !$allblogs ) + { + if ( !Ban::addBan($blogid, $iprange, $reason) ) + { + self::error(_ERROR_ADDBAN); + return; + } + } + else + { + // get blogs fot which member has admin rights + $adminblogs = $member->getAdminBlogs(); + $failed = 0; + foreach ($adminblogs as $blogje) + { + if ( !Ban::addBan($blogje, $iprange, $reason) ) + { + $failed = 1; + } + } + if ( $failed ) + { + self::error(_ERROR_ADDBAN); + return; + } + } + self::action_banlist(); + return; + } + + /** + * Admin::action_clearactionlog() + * + * @param void + * @return void + */ + static private function action_clearactionlog() + { + global $member; + + $member->isAdmin() or self::disallow(); + + ActionLog::clear(); + + self::action_manage(_MSG_ACTIONLOGCLEARED); + return; + } + + /** + * Admin::action_backupoverview() + * + * @param void + * @return void + */ + static private function action_backupoverview() + { + global $member, $manager; + + $member->isAdmin() or self::disallow(); + + self::$skin->parse('backupoverview'); + return; + } /** * Admin::action_backupcreate() @@ -6366,11 +10234,11 @@ selector(); * @return void * */ - function action_backupcreate() + static private function action_backupcreate() { global $member, $DIR_LIBS; - $member->isAdmin() or $this->disallow(); + $member->isAdmin() or self::disallow(); // use compression ? $useGzip = (integer) postVar('gzip'); @@ -6382,7 +10250,7 @@ selector(); @set_time_limit(1200); Backup::do_backup($useGzip); - exit; + return; } /** @@ -6392,15 +10260,16 @@ selector(); * @param void * @return void */ - function action_backuprestore() + static private function action_backuprestore() { global $member, $DIR_LIBS; - $member->isAdmin() or $this->disallow(); + $member->isAdmin() or self::disallow(); if ( intPostVar('letsgo') != 1 ) { - $this->error(_ERROR_BACKUP_NOTSURE); + self::error(_ERROR_BACKUP_NOTSURE); + return; } include($DIR_LIBS . 'backup.php'); @@ -6412,11 +10281,10 @@ selector(); $message = Backup::do_restore(); if ( $message != '' ) { - $this->error($message); + self::error($message); + return; } - $this->pagehead(); - echo '

' . _RESTORE_COMPLETE . "

\n"; - $this->pagefoot(); + self::$skin->parse('backuprestore'); return; } @@ -6428,43 +10296,28 @@ selector(); * @return void * */ - function action_pluginlist() + static private function action_pluginlist() { global $DIR_PLUGINS, $member, $manager; // check if allowed - $member->isAdmin() or $this->disallow(); + $member->isAdmin() or self::disallow(); - $this->pagehead(); - - echo '

(',_BACKTOMANAGE,')

'; - - echo '

' , _PLUGS_TITLE_MANAGE , ' ', help('plugins'), '

'; - - echo '

' , _PLUGS_TITLE_INSTALLED , '   ', helplink('getplugins'), _PLUGS_TITLE_GETPLUGINS, '

'; - - $query = 'SELECT * FROM '.sql_table('plugin').' ORDER BY porder ASC'; - - $template['content'] = 'pluginlist'; - $template['tabindex'] = 10; - showlist($query, 'table', $template); - - echo '

' . _PLUGS_TITLE_UPDATE . "

\n"; - echo '

' . _PLUGS_TEXT_UPDATE . "

\n"; - echo '
' . "\n"; - echo "
\n"; - echo '' . "\n"; - $manager->addTicketHidden(); - echo '' . "\n"; - echo "
\n"; - echo "
\n"; - - echo '

' . _PLUGS_TITLE_NEW . "

\n"; - - // find a list of possibly non-installed plugins - $candidates = array(); - $dirhandle = opendir($DIR_PLUGINS); + self::$skin->parse('pluginlist'); + return; + } + + /** + * Admin::action_pluginhelp() + * + * @param void + * @return void + */ + static private function action_pluginhelp() + { + global $member, $manager, $DIR_PLUGINS, $CONF; +<<<<<<< HEAD while ( $filename = readdir($dirhandle) ) { if ( preg_match('#^NP_(.*)\.php$#', $filename, $matches) ) @@ -6482,38 +10335,24 @@ selector(); } } } +======= + // check if allowed + $member->isAdmin() or self::disallow(); +>>>>>>> skinnable-master - closedir($dirhandle); + $plugid = intGetVar('plugid'); - if ( sizeof($candidates) > 0 ) - { - echo '

' . _PLUGS_ADD_TEXT . "

\n"; - - echo '
' . "\n"; - echo "
\n"; - echo '' . "\n"; - $manager->addTicketHidden(); - echo '\n"; - echo '\n"; - echo "
\n"; - echo "
\n"; - } - else + if ( !$manager->pidInstalled($plugid) ) { - echo '

', _PLUGS_NOCANDIDATES, '

'; + self::error(_ERROR_NOSUCHPLUGIN); + return; } - $this->pagefoot(); + self::$skin->parse('pluginhelp'); return; } +<<<<<<< HEAD /** * @todo document this */ @@ -6550,6 +10389,8 @@ selector(); $this->pagefoot(); } +======= +>>>>>>> skinnable-master /** * Admin::action_pluginadd() * @@ -6557,80 +10398,312 @@ selector(); * @return Void * */ - function action_pluginadd() + static private function action_pluginadd() { global $member, $manager, $DIR_PLUGINS; // check if allowed - $member->isAdmin() or $this->disallow(); + $member->isAdmin() or self::disallow(); + + $name = postVar('filename'); + + if ( $manager->pluginInstalled($name) ) + { + self::error(_ERROR_DUPPLUGIN); + return; + } + + if ( !checkPlugin($name) ) + { + self::error(_ERROR_PLUGFILEERROR . ' (' . Entity::hsc($name) . ')'); + return; + } + + // get number of currently installed plugins +<<<<<<< HEAD + $res = DB::getResult('SELECT * FROM '.sql_table('plugin')); +======= + $res = DB::getResult('SELECT * FROM ' . sql_table('plugin')); +>>>>>>> skinnable-master + $numCurrent = $res->rowCount(); + + // plugin will be added as last one in the list + $newOrder = $numCurrent + 1; + + $data = array('file' => &$name); + $manager->notify('PreAddPlugin', $data); + + // do this before calling getPlugin (in case the plugin id is used there) +<<<<<<< HEAD + $query = 'INSERT INTO '.sql_table('plugin').' (porder, pfile) VALUES ('.$newOrder.','.DB::quoteValue($name).')'; +======= + $query = "INSERT INTO %s (porder, pfile) VALUES (%d, %s);"; + $query = sprintf($query, sql_table('plugin'), (integer) $newOrder, DB::quoteValue($name)); +>>>>>>> skinnable-master + DB::execute($query); + $iPid = DB::getInsertId(); + + $manager->clearCachedInfo('installedPlugins'); + + // Load the plugin for condition checking and instalation + $plugin =& $manager->getPlugin($name); + + // check if it got loaded (could have failed) + if ( !$plugin ) + { +<<<<<<< HEAD + DB::execute('DELETE FROM ' . sql_table('plugin') . ' WHERE pid='. intval($iPid)); +======= + $query = "DELETE FROM %s WHERE pid=%d;"; + $query = sprintf($query, sql_table('plugin'), (integer) $iPid); + + DB::execute($query); + +>>>>>>> skinnable-master + $manager->clearCachedInfo('installedPlugins'); + self::error(_ERROR_PLUGIN_LOAD); + return; + } + + // check if plugin needs a newer Nucleus version + if ( getNucleusVersion() < $plugin->getMinNucleusVersion() ) + { + // uninstall plugin again... + self::deleteOnePlugin($plugin->getID()); + + // ...and show error + self::error(_ERROR_NUCLEUSVERSIONREQ . Entity::hsc($plugin->getMinNucleusVersion())); + return; + } + + // check if plugin needs a newer Nucleus version + if ( (getNucleusVersion() == $plugin->getMinNucleusVersion()) && (getNucleusPatchLevel() < $plugin->getMinNucleusPatchLevel()) ) + { + // uninstall plugin again... + self::deleteOnePlugin($plugin->getID()); + + // ...and show error + self::error(_ERROR_NUCLEUSVERSIONREQ . Entity::hsc( $plugin->getMinNucleusVersion() . ' patch ' . $plugin->getMinNucleusPatchLevel() ) ); + return; + } + + $pluginList = $plugin->getPluginDep(); + foreach ( $pluginList as $pluginName ) + { + $res = DB::getResult('SELECT * FROM '.sql_table('plugin') . ' WHERE pfile=' . DB::quoteValue($pluginName)); + if ($res->rowCount() == 0) + { + // uninstall plugin again... + self::deleteOnePlugin($plugin->getID()); + self::error(sprintf(_ERROR_INSREQPLUGIN, Entity::hsc($pluginName))); + return; + } + } + + // call the install method of the plugin + $plugin->install(); + + $data = array('plugin' => &$plugin); + $manager->notify('PostAddPlugin', $data); + + // update all events + self::action_pluginupdate(); + return; + } + + /** + * ADMIN:action_pluginupdate(): + * + * @param Void + * @return Void + * + */ + static private function action_pluginupdate() + { + global $member, $manager, $CONF; + + // check if allowed + $member->isAdmin() or self::disallow(); + + // delete everything from plugin_events + DB::execute('DELETE FROM '.sql_table('plugin_event')); + + // loop over all installed plugins + $res = DB::getResult('SELECT pid, pfile FROM '.sql_table('plugin')); + foreach ( $res as $row ) + { + $pid = $row['pid']; + $plug =& $manager->getPlugin($row['pfile']); + if ( $plug ) + { + $eventList = $plug->getEventList(); + foreach ( $eventList as $eventName ) + { + $query = "INSERT INTO %s (pid, event) VALUES (%d, %s)"; + $query = sprintf($query, sql_table('plugin_event'), (integer) $pid, DB::quoteValue($eventName)); + DB::execute($query); + } + } + } + redirect($CONF['AdminURL'] . '?action=pluginlist'); + return; + } + + /** + * Admin::action_plugindelete() + * + * @param void + * @return void + */ + static private function action_plugindelete() + { + global $member, $manager; + + // check if allowed + $member->isAdmin() or self::disallow(); + + $pid = intGetVar('plugid'); + + if ( !$manager->pidInstalled($pid) ) + { + self::error(_ERROR_NOSUCHPLUGIN); + return; + } + + self::$skin->parse('plugindelete'); + return; + } + + /** + * Admin::action_plugindeleteconfirm() + * + * @param void + * @return void + */ + static private function action_plugindeleteconfirm() + { + global $member, $manager, $CONF; + + // check if allowed + $member->isAdmin() or self::disallow(); + + $pid = intPostVar('plugid'); + + $error = self::deleteOnePlugin($pid, 1); + if ( $error ) + { + self::error($error); + return; + } + + redirect($CONF['AdminURL'] . '?action=pluginlist'); + return; + } + + /** + * Admin::deleteOnePlugin() + * + * @param integer $pid + * @param boolean $callUninstall + * @return string empty or message if failed + */ + static public function deleteOnePlugin($pid, $callUninstall = 0) + { + global $manager; - $name = postVar('filename'); + $pid = intval($pid); - if ( $manager->pluginInstalled($name) ) + if ( !$manager->pidInstalled($pid) ) { - $this->error(_ERROR_DUPPLUGIN); + return _ERROR_NOSUCHPLUGIN; } - if ( !checkPlugin($name) ) + $query = "SELECT pfile as result FROM %s WHERE pid=%d;"; + $query = sprintf($query, sql_table('plugin'), (integer) $pid); + $name = DB::getValue($query); + + // check dependency before delete + $res = DB::getResult('SELECT pfile FROM ' . sql_table('plugin')); + foreach ( $res as $row ) { - $this->error(_ERROR_PLUGFILEERROR . ' (' . Entity::hsc($name) . ')'); + $plug =& $manager->getPlugin($row['pfile']); + if ( $plug ) + { + $depList = $plug->getPluginDep(); + foreach ( $depList as $depName ) + { + if ( $name == $depName ) + { + return sprintf(_ERROR_DELREQPLUGIN, $row['pfile']); + } + } + } } - // get number of currently installed plugins - $res = DB::getResult('SELECT * FROM '.sql_table('plugin')); - $numCurrent = $res->rowCount(); - - // plugin will be added as last one in the list - $newOrder = $numCurrent + 1; - - $manager->notify( - 'PreAddPlugin', - array( - 'file' => &$name - ) - ); - - // do this before calling getPlugin (in case the plugin id is used there) - $query = 'INSERT INTO '.sql_table('plugin').' (porder, pfile) VALUES ('.$newOrder.','.DB::quoteValue($name).')'; - DB::execute($query); - $iPid = DB::getInsertId(); - - $manager->clearCachedInfo('installedPlugins'); - - // Load the plugin for condition checking and instalation - $plugin =& $manager->getPlugin($name); + $data = array('plugid' => $pid); + $manager->notify('PreDeletePlugin', $data); - // check if it got loaded (could have failed) - if ( !$plugin ) + // call the unInstall method of the plugin + if ( $callUninstall ) { - DB::execute('DELETE FROM ' . sql_table('plugin') . ' WHERE pid='. intval($iPid)); - $manager->clearCachedInfo('installedPlugins'); - $this->error(_ERROR_PLUGIN_LOAD); + $plugin =& $manager->getPlugin($name); + if ( $plugin ) + { + $plugin->unInstall(); + } } - // check if plugin needs a newer Nucleus version - if ( getNucleusVersion() < $plugin->getMinNucleusVersion() ) + // delete all subscriptions + DB::execute('DELETE FROM ' . sql_table('plugin_event') . ' WHERE pid=' . $pid); + + // delete all options + // get OIDs from plugin_option_desc + $res = DB::getResult('SELECT oid FROM ' . sql_table('plugin_option_desc') . ' WHERE opid=' . $pid); + $aOIDs = array(); + foreach ( $res as $row ) { - // uninstall plugin again... - $this->deleteOnePlugin($plugin->getID()); - - // ...and show error - $this->error(_ERROR_NUCLEUSVERSIONREQ . Entity::hsc($plugin->getMinNucleusVersion())); + array_push($aOIDs, $row['oid']); } - // check if plugin needs a newer Nucleus version - if ( (getNucleusVersion() == $plugin->getMinNucleusVersion()) && (getNucleusPatchLevel() < $plugin->getMinNucleusPatchLevel()) ) + // delete from plugin_option and plugin_option_desc + DB::execute('DELETE FROM ' . sql_table('plugin_option_desc') . ' WHERE opid=' . $pid); + if (count($aOIDs) > 0) { - // uninstall plugin again... - $this->deleteOnePlugin($plugin->getID()); - - // ...and show error - $this->error(_ERROR_NUCLEUSVERSIONREQ . Entity::hsc( $plugin->getMinNucleusVersion() . ' patch ' . $plugin->getMinNucleusPatchLevel() ) ); + DB::execute('DELETE FROM ' . sql_table('plugin_option') . ' WHERE oid in (' . implode(',', $aOIDs) . ')'); } - $pluginList = $plugin->getPluginDep(); - foreach ( $pluginList as $pluginName ) + // update order numbers + $res = DB::getValue('SELECT porder FROM ' . sql_table('plugin') . ' WHERE pid=' . $pid); + DB::execute('UPDATE ' . sql_table('plugin') . ' SET porder=(porder - 1) WHERE porder>' . $res); + + // delete row + DB::execute('DELETE FROM ' . sql_table('plugin') . ' WHERE pid=' . $pid); + + $manager->clearCachedInfo('installedPlugins'); + $data = array('plugid' => $pid); + $manager->notify('PostDeletePlugin', $data); + + return ''; + } + + /** + * Admin::action_pluginup() + * + * @param void + * @return void + */ + static private function action_pluginup() + { + global $member, $manager, $CONF; + + // check if allowed + $member->isAdmin() or self::disallow(); + + $plugid = intGetVar('plugid'); + + if ( !$manager->pidInstalled($plugid) ) { +<<<<<<< HEAD $res = DB::getResult('SELECT * FROM '.sql_table('plugin') . ' WHERE pfile=' . DB::quoteValue($pluginName)); if ($res->rowCount() == 0) { @@ -6638,35 +10711,40 @@ selector(); $this->deleteOnePlugin($plugin->getID()); $this->error(sprintf(_ERROR_INSREQPLUGIN, Entity::hsc($pluginName))); } +======= + self::error(_ERROR_NOSUCHPLUGIN); + return; +>>>>>>> skinnable-master } - // call the install method of the plugin - $plugin->install(); + // 1. get old order number + $oldOrder = DB::getValue('SELECT porder FROM ' . sql_table('plugin') . ' WHERE pid=' . $plugid); - $manager->notify( - 'PostAddPlugin', - array( - 'plugin' => &$plugin - ) - ); + // 2. calculate new order number + $newOrder = ($oldOrder > 1) ? ($oldOrder - 1) : 1; - // update all events - $this->action_pluginupdate(); + // 3. update plug numbers + DB::execute('UPDATE ' . sql_table('plugin') . ' SET porder=' . $oldOrder . ' WHERE porder=' . $newOrder); + DB::execute('UPDATE ' . sql_table('plugin') . ' SET porder=' . $newOrder . ' WHERE pid=' . $plugid); + + //self::action_pluginlist(); + // To avoid showing ticket in the URL, redirect to pluginlist, instead. + redirect($CONF['AdminURL'] . '?action=pluginlist'); return; } /** - * ADMIN:action_pluginupdate(): - * - * @param Void - * @return Void + * Admin::action_plugindown() * + * @param void + * @return void */ - function action_pluginupdate() + static private function action_plugindown() { global $member, $manager, $CONF; // check if allowed +<<<<<<< HEAD $member->isAdmin() or $this->disallow(); // delete everything from plugin_events @@ -6688,11 +10766,37 @@ selector(); DB::execute($query); } } +======= + $member->isAdmin() or self::disallow(); + + $plugid = intGetVar('plugid'); + if ( !$manager->pidInstalled($plugid) ) + { + self::error(_ERROR_NOSUCHPLUGIN); + return; +>>>>>>> skinnable-master } + + // 1. get old order number + $oldOrder = DB::getValue('SELECT porder FROM ' . sql_table('plugin') . ' WHERE pid=' . $plugid); + + $res = DB::getResult('SELECT * FROM ' . sql_table('plugin')); + $maxOrder = $res->rowCount(); + + // 2. calculate new order number + $newOrder = ($oldOrder < $maxOrder) ? ($oldOrder + 1) : $maxOrder; + + // 3. update plug numbers + DB::execute('UPDATE ' . sql_table('plugin') . ' SET porder=' . $oldOrder . ' WHERE porder=' . $newOrder); + DB::execute('UPDATE ' . sql_table('plugin') . ' SET porder=' . $newOrder . ' WHERE pid=' . $plugid); + + //self::action_pluginlist(); + // To avoid showing ticket in the URL, redirect to pluginlist, instead. redirect($CONF['AdminURL'] . '?action=pluginlist'); return; } +<<<<<<< HEAD /** * @todo document this */ @@ -6876,6 +10980,8 @@ selector(); redirect($CONF['AdminURL'] . '?action=pluginlist'); } +======= +>>>>>>> skinnable-master /** * Admin::action_pluginoptions() * @@ -6886,19 +10992,21 @@ selector(); * @return void * */ - public function action_pluginoptions($message = '') + static private function action_pluginoptions($message = '') { global $member, $manager; // check if allowed - $member->isAdmin() or $this->disallow(); + $member->isAdmin() or self::disallow(); - $pid = (integer) requestVar('plugid'); + $pid = intRequestVar('plugid'); if ( !$manager->pidInstalled($pid) ) { - $this->error(_ERROR_NOSUCHPLUGIN); + self::error(_ERROR_NOSUCHPLUGIN); + return; } +<<<<<<< HEAD $pname = $manager->getPluginNameFromPid($pid); /* NOTE: to include translation file */ @@ -6957,11 +11065,17 @@ selector(); if ( $amount == 0 ) { echo '

',_ERROR_NOPLUGOPTIONS,'

'; +======= + if ( isset($message) ) + { + self::$headMess = $message; +>>>>>>> skinnable-master } - echo "\n"; - echo "\n"; - $this->pagefoot(); + $plugname = $manager->getPluginNameFromPid($pid); + $plugin = $manager->getPlugin($plugname); + self::$extrahead .= "\n"; + self::$skin->parse('pluginoptions'); return; } @@ -6974,42 +11088,128 @@ selector(); * @param void * @return void */ - public function action_pluginoptionsupdate() + static private function action_pluginoptionsupdate() { global $member, $manager; // check if allowed - $member->isAdmin() or $this->disallow(); + $member->isAdmin() or self::disallow(); + + $pid = intRequestVar('plugid'); - $pid = (integer) requestVar('plugid'); if ( !$manager->pidInstalled($pid) ) { - $this->error(_ERROR_NOSUCHPLUGIN); + self::error(_ERROR_NOSUCHPLUGIN); + return; } $aOptions = requestArray('plugoption'); NucleusPlugin::apply_plugin_options($aOptions); - $manager->notify('PostPluginOptionsUpdate',array('context' => 'global', 'plugid' => $pid)); + $data = array( + 'context' => 'global', + 'plugid' => $pid + ); + $manager->notify('PostPluginOptionsUpdate', $data); - $this->action_pluginoptions(_PLUGS_OPTIONS_UPDATED); + self::action_pluginoptions(_PLUGS_OPTIONS_UPDATED); return; } /** - * Admin::_insertPluginOptions() + * Admin::skineditgeneral() * - * Output plugin option field + * @param integer $skinid + * @param string $handler + * @return string empty or message if failed + */ + static private function skineditgeneral($skinid, $handler='') + { + global $manager; + + $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() * - * @access public - * @param string $context plugin option context - * @param integer $contextid plugin option context id + * @param integer $skinid * @return void */ - public function _insertPluginOptions($context, $contextid = 0) + static private function skindeleteconfirm($skinid) + { + global $manager; + + if ( !in_array(self::$action, self::$adminskin_actions) ) + { + $event_identifier = 'Skin'; + } + else + { + $event_identifier = 'AdminSkin'; + } + + $data = array('skinid' => $skinid); + $manager->notify("PreDelete{$event_identifier}", $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); + + $manager->notify("PostDelete{$event_identifier}", $data); + + return; + } + + /** + * Admin::skinremovetypeconfirm() + * + * @param integer $skinid + * @param string $skintype + * @return string empty or message if failed + */ + static private function skinremovetypeconfirm($skinid, $skintype) { global $manager; +<<<<<<< HEAD /* get current registered plugin option list in this context even if it's not used */ $query = 'SELECT * FROM %s AS plugins, %s AS options LEFT OUTER JOIN %s AS added ' . 'ON ( options.oid=added.oid ) ' @@ -7063,61 +11263,251 @@ selector(); echo ''; listplug_plugOptionRow($option); echo ''; +======= + if ( !in_array(self::$action, self::$adminskin_actions) ) + { + $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($row['stype'])); + DB::execute($query); +>>>>>>> skinnable-master } } return; } /** - * Admin::input_yesno() - * Output input elements with radio attribute for yes/no options + * Admin::skinieimport() * - * @param string $name name attribute - * @param string $value_current current value attribute - * @param integer $tabindex tab index - * @param string $value_yes value attribute for yes option - * @param string $value_no value attribute for no option - * @param string $text_yes child text element for yes option - * @param string $text_no child text element for no option - * @param boolean $isAdmin have admin right or not - * @return void + * @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; + } + + self::$contents['mode'] = $mode; + self::$contents['skinfile'] = $skinFileRaw; + self::$contents['skininfo'] = $importer->getInfo(); + self::$contents['skinnames'] = $importer->getSkinNames(); + self::$contents['tpltnames'] = $importer->getTemplateNames(); + + // clashes + $skinNameClashes = $importer->checkSkinNameClashes(); + $templateNameClashes = $importer->checkTemplateNameClashes(); + $hasNameClashes = (count($skinNameClashes) > 0) || (count($templateNameClashes) > 0); + + self::$contents['skinclashes'] = $skinNameClashes; + self::$contents['tpltclashes'] = $templateNameClashes; + self::$contents['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 */ - function input_yesno($name, $value_current, $tabindex = 0, $value_yes = 1, $value_no = 0, $text_yes = _YES, $text_no = _NO, $isAdmin = 0) + static private function skiniedoimport($mode, $skinFileRaw, $allowOverwrite) { - $id = preg_replace('#\[|\]#', '-', $name); - $id_yes = $id . $value_yes; - $id_no = $id . $value_no; + global $DIR_LIBS, $DIR_SKINS; + + // load skinie class + include_once($DIR_LIBS . 'skinie.php'); + + $importer = new SkinImport(); - /* yes option */ - echo 'readFile($skinFile); + if ( $error ) + { + unset($importer); + return $error; + } + + $error = $importer->writeToDatabase($allowOverwrite); + if ( $error ) + { + unset($importer); + return $error; + } + + self::$contents['mode'] = $mode; + self::$contents['skinfile'] = $skinFileRaw; + self::$contents['skininfo'] = $importer->getInfo(); + self::$contents['skinnames'] = $importer->getSkinNames(); + self::$contents['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) ) { - echo " tabindex='$tabindex' checked='checked'"; + $aSkins = array(); } - echo " />\n"; - echo '\n"; - /* no option */ - echo 'addSkin($skinId); } - if ($isAdmin && $name=="canlogin") + foreach ( $templateList as $templateId ) { - echo ' disabled="disabled"'; + $exporter->addTemplate($templateId); } - echo " />\n"; - echo '\n"; + $exporter->setInfo($info); + $exporter->export(); return; } + + /** + * Admin::action_parseSpecialskin() + * + * @param void + * @return void + */ + static private function action_parseSpecialskin() + { + self::$skin->parse(self::$action); + return; + } } diff --git a/nucleus/libs/AdminActions.php b/nucleus/libs/AdminActions.php new file mode 100644 index 0000000..880ea41 --- /dev/null +++ b/nucleus/libs/AdminActions.php @@ -0,0 +1,5466 @@ + _ADM_SKPRT_ACTIONLOG, + 'activate' => _ADM_SKPRT_ACTIVATE, + 'activatesetpwd' => _ADM_SKPRT_ACTIVATESETPWD, + 'addnewlog' => _ADM_SKPRT_ADDNEWLOG, + 'adminerrorpage' => _ADM_SKPRT_ADMINERRORPAGE, + 'adminskindelete' => _ADM_SKPRT_ADMINSKINDELETE, + 'adminskinedit' => _ADM_SKPRT_ADMINSKINEDIT, + 'adminskinedittype' => _ADM_SKPRT_ADMINSKINEDITTYPE, + 'adminskiniedoimport' => _ADM_SKPRT_ADMINSKINIEDOIMPORT, + 'adminskinieimport' => _ADM_SKPRT_ADMINSKINIEIMPORT, + 'adminskinieoverview' => _ADM_SKPRT_ADMINSKINIEOVERVIEW, + 'adminskinoverview' => _ADM_SKPRT_ADMINSKINOVERVIEW, + 'adminskinremovetype' => _ADM_SKPRT_ADMINSKINREMOVETYPE, + 'admintemplatedelete' => _ADM_SKPRT_ADMINTEMPLATEDELETE, + 'admintemplateedit' => _ADM_SKPRT_ADMINTEMPLATEEDIT, + 'admintemplateoverview' => _ADM_SKPRT_ADMINTEMPLATEOVERVIEW, + 'backupoverview' => _ADM_SKPRT_BACKUPOVERVIEW, + 'backuprestore' => _ADM_SKPRT_BACKUPRESTORE, + 'banlist' => _ADM_SKPRT_BANLIST, + 'banlistdelete' => _ADM_SKPRT_BANLISTDELETE, + 'banlistdeleteconfirm' => _ADM_SKPRT_BANLISTDELETECONFIRM, + 'banlistnew' => _ADM_SKPRT_BANLISTNEW, + 'batchcategory' => _ADM_SKPRT_BATCHCATEGORY, + 'batchcomment' => _ADM_SKPRT_BATCHCOMMENT, + 'batchdelete' => _ADM_SKPRT_BATCHDELETE, + 'batchitem' => _ADM_SKPRT_BATCHITEM, + 'batchmember' => _ADM_SKPRT_BATCHMEMBER, + 'batchmove' => _ADM_SKPRT_BATCHMOVE, + 'batchmovecat' => _ADM_SKPRT_BATCHMOVECAT, + 'batchteam' => _ADM_SKPRT_BATCHTEAM, + 'blogcommentlist' => _ADM_SKPRT_BLOGCOMMENTLIST, + 'blogsettings' => _ADM_SKPRT_BLOGSETTINGS, + 'bookmarklet' => _ADM_SKPRT_BOOKMARKLET, + 'browseowncomments' => _ADM_SKPRT_BROWSEOWNCOMMENTS, + 'browseownitems' => _ADM_SKPRT_BROWSEOWNITEMS, + 'categorydelete' => _ADM_SKPRT_CATEGORYDELETE, + 'categoryedit' => _ADM_SKPRT_CATEGORYEDIT, + 'commentdelete' => _ADM_SKPRT_COMMENTDELETE, + 'commentedit' => _ADM_SKPRT_COMMENTEDIT, + 'createitem' => _ADM_SKPRT_CREATEITEM, + 'createnewlog' => _ADM_SKPRT_CREATENEWLOG, + 'createaccountinput' => _ADM_SKPRT_CREATEACCOUNTINPUT, + 'createaccountsuccess' => _ADM_SKPRT_CREATEACCOUNTSUCCESS, + 'createaccountdisable' => _ADM_SKPRT_CREATEACCOUNTDISALLOWED, + 'deleteblog' => _ADM_SKPRT_DELETEBLOG, + 'editmembersettings' => _ADM_SKPRT_EDITMEMBERSETTINGS, + 'forgotpassword' => _ADM_SKPRT_FORGOTPASSWORD, + 'itemcommentlist' => _ADM_SKPRT_ITEMCOMMENTLIST, + 'itemdelete' => _ADM_SKPRT_ITEMDELETE, + 'itemedit' => _ADM_SKPRT_ITEMEDIT, + 'itemlist' => _ADM_SKPRT_ITEMLIST, + 'itemmove' => _ADM_SKPRT_ITEMMOVE, + 'manage' => _ADM_SKPRT_MANAGE, + 'manageteam' => _ADM_SKPRT_MANAGETEAM, + 'memberdelete' => _ADM_SKPRT_MEMBERDELETE, + 'overview' => _ADM_SKPRT_OVERVIEW, + 'pagefoot' => _ADM_SKPRT_PAGEFOOT, + 'pagehead' => _ADM_SKPRT_PAGEHEAD, + 'plugindelete' => _ADM_SKPRT_PLUGINDELETE, + 'pluginhelp' => _ADM_SKPRT_PLUGINHELP, + 'pluginlist' => _ADM_SKPRT_PLUGINLIST, + 'pluginoptions' => _ADM_SKPRT_PLUGINOPTIONS, + 'settingsedit' => _ADM_SKPRT_SETTINGSEDIT, + 'showlogin' => _ADM_SKPRT_SHOWLOGIN, + 'skindelete' => _ADM_SKPRT_SKINDELETE, + 'skinedit' => _ADM_SKPRT_SKINEDIT, + 'skinedittype' => _ADM_SKPRT_SKINEDITTYPE, + 'skiniedoimport' => _ADM_SKPRT_SKINIEDOIMPORT, + 'skinieimport' => _ADM_SKPRT_SKINIEIMPORT, + 'skinieoverview' => _ADM_SKPRT_SKINIEOVERVIEW, + 'skinoverview' => _ADM_SKPRT_SKINOVERVIEW, + 'skinremovetype' => _ADM_SKPRT_SKINREMOVETYPE, + 'systemoverview' => _ADM_SKPRT_SYSTEMOVERVIEW, + 'teamdelete' => _ADM_SKPRT_TEAMDELETE, + 'templatedelete' => _ADM_SKPRT_TEMPLATEDELETE, + 'templateedit' => _ADM_SKPRT_TEMPLATEEDIT, + 'templateoverview' => _ADM_SKPRT_TEMPLATEOVERVIEW, + 'usermanagement' => _ADM_SKPRT_USERMANAGEMENT + ); + + /** + * AdminActions::getNormalSkinTypes() + * + * @static + * @param void + * @return array list of friendly names for page actions + */ + static public function getNormalSkinTypes() + { + return self::$normal_skin_types; + } + + /** + * AdminActions::__construct() + * Constructor for a new Actions object + * + * @param string $type + * @return void + */ + public function __construct($type) + { + // call constructor of superclass first + parent::__construct(); + + /* alias */ + if ( $type == 'admntemplateoverview' ) + { + $this->skintype = 'admintemplateoverview'; + } + else + { + $this->skintype = $type; + } + + return; + } + + /** + * AdminActions::getAvailableActions() + * + * @param void + * @return array allowed actions for the page type + */ + public function getAvailableActions() + { + $extra_actions = array(); + + switch ( $this->skintype ) + { + case 'actionlog': + $extra_actions = array( + 'actionloglist', + ); + break; + case 'activate': + $extra_actions = array( + 'activationmessage', + 'eventformextra', + ); + break; + case 'activatesetpwd': + $extra_actions = array( + /* nothing special */ + ); + break; + case 'addnewlog': + $extra_actions = array( + 'getblogsetting', + 'blogsetting', + 'requestblogid', + ); + break; + case 'adminerrorpage': + $extra_actions = array( + /* nothing special */ + ); + break; + case 'adminskindelete': + $extra_actions = array( + 'editskintype', + ); + break; + case 'adminskinedit': + $extra_actions = array( + 'editskin', + 'normalskinlist', + 'specialskinlist', + ); + break; + case 'adminskinedittype': + $extra_actions = array( + 'editskintype', + 'skintypehelp', + 'allowedskinactions', + 'skineditallowedlist', + ); + break; + case 'adminskiniedoimport': + $extra_actions = array( + 'importskininfo', + ); + break; + case 'adminskinieimport': + $extra_actions = array( + 'importskininfo', + ); + break; + case 'adminskinieoverview': + $extra_actions = array( + 'selectlocalskinfiles', + 'skinielist', + ); + break; + case 'adminskinoverview': + $extra_actions = array( + 'skinoverview', + ); + break; + case 'adminskinremovetype': + $extra_actions = array( + 'editskintype', + ); + break; + case 'admintemplatedelete': + $extra_actions = array( + 'editadmintemplateinfo', + ); + case 'admintemplateedit': + $extra_actions = array( + 'edittemplateinfo', + ); + break; + case 'admintemplateoverview': + $extra_actions = array( + 'templateoverview', + ); + break; + case 'backupoverview': + $extra_actions = array( + /* nothing special */ + ); + break; + case 'backuprestore': + $extra_actions = array( + /* nothing special */ + ); + break; + case 'banlist': + $extra_actions = array( + 'adminbloglink', + 'adminbanlist', + 'requestblogid', + ); + break; + case 'banlistdelete': + $extra_actions = array( + 'requestiprange', + 'requestblogid', + ); + break; + case 'banlistdeleteconfirm': + $extra_actions = array( + 'banlistdeletedlist', + 'requestblogid', + ); + break; + case 'banlistnew': + $extra_actions = array( + 'iprangeinput', + 'requestblogid', + 'blogsetting', + ); + break; + case 'batchcategory': + $extra_actions = array( + 'adminbatchaction', + 'adminbatchlist', + ); + break; + case 'batchcomment': + $extra_actions = array( + 'adminbatchaction', + 'adminbatchlist', + ); + break; + case 'batchdelete': + $extra_actions = array( + 'batchdeletetype', + 'batchdeletelist', + ); + break; + case 'batchitem': + $extra_actions = array( + 'adminbatchaction', + 'adminbatchlist', + ); + break; + case 'batchmember': + $extra_actions = array( + 'adminbatchaction', + 'adminbatchlist', + ); + break; + case 'batchmove': + $extra_actions = array( + 'batchmovetitle', + 'batchmovetype', + 'batchmovelist', + 'movedistselect', + 'batchmovebtn', + ); + break; + case 'batchmovecat': + $extra_actions = array( + 'batchmovetitle', + 'batchmovetype', + 'batchmovelist', + 'movedistselect', + 'batchmovebtn', + ); + break; + case 'batchteam': + $extra_actions = array( + 'requestblogid', + 'adminbatchaction', + 'adminbatchlist', + ); + break; + case 'blogcommentlist': + $extra_actions = array( + 'adminbloglink', + 'commentnavlist', + 'adminbatchlist', + ); + break; + case 'blogsettings': + $extra_actions = array( + 'adminbloglink', + 'blogcatlist', + 'blognotifysetting', + 'blogsetting', + 'blogsettingyesno', + 'blogteammembers', + 'blogtime', + 'defcatselect', + 'defskinselect', + 'pluginextras', + 'pluginoptions', + 'requestblogid', + ); + break; + case 'bookmarklet': + $extra_actions = array( + 'bookmarkletadmin', + ); + break; + case 'browseowncomments': + $extra_actions = array( + 'commentnavlist', + ); + break; + case 'browseownitems': + $extra_actions = array( + 'itemnavlist', + ); + break; + case 'categorydelete': + $extra_actions = array( + 'categorysetting', + 'requestblogid', + ); + break; + case 'categoryedit': + $extra_actions = array( + 'requestblogid', + 'categorysetting', + 'editdesturl', + 'pluginoptions' + ); + break; + case 'commentdelete': + $extra_actions = array( + 'deletecomment', + ); + break; + case 'commentedit': + $extra_actions = array( + 'editcomment', + ); + break; + case 'createaccountinput': + $extra_actions = array( + 'contents', + 'pluginextras', + 'eventformextra', + ); + break; + case 'createaccountsuccess': + $extra_actions = array( + 'contents', + ); + break; + case 'createaccountdisable': + $extra_actions = array( + /* nothing special */ + ); + break; + case 'createitem': + $extra_actions = array( + 'adminbloglink', + 'blogid', + 'contents', + 'categories', + 'currenttime', + 'init', + 'pluginoptions', + 'pluginextras' + ); + break; + case 'createnewlog': + $extra_actions = array( + 'defskinselect', + 'blogtime', + ); + break; + case 'deleteblog': + $extra_actions = array( + 'blogsetting', + 'requestblogid', + ); + break; + case 'editmembersettings': + $extra_actions = array( + 'defskinselect', + 'editmember', + 'localeselectoptions', + 'pluginoptions', + 'defadminskinselect', + 'defbookmarkletselect', + 'pluginextras', + ); + break; + case 'forgotpassword': + $extra_actions = array( + /* nothing special */ + ); + break; + case 'itemcommentlist': + $extra_actions = array( + 'requestblogid', + 'commentnavlist', + ); + break; + case 'itemdelete': + $extra_actions = array( + 'deleteitemtitle', + 'deleteitembody', + 'deleteitemid', + ); + break; + case 'itemedit': + $extra_actions = array( + 'init', + 'contents', + 'checkedonval', + 'categories', + 'currenttime', + 'itemtime', + 'pluginoptions', + 'pluginextras' + ); + break; + case 'itemlist': + $extra_actions = array( + 'adminbloglink', + 'ilistaddnew', + 'itemnavlist', + ); + break; + case 'itemmove': + $extra_actions = array( + 'moveitemid', + 'movedistselect', + ); + break; + case 'manage': + $extra_actions = array( + /* nothing special */ + ); + break; + case 'manageteam': + $extra_actions = array( + 'requestblogid', + 'blogsetting', + 'blogteamlist', + 'newmemberselect', + 'inputyesno', + ); + break; + case 'memberdelete': + $extra_actions = array( + 'editmember', + ); + break; + case 'overview': + $extra_actions = array( + 'yrbloglist', + ); + break; + case 'plugindelete': + $extra_actions = array( + 'editpluginfo', + ); + break; + case 'pluginhelp': + $extra_actions = array( + 'helpplugname', + 'pluginhelp', + ); + break; + case 'pluginlist': + $extra_actions = array( + 'pluginlistlist', + 'newpluginlist', + ); + break; + case 'pluginoptions': + $extra_actions = array( + 'editpluginfo', + 'editplugoptionslist', + ); + break; + case 'settingsedit': + $extra_actions = array( + 'defblogselect', + 'defskinselect', + 'configsettingsedit', + 'configsettingsyesno', + 'outputspecialdirs', + 'jstoolbaroptions', + 'localeselectoptions', + 'mediadirwarning', + 'pluginextras', + 'defadminskinselect', + 'defbookmarkletselect', + ); + break; + case 'showlogin': + $extra_actions = array( + 'passrequestvars', + ); + break; + case 'skindelete': + $extra_actions = array( + 'editskintype', + ); + break; + case 'skinedit': + $extra_actions = array( + 'editskin', + 'normalskinlist', + 'specialskinlist' + ); + break; + case 'skinedittype': + $extra_actions = array( + 'editskintype', + 'skintypehelp', + 'allowedskinactions', + 'skineditallowedlist' + ); + break; + case 'skiniedoimport': + $extra_actions = array( + 'importskininfo', + ); + break; + case 'skinieimport': + $extra_actions = array( + 'importskininfo', + ); + break; + case 'skinieoverview': + $extra_actions = array( + 'selectlocalskinfiles', + 'skinielist', + ); + break; + case 'skinoverview': + $extra_actions = array( + 'skinoverview', + ); + break; + case 'skinremovetype': + $extra_actions = array( + 'editskintype', + ); + break; + case 'systemoverview': + $extra_actions = array( + 'systemsettings', + ); + break; + case 'teamdelete': + $extra_actions = array( + 'editmember', + 'blogsetting', + 'requestblogid', + ); + break; + case 'templatedelete': + $extra_actions = array( + 'edittemplateinfo', + ); + break; + case 'templateedit': + $extra_actions = array( + 'edittemplateinfo', + ); + break; + case 'templateoverview': + $extra_actions = array( + 'templateoverview', + ); + break; + case 'usermanagement': + $extra_actions = array( + 'editmemberlist', + 'inputyesno', + ); + break; + case 'importAdmin': + $extra_actions = array( + 'charset', + 'adminurl', + 'extrahead', + 'member', + 'versioncheckurl', + 'version', + 'codename', + 'newestcompare', + 'selectlocalskinfiles', + 'skinielist', + ); + break; + default: + break; + } + + $defined_actions = array_merge(self::$default_actions, $extra_actions); + + return array_merge($defined_actions, parent::getAvailableActions()); + } + + /** + * AdminActions::parse_actionloglist() + * Parse skinvar actionloglist + * + * @param string $template_name name of template to use + * @return void + */ + public function parse_actionloglist($template_name = '') + { + $query = "SELECT * FROM %s ORDER BY timestamp DESC;"; + $query = sprintf($query, sql_table('actionlog')); + + $resource = DB::getResult($query); + if ( $resource->rowCount() > 0 ) + { + $template['content'] = 'actionlist'; + $action_list = showlist($resource, 'table', $template, $template_name); + $this->parser->parse($action_list); + } + else + { + /* TODO: nothing to be shown */ + } + return; + } + + /** + * AdminActions::parse_activationmessage() + * Parse skinvar activationmessage + * + * @param string $type type of message + * @param string $template_name name of template to use + * @return void + */ + public function parse_activationmessage($type, $template_name = '') + { + global $CONF, $manager; + + $template = array(); + + if ( !empty($template_name)) + { + $template =& $manager->getTemplate($template_name); + } + + $key = postVar('ackey'); + if ( !$key ) + { + Admin::error(_ERROR_ACTIVATE); + } + + $info = MEMBER::getActivationInfo($key); + if ( !$info ) + { + Admin::error(_ERROR_ACTIVATE); + } + + $mem =& $manager->getMember($info->vmember); + if ( !$mem ) + { + Admin::error(_ERROR_ACTIVATE); + } + switch ( $info->vtype ) + { + case 'forgot': + if ( array_key_exists('ACTIVATE_FORGOT_TITLE', $template) && !empty($template['ACTIVATE_FORGOT_TITLE']) ) + { + $title = $template['ACTIVATE_FORGOT_TITLE']; + } + else + { + $title = _ACTIVATE_FORGOT_TITLE; + } + if ( array_key_exists('ACTIVATE_FORGOT_TEXT', $template) && !empty($template['ACTIVATE_FORGOT_TEXT']) ) + { + $text = $template['ACTIVATE_FORGOT_TEXT']; + } + else + { + $text = _ACTIVATE_FORGOT_TEXT; + } + break; + case 'register': + if ( array_key_exists('ACTIVATE_REGISTER_TITLE', $template) && !empty($template['ACTIVATE_REGISTER_TITLE']) ) + { + $title = $template['ACTIVATE_REGISTER_TITLE']; + } + else + { + $title = _ACTIVATE_REGISTER_TITLE; + } + if ( array_key_exists('ACTIVATE_REGISTER_TEXT', $template) && !empty($template['ACTIVATE_REGISTER_TEXT']) ) + { + $text = $template['ACTIVATE_REGISTER_TEXT']; + } + else + { + $text = _ACTIVATE_REGISTER_TEXT; + } + break; + case 'addresschange': + if ( array_key_exists('ACTIVATE_CHANGE_TITLE', $template) && !empty($template['ACTIVATE_CHANGE_TITLE']) ) + { + $title = $template['ACTIVATE_CHANGE_TITLE']; + } + else + { + $title = _ACTIVATE_CHANGE_TITLE; + } + if (array_key_exists('ACTIVATE_CHANGE_TEXT', $template) && !empty($template['ACTIVATE_CHANGE_TEXT'])) + { + $text = $template['ACTIVATE_CHANGE_TEXT']; + } + else + { + $text = _ACTIVATE_CHANGE_TEXT; + } + break; + } + $aVars = array( + 'memberName' => Entity::hsc($mem->getDisplayName()), + 'realName' => Entity::hsc($mem->getRealName()), + ); + switch ( $type ) + { + case 'title': + echo Template::fill($title, $aVars); + break; + case 'text': + echo Template::fill($text, $aVars); + break; + case 'ackey': + echo Entity::hsc($key); + break; + } + return; + } + + /** + * AdminActions::parse_addtickettourl() + * Parse skinvar addtickettourl + * + * @param string $url URI for ticket + * @return void + */ + public function parse_addtickettourl($url) + { + global $manager; + $url = $manager->addTicketToUrl($url); + echo Entity::hsc($url); + return; + } + + /** + * AdminActions::parse_adminbanlist() + * Parse skinvar adminbanlist + * + * @param string $template_name name of template to use + * @return void + */ + public function parse_adminbanlist($template_name = '') + { + $blogid = intRequestVar('blogid'); + + $query = "SELECT * FROM %s WHERE blogid=%d ORDER BY iprange;"; + $query = sprintf($query, sql_table('ban'), (integer) $blogid); + + $resource = DB::getResult($query); + if ( $resource->rowCount() > 0 ) + { + $template['content'] = 'banlist'; + $ban_list = showlist($resource, 'table', $template, $template_name); + $this->parser-parse($ban_list); + } + else + { + echo _BAN_NONE; + } + return; + } + + /** + * AdminActions::parse_adminbatchaction() + * Parse skinvar adminbatchaction + * + * @param void + * @return void + */ + public function parse_adminbatchaction() + { + echo Entity::hsc(requestVar('batchaction')); + return; + } + + /** + * AdminActions::parse_adminbatchlist() + * Parse skinvar adminbatchlist + * + * @param string $template_name name of template to use + * @return void + */ + public function parse_adminbatchlist($template_name = '') + { + global $manager; + $templates = array(); + + if ( !empty($template_name) ) + { + $templates =& $manager->getTemplate($template_name); + } + + if ( !array_key_exists('ADMIN_BATCHLIST', $templates) || empty($templates['ADMIN_BATCHLIST']) ) + { + $template = '
  • <%text(_BATCH_EXECUTING)%> ' + . '<%adminbatchaction%> ' + . '<%batchlisttype%> ' + . '<%batchid%>... ' + . '<%batchlistmsg%>' + . "
  • \n"; + } + else + { + $template = $templates['ADMIN_BATCHLIST']; + } + + $selected = requestIntArray('batch'); + $action = requestVar('batchaction'); + + switch ( $this->skintype ) + { + case 'batchitem': + $batchlisttype = _BATCH_ONITEM; + $deleteaction = 'deleteOneItem'; + $moveaction = 'moveOneItem'; + $destid = intRequestVar('destcatid'); + break; + case 'batchcomment': + $batchlisttype = _BATCH_ONCOMMENT; + $deleteaction = 'deleteOneComment'; + break; + case 'batchmember': + $batchlisttype = _BATCH_ONMEMBER; + $deleteaction = 'deleteOneMember'; + $setadminsql = sql_table('member') . ' SET madmin = 1 WHERE mnumber = '; + $unsetchksql = 'SELECT * FROM ' . sql_table('member') . ' WHERE madmin = 1 AND mcanlogin = 1'; + $unsetupsql = sql_table('member') . ' SET madmin = 0 WHERE mnumber = '; + $unseterrmsg = _ERROR_ATLEASTONEADMIN; + break; + case 'batchteam': + $blogid = intRequestVar('blogid'); + $batchlisttype = _BATCH_ONTEAM; + $deleteaction = 'deleteOneTeamMember'; + $setadminsql = sql_table('team') . ' SET tadmin = 1 WHERE tblog = ' . $blogid . ' AND tmember = '; + $unsetchksql = 'SELECT * FROM ' . sql_table('team') . ' WHERE tadmin = 1 AND tblog = ' . $blogid; + $unseterrmsg = _ERROR_ATLEASTONEBLOGADMIN; + $unsetupsql = sql_table('team') . ' SET tadmin = 0 WHERE tblog = ' . $blogid . ' AND tmember = '; + break; + case 'batchcategory': + $batchlisttype = _BATCH_ONCATEGORY; + $deleteaction = 'deleteOneCategory'; + $moveaction = 'moveOneCategory'; + $destid = intRequestVar('destblogid'); + break; + } + + // walk over all selectedids and perform action + foreach ( $selected as $selectedid ) + { + $error = ''; + $selectedid = intval($selectedid); + switch ( $action ) + { + case 'delete': + if ( $this->skintype != 'batchteam' ) + { + $params = array($selectedid); + $error = call_user_func_array(array('Admin', $deleteaction), $params); + } + else + { + $error = Admin::deleteOneTeamMember($blogid, $selectedid); + } + break; + case 'move': + $params = array($selectedid, $destid); + $error = call_user_func_array(array('Admin', $moveaction), $params); + break; + case 'setadmin': + // always succeeds + DB::execute("UPDATE {$setadminsql} {$selectedid};"); + $error = ''; + break; + case 'unsetadmin': + // there should always remain at least one super-admin + $r = DB::getResult($unsetchksql); + if ( $r->rowCount() < 2 ) + { + $error = $unseterrmsg; + } + else + { + DB::execute("UPDATE {$unsetupsql} {$selectedid};"); + } + break; + default: + $error = _BATCH_UNKNOWN . Entity::hsc($action); + } + + $data = array( + 'batchid' => $selectedid, + 'batchlisttype' => Entity::hsc($batchlisttype), + 'adminbatchaction' => Entity::hsc($action), + 'batchlistmsg' => $error ? $error : _BATCH_SUCCESS, + ); + + $this->parser->parse(Template::fill($template, $data)); + echo '
    '; + } + return; + } + + /** + * AdminActions::parse_adminbloglink() + * Parse skinvar adminbloglink + * + * @param string $template_name name of template to use + * @return void + */ + public function parse_adminbloglink($template_name = '') + { + global $manager; + $blogid = intRequestVar('blogid'); + $blog =& $manager->getBlog($blogid); + $templates = array(); + + if ( !empty($template_name) ) + { + $templates =& $manager->getTemplate($template_name); + } + + if ( !array_key_exists('ADMIN_BLOGLINK', $templates) || empty($templates['ADMIN_BLOGLINK']) ) + { + $template = '<%blogname%>'; + } + else + { + $template = $templates['ADMIN_BLOGLINK']; + } + + $data = array( + 'url' => Entity::hsc($blog->getURL()), + 'adminbloglinktitle' => _BLOGLIST_TT_VISIT, + 'blogname' => Entity::hsc($blog->getName()) + ); + + echo Template::fill($template, $data); + return; + } + + /** + * AdminActions::parse_adminerrormesg() + * Parse skinvar adminerrormesg + * + * @param void + * @return void + */ + public function parse_adminerrormesg() + { + global $CONF; + $message = ''; + + if ( requestVar('errormessage') ) + { + $message = requestVar('errormessage'); + } + elseif ( cookieVar($CONF['CookiePrefix'] . 'errormessage') ) + { + $message = cookieVar($CONF['CookiePrefix'] . 'errormessage'); + } + elseif ( Admin::sessionVar($CONF['CookiePrefix'] . 'errormessage') ) + { + $message = Admin::sessionVar($CONF['CookiePrefix'] . 'errormessage'); + } + echo Entity::hsc($message); + return; + } + + /** + * AdminActions::parse_allowedskinactions() + * Parse skinvar allowedskinactions + * + * @param void + * @return void + */ + public function parse_allowedskinactions() + { + global $manager; + + $type = strtolower(trim(requestVar('type'))); + $skinid = intRequestVar('skinid'); + + if ( !in_array($this->skintype, Admin::$adminskin_actions) ) + { + $skin =& $manager->getSkin($skinid); + $tag = 'skinvar'; + } + else + { + $skin =& $manager->getSkin($skinid, 'AdminActions'); + $tag = 'adminskinvar'; + } + + $actions = $skin->getAllowedActionsForType($type); + sort($actions); + + while ( $current = array_shift($actions) ) + { + echo helplink("{$tag}-{$current}") . "$current\n"; + + if ( count($actions) != 0 ) + { + echo ", "; + } + } + return; + } + + /** + * AdminActions::parse_banlistdeletedlist() + * Parse skinvar banlistdeletedlist + * + * @param string $template_name name of template to use + * @return void + */ + public function parse_banlistdeletedlist($template_name = '') + { + global $manager; + + $templates = array(); + if ( $template_name ) + { + $templates =& $manager->getTemplate($template_name); + } + + if ( !array_key_exists('BANLIST_DELETED_LIST', $templates) || empty($templates['BANLIST_DELETED_LIST']) ) + { + $template = "
  • <%blogname%>
  • \n"; + } + else + { + $template = $templates['BANLIST_DELETED_LIST']; + } + + $deleted = requestArray('delblogs'); + foreach ( $deleted as $delblog ) + { + $blog =& $manager->getBlog($delblog); + $data = array( + 'blogname' => Entity::hsc($blog->getName()) + ); + echo Template::fill($template, $data); + } + + return; + } + + /** + * AdminActions::parse_batchdeletelist() + * Parse skinvar batchdeletelist + * + * @param void + * @return void + */ + public function parse_batchdeletelist() + { + $selected = requestIntArray('batch'); + $index = 0; + + foreach ( $selected as $select ) + { + echo '\n"; + } + // add hidden vars for team & comment + if ( requestVar('action') == 'batchteam' ) + { + echo '\n"; + } + if ( requestVar('action') == 'batchcomment' ) + { + echo '\n"; + } + return; + } + + /** + * AdminActions::parse_defadminskinselect() + * Parse skinvar defadminskinselect + * + * @param string $template_name name of template to use + * @return void + */ + public function parse_defadminskinselect($template_name) + { + global $CONF, $action, $manager; + + if ( $action == 'editmembersettings' ) + { + global $member; + $default = $member->adminskin; + } + elseif ( $action == 'memberedit' ) + { + $mem = $manager->getMember(intRequestVar('memberid')); + $default = $mem->adminskin; + } + else + { + $default = $CONF['AdminSkin']; + } + + $query = "SELECT sdname as text, sdnumber as value FROM %s WHERE sdname LIKE 'admin/%%'"; + $query = sprintf($query, sql_table('skin_desc')); + $template = array( + 'name' => 'adminskin', + 'tabindex' => 10080, + 'selected' => $default + ); + + if ( $this->skintype != 'settingsedit' ) + { + $template['extra'] = Entity::hsc(_MEMBERS_USESITELANG); + } + + $skin_select = showlist($query, 'select', $template, $template_name); + $this->parser->parse($skin_select); + return; + } + + /** + * AdminActions::parse_defbookmarkletselect() + * Parse skinvar defbookmarkletselect + * + * @param string $template_name name of template to use + * @return void + */ + public function parse_defbookmarkletselect($template_name) + { + global $CONF, $action, $manager; + + if ( $action == 'editmembersettings' ) + { + global $member; + $default = $member->bookmarklet; + } + elseif ( $action == 'memberedit' ) + { + $mem = $manager->getMember(intRequestVar('memberid')); + $default = $mem->bookmarklet; + } + else + { + $default = $CONF['BookmarkletSkin']; + } + + $query = "SELECT sdname as text, sdnumber as value FROM %s WHERE sdname LIKE 'admin/%%'"; + $query = sprintf($query, sql_table('skin_desc')); + + $template = array( + 'name' => 'bookmarklet', + 'tabindex' => 10085, + 'selected' => $default + ); + + if ( $this->skintype != 'settingsedit' ) + { + $template['extra'] = Entity::hsc(_MEMBERS_USESITELANG); + } + + $bookmarklet_select = showlist($query, 'select', $template, $template_name); + $this->parser->parse($bookmarklet_select); + return; + } + + /** + * AdminActions::parse_batchdeletetype() + * Parse skinvar batchdeletetype + * + * @param void + * @return void + */ + public function parse_batchdeletetype() + { + echo Entity::hsc(requestVar('action')); + return; + } + + /** + * AdminActions::parse_batchmovebtn() + * Parse skinvar batchmovebtn + * + * @param void + * @return void + */ + public function parse_batchmovebtn() + { + $actionType = requestVar('action'); + switch ( $actionType ) + { + case 'batchitem': + echo _MOVE_BTN; + break; + case 'batchcategory': + echo _MOVECAT_BTN; + break; + } + return; + } + + /** + * AdminActions::parse_batchmovelist() + * Parse skinvar batchmovelist + * + * @param void + * @param void + */ + public function parse_batchmovelist() + { + $selected = requestIntArray('batch'); + $count = 0; + foreach ( $selected as $select ) + { + echo '\n"; + $count++; + } + return; + } + + /** + * AdminActions::parse_batchmovetitle() + * Parse skinvar batchmovetitle + * + * @param void + * @return void + */ + public function parse_batchmovetitle() + { + $actionType = requestVar('action'); + switch ( $actionType ) + { + case 'batchitem': + echo _MOVE_TITLE; + break; + case 'batchcategory': + echo _MOVECAT_TITLE; + break; + } + return; + } + + /** + * AdminActions::parse_batchmovetype() + * Parse skinvar batchmovetype + * + * @param void + * @return void + */ + public function parse_batchmovetype() + { + echo Entity::hsc(requestVar('action')); + return; + } + + /** + * AdminActions::parse_blogcatlist() + * Parse skinvar blogcatlist + * + * @param void + * @return void + */ + public function parse_blogcatlist($template_name = '') + { + global $manager; + $blogid = intRequestVar('blogid'); + $query = "SELECT * FROM %s WHERE cblog = %d ORDER BY cname;"; + $query = sprintf($query, sql_table('category'), (integer) $blogid); + + $resource = DB::getResult($query); + if ( $resource->rowCount() > 0 ) + { + $template['content'] = 'categorylist'; + $template['tabindex'] = 200; + $category_list = listplug_batchlist('category', $resource, 'table', $template, $template_name); + $this->parser->parse($category_list); + } + else + { + /* TODO: nothing to be shown */ + } + $resource->closeCursor(); + + return; + } + + /** + * AdminActions::parse_blogid() + * Parse skinvar blogid + * + * @param void + * @return void + */ + public function parse_blogid() + { + echo intRequestVar('blogid'); + return; + } + + /** + * AdminActions::parse_blognotifysetting() + * Parse skinvar blognotifysetting + * + * @param void + * @return void + */ + public function parse_blognotifysetting($type) + { + global $manager; + $blogid = intRequestVar('blogid'); + $blog =& $manager->getBlog($blogid); + + switch ( $type ) + { + case 'comment': + if ( !$blog->notifyOnComment() ) + { + return; + } + break; + case 'vote': + if ( !$blog->notifyOnVote() ) + { + return; + } + break; + case 'newitem': + if ( !$blog->notifyOnNewItem() ) + { + return; + } + break; + } + echo ' checked="checked"'; + return; + } + + /** + * AdminActions::parse_blogsetting() + * Parse skinvar blogsetting + * + * @param string $which name of weblog setting + * @return void + */ + public function parse_blogsetting($which) + { + echo $this->parse_getblogsetting($which); + return; + } + + /** + * AdminActions::parse_blogsettingyesno() + * Parse skinvar blogsettingyesno + * + * @param string $type type of weblog setting + * @param string $template_name name of template to use + * @return void + */ + public function parse_blogsettingyesno($type, $template_name = '') + { + global $manager; + + $blogid = intRequestVar('blogid'); + $blog =& $manager->getBlog($blogid); + + switch ( $type ) + { + case 'convertbreaks': + $checkedval = $blog->convertBreaks(); + $tabindex = 55; + break; + case 'allowpastposting': + $checkedval = $blog->allowPastPosting(); + $tabindex = 57; + break; + case 'comments': + $checkedval = $blog->commentsEnabled(); + $tabindex = 60; + break; + case 'public': + $checkedval = $blog->isPublic(); + $tabindex = 70; + break; + case 'reqemail': + $checkedval = $blog->emailRequired(); + $tabindex = 72; + break; + case 'searchable': + $checkedval = $blog->getSearchable(); + $tabindex = 122; + break; + } + $this->parse_inputyesno($type, $checkedval, $tabindex, 1, 0, _YES, _NO, 0, $template_name); + return; + } + + /** + * AdminActions::parse_blogteamlist() + * Parse skinvar blogteamlist + * + * @param string $template_name name of template to use + * @return void + */ + public function parse_blogteamlist($template_name = '') + { + global $manager; + $blogid = intRequestVar('blogid'); + $query = "SELECT tblog, tmember, mname, mrealname, memail, tadmin " + . "FROM %s, %s " + . "WHERE tmember=mnumber AND tblog= %d"; + $query = sprintf($query, sql_table('member'), sql_table('team'), (integer) $blogid); + + $resource = DB::getResult($query); + if ( $resource->rowCount() > 0 ) + { + $template['content'] = 'teamlist'; + $template['tabindex'] = 10; + + $team_list = listplug_batchlist('team', $resource, 'table', $template, $template_name); + $this->parser->parse($team_list); + } + else + { + echo _LISTS_NOMORE; + } + $resource->closeCursor(); + + return; + } + + /** + * AdminActions::parse_blogteammembers() + * Parse skinvar blogteammembers + * + * @param void + * @return void + */ + public function parse_blogteammembers() + { + $blogid = intRequestVar('blogid'); + $query = "SELECT mname, mrealname " + . "FROM %s, %s " + . "WHERE mnumber=tmember AND tblog=%d;"; + $query = sprintf($query, sql_table('member'), sql_table('team'), (integer) $blogid); + $res = DB::getResult($query); + $memberNames = array(); + foreach ( $res as $row ) + { + $memberNames[] = Entity::hsc($row['mname']) . ' (' . Entity::hsc($row['mrealname']). ')'; + } + echo implode(',', $memberNames); + } + + /** + * AdminActions::parse_blogtime() + * Parse skinvar blogtime + * + * @param string $type type of time + * @param string $format format for time expression + * @param integer $offset offset of time + * @return void + */ + public function parse_blogtime($type, $format = '%H:%M', $offset = 0) + { + global $manager; + + if ( $type != 'blogtime' ) + { + /* return server time */ + $timestamp = time() + $offset; + } + else + { + $bid = intRequestVar('blogid'); + $b =& $manager->getBlog($bid); + $timestamp = $b->getCorrectTime() + $offset; + } + + echo i18n::formatted_datetime($format, $timestamp); + return; + } + + /** + * AdminActions::parse_bookmarkletadmin() + * Parse skinvar bookmarkletadmin + * + * @param void + * @return void + */ + public function parse_bookmarkletadmin() + { + global $manager; + + $blogid = intRequestVar('blogid'); + + echo Entity::hsc('javascript:' . getBookmarklet($blogid)); + return; + } + + /** + * AdminActions::parse_categories() + * Parse skinvar categories + * + * create category dropdown box + * + * @param string $type name of setting for category + * @return void + */ + public function parse_categories($startidx = 0) + { + global $manager; + + if ( !array_key_exists('catid', Admin::$contents) || empty(Admin::$contents['catid']) ) + { + $catid = Admin::$blog->getDefaultCategory(); + } + else + { + $catid = Admin::$contents['catid']; + } + + $this->selectBlog('catid', 'category', $catid, $startidx, 1, Admin::$blog->getID()); + + return; + } + + /** + * AdminActions::parse_categorysetting() + * Parse skinvar categorysetting + * + * @param string $type type in category setting + * @return void + */ + public function parse_categorysetting($type) + { + $catid = intRequestVar('catid'); + if ( $type == 'id' ) + { + echo $catid; + return; + } + $blogid = intRequestVar('blogid'); + $query = "SELECT * FROM %s WHERE cblog = %d AND catid = %d;"; + $query = sprintf($query, sql_table('category'), (integer) $blogid, (integer) $catid); + $row = DB::getRow($query); + + if ( $type != 'name' ) + { + echo Entity::hsc($row['cdesc']); + } + else + { + echo Entity::hsc($row['cname']); + } + + return; + } + + /** + * AdminActions::parse_codename() + * Parse templatevar codename + * + * @param $value + * @param $name + * + */ + public function parse_checkedonval($value, $name) + { + global $manager; + + $item = false; + $itemid = intRequestVar('itemid'); + $item =& $manager->getItem($itemid, 1, 1); + + if ( $item ) + { + $blog =& $manager->getBlog($item['blogid']); + + if ( $blog->convertBreaks() && requestVar('action') == 'itemedit' ) + { + $item['body'] = removeBreaks($item['body']); + $item['more'] = removeBreaks($item['more']); + } + } + + $contents = array(); + if ( requestVar('action') == 'itemedit' ) + { + $contents = $item; + } + if ( !isset($contents[$name]) ) + { + $contents[$name] = ''; + } + if ($contents[$name] == $value) + { + echo 'checked="checked"'; + } + return; + } + + /** + * AdminActions::parse_codename() + * Parse templatevar codename + * + * @param void + * @return void + * + * TODO: is this need??? + */ + public function parse_codename() + { + global $nucleus; + echo $nucleus['codename']; + return; + } + + /** + * AdminActions::parse_commentnavlist() + * Parse skinvar commentnavlist + * + * @param string $template_name name of template to use + * @return void + */ + public function parse_commentnavlist($template_name = '') + { + global $CONF, $manager, $member; + + // start index + if ( postVar('start') ) + { + $start = intPostVar('start'); + } + else + { + $start = 0; + } + + // amount of items to show + if ( postVar('amount') ) + { + $amount = intPostVar('amount'); + } + else + { + $amount = (integer) $CONF['DefaultListSize']; + if ( $amount < 1 ) + { + $amount = 10; + } + } + $query = 'SELECT cbody, cuser, cmail, cemail, mname, ctime, chost, cnumber, cip, citem ' + . 'FROM %s ' + . 'LEFT OUTER JOIN %s ON mnumber=cmember ' + . 'WHERE '; + $query = sprintf($query, sql_table('comment'), sql_table('member')); + + if ( $this->skintype == 'itemcommentlist' ) + { + $itemid = intRequestVar('itemid'); + $query .= " citem={$itemid}"; + $template['canAddBan'] = $member->blogAdminRights(intRequestVar('blogid')); + $bid = 0; + $nonComments = _NOCOMMENTS; + } + elseif ( $this->skintype == 'browseowncomments' ) + { + $itemid = 0; + $query .= ' cmember=' . $member->getID(); + $template['canAddBan'] = 0; + $bid = 0; + $nonComments = _NOCOMMENTS_YOUR; + } + elseif ( $this->skintype == 'blogcommentlist' ) + { + $itemid = 0; + $query .= ' cblog=' . intRequestVar('blogid'); + $template['canAddBan'] = $member->blogAdminRights(intRequestVar('blogid')); + $bid = intRequestVar('blogid'); + $nonComments = _NOCOMMENTS_BLOG; + } + + $search = postVar('search'); + if ( !empty($search) ) + { + $query .= ' and cbody LIKE ' . DB::quoteValue('%'.$search.'%'); + } + + $query .= " ORDER BY ctime ASC LIMIT {$start},{$amount}"; + + $resource = DB::getResult($query); + if ( $resource->rowCount() > 0 ) + { + $template['action'] = $this->skintype; + $template['start'] = $start; + $template['amount'] = $amount; + $template['minamount'] = 0; + $template['maxamount'] = 1000; + $template['blogid'] = $bid; + $template['search'] = $search; + $template['itemid'] = $itemid; + + $template['content'] = 'commentlist'; + + $navlist = listplug_navlist('comment', $resource, 'table', $template, $template_name); + $this->parser->parse($navlist); + } + else + { + /* TODO: nothing to be shown */ + } + $resource->closeCursor(); + + return; + } + + /** + * AdminActions::parse_configsettingsedit() + * Parse skinvar configsettingsedit + * + * @param string $type type of global configuration + * @return void + */ + public function parse_configsettingsedit($type) + { + global $CONF; + switch ( $type ) + { + case 'DefaultListSize': + if ( !array_key_exists('DefaultListSize', $CONF) ) + { + $query = "INSERT INTO %s VALUES (DefaultListSize, 10);"; + $query = sprintf($query, sql_table('config')); + DB::execute($query); + $CONF['DefaultListSize'] = 10; + } + elseif ( intval($CONF['DefaultListSize']) < 1 ) + { + $CONF['DefaultListSize'] = 10; + } + echo intval($CONF['DefaultListSize']); + break; + case 'SessionCookie': + $value = $CONF['SessionCookie']; + $txt1 = _SETTINGS_COOKIESESSION; + $txt2 = _SETTINGS_COOKIEMONTH; + $this->parse_inputyesno('SessionCookie', $value, 10190, 1, 0, $txt1, $txt2); + break; + case 'URLMode': + $value = $CONF['URLMode']; + $txt1 = _SETTINGS_URLMODE_NORMAL; + $txt2 = _SETTINGS_URLMODE_PATHINFO; + $this->parse_inputyesno('URLMode', $value, 10077, 'normal', 'pathinfo', $txt1, $txt2); + break; + default: + if ( array_key_exists($type, $CONF) && is_string($CONF[$type]) ) + { + echo Entity::hsc($CONF[$type]); + } + break; + } + return; + } + + /** + * AdminActions::parse_configsettingsyesno() + * Parse skinvar configsettingsyesno + * + * @param string $type type of global setting + * @param integer $tabindex tabindex attribute of input element + * @return void + */ + public function parse_configsettingsyesno($type, $tabindex) + { + global $CONF; + if ( array_key_exists($type, $CONF) ) + { + $this->parse_inputyesno($type, $CONF[$type], $tabindex); + } + return; + } + + /** + * AdminActions::parse_contents() + * Parse skinvar contents + * + * @param string $which part for item + * @return void + */ + public function parse_contents($which) + { + if ( !array_key_exists($which, Admin::$contents) ) + { + Admin::$contents[$which] = ''; + } + echo Entity::hsc(Admin::$contents[$which]); + } + + /** + * AdminActions::parse_currenttime() + * Parse skinvar currenttime + * + * @param string $what + */ + // for future items + public function parse_currenttime($what) + { + $nu = getdate(Admin::$blog->getCorrectTime()); + echo $nu[$what]; + } + + /** + * AdminActions::parse_customhelplink() + * Parse skinvar customhelplink + * + * @param string $topic name of topic + * @param string $tplName name of template + * @param string $url string as URI + * @param string $iconURL string as URI for icon + * @param string $alt alternative text for image element + * @param string $title title for anchor element + * @return void + */ + public function parse_customhelplink($topic, $tplName = '', $url = '', $iconURL = '', $alt = '', $title = '', $onclick = '') + { + $this->customHelp($topic, $url, $iconURL); + return; + } + + /** + * AdminActions::parse_date() + * Parse skinvar date + */ + public function parse_date($format = 'c') + { + global $CONF, $manager; + /* TODO: offset is based on i18n::get_current_locale()? */ + echo i18n::formatted_datetime($format, time()); + return; + } + + /** + * AdminActions::parse_normalskinlist() + * Parse skinvar defaultadminskintypes + * + * @param string $template_name name of template + * @return void + */ + public function parse_normalskinlist($template_name = '') + { + global $CONF, $manager; + + if ( !in_array($this->skintype, Admin::$adminskin_actions) ) + { + $skin =& $manager->getSkin($CONF['BaseSkin']); + /* TODO: removeaction? */ + $template['editaction'] = 'skinedittype'; + } + else + { + $skin =& $manager->getSkin($CONF['AdminSkin'], 'AdminActions'); + $template['editaction'] = 'adminskinedittype'; + /* TODO: removeaction? */ + } + + $temporary = $skin->getNormalTypes(); + $normal_skintype = array(); + foreach ( $temporary as $type => $label ) + { + $normal_skintype[] = array( + 'skintype' => $type, + 'skintypename' => $label + ); + } + + $template['tabindex'] = 10; + $template['skinid'] = intRequestVar('skinid'); + $template['skinname'] = $skin->getName(); + $skin_list = showlist($normal_skintype, 'list_normalskinlist', $template, $template_name); + $this->parser->parse($skin_list); + + return; + } + + /** + * AdminActions::parse_defblogselect() + * Parse skinvar defblogselect + * + * @param string $template_name name of template + * @return void + */ + public function parse_defblogselect($template_name = '') + { + global $CONF; + + $query = "SELECT bname as text, bnumber as value FROM %s;"; + $query = sprintf($query, sql_table('blog')); + + $template['name'] = 'DefaultBlog'; + $template['selected'] = $CONF['DefaultBlog']; + $template['tabindex'] = 10; + $blog_select = showlist($query, 'select', $template, $template_name); + $this->parser->parse($blog_select); + + return; + } + + /** + * AdminActions::parse_defcatselect() + * Parse skinvar defcatselect + * + * @param string $template_name name of template + * @return void + */ + public function parse_defcatselect($template_name = '') + { + global $manager; + + $blogid = intRequestVar('blogid'); + $blog =& $manager->getBlog($blogid); + + $query = "SELECT cname as text, catid as value FROM %s WHERE cblog=%d;"; + $query = sprintf($query, sql_table('category'), (integer) $blog->getID()); + + $template['name'] = 'defcat'; + $template['selected'] = $blog->getDefaultCategory(); + $template['tabindex'] = 110; + + $category_select = showlist($query, 'select', $template, $template_name); + $this->parser->parse($category_select); + + return; + } + + /** + * AdminActions::parse_defskinselect() + * Parse skinvar defskinselect + * + * @param string $type type of skin + * @param string $template_name name of template + * @return void + */ + public function parse_defskinselect($type = 'blog', $template_name = '') + { + global $CONF, $manager, $member; + + if ( !in_array($this->skintype, Admin::$adminskin_actions) ) + { + $blogid = intRequestVar('blogid'); + if ( !$blogid ) + { + $template['selected'] = $CONF['BaseSkin']; + } + else + { + $blog =& $manager->getBlog($blogid); + $template['selected'] = $blog->getDefaultSkin(); + } + + if ( $type != 'blog' ) + { + $template['name'] = 'BaseSkin'; + } + else + { + $template['name'] = 'defskin'; + } + + $query = "SELECT sdname as text, sdnumber as value FROM %s WHERE sdname NOT LIKE 'admin/%%';"; + } + else + { + /* TODO: member object will have its own adminskin id */ + $template['selected'] = $CONF['AdminSkin']; + $template['name'] = 'AdminSkin'; + $query = "SELECT sdname as text, sdnumber as value FROM %s WHERE sdname LIKE 'admin/%%';"; + } + + $query = sprintf($query, sql_table('skin_desc')); + $template['tabindex'] = 50; + + $skin_select = showlist($query, 'select', $template, $template_name); + $this->parser->parse($skin_select); + + return; + } + + /** + * AdminActions::parse_deletecomment() + * Parse skinvar deletecomment + * + * @param string $type type of infomation for comment + * @return void + */ + public function parse_deletecomment($type = 'id') + { + $commentid = intRequestVar('commentid'); + $comment = COMMENT::getComment($commentid); + + switch ( $type ) + { + case 'id': + echo intRequestVar('commentid'); + break; + case 'author': + if ( array_key_exists('member', $comment) && !empty($comment['member']) ) + { + echo $comment['member']; + } + else + { + echo $comment['user']; + } + break; + case 'body': + $body = strip_tags($comment['body']); + echo Entity::hsc(shorten($body, 300, '...')); + } + return; + } + + /** + * AdminActions::parse_deleteitembody() + * Parse skinvar deleteitembody + * + * @param void + * @return void + */ + public function parse_deleteitembody() + { + global $manager; + + $itemid = intRequestVar('itemid'); + $item =& $manager->getItem($itemid, 1, 1); + + $body = strip_tags($item['body']); + + echo Entity::hsc(shorten($body, 300, '...')); + + return; + } + + /** + * AdminActions::parse_deleteitemid() + * Parse skinvar deleteitemid + * + * @param void + * @return void + */ + public function parse_deleteitemid() + { + echo (integer) intRequestVar('itemid'); + return; + } + + /** + * AdminActions::parse_deleteitemtitle() + * Parse skinvar deleteitemtitle + * + * @param void + * @return void + */ + public function parse_deleteitemtitle() + { + global $manager; + + $itemid = intRequestVar('itemid'); + $item =& $manager->getItem($itemid, 1, 1); + + echo Entity::hsc(strip_tags($item['title'])); + + return; + } + + /** + * AdminActions::parse_editcomment() + * Parse skinvar editcomment + * + * @param string $type type of comment setting + * @return void + */ + public function parse_editcomment($type = 'id') + { + global $manager; + + $comment = Admin::$contents; + + switch ( $type ) + { + case 'id': + echo intRequestVar('commentid'); + break; + case 'user': + if ( !array_key_exists('member', $comment) || empty($comment['member']) ) + { + echo $comment['user'] . " (" . _EDITC_NONMEMBER . ")"; + } + else + { + echo $comment['member'] . " (" . _EDITC_MEMBER . ")"; + } + break; + case 'date': + echo date("Y-m-d @ H:i", $comment['timestamp']); + break; + case 'body': + $comment['body'] = str_replace('
    ', '', $comment['body']); + $comment['body'] = preg_replace("#[^<]*#", "\\1", $comment['body']); + echo $comment['body']; + break; + case 'cmail': + echo $comment['userid']; + break; + case 'url': + echo $comment['userid']; + break; + default: + if ( array_key_exists($type, $comment) && !empty($comment[$type]) ) + { + echo $comment[$type]; + } + break; + } + return; + } + + /** + * AdminActions::parse_editdesturl() + * Parse skinvar editdesturl + */ + public function parse_editdesturl() + { + if ( requestVar('desturl') ) + { + echo Entity::hsc(requestVar('desturl')); + } + return; + } + + /** + * AdminActions::parse_editmemberlist() + * Parse skinvar editmemberlist + * + * @param string $template_name name of template + * @return void + */ + public function parse_editmemberlist($template_name = '') + { + global $manager; + // show list of members with actions + $query = 'SELECT * FROM %s;'; + $query = sprintf($query, sql_table('member')); + + $resource = DB::getResult($query); + if ( $resource->rowCount() > 0 ) + { + $template['content'] = 'memberlist'; + $template['tabindex'] = 10; + + $member_list = listplug_batchlist('member', $resource, 'table', $template, $template_name); + $this->parser->parse($member_list); + } + else + { + echo _LISTS_NOMORE; + } + $resource->closeCursor(); + + return; + } + + /** + * AdminActions::parse_editmember() + * Parse skinvar editmember + * + * @param string $type type of information for member + * @return string $tempateName name of template to use + * @return void + */ + public function parse_editmember($type = 'id', $template_name = '') + { + global $CONF, $manager, $member; + + $memberid = intRequestVar('memberid'); + $mem =& $manager->getMember($memberid); + + switch ( $type ) + { + case 'id': + echo intRequestVar('memberid'); + break; + case 'displayname': + if ( $this->skintype == 'teamdelete' || $this->skintype == 'memberdelete' ) + { + echo Entity::hsc($mem->getDisplayName()); + } + else + { + $dispName = Entity::hsc($mem->getDisplayName()); + if ( $CONF['AllowLoginEdit'] || $member->isAdmin() ) + { + echo '\n"; + } + else + { + echo $dispName; + } + } + break; + case 'realname': + echo Entity::hsc($mem->getRealName()); + break; + case 'email': + echo Entity::hsc($mem->getEmail()); + break; + case 'url': + echo Entity::hsc($mem->getURL()); + break; + case 'admin': + $this->parse_inputyesno('admin', $mem->isAdmin(), 60, 1, 0, _YES, _NO, 0, $template_name); + break; + case 'canlogin': + $this->parse_inputyesno('canlogin', $mem->canLogin(), 70, 1, 0, _YES, _NO, $mem->isAdmin(), $template_name); + break; + case 'notes': + echo Entity::hsc($mem->getNotes()); + break; + case 'autosave': + $this->parse_inputyesno('autosave', $mem->getAutosave(), 87, 1, 0, _YES, _NO, 0, $template_name); + break; + default: + break; + } + return; + } + + /** + * AdminActions::parse_editpluginfo() + * Parse skinvar editpluginfo + * + * @param string $type type of plugin info + * @return void + */ + public function parse_editpluginfo($type) + { + global $manager; + + $pid = intRequestVar('plugid'); + switch ( $type ) + { + case 'id': + echo $pid; + break; + case 'name': + echo Entity::hsc($manager->getPluginNameFromPid($pid)); + break; + } + return; + } + + /** + * AdminActions::parse_editplugoptionslist() + * Parse skinvar editplugoptionslist + * + * @param string $template_name name of template + * @return void + */ + public function parse_editplugoptionslist($template_name = '') + { + global $manager; + + $pid = intRequestVar('plugid'); + $aOptions = array(); + $aOIDs = array(); + + $query = "SELECT * FROM %s WHERE ocontext='global' AND opid=%d ORDER BY oid ASC;"; + $query = sprintf($query, sql_table('plugin_option_desc'), (integer) $pid); + $resource = DB::getResult($query); + + foreach ( $resource as $row ) + { + $aOIDs[] = $row['oid']; + $aOptions[$row['oid']] = array( + 'oid' => $row['oid'], + 'value' => $row['odef'], + 'name' => $row['oname'], + 'description' => $row['odesc'], + 'type' => $row['otype'], + 'typeinfo' => $row['oextra'], + 'contextid' => 0 + ); + } + + // fill out actual values + if ( count($aOIDs) > 0 ) + { + $query = 'SELECT oid, ovalue FROM %s WHERE oid in (%s)'; + $query = sprintf($query, sql_table('plugin_option'), implode(',', $aOIDs)); + + $result = DB::getResult($query); + foreach ( $result as $row ) + { + $aOptions[$row['oid']]['value'] = $row['ovalue']; + } + } + + // call plugins + $data = array( + 'context' => 'global', + 'plugid' => $pid, + 'options' => &$aOptions + ); + $manager->notify('PrePluginOptionsEdit', $data); + + if ( sizeof($aOptions) > 0 ) + { + $template['content'] = 'plugoptionlist'; + $option_list = showlist($aOptions, 'table', $template, $template_name); + $this->parser->parse($option_list); + } + else + { + echo '

    ' . _ERROR_NOPLUGOPTIONS . "

    \n"; + } + return; + } + + /** + * AdminActions::parse_editskin() + * Parse skinvar editskin + * + * @param string $type type of skin + * @return void + */ + public function parse_editskin($type = 'id') + { + global $manager; + + $skinid = intRequestVar('skinid'); + + if ( !in_array($this->skintype, Admin::$adminskin_actions) ) + { + $skin =& $manager->getSKIN($skinid); + } + else + { + $skin =& $manager->getSKIN($skinid, 'AdminActions'); + } + + switch ( $type ) + { + case 'id': + echo intRequestVar('skinid'); + break; + case 'name': + echo Entity::hsc($skin->getName()); + break; + case 'desc': + echo Entity::hsc($skin->getDescription()); + break; + case 'type': + echo Entity::hsc($skin->getContentType()); + break; + case 'prefix': + echo Entity::hsc($skin->getIncludePrefix()); + break; + case 'mode': + $this->parse_inputyesno('inc_mode', $skin->getIncludeMode(), 120, 'skindir', 'normal', _PARSER_INCMODE_SKINDIR, _PARSER_INCMODE_NORMAL); + default: + break; + } + return; + } + + /** + * AdminActions::parse_editskintype() + * Parse skinvar editskintype + * + * @param string $type name of type for skin type + * @return void + */ + public function parse_editskintype($stype = 'id') + { + global $manager; + + static $skin = NULL; + static $types = array(); + + if ( $skin == NULL ) + { + $skinid = intRequestVar('skinid'); + + if ( !in_array($this->skintype, Admin::$adminskin_actions) ) + { + $skin =& $manager->getSkin($skinid); + } + else + { + $skin =& $manager->getSkin($skinid, 'AdminActions'); + } + + $types = $skin->getNormalTypes(); + } + + $type = strtolower(trim(requestVar('type'))); + + switch ( $stype ) + { + case 'id': + echo $skin->getID(); + break; + case 'name': + echo Entity::hsc($skin->getName()); + break; + case 'desc': + echo Entity::hsc($skin->getDescription()); + break; + case 'type': + echo Entity::hsc($skin->getContentType()); + break; + case 'content': + echo Entity::hsc($skin->getContentFromDB($type)); + break; + case 'skintype': + if ( !array_key_exists($type, $types) ) + { + $skinType = ucfirst($type); + } + else + { + $skinType = $types[$type]; + } + echo Entity::hsc($skinType); + break; + case 'skintyperaw': + echo Entity::hsc($type); + break; + case 'prefix': + echo Entity::hsc($skin->getIncludePrefix()); + break; + case 'mode': + if ( !$skin->getIncludeMode() != 'skindir' ) + { + $incMode = _PARSER_INCMODE_NORMAL; + } + else + { + $incMode = _PARSER_INCMODE_SKINDIR; + } + echo Entity::hsc($incMode); + break; + default: + break; + } + return; + } + + /** + * AdminActions::parse_adminurl() + * Parse skinvar adminurl + * (shortcut for admin url) + * + * @param void + * @return void + */ + public function parse_adminurl() + { + $this->parse_sitevar('adminurl'); + return; + } + + /** + * AdminActions::parse_edittemplateinfo() + * Parse skinvar edittemplateinfo + * + * @param string $format format to output + * @param string $typedesc type of template + * @param string $typename type name of template + * @param string $help help text + * @param string $tabindex index value for tabindex attribute of input element + * @param string $big textarea size + * @param string $tplt name of template to be filled + * @return boolean + */ + public function parse_edittemplateinfo($format, $typedesc = '', $typename = '', $help = '', $tabindex = 0, $big = 0, $template_name = '') + { + global $manager; + static $id = NULL; + static $name = NULL; + static $desc = NULL; + + if ( $id == NULL ) + { + $id = intRequestVar('templateid'); + } + + if ( $name == NULL ) + { + $name = Template::getNameFromId($id); + } + + if ( $desc == NULL ) + { + $desc = Template::getDesc($id); + } + + $template =& $manager->getTemplate($name); + + switch ( $format ) + { + case 'id': + echo (integer) $id; + break; + case 'name': + echo Entity::hsc($name); + break; + case 'desc': + echo Entity::hsc($desc); + break; + case 'extratemplate': + $tabidx = 600; + $pluginfields = array(); + if ( !in_array($this->skintype, Admin::$adminskin_actions) ) + { + $data = array('fields' => &$pluginfields); + $manager->notify('TemplateExtraFields', $data); + } + else + { + $data = array('fields' => &$pluginfields); + $manager->notify('AdminTemplateExtraFields', $data); + } + + foreach ( $pluginfields as $ptkey => $ptvalue ) + { + $tmplt = array(); + if ( $desc ) + { + $tmplt =& $manager->getTemplate($desc); + } + + /* extra plugin field */ + if ( !array_key_exists('TEMPLATE_EDIT_EXPLUGNAME', $tmplt) || empty($tmplt['TEMPLATE_EDIT_EXPLUGNAME']) ) + { + $base = "\n" + . "<%explugtplname%>\n" + . ""; + } + else + { + $base = $tmplt['TEMPLATE_EDIT_EXPLUGNAME']; + } + $data = array( + 'explugtplname' => Entity::hsc($ptkey) + ); + echo Template::fill($base, $data); + + foreach ( $ptvalue as $ptname => $ptdesc ) + { + if ( !array_key_exists($ptname, $template) ) + { + $content = ''; + } + else + { + $content = $template[$ptname]; + } + $tempate_textarea = listplug_templateEditRow($content, $ptdesc, $ptname, $help, $tabidx++, $big, $template_name); + $this->parser->parse($tempate_textarea); + continue; + } + } + break; + default: + $typedesc = defined($typedesc) ? constant($typedesc) : $typedesc; + $typename = defined($typename) ? constant($typename) : $typename; + + if ( !array_key_exists($typename, $template) ) + { + $content = ''; + } + else + { + $content = $template[$typename]; + } + $tempate_textarea = listplug_templateEditRow($content, $typedesc, $typename, $help, $tabindex, $big, $template_name); + $this->parser->parse($tempate_textarea); + break; + } + + return; + } + + /** + * AdminActions::parse_eventformextra() + * Parse skinvar eventformextra + * + * @param string $type name of type for event form extra + * @return void + */ + public function parse_eventformextra($type = 'activation') + { + global $manager; + + $data = array(); + + switch ( $type ) + { + case 'activation': + $key = requestVar('ackey'); + if ( !$key ) + { + Admin::error(_ERROR_ACTIVATE); + } + $info = MEMBER::getActivationInfo($key); + if ( !$info ) + { + Admin::error(_ERROR_ACTIVATE); + } + $mem =& $manager->getMember($info->vmember); + if ( !$mem ) + { + Admin::error(_ERROR_ACTIVATE); + } + $data = array( + 'type' => 'activation', + 'member' => $mem + ); + break; + case 'membermailform-notloggedin': + $data = array('type' => 'membermailform-notloggedin',); + break; + } + $manager->notify('FormExtra', $data); + return; + } + + /** + * AdminActions::parse_extrahead() + * Parse skinvar extrahead + */ + public function parse_extrahead() + { + global $manager; + + $data = array( + 'extrahead' => &Admin::$extrahead, + 'action' => Admin::$action + ); + + $manager->notify('AdminPrePageHead', $data); + + $this->parser->parse(Admin::$extrahead); + return; + } + + /** + * AdminActions::parse_member() + * Parse skinvar member + * (includes a member info thingie) + * + * @param string $what which memberdata is needed + * @return void + */ + public function parse_member($what) + { + global $memberinfo, $member, $CONF; + + // 1. only allow the member-details-page specific variables on member pages + if ( $this->skintype == 'member' ) + { + switch( $what ) + { + case 'name': + echo Entity::hsc($memberinfo->getDisplayName()); + break; + case 'realname': + echo Entity::hsc($memberinfo->getRealName()); + break; + case 'notes': + echo Entity::hsc($memberinfo->getNotes()); + break; + case 'url': + echo Entity::hsc($memberinfo->getURL()); + break; + case 'email': + echo Entity::hsc($memberinfo->getEmail()); + break; + case 'id': + echo Entity::hsc($memberinfo->getID()); + break; + } + } + + // 2. the next bunch of options is available everywhere, as long as the user is logged in + if ( $member->isLoggedIn() ) + { + switch( $what ) + { + case 'yourname': + echo $member->getDisplayName(); + break; + case 'yourrealname': + echo $member->getRealName(); + break; + case 'yournotes': + echo $member->getNotes(); + break; + case 'yoururl': + echo $member->getURL(); + break; + case 'youremail': + echo $member->getEmail(); + break; + case 'yourid': + echo $member->getID(); + break; + case 'yourprofileurl': + if ( $CONF['URLMode'] == 'pathinfo' ) + { + echo Link::create_member_link($member->getID()); + } + else + { + echo $CONF['IndexURL'] . Link::create_member_link($member->getID()); + } + break; + } + } + return; + } + + /** + * AdminActions::parse_version() + * Parse skinvar version + * (include nucleus versionnumber) + * + * @param void + * @return void + */ + public function parse_version() + { + global $nucleus; + echo 'Nucleus CMS ' . $nucleus['version']; + return; + } + + /** + * AdminActions::parse_sitevar() + * Parse skinvar sitevar + * (include a sitevar) + * + * @param string $which + * @return void + */ + public function parse_sitevar($which) + { + global $CONF; + switch ( $which ) + { + case 'url': + echo $CONF['IndexURL']; + break; + case 'name': + echo $CONF['SiteName']; + break; + case 'admin': + echo $CONF['AdminEmail']; + break; + case 'adminurl': + echo $CONF['AdminURL']; + break; + } + return; + } + + /** + * AdminActions::parse_actionurl() + * Parse $CONF; + * + * @param void + * @return void + */ + public function parse_actionurl() + { + global $CONF; + echo Entity::hsc($CONF['ActionURL']); + return; + } + + /** + * AdminActions::parse_getblogsetting() + * Parse skinvar getblogsetting + */ + public function parse_getblogsetting($which) + { + global $blog, $manager; + + if ( $blog ) + { + $b =& $blog; + } + elseif ( $bid = intRequestVar('blogid') ) + { + $b =& $manager->getBlog($bid); + } + else + { + return; + } + + switch ( $which ) + { + case 'id': + return Entity::hsc($b->getID()); + break; + case 'url': + return Entity::hsc($b->getURL()); + break; + case 'name': + return Entity::hsc($b->getName()); + break; + case 'desc': + return Entity::hsc($b->getDescription()); + break; + case 'short': + return Entity::hsc($b->getShortName()); + break; + case 'notifyaddress': + return Entity::hsc($b->getNotifyAddress()); + break; + case 'maxcomments': + return Entity::hsc($b->getMaxComments()); + break; + case 'updatefile': + return Entity::hsc($b->getUpdateFile()); + break; + case 'timeoffset': + return Entity::hsc($b->getTimeOffset()); + break; + } + return; + } + + /** + * AdminActions::parse_geteditpluginfo() + * Parse skinvar geteditpluginfo + * + * @param string $type name of setting for edit plugin info + * @return void + */ + public function parse_geteditpluginfo($type) + { + global $manager; + $pid = intRequestVar('plugid'); + switch ( $type ) + { + case 'id': + return $pid; + break; + case 'name': + return Entity::hsc($manager->getPluginNameFromPid($pid)); + break; + } + return; + } + + /** + * AdminActions::parse_getmember() + * Parse skinvar getmember + * (includes a member info thingie) + * + * @param string $what name of setting for member + * @return void + */ + public function parse_getmember($what) + { + global $memberinfo, $member; + // 1. only allow the member-details-page specific variables on member pages + if ( $this->skintype == 'member' ) + { + switch ( $what ) + { + case 'name': + return Entity::hsc($memberinfo->getDisplayName()); + break; + case 'realname': + return Entity::hsc($memberinfo->getRealName()); + break; + case 'notes': + return Entity::hsc($memberinfo->getNotes()); + break; + case 'url': + return Entity::hsc($memberinfo->getURL()); + break; + case 'email': + return Entity::hsc($memberinfo->getEmail()); + break; + case 'id': + return Entity::hsc($memberinfo->getID()); + break; + } + } + // 2. the next bunch of options is available everywhere, as long as the user is logged in + if ( $member->isLoggedIn() ) + { + switch ( $what ) + { + case 'yourname': + return $member->getDisplayName(); + break; + case 'yourrealname': + return $member->getRealName(); + break; + case 'yournotes': + return $member->getNotes(); + break; + case 'yoururl': + return $member->getURL(); + break; + case 'youremail': + return $member->getEmail(); + break; + case 'yourid': + return $member->getID(); + break; + } + } + return; + } + + /** + * AdminActions::parse_headmessage() + * Parse skinvar headmessage + * + * @param void + * @return void + */ + public function parse_headmessage() + { + if ( !empty(Admin::$headMess) ) + { + echo '

    ' . _MESSAGE . ': ' . Entity::hsc(Admin::$headMess) . "

    \n"; + } + return; + } + + /** + * AdminActions::parse_helplink() + * Parse skinvar helplink + * + * @param string $topic name of topic for help + * @return void + */ + public function parse_helplink($topic = '') + { + if ( !empty($topic) ) + { + help($topic); + } + return; + } + + /** + * AdminActions::parse_helpplugname() + * Parse skinvar helpplugname + * + * @param void + * @return void + */ + public function parse_helpplugname() + { + $plugid = intGetVar('plugid'); + Entity::hsc($manager->getPluginNameFromPid($plugid)); + return; + } + + /** + * AdminActions::parse_ilistaddnew() + * Parse skinvar ilistaddnew + * + * @param void + * @return void + */ + public function parse_ilistaddnew() + { + $blogid = intRequestVar('blogid'); + if ( intPostVar('start') == 0 ) + { + echo '

    ' . _ITEMLIST_ADDNEW . "

    \n"; + } + return; + } + + /** + * AdminActions::parse_importskininfo() + * Parse skinvar importskininfo + * + * @param string $type name of information for imported skin + * @return void + */ + public function parse_importskininfo($type) + { + switch ( $type ) + { + case 'info': + echo Entity::hsc(Admin::$contents['skininfo']); + break; + case 'snames': + $dataArr = Admin::$contents['skinnames']; + echo implode(' ' . _AND . ' ', $dataArr); + break; + case 'tnames': + $dataArr = Admin::$contents['tpltnames']; + echo implode(' ' . _AND . ' ', $dataArr); + break; + case 'sclashes': + $dataArr = Admin::$contents['skinclashes']; + echo implode(' ' . _AND . ' ', $dataArr); + break; + case 'tclashes': + $dataArr = Admin::$contents['tpltclashes']; + echo implode(' ' . _AND . ' ', $dataArr); + break; + case 'skinfile': + echo Entity::hsc(Admin::$contents['skinfile']); + break; + case 'mode': + echo Entity::hsc(Admin::$contents['mode']); + break; + } + return; + } + + /** + * AdminActions::parse_init() + * some init stuff for all forms + * + * @param void + * @return void + */ + public function parse_init() + { + global $manager; + + $authorid = ''; + if ( requestVar('action') == 'itemedit' ) + { + $authorid = Admin::$contents['authorid']; + } + + Admin::$blog->insertJavaScriptInfo($authorid); + return; + } + + /** + * AdminActions::parse_inputyesno() + * Parse skinvar inputyesno + * + * @param string $name + * @param string $checkedval + * @param string $tabindex + * @param string $value1 + * @param string $value2 + * @param string $yesval + * @param string $noval + * @param string $isAdmin + * @param string $template_name + * @return void + */ + public function parse_inputyesno($name, $checkedval, $tabindex = 0, $value1 = 1, $value2 = 0, $yesval = _YES, $noval = _NO, $isAdmin = 0, $template_name = '') + { + $input_yesno = listplug_input_yesno($name, $checkedval, $tabindex, $value1, $value2, $yesval, $noval, $isAdmin, $template_name); + $this->parser->parse($input_yesno); + return; + } + + /** + * AdminActions::parse_insertpluginfo() + * Parse templatevar insertpluginfo + */ + public function parse_insertpluginfo($type) + { + switch ( $type ) + { + case 'id': + return Admin::$aOptions['pid']; + break; + case 'name': + return Entity::hsc(Admin::$aOptions['pfile']); + break; + } + return; + } + + /** + * AdminActions::parse_insplugoptcontent() + * Parse skinvar insplugoptcontent + * + * @param void + * @return void + */ + public function parse_insplugoptcontent() + { + $meta = NucleusPlugin::getOptionMeta(Admin::$aOptions['typeinfo']); + if ( array_key_exists('access', $meta) && $meta['access'] != 'hidden' ) + { + echo ''; + listplug_plugOptionRow(Admin::$aOptions); + echo ''; + } + return; + } + + /** + * AdminActions::parse_iprangeinput() + * Parse skinvar iprangeinput + * + * @param void + * @return void + */ + public function parse_iprangeinput() + { + if ( requestVar('ip') ) + { + $iprangeVal = Entity::hsc(requestVar('ip')); + echo "\n"; + echo "
    \n"; + echo '' . "\n"; + echo '' . "\n"; + echo "\n"; + } + else + { + echo '' . "\n"; + echo '' . "\n"; + } + return; + } + + /** + * AdminActions::parse_itemnavlist() + * Parse skinvar itemnavlist + * + * @param string $template_name name of template to use + * @return void + */ + public function parse_itemnavlist($template_name = '') + { + global $CONF, $manager, $member; + + $query = "SELECT bshortname, cname, mname, ititle, ibody, inumber, idraft, itime" + . " FROM %s, %s, %s, %s" + . " WHERE iblog=bnumber AND iauthor=mnumber AND icat=catid"; + + $query = sprintf($query, sql_table('item'), sql_table('blog'), sql_table('member'), sql_table('category')); + + if ( $this->skintype == 'itemlist' ) + { + $blog = FALSE; + if ( array_key_exists('blogid', $_REQUEST) ) + { + $blogid = intRequestVar('blogid'); + } + else if ( array_key_exists('itemid', $_REQUEST) ) + { + $itemid = intRequestVar('itemid'); + $item = &$manager->getItem($itemid, 1, 1); + $blogid = (integer) $item['blogid']; + } + $blog =& $manager->getBlog($blogid); + + $query .= " AND iblog={$blogid}"; + $template['now'] = $blog->getCorrectTime(time()); + + // non-blog-admins can only edit/delete their own items + if ( !$member->blogAdminRights($blogid) ) + { + $query .= ' AND iauthor = ' . $member->getID(); + } + } + elseif ( $this->skintype == 'browseownitems' ) + { + $query .= ' AND iauthor = ' . $member->getID(); + $blogid = 0; + $template['now'] = time(); + } + + // search through items + $search = postVar('search'); + + if ( !empty($search) ) + { + $query .= ' AND ((ititle LIKE ' . DB::quoteValue('%'.$search.'%') . ') ' + . ' OR (ibody LIKE ' . DB::quoteValue('%'.$search.'%') . ') ' + . ' OR (imore LIKE ' . DB::quoteValue('%'.$search.'%') . '))'; + } + + if ( postVar('start') ) + { + $start = intPostVar('start'); + } + else + { + $start = 0; + } + + // amount of items to show + if ( postVar('amount') ) + { + $amount = intPostVar('amount'); + } + else + { + $amount = (integer) $CONF['DefaultListSize']; + if ( $amount < 1 ) + { + $amount = 10; + } + } + + $query .= ' ORDER BY itime DESC' + . " LIMIT {$start},{$amount}"; + + $resource = DB::getResult($query); + if ( $resource->rowCount() > 0 ) + { + $template['action'] = $this->skintype; + $template['start'] = $start; + $template['amount'] = $amount; + $template['minamount'] = 0; + $template['maxamount'] = 1000; + $template['blogid'] = $blogid; + $template['search'] = $search; + $template['itemid'] = 0; + + $template['content'] = 'itemlist'; + + $navlist = listplug_navlist('item', $query, 'table', $template, $template_name); + $this->parser->parse($navlist); + } + else + { + /* TODO: nothing to be shown */ + } + $resource->closeCursor(); + + return; + } + + /** + * AdminActions::parse_itemtime() + * date change on edit item + * + * @param string $key key of PHP's getDate() + * @return void + */ + public function parse_itemtime($key) + { + global $manager; + + $contents = Admin::$contents; + $itemtime = getdate($contents['timestamp']); + echo $itemtime[$key]; + return; + } + + /** + * AdminActions::parse_jstoolbaroptions() + * Parse skinvar jstoolbaroptions + * + * @param void + * @return void + */ + public function parse_jstoolbaroptions() + { + global $CONF; + $options = array( + _SETTINGS_JSTOOLBAR_NONE, + _SETTINGS_JSTOOLBAR_SIMPLE, + _SETTINGS_JSTOOLBAR_FULL + ); + + $i = 1; + foreach ( $options as $option ) + { + $text = "\n"; + $extra = ($CONF['DisableJsTools'] == $i) ? ' selected="selected"' : ''; + echo sprintf($text, $i, $extra, $option); + $i++; + } + return; + } + /** + * AdminActions::parse_localeselectoptions() + * Parse skinvar localeselectoptions + * + * @param void + * @return void + */ + public function parse_localeselectoptions() + { + global $CONF, $member; + + $locales = i18n::get_available_locale_list(); + + /* default option */ + if ( $this->skintype == 'editmembersettings' ) + { + if ( !$member->getLocale() ) + { + echo "\n"; + } + else + { + echo "\n"; + } + } + else + { + if ( $CONF['Locale'] == 'en_Latn_US' ) + { + echo "\n"; + } + else + { + echo "\n"; + } + } + + /* optional options */ + foreach ( $locales as $locale ) + { + if ( $this->skintype == 'editmembersettings' ) + { + if ( $locale != $member->getLocale() ) + { + echo "\n"; + } + return; + } + + /** + * AdminActions::parse_listplugplugoptionrow() + * Parse templatevar listplugplugoptionrow + * + * @param string $template_name name of template + * @return void + */ + public function parse_listplugplugoptionrow($template_name = '') + { + echo listplug_plugOptionRow(Admin::$aOptions, $template_name); + return; + } + + /** + * AdminActions::parse_mediadirwarning() + * Parse skinvar mediadirwarning + * + * @param void + * @return void + */ + public function parse_mediadirwarning() + { + global $DIR_MEDIA; + if ( !is_dir($DIR_MEDIA) ) + { + echo "
    " . _WARNING_NOTADIR . "\n"; + } + if ( !is_readable($DIR_MEDIA) ) + { + echo "
    " . _WARNING_NOTREADABLE . "\n"; + } + if ( !is_writeable($DIR_MEDIA) ) + { + echo "
    " . _WARNING_NOTWRITABLE . "\n"; + } + return; + } + + /** + * AdminActions::parse_movedistselect() + * Parse skinvar movedistselect + */ + public function parse_movedistselect() + { + $actionType = requestVar('action'); + switch ( $actionType ) + { + case 'batchitem': + $this->selectBlog('destcatid', 'category'); + break; + case 'batchcategory': + $this->selectBlog('destblogid'); + break; + default: + if ( $this->skintype == 'itemmove' ) + { + $query = "SELECT icat as result FROM %s WHERE inumber=%d;"; + $query = sprintf($query, sql_table('item'), intRequestVar('itemid')); + $catid = DB::getValue(sprintf($query, intRequestVar('itemid'))); + $this->selectBlog('catid', 'category', $catid, 10, 1); + } + break; + } + return; + } + + /** + * AdminActions::parse_moveitemid() + * Parse skinvar moveitemid + * + * @param void + * @return void + */ + public function parse_moveitemid() + { + echo intRequestVar('itemid'); + return; + } + + /** + * AdminActions::parse_newestcompare() + * Parse skinvar newestcompare + * + * @param void + * @return void + */ + public function parse_newestcompare() + { + global $nucleus; + + $newestVersion = getLatestVersion(); + $newestCompare = str_replace('/', '.', $newestVersion); + $currentVersion = str_replace(array('/', 'v'), array('.', ''), $nucleus['version']); + + if ( $newestVersion && version_compare($newestCompare, $currentVersion, '>') ) + { + echo '
    '; + echo _ADMIN_SYSTEMOVERVIEW_LATESTVERSION_TEXT . $newestVersion . ''; + } + else + { + echo _ADMIN_SYSTEMOVERVIEW_VERSION_LATEST; + } + return; + } + + /** + * AdminActions::parse_newmemberselect() + * Parse skinvar newmemberselect + * + * @param string $template_name name of template to use + * @return void + */ + public function parse_newmemberselect($template_name = '') + { + $blogid = intRequestVar('blogid'); + + $query = "SELECT tmember FROM %s WHERE tblog=%d;"; + $query = sprintf($query, sql_table('team'), (integer) $blogid); + $res = DB::getResult($query); + + $tmem = array(); + foreach ( $res as $row ) + { + $tmem[] = intval($row['tmember']); + } + + $query = "SELECT mname as text, mnumber as value FROM %s WHERE mnumber NOT IN (%s);"; + $query = sprintf($query, sql_table('member'), implode(', ', $tmem)); + + $template = array( + 'name' => 'memberid', + 'tabindex' => 10000, + 'selected' => 0 + ); + $member_select = showlist($query, 'select', $template, $template_name); + $this->parser->parse($member_select); + return; + } + + /** + * AdminActions::parse_newpluginlist() + * Parse skinvar newpluginlist + * + * @param void + * @return void + */ + public function parse_newpluginlist() + { + $candidates = $this->newPlugCandidates; + foreach ( $candidates as $name ) + { + echo '\n"; + } + return; + } + + /** + * AdminActions::parse_outputspecialdirs() + * Parse skinvar outputspecialdirs + * + * @param string $type type of setting for directory + * @return void + */ + public function parse_outputspecialdirs($type) + { + global $DIR_MEDIA, $DIR_NUCLEUS; + + switch ( $type ) + { + case 'nucleusdir': + echo Entity::hsc($DIR_NUCLEUS); + break; + case 'mediadir': + echo Entity::hsc($DIR_MEDIA); + break; + } + return; + } + + /** + * AdminActions::parse_passrequestvars() + * Parse skinvar passrequestvars + * + * @param void + * @return void + */ + public function parse_passrequestvars() + { + $passvar = Admin::$passvar; + $oldaction = postVar('oldaction'); + + if ( ($oldaction != 'logout') + && ($oldaction != 'login') + && $passvar + && !postVar('customaction') ) + { + passRequestVars(); + } + return; + } + + /** + * AdminActions::parse_pluginextras() + * Parse skinvar pluginextras + * + * @param string $type type of plugin context + * @return void + */ + public function parse_pluginextras($type = 'global') + { + global $manager; + + switch ( $type ) + { + case 'member': + $id = intRequestVar('memberid'); + $mem =& $manager->getMember($id); + $data = array('member' => &$mem); + $manager->notify('MemberSettingsFormExtras', $data); + break; + case 'blog': + $id = intRequestVar('blogid'); + $blg =& $manager->getBlog($id); + $data = array('member' => &$blg); + $manager->notify('BlogSettingsFormExtras', $data); + break; + case 'createaccount': + $data = array( + 'type' => 'createaccount.php', + 'prelabel' => '', + 'postlabel' => '
    ', + 'prefield' => '', + 'postfield' => '

    ' + ); + $manager->notify('RegistrationFormExtraFields', $data); + break; + default: + $data = array(); + $manager->notify('GeneralSettingsFormExtras', $data); + break; + } + return; + } + + /** + * AdminActions::parse_pluginhelp() + * Parse skinvar pluginhelp + * + * @param void + * @return void + */ + public function parse_pluginhelp() + { + global $manager, $DIR_PLUGINS; + + $plugid = intGetVar('plugid'); + $plugName = $manager->getPluginNameFromPid($plugid); + $plug =& $manager->getPlugin($plugName); + + if ( $plug->supportsFeature('HelpPage') > 0 ) + { + $helpfile = $DIR_PLUGINS . $plug->getShortName() . '/help.'; + if ( @file_exists($helpfile . 'php') ) + { + @include($helpfile . 'php'); + return; + } + elseif ( @file_exists($helpfile . 'html') ) + { + @include($helpfile . 'html'); + return; + } + } + echo '

    ' . _ERROR . ': ' . _ERROR_PLUGNOHELPFILE . "

    \n"; + echo '

    (' . _BACK . ")

    \n"; + return; + } + + /** + * AdminActions::parse_pluginlistlist() + * Parse skinvar pluginlistlist + * + * @param string $template_name name of template to use + * @return void + */ + public function parse_pluginlistlist($template_name = '') + { + $query = "SELECT * FROM %s ORDER BY porder ASC;"; + $query = sprintf($query, sql_table('plugin')); + + $template['content'] = 'pluginlist'; + $template['tabindex'] = 10; + + $plugin_list = showlist($query, 'table', $template, $template_name); + $this->parser->parse($plugin_list); + + return; + } + + /** + * AdminActions::parse_pluginoptions() + * Parse skinvar pluginoptions + * + * @param string $type type of plugin option + * @return void + */ + public function parse_pluginoptions($context='global', $template_name='') + { + global $itemid, $manager; + + switch ( $context ) + { + case 'member': + $contextid = intRequestVar('memberid'); + break; + case 'blog': + $contextid = intRequestVar('blogid'); + break; + case 'category': + $contextid = intRequestVar('catid'); + break; + case 'item': + $contextid = $itemid; + break; + } + + /* Actually registererd plugin options */ + $aIdToValue = array(); + $query = "SELECT oid, ovalue FROM %s WHERE ocontextid=%d;"; + $query = sprintf($query, sql_table('plugin_option'), (integer) $contextid); + $res = DB::getResult($query); + foreach ( $res as $row ) + { + $aIdToValue[$row['oid']] = $row['ovalue']; + } + + /* Currently available plugin options */ + $query = "SELECT * FROM %s, %s WHERE opid=pid and ocontext= %s ORDER BY porder, oid ASC;"; + $query = sprintf($query, sql_table('plugin_option_desc'), sql_table('plugin'), DB::quoteValue($context)); + $res = DB::getResult($query); + + $options = array(); + foreach ($res as $row ) + { + if ( !array_key_exists($row['oid'], $aIdToValue) ) + { + $value = $row['odef']; + } + else + { + $value = $aIdToValue[$row['oid']]; + } + + $options[] = array( + 'pid' => $row['pid'], + 'pfile' => $row['pfile'], + 'oid' => $row['oid'], + 'value' => $value, + 'name' => $row['oname'], + 'description' => $row['odesc'], + 'type' => $row['otype'], + 'typeinfo' => $row['oextra'], + 'contextid' => $contextid, + 'extra' => '' + ); + } + + $data = array( + 'context' => $context, + 'contextid' => $contextid, + 'options' => &$options + ); + $manager->notify('PrePluginOptionsEdit', $data); + + $template = array(); + if ( $template_name ) + { + $templates =& $manager->getTemplate($template_name); + if ( !array_key_exists('INSERT_PLUGOPTION_TITLE', $templates) || empty($templates['INSERT_PLUGOPTION_TITLE']) ) + { + $template['title'] = "" + . "<%sprinttext(_PLUGIN_OPTIONS_TITLE, <|%insertpluginfo(name)%|>)%>" + . "\n"; + } + else + { + $template['title'] = $templates['INSERT_PLUGOPTION_TITLE']; + } + + if ( !array_key_exists('INSERT_PLUGOPTION_BODY', $templates) || empty($templates['INSERT_PLUGOPTION_BODY']) ) + { + $template['body'] = "" + . "<%listplugplugoptionrow%>" + . "\n"; + } + else + { + $template['body'] = $templates['INSERT_PLUGOPTION_BODY']; + } + } + + $prevPid = -1; + + foreach ( $options as $option ) + { + // new plugin? + if ( $prevPid != $option['pid'] ) + { + $prevPid = $option['pid']; + $this->parser->parse($template['title']); + } + + $meta = NucleusPlugin::getOptionMeta($option['typeinfo']); + + if ( @$meta['access'] != 'hidden' ) + { + $parsed = $this->parser->parse($template['body']); + } + } + + return; + } + + /** + * AdminActions::parse_qmenuaddselect() + * Parse skinvar qmanuaddselect + * + * @param string $template_name name of template to use + * @return void + */ + public function parse_qmenuaddselect($template_name = '') + { + global $member, $blogid; + $showAll = requestVar('showall'); + if ( $member->isAdmin() && ($showAll == 'yes') ) + { + // Super-Admins have access to all blogs! (no add item support though) + $query = 'SELECT bnumber as value, bname as text FROM %s ORDER BY bname;'; + $query = sprintf($query, sql_table('blog')); + } + else + { + $query = 'SELECT bnumber as value, bname as text FROM %s, %s WHERE tblog=bnumber and tmember=%d ORDER BY bname;'; + $query = sprintf($query, sql_table('blog'), sql_table('team'), (integer) $member->getID()); + } + + $template['name'] = 'blogid'; + $template['tabindex'] = 15000; + $template['extra'] = _QMENU_ADD_SELECT; + $template['selected'] = 0; + $template['shorten'] = 10; + $template['shortenel'] = ''; + $template['javascript'] = 'onchange="return form.submit()"'; + + $selectlist = showlist($query, 'select', $template, $template_name); + $this->parser->parse($selectlist); + + return; + } + + /** + * AdminActions::parse_quickmenu() + * Parse skinvar quickmenu + * + * @param string $template_name name of template to use + * @return void + */ + public function parse_quickmenu($template_name = '') + { + global $manager; + $templates = array(); + + if ( !empty($template_name) ) + { + $templates = & $manager->getTemplate($template_name); + } + $pluginExtras = array(); + $data = array('options' => &$pluginExtras); + $manager->notify('QuickMenu', $data); + + $template = array(); + if ( count($pluginExtras) > 0 ) + { + if ( !array_key_exists('PLUGIN_QUICKMENU_HEAD', $templates) || empty($templates['PLUGIN_QUICKMENU_HEAD']) ) + { + $template['head'] = "

    <%text(_QMENU_PLUGINS)%>

    \n" + . "
      \n"; + } + else + { + $template['head'] = $templates['PLUGIN_QUICKMENU_HEAD']; + } + + if ( !array_key_exists('PLUGIN_QUICKMENU_BODY', $templates) && empty($templates['PLUGIN_QUICKMENU_BODY']) ) + { + $template['body'] = "
    • \" title=\"<%plugadmintooltip%>\"><%plugadmintitle%>
    • \n"; + } + else + { + $template['body'] = $templates['PLUGIN_QUICKMENU_BODY']; + } + + if ( !array_key_exists('PLUGIN_QUICKMENU_FOOT', $templates) || empty($templates['PLUGIN_QUICKMENU_FOOT']) ) + { + $template['foot'] = "
    \n"; + } + else + { + $template['foot'] = $templates['PLUGIN_QUICKMENU_FOOT']; + } + + $this->parser->parse($template['head']); + foreach ( $pluginExtras as $aInfo ) + { + $data = array( + 'plugadminurl' => Entity::hsc($aInfo['url']), + 'plugadmintooltip' => Entity::hsc($aInfo['tooltip']), + 'plugadmintitle' => Entity::hsc($aInfo['title']), + ); + $body = Template::fill($template['body'], $data); + $this->parser->parse($body); + } + $this->parser->parse($template['foot']); + } + return; + } + + /** + * AdminActions::parse_requestblogid() + * Parse skinvar requestblogid + * + * @param void + * @return void + */ + public function parse_requestblogid() + { + echo intRequestVar('blogid'); + return; + } + + /** + * AdminActions::parse_requestiprange() + * Parse skinvar requestiprange + * + * @param void + * @return void + */ + public function parse_requestiprange() + { + if ( requestVar('iprange') ) + { + echo Entity::hsc(requestVar('iprange')); + } + elseif ( requestVar('ip') ) + { + echo Entity::hsc(requestVar('ip')); + } + return; + } + + /** + * AdminActions::parse_selectlocalskinfiles() + * Parse skinvar selectlocalskinfiles + * + * @param void + * @return void + */ + public function parse_selectlocalskinfiles() + { + global $DIR_SKINS; + + if ( !class_exists('SkinImport', FALSE) ) + { + include_libs('skinie.php'); + } + + if ( !in_array($this->skintype, Admin::$adminskin_actions) && $this->skintype != 'importAdmin' ) + { + $skindir = $DIR_SKINS; + } + else + { + $skindir = "{$DIR_SKINS}admin/"; + } + + $candidates = SkinImport::searchForCandidates($skindir); + foreach ( $candidates as $skinname => $skinfile ) + { + $skinname = Entity::hsc($skinname); + if ( !in_array($this->skintype, Admin::$adminskin_actions) && $this->skintype != 'importAdmin' ) + { + $skinfile = Entity::hsc($skinfile); + } + else + { + $skinfile = Entity::hsc("admin/$skinfile"); + } + echo "\n"; + } + + return; + } + + /** + * AdminActions::parse_skineditallowedlist() + * Parse skinvar skineditallowedlist + * + * @param string $type type of skin + * @param string $template_name name of template + * @return void + */ + public function parse_skineditallowedlist($type, $template_name = '') + { + switch ( $type ) + { + case 'blog': + $query = "SELECT bshortname, bname FROM %s;"; + $show = array( + 'content' => 'shortblognames' + ); + $query = sprintf($query, sql_table('blog')); + break; + case 'template': + if ( !in_array($this->skintype, Admin::$adminskin_actions) ) + { + $query = "SELECT tdname as name, tddesc as description FROM %s WHERE tdname NOT LIKE 'admin/%%';"; + } + else + { + $query = "SELECT tdname as name, tddesc as description FROM %s WHERE tdname LIKE 'admin/%%';"; + } + $show = array( + 'content' => 'shortnames' + ); + $query = sprintf($query, sql_table('template_desc')); + break; + } + + $skin_list = showlist($query, 'table', $show, $template_name); + $this->parser->parse($skin_list); + return; + } + + /** + * AdminActions::parse_skinielist() + * Parse skinvar skinielist + * + * @param string $type type of skin + * @param string $template_name name of template to use + * @return void + */ + public function parse_skinielist($type, $template_name = '') + { + global $manager; + + $templates = array(); + if ( $template_name ) + { + $templates =& $manager->getTemplate($template_name); + } + if ( !array_key_exists('SKINIE_EXPORT_LIST', $templates) || empty($templates['SKINIE_EXPORT_LIST']) ) + { + $template = "\n" + . "" + . "\" id=\"<%expid%>\" />\n" + . "\n" + . "\n" + . "<%expdesc%>\n" + . "\n"; + } + else + { + $template = $templates['SKINIE_EXPORT_LIST']; + } + + switch ( $type ) + { + case 'skin': + if ( !in_array($this->skintype, Admin::$adminskin_actions) ) + { + $res = DB::getResult('SELECT * FROM ' . sql_table('skin_desc'). " WHERE sdname NOT LIKE 'admin/%%';"); + } + else + { + $res = DB::getResult('SELECT * FROM ' . sql_table('skin_desc'). " WHERE sdname LIKE 'admin/%%';"); + } + foreach ( $res as $row ) + { + $data = array( + 'typeid' => 'skin[' . $row['sdnumber'] . ']', + 'expid' => 'skinexp' . $row['sdnumber'], + 'expname' => Entity::hsc($row['sdname']), + 'expdesc' => Entity::hsc($row['sddesc']) + ); + echo Template::fill($template, $data); + } + break; + case 'template': + if ( !in_array($this->skintype, Admin::$adminskin_actions) ) + { + $res = DB::getResult('SELECT * FROM '.sql_table('template_desc'). " WHERE tdname NOT LIKE 'admin/%%';"); + } + else + { + $res = DB::getResult('SELECT * FROM '.sql_table('template_desc'). " WHERE tdname LIKE 'admin/%%';"); + } + foreach ( $res as $row ) + { + $data = array( + 'typeid' => 'template[' . $row['tdnumber'] . ']', + 'expid' => 'templateexp' . $row['tdnumber'], + 'expname' => Entity::hsc($row['tdname']), + 'expdesc' => Entity::hsc($row['tddesc']) + ); + echo Template::fill($template, $data); + } + break; + } + return; + } + + /** + * AdminActions::parse_skinoverview() + * Parse skinvar skinoverview + * + * @param string $template_name name of template to use + * @return void + */ + public function parse_skinoverview($template_name = '') + { + global $CONF; + + $template = array(); + if ( !in_array($this->skintype, Admin::$adminskin_actions) ) + { + $query = "SELECT * FROM %s WHERE sdname NOT LIKE 'admin/%%' ORDER BY sdname;"; + $template['handler'] = 'Actions'; + $template['editaction'] = 'skinedit'; + $template['cloneaction'] = 'skinclone'; + $template['deleteaction'] = 'skindelete'; + $template['edittypeaction'] = 'skinedittype'; + $template['default'] = $CONF['BaseSkin']; + } + else + { + $query = "SELECT * FROM %s WHERE sdname LIKE 'admin/%%' ORDER BY sdname;"; + $template['handler'] = 'AdminActions'; + $template['editaction'] = 'adminskinedit'; + $template['cloneaction'] = 'adminskinclone'; + $template['deleteaction'] = 'adminskindelete'; + $template['edittypeaction'] = 'adminskinedittype'; + $template['default'] = $CONF['AdminSkin']; + } + $query = sprintf($query, sql_table('skin_desc')); + + $template['tabindex'] = 10; + $template['content'] = 'skinlist'; + + $skin_list = showlist($query, 'table', $template, $template_name); + $this->parser->parse($skin_list); + + return; + } + + /** + * AdminActions::parse_skintypehelp() + * Check editing skintypehelp + * + * @param void + * @return void + */ + public function parse_skintypehelp() + { + $surrent_skin_type = strtolower(trim(requestVar('type'))); + $page_action = strtolower(trim(requestVar('action'))); + if ( in_array($page_action, Admin::$adminskin_actions) ) + { + $normal_types = array_keys(self::$normal_skin_types); + } + else + { + $normal_types = array_keys(Actions::getNormalSkinTypes()); + } + + if ( in_array($surrent_skin_type, $normal_types) ) + { + help('skinpart' . $surrent_skin_type); + } + else + { + help('skinpartspecial'); + } + return; + } + + /** + * AdminActions::parse_specialskinlist() + * Parse skinvar specialskinlist + * + * @param string $template_name name of template to use + * @return void + */ + public function parse_specialskinlist($template_name = '') + { + global $CONF, $manager; + + $template = array(); + + $skinid = intRequestVar('skinid'); + + if ( !in_array($this->skintype, Admin::$adminskin_actions) ) + { + $skin =& $manager->getSkin($skinid); + $template['editaction'] = 'skinedittype'; + $template['removeaction'] = 'skinremovetype'; + } + else + { + $skin =& $manager->getSkin($skinid, 'AdminActions'); + $template['editaction'] = 'adminskinedittype'; + $template['removeaction'] = 'adminskinremovetype'; + } + $normal_types = $skin->getNormalTypes(); + $available_types = $skin->getAvailableTypes(); + + $special_skintypes = array(); + foreach( $available_types as $skintype => $skinname ) + { + if ( !array_key_exists($skintype, $normal_types) ) + { + $special_skintypes[] = array( + 'skintype' => $skintype, + 'skintypename' => $skinname + ); + } + } + + if ( sizeof($special_skintypes) > 0 ) + { + $template['tabindex'] = 75; + $template['skinid'] = $skin->getID(); + $template['skinname'] = $skin->getName(); + $skin_list = showlist($special_skintypes, 'list_specialskinlist', $template, $template_name); + $this->parser->parse($skin_list); + } + else + { + /* TODO: nothing to be shown */ + } + + return; + } + + /** + * AdminActions::parse_sprinttext() + * Parse sprinttext + * + * @param string $which + * @param string $val + * @return void + */ + public function parse_sprinttext($which, $val) + { + if ( !defined($which) ) + { + $base = $which; + } + else + { + $base = constant($which); + } + + if ( preg_match('#[^<|%].*[^%|>]#', $val, $matchies) ) + { + if ( !preg_match('#[(].*[^)]#', $matchies[0], $args) ) + { + $met = 'parse_' . $matchies[0]; + } + else + { + $arg = trim($args[0], '()'); + $met = 'parse_' . substr($matchies[0], 0, strpos($matchies[0], '(')); + } + + if ( method_exists($this, $met) ) + { + $value = call_user_func(array($this, $met), $arg); + } + } + + if ( !isset($value) || empty($value) ) + { + $value = $val; + } + echo sprintf($base, $value); + return; + } + + /** + * AdminActions::parse_systemsettings() + * Parse skinvar systemsettings + * + * @param string $type type of settings for system + * @param string $template_name name of template to use + * @return void + */ + public function parse_systemsettings($type = 'phpinfo', $template_name = '') + { + global $manager, $member, $CONF, $nucleus; + + $member->isAdmin() or Admin::disallow(); + + $enable = _ADMIN_SYSTEMOVERVIEW_ENABLE; + $disable = _ADMIN_SYSTEMOVERVIEW_DISABLE; + + switch ( $type ) + { + case 'phpversion': + echo phpversion(); + break; + case 'sqlserverinfo': + echo DB::getAttribute(PDO::ATTR_SERVER_VERSION); + break; + case 'sqlclientinfo': + echo DB::getAttribute(PDO::ATTR_CLIENT_VERSION); + break; + case 'magicquotesgpc': + echo ini_get('magic_quotes_gpc') ? 'On' : 'Off'; + break; + case 'magicquotesruntime': + echo ini_get('magic_quotes_runtime') ? 'On' : 'Off'; + break; + case 'registerglobals': + echo ini_get('register_globals') ? 'On' : 'Off'; + break; + case 'gdinfo': + $templates = array(); + if ( $template_name ) + { + $templates =& $manager->getTemplate($template_name); + } + if ( !array_key_exists('SYSTEMINFO_GDSETTINGS', $templates) || empty($templates['SYSTEMINFO_GDSETTINGS']) ) + { + $template = "\n" + . "<%key%>\n" + . "<%value%>\n" + . "\n"; + } + else + { + $template = $templates['SYSTEMINFO_GDSETTINGS']; + } + + $gdinfo = gd_info(); + + foreach ( $gdinfo as $key => $value ) + { + if ( is_bool($value) ) + { + $value = $value ? $enable : $disable; + } + else + { + $value = Entity::hsc($value); + } + $data = array( + 'key' => $key, + 'value' => $value, + ); + echo Template::fill($template, $data); + } + break; + case 'modrewrite': + if ( function_exists('apache_get_modules') && in_array('mod_rewrite', apache_get_modules()) ) + { + echo $enable; + } + else + { + ob_start(); + phpinfo(INFO_MODULES); + $im = ob_get_contents(); + ob_end_clean(); + if ( i18n::strpos($im, 'mod_rewrite') !== FALSE ) + { + echo $enable; + } + else + { + echo $disable; + } + } + break; + case 'nucleusversion': + echo getNucleusVersion() / 100 . '(' . $nucleus['version'] . ')'; + break; + case 'nucleuspatchlevel': + echo getNucleusPatchLevel(); + break; + case 'confself': + echo $CONF['Self']; + break; + case 'confitemurl': + echo $CONF['ItemURL']; + break; + case 'alertonheaderssent': + echo $CONF['alertOnHeadersSent'] ? $enable : $disable; + break; + case 'nucleuscodename': + if ( $nucleus['codename'] != '' ) + { + echo ' "' . $nucleus['codename'] . '"'; + } + break; + case 'versioncheckurl': + echo sprintf(_ADMIN_SYSTEMOVERVIEW_VERSIONCHECK_URL, getNucleusVersion(), getNucleusPatchLevel()); + break; + } + return; + } + + /** + * AdminActions::parse_templateoverview() + * Parse skinvar templateoverview + * + * @param string $template_name name of template to use + * @return void + */ + public function parse_templateoverview($template_name = '') + { + if ( !in_array($this->skintype, Admin::$adminskin_actions) ) + { + $query = "SELECT * FROM %s WHERE tdname NOT LIKE 'admin/%%' ORDER BY tdname;"; + $template['deleteaction'] = 'templatedelete'; + $template['editaction'] = 'templateedit'; + $template['cloneaction'] = 'templateclone'; + } + else + { + $query = "SELECT * FROM %s WHERE tdname LIKE 'admin/%%' ORDER BY tdname;"; + $template['deleteaction'] = 'admintemplatedelete'; + $template['editaction'] = 'admintemplateedit'; + $template['cloneaction'] = 'admintemplateclone'; + } + $query = sprintf($query, sql_table('template_desc')); + + $template['tabindex'] = 10; + $template['content'] = 'templatelist'; + + $template_list = showlist($query, 'table', $template, $template_name); + $this->parser->parse($template_list); + + return; + } + + /** + * AdminActions::parse_ticket() + * Parse ticket + * + * @param void + * @return void + */ + public function parse_ticket() + { + global $manager; + $manager->addTicketHidden(); + return; + } + + /** + * AdminActions::parse_versioncheckurl() + * Parse skinvar versioncheckurl + * + * @param void + * @return void + */ + public function parse_versioncheckurl() + { + echo sprintf(_ADMIN_SYSTEMOVERVIEW_VERSIONCHECK_URL, getNucleusVersion(), getNucleusPatchLevel()); + return; + } + + /** + * AdminActions::parse_yrbloglist() + * Parse skinvar yrbloglist + * + * @param string $template_name name of template to use + * @return void + */ + public function parse_yrbloglist($template_name = '') + { + global $member; + $showAll = requestVar('showall'); + + if ( $member->isAdmin() && ($showAll == 'yes') ) + { + // Super-Admins have access to all blogs! (no add item support though) + $query = "SELECT bnumber, bname, 1 as tadmin, burl, bshortname" + . " FROM %s" + . " ORDER BY bnumber;"; + $query = sprintf($query, sql_table('blog')); + } + else + { + $query = "SELECT bnumber, bname, tadmin, burl, bshortname" + . " FROM %s,%s" + . " WHERE tblog=bnumber and tmember=%d" + . " ORDER BY bnumber;"; + $query = sprintf($query, sql_table('blog'), sql_table('team'), (integer) $member->getID()); + } + + $resource = DB::getResult($query); + if ( ($showAll != 'yes') && $member->isAdmin() ) + { + $query = 'SELECT COUNT(*) as result FROM ' . sql_table('blog'); + $total = DB::getValue($query); + + if ( $total > $resource->rowCount() ) + { + echo '

    ' . _OVERVIEW_SHOWALL . '

    '; + } + } + + if ( $resource->rowCount() > 0 ) + { + $template['content'] = 'bloglist'; + $template['superadmin'] = $member->isAdmin(); + + $list_resource_table = showlist($resource, 'table', $template, $template_name); + $this->parser->parse($list_resource_table); + $resource->closeCursor(); + + echo '

    ' . _OVERVIEW_YRDRAFTS . '

    '; + + $query = 'SELECT ititle, inumber, bshortname FROM %s, %s ' + . 'WHERE iauthor=%d AND iblog=bnumber AND idraft=1;'; + $query = sprintf($query, sql_table('item'), sql_table('blog'), (integer) $member->getID()); + + $resource = DB::getResult($query); + if ( $resource->rowCount() > 0 ) + { + $template['content'] = 'draftlist'; + $draft_list = showlist($resource, 'table', $template, $template_name); + $this->parser->parse($draft_list); + } + else + { + echo _OVERVIEW_NODRAFTS; + } + } + else + { + echo _OVERVIEW_NOBLOGS; + } + $resource->closeCursor(); + + return; + } + + /** + * AdminActions::checkCondition() + * Checks conditions for if statements + * + * @param string $field type of <%if%> + * @param string $name property of field + * @param string $value value of property + * @return boolean condition + */ + protected function checkCondition($field, $name='', $value = '') + { + global $CONF, $archiveprevexists, $archivenextexists, $blog, $catid, $itemidnext, $itemidprev, $manager, $member; + + $condition = 0; + switch ( $field ) + { + case 'category': + if ( !$blog ) + { + if ( $blogid ) + { + $blog =& $manager->getBlog($blogid); + } + elseif ( $catid ) + { + $blogid = getBlogIDFromCatID($catid); + $blog =& $manager->getBlog($blogid); + } + elseif ( intRequestVar('catid') ) + { + $catid = intRequestVar('catid'); + $blogid = getBlogIDFromCatID($catid); + $blog =& $manager->getBlog($blogid); + } + else + { + return; + } + } + $condition = ($blog && $this->ifCategory($name, $value)); + break; + case 'loggedin': + $condition = $member->isLoggedIn(); + break; + case 'onteam': + $condition = $member->isLoggedIn() && $this->ifOnTeam($name); + break; + case 'admin': + $condition = $member->isLoggedIn() && $this->ifAdmin($name); + break; + case 'superadmin': + $condition = $member->isLoggedIn() && $member->isAdmin(); + break; + case 'allowloginedit': + $condition = $member->isLoggedIn() && ($CONF['AllowLoginEdit'] || $member->isAdmin()); + break; + case 'nextitem': + $condition = ($itemidnext != ''); + break; + case 'previtem': + $condition = ($itemidprev != ''); + break; + case 'archiveprevexists': + $condition = ($archiveprevexists == true); + break; + case 'archivenextexists': + $condition = ($archivenextexists == true); + break; + case 'skintype': + $condition = (($name == $this->skintype) || ($name == requestVar('action'))); + break; + case 'hasplugin': + $condition = $this->ifHasPlugin($name, $value); + break; + case 'adminaction': + $condition = (Admin::$action == $name); + break; + case 'adminoldaction': + $condition = (Admin::$action == $name); + break; + case 'addresschange': + $condition = ($this->ifAddresscange()); + break; + case 'bechangepass': + $condition = ($this->beChangePassword()); + break; + case 'skincandidates': + $condition = ($this->ifSkincandidates()); + break; + case 'nameclashes': + $condition = Admin::$contents['nameclashes']; + break; + case 'existsnewplugin': + $condition = ($this->existsNewPlugin()); + break; + case 'autosave': + if ( $value == '' ) + { + $value = 1; + } + $condition = (boolean) ($member->getAutosave() == $value); + break; + case 'blogsetting': + if ( $value == '' ) + { + $value = 1; + } + $condition = (Admin::$blog->getSetting($name) == $value); + break; + case 'itemproperty': + if ( $value == '' ) + { + $value = 1; + } + if ( array_key_exists($name, Admin::$contents) ) + { + $condition = (boolean) (Admin::$contents[$name] == $value); + } + break; + default: + $condition = $manager->pluginInstalled("NP_{$field}") && $this->ifPlugin($field, $name, $value); + break; + } + return $condition; + } + + /** + * AdminActions::_ifHasPlugin() + * hasplugin,PlugName + * -> checks if plugin exists + * hasplugin,PlugName,OptionName + * -> checks if the option OptionName from plugin PlugName is not set to 'no' + * hasplugin,PlugName,OptionName=value + * -> checks if the option OptionName from plugin PlugName is set to value + * + * @param string $name name of plugin + * @param string $value + * @return + */ + private function ifHasPlugin($name, $value) + { + global $manager; + $condition = false; + // (pluginInstalled method won't write a message in the actionlog on failure) + if ( $manager->pluginInstalled("NP_{$name}") ) + { + $plugin =& $manager->getPlugin("NP_{$name}"); + if ( $plugin != NULL ) + { + if ( $value == "" ) + { + $condition = true; + } + else + { + list($name2, $value2) = preg_split('#=#', $value, 2); + if ( $value2 == "" && $plugin->getOption($name2) != 'no' ) + { + $condition = true; + } + else if ( $plugin->getOption($name2) == $value2 ) + { + $condition = true; + } + } + } + } + return $condition; + } + + /** + * AdminActions::beChangePassword() + * + * @param void + * @return void + */ + private function beChangePassword() + { + return intRequestVar('bNeedsPasswordChange'); + } + + /** + * AdminActions::ifSkincandidates() + * Checks if a plugin exists and call its doIf function + * + * @param void + * @return void + * @return boolean + */ + private function ifSkincandidates() + { + global $DIR_SKINS; + $candidates = SKINIMPORT::searchForCandidates($DIR_SKINS); + return (count($candidates) > 0); + } + + /** + * AdminActions::ifPlugin() + * Checks if a plugin exists and call its doIf function + * + * @param string $name name of plugin + * @param string $key + * @param string $value + * @return callback + */ + private function ifPlugin($name, $key = '', $value = '') + { + global $manager; + + $plugin =& $manager->getPlugin("NP_{$name}"); + if ( !$plugin ) + { + return; + } + + $params = func_get_args(); + array_shift($params); + + return call_user_func_array(array($plugin, 'doIf'), $params); + } + + /** + * AdminActions::ifCategory() + * Different checks for a category + * + * @param string $key key for information of category + * @param string $value value for information of category + * @return boolean + */ + private function ifCategory($key = '', $value='') + { + global $blog, $catid; + + // when no parameter is defined, just check if a category is selected + if (($key != 'catname' && $key != 'catid') || ($value == '')) + { + return $blog->isValidCategory($catid); + } + + // check category name + if ( $key == 'catname' ) + { + $value = $blog->getCategoryIdFromName($value); + if ($value == $catid) + { + return $blog->isValidCategory($catid); + } + } + + // check category id + if (($key == 'catid') && ($value == $catid)) + { + return $blog->isValidCategory($catid); + } + + return FALSE; + } + + /** + * AdminActions::ifOnTeam() + * Checks if a member is on the team of a blog and return his rights + * + * @param string $blogName name of weblog + * @return boolean + */ + private function ifOnTeam($blogName = '') + { + global $blog, $member, $manager; + + // when no blog found + if ( ($blogName == '') && !is_object($blog) ) + { + return 0; + } + + // explicit blog selection + if ($blogName != '') + { + $blogid = getBlogIDFromName($blogName); + } + + if (($blogName == '') || !$manager->existsBlogID($blogid)) + { + // use current blog + $blogid = $blog->getID(); + } + return $member->teamRights($blogid); + } + + /** + * AdminActions::ifAdmin() + * Checks if a member is admin of a blog + * + * @param string $blogName name of weblog + * @return boolean + */ + private function ifAdmin($blogName = '') + { + global $blog, $member, $manager; + + // when no blog found + if (($blogName == '') && (!is_object($blog))) + { + return 0; + } + + // explicit blog selection + if ($blogName != '') + { + $blogid = getBlogIDFromName($blogName); + } + + if (($blogName == '') || !$manager->existsBlogID($blogid)) + { + // use current blog + $blogid = $blog->getID(); + } + + return $member->isBlogAdmin($blogid); + } + + /** + * AdminActions::ifAddresscange() + * Check e-Mail address is changed + * + * @param void + * @return boolean + */ + private function ifAddresscange() + { + global $manager; + + $key = $this->objAdmin->sessionVar("{$CONF['CookiePrefix']}ackey"); + if ( !$key ) + { + return FALSE; + } + $info = MEMBER::getActivationInfo($key); + if ( !$info ) + { + return FALSE; + } + $mem =& $manager->getMember($info->vmember); + if ( !$mem ) + { + return FALSE; + } + if ( $info->vtype == 'addresschange' ) + { + return TRUE; + } + return FALSE; + } + + /** + * TODO: move + * AdminActions::customHelp() + * shows a link to custom help file + * + * @param string $id + * @param string $tplName + * @param string $url + * @param string $iconURL + * @param string $alt + * @param string $title + * @param $onclick + * + */ + private function customHelp($id, $tplName = '', $url = '', $iconURL = '', $alt = '', $title = '', $onclick = '') + { + echo $this->customHelpHtml($id, $tplName, $url, $iconURL, $alt, $title, $onclick); + } + + /** + * TODO: move + * AdminActions::customHelp() + * shows a link to custom help file + * + * @param string $id + * @param string $tplName + * @param string $url + * @param string $iconURL + * @param string $alt + * @param string $title + * @param $onclick + * + */ + static function customHelplink($id, $tplName = '', $url = '', $title = '', $onclick = '') + { + global $CONF, $manager; + + $templates = array(); + + if ( $tplName ) + { + $templates =& $manager->getTemplate($tplName); + } + + if ( !array_key_exists('ADMIN_CUSTOMHELPLINK_ANCHOR', $templates) || empty($templates['ADMIN_CUSTOMHELPLINK_ANCHOR']) ) + { + $template = "#<%helptarget%>\" title=\"<%title%>\" <%onclick%>>\n"; + } + else + { + $template = $templates['ADMIN_CUSTOMHELPLINK_ANCHOR']; + } + + if ( empty($url) ) + { + $url = $CONF['AdminURL'] . 'documentation/customHelp.html'; + } + + if ( empty($onclick) ) + { + $onclick = 'onclick="if (event && event.preventDefault) event.preventDefault(); return help(this.href);"'; + } + elseif ( preg_match('#^onclick#', $onclick) ) + { + $onclick = $onclick; + } + else + { + $onclick = 'onclick="' . $onclick . '"'; + } + + $data = array( + 'helpurl' => $url, + 'helptarget' => $id, + 'onclick' => $onclick, + 'title' => (isset($title) && !empty($title)) ? $title : _HELP_TT, + ); + return Template::fill($template, $data); + } + + /** + * TODO: move + * AdminActions::customHelpHtml() + */ + private function customHelpHtml($id, $tplName = '', $url = '', $iconURL = '', $alt = '', $title = '', $onclick = '') + { + global $CONF, $manager; + + $templates = array(); + + if ( $tplName ) + { + $templates =& $manager->getTemplate($tplName); + } + if ( !array_key_exists('ADMIN_CUSTOMHELPLINK_ICON', $templates) || !empty($templates['ADMIN_CUSTOMHELPLINK_ICON']) ) + { + $template = "\" <%width%><%height%>alt=\"<%alt%>\" title=\"<%title%>\" />\n"; + } + else + { + $template = $templates['ADMIN_CUSTOMHELPLINK_ICON']; + } + + if ( empty($iconURL) ) + { + $iconURL = $CONF['AdminURL'] . 'documentation/icon-help.gif'; + } + + if ( function_exists('getimagesize') ) + { + $size = getimagesize($iconURL); + $width = 'width="' . $size[0] . '" '; + $height = 'height="' . $size[1] . '" '; + } + + $data = array( + 'iconurl' => $iconURL, + 'width' => $width, + 'height' => $height, + 'alt' => (isset($alt) && !empty($alt)) ? $alt : _HELP_TT, + 'title' => (isset($title) && !empty($title)) ? $title : _HELP_TT, + ); + + $icon = Template::fill($template, $data); + $help = $this->customHelplink($id, $tplName, $url, $title, $onclick); + + return $help . $icon; + } + + /** + * AdminActions::existsNewPlugin() + * Check exists new plugin + * + * @param void + * @return boolean exists or not + */ + private function existsNewPlugin() + { + global $DIR_PLUGINS; + + $query = "SELECT * FROM %s;"; + $query = sprintf($query, sql_table('plugin')); + $res = DB::getResult($query); + + $installed = array(); + foreach( $res as $row ) + { + $installed[] = $row['pfile']; + } + + $files = scandir($DIR_PLUGINS); + + $candidates = array(); + foreach ( $files as $file ) + { + if ( preg_match("#^(NP_.*)\.php$#", $file, $matches) ) + { + if ( !in_array($matches[1], $installed) ) + { + $candidates[] = preg_replace("#^NP_#", "", $matches[1]); + } + } + } + $this->newPlugCandidates = $candidates; + return (count($candidates) > 0); + } + + /** + * AdminActions::pagehead() + * Output admin page head + * + * @param void + * @return void + */ + public function parse_pagehead() + { + global $member, $nucleus, $CONF, $manager; + + /* HTTP 1.1 application for no caching */ + header("Cache-Control: no-cache, must-revalidate"); + header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); + + $content = $this->parser->skin->getContentFromDB('pagehead'); + if ( !$content ) + { + $root_element = 'html'; + $charset = i18n::get_current_charset(); + $locale = preg_replace('#_#', '-', i18n::get_current_locale()); + $xml_version_info = '1.0'; + $formal_public_identifier = '-//W3C//DTD XHTML 1.0 Strict//EN'; + $system_identifier = 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'; + $xhtml_namespace = 'http://www.w3.org/1999/xhtml'; + + $content = "\n" + . "\n" + . "<{$root_element} xmlns=\"{$xhtml_namespace}\" xml:lang=\"{$locale}\" lang=\"{$locale}\">\n" + . "\n" + . "<%sitevar(name)%> - Admin\n" + . "" + . "" + . "" + . "<%extrahead%>" + . "" + . "" + . "
    " + . "
    " + . "

    <%sitevar(name)%>

    " + . "
    " + . "
    " + . "
    " + . "
    " + . "\" />\n" + . "\n" + . "\n" + . "\n" + . "<%extrahead%>\n" + . "\n" + . "\n" + . "\n" + . "
    \n" + . "
    \n" + . "

    <%sitevar(name)%>

    \n" + . "
    \n" + . "
    \n" + . "
    \n" + . "
    \n" + . "<%if(loggedin)%>" + . "<%text(_LOGGEDINAS)%> <%member(yourrealname)%> - index.php?action=logout\"><%text(_LOGOUT)%>
    " + . "index.php?action=overview\"><%text(_ADMINHOME)%> - " + . "<%else%>" + . "index.php?action=showlogin\" title=\"Log in\"><%text(_NOTLOGGEDIN)%>
    " + . "<%endif%>" + . "\"><%text(_YOURSITE)%>
    " + . "(" + . "<%if(superadmin)%>" + . "\" title=\"<%text(_ADMIN_SYSTEMOVERVIEW_VERSIONCHECK_TITLE)%>\"><%version%><%codename%>" + . "<%newestcompare%><%else%><%version%><%codename%>" + . "<%endif%>" + . ")" + . "
    "; + } + + $this->parser->parse($content); + return; + } + + /** + * AdminActionss::pagefoot() + * Output admin page foot include quickmenu + * + * @param void + * @return void + */ + public function parse_pagefoot() + { + global $action, $member, $manager, $blogid; + + $data = array('action' => Admin::$action); + $manager->notify('AdminPrePageFoot', $data); + + $content = $this->parser->skin->getContentFromDB('pagefoot'); + if ( !$content ) + { + $content = "<%if(loggedin)%>" + . "<%ifnot(adminaction,showlogin)%>" + . "

    <%text(_LOGOUT)%>

    " + . "" + . "<%endif%>" + . "<%endif%>" + . "
    " + . "\">Nucleus CMS © 2002- <%date(%Y)%> <%text(_ADMINPAGEFOOT_COPYRIGHT)%>" + . " - \"><%text(_ADMINPAGEFOOT_DONATE)%>" + . "
    " + . "
    " + . "" + . "
    " + . "<%if(loggedin)%>" + . "<%ifnot(adminaction,showlogin)%>" + . "" + . "

    <%text(_QMENU_ADD)%>

    " + . "
    index.php\">" + . "
    " + . "" + . "<%qmenuaddselect(admin/default)%>" + . "
    " + . "
    " + . "

    <%member(yourrealname)%>

    " + . "" + . "<%if(superadmin)%>" + . "

    <%text(_QMENU_MANAGE)%>

    " + . "" + . "

    <%text(_QMENU_LAYOUT)%>

    " + . "" + . "

    <%text(_SKINABLEADMIN_QMENU_LAYOUT)%>

    " + . "" + . "<%endif%>" + . "<%quickmenu(admin/default)%>" + . "<%endif%>" + . "<%elseif(adminaction,activate)%>" + . "

    <%text(_QMENU_ACTIVATE)%>

    " + . "<%text(_QMENU_ACTIVATE_TEXT)%>" + . "<%elseif(adminaction,activatesetpwd)%>" + . "

    <%text(_QMENU_ACTIVATE)%>

    <%text(_QMENU_ACTIVATE_TEXT)%>" + . "<%else%>" + . "

    <%text(_QMENU_INTRO)%>

    <%text(_QMENU_INTRO_TEXT)%>" + . "<%endif%>" + . "
    " + . "" + . "
    " + . "" + . "
    " + . "" + . "" + . "
    " + . "" + . "

    <%benchmark%>

    " + . "" + . ""; + } + + $this->parser->parse($content); + return; + } + /** + * AdminActions::selectBlog() + * Inserts a HTML select element with choices for all blogs to which the user has access + * mode = 'blog' => shows blognames and values are blogids + * mode = 'category' => show category names and values are catids + * + * @param string $name + * @param string $mode + * @param integer $selected + * @param integer $tabindex + * @param integer $showNewCat + * @param integer $iForcedBlogInclude ID for weblog always included + * @param $iForcedBlogInclude + * ID of a blog that always needs to be included, without checking if the + * member is on the blog team (-1 = none) + * @return void + */ + private function selectBlog($name, $mode='blog', $selected = 0, $tabindex = 0, $showNewCat = 0, $iForcedBlogInclude = -1) + { + global $member, $CONF; + + // 0. get IDs of blogs to which member can post items (+ forced blog) + $aBlogIds = array(); + if ( $iForcedBlogInclude != -1 ) + { + $aBlogIds[] = intval($iForcedBlogInclude); + } + + if ( $member->isAdmin() && array_key_exists('ShowAllBlogs', $CONF) && $CONF['ShowAllBlogs'] ) + { + $query = "SELECT bnumber FROM %s ORDER BY bname;"; + $query = sprintf($query, sql_table('blog')); + } + else + { + $query = "SELECT bnumber FROM %s, %s WHERE tblog=bnumber AND tmember=%d;"; + $query = sprintf($query, sql_table('blog'), sql_table('team'), (integer) $member->getID()); + } + + $rblogids = DB::getResult($query); + foreach ( $rblogids as $row ) + { + if ( $row['bnumber'] != $iForcedBlogInclude ) + { + $aBlogIds[] = intval($row['bnumber']); + } + } + + if ( count($aBlogIds) == 0 ) + { + return; + } + + echo "\n"; + return; + } +} diff --git a/nucleus/libs/BAN.php b/nucleus/libs/BAN.php index cd8f8cf..27f7af6 100644 --- a/nucleus/libs/BAN.php +++ b/nucleus/libs/BAN.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD $blogid, + 'iprange' => &$iprange, + 'reason' => &$reason + ); + $manager->notify('PreAddBan', $data); + + $query = 'INSERT INTO %s (blogid, iprange, reason) VALUES (%d, %s, %s)'; + $query = sprintf($query, sql_table('ban'), intval($blogid), DB::quoteValue($iprange), DB::quoteValue($reason)); + $res = DB::execute($query); + + $manager->notify('PostAddBan', $data); + + return $res !== FALSE ? 1 : 0; + } + + /** + * Removes a ban from the banlist (correct iprange is needed as argument) + * Returns 1 on success, 0 on error + */ + public function removeBan($blogid, $iprange) + { + global $manager; + + $data = array( + 'blogid' => $blogid, + 'range' => $iprange + ); + $manager->notify('PreDeleteBan', $data); + + $query = 'DELETE FROM %s WHERE blogid=%d and iprange=%s'; + $query = sprintf($query, sql_table('ban'), intval($blogid), DB::quoteValue($iprange)); + $res = DB::execute($query); + + $manager->notify('PostDeleteBan', $data); + + return $res !== FALSE ? 1 : 0; + } +} + +class BanInfo +{ + public $iprange; + public $message; + + public function __construct($iprange, $message) + { + $this->iprange = $iprange; + $this->message = $message; + return; + } +} +>>>>>>> skinnable-master diff --git a/nucleus/libs/BLOG.php b/nucleus/libs/BLOG.php index f0f91a5..bede7bd 100644 --- a/nucleus/libs/BLOG.php +++ b/nucleus/libs/BLOG.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD blogid = (integer) $id; + $this->readSettings(); + $this->setSelectedCategory($catid); + return; + } + + /** + * Blog::readLog() + * Shows the given amount of items for this blog + * + * @param string $template String representing the template _NAME_ (!) + * @param integer $amountEntries amount of entries to show + * @param integer $startpos offset from where items should be shown (e.g. 5 = start at fifth item) + * @return integer amount of items shown + */ + public function readLog($template, $amountEntries, $offset = 0, $startpos = 0) + { + return $this->readLogAmount($template,$amountEntries,'','',1,1,$offset, $startpos); + } + + /** + * Blog::showArchive() + * Shows an archive for a given month + * + * @param integer $year year + * @param integer $month month + * @param string $template String representing the template name to be used + * @return void + */ + public function showArchive($templatename, $year, $month=0, $day=0) + { + // create extra where clause for select query + if ( $day == 0 && $month != 0 ) + { + $timestamp_start = mktime(0,0,0,$month,1,$year); + // also works when $month==12 + $timestamp_end = mktime(0,0,0,$month+1,1,$year); + } + elseif ( $month == 0 ) + { + $timestamp_start = mktime(0,0,0,1,1,$year); + // also works when $month==12 + $timestamp_end = mktime(0,0,0,12,31,$year); + } + else + { + $timestamp_start = mktime(0,0,0,$month,$day,$year); + $timestamp_end = mktime(0,0,0,$month,$day+1,$year); + } + $extra_query = " and i.itime>=%s and i.itime<%s"; + $extra_query = sprintf($extra_query, DB::formatDateTime($timestamp_start), DB::formatDateTime($timestamp_end)); + + $this->readLogAmount($templatename,0,$extra_query,'',1,1); + return; + } + + /** + * Blog::setSelectedCategory() + * Sets the selected category by id (only when category exists) + * + * @param integer $catid ID for category + * @return void + */ + public function setSelectedCategory($catid) + { + if ( $this->isValidCategory($catid) || (intval($catid) == 0) ) + { + $this->selectedcatid = intval($catid); + } + return; + } + + /** + * Blog::setSelectedCategoryByName() + * Sets the selected category by name + * + * @param string $catname name of category + * @return void + */ + public function setSelectedCategoryByName($catname) + { + $this->setSelectedCategory($this->getCategoryIdFromName($catname)); + return; + } + + /** + * Blog::getSelectedCategory() + * Returns the selected category + * + * @param void + * @return integer + */ + public function getSelectedCategory() + { + return $this->selectedcatid; + } + + /** + * Shows the given amount of items for this blog + * + * @param string $template string representing the template _NAME_ (!) + * @param integer $amountEntries amount of entries to show (0 = no limit) + * @param string $extraQuery extra conditions to be added to the query + * @param string $highlight contains a query that should be highlighted + * @param integer $comments 1=show comments 0=don't show comments + * @param integer $dateheads 1=show dateheads 0=don't show dateheads + * @param integer $offset offset + * @return integer amount of items shown + */ + private function readLogAmount($template, $amountEntries, $extraQuery, $highlight, $comments, $dateheads, $offset = 0, $startpos = 0) + { + $query = $this->getSqlBlog($extraQuery); + + if ( $amountEntries > 0 ) + { + // $offset zou moeten worden: + // (($startpos / $amountentries) + 1) * $offset ... later testen ... + $query .= ' LIMIT ' . intval($startpos + $offset).',' . intval($amountEntries); + } + return $this->showUsingQuery($template, $query, $highlight, $comments, $dateheads); + } + + /** + * Blog::showUsingQuery() + * Do the job for readLogAmmount + * + * @param string $templateName template name + * @param string $query string for query + * @param string $highlight string to be highlighted + * @param integer $comments the number of comments + * @param boolean $dateheads date header is needed or not + * @return integer the number of rows as a result of mysql query + */ + private function showUsingQuery($templateName, $query, $highlight = '', $comments = 0, $dateheads = 1) + { + global $CONF, $manager, $currentTemplateName; + + $lastVisit = cookieVar($CONF['CookiePrefix'] .'lastVisit'); + if ( $lastVisit != 0 ) + { + $lastVisit = $this->getCorrectTime($lastVisit); + } + + // set templatename as global variable (so plugins can access it) + $currentTemplateName = $templateName; + $template =& $manager->getTemplate($templateName); + + // create parser object & action handler + $handler = new ItemActions($this); + $handler->setTemplate($template); + $handler->setHighlight($highlight); + $handler->setLastVisit($lastVisit); + $handler->setShowComments($comments); + + $parser = new Parser($handler); + + // execute query + $items = DB::getResult($query); + + // loop over all items + $old_date = 0; + foreach ( $items as $item ) + { + // string timestamp -> unix timestamp + $item['timestamp'] = strtotime($item['itime']); + + // action handler needs to know the item we're handling + $handler->setCurrentItem($item); + + // add date header if needed + if ( $dateheads ) + { + $new_date = date('dFY', $item['timestamp']); + if ( $new_date != $old_date ) + { + // unless this is the first time, write date footer + $timestamp = $item['timestamp']; + if ( $old_date != 0 ) + { + $oldTS = strtotime($old_date); + $data = array('blog' => &$this, 'timestamp' => $oldTS); + $manager->notify('PreDateFoot', $data); + + if ( !in_array('DATE_FOOTER', $template) || empty($template['DATE_FOOTER']) ) + { + $tmp_footer = ''; + } + else + { + $tmp_footer = i18n::formatted_datetime($template['DATE_FOOTER'], $oldTS); + } + $parser->parse($tmp_footer); + $manager->notify('PostDateFoot', $data); + } + + $data = array('blog' => &$this, 'timestamp' => $timestamp); + $manager->notify('PreDateHead', $data); + + // note, to use templatvars in the dateheader, the %-characters need to be doubled in + // order to be preserved by strftime + if ( !in_array('DATE_HEADER', $template) || empty($template['DATE_HEADER']) ) + { + $tmp_header = ''; + } + else + { + $tmp_header = i18n::formatted_datetime($template['DATE_HEADER'], $timestamp); + } + $parser->parse($tmp_header); + $manager->notify('PostDateHead', $data); + } + $old_date = $new_date; + } + + // parse item + $parser->parse($template['ITEM_HEADER']); + $data = array('blog' => &$this, 'item' => &$item); + $manager->notify('PreItem', $data); + $parser->parse($template['ITEM']); + $manager->notify('PostItem', $data); + $parser->parse($template['ITEM_FOOTER']); + } + + $numrows = $items->rowCount(); + + // add another date footer if there was at least one item + if ( ($numrows > 0) && $dateheads ) + { + $data = array('blog' => &$this, 'timestamp' => strtotime($old_date)); + $manager->notify('PreDateFoot', $data); + $parser->parse($template['DATE_FOOTER']); + $manager->notify('PostDateFoot', $data); + } + + $items->closeCursor(); + return $numrows; + } + + /** + * Blog::showOneitem() + * Simplified function for showing only one item + * + * @param integer $itemid ID for item + * @param array $template template for item + * @param string $highlight string for highlight + * @return integer 1 + */ + public function showOneitem($itemid, $template, $highlight) + { + $extraQuery = ' and inumber=' . intval($itemid); + + return $this->readLogAmount($template, 1, $extraQuery, $highlight, 0, 0); + } + + /** + * Blog::addItem() + * Adds an item to this blog + * + * @param integer $catid ID for category + * @param string $title ID for + * @param string $body text for body + * @param string $more text for more + * @param integer $blogid ID for blog + * @param integer $authorid ID for author + * @param timestamp $timestamp UNIX timestamp for post + * @param boolean $closed opened or closed + * @param boolean $draft draft or not + * @param boolean $posted posted or not + * @return integer ID for added item + */ + function additem($catid, $title, $body, $more, $blogid, $authorid, $timestamp, $closed, $draft, $posted='1') + { + global $manager; + + $blogid = (integer) $blogid; + $authorid = (integer) $authorid; + $title = $title; + $body = $body; + $more = $more; + $catid = intval($catid); + + // convert newlines to
    + if ( $this->convertBreaks() ) + { + $body = addBreaks($body); + $more = addBreaks($more); + } + + if ( $closed != '1' ) + { + $closed = '0'; + } + if ( $draft != '0' ) + { + $draft = '1'; + } + + if ( !$this->isValidCategory($catid) ) + { + $catid = $this->getDefaultCategory(); + } + + $isFuture = 0; + if ( $timestamp > $this->getCorrectTime() ) + { + $isFuture = 1; + } + + $timestamp = date('Y-m-d H:i:s',$timestamp); + + $data = array('title' => &$title, 'body' => &$body, 'more' => &$more, 'blog' => $this, 'authorid' => &$authorid, 'timestamp' => &$timestamp, 'closed' => &$closed, 'draft' => &$draft, 'catid' => &$catid); + $manager->notify('PreAddItem', $data); + + $ititle = DB::quoteValue($title); + $ibody = DB::quoteValue($body); + $imore = DB::quoteValue($more); + $timestamp = DB::formatDateTime(strtotime($timestamp)); + + $query = "INSERT INTO %s (ITITLE, IBODY, IMORE, IBLOG, IAUTHOR, ITIME, ICLOSED, IDRAFT, ICAT, IPOSTED) VALUES (%s, %s, %s, %d, %d, %s, %s, %s, %s, %s)"; + $query = sprintf($query, sql_table('item'), $ititle, $ibody, $imore, $blogid, $authorid, $timestamp, $closed, $draft, $catid, $posted); + DB::execute($query); + $itemid = DB::getInsertId(); + + $data = array('itemid' => $itemid); + $manager->notify('PostAddItem', $data); + + if ( !$draft ) + { + $this->updateUpdateFile(); + } + // send notification mail + if ( !$draft && !$isFuture && $this->getNotifyAddress() && $this->notifyOnNewItem() ) + { + $this->sendNewItemNotification($itemid, $title, $body); + } + return $itemid; + } + + /** + * Blog::sendNewItemNotification() + * Send a new item notification to the notification list + * + * @param string $itemid ID of the item + * @param string $title title of the item + * @param string $body body of the item + * @return void + */ + public function sendNewItemNotification($itemid, $title, $body) + { + global $CONF, $member; + + $ascii = Entity::anchor_footnoting($body); + + $message = _NOTIFY_NI_MSG . " \n"; + $temp = parse_url($CONF['Self']); + if ( $temp['scheme'] ) + { + $message .= Link::create_item_link($itemid) . "\n\n"; + } + else + { + $tempurl = $this->getURL(); + if ( i18n::substr($tempurl, -1) == '/' || i18n::substr($tempurl, -4) == '.php' ) + { + $message .= $tempurl . '?itemid=' . $itemid . "\n\n"; + } + else + { + $message .= $tempurl . '/?itemid=' . $itemid . "\n\n"; + } + } + $message .= _NOTIFY_TITLE . ' ' . strip_tags($title) . "\n"; + $message .= _NOTIFY_CONTENTS . "\n " . $ascii . "\n"; + $message .= NOTIFICATION::get_mail_footer(); + + $subject = $this->getName() . ': ' . _NOTIFY_NI_TITLE; + + $from = $member->getNotifyFromMailAddress(); + + NOTIFICATION::mail($this->getNotifyAddress(), $subject, $message, $from, i18n::get_current_charset()); + return; + } + + /** + * Blog::createNewCategory() + * Creates a new category for this blog + * + * @param string $catName name of the new category. When empty, a name is generated automatically (starting with newcat) + * @param string $catDescription description of the new category. Defaults to 'New Category' + * @return integer ID for new category on success. 0 on failure + */ + public function createNewCategory($catName = '', $catDescription = _CREATED_NEW_CATEGORY_DESC) + { + global $member, $manager; + + if ( !$member->blogAdminRights($this->blogid) ) + { + return 0; + } + + // generate + if ( $catName == '' ) + { + $catName = _CREATED_NEW_CATEGORY_NAME; + $i = 1; + + $res = DB::getResult('SELECT * FROM '.sql_table('category')." WHERE cname='".$catName.$i."' and cblog=".$this->blogid); + while ( $res->rowCount() > 0 ) + { + $i++; + $res = DB::getResult('SELECT * FROM '.sql_table('category')." WHERE cname='".$catName.$i."' and cblog=".$this->blogid); + } + + $catName = $catName . $i; + } + + $data = array( + 'blog' => &$this, + 'name' => &$catName, + 'description' => $catDescription + ); + $manager->notify('PreAddCategory', $data); + + $query = "INSERT INTO %s (cblog, cname, cdesc) VALUES (%d, %s, %s)"; + $query = sprintf($query, sql_table('category'), (integer) $this->blogid, DB::quoteValue($catName), DB::quoteValue($catDescription)); + DB::execute($query); + $catid = DB::getInsertId(); + + $data = array( + 'blog' => &$this, + 'name' => $catName, + 'description' => $catDescription, + 'catid' => $catid + ); + $manager->notify('PostAddCategory', $data); + + return $catid; + } + + /** + * Blog::search() + * Searches all months of this blog for the given query + * + * @param string $query search query + * @param array $template template to be used (__NAME__ of the template) + * @param integer $amountMonths max amount of months to be search (0 = all) + * @param integer $maxresults max number of results to show + * @param integer $startpos offset + * @return amount of hits found + */ + public function search($query, $template, $amountMonths, $maxresults, $startpos) { + global $CONF, $manager; + + $highlight = ''; + $sqlquery = $this->getSqlSearch($query, $amountMonths, $highlight); + + if ( $sqlquery == '' ) + { + // no query -> show everything + $extraquery = ''; + $amountfound = $this->readLogAmount($template, $maxresults, $extraQuery, $query, 1, 1); + } + else + { + // add LIMIT to query (to split search results into pages) + if ( intval($maxresults > 0) ) + { + $sqlquery .= ' LIMIT ' . intval($startpos) . ',' . intval($maxresults); + } + + // show results + $amountfound = $this->showUsingQuery($template, $sqlquery, $highlight, 1, 1); + + // when no results were found, show a message + if ( $amountfound == 0 ) + { + $template =& $manager->getTemplate($template); + $vars = array( + 'query' => Entity::hsc($query), + 'blogid' => $this->blogid + ); + echo Template::fill($template['SEARCH_NOTHINGFOUND'], $vars); + } + } + return $amountfound; + } + + /** + * Blog::getSqlSearch() + * Returns an SQL query to use for a search query + * No LIMIT clause is added. (caller should add this if multiple pages are requested) + * + * @param string $query search query + * @param integer $amountMonths amount of months to search back. Default = 0 = unlimited + * @param string $mode either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query + * @return string $highlight words to highlight (out parameter) + * @return string either a full SQL query, or an empty string (if querystring empty) + */ + public function getSqlSearch($query, $amountMonths = 0, &$highlight, $mode = '') + { + $searchclass = new Search($query); + + $highlight = $searchclass->inclusive; + + // if querystring is empty, return empty string + if ( $searchclass->inclusive == '' ) + { + return ''; + } + + $where = $searchclass->boolean_sql_where('ititle,ibody,imore'); + $select = $searchclass->boolean_sql_select('ititle,ibody,imore'); + + // get list of blogs to search + $blogs = $searchclass->blogs; // array containing blogs that always need to be included + $blogs[] = $this->blogid; // also search current blog (duh) + $blogs = array_unique($blogs); // remove duplicates + $selectblogs = ''; + if ( count($blogs) > 0 ) + { + $selectblogs = ' and i.iblog in (' . implode(',', $blogs) . ')'; + } + + if ( $mode == '' ) + { + $query = 'SELECT i.inumber as itemid, i.ititle as title, i.ibody as body, i.itime, i.imore as more, i.icat as catid, i.iclosed as closed, + m.mname as author, m.mrealname as authorname, m.mnumber as authorid, m.memail as authormail, m.murl as authorurl, + c.cname as category'; + + if ( $select ) + { + $query .= ', '.$select. ' as score '; + } + } + else + { + $query = 'SELECT COUNT(*) as result '; + } + + $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c' + . ' WHERE i.iauthor=m.mnumber' + . ' and i.icat=c.catid' + // exclude drafts + . ' and i.idraft=0' + . $selectblogs + // don't show future items + . ' and i.itime<=' . DB::formatDateTime($this->getCorrectTime()) + . ' and '.$where; + + // take into account amount of months to search + if ( $amountMonths > 0 ) + { + $localtime = getdate($this->getCorrectTime()); + $timestamp_start = mktime(0,0,0,$localtime['mon'] - $amountMonths,1,$localtime['year']); + $query .= ' and i.itime>' . DB::formatDateTime($timestamp_start); + } + + if ( $mode == '' ) + { + if ( $select ) + { + $query .= ' ORDER BY score DESC'; + } + else + { + $query .= ' ORDER BY i.itime DESC '; + } + } + + return $query; + } + + /** + * Blog::getSqlBlog() + * Returns the SQL query that's normally used to display the blog items on the index type skins + * No LIMIT clause is added. (caller should add this if multiple pages are requested) + * + * @param string $extraQuery extra query string + * @param string $mode either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query + * @return string either a full SQL query, or an empty string + */ + public function getSqlBlog($extraQuery, $mode = '') + { + if ( $mode == '' ) + { + $query = 'SELECT i.inumber as itemid, i.ititle as title, i.ibody as body, m.mname as author, + m.mrealname as authorname, i.itime, i.imore as more, m.mnumber as authorid, m.memail as authormail, + m.murl as authorurl, c.cname as category, i.icat as catid, i.iclosed as closed'; + } + else + { + $query = 'SELECT COUNT(*) as result '; + } + + $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c' + . ' WHERE i.iblog='.$this->blogid + . ' and i.iauthor=m.mnumber' + . ' and i.icat=c.catid' + . ' and i.idraft=0' // exclude drafts + . ' and i.itime<=' . DB::formatDateTime($this->getCorrectTime()); // don't show future items + + if ( $this->selectedcatid ) + { + $query .= ' and i.icat=' . $this->selectedcatid . ' '; + } + + $query .= $extraQuery; + + if ( $mode == '' ) + { + $query .= ' ORDER BY i.itime DESC'; + } + return $query; + } + + /** + * Blog::showArchiveList() + * Shows the archivelist using the given template + * + * @param string $template template name + * @param string $mode year/month/day + * @param integer $limit limit of record count + * @return void + */ + public function showArchiveList($template, $mode = 'month', $limit = 0) + { + global $CONF, $catid, $manager; + + if ( !isset ($linkparams) ) + { + $linkparams = array(); + } + + if ( $catid ) + { + $linkparams = array('catid' => $catid); + } + + $template =& $manager->getTemplate($template); + $listitem['blogid'] = $this->blogid; + + if ( !array_key_exists('ARCHIVELIST_HEADER', $template) || !$template['ARCHIVELIST_HEADER'] ) + { + $tplt = ''; + } + else + { + $tplt = $template['ARCHIVELIST_HEADER']; + } + + echo Template::fill($tplt, $listitem); + + $query = 'SELECT itime, SUBSTRING(itime,1,4) AS Year, SUBSTRING(itime,6,2) AS Month, SUBSTRING(itime,9,2) AS Day' + . ' FROM '.sql_table('item') + . ' WHERE iblog=' . $this->blogid + . ' AND itime <=' . DB::formatDateTime($this->getCorrectTime()) // don't show future items! + . ' AND idraft=0'; // don't show draft items + + if ( $catid ) + { + $query .= ' and icat=' . intval($catid); + } + + $query .= ' GROUP BY Year'; + if ( $mode == 'month' || $mode == 'day' ) + { + $query .= ', Month'; + } + if ( $mode == 'day' ) + { + $query .= ', Day'; + } + + $query .= ' ORDER BY itime DESC'; + + if ( $limit > 0 ) + { + $query .= ' LIMIT ' . intval($limit); + } + + $res = DB::getResult($query); + foreach ( $res as $current ) + { + /* string time -> unix timestamp */ + $current['itime'] = strtotime($current['itime']); + + if ( $mode == 'day' ) + { + $archivedate = date('Y-m-d',$current['itime']); + $archive['day'] = date('d',$current['itime']); + $listitem['day'] = date('d',$current['itime']); + $listitem['month'] = date('m',$current['itime']); + $archive['month'] = $listitem['month']; + } + elseif ( $mode == 'year' ) + { + $archivedate = date('Y',$current['itime']); + $listitem['day'] = ''; + $listitem['month'] = ''; + $archive['day'] = ''; + $archive['month'] = ''; + } + else + { + $archivedate = date('Y-m',$current['itime']); + $listitem['month'] = date('m',$current['itime']); + $archive['month'] = $listitem['month']; + $listitem['day'] = ''; + $archive['day'] = ''; + } + + $listitem['year'] = date('Y',$current['itime']); + $archive['year'] = $listitem['year']; + $listitem['archivelink'] = Link::create_archive_link($this->blogid,$archivedate,$linkparams); + + $data = array('listitem' => &$listitem); + $manager->notify('PreArchiveListItem', $data); + + $temp = Template::fill($template['ARCHIVELIST_LISTITEM'],$listitem); + echo i18n::formatted_datetime($temp, $current['itime']); + return; + } + + $res->closeCursor(); + + if ( !array_key_exists('ARCHIVELIST_FOOTER', $template) || !$template['ARCHIVELIST_FOOTER'] ) + { + $tplt = ''; + } + else + { + $tplt = $template['ARCHIVELIST_FOOTER']; + } + + echo Template::fill($tplt, $listitem); + return; + } + + /** + * Blog::showCategoryList() + * Shows the list of categories using a given template + * + * @param string $template Template Name + * @return void + */ + public function showCategoryList($template) + { + global $CONF, $archive, $archivelist, $manager; + + /* + * determine arguments next to catids + * I guess this can be done in a better way, but it works + */ + $linkparams = array(); + if ( $archive ) + { + $blogurl = Link::create_archive_link($this->blogid, $archive, ''); + $linkparams['blogid'] = $this->blogid; + $linkparams['archive'] = $archive; + } + else if ( $archivelist ) + { + $blogurl = Link::create_archivelist_link($this->blogid, ''); + $linkparams['archivelist'] = $archivelist; + } + else + { + $blogurl = Link::create_blogid_link($this->blogid, ''); + $linkparams['blogid'] = $this->blogid; + } + + $template =& $manager->getTemplate($template); + + //: Change: Set nocatselected variable + if ( $this->selectedcatid ) + { + $nocatselected = 'no'; + } + else + { + $nocatselected = 'yes'; + } + + $args = array( + 'blogid' => $this->blogid, + 'blogurl' => $blogurl, + 'self' => $CONF['Self'], + 'catiscurrent' => $nocatselected, // Change: Set catiscurrent template variable for header + 'currentcat' => $nocatselected + ); + + /* output header of category list item */ + if ( !array_key_exists('CATLIST_HEADER', $template) || empty($template['CATLIST_HEADER']) ) + { + echo Template::fill(NULL, $args); + } + else + { + echo Template::fill($template['CATLIST_HEADER'], $args); + } + + $query = "SELECT catid, cdesc as catdesc, cname as catname FROM %s WHERE cblog=%d ORDER BY cname ASC;"; + $query = sprintf($query, sql_table('category'), (integer) $this->blogid); + $res = DB::getResult($query); + + foreach ( $res as $row ) + { + $args = array( + 'catid' => $row['catid'], + 'name' => $row['catname'], + 'extra' => $linkparams + ); + + $row['blogid'] = $this->blogid; + $row['blogurl'] = $blogurl; + $row['catlink'] = Link::create_link('category', $args); + $row['self'] = $CONF['Self']; + + // this gives catiscurrent = no when no category is selected. + $row['catiscurrent'] = 'no'; + $row['currentcat'] = 'no'; + + if ( $this->selectedcatid ) + { + if ( $this->selectedcatid == $row['catid'] ) + { + $row['catiscurrent'] = 'yes'; + $row['currentcat'] = 'yes'; + } + } + else + { + global $itemid; + if ( (integer) $itemid && $manager->existsItem((integer) $itemid, 0, 0) ) + { + $iobj =& $manager->getItem($itemid, 0, 0); + $cid = $iobj['catid']; + + if ( $cid == $row['catid'] ) + { + $row['catiscurrent'] = 'yes'; + $row['currentcat'] = 'yes'; + } + } + } + + $data = array('listitem' => &$row); + $manager->notify('PreCategoryListItem', $data); + + if ( !array_key_exists('CATLIST_LISTITEM', $template) || empty($template['CATLIST_LISTITEM'])) + { + echo Template::fill(NULL, $row); + } + else + { + echo Template::fill($template['CATLIST_LISTITEM'], $row); + } + } + + $res->closeCursor(); + + $args = array( + 'blogid' => $this->blogid, + 'blogurl' => $blogurl, + 'self' => $CONF['Self'], + 'catiscurrent' => $nocatselected, //: Change: Set catiscurrent template variable for footer + 'currentcat' => $nocatselected + ); + + if ( !array_key_exists('CATLIST_FOOTER', $template) || empty($template['CATLIST_FOOTER'])) + { + echo Template::fill(NULL, $args); + } + else + { + echo Template::fill($template['CATLIST_FOOTER'], $args); + } + + return; + } + + /** + * Blog::showBlogList() + * Shows a list of all blogs in the system using a given template + * ordered by number, name, shortname or description + * in ascending or descending order + * + * @param string $template tempalte name + * @param string $bnametype bname/bshortname + * @param string $orderby string for 'ORDER BY' SQL + * @param string $direction ASC/DESC + * @return void + */ + static public function showBlogList($template, $bnametype, $orderby, $direction) + { + global $CONF, $manager; + + switch ( $orderby ) + { + case 'number': + $orderby='bnumber'; + break; + case 'name': + $orderby='bname'; + break; + case 'shortname': + $orderby='bshortname'; + break; + case 'description': + $orderby='bdesc'; + break; + default: + $orderby='bnumber'; + break; + } + + $direction=strtolower($direction); + switch ( $direction ) + { + case 'asc': + $direction='ASC'; + break; + case 'desc': + $direction='DESC'; + break; + default: + $direction='ASC'; + break; + } + + $template =& $manager->getTemplate($template); + + if ( array_key_exists('BLOGLIST_HEADER', $template) && !empty($template['BLOGLIST_HEADER']) ) + { + $vars = array( + 'sitename' => $CONF['SiteName'], + 'siteurl' => $CONF['IndexURL'] + ); + + echo Template::fill($template['BLOGLIST_HEADER'], $vars); + } + + if ( array_key_exists('BLOGLIST_LISTITEM', $template) && !empty($template['BLOGLIST_LISTITEM']) ) + { + $query = 'SELECT bnumber, bname, bshortname, bdesc, burl FROM '.sql_table('blog').' ORDER BY '.$orderby.' '.$direction; + $res = DB::getResult($query); + + foreach ( $res as $row ) + { + $list = array(); + $list['bloglink'] = Link::create_blogid_link($row['bnumber']); + $list['blogdesc'] = $row['bdesc']; + $list['blogurl'] = $row['burl']; + + if ( $bnametype == 'shortname' ) + { + $list['blogname'] = $row['bshortname']; + } + else + { + /* all other cases */ + $list['blogname'] = $row['bname']; + } + + $data = array('listitem' => &$list); + $manager->notify('PreBlogListItem', $data); + + echo Template::fill($template['BLOGLIST_LISTITEM'], $list); + } + + $res->closeCursor(); + } + + + if ( array_key_exists('BLOGLIST_FOOTER', $template) && !empty($template['BLOGLIST_FOOTER']) ) + { + $vars = array( + 'sitename' => $CONF['SiteName'], + 'siteurl' => $CONF['IndexURL'] + ); + echo Template::fill($template['BLOGLIST_FOOTER']); + } + return; + } + + /** + * Blog::readSettings() + * Read the blog settings + * + * @param void + * @return void + */ + public function readSettings() + { + $query = 'SELECT * FROM %s WHERE bnumber=%d;'; + $query = sprintf($query, sql_table('blog'), (integer) $this->blogid); + $res = DB::getResult($query); + + $this->isValid = ($res->rowCount() > 0); + if ( $this->isValid ) + { + $this->settings = $res->fetch(PDO::FETCH_ASSOC); + } + return; + } + + /** + * Blog::writeSettings() + * Write the blog settings + */ + public function writeSettings() + { + // (can't use floatval since not available prior to PHP 4.2) + $offset = $this->getTimeOffset(); + if ( !is_float($offset) ) + { + $offset = (integer) $offset; + } + + $query = 'UPDATE '.sql_table('blog') + . ' SET bname=' . DB::quoteValue($this->getName()) . ',' + . ' bshortname='. DB::quoteValue($this->getShortName()) . ',' + . ' bcomments='. intval($this->commentsEnabled()) . ',' + . ' bmaxcomments=' . intval($this->getMaxComments()) . ',' + . ' btimeoffset=' . $offset . ',' + . ' bpublic=' . intval($this->isPublic()) . ',' + . ' breqemail=' . intval($this->emailRequired()) . ',' + . ' bconvertbreaks=' . intval($this->convertBreaks()) . ',' + . ' ballowpast=' . intval($this->allowPastPosting()) . ',' + . ' bnotify=' . DB::quoteValue($this->getNotifyAddress()) . ',' + . ' bnotifytype=' . intval($this->getNotifyType()) . ',' + . ' burl=' . DB::quoteValue($this->getURL()) . ',' + . ' bupdate=' . DB::quoteValue($this->getUpdateFile()) . ',' + . ' bdesc=' . DB::quoteValue($this->getDescription()) . ',' + . ' bdefcat=' . intval($this->getDefaultCategory()) . ',' + . ' bdefskin=' . intval($this->getDefaultSkin()) . ',' + . ' bincludesearch=' . intval($this->getSearchable()) + . ' WHERE bnumber=' . intval($this->blogid); + DB::execute($query); + return; + } + + /** + * Blog::updateUpdatefile() + * Update the update file if requested + * + * @param void + * @return void + */ + public function updateUpdatefile() + { + if ( $this->getUpdateFile() ) + { + $f_update = fopen($this->getUpdateFile(), 'w'); + fputs($f_update,$this->getCorrectTime()); + fclose($f_update); + } + return; + } + + /** + * Blog::isValidCategory() + * Check if a category with a given catid is valid + * + * @param integer $catid ID for category + * @return boolean exists or not + */ + public function isValidCategory($catid) + { + $query = 'SELECT * FROM %s WHERE cblog=%d and catid=%d;'; + $query = sprintf($query, sql_table('category'), (integer) $this->blogid, (integer) $catid); + $res = DB::getResult($query); + return ($res->rowCount() != 0); + } + + /** + * Blog::getCategoryName() + * Get the category name for a given catid + * + * @param integer $catid ID for category + * @return string name of category + */ + public function getCategoryName($catid) + { + $query = 'SELECT cname FROM %s WHERE cblog=%d and catid=%d;'; + $query = sprintf($query, sql_table('category'), (integer) $this->blogid, (integer) $catid); + $res = DB::getValue($query); + return $res; + } + + /** + * Blog::getCategoryDesc() + * Get the category description for a given catid + * + * @param $catid + * category id + */ + public function getCategoryDesc($catid) + { + $query = 'SELECT cdesc FROM %s WHERE cblog=%d and catid=%d;'; + $query = sprintf($query, sql_table('category'), (integer) $this->blogid, (integer) $catid); + $res = DB::getValue($query); + return $res; + } + + /** + * Blog::getCategoryIdFromName + * Get the category id for a given category name + * + * @param string $name category name + * @return ID for category + */ + public function getCategoryIdFromName($name) + { + $query = 'SELECT catid FROM %s WHERE cblog=%d and cname=%s;'; + $query = sprintf($query, sql_table('category'), (integer) $this->blogid, DB::quoteValue($name)); + + $res = DB::getValue(); + if ( !$res ) + { + return $this->getDefaultCategory(); + } + return $res; + } + + /** + * Blog::insertJavaScriptInfo() + * Insert a javascript that includes information about the settings + * of an author: ConvertBreaks, MediaUrl and AuthorId + * + * @param $authorid id of the author + */ + public function insertJavaScriptInfo($authorid = '') + { + global $member, $CONF; + + if ( $authorid == '' ) + { + $authorid = $member->getID(); + } + + echo "\n"; + return; + } + + /** + * Blog::setAllowPastPosting() + * Set the the setting for allowing to publish postings in the past + * + * @param boolean $val new value for ballowpast + * @return void + */ + public function setAllowPastPosting($val) + { + $this->setSetting('ballowpast', $val); + return; + } + + /** + * Blog::allowPastPosting() + * Get the the setting if it is allowed to publish postings in the past + * [should be named as getAllowPastPosting()] + * + * @param void + * @return boolean + */ + public function allowPastPosting() + { + return $this->getSetting('ballowpast'); + } + + /** + * Blog::getCorrectTime() + * + * @param integer $t + * @return integer + */ + public function getCorrectTime($t=0) + { + if ( $t == 0 ) + { + $t = time(); + } + return ($t + 3600 * $this->getTimeOffset()); + } + + /** + * Blog::getName() + * + * @param void + * @return string name of this weblog + */ + public function getName() + { + return $this->getSetting('bname'); + } + + /** + * Blog::getShortName() + * + * @param void + * @return string short name of this weblog + */ + public function getShortName() + { + return $this->getSetting('bshortname'); + } + + /** + * Blog::getMaxComments() + * + * @param void + * @return integer maximum number of comments + */ + public function getMaxComments() + { + return $this->getSetting('bmaxcomments'); + } + + /** + * Blog::getNotifyAddress() + * + * @param void + * @return string mail address for notifying + */ + public function getNotifyAddress() + { + return $this->getSetting('bnotify'); + } + + /** + * Blog::getNotifyType() + * + * @param void + * @return integer notifycation type + */ + public function getNotifyType() + { + return $this->getSetting('bnotifytype'); + } + + /** + * Blog::notifyOnComment() + * + * @param void + * @return boolean + */ + public function notifyOnComment() + { + $n = $this->getNotifyType(); + return (($n != 0) && (($n % 3) == 0)); + } + + /** + * Blog::notifyOnVote() + * + * @param void + * @return boolean + */ + public function notifyOnVote() + { + $n = $this->getNotifyType(); + return (($n != 0) && (($n % 5) == 0)); + } + + /** + * Blog::notifyOnNewItem() + * + * @param void + * @return boolean + */ + public function notifyOnNewItem() + { + $n = $this->getNotifyType(); + return (($n != 0) && (($n % 7) == 0)); + } + + /** + * Blog::setNotifyType() + * + * @param integer $val + * @return void + */ + public function setNotifyType($val) + { + $this->setSetting('bnotifytype',$val); + return; + } + + /** + * Blog::getTimeOffset() + * @param void + * @return + */ + public function getTimeOffset() + { + return $this->getSetting('btimeoffset'); + } + + /** + * Blog::commentsEnabled() + * @param void + * @return integer enabled or not + */ + public function commentsEnabled() + { + return $this->getSetting('bcomments'); + } + + /** + * Blog::getURL() + * @param void + * @return string URI for this weblog + */ + public function getURL() + { + return $this->getSetting('burl'); + } + + /** + * Blog::getDefaultSkin() + * @param void + * @return name of skin as default for this weblog + */ + public function getDefaultSkin() + { + return $this->getSetting('bdefskin'); + } + + /** + * Blog::getUpdateFile() + * @param void + * @return string name of file to be updated when weblog is updated + */ + public function getUpdateFile() + { + return $this->getSetting('bupdate'); + } + + /** + * Blog::getDescription() + * @param void + * @return string description for this weblog + */ + public function getDescription() + { + return $this->getSetting('bdesc'); + } + + /** + * Blog::isPublic() + * @param void + * @return integer publlic or not + */ + public function isPublic() + { + return $this->getSetting('bpublic'); + } + + /** + * Blog::emailRequired() + * @param void + * @return integer email is required when posting comment or not + */ + public function emailRequired() + { + return $this->getSetting('breqemail'); + } + + /** + * Blog::getSearchable() + * @param void + * @return integer searchable or not + */ + public function getSearchable() + { + return $this->getSetting('bincludesearch'); + } + + /** + * Blog::getDefaultCategory() + * @param void + * @return ID for category as a default + */ + public function getDefaultCategory() + { + return $this->getSetting('bdefcat'); + } + + /** + * Blog::setPublic() + * @param integer $val allow comments by non-registered members or not + * @return void + */ + public function setPublic($val) + { + $this->setSetting('bpublic', $val); + return; + } + + /** + * Blog::setSearchable() + * @param integer $val searchable from the other blogs or not + * @return void + */ + public function setSearchable($val) + { + $this->setSetting('bincludesearch', $val); + return; + } + + /** + * Blog::setDescription + * @param string $val description for this weblog + * @return void + */ + public function setDescription($val) + { + $this->setSetting('bdesc',$val); + return; + } + + /** + * Blog::setUpdateFile() + * @param string $val name of file to beupdated when weblog is updated + * @return + */ + public function setUpdateFile($val) + { + $this->setSetting('bupdate',$val); + return; + } + + /** + * Blog::setDefaultSkin() + * @param integer $val ID for default skin to use when displaying this weblog + * @return void + */ + public function setDefaultSkin($val) + { + $this->setSetting('bdefskin', $val); + return; + } + + /** + * Blog::setURL() + * @param string $val URI for this weblog + * @return + */ + public function setURL($val) + { + $this->setSetting('burl', $val); + return; + } + + /** + * Blog::setName() + * @param string $val name of this weblog + * @return void + */ + public function setName($val) + { + $this->setSetting('bname', $val); + return; + } + + /** + * Blog::setShortName() + * @param string $val short name for this weblog + * @return void + */ + public function setShortName($val) + { + $this->setSetting('bshortname', $val); + return; + } + + /** + * Blog::setCommentsEnabled() + * @param integer $val enabling posting comment or not + * @return void + */ + public function setCommentsEnabled($val) + { + $this->setSetting('bcomments',$val); + return; + } + + /** + * Blog::setMaxComments() + * @param integer $val maximum number of comments for this weblog + * @return void + */ + public function setMaxComments($val) + { + $this->setSetting('bmaxcomments', $val); + return; + } + + /** + * Blog::setNotifyAddress() + * @param string $val email to be notified if weblog updated + * @return void + */ + public function setNotifyAddress($val) + { + $this->setSetting('bnotify', $val); + return; + } + + /** + * Blog::setEmailRequired() + * @param string requiring comments with email or not from non member + * @return void + */ + public function setEmailRequired($val) + { + $this->setSetting('breqemail', $val); + return; + } + + /** + * Blog::setTimeOffset() + * @param integer $val time offset + * @return void + */ + public function setTimeOffset($val) + { + // check validity of value + // 1. replace , by . (common mistake) + $val = str_replace(',','.',$val); + + // 2. cast to float or int + if ( is_numeric($val) && (i18n::strpos($val, '.5') === (i18n::strlen($val) - 2)) ) + { + $val = (float) $val; + } + else + { + $val = (integer) $val; + } + + $this->setSetting('btimeoffset',$val); + return; + } + + /** + * Blog::setDefaultCategory() + * @param integer $val ID for default category for this weblog + * @return + */ + public function setDefaultCategory($val) + { + $this->setSetting('bdefcat',$val); + return; + } + + /** + * Blog::getSetting() + * @param string $key key for setting of this weblog + * @return mixed value for the setting + */ + public function getSetting($key) + { + return $this->settings[$key]; + } + + /** + * Blog::setSetting() + * @param string $key key for setting of this weblog + * @param mixed $value value for the key + * @return + */ + public function setSetting($key, $value) + { + $this->settings[$key] = $value; + return; + } + + /** + * Blog::addTeamMember() + * Tries to add a member to the team. + * Returns false if the member was already on the team + * + * @param integer $memberid id for member + * @param boolean $admin super-admin or not + * @return boolean Success/Fail + */ + public function addTeamMember($memberid, $admin) + { + global $manager; + + $memberid = intval($memberid); + $admin = intval($admin); + + // check if member is already a member + $tmem =& $manager->getMember($memberid); + + if ( $tmem->isTeamMember($this->blogid) ) + { + return 0; + } + + $data = array( + 'blog' => &$this, + 'member' => &$tmem, + 'admin' => &$admin + ); + $manager->notify('PreAddTeamMember', $data); + + // add to team + $query = "INSERT INTO %s (TMEMBER, TBLOG, TADMIN) VALUES (%d, %d, %d);"; + $query = sprintf($query, sql_table('team'), (integer) $memberid, (integer) $this->blogid, (integer) $admin); + DB::execute($query); + + $data = array( + 'blog' => &$this, + 'member' => &$tmem, + 'admin' => $admin + ); + $manager->notify('PostAddTeamMember', $data); + + $logMsg = sprintf(_TEAM_ADD_NEWTEAMMEMBER, $tmem->getDisplayName(), $memberid, $this->getName()); + ActionLog::add(INFO, $logMsg); + + return 1; + } + + /** + * Blog::getID() + * @param void + * @return integer ID for this weblog + */ + public function getID() + { + return (integer) $this->blogid; + } + + /** + * Checks if a blog with a given shortname exists + * Returns true if there is a blog with the given shortname (static) + * + * @param string $name blog shortname + * @return boolean exists or not + */ + public function exists($name) + { + $r = DB::getResult('SELECT * FROM '.sql_table('blog').' WHERE bshortname='. DB::quoteValue($name)); + return ($r->rowCount() != 0); + } + + /** + * Checks if a blog with a given id exists + * Returns true if there is a blog with the given ID (static) + * + * @param integer $id ID for searched weblog + * @return boolean exists or not + */ + public function existsID($id) + { + $r = DB::getResult('SELECT * FROM '.sql_table('blog').' WHERE bnumber='.intval($id)); + return ($r->rowCount() != 0); + } + + /** + * Blog::setFuturePost() + * flag there is a future post pending + * + * @param void + * @return void + */ + public function setFuturePost() + { + $query = "UPDATE %s SET bfuturepost='1' WHERE bnumber=%d;"; + $query = sprintf($query, sql_table('blog'), (integer) $this->blogid); + DB::execute($query); + return; + } + + /** + * Blog::clearFuturePost() + * clear there is a future post pending + * + * @param void + * @return void + */ + public function clearFuturePost() + { + $query = "UPDATE %s SET bfuturepost='0' WHERE bnumber=%d;"; + $query = sprintf($query, sql_table('blog'), (integer) $this->blogid); + DB::execute($query); + return; + } + + /** + * Blog::checkJustPosted() + * check if we should throw justPosted event + * + * @param void + * @return void + */ + public function checkJustPosted() + { + global $manager; + + if ( $this->settings['bfuturepost'] == 1 ) + { + $query = "SELECT * FROM %s WHERE iposted=0 AND iblog=%d AND itime < NOW();"; + $query = sprintf($query, sql_table('item'), (integer) $this->blogid); + + $result = DB::getResult($query); + if ( $result->rowCount() > 0 ) + { + // This $pinged is allow a plugin to tell other hook to the event that a ping is sent already + // Note that the plugins's calling order is subject to thri order in the plugin list + $pinged = FALSE; + $data = array('blogid' => $this->blogid, 'pinged' => &$pinged); + $manager->notify('JustPosted', $data); + + // clear all expired future posts + $query = "UPDATE %s SET iposted='1' WHERE iblog=%d AND itime < NOW();"; + $query = spriintf($query, sql_table('item'), (integer) $this->blogid); + DB::execute($query); + + // check to see any pending future post, clear the flag is none + $query = "SELECT * FROM %s WHERE iposted=0 AND iblog=%d;"; + $query = sprintf($query, sql_table('item'), (integer) $this->blogid); + + $result = DB::getResult($query); + if ( $result->rowCount() == 0 ) + { + $this->clearFuturePost(); + } + } + } + return; + } + + /** + * Blog::readLogFromList() + * Shows the given list of items for this blog + * + * @param array $itemarray array of item numbers to be displayed + * @param string $template string representing the template _NAME_ (!) + * @param string $highlight contains a query that should be highlighted + * @param boolean $comments 1=show comments 0=don't show comments + * @param boolean $dateheads 1=show dateheads 0=don't show dateheads + * @param boolean $showDrafts 0=do not show drafts 1=show drafts + * @param boolean $showFuture 0=do not show future posts 1=show future posts + * @return integer amount of items shown + */ + public function readLogFromList($itemarray, $template, $highlight = '', $comments = 1, $dateheads = 1,$showDrafts = 0, $showFuture = 0) + { + $query = $this->getSqlItemList($itemarray,$showDrafts,$showFuture); + return $this->showUsingQuery($template, $query, $highlight, $comments, $dateheads); + } + + /** + * Blog::getSqlItemList() + * Returns the SQL query used to fill out templates for a list of items + * No LIMIT clause is added. (caller should add this if multiple pages are requested) + * + * @param array $itemarray an array holding the item numbers of the items to be displayed + * @param integer $showDrafts 0=do not show drafts 1=show drafts + * @param integer $showFuture 0=do not show future posts 1=show future posts + * @return string either a full SQL query, or an empty string + */ + public function getSqlItemList($itemarray,$showDrafts = 0,$showFuture = 0) + { + if ( !is_array($itemarray) ) + { + return ''; + } + + $showDrafts = intval($showDrafts); + $showFuture = intval($showFuture); + $items = array(); + + foreach ( $itemarray as $value ) + { + if ( intval($value) ) + { + $items[] = intval($value); + } + } + if ( !count($items) ) + { + return ''; + } + + $i = count($items); + $query = ''; + foreach ( $items as $value ) + { + $query .= '(' + . 'SELECT' + . ' i.inumber as itemid,' + . ' i.ititle as title,' + . ' i.ibody as body,' + . ' m.mname as author,' + . ' m.mrealname as authorname,' + . ' i.itime,' + . ' i.imore as more,' + . ' m.mnumber as authorid,' + . ' m.memail as authormail,' + . ' m.murl as authorurl,' + . ' c.cname as category,' + . ' i.icat as catid,' + . ' i.iclosed as closed'; + + $query .= ' FROM ' + . sql_table('item') . ' as i, ' + . sql_table('member') . ' as m, ' + . sql_table('category') . ' as c' + . ' WHERE' + . ' i.iblog='.$this->blogid + . ' and i.iauthor=m.mnumber' + . ' and i.icat=c.catid'; + + // exclude drafts + if ( !$showDrafts ) + { + $query .= ' and i.idraft=0'; + } + if ( !$showFuture ) + { + // don't show future items + $query .= ' and i.itime<=' . DB::formatDateTime($this->getCorrectTime()); + } + + $query .= ' and i.inumber='.intval($value); + $query .= ')'; + $i--; + if ($i) $query .= ' UNION '; + } + + return $query; + } + + /** + * Blog::convertBreaks() + * Get the the setting for the line break handling + * [should be named as getConvertBreaks()] + * + * @deprecated + * @param void + * @return + */ + public function convertBreaks() + { + return $this->getSetting('bconvertbreaks'); + } + + /** + * Set the the setting for the line break handling + * + * @deprecated + * @param boolean $val new value for bconvertbreaks + * @return void + */ + public function setConvertBreaks($val) + { + $this->setSetting('bconvertbreaks', $val); + return; + } +} +>>>>>>> skinnable-master diff --git a/nucleus/libs/BODYACTIONS.php b/nucleus/libs/BODYACTIONS.php index 137af90..8464021 100644 --- a/nucleus/libs/BODYACTIONS.php +++ b/nucleus/libs/BODYACTIONS.php @@ -15,7 +15,11 @@ * * @license http://nucleuscms.org/license.txt GNU General Public License * @copyright Copyright (C) 2002-2009 The Nucleus Group +<<<<<<< HEAD * @version $Id: BODYACTIONS.php 1757 2012-04-15 09:02:32Z sakamocchi $ +======= + * @version $Id: BODYACTIONS.php 1886 2012-06-17 08:27:27Z sakamocchi $ +>>>>>>> skinnable-master */ class BodyActions extends BaseActions @@ -39,7 +43,11 @@ class BodyActions extends BaseActions */ public function __construct() { +<<<<<<< HEAD parent::__construct(); +======= + parent::__construct(); +>>>>>>> skinnable-master return; } @@ -107,9 +115,16 @@ class BodyActions extends BaseActions array_shift($params); // add item reference (array_unshift didn't work) +<<<<<<< HEAD $params = array_merge(array(&$this->currentItem), $params); call_user_func_array(array(&$plugin, 'doItemVar'), $params); +======= + $target = array(&$this->currentItem); + $params = array_merge($target, $params); + + call_user_func_array(array($plugin, 'doItemVar'), $params); +>>>>>>> skinnable-master return; } @@ -126,7 +141,11 @@ class BodyActions extends BaseActions // image/popup calls have arguments separated by | $args = func_get_args(); $args = preg_split('#\|#', implode($args, ', ')); +<<<<<<< HEAD echo call_user_func_array(array(&$this, 'createImageCode'), $args); +======= + echo call_user_func_array(array($this, 'createImageCode'), $args); +>>>>>>> skinnable-master } /** @@ -174,7 +193,11 @@ class BodyActions extends BaseActions // image/popup calls have arguments separated by | $args = func_get_args(); $args = preg_split('#\|#', implode($args, ', ')); +<<<<<<< HEAD echo call_user_func_array(array(&$this, 'createMediaCode'), $args); +======= + echo call_user_func_array(array($this, 'createMediaCode'), $args); +>>>>>>> skinnable-master } /** @@ -215,7 +238,11 @@ class BodyActions extends BaseActions // image/popup calls have arguments separated by | $args = func_get_args(); $args = preg_split('#\|#', implode($args, ', ')); +<<<<<<< HEAD echo call_user_func_array(array(&$this, 'createPopupCode'), $args); +======= + echo call_user_func_array(array($this, 'createPopupCode'), $args); +>>>>>>> skinnable-master } /** @@ -280,7 +307,11 @@ class BodyActions extends BaseActions $condition = ($blog && ($blog->getSetting($name) == $value)); break; case 'itemblogsetting': +<<<<<<< HEAD $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem['itemid'])); +======= + $b =& $manager->getBlog($this->currentItem['blogid']); +>>>>>>> skinnable-master $condition = ($b && ($b->getSetting($name) == $value)); break; case 'loggedin': @@ -354,7 +385,11 @@ class BodyActions extends BaseActions { global $member, $manager; +<<<<<<< HEAD $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem['itemid'])); +======= + $b =& $manager->getBlog($this->currentItem['blogid']); +>>>>>>> skinnable-master // when no parameter is defined, just check if author is current visitor if ( ($key != 'isadmin' && $key != 'name') || ($key == 'name' && $value == '') ) @@ -400,7 +435,11 @@ class BodyActions extends BaseActions { global $catid, $manager; +<<<<<<< HEAD $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem['itemid'])); +======= + $b =& $manager->getBlog($this->currentItem['blogid']); +>>>>>>> skinnable-master // when no parameter is defined, just check if a category is selected if ( ($key != 'catname' && $key != 'catid') || ($value == '') ) @@ -558,6 +597,10 @@ class BodyActions extends BaseActions $params = func_get_args(); array_shift($params); +<<<<<<< HEAD return call_user_func_array(array(&$plugin, 'doIf'), $params); +======= + return call_user_func_array(array($plugin, 'doIf'), $params); +>>>>>>> skinnable-master } } diff --git a/nucleus/libs/BaseActions.php b/nucleus/libs/BaseActions.php index 9473d52..6ae996b 100644 --- a/nucleus/libs/BaseActions.php +++ b/nucleus/libs/BaseActions.php @@ -17,7 +17,11 @@ * * @license http://nucleuscms.org/license.txt GNU General Public License * @copyright Copyright (C) 2002-2009 The Nucleus Group +<<<<<<< HEAD * @version $Id: BaseActions.php 1848 2012-05-16 12:17:00Z sakamocchi $ +======= + * @version $Id: BaseActions.php 1882 2012-06-17 07:52:43Z sakamocchi $ +>>>>>>> skinnable-master */ class BaseActions @@ -139,14 +143,22 @@ class BaseActions /** * BaseActions::parse_locale() +<<<<<<< HEAD * Parse locale to language-script-region according to RFC 4646 +======= + * Parse locale to language-region according to RFC 4646 +>>>>>>> skinnable-master * * @param void * @return void */ public function parse_locale() { +<<<<<<< HEAD echo preg_replace('#_#', '-', i18n::get_current_locale()); +======= + echo preg_replace('#(.+)_(.+)_(.+)#', '$1-$3', i18n::get_current_locale()); +>>>>>>> skinnable-master return; } @@ -434,7 +446,11 @@ class BaseActions { $this->addIfExecute(); $args = func_get_args(); +<<<<<<< HEAD $condition = call_user_func_array(array(&$this,'checkCondition'), $args); +======= + $condition = call_user_func_array(array($this,'checkCondition'), $args); +>>>>>>> skinnable-master $this->addIfCondition($condition); return; } @@ -505,7 +521,11 @@ class BaseActions { ob_end_clean(); $args = func_get_args(); +<<<<<<< HEAD $condition = call_user_func_array(array(&$this,'checkCondition'), $args); +======= + $condition = call_user_func_array(array($this,'checkCondition'), $args); +>>>>>>> skinnable-master $this->addIfCondition($condition); } return; @@ -523,7 +543,11 @@ class BaseActions $this->addIfExecute(); $args = func_get_args(); +<<<<<<< HEAD $condition = call_user_func_array(array(&$this,'checkCondition'), $args); +======= + $condition = call_user_func_array(array($this,'checkCondition'), $args); +>>>>>>> skinnable-master $this->addIfCondition(!$condition); return; } @@ -559,7 +583,11 @@ class BaseActions { ob_end_clean(); $args = func_get_args(); +<<<<<<< HEAD $condition = call_user_func_array(array(&$this,'checkCondition'), $args); +======= + $condition = call_user_func_array(array($this,'checkCondition'), $args); +>>>>>>> skinnable-master $this->addIfCondition(!$condition); } return; diff --git a/nucleus/libs/COMMENT.php b/nucleus/libs/COMMENT.php index bb38e11..3cb7daa 100644 --- a/nucleus/libs/COMMENT.php +++ b/nucleus/libs/COMMENT.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD tags + $body = addBreaks($body); + + // create hyperlinks for http:// addresses + // there's a testcase for this in /build/testcases/urllinking.txt + $replace_from = array( + '/([^:\/\/\w]|^)((https:\/\/)([\w\.-]+)([\/\w+\.~%&?@=_:;#,-]+))/i', + '/([^:\/\/\w]|^)((http:\/\/|www\.)([\w\.-]+)([\/\w+\.~%&?@=_:;#,-]+))/i', + '/([^:\/\/\w]|^)((ftp:\/\/|ftp\.)([\w\.-]+)([\/\w+\.~%&?@=_:;#,-]+))/i', + '/([^:\/\/\w]|^)(mailto:(([a-zA-Z\@\%\.\-\+_])+))/i' + ); + + return preg_replace_callback($replace_from, array(__CLASS__, 'prepareBody_cb'), $body); + } + + /** + * Comment::createLinkCode() + * Creates a link code for unlinked URLs with different protocols + * + * @static + * @param string $pre Prefix of comment + * @param string $url URL + * @param string $protocol http, mailto and so on + * @return string string including anchor element and child text + */ + static private function createLinkCode($pre, $url, $protocol = 'http') + { + $post = ''; + + // it's possible that $url ends contains entities we don't want, + // since htmlspecialchars is applied _before_ URL linking + // move the part of URL, starting from the disallowed entity to the 'post' link part + $aBadEntities = array('"', '>', '<'); + foreach ( $aBadEntities as $entity ) + { + $pos = i18n::strpos($url, $entity); + + if ( $pos ) + { + $post = i18n::substr($url, $pos) . $post; + $url = i18n::substr($url, 0, $pos); + } + } + + // remove entities at end (&&&&) + if ( preg_match('/(&\w+;)+$/i', $url, $matches) ) + { + $post = $matches[0] . $post; // found entities (1 or more) + $url = i18n::substr($url, 0, i18n::strlen($url) - i18n::strlen($post) ); + } + + // move ending comma from url to 'post' part + if ( i18n::substr($url, i18n::strlen($url) - 1) == ',' ) + { + $url = i18n::substr($url, 0, i18n::strlen($url) - 1); + $post = ',' . $post; + } + + if ( !preg_match('#^' . $protocol . '://#', $url) ) + { + $linkedUrl = $protocol . ( ($protocol == 'mailto') ? ':' : '://') . $url; + } + else + { + $linkedUrl = $url; + } + + if ( $protocol != 'mailto' ) + { + $displayedUrl = $linkedUrl; + } + else + { + $displayedUrl = $url; + } + + return $pre . '' . Entity::hsc(Entity::shorten($displayedUrl,30,'...')) . '' . $post; + } + + /** + * Comment::prepareBody_cb() + * This method is a callback for creating link codes + * + * @param array $match elements for achor + * @return string including anchor element and child text + * + */ + static public function prepareBody_cb($match) + { + if ( !preg_match('/^[a-z]+/i', $match[2], $protocol) ) + { + return $match[0]; + } + + switch( strtolower($protocol[0]) ) + { + case 'https': + return self::createLinkCode($match[1], $match[2], 'https'); + break; + + case 'ftp': + return self::createLinkCode($match[1], $match[2], 'ftp'); + break; + + case 'mailto': + return self::createLinkCode($match[1], $match[3], 'mailto'); + break; + + default: + return self::createLinkCode($match[1], $match[2], 'http'); + break; + } + return; + } +} +>>>>>>> skinnable-master diff --git a/nucleus/libs/COMMENTACTIONS.php b/nucleus/libs/COMMENTACTIONS.php index b320145..8ef2afb 100644 --- a/nucleus/libs/COMMENTACTIONS.php +++ b/nucleus/libs/COMMENTACTIONS.php @@ -232,8 +232,13 @@ class CommentActions extends BaseActions public function parse_blogurl() { global $manager; +<<<<<<< HEAD $blogid = getBlogIDFromItemID($this->commentsObj->itemid); $blog =& $manager->getBlog($blogid); +======= + $item =& $manager->getItem($this->commentsObj->itemid, 1, 1); + $blog =& $manager->getBlog($item['blogid']); +>>>>>>> skinnable-master echo $blog->getURL(); return; } @@ -537,10 +542,19 @@ class CommentActions extends BaseActions array_shift($params); // pass info on current item and current comment as well +<<<<<<< HEAD $params = array_merge(array(&$this->currentComment), $params); $params = array_merge(array(&$this->commentsObj->itemActions->currentItem), $params); call_user_func_array(array(&$plugin,'doTemplateCommentsVar'), $params); +======= + $target = array(&$this->currentComment); + $params = array_merge($target, $params); + $target = array(&$this->commentsObj->itemActions->currentItem); + $params = array_merge($target, $params); + + call_user_func_array(array($plugin,'doTemplateCommentsVar'), $params); +>>>>>>> skinnable-master return; } @@ -641,7 +655,11 @@ class CommentActions extends BaseActions */ public function parse_userlinkraw() { +<<<<<<< HEAD echo $this->currentComment['userlinkraw']; +======= + echo (array_key_exists('userlinkraw', $this->currentComment) && !empty($this->currentComment['userlinkraw'])) ? $this->currentComment['userlinkraw'] : ''; +>>>>>>> skinnable-master return; } @@ -705,8 +723,14 @@ class CommentActions extends BaseActions $condition = ($blog && ($blog->getSetting($name) == $value)); break; case 'itemblogsetting': +<<<<<<< HEAD $b =& $manager->getBlog(getBlogIDFromItemID($this->currentComment['itemid'])); $condition = ($b && ($b->getSetting($name) == $value)); +======= + $item =& $manager->getItem($this->currentComment['itemid'], 1, 1); + $blog =& $manager->getBlog($item['blogid']); + $condition = ($blog && ($blog->getSetting($name) == $value)); +>>>>>>> skinnable-master break; case 'loggedin': $condition = $member->isLoggedIn(); @@ -781,6 +805,7 @@ class CommentActions extends BaseActions return FALSE; } +<<<<<<< HEAD $mem =& $manager->getMember($this->currentComment['memberid']); $b =& $manager->getBlog(getBlogIDFromItemID($this->currentComment['itemid'])); $citem =& $manager->getItem($this->currentComment['itemid'], 1, 1); @@ -788,6 +813,15 @@ class CommentActions extends BaseActions // when no parameter is defined, just check if item author is current visitor if (($key != 'isadmin' && $key != 'name' && $key != 'isauthor' && $key != 'isonteam')) { return (intval($member->getID()) > 0 && intval($member->getID()) == intval($citem['authorid'])); +======= + $member =& $manager->getMember($this->currentComment['memberid']); + $item =& $manager->getItem($this->currentComment['itemid'], 1, 1); + + // when no parameter is defined, just check if item author is current visitor + if ( ($key != 'isadmin' && $key != 'name' && $key != 'isauthor' && $key != 'isonteam') ) + { + return (intval($memberber->getID()) > 0 && intval($memberber->getID()) == (integer) $item['authorid']); +>>>>>>> skinnable-master } // check comment author name @@ -798,7 +832,11 @@ class CommentActions extends BaseActions { return FALSE; } +<<<<<<< HEAD if ( $value == strtolower($mem->getDisplayName()) ) +======= + if ( $value == strtolower($member->getDisplayName()) ) +>>>>>>> skinnable-master { return TRUE; } @@ -807,24 +845,40 @@ class CommentActions extends BaseActions // check if comment author is admin if ( $key == 'isadmin' ) { +<<<<<<< HEAD $blogid = intval($b->getID()); if ( $mem->isAdmin() ) { return TRUE; } return $mem->isBlogAdmin($blogid); +======= + if ( $member->isAdmin() ) + { + return TRUE; + } + return $member->isBlogAdmin($item['blogid']); +>>>>>>> skinnable-master } // check if comment author is item author if ( $key == 'isauthor' ) { +<<<<<<< HEAD return (intval($citem['authorid']) == intval($this->currentComment['memberid'])); +======= + return ((integer) $item['authorid'] == (integer) $this->currentComment['memberid']); +>>>>>>> skinnable-master } // check if comment author is on team if ( $key == 'isonteam' ) { +<<<<<<< HEAD return $mem->teamRights(intval($b->getID())); +======= + return $member->teamRights((integer) $item['blogid']); +>>>>>>> skinnable-master } return FALSE; } @@ -840,6 +894,7 @@ class CommentActions extends BaseActions private function ifItemCategory($key = '', $value = '') { global $catid, $manager; +<<<<<<< HEAD $b =& $manager->getBlog(getBlogIDFromItemID($this->currentComment['itemid'])); $citem =& $manager->getItem($this->currentComment['itemid'],1,1); @@ -865,6 +920,32 @@ class CommentActions extends BaseActions if ( ($key == 'catid') && ($value == $icatid) ) { return $b->isValidCategory($icatid); +======= + + $item =& $manager->getItem($this->currentComment['itemid'],1,1); + $blog =& $manager->getBlog($item['blogid']); + + // when no parameter is defined, just check if a category is selected + if ( ($key != 'catname' && $key != 'catid') || ($value == '') ) + { + return $blog->isValidCategory($item['catid']); + } + + // check category name + if ( $key == 'catname' ) + { + $value = $blog->getCategoryIdFromName($value); + if ( $value == $item['catid'] ) + { + return $blog->isValidCategory($item['catid']); + } + } + + // check category id + if ( ($key == 'catid') && ($value == $item['catid']) ) + { + return $blog->isValidCategory($item['catid']); +>>>>>>> skinnable-master } return FALSE; } @@ -878,12 +959,22 @@ class CommentActions extends BaseActions */ private function ifOnTeam($blogName = '') { +<<<<<<< HEAD global $blog, $member, $manager; $b =& $manager->getBlog(getBlogIDFromItemID($this->currentComment['itemid'])); // when no blog found if ( ($blogName == '') && (!is_object($b)) ) +======= + global $member, $manager; + + $item =& $manager->getItem($this->currentComment['itemid'], 1, 1); + $blog =& $manager->getBlog($item['blogid']); + + // when no blog found + if ( ($blogName == '') && !is_object($blog) ) +>>>>>>> skinnable-master { return 0; } @@ -897,7 +988,11 @@ class CommentActions extends BaseActions // use current blog if ( ($blogName == '') || !$manager->existsBlogID($blogid) ) { +<<<<<<< HEAD $blogid = $b->getID(); +======= + $blogid = $blog->getID(); +>>>>>>> skinnable-master } return $member->teamRights($blogid); @@ -912,12 +1007,22 @@ class CommentActions extends BaseActions */ private function ifAdmin($blogName = '') { +<<<<<<< HEAD global $blog, $member, $manager; $b =& $manager->getBlog(getBlogIDFromItemID($this->currentComment['itemid'])); // when no blog found if ( ($blogName == '') && (!is_object($b)) ) +======= + global $member, $manager; + + $item =& $manager->getItem($this->currentComment['itemid'], 1, 1); + $blog =& $manager->getBlog($item['blogid']); + + // when no blog found + if ( ($blogName == '') && !is_object($blog) ) +>>>>>>> skinnable-master { return 0; } @@ -931,7 +1036,11 @@ class CommentActions extends BaseActions // use current blog if ( ($blogName == '') || !$manager->existsBlogID($blogid) ) { +<<<<<<< HEAD $blogid = $b->getID(); +======= + $blogid = $blog->getID(); +>>>>>>> skinnable-master } return $member->isBlogAdmin($blogid); @@ -1004,6 +1113,10 @@ class CommentActions extends BaseActions $params = func_get_args(); array_shift($params); +<<<<<<< HEAD return call_user_func_array(array(&$plugin, 'doIf'), $params); +======= + return call_user_func_array(array($plugin, 'doIf'), $params); +>>>>>>> skinnable-master } } diff --git a/nucleus/libs/COMMENTS.php b/nucleus/libs/COMMENTS.php index 6783c06..5eaf79d 100644 --- a/nucleus/libs/COMMENTS.php +++ b/nucleus/libs/COMMENTS.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD itemid = (integer) $itemid; + return; + } + + /** + * Comments::setItemActions() + * Used when parsing comments + * + * @param object $itemActions itemActions object, that will take care of the parsing + * @return void + */ + public function setItemActions(&$itemActions) + { + $this->itemActions =& $itemActions; + return; + } + + /** + * Comments::showComments() + * Shows maximum $max comments to the given item using the given template + * returns the amount of shown comments (if maxToShow = -1, then there is no limit) + * + * @param array template template to use + * @param integer maxToShow max. comments to show + * @param integer showNone indicates if the 'no comments' thingie should be outputted + * when there are no comments (useful for closed items) + * @param string highlight Highlight to use (if any) + * @return integer number of comments + */ + public function showComments($template, $maxToShow = -1, $showNone = 1, $highlight = '') + { + global $CONF, $manager; + + if ( $maxToShow == 0 ) + { + $this->commentcount = $this->amountComments(); + } + else + { + $query = 'SELECT citem as itemid, cnumber as commentid, cbody as body, cuser as user, cmail as userid, ' + . 'cemail as email, cmember as memberid, ctime, chost as host, cip as ip, cblog as blogid ' + . 'FROM %s as c WHERE citem=%d ORDER BY ctime'; + + $query = sprintf($query, sql_table('comment'), (integer) $this->itemid); + $comments = DB::getResult($query); + $this->commentcount = $comments->rowCount(); + } + + // create parser object & action handler + $handler = new CommentActions($this); + $handler->setTemplate($template); + + $parser = new Parser($handler); + + // if no result was found + if ( $this->commentcount == 0 ) + { + // note: when no reactions, COMMENTS_HEADER and COMMENTS_FOOTER are _NOT_ used + if ( $showNone ) + { + $parser->parse($template['COMMENTS_NONE']); + } + return 0; + } + + // if too many comments to show + if ( ($maxToShow != -1) && ($this->commentcount > $maxToShow) ) + { + $parser->parse($template['COMMENTS_TOOMUCH']); + return 0; + } + + $parser->parse($template['COMMENTS_HEADER']); + + foreach ( $comments as $comment ) + { + $comment['timestamp'] = strtotime($comment['ctime']); + $handler->setCurrentComment($comment); + $handler->setHighlight($highlight); + + $data = array('comment' => &$comment); + $manager->notify('PreComment', $data); + $parser->parse($template['COMMENTS_BODY']); + $manager->notify('PostComment', $data); + } + + $parser->parse($template['COMMENTS_FOOTER']); + + $comments->closeCursor(); + + return $this->commentcount; + } + + /** + * Comments::amountComments() + * Returns the amount of comments for this itemid + * + * @param void + * @return integer number of comments + */ + public function amountComments() + { + $query = 'SELECT COUNT(*) FROM %s WHERE citem=%d;'; + $query = sprintf($query, sql_table('comment'), (integer) $this->itemid); + $res = DB::getValue($query); + + return $res; + } + + /** + * Comments::addComment() + * Adds a new comment to the database + * + * @param string $timestamp + * @param array $comment + * @return mixed + */ + public function addComment($timestamp, $comment) + { + global $CONF, $member, $manager; + + $blogid = getBlogIDFromItemID($this->itemid); + + $settings =& $manager->getBlog($blogid); + $settings->readSettings(); + + // begin if: comments disabled + if ( !$settings->commentsEnabled() ) + { + return _ERROR_COMMENTS_DISABLED; + } + + // begin if: public cannot comment + if ( !$settings->isPublic() && !$member->isLoggedIn() ) + { + return _ERROR_COMMENTS_NONPUBLIC; + } + + // begin if: comment uses a protected member name + if ( $CONF['ProtectMemNames'] && !$member->isLoggedIn() && Member::isNameProtected($comment['user']) ) + { + return _ERROR_COMMENTS_MEMBERNICK; + } + + // begin if: email required, but missing (doesn't apply to members) + if ( $settings->emailRequired() && i18n::strlen($comment['email']) == 0 && !$member->isLoggedIn() ) + { + return _ERROR_EMAIL_REQUIRED; + } + + // begin if: commenter's name is too long + if ( i18n::strlen($comment['user']) > 40 ) + { + return _ERROR_USER_TOO_LONG; + } + + // begin if: commenter's email is too long + if ( i18n::strlen($comment['email']) > 100 ) + { + return _ERROR_EMAIL_TOO_LONG; + } + + // begin if: commenter's url is too long + if ( i18n::strlen($comment['userid']) > 100 ) + { + return _ERROR_URL_TOO_LONG; + } + + $comment['timestamp'] = $timestamp; + $comment['host'] = gethostbyaddr(serverVar('REMOTE_ADDR') ); + $comment['ip'] = serverVar('REMOTE_ADDR'); + + // begin if: member is logged in, use that data + if ( $member->isLoggedIn() ) + { + $comment['memberid'] = $member->getID(); + $comment['user'] = ''; + $comment['userid'] = ''; + $comment['email'] = ''; + } + else + { + $comment['memberid'] = 0; + } + + // spam check + $continue = FALSE; + $plugins = array(); + + if ( isset($manager->subscriptions['ValidateForm']) ) + { + $plugins = array_merge($plugins, $manager->subscriptions['ValidateForm']); + } + + if ( isset($manager->subscriptions['PreAddComment']) ) + { + $plugins = array_merge($plugins, $manager->subscriptions['PreAddComment']); + } + + if ( isset($manager->subscriptions['PostAddComment']) ) + { + $plugins = array_merge($plugins, $manager->subscriptions['PostAddComment']); + } + + $plugins = array_unique($plugins); + + while ( list(, $plugin) = each($plugins) ) + { + $p = $manager->getPlugin($plugin); + $continue = $continue || $p->supportsFeature('handleSpam'); + } + + $spamcheck = array( + 'type' => 'comment', + 'body' => $comment['body'], + 'id' => $comment['itemid'], + 'live' => TRUE, + 'return' => $continue + ); + + // begin if: member logged in + if ( $member->isLoggedIn() ) + { + $spamcheck['author'] = $member->displayname; + $spamcheck['email'] = $member->email; + } + // else: public + else + { + $spamcheck['author'] = $comment['user']; + $spamcheck['email'] = $comment['email']; + $spamcheck['url'] = $comment['userid']; + } + + $data = array('spamcheck' => &$spamcheck); + $manager->notify('SpamCheck', $data); + + if ( !$continue && isset($spamcheck['result']) && $spamcheck['result'] == TRUE ) + { + return _ERROR_COMMENTS_SPAM; + } + + // isValidComment returns either "1" or an error message + $isvalid = $this->isValidComment($comment, $spamcheck); + if ( $isvalid != 1 ) + { + return $isvalid; + } + + // begin if: send email to notification address + if ( $settings->getNotifyAddress() && $settings->notifyOnComment() ) + { + + $message = _NOTIFY_NC_MSG . ' ' . $this->itemid . "\n"; + $temp = parse_url($CONF['Self']); + + if ( $temp['scheme'] ) + { + $message .= Link::create_item_link($this->itemid) . "\n\n"; + } + else + { + $tempurl = $settings->getURL(); + + if ( i18n::substr($tempurl, -1) == '/' || i18n::substr($tempurl, -4) == '.php' ) + { + $message .= $tempurl . '?itemid=' . $this->itemid . "\n\n"; + } + else + { + $message .= $tempurl . '/?itemid=' . $this->itemid . "\n\n"; + } + } + + if ( $comment['memberid'] == 0 ) + { + $message .= _NOTIFY_USER . ' ' . $comment['user'] . "\n"; + $message .= _NOTIFY_USERID . ' ' . $comment['userid'] . "\n"; + } + else + { + $message .= _NOTIFY_MEMBER .' ' . $member->getDisplayName() . ' (ID=' . $member->getID() . ")\n"; + } + + $message .= _NOTIFY_HOST . ' ' . $comment['host'] . "\n"; + $message .= _NOTIFY_COMMENT . "\n " . $comment['body'] . "\n"; + $message .= NOTIFICATION::get_mail_footer(); + + $item =& $manager->getItem($this->itemid, 0, 0); + $subject = _NOTIFY_NC_TITLE . ' ' . strip_tags($item['title']) . ' (' . $this->itemid . ')'; + + $from = $member->getNotifyFromMailAddress($comment['email']); + + NOTIFICATION::mail($settings->getNotifyAddress(), $subject, $message, $from, i18n::get_current_charset()); + } + + $comment = Comment::prepare($comment); + + $data = array('comment' => &$comment, 'spamcheck' => &$spamcheck); + $manager->notify('PreAddComment', $data); + + $name = DB::quoteValue($comment['user']); + $url = DB::quoteValue($comment['userid']); + $email = DB::quoteValue($comment['email']); + $body = DB::quoteValue($comment['body']); + $host = DB::quoteValue($comment['host']); + $ip = DB::quoteValue($comment['ip']); + $memberid = intval($comment['memberid']); + $timestamp = DB::formatDateTime($comment['timestamp']); + $itemid = $this->itemid; + + $qSql = 'SELECT COUNT(*) AS result ' + . 'FROM ' . sql_table('comment') + . ' WHERE ' + . 'cmail = ' . $url + . ' AND cmember = ' . $memberid + . ' AND cbody = ' . $body + . ' AND citem = ' . $itemid + . ' AND cblog = ' . $blogid; + $result = (integer) DB::getValue($qSql); + + if ( $result > 0 ) + { + return _ERROR_BADACTION; + } + + $query = sprintf('INSERT INTO %s (cuser, cmail, cemail, cmember, cbody, citem, ctime, chost, cip, cblog) ' + . 'VALUES (%s, %s, %s, %d, %s, %d, %s, %s, %s, %d)' + , sql_table('comment'), $name, $url, $email, $memberid, $body, $itemid, $timestamp, $host, $ip, $blogid); + + DB::execute($query); + + // post add comment + $commentid = DB::getInsertId(); + $data = array('comment' => &$comment, 'commentid' => &$commentid, 'spamcheck' => &$spamcheck); + $manager->notify('PostAddComment', $data); + + // succeeded ! + return TRUE; + } + + /** + * Comments::isValidComment() + * Checks if a comment is valid and call plugins + * that can check if the comment is a spam comment + * + * @param array $comment array with comment elements + * @param array $spamcheck array with spamcheck elements + * @return boolean valid or not + */ + private function isValidComment(&$comment, &$spamcheck) + { + global $member, $manager; + + // check if there exists a item for this date + $item =& $manager->getItem($this->itemid, 0, 0); + + if ( !$item ) + { + return _ERROR_NOSUCHITEM; + } + + if ( $item['closed'] ) + { + return _ERROR_ITEMCLOSED; + } + + // don't allow words that are too long + if ( preg_match('/[a-zA-Z0-9|\.,;:!\?=\/\\\\]{90,90}/', $comment['body']) != 0 ) + { + return _ERROR_COMMENT_LONGWORD; + } + + // check lengths of comment + if ( i18n::strlen($comment['body']) < 3 ) + { + return _ERROR_COMMENT_NOCOMMENT; + } + + if ( i18n::strlen($comment['body']) > 5000 ) + { + return _ERROR_COMMENT_TOOLONG; + } + + // only check username if no member logged in + if ( !$member->isLoggedIn() && (i18n::strlen($comment['user']) < 2) ) + { + return _ERROR_COMMENT_NOUSERNAME; + } + + if ( (i18n::strlen($comment['email']) != 0) && !NOTIFICATION::address_validation(trim($comment['email'])) ) + { + return _ERROR_BADMAILADDRESS; + } + + // let plugins do verification (any plugin which thinks the comment is invalid + // can change 'error' to something other than '1') + $result = 1; + $data = array('type' => 'comment', 'comment' => &$comment, 'error' => &$result, 'spamcheck' => &$spamcheck); + $manager->notify('ValidateForm', $data); + + return $result; + } +} +>>>>>>> skinnable-master diff --git a/nucleus/libs/ENCAPSULATE.php b/nucleus/libs/ENCAPSULATE.php deleted file mode 100644 index 4318774..0000000 --- a/nucleus/libs/ENCAPSULATE.php +++ /dev/null @@ -1,260 +0,0 @@ - 0) { - $this->showHead(); - echo $list; - $this->showFoot(); - } else { - echo $errorMessage; - } - - return $nbOfRows; - } -} - -/** - * A class used to encapsulate a list of some sort inside next/prev buttons - */ -class NavList extends Encapsulate -{ - function __construct($action, $start, $amount, $minamount, $maxamount, $blogid, $search, $itemid) { - $this->action = $action; - $this->start = $start; - $this->amount = $amount; - $this->minamount = $minamount; - $this->maxamount = $maxamount; - $this->blogid = $blogid; - $this->search = $search; - $this->itemid = $itemid; - } - - function showBatchList($batchtype, $query, $type, $template, $errorMessage = _LISTS_NOMORE) { - $batch = new Batch($batchtype); - - $this->doEncapsulate( - array(&$batch, 'showlist'), - array(&$query, $type, $template), - $errorMessage - ); - - } - - - function showHead() { - $this->showNavigation(); - } - function showFoot() { - $this->showNavigation(); - } - - /** - * Displays a next/prev bar for long tables - */ - function showNavigation() { - $action = $this->action; - $start = $this->start; - $amount = $this->amount; - $minamount = $this->minamount; - $maxamount = $this->maxamount; - $blogid = $this->blogid; - $search = Entity::hsc($this->search); - $itemid = $this->itemid; - - $prev = $start - $amount; - if ($prev < $minamount) $prev=$minamount; - - // maxamount not used yet - // if ($start + $amount <= $maxamount) - $next = $start + $amount; - // else - // $next = $start; - - ?> - - - - type = $type; - } - - function showHead() { - ?> -
    - showOperationList(); - } - - function showFoot() { - $this->showOperationList(); - ?> -
    - -
    - - - - addTicketHidden(); - - // add hidden fields for 'team' and 'comment' batchlists - if ($this->type == 'team') - { - echo ''; - } - if ($this->type == 'comment') - { - echo ''; - } - - echo ''; - ?>( - - - - ) -
    - doEncapsulate( 'showlist', - array($query, $type, $template), - $errorMessage - ); - } - -} -?> diff --git a/nucleus/libs/ENTITY.php b/nucleus/libs/ENTITY.php index 524f748..413d324 100644 --- a/nucleus/libs/ENTITY.php +++ b/nucleus/libs/ENTITY.php @@ -1,664 +1,664 @@ -]*>.+<\/del[^>]*>#isU", '', $string); - $string = preg_replace("#]*>.+<\/script[^>]*>#isU", '', $string); - $string = preg_replace("#]*>.+<\/style[^>]*>#isU", '', $string); - $string = preg_replace('#>#', '> ', $string); - $string = preg_replace('#<#', ' <', $string); - $string = strip_tags($string); - $string = preg_replace("#\s+#", " ", $string); - $string = trim($string); - return $string; - } - - /** - * shortens a text string to maxlength. - * $suffix is what needs to be added at the end (end length is <= $maxlength) - * - * The purpose is to limit the width of string for rendered screen in web browser. - * So it depends on style sheet, browser's rendering scheme, client's system font. - * - * NOTE: In general, non-Latin font such as Japanese, Chinese, Cyrillic have two times as width as Latin fonts, - * but this is not always correct, for example, rendered by proportional font. - * - * @static - * @param string $escaped_string target string - * @param integer $maxlength maximum length of return string which includes suffix - * @param string $suffix added in the end of shortened-string - * @return string - */ - static public function shorten($string, $maxlength, $suffix) - { - static $flag; - - $decoded_entities_pcre = array(); - $encoded_entities = array(); - - /* 1. store html entities */ - preg_match('#&[^&]+?;#', $string, $encoded_entities); - if ( !$encoded_entities ) - { - $flag = FALSE; - } - else - { - $flag = TRUE; - } - if ( $flag ) - { - foreach ( $encoded_entities as $encoded_entity ) - { - $decoded_entities_pcre[] = '#' . html_entity_decode($encoded_entity, ENT_QUOTES, i18n::get_current_charset()) . '#'; - } - } - - /* 2. decode string */ - $string = html_entity_decode($string, ENT_QUOTES, i18n::get_current_charset()); - - /* 3. shorten string and add suffix if string length is longer */ - if ( i18n::strlen($string) > $maxlength - i18n::strlen($suffix) ) - { - $string = i18n::substr($string, 0, $maxlength - i18n::strlen($suffix) ); - $string .= $suffix; - } - - /* 4. recover entities */ - if ( $flag ) - { - $string = preg_replace($decoded_entities_pcre, $encoded_entities, $string); - } - - return $string; - } - - /** - * Entity::highlight() - * highlights a specific query in a given HTML text (not within HTML tags) - * - * @static - * @param string $text text to be highlighted - * @param string $expression regular expression to be matched (can be an array of expressions as well) - * @param string $highlight highlight to be used (use \\0 to indicate the matched expression) - * @return string - */ - static public function highlight($text, $expression, $highlight) - { - if ( !$highlight || !$expression ) - { - return $text; - } - - if ( is_array($expression) && (count($expression) == 0) ) - { - return $text; - } - - $text = "{$text}"; - preg_match_all('#(<[^>]+>)([^<>]*)#', $text, $matches); - $result = ''; - $count = count($matches[2]); - - for ( $i = 0; $i < $count; $i++ ) - { - if ( $i != 0 ) - { - $result .= $matches[1][$i]; - } - - if ( is_array($expression) ) - { - foreach ( $expression as $regex ) - { - $matches[2][$i] = preg_replace("#{$regex}#i", $highlight, $matches[2][$i]); - } - $result .= $matches[2][$i]; - } - else - { - $result .= preg_replace("#{$expression}#i", $highlight, $matches[2][$i]); - } - } - return $result; - } - - /** - * Entity::anchor_footnoting() - * change strings with footnoticing generated from anchor elements - * - * @static - * @param String $string strings which includes html elements - * @return String string with footnotes - */ - static public function anchor_footnoting($string) - { - /* 1. detect anchor elements */ - $anchors = array(); - if ( !preg_match_all("#]*href=[\"\']([^\"^']*)[\"\'][^>]*>([^<]*)<\/a>#i", $subject, $anchors) ) - { - return $string; - } - - /* 2. add footnotes */ - $string .= "\n\n"; - $count = 1; - foreach ( $anchors as $anchor ) - { - preg_replace("#{$anchor[0]}#", "{$anchor[2]} [{$count}] ", $subject); - $subject .= "[{$count}] {$anchor[1]}\n"; - $count++; - } - - return strip_tags($ascii); - } - - /* - * NOTE: Obsoleted functions - */ - - /** - * Entity::named_to_numeric() - * - * @deprecated - * @param String $string - */ - function named_to_numeric ($string) - { - $string = preg_replace('/(&[0-9A-Za-z]+)(;?\=?|([^A-Za-z0-9\;\:\.\-\_]))/e', "Entity::_named('\\1', '\\2') . '\\3'", $string); - return $string; - } - - /** - * Entity::named_to_numeric() - * - * @deprecated - * @param String $string - */ - function normalize_numeric ($string) { - $string = preg_replace('/&#([0-9]+)(;)?/e', "'&#x'.dechex('\\1').';'", $string); - $string = preg_replace('/&#[Xx](0)*([0-9A-Fa-f]+)(;?|([^A-Za-z0-9\;\:\.\-\_]))/e', "'&#x' . strtoupper('\\2') . ';\\4'", $string); - $string = strtr($string, self::$entities['Windows-1252']); - return $string; - } - - /** - * Entity::numeric_to_utf8() - * - * @deprecated - * @param String $string - */ - function numeric_to_utf8 ($string) { - $string = preg_replace('/&#([0-9]+)(;)?/e', "'&#x'.dechex('\\1').';'", $string); - $string = preg_replace('/&#[Xx](0)*([0-9A-Fa-f]+)(;?|([^A-Za-z0-9\;\:\.\-\_]))/e', "'&#x' . strtoupper('\\2') . ';\\4'", $string); - $string = preg_replace('/&#x([0-9A-Fa-f]+);/e', "Entity::_hex_to_utf8('\\1')", $string); - return $string; - } - - /** - * Entity::numeric_to_named() - * convert decimal and hexadecimal numeric character references into named character references - * - * @deprecated - * @param String $string - */ - function numeric_to_named ($string) - { - $string = preg_replace('/&#[Xx]([0-9A-Fa-f]+)/e', "'&#'.hexdec('\\1')", $string); - $string = strtr($string, array_flip(self::$entities['named_to_numeric'])); - return $string; - } - - /** - * Entity::specialchars() - * convert HTML entities to named character reference - * - * @deprecated - * @param String $string - */ - function specialchars ($string, $type = 'xml') - { - $specialchars = array( - '"' => '"', - '&' => '&', - '<' => '<', - '>' => '>' - ); - if ( $type != 'xml' ) - { - $specialchars["'"] = '''; - } - else - { - $specialchars["'"] = '''; - } - - $string = preg_replace('/&(#?[Xx]?[0-9A-Za-z]+);/', "[[[ENTITY:\\1]]]", $string); - $string = strtr($string, $specialchars); - $string = preg_replace('/\[\[\[ENTITY\:([^\]]+)\]\]\]/', "&\\1;", $string); - return $string; - } - - /** - * Entity::_hex_to_utf8() - * convert decimal numeric character references to hexadecimal numeric character references - * - * @deprecated - * @param String $string - */ - function _hex_to_utf8($s) - { - $c = hexdec($s); - - if ( $c < 0x80 ) - { - $str = chr($c); - } - else if ( $c < 0x800 ) - { - $str = chr(0xC0 | $c>>6) . chr(0x80 | $c & 0x3F); - } - else if ( $c < 0x10000 ) - { - $str = chr(0xE0 | $c>>12) . chr(0x80 | $c>>6 & 0x3F) . chr(0x80 | $c & 0x3F); - } - else if ( $c < 0x200000 ) - { - $str = chr(0xF0 | $c>>18) . chr(0x80 | $c>>12 & 0x3F) . chr(0x80 | $c>>6 & 0x3F) . chr(0x80 | $c & 0x3F); - } - return $str; - } - - /** - * Entity::_named() - * convert entities to named character reference - * - * @deprecated - * @param String $string - * @param String $extra - * @return - */ - function _named($entity, $extra) - { - if ( $extra == '=' ) - { - return $entity . '='; - } - - $length = i18n::strlen($entity); - - while ( $length > 0 ) - { - $check = i18n::substr($entity, 0, $length); - if ( array_key_exists($check, self::$entities['named_to_numeric']) ) - { - return self::$entities['named_to_numeric'][$check] . ';' . i18n::substr($entity, $length); - } - $length--; - } - - if ( $extra != ';' ) - { - return $entity; - } - else - { - return "{$entity};"; - } - } - - /** - * ENTITIY::$entities - * - * HTML 4.01 Specification - * @link http://www.w3.org/TR/html4/sgml/entities.html - * @see 24 Character entity references in HTML 4 - * - * XHTML™ 1.0 The Extensible HyperText Markup Language (Second Edition) - * A Reformulation of HTML 4 in XML 1.0 - * @link http://www.w3.org/TR/xhtml1/ - * @see 4.12. Entity references as hex values - * @see C.16. The Named Character Reference ' - * - * @static - * @deprecated - */ - static private $entities = array ( - 'named_to_numeric' => array ( - ' ' => ' ', - '¡' => '¡', - '¢' => '¢', - '£' => '£', - '¤' => '¤', - '¥' => '¥', - '¦' => '¦', - '§' => '§', - '¨' => '¨', - '©' => '©', - 'ª' => 'ª', - '«' => '«', - '¬' => '¬', - '­' => '­', - '®' => '®', - '¯' => '¯', - '°' => '°', - '±' => '±', - '²' => '²', - '³' => '³', - '´' => '´', - 'µ' => 'µ', - '¶' => '¶', - '·' => '·', - '¸' => '¸', - '¹' => '¹', - 'º' => 'º', - '»' => '»', - '¼' => '¼', - '½' => '½', - '¾' => '¾', - '¿' => '¿', - 'À' => 'À', - 'Á' => 'Á', - 'Â' => 'Â', - 'Ã' => 'Ã', - 'Ä' => 'Ä', - 'Å' => 'Å', - 'Æ' => 'Æ', - 'Ç' => 'Ç', - 'È' => 'È', - 'É' => 'É', - 'Ê' => 'Ê', - 'Ë' => 'Ë', - 'Ì' => 'Ì', - 'Í' => 'Í', - 'Î' => 'Î', - 'Ï' => 'Ï', - 'Ð' => 'Ð', - 'Ñ' => 'Ñ', - 'Ò' => 'Ò', - 'Ó' => 'Ó', - 'Ô' => 'Ô', - 'Õ' => 'Õ', - 'Ö' => 'Ö', - '×' => '×', - 'Ø' => 'Ø', - 'Ù' => 'Ù', - 'Ú' => 'Ú', - 'Û' => 'Û', - 'Ü' => 'Ü', - 'Ý' => 'Ý', - 'Þ' => 'Þ', - 'ß' => 'ß', - 'à' => 'à', - 'á' => 'á', - 'â' => 'â', - 'ã' => 'ã', - 'ä' => 'ä', - 'å' => 'å', - 'æ' => 'æ', - 'ç' => 'ç', - 'è' => 'è', - 'é' => 'é', - 'ê' => 'ê', - 'ë' => 'ë', - 'ì' => 'ì', - 'í' => 'í', - 'î' => 'î', - 'ï' => 'ï', - 'ð' => 'ð', - 'ñ' => 'ñ', - 'ò' => 'ò', - 'ó' => 'ó', - 'ô' => 'ô', - 'õ' => 'õ', - 'ö' => 'ö', - '÷' => '÷', - 'ø' => 'ø', - 'ù' => 'ù', - 'ú' => 'ú', - 'û' => 'û', - 'ü' => 'ü', - 'ý' => 'ý', - 'þ' => 'þ', - 'ÿ' => 'ÿ', - '&OElig' => 'Œ', - '&oelig' => 'å', - '&Scaron' => 'Š', - '&scaron' => 'š', - '&Yuml' => 'Ÿ', - '&circ' => 'ˆ', - '&tilde' => '˜', - '&esnp' => ' ', - '&emsp' => ' ', - '&thinsp' => ' ', - '&zwnj' => '‌', - '&zwj' => '‍', - '&lrm' => '‎', - '&rlm' => '‏', - '&ndash' => '–', - '&mdash' => '—', - '&lsquo' => '‘', - '&rsquo' => '’', - '&sbquo' => '‚', - '&ldquo' => '“', - '&rdquo' => '”', - '&bdquo' => '„', - '&dagger' => '†', - '&Dagger' => '‡', - '&permil' => '‰', - '&lsaquo' => '‹', - '&rsaquo' => '›', - '&euro' => '€', - '&fnof' => 'ƒ', - '&Alpha' => 'Α', - '&Beta' => 'Β', - '&Gamma' => 'Γ', - '&Delta' => 'Δ', - '&Epsilon' => 'Ε', - '&Zeta' => 'Ζ', - '&Eta' => 'Η', - '&Theta' => 'Θ', - '&Iota' => 'Ι', - '&Kappa' => 'Κ', - '&Lambda' => 'Λ', - '&Mu' => 'Μ', - '&Nu' => 'Ν', - '&Xi' => 'Ξ', - '&Omicron' => 'Ο', - '&Pi' => 'Π', - '&Rho' => 'Ρ', - '&Sigma' => 'Σ', - '&Tau' => 'Τ', - '&Upsilon' => 'Υ', - '&Phi' => 'Φ', - '&Chi' => 'Χ', - '&Psi' => 'Ψ', - '&Omega' => 'Ω', - '&alpha' => 'α', - '&beta' => 'β', - '&gamma' => 'γ', - '&delta' => 'δ', - '&epsilon' => 'ε', - '&zeta' => 'ζ', - '&eta' => 'η', - '&theta' => 'θ', - '&iota' => 'ι', - '&kappa' => 'κ', - '&lambda' => 'λ', - '&mu' => 'μ', - '&nu' => 'ν', - '&xi' => 'ξ', - '&omicron' => 'ο', - '&pi' => 'π', - '&rho' => 'ρ', - '&sigmaf' => 'ς', - '&sigma' => 'σ', - '&tau' => 'τ', - '&upsilon' => 'υ', - '&phi' => 'φ', - '&chi' => 'χ', - '&psi' => 'ψ', - '&omega' => 'ω', - '&thetasym' => 'ϑ', - '&upsih' => 'ϒ', - '&piv' => 'ϖ', - '&bull' => '•', - '&hellip' => '…', - '&prime' => '′', - '&Prime' => '″', - '&oline' => '‾', - '&frasl' => '⁄', - '&weierp' => '℘', - '&image' => 'ℑ', - '&real' => 'ℜ', - '&trade' => 'ℒ', - '&alefsym' => 'ℵ', - '&larr' => '←', - '&uarr' => '↑', - '&rarr' => '→', - '&darr' => '↓', - '&harr' => '↔', - '&crarr' => '↵', - '&lArr' => '⇐', - '&uArr' => '⇑', - '&rArr' => '⇒', - '&dArr' => '⇓', - '&hArr' => '⇔', - '&forall' => '∀', - '&part' => '∂', - '&exist' => '∃', - '&empty' => '∅', - '&nabla' => '∇', - '&isin' => '∈', - '¬in' => '∉', - '&ni' => '∋', - '&prod' => '∏', - '&sum' => '∑', - '&minus' => '−', - '&lowast' => '∗', - '&radic' => '√', - '&prop' => '∝', - '&infin' => '∞', - '&ang' => '∠', - '&and' => '∧', - '&or' => '∨', - '&cap' => '∩', - '&cup' => '∪', - '&int' => '∫', - '&there4' => '∴', - '&sim' => '∼', - '&cong' => '≅', - '&asymp' => '≈', - '&ne' => '≠', - '&equiv' => '≡', - '&le' => '≤', - '&ge' => '≥', - '&sub' => '⊂', - '&sup' => '⊃', - '&nsub' => '⊄', - '&sube' => '⊆', - '&supe' => '⊇', - '&oplus' => '⊕', - '&otimes' => '⊖', - '&perp' => '⊥', - '&sdot' => '⋅', - '&lceil' => '⍨', - '&rceil' => '⌉', - '&lfloor' => '⌊', - '&rfloor' => '⌋', - '&lang' => '〈', - '&rang' => '⌰', - '&loz' => '◊', - '&spades' => '♠', - '&clubs' => '♣', - '&hearts' => '♥', - '&diams' => '♦' - ), - 'Windows-1252' => array( - '€' => '€', - '‚' => '‚', - 'ƒ' => 'ƒ', - '„' => '„', - '…' => '…', - '†' => '†', - '‡' => '‡', - 'ˆ' => 'ˆ', - '‰' => '‰', - 'Š' => 'Š', - '‹' => '‹', - 'Œ' => 'Œ', - 'Ž' => 'Ž', - '‘' => '‘', - '’' => '’', - '“' => '“', - '”' => '”', - '•' => '•', - '–' => '–', - '—' => '—', - '˜' => '˜', - '™' => '™', - 'š' => 'š', - '›' => '›', - 'œ' => 'œ', - 'ž' => 'ž', - 'Ÿ' => 'Ÿ', - ) - ); -} +]*>.+<\/del[^>]*>#isU", '', $string); + $string = preg_replace("#]*>.+<\/script[^>]*>#isU", '', $string); + $string = preg_replace("#]*>.+<\/style[^>]*>#isU", '', $string); + $string = preg_replace('#>#', '> ', $string); + $string = preg_replace('#<#', ' <', $string); + $string = strip_tags($string); + $string = preg_replace("#\s+#", " ", $string); + $string = trim($string); + return $string; + } + + /** + * shortens a text string to maxlength. + * $suffix is what needs to be added at the end (end length is <= $maxlength) + * + * The purpose is to limit the width of string for rendered screen in web browser. + * So it depends on style sheet, browser's rendering scheme, client's system font. + * + * NOTE: In general, non-Latin font such as Japanese, Chinese, Cyrillic have two times as width as Latin fonts, + * but this is not always correct, for example, rendered by proportional font. + * + * @static + * @param string $escaped_string target string + * @param integer $maxlength maximum length of return string which includes suffix + * @param string $suffix added in the end of shortened-string + * @return string + */ + static public function shorten($string, $maxlength, $suffix) + { + static $flag; + + $decoded_entities_pcre = array(); + $encoded_entities = array(); + + /* 1. store html entities */ + preg_match('#&[^&]+?;#', $string, $encoded_entities); + if ( !$encoded_entities ) + { + $flag = FALSE; + } + else + { + $flag = TRUE; + } + if ( $flag ) + { + foreach ( $encoded_entities as $encoded_entity ) + { + $decoded_entities_pcre[] = '#' . html_entity_decode($encoded_entity, ENT_QUOTES, i18n::get_current_charset()) . '#'; + } + } + + /* 2. decode string */ + $string = html_entity_decode($string, ENT_QUOTES, i18n::get_current_charset()); + + /* 3. shorten string and add suffix if string length is longer */ + if ( i18n::strlen($string) > $maxlength - i18n::strlen($suffix) ) + { + $string = i18n::substr($string, 0, $maxlength - i18n::strlen($suffix) ); + $string .= $suffix; + } + + /* 4. recover entities */ + if ( $flag ) + { + $string = preg_replace($decoded_entities_pcre, $encoded_entities, $string); + } + + return $string; + } + + /** + * Entity::highlight() + * highlights a specific query in a given HTML text (not within HTML tags) + * + * @static + * @param string $text text to be highlighted + * @param string $expression regular expression to be matched (can be an array of expressions as well) + * @param string $highlight highlight to be used (use \\0 to indicate the matched expression) + * @return string + */ + static public function highlight($text, $expression, $highlight) + { + if ( !$highlight || !$expression ) + { + return $text; + } + + if ( is_array($expression) && (count($expression) == 0) ) + { + return $text; + } + + $text = "{$text}"; + preg_match_all('#(<[^>]+>)([^<>]*)#', $text, $matches); + $result = ''; + $count = count($matches[2]); + + for ( $i = 0; $i < $count; $i++ ) + { + if ( $i != 0 ) + { + $result .= $matches[1][$i]; + } + + if ( is_array($expression) ) + { + foreach ( $expression as $regex ) + { + $matches[2][$i] = preg_replace("#{$regex}#i", $highlight, $matches[2][$i]); + } + $result .= $matches[2][$i]; + } + else + { + $result .= preg_replace("#{$expression}#i", $highlight, $matches[2][$i]); + } + } + return $result; + } + + /** + * Entity::anchor_footnoting() + * change strings with footnoticing generated from anchor elements + * + * @static + * @param String $string strings which includes html elements + * @return String string with footnotes + */ + static public function anchor_footnoting($string) + { + /* 1. detect anchor elements */ + $anchors = array(); + if ( !preg_match_all("#]*href=[\"\']([^\"^']*)[\"\'][^>]*>([^<]*)<\/a>#i", $subject, $anchors) ) + { + return $string; + } + + /* 2. add footnotes */ + $string .= "\n\n"; + $count = 1; + foreach ( $anchors as $anchor ) + { + preg_replace("#{$anchor[0]}#", "{$anchor[2]} [{$count}] ", $subject); + $subject .= "[{$count}] {$anchor[1]}\n"; + $count++; + } + + return strip_tags($ascii); + } + + /* + * NOTE: Obsoleted functions + */ + + /** + * Entity::named_to_numeric() + * + * @deprecated + * @param String $string + */ + function named_to_numeric ($string) + { + $string = preg_replace('/(&[0-9A-Za-z]+)(;?\=?|([^A-Za-z0-9\;\:\.\-\_]))/e', "Entity::_named('\\1', '\\2') . '\\3'", $string); + return $string; + } + + /** + * Entity::named_to_numeric() + * + * @deprecated + * @param String $string + */ + function normalize_numeric ($string) { + $string = preg_replace('/&#([0-9]+)(;)?/e', "'&#x'.dechex('\\1').';'", $string); + $string = preg_replace('/&#[Xx](0)*([0-9A-Fa-f]+)(;?|([^A-Za-z0-9\;\:\.\-\_]))/e', "'&#x' . strtoupper('\\2') . ';\\4'", $string); + $string = strtr($string, self::$entities['Windows-1252']); + return $string; + } + + /** + * Entity::numeric_to_utf8() + * + * @deprecated + * @param String $string + */ + function numeric_to_utf8 ($string) { + $string = preg_replace('/&#([0-9]+)(;)?/e', "'&#x'.dechex('\\1').';'", $string); + $string = preg_replace('/&#[Xx](0)*([0-9A-Fa-f]+)(;?|([^A-Za-z0-9\;\:\.\-\_]))/e', "'&#x' . strtoupper('\\2') . ';\\4'", $string); + $string = preg_replace('/&#x([0-9A-Fa-f]+);/e', "Entity::_hex_to_utf8('\\1')", $string); + return $string; + } + + /** + * Entity::numeric_to_named() + * convert decimal and hexadecimal numeric character references into named character references + * + * @deprecated + * @param String $string + */ + function numeric_to_named ($string) + { + $string = preg_replace('/&#[Xx]([0-9A-Fa-f]+)/e', "'&#'.hexdec('\\1')", $string); + $string = strtr($string, array_flip(self::$entities['named_to_numeric'])); + return $string; + } + + /** + * Entity::specialchars() + * convert HTML entities to named character reference + * + * @deprecated + * @param String $string + */ + function specialchars ($string, $type = 'xml') + { + $specialchars = array( + '"' => '"', + '&' => '&', + '<' => '<', + '>' => '>' + ); + if ( $type != 'xml' ) + { + $specialchars["'"] = '''; + } + else + { + $specialchars["'"] = '''; + } + + $string = preg_replace('/&(#?[Xx]?[0-9A-Za-z]+);/', "[[[ENTITY:\\1]]]", $string); + $string = strtr($string, $specialchars); + $string = preg_replace('/\[\[\[ENTITY\:([^\]]+)\]\]\]/', "&\\1;", $string); + return $string; + } + + /** + * Entity::_hex_to_utf8() + * convert decimal numeric character references to hexadecimal numeric character references + * + * @deprecated + * @param String $string + */ + function _hex_to_utf8($s) + { + $c = hexdec($s); + + if ( $c < 0x80 ) + { + $str = chr($c); + } + else if ( $c < 0x800 ) + { + $str = chr(0xC0 | $c>>6) . chr(0x80 | $c & 0x3F); + } + else if ( $c < 0x10000 ) + { + $str = chr(0xE0 | $c>>12) . chr(0x80 | $c>>6 & 0x3F) . chr(0x80 | $c & 0x3F); + } + else if ( $c < 0x200000 ) + { + $str = chr(0xF0 | $c>>18) . chr(0x80 | $c>>12 & 0x3F) . chr(0x80 | $c>>6 & 0x3F) . chr(0x80 | $c & 0x3F); + } + return $str; + } + + /** + * Entity::_named() + * convert entities to named character reference + * + * @deprecated + * @param String $string + * @param String $extra + * @return + */ + function _named($entity, $extra) + { + if ( $extra == '=' ) + { + return $entity . '='; + } + + $length = i18n::strlen($entity); + + while ( $length > 0 ) + { + $check = i18n::substr($entity, 0, $length); + if ( array_key_exists($check, self::$entities['named_to_numeric']) ) + { + return self::$entities['named_to_numeric'][$check] . ';' . i18n::substr($entity, $length); + } + $length--; + } + + if ( $extra != ';' ) + { + return $entity; + } + else + { + return "{$entity};"; + } + } + + /** + * ENTITIY::$entities + * + * HTML 4.01 Specification + * @link http://www.w3.org/TR/html4/sgml/entities.html + * @see 24 Character entity references in HTML 4 + * + * XHTML™ 1.0 The Extensible HyperText Markup Language (Second Edition) + * A Reformulation of HTML 4 in XML 1.0 + * @link http://www.w3.org/TR/xhtml1/ + * @see 4.12. Entity references as hex values + * @see C.16. The Named Character Reference ' + * + * @static + * @deprecated + */ + static private $entities = array ( + 'named_to_numeric' => array ( + ' ' => ' ', + '¡' => '¡', + '¢' => '¢', + '£' => '£', + '¤' => '¤', + '¥' => '¥', + '¦' => '¦', + '§' => '§', + '¨' => '¨', + '©' => '©', + 'ª' => 'ª', + '«' => '«', + '¬' => '¬', + '­' => '­', + '®' => '®', + '¯' => '¯', + '°' => '°', + '±' => '±', + '²' => '²', + '³' => '³', + '´' => '´', + 'µ' => 'µ', + '¶' => '¶', + '·' => '·', + '¸' => '¸', + '¹' => '¹', + 'º' => 'º', + '»' => '»', + '¼' => '¼', + '½' => '½', + '¾' => '¾', + '¿' => '¿', + 'À' => 'À', + 'Á' => 'Á', + 'Â' => 'Â', + 'Ã' => 'Ã', + 'Ä' => 'Ä', + 'Å' => 'Å', + 'Æ' => 'Æ', + 'Ç' => 'Ç', + 'È' => 'È', + 'É' => 'É', + 'Ê' => 'Ê', + 'Ë' => 'Ë', + 'Ì' => 'Ì', + 'Í' => 'Í', + 'Î' => 'Î', + 'Ï' => 'Ï', + 'Ð' => 'Ð', + 'Ñ' => 'Ñ', + 'Ò' => 'Ò', + 'Ó' => 'Ó', + 'Ô' => 'Ô', + 'Õ' => 'Õ', + 'Ö' => 'Ö', + '×' => '×', + 'Ø' => 'Ø', + 'Ù' => 'Ù', + 'Ú' => 'Ú', + 'Û' => 'Û', + 'Ü' => 'Ü', + 'Ý' => 'Ý', + 'Þ' => 'Þ', + 'ß' => 'ß', + 'à' => 'à', + 'á' => 'á', + 'â' => 'â', + 'ã' => 'ã', + 'ä' => 'ä', + 'å' => 'å', + 'æ' => 'æ', + 'ç' => 'ç', + 'è' => 'è', + 'é' => 'é', + 'ê' => 'ê', + 'ë' => 'ë', + 'ì' => 'ì', + 'í' => 'í', + 'î' => 'î', + 'ï' => 'ï', + 'ð' => 'ð', + 'ñ' => 'ñ', + 'ò' => 'ò', + 'ó' => 'ó', + 'ô' => 'ô', + 'õ' => 'õ', + 'ö' => 'ö', + '÷' => '÷', + 'ø' => 'ø', + 'ù' => 'ù', + 'ú' => 'ú', + 'û' => 'û', + 'ü' => 'ü', + 'ý' => 'ý', + 'þ' => 'þ', + 'ÿ' => 'ÿ', + '&OElig' => 'Œ', + '&oelig' => 'å', + '&Scaron' => 'Š', + '&scaron' => 'š', + '&Yuml' => 'Ÿ', + '&circ' => 'ˆ', + '&tilde' => '˜', + '&esnp' => ' ', + '&emsp' => ' ', + '&thinsp' => ' ', + '&zwnj' => '‌', + '&zwj' => '‍', + '&lrm' => '‎', + '&rlm' => '‏', + '&ndash' => '–', + '&mdash' => '—', + '&lsquo' => '‘', + '&rsquo' => '’', + '&sbquo' => '‚', + '&ldquo' => '“', + '&rdquo' => '”', + '&bdquo' => '„', + '&dagger' => '†', + '&Dagger' => '‡', + '&permil' => '‰', + '&lsaquo' => '‹', + '&rsaquo' => '›', + '&euro' => '€', + '&fnof' => 'ƒ', + '&Alpha' => 'Α', + '&Beta' => 'Β', + '&Gamma' => 'Γ', + '&Delta' => 'Δ', + '&Epsilon' => 'Ε', + '&Zeta' => 'Ζ', + '&Eta' => 'Η', + '&Theta' => 'Θ', + '&Iota' => 'Ι', + '&Kappa' => 'Κ', + '&Lambda' => 'Λ', + '&Mu' => 'Μ', + '&Nu' => 'Ν', + '&Xi' => 'Ξ', + '&Omicron' => 'Ο', + '&Pi' => 'Π', + '&Rho' => 'Ρ', + '&Sigma' => 'Σ', + '&Tau' => 'Τ', + '&Upsilon' => 'Υ', + '&Phi' => 'Φ', + '&Chi' => 'Χ', + '&Psi' => 'Ψ', + '&Omega' => 'Ω', + '&alpha' => 'α', + '&beta' => 'β', + '&gamma' => 'γ', + '&delta' => 'δ', + '&epsilon' => 'ε', + '&zeta' => 'ζ', + '&eta' => 'η', + '&theta' => 'θ', + '&iota' => 'ι', + '&kappa' => 'κ', + '&lambda' => 'λ', + '&mu' => 'μ', + '&nu' => 'ν', + '&xi' => 'ξ', + '&omicron' => 'ο', + '&pi' => 'π', + '&rho' => 'ρ', + '&sigmaf' => 'ς', + '&sigma' => 'σ', + '&tau' => 'τ', + '&upsilon' => 'υ', + '&phi' => 'φ', + '&chi' => 'χ', + '&psi' => 'ψ', + '&omega' => 'ω', + '&thetasym' => 'ϑ', + '&upsih' => 'ϒ', + '&piv' => 'ϖ', + '&bull' => '•', + '&hellip' => '…', + '&prime' => '′', + '&Prime' => '″', + '&oline' => '‾', + '&frasl' => '⁄', + '&weierp' => '℘', + '&image' => 'ℑ', + '&real' => 'ℜ', + '&trade' => 'ℒ', + '&alefsym' => 'ℵ', + '&larr' => '←', + '&uarr' => '↑', + '&rarr' => '→', + '&darr' => '↓', + '&harr' => '↔', + '&crarr' => '↵', + '&lArr' => '⇐', + '&uArr' => '⇑', + '&rArr' => '⇒', + '&dArr' => '⇓', + '&hArr' => '⇔', + '&forall' => '∀', + '&part' => '∂', + '&exist' => '∃', + '&empty' => '∅', + '&nabla' => '∇', + '&isin' => '∈', + '¬in' => '∉', + '&ni' => '∋', + '&prod' => '∏', + '&sum' => '∑', + '&minus' => '−', + '&lowast' => '∗', + '&radic' => '√', + '&prop' => '∝', + '&infin' => '∞', + '&ang' => '∠', + '&and' => '∧', + '&or' => '∨', + '&cap' => '∩', + '&cup' => '∪', + '&int' => '∫', + '&there4' => '∴', + '&sim' => '∼', + '&cong' => '≅', + '&asymp' => '≈', + '&ne' => '≠', + '&equiv' => '≡', + '&le' => '≤', + '&ge' => '≥', + '&sub' => '⊂', + '&sup' => '⊃', + '&nsub' => '⊄', + '&sube' => '⊆', + '&supe' => '⊇', + '&oplus' => '⊕', + '&otimes' => '⊖', + '&perp' => '⊥', + '&sdot' => '⋅', + '&lceil' => '⍨', + '&rceil' => '⌉', + '&lfloor' => '⌊', + '&rfloor' => '⌋', + '&lang' => '〈', + '&rang' => '⌰', + '&loz' => '◊', + '&spades' => '♠', + '&clubs' => '♣', + '&hearts' => '♥', + '&diams' => '♦' + ), + 'Windows-1252' => array( + '€' => '€', + '‚' => '‚', + 'ƒ' => 'ƒ', + '„' => '„', + '…' => '…', + '†' => '†', + '‡' => '‡', + 'ˆ' => 'ˆ', + '‰' => '‰', + 'Š' => 'Š', + '‹' => '‹', + 'Œ' => 'Œ', + 'Ž' => 'Ž', + '‘' => '‘', + '’' => '’', + '“' => '“', + '”' => '”', + '•' => '•', + '–' => '–', + '—' => '—', + '˜' => '˜', + '™' => '™', + 'š' => 'š', + '›' => '›', + 'œ' => 'œ', + 'ž' => 'ž', + 'Ÿ' => 'Ÿ', + ) + ); +} diff --git a/nucleus/libs/ITEM.php b/nucleus/libs/ITEM.php index 475f6a3..0fce570 100644 --- a/nucleus/libs/ITEM.php +++ b/nucleus/libs/ITEM.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD 'added', 'draftid' => $itemid); } } +======= +itemid = $item_id; + return; + } + + /** + * Item::getitem() + * Returns one item with the specific itemid + * + * @static + * @param int $item_id + * @param bool $allow_draft + * @param bool $allow_future + * @return mixed + */ + static public function getitem($item_id, $allow_draft, $allow_future) + { + global $manager; + + $item_id = (integer) $item_id; + + $query = 'SELECT ' . + 'i.idraft AS draft, ' . + 'i.inumber AS itemid, ' . + 'i.iclosed AS closed, ' . + 'i.ititle AS title, ' . + 'i.ibody AS body, ' . + 'm.mname AS author, ' . + 'i.iauthor AS authorid, ' . + 'i.itime, ' . + 'i.imore AS more, ' . + 'i.ikarmapos AS karmapos, ' . + 'i.ikarmaneg AS karmaneg, ' . + 'i.icat AS catid, ' . + 'i.iblog AS blogid ' . + 'FROM %s AS i, %s AS m, %s AS b ' . + 'WHERE i.inumber = %d ' . + 'AND i.iauthor = m.mnumber ' . + 'AND i.iblog = b.bnumber '; + + $query = sprintf($query, sql_table('item'), sql_table('member'), sql_table('blog'), $item_id); + + if ( !$allow_draft ) + { + $query .= "AND i.idraft = 0 "; + } + + if ( !$allow_future ) + { + $blog =& $manager->getBlog(getBlogIDFromItemID($item_id)); + $query .= 'AND i.itime <= ' . DB::formatDateTime($blog->getCorrectTime()); + } + + $query .= ' LIMIT 1'; + $result = DB::getResult($query); + + if ( $result->rowCount() != 1 ) + { + return 0; + } + + $aItemInfo = $result->fetch(PDO::FETCH_ASSOC); + $aItemInfo['timestamp'] = strtotime($aItemInfo['itime']); + return $aItemInfo; + } + + /** + * Item::createFromRequest() + * Tries to create an item from the data in the current request (comes from + * bookmarklet or admin area + * + * @static + * @param void + * @return array (status = added/error/newcategory, message) + * + */ + static public function createFromRequest() + { + global $member, $manager; + + /* + * TODO: these values from user agent should be validated but not implemented yet + */ + $i_author = $member->getID(); + $i_body = postVar('body'); + $i_title = postVar('title'); + $i_more = postVar('more'); + $i_actiontype = postVar('actiontype'); + $i_closed = intPostVar('closed'); + $i_hour = intPostVar('hour'); + $i_minutes = intPostVar('minutes'); + $i_month = intPostVar('month'); + $i_day = intPostVar('day'); + $i_year = intPostVar('year'); + $i_catid = postVar('catid'); + $i_draftid = intPostVar('draftid'); + + if ( !$member->canAddItem($i_catid) ) + { + return array('status' => 'error', 'message' => _ERROR_DISALLOWED); + } + + if ( !in_array($i_actiontype, self::$actiontypes) ) + { + $i_actiontype = 'addnow'; + } + + $i_draft = (integer) ( $i_actiontype == 'adddraft' ); + + if ( !trim($i_body) ) + { + return array('status' => 'error', 'message' => _ERROR_NOEMPTYITEMS); + } + + // create new category if needed + if ( i18n::strpos($i_catid, 'newcat') === 0 ) + { + // get blogid + list($i_blogid) = sscanf($i_catid, "newcat-%d"); + + // create + $blog =& $manager->getBlog($i_blogid); + $i_catid = $blog->createNewCategory(); + + // show error when sth goes wrong + if ( !$i_catid ) + { + return array('status' => 'error','message' => 'Could not create new category'); + } + } + else + { + // force blogid (must be same as category id) + $i_blogid = getBlogIDFromCatID($i_catid); + $blog =& $manager->getBlog($i_blogid); + } + + if ( $i_actiontype == 'addfuture' ) + { + $posttime = mktime($i_hour, $i_minutes, 0, $i_month, $i_day, $i_year); + + // make sure the date is in the future, unless we allow past dates + if ( (!$blog->allowPastPosting()) && ($posttime < $blog->getCorrectTime()) ) + { + $posttime = $blog->getCorrectTime(); + } + } + else + { + if ( !$i_draft ) + { + $posttime = $blog->getCorrectTime(); + } + else + { + $posttime = 0; + } + } + + if ( $posttime > $blog->getCorrectTime() ) + { + $posted = 0; + $blog->setFuturePost(); + } + else + { + $posted = 1; + } + + $itemid = $blog->additem($i_catid, $i_title, $i_body, $i_more, $i_blogid, $i_author, $posttime, $i_closed, $i_draft, $posted); + + //Setting the itemOptions + $aOptions = requestArray('plugoption'); + NucleusPlugin::apply_plugin_options($aOptions, $itemid); + $data = array( + 'context' => 'item', + 'itemid' => $itemid, + 'item' => array( + 'title' => $i_title, + 'body' => $i_body, + 'more' => $i_more, + 'closed' => $i_closed, + 'catid' => $i_catid + ) + ); + + $manager->notify('PostPluginOptionsUpdate', $data); + + if ( $i_draftid > 0 ) + { + // delete permission is checked inside Item::delete() + self::delete($i_draftid); + } + + // success + if ( $i_catid != intRequestVar('catid') ) + { + return array('status' => 'newcategory', 'itemid' => $itemid, 'catid' => $i_catid); + } + + return array('status' => 'added', 'itemid' => $itemid); + } + + /** + * Item::update() + * Updates an item + * + * @static + * @param integer $itemid item id + * @param integer $catid category id + * @param string $title title + * @param string $body body text + * @param string $more more text + * @param boolean $closed closed or not + * @param boolean $wasdraft previously draft or not + * @param boolean $publish published or not + * @param timestamp $timestamp timestamp + * @return void + */ + static public function update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp = 0) + { + global $manager; + + $itemid = (integer) $itemid; + $closed = (boolean) $closed; + + // get destination blogid + $new_blogid = getBlogIDFromCatID($catid); + $old_blogid = getBlogIDFromItemID($itemid); + + // move will be done on end of method + $moveNeeded = 0; + if ( $new_blogid != $old_blogid ) + { + $moveNeeded = 1; + } + + $blog =& $manager->getBlog($new_blogid); + + // begin if: convert line breaks to
    + if ( $blog->convertBreaks() ) + { + $body = addBreaks($body); + $more = addBreaks($more); + } + + // call plugins + $data = array( + 'itemid' => $itemid, + 'title' => &$title, + 'body' => &$body, + 'more' => &$more, + 'blog' => &$blog, + 'closed' => &$closed, + 'catid' => &$catid + ); + $manager->notify('PreUpdateItem', $data); + + // update item itself + $query = 'UPDATE ' . sql_table('item') + . ' SET' + . ' ibody = ' . DB::quoteValue($body) . ',' + . ' ititle = ' . DB::quoteValue($title) . ',' + . ' imore = ' . DB::quoteValue($more) . ',' + . ' iclosed = ' . intval($closed) . ',' + . ' icat = ' . intval($catid); + + // if we received an updated timestamp that is in the past, but past posting is not allowed, + // reject that date change (timestamp = 0 will make sure the current date is kept) + if ( (!$blog->allowPastPosting()) && ($timestamp < $blog->getCorrectTime()) ) + { + $timestamp = 0; + } + + // begin if: post is in the future + if ( $timestamp > $blog->getCorrectTime(time()) ) + { + $isFuture = 1; + $query .= ', iposted = 0'; + } + else + { + $isFuture = 0; + $query .= ', iposted = 1'; + } + + if ( $wasdraft && $publish ) + { + // set timestamp to current date only if it's not a future item + // draft items have timestamp == 0 + // don't allow timestamps in the past (unless otherwise defined in blogsettings) + $query .= ', idraft = 0'; + + if ( $timestamp == 0 ) + { + $timestamp = $blog->getCorrectTime(); + } + + // send new item notification + if ( !$isFuture && $blog->getNotifyAddress() && $blog->notifyOnNewItem() ) + { + $blog->sendNewItemNotification($itemid, $title, $body); + } + } + + // save back to drafts + if ( !$wasdraft && !$publish ) + { + $query .= ', idraft = 1'; + // set timestamp back to zero for a draft + $query .= ', itime = ' . DB::formatDateTime($timestamp); + } + + // update timestamp when needed + if ( $timestamp != 0 ) + { + $query .= ', itime = ' . DB::formatDateTime($timestamp); + } + + // make sure the correct item is updated + $query .= ' WHERE inumber = ' . $itemid; + + // off we go! + DB::execute($query); + + $data = array('itemid' => $itemid); + $manager->notify('PostUpdateItem', $data); + + // when needed, move item and comments to new blog + if ( $moveNeeded ) + { + self::move($itemid, $catid); + } + + //update the itemOptions + $aOptions = requestArray('plugoption'); + NucleusPlugin::apply_plugin_options($aOptions); + $data = array( + 'context' => 'item', + 'itemid' => $itemid, + 'item' => array( + 'title' => $title, + 'body' => $body, + 'more' => $more, + 'closed' => $closed, + 'catid' => $catid + ) + ); + $manager->notify('PostPluginOptionsUpdate', $data); + return; + } + + /** + * Item::move() + * Move an item to another blog (no checks) + * + * @static + * @param integer $itemid + * @param integer $new_catid + * @return void + */ + static public function move($itemid, $new_catid) + { + global $manager; + + $itemid = (integer) $itemid; + $new_catid = (integer) $new_catid; + $new_blogid = getBlogIDFromCatID($new_catid); + + $data = array( + 'itemid' => $itemid, + 'destblogid' => $new_blogid, + 'destcatid' => $new_catid + ); + $manager->notify('PreMoveItem', $data); + + // update item table + $query = "UPDATE %s SET iblog=%d, icat=%d WHERE inumber=%d"; + $query = sprintf($query, sql_table('item'), $new_blogid, $new_catid, $itemid); + DB::execute($query); + + // update comments + $query = "UPDATE %s SET cblog=%d WHERE citem=%d"; + $query = sprintf($query, sql_table('comment'), $new_blogid, $itemid); + DB::execute($query); + + $data = array( + 'itemid' => $itemid, + 'destblogid' => $new_blogid, + 'destcatid' => $new_catid + ); + $manager->notify('PostMoveItem', $data); + return; + } + + /** + * Item::delete() + * Deletes an item + * + * @param integer $itemid + * @return void + */ + static public function delete($itemid) + { + global $manager, $member; + + $itemid = (integer) $itemid; + + // check permission + if ( !$member->canAlterItem($itemid) ) + { + return 1; + } + + $data = array('itemid' => $itemid); + $manager->notify('PreDeleteItem', $data); + + // delete item + $query = "DELETE FROM %s WHERE inumber=%d;"; + $query = sprintf($query, sql_table('item'), $itemid); + DB::execute($query); + + // delete the comments associated with the item + $query = "DELETE FROM %s WHERE citem=%d;"; + $query = sprintf($query, sql_table('comment'), $itemid); + DB::execute($query); + + // delete all associated plugin options + NucleusPlugin::delete_option_values('item', $itemid); + + $manager->notify('PostDeleteItem', $data); + + return 0; + } + + /** + * Item::exists() + * Returns true if there is an item with the given ID + * + * @static + * @param integer $itemid + * @param boolean $future + * @param boolean $draft + * @return boolean exists or not + */ + static public function exists($itemid, $future, $draft) + { + global $manager; + + $itemid = (integer) $itemid; + + $query = 'SELECT * FROM %s WHERE inumber=%d'; + $query = sprintf($query, sql_table('item'), $itemid); + + if ( !$future ) + { + $blogid = getBlogIDFromItemID($itemid); + if ( !$blogid ) + { + return 0; + } + $blog =& $manager->getBlog($blogid); + $query .= ' AND itime<=' . DB::formatDateTime($blog->getCorrectTime()); + } + + if ( !$draft ) + { + $query .= ' AND idraft=0'; + } + + $result = DB::getResult($query); + return ( $result->rowCount() != 0 ); + } + + /** + * Item::createDraftFromRequest() + * Tries to create an draft from the data + * in the current request (comes from bookmarklet or admin area) + * Used by xmlHTTPRequest AutoDraft + * + * Returns an array with status info: + * status = 'added', 'error', 'newcategory' + * + * @static + * @param void + * @return array (status = added/error/newcategory, message) + */ + static public function createDraftFromRequest() + { + global $member, $manager; + + /* + * TODO: these values from user agent should be validated but not implemented yet + */ + $i_author = $member->getID(); + $i_body = postVar('body'); + $i_title = postVar('title'); + $i_more = postVar('more'); + $i_closed = intPostVar('closed'); + $i_catid = postVar('catid'); + $i_draft = 1; + $type = postVar('type'); + $i_draftid = intPostVar('draftid'); + + if ( $type == 'edit' ) + { + $itemid = intPostVar('itemid'); + $i_blogid = getBlogIDFromItemID($itemid); + } + else + { + $i_blogid = intPostVar('blogid'); + } + + if ( !$member->canAddItem($i_catid) ) + { + return array('status' => 'error', 'message' => _ERROR_DISALLOWED); + } + + if ( !trim($i_body) ) + { + return array('status' => 'error', 'message' => _ERROR_NOEMPTYITEMS); + } + + // create new category if needed + if ( i18n::strpos($i_catid,'newcat') === 0 ) + { + // Set in default category + $blog =& $manager->getBlog($i_blogid); + $i_catid = $blog->getDefaultCategory(); + } + else + { + // force blogid (must be same as category id) + $i_blogid = getBlogIDFromCatID($i_catid); + $blog =& $manager->getBlog($i_blogid); + } + + $posttime = 0; + + if ( $i_draftid > 0 ) + { + self::update($i_draftid, $i_catid, $i_title, $i_body, $i_more, $i_closed, 1, 0, 0); + $itemid = $i_draftid; + } + else + { + $itemid = $blog->additem($i_catid, $i_title, $i_body, $i_more, $i_blogid, $i_author, $posttime, $i_closed, $i_draft); + } + + return array('status' => 'added', 'draftid' => $itemid); + } +} +>>>>>>> skinnable-master diff --git a/nucleus/libs/ITEMACTIONS.php b/nucleus/libs/ITEMACTIONS.php index 9aa96d4..7db9281 100644 --- a/nucleus/libs/ITEMACTIONS.php +++ b/nucleus/libs/ITEMACTIONS.php @@ -14,7 +14,11 @@ * * @license http://nucleuscms.org/license.txt GNU General Public License * @copyright Copyright (C) 2002-2009 The Nucleus Group +<<<<<<< HEAD * @version $Id: ITEMACTIONS.php 1757 2012-04-15 09:02:32Z sakamocchi $ +======= + * @version $Id: ITEMACTIONS.php 1886 2012-06-17 08:27:27Z sakamocchi $ +>>>>>>> skinnable-master */ class ItemActions extends BaseActions { @@ -101,7 +105,11 @@ class ItemActions extends BaseActions /* actions defined in BodyAction class */ 'image', 'media', +<<<<<<< HEAD 'popup', +======= + 'popup' +>>>>>>> skinnable-master ); /** @@ -753,9 +761,16 @@ class ItemActions extends BaseActions array_shift($params); // add item reference (array_unshift didn't work) +<<<<<<< HEAD $params = array_merge(array(&$this->currentItem),$params); call_user_func_array(array(&$plugin,'doTemplateVar'), $params); +======= + $target = array(&$this->currentItem); + $params = array_merge($target,$params); + + call_user_func_array(array($plugin,'doTemplateVar'), $params); +>>>>>>> skinnable-master return; } @@ -817,7 +832,12 @@ class ItemActions extends BaseActions $handler->setCurrentItem($this->currentItem); $parser = new Parser($handler); +<<<<<<< HEAD $parser->parse($handler->highlight($data)); +======= + $highlight = $handler->highlight($data); + $parser->parse($highlight); +>>>>>>> skinnable-master return; } @@ -847,8 +867,14 @@ class ItemActions extends BaseActions $condition = ($blog && ($blog->getSetting($name) == $value)); break; case 'itemblogsetting': +<<<<<<< HEAD $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem['itemid'])); $condition = ($b && ($b->getSetting($name) == $value)); +======= + $item =& $manager->getItem($this->currentItem['itemid'], 1, 1); + $t_blog =& $manager->getBlog($item['blogid']); + $condition = ($t_blog && ($t_blog->getSetting($name) == $value)); +>>>>>>> skinnable-master break; case 'loggedin': $condition = $member->isLoggedIn(); @@ -920,8 +946,11 @@ class ItemActions extends BaseActions { global $member, $manager; +<<<<<<< HEAD $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem['itemid'])); +======= +>>>>>>> skinnable-master // when no parameter is defined, just check if author is current visitor if ( ($key != 'isadmin' && $key != 'name') || ($key == 'name' && $value == '') ) { @@ -941,6 +970,7 @@ class ItemActions extends BaseActions // check if author is admin if ( ($key == 'isadmin') ) { +<<<<<<< HEAD $aid = intval($this->currentItem['authorid']); $blogid = intval($b->getID()); $amember =& $manager->getMember($aid); @@ -949,6 +979,14 @@ class ItemActions extends BaseActions return TRUE; } return (boolean) $amember->isBlogAdmin($blogid); +======= + $i_author =& $manager->getMember($this->currentItem['authorid']); + if ( $i_author->isAdmin() ) + { + return TRUE; + } + return (boolean) $i_author->isBlogAdmin($this->currentItem['blogid']); +>>>>>>> skinnable-master } return FALSE; @@ -966,12 +1004,20 @@ class ItemActions extends BaseActions { global $catid, $manager; +<<<<<<< HEAD $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem['itemid'])); +======= + $blog =& $manager->getBlog($this->currentItem['blogid']); +>>>>>>> skinnable-master // when no parameter is defined, just check if a category is selected if ( ($key != 'catname' && $key != 'catid') || ($value == '') ) { +<<<<<<< HEAD return (boolean) $b->isValidCategory($catid); +======= + return (boolean) $blog->isValidCategory($catid); +>>>>>>> skinnable-master } $icatid = $this->currentItem['catid']; @@ -979,17 +1025,28 @@ class ItemActions extends BaseActions // check category name if ( $key == 'catname' ) { +<<<<<<< HEAD $value = $b->getCategoryIdFromName($value); if ( $value == $icatid ) { return (boolean) $b->isValidCategory($icatid); +======= + $value = $blog->getCategoryIdFromName($value); + if ( $value == $icatid ) + { + return (boolean) $blog->isValidCategory($icatid); +>>>>>>> skinnable-master } } // check category id if ( ($key == 'catid') && ($value == $icatid) ) { +<<<<<<< HEAD return (boolean) $b->isValidCategory($icatid); +======= + return (boolean) $blog->isValidCategory($icatid); +>>>>>>> skinnable-master } return FALSE; } @@ -1123,6 +1180,10 @@ class ItemActions extends BaseActions $params = func_get_args(); array_shift($params); +<<<<<<< HEAD return (boolean) call_user_func_array(array(&$plugin, 'doIf'), $params); +======= + return (boolean) call_user_func_array(array($plugin, 'doIf'), $params); +>>>>>>> skinnable-master } } diff --git a/nucleus/libs/KARMA.php b/nucleus/libs/KARMA.php index 1c7dcb4..5471c04 100644 --- a/nucleus/libs/KARMA.php +++ b/nucleus/libs/KARMA.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD +======= +itemid = intval($itemid); + + // have we read the karma info yet? + $this->inforead = intval($initread); + + // number of positive and negative votes + $this->karmapos = intval($initpos); + $this->karmaneg = intval($initneg); + } + + function getNbPosVotes() { + if (!$this->inforead) $this->readFromDatabase(); + return $this->karmapos; + } + function getNbNegVotes() { + if (!$this->inforead) $this->readFromDatabase(); + return $this->karmaneg; + } + function getNbOfVotes() { + if (!$this->inforead) $this->readFromDatabase(); + return ($this->karmapos + $this->karmaneg); + } + function getTotalScore() { + if (!$this->inforead) $this->readFromDatabase(); + return ($this->karmapos - $this->karmaneg); + } + + function setNbPosVotes($val) { + $this->karmapos = intval($val); + } + function setNbNegVotes($val) { + $this->karmaneg = intval($val); + } + + + // adds a positive vote + function votePositive() { + $newKarma = $this->getNbPosVotes() + 1; + $this->setNbPosVotes($newKarma); + $this->writeToDatabase(); + $this->saveIP(); + } + + // adds a negative vote + function voteNegative() { + $newKarma = $this->getNbNegVotes() + 1; + $this->setNbNegVotes($newKarma); + $this->writeToDatabase(); + $this->saveIP(); + } + + + + // these methods shouldn't be called directly + function readFromDatabase() { + $query = 'SELECT ikarmapos, ikarmaneg FROM '.sql_table('item').' WHERE inumber=' . $this->itemid; + $res = DB::getRow($query); + + $this->karmapos = $res['ikarmapos']; + $this->karmaneg = $res['ikarmaneg']; + $this->inforead = 1; + } + + + function writeToDatabase() { + $query = 'UPDATE '.sql_table('item').' SET ikarmapos=' . $this->karmapos . ', ikarmaneg='.$this->karmaneg.' WHERE inumber=' . $this->itemid; + DB::execute($query); + } + + // checks if a vote is still allowed for an IP + function isVoteAllowed($ip) { + $query = 'SELECT * FROM '.sql_table('karma')." WHERE itemid={$this->itemid} and ip=". DB::quoteValue($ip); + $res = DB::getResult($query); + return ($res->rowCount() == 0); + } + + // save IP in database so no multiple votes are possible + function saveIP() { + $query = 'INSERT INTO ' . sql_table('karma') .' (itemid, ip) VALUES (' . $this->itemid . ','. DB::quoteValue(serverVar('REMOTE_ADDR')) .')'; + DB::execute($query); + } +} + +?> +>>>>>>> skinnable-master diff --git a/nucleus/libs/LINK.php b/nucleus/libs/LINK.php index cbc80eb..9285a2f 100644 --- a/nucleus/libs/LINK.php +++ b/nucleus/libs/LINK.php @@ -1,272 +1,271 @@ - $itemid, 'extra' => $extra) ); - } - - /** - * Link::create_member_link() - * Create a link to a member - * - * @static - * @param $memberid member id - * @param $extra extra parameter - */ - static public function create_member_link($memberid, $extra = '') { - return self::create_link('member', array('memberid' => $memberid, 'extra' => $extra) ); - } - - /** - * Link::create_category_link() - * Create a link to a category - * - * @static - * @param $catid category id - * @param $extra extra parameter - */ - static public function create_category_link($catid, $extra = '') { - return self::create_link('category', array('catid' => $catid, 'extra' => $extra) ); - } - - /** - * Link::cteate_archive_link() - * Create a link to an archive - * - * @static - * @param $blogid blog id - * @param $archive archive identifier - * @param $extra extra parameter - */ - static public function create_archive_link($blogid, $archive, $extra = '') { - return self::create_link('archive', array('blogid' => $blogid, 'archive' => $archive, 'extra' => $extra) ); - } - - /** - * Link::create_archivelist_link() - * Create a link to an archive list - * - * @static - * @param $blogid blog id - * @param $extra extra parameter - */ - static public function create_archivelist_link($blogid = '', $extra = '') { - return self::create_link('archivelist', array('blogid' => $blogid, 'extra' => $extra) ); - } - - /** - * Link::create_blogid_link() - * Create a link to a blog - * - * @static - * @param $blogid blog id - * @param $extra extra parameter - */ - static public function create_blogid_link($blogid, $params = '') { - return self::create_link('blog', array('blogid' => $blogid, 'extra' => $params) ); - } - - /** - * Link::create_link() - * Create a link - * - * Universell function that creates link of different types (like item, blog ...) - * and with an array of parameters - * - * @static - * @param $type type of the link - * @param $params array with parameters - */ - static public function create_link($type, $params) { - global $manager, $CONF; - - $generatedURL = ''; - $usePathInfo = ($CONF['URLMode'] == 'pathinfo'); - - // ask plugins first - $created = false; - - if ($usePathInfo) - { - $manager->notify( - 'GenerateURL', - array( - 'type' => $type, - 'params' => $params, - 'completed' => &$created, - 'url' => &$url - ) - ); - } - - // if a plugin created the URL, return it - if ($created) - { - return $url; - } - - // default implementation - switch ($type) { - case 'item': - if ($usePathInfo) { - $url = $CONF['ItemURL'] . '/' . $CONF['ItemKey'] . '/' . $params['itemid']; - } else { - $url = $CONF['ItemURL'] . '?itemid=' . $params['itemid']; - } - break; - - case 'member': - if ($usePathInfo) { - $url = $CONF['MemberURL'] . '/' . $CONF['MemberKey'] . '/' . $params['memberid']; - } else { - $url = $CONF['MemberURL'] . '?memberid=' . $params['memberid']; - } - break; - - case 'category': - if ($usePathInfo) { - $url = $CONF['CategoryURL'] . '/' . $CONF['CategoryKey'] . '/' . $params['catid']; - } else { - $url = $CONF['CategoryURL'] . '?catid=' . $params['catid']; - } - break; - - case 'archivelist': - if (!$params['blogid']) { - $params['blogid'] = $CONF['DefaultBlog']; - } - - if ($usePathInfo) { - $url = $CONF['ArchiveListURL'] . '/' . $CONF['ArchivesKey'] . '/' . $params['blogid']; - } else { - $url = $CONF['ArchiveListURL'] . '?archivelist=' . $params['blogid']; - } - break; - - case 'archive': - if ($usePathInfo) { - $url = $CONF['ArchiveURL'] . '/' . $CONF['ArchiveKey'] . '/'.$params['blogid'].'/' . $params['archive']; - } else { - $url = $CONF['ArchiveURL'] . '?blogid='.$params['blogid'].'&archive=' . $params['archive']; - } - break; - - case 'blog': - if ($usePathInfo) { - $url = $CONF['BlogURL'] . '/' . $CONF['BlogKey'] . '/' . $params['blogid']; - } else { - $url = $CONF['BlogURL'] . '?blogid=' . $params['blogid']; - } - break; - } - - return Link::add_link_params($url, (isset($params['extra'])? $params['extra'] : null)); - } - - static private function add_link_params($link, $params) - { - global $CONF; - - if (is_array($params) ) { - - if ($CONF['URLMode'] == 'pathinfo') { - - foreach ($params as $param => $value) { - // change in 3.63 to fix problem where URL generated with extra params mike look like category/4/blogid/1 - // but they should use the URL keys like this: category/4/blog/1 - // if user wants old urls back, set $CONF['NoURLKeysInExtraParams'] = 1; in config.php - if (isset($CONF['NoURLKeysInExtraParams']) && $CONF['NoURLKeysInExtraParams'] == 1) - { - $link .= '/' . $param . '/' . urlencode($value); - } else { - switch ($param) { - case 'itemid': - $link .= '/' . $CONF['ItemKey'] . '/' . urlencode($value); - break; - case 'memberid': - $link .= '/' . $CONF['MemberKey'] . '/' . urlencode($value); - break; - case 'catid': - $link .= '/' . $CONF['CategoryKey'] . '/' . urlencode($value); - break; - case 'archivelist': - $link .= '/' . $CONF['ArchivesKey'] . '/' . urlencode($value); - break; - case 'archive': - $link .= '/' . $CONF['ArchiveKey'] . '/' . urlencode($value); - break; - case 'blogid': - $link .= '/' . $CONF['BlogKey'] . '/' . urlencode($value); - break; - default: - $link .= '/' . $param . '/' . urlencode($value); - break; - } - } - } - - } else { - - foreach ($params as $param => $value) { - $link .= '&' . $param . '=' . urlencode($value); - } - - } - } - - return $link; - } - - /** - * Link::create_blog_link() - * Create an link to a blog - * - * This function considers the URLMode of the blog - * - * @static - * @param $url url - * @param $params parameters - */ - static public function create_blog_link($url, $params) { - global $CONF; - if ($CONF['URLMode'] == 'normal') { - if (i18n::strpos($url, '?') === FALSE && is_array($params)) { - $fParam = reset($params); - $fKey = key($params); - array_shift($params); - $url .= '?' . $fKey . '=' . $fParam; - } - } elseif ($CONF['URLMode'] == 'pathinfo' && i18n::substr($url, -1) == '/') { - $url = i18n::substr($url, 0, -1); - } - return addLinkParams($url, $params); - } - -} + */ +class Link +{ + + /** + * Link::create_item_link() + * Create a link to an item + * @static + * @param $itemid item id + * @param $extra extra parameter + */ + static public function create_item_link($itemid, $extra = '') { + return self::create_link('item', array('itemid' => $itemid, 'extra' => $extra) ); + } + + /** + * Link::create_member_link() + * Create a link to a member + * + * @static + * @param $memberid member id + * @param $extra extra parameter + */ + static public function create_member_link($memberid, $extra = '') { + return self::create_link('member', array('memberid' => $memberid, 'extra' => $extra) ); + } + + /** + * Link::create_category_link() + * Create a link to a category + * + * @static + * @param $catid category id + * @param $extra extra parameter + */ + static public function create_category_link($catid, $extra = '') { + return self::create_link('category', array('catid' => $catid, 'extra' => $extra) ); + } + + /** + * Link::cteate_archive_link() + * Create a link to an archive + * + * @static + * @param $blogid blog id + * @param $archive archive identifier + * @param $extra extra parameter + */ + static public function create_archive_link($blogid, $archive, $extra = '') { + return self::create_link('archive', array('blogid' => $blogid, 'archive' => $archive, 'extra' => $extra) ); + } + + /** + * Link::create_archivelist_link() + * Create a link to an archive list + * + * @static + * @param $blogid blog id + * @param $extra extra parameter + */ + static public function create_archivelist_link($blogid = '', $extra = '') { + return self::create_link('archivelist', array('blogid' => $blogid, 'extra' => $extra) ); + } + + /** + * Link::create_blogid_link() + * Create a link to a blog + * + * @static + * @param $blogid blog id + * @param $extra extra parameter + */ + static public function create_blogid_link($blogid, $params = '') { + return self::create_link('blog', array('blogid' => $blogid, 'extra' => $params) ); + } + + /** + * Link::create_link() + * Create a link + * + * Universell function that creates link of different types (like item, blog ...) + * and with an array of parameters + * + * @static + * @param $type type of the link + * @param $params array with parameters + */ + static public function create_link($type, $params) { + global $manager, $CONF; + + $generatedURL = ''; + $usePathInfo = ($CONF['URLMode'] == 'pathinfo'); + + // ask plugins first + $created = false; + + if ($usePathInfo) + { + $data = array( + 'type' => $type, + 'params' => $params, + 'completed' => &$created, + 'url' => &$url + ); + $manager->notify('GenerateURL', $data); + } + + // if a plugin created the URL, return it + if ($created) + { + return $url; + } + + // default implementation + switch ($type) { + case 'item': + if ($usePathInfo) { + $url = $CONF['ItemURL'] . '/' . $CONF['ItemKey'] . '/' . $params['itemid']; + } else { + $url = $CONF['ItemURL'] . '?itemid=' . $params['itemid']; + } + break; + + case 'member': + if ($usePathInfo) { + $url = $CONF['MemberURL'] . '/' . $CONF['MemberKey'] . '/' . $params['memberid']; + } else { + $url = $CONF['MemberURL'] . '?memberid=' . $params['memberid']; + } + break; + + case 'category': + if ($usePathInfo) { + $url = $CONF['CategoryURL'] . '/' . $CONF['CategoryKey'] . '/' . $params['catid']; + } else { + $url = $CONF['CategoryURL'] . '?catid=' . $params['catid']; + } + break; + + case 'archivelist': + if (!$params['blogid']) { + $params['blogid'] = $CONF['DefaultBlog']; + } + + if ($usePathInfo) { + $url = $CONF['ArchiveListURL'] . '/' . $CONF['ArchivesKey'] . '/' . $params['blogid']; + } else { + $url = $CONF['ArchiveListURL'] . '?archivelist=' . $params['blogid']; + } + break; + + case 'archive': + if ($usePathInfo) { + $url = $CONF['ArchiveURL'] . '/' . $CONF['ArchiveKey'] . '/'.$params['blogid'].'/' . $params['archive']; + } else { + $url = $CONF['ArchiveURL'] . '?blogid='.$params['blogid'].'&archive=' . $params['archive']; + } + break; + + case 'blog': + if ($usePathInfo) { + $url = $CONF['BlogURL'] . '/' . $CONF['BlogKey'] . '/' . $params['blogid']; + } else { + $url = $CONF['BlogURL'] . '?blogid=' . $params['blogid']; + } + break; + } + + return Link::add_link_params($url, (isset($params['extra'])? $params['extra'] : null)); + } + + static private function add_link_params($link, $params) + { + global $CONF; + + if (is_array($params) ) { + + if ($CONF['URLMode'] == 'pathinfo') { + + foreach ($params as $param => $value) { + // change in 3.63 to fix problem where URL generated with extra params mike look like category/4/blogid/1 + // but they should use the URL keys like this: category/4/blog/1 + // if user wants old urls back, set $CONF['NoURLKeysInExtraParams'] = 1; in config.php + if (isset($CONF['NoURLKeysInExtraParams']) && $CONF['NoURLKeysInExtraParams'] == 1) + { + $link .= '/' . $param . '/' . urlencode($value); + } else { + switch ($param) { + case 'itemid': + $link .= '/' . $CONF['ItemKey'] . '/' . urlencode($value); + break; + case 'memberid': + $link .= '/' . $CONF['MemberKey'] . '/' . urlencode($value); + break; + case 'catid': + $link .= '/' . $CONF['CategoryKey'] . '/' . urlencode($value); + break; + case 'archivelist': + $link .= '/' . $CONF['ArchivesKey'] . '/' . urlencode($value); + break; + case 'archive': + $link .= '/' . $CONF['ArchiveKey'] . '/' . urlencode($value); + break; + case 'blogid': + $link .= '/' . $CONF['BlogKey'] . '/' . urlencode($value); + break; + default: + $link .= '/' . $param . '/' . urlencode($value); + break; + } + } + } + + } else { + + foreach ($params as $param => $value) { + $link .= '&' . $param . '=' . urlencode($value); + } + + } + } + + return $link; + } + + /** + * Link::create_blog_link() + * Create an link to a blog + * + * This function considers the URLMode of the blog + * + * @static + * @param $url url + * @param $params parameters + */ + static public function create_blog_link($url, $params) { + global $CONF; + if ($CONF['URLMode'] == 'normal') { + if (i18n::strpos($url, '?') === FALSE && is_array($params)) { + $fParam = reset($params); + $fKey = key($params); + array_shift($params); + $url .= '?' . $fKey . '=' . $fParam; + } + } elseif ($CONF['URLMode'] == 'pathinfo' && i18n::substr($url, -1) == '/') { + $url = i18n::substr($url, 0, -1); + } + return addLinkParams($url, $params); + } + +} diff --git a/nucleus/libs/MANAGER.php b/nucleus/libs/MANAGER.php index 737899a..d41bd3d 100644 --- a/nucleus/libs/MANAGER.php +++ b/nucleus/libs/MANAGER.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD $name) + */ + private $cachedInfo; + + /** + * The plugin subscriptionlist + * + * The subcription array has the following structure + * $subscriptions[$EventName] = array containing names of plugin classes to be + * notified when that event happens + * + * NOTE: this is referred by Comments::addComment() for spamcheck API + * TODO: we should add new methods to get this + */ + public $subscriptions; + + /** + * Ticket functions. These are uses by the admin area to make it impossible to simulate certain GET/POST + * requests. tickets are user specific + */ + private $currentRequestTicket = ''; + + /** + * Returns the only instance of this class. Creates the instance if it + * does not yet exists. Users should use this function as + * $manager =& Manager::instance(); to get a reference to the object + * instead of a copy + */ + static public function &instance() + { + static $instance = array(); + if ( empty($instance) ) + { + $instance[0] = new Manager(); + } + return $instance[0]; + } + + /** + * The constructor of this class initializes the object caches + */ + public function __construct() + { + $this->items = array(); + $this->blogs = array(); + $this->plugins = array(); + $this->karma = array(); + $this->templates = array(); + $this->skins = array(); + $this->parserPrefs = array(); + $this->cachedInfo = array(); + $this->members = array(); + return; + } + + /** + * Returns the requested item object. If it is not in the cache, it will + * first be loaded and then placed in the cache. + * Intended use: $item =& $manager->getItem(1234, 0, 0) + */ + public function &getItem($itemid, $allowdraft, $allowfuture) + { + /* confirm to cached */ + if ( !array_key_exists($itemid, $this->items) ) + { + $this->loadClass('ITEM'); + $item = Item::getitem($itemid, $allowdraft, $allowfuture); + $this->items[$itemid] = $item; + } + + $item =& $this->items[$itemid]; + if ( !$allowdraft && ($item['draft']) ) + { + return 0; + } + + $blog =& $this->getBlog($item['blogid']); + if ( !$allowfuture && ($item['timestamp'] > $blog->getCorrectTime()) ) + { + return 0; + } + + return $item; + } + + /** + * Loads a class if it has not yet been loaded + */ + public function loadClass($name) + { + $this->_loadClass($name, $name . '.php'); + return; + } + + /** + * Checks if an item exists + */ + public function existsItem($id,$future,$draft) + { + $this->_loadClass('ITEM','ITEM.php'); + return Item::exists($id,$future,$draft); + } + + /** + * Checks if a category exists + */ + public function existsCategory($id) + { + return (DB::getValue('SELECT COUNT(*) as result FROM '.sql_table('category').' WHERE catid='.intval($id)) > 0); + } + + /** + * Returns the blog object for a given blogid + */ + public function &getBlog($blogid) + { + if ( !array_key_exists($blogid, $this->blogs) ) + { + $this->_loadClass('BLOG','BLOG.php'); + $this->blogs[$blogid] = new Blog($blogid); + } + return $this->blogs[$blogid]; + } + + /** + * Checks if a blog exists + */ + public function existsBlog($name) + { + $this->_loadClass('BLOG','BLOG.php'); + return Blog::exists($name); + } + + /** + * Checks if a blog id exists + */ + public function existsBlogID($id) + { + $this->_loadClass('BLOG','BLOG.php'); + return Blog::existsID($id); + } + + /** + * Returns a previously read template + */ + public function &getTemplate($templateName) + { + if ( !array_key_exists($templateName, $this->templates) ) + { + $this->_loadClass('Template','TEMPLATE.php'); + $tmplate_tmp = Template::read($templateName); + $this->templates[$templateName] =& $tmplate_tmp; + } + return $this->templates[$templateName]; + } + + /** + * Returns a KARMA object (karma votes) + */ + public function &getKarma($itemid) + { + if ( !array_key_exists($itemid, $this->karma) ) + { + $this->_loadClass('Karma','KARMA.php'); + $this->karma[$itemid] = new Karma($itemid); + } + return $this->karma[$itemid]; + } + + /** + * Returns a MEMBER object + */ + public function &getMember($memberid) + { + if ( !array_key_exists($memberid, $this->members) ) + { + $this->_loadClass('Member','MEMBER.php'); + $this->members[$memberid] =& Member::createFromID($memberid);; + } + return $this->members[$memberid]; + } + + /** + * Manager::getSkin() + * + * @param integer $skinid ID for skin + * @param string $action_class action class for handling skin variables + * @param string $event_identifier identifier for event name + * @return object instance of Skin class + */ + public function &getSkin($skinid, $action_class='Actions', $event_identifier='Skin') + { + if ( !array_key_exists($skinid, $this->skins) ) + { + $this->_loadClass('Skin', 'SKIN.php'); + $this->skins[$skinid] = new Skin($skinid, $action_class, $event_identifier); + } + + return $this->skins[$skinid]; + } + + /** + * Set the global parser preferences + */ + public function setParserProperty($name, $value) + { + $this->parserPrefs[$name] = $value; + return; + } + + /** + * Get the global parser preferences + */ + public function getParserProperty($name) + { + return $this->parserPrefs[$name]; + } + + /** + * A helper function to load a class + * + * private + */ + private function _loadClass($name, $filename) + { + global $DIR_LIBS; + + if ( !class_exists($name) ) + { + include($DIR_LIBS . $filename); + } + return; + } + + /** + * Manager::_loadPlugin() + * loading a certain plugin + * + * @param string $name plugin name + * @return void + */ + private function _loadPlugin($name) + { + global $DIR_PLUGINS, $MYSQL_HANDLER, $MYSQL_PREFIX; + + if ( class_exists($name) ) + { + return; + } + + $fileName = "{$DIR_PLUGINS}{$name}.php"; + + if ( !file_exists($fileName) ) + { + if ( !defined('_MANAGER_PLUGINFILE_NOTFOUND') ) + { + define('_MANAGER_PLUGINFILE_NOTFOUND', 'Plugin %s was not loaded (File not found)'); + } + ActionLog::add(WARNING, sprintf(_MANAGER_PLUGINFILE_NOTFOUND, $name)); + return 0; + } + + // load plugin + include($fileName); + + // check if class exists (avoid errors in eval'd code) + if ( !class_exists($name) ) + { + ActionLog::add(WARNING, sprintf(_MANAGER_PLUGINFILE_NOCLASS, $name)); + return 0; + } + + // add to plugin array + $this->plugins[$name] = new $name(); + + // get plugid + $this->plugins[$name]->setID($this->getPidFromName($name)); + + // unload plugin if a prefix is used and the plugin cannot handle this + if ( ($MYSQL_PREFIX != '') + && !$this->plugins[$name]->supportsFeature('SqlTablePrefix') ) + { + unset($this->plugins[$name]); + ActionLog::add(WARNING, sprintf(_MANAGER_PLUGINTABLEPREFIX_NOTSUPPORT, $name)); + return 0; + } + + // unload plugin if using non-mysql handler and plugin does not support it + if ( (!in_array('mysql',$MYSQL_HANDLER)) + && !$this->plugins[$name]->supportsFeature('SqlApi') ) + { + unset($this->plugins[$name]); + ActionLog::add(WARNING, sprintf(_MANAGER_PLUGINSQLAPI_NOTSUPPORT, $name)); + return 0; + } + + // call init method + $this->plugins[$name]->init(); + + return; + } + + /** + * Manager:getPlugin() + * Returns a PLUGIN object + * + * @param string $name name of plugin + * @return object plugin object + */ + public function &getPlugin($name) + { + // retrieve the name of the plugin in the right capitalisation + $name = $this->getUpperCaseName ($name); + + // get the plugin + $plugin =& $this->plugins[$name]; + + if ( !$plugin ) + { + // load class if needed + $this->_loadPlugin($name); + $plugin =& $this->plugins[$name]; + } + return $plugin; + } + + /** + * Manager::pluginLoaded() + * Checks if the given plugin IS loaded or not + * + * @param string $name name of plugin + * @return object plugin object + */ + public function &pluginLoaded($name) + { + $plugin =& $this->plugins[$name]; + return $plugin; + } + + /** + * Manager::pidLoaded() + * + * @param integer $pid id for plugin + * @return object plugin object + */ + public function &pidLoaded($pid) + { + $plugin=false; + reset($this->plugins); + while ( list($name) = each($this->plugins) ) + { + if ( $pid!=$this->plugins[$name]->getId() ) + { + continue; + } + $plugin= & $this->plugins[$name]; + break; + } + return $plugin; + } + + /** + * Manager::pluginInstalled() + * checks if the given plugin IS installed or not + * + * @param string $name name of plugin + * @return boolean exists or not + */ + public function pluginInstalled($name) + { + $this->_initCacheInfo('installedPlugins'); + return ($this->getPidFromName($name) != -1); + } + + /** + * Manager::pidInstalled() + * checks if the given plugin IS installed or not + * + * @param integer $pid id of plugin + * @return boolean exists or not + */ + public function pidInstalled($pid) + { + $this->_initCacheInfo('installedPlugins'); + return ($this->cachedInfo['installedPlugins'][$pid] != ''); + } + + /** + * Manager::getPidFromName() + * + * @param string $name name of plugin + * @return mixed id for plugin or -1 if not exists + */ + public function getPidFromName($name) + { + $this->_initCacheInfo('installedPlugins'); + foreach ( $this->cachedInfo['installedPlugins'] as $pid => $pfile ) + { + if (strtolower($pfile) == strtolower($name)) + { + return $pid; + } + } + return -1; + } + + /** + * Manager::getPluginNameFromPid() + * + * @param string $pid ID for plugin + * @return string name of plugin + */ + public function getPluginNameFromPid($pid) + { + if ( !array_key_exists($pid, $this->cachedInfo['installedPlugins']) ) + { + $query = 'SELECT pfile FROM %s WHERE pid=%d;'; + $query = sprintf($query, sql_table('plugin'), (integer) $pid); + return DB::getValue($query); + } + return $this->cachedInfo['installedPlugins'][$pid]; + } + + /** + * Manager::getUpperCaseName() + * Retrieve the name of a plugin in the right capitalisation + * + * @param string $name name of plugin + * @return string name according to UpperCamelCase + */ + public function getUpperCaseName ($name) + { + $this->_initCacheInfo('installedPlugins'); + foreach ( $this->cachedInfo['installedPlugins'] as $pid => $pfile ) + { + if ( strtolower($pfile) == strtolower($name) ) + { + return $pfile; + } + } + return -1; + } + + /** + * Manager::clearCachedInfo() + * + * @param string $what + * @return void + */ + public function clearCachedInfo($what) + { + unset($this->cachedInfo[$what]); + return; + } + + /** + * Manager::_initCacheInfo() + * Loads some info on the first call only + * + * @param string $what 'installedPlugins' + * @return void + */ + private function _initCacheInfo($what) + { + if ( array_key_exists($what, $this->cachedInfo) + && is_array($this->cachedInfo[$what]) ) + { + return; + } + + switch ($what) + { + // 'installedPlugins' = array ($pid => $name) + case 'installedPlugins': + $this->cachedInfo['installedPlugins'] = array(); + $res = DB::getResult('SELECT pid, pfile FROM ' . sql_table('plugin')); + foreach ( $res as $row ) + { + $this->cachedInfo['installedPlugins'][$row['pid']] = $row['pfile']; + } + break; + } + return; + } + + /** + * Manager::notify() + * A function to notify plugins that something has happened. Only the plugins + * that are subscribed to the event will get notified. + * Upon the first call, the list of subscriptions will be fetched from the + * database. The plugins itsself will only get loaded when they are first needed + * + * @param string $eventName Name of the event (method to be called on plugins) + * @param string $data Can contain any type of data, + * depending on the event type. Usually this is an itemid, blogid, ... + * but it can also be an array containing multiple values + * @return void + */ + public function notify($eventName, &$data) + { + // load subscription list if needed + if ( !is_array($this->subscriptions) ) + { + $this->_loadSubscriptions(); + } + + // get listening objects + $listeners = false; + if ( array_key_exists($eventName, $this->subscriptions) + && !empty($this->subscriptions[$eventName]) ) + { + $listeners = $this->subscriptions[$eventName]; + } + + // notify all of them + if ( is_array($listeners) ) + { + foreach( $listeners as $listener ) + { + // load class if needed + $this->_loadPlugin($listener); + + // do notify (if method exists) + if ( array_key_exists($listener, $this->plugins) + && !empty($this->plugins[$listener]) + && method_exists($this->plugins[$listener], 'event_' . $eventName) ) + { + call_user_func(array($this->plugins[$listener], 'event_' . $eventName), $data); + } + } + } + return; + } + + /** + * Manager::_loadSubscriptions() + * Loads plugin subscriptions + * + * @param void + * @return void + */ + private function _loadSubscriptions() + { + // initialize as array + $this->subscriptions = array(); + + $query = "SELECT p.pfile as pfile, e.event as event" + . " FROM %s as e, %s as p" + . " WHERE e.pid=p.pid ORDER BY p.porder ASC"; + $query = sprintf($query, sql_table('plugin_event'), sql_table('plugin')); + $res = DB::getResult($query); + + foreach ( $res as $row ) + { + $pluginName = $row['pfile']; + $eventName = $row['event']; + $this->subscriptions[$eventName][] = $pluginName; + } + return; + } + + /** + * Manager::getNumberOfSubscribers() + * + * @param string $event name of events + * @return integer number of event subscriber + */ + public function getNumberOfSubscribers($event) + { + $query = 'SELECT COUNT(*) as count FROM %s WHERE event=%s;'; + $query = sprintf($query, sql_table('plugin_event'), DB::quoteValue($event)); + return (integer) DB::getValue($query); + } + + /** + * Manager::addTicketToUrl() + * GET requests: Adds ticket to URL (URL should NOT be html-encoded!, ticket is added at the end) + * + * @param string url string for URI + * @return void + */ + public function addTicketToUrl($url) + { + $ticketCode = 'ticket=' . $this->_generateTicket(); + if ( i18n::strpos($url, '?') === FALSE ) + { + $ticketCode = "{$url}?{$ticketCode}"; + } + else + { + $ticketCode = "{$url}&{$ticketCode}"; + } + return $ticketCode; + } + + /** + * Manager::addTicketHidden() + * POST requests: Adds ticket as hidden formvar + * + * @param void + * @return void + */ + public function addTicketHidden() + { + $ticket = $this->_generateTicket(); + echo ''; + return; + } + + /** + * Manager::getNewTicket() + * Get a new ticket + * (xmlHTTPRequest AutoSaveDraft uses this to refresh the ticket) + * + * @param void + * @return string string of ticket + */ + public function getNewTicket() + { + $this->currentRequestTicket = ''; + return $this->_generateTicket(); + } + + /** + * Manager::checkTicket() + * Checks the ticket that was passed along with the current request + * + * @param void + * @return boolean correct or not + */ + public function checkTicket() + { + global $member; + + // get ticket from request + $ticket = requestVar('ticket'); + + // no ticket -> don't allow + if ( $ticket == '' ) + { + return FALSE; + } + + // remove expired tickets first + $this->_cleanUpExpiredTickets(); + + // get member id + if (!$member->isLoggedIn()) + { + $memberId = -1; + } + else + { + $memberId = $member->getID(); + } + + // check if ticket is a valid one + $query = sprintf('SELECT COUNT(*) as result FROM %s WHERE member=%d and ticket=%s', + sql_table('tickets'), + intval($memberId), + DB::quoteValue($ticket) + ); + + /* + * NOTE: + * [in the original implementation, the checked ticket was deleted. This would lead to invalid + * tickets when using the browsers back button and clicking another link/form + * leaving the keys in the database is not a real problem, since they're member-specific and + * only valid for a period of one hour] + */ + if ( DB::getValue($query) != 1 ) + { + return FALSE; + } + + return TRUE; + } + + /** + * Manager::_cleanUpExpiredTickets() + * Removes the expired tickets + * + * @param void + * @return void + */ + private function _cleanUpExpiredTickets() + { + // remove tickets older than 1 hour + $oldTime = time() - 60 * 60; + $query = 'DELETE FROM %s WHERE ctime < %s'; + $query = sprintf($query, sql_table('tickets'), DB::formatDateTime($oldTime)); + DB::execute($query); + return; + } + + /** + * Manager::_generateTicket() + * Generates/returns a ticket (one ticket per page request) + * + * @param void + * @return void + */ + private function _generateTicket() + { + if ( $this->currentRequestTicket == '' ) + { + // generate new ticket (only one ticket will be generated per page request) + // and store in database + global $member; + // get member id + if ( !$member->isLoggedIn() ) + { + $memberId = -1; + } + else + { + $memberId = $member->getID(); + } + + $ok = false; + while ( !$ok ) + { + // generate a random token + srand((double)microtime()*1000000); + $ticket = md5(uniqid(rand(), true)); + + // add in database as non-active + $query = 'INSERT INTO %s (ticket, member, ctime) VALUES (%s, %d, %s)'; + $query = sprintf($query, sql_table('tickets'), DB::quoteValue($ticket), (integer) $memberId, DB::formatDateTime()); + + if ( DB::execute($query) !== FALSE ) + { + $ok = true; + } + } + $this->currentRequestTicket = $ticket; + } + return $this->currentRequestTicket; + } +} + +>>>>>>> skinnable-master diff --git a/nucleus/libs/MEDIA.php b/nucleus/libs/MEDIA.php index 1c6ab00..66f8c66 100644 --- a/nucleus/libs/MEDIA.php +++ b/nucleus/libs/MEDIA.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD path}/{$this->name}", FALSE); } } +======= + '.jpeg', + 'image/png' => '.png', + 'image/gif' => '.gif', + ); + + /** + * Media::getCollectionList() + * Gets the list of collections available to the currently logged + * in member + * + * @param boolean $exceptReadOnly + * @return array dirname => display name + */ + static public function getCollectionList($exceptReadOnly = FALSE) + { + global $member, $DIR_MEDIA; + + $collections = array(); + + // add private directory for member + $collections[$member->getID()] = PRIVATE_COLLECTION; + + // add global collections + if ( !is_dir($DIR_MEDIA) ) + { + return $collections; + } + + $dirhandle = opendir($DIR_MEDIA); + while ( $dirname = readdir($dirhandle) ) + { + // only add non-numeric (numeric=private) dirs + if ( @is_dir($DIR_MEDIA . $dirname) && + ($dirname != '.') && + ($dirname != '..') && + ($dirname != self::$thumbdir) && + (!is_numeric($dirname)) ) + { + if ( @is_writable($DIR_MEDIA . $dirname) ) + { + $collections[$dirname] = $dirname; + } + else if ( $exceptReadOnly == FALSE ) + { + $collections[$dirname] = $dirname . ' ' . READ_ONLY_MEDIA_FOLDER; + } + } + } + closedir($dirhandle); + + return $collections; + } + + /** + * Media::getMediaListByCollection() + * Returns an array of MediaObject objects for a certain collection + * + * @param string $collection name of the collection + * @param string $filter filter on filename (defaults to none) + * @return void + */ + static public function getMediaListByCollection($collection, $filter = '') + { + global $CONF, $DIR_MEDIA; + + $filelist = array(); + + // 1. go through all objects and add them to the filelist + $mediadir = $DIR_MEDIA . $collection . '/'; + + // return if dir does not exist + if ( !is_dir($mediadir) ) + { + return $filelist; + } + + $dirhandle = opendir($mediadir); + while ( $filename = readdir($dirhandle) ) + { + // only add files that match the filter + if ( !is_dir($mediadir . $filename) && self::checkFilter($filename, $filter) ) + { + array_push($filelist, new MediaObject($collection, $filename, $DIR_MEDIA)); + } + } + closedir($dirhandle); + + /* sort array */ + if ( !$CONF['MediaPrefix'] ) + { + usort($filelist, array(__CLASS__, 'sort_media_by_timestamp')); + } + else + { + usort($filelist, array(__CLASS__, 'sort_media_by_filename')); + } + + return $filelist; + } + + /** + * Media::checkFilter() + * + * @param string $strText + * @param string $strFilter + * @return boolean + */ + static public function checkFilter($strText, $strFilter) + { + if ( $strFilter == '' ) + { + return 1; + } + else + { + return is_integer(i18n::strpos(strtolower($strText), strtolower($strFilter))); + } + } + + /** + * Media::isValidCollection() + * checks if a collection exists with the given name, and if it's + * allowed for the currently logged in member to upload files to it + * + * @param string $collectionName + * @param string $exceptReadOnly + * @return boolean + */ + static public function isValidCollection($collectionName, $exceptReadOnly = FALSE) + { + global $member, $DIR_MEDIA; + + // allow creating new private directory + if ( $collectionName === (string)$member->getID() ) + { + return TRUE; + } + + $collections = self::getCollectionList($exceptReadOnly); + $dirname = $collections[$collectionName]; + + if ( $dirname == NULL || $dirname === PRIVATE_COLLECTION ) + { + return FALSE; + } + + // other collections should exist and be writable + $collectionDir = $DIR_MEDIA . $collectionName; + if ( $exceptReadOnly ) + { + return ( @is_dir($collectionDir) && @is_writable($collectionDir) ); + } + + // other collections should exist + return @is_dir($collectionDir); + } + + /** + * Media::addMediaObject() + * Adds an uploaded file to the media archive + * + * @param string $collection collection + * @param array $uploadfile the postFileInfo(..) array + * @param string $filename the filename that should be used to save the file as + * (date prefix should be already added here) + * @return string blank if success, message if failed + */ + static public function addMediaObject($collection, $uploadfile, $filename) + { + global $DIR_MEDIA, $manager; + + // clean filename of characters that may cause trouble in a filename using cleanFileName() function from globalfunctions.php + $filename = cleanFileName($filename); + + // should already have tested for allowable types before calling this method. This will only catch files with no extension at all + if ( $filename === FALSE ) + { + return _ERROR_BADFILETYPE; + } + + // trigger PreMediaUpload event + $data = array('collection' => &$collection, 'uploadfile' => $uploadfile, 'filename' => &$filename); + $manager->notify('PreMediaUpload', $data); + + // don't allow uploads to unknown or forbidden collections + $exceptReadOnly = TRUE; + if ( !self::isValidCollection($collection,$exceptReadOnly) ) + { + return _ERROR_DISALLOWED; + } + + // check dir permissions (try to create dir if it does not exist) + $mediadir = $DIR_MEDIA . $collection; + + // try to create new private media directories if needed + if ( !@is_dir($mediadir) && is_numeric($collection) ) + { + $oldumask = umask(0000); + if ( !@mkdir($mediadir, 0777) ) + { + return _ERROR_BADPERMISSIONS; + } + umask($oldumask); + } + + // if dir still not exists, the action is disallowed + if ( !@is_dir($mediadir) ) + { + return _ERROR_DISALLOWED; + } + + if ( !is_writeable($mediadir) ) + { + return _ERROR_BADPERMISSIONS; + } + + // add trailing slash (don't add it earlier since it causes mkdir to fail on some systems) + $mediadir .= '/'; + + if ( file_exists($mediadir . $filename) ) + { + return _ERROR_UPLOADDUPLICATE; + } + + // move file to directory + if ( is_uploaded_file($uploadfile) ) + { + if ( !@move_uploaded_file($uploadfile, $mediadir . $filename) ) + { + return _ERROR_UPLOADMOVEP; + } + } + else + { + if ( !copy($uploadfile, $mediadir . $filename) ) + { + return _ERROR_UPLOADCOPY ; + } + } + + // chmod uploaded file + $oldumask = umask(0000); + @chmod($mediadir . $filename, 0644); + umask($oldumask); + + $data = array('collection' => $collection, 'mediadir' => $mediadir, 'filename' => $filename); + $manager->notify('PostMediaUpload', $data); + + return ''; + } + + /** + * Media::addMediaObjectRaw() + * Adds an uploaded file to the media dir. + * + * NOTE: does not check if $collection is valid. + * + * @param string $collection collection to use + * @param string $filename the filename that should be used to save the file + * as (date prefix should be already added here) + * @param &$data File data (binary) + * @return string blank if success, message if failed + */ + static public function addMediaObjectRaw($collection, $filename, &$data) + { + global $DIR_MEDIA; + + // check dir permissions (try to create dir if it does not exist) + $mediadir = $DIR_MEDIA . $collection; + + // try to create new private media directories if needed + if ( !@is_dir($mediadir) && is_numeric($collection) ) + { + $oldumask = umask(0000); + if ( !@mkdir($mediadir, 0777) ) + { + return _ERROR_BADPERMISSIONS; + } + umask($oldumask); + } + + // if dir still not exists, the action is disallowed + if ( !@is_dir($mediadir) ) + { + return _ERROR_DISALLOWED; + } + + if ( !is_writeable($mediadir) ) + { + return _ERROR_BADPERMISSIONS; + } + + // add trailing slash (don't add it earlier since it causes mkdir to fail on some systems) + $mediadir .= '/'; + + if ( file_exists($mediadir . $filename) ) + { + return _ERROR_UPLOADDUPLICATE; + } + + // create file + $fh = @fopen($mediadir . $filename, 'wb'); + if ( !$fh ) + { + return _ERROR_UPLOADFAILED; + } + $ok = @fwrite($fh, $data); + @fclose($fh); + if ( !$ok ) + { + return _ERROR_UPLOADFAILED; + } + + // chmod uploaded file + $oldumask = umask(0000); + @chmod($mediadir . $filename, 0644); + umask($oldumask); + + return ''; + } + + /** + * Media::responseResampledImage() + * send resampled image via HTTP + * + * @param object $medium MediaObject Object + * @exit + */ + static public function responseResampledImage($medium, $maxwidth=0, $maxheight=0) + { + if ( get_class($medium) !== 'MediaObject' ) + { + header("HTTP/1.1 500 Internal Server Error"); + exit('Nucleus CMS: Fail to generate resampled image'); + return; + } + + $resampledimage = $medium->getResampledBinary($maxwidth, $maxheight); + if ( $resampledimage === FALSE ) + { + unset($resampledimage); + header("HTTP/1.1 503 Service Unavailable"); + exit('Nucleus CMS: Fail to generate resampled image'); + return; + } + + header("Content-type: {$medium->mime}"); + echo $resampledimage; + + unset($resampledimage); + + exit; + } + + /** + * Media::storeResampledImage() + * Store resampled image binary to filesystem as file + * + * @param object $medium MediaObject Object + * @param integer $maxwidth maximum width + * @param integer $maxheight maximum height + * @param string $path directory path for destination + * @param string $name file name for destination + * @return boolean + */ + static public function storeResampledImage($medium, $maxwidth=0, $maxheight=0, $path='', $name='') + { + global $DIR_MEDIA; + + if ( get_class($medium) !== 'MediaObject' ) + { + return FALSE; + } + + if ( $path !== '' ) + { + $path = realpath($path); + if ( !file_exists($path) + || strpos($path, $DIR_MEDIA) !== 0 ) + { + return FALSE; + } + } + else + { + $path = '$DIR_MEDIA/' . self::$thumbdir; + } + + if ( $name === '' ) + { + $name = $medium->getHashedname(); + } + + $resampledimage = $medium->getResampledBinary($maxwidth, $maxheight); + if ( !$resampledimage ) + { + unset($resampledimage); + return FALSE; + } + + $handle = @fopen("{$path}/{$name}", 'w'); + if ( !$handle ) + { + unset ($resampledimage); + return FALSE; + } + + if ( !@fwrite($handle, $resampledimage) ) + { + unset($resampledimage); + @unlink("{$path}/{$name}"); + return FALSE; + } + + unset($resampledimage); + fclose($handle); + + if ( !@chmod("{$path}/{$name}", 0774) ) + { + @unlink("{$path}/{$name}"); + return FALSE; + } + + return TRUE; + } + + /** + * Media::sort_media_by_timestamp() + * User-defined sort method to sort an array of MediaObjects + * + * @param object $a + * @param object $b + * @return boolean + */ + static private function sort_media_by_timestamp($a, $b) + { + if ($a->timestamp == $b->timestamp) return 0; + return ($a->timestamp > $b->timestamp) ? -1 : 1; + } + + /** + * Media::sort_media_by_filename() + * User-defined sort method to sort an array of MediaObjects + * + * @param object $a + * @param object $b + * @return boolean + */ + static private function sort_media_by_filename($a, $b) + { + if ($a->filename == $b->filename) return 0; + return ($a->filename > $b->filename) ? -1 : 1; + } +} + +class MediaObject +{ + public $mime = ''; + + public $root = ''; + public $path = ''; + public $private; + public $collection; + public $filename = ''; + + public $prefix = ''; + public $name = ''; + public $suffix = ''; + + public $timestamp = 0; + public $size = 0; + + public $width = 0; + public $height = 0; + public $resampledwidth = 0; + public $resampledheight = 0; + + /** + * MediaObject::__construct() + * + * @param string $collection + * @param string $filename + * @param string $root fullpath to media directory + */ + public function __construct($collection, $filename, $root=0) + { + global $CONF, $DIR_MEDIA; + + /* for backward compatibility */ + if ( is_numeric($root) ) + { + $root = $DIR_MEDIA; + } + + $root = preg_replace('#/*$#', '', $root); + + /* get and validate fullpath for the medium */ + if ( !file_exists($root) + || FALSE === ($fullpath = realpath("{$root}/{$collection}/{$filename}")) + || strpos($fullpath, $root) !== 0 + || !file_exists($fullpath) ) + { + return FALSE; + } + + /* store fundamentals */ + $this->root = $root; + $this->private = (integer) $collection; + $this->collection = $collection; + $this->filename = basename($fullpath); + $this->timestamp = filemtime($fullpath); + + /* store relative directory path from root directory for media */ + $this->path = preg_replace(array("#{$this->root}/#", "#/{$this->filename}#"), '', $fullpath); + if ( $this->path === $this->name ) + { + $this->path = ''; + } + + return; + } + + /** + * MediaObject::refine() + * refine data + * + * @param void + * @return void + */ + public function refine() + { + global $CONF; + + /* store size (byte order) */ + $this->size = filesize("{$this->root}/{$this->path}/{$this->filename}"); + + /* get width and height if this is image binary */ + if ( FALSE === ($info = @getimagesize ("{$this->root}/{$this->path}/{$this->filename}")) ) + { + $this->mime = 'application/octet-stream'; + $this->width = 0; + $this->height = 0; + } + else + { + $this->mime = $info['mime']; + $this->width = $info[0]; + $this->height = $info[1]; + } + + /* utilise Fileinfo subsystem if available */ + if ( defined('FILEINFO_MIME_TYPE') && function_exists ('finfo_open') + && (FALSE !== ($info = finfo_open(FILEINFO_MIME_TYPE))) ) + { + $this->mime = finfo_file($info, "{$this->root}/{$this->path}/{$this->filename}"); + } + + /* store data with parsed filename */ + if ( preg_match('#^(.*)\.([a-zA-Z0-9]{2,})$#', $this->filename, $info) === 1 ) + { + $this->name = $info[1]; + $this->suffix = $info[2]; + + if ( $CONF['MediaPrefix'] && preg_match('#^([0-9]{8})\-(.*)$#', $this->name, $info) == 1 ) + { + $this->prefix = preg_replace('#^([0-9]{4})([0-9]{2})([0-9]{2})$#', '$1/$2/$3', $info[1]); + $this->name = $info[2]; + } + } + + return; + } + + /** + * MediaObject::setResampledSize() + * Set resampled size + * + * @param integer $maxwidth + * @param integer $maxheight + * @return boolean + */ + public function setResampledSize($maxwidth=0, $maxheight=0) + { + if ( ($maxwidth == 0) && ($maxheight == 0) ) + { + return FALSE; + } + else if ( $this->width == 0 || $this->height == 0 ) + { + return FALSE; + } + else if ($this->width < $maxwidth && $this->height < $maxheight ) + { + $this->resampledwidth = $this->width; + $this->resampledheight = $this->height; + } + else if ( $maxheight == 0 || $this->width > $this->height ) + { + $this->resampledheight = intval ($this->height * $maxwidth / $this->width); + $this->resampledwidth = $maxwidth; + } + else if ( $maxwidth == 0 || $this->width <= $this->height ) + { + $this->resampledwidth = intval ($this->width * $maxheight / $this->height); + $this->resampledheight = $maxheight; + } + return TRUE; + } + + /** + * MediaObject::getResampledBinary() + * Return resampled image binary + * + * @param void + * @return mixed binary if success, FALSE if failed + */ + public function getResampledBinary($maxwidth=0, $maxheight=0) + { + static $gdinfo = array(); + static $original; + static $resampledimage; + + if ( !$this->setResampledSize($maxwidth, $maxheight) ) + { + return FALSE; + } + + if ( $gdinfo = array() ) + { + $gdinfo = gd_info(); + } + + if ( $this->path !== '' ) + { + $fullpath = "{$this->root}/{$this->path}/{$this->name}"; + } + else + { + $fullpath = "{$this->root}/{$this->name}"; + } + if ( !file_exists($fullpath) ) + { + return FALSE; + } + + if ( !array_key_exists($this->mime, Media::$image_mime) + || $this->width == 0 + || $this->height == 0 + || $this->resampledwidth == 0 + || $this->resampledheight == 0 ) + { + return FALSE; + } + + /* check current available memory */ + $memorymax = trim(ini_get("memory_limit")); + switch ( strtolower ($memorymax[strlen($memorymax)-1]) ) + { + case 'g': + $memorymax *= 1024; + case 'm': + $memorymax *= 1024; + case 'k': + $memorymax *= 1024; + } + + /* + * this code is based on analyze if gd.c in php source code + * if you can read C/C++, please check these elements and notify us if you have some ideas + */ + if ( (memory_get_usage() + + ($this->resampledwidth * $this->resampledheight * 5 + $this->resampledheight * 24 + 10000) + + ($this->width * $this->height * 5 + $this->height * 24 + 10000)) + > $memorymax ) + { + return FALSE; + } + + switch ( $this->mime ) + { + case 'image/gif': + if ( (!array_key_exists('GIF Read Support', $gdinfo) || !isset($gdinfo['GIF Read Support'])) + || (!array_key_exists('GIF Create Support', $gdinfo) || !isset($gdinfo['GIF Create Support'])) ) + { + return FALSE; + } + $function = 'imagecreatefromgif'; + break; + case 'image/jpeg': + if ( (!array_key_exists('JPEG Support', $gdinfo) || !isset($gdinfo['JPEG Support'])) + && (!array_key_exists('JPG Support', $gdinfo) || !isset($gdinfo['JPG Support'])) ) + { + return FALSE; + } + $function = 'imagecreatefromjpeg'; + break; + case 'image/png': + if ( !array_key_exists('PNG Support', $gdinfo) || !isset($gdinfo['PNG Support']) ) + { + return FALSE; + } + $function = 'imagecreatefrompng'; + break; + default: + return FALSE; + } + + if ( !is_callable($function) ) + { + return FALSE; + } + + $original = call_user_func_array($function, $fullpath); + if ( !$original ) + { + return FALSE; + } + + $resampledimage = imagecreatetruecolor($this->resampledwidth, $this->resampledheight); + if ( !$resampledimage ) + { + imagedestroy($original); + return FALSE; + } + + @set_time_limit(ini_get('max_execution_time')); + if ( !ImageCopyResampled($resampledimage, $original, 0, 0, 0, 0, $this->resampledwidth, $this->resampledheight, $this->width, $this->height) ) + { + return FALSE; + } + + imagedestroy($original); + + ob_start(); + + switch ( $this->mime ) + { + case 'image/gif': + imagegif($resampledimage); + break; + case 'image/jpeg': + imagejpeg($resampledimage); + break; + case 'image/png': + imagepng($resampledimage); + break; + case 'image/bmp': + case 'image/x-ms-bmp': + imagepng($resampledimage); + break; + default: + return FALSE; + } + + imagedestroy($resampledimage); + + return ob_get_clean(); + } + + public function getHashedName() + { + return (string) hash(Media::$algorism, "{$this->path}/{$this->name}", FALSE); + } +} +>>>>>>> skinnable-master diff --git a/nucleus/libs/MEMBER.php b/nucleus/libs/MEMBER.php index 8172d43..1047d78 100644 --- a/nucleus/libs/MEMBER.php +++ b/nucleus/libs/MEMBER.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD readFromName($displayname); + return $mem; + } + + /** + * Member::createFromID() + * Create a member object for a given ID + * + * @static + * @param Integer $id id for member + */ + public static function &createFromID($id) + { + $mem = new Member(); + $mem->readFromID($id); + return $mem; + } + + /** + * Member::readFromName() + * Read member table in database + * + * @param String $displayname login name + * @return Object SQL resource + * + */ + public function readFromName($displayname) + { + return $this->read('mname='.DB::quoteValue($displayname)); + } + + /** + * Member::readFromID() + * Read member table in database + * + * @param Integer $id id for member + * @return Object SQL resource + * + */ + public function readFromID($id) + { + return $this->read("mnumber=" . intval($id)); + } + + /** + * Member::hash() + * hash the target string + * + * @param String $string target string + * @return Void hashed string + */ + public function hash($string) + { + switch ( $this->algorism ) + { + case 'md5': + default: + $string = md5($string); + } + return $string; + } + + /** + * Member::set_cookie_salt() + * + * @param integer $key secureCookieKey value + * @return void + * + */ + private function set_cookie_salt($key = 0) + { + if ( !$key ) + { + $key = 24; + } + + switch( $key ) + { + case 8: + $this->cookie_salt = preg_replace('/\.[0-9]+\.[0-9]+\.[0-9]+$/', '', serverVar('REMOTE_ADDR')); + break; + case 16: + $this->cookie_salt = preg_replace('/\.[0-9]+\.[0-9]+$/', '', serverVar('REMOTE_ADDR')); + break; + case 24: + $this->cookie_salt = preg_replace('/\.[0-9]+$/', '', serverVar('REMOTE_ADDR')); + break; + case 32: + $this->cookie_salt = serverVar('REMOTE_ADDR'); + break; + default: + $this->cookie_salt = 'none'; + } + return; + } + + /** + * Member::login() + * Tries to login as a given user. + * Returns true when succeeded, returns false when failed + * 3.40 adds CustomLogin event + * + * @param String $login login name for member + * @param String $password password for member + * @param Integer $shared whether the user agent is shared or not + * + */ + public function login($login, $password, $shared=1) + { + global $CONF, $errormessage, $manager; + + /* TODO: validation for $login, $password, $shared */ + if ( $login == '' || $password == '' ) + { + return 0; + } + /* limiting the length of password to avoid hash collision */ + $password=i18n::substr($password, 0, 40); + + /* + * generate cookie salt from secure cookie key settings + * (either 'none', 0, 8, 16, 24, or 32) + */ + if ( !$this->cookie_salt ) + { + $salt = 0; + if ( array_key_exists('secureCookieKey', $CONF) ) + { + $salt = $CONF['secureCookieKey']; + } + $this->set_cookie_salt($salt); + } + + $success = 0; + $allowlocal = 1; + $data = array('login' => &$login, 'password'=>&$password, 'success'=>&$success, 'allowlocal'=>&$allowlocal); + $manager->notify('CustomLogin', $data); + + $this->loggedin = 0; + if ( $success ) + { + $this->loggedin = ( $this->readFromName($login) ); + } + elseif ( $allowlocal ) + { + $this->loggedin = ( $this->readFromName($login) && $this->checkPassword($password) ); + } + + /* login failed */ + if ( !$this->loggedin ) + { + $trimlogin = trim($login); + if ( empty($trimlogin) ) + { + $errormessage = "Please enter a username."; + } + else + { + $errormessage = 'Login failed for ' . $login; + } + $data = array('username' => $login); + $manager->notify('LoginFailed', $data); + ActionLog::add(INFO, $errormessage); + } + /* login success */ + else + { + /* For lower compatibility */ + if ( strlen($this->password) === 32 ) + { + $this->password = $this->hash($password); + } + + $this->newCookieKey(); + $this->setCookies($shared); + + if ( $this->cookie_salt !== 'none' ) + { + /* secure cookie key */ + $this->setCookieKey($this->hash($this->getCookieKey() . $this->cookie_salt)); + $this->write(); + } + + $errormessage = ''; + $data = array('member' => &$this, 'username' => $login); + $manager->notify('LoginSuccess', $data); + ActionLog::add(INFO, "Login successful for $login (sharedpc=$shared)"); + } + + return $this->loggedin; + } + + /** + * Member::cookielogin() + * Login using cookie key + * + * @param String $login not used + * @param String $cookiekey not used + * @return Boolean login or not + */ + public function cookielogin($login='', $cookiekey='') + { + global $CONF, $manager; + + if ( !headers_sent() && cookieVar("{$CONF['CookiePrefix']}user") ) + { + /* Cookie Authentication */ + $ck = cookieVar("{$CONF['CookiePrefix']}loginkey"); + + /* TODO: validation for each cookie values */ + + /* limiting the length of password to avoid hash collision */ + $ck = i18n::substr($ck,0,32); + + /* + * generate cookie salt from secure cookie key settings + * (either 'none', 0, 8, 16, 24, or 32) + */ + if ( !$this->cookie_salt ) + { + $salt = 0; + if ( array_key_exists('secureCookieKey', $CONF) ) + { + $salt = $CONF['secureCookieKey']; + } + $this->set_cookie_salt($salt); + } + + if ( $this->cookie_salt !== 'none' ) + { + $ck = $this->hash($ck . $this->cookie_salt); + } + $this->loggedin = ( $this->readFromName(cookieVar("{$CONF['CookiePrefix']}user")) && $this->checkCookieKey($ck) ); + unset($ck); + + /* renew cookies when not on a shared computer */ + if ( $this->loggedin && (cookieVar($CONF['CookiePrefix'] . 'sharedpc') != 1) ) + { + $this->setCookieKey(cookieVar("{$CONF['CookiePrefix']}loginkey")); + $this->setCookies(); + } + } + return $this->loggedin; + } + + /** + * Member::logout() + * logout and expire cookie + * + * @param Void + * @return Void + */ + public function logout() + { + global $CONF, $manager; + + if ( !headers_sent() && cookieVar("{$CONF['CookiePrefix']}user") ) + { + /* remove cookies on logout */ + setcookie("{$CONF['CookiePrefix']}user", '', (time() - 2592000), $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']); + setcookie("{$CONF['CookiePrefix']}loginkey", '', (time() - 2592000), $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']); + $data = array('username' => cookieVar("{$CONF['CookiePrefix']}user")); + $manager->notify('Logout', $data); + } + + $this->loggedin = 0; + return; + } + + /** + * Member::isLoggedIn() + * return member is loggedin or not + * + * @param Void + * @return Void + */ + public function isLoggedIn() + { + return $this->loggedin; + } + + /** + * MEMBER:read() + * Read member information from the database + * + * @param String $where where statement + * @return Resource SQL resource + * + */ + public function read($where) + { + // read info + $query = 'SELECT * FROM '.sql_table('member') . ' WHERE ' . $where; + + $row = DB::getRow($query); + + $this->setRealName($row['mrealname']); + $this->setEmail($row['memail']); + $this->password = $row['mpassword']; + $this->setCookieKey($row['mcookiekey']); + $this->setURL($row['murl']); + $this->setDisplayName($row['mname']); + $this->setAdmin($row['madmin']); + $this->id = $row['mnumber']; + $this->setCanLogin($row['mcanlogin']); + $this->setNotes($row['mnotes']); + $this->setLocale($row['mlocale']); + $this->setAutosave($row['mautosave']); + $this->setAdminSkin($row['madminskin']); + $this->setBookmarklet($row['mbkmklt']); + + return $row ? TRUE : FALSE; + } + + /** + * Member::isBlogAdmin() + * Returns true if member is an admin for the given blog + * (returns false if not a team member) + * + * @param Integer $blogid weblog id + * @return Integer weblog admin or not + * + */ + public function isBlogAdmin($blogid) + { + $query = 'SELECT tadmin FROM '.sql_table('team').' WHERE' + . ' tblog=' . intval($blogid) + . ' and tmember='. $this->getID(); + $res = DB::getValue($query); + if ( $res ) + return ($res == 1); + else + return 0; + } + + /** + * Member::blogAdminRights() + * + * @param integer $blogid ID of target weblog + * @return boolean whether to have admin rights to the weblog or not + * + */ + public function blogAdminRights($blogid) + { + return ($this->isAdmin() || $this->isBlogAdmin($blogid)); + } + + /** + * Member::teamRights() + * + * @param integer $blogid ID of target weblog + * @return boolean whether to have admin right to the weblog or not + * + */ + public function teamRights($blogid) + { + return ($this->isAdmin() || $this->isTeamMember($blogid)); + } + + /** + * Member::isTeamMember() + * Returns true if this member is a team member of the given blog + * + * @param integer $blogid ID of target weblog + * @return boolean whether to join the weblog or not + * + */ + public function isTeamMember($blogid) + { + $query = 'SELECT * FROM '.sql_table('team').' WHERE' + . ' tblog=' . intval($blogid) + . ' and tmember='. $this->getID(); + $res = DB::getResult($query); + return ($res->rowCount() != 0); + } + + /** + * Member::canAddItem() + * + * @param integer $catid ID of target category + * @return boolean whether to be able to add items to the category or not + * + */ + public function canAddItem($catid) + { + global $manager; + + // if this is a 'newcat' style newcat + // no blog admin of destination blog -> NOK + // blog admin of destination blog -> OK + if ( i18n::strpos($catid,'newcat') === 0 ) + { + // get blogid + list($blogid) = sscanf($catid,"newcat-%d"); + return $this->blogAdminRights($blogid); + } + + // category does not exist -> NOK + if ( !$manager->existsCategory($catid) ) + { + return 0; + } + + $blogid = getBlogIDFromCatID($catid); + + // no team rights for blog -> NOK + if (!$this->teamRights($blogid)) + { + return 0; + } + + // all other cases: OK + return 1; + } + + /** + * Member::canAlterComment() + * Returns true if this member can edit/delete a commentitem. This can be in the + * following cases: + * - member is a super-admin + * - member is the author of the comment + * - member is admin of the blog associated with the comment + * - member is author of the item associated with the comment + * + * @param integer $commentid ID of target comment + * @return boolean delete/edit the comment or not + * + */ + public function canAlterComment($commentid) + { + if ( $this->isAdmin() ) + { + return 1; + } + + $query = 'SELECT citem as itemid, iblog as blogid, cmember as cauthor, iauthor' + . ' FROM '.sql_table('comment') .', '.sql_table('item').', '.sql_table('blog') + . ' WHERE citem=inumber and iblog=bnumber and cnumber=' . intval($commentid); + $res = DB::getRow($query); + + return ($res['cauthor'] == $this->getID()) or $this->isBlogAdmin($res['blogid']) or ($res['iauthor'] == $this->getID()); + } + + /** + * Member::canAlterItem() + * Returns true if this member can edit/delete an item. This is true in the following + * cases: - member is a super-admin + * - member is the author of the item + * - member is admin of the the associated blog + * + * @param integer $itemid ID of target item + * @return boolean delete/edit the item or not + * + */ + public function canAlterItem($itemid) + { + if ($this->isAdmin()) return 1; + + $query = 'SELECT iblog, iauthor FROM '.sql_table('item').' WHERE inumber=' . intval($itemid); + $res = DB::getRow($query); + return ($res['iauthor'] == $this->getID()) or $this->isBlogAdmin($res['iblog']); + } + + /** + * Member::canBeDeleted() + * Return true if member can be deleted. This means that there are no items posted by the member left + * + * @param void + * @return boolean whether there is no items or exists + * + */ + public function canBeDeleted() + { + $res = DB::getResult('SELECT * FROM '.sql_table('item').' WHERE iauthor=' . $this->getID()); + return ( $res->rowCount() == 0 ); + } + + /** + * Member::canUpdateItem() + * returns true if this member can move/update an item to a given category, + * false if not (see comments fot the tests that are executed) + * + * @param integer $itemid + * @param string $newcat (can also be of form 'newcat-x' with x=blogid) + * @return boolean whether being able to update the item or not + * + */ + public function canUpdateItem($itemid, $newcat) + { + global $manager; + + // item does not exists -> NOK + if ( !$manager->existsItem($itemid,1,1) ) + { + return 0; + } + + // cannot alter item -> NOK + if (!$this->canAlterItem($itemid)) + { + return 0; + } + + // if this is a 'newcat' style newcat + // no blog admin of destination blog -> NOK + // blog admin of destination blog -> OK + if ( i18n::strpos($newcat, 'newcat') === 0 ) + { + // get blogid + list($blogid) = sscanf($newcat, 'newcat-%d'); + return $this->blogAdminRights($blogid); + } + + // category does not exist -> NOK + if (!$manager->existsCategory($newcat)) + { + return 0; + } + + // get item + $item =& $manager->getItem($itemid,1,1); + + // old catid = new catid -> OK + if ($item['catid'] == $newcat) + { + return 1; + } + + // not a valid category -> NOK + $validCat = DB::getValue('SELECT COUNT(*) AS result FROM '.sql_table('category').' WHERE catid='.intval($newcat)); + if ( !$validCat ) + { + return 0; + } + + // get destination blog + $item =& $manager->getItem($itemid, 1, 1); + $source_blogid = $item['blogid']; + $dest_blogid = getBlogIDFromCatID($newcat); + + // not a team member of destination blog -> NOK + if ( !$this->teamRights($dest_blogid) ) + { + return 0; + } + + // if member is author of item -> OK + if ( $item['authorid'] == $this->getID() ) + { + return 1; + } + + // if member has admin rights on both blogs: OK + if ( ($this->blogAdminRights($dest_blogid)) && ($this->blogAdminRights($source_blogid)) ) + { + return 1; + } + + // all other cases: NOK + return 0; + } + + /** + * Member::setCookies() + * Sets the cookies for the member + * + * @param boolean $shared set this to 1 when using a shared computer. Cookies will expire + * at the end of the session in this case. + * @return void + * + */ + public function setCookies($shared = 0) + { + global $CONF; + + if ( $CONF['SessionCookie'] || $shared ) + { + $lifetime = 0; + } + else + { + $lifetime = time()+2592000; + } + + setcookie($CONF['CookiePrefix'] . 'user', $this->getDisplayName(), $lifetime, $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']); + setcookie($CONF['CookiePrefix'] . 'loginkey', $this->getCookieKey(), $lifetime, $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']); + + // make sure cookies on shared pcs don't get renewed + if ( $shared ) + { + setcookie($CONF['CookiePrefix'] .'sharedpc', '1',$lifetime,$CONF['CookiePath'],$CONF['CookieDomain'],$CONF['CookieSecure']); + } + return; + } + + /** + * Member::sendActivationLink() + * Send activation mail + * + * @param string $type activation type + * @param string $extra extra info + * @return void + */ + public function sendActivationLink($type, $extra='') + { + global $CONF; + + if ( !isset($CONF['ActivationDays']) ) + { + $CONF['ActivationDays'] = 2; + } + + // generate key and URL + $key = $this->generateActivationEntry($type, $extra); + $url = $CONF['AdminURL'] . 'index.php?action=activate&key=' . $key; + + // choose text to use in mail + switch ( $type ) + { + case 'register': + $message = _ACTIVATE_REGISTER_MAIL; + $subject = _ACTIVATE_REGISTER_MAILTITLE; + break; + case 'forgot': + $message = _ACTIVATE_FORGOT_MAIL; + $subject = _ACTIVATE_FORGOT_MAILTITLE; + break; + case 'addresschange': + $message = _ACTIVATE_CHANGE_MAIL; + $subject = _ACTIVATE_CHANGE_MAILTITLE; + break; + default; + } + + // fill out variables in text + $aVars = array( + 'siteName' => $CONF['SiteName'], + 'siteUrl' => $CONF['IndexURL'], + 'memberName' => $this->getDisplayName(), + 'activationUrl' => $url, + 'activationDays' => $CONF['ActivationDays'] + ); + + $message = Template::fill($message, $aVars); + $subject = Template::fill($subject, $aVars); + + // send mail + NOTIFICATION::mail($this->getEmail(), $subject ,$message, $CONF['AdminEmail'], i18n::get_current_charset()); + + ActionLog::add(INFO, _ACTIONLOG_ACTIVATIONLINK . ' (' . $this->getDisplayName() . ' / type: ' . $type . ')'); + return; + } + + /** + * Member::getAdminBlogs() + * Returns an array of all blogids for which member has admin rights + * + * @param void + * @return array weblog IDs in which this member has admin rights + * + */ + public function getAdminBlogs() + { + $blogs = array(); + + if ($this->isAdmin()) + { + $query = 'SELECT bnumber as blogid from '.sql_table('blog'); + } + else + { + $query = 'SELECT tblog as blogid from '.sql_table('team').' where tadmin=1 and tmember=' . $this->getID(); + } + + $res = DB::getResult($query); + if ( $res->rowCount() > 0 ) + { + foreach ( $res as $row ) + { + array_push($blogs, $row['blogid']); + } + } + return $blogs; + } + + /** + * Member::getTeamBlogs() + * Returns an array of all blogids for which member has team rights + * + * @param boolean $incAdmin whether checking weblog admin rights or not + * @return array weblog IDs in which this member join + * + */ + public function getTeamBlogs($incAdmin = 1) + { + $incAdmin = intval($incAdmin); + $blogs = array(); + + if ( $this->isAdmin() && $incAdmin ) + { + $query = 'SELECT bnumber as blogid from '.sql_table('blog'); + } + else + { + $query = 'SELECT tblog as blogid from '.sql_table('team').' where tmember=' . $this->getID(); + } + + $res = DB::getResult($query); + if ( $res->rowCount() > 0 ) + { + foreach ( $res as $row ) + { + array_push($blogs, $row['blogid']); + } + } + return $blogs; + } + + /** + * Member::getNotifyFromMailAddress() + * + * Returns an email address from which notification of commenting/karma voting can + * be sent. A suggestion can be given for when the member is not logged in + * + * @param String $suggest + * @return String mail address or suggestion + */ + public function getNotifyFromMailAddress($suggest = "") + { + global $CONF; + if ( $this->isLoggedIn() ) + { + return $this->getDisplayName() . " <" . $this->getEmail() . ">"; + } + else if ( NOTIFICATION::address_validation($suggest) ) + { + return $suggest; + } + return $CONF['AdminEmail']; + } + + /** + * Member::write() + * Write data to database + * + * @param void + * @return void + * + */ + public function write() + { + $query = 'UPDATE '.sql_table('member') + . ' SET mname=' . DB::quoteValue($this->displayname) . ', ' + . 'mrealname='. DB::quoteValue($this->realname) . ', ' + . 'mpassword='. DB::quoteValue($this->password) . ', ' + . 'mcookiekey='. DB::quoteValue($this->cookiekey) . ', ' + . 'murl=' . DB::quoteValue($this->url) . ', ' + . 'memail=' . DB::quoteValue($this->email) . ', ' + . 'madmin=' . intval($this->admin) . ', ' + . 'mnotes=' . DB::quoteValue($this->notes) . ', ' + . 'mcanlogin=' . intval($this->canlogin) . ', ' + . 'mlocale=' . DB::quoteValue($this->locale) . ', ' + . 'madminskin=' . DB::quoteValue($this->adminskin) . ', ' + . 'mbkmklt=' . DB::quoteValue($this->bookmarklet) . ', ' + . 'mautosave=' . intval($this->autosave) . ' ' + . 'WHERE mnumber=' . intval($this->id); + DB::execute($query); + return; + } + + public function checkCookieKey($key) + { + return ( ($key != '') && ( $key == $this->getCookieKey() ) ); + } + + public function checkPassword($pw) + { + /* for lower compatibility (md5) */ + if ( strlen($this->password) === 32 ) + { + return (md5($pw) == $this->password); + } + return ($this->hash($pw) == $this->password); + } + + public function getRealName() + { + return $this->realname; + } + + public function setRealName($name) + { + $this->realname = $name; + } + + public function getEmail() + { + return $this->email; + } + + public function setEmail($email) + { + $this->email = $email; + } + + public function getPassword() + { + return $this->password; + } + + public function setPassword($pwd) + { + $this->password = $this->hash($pwd); + } + + public function getCookieKey() + { + return $this->cookiekey; + } + + /** + * Member::newCookieKey() + * Generate new cookiekey, save it, and return it + * + * @param void + * @return void + * + */ + public function newCookieKey() + { + mt_srand( (double) microtime() * 1000000); + $this->cookiekey = $this->hash(uniqid(mt_rand())); + $this->write(); + return $this->cookiekey; + } + + public function setCookieKey($val) + { + $this->cookiekey = $val; + } + + public function getURL() + { + return $this->url; + } + + public function setURL($site) + { + $this->url = $site; + } + + public function setAdminSkin($skin) + { + $this->adminskin = $skin; + } + + public function setBookmarklet($skin) + { + $this->bookmarklet = $skin; + } + + public function getAdminSkin() + { + return $this->adminskin; + } + + public function getBookmarklet() + { + return $this->bookmarklet; + } + + public function getLocale() + { + return $this->locale; + } + + public function setLocale($locale) + { + if ( !preg_match('#^(.+)_(.+)_(.+)$#', $locale) + && ($locale = i18n::convert_old_language_file_name_to_locale($locale)) === FALSE ) + { + $locale = ''; + } + $this->locale = $locale; + return; + } + + public function setDisplayName($nick) + { + $this->displayname = $nick; + } + + public function getDisplayName() + { + return $this->displayname; + } + + public function isAdmin() + { + return $this->admin; + } + + public function setAdmin($val) + { + $this->admin = $val; + } + + public function canLogin() + { + return $this->canlogin; + } + + public function setCanLogin($val) + { + $this->canlogin = $val; + } + + public function getNotes() + { + return $this->notes; + } + + public function setNotes($val) + { + $this->notes = $val; + } + + public function getAutosave() + { + return $this->autosave; + } + + public function setAutosave($val) + { + $this->autosave = $val; + return; + } + + /** + * Member::getID() + * + * @param void + * @return integer id of this member object + * + */ + public function getID() + { + return $this->id; + } + + /** + * Member::exists() + * Returns true if there is a member with the given login name + * + * @static + * @param string $name target name + * @return boolean whether target name exists or not + */ + public static function exists($name) + { + $r = DB::getResult('SELECT * FROM ' . sql_table('member') . ' WHERE mname=' . DB::quoteValue($name)); + return ( $r->rowCount() != 0 ); + } + + /** + * Member::existsID() + * Returns true if there is a member with the given ID + * + * @static + * @param integer $id target id + * @return boolean whether target id exists or not + * + */ + public static function existsID($id) + { + $r = DB::getResult('SELECT * FROM ' . sql_table('member') . ' WHERE mnumber=' . intval($id)); + return ( $r->rowCount() != 0 ); + } + + /** + * Member::isNameProtected() + * Checks if a username is protected. + * If so, it can not be used on anonymous comments + * + * @param string $name target name + * @return boolean whether the name exists or not + * + */ + public function isNameProtected($name) + { + // extract name + $name = strip_tags($name); + $name = trim($name); + return self::exists($name); + } + + /** + * Member::create() + * Adds a new member + * + * @static + * @param String $name + * @param String $realname + * @param String $password + * @param String $email + * @param String $url + * @param String $admin + * @param String $canlogin + * @param String $notes + * @return String 1 if success, others if fail + */ + static public function create($name, $realname, $password, $email, $url, $admin, $canlogin, $notes) + { + if ( !NOTIFICATION::address_validation($email) ) + { + return _ERROR_BADMAILADDRESS; + } + + /* TODO: this method should be in MEMBER class, not globalfunctions */ + if ( !isValidDisplayName($name) ) + { + return _ERROR_BADNAME; + } + + if ( self::exists($name) ) + { + return _ERROR_NICKNAMEINUSE; + } + + if ( !$realname ) + { + return _ERROR_REALNAMEMISSING; + } + + /* TODO: check the number of characters */ + if ( !$password ) + { + return _ERROR_PASSWORDMISSING; + } + + /* + * begin if: sometimes user didn't prefix the URL with http:// or https://, + * this cause a malformed URL. Let's fix it. + */ + + if ( !preg_match('#^https?://#', $url) ) + { + $url = 'http://' . $url; + } + + $name = DB::quoteValue($name); + $realname = DB::quoteValue($realname); + /* NOTE: hashed password is automatically updated if the length is 32 bytes when logging in */ + $password = DB::quoteValue(md5($password)); + $email = DB::quoteValue($email); + $url = DB::quoteValue($url); + $admin = (integer) $admin; + $canlogin = (integer) $canlogin; + $notes = DB::quoteValue($notes); + + $query = "INSERT INTO %s" + . " (MNAME,MREALNAME,MPASSWORD,MEMAIL,MURL, MADMIN, MCANLOGIN, MNOTES)" + . " VALUES (%s, %s, %s, %s, %s, %d, %d, %s)"; + $query = sprintf($query, sql_table('member'), $name, $realname, $password, $email, $url, $admin, $canlogin, $notes); + DB::execute($query); + + ActionLog::add(INFO, _ACTIONLOG_NEWMEMBER . ' ' . $name); + + return 1; + } + + /** + * Member::getActivationInfo() + * Returns activation info for a certain key (an object with properties vkey, vmember, ...) + * + * @static + * @param string $key activation key + * @return mixed return 0 if failed, else return activation table object + * + */ + public static function getActivationInfo($key) + { + $query = 'SELECT * FROM ' . sql_table('activation') . ' WHERE vkey=' . DB::quoteValue($key); + $res = DB::getResult($query); + + if ( !$res || ($res->rowCount() == 0) ) + { + return 0; + } + return $res->fetch(); + } + + /** + * Member::generateActivationEntry() + * Creates an account activation key + * addresschange -> old email address + * + * @param string $type one of the following values (determines what to do when activation expires) + * 'register' (new member registration) + * 'forgot' (forgotton password) + * 'addresschange' (member address has changed) + * @param string $extra extra info (needed when validation link expires) + * @return string activation key + */ + public function generateActivationEntry($type, $extra = '') + { + // clean up old entries + $this->cleanupActivationTable(); + + // kill any existing entries for the current member (delete is ok) + // (only one outstanding activation key can be present for a member) + DB::execute('DELETE FROM ' . sql_table('activation') . ' WHERE vmember=' . intval($this->getID())); + + // indicates if the member can log in while the link is active + $canLoginWhileActive = false; + switch ( $type ) + { + case 'forgot': + $canLoginWhileActive = true; + break; + case 'register': + break; + case 'addresschange': + $extra = $extra . '/' . ( $this->canLogin() ? '1' : '0' ); + break; + } + + $ok = false; + while ( !$ok ) + { + // generate a random key + srand((double)microtime()*1000000); + $key = $this->hash(uniqid(rand(), true)); + + // attempt to add entry in database + // add in database as non-active + $query = 'INSERT INTO %s (vkey, vtime, vmember, vtype, vextra) VALUES (%s, %s, %d, %s, %s)'; + $query = sprintf($query + , sql_table('activation') + , DB::quoteValue($key) + , DB::formatDateTime() + , intval($this->getID()) + , DB::quoteValue($type) + , DB::quoteValue($extra) + ); + if ( DB::execute($query) !== FALSE ) + $ok = true; + } + + // mark member as not allowed to log in + if ( !$canLoginWhileActive ) + { + $this->setCanLogin(0); + $this->write(); + } + + // return the key + return $key; + } + + /** + * Member::activate() + * Inidicates that an activation link has been clicked and any forms displayed + * there have been successfully filled out. + * + * @param string $key activation key + * @return boolean + * + */ + public function activate($key) + { + // get activate info + $info = self::getActivationInfo($key); + + // no active key + if ( !$info ) + { + return false; + } + + switch ( $info['vtype'] ) + { + case 'forgot': + // nothing to do + break; + case 'register': + // set canlogin value + global $CONF; + DB::execute('UPDATE ' . sql_table('member') . ' SET mcanlogin=' . intval($CONF['NewMemberCanLogon']). ' WHERE mnumber=' . intval($info['vmember'])); + break; + case 'addresschange': + // reset old 'canlogin' value + list($oldEmail, $oldCanLogin) = preg_split('#/#', $info['vextra']); + DB::execute('UPDATE ' . sql_table('member') . ' SET mcanlogin=' . intval($oldCanLogin). ' WHERE mnumber=' . intval($info['vmember'])); + break; + } + + // delete from activation table + DB::execute('DELETE FROM ' . sql_table('activation') . ' WHERE vkey=' . DB::quoteValue($key)); + + // success! + return true; + } + + /** + * Member::cleanupActivationTable() + * Cleans up entries in the activation table. All entries older than 2 days are removed. + * (static) + * + * @param void + * @return void + */ + public function cleanupActivationTable() + { + $actdays = 2; + if ( isset($CONF['ActivationDays']) && intval($CONF['ActivationDays']) > 0 ) + { + $actdays = intval($CONF['ActivationDays']); + } + else + { + $CONF['ActivationDays'] = 2; + } + $boundary = time() - (60 * 60 * 24 * $actdays); + + // 1. walk over all entries, and see if special actions need to be performed + $query = sprintf('SELECT * FROM %s WHERE vtime < %s', sql_table('activation'), DB::formatDateTime($boundary)); + $res = DB::getResult($query); + + foreach ( $res as $row ) + { + switch ( $row['vtype'] ) + { + case 'register': + // delete all information about this site member. registration is undone because there was + // no timely activation + include_once($DIR_LIBS . 'ADMIN.php'); + Admin::deleteOneMember(intval($row['vmember'])); + break; + case 'addresschange': + // revert the e-mail address of the member back to old address + list($oldEmail, $oldCanLogin) = preg_split('#/#', $row['vextra']); + DB::execute('UPDATE ' . sql_table('member') . ' SET mcanlogin=' . intval($oldCanLogin). ', memail=' . DB::quoteValue($oldEmail). ' WHERE mnumber=' . intval($row['vmember'])); + break; + case 'forgot': + // delete the activation link and ignore. member can request a new password using the + // forgot password link + break; + } + } + + // 2. delete activation entries for real + $query = sprintf('DELETE FROM %s WHERE vtime < %s', sql_table('activation'), DB::formatDateTime($boundary)); + DB::execute($query); + return; + } + + /** + * Member::$language + * + * @obsolete + * @param void + * @return void + * + */ + public $language = ''; + /** + * Member::getLanguage() + * + * @obsolete + * @param void + * @return void + * + */ + public function getLanguage() + { + if ( ($language = i18n::convert_locale_to_old_language_file_name($this->locale)) === FALSE ) + { + $language = ''; + } + return $language; + } +} +>>>>>>> skinnable-master diff --git a/nucleus/libs/NOTIFICATION.php b/nucleus/libs/NOTIFICATION.php index 22fe7e1..e7f3d38 100644 --- a/nucleus/libs/NOTIFICATION.php +++ b/nucleus/libs/NOTIFICATION.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD $#", $mailbox, $match) ) + { + $display_name = self::seven_bit_characters_encoder(trim($match[1])); + $local_part = trim($match[2]); + $domain = trim($match[3]); + $encoded_mailboxes[] = "{$display_name} <{$local_part}@{$domain}>"; + } + else if ( preg_match("#([^,]+)?@([^,]+)?#", $mailbox) ) + { + $encoded_mailboxes[] = $mailbox; + } + else + { + continue; + } + } + if ( $encoded_mailboxes == array() ) + { + return FALSE; + } + return implode(',', $encoded_mailboxes); + } + + /** + * NOTIFICATION::seven_bit_characters_encoder + * Encoder into 7bit ASCII expression for Non-ASCII Text based on RFC 2047. + * + * @link http://www.ietf.org/rfc/rfc2047.txt + * @see 2. Syntax of encoded-words + * + * NOTE: RFC 2047 has a ambiguousity for dealing with 'linear-white-space'. + * This causes a trouble related to line breaking between single byte and multi-byte strings. + * To avoid this, single byte string is encoded as well as multi byte string here. + * + * NOTE: RFC 2231 also defines the way to use non-ASCII characters in MIME header. + * http://www.ietf.org/rfc/rfc2231.txt + * + * NOTE: iconv extension give the same functions as this in PHP5 + * iconv_mime_encode(): + * http://www.php.net/manual/en/function.iconv-mime-encode.php + * + * @static + * @param string $charset Character set encoding + * @param string $type type of 7 bit encoding, should be 'B' or 'Q' + * @param string $string Target string with header field + * @return string encoded string + * + */ + static private function seven_bit_characters_encoder($string) + { + $header = chr(13) . chr(10) . chr(32) . '=?' . self::$charset . '?' . self::$scheme . '?'; + $footer = "?="; + $restriction = 78 - strlen($header) - strlen($footer) ; + + $encoded_words = array(); + for ( $i = 0; $i < i18n::strlen($string); $i++ ) + { + if ( self::$scheme == 'B' ) + { + if ( $i == 0 ) + { + $letters = ''; + } + + $letter = i18n::substr($string, $i, 1); + $expected_length = strlen($letters) + strlen($letter) * 4 / 3; + + if ( $expected_length > $restriction ) + { + $encoded_text = self::b_encoder($letters); + $encoded_words[] = "{$header}{$encoded_text}{$footer}"; + $letters = ''; + } + + $letters .= $letter; + + if ( $i == i18n::strlen($string) - 1 ) + { + $encoded_text = self::b_encoder($letters); + $encoded_words[] = "{$header}{$encoded_text}{$footer}"; + break; + } + continue; + } + else + { + if ( $i == 0 ) + { + $encoded_text = ''; + } + + $encoded_letter = self::q_encoder(i18n::substr($string, $i, 1)); + $expected_length = strlen($encoded_text) + strlen($encoded_letter); + + if ( $expected_length > $restriction ) + { + $encoded_words[] = "{$header}{$encoded_text}{$footer}"; + $letters = ''; + } + + $encoded_text .= $encoded_letter; + + if ( $i == i18n::strlen($string) - 1 ) + { + $encoded_words[] = "{$header}{$encoded_text}{$footer}"; + break; + } + continue; + } + } + + return implode('', $encoded_words); + } + + /** + * NOTIFICATION::b_encoder() + * + * B encoder according to RFC 2047. + * The "B" encoding is identical to the "BASE64" encoding defined by RFC 4648. + * + * @link http://www.ietf.org/rfc/rfc4648.txt + * @see 6.8. Base64 Content-Transfer-Encoding + * + * NOTE: According to RFC 4648 + * (1) The final quantum of encoding input is an integral multiple of 24 bits; + * here, the final unit of encoded output will be an integral multiple + * of 4 characters with no "=" padding. + * (2) The final quantum of encoding input is exactly 8 bits; here, + * the final unit of encoded output will be two characters followed + * by two "=" padding characters. + * (3) The final quantum of encoding input is exactly 16 bits; here, + * the final unit of encoded output will be three characters followed + * by one "=" padding character. + * + * @static + * @param string $target targetted string + * @return string encoded string + */ + static private function b_encoder($target) + { + return base64_encode($target); + } + + /** + * NOTIFICATION::q_encoder() + * + * Q encoder according to RFC 2047. + * The "Q" encoding is similar to "Quoted-Printable" content-transfer-encoding defined in RFC 2045, + * but the "Q" encoding and the "Quoted-Printable" are different a bit. + * + * @link http://www.ietf.org/rfc/rfc2047.txt + * @see 4.2. The "Q" encoding + * + * NOTE: According to RFC 2047 + * (1) Any 8-bit value may be represented by a "=" followed by two hexadecimal digits. + * For example, if the character set in use were ISO-8859-1, + * the "=" character would thus be encoded as "=3D", and a SPACE by "=20". + * (Upper case should be used for hexadecimal digits "A" through "F".) + * (2) The 8-bit hexadecimal value 20 (e.g., ISO-8859-1 SPACE) may be + * represented as "_" (underscore, ASCII 95.). + * (This character may not pass through some internetwork mail gateways, + * but its use will greatly enhance readability of "Q" encoded data + * with mail readers that do not support this encoding.) + * Note that the "_" always represents hexadecimal 20, + * even if the SPACE character occupies a different code position + * in the character set in use. + * (3) 8-bit values which correspond to printable ASCII characters + * other than "=", "?", and "_" (underscore), MAY be represented as those characters. + * (But see section 5 for restrictions.) + * In particular, SPACE and TAB MUST NOT be represented as themselves within encoded words. + * + * @static + * @param string $target targetted string + * @return string encoded string + */ + static private function q_encoder($target) + { + $string = ''; + + for ( $i = 0; $i < strlen($target); $i++ ) + { + $letter = substr ($target, $i, 1); + $order = ord($letter); + + // Printable ASCII characters without "=", "?", "_" + if ((33 <= $order && $order <= 60) + || (62 == $order) + || (64 <= $order && $order <= 94) + || (96 <= $order && $order <= 126)) + { + $string .= strtoupper(dechex($order)); + } + // Space shuold be encoded as the same strings as "_" + else if ($order == 32) + { + $string .= '_'; + } + // Other characters + else + { + $string .= '=' . strtoupper(dechex($order)); + } + } + + return $string; + } + + /** + * NOTICE: Deprecated + * NOTIFICATION::$addresses + * + * @deprecated + */ + private $addresses = array(); + + /** + * NOTICE: Deprecated + * takes one string as argument, containing multiple e-mail addresses + * separated by semicolons + * eg: site@demuynck.org;nucleus@demuynck.org;foo@bar.com + * + * @deprecated + */ + function __construct($addresses) + { + $this->addresses = preg_split('#;#' , $addresses); + } + + /** + * NOTICE: Deprecated + * NOTIFICATION::validAddresses() + * + * returns true if all addresses are valid + * + * @deprecated + * @param Void + * @return Boolean + */ + function validAddresses() + { + foreach ( $this->addresses as $address ) + { + if ( !self::address_validation(trim($address)) ) + { + return 0; + } + } + return 1; + } + + /** + * NOTICE: Deprecated + * NOTIFICATION::notify() + * + * Sends email messages to all the email addresses + * + * @deprecated + * @param String $title + * @param String $message + * @param String $from + * @return Void + */ + function notify($title, $message, $from) + { + global $member; + $addresses = array(); + + foreach ($this->addresses as $address) + { + if ( $member->isLoggedIn() && ($member->getEmail() == $address) ) + { + continue; + } + $addresses[] = $address; + } + + self::mail(implode(',', $addresses), $title, $message , $from); + return; + } +} +>>>>>>> skinnable-master diff --git a/nucleus/libs/PARSER.php b/nucleus/libs/PARSER.php index c23d297..79f372e 100644 --- a/nucleus/libs/PARSER.php +++ b/nucleus/libs/PARSER.php @@ -12,7 +12,11 @@ /** * @license http://nucleuscms.org/license.txt GNU General Public License * @copyright Copyright (C) 2002-2009 The Nucleus Group +<<<<<<< HEAD * @version $Id: PARSER.php 1757 2012-04-15 09:02:32Z sakamocchi $ +======= + * @version $Id: PARSER.php 1879 2012-06-17 07:45:09Z sakamocchi $ +>>>>>>> skinnable-master */ if ( !function_exists('requestVar') ) @@ -62,8 +66,11 @@ class Parser $this->pdelim = $pdelim; $this->norestrictions = 0; // set this to 1 to disable checking for allowedActions +<<<<<<< HEAD $this->skin = NULL; +======= +>>>>>>> skinnable-master $handler->setParser($this); return; @@ -137,7 +144,11 @@ class Parser if ( in_array($actionlc, $this->actions) || $this->norestrictions ) { +<<<<<<< HEAD call_user_func_array(array(&$this->handler, "parse_{$actionlc}"), $params); +======= + call_user_func_array(array($this->handler, "parse_{$actionlc}"), $params); +>>>>>>> skinnable-master } else { diff --git a/nucleus/libs/PLUGIN.php b/nucleus/libs/PLUGIN.php index 5a175c2..b52b93c 100644 --- a/nucleus/libs/PLUGIN.php +++ b/nucleus/libs/PLUGIN.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD if the plugin uses the sql_table() method to get table names + * 'HelpPage' -> if the plugin provides a helppage + * 'SqlApi' -> if the plugin uses the complete sql_* or DB::* api (must also require nucleuscms 3.5) + */ + public function supportsFeature($feature) + { + return 0; + } + + /** + * Report a list of plugin that is required to final public function + * + * @returns an array of names of plugin, an empty array indicates no dependency + */ + public function getPluginDep() + { + return array(); + } + + // these helper final public functions should not be redefined in your plugin + + /** + * Creates a new option for this plugin + * + * @param name + * A string uniquely identifying your option. (max. length is 20 characters) + * @param description + * A description that will show up in the nucleus admin area (max. length: 255 characters) + * @param type + * Either 'text', 'yesno' or 'password' + * This info is used when showing 'edit plugin options' screens + * @param value + * Initial value for the option (max. value length is 128 characters) + */ + final public function createOption($name, $desc, $type, $defValue = '', $typeExtras = '') + { + return $this->create_option('global', $name, $desc, $type, $defValue, $typeExtras); + } + + final public function createBlogOption($name, $desc, $type, $defValue = '', $typeExtras = '') + { + return $this->create_option('blog', $name, $desc, $type, $defValue, $typeExtras); + } + + final public function createMemberOption($name, $desc, $type, $defValue = '', $typeExtras = '') + { + return $this->create_option('member', $name, $desc, $type, $defValue, $typeExtras); + } + + final public function createCategoryOption($name, $desc, $type, $defValue = '', $typeExtras = '') + { + return $this->create_option('category', $name, $desc, $type, $defValue, $typeExtras); + } + + final public function createItemOption($name, $desc, $type, $defValue = '', $typeExtras = '') + { + return $this->create_option('item', $name, $desc, $type, $defValue, $typeExtras); + } + + /** + * Removes the option from the database + * + * Note: Options get erased automatically on plugin uninstall + */ + final public function deleteOption($name) + { + return $this->delete_option('global', $name); + } + + final public function deleteBlogOption($name) + { + return $this->delete_option('blog', $name); + } + + final public function deleteMemberOption($name) + { + return $this->delete_option('member', $name); + } + + final public function deleteCategoryOption($name) + { + return $this->delete_option('category', $name); + } + + final public function deleteItemOption($name) + { + return $this->delete_option('item', $name); + } + + /** + * Sets the value of an option to something new + */ + final public function setOption($name, $value) + { + return $this->set_option('global', 0, $name, $value); + } + + final public function setBlogOption($blogid, $name, $value) + { + return $this->set_option('blog', $blogid, $name, $value); + } + + final public function setMemberOption($memberid, $name, $value) + { + return $this->set_option('member', $memberid, $name, $value); + } + + final public function setCategoryOption($catid, $name, $value) + { + return $this->set_option('category', $catid, $name, $value); + } + + final public function setItemOption($itemid, $name, $value) { + return $this->set_option('item', $itemid, $name, $value); + } + + /** + * Retrieves the current value for an option + */ + final public function getOption($name) + { + // only request the options the very first time. On subsequent requests + // the static collection is used to save SQL queries. + if ( $this->plugin_options == 0 ) + { + $this->plugin_options = array(); + + $query = "SELECT d.oname as name, o.ovalue as value FROM %s o, %s d WHERE d.opid=%d AND d.oid=o.oid;"; + $query = sprintf($query, sql_table('plugin_option'), sql_table('plugin_option_desc'), (integer) $this->plugid); + $result = DB::getResult($query); + foreach ( $result as $row ) + { + $this->plugin_options[strtolower($row['name'])] = $row['value']; + } + } + if ( isset($this->plugin_options[strtolower($name)]) ) + { + return $this->plugin_options[strtolower($name)]; + } + else + { + return $this->get_option('global', 0, $name); + } + } + + final public function getBlogOption($blogid, $name) + { + return $this->get_option('blog', $blogid, $name); + } + + final public function getMemberOption($memberid, $name) + { + return $this->get_option('member', $memberid, $name); + } + + final public function getCategoryOption($catid, $name) + { + return $this->get_option('category', $catid, $name); + } + + final public function getItemOption($itemid, $name) + { + return $this->get_option('item', $itemid, $name); + } + + /** + * Retrieves an associative array with the option value for each + * context id + */ + final public function getAllBlogOptions($name) + { + return $this->get_all_options('blog', $name); + } + + final public function getAllMemberOptions($name) + { + return $this->get_all_options('member', $name); + } + + final public function getAllCategoryOptions($name) + { + return $this->get_all_options('category', $name); + } + + final public function getAllItemOptions($name) + { + return $this->get_all_options('item', $name); + } + + /** + * Retrieves an indexed array with the top (or bottom) of an option + * (delegates to getOptionTop()) + */ + final public function getBlogOptionTop($name, $amount = 10, $sort = 'desc') + { + return $this->get_option_top('blog', $name, $amount, $sort); + } + + final public function getMemberOptionTop($name, $amount = 10, $sort = 'desc') + { + return $this->get_option_top('member', $name, $amount, $sort); + } + + final public function getCategoryOptionTop($name, $amount = 10, $sort = 'desc') + { + return $this->get_option_top('category', $name, $amount, $sort); + } + + final public function getItemOptionTop($name, $amount = 10, $sort = 'desc') + { + return $this->get_option_top('item', $name, $amount, $sort); + } + + /** + * NucleusPlugin::getID() + * get id for this plugin + * + * @access public + * @param void + * @return integer this plugid id + */ + final public function getID() + { + return (integer) $this->plugid; + } + + /** + * NucleusPlugin::setID() + * set favorite id for this plugin + * + * @access public + * @param integer $plugid favorite id for plugin + * @return void + */ + final public function setID($plugid) + { + $this->plugid = (integer) $plugid; + return; + } + + /** + * Returns the URL of the admin area for this plugin (in case there's + * no such area, the returned information is invalid) + * + * public + */ + final public function getAdminURL() + { + global $CONF; + return $CONF['PluginURL'] . $this->getShortName() . '/'; + } + + /** + * Returns the directory where the admin directory is located and + * where the plugin can maintain his extra files + * + * public + */ + final public function getDirectory() + { + global $DIR_PLUGINS; + return $DIR_PLUGINS . $this->getShortName() . '/'; + } + + /** + * Derives the short name for the plugin from the classname (all + * lowercase) + * + * public + */ + final public function getShortName() + { + return str_replace('np_','',strtolower(get_class($this))); + } + + /** + * Clears the option value cache which saves the option values during + * the plugin execution. This function is usefull if the options has + * changed during the plugin execution (especially in association with + * the PrePluginOptionsUpdate and the PostPluginOptionsUpdate events) + * + * public + **/ + final public function clearOptionValueCache() + { + $this->option_values = array(); + $this->plugin_options = 0; + return; + } + + // internal functions of the class starts here + protected $option_values; // oid_contextid => value + protected $option_info; // context_name => array('oid' => ..., 'default' => ...) + protected $plugin_options; // see getOption() + protected $plugid; // plugin id + + /** + * Class constructor: Initializes some internal data + */ + public function __construct() + { + $this->option_values = array(); // oid_contextid => value + $this->option_info = array(); // context_name => array('oid' => ..., 'default' => ...) + $this->plugin_options = 0; + } + + /** + * Retrieves an array of the top (or bottom) of an option from a plugin. + * @author TeRanEX + * @param string $context the context for the option: item, blog, member,... + * @param string $name the name of the option + * @param int $amount how many rows must be returned + * @param string $sort desc or asc + * @return array array with both values and contextid's + * @access private + */ + final protected function get_option_top($context, $name, $amount = 10, $sort = 'desc') + { + if ( ($sort != 'desc') && ($sort != 'asc') ) + { + $sort= 'desc'; + } + + $oid = $this->get_option_id($context, $name); + + // retrieve the data and return + $query = "SELECT otype, oextra FROM %s WHERE oid = %d;"; + $query = sprintf($query, sql_table('plugin_option_desc'), $oid); + $row = DB::getRow($query); + + if ( ($this->optionCanBeNumeric($row['otype'])) && ($row['oextra'] == 'number' ) ) + { + $orderby = 'CAST(ovalue AS SIGNED)'; + } + else + { + $orderby = 'ovalue'; + } + $query = "SELECT ovalue value, ocontextid id FROM %s WHERE oid = %d ORDER BY %s %s LIMIT 0,%d;"; + $query = sprintf($query, sql_table('plugin_option'), $oid, $orderby, $sort, (integer) $amount); + $result = DB::getResult($query); + + // create the array + $i = 0; + $top = array(); + foreach( $result as $row ) + { + $top[$i++] = $row; + } + + // return the array (duh!) + return $top; + } + + /** + * Creates an option in the database table plugin_option_desc + * + * private + */ + final protected function create_option($context, $name, $desc, $type, $defValue, $typeExtras = '') + { + // create in plugin_option_desc + $query = 'INSERT INTO ' . sql_table('plugin_option_desc') + .' (opid, oname, ocontext, odesc, otype, odef, oextra)' + .' VALUES ('.intval($this->plugid) + .', '.DB::quoteValue($name) + .', '.DB::quoteValue($context) + .', '.DB::quoteValue($desc) + .', '.DB::quoteValue($type) + .', '.DB::quoteValue($defValue) + .', '.DB::quoteValue($typeExtras).')'; + DB::execute($query); + $oid = DB::getInsertId(); + + $key = $context . '_' . $name; + $this->option_info[$key] = array('oid' => $oid, 'default' => $defValue); + return 1; + } + + /** + * Deletes an option from the database tables + * plugin_option and plugin_option_desc + * + * private + */ + final protected function delete_option($context, $name) + { + $oid = $this->get_option_id($context, $name); + if ( !$oid ) + { + return 0; // no such option + } + + // delete all things from plugin_option + $query = "DELETE FROM %s WHERE oid=%d;"; + $query = sprintf($query, sql_table('plugin_option'), (integer) $oid); + DB::execute($query); + + // delete entry from plugin_option_desc + $query = "DELETE FROM %s WHERE oid=%d;"; + $query = sprintf($query, sql_table('plugin_option_desc'), $oid); + DB::execute($query); + + // clear from cache + unset($this->option_info["{$context}_{$name}"]); + $this->option_values = array(); + return 1; + } + + /** + * Update an option in the database table plugin_option + * + * returns: 1 on success, 0 on failure + * private + */ + final protected function set_option($context, $contextid, $name, $value) + { + global $manager; + + $oid = $this->get_option_id($context, $name); + if ( !$oid ) + { + return 0; + } + + // check if context id exists + switch ( $context ) + { + case 'member': + if ( !Member::existsID($contextid) ) + { + return 0; + } + break; + case 'blog': + if ( !$manager->existsBlogID($contextid) ) + { + return 0; + } + break; + case 'category': + if ( !$manager->existsCategory($contextid) ) + { + return 0; + } + break; + case 'item': + if ( !$manager->existsItem($contextid, true, true) ) + { + return 0; + } + break; + case 'global': + if ( $contextid != 0 ) + { + return 0; + } + break; + } + + // update plugin_option + $query = "DELETE FROM %s WHERE oid=%d and ocontextid=%d;"; + $query = sprintf($query, sql_table('plugin_option'), (integer) $oid, (integer) $contextid); + DB::execute($query); + + $query = "INSERT INTO %s (ovalue, oid, ocontextid) VALUES (%s, %d, %d);"; + $query = sprintf($query, sql_table('plugin_option'), DB::quoteValue($value), $oid, $contextid); + DB::execute($query); + + // update cache + $this->option_values["{$oid}_{$contextid}"] = $value; + if ( $context == 'global' ) + { + $this->plugin_options[strtolower($name)] = $value; + } + + return 1; + } + + /** + * Get an option from Cache or database + * - if not in the option Cache read it from the database + * - if not in the database write default values into the database + * + * private + */ + final protected function get_option($context, $contextid, $name) + { + $oid = $this->get_option_id($context, $name); + if ( !$oid ) + { + return ''; + } + + $key = "{$oid}_{$contextid}"; + + if ( isset($this->option_values[$key]) ) + { + return $this->option_values[$key]; + } + + // get from DB + $query = "SELECT ovalue FROM %s WHERE oid=%d and ocontextid=%d;"; + $query = sprintf($query, sql_table('plugin_option'), (integer) $oid, (integer) $contextid); + $result = DB::getResult($query); + + if ( !$result || ($result->rowCount() == 0) ) + { + // fill DB with default value + $this->option_values[$key] = $this->get_default_value($context, $name); + $query = "INSERT INTO %s (oid, ocontextid, ovalue) VALUES (%d, %d, %s);"; + $query = sprintf($query, sql_table('plugin_option'), (integer) $oid, (integer) $contextid, DB::quoteValue($this->option_values[$key])); + DB::execute($query); + } + else + { + $row = $result->fetch(); + $this->option_values[$key] = $row['ovalue']; + } + + return $this->option_values[$key]; + } + + /** + * Returns assoc array with all values for a given option + * (one option per possible context id) + * + * private + */ + final protected function get_all_options($context, $name) + { + $oid = $this->get_option_id($context, $name); + if ( !$oid ) + { + return array(); + } + $default_value = $this->get_default_value($context, $name); + + $options = array(); + $query = "SELECT %s as contextid FROM %s;"; + switch ( $context ) + { + case 'blog': + $query = sprintf($query, 'bnumber', sql_table('blog')); + break; + case 'category': + $query = sprintf($query, 'catid', sql_table('category')); + break; + case 'member': + $query = sprintf($query, 'mnumber', sql_table('member')); + break; + case 'item': + $query = sprintf($query, 'inumber', sql_table('item')); + break; + } + + $result = DB::getResult($query); + if ( $result ) + { + foreach ( $result as $row ) + { + $options[$row['contextid']] = $default_value; + } + } + + $query = "SELECT ocontextid, ovalue FROM %s WHERE oid=%d;"; + $query = sprintf($query, sql_table('plugin_option'), $oid); + $result = DB::getResult($query); + foreach ( $result as $row ) + { + $options[$row['ocontextid']] = $row['ovalue']; + } + + return $options; + } + + /** + * NucleusPlugin::get_option_id + * + * Gets the 'option identifier' that corresponds to a given option name. + * When this method is called for the first time, all the OIDs for the plugin + * are loaded into memory, to avoid re-doing the same query all over. + * + * @param string $context option context + * @param string $name plugin name + * @return integer option id + */ + final protected function get_option_id($context, $name) + { + $key = "{$context}_{$name}"; + + if ( array_key_exists($key, $this->option_info) + && array_key_exists('oid', $this->option_info[$key]) ) + { + return $this->option_info[$key]['oid']; + } + + // load all OIDs for this plugin from the database + $this->option_info = array(); + $query = "SELECT oid, oname, ocontext, odef FROM %s WHERE opid=%d;"; + $query = sprintf($query, sql_table('plugin_option_desc'), $this->plugid); + $result = DB::getResult($query); + foreach ( $result as $row ) + { + $k = $row['ocontext'] . '_' . $row['oname']; + $this->option_info[$k] = array('oid' => $row['oid'], 'default' => $row['odef']); + } + $result->closeCursor(); + + return $this->option_info[$key]['oid']; + } + final protected function get_default_value($context, $name) + { + $key = $context . '_' . $name; + + if ( array_key_exists($key, $this->option_info) + && array_key_exists('default', $this->option_info[$key]) ) + { + return $this->option_info[$key]['default']; + } + return; + } + + /** + * NucleusPlugin::delete_option_values() + * Deletes all option values for a given context and contextid + * (used when e.g. a blog, member or category is deleted) + * + *@static + *@param String $context global/blog/category/item/member + *@param Integer $contextid ID + *@return Void + */ + static public function delete_option_values($context, $contextid) + { + // delete all associated plugin options + $aOIDs = array(); + // find ids + $query = "SELECT oid FROM %s WHERE ocontext=%s;"; + $query = sprintf($query, sql_table('plugin_option_desc'), DB::quoteValue($context)); + + $result = DB::getResult($query); + foreach ( $result as $row ) + { + array_push($aOIDs, $row['oid']); + } + $result->closeCursor(); + // delete those options. go go go + if ( count($aOIDs) > 0 ) + { + $query = "DELETE FROM %s WHERE oid in (%s) and ocontextid=%d;"; + $query = sprintf($query, sql_table('plugin_option'), implode(',',$aOIDs), (integer) $contextid); + DB::execute($query); + } + return; + } + + /** + * NucleusPlugin::getOptionMeta() + * splits the option's typeextra field (at ;'s) to split the meta collection + * + * @static + * @param string $typeExtra the value of the typeExtra field of an option + * @return array array of the meta-key/value-pairs + */ + static public function getOptionMeta($typeExtra) + { + $meta = array(); + + /* 1. if $typeExtra includes delimiter ';', split it to tokens */ + $tokens = preg_split('#;#', $typeExtra); + + /* + * 2. if each of tokens includes "=", it consists of key => value + * else it's 'select' option + */ + foreach ( $tokens as $token ) + { + $matches = array(); + if ( preg_match("#^([^=]+)?=([^=]+)?$#", $token, $matches) ) + { + $meta[$matches[1]] = $matches[2]; + } + else + { + $meta['select'] = $token; + } + } + return $meta; + } + + /** + * NucleusPlugin::getOptionSelectValues() + * filters the selectlists out of the meta collection + * + * @static + * @param string $typeExtra the value of the typeExtra field of an option + * @return string the selectlist + */ + static public function getOptionSelectValues($typeExtra) + { + $meta = NucleusPlugin::getOptionMeta($typeExtra); + + if ( array_key_exists('select', $meta) ) + { + return $meta['select']; + } + return; + } + + /** + * checks if the eventlist in the database is up-to-date + * @return bool if it is up-to-date it return true, else false + * @author TeRanEX + */ + public function subscribtionListIsUptodate() + { + $res = DB::getResult('SELECT event FROM '.sql_table('plugin_event').' WHERE pid = '.$this->plugid); + $ev = array(); + foreach ( $res as $row ) + { + array_push($ev, $row['event']); + } + if ( count($ev) != count($this->getEventList()) ) + { + return false; + } + $d = array_diff($ev, $this->getEventList()); + if ( count($d) > 0 ) + { + // there are differences so the db is not up-to-date + return false; + } + return true; + } + + /** + * NucleusPlugin::apply_plugin_options() + * Update its entry in database table + * + * @static + * @param $options: array ( 'oid' => array( 'contextid' => 'value')) + * (taken from request using requestVar()) + * @param $new_contextid: integer (accepts a contextid when it is for a new + * contextid there was no id available at the moment of writing the + * formcontrols into the page (by ex: itemOptions for new item) + * @return void + */ + static public function apply_plugin_options(&$options, $new_contextid = 0) + { + global $manager; + + if ( !is_array($options) ) + { + return; + } + + foreach ( $options as $oid => $values ) + { + // get option type info + $query = "SELECT opid, oname, ocontext, otype, oextra, odef FROM %s WHERE oid=%d;"; + $query = sprintf($query, sql_table('plugin_option_desc'), (integer) $oid); + $result = DB::getRow($query); + if ( $result ) + { + foreach ( $values as $id => $value ) + { + // decide wether we are using the contextid of newContextid + if ( $new_contextid != 0 ) + { + $contextid = $new_contextid; + } + else + { + $contextid = $id; + } + + // retreive any metadata + $meta = NucleusPlugin::getOptionMeta($result['oextra']); + + // if the option is readonly or hidden it may not be saved + if ( array_key_exists('access', $meta) + && in_array($meta['access'], array('readonly', 'hidden')) ) + { + return; + } + + // value comes from request + $value = undoMagic($value); + + /* validation the value according to its type */ + switch ( $result['otype'] ) + { + case 'yesno': + if ( ($value != 'yes') && ($value != 'no') ) + { + $value = 'no'; + } + break; + case 'text': + case 'select': + if ( array_key_exists('datatype', $meta) + && ($meta['datatype'] == 'numerical') && ($value != (integer) $value) ) + { + $value = (integer) $result['odef']; + } + break; + case 'password': + case 'textarea': + default: + break; + } + + /* + * trigger event PrePluginOptionsUpdate to give the plugin the + * possibility to change/validate the new value for the option + */ + $data = array( + 'context' => $result['ocontext'], + 'plugid' => $result['opid'], + 'optionname' => $result['oname'], + 'contextid' => $contextid, + 'value' => &$value); + $manager->notify('PrePluginOptionsUpdate', $data); + + // delete and insert its fields of table in database + $query = "DELETE FROM %s WHERE oid=%d AND ocontextid=%d;"; + $query = sprintf($query, sql_table('plugin_option'), (integer) $oid, (integer) $contextid); + DB::execute($query); + $query = "INSERT INTO %s (oid, ocontextid, ovalue) VALUES (%d, %d, %s);"; + $query = sprintf($query, sql_table('plugin_option'), (integer) $oid, (integer) $contextid, DB::quoteValue($value)); + DB::execute($query); + + // clear option value cache if the plugin object is already loaded + $plugin=& $manager->pidLoaded($result['opid']); + if ( $plugin ) + { + $plugin->clearOptionValueCache(); + } + + continue; + } + } + continue; + } + return; + } +} +>>>>>>> skinnable-master diff --git a/nucleus/libs/PLUGINADMIN.php b/nucleus/libs/PLUGINADMIN.php index 56f2df6..e1fce52 100644 --- a/nucleus/libs/PLUGINADMIN.php +++ b/nucleus/libs/PLUGINADMIN.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD strFullName = "NP_{$pluginName}"; + + // check if plugin exists and is installed + if ( !$manager->pluginInstalled($this->strFullName) ) + { + doError(_ERROR_INVALID_PLUGIN); + return; + } + + $this->plugin = &$manager->getPlugin($this->strFullName); + $this->bValid = $this->plugin; + + if ( !$this->bValid ) + { + doError(_ERROR_INVALID_PLUGIN); + return; + } + + Admin::initialize(); + Admin::$action = "plugin_{$pluginName}"; + + return; + } + + /** + * PluginAdmin::start() + * + * @param string $extraHead child elements for header element + * @return void + */ + public function start($extraHead = '') + { + global $CONF; + $this->extrahead = $extraHead . '' . "\n"; + ob_start(); + return; + } + + /** + * PluginAdmin::end() + * + * @param void + * @return void + */ + public function end() + { + $this->AddTicketByJS(); + $contents = ob_get_contents(); + ob_end_clean(); + $this->skinContents = '<%pagehead%>' . $contents . '<%pagefoot%>'; + Admin::action_PluginAdmin($this->skinContents, $this->extrahead); + return; + } + + /** + * PluginAdmin::_AddTicketByJS() + * Add ticket when not used in plugin's admin page + * to avoid CSRF. + * + * @param void + * @return void + */ + private function AddTicketByJS() + { + global $CONF,$ticketforplugin; + if ( !($ticket = $ticketforplugin['ticket']) ) + { + return; + } + $ticket=Entity::hsc($ticket); + +?>>>>>>> skinnable-master diff --git a/nucleus/libs/SEARCH.php b/nucleus/libs/SEARCH.php index ae28362..81edfb5 100644 --- a/nucleus/libs/SEARCH.php +++ b/nucleus/libs/SEARCH.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD +======= +,=,?,!,#,^,(,),[,\],:,;,\\\,%]/","",$text); + $this->querystring = $text; + $this->marked = $this->boolean_mark_atoms($text); + $this->inclusive = $this->boolean_inclusive_atoms($text); + $this->blogs = array(); + + // get all public searchable blogs, no matter what, include the current blog allways. + $res = DB::getResult('SELECT bnumber FROM '.sql_table('blog').' WHERE bincludesearch=1 '); + foreach ( $res as $row ) + $this->blogs[] = intval($row['bnumber']); + } + + function boolean_sql_select($match){ + if (i18n::strlen($this->inclusive) > 0) { + /* build sql for determining score for each record */ + $result=preg_split("# #",$this->inclusive); + for($cth=0;$cth=4){ + $stringsum_long .= " $result[$cth] "; + }else{ + $stringsum_a[] = ' '.$this->boolean_sql_select_short($result[$cth],$match).' '; + } + } + + if(i18n::strlen($stringsum_long)>0){ + $stringsum_long = DB::quoteValue($stringsum_long); + $stringsum_a[] = " match ({$match}) against ({$stringsum_long}) "; + } + + $stringsum .= implode("+",$stringsum_a); + return $stringsum; + } + } + + function boolean_inclusive_atoms($string){ + $result = trim($string); + $result = preg_replace("#([[:space:]]{2,})#", ' ', $result); + + # replaced eregi_replace() below with preg_replace(). ereg* functions are deprecated in PHP 5.3.0 + # just added delimiters to regex and the 'i' for case-insensitive matching + + /* convert normal boolean operators to shortened syntax */ + $result = preg_replace('# not #i', ' -', $result); + $result = preg_replace('# and #i', ' ', $result); + $result = preg_replace('# or #i', ',', $result); + + /* drop unnecessary spaces */ + $result = str_replace(' ,', ',', $result); + $result = str_replace(', ', ',', $result); + $result = str_replace('- ', '-', $result); + $result = str_replace('+', '', $result); + + /* strip exlusive atoms */ + $result = preg_replace( + "#\-\([A-Za-z0-9]{1,}[A-Za-z0-9\-\.\_\,]{0,}\)#", + '', + $result); + + $result = str_replace('(', ' ', $result); + $result = str_replace(')', ' ', $result); + $result = str_replace(',', ' ', $result); + + return $result; + } + + function boolean_sql_where($match){ + + $result = $this->marked; + + $this->boolean_sql_where_cb1($match); // set the static $match + + $result = preg_replace_callback( + + "/foo\[\(\'([^\)]{4,})\'\)\]bar/", + + array($this,'boolean_sql_where_cb1'), + + $result); + + $this->boolean_sql_where_cb2($match); // set the static $match + + $result = preg_replace_callback( + + "/foo\[\(\'([^\)]{1,3})\'\)\]bar/", + + array($this,'boolean_sql_where_cb2'), + + $result); + + return $result; + + } + + function boolean_sql_where_cb1($matches){ + + static $match; + + if (!is_array($matches)) $match=$matches; + + else return ' match ('.$match.') against ('.DB::quoteValue($matches[1]).') > 0 '; + + } + + function boolean_sql_where_cb2($matches){ + + static $match; + + if (!is_array($matches)) $match=$matches; + + else return ' ('.$this->boolean_sql_where_short($matches[1], $match).') '; + + } + + function boolean_mark_atoms($string){ + $result = trim($string); + $result = preg_replace("/([[:space:]]{2,})/",' ',$result); + + # replaced eregi_replace() below with preg_replace(). ereg* functions are deprecated in PHP 5.3.0 + # just added delimiters to regex and the 'i' for case-insensitive matching + + /* convert normal boolean operators to shortened syntax */ + $result = preg_replace('# not #i', ' -', $result); + $result = preg_replace('# and #i', ' ', $result); + $result = preg_replace('# or #i', ',', $result); + + /* strip excessive whitespace */ + $result = str_replace('( ', '(', $result); + $result = str_replace(' )', ')', $result); + $result = str_replace(', ', ',', $result); + $result = str_replace(' ,', ',', $result); + $result = str_replace('- ', '-', $result); + $result = str_replace('+', '', $result); + + // remove double spaces (we might have introduced some new ones above) + $result = trim($result); + $result = preg_replace("#([[:space:]]{2,})#", ' ', $result); + + /* apply arbitrary function to all 'word' atoms */ + + $result_a = preg_split('# #', $result); + + for($word = 0;$word +>>>>>>> skinnable-master diff --git a/nucleus/libs/SKIN.php b/nucleus/libs/SKIN.php index e6a8a8f..55547be 100644 --- a/nucleus/libs/SKIN.php +++ b/nucleus/libs/SKIN.php @@ -14,7 +14,11 @@ * * @license http://nucleuscms.org/license.txt GNU General Public License * @copyright Copyright (C) 2002-2009 The Nucleus Group +<<<<<<< HEAD * @version $Id: SKIN.php 1816 2012-05-03 01:40:10Z sakamocchi $ +======= + * @version $Id: SKIN.php 1886 2012-06-17 08:27:27Z sakamocchi $ +>>>>>>> skinnable-master */ if ( !function_exists('requestVar') ) @@ -54,9 +58,13 @@ class Skin $this->id = (integer) $id; +<<<<<<< HEAD /* * NOTE: include needed action class */ +======= + /* NOTE: include needed action class */ +>>>>>>> skinnable-master if ( $action_class != 'Actions' ) { if ( !class_exists($action_class, FALSE) @@ -338,6 +346,7 @@ class Skin // retrieve contents $contents = FALSE; +<<<<<<< HEAD if ( $type != 'fileparse' ) { $contents = $this->getContentFromDB($type); @@ -345,6 +354,22 @@ class Skin else if ( $path !== '' && i18n::strpos(realpath($path), realpath("$DIR_NUCLEUS/../")) == 0 ) { $contents = $this->getContentFromFile($path); +======= + if ( $type == 'pluginadmin' ) + { + $contents = $path; + } + else + { + if ( $type != 'fileparse' && $type != 'importAdmin') + { + $contents = $this->getContentFromDB($type); + } + else if ( $path !== '' && i18n::strpos(realpath($path), realpath("$DIR_NUCLEUS/../")) == 0 ) + { + $contents = $this->getContentFromFile($path); + } +>>>>>>> skinnable-master } // use base skin if this skin does not have contents if ( $contents === FALSE ) @@ -450,7 +475,11 @@ class Skin $res = DB::getValue($query); $skintypeexists = !empty($res); +<<<<<<< HEAD $skintypevalue = ($content == true); +======= + $skintypevalue = !empty($content); +>>>>>>> skinnable-master if( $skintypevalue && $skintypeexists ) { @@ -459,6 +488,7 @@ class Skin 'type' => $type, 'content' => &$content ); +<<<<<<< HEAD // PreUpdateSkinPart event $manager->notify("PreUpdate{{$this->event_identifier}}Part", $data); @@ -474,24 +504,49 @@ class Skin $manager->notify("PreAdd{$this->event_identifier}Part", $data); } else if( !$skintypevalue && $skintypeexists ) +======= + $manager->notify("PreUpdate{$this->event_identifier}Part", $data); + } + else if( $skintypevalue ) + { + $data = array( + 'skinid' => $this->id, + 'type' => $type, + 'content' => &$content + ); + $manager->notify("PreAdd{$this->event_identifier}Part", $data); + } + else if( $skintypeexists ) +>>>>>>> skinnable-master { $data = array( 'skinid' => $this->id, 'type' => $type ); +<<<<<<< HEAD +======= +>>>>>>> skinnable-master $manager->notify("PreDelete{$this->event_identifier}Part", $data); } // delete old thingie +<<<<<<< HEAD $query = "DELETE FROM %s WHERE stype=%s and sdesc=%d"; +======= + $query = "DELETE FROM %s WHERE stype=%s and sdesc=%d;"; +>>>>>>> skinnable-master $query = sprintf($query, sql_table('skin'), DB::quoteValue($type), (integer) $this->id); DB::execute($query); // write new thingie if ( $content ) { +<<<<<<< HEAD $query = "INSERT INTO %s (scontent, stype, sdesc) VALUE (%s, %s, %d)"; +======= + $query = "INSERT INTO %s (scontent, stype, sdesc) VALUES (%s, %s, %d);"; +>>>>>>> skinnable-master $query = sprintf($query, sql_table('skin'), DB::quoteValue($content), DB::quoteValue($type), (integer) $this->id); DB::execute($query); } @@ -499,6 +554,7 @@ class Skin if( $skintypevalue && $skintypeexists ) { $data = array( +<<<<<<< HEAD 'skinid' => $this->id, 'type' => $type, 'content' => &$content @@ -519,12 +575,33 @@ class Skin $manager->notify("PostAdd{$this->event_identifier}Part", $data); } else if( (!$skintypevalue) && $skintypeexists ) +======= + 'skinid' => $this->id, + 'type' => $type, + 'content' => &$content + ); + $manager->notify("PostUpdate{$this->event_identifier}Part", $data); + } + else if( $skintypevalue ) + { + $data = array( + 'skinid' => $this->id, + 'type' => $type, + 'content' => &$content + ); + $manager->notify("PostAdd{$this->event_identifier}Part", $data); + } + else if( $skintypeexists ) +>>>>>>> skinnable-master { $data = array( 'skinid' => $this->id, 'type' => $type ); +<<<<<<< HEAD +======= +>>>>>>> skinnable-master $manager->notify("PostDelete{$this->event_identifier}Part", $data); } return; @@ -613,14 +690,24 @@ class Skin } /** +<<<<<<< HEAD * Skin::getDefaultTypes() +======= + * Skin::getNormalTypes() +>>>>>>> skinnable-master * * @param string void * @return array default skin types */ +<<<<<<< HEAD public function getDefaultTypes() { return call_user_func(array($this->action_class, 'getAvailableSkinTypes')); +======= + public function getNormalTypes() + { + return call_user_func(array($this->action_class, 'getNormalSkinTypes')); +>>>>>>> skinnable-master } /** @@ -631,7 +718,11 @@ class Skin */ public function getAvailableTypes() { +<<<<<<< HEAD $default_skintypes = $this->getDefaultTypes(); +======= + $default_skintypes = $this->getNormalTypes(); +>>>>>>> skinnable-master $query = "SELECT stype FROM %s WHERE sdesc=%d;"; $query = sprintf($query, sql_table('skin'), (integer) $this->id); @@ -659,7 +750,11 @@ class Skin * Skin::getAllowedActionsForType() * Get the allowed actions for a skin type * returns an array with the allowed actions +<<<<<<< HEAD * +======= + * @return array allowed action types +>>>>>>> skinnable-master * @param string $skintype type of the skin * @return array allowed action types */ diff --git a/nucleus/libs/TEMPLATE.php b/nucleus/libs/TEMPLATE.php index 8421d64..ea7a6ac 100644 --- a/nucleus/libs/TEMPLATE.php +++ b/nucleus/libs/TEMPLATE.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD id = intval($templateid); + return; + } + + /** + * Template::getID() + * + * @param void + * @return integer id for this instance of Template class + */ + public function getID() + { + return (integer) $this->id; + } + + /** + * Template::createFromName() + * + * @statc + * @param string $name template name + * @return object instance of Template class generated by the name + */ + static public function createFromName($name) + { + return new Template(Template::getIdFromName($name)); + } + + /** + * Template::getIdFromName() + * + * @static + * @param string $name template name + * @return integer id for the template + */ + static public function getIdFromName($name) + { + $name = DB::quoteValue($name); + $query = "SELECT tdnumber FROM %s WHERE tdname=%s"; + $query = sprintf($query, sql_table('template_desc'), $name); + return DB::getValue($query); + } + + /** + * Template::updateGeneralInfo() + * Updates the general information about the template + * + * @param string $name template name + * @param string $desc description for this template + * @return void + */ + public function updateGeneralInfo($name, $desc) + { + $query = "UPDATE %s SET tdname=%s, tddesc=%s WHERE tdnumber=%d"; + $query = sprintf($query, sql_table('template_desc'), DB::quoteValue($name), DB::quoteValue($desc), (integer) $this->getID()); + DB::execute($query); + return; + } + + /** + * Template::update() + * Updates the contents of one part of the template + * + * @param String $type value for nucleus_template.tpartname + * @param String $content value for nucleus_template.tcontent + * @return Void + */ + public function update($type, $content) + { + // delete old thingie + $query = "DELETE FROM %s WHERE tpartname=%s and tdesc=%d"; + $query = sprintf($query, sql_table('template'), DB::quoteValue($type), (integer) $this->getID()); + DB::execute($query); + + // write new thingie + if ( $content ) + { + $query = "INSERT INTO %s (tcontent, tpartname, tdesc) VALUES (%s, %s, %d)"; + $query = sprintf($query, sql_table('template'), DB::quoteValue($content), DB::quoteValue($type), (integer) $this->getID()); + DB::execute($query); + } + return; + } + + /** + * Template::deleteAllParts() + * Deletes all template parts from the database + * + * @param void + * @return void + */ + public function deleteAllParts() + { + $query = "DELETE FROM %s WHERE tdesc=%d"; + $query = sprintf($query, sql_table('template'), (integer) $this->getID()); + DB::execute($query); + return; + } + + /** + * Template::createNew() + * Creates a new template + * + * @static + * @param string $name name for new template + * @param string $desc description for new template + * @return integer id for new template + */ + static public function createNew($name, $desc) + { + global $manager; + + $data = array( + 'name' => &$name, + 'description' => &$desc + ); + $manager->notify('PreAddTemplate', $data); + + DB::execute('INSERT INTO '.sql_table('template_desc').' (tdname, tddesc) VALUES (' . DB::quoteValue($name) . ',' . DB::quoteValue($desc) . ')'); + $newId = DB::getInsertId(); + + $data = array( + 'templateid' => $newId, + 'name' => $name, + 'description' => $desc + ); + $manager->notify('PostAddTemplate', $data); + + return $newId; + } + + /** + * Reads a template and returns an array with the parts. + * + * @static + * @param string $name name of the template file + * @return array template array + */ + static public function read($name) + { + global $manager; + $data = array('template' => &$name); + $manager->notify('PreTemplateRead', $data); + + $query = "SELECT tpartname, tcontent FROM %s, %s WHERE tdesc=tdnumber and tdname=%s"; + $query = sprintf($query, sql_table('template_desc'), sql_table('template'), DB::quoteValue($name)); + $res = DB::getResult($query); + + $template = array(); + foreach ( $res as $row ) + { + $template[$row['tpartname']] = $row['tcontent']; + } + + return $template; + } + + /** + * fills a template with values + * + * @static + * @param string $template Template to be used + * @param array $values Array of all the values + * @return string string filled with tag contents + */ + static public function fill($template, $values) + { + + if ( sizeof($values) != 0 ) + { + foreach ( $values as $key => $value ) + { + $template = preg_replace('#<%' . preg_quote($key, '#') . '%>#', $value, $template); + } + } + + // remove non matched template-tags + return preg_replace('#<%([a-zA-Z]+)?%>#', '', $template); + } + + /** + * Template::exists() + * returns true if there is a template with the given shortname + * + * @static + * @param string $name template name + * @return boolean exists or not + */ + static public function exists($name) + { + $query = "SELECT * FROM %s WHERE tdname=%s"; + $query = sprintf($query, sql_table('template_desc'), DB::quoteValue($name)); + $r = DB::getResult($query); + return ($r->rowCount() != 0); + } + + /** + * Template::existsID() + * returns true if there is a template with the given ID + * + * @static + * @param integer $id id for template + * @return bookean exists or not + */ + static public function existsID($id) + { + $query = "SELECT * FROM %s WHERE tdnumber=%d"; + $query = sprintf($query, sql_table('template_desc'), (integer) $id); + $r = DB::getResult($query); + return ($r->rowCount() != 0); + } + + /** + * Template::getNameFromId() + * + * @static + * @param integer $id id for template + * @return object sql object + */ + static public function getNameFromId($id) + { + $query = "SELECT tdname as result FROM %s WHERE tdnumber=%d"; + $query = sprintf($query, sql_table('template_desc'), (integer) $id); + return DB::getValue($query); + } + + /** + * Template::getDesc() + * + * @static + * @param integer $id id for template + * @return string description for the template + */ + static public function getDesc($id) + { + $query = "SELECT tddesc FROM %s WHERE tdnumber=%d"; + $query = sprintf($query, sql_table('template_desc'), (integer) $id); + return DB::getValue($query); + } +} +>>>>>>> skinnable-master diff --git a/nucleus/libs/backup.php b/nucleus/libs/backup.php index 64ae2da..ecc4762 100644 --- a/nucleus/libs/backup.php +++ b/nucleus/libs/backup.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD getPlugin($row['pfile']); + if ( $plug ) + { + $tables = array_merge($tables, (array) $plug->getTableList()); + } + } + ob_end_clean(); + + // remove duplicates + $tables = array_unique($tables); + + // make sure browsers don't cache the backup + header("Pragma: no-cache"); + + // don't allow gzip compression when extension is not loaded + if ( ($gzip != 0) && !extension_loaded("zlib") ) + { + $gzip = 0; + } + + if ( !$gzip ) + { + $filename = 'nucleus_db_backup_' . i18n::formatted_datetime('%Y-%m-%d-%H-%M-%S', time()) . ".sql"; + } + else + { + // use an output buffer + @ob_start(); + @ob_implicit_flush(0); + + // set filename + $filename = 'nucleus_db_backup_' . i18n::formatted_datetime('%Y-%m-%d-%H-%M-%S', time()) . ".sql.gz"; + } + + // send headers that tell the browser a file is coming + header("Content-Type: text/x-delimtext; name=\"$filename\""); + header("Content-disposition: attachment; filename=$filename"); + + // dump header + echo "/*\n"; + echo " * This is a backup file generated by Nucleus \n"; + echo " * http://www.nucleuscms.org/\n"; + echo " * \n"; + echo " * backup-date: " . i18n::formatted_datetime('rfc822GMT', time()) . "\n"; + echo " * Nucleus CMS version: " . $nucleus['version'] . "\n"; + echo " * \n"; + echo " * WARNING: Only try to restore on servers running the exact same version of Nucleus\n"; + echo " */\n"; + + // dump all tables + reset($tables); + /* NOTE: hope to use 'self' keyword here but works bad so here use __CLASS__ macro. */ + array_walk($tables, array(__CLASS__, 'dump_table')); + + if ( $gzip ) + { + $Size = ob_get_length(); + $Crc = crc32(ob_get_contents()); + $contents = gzcompress(ob_get_contents()); + ob_end_clean(); + echo "\x1f\x8b\x08\x00\x00\x00\x00\x00" . substr($contents, 0, strlen($contents) - 4) + . self::gzip_print_four_characters($Crc) . self::gzip_print_four_characters($Size); + } + exit; + } + + /** + * Backup::dump_table() + * Creates a dump for a single table + * ($tablename and $key are filled in by array_walk) + * + * @static + * @param string $tablename + * @param string $key + */ + static private function dump_table($tablename, $key) + { + echo "/*\n"; + echo " * TABLE: " . $tablename . "\n"; + echo " */\n"; + + // dump table structure + self::dump_structure($tablename); + + // dump table contents + self::dump_contents($tablename); + return; + } + + /** + * Backup::dump_structure() + * Creates a dump of the table structure for one table + * + * @static + * @param string $tablename + * @return void + * + */ + static private function dump_structure($tablename) + { + // add command to drop table on restore + echo "DROP TABLE IF EXISTS {$tablename};\n\n"; + $result = DB::getRow("SHOW CREATE TABLE {$tablename}"); + echo $result['Create Table']; + echo ";\n\n"; + return; + } + + /** + * Backup::get_field_names() + * Returns the field named for the given table in the + * following format: + * (column1, column2, ..., columnn) + * + * @static + * @param resource $result + * @param integer $num_fields + * @return string + */ + static private function get_field_names($result, $num_fields) + { + $fields = array(); + for ( $j = 0; $j < $num_fields; $j++ ) + { + $col = $result->getColumnMeta($j); + $fields[] = $col['name']; + } + + return '(' . implode(', ', $fields) . ')'; + } + + /** + * Backup::dump_contents() + * Creates a dump of the table content for one table + * + * @static + * @param string $tablename + * @return void + * + */ + static private function dump_contents($tablename) + { + /* + * Grab the data from the table. + */ + $result = DB::getResult("SELECT * FROM $tablename"); + + if ( $result->rowCount() > 0 ) + { + echo "\n"; + echo "/*\n"; + echo " * Table Data for {$tablename}\n"; + echo " */\n"; + } + + $num_fields = $result->columnCount(); + + /* + * Compose fieldname list + */ + $tablename_list = self::get_field_names($result, $num_fields); + + /* + * Loop through the resulting rows and build the sql statement. + */ + foreach ( $result as $row ) + { + // Start building the SQL statement. + echo 'INSERT INTO ' . $tablename . ' ' . $tablename_list . ' VALUES('; + + // Loop through the rows and fill in data for each column + for ( $j = 0; $j < $num_fields; $j++ ) + { + if ( !isset($row[$j]) ) + { + // no data for column + echo ' NULL'; + } + elseif ( $row[$j] != '' ) + { + // data + echo ' ' . DB::quoteValue($row[$j]); + } + else + { + // empty column (!= no data!) + echo "''"; + } + + // only add comma when not last column + if ( $j != ($num_fields - 1) ) + { + echo ','; + } + } + echo ");\n"; + } + echo "\n"; + return; + } + + /** + * Backup::gzip_print_four_characters() + * + * @static + * @param integer $val + * @return integer + */ + static private function gzip_print_four_characters($Val) + { + for ( $i = 0; $i < 4; $i ++ ) + { + $return .= chr($Val % 256); + $Val = floor($Val / 256); + } + return $return; + } + + /** + * Backup::do_restore() + * Restores a database backup + * + * NOTE: this remains not-static for compatibility + * + * @param void + * @return void + */ + public function do_restore() + { + $uploadInfo = postFileInfo('backup_file'); + + // first of all: get uploaded file: + if ( array_key_exists('name', $uploadInfo) && empty($uploadInfo['name']) ) + { + return 'No file uploaded'; + } + if ( !is_uploaded_file($uploadInfo['tmp_name']) ) + { + return 'No file uploaded'; + } + + $backup_file_name = $uploadInfo['name']; + $backup_file_tmpname = $uploadInfo['tmp_name']; + $backup_file_type = $uploadInfo['type']; + + if ( !file_exists($backup_file_tmpname) ) + { + return 'File Upload Error'; + } + + if ( !preg_match("#^(text/[a-zA-Z]+)|(application/(x\-)?gzip(\-compressed)?)|(application/octet-stream)$#i", $backup_file_type) ) + { + return 'The uploaded file is not of the correct type'; + } + + $gzip = 0; + if ( preg_match("#\.gz#i", $backup_file_name) ) + { + $gzip = 1; + } + + if ( !extension_loaded("zlib") && $gzip ) + { + return 'Cannot decompress gzipped backup (zlib package not installed)'; + } + + // get sql query according to gzip setting (either decompress, or not) + $contents = self::get_contents($backup_file_tmpname, $gzip); + if ( $contents == '' ) + { + return 'Cannot get contents from this file.'; + } + + /* detect lines */ + $lines = preg_split('/[\r\n]/', $contents); + if( $lines === $contents ) + { + return 'Cannot parse contents from this file'; + } + + /* get sql statements from each lines */ + $queries = self::get_queries($lines); + if ( $queries === array() ) + { + return "Cannot get SQL queries from this file."; + } + + /* execute sql statements */ + foreach ( $queries as $query ) + { + if ( DB::execute($query) === FALSE ) + { + $error = DB::getError(); + debug('SQL Error: ' . $error[2]); + break; + } + continue; + } + return; + } + + static private function get_contents($temporary_name, $gzip = 0) + { + $contents = ''; + if ( $gzip ) + { + // decompress and read + $gz_ptr = gzopen($temporary_name, 'rb'); + while ( !gzeof($gz_ptr) ) + { + $contents .= gzgets($gz_ptr, 100000); + } + } + else + { + // just read + $fsize = filesize($temporary_name); + if ( $fsize > 0 ) + { + $contents = fread(fopen($temporary_name, 'r'), $fsize); + } + } + return $contents; + } + + static private function get_queries($lines) + { + $query = ''; + $queries = array(); + foreach ( $lines as $line ) + { + $line = trim($line); + if ( !$line || $line[0] == '#' || preg_match('#^[\s|/]?\*#', $line) ) + { + continue; + } + + if ( preg_match('/^(.*);$/', $line, $matches) === 0 ) + { + $query .= $line; + } + else + { + $query .= $matches[1]; + $queries[] = $query; + $query = ''; + } + continue; + } + return $queries; + } +>>>>>>> skinnable-master } \ No newline at end of file diff --git a/nucleus/libs/globalfunctions.php b/nucleus/libs/globalfunctions.php index 9a7688a..e6448a8 100644 --- a/nucleus/libs/globalfunctions.php +++ b/nucleus/libs/globalfunctions.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD 0 ) +{ + $nucleus['version'] .= '/' . getNucleusPatchLevel(); +} + +/* Avoid notices */ +if ( !array_key_exists('installscript', $CONF) || empty($CONF['installscript']) ) +{ + $CONF['installscript'] = 0; +} +if ( !array_key_exists('UsingAdminArea', $CONF) ) +{ + $CONF['UsingAdminArea'] = 0; +} + +if ( !headers_sent() ) +{ + header('Generator: Nucleus CMS ' . $nucleus['version']); +} + + +/* TODO: This is for compatibility since 4.0, should be obsoleted at future release. */ +if ( !isset($DIR_LOCALES) ) +{ + $DIR_LOCALES = $DIR_NUCLEUS . 'locales/'; +} +global $DIR_LANG; +if ( !isset($DIR_LANG) ) +{ + $DIR_LANG = $DIR_LOCALES; +} + +/* load and initialize i18n class */ +if (!class_exists('i18n', FALSE)) +{ + include($DIR_LIBS . 'i18n.php'); +} +if ( !i18n::init('UTF-8', $DIR_LOCALES) ) +{ + exit('Fail to initialize i18n class.'); +} + +/* TODO: This is just for compatibility since 4.0, should be obsoleted at future release. */ +define('_CHARSET', i18n::get_current_charset()); + + +/* + * NOTE: Since 4.0 release, Entity class becomes to be important class + * with some wrapper functions for htmlspechalchars/htmlentity PHP's built-in function + */ +include($DIR_LIBS . 'ENTITY.php'); + +/* we will use postVar, getVar, ... methods instead of $_GET, $_POST ... */ +if ( $CONF['installscript'] != 1 ) +{ + /* vars were already included in install.php */ + include_once($DIR_LIBS . 'vars4.1.0.php'); + + /* added for 4.0 DB::* wrapper and compatibility sql_* */ + include_once($DIR_LIBS . 'sql/sql.php'); +} + +/* include core classes that are needed for login & plugin handling */ +include($DIR_LIBS . 'MEMBER.php'); +include($DIR_LIBS . 'ACTIONLOG.php'); +include($DIR_LIBS . 'MANAGER.php'); +include($DIR_LIBS . 'PLUGIN.php'); + +$manager =& MANAGER::instance(); + +/* only needed when updating logs */ +if ( $CONF['UsingAdminArea'] ) +{ + /* XML-RPC client classes */ + include($DIR_LIBS . 'xmlrpc.inc.php'); + include($DIR_LIBS . 'ADMIN.php'); +} + + +/* connect to database */ +if ( !isset($MYSQL_HANDLER) ) +{ + $MYSQL_HANDLER = array('mysql',''); +} +if ( $MYSQL_HANDLER[0] == '' ) +{ + $MYSQL_HANDLER[0] = 'mysql'; +} +DB::setConnectionInfo($MYSQL_HANDLER[1], $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE); + + +/* force locale or charset */ +$locale = ''; +$charset = i18n::get_current_charset(); + +$data = array( + 'locale' => &$locale, + 'charset' => &$charset +); +$manager->notify('ForceLocale', $data); + +if ( $data['locale'] !== '' ) +{ + i18n::set_forced_locale($data['locale']); +} +if ( $data['charset'] !== '' ) +{ + i18n::set_forced_charset($data['charset']); +} +unset($locale); +unset($charset); + + +/* convert forced charset to current charset */ +if ( i18n::get_forced_charset() != i18n::get_current_charset() ) +{ + $_POST = i18n::convert_array($_POST, i18n::get_forced_charset()); + $_GET = i18n::convert_array($_GET, i18n::get_forced_charset()); + $_REQUEST = i18n::convert_array($_REQUEST, i18n::get_forced_charset()); + $_COOKIE = i18n::convert_array($_COOKIE, i18n::get_forced_charset()); + $_FILES = i18n::convert_array($_FILES, i18n::get_forced_charset()); + + if ( session_id() !== '' ) + { + $_SESSION = i18n::convert_array($_SESSION, i18n::get_forced_charset()); + } +} + + +/* sanitize option */ +$bLoggingSanitizedResult = 0; +$bSanitizeAndContinue = 0; +$orgRequestURI = serverVar('REQUEST_URI'); +sanitizeParams(); + +/* logs sanitized result if need */ +if ( $orgRequestURI !== serverVar('REQUEST_URI') ) +{ + $msg = "Sanitized [" . serverVar('REMOTE_ADDR') . "] "; + $msg .= $orgRequestURI . " -> " . serverVar('REQUEST_URI'); + if ( $bLoggingSanitizedResult ) + { + addToLog(WARNING, $msg); + } + if ( !$bSanitizeAndContinue ) + { + die(""); + } +} + +/* get all variables that can come from the request and put them in the global scope */ +$blogid = requestVar('blogid'); +$itemid = intRequestVar('itemid'); +$catid = intRequestVar('catid'); +$skinid = requestVar('skinid'); +$memberid = requestVar('memberid'); +$archivelist = requestVar('archivelist'); +$imagepopup = requestVar('imagepopup'); +$archive = requestVar('archive'); +$query = requestVar('query'); +$highlight = requestVar('highlight'); +$amount = requestVar('amount'); +$action = requestVar('action'); +$nextaction = requestVar('nextaction'); +$maxresults = requestVar('maxresults'); +$startpos = intRequestVar('startpos'); +$errormessage = ''; +$error = ''; +$special = requestVar('special'); + + +/* read config */ +getConfig(); + + +/* Properly set $CONF['Self'] and others if it's not set... + * usually when we are access from admin menu + */ +if ( !array_key_exists('Self', $CONF) ) +{ + $CONF['Self'] = $CONF['IndexURL']; + /* strip trailing */ + if ( $CONF['Self'][i18n::strlen($CONF['Self']) -1] == "/" ) + { + $CONF['Self'] = i18n::substr($CONF['Self'], 0, i18n::strlen($CONF['Self']) -1); + } +} + +$CONF['ItemURL'] = $CONF['Self']; +$CONF['ArchiveURL'] = $CONF['Self']; +$CONF['ArchiveListURL'] = $CONF['Self']; +$CONF['MemberURL'] = $CONF['Self']; +$CONF['SearchURL'] = $CONF['Self']; +$CONF['BlogURL'] = $CONF['Self']; +$CONF['CategoryURL'] = $CONF['Self']; + +/* automatically use simpler toolbar for mozilla */ +if ( ($CONF['DisableJsTools'] == 0) + && i18n::strpos(serverVar('HTTP_USER_AGENT'), 'Mozilla/5.0') !== FALSE + && i18n::strpos(serverVar('HTTP_USER_AGENT'), 'Gecko') !== FALSE ) +{ + $CONF['DisableJsTools'] = 2; +} + +/* login processing */ +$member = new Member(); +if ( $action == 'login' ) +{ + $login = postVar('login'); + $password = postVar('password'); + $shared = intPostVar('shared'); + $member->login($login, $password, $shared); +} +elseif ( ($action == 'logout') ) +{ + $member->logout(); +} +else +{ + $member->cookielogin(); +} + +/* TODO: This is for backward compatibility, should be obsoleted near future. */ +if ( !preg_match('#^(.+)_(.+)_(.+)$#', $CONF['Locale']) + && ($CONF['Locale'] = i18n::convert_old_language_file_name_to_locale($CONF['Locale'])) === FALSE ) +{ + $CONF['Locale'] = 'en_Latn_US'; +} +if ( !array_key_exists('Language', $CONF) ) +{ + $CONF['Language'] = i18n::convert_locale_to_old_language_file_name($CONF['Locale']); +} +$locale = $CONF['Locale']; + + +/* NOTE: include translation file and set locale */ +if ( $member->isLoggedIn() ) +{ + if ( $member->getLocale() ) + { + $locale = $member->getLocale(); + } +} +else +{ + if ( i18n::get_forced_locale() !== '' ) + { + $locale = i18n::get_forced_locale(); + } +} +include_translation($locale); +i18n::set_current_locale($locale); + + +/* login completed */ +$data = array('loggedIn' => $member->isLoggedIn()); +$manager->notify('PostAuthentication', $data); + +/* next action */ +if ( $member->isLoggedIn() && $nextaction ) +{ + $action = $nextaction; +} + +/* first, let's see if the site is disabled or not. always allow admin area access. */ +if ( $CONF['DisableSite'] && !$member->isAdmin() && !$CONF['UsingAdminArea'] ) +{ + redirect($CONF['DisableSiteURL']); + exit; +} + +/* load other classes */ +include($DIR_LIBS . 'PARSER.php'); +include($DIR_LIBS . 'SKIN.php'); +include($DIR_LIBS . 'TEMPLATE.php'); +include($DIR_LIBS . 'BLOG.php'); +include($DIR_LIBS . 'BODYACTIONS.php'); +include($DIR_LIBS . 'COMMENTS.php'); +include($DIR_LIBS . 'COMMENT.php'); +include($DIR_LIBS . 'NOTIFICATION.php'); +include($DIR_LIBS . 'BAN.php'); +include($DIR_LIBS . 'SEARCH.php'); +include($DIR_LIBS . 'LINK.php'); + +/* set lastVisit cookie (if allowed) */ +if ( !headers_sent() ) +{ + if ( $CONF['LastVisit'] ) + { + setcookie($CONF['CookiePrefix'] . 'lastVisit', time(), time() + 2592000, $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']); + } + else + { + setcookie($CONF['CookiePrefix'] . 'lastVisit', '', (time() - 2592000), $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']); + } +} + +/* for path resolving */ +$virtualpath = getVar('virtualpath'); +if ( getVar('virtualpath') == '' ) +{ + $virtualpath = serverVar('PATH_INFO'); +} + +/* + * switch URLMode back to normal when $CONF['Self'] ends in .php + * this avoids urls like index.php/item/13/index.php/item/15 + */ +if ( !array_key_exists('URLMode', $CONF) || ($CONF['URLMode'] != 'pathinfo') ) +{ + $CONF['URLMode'] = 'normal'; +} +else +{ + if ( i18n::substr($CONF['Self'], i18n::strlen($CONF['Self']) - 4) != '.php' ) + { + decodePathInfo($virtualpath); + } +} + +/* + * PostParseURL is a place to cleanup any of the path-related global variables before the selector function is run. + * It has 2 values in the data in case the original virtualpath is needed, but most the use will be in tweaking + * global variables to clean up (scrub out catid or add catid) or to set someother global variable based on + * the values of something like catid or itemid + * New in 3.60 + */ +$data = array( + 'type' => basename(serverVar('SCRIPT_NAME')), + 'info' => $virtualpath +); +$manager->notify('PostParseURL', $data); + +/* + * NOTE: Here is the end of initialization + */ + +/** + * include_libs() + * This function includes or requires the specified library file + * + * @param string $file + * @param boolean $once use the _once() version + * @param boolean $require use require() instead of include() + * @return void + */ +function include_libs($file, $once = TRUE, $require = TRUE) +{ + global $DIR_LIBS; + + // $DIR_LIBS isn't a directory + if ( !is_dir($DIR_LIBS) ) + { + exit; + } + + $lib_path = $DIR_LIBS . $file; + + if ( $once && $require ) + { + require_once($lib_path); + } + else if ( $once && !$require ) + { + include_once($lib_path); + } + else if ( $require ) + { + require($lib_path); + } + else + { + include($lib_path); + } + return; +} + +/** + * include_plugins() + * This function includes or requires the specified plugin file + * + * @param string $file + * @param boolean $once use the _once() version + * @param boolean $require use require() instead of include() + * @return + */ +function include_plugins($file, $once = TRUE, $require = TRUE) +{ + global $DIR_PLUGINS; + + // begin if: $DIR_LIBS isn't a directory + if ( !is_dir($DIR_PLUGINS) ) + { + exit; + } + + $plugin_path = $DIR_PLUGINS . $file; + + // begin if: + if ( $once && $require ) + { + require_once($plugin_path); + } + else if ( $once && !$require ) + { + include_once($plugin_path); + } + elseif ( $require ) + { + require($plugin_path); + } + else + { + include($plugin_path); + } + return; +} + +/** + * include_translation() + * This function decide which locale is used and include translation + * + * @param string &$locale locale name referring to 'language tags' defined in RFC 5646 + * @return void + */ +function include_translation(&$locale) +{ + global $DIR_LOCALES; + + $translation_file = $DIR_LOCALES . $locale . '.' . i18n::get_current_charset() . '.php'; + if ( !file_exists($translation_file) ) + { + $locale = 'en_Latn_US'; + $translation_file = $DIR_LOCALES . 'en_Latn_US.ISO-8859-1.php'; + } + include($translation_file); + + /* + * NOTE: + * PHP is written by C and utilize C library, whose APIs are defined in POSIX. + * + * setlocale() is one of APIs of C library. + * but the argument value for setlocale() depends on each implements + * + * The latest POSIX standard: + * The Open Group Base Specifications Issue 7 + * IEEE Std 1003.1™-2008 + * http://pubs.opengroup.org/onlinepubs/9699919799/mindex.html + * + * Microsoft's operating system uses their own implementation + * Language Strings + * http://msdn.microsoft.com/en-us/library/39cwe7zf%28v=vs.110%29.aspx + * Country/Region Strings + * http://msdn.microsoft.com/en-us/library/cdax410z%28v=vs.110%29.aspx + * + * Linux and Unix (in this meaning, Apple's OS X derives from UNIX) uses ISO standard. + * two characters language tag (ISO 639-1) + * two characters region and country lag (ISO 3166-1 alpha-1) + * + */ + if ( PHP_OS == "WIN32" || PHP_OS == "WINNT" ) + { + /* LOCALE_IN_WINDOWS is defined in each translation files */ + setlocale(LC_ALL, _LOCALE_IN_WINDOWS); + } + else + { + setlocale(LC_ALL, preg_replace('#(.+)_(.+)_(.+)#', '$1-$3', $locale)); + } + return; +} + +/** + * intPostVar() + * This function returns the integer value of $_POST for the variable $name + * + * @param string $name field to get the integer value of + * @return integer + */ +function intPostVar($name) +{ + return (integer) postVar($name); +} + + +/** + * intGetVar() + * This function returns the integer value of $_GET for the variable $name + * + * @param string $name field to get the integer value of + * @return integer + */ +function intGetVar($name) +{ + return (integer) getVar($name); +} + + +/** + * intRequestVar() + * This function returns the integer value of $_REQUEST for the variable $name. Also checks $_GET and $_POST if not found in $_REQUEST + * + * @param string $name field to get the integer value of + * @return int + */ +function intRequestVar($name) +{ + return (integer) requestVar($name); +} + + +/** + * intCookieVar() + * This function returns the integer value of $_COOKIE for the variable $name + * + * @param string $name field to get the integer value of + * @return integer + */ +function intCookieVar($name) +{ + return (integer) cookieVar($name); +} + +/** + * getNucleusVersion() + * This function returns the current Nucleus version (100 = 1.00, 101 = 1.01, etc...) + * + * @param void + * @return integer + */ +function getNucleusVersion() +{ + return 400; +} + +/** + * getNucleusPatchLevel() + * TODO: Better description of this function. + * + * Power users can install patches in between nucleus releases. These patches + * usually add new functionality in the plugin API and allow those to + * be tested without having to install CVS. + * + *@param void + * @return integer + */ +function getNucleusPatchLevel() +{ + return 0; +} + +/** + * getLatestVersion() + * This function returns the latest Nucleus version available for download from nucleuscms.org or FALSE if unable to attain data + * Format will be major.minor/patachlevel e.g. 3.41 or 3.41/02 + * + * @param void + * @return mixed + */ +function getLatestVersion() +{ + // begin if: cURL is not available in this PHP installation + if ( !function_exists('curl_init') ) + { + return FALSE; + } + + $curl = curl_init(); + $timeout = 5; + + curl_setopt ($curl, CURLOPT_URL, 'http://nucleuscms.org/version_check.php'); + curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, $timeout); + + $return = curl_exec($curl); + + curl_close($curl); + + return $return; +} + +/** + * sql_table() + * This function returns a Nucleus table name with the appropriate prefix + * @param string $name + * @return string + */ +function sql_table($name) +{ + global $MYSQL_PREFIX; + + // begin if: no MySQL prefix + if ( empty($MYSQL_PREFIX) ) + { + return 'nucleus_' . $name; + } + // else: use MySQL prefix + else + { + return $MYSQL_PREFIX . 'nucleus_' . $name; + } + return; +} + +/** + * sendContentType() + * This function sends the Content-Type header if headers have not already been sent + * It also determines if the browser can accept application/xhtml+xml and sends it only to those that can. + * + * if content type is application/xhtml+xml, only send it to browsers + * that can handle it (IE6 cannot). Otherwise, send text/html + * + * v2.5: + * For admin area pages, keep sending text/html (unless it's a debug version) + * application/xhtml+xml still causes too much problems with the javascript implementations + * + * v3.3: + * ($CONF['UsingAdminArea'] && !$CONF['debug']) gets removed, + * application/xhtml+xml seems to be working, so we're going to use it if we can. + * + * @param string $content_type MIME media type registered to IANA, http://www.iana.org/assignments/media-types/index.html + * @param string $page_type + * @param string $charset Deprecated. This has no meaning. + * @return void + * + */ +function sendContentType($content_type, $page_type = '', $charset = '') +{ + global $manager, $CONF; + + if ( headers_sent() ) + { + return; + } + + /* NOTE: MIME Media Type */ + if ( ($content_type == 'application/xhtml+xml') + && (!stristr(serverVar('HTTP_ACCEPT'), 'application/xhtml+xml') ) ) + { + $content_type = 'text/html'; + } + + /* NOTE: generate event */ + $data = array( + 'pageType' => $page_type, + 'contentType' => &$content_type + ); + $manager->notify('PreSendContentType', $data); + + /* NOTE: confirm MIME Media Type */ + $content_type = preg_replace('#[^a-zA-Z0-9-+./]#', '', $content_type); + + /* NOTE: confirm character set */ + $charset = i18n::get_current_charset(); + if ( i18n::get_forced_charset() !== '' ) + { + $charset = i18n::get_forced_charset(); + } + + /* NOTE: send HTTP 1.1 header */ + header("Content-Type: {$content_type}; charset={$charset}"); + + /* NOTE: set handler for translating character set */ + if ( $charset != i18n::get_current_charset() ) + { + ob_start(array('i18n', 'convert_handler')); + } + + return; +} + +/** + * parseHighlight() + * This function parses a query into an array of expressions that can be passed on to the highlight method + * @param string $query + * @return void + */ +function parseHighlight($query) +{ + // TODO: add more intelligent splitting logic + + // get rid of quotes + $query = preg_replace('/\'|"/', '', $query); + + if ( !$query ) + { + return array(); + } + + $aHighlight = preg_split('# #', $query); + + for ( $i = 0; $i < count($aHighlight); $i++ ) + { + $aHighlight[$i] = trim($aHighlight[$i]); + + if ( i18n::strlen($aHighlight[$i]) < 3 ) + { + unset($aHighlight[$i]); + } + } + + if ( count($aHighlight) == 1 ) + { + return $aHighlight[0]; + } + else + { + return $aHighlight; + } + return; +} + +/** + * getConfig() + * + * @param void + * @return void + */ +function getConfig() +{ + global $CONF; + + $query = sprintf('SELECT * FROM %s', sql_table('config')); + $res = DB::getResult($query); + + foreach ( $res as $row ) + { + $CONF[$row['name']] = $row['value']; + } + return; +} + +/** + * This function gets the blog ID from the blog name + * @param string $name + * @return + */ +function getBlogIDFromName($name) +{ + $query = sprintf('SELECT bnumber AS result FROM %s WHERE bshortname=%s', sql_table('blog'), DB::quoteValue($name)); + return DB::getValue($query); +} + +/** + * This function gets the blog name from the blog ID + * @param int $id + * @return object + */ +function getBlogNameFromID($id) +{ + $query = sprintf('SELECT bname AS result FROM %s WHERE bnumber=%d', sql_table('blog'), intval($id)); + return DB::getValue($query); +} + +/** + * This function gets the blog ID from the item ID + * @param int $item_id + * @return object + */ +function getBlogIDFromItemID($item_id) +{ + $query = sprintf('SELECT iblog AS result FROM %s WHERE inumber=%d', sql_table('item'), intval($item_id)); + return DB::getValue($query); +} + +/** + * This function gets the blog ID from the comment ID + * @param int $comment_id + * @return object + */ +function getBlogIDFromCommentID($comment_id) +{ + $query = sprintf('SELECT cblog AS result FROM %s WHERE cnumber=%d', sql_table('comment'), intval($comment_id)); + return DB::getValue($query); +} + +/** + * This function gets the blog ID from the category ID + * @param int $category_id + * @return object + */ +function getBlogIDFromCatID($category_id) +{ + $query = sprintf('SELECT cblog AS result FROM %s WHERE catid=%d', sql_table('category'), intval($category_id)); + return DB::getValue($query); +} + +/** + * This function gets the category ID from the category name + * @param int $name + * @return object + */ +function getCatIDFromName($name) +{ + $query = sprintf('SELECT catid AS result FROM %s WHERE cname=%s', sql_table('category'), DB::quoteValue($name)); + return DB::getValue($query); +} + + +/** + * functions to be used in index.php to select something + */ +function selectBlog($shortname) +{ + global $blogid, $archivelist; + $blogid = getBlogIDFromName($shortname); + + // also force archivelist variable, if it is set + if ( $archivelist ) + { + $archivelist = $blogid; + } + return; +} +function selectSkin($skinname) +{ + global $skinid; + $skinid = SKIN::getIdFromName($skinname); + return; +} +function selectCategory($cat) +{ + global $catid; + if ( is_numeric($cat) ) + { + $catid = (integer) $cat; + } + else + { + $catid = getCatIDFromName($cat); + } + return; +} +function selectItem($id) +{ + global $itemid; + $itemid = (integer) $id; + return; +} +function selectSpecialSkinType($id) +{ + global $special; + $special = strtolower($id); + return; +} +function selector() +{ + global $archive, $archivelist, $archivenext, $archivenextexists, $archiveprev, $archiveprevexists, $archivetype; + global $blog, $blogid; + global $catid; + global $itemid, $itemidnext, $itemidprev, $itemtitlenext, $itemtitleprev; + global $CONF, $DIR_LIBS, $amount, $errormessage, $imagepopup; + global $manager, $maxresults, $query; + global $member, $memberid, $memberinfo; + global $skinid, $skinpart, $special; + + $actionNames = array('addcomment', 'sendmessage', 'createaccount', 'forgotpassword', 'votepositive', 'votenegative', 'plugin'); + $action = requestVar('action'); + + if ( in_array($action, $actionNames) ) + { + include_once($DIR_LIBS . 'ACTION.php'); + $a = new Action(); + $errorInfo = $a->doAction($action); + + if ( $errorInfo ) + { + $errormessage = $errorInfo['message']; + } + } + + // show error when headers already sent out + if ( headers_sent() && $CONF['alertOnHeadersSent'] ) + { + // try to get line number/filename (extra headers_sent params only exists in PHP 4.3+) + if ( function_exists('version_compare') && version_compare('4.3.0', phpversion(), '<=') ) + { + headers_sent($hsFile, $hsLine); + $extraInfo = ' in ' . $hsFile . ' line ' . $hsLine . ''; + } + else + { + $extraInfo = ''; + } + + startUpError( + "

    The page headers have already been sent out{$extraInfo}. This could cause Nucleus not to work in the expected way.

    " + . "

    Usually, this is caused by spaces or newlines at the end of the config.php file, " + . "at the end of the translation file or at the end of a plugin file.

    " + . "

    Please check this and try again.

    " + . "

    If you don't want to see this error message again, without solving the problem, " + . "set {$CONF['alertOnHeadersSent']} in globalfunctions.php to 0

    " + . "Page headers already sent" + ); + exit; + } + + // make is so ?archivelist without blogname or blogid shows the archivelist + // for the default weblog + if ( serverVar('QUERY_STRING') == 'archivelist' ) + { + $archivelist = $CONF['DefaultBlog']; + } + + // now decide which type of skin we need + if ( $itemid ) + { + // itemid given -> only show that item + $type = 'item'; + + if ( !$manager->existsItem($itemid,intval($CONF['allowFuture']),intval($CONF['allowDrafts'])) ) + { + doError(_ERROR_NOSUCHITEM); + return; + } + + // 1. get timestamp, blogid and catid for item + $query = 'SELECT itime, iblog, icat FROM %s WHERE inumber=%d'; + $query = sprintf($query, sql_table('item'), intval($itemid)); + $row = DB::getRow($query); + + // if a different blog id has been set through the request or selectBlog(), + // deny access + + if ( $blogid && (intval($blogid) != $row['iblog']) ) + { + doError(_ERROR_NOSUCHITEM); + return; + } + + // if a category has been selected which doesn't match the item, ignore the + // category. #85 + if ( ($catid != 0) && ($catid != $row['icat']) ) + { + $catid = 0; + } + + $blogid = $row['iblog']; + $timestamp = strtotime($row['itime']); + + $b =& $manager->getBlog($blogid); + + if ( !$b->isValidCategory($catid) ) + { + $query = "SELECT inumber, ititle FROM %s WHERE itime<%s AND idraft=0 AND iblog=%d ORDER BY itime DESC LIMIT 1"; + $query = sprintf($query, sql_table('item'), DB::formatDateTime($timestamp), intval($blogid)); + } + else + { + $query = "SELECT inumber, ititle FROM %s WHERE itime<%s AND idraft=0 AND iblog=%d AND icat=%d ORDER BY itime DESC LIMIT 1"; + $query = sprintf($query, sql_table('item'), DB::formatDateTime($timestamp), intval($blogid), intval($catid)); + } + $row = DB::getRow($query); + + if ( $row ) + { + $itemidprev = $row['inumber']; + $itemtitleprev = $row['ititle']; + } + + // get next itemid and title + if ( !$b->isValidCategory($catid) ) + { + $query = "SELECT inumber, ititle FROM %s WHERE itime>%s AND itime<=%s AND idraft=0 AND iblog=%d ORDER BY itime ASC LIMIT 1"; + $query = sprintf($query, sql_table('item'), DB::formatDateTime($timestamp), DB::formatDateTime($b->getCorrectTime()), intval($blogid)); + } + else + { + $query = "SELECT inumber, ititle FROM %s WHERE itime>%s AND itime<=%s AND idraft=0 AND iblog=%d AND icat=%d ORDER BY itime ASC LIMIT 1"; + $query = sprintf($query, sql_table('item'), DB::formatDateTime($timestamp), DB::formatDateTime($b->getCorrectTime()), intval($blogid), intval($catid)); + } + $row = DB::getRow($query); + + if ( $row ) + { + $itemidnext = $row['inumber']; + $itemtitlenext = $row['ititle']; + } + } + elseif ( $archive ) + { + // show archive + $type = 'archive'; + + // sql queries for the timestamp of the first and the last published item + $query = sprintf('SELECT UNIX_TIMESTAMP(itime) as result FROM %s WHERE idraft=0 ORDER BY itime ASC', sql_table('item')); + $first_timestamp = DB::getValue($query); + $query = sprintf('SELECT UNIX_TIMESTAMP(itime) as result FROM %s WHERE idraft=0 ORDER BY itime DESC', sql_table('item')); + $last_timestamp = DB::getValue($query); + + sscanf($archive, '%d-%d-%d', $y, $m, $d); + + if ( $d != 0 ) + { + $archivetype = _LABEL_DAY_UNIT; + $t = mktime(0, 0, 0, $m, $d, $y); + // one day has 24 * 60 * 60 = 86400 seconds + $archiveprev = i18n::formatted_datetime('%Y-%m-%d', $t - 86400 ); + // check for published items + if ( $t > $first_timestamp ) + { + $archiveprevexists = true; + } + else + { + $archiveprevexists = false; + } + + // one day later + $t += 86400; + $archivenext = i18n::formatted_datetime('%Y-%m-%d', $t); + if ( $t < $last_timestamp ) + { + $archivenextexists = true; + } + else + { + $archivenextexists = false; + } + } + elseif ( $m == 0 ) + { + $archivetype = _LABEL_YEAR_UNIT; + $t = mktime(0, 0, 0, 12, 31, $y - 1); + // one day before is in the previous year + $archiveprev = i18n::formatted_datetime('%Y', $t); + if ( $t > $first_timestamp ) + { + $archiveprevexists = true; + } + else + { + $archiveprevexists = false; + } + + // timestamp for the next year + $t = mktime(0, 0, 0, 1, 1, $y + 1); + $archivenext = i18n::formatted_datetime('%Y', $t); + if ( $t < $last_timestamp ) + { + $archivenextexists = true; + } + else + { + $archivenextexists = false; + } + } + else + { + $archivetype = _LABEL_MONTH_UNIT; + $t = mktime(0, 0, 0, $m, 1, $y); + // one day before is in the previous month + $archiveprev = i18n::formatted_datetime('%Y-%m', $t - 86400); + if ( $t > $first_timestamp ) + { + $archiveprevexists = true; + } + else + { + $archiveprevexists = false; + } + + // timestamp for the next month + $t = mktime(0, 0, 0, $m+1, 1, $y); + $archivenext = i18n::formatted_datetime('%Y-%m', $t); + if ( $t < $last_timestamp ) + { + $archivenextexists = true; + } + else + { + $archivenextexists = false; + } + } + } + elseif ( $archivelist ) + { + $type = 'archivelist'; + + if ( is_numeric($archivelist) ) + { + $blogid = intVal($archivelist); + } + else + { + $blogid = getBlogIDFromName($archivelist); + } + + if ( !$blogid ) + { + doError(_ERROR_NOSUCHBLOG); + return; + } + } + elseif ( $query ) + { + global $startpos; + $type = 'search'; + $query = stripslashes($query); + + if ( is_numeric($blogid) ) + { + $blogid = intVal($blogid); + } + else + { + $blogid = getBlogIDFromName($blogid); + } + + if ( !$blogid ) + { + doError(_ERROR_NOSUCHBLOG); + return; + } + } + elseif ( $memberid ) + { + $type = 'member'; + + if ( !Member::existsID($memberid) ) + { + doError(_ERROR_NOSUCHMEMBER); + return; + } + $memberinfo = $manager->getMember($memberid); + } + elseif ( $imagepopup ) + { + // media object (images etc.) + $type = 'imagepopup'; + + // TODO: check if media-object exists + // TODO: set some vars? + } + else + { + // show regular index page + global $startpos; + $type = 'index'; + } + + // any type of skin with catid + if ( $catid && !$blogid ) + { + $blogid = getBlogIDFromCatID($catid); + } + + // decide which blog should be displayed + if ( !$blogid ) + { + $blogid = $CONF['DefaultBlog']; + } + + $b =& $manager->getBlog($blogid); + $blog = $b; // references can't be placed in global variables? + + if ( !$blog->isValid ) + { + doError(_ERROR_NOSUCHBLOG); + return; + } + + // set catid if necessary + if ( $catid ) + { + // check if the category is valid + if ( !$blog->isValidCategory($catid) ) + { + doError(_ERROR_NOSUCHCATEGORY); + return; + } + else + { + $blog->setSelectedCategory($catid); + } + } + + if ( !$skinid ) + { + $skinid = $blog->getDefaultSkin(); + } + + if ( !empty($special) && isValidShortName($special) ) + { + $type = strtolower($special); + } + + $skin =& $manager->getSkin($skinid); + + if ( !$skin->isValid() ) + { + doError(_ERROR_NOSUCHSKIN); + return; + } + + // set global skinpart variable so can determine quickly what is being parsed from any plugin or phpinclude + $skinpart = $type; + + // parse the skin + $skin->parse($type); + + // check to see we should throw JustPosted event + $blog->checkJustPosted(); + return; +} + +/** + * doError() + * Show error skin with given message. An optional skin-object to use can be given + * + * @param string $msg + * @param string $skin + * @return void + */ +function doError($msg, $skin = '') +{ + global $errormessage, $CONF, $skinid, $blogid, $manager; + + if ( $skin == '' ) + { + if ( Skin::existsID($skinid) ) + { + $id = $skinid; + } + elseif ( $manager->existsBlogID($blogid) ) + { + $blog =& $manager->getBlog($blogid); + $id = $blog->getDefaultSkin(); + } + elseif ($CONF['DefaultBlog'] ) + { + $blog =& $manager->getBlog($CONF['DefaultBlog']); + $id = $blog->getDefaultSkin(); + } + else + { + // this statement should actually never be executed + $id = $CONF['BaseSkin']; + } + $skin =& $manager->getSkin($id); + } + + $errormessage = $msg; + $skin->parse('error'); + return; +} + +/** + * Errors before the database connection has been made + * + * @param string $msg message to notify + * @param string $title page title + * @return void + */ +function startUpError($msg, $title) +{ + header('Content-Type: text/xml; charset=' . i18n::get_current_charset()); + echo "\n"; + echo "\n"; + echo "{$title}\n"; + echo "\n"; + echo "

    {$title}

    \n"; + echo $msg; + echo "\n"; + echo "\n"; + exit; +} + +function isValidShortName($name) +{ + return preg_match('#^[a-z0-9]+$#i', $name); +} +function isValidDisplayName($name) +{ + return preg_match('#^[a-z0-9]+[a-z0-9 ]*[a-z0-9]+$#i', $name); +} +function isValidCategoryName($name) +{ + return 1; +} +function isValidTemplateName($name) +{ + return preg_match('#^[a-z0-9/_\-]+$#i', $name); +} +function isValidSkinName($name) +{ + return preg_match('#^[a-z0-9/_\-]+$#i', $name); +} + +// add and remove linebreaks +function addBreaks($var) +{ + return nl2br($var); +} +function removeBreaks($var) +{ + return preg_replace("/
    ([\r\n])/", "$1", $var); +} + +/** + * parseFile() + * + * @param string $filename + * @param string $includeMode + * @param string $includePrefix + * @return void + */ +function parseFile($filename, $includeMode = 'normal', $includePrefix = '') +{ + global $manager, $skinid; + + if ( !$skinid || !existsID($skinid) ) + { + $skin =& $manager->getSkin($CONF['BaseSkin']); + } + else + { + $skin =& $manager->getSkin($skinid); + } + + $oldIncludeMode = Parser::getProperty('IncludeMode'); + $oldIncludePrefix = Parser::getProperty('IncludePrefix'); + + $skin->parse('fileparse', $filename); + + Parser::setProperty('IncludeMode', $oldIncludeMode); + Parser::setProperty('IncludePrefix', $oldIncludePrefix); + + return; +} + +/** + * debug() + * Outputs a debug message + * + * @param string $msg + * @return void + */ +function debug($msg) +{ + echo '

    ' . $msg . "

    \n"; + return; +} + +// shows a link to help file +function help($id) +{ + echo helpHtml($id); + return; +} +function helpHtml($id) +{ + global $CONF; + return helplink($id) . '' . _HELP_TT . ''; +} +function helplink($id) +{ + global $CONF; + return ''; +} + +/** + * includephp() + * Includes a PHP file. This method can be called while parsing templates and skins + * + * @param string $filename name of file to parse + * @return void + */ +function includephp($filename) +{ + // make predefined variables global, so most simple scripts can be used here + + // apache (names taken from PHP doc) + global $GATEWAY_INTERFACE, $SERVER_NAME, $SERVER_SOFTWARE, $SERVER_PROTOCOL; + global $REQUEST_METHOD, $QUERY_STRING, $DOCUMENT_ROOT, $HTTP_ACCEPT; + global $HTTP_ACCEPT_CHARSET, $HTTP_ACCEPT_ENCODING, $HTTP_ACCEPT_LANGUAGE; + global $HTTP_CONNECTION, $HTTP_HOST, $HTTP_REFERER, $HTTP_USER_AGENT; + global $REMOTE_ADDR, $REMOTE_PORT, $SCRIPT_FILENAME, $SERVER_ADMIN; + global $SERVER_PORT, $SERVER_SIGNATURE, $PATH_TRANSLATED, $SCRIPT_NAME; + global $REQUEST_URI; + + // php (taken from PHP doc) + global $argv, $argc, $PHP_SELF, $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $HTTP_POST_VARS; + global $HTTP_POST_FILES, $HTTP_ENV_VARS, $HTTP_SERVER_VARS, $HTTP_SESSION_VARS; + + // other + global $PATH_INFO, $HTTPS, $HTTP_RAW_POST_DATA, $HTTP_X_FORWARDED_FOR; + + if ( @file_exists($filename) ) + { + include($filename); + } + return; +} + +/** + * Checks if a certain plugin exists + * @param string $plug name of plugin + * @return boolean exists or not + */ +function checkPlugin($name) +{ + global $DIR_PLUGINS; + return file_exists($DIR_PLUGINS . preg_replace('#[\\\\|/]#', '', $name) . '.php'); +} + +/** + * alterQueryStr() + * + * @param string $querystr querystring to alter (e.g. foo=1&bar=2&x=y) + * @param string $param name of parameter to change (e.g. 'foo') + * @param string $value New value for that parameter (e.g. 3) + * @return string altered query string (for the examples above: foo=3&bar=2&x=y) + */ +function alterQueryStr($querystr, $param, $value) +{ + $vars = preg_split('#&#', $querystr); + $set = FALSE; + + for ( $i = 0; $i < count($vars); $i++ ) + { + $v = preg_split('#=#', $vars[$i]); + + if ( $v[0] == $param ) + { + $v[1] = $value; + $vars[$i] = implode('=', $v); + $set = true; + break; + } + } + if ( !$set ) + { + $vars[] = "{$param}={$value}"; + } + return ltrim(implode('&', $vars), '&'); +} + +/** + * passVar() + * passes one variable as hidden input field (multiple fields for arrays) + * @see passRequestVars in varsx.x.x.php + * + * @param string $key + * @param string $value + * @return void + */ +function passVar($key, $value) +{ + // array ? + if ( is_array($value) ) + { + for ( $i = 0; $i < sizeof($value); $i++ ) + { + passVar($key . '[' . $i . ']', $value[$i]); + } + return; + } + + // other values: do stripslashes if needed + echo '' . "\n"; + return; +} + +/** + * checkVars() + * + * @param string $variables + * @return void + */ +function checkVars($variables) +{ + foreach ( $variables as $variable ) + { + if ( array_key_exists($variable, $_GET) + || array_key_exists($variable, $_POST) + || array_key_exists($variable, $_COOKIE) + || array_key_exists($variable, $_ENV) + || (session_id() !== '' && array_key_exists($variable, $_SESSION)) + || array_key_exists($variable, $_FILES) ) + { + die('Sorry. An error occurred.'); + } + } + return; +} + +/** + * sanitizeParams() + * Sanitize parameters such as $_GET and $_SERVER['REQUEST_URI'] etc. + * to avoid XSS. + * + * @param void + * @return void + */ +function sanitizeParams() +{ + $array = array(); + $str = ''; + $frontParam = ''; + + // REQUEST_URI of $_SERVER + $str =& $_SERVER["REQUEST_URI"]; + serverStringToArray($str, $array, $frontParam); + sanitizeArray($array); + arrayToServerString($array, $frontParam, $str); + + // QUERY_STRING of $_SERVER + $str =& $_SERVER["QUERY_STRING"]; + serverStringToArray($str, $array, $frontParam); + sanitizeArray($array); + arrayToServerString($array, $frontParam, $str); + + // $_GET + convArrayForSanitizing($_GET, $array); + sanitizeArray($array); + revertArrayForSanitizing($array, $_GET); + + // $_REQUEST (only GET param) + convArrayForSanitizing($_REQUEST, $array); + sanitizeArray($array); + revertArrayForSanitizing($array, $_REQUEST); + + return; +} + +function _addInputTags(&$keys,$prefix='') +{ + foreach ( $keys as $key=>$value ) + { + if ( $prefix ) + { + $key=$prefix.'['.$key.']'; + } + if ( is_array($value) ) + { + _addInputTags($value,$key); + } + else + { + if ( get_magic_quotes_gpc() ) + {$value=stripslashes($value); + } + if ( $key == 'ticket' ) + { + continue; + } + echo ''."\n"; + } + } + return; +} + +/** + * serverStringToArray() + * Convert the server string such as $_SERVER['REQUEST_URI'] + * to arry like arry['blogid']=1 and array['page']=2 etc. + * + * @param string $uri string + * @param string &$query_elements elements of query according to application/x-www-form-urlencoded + * @param string &$hier_part hierarchical part includes path + * + * NOTE: + * RFC 3986: Uniform Resource Identifiers (URI): Generic Syntax + * 3. Syntax Components + * http://www.ietf.org/rfc/rfc3986.txt + * + * Hypertext Markup Language - 2.0 + * 8.2.1. The form-urlencoded Media Type + * http://tools.ietf.org/html/rfc1866#section-8.2.1 + * + * $_SERVER > Language Reference > Predefined Variables > PHP Manual + * http://www.php.net/manual/en/reserved.variables.server.php + */ +function serverStringToArray($uri, &$query_elements, &$hier_part) +{ + // init param + $query_elements = array(); + $hier_part = ""; + + // split hierarchical part, e.g. /index.php, query and fragment, e.g. blogid=1&page=2#section1 + if ( i18n::strpos($uri, "?") > 0 ) + { + list($hier_part, $query_and_fragment) = preg_split("#\?#", $uri, 2); + } + else + { + $query_and_fragment = $uri; + $hier_part = ''; + } + + // If there is no query like blogid=1&page=2, return + if ( i18n::strpos($uri, "=") == FALSE && !i18n::strlen($hier_part) ) + { + $hier_part = $uri; + return; + } + + $query_elements = preg_split("#&#", $query_and_fragment); + return; +} + +/** + * arrayToServerString() + * Convert array like array['blogid'] to server string + * such as $_SERVER['REQUEST_URI'] + * + * @param array $query_elements elements of query according to application/x-www-form-urlencoded + * @param string $hier_part hier-part defined in RFC3986 + * @param string &$uri return value + * @return void + * + * NOTE: + * RFC 3986: Uniform Resource Identifiers (URI): Generic Syntax + * 3. Syntax Components + * http://www.ietf.org/rfc/rfc3986.txt + * + * Hypertext Markup Language - 2.0 + * 8.2.1. The form-urlencoded Media Type + * http://tools.ietf.org/html/rfc1866#section-8.2.1 + * + * $_SERVER > Language Reference > Predefined Variables > PHP Manual + * http://www.php.net/manual/en/reserved.variables.server.php + */ +function arrayToServerString($query_elements, $hier_part, &$uri) +{ + if ( i18n::strpos($uri, "?") !== FALSE ) + { + $uri = $hier_part . "?"; + } + else + { + $uri = $hier_part; + } + if ( count($query_elements) > 0 ) + { + $uri .= implode("&", $query_elements); + } + return; +} + +/** + * sanitizeArray() + * Sanitize array parameters. + * This function checks both key and value. + * - check key if it inclues " (double quote), remove from array + * - check value if it includes \ (escape sequece), remove remaining string + * + * @param array &$array elements of query according to application/x-www-form-urlencoded + * @return void + */ +function sanitizeArray(&$array) +{ + $excludeListForSanitization = array('query'); + + foreach ( $array as $k => $v ) + { + // split to key and value + list($key, $val) = preg_split("#=#", $v, 2); + if ( !isset($val) ) + { + continue; + } + + // when magic quotes is on, need to use stripslashes, + // and then addslashes + if ( get_magic_quotes_gpc() ) + { + $val = stripslashes($val); + } + + // note that we must use addslashes here because this function is called before the db connection is made + // and sql_real_escape_string needs a db connection + $val = addslashes($val); + + // if $key is included in exclude list, skip this param + if ( !in_array($key, $excludeListForSanitization) ) + { + // check value + if ( i18n::strpos($val, '\\') > 0 ) + { + list($val, $tmp) = preg_split('#\\\\#', $val); + } + + // remove control code etc. + $val = strtr($val, "\0\r\n<>'\"", " "); + + // check key + if ( preg_match('#\"#', $key) > 0 ) + { + unset($array[$k]); + continue; + } + + // set sanitized info + $array[$k] = sprintf("%s=%s", $key, $val); + } + } + return; +} + +/** + * convArrayForSanitizing() + * Convert array for sanitizeArray function + * + * @param string $src array to be sanitized + * @param array &$array array to be temporarily stored + * @return void + */ +function convArrayForSanitizing($src, &$array) +{ + $array = array(); + foreach ( $src as $key => $val ) + { + if ( !key_exists($key, $_GET) ) + { + continue; + } + $array[] = sprintf("%s=%s", $key, $val); + continue; + } + return; +} + +/** + * revertArrayForSanitizing() + * Revert array after sanitizeArray function + * + * @param array $array element of query according to application/x-www-form-urlencoded + * @param array &$dst combination of key and value + * @return void + */ +function revertArrayForSanitizing($array, &$dst) +{ + foreach ( $array as $v ) + { + list($key, $val) = preg_split("#=#", $v, 2); + $dst[$key] = $val; + continue; + } + return; +} + +/** +>>>>>>> skinnable-master * decodePathInfo() * * @param string $virtualpath @@ -1948,6 +3787,7 @@ function decodePathInfo($virtualpath) /** +<<<<<<< HEAD * redirect() * Stops processing the request and redirects to the given URL. * - no actual contents should have been sent to the output yet @@ -2344,3 +4184,401 @@ function ticketForPlugin() $ticketforplugin['ticket'] = preg_split($ticket, i18n::strpos($ticket, 'ticket=') + 7); return; } +======= + * redirect() + * Stops processing the request and redirects to the given URL. + * - no actual contents should have been sent to the output yet + * - the URL will be stripped of illegal or dangerous characters + * + * @param string $uri + * @return void + */ +function redirect($url) +{ + $url = preg_replace('#[^a-z0-9-~+_.?\#=&;,/:@%*]#i', '', $url); + header('Location: ' . $url); + exit; +} + +/** + * getBookmarklet() + * Returns the Javascript code for a bookmarklet that works on most modern browsers + * + * @param integer $blogid ID for weblog + * @return script to call Bookmarklet + */ +function getBookmarklet($blogid, $width=600, $height=500) +{ + global $CONF; + + $script = "Q='';" + . "x=document;" + . "y=window;" + . "if ( x.selection )" + . "{" + . " Q=x.selection.createRange().text;" + . "}" + . "else if ( y.getSelection )" + . "{" + . " Q=y.getSelection();" + . "}" + . "else if ( x.getSelection )" + . "{" + . " Q=x.getSelection();" + . "}" + . "wingm = window.open('{$CONF['AdminURL']}bookmarklet.php?blogid={$blogid}" + . " &logtext=' + encodeURIComponent(Q) +" + . " '&loglink=' + encodeURIComponent(x.location.href) +" + . " '&loglinktitle=' + encodeURIComponent(x.title)," + . " 'nucleusbm'," + . " 'scrollbars=yes,width={$width},height={$height},left=10,top=10,status=yes,resizable=yes');" + . "wingm.focus();"; + + return $script; +} + +/** + * cleanFileName() + * cleans filename of uploaded file for writing to file system + * + * @param string $str + * @return string $cleaned filename ready for use + */ +function cleanFileName($str) +{ + $str = strtolower($str); + $ext_point = i18n::strrpos($str,"."); + if ( $ext_point === FALSE ) + { + return FALSE; + } + $ext = i18n::substr($str,$ext_point,i18n::strlen($str)); + $str = i18n::substr($str,0,$ext_point); + + return preg_replace("#[^a-z0-9-]#", "_", $str) . $ext; +} + +/** + * use Notification class instead of this + * Deprecated since 4.0: + */ +function getMailFooter() +{ + NOTIFICATION::get_mail_footer(); +} +function isValidMailAddress($address) +{ + return NOTIFICATION::address_validation($address); +} +/** + * use Entity class instead of this + * Deprecated since 4.0: + */ +function highlight($text, $expression, $highlight) +{ + return Entity::highlight($text, $expression, $highlight); +} +function shorten($string, $maxlength, $suffix) +{ + return Entity::shorten($string, $maxlength, $suffix); +} +function stringStripTags ($string) +{ + return Entity::strip_tags($string); +} +function toAscii($string) +{ + return Entity::anchor_footnoting($string); +} +function stringToAttribute ($string) +{ + return Entity::hsc($string); +} +function stringToXML ($string) +{ + return Entity::hen($string); +} +function encode_desc($data) +{ + return Entity::hen($data); +} +/** + * Centralisation of the functions that deals with locales + * This functions is based on the old way to deal with languages + * Deprecated since 4.0: + */ +function getLanguageName() +{ + if( ($language = i18n::convert_locale_to_old_language_file_name(i18n::get_current_locale())) === FALSE ) + { + $language ='english'; + } + return $language; +} +function selectLanguage($language) +{ + global $DIR_LANG; + include($DIR_LANG . preg_replace('#[\\\\|/]#', '', $language) . '.php'); + return; +} +/** + * use i18n class instead of these + * Deprecated since 4.0 + */ +function checkLanguage($lang) +{ + return ( preg_match('#^(.+)_(.+)_(.+)$#', $lang) + || i18n::convert_old_language_file_name_to_locale($lang) ); +} +function formatDate($format, $timestamp, $default_format, &$blog) +{ + $offset = date('Z', $timestamp); + if ( $blog ) + { + $offset += $blog->getTimeOffset() * 3600; + } + return i18n::formatted_datetime($format, $timestamp, $offset, $default_format); +} + +/** + * use DB class instead of these + * Deprecated since 4.0 + */ +function quickQuery($query) +{ + $row = DB::getRow($query); + return $row['result']; +} +function mysqldate($timestamp) +{ + return DB::formatDateTime($timestamp); + } +/** + * Centralisation of the functions that generate links + * Deprecated since 4.0: + * Please use Link::FunctionName(...) instead + */ +function createItemLink($itemid, $extra = '') +{ + return Link::create_item_link($itemid, $extra); +} +function createMemberLink($memberid, $extra = '') +{ + return Link::create_member_link($memberid, $extra); +} +function createCategoryLink($catid, $extra = '') +{ + return Link::create_category_link($catid, $extra); +} +function createArchiveListLink($blogid = '', $extra = '') +{ + return Link::create_archivelist_link($blogid, $extra); +} +function createArchiveLink($blogid, $archive, $extra = '') +{ + return Link::create_archive_link($blogid, $archive, $extra); +} +function createBlogidLink($blogid, $params = '') +{ + return Link::create_blogid_link($blogid, $params = ''); +} +function createLink($type, $params) +{ + return Link::create_link($type, $params); +} +function createBlogLink($url, $params) +{ + return Link::create_blog_link($url, $params); +} +/** + * use ActionLog class instead of this + * Deprecated since 4.0 + */ +function addToLog($level, $msg) +{ + ActionLog::add($level, $msg); +} +/** + * use PHP's implement + * Deprecated since 4.0 + */ +function ifset(&$var) +{ + if ( isset($var) ) + { + return $var; + } + + return NULL; +} +/** + * use Manager::getPluginNameFromPid() instead of this + * Deprecated since 4.0 + */ +function getPluginNameFromPid($pid) +{ + global $manager; + return $manager->getPluginNameFromPid($pid); +} +/** + * use Manager::numberOfEventSubscribers() instead of this + * Deprecated since 4.0 + */ +function numberOfEventSubscribers($event) +{ + global $manager; + return $manager->getNumberOfSubscribers($event); +} + +/** + * PluginAdmin has already the alternative implement + * Deprecated since 4.0 + */ +function ticketForPlugin() +{ + global $CONF, $DIR_LIBS, $DIR_LOCALES, $DIR_PLUGINS, $manager, $member, $ticketforplugin; + + /* initialize */ + $ticketforplugin = array(); + $ticketforplugin['ticket'] = FALSE; + + /* Check if using plugin's php file. */ + $p_translated = serverVar('SCRIPT_FILENAME'); + + if (!file_exists($p_translated) ) + { + header("HTTP/1.0 404 Not Found"); + exit(''); + } + + // check whether this is plugin or not + $p_translated = str_replace('\\', '/', $p_translated); + $d_plugins = str_replace('\\', '/', $DIR_PLUGINS); + if ( i18n::strpos($p_translated, $d_plugins) !== 0 ) + { + return; + } + + // Solve the plugin php file or admin directory + $phppath = i18n::substr($p_translated, i18n::strlen($d_plugins) ); + // Remove the first "/" if exists. + $phppath = preg_replace('#^/#', '', $phppath); + // Remove the first "NP_" and the last ".php" if exists. + $path = preg_replace('#^NP_(.*)\.php$#', '$1', $phppath); + // Remove the "/" and beyond. + $path = preg_replace('#^([^/]*)/(.*)$#', '$1', $path); + + // Solve the plugin name. + $plugins = array(); + $query = sprintf('SELECT pfile FROM %s;', sql_table('plugin')); + $res = DB::getResult($query); + + foreach ( $res as $row ) + { + $name = i18n::substr($row['pfile'], 3); + $plugins[strtolower($name)] = $name; + } + + $res->closeCursor(); + + if ( !array_key_exists($path, $plugins) ) + { + header("HTTP/1.0 404 Not Found"); + exit(''); + } + else + { + $plugin_name = $plugins[$path]; + } + + /* Return if not index.php */ + if ( ($phppath != strtolower($plugin_name) . '/') + && ($phppath != strtolower($plugin_name) . '/index.php') ) + { + return; + } + + /* Exit if not logged in. */ + if ( !$member->isLoggedIn() ) + { + exit('You aren\'t logged in.'); + } + + /* Check if this feature is needed (ie, if "$manager->checkTicket()" is not included in the script). */ + if ( $file = @file($p_translated) ) + { + $prevline = ''; + + foreach($file as $line) + { + if (preg_match('#[\$]manager([\s]*)[\-]>([\s]*)checkTicket([\s]*)[\(]#i', $prevline . $line) ) + { + return; + } + + $prevline = $line; + } + } + + /* Show a form if not valid ticket */ + if ( (i18n::strpos(serverVar('REQUEST_URI'), '?') !== FALSE + || serverVar('QUERY_STRING') + || strtoupper(serverVar('REQUEST_METHOD') ) == 'POST') + && !$manager->checkTicket() ) + { + $oPluginAdmin = new PluginAdmin($plugin_name); + $oPluginAdmin->start(); + + echo '

    ' . _ERROR_BADTICKET . "

    \n"; + + // Resolve URI and QUERY_STRING + if ($uri = serverVar('REQUEST_URI') ) + { + list($uri, $qstring) = preg_split('#\?#', $uri); + } + else + { + if ( !($uri = serverVar('PHP_SELF') ) ) + { + $uri = serverVar('SCRIPT_NAME'); + } + $qstring = serverVar('QUERY_STRING'); + } + if ($qstring) + { + $qstring = '?' . $qstring; + } + + echo '

    ' . _SETTINGS_UPDATE . ' : ' . _QMENU_PLUGINS . ' ' . Entity::hsc($plugin_name) . " ?

    \n"; + + switch(strtoupper(serverVar('REQUEST_METHOD') ) ) + { + case 'POST': + echo '
    '; + $manager->addTicketHidden(); + _addInputTags($_POST); + break; + + case 'GET': + echo ''; + $manager->addTicketHidden(); + _addInputTags($_GET); + + default: + break; + } + + echo '    '; + echo ''; + echo "
    \n"; + + $oPluginAdmin->end(); + exit; + } + + /* Create new ticket */ + $ticket=$manager->addTicketToUrl(''); + $ticketforplugin['ticket'] = preg_split($ticket, i18n::strpos($ticket, 'ticket=') + 7); + return; +} +>>>>>>> skinnable-master diff --git a/nucleus/libs/i18n.php b/nucleus/libs/i18n.php index 1b494ea..9f846df 100644 --- a/nucleus/libs/i18n.php +++ b/nucleus/libs/i18n.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD "pt_Latn_BR" ); } +======= + $value ) + { + if ( !is_array($value) ) + { + $array[$key] = self::convert($value, $from, $to); + } + else + { + self::convert_array($array[$key]); + } + } + } + + return $array; + } + + /** + * i18n::strlen + * strlen wrapper + * + * @static + * @param string $string target string + * @return integer the number of letters + */ + static public function strlen($string) + { + $length = 0; + if ( self::$mode == 'iconv' ) + { + $length = iconv_strlen($string, self::$current_charset); + } + else if ( self::$mode == 'mbstring' ) + { + $length = mb_strlen($string, self::$current_charset); + } + else + { + $length = strlen($string); + } + return (integer) $length; + } + + /** + * i18n::strpos + * strpos wrapper + * + * @static + * @param string $haystack string to search + * @param string $needle string for search + * @param integer $offset the position from which the search should be performed. + * @return integer/FALSE the numeric position of the first occurrence of needle in haystack + */ + static public function strpos($haystack, $needle, $offset=0) + { + $position = 0; + if ( self::$mode == 'iconv' ) + { + $position = iconv_strpos($haystack, $needle, $offset, self::$current_charset); + } + else if ( self::$mode == 'mbstring' ) + { + $position = mb_strpos($haystack, $needle, $offset, self::$current_charset); + } + else + { + $position = strpos($haystack, $needle, $offset); + } + + if ( $position !== FALSE) + { + $position = (integer) $position; + } + return $position; + } + + /** + * i18n::strrpos + * strrpos wrapper + * + * @static + * @param string $haystack string to search + * @param string $needle string for search + * @return integer/FALSE the numeric position of the last occurrence of needle in haystack + */ + static public function strrpos ($haystack, $needle) + { + $position = 0; + if ( self::$mode == 'iconv' ) + { + $position = iconv_strrpos($haystack, $needle, self::$current_charset); + } + else if ( self::$mode == 'mbstring' ) + { + $position = mb_strrpos($haystack, $needle, 0, self::$current_charset); + } + else + { + $position = strrpos($haystack, $needle, 0); + } + + if ( $position !== FALSE) + { + $position = (integer) $position; + } + return $position; + } + + /** + * i18n::substr + * substr wrapper + * + * @static + * @param string $string string to be cut + * @param string $start the position of starting + * @param integer $length the length to be cut + * @return string the extracted part of string + */ + static public function substr($string, $start, $length=0) + { + $return = ''; + + if ( $length == 0 ) + { + $length = self::strlen($string) - $start; + } + + if ( self::$mode == 'iconv' ) + { + $return = iconv_substr($string, $start, $length, self::$current_charset); + } + else if ( self::$mode == 'mbstring' ) + { + $return = mb_substr($string, $start, $length, self::$current_charset); + } + else + { + $return = strrpos($string, $start, $length); + } + return (string) $return; + } + + /** + * i18n::strftime + * strftime function based on multibyte processing + * + * @static + * @param string $format format with singlebyte or multibyte + * @param timestamp $timestamp UNIX timestamp + * @return string formatted timestamp + */ + static public function strftime($format, $timestamp='') + { + return preg_replace_callback('/(%[a-z%])/i', + create_function('$matches', 'return strftime($matches[1], ' . intval($timestamp) . ');'), + $format + ); + } + + /** + * i18n::formatted_datetime() + * return formatted datetime string + * + * Date and Time Formats + * @link http://www.w3.org/TR/NOTE-datetime + * + * Working with Time Zones + * @link http://www.w3.org/TR/timezone/ + * + * @param String $format time expression format + * @param String $timestamp UNIX timestamp + * @param Integer $offset timestamp offset + * @return String formatted datetime + */ + static public function formatted_datetime($format, $timestamp, $offset=0) + { + $suffix = ''; + $string = ''; + + switch ( $format ) + { + case 'mysql': + /* + * MySQL 5.0 Reference Manual + * 10.3.1. The DATE, DATETIME, and TIMESTAMP Types + * http://dev.mysql.com/doc/refman/5.0/en/datetime.html + */ + $timestamp += $offset; + $format = '%Y-%m-%d %H:%M:%S'; + $suffix =''; + break; + + case 'rfc822': + /* + * RFC 822: STANDARD FOR THE FORMAT OF ARPA INTERNET TEXT MESSAGES + * 5. DATE AND TIME SPECIFICATION + * http://www.ietf.org/rfc/rfc0822.txt + */ + $format = '%a, %d %m %y %H:%M:%S '; + if ( $offset < 0 ) + { + $suffix = '-'; + $offset = -$offset; + } + else + { + $suffix = '+'; + } + + $suffix .= sprintf("%02d%02d", floor($offset / 3600), round(($offset % 3600) / 60) ); + break; + case 'rfc822GMT': + /* + * RFC 822: STANDARD FOR THE FORMAT OF ARPA INTERNET TEXT MESSAGES + * 5. DATE AND TIME SPECIFICATION + * http://www.ietf.org/rfc/rfc0822.txt + */ + $format = '%a, %d %m %y %H:%M:%S '; + $timestamp -= $offset; + $suffix = 'GMT'; + break; + case 'iso8601': + case 'rfc3339': + /* + * RFC3339: Date and Time on the Internet: Timestamps + * 5. Date and Time format + * http://www.ietf.org/rfc/rfc3339.txt + */ + $format = '%Y-%m-%dT%H:%M:%S'; + if ( $offset < 0 ) + { + $suffix = '-'; + $offset = -$offset; + } + else + { + $suffix = '+'; + } + $suffix .= sprintf("%02d:%02d", floor($offset / 3600), round(($offset % 3600) / 60) ); + break; + case 'utc': + case 'iso8601UTC': + case 'rfc3339UTC': + /* + * RFC3339: Date and Time on the Internet: Timestamps + * 5. Date and Time format + * http://www.ietf.org/rfc/rfc3339.txt + */ + $timestamp -= $offset; + $format = '%Y-%m-%dT%H:%M:%SZ'; + $suffix = ''; + break; + case '': + $format = '%X %x'; + $offset = ''; + break; + default: + $suffix = ''; + break; + } + return i18n::strftime($format, $timestamp) . $suffix; + } + + /** + * i18n::convert_locale_to_old_language_file_name() + * NOTE: this should be obsoleted near future. + * + * @static + * @param string $target_locale locale name as language_script_region + * @return string old translation file name + */ + static public function convert_locale_to_old_language_file_name($target_locale) + { + $target_language = ''; + foreach ( self::$lang_refs as $language => $locale ) + { + if ( preg_match('#-#', $language) ) + { + if ( $target_locale . '.' . self::$current_charset == $locale ) + { + $target_language = $language; + break; + } + } + else if ( $target_locale == $locale ) + { + $target_language = $language; + } + } + return $target_language; + } + + /** + * i18n::convert_old_language_file_name_to_locale() + * NOTE: this should be obsoleted near future. + * + * @static + * @param string $target_language old translation file name + * @return string locale name as language_script_region + */ + static public function convert_old_language_file_name_to_locale($target_language) + { + $target_locale = ''; + foreach ( self::$lang_refs as $language => $locale ) + { + if ( $target_language == $language ) + { + if ( preg_match('#^(.+)\.(.+)$#', $locale, $match) ) + { + $target_locale = $match[1]; + } + else + { + $target_locale = $locale; + } + break; + } + } + return $target_locale; + } + + /** + * i18n::$lang_refs + * reference table to convert old and new way to name translation files. + * NOTE: this should be obsoleted as soon as possible. + * + * @static + */ + static private $lang_refs = array( + "english" => "en_Latn_US", + "english-utf8" => "en_Latn_US.UTF-8", + "bulgarian" => "bg_Cyrl_BG", + "finnish" => "fi_Latn_FI", + "catalan" => "ca_Latn_ES", + "french" => "fr_Latn_FR", + "russian" => "ru_Cyrl_RU", + "chinese" => "zh_Hans_CN", + "simchinese" => "zh_Hans_CN", + "chineseb5" => "zh_Hant_TW", + "traditional_chinese" => "zh_Hant_TW", + "galego" => "gl_Latn_ES", + "german" => "de_Latn_DE", + "korean-utf" => "ko_Kore_KR.UTF-8", + "korean-euc-kr" => "ko_Kore_KR.EUC-KR", + "slovak" => "sk_Latn_SK", + "czech" => "cs_Latn_CZ", + "hungarian" => "hu_Latn_HU", + "latvian" => "lv_Latn_LV", + "nederlands" => "nl_Latn_NL", + "italiano" => "it_Latn_IT", + "persian" => "fa_Arab_IR", + "spanish" => "es_Latn_ES", + "spanish-utf8" => "es_Latn_ES.UTF-8", + "japanese-euc" => "ja_Jpan_JP.EUC-JP", + "japanese-utf8" => "ja_Jpan_JP.UTF-8", + "portuguese_brazil" => "pt_Latn_BR" + ); +} +>>>>>>> skinnable-master diff --git a/nucleus/libs/include/readme.txt b/nucleus/libs/include/readme.txt deleted file mode 100644 index 65de9e2..0000000 --- a/nucleus/libs/include/readme.txt +++ /dev/null @@ -1,7 +0,0 @@ -README for the libs/include directory -------------------------------------- - -This directory contains templates used by the admin-area. -They're not really intended to be edited by the people using Nucleus (i.e. there's -no documentation and little support). But if you really can't stop yourself, -go ahead :) diff --git a/nucleus/libs/index.html b/nucleus/libs/index.html index 079e5b5..3974d80 100644 --- a/nucleus/libs/index.html +++ b/nucleus/libs/index.html @@ -1,11 +1,11 @@ - - - - Nothing Here - - - -

    Nothing to see here

    - - - + + + + Nothing Here + + + +

    Nothing to see here

    + + + \ No newline at end of file diff --git a/nucleus/libs/showlist.php b/nucleus/libs/showlist.php index 8fcbccc..a0eaba9 100644 --- a/nucleus/libs/showlist.php +++ b/nucleus/libs/showlist.php @@ -14,11 +14,16 @@ * * @license http://nucleuscms.org/license.txt GNU General Public License * @copyright Copyright (C) 2002-2009 The Nucleus Group +<<<<<<< HEAD * @version $Id: showlist.php 1785 2012-04-22 11:25:14Z sakamocchi $ +======= + * @version $Id: showlist.php 1886 2012-06-17 08:27:27Z sakamocchi $ +>>>>>>> skinnable-master */ // can take either an array of objects, or an SQL query +<<<<<<< HEAD function showlist($query, $type, $template) { if ( is_array($query) ) @@ -222,10 +227,384 @@ function listplug_table_pluginlist($template, $type) break; case 'BODY': $current = $template['current']; +======= +function showlist($query, $type, $vars, $template_name = '') +{ + $contents = ''; + + /* count */ + if ( is_string($query) ) + { + $resource = DB::getResult($query); + } + else + { + $resource = $query; + } + + /* HEAD */ + $contents .= call_user_func("listplug_{$type}", $vars, 'HEAD', $template_name); + + /* BODY */ + foreach ( $resource as $row ) + { + $vars['current'] = $row; + $contents .= call_user_func("listplug_{$type}", $vars, 'BODY', $template_name); + } + + /* FOOT */ + $contents .= call_user_func("listplug_{$type}", $vars, 'FOOT', $template_name); + + /* close SQL resource */ + if ( is_string($query) ) + { + $resource->closeCursor(); + } + + return $contents; +} + +function listplug_select($vars, $type, $template_name = '') +{ + global $manager; + + $templates = array(); + if ( !empty($template_name) ) + { + $templates =& $manager->getTemplate($template_name); + } + + switch( $type ) + { + case 'HEAD': + if ( !array_key_exists('SHOWLIST_LISTPLUG_SELECT_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_SELECT_HEAD']) ) + { + $template = "\n"; + } + else + { + $template = $templates['SHOWLIST_LISTPLUG_SELECT_FOOT']; + } + $data = array(); + break; + } + + return Template::fill($template, $data); +} + +function listplug_table($vars, $type, $template_name = '') +{ + global $manager; + + $templates = array(); + if ( !empty($template_name) ) + { + $templates =& $manager->getTemplate($template_name); + } + + switch( $type ) + { + case 'HEAD': + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_HEAD']) ) + { + $template = "\n" + . "\n" + . "\n" + . "<%typehead%>\n" + . "\n" + . "\n" + . "\n"; + } + else + { + $template = $templates['SHOWLIST_LISTPLUG_TABLE_HEAD']; + } + $data = array( + 'summary' => $vars['content'], + 'typehead' => call_user_func("listplug_table_" . $vars['content'] , $vars, 'HEAD', $template_name) + ); + break; + case 'BODY': + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_BODY']) ) + { + $template = "\n" + . "<%typebody%>\n" + . "\n"; + } + else + { + $template = $templates['SHOWLIST_LISTPLUG_TABLE_BODY']; + } + // tabletype specific thingies + $data = array( + 'typebody' => call_user_func("listplug_table_" . $vars['content'] , $vars, 'BODY', $template_name) + ); + break; + case 'FOOT': + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_FOOT']) ) + { + $template = "<%typefoot%>\n" + . "\n" + . "
    \n"; + } + else + { + $template = $templates['SHOWLIST_LISTPLUG_TABLE_FOOT']; + } + // tabletype specific thingies + $data = array( + 'typefoot' => call_user_func("listplug_table_" . $vars['content'] , $vars, 'FOOT', $template_name) + ); + break; + } + + return Template::fill($template, $data); +} + +function listplug_table_memberlist($vars, $type, $template_name = '') +{ + global $manager; + + $templates = array(); + if ( !empty($template_name) ) + { + $templates =& $manager->getTemplate($template_name); + } + + switch( $type ) + { + case 'HEAD': + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_MEMBLIST_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_MEMBLIST_HEAD']) ) + { + $template = "<%colmembername%>\n" + . "<%colmemberrname%>\n" + . "<%colmemberurl%>\n" + . "<%colmemberadmin%><%helplink(superadmin)%>\n" + . "<%colmemberlogin%><%helplink(canlogin)%>\n" + . "<%colactions%>\n"; + } + else + { + $template = $templates['SHOWLIST_LISTPLUG_TABLE_MEMBLIST_HEAD']; + } + $data = array( + 'colmembername' => _LIST_MEMBER_NAME, + 'colmemberrname' => _LIST_MEMBER_RNAME, + 'colmemberurl' => _LIST_MEMBER_URL, + 'colmemberadmin' => _LIST_MEMBER_ADMIN, + 'colmemberlogin' => _LIST_MEMBER_LOGIN, + 'colactions' => _LISTS_ACTIONS, + ); + break; + case 'BODY': + $current = $vars['current']; + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_MEMBLIST_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_MEMBLIST_BODY']) ) + { + $template = "\n" + . "\" name=\"batch[<%id%>]\" value=\"<%memberid%>\" />\n" + . "
    \" tabindex=\"<%tabindex%>\"><%name%>\n" + . "\n\n" + . "<%realname%>\n" + . "\" tabindex=\"<%tabindex%>\"><%url%>\n" + . "<%admin%>\n" + . "<%login%>\n" + . "\" tabindex=\"<%tabindex%>\"><%editbtn%>\n" + . "\" tabindex=\"<%tabindex%>\"><%deletebtn%>\n"; + } + else + { + $template = $templates['SHOWLIST_LISTPLUG_TABLE_MEMBLIST_BODY']; + } + $data = array( + 'id' => listplug_nextBatchId(), + 'memberid' => $current['mnumber'], + 'mailaddress' => Entity::hsc($current['memail']), + 'tabindex' => $vars['tabindex'], + 'name' => Entity::hsc($current['mname']), + 'realname' => Entity::hsc($current['mrealname']), + 'url' => Entity::hsc($current['murl']), + 'admin' => $current['madmin'] ? _YES : _NO, + 'login' => $current['mcanlogin'] ? _YES : _NO, + 'editbtn' => _LISTS_EDIT, + 'deletebtn' => _LISTS_DELETE, + ); + break; + case 'FOOT': + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_MEMBLIST_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_MEMBLIST_FOOT']) ) + { + $template = ""; + } + else + { + $template = $templates['SHOWLIST_LISTPLUG_TABLE_MEMBLIST_FOOT']; + } + $data = array(); + break; + } + return Template::fill($template, $data); +} + +function listplug_table_teamlist($vars, $type, $template_name = '') +{ + global $manager; + + $templates = array(); + if ( !empty($template_name) ) + { + $templates =& $manager->getTemplate($template_name); + } + + switch( $type ) + { + case 'HEAD': + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_TEAMLIST_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_TEAMLIST_HEAD']) ) + { + $template = "<%colmembername%>\n" + . "<%colmemberrname%>\n" + . "<%colteamadmin%><%helplink(teamadmin)%>\n" + . "<%colactions%>\n"; + } + else + { + $template = $templates['SHOWLIST_LISTPLUG_TABLE_TEAMLIST_HEAD']; + } + $data = array( + 'colmembername' => _LIST_MEMBER_NAME, + 'colmemberrname' => _LIST_MEMBER_RNAME, + 'colteamadmin' => _LIST_TEAM_ADMIN, + 'colactions' => _LISTS_ACTIONS, + ); + break; + case 'BODY': + $current = $vars['current']; + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_TEAMLIST_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_TEAMLIST_BODY']) ) + { + $template = "\n" + . "\" name=\"batch[<%id%>]\" value=\"<%memberid%>\" />\n" + . "\n\n" + . "<%realname%>\n" + . "<%admin%>\n" + . "&blogid=<%blogid%>\" tabindex=\"<%tabindex%>\"><%deletebtn%>\n" + . "\" tabindex=\"<%tabindex%>\"><%chadminbtn%>\n"; + } + else + { + $template = $templates['SHOWLIST_LISTPLUG_TABLE_TEAMLIST_BODY']; + } + $url = 'index.php?action=teamchangeadmin&memberid=' . intval($current['tmember']) . '&blogid=' . intval($current['tblog']); + $url = $manager->addTicketToUrl($url); + $data = array( + 'id' => listplug_nextBatchId(), + 'memberid' => $current['tmember'], + 'mailaddress' => Entity::hsc($current['memail']), + 'tabindex' => $vars['tabindex'], + 'name' => Entity::hsc($current['mname']), + 'realname' => Entity::hsc($current['mrealname']), + 'admin' => ($current['tadmin'] ? _YES : _NO), + 'blogid' => $current['tblog'], + 'deletebtn' => '<%text(_LISTS_DELETE)%>', + 'chadminurl' => Entity::hsc($url), + 'chadminbtn' => '<%text(_LIST_TEAM_CHADMIN)%>' + ); + break; + case 'FOOT': + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_TEAMLIST_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_TEAMLIST_FOOT']) ) + { + $template = ""; + } + else + { + $template = $templates['SHOWLIST_LISTPLUG_TABLE_TEAMLIST_FOOT']; + } + $data = array(); + break; + } + return Template::fill($template, $data); +} + +function listplug_table_pluginlist($vars, $type, $template_name = '') +{ + static $plugins = array(); + global $manager; + + $templates = array(); + if ( !empty($template_name) ) + { + $templates =& $manager->getTemplate($template_name); + } + + switch( $type ) + { + case 'HEAD': + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HEAD']) ) + { + $template = "<%colinfo%>\n" + . "<%coldesc%>\n" + . "<%colactions%>\n"; + } + else + { + $template = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HEAD']; + } + $data = array( + 'colinfo' => _LISTS_INFO, + 'coldesc' => _LISTS_DESC, + 'colactions' => _LISTS_ACTIONS, + ); + break; + case 'BODY': + $current = $vars['current']; +>>>>>>> skinnable-master $plug =& $manager->getPlugin($current['pfile']); if ( $plug ) { +<<<<<<< HEAD echo "\n"; echo '

    ' . Entity::hsc($plug->getName()) . "

    \n"; @@ -272,6 +651,127 @@ function listplug_table_pluginlist($template, $type) foreach ( $res as $row ) { $preq =& $manager->getPlugin($row['pfile']); +======= + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_BODY']) ) + { + $template = "\n" + . "<%plugname%>
    \n" + . "<%autherlabel%> <%plugauther%>
    \n" + . "<%versionlabel%> <%plugversion%>
    \n" + . "<%pluggeturl%>
    \n" + . "\n" + . "\n" + . "<%desclabel%>
    <%plugdesc%>\n" + . "<%eventlist%>\n" + . "<%needupdate%>\n" + . "<%dependlist%>\n" + . "<%depreqlist%>\n" + . "\n"; + } + else + { + $template = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_BODY']; + } + $data = array( + 'plugname' => Entity::hsc($plug->getName()), + 'autherlabel' => _LIST_PLUGS_AUTHOR, + 'plugauther' => Entity::hsc($plug->getAuthor()), + 'versionlabel' => _LIST_PLUGS_VER, + 'plugversion' => Entity::hsc($plug->getVersion()), + 'tabindex' => $vars['tabindex'], + 'desclabel' => _LIST_PLUGS_DESC, + 'plugdesc' => Entity::hen($plug->getDescription()), + ); + if ( $plug->getURL() ) + { + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_GURL', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_GURL']) ) + { + $subTpl = "\" tabindex=\"<%tabindex%>\"><%plugsite%>"; + } + else + { + $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_GURL']; + } + $subData = array( + 'plugurl' => Entity::hsc($plug->getURL()), + 'tabindex' => $vars['tabindex'], + 'plugsite' => _LIST_PLUGS_SITE, + ); + $data['pluggeturl'] = Template::fill($subTpl, $subData); + } + else + { + $data['pluggeturl'] = ''; + } + if ( count($plug->getEventList()) > 0 ) + { + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLUGEVENTLIST', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGEVENTLIST']) ) + { + $subTpl = "

    <%evntlstlbl%>
    <%eventlist%>"; + } + else + { + $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGEVENTLIST']; + } + $subData = array( + 'evntlstlbl' => _LIST_PLUGS_SUBS, + 'eventlist' => Entity::hsc(implode(', ', $plug->getEventList())), + ); + $data['eventlist'] = Template::fill($subTpl, $subData); + } + else + { + $data['eventlist'] = ''; + } + if ( !$plug->subscribtionListIsUptodate() ) + { + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLUGNEDUPDATE', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGNEDUPDATE']) ) + { + $subTpl = "

    <%updatealert%>"; + } + else + { + $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGNEDUPDATE']; + } + $subData = array( + 'updatealert' => _LIST_PLUG_SUBS_NEEDUPDATE, + ); + $data['needupdate'] = Template::fill($subTpl, $subData); + } + else + { + $data['needupdate'] = ''; + } + if ( count($plug->getPluginDep() ) > 0) + { + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPEND', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPEND']) ) + { + $subTpl = "

    <%deplistlbl%>
    <%dependlist%>"; + } + else + { + $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPEND']; + } + $subData = array( + 'deplistlbl' => _LIST_PLUGS_DEP, + 'dependlist' => Entity::hsc(implode(', ', $plug->getPluginDep())), + ); + $data['dependlist'] = Template::fill($subTpl, $subData); + } + else + { + $data['dependlist'] = ''; + } + /* check dependency */ + if ( empty($plugins) ) + { + $plugins = DB::getResult('SELECT pfile FROM ' . sql_table('plugin')); + } + $req = array(); + foreach ( $plugins as $plugin ) + { + $preq =& $manager->getPlugin($plugin['pfile']); +>>>>>>> skinnable-master if ( $preq ) { $depList = $preq->getPluginDep(); @@ -279,7 +779,11 @@ function listplug_table_pluginlist($template, $type) { if ( $current['pfile'] == $depName ) { +<<<<<<< HEAD $req[] = $row['pfile']; +======= + $req[] = $plugin['pfile']; +>>>>>>> skinnable-master } } } @@ -287,6 +791,7 @@ function listplug_table_pluginlist($template, $type) if ( count($req) > 0 ) { +<<<<<<< HEAD echo '
    ' . _LIST_PLUGS_DEPREQ . "
    \n"; echo '
    ' . Entity::hsc(implode(', ', $req)) . "
    \n"; } @@ -367,45 +872,261 @@ function listplug_table_plugoptionlist($template, $type) function listplug_plugOptionRow($current) { - $varname = "plugoption[{$current['oid']}][{$current['contextid']}]"; - - // retreive the optionmeta - $meta = NucleusPlugin::getOptionMeta($current['typeinfo']); - - // only if it is not a hidden option write the controls to the page - if ( in_array('access', $meta) && $meta['access'] == 'hidden' ) - { - return; - } - - if ( !$current['description'] ) - { - echo '' , Entity::hsc($current['name']) . "\n"; - } - else - { - if ( !defined($current['description']) ) - { - echo '' , Entity::hsc($current['description']) . "\n"; - } - else - { - echo '' , Entity::hsc(constant($current['description'])) . "\n"; - } - } - echo "\n"; - switch($current['type']) - { - case 'yesno': - Admin::input_yesno($varname, $current['value'], 0, 'yes', 'no'); - break; - case 'password': - echo '\n"; - break; - case 'select': - echo '\" />\n" + . "\n"; + } + else + { + $template = $templates['SHOWLIST_LISTPLUG_TABLE_POPTLIST_FOOT']; + } + $data = array( + 'savetext' => _PLUGS_SAVE, + ); + break; + } + + return Template::fill($template, $data); +} + +function listplug_plugOptionRow($current, $template_name = '') +{ + global $manager; + + $templates = array(); + if ( !empty($template_name) ) + { + $templates =& $manager->getTemplate($template_name); + } + +>>>>>>> skinnable-master + $varname = "plugoption[{$current['oid']}][{$current['contextid']}]"; + + // retreive the optionmeta + $meta = NucleusPlugin::getOptionMeta($current['typeinfo']); + + // only if it is not a hidden option write the controls to the page + if ( in_array('access', $meta) && $meta['access'] == 'hidden' ) + { +<<<<<<< HEAD + return; + } + + if ( !$current['description'] ) + { + echo '' , Entity::hsc($current['name']) . "\n"; + } + else + { + if ( !defined($current['description']) ) + { + echo '' , Entity::hsc($current['description']) . "\n"; + } + else + { + echo '' , Entity::hsc(constant($current['description'])) . "\n"; + } + } + echo "\n"; + switch($current['type']) + { + case 'yesno': + Admin::input_yesno($varname, $current['value'], 0, 'yes', 'no'); + break; + case 'password': + echo '\n"; + break; + case 'select': + echo '\n"; - echo "\n"; - echo "\n"; - - $current['ibody'] = strip_tags($current['ibody']); - $current['ibody'] = Entity::hsc(Entity::shorten($current['ibody'], 300, '...')); - echo "

    {$current['ibody']}

    \n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - break; +======= + return false; } - return; -} - -// for batch operations: generates the index numbers for checkboxes -function listplug_nextBatchId() -{ - static $id = 0; - return $id++; -} - -function listplug_table_commentlist($template, $type) -{ - switch( $type ) + else { - case 'HEAD': - echo '' . _LISTS_INFO . "\n"; - echo '' . _LIST_COMMENT . "\n"; - echo '' . _LISTS_ACTIONS . ""; - break; - case 'BODY': - $current = $template['current']; - $current['ctime'] = strtotime($current['ctime']); // string -> unix timestamp - - echo "\n"; - echo "
      \n"; - echo '
    • ' . date("Y-m-d@H:i",$current['ctime']) . "
    • \n"; - if ( isset($current['mname']) ) - { - echo '
    • ' . Entity::hsc($current['mname']) ,' ', _LIST_COMMENTS_MEMBER . "
    • \n"; - } - else - { - echo '
    • ' . Entity::hsc($current['cuser']) . "
    • \n"; - } - if ( isset($current['cmail']) && $current['cmail'] ) - { - echo '
    • ' . Entity::hsc($current['cmail']) . "
    • \n"; - } - if ( isset($current['cemail']) && $current['cemail'] ) - { - echo '
    • ' . Entity::hsc($current['cemail']) . "
    • \n"; + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_POPTLIST_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_POPTLIST_BODY']) ) + { + $template = "<%description%>\n" + . "\n"; + } + else + { + $template = $templates['SHOWLIST_LISTPLUG_TABLE_POPTLIST_BODY']; + } + + $data = array(); + + switch($current['type']) + { + case 'yesno': + $template .= listplug_input_yesno($varname, $current['value'], 0, 'yes', 'no', _YES, _NO, 0, $template_name, 1); + break; + case 'password': + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OPWORD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OPWORD']) ) + { + $template .= "\" value=\"<%value%>\" />\n"; + } + else + { + $template .= $templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OPWORD']; + } + $data = array( + 'varname' => Entity::hsc($varname), + 'value' => Entity::hsc($current['value']), + ); + break; + case 'select': + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEP', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEP']) ) + { + $template .= "\n"; + } + else + { + $template .= $templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEC']; + } + $data['varname'] = Entity::hsc($varname); + break; + case 'textarea': + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OTAREA', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OTAREA']) ) + { + $template .= "\n"; + } + else + { + $template .= $templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OTAREA']; + } + $data = array( + 'varname' => Entity::hsc($varname), + 'value' => Entity::hsc($current['value']) + ); + if ( !array_key_exists('access', $current) || $current['access'] != 'readonly') + { + $data['readonly'] = ''; + } + else + { + $data['readonly'] = ' readonly="readonly"'; + } + break; + case 'text': + default: + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OITEXT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OITEXT']) ) + { + $template .= "\" value=\"<%value%>\"<%datatype%><%readonly%> />\n"; + } + else + { + $template .= $templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OITEXT']; + } + $data = array( + 'varname' => Entity::hsc($varname), + 'value' => Entity::hsc($current['value']) + ); + if ( !array_key_exists('datatype', $current) || $current['datatype'] != 'numerical') + { + $data['datatype'] = ''; + } + else + { + $data['datatype'] = ' onkeyup="checkNumeric(this)" onblur="checkNumeric(this)"'; + } + if ( !array_key_exists('access', $current) || $current['access'] != 'readonly') + { + $data['readonly'] = ''; + } + else + { + $data['readonly'] = ' readonly="readonly"'; + } + } + + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLUGOPTN_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGOPTN_FOOT']) ) + { + $template .= "<%extra%>\n"; + } + else + { + $template .= $templates['SHOWLIST_LISTPLUG_TABLE_PLUGOPTN_FOOT']; + } + + if ( !array_key_exists('extra', $current) ) + { + $data['extra'] = ''; + } + else + { + $data['extra'] = Entity::hsc($current['extra']); + } + + if ( !array_key_exists('description', $current) ) + { + $data['description'] = Entity::hsc($current['name']); + } + else if ( !defined($current['description']) ) + { + $data['description'] = Entity::hsc($current['description']); + } + else + { + $data['description'] = Entity::hsc(constant($current['description'])); + } + } + return Template::fill($template, $data, 1); +} + +/** + * listplug_templateEditRow() + * + * @param array $content content of target template + * @param string $desc description of target template + * @param string $name name of target template + * @param string $help help text + * @param integer $tabindex a number for tab index + * @param boolean $big large or small textarea + * @param array $template_name name of template for filling + * @return void + */ +function listplug_templateEditRow($content, $desc, $name, $help = '', $tabindex = 0, $big = 0, $template_name = '') +{ + global $manager; + + static $count = 0; + + $tmplt = array(); + $base = array(); + + $templates = array(); + if ( $template_name ) + { + $templates =& $manager->getTemplate($template_name); + } + + $data = array( + 'description' => $desc, + 'help' => empty($help) ? '' : helpHtml('template' . $help), + 'count' => $count++, + 'name' => $name, + 'tabindex' => $tabindex, + 'rows' => $big ? 10 : 5, + ); + + $message = ''; + + /* row head */ + if ( !array_key_exists('TEMPLATE_EDIT_ROW_HEAD', $templates) || empty($tmplt['TEMPLATE_EDIT_ROW_HEAD']) ) + { + $template = "\n" + . "<%description%><%help%>\n" + . "\">\n" + . "\n" + . "\n" + . "\n"; + } + else + { + $template = $tmplt['TEMPLATE_EDIT_ROW_TAIL']; + } + $message .= TEMPLATE::fill($template, $data); + + return $message; +} + +function listplug_table_itemlist($vars, $type, $template_name = '') +{ + global $manager; + + $cssclass = ''; + + $templates = array(); + if ( !empty($template_name) ) + { + $templates =& $manager->getTemplate($template_name); + } +>>>>>>> skinnable-master + + switch( $type ) + { + case 'HEAD': +<<<<<<< HEAD + echo ""._LIST_ITEM_INFO."\n"; + echo ""._LIST_ITEM_CONTENT."\n"; + echo ""._LISTS_ACTIONS.""; + break; + case 'BODY': + $current = $template['current']; + // string -> unix timestamp + $current['itime'] = strtotime($current['itime']); + + if ( $current['idraft'] == 1 ) + { + $cssclass = " class='draft'"; + } + + // (can't use offset time since offsets might vary between blogs) + if ( $current['itime'] > $template['now'] ) + { + $cssclass = " class='future'"; + } + + echo "\n"; + echo "
      \n"; + echo '
      ' . _LIST_ITEM_BLOG . "
      \n"; + echo '
      ' . Entity::hsc($current['bshortname']) . "
      \n"; + echo '
      ' . _LIST_ITEM_CAT . "
      \n"; + echo '
      ' . Entity::hsc($current['cname']) . "
      \n"; + echo '
      ' . _LIST_ITEM_AUTHOR . "
      \n"; + echo '
      ' . Entity::hsc($current['mname']) . "
      \n"; + echo '
      ' . _LIST_ITEM_DATE . "
      \n"; + echo '
      ' . date("Y-m-d",$current['itime']) . "
      \n"; + echo '
      ' . _LIST_ITEM_TIME . "
      \n"; + echo '
      ' . date("H:i",$current['itime']) . "
      \n"; + echo "
      \n"; + echo "\n"; + + $id = listplug_nextBatchId(); + + echo "\n"; + echo "

      \n"; + echo "\n"; + echo "\n"; + echo "

      \n"; + + $current['ibody'] = strip_tags($current['ibody']); + $current['ibody'] = Entity::hsc(Entity::shorten($current['ibody'], 300, '...')); + echo "

      {$current['ibody']}

      \n"; + echo "\n"; + + echo "\n"; + echo "\n"; echo "\n"; + break; + } + return; +======= + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_ITEMLIST_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_ITEMLIST_HEAD']) ) + { + $template = "<%colinfo%>\n" + . "<%colcontent%>\n" + . "<%colaction%>\n"; + } + else + { + $template = $templates['SHOWLIST_LISTPLUG_TABLE_ITEMLIST_HEAD']; + } + $data = array( + 'colinfo' => _LIST_ITEM_INFO, + 'colcontent' => _LIST_ITEM_CONTENT, + 'colaction' => _LISTS_ACTIONS + ); + break; + case 'BODY': + $current = $vars['current']; + // string -> unix timestamp + $current['itime'] = strtotime($current['itime']); + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_ITEMLIST_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_ITEMLIST_BODY']) ) + { + $template = ">\n" + . "<%bshortlabel%> <%bshortnameval%>
      \n" + . "<%categorylabel%> <%categorynameval%>
      \n" + . "<%authorlabel%> <%authornameval%>
      \n" + . "<%itemdatelabel%> <%itemdateval%>
      \n" + . "<%itemtimelabel%> <%itemtimeval%>\n" + . "\n" + . ">\n" + . "\" name=\"batch[<%batchid%>]\" value=\"<%itemid%>\" />\n" + . "
      \n" + . "<%itembody%>\n" + . "\n" + . ">\n" + . "\"><%editbtn%>
      \n" + . "\"><%movebtn%>
      \n" + . "\"><%delbtn%>
      \n" + . "<%camount%>\n" + . "\n"; + } + else + { + $template = $templates['SHOWLIST_LISTPLUG_TABLE_ITEMLIST_BODY']; + } + $cssclass = ''; + + if ( $current['idraft'] == 1 ) + { + $cssclass = ' class="draft"'; + } + + // (can't use offset time since offsets might vary between blogs) + if ( $current['itime'] > $vars['now'] ) + { + $cssclass = ' class="future"'; + } + $body = strip_tags($current['ibody']); + $data = array( + 'cssclass' => $cssclass, + 'bshortlabel' => _LIST_ITEM_BLOG, + 'bshortnameval' => Entity::hsc($current['bshortname']), + 'categorylabel' => _LIST_ITEM_CAT, + 'categorynameval' => Entity::hsc($current['cname']), + 'authorlabel' => _LIST_ITEM_AUTHOR, + 'authornameval' => Entity::hsc($current['mname']), + 'itemdatelabel' => _LIST_ITEM_DATE, + 'itemdateval' => date("Y-m-d",$current['itime']), + 'itemdatelabel' => _LIST_ITEM_TIME, + 'itemdateval' => date("H:i",$current['itime']), + 'batchid' => listplug_nextBatchId(), + 'itemid' => $current['inumber'], + 'itemtitle' => Entity::hsc(strip_tags($current['ititle'])), + 'itembody' => Entity::hsc(Entity::shorten($body, 300, '...')), + 'editbtn' => _LISTS_EDIT, + 'movebtn' => _LISTS_MOVE, + 'delbtn' => _LISTS_DELETE, + ); + // evaluate amount of comments for the item + $comment = new Comments($current['inumber']); + $camount = $comment->amountComments(); + if ( $camount > 0 ) + { + $data['camount'] = "(" . sprintf(_LIST_ITEM_COMMENTS, $comment->amountComments()) . ")
      \n"; + } + else + { + $data['camount'] = _LIST_ITEM_NOCONTENT . "
      \n"; + } + break; + case 'FOOT': + if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_ITEMLIST_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_ITEMLIST_FOOT']) ) + { + $template = "\n"; + } + else + { + $template = $templates['SHOWLIST_LISTPLUG_TABLE_ITEMLIST_FOOT']; + } + $data = array(); + break; + } + return Template::fill($template, $data); +>>>>>>> skinnable-master +} - $id = listplug_nextBatchId(); +// for batch operations: generates the index numbers for checkboxes +function listplug_nextBatchId() +{ + static $id = 0; + return $id++; +} + +<<<<<<< HEAD +function listplug_table_commentlist($template, $type) +{ + switch( $type ) + { + case 'HEAD': + echo '' . _LISTS_INFO . "\n"; + echo '' . _LIST_COMMENT . "\n"; + echo '' . _LISTS_ACTIONS . ""; + break; + case 'BODY': + $current = $template['current']; + $current['ctime'] = strtotime($current['ctime']); // string -> unix timestamp - echo ''; - echo "\n"; - echo "