Page 1 of 1
Unprotected page plugin
Posted: Thu Oct 17, 2019 8:35 pm
by Mates-K1
Continue of debate about
issue #1066
What about this way? Stephen, can you please check if the plugin category and class? Are right by your way? And my english?
Code: Select all
<?php
/*
* Unprotected pages
*
* Allows make any page unprotected in private gallery.
*
* @author Stephen Billard (sbillard)
*
* @Copyright 2019 by Stephen L Billard for use in {@link https://%GITHUB% netPhotoGraphics} and derivatives
*
* @pluginCategory tools
*
*/
$plugin_is_filter = 9 | FEATURE_PLUGIN;
$plugin_description = gettext('Allows make any page unprotected in private gallery.');
npgFilters::register('isUnprotectedPage', 'test_protection');
function test_protection($allow, $page) {
switch ($page) {
case 'pages':
global $_CMS_current_page;
return in_array($_CMS_current_page->getTitleLink(), array('predmluva', 'podekovani'));
case 'news':
return true;
break;
}
return $allow;
}
Can you crush to me how to show pages like in gallery setting - unprotected pages part? (have checkbox to check page in plugin setting)
After all, you will teach me to write in PHP through this exercises.
Re: Unprotected page plugin
Posted: Thu Oct 17, 2019 11:26 pm
by stephenbillard
Ok, here you are.
Please ask questions about this code--that is the way you learn. But try to do a little research before asking. For instance look up the functions used to see if you can understand what they do.
Code: Select all
<?php
/*
* Unprotected pages
*
* Allows make any page unprotected in private gallery.
*
* Assumes that the zenpage CMS plugin is enabled!
*
* @author Stephen Billard (sbillard)
*
* @Copyright 2019 by Stephen L Billard for use in {@link https://%GITHUB% netPhotoGraphics} and derivatives
*
* @pluginCategory tools
*
*/
$plugin_is_filter = 9 | FEATURE_PLUGIN;
$plugin_description = gettext('Allows make any page unprotected in private gallery.');
$option_interface = 'unprotectedPages';
npgFilters::register('isUnprotectedPage', 'unprotectedPages::test');
class unprotectedPages {
function getOptionsSupported() {
return array(
gettext('Unprotect') => array(
'key' => 'unprotectedPagesList',
'type' => OPTION_TYPE_CUSTOM,
'desc' => gettext('Check the pages you want to be unprotected.')
)
);
}
function handleOption($option, $currentValue) {
global $_CMS;
if ($option == 'unprotectedPagesList') {
$pages = $_CMS->getPages();
foreach ($pages as $page) {
$list[get_language_string($page['title'])] = $page['titlelink'];
}
$current = getSerializedArray(getOption('unprotectedPages'));
?>
<ul class="shortchecklist">
<?php
generateUnorderedListFromArray($current, $list, 'page_unprotected_', false, true, true);
?>
</ul>
<?php
}
}
function handleOptionSave($themename, $themealbum) {
$unprotected = array();
foreach ($_POST as $option => $value) {
if (strpos($option, 'page_unprotected_') === 0) {
$unprotected[] = $value;
}
}
setOption('unprotectedPages', serialize($unprotected));
}
static function test($allow, $page) {
$unprotected = getSerializedArray(getOption('unprotectedPages'));
switch ($page) {
case 'pages':
global $_CMS_current_page;
return in_array($_CMS_current_page->getTitleLink(), $unprotected);
case 'news':
return true;
break;
}
return $allow;
}
}
Re: Unprotected page plugin
Posted: Fri Oct 18, 2019 8:04 pm
by Mates-K1
Many thanks!!!
Works great.
I have another two questions
1) is possible to make box with list of pages more wider and higher? get rid of at least one of slider? See attachment please.
2) And... is possible to make this plugin as official nPG plugin please?
Thanks for link to demoplugin, I really think it is great source!
I think my Christmas wish will be book about PHP.
Re: Unprotected page plugin
Posted: Sat Oct 19, 2019 12:45 am
by stephenbillard
1. Yes, the box could be made a different size. The UL class "shortchecklist" is what controls this box. You could use a different class and properly define it. The horizontal slider only comes on if your titles are too large, so you could also shorten them.
(NOTE: I have updated the admin.css to give more room on this class--seems other uses can benefit.)
2. If lots of people want this to be official, it could be done. But if you are the only user....
Re: Unprotected page plugin
Posted: Sat Oct 19, 2019 8:32 pm
by stephenbillard
Well, I got interested in this. I have fixed the display size issues and also implemented a new custom option type to simplify this kind of option. I also implemented "public" news categories. (Note that uncategorized news articles are public by default!)
All this means the plugin has a definite dependency on the netPhotoGraphics release, so I have decided to include it as a standard plugin. The name is now "publicCMS". The implementation is in the .07 development release.
Re: Unprotected page plugin
Posted: Sat Oct 19, 2019 9:37 pm
by Mates-K1
Many thanks, Stephen.