Version 4.2.0
This commit is contained in:
1 parent
0dc2aee5ed
commit
96997ddd8e
2074 files changed
+125454
-55780
No files matched your search
@@ -1,13 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Databases Model
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @subpackage Content
|
||||
* @since 31 March 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\cms\modules\admin\databases;
|
||||
@@ -61,7 +60,7 @@ class _databases extends \IPS\Node\Controller
|
||||
'database_name' => '50'
|
||||
);
|
||||
|
||||
$table->mainColumn = 'word_custom';
|
||||
$table->mainColumn = 'database_name';
|
||||
$table->quickSearch = 'word_custom';
|
||||
|
||||
$table->sortBy = $table->sortBy ?: 'word_custom';
|
||||
@@ -124,13 +123,12 @@ class _databases extends \IPS\Node\Controller
|
||||
);
|
||||
|
||||
/* Buttons */
|
||||
$table->rootButtons = array(
|
||||
'add' => array(
|
||||
'title' => 'add',
|
||||
'icon' => 'plus',
|
||||
'link' => \IPS\Http\Url::internal( 'app=cms&module=databases&controller=databases&do=add' ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('cms_database_add') )
|
||||
),
|
||||
\IPS\Output::i()->sidebar['actions']['add'] = array(
|
||||
'primary' => true,
|
||||
'title' => 'add',
|
||||
'icon' => 'plus',
|
||||
'link' => \IPS\Http\Url::internal( 'app=cms&module=databases&controller=databases&do=add' ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('cms_database_add') )
|
||||
);
|
||||
|
||||
/*if ( \IPS\Application::appIsEnabled('forums') )
|
||||
@@ -216,7 +214,7 @@ class _databases extends \IPS\Node\Controller
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_databases.js', 'cms', 'admin' ) );
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( \IPS\Member::loggedIn()->language()->addToStack('menu__cms_databases_databases'), (string) $table );
|
||||
\IPS\Output::i()->output = (string) $table;
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__cms_databases_databases');
|
||||
}
|
||||
|
||||
@@ -289,6 +287,20 @@ class _databases extends \IPS\Node\Controller
|
||||
$database->key = uniqid();
|
||||
$database->save();
|
||||
|
||||
/* Set default perms, these will be editable post DB import */
|
||||
\IPS\Db::i()->replace( 'core_permission_index', array(
|
||||
'app' => 'cms',
|
||||
'perm_type' => $database::$permType,
|
||||
'perm_type_id' => $database->id,
|
||||
'perm_view' => '*',
|
||||
'perm_2' => '*', #read
|
||||
'perm_3' => \IPS\Settings::i()->admin_group, #add
|
||||
'perm_4' => \IPS\Settings::i()->admin_group, #edit
|
||||
'perm_5' => \IPS\Settings::i()->admin_group, #reply
|
||||
'perm_6' => \IPS\Settings::i()->admin_group, #rate
|
||||
'perm_7' => \IPS\Settings::i()->admin_group, #review
|
||||
) );
|
||||
|
||||
$json = json_decode( @file_get_contents( \IPS\ROOT_PATH . "/applications/cms/data/databaseschema.json" ), true );
|
||||
$table = $json['cms_custom_database_1'];
|
||||
|
||||
@@ -394,19 +406,6 @@ class _databases extends \IPS\Node\Controller
|
||||
|
||||
$database->save();
|
||||
|
||||
/* Set default perms, these will be editable post DB import */
|
||||
$perms = $database->permissions();
|
||||
|
||||
\IPS\Db::i()->update( 'core_permission_index', array(
|
||||
'perm_view' => '*',
|
||||
'perm_2' => '*', #read
|
||||
'perm_3' => \IPS\Settings::i()->admin_group, #add
|
||||
'perm_4' => \IPS\Settings::i()->admin_group, #edit
|
||||
'perm_5' => \IPS\Settings::i()->admin_group, #reply
|
||||
'perm_6' => \IPS\Settings::i()->admin_group, #rate
|
||||
'perm_7' => \IPS\Settings::i()->admin_group, #review
|
||||
), array( 'perm_id=?', $perms['perm_id'] ) );
|
||||
|
||||
/* set up some stores (and make sure they are clean from previous possibly broken imports */
|
||||
\IPS\Data\Store::i()->db_import_cat_map = array();
|
||||
\IPS\Data\Store::i()->db_import_cat_parent_map = array();
|
||||
@@ -498,8 +497,15 @@ class _databases extends \IPS\Node\Controller
|
||||
$fieldsClass = 'IPS\cms\Fields' . $database->id;
|
||||
|
||||
$obj = new $fieldsClass;
|
||||
|
||||
$obj->saveForm( $obj->formatFormValues( $attrs ) );
|
||||
$values = $obj->formatFormValues( $attrs );
|
||||
|
||||
if ( isset( $attrs['field_extra'] ) )
|
||||
{
|
||||
/* The export format is always correct */
|
||||
$values['field_extra'] = $attrs['field_extra'];
|
||||
}
|
||||
|
||||
$obj->saveForm( $values );
|
||||
|
||||
if ( $displayJson )
|
||||
{
|
||||
@@ -524,9 +530,26 @@ class _databases extends \IPS\Node\Controller
|
||||
|
||||
\IPS\Data\Store::i()->db_import_field_map = $map;
|
||||
|
||||
$existingPerms = $obj->permissions();
|
||||
$existingPerms = $obj->permissions();
|
||||
$newPerms = array_merge( $perms, array( 'perm_id' => $existingPerms['perm_id'], 'perm_type_id' => $obj->id ) );
|
||||
|
||||
/* Set default permissions if not defined in export */
|
||||
if( !isset( $perms['perm_view'] ) )
|
||||
{
|
||||
$newPerms['perm_view'] = '*';
|
||||
}
|
||||
|
||||
if( !isset( $perms['perm_2'] ) )
|
||||
{
|
||||
$newPerms['perm_2'] = \IPS\Settings::i()->admin_group;
|
||||
}
|
||||
|
||||
if( !isset( $perms['perm_3'] ) )
|
||||
{
|
||||
$newPerms['perm_3'] = \IPS\Settings::i()->admin_group;
|
||||
}
|
||||
|
||||
\IPS\Db::i()->update( 'core_permission_index', array_merge( $perms, array( 'perm_id' => $existingPerms['perm_id'], 'perm_type_id' => $obj->id ) ), array( 'perm_id=?', $existingPerms['perm_id'] ) );
|
||||
\IPS\Db::i()->update( 'core_permission_index', $newPerms, array( 'perm_id=?', $existingPerms['perm_id'] ) );
|
||||
|
||||
\IPS\Lang::saveCustom( 'cms', "content_field_" . $obj->id, $attrs['field_title'] );
|
||||
|
||||
@@ -1144,6 +1167,296 @@ class _databases extends \IPS\Node\Controller
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the database form - abstracted so plugins can adjust easier */
|
||||
$form = $this->_getDatabaseForm( $current, $category );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$new = FALSE;
|
||||
|
||||
if ( empty( $current ) )
|
||||
{
|
||||
$new = TRUE;
|
||||
$current = new \IPS\cms\Databases;
|
||||
$current->key = uniqid(); # This is modified below to use a proper key
|
||||
$current->featured_settings = NULL;
|
||||
$current->fixed_field_perms = NULL;
|
||||
$current->save();
|
||||
|
||||
/* Create a new database table */
|
||||
try
|
||||
{
|
||||
\IPS\cms\Databases::createDatabase( $current );
|
||||
$current->preLoadWords();
|
||||
|
||||
\IPS\Member::clearCreateMenu();
|
||||
}
|
||||
catch ( \Exception $ex )
|
||||
{
|
||||
$current->delete();
|
||||
|
||||
\IPS\Output::i()->error( \IPS\Member::loggedIn()->language()->addToStack('content_acp_err_db_creation_fail', FALSE, array( 'sprintf' => $ex->getMessage() ) ), '4T259/1', 403, '' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $values['database_key'] )
|
||||
{
|
||||
if ( is_array( $values['database_name'] ) )
|
||||
{
|
||||
$keyToUse = uniqid();
|
||||
foreach( $values['database_name'] as $langId => $word )
|
||||
{
|
||||
if ( ! empty( $word ) )
|
||||
{
|
||||
$keyToUse = $word;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$current->key = \IPS\Http\Url\Friendly::seoTitle( $keyToUse );
|
||||
}
|
||||
else
|
||||
{
|
||||
$current->key = \IPS\Http\Url\Friendly::seoTitle( $values['database_name'] );
|
||||
}
|
||||
|
||||
/* Now test it */
|
||||
try
|
||||
{
|
||||
$database = \IPS\cms\Databases::load( $current->key, 'database_key');
|
||||
|
||||
/* It's taken... */
|
||||
if ( $current->id != $database->id )
|
||||
{
|
||||
$current->key .= '_' . uniqid();
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
{
|
||||
/* Doesn't exist? Good! */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$current->key = $values['database_key'];
|
||||
}
|
||||
|
||||
/* Bit options */
|
||||
foreach ( array( 'comments', 'comments_mod', 'reviews', 'reviews_mod', 'indefinite_own_edit' ) as $k )
|
||||
{
|
||||
if ( isset( $values[ "cms_bitoptions_{$k}" ] ) )
|
||||
{
|
||||
$current->options[ $k ] = $values["cms_bitoptions_{$k}"];
|
||||
unset( $values["cms_bitoptions_{$k}"] );
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Lang::saveCustom( 'cms', "content_db_" . $current->id, $values['database_name'] );
|
||||
\IPS\Lang::saveCustom( 'cms', "content_db_" . $current->id . '_desc', $values['database_description'] );
|
||||
\IPS\Lang::saveCustom( 'cms', "content_db_lang_sl_" . $current->id, $values['database_lang_sl'] );
|
||||
\IPS\Lang::saveCustom( 'cms', "content_db_lang_pl_" . $current->id, $values['database_lang_pl'] );
|
||||
\IPS\Lang::saveCustom( 'cms', "content_db_lang_su_" . $current->id, $values['database_lang_su'] );
|
||||
\IPS\Lang::saveCustom( 'cms', "content_db_lang_pu_" . $current->id, $values['database_lang_pu'] );
|
||||
\IPS\Lang::saveCustom( 'cms', "content_db_lang_ia_" . $current->id, $values['database_lang_ia'] );
|
||||
\IPS\Lang::saveCustom( 'cms', "content_db_lang_sl_" . $current->id . '_pl', $values['database_lang_pu'] );
|
||||
\IPS\Lang::saveCustom( 'cms', "digest_area_cms_records" . $current->id, $values['database_lang_pu'] );
|
||||
\IPS\Lang::saveCustom( 'cms', "digest_area_cms_categories" . $current->id, $values['database_lang_pu'] );
|
||||
|
||||
$menu = array();
|
||||
foreach( \IPS\Lang::getEnabledLanguages() as $id => $lang )
|
||||
{
|
||||
$menu[ $lang->_id ] = \sprintf( $lang->get('cms_create_menu_records_x'), $values['database_lang_su'][ $lang->_id ], $values['database_name'][ $lang->_id ] );
|
||||
}
|
||||
|
||||
/* Notification, search/followed/new content langs */
|
||||
\IPS\Lang::saveCustom( 'cms', "cms_create_menu_records_" . $current->id, $menu );
|
||||
\IPS\Lang::saveCustom( 'cms', "cms_records" . $current->id . '_pl', $values['database_lang_pu'] );
|
||||
\IPS\Lang::saveCustom( 'cms', "module__cms_records" . $current->id, $values['database_name'] );
|
||||
|
||||
$current->use_categories = $values['database_use_categories'];
|
||||
$current->template_categories = $values['database_template_categories'];
|
||||
$current->template_listing = $values['database_template_listing'];
|
||||
$current->template_display = $values['database_template_display'];
|
||||
$current->template_form = $values['database_template_form'];
|
||||
$current->template_featured = $values['database_template_featured'];
|
||||
$current->cat_index_type = $values['database_cat_index_type'];
|
||||
$current->use_as_page_title = $values['database_use_as_page_title'];
|
||||
|
||||
$current->all_editable = (int) $values['database_all_editable'];
|
||||
$current->revisions = (int) $values['database_revisions'];
|
||||
$current->search = (int) $values['database_search'];
|
||||
$current->comment_bump = $values['database_comment_bump'];
|
||||
if ( $values['database_rss_enable'] )
|
||||
{
|
||||
$current->rss = $values['database_rss'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$current->rss = 0;
|
||||
}
|
||||
$current->record_approve = $values['database_record_approve'];
|
||||
|
||||
if ( \IPS\Settings::i()->tags_enabled )
|
||||
{
|
||||
$current->tags_enabled = (int) $values['database_tags_enabled'];
|
||||
$current->tags_noprefixes = !(bool) $values['database_tags_noprefixes'];
|
||||
|
||||
if ( ! \IPS\Settings::i()->tags_open_system )
|
||||
{
|
||||
$current->tags_predefined = ( is_array( $values['database_tags_predefined'] ) ) ? implode( ',', array_filter( array_map( 'trim', $values['database_tags_predefined'] ) ) ) : NULL;
|
||||
}
|
||||
}
|
||||
|
||||
$categories = 0;
|
||||
if ( isset( $values['database_featured_categories'] ) )
|
||||
{
|
||||
if ( $values['database_featured_categories'] !== 0 )
|
||||
{
|
||||
$categories = array_keys( $values['database_featured_categories'] );
|
||||
}
|
||||
}
|
||||
|
||||
/* Featured settings */
|
||||
$current->featured_settings = array(
|
||||
'featured' => $values['database_featured_featured'],
|
||||
'perpage' => $values['database_featured_perpage'],
|
||||
'pagination' => $values['database_featured_pagination'],
|
||||
'sort' => $values['database_featured_sort'],
|
||||
'direction' => $values['database_featured_direction'],
|
||||
'categories' => $categories
|
||||
);
|
||||
|
||||
$current->field_sort = $values['database_field_sort'];
|
||||
$current->field_direction = $values['database_field_direction'];
|
||||
$current->field_perpage = $values['database_field_perpage'];
|
||||
|
||||
if ( \IPS\Application::appIsEnabled( 'forums' ) )
|
||||
{
|
||||
$current->forum_record = (int) $values['database_forum_record'];
|
||||
$current->forum_comments = (int) $values['database_forum_comments'];
|
||||
$current->forum_forum = ( ! $values['database_forum_forum'] ) ? 0 : $values['database_forum_forum']->id;
|
||||
$current->forum_prefix = $values['database_forum_prefix'];
|
||||
$current->forum_suffix = $values['database_forum_suffix'];
|
||||
$current->forum_delete = (int) $values['database_forum_delete'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$current->forum_record = 0;
|
||||
$current->forum_comments = 0;
|
||||
$current->forum_delete = 0;
|
||||
}
|
||||
|
||||
$fieldSettingJson = array();
|
||||
|
||||
foreach( $values as $k => $v )
|
||||
{
|
||||
if ( mb_stristr( $k, 'fixed_field_setting__' ) )
|
||||
{
|
||||
$bits = explode( '__', $k );
|
||||
|
||||
$fieldSettingJson[ $bits[1] ][ $bits[2] ] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
$current->fixed_field_settings = $fieldSettingJson;
|
||||
|
||||
$fixedFields = $current->fixed_field_perms;
|
||||
$fixedFields['record_image']['visible'] = $values['database_record_image'];
|
||||
|
||||
foreach( array( 'perm_view', 'perm_2', 'perm_3' ) as $p )
|
||||
{
|
||||
if ( ! isset( $fixedFields['record_image'][ $p ] ) )
|
||||
{
|
||||
$fixedFields['record_image'][ $p ] = '*';
|
||||
}
|
||||
}
|
||||
|
||||
$current->fixed_field_perms = $fixedFields;
|
||||
$current->use_categories = $values['database_use_categories'];
|
||||
|
||||
$current->save();
|
||||
|
||||
/* Make sure we have a default category */
|
||||
$current->default_category = $current->_default_category;
|
||||
|
||||
if ( ! $current->use_categories )
|
||||
{
|
||||
$class = '\IPS\cms\Categories' . $current->id;
|
||||
$category = $class::load( $current->get__default_category() );
|
||||
$category->allow_rating = $values['category_allow_rating'];
|
||||
$category->can_view_others = $values['category_can_view_others'];
|
||||
$category->save();
|
||||
}
|
||||
|
||||
if ( $new )
|
||||
{
|
||||
if ( $values['database_create_page'] === 'new' )
|
||||
{
|
||||
$pageValues = array();
|
||||
|
||||
foreach( $values as $k => $v )
|
||||
{
|
||||
if( mb_strpos( $k, 'page_' ) === 0 )
|
||||
{
|
||||
$pageValues[ $k ] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $values['page_type'] === 'html' )
|
||||
{
|
||||
$pageValues['page_content'] = '{database="' . $current->id . '"}';
|
||||
$pageValues['page_template'] = '';
|
||||
}
|
||||
$pageValues['page_folder_id'] = $pageValues['page_folder_id'] ?: 0;
|
||||
|
||||
$newPage = \IPS\cms\Pages\Page::createFromForm( $pageValues, 'html' );
|
||||
|
||||
if ( $values['page_type'] !== 'html' )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'cms_page_widget_areas', array(
|
||||
'area_page_id' => $newPage->id,
|
||||
'area_widgets' => json_encode( array( array( 'app' => 'cms', 'key' => 'Database', 'unique' => uniqid(), 'configuration' => array( 'database' => $current->id ) ) ) ),
|
||||
'area_area' => 'col1',
|
||||
'area_orientation' => 'horizontal'
|
||||
) );
|
||||
}
|
||||
|
||||
$current->page_id = $newPage->id;
|
||||
$current->save();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Use categories setting may have changed */
|
||||
$current->preLoadWords();
|
||||
\IPS\Member::clearCreateMenu();
|
||||
}
|
||||
|
||||
if ( $new )
|
||||
{
|
||||
\IPS\Session::i()->log( 'acplogs__cms_added_database', array( 'content_db_' . $current->id => TRUE ) );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=databases&controller=databases&do=permissions&id=' . $current->id ) );
|
||||
}
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__cms_edited_database', array( 'content_db_' . $current->id => TRUE ) );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=databases&controller=databases' ), 'saved' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( $current ? "content_db_" . $current->id : 'add', $form, FALSE );
|
||||
\IPS\Output::i()->title = ( $current ) ? \IPS\Member::loggedIn()->language()->addToStack('cms_editing_database', NULL, array( 'sprintf' => array( $current->_title ) ) ) : \IPS\Member::loggedIn()->language()->addToStack('cms_adding_database');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the database form
|
||||
*
|
||||
* @param \IPS\cms\Databases $current The current database
|
||||
* @param \IPS\cms\Categories $category The default catgory
|
||||
* @return \IPS\Form
|
||||
*/
|
||||
protected function _getDatabaseForm( $current, $category )
|
||||
{
|
||||
$form = new \IPS\Helpers\Form( 'form', 'save', NULL, array( 'data-controller' => 'cms.admin.databases.form' ) );
|
||||
|
||||
$form->addTab( 'content_database_form_details' );
|
||||
@@ -1569,282 +1882,7 @@ class _databases extends \IPS\Node\Controller
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$new = FALSE;
|
||||
|
||||
if ( empty( $current ) )
|
||||
{
|
||||
$new = TRUE;
|
||||
$current = new \IPS\cms\Databases;
|
||||
$current->key = uniqid(); # This is modified below to use a proper key
|
||||
$current->featured_settings = NULL;
|
||||
$current->fixed_field_perms = NULL;
|
||||
$current->save();
|
||||
|
||||
/* Create a new database table */
|
||||
try
|
||||
{
|
||||
\IPS\cms\Databases::createDatabase( $current );
|
||||
$current->preLoadWords();
|
||||
|
||||
\IPS\Member::clearCreateMenu();
|
||||
}
|
||||
catch ( \Exception $ex )
|
||||
{
|
||||
$current->delete();
|
||||
|
||||
\IPS\Output::i()->error( \IPS\Member::loggedIn()->language()->addToStack('content_acp_err_db_creation_fail', FALSE, array( 'sprintf' => $ex->getMessage() ) ), '4T259/1', 403, '' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $values['database_key'] )
|
||||
{
|
||||
if ( is_array( $values['database_name'] ) )
|
||||
{
|
||||
$keyToUse = uniqid();
|
||||
foreach( $values['database_name'] as $langId => $word )
|
||||
{
|
||||
if ( ! empty( $word ) )
|
||||
{
|
||||
$keyToUse = $word;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$current->key = \IPS\Http\Url\Friendly::seoTitle( $keyToUse );
|
||||
}
|
||||
else
|
||||
{
|
||||
$current->key = \IPS\Http\Url\Friendly::seoTitle( $values['database_name'] );
|
||||
}
|
||||
|
||||
/* Now test it */
|
||||
try
|
||||
{
|
||||
$database = \IPS\cms\Databases::load( $current->key, 'database_key');
|
||||
|
||||
/* It's taken... */
|
||||
if ( $current->id != $database->id )
|
||||
{
|
||||
$current->key .= '_' . uniqid();
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
{
|
||||
/* Doesn't exist? Good! */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$current->key = $values['database_key'];
|
||||
}
|
||||
|
||||
/* Bit options */
|
||||
foreach ( array( 'comments', 'comments_mod', 'reviews', 'reviews_mod', 'indefinite_own_edit' ) as $k )
|
||||
{
|
||||
if ( isset( $values[ "cms_bitoptions_{$k}" ] ) )
|
||||
{
|
||||
$current->options[ $k ] = $values["cms_bitoptions_{$k}"];
|
||||
unset( $values["cms_bitoptions_{$k}"] );
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Lang::saveCustom( 'cms', "content_db_" . $current->id, $values['database_name'] );
|
||||
\IPS\Lang::saveCustom( 'cms', "content_db_" . $current->id . '_desc', $values['database_description'] );
|
||||
\IPS\Lang::saveCustom( 'cms', "content_db_lang_sl_" . $current->id, $values['database_lang_sl'] );
|
||||
\IPS\Lang::saveCustom( 'cms', "content_db_lang_pl_" . $current->id, $values['database_lang_pl'] );
|
||||
\IPS\Lang::saveCustom( 'cms', "content_db_lang_su_" . $current->id, $values['database_lang_su'] );
|
||||
\IPS\Lang::saveCustom( 'cms', "content_db_lang_pu_" . $current->id, $values['database_lang_pu'] );
|
||||
\IPS\Lang::saveCustom( 'cms', "content_db_lang_ia_" . $current->id, $values['database_lang_ia'] );
|
||||
\IPS\Lang::saveCustom( 'cms', "content_db_lang_sl_" . $current->id . '_pl', $values['database_lang_pu'] );
|
||||
\IPS\Lang::saveCustom( 'cms', "digest_area_cms_records" . $current->id, $values['database_lang_pu'] );
|
||||
\IPS\Lang::saveCustom( 'cms', "digest_area_cms_categories" . $current->id, $values['database_lang_pu'] );
|
||||
|
||||
$menu = array();
|
||||
foreach( \IPS\Lang::getEnabledLanguages() as $id => $lang )
|
||||
{
|
||||
$menu[ $lang->_id ] = \sprintf( $lang->get('cms_create_menu_records_x'), $values['database_lang_su'][ $lang->_id ], $values['database_name'][ $lang->_id ] );
|
||||
}
|
||||
|
||||
/* Notification, search/followed/new content langs */
|
||||
\IPS\Lang::saveCustom( 'cms', "cms_create_menu_records_" . $current->id, $menu );
|
||||
\IPS\Lang::saveCustom( 'cms', "cms_records" . $current->id . '_pl', $values['database_lang_pu'] );
|
||||
\IPS\Lang::saveCustom( 'cms', "module__cms_records" . $current->id, $values['database_name'] );
|
||||
|
||||
$current->use_categories = $values['database_use_categories'];
|
||||
$current->template_categories = $values['database_template_categories'];
|
||||
$current->template_listing = $values['database_template_listing'];
|
||||
$current->template_display = $values['database_template_display'];
|
||||
$current->template_form = $values['database_template_form'];
|
||||
$current->template_featured = $values['database_template_featured'];
|
||||
$current->cat_index_type = $values['database_cat_index_type'];
|
||||
$current->use_as_page_title = $values['database_use_as_page_title'];
|
||||
|
||||
$current->all_editable = (int) $values['database_all_editable'];
|
||||
$current->revisions = (int) $values['database_revisions'];
|
||||
$current->search = (int) $values['database_search'];
|
||||
$current->comment_bump = $values['database_comment_bump'];
|
||||
if ( $values['database_rss_enable'] )
|
||||
{
|
||||
$current->rss = $values['database_rss'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$current->rss = 0;
|
||||
}
|
||||
$current->record_approve = $values['database_record_approve'];
|
||||
|
||||
if ( \IPS\Settings::i()->tags_enabled )
|
||||
{
|
||||
$current->tags_enabled = (int) $values['database_tags_enabled'];
|
||||
$current->tags_noprefixes = !(bool) $values['database_tags_noprefixes'];
|
||||
|
||||
if ( ! \IPS\Settings::i()->tags_open_system )
|
||||
{
|
||||
$current->tags_predefined = ( is_array( $values['database_tags_predefined'] ) ) ? implode( ',', array_filter( array_map( 'trim', $values['database_tags_predefined'] ) ) ) : NULL;
|
||||
}
|
||||
}
|
||||
|
||||
$categories = 0;
|
||||
if ( isset( $values['database_featured_categories'] ) )
|
||||
{
|
||||
if ( $values['database_featured_categories'] !== 0 )
|
||||
{
|
||||
$categories = array_keys( $values['database_featured_categories'] );
|
||||
}
|
||||
}
|
||||
|
||||
/* Featured settings */
|
||||
$current->featured_settings = array(
|
||||
'featured' => $values['database_featured_featured'],
|
||||
'perpage' => $values['database_featured_perpage'],
|
||||
'pagination' => $values['database_featured_pagination'],
|
||||
'sort' => $values['database_featured_sort'],
|
||||
'direction' => $values['database_featured_direction'],
|
||||
'categories' => $categories
|
||||
);
|
||||
|
||||
$current->field_sort = $values['database_field_sort'];
|
||||
$current->field_direction = $values['database_field_direction'];
|
||||
$current->field_perpage = $values['database_field_perpage'];
|
||||
|
||||
if ( \IPS\Application::appIsEnabled( 'forums' ) )
|
||||
{
|
||||
$current->forum_record = (int) $values['database_forum_record'];
|
||||
$current->forum_comments = (int) $values['database_forum_comments'];
|
||||
$current->forum_forum = ( ! $values['database_forum_forum'] ) ? 0 : $values['database_forum_forum']->id;
|
||||
$current->forum_prefix = $values['database_forum_prefix'];
|
||||
$current->forum_suffix = $values['database_forum_suffix'];
|
||||
$current->forum_delete = (int) $values['database_forum_delete'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$current->forum_record = 0;
|
||||
$current->forum_comments = 0;
|
||||
$current->forum_delete = 0;
|
||||
}
|
||||
|
||||
$fieldSettingJson = array();
|
||||
|
||||
foreach( $values as $k => $v )
|
||||
{
|
||||
if ( mb_stristr( $k, 'fixed_field_setting__' ) )
|
||||
{
|
||||
$bits = explode( '__', $k );
|
||||
|
||||
$fieldSettingJson[ $bits[1] ][ $bits[2] ] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
$current->fixed_field_settings = $fieldSettingJson;
|
||||
|
||||
$fixedFields = $current->fixed_field_perms;
|
||||
$fixedFields['record_image']['visible'] = $values['database_record_image'];
|
||||
|
||||
foreach( array( 'perm_view', 'perm_2', 'perm_3' ) as $p )
|
||||
{
|
||||
if ( ! isset( $fixedFields['record_image'][ $p ] ) )
|
||||
{
|
||||
$fixedFields['record_image'][ $p ] = '*';
|
||||
}
|
||||
}
|
||||
|
||||
$current->fixed_field_perms = $fixedFields;
|
||||
$current->use_categories = $values['database_use_categories'];
|
||||
|
||||
$current->save();
|
||||
|
||||
/* Make sure we have a default category */
|
||||
$current->default_category = $current->_default_category;
|
||||
|
||||
if ( ! $current->use_categories )
|
||||
{
|
||||
$class = '\IPS\cms\Categories' . $current->id;
|
||||
$category = $class::load( $current->get__default_category() );
|
||||
$category->allow_rating = $values['category_allow_rating'];
|
||||
$category->can_view_others = $values['category_can_view_others'];
|
||||
$category->save();
|
||||
}
|
||||
|
||||
if ( $new )
|
||||
{
|
||||
if ( $values['database_create_page'] === 'new' )
|
||||
{
|
||||
$pageValues = array();
|
||||
|
||||
foreach( $values as $k => $v )
|
||||
{
|
||||
if( mb_strpos( $k, 'page_' ) === 0 )
|
||||
{
|
||||
$pageValues[ $k ] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $values['page_type'] === 'html' )
|
||||
{
|
||||
$pageValues['page_content'] = '{database="' . $current->id . '"}';
|
||||
$pageValues['page_template'] = '';
|
||||
}
|
||||
$pageValues['page_folder_id'] = $pageValues['page_folder_id'] ?: 0;
|
||||
|
||||
$newPage = \IPS\cms\Pages\Page::createFromForm( $pageValues, 'html' );
|
||||
|
||||
if ( $values['page_type'] !== 'html' )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'cms_page_widget_areas', array(
|
||||
'area_page_id' => $newPage->id,
|
||||
'area_widgets' => json_encode( array( array( 'app' => 'cms', 'key' => 'Database', 'unique' => uniqid(), 'configuration' => array( 'database' => $current->id ) ) ) ),
|
||||
'area_area' => 'col1',
|
||||
'area_orientation' => 'horizontal'
|
||||
) );
|
||||
}
|
||||
|
||||
$current->page_id = $newPage->id;
|
||||
$current->save();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Use categories setting may have changed */
|
||||
$current->preLoadWords();
|
||||
\IPS\Member::clearCreateMenu();
|
||||
}
|
||||
|
||||
if ( $new )
|
||||
{
|
||||
\IPS\Session::i()->log( 'acplogs__cms_added_database', array( 'content_db_' . $current->id => TRUE ) );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=databases&controller=databases&do=permissions&id=' . $current->id ) );
|
||||
}
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__cms_edited_database', array( 'content_db_' . $current->id => TRUE ) );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=databases&controller=databases' ), 'saved' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( $current ? "content_db_" . $current->id : 'add', $form, FALSE );
|
||||
\IPS\Output::i()->title = ( $current ) ? \IPS\Member::loggedIn()->language()->addToStack('cms_editing_database', NULL, array( 'sprintf' => array( $current->_title ) ) ) : \IPS\Member::loggedIn()->language()->addToStack('cms_adding_database');
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user