From 6a7696ebb4c9db74ed3298ef2af1e43822b2424a Mon Sep 17 00:00:00 2001 From: emanuele Date: Thu, 14 Mar 2013 16:37:42 +0100 Subject: [PATCH 1/3] Added template for selection of boards by checks instead of ids Signed-off-by: emanuele --- PrivateTopics.english.php | 4 +-- PrivateTopics.php | 37 ++++++++++++++++++++------- PrivateTopics.template.php | 51 ++++++++++++++++++++++++++++++++++++++ package-info.xml | 2 ++ 4 files changed, 83 insertions(+), 11 deletions(-) create mode 100644 PrivateTopics.template.php diff --git a/PrivateTopics.english.php b/PrivateTopics.english.php index e27eb3b..49c7fdc 100644 --- a/PrivateTopics.english.php +++ b/PrivateTopics.english.php @@ -36,8 +36,8 @@ $txt['PrivateTopics_panel_desc'] = 'From Here you can set up the Private Topics Settings'; $txt['PrivateTopics_enable'] = 'Enable the Private Topics mod'; $txt['PrivateTopics_enable_sub'] = 'This is the master setting, needs ot be on for the mod to work properly.'; -$txt['PrivateTopics_boards'] = 'Put the Board IDs where you want to use topics as private.'; -$txt['PrivateTopics_boards_sub'] = 'Comma separate, for example: 1,2,3,4'; +$txt['PrivateTopics_boards'] = 'Boards where you want to use topics as private'; +$txt['PrivateTopics_select_boards'] = 'Select the boards'; $txt['PrivateTopics_redirect'] = 'I\'m sorry, you aren\'t allowed to see this topic.'; $txt['PrivateTopics_redirect_message'] = 'This message belongs to a private topic.'; $txt['PrivateTopics_boardindex_message'] = 'Set a custom text for the Board and MessageIndex last topic cell'; diff --git a/PrivateTopics.php b/PrivateTopics.php index 319dcf5..d8af9e8 100644 --- a/PrivateTopics.php +++ b/PrivateTopics.php @@ -148,8 +148,7 @@ public function doBoard($board) $check = $temp->getSetting('boards'); if (!empty($check)) - $array = explode(',', $check); - + $array = unserialize($check); else $array = array(); @@ -217,7 +216,7 @@ public static function handler($return_config = false) public static function settings($return_config = false) { - global $txt, $scripturl, $context, $sourcedir; + global $txt, $scripturl, $context, $sourcedir, $smcFunc, $modSettings; /* I can has Adminz? */ isAllowedTo('admin_forum'); @@ -225,10 +224,30 @@ public static function settings($return_config = false) $tools = self::doTools(); require_once($sourcedir . '/ManageServer.php'); + loadTemplate('PrivateTopics'); + loadLanguage('ManageMembers'); + + $selected_board = unserialize($tools->getSetting('boards') ? $tools->getSetting('boards') : serialize(array())); + $context['boards'] = array(); + $result = $smcFunc['db_query']('', ' + SELECT id_board, name, child_level + FROM {db_prefix}boards + ORDER BY board_order', + array( + ) + ); + while ($row = $smcFunc['db_fetch_assoc']($result)) + $context['boards'][$row['id_board']] = array( + 'id' => $row['id_board'], + 'name' => $row['name'], + 'child_level' => $row['child_level'], + 'selected' => in_array($row['id_board'], $selected_board) + ); + $smcFunc['db_free_result']($result); $config_vars = array( array('check', self::$name .'_enable', 'subtext' => $tools->getText('enable_sub')), - array('text', self::$name .'_boards', 'size' => 10, 'subtext' => $tools->getText('boards_sub')), + array('callback', self::$name .'_boards', 'subtext' => $tools->getText('boards_sub')), array('text', self::$name .'_boardindex_message', 'size' => 70, 'subtext' => $tools->getText('boardindex_message_sub')), ); @@ -248,13 +267,13 @@ public static function settings($return_config = false) /* Clean the boards var, we only want integers and nothing else! */ if (!empty($_POST['PrivateTopics_boards'])) { - $PrivateTopics_boards = explode(',', preg_replace('/[^0-9,]/', '', $_POST['PrivateTopics_boards'])); + $save_board = array(); - foreach ($PrivateTopics_boards as $key => $value) - if ($value == '') - unset($PrivateTopics_boards[$key]); + foreach ($_POST['PrivateTopics_boards'] as $key => $value) + if (isset($context['boards'][$value])) + $save_board[] = $value; - $_POST['PrivateTopics_boards'] = implode(',', $PrivateTopics_boards); + updateSettings(array('PrivateTopics_boards' => serialize($save_board))); } saveDBSettings($config_vars); diff --git a/PrivateTopics.template.php b/PrivateTopics.template.php new file mode 100644 index 0000000..d6ba9a0 --- /dev/null +++ b/PrivateTopics.template.php @@ -0,0 +1,51 @@ + + * @copyright 2012, 2013 Jessica González + * @license http://www.mozilla.org/MPL/ MPL 2.0 + * + * @version 1.0 + */ + +/* + * Version: MPL 2.0 + * + * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. + * If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + */ + +function template_callback_PrivateTopics_boards() +{ + global $context, $txt; + if (!empty($context['boards'])) + { + echo ' +
+ ', $txt['PrivateTopics_boards'], ': +
+
+
+ ', $txt['PrivateTopics_select_boards'], ''; + foreach ($context['boards'] as $board) + echo ' +
'; + + echo ' +
+ +
+
'; + } +} \ No newline at end of file diff --git a/package-info.xml b/package-info.xml index bfacf07..5c216d1 100644 --- a/package-info.xml +++ b/package-info.xml @@ -15,6 +15,7 @@ source source lang + theme @@ -24,5 +25,6 @@ PrivateTopics.xml + \ No newline at end of file From 30d22c82702fd3c31e0b527b318a64227df57cf9 Mon Sep 17 00:00:00 2001 From: emanuele Date: Thu, 14 Mar 2013 16:34:29 +0100 Subject: [PATCH 2/3] Improved autosuggest Signed-off-by: emanuele --- PrivateTopics.english.php | 3 +-- PrivateTopics.php | 53 +++++++++++++++++++++++---------------- PrivateTopics.xml | 32 +++++++++++++++++------ 3 files changed, 57 insertions(+), 31 deletions(-) diff --git a/PrivateTopics.english.php b/PrivateTopics.english.php index 49c7fdc..f44e4f8 100644 --- a/PrivateTopics.english.php +++ b/PrivateTopics.english.php @@ -52,8 +52,7 @@ $txt['permissionname_PrivateTopics_title'] = 'Private Topics'; /* Post strings */ -$txt['PrivateTopics_post_message'] = 'Type the user ID'; -$txt['PrivateTopics_post_example'] = 'Use commas, example: 1,2,3,4'; +$txt['PrivateTopics_post_message'] = 'Users allowed to see the topic:'; $txt['PrivateTopics_post_enable'] = 'Mark as private topic'; /* Send pm */ diff --git a/PrivateTopics.php b/PrivateTopics.php index d8af9e8..754b5a7 100644 --- a/PrivateTopics.php +++ b/PrivateTopics.php @@ -60,17 +60,21 @@ public function doSave($topic) $this->_topic = $topic; + $save = array(); + foreach ($this->_users as $user) + $save[] = array( + $this->_topic, + $user, + ); + $smcFunc['db_insert']('replace', '{db_prefix}private_topics', array( 'topic_id' => 'int', - 'users' => 'string' + 'user' => 'int' ), - array( - $this->_topic, - $this->_users - ), - array('topic_id') + $save, + array('topic_id', 'user') ); } @@ -82,14 +86,14 @@ public function doUpdate($id) cache_put_data(self::$name .':'. $id, '', 120); $smcFunc['db_query']('', ' - UPDATE {db_prefix}private_topics - SET users = {string:users} + DELETE FROM {db_prefix}private_topics WHERE topic_id = {int:topic_id}', array( - 'topic_id' => $id, - 'users' => $this->_users + 'topic_id' => $id ) ); + + $this->doSave($id); } public function doGet() @@ -102,27 +106,32 @@ public function doGet() if (($this->_return = cache_get_data(self::$name .':'. $this->_topic, 120)) == null) { $this->_request = $smcFunc['db_query']('', ' - SELECT users, topic_id - FROM {db_prefix}private_topics - WHERE topic_id = {int:topic} - LIMIT 1', + SELECT pt.user, pt.topic_id, mem.real_name + FROM {db_prefix}private_topics as pt + LEFT JOIN {db_prefix}members as mem ON (pt.user = mem.id_member) + WHERE topic_id = {int:topic}', array( 'topic' => $this->_topic, ) ); - $temp = $smcFunc['db_fetch_assoc']($this->_request); + $temp = array(); + while ($row = $smcFunc['db_fetch_assoc']($this->_request)) + { + if (!empty($row['real_name'])) + $temp[$row['user']] = $row['real_name']; + + } - if (!empty($temp)) - $this->_return = explode(',', $temp['users']); + $smcFunc['db_free_result']($this->_request); + if (!empty($temp)) + $this->_return = $temp; else - $this->_return = 'no'; - - /* Cache this beauty */ - cache_put_data(self::$name .':'. $this->_topic, $this->_return, 120); + $this->_return = false; - $smcFunc['db_free_result']($this->_request); + /* Cache this beauty */ + cache_put_data(self::$name .':'. $this->_topic, $this->_return, 120); } return $this->_return; diff --git a/PrivateTopics.xml b/PrivateTopics.xml index bf23e48..e8e2877 100644 --- a/PrivateTopics.xml +++ b/PrivateTopics.xml @@ -231,8 +231,10 @@ if (!empty($ptBoard) && $ptCanSet && is_array($ptArray)) { - $context['ptenable'] = $ptArray != 'no'; - $context['ptusers'] = implode(',', $ptArray); + $context['ptenable'] = $ptArray !== false; + $context['ptusers'] = $smcFunc['htmlspecialchars']('"' . implode('", "', $ptArray) . '"'); + foreach ($ptArray as $key => $name) + $context['ptusers_auto'][$key] = $name; } } @@ -268,7 +270,7 @@ $ptuserstemp2 = array_unique($ptuserstemp); - $ptusers = implode(',', $ptuserstemp); + $ptusers = $ptuserstemp; } /* No? then do it the old way instead */ @@ -297,7 +299,7 @@ $ptuserstemp2 = array_unique($ptuserstemp); /* Done, fill up the array */ - $ptusers = implode(',', $ptuserstemp2); + $ptusers = $ptuserstemp2; } /* If there was no users, then use the topic starter */ @@ -324,8 +326,8 @@ - doGet() != 'no') + doGet() !== false) $pt->doUpdate($topicOptions['id']); modifyPost($msgOptions, $topicOptions, $posterOptions);]]> @@ -513,7 +515,23 @@ function suggestMember() sURLMask: \'action=profile;u=%item_id%\', sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\', bItemList: true, - sItemListContainerId: \'to_item_list_container\', + sItemListContainerId: \'to_item_list_container\','; + if (!empty($context['ptusers'])) + { + echo ' + aListItems: ['; + $i = 0; + foreach ($context['ptusers_auto'] as $id => $member) + echo ' + { + sItemId: ', JavaScriptEscape($id), ', + sItemName: ', JavaScriptEscape($member), ' + }', $i++ == count($context['ptusers_auto']) - 1 ? '' : ','; + + echo ' + ],'; + } +echo ' }); } suggestMember(); From e7e422dc2b728bfd354b9edbbb43a76f9c378e35 Mon Sep 17 00:00:00 2001 From: Suki Date: Fri, 29 Mar 2013 09:59:40 -0600 Subject: [PATCH 3/3] Add support for Sources/News.php Signed-off-by: Suki --- PrivateTopics.xml | 137 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/PrivateTopics.xml b/PrivateTopics.xml index e8e2877..b24c2ca 100644 --- a/PrivateTopics.xml +++ b/PrivateTopics.xml @@ -463,6 +463,143 @@ + + + $board, + 'is_approved' => 1, + 'limit' => $_GET['limit'], + 'optimize_msg' => $optimize_msg, + ) + );]]> + $board, + 'is_approved' => 1, + 'limit' => $_GET['limit'], + 'optimize_msg' => $optimize_msg, + ) + );]]> + + + $_GET['limit'], + 'current_board' => $board, + 'is_approved' => 1, + 'optimize_msg' => $optimize_msg, + ) + );]]> + $_GET['limit'], + 'current_board' => $board, + 'is_approved' => 1, + 'optimize_msg' => $optimize_msg, + ) + );]]> + + + + + + + + + + + + + + + + = {int:min_message_id}]]> + = {int:min_message_id} + '. (!empty($modSettings['PrivateTopics_enable']) && !allowedTo('can_always_see_private_topics') ? 'AND pt.user IS NULL' : '') .']]> + + + + + + + + + + $user_info['id'],]]> + + +