|
From: <dac...@us...> - 2007-09-03 12:36:41
|
Revision: 54
http://thevr.svn.sourceforge.net/thevr/?rev=54&view=rev
Author: dachebodt
Date: 2007-09-03 04:34:57 -0700 (Mon, 03 Sep 2007)
Log Message:
-----------
Fixed a few bugs and completed code to allow setting permissions for different content types
Modified Paths:
--------------
mods/cms/trunk/modules/content/acp_content.php
mods/cms/trunk/modules/content/cms_content.php
mods/cms/trunk/modules/content/functions_properties.php
mods/cms/trunk/modules/content/info/acp_content.php
mods/cms/trunk/modules/content/language/en/content.php
mods/cms/trunk/modules/content/template/acp_content.html
Modified: mods/cms/trunk/modules/content/acp_content.php
===================================================================
--- mods/cms/trunk/modules/content/acp_content.php 2007-09-03 06:28:24 UTC (rev 53)
+++ mods/cms/trunk/modules/content/acp_content.php 2007-09-03 11:34:57 UTC (rev 54)
@@ -19,7 +19,7 @@
function main($id, $mode)
{
- global $config, $db, $user, $auth, $template, $mtemplate, $phpbb_root_path, $phpbb_admin_path, $phpEx;
+ global $config, $db, $user, $cache, $auth, $template, $mtemplate, $phpbb_root_path, $phpbb_admin_path, $phpEx;
include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx);
include($phpbb_root_path . "modules/content/constants.$phpEx");
@@ -45,44 +45,95 @@
case 'edit_type':
$action = '';
+ $posted_permission = request_var('permission', '');
+ $content_name = utf8_normalize_nfc(request_var('content_name', '', true));
- $sql = 'SELECT module_id
- FROM ' . MODULES_TABLE . "
- WHERE module_langname = 'CMS_CONTENT'
- AND module_class = 'cms'
- AND parent_id = 0";
- $result = $db->sql_query($sql);
- $parent_id = $db->sql_fetchfield('module_id');
- $db->sql_freeresult($result);
-
- $module_data['module_class'] = 'cms';
- $module_data['module_basename'] = 'content';
- $module_data['module_dir'] = 'content';
- $module_data['parent_id'] = $parent_id;
$module_data['module_enabled'] = request_var('active', '0');
$module_data['module_display'] = request_var('display', '1');
$module_data['module_langname'] = utf8_normalize_nfc(request_var('content_langname', '', true));
- $module_data['module_mode'] = request_var('content_name', '');
- $module_data['module_auth'] = request_var('permission', '');
+ $module_data['module_mode'] = strtolower($content_name);
+ $module_data['module_auth'] = ($posted_permission) ? 'acl_' . $posted_permission : '';
if(!$module_data['module_langname'])
{
- trigger_error();
+ trigger_error('MISSING_CONTENT_LANGNAME');
}
if(!$module_data['module_mode'])
{
- trigger_error();
+ trigger_error('MISSING_CONTENT_NAME');
}
+ $permission = '';
if($content_id)
{
$module_data['module_id'] = $content_id;
+
+ $sql = 'SELECT *
+ FROM ' . MODULES_TABLE . "
+ WHERE module_id = $content_id";
+ $result = $db->sql_query($sql);
+ $row = $db->sql_fetchrow($result);
+ $db->sql_freeresult($result);
+
+ $permission = $row['module_auth'];
+ $module_data['parent_id'] = $row['parent_id'];
+
+ $update = ($module_data['module_enabled'] != $row['module_enabled'] || $module_data['module_display'] != $row['module_display'] || $module_data['module_langname'] != $row['module_langname'] || $module_data['module_mode'] != $row['module_mode'] || $module_data['module_auth'] != $permission) ? true : false;
}
+ else
+ {
+ $sql = 'SELECT module_id
+ FROM ' . MODULES_TABLE . "
+ WHERE module_langname = 'CMS_CONTENT'
+ AND module_class = 'cms'";
+ $result = $db->sql_query($sql);
+ $parent_id = $db->sql_fetchfield('module_id');
+ $db->sql_freeresult($result);
- $errors = $_module->update_module_data($module_data, true);
- $_module->remove_cache_file();
+ $module_data['parent_id'] = $parent_id;
+ $update = true;
+ }
+ // handle content permission
+ if($module_data['module_auth'] != $permission)
+ {
+ include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
+
+ $auth_admin = new auth_admin();
+
+ // if we already have permissions, remove it from acl
+ if($permission)
+ {
+ $sql = 'DELETE FROM ' . ACL_OPTIONS_TABLE . " WHERE auth_option = '$permission'";
+ $db->sql_query($sql);
+ }
+
+ if($posted_permission)
+ {
+ $permissions = array(
+ 'local' => array(),
+ 'global' => array($posted_permission),
+ );
+
+ $auth_admin->acl_add_option($permissions);
+ }
+
+ $cache->destroy('_acl_options');
+ $auth_admin->acl_clear_prefetch();
+ }
+
+ $errors = array();
+ if($update)
+ {
+ $module_data['module_class'] = 'cms';
+ $module_data['module_basename'] = 'content';
+ $module_data['module_dir'] = 'content';
+
+ $errors = $_module->update_module_data($module_data, true);
+ $_module->remove_cache_file();
+ }
+
if(empty($errors))
{
$data = array();
@@ -124,9 +175,7 @@
$db->sql_query($sql);
meta_refresh(3, $this->u_action);
-
- $message = $user->lang['TYPE_ADDED'];
- trigger_error($message);
+ trigger_error('CONTENT_TYPE_UPDATED');
}
else
{
@@ -209,10 +258,31 @@
$sql = 'DELETE FROM ' . CONTENT_TYPES_TABLE . ' WHERE content_id = ' . (int) $content_id;
$db->sql_query($sql);
+ // delete any permissions added by this content type
+ $sql = 'SELECT module_auth
+ FROM ' . MODULES_TABLE . "
+ WHERE module_langname = 'CMS_CONTENT'
+ AND module_class = 'cms'";
+ $result = $db->sql_query($sql);
+ $module_auth = $db->sql_fetchfield('module_auth');
+ $db->sql_freeresult($result);
+
+ if($module_auth)
+ {
+ include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
+
+ $auth_admin = new auth_admin();
+ $permission = str_replace('acl_', '', $module_auth);
+
+ $sql = 'DELETE FROM ' . ACL_OPTIONS_TABLE . " WHERE auth_option = '$permission'";
+ $db->sql_query($sql);
+
+ $cache->destroy('_acl_options');
+ $auth_admin->acl_clear_prefetch();
+ }
+
meta_refresh(5, $this->u_action);
-
- $message = $user->lang['TYPE_DELETED'];
- trigger_error($message);
+ trigger_error('CONTENT_TYPE_DELETED');
}
break;
@@ -322,7 +392,7 @@
$mtemplate->assign_vars(array(
'CONTENT_NAME' => $row['module_mode'],
'LANGNAME' => $row['module_langname'],
- 'PERMISSION' => $row['module_auth'],
+ 'PERMISSION' => str_replace('acl_', '', $row['module_auth']),
'S_ACTIVE' => $row['module_enabled'],
'S_APPROVAL' => $row['req_approval'],
Modified: mods/cms/trunk/modules/content/cms_content.php
===================================================================
--- mods/cms/trunk/modules/content/cms_content.php 2007-09-03 06:28:24 UTC (rev 53)
+++ mods/cms/trunk/modules/content/cms_content.php 2007-09-03 11:34:57 UTC (rev 54)
@@ -335,6 +335,14 @@
'CONTENT' => $mtemplate->assign_display('content')
));
}
+
+ if(!sizeof($tpl_ary))
+ {
+ $template->assign_block_vars('module', array(
+ 'TITLE' => $content_name,
+ 'CONTENT' => sprintf($user->lang['NO_CMS_CONTENT'], $content_name)
+ ));
+ }
}
if(isset($store_mtemplate))
Modified: mods/cms/trunk/modules/content/functions_properties.php
===================================================================
--- mods/cms/trunk/modules/content/functions_properties.php 2007-09-03 06:28:24 UTC (rev 53)
+++ mods/cms/trunk/modules/content/functions_properties.php 2007-09-03 11:34:57 UTC (rev 54)
@@ -19,7 +19,7 @@
foreach($properties as $i => $props)
{
$selected = ($i == $type) ? ' selected="selected"' : '';
- $options .= '<option value="' . $i . '"' . $selected . '>' . $props['label'] . "</option>\n";
+ $options .= '<option value="' . $i . '"' . $selected . '>' . $user->lang[$props['label']] . "</option>\n";
}
return $options;
Modified: mods/cms/trunk/modules/content/info/acp_content.php
===================================================================
--- mods/cms/trunk/modules/content/info/acp_content.php 2007-09-03 06:28:24 UTC (rev 53)
+++ mods/cms/trunk/modules/content/info/acp_content.php 2007-09-03 11:34:57 UTC (rev 54)
@@ -57,7 +57,6 @@
`content_id` int(3) NOT NULL auto_increment,
`content_name` varchar(125) collate utf8_bin NOT NULL,
`content_langname` varchar(255) collate utf8_bin NOT NULL,
- `permission` mediumtext collate utf8_bin NOT NULL,
`content_fields` text collate utf8_bin,
`req_approval` tinyint(1) NOT NULL default '1',
`allow_comments` tinyint(1) NOT NULL default '1',
Modified: mods/cms/trunk/modules/content/language/en/content.php
===================================================================
--- mods/cms/trunk/modules/content/language/en/content.php 2007-09-03 06:28:24 UTC (rev 53)
+++ mods/cms/trunk/modules/content/language/en/content.php 2007-09-03 11:34:57 UTC (rev 54)
@@ -44,10 +44,14 @@
'SEARCH_USER_POSTS' => 'Search all posts by this user',
'VIEW_AUTHOR_CONTENTS' => 'View all %s by this author',
+ 'VIEW_TYPE' => 'View content type',
+ 'EDIT_TYPE' => 'Edit content type',
+ 'EDIT_ITEM' => 'Edit Item',
'NAME' => 'Content type name',
'LANGNAME' => 'Content type language name',
'PERMISSION' => 'Content type permission',
+ 'PERMISSION_AFTER' => 'Ex: u_view_news',
'LABEL' => 'Label',
'TYPE' => 'Type',
'TEASER_DISP' => 'Display Teaser?',
@@ -73,6 +77,23 @@
'CONTENT_TYPE' => 'Content Type',
'EDIT' => 'Edit',
'EDIT_TYPE' => 'Edit Content Type',
+ 'ADD_TYPE' => 'Add New Content Type',
+ 'ADD_ITEM' => 'Add New Item',
+
+ 'NO_ITEMS' => 'There are no existing items for this content type.',
+ 'NO_CONTENT_TYPE' => 'There are no existing content types',
+ 'NO_CMS_CONTENT' => 'No %s(s) have been posted yet.',
+ 'TEXT' => 'Text',
+ 'SMALL_TEXTAREA' => 'Small Textarea',
+ 'LARGE_TEXTAREA' => 'Large Textarea',
+
+ 'CONTENT_FIELDS' => 'Content Fields',
+ 'CONTENT_SETTINGS' => 'Content Settings',
+ 'CONTENT_TYPE_UPDATED' => 'Content type updated successfully',
+ 'CONTENT_TYPE_DELETED' => 'Content type deleted successfully',
+
+ 'MISSING_CONTENT_LANGNAME' => 'Missing content language name',
+ 'MISSING_CONTENT_NAME' => 'Missing content name',
));
?>
\ No newline at end of file
Modified: mods/cms/trunk/modules/content/template/acp_content.html
===================================================================
--- mods/cms/trunk/modules/content/template/acp_content.html 2007-09-03 06:28:24 UTC (rev 53)
+++ mods/cms/trunk/modules/content/template/acp_content.html 2007-09-03 11:34:57 UTC (rev 54)
@@ -52,15 +52,19 @@
<!-- ELSEIF S_VIEW_TYPE -->
- <p align="right"><a href="{U_ADD_ITEM}">{L_ADD}</a></p>
+ <p align="right"><a href="{U_ADD_ITEM}">{L_ADD_ITEM}</a></p>
<table cellspacing="1" width="90%">
<tbody>
+
+ <!-- IF .item -->
<tr>
<th style="text-align:center">{L_TITLE}</th>
<th style="text-align:center">{L_STATUS}</th>
<th style="text-align:center">{L_APPROVER}</th>
<th style="text-align:center">{L_ACTION}</th>
</tr>
+ <!-- ENDIF -->
+
<!-- BEGIN item -->
<tr>
<td><a href="{item.U_VIEW}">{item.TITLE}</a><br>{item.POSTED} <a href="{item.U_AUTHOR}">{item.AUTHOR}</a></td>
@@ -73,8 +77,11 @@
</tr>
<!-- BEGINELSE -->
<tr>
- <td>No content</td>
+ <th>{L_INFORMATION}</th>
</tr>
+ <tr>
+ <td>{L_NO_ITEMS}</td>
+ </tr>
<!-- END item -->
</tbody>
</table>
@@ -83,6 +90,7 @@
<form id="edit_type" method="post" action="{U_ACTION}">
<fieldset>
+ <legend>{L_CONTENT_TYPE}</legend>
<dl>
<dt><label for="content_name">{L_NAME}:</label></dt>
<dd><input name="content_name" type="text" id="content_name" class="medium" maxlength="50" value="{CONTENT_NAME}" /></dd>
@@ -93,7 +101,7 @@
</dl>
<dl>
<dt><label for="permission">{L_PERMISSION}:</label></dt>
- <dd><input name="permission" type="text" id="permission" class="medium" maxlength="75" value="{PERMISSION}" /></dd>
+ <dd><input name="permission" type="text" id="permission" class="medium" maxlength="75" value="{PERMISSION}" /> {L_PERMISSION_AFTER}</dd>
</dl>
<dl>
<dt><label for="active">{L_ACTIVE}:</label></dt>
@@ -102,6 +110,7 @@
</fieldset>
<fieldset>
+ <legend>{L_CONTENT_FIELDS}</legend>
<table cellspacing="1" width="90%">
<tbody>
<tr>
@@ -129,6 +138,7 @@
</fieldset>
<fieldset>
+ <legend>{L_CONTENT_SETTINGS}</legend>
<dl>
<dt><label for="req_approval">{L_REQ_APPROVAL}:</label></dt>
<dd><input type="radio" class="radio" id="req_approval" name="req_approval" value="1"<!-- IF S_APPROVAL --> checked="checked"<!-- ENDIF --> /> {L_YES} <input type="radio" class="radio" name="req_approval" value="0"<!-- IF not S_APPROVAL --> checked="checked"<!-- ENDIF --> /> {L_NO}</dd>
@@ -174,8 +184,12 @@
<!-- ELSE -->
- <p align="right"><a href="{U_ADD_TYPE}">{L_ADD}</a></p>
+ <p align="right"><a href="{U_ADD_TYPE}">{L_ADD_TYPE}</a></p>
<table cellspacing="1" width="90%">
+ <thead>
+ <th>{L_CONTENT_TYPE}</th>
+ <th>{L_ACTION}</th>
+ </thead>
<tbody>
<!-- BEGIN types -->
<tr <!-- IF types.S_ROW_COUNT is even -->class="row1"<!-- ELSE -->class="row2"<!-- ENDIF -->>
@@ -200,7 +214,7 @@
</tr>
<!-- BEGINELSE -->
<tr>
- <td>No types</td>
+ <td>{L_NO_CONTENT_TYPES}</td>
</tr>
<!-- END types -->
</tbody>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|