How to split content in the classic way, pre-1.7.

Please post answers on the most frequently asked questions about CMSimple
Post Reply
chrinux
Posts: 3
Joined: Sun Apr 23, 2017 10:23 am

How to split content in the classic way, pre-1.7.

Post by chrinux » Tue Mar 23, 2021 4:18 pm

Is there a way to split the content/create the menu in the classic way as it was before version 1.7? So, writing the content with h1, h2, ... h6 and get the menu from the headlines without using the page manager.
Thank you,
Christian
--- My suggested solution (25.3.21):

Unfortunately the 1.7-Development has eliminated the previously straightforward functionality of creating the menu by splitting the content by html headlines (as it was until 1.6.10). This adds more complexities and difficulties to the system.

I have written some lines of code (I am not a php programmer) that brings back the classic CMSimple headlines splitting by automatically creating the necessary XH_ml html comments.

Users that are interested can implement the following steps:

1. Set $cf['mode']['advanced'] = "true"; (thank you, Christoph) in cmsimple/config.php.
This shows the XH_ml comments in the code editor of TinyMCE and gives back a bit more control over what is happening behind the scenes.

2. Save the following code to cmsimple/userfuncs.php:

Code: Select all

function create_ml_comments($text){
 global $cf;
 if(!$cf['mode']['advanced']){return $text;}

# $cf['menu']['levels'] (config.php)
# can not be used since it is overwritten in functions.php
$ml = 5;

$text = preg_replace("/<!--XH_ml.*[\n\r]/i",'', $text);
preg_match_all('/(<h[1-'.$ml.'].*?>.*?<\/h[1-'.$ml.']>)/',$text,$hls);
foreach($hls[0] as $headline){
 preg_match('/<h([1-'.$ml.']).*?(title="(.*?)"|)>(.*?)<\/h[1-'.$ml.']>/',$headline,$hls);
$title=$hls[4];
 if($hls[3]!=""){$title=$hls[3];}
 $text =
str_replace($headline,'<!--XH_ml'.$hls[1].':'.$title."-->\n".$headline,$text);
}
return $text;
}
(Please feel free to change and adjust my code.)

3. Put the following line in cmsimple/adminfuncs.php in function XH_saveEditorContents():

$text = create_ml_comments($text);

(I am not sure where the best place is; probably somewhere at the beginning or at the end. I put mine after global...)

As you can see in my code, you can still have an alternative menu entry by using the title option in the html headline tag.

<h1 title="alternative entry for menu">...

1.7-Development may please include this in future releases to return a little simplicity to CMSimple as originally intended by Peter Harteg (simple, small, fast).

Thank you very much and greetings,
Christian
Last edited by chrinux on Thu Mar 25, 2021 9:09 pm, edited 1 time in total.

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

Re: How to split content in the classic way, pre-1.7.

Post by cmb » Tue Mar 23, 2021 5:23 pm

You can enable the advanced mode (in cmsimple/config.php $cf['mode']['advanced']="true";). The format is still slightly different than before XH 1.7, but it's basically the same.
Christoph M. Becker – Plugins for CMSimple_XH

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

Re: How to split content in the classic way, pre-1.7.

Post by Tata » Tue Mar 23, 2021 6:45 pm

Hm, changing the

Code: Select all

$cf['mode']['advanced']="";
to

Code: Select all

$cf['mode']['advanced']="true";
returns
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
when opening the Pagemanager.
Writing a H1 page produces no new menu item. It simply creates a H1 Page heading on an original H1 page.
Also the value

Code: Select all

$cf['mode']['advanced']
seems to be only accessible directly in config.php, but not in the BE-Configuration.
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: 14227
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: How to split content in the classic way, pre-1.7.

Post by cmb » Tue Mar 23, 2021 9:27 pm

Tata wrote:
Tue Mar 23, 2021 6:45 pm
Hm, changing the

Code: Select all

$cf['mode']['advanced']="";
to

Code: Select all

$cf['mode']['advanced']="true";
returns
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
when opening the Pagemanager.
That would be a bug in Pagemanager. Even if it can't deal with advanced mode, it shouldn't fail "arbitrily". I cannot reproduce that error message, though.
Tata wrote:
Tue Mar 23, 2021 6:45 pm
Writing a H1 page produces no new menu item. It simply creates a H1 Page heading on an original H1 page.
Also the value

Code: Select all

$cf['mode']['advanced']
seems to be only accessible directly in config.php, but not in the BE-Configuration.
It was a deliberate decision not to show this configuration option in the backend, since it is likely rarely wanted. And yes, if you use one of the WYSIWYG editors, you won't be able to manipulate the page structure, unless you switch to the source code view (or use Codeeditor_XH, or Settings → Backups → Edit). There you can see:

Code: Select all

<!--XH_ml1:Start-->
<h1>Start</h1>
<p class="xh_success">Congratulations on the successful installation of <strong>CMSimple_XH</strong>.</p>
The HTML comment at the beginning serves the same purpose as h1, h2, h3 before XH 1.7. You can rename the page, e.g.

Code: Select all

<!--XH_ml1:My Start Page-->
<h1>Start</h1>
<p class="xh_success">Congratulations on the successful installation of <strong>CMSimple_XH</strong>.</p>
Or you can delete the whole page by deleting everything that is shown in the source code view. Or you can add new pages.
Christoph M. Becker – Plugins for CMSimple_XH

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

Re: How to split content in the classic way, pre-1.7.

Post by Tata » Tue Mar 23, 2021 9:49 pm

Anyway, the old way pages creation by starting each page with the page name in editor was simple. But the "1.7x" way is basically just as simple. It only requires to understand the principle. I even think, that creating some basic pages structure with the page manager makes more sense, it is safer and also offers more flexibility.
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.

Post Reply