Skip to content

Commit

Permalink
Closes #5303 - Rewrite of prefs page to use admin-ui.
Browse files Browse the repository at this point in the history
  • Loading branch information
CaMer0n committed Jul 26, 2024
1 parent 7871b9d commit ee69952
Showing 1 changed file with 92 additions and 17 deletions.
109 changes: 92 additions & 17 deletions e107_admin/newspost.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class news_admin extends e_admin_dispatcher
'cat/create' => 'H|H3|H4|H5',
'cat/edit' => 'H|H4', // edit button and inline editing in list mode.
'cat/delete' => 'H|H5', // delete button in list mode.
'main/settings' => '0',
'main/prefs' => '0',
'sub/list' => 'N'
);

Expand All @@ -84,7 +84,7 @@ class news_admin extends e_admin_dispatcher
'cat/list' => array('caption'=> LAN_CATEGORIES, 'icon'=> 'folder'), // Create Category.
'cat/create' => array('caption'=> LAN_NEWS_63, 'icon'=> 'fas-folder-plus'), // Category List
'other2' => array('divider'=> true),
'main/settings' => array('caption'=> LAN_PREFS, 'icon'=>'fa-cog'), // Preferences
'main/prefs' => array('caption'=> LAN_PREFS, 'icon'=>'fa-cog'), // Preferences
// 'main/submitted' => array('caption'=> LAN_NEWS_64, 'perm' => 'N'), // Submitted News
'sub/list' => array('caption'=> NWSLAN_47, 'icon'=>'fa-user-edit'), // Submitted News
// 'main/maint' => array('caption'=> LAN_NEWS_55, 'perm' => '0') // Maintenance
Expand Down Expand Up @@ -484,15 +484,31 @@ class news_admin_ui extends e_admin_ui

protected $fieldpref = array('checkboxes','news_id', 'news_thumbnail', 'news_title', 'news_datestamp', 'news_category', 'news_class', 'options');

/* //TODO
protected $prefs = array(
protected $preftabs = ['general'=>LAN_GENERAL,'subnews'=>LAN_NEWS_101];

protected $prefs = [
'news_default_template' => ['title' => NWSLAN_127, 'type' => 'dropdown', 'data'=>'safestr', 'help' => LAN_NEWS_88, 'tab' => 'general'],
'newsposts' => ['title' => NWSLAN_88, 'type' => 'dropdown', 'data'=>'int', 'tab' => 'general'],
'news_list_limit' => ['title' => LAN_NEWS_91, 'type' => 'dropdown', 'data'=>'int', 'help' => LAN_NEWS_92, 'tab' => 'general'],
'news_list_templates' => ['title' => LAN_NEWS_93, 'type' => 'checkboxes', 'help' => LAN_NEWS_94, 'tab' => 'general'],
'news_pagination' => ['title' => LAN_PAGINATION, 'type' => 'dropdown', 'data'=>'safestr', 'help' => LAN_NEWS_112, 'tab' => 'general'],
'news_cache_timeout' => ['title' => LAN_NEWS_110, 'type' => 'number', 'data'=>'int', 'help' => LAN_NEWS_111, 'tab' => 'general'],
'news_cats' => ['title' => NWSLAN_86, 'type' => 'boolean', 'data'=>'int', 'tab' => 'general'],
'nbr_cols' => ['title' => NWSLAN_87, 'type' => 'dropdown', 'data'=>'int', 'tab' => 'general'],
'newsposts_archive' => ['title' => NWSLAN_115, 'type' => 'dropdown', 'data'=>'int', 'help' => NWSLAN_116, 'tab' => 'general'],
'newsposts_archive_title' => ['title' => NWSLAN_117, 'type' => 'text', 'data'=>'safestr', 'tab' => 'general'],
'news_editauthor' => ['title' => LAN_NEWS_51, 'type' => 'userclass', 'data'=>'int', 'tab' => 'general', 'writeParms'=>['classlist'=>'nobody,main,admin,classes']],
'news_newdateheader' => ['title' => NWSLAN_111, 'type' => 'boolean', 'data'=>'int', 'help' => NWSLAN_112, 'tab' => 'general'],
'news_unstemplate' => ['title' => NWSLAN_113, 'type' => 'boolean', 'data'=>'int', 'help' => NWSLAN_114, 'tab' =>'general'],
'subnews_class' => ['title' => NWSLAN_106, 'type' => 'userclass','data'=>'int', 'tab' => 'subnews', 'writeParms'=>['classlist'=>'nobody,public,guest,member,admin,classes'] ],
'subnews_htmlarea' => ['title' => NWSLAN_107, 'type' => 'boolean', 'data'=>'int', 'tab' => 'subnews'],
'subnews_attach' => ['title' => NWSLAN_100, 'type' => 'boolean', 'data'=>'int', 'tab' => 'subnews'],
'subnews_attach_minsize' => ['title' => LAN_NEWS_99, 'type' => 'dropdown', 'tab' => 'subnews'],
'subnews_resize' => ['title' => NWSLAN_101, 'type' => 'number', 'data'=>'int', 'tab' => 'subnews', 'writeParms' => ['maxlength'=>5] ],
'news_subheader' => ['title' => NWSLAN_120, 'type' => 'bbarea', 'tab' => 'subnews']

];

'news_category' => array('title' => NWSLAN_127, 'type' => 'dropdown', 'help'=> "Determines how the default news page should appear."),
);
*/

protected $cats = array();
protected $newspost;
protected $addons = array();
Expand Down Expand Up @@ -862,13 +878,13 @@ function init()
{

$this->addons = e107::getAddonConfig('e_admin',null, 'config', $this);

/*
if(!empty($_POST['save_prefs']))
{
$this->saveSettings();
}
}*/

if(e_DEBUG == true) // allowing manual fixing of comment total in DEBUG mode.
if(deftrue('e_DEBUG')) // allowing manual fixing of comment total in DEBUG mode.
{
$this->fields['news_comment_total']['noedit'] = false;
$this->fields['news_comment_total']['inline'] = true;
Expand Down Expand Up @@ -964,8 +980,67 @@ function CreateObserver()
$this->initSEOFields();
}

function beforePrefsSave($new_data, $old_data)
{

$new_data['news_default_template'] = preg_replace('#[^\w\pL\-]#u', '', $new_data['news_default_template']);

function saveSettings()
return $new_data;
}

function afterPrefsSave()
{
$this->clearCache();
}
function PrefsObserver()
{
parent::PrefsObserver();

$newsTemplates = array();
$pref = e107::getPref();

if($newInfo = e107::getTemplateInfo('news', 'news', null, 'front', true)) //TODO 'category'=>'Categories'? research 'Use non-standard template for news layout' and integrate here.
{
foreach($newInfo as $k=>$val)
{
$newsTemplates[$k] = $val['title'];
}

}
else
{
$newsTemplates = array('default'=>LAN_DEFAULT, 'list'=>LAN_LIST);
}

$imageSizes = array(

'400×300' => '400x300',
'640×480' => '640x480',
'800×600' => '800x600',
'1024×768' => '1024x768',
'1600×1200' => '2 MP (1600×1200)',
'2272×1704' => '4 MP (2272×1704)',
'2816×2112' => '6 MP (2816×2112)',
'3264×2448' => '8 MP (3264×2448)',
// 10 MP (3648×2736)
// 12 MP (4096×3072)

);

$this->prefs['news_default_template']['writeParms']['optArray'] = $newsTemplates;
$this->prefs['newsposts']['writeParms']['optArray'] = $this->_optrange(50, false);
$this->prefs['news_list_limit']['writeParms']['optArray'] = $this->_optrange(50, false);
$this->prefs['news_list_templates']['writeParms'] = ['optArray' => $this->news_renderTypes, 'useKeyValues' => 1];
$this->prefs['news_pagination']['writeParms'] = ['optArray' => ['record'=> "Record", 'page'=>'Page'], 'value'=>varset($pref['news_pagination'],'record')];
$this->prefs['nbr_cols']['writeParms']['optArray'] = $this->_optrange(6, false);
$this->prefs['newsposts_archive']['writeParms']['optArray'] = $this->_optrange(intval($pref['newsposts']) - 1);

$this->prefs['subnews_attach_minsize']['writeParms']['optArray'] = $imageSizes;


}

/*function saveSettings()
{
if(!getperms('0'))
{
Expand Down Expand Up @@ -1002,7 +1077,7 @@ function saveSettings()
e107::getLog()->logArrayDiffs($temp, e107::getPref(), 'NEWS_06');
$this->clearCache();
}
}
}*/



Expand All @@ -1023,7 +1098,7 @@ private function _optrange($num, $zero = true)
return $tmp;
}

function settingsPage()
/* function settingsPage()
{
// return $this->newspost->show_news_prefs();
Expand Down Expand Up @@ -1251,7 +1326,7 @@ function settingsPage()
return e107::getMessage()->render().$text;
// e107::getRender()->tablerender(NWSLAN_90, e107::getMessage()->render().$text);
}
}*/


function noPermissions($qry = '')
Expand Down

0 comments on commit ee69952

Please sign in to comment.