Project

General

Profile

1
<?php
2
/**
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 *
18
 * @category        core
19
 * @package         test
20
 * @subpackage      test
21
 * @author          Dietmar Wöllbrink
22
 * @copyright       WebsiteBaker Org. e.V.
23
 * @link            http://websitebaker.org/
24
 * @license         http://www.gnu.org/licenses/gpl.html
25
 * @platform        WebsiteBaker 2.8.4
26
 * @requirements    PHP 5.4 and higher
27
 * @version         $Id: rebuildAccessFiles.php 2 2017-07-02 15:14:29Z Manuela $
28
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb/2.10.x/trunk/admin/pages/rebuildAccessFiles.php $
29
 * @lastmodified    $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
30
 * @created         2016-02-17
31
 *
32
 */
33

    
34
 // Create new admin object and print admin header
35
require( dirname(dirname((__DIR__))).'/config.php' );
36
if ( !class_exists('admin', false) ) { require(WB_PATH.'/framework/class.admin.php'); }
37
if ( !class_exists( 'order', false ) ) { require(WB_PATH.'/framework/class.order.php'); }
38

    
39
// suppress to print the header, so no new FTAN will be set
40
//$admin = new admin('Pages', 'pages_settings',false);
41

    
42
if ( !function_exists( 'create_access_file' ) ) { require(WB_PATH.'/framework/functions.php'); }
43
require (WB_PATH.'/modules/SimpleRegister.php');
44

    
45
//$target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
46
//$pagetree_url = ADMIN_URL.'/pages/index.php';
47

    
48
    function _makeSql($iParentKey = 0)
49
    {
50
        global $oDb, $oReg;
51
        $iParentKey = intval($iParentKey);
52
        $sql  = 'SELECT ( SELECT COUNT(*) '
53
              .          'FROM `'.$oReg->TablePrefix.'pages` `x` '
54
              .          'WHERE x.`parent`=p.`page_id`'
55
              .        ') `children`, '
56
              .        's.`module`, MAX(s.`publ_start` + s.`publ_end`) published, p.`link`, '
57
              .        '(SELECT MAX(`position`) FROM `'.$oReg->TablePrefix.'pages` '
58
              .        'WHERE `parent`='.$iParentKey.') max_position, '
59
              .        '0 min_position, '
60
              .        'p.`position`, '
61
              .        'p.`page_id`, p.`parent`, p.`level`, p.`language`, p.`admin_groups`, '
62
              .        'p.`admin_users`, p.`viewing_groups`, p.`viewing_users`, p.`visibility`, '
63
              .        'p.`menu_title`, p.`page_title`, p.`page_trail`, p.`modified_when`, '
64
              .        'GROUP_CONCAT(CAST(CONCAT(s.`section_id`, \' - \', s.`module`) AS CHAR) ORDER BY s.`position` SEPARATOR \'\n\') `section_list` '
65
              . 'FROM `'.$oReg->TablePrefix.'pages` p '
66
              .    'INNER JOIN `'.$oReg->TablePrefix.'sections` s '
67
              .    'ON p.`page_id`=s.`page_id` '
68
              . 'WHERE `parent`='.$iParentKey.' '
69
              .    (($oReg->PageTrash != 'inline') ? 'AND `visibility`!=\'deleted\' ' : '')
70
              . 'GROUP BY p.`page_id` '
71
              . 'ORDER BY p.`position` ASC';
72
        return $sql;
73
    }
74

    
75
    function _IterateTree($iParent = 0)
76
    {
77
        global $oDb, $oReg, $_queries, $index,$aOutput;
78
      // Get page list from database
79
        if(($oPages = $oDb->query(_makeSql($iParent))))
80
        {
81
            $_queries++;
82
            $iMinPosition = 1;
83
            while($aPage = $oPages->fetchRow(MYSQLI_ASSOC))
84
            { // iterate through the current branch
85
                if($oReg->PageLevelLimit && ($aPage['level'] > $oReg->PageLevelLimit)) {
86
                    break;
87
                }
88

    
89
                // array for sitemap
90
                $aOutput[$aPage['page_id']] = array(
91
                'loc' => $oReg->AppUrl.$oReg->PagesDir.trim($aPage['link'],'/').$oReg->PageExtension,
92
                'lastmod' => date(DATE_W3C, (int)$aPage['modified_when']),
93
                'changefreq' => 'monthly',
94
                'priority' => '0.5'
95
                );
96

    
97
                // array to create accessfiles
98
                $aOutput[$aPage['page_id']] = $aPage;
99
                // could not use oReg, we are needing backslashes to create access files
100
                $sPageFile = WB_PATH.PAGES_DIRECTORY.'/'.trim($aPage['link'],'/').$oReg->PageExtension;
101
                if( is_writeable( $sPageFile ) || !file_exists( $sPageFile ) ) {
102
                    create_access_file( $sPageFile, $aPage['page_id'], $aPage['level']);
103
                    $index++; //
104
                }
105

    
106
                if((int)$aPage['children'] > 0 ) {
107
                    _IterateTree($aPage['page_id']);
108
                }
109
          }
110
        }
111
        return $aOutput;
112
    }
113

    
114
      $_queries  = $index = 0;
115
      $iTreeRoot = 0;
116
      $aOutput   = array();
117
      $aPageTree = array();
118

    
119
      $aPageTree = _IterateTree($iTreeRoot);
120

    
121
      echo '<h3>Creating '.$index.' access files</h3>';
(16-16/25)