Unprotected page plugin

Get help and feedback for everything development and customization related
Post Reply
Mates-K1
Posts: 26
Joined: Tue Aug 28, 2018 9:43 pm
Location: Ústí nad Orlicí, Czech Republic

Unprotected page plugin

Post 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. :mrgreen: :roll:
stephenbillard
Site Admin
Posts: 85
Joined: Tue Aug 14, 2018 6:33 pm
Location: Huntington Beach, CA, USA

Re: Unprotected page plugin

Post 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;
	}

}

-Stephen
Mates-K1
Posts: 26
Joined: Tue Aug 28, 2018 9:43 pm
Location: Ústí nad Orlicí, Czech Republic

Re: Unprotected page plugin

Post 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? :roll:


Thanks for link to demoplugin, I really think it is great source!
I think my Christmas wish will be book about PHP. :D
Attachments
sirka.jpg
sirka.jpg (24.71 KiB) Viewed 3759 times
stephenbillard
Site Admin
Posts: 85
Joined: Tue Aug 14, 2018 6:33 pm
Location: Huntington Beach, CA, USA

Re: Unprotected page plugin

Post 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....
-Stephen
stephenbillard
Site Admin
Posts: 85
Joined: Tue Aug 14, 2018 6:33 pm
Location: Huntington Beach, CA, USA

Re: Unprotected page plugin

Post 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.
-Stephen
Mates-K1
Posts: 26
Joined: Tue Aug 28, 2018 9:43 pm
Location: Ústí nad Orlicí, Czech Republic

Re: Unprotected page plugin

Post by Mates-K1 »

Many thanks, Stephen. :P
Post Reply