ExpandContract behavior.

Third Party Plugins to CMSimple - how to install, use and create plugins

Moderator: Tata

Tata
Posts: 3587
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

ExpandContract behavior.

Post by Tata » Thu Oct 20, 2016 2:39 pm

From help file of the plugin:
The pages linked via Expandcontract are either

all hidden subpages under the page where the plugin is called (default setting), e.g.:
So far, so gut. But there is an option to heep a page non-published. Which makes the page invisible both in navigation and on the page. The plugin, however, doesn't see any difference and treats the non-pulished pages as hidden - they are showm after {{{expand}} call and expanded.
I wrote about this to svasti. But seems to be ocuppied for now.
Just to let you know. NON-PUBLISHED PAGES ARE NOT HIDDEN FOR THE PLUGIN.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: ExpandContract behavior.

Post by cmb » Thu Oct 20, 2016 3:55 pm

Tata wrote:Just to let you know. NON-PUBLISHED PAGES ARE NOT HIDDEN FOR THE PLUGIN.
Thanks for the info!

That is, however, to be expected for most plugins, because non-published pages are actually converted to hidden pages by CMSimple_XH. Under classic CMSimple (i.e. < 4) they were really removed (in non-edit mode). We tried once to restore the more logical behavior of CMSimple, but there are some edge-cases where it didn't work, so we left it for the time being.
Christoph M. Becker – Plugins for CMSimple_XH

Tata
Posts: 3587
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: ExpandContract behavior.

Post by Tata » Thu Oct 20, 2016 4:32 pm

Well, I tried it with testing the presence of #CMSimple remove#. It seemed logical to me, but the plugin didn't recognize this clause.
I think that it would require some unique mask for non-published pahes in functions.php to be used by any plugin working with anyway hidden pages. The the expandcontract plugin would check if a page is only hidden - and use it for expand/contract if the page is only hidden from navigation or ignore if the page is non-published. In actual stage the plugin can only be used on websits where no page is mporarilly set as inaccessible.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: ExpandContract behavior.

Post by cmb » Thu Oct 20, 2016 5:28 pm

Tata wrote:Well, I tried it with testing the presence of #CMSimple remove#. It seemed logical to me, but the plugin didn't recognize this clause.
Under CMSimple_XH the plugin can't see the #CMSimple remove#, because page_params replaces the page content with #CMSimple hide#. So a plugin can only investigate the page data and check whether a page is unpublished via the page tab. I assume that very few plugins do so. Most plugins simply check for hide(), what is usually correct.
Christoph M. Becker – Plugins for CMSimple_XH

Tata
Posts: 3587
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: ExpandContract behavior.

Post by Tata » Thu Oct 20, 2016 5:42 pm

I fully understand. My point is, that if using plugin that works with hidden pages (e.g. expandcontract), then the webmaster can't work with temporarilly inaccessible pages and the "non-published" feature is worthless for him. It could be very usefull if there would be distinguished between "hidden from navigation" and "non-published". So here is to find the way how the page-params will make the work.
E.g. the page I am rebuilding right now. There is the restaurant menu with dishes in groups with expandible individual items. In actual situation a specific dish won't be offered because of actual inavailability of ingredients. So the admin simply set this very item/page as non-published and it will be temporarilly removed from the menu offered on the webpage.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

Tata
Posts: 3587
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: ExpandContract behavior.

Post by Tata » Thu Oct 20, 2016 5:51 pm

Tata wrote:My point is, that if using plugin that works with hidden pages (e.g. expandcontract)
Not only with hidden pages but also with other editable paramaters.
Maybe a config.php within page_params would make it. Even if accessible only by the plugin itself as a storage for edited parameters. From this file then the plugins could read the settings.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: ExpandContract behavior.

Post by cmb » Fri Oct 21, 2016 7:44 am

Tata wrote:
Tata wrote:My point is, that if using plugin that works with hidden pages (e.g. expandcontract)
Not only with hidden pages but also with other editable paramaters.
Maybe a config.php within page_params would make it. Even if accessible only by the plugin itself as a storage for edited parameters. From this file then the plugins could read the settings.
The information is already stored in the "page data". A plugin can access these data. However, #CMSimple hide# and #CMSimple remove# are not part of the page data, but rather of the content. It might be time to think about dropping support for these special scripts.
Christoph M. Becker – Plugins for CMSimple_XH

Tata
Posts: 3587
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: ExpandContract behavior.

Post by Tata » Fri Oct 21, 2016 8:36 am

cmb wrote:It might be time to think about dropping support for these special scripts.
I think - if these values are stored - it would be very reasonable to make them as much usable as possible.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

Tata
Posts: 3587
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: ExpandContract behavior.

Post by Tata » Fri Oct 21, 2016 9:22 am

Dummy test,
I tried to put in expandcontract index.php

Code: Select all

        $content = str_replace('#CMSimple remove#', '', 'NOT AVAILABLE');
        $content = str_replace('#CMSimple hide#', '', $c[$value]);
or

Code: Select all

        $content = str_replace('#CMSimple hide#', $c[$value]), );
        $content = str_replace('#CMSimple remove#', '', 'NOT AVAILABLE';
In first case all expandable items showed only the message "NOT AVAILABLE". In the second case the non-published pages were shown only with their heading without the page content. The other pages were show normally.
Frankly something like this
[ external image ]
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

Holger
Site Admin
Posts: 3470
Joined: Mon May 19, 2008 7:10 pm
Location: Hessen, Germany

Re: ExpandContract behavior.

Post by Holger » Sat Oct 22, 2016 6:59 pm

Hi Tata,

if I'm right it would be a solution if ExpandContract ignores hidden sub-pages, set "unpublished" via pagedata.
If so, only a few additional lines will do the trick:

Code: Select all

.
.
.
global $s, $cl, $l, $cf, $h, $c, $u, $pd_router, $plugin_cf, $plugin_tx, $bjs; //add $pd_router
.
.
.

if ($l[$i] <= $tl) {
    if (hide($i)) {
        $data = $pd_router->find_page($i); //new
         if ($data['published'] != '0') { //new
             $pageNrArray[] = $i;
          } // new
    }
 }

Below the complete changed code of index.php. Try this for your tests

Code: Select all

<?php
/**
 * Front-end of Expandcontract_XH.
 *
 * @category  CMSimple_XH
 * @author    svasti <svasti@svasti.de>
 * @copyright 2014-16 by svasti <http://svasti.de>
 */

/**
 * Prevent direct access.
 */
if (!defined('CMSIMPLE_XH_VERSION')) {
    header('HTTP/1.0 403 Forbidden');
    exit;
}


function expand($link='',$linktext='',$withheading='',$closebutton='',$limitheight='',$usebuttons='')
{
    global $s, $cl, $l, $cf, $h, $c, $u, $pd_router, $plugin_cf, $plugin_tx, $bjs;

    if ($s < 0) return;

    $o = $t = '';
    $pageNrArray = array();

    $withheading = $withheading!==''? $withheading : $plugin_cf['expandcontract']['show_headings'];
    $closebutton = $closebutton!==''? $closebutton : $plugin_cf['expandcontract']['show_close_button'];
    $limitheight = $limitheight!==''? $limitheight : $plugin_cf['expandcontract']['max_height'];
    $usebuttons  = $usebuttons!==''?  $usebuttons  : $plugin_cf['expandcontract']['use_inline_buttons'];

    // $unikId only to demonstrate different settings on the same page
    $unikId = $withheading . $closebutton . $limitheight . $usebuttons;

    if ($link) {
        if (strpos($link, ',')) { 
            $linklist = explode(',', $link);
            foreach ($linklist as $singlelink) {
                $pageNrArray[] = array_search($singlelink, $h);
            }
            $link = false;
        } else {
            $pageNrArray[] = array_search($link, $h);
        }
    } else {
        $tl = $l[$s] + 1 + $cf['menu']['levelcatch'];
        for ($i = $s + 1; $i < $cl; $i++) {
            if ($l[$i] <= $l[$s]) {
                break;
            }
            if ($l[$i] <= $tl) {
                if (hide($i)) {
                    $data = $pd_router->find_page($i);
                    if ($data['published'] != '0') {
                        $pageNrArray[] = $i;
                    }
                }
            }
            if ($l[$i] < $tl) {
                $tl = $l[$i];
            }
        }
    }


    if (!$link) $o .= "\n\n<!-- E X P A N D - C O N T R A C T    S T A R T -->\n"
                    . '<div class="expand_area">' . "\n";

    foreach ($pageNrArray as $value) {

        $js = '" onclick="expandcontract(\'popup'.$value.$unikId.'\'); return false;';

        $content = str_replace('#CMSimple hide#', '', $c[$value]);
        if (!$withheading) {
            $content = preg_replace("/.*<\/h[1-".$cf['menu']['levels']."]>/isU", "", $content);
        }

        if ($usebuttons) {
            $o .= '<form method="post" class="expand_button" action="?'
               .  $u[$value] . $js . '"><input type="submit" value="';
            $o .= $linktext? $linktext : $h[$value];
            $o .=  '"></form>';
        } else {
            if (!$link) $t .= '<p class="expand_link">';
            $t .= a($value,$js);
            $t .= $linktext? $linktext : $h[$value];
            $t .= '</a>';
            if (!$link) $t .= '</p>' . "\n\n";
        }

        $t .= '<div style="display:none;" id="popup'.$value.$unikId.'" class="expand_content">';
        if ($limitheight) $t .= '<div style="height:'.$limitheight.';overflow-y:scroll;">';
        $t .= $content . '<div style="clear:both"></div>';
        if ($limitheight) $t .= '</div>';
        if ($closebutton) {
            $t .= '<button type="submit" onclick="expandcontract(\'popup'.$value.$unikId.'\');">'
               .  $plugin_tx['expandcontract']['close'] .'</button>';
        }
        $t .= '</div>';
    }
    if ($s >= 0) $o .= evaluate_scripting($t);
    if (!$link) $o .= '</div>' . "\n\n<!-- E X P A N D - C O N T R A C T    E N D -->\n\n\n";

    static $firstExpand = true;
    if ($firstExpand) {
        $firstExpand = false;

        $bjs .= '<script type="text/javascript">
              // <![CDATA[
              function expandcontract(page)
              {
                  if (document.getElementById(page).style.display == \'block\') {
                      document.getElementById(page).style.display = \'none\';
                   } else {';
        if ($plugin_cf['expandcontract']['auto-close']) {
            $bjs .= 'var expandlist = document.getElementsByClassName(\'expand_content\');
                     for (index = 0; index < expandlist.length; ++index) {
                           expandlist[index].style.display = \'none\';
                     }';
        }
        $bjs .= '    document.getElementById(page).style.display = \'block\';
                  }
              }
              // ]]>
              </script>';
    }

    return $o;
}
?>

Post Reply