~i', $content); $content = preg_replace('~(.*)'; $pagemanager_h[] = trim(strip_tags($tx['toc']['newpage'])); $pagemanager_no_rename[] = preg_match('/.*?<.*?/isU', $tx['toc']['newpage']); $l[] = 1; $s = 0; return; } foreach ($temp_h as $i => $pagemanager_heading) { if ($pagemanager_heading == '') { $empty++; $pagemanager_heading = $tx['toc']['empty'] . ' ' . $empty; } $pagemanager_h[$i] = $pagemanager_heading; } } /** * Returns plugin version information. * * @return string */ function pagemanager_version() { global $tx; return '

' . $tx['message']['plugin_standard1'] . '

' . $tx['message']['plugin_standard2'] . ' ' . $tx['filetype']['config'] . '

' .tag('hr').'

Pagemanager_XH

'."\n" .'

Version: '.PAGEMANAGER_VERSION.'

'."\n" .'

Author: Copyright © 2011-2012 Christoph M. Becker

'."\n" .'

Adapted for CMSimple 4.0 and higher by ge-webdesign.de

' .'

' .'Pagemanager_XH is powered by ' .'' .'jQuery4CMSimple' .' and jsTree.

'."\n" .'

This program is free software: you can redistribute it and/or modify' .' it under the terms of the GNU General Public License as published by' .' the Free Software Foundation, either version 3 of the License, or' .' (at your option) any later version.

'."\n" .'

This program is distributed in the hope that it will be useful,' .' but WITHOUT ANY WARRANTY; without even the implied warranty of' .' MERCHAN­TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the' .' GNU General Public License for more details.

'."\n" .'

You should have received a copy of the GNU General Public License' .' along with this program. If not, see' .' http://www.gnu.org/licenses/.

'."\n"; } /** * Returns the toolbar. * * @param string $image_ext The image extension (.gif or .png). * @param string $save_js The js code for onclick. * @return string The (x)html. */ function pagemanager_toolbar($image_ext, $save_js) { global $pth, $plugin_cf, $tx; $imgdir = $pth['folder']['plugins'].'pagemanager/images/'; $horizontal = strtolower($plugin_cf['pagemanager']['toolbar_vertical']) != 'true'; $res = '
'."\n"; $toolbar = array('save', 'separator', 'expand', 'collapse', 'separator', 'create', 'create_after', 'rename', 'delete', 'separator', 'cut', 'copy', 'paste', 'paste_after', 'separator', 'help'); foreach ($toolbar as $tool) { $link = ($tool != 'help' ? 'href="#"' : 'href="'.$pth['file']['plugin_help'].'" target="_blank"'); $img = $imgdir.$tool.($tool != 'separator' || !$horizontal ? '' : '_v').$image_ext; $class = $tool == 'separator' ? 'separator' : 'tool'; $res .= ($tool != 'separator' ? '' : '') .($horizontal ? '' : tag('br'))."\n"; } $res .= '
'."\n"; return $res; } /** * Instanciate the pagemanager.js template. * * @param string $image_ext The image extension (.gif or .png). * @return string The (x)html. */ function pagemanager_instanciateJS($image_ext) { global $pth, $plugin_cf, $cf, $tx; $js = rf($pth['folder']['plugins'].'pagemanager/pagemanager.js'); preg_match_all('/<<>>/', $js, $options); foreach ($options[1] as $opt) { $pagemanager_cf[$opt] = addcslashes($plugin_cf['pagemanager'][$opt], "\0'\"\\\f\n\r\t\v"); } preg_match_all('/<<>>/', $js, $options); foreach ($options[1] as $opt) $pagemanager_tx[$opt] = addcslashes($tx['pagemanager'][$opt], "\0'\"\\\f\n\r\t\v"); // replace config variables $js = str_replace('<<>>', 'true', $js); $js = str_replace('<<>>', '200', $js); $js = str_replace('<<>>', 'cmsimple', $js); // replace language variables $js = str_replace('<<>>', $pagemanager_tx["button_cancel"], $js); $js = str_replace('<<>>', $pagemanager_tx["button_delete"], $js); $js = str_replace('<<>>', $pagemanager_tx["button_ok"], $js); $js = str_replace('<<>>', $pagemanager_tx["error_cant_rename"], $js); $js = str_replace('<<>>', $pagemanager_tx["error_offending_extension"], $js); $js = str_replace('<<>>', $pagemanager_tx["message_confirm_deletion"], $js); $js = str_replace('<<>>', $pagemanager_tx["message_confirm_leave"], $js); $js = str_replace('<<>>', $pagemanager_tx["message_delete_last"], $js); $js = str_replace('<<>>', $pagemanager_tx["message_menu_level"], $js); $js = str_replace('<<>>', $pagemanager_tx["message_no_selection"], $js); $js = str_replace('<<>>', $pagemanager_tx["message_warning_leave"], $js); $js = str_replace('<<>>', $pagemanager_tx["op_create"], $js); $js = str_replace('<<>>', $pagemanager_tx["op_create_after"], $js); $js = str_replace('<<>>', $pagemanager_tx["op_rename"], $js); $js = str_replace('<<>>', $pagemanager_tx["op_delete"], $js); $js = str_replace('<<>>', $pagemanager_tx["op_cut"], $js); $js = str_replace('<<>>', $pagemanager_tx["op_copy"], $js); $js = str_replace('<<>>', $pagemanager_tx["op_paste"], $js); $js = str_replace('<<>>', $pagemanager_tx["op_paste_after"], $js); $js = str_replace('<<>>', $pagemanager_tx["treeview_loading"], $js); $js = str_replace('<<>>', $pagemanager_tx["treeview_new"], $js); // replace the rest $js = str_replace('<<>>', $cf['menu']['levels'], $js); $js = str_replace('<<>>', $tx['toc']['dupl'], $js); $js = str_replace('<<>>', $image_ext, $js); $js = str_replace('<<>>', $pth['folder']['plugins'].'pagemanager/images/', $js); return ''."\n" .''."\n"; } /** * Emits the page administration (X)HTML. * * @return void */ function pagemanager_edit() { global $hjs, $pth, $o, $sn, $h, $l, $plugin, $plugin_cf, $tx, $u, $pagemanager_h, $pagemanager_no_rename, $pd_router; include_once($pth['folder']['plugins'].'jquery/jquery.inc.php'); include_jQuery(); include_jQueryUI(); include_jQueryPlugin('jsTree', $pth['folder']['plugins'] .'pagemanager/jstree/jquery.jstree.js'); $image_ext = (file_exists($pth['folder']['plugins'].'pagemanager/images/help.png')) ? '.png' : '.gif'; pagemanager_rfc(); $bo = ''; $swo = '

' .$tx['pagemanager']['error_structure_warning'] .'

' .$tx['pagemanager']['error_structure_confirmation'] .'

'."\n"; $save_js = 'jQuery(\'#pagemanager-xml\')[0].value =' .' jQuery(\'#pagemanager\').jstree(\'get_xml\', \'nest\', -1, new Array(\'id\', \'title\', \'pdattr\'))'; $xhpages = isset($_GET['xhpages']) ? '&pagemanager-xhpages' : ''; $bo .= '
'."\n"; $bo .= strtolower($plugin_cf['pagemanager']['toolbar_show']) == 'true' ? pagemanager_toolbar($image_ext, $save_js) : ''; // output the treeview of the page structure // uses ugly hack to clean up irregular page structure $irregular = FALSE; $pd = $pd_router->find_page(0); $bo .= ''."\n" .'
'."\n" .'
    '."\n".'
  • '.$pagemanager_h[0].''; $stack = array(); for ($i = 1; $i < count($h); $i++) { $ldiff = $l[$i] - $l[$i-1]; if ($ldiff <= 0) { // same level or decreasing $bo .= '
  • '."\n"; if ($ldiff != 0 && count($stack) > 0) { $jdiff = array_pop($stack); if ($jdiff + $ldiff > 0) { array_push($stack, $jdiff + $ldiff); $ldiff = 0; } else { $ldiff += $jdiff - 1; } } for ($j = $ldiff; $j < 0; $j++) $bo .= '
'."\n"; } else { // level increasing if ($ldiff > 1) { array_push($stack, $ldiff); $irregular = TRUE; } $bo .= "\n".'
'."\n"; if ($irregular) $o .= $swo; $o .= $bo; $o .= pagemanager_instanciateJS($image_ext); // HACK?: send 'edit' as query param to prevent the last if clause in // rfc() to insert #CMSimple hide# $o .= tag('input type="hidden" name="admin" value=""')."\n" .tag('input type="hidden" name="action" value="plugin_save"')."\n" .tag('input type="hidden" name="xml" id="pagemanager-xml" value=""')."\n" .tag('input id="pagemanager-submit" type="submit" class="submit" value="' .ucfirst($tx['action']['save']).'"' .' onclick="'.$save_js.'"' .' style="display: none"')."\n" .'
'."\n" .''."\n"; $o .= '
'."\n" .'
'."\n"; } /** * Handles start elements of jsTree's xml result. * * @return void */ function pagemanager_start_element_handler($parser, $name, $attribs) { global $o, $pagemanager_state; if ($name == 'ITEM') { $pagemanager_state['level']++; $pagemanager_state['id'] = $attribs['ID'] == '' ? '' : preg_replace('/(copy_)?pagemanager-([0-9]*)/', '$2', $attribs['ID']); $pagemanager_state['title'] = htmlspecialchars($attribs['TITLE']); $pagemanager_state['pdattr'] = $attribs['PDATTR']; $pagemanager_state['num']++; } } /** * Handles end elements of jsTree's xml result. * * @return void */ function pagemanager_end_element_handler($parser, $name) { global $pagemanager_state; if ($name == 'ITEM') $pagemanager_state['level']--; } /** * Handles character data of jsTree's xml result. * * @return void */ function pagemanager_cdata_handler($parser, $data) { global $c, $h, $cf, $pagemanager_fp, $pagemanager_state, $pagemanager_pd, $pd_router, $plugin_cf; $data = htmlspecialchars($data); if (isset($c[$pagemanager_state['id']])) { $cnt = $c[$pagemanager_state['id']]; $cnt = preg_replace('/]*)>' .'((<[^>]*>)*)[^<]*((<[^>]*>)*)<\/h[1-'.$cf['menu']['levels'].']([^>]*)>/i', '${2}'.addcslashes($pagemanager_state['title'], '$\\').'$4' .'', $cnt, 1); fwrite($pagemanager_fp, rmnl($cnt."\n")); } else { fwrite($pagemanager_fp, ''.$pagemanager_state['title'] .''."\n"); } if ($pagemanager_state['id'] == '') { $pd = $pd_router->new_page(array()); } else { $pd = $pd_router->find_page($pagemanager_state['id']); } $pd['url'] = uenc($pagemanager_state['title']); $pd[$plugin_cf['pagemanager']['pagedata_attribute']] = $pagemanager_state['pdattr']; $pagemanager_pd[] = $pd; } /** * Saves content.htm manually and * pagedata.php via $pd_router->model->refresh(). * * @return void */ function pagemanager_save($xml) { global $pth, $tx, $pd_router, $pagemanager_state, $pagemanager_fp, $pagemanager_pd; $pagemanager_pd = array(); $parser = xml_parser_create('UTF-8'); xml_set_element_handler($parser, 'pagemanager_start_element_handler', 'pagemanager_end_element_handler'); xml_set_character_data_handler($parser, 'pagemanager_cdata_handler'); $pagemanager_state['level'] = 0; $pagemanager_state['num'] = -1; if ($pagemanager_fp = fopen($pth['file']['content'], 'w')) { fputs($pagemanager_fp, 'Content'."\n"); xml_parse($parser, $xml, TRUE); fputs($pagemanager_fp, ''); fclose($pagemanager_fp); $pd_router->model->refresh($pagemanager_pd); } else e('cntwriteto', 'content', $pth['file']['content']); rfc(); // is neccessary, if relocation fails! } /** * Hook into new edit menu of CMSimple_XH 1.5 */ if ($f === 'xhpages' && isset($cf['pagemanager']['external']) && in_array($cf['pagemanager']['external'], array('', 'pagemanager'))) { pagemanager_edit(); } /** * Plugin administration */ if (isset($pagemanager)) { // check requirements (RELEASE-TODO) define('PAGEMANAGER_PHP_VERSION', '4.3.0'); if (version_compare(PHP_VERSION, PAGEMANAGER_PHP_VERSION) < 0) $e .= '
  • '.sprintf($tx['pagemanager']['error_phpversion'], PAGEMANAGER_PHP_VERSION).'
  • '."\n"; foreach (array('pcre', 'xml') as $ext) { if (!extension_loaded($ext)) $e .= '
  • '.sprintf($tx['pagemanager']['error_extension'], $ext).'
  • '."\n"; } if (!file_exists($pth['folder']['plugins'].'jquery/jquery.inc.php')) $e .= '
  • '.$tx['pagemanager']['error_jquery'].'
  • '."\n"; if (strtolower($tx['meta']['codepage']) != 'utf-8') { $e .= '
  • '.$tx['pagemanager']['error_encoding'].'
  • '."\n"; } initvar('admin'); initvar('action'); $o .= print_plugin_admin('on'); switch ($admin) { case '': if ($action == 'plugin_save') { pagemanager_save(stsl($_POST['xml'])); if (!headers_sent()) { header('Location: http://'.$_SERVER['SERVER_NAME'].$sn .(isset($_GET['pagemanager-xhpages']) ? '?&normal&xhpages' : '?&pagemanager&normal&admin=plugin_main')); } exit(); } else { $o .= pagemanager_version(); } break; case 'plugin_main': pagemanager_edit(); break; default: $o .= plugin_admin_common($action, $admin, $plugin); } } ?>