Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:MissAllSunday/PrivateTopic.git
Browse files Browse the repository at this point in the history
  • Loading branch information
MissAllSunday committed Jan 24, 2014
2 parents 0f06bf0 + d3d5680 commit 00aa61a
Show file tree
Hide file tree
Showing 5 changed files with 277 additions and 42 deletions.
7 changes: 3 additions & 4 deletions PrivateTopics.english.php
Expand Up @@ -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';
Expand All @@ -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 */
Expand Down
90 changes: 59 additions & 31 deletions PrivateTopics.php
Expand Up @@ -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')
);
}

Expand All @@ -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()
Expand All @@ -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;
Expand Down Expand Up @@ -153,8 +162,7 @@ public function doBoard($board)
$check = $temp->getSetting('boards');

if (!empty($check))
$array = explode(',', $check);

$array = unserialize($check);
else
$array = array();

Expand Down Expand Up @@ -222,18 +230,38 @@ 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');

$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')),

);
Expand All @@ -253,13 +281,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);
Expand Down
51 changes: 51 additions & 0 deletions PrivateTopics.template.php
@@ -0,0 +1,51 @@
<?php

/**
* PrivateTopics.php
*
* @package Private Topics mod
* @version 1.0
* @author Jessica González <missallsunday@simplemachines.org>
* @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 '
<dt>
<strong>', $txt['PrivateTopics_boards'], ':</strong>
</dt>
<dd>
<fieldset id="visible_boards" style="width: 95%;">
<legend>', $txt['PrivateTopics_select_boards'], '</legend>';
foreach ($context['boards'] as $board)
echo '
<div style="margin-left: ', $board['child_level'], 'em;"><input type="checkbox" name="PrivateTopics_boards[]" id="PrivateTopics_boards_', $board['id'], '" value="', $board['id'], '" ', $board['selected'] ? ' checked="checked"' : '', ' class="input_check" /> <label for="PrivateTopics_boards_', $board['id'], '">', $board['name'], '</label></div>';

echo '
<br />
<input type="checkbox" id="checkall_check" class="input_check" onclick="invertAll(this, this.form, \'PrivateTopics_boards\');" /> <label for="checkall_check"><em>', $txt['check_all'], '</em></label>
</fieldset>
</dd>';
}
}

0 comments on commit 00aa61a

Please sign in to comment.