Пример #1
0
Файл: web.php Проект: rigidus/ea
 public function loadPageData()
 {
     $arr_t = self::$page_tree;
     unset($arr_t[0], $arr_t[1]);
     $arr = array();
     $arr[0] = self::$page_tree[0];
     $arr[1] = self::$page_tree[1];
     $i = 2;
     foreach ($arr_t as $k => $v) {
         $v = string::clearBoth($v);
         $t = explode('/', $v);
         $count = count($t);
         $tt = array();
         $g = array();
         // start matrix
         for ($z = 1; $z <= $count; $z++) {
             $g = $t;
             $g[$z] = str_replace($t[$z], '[dynamic]', $t[$z]);
             $tt = implode('/', $g);
             $arr[$i] = '/' . string::clearBoth($tt) . '/';
             $i++;
         }
         $matrix = array();
         $x = 1;
         $y = 2;
         for ($z = 0; $z < $count * 2; $z++) {
             $m = $x + $y;
             if ($m < $count) {
                 $matrix[] = array($x, $m);
                 $y++;
             } elseif ($m == $count) {
                 $x++;
                 $y = 2;
             }
         }
         foreach ($matrix as $u => $r) {
             $g = $t;
             $g[$r[0]] = str_replace($t[$r[0]], '[dynamic]', $t[$r[0]]);
             $g[$r[1]] = str_replace($t[$r[1]], '[dynamic]', $t[$r[1]]);
             $tt = implode('/', $g);
             $arr[$i] = '/' . string::clearBoth($tt) . '/';
             $i++;
         }
         // end matrix
     }
     $list_path = "";
     foreach ($arr as $v) {
         if (!empty($v)) {
             $list_path .= "'" . $v . "',";
         }
     }
     $list_path = ereg_replace(",\$", "", $list_path);
     db::table('pages');
     db::join('templates', 'pages', 'tmpl_id');
     db::where('page_folder', $list_path, 'IN');
     db::where('site_id', SITE_ID, '=', 'pages');
     db::order('page_level');
     $res = db::select();
     $t_pages = array();
     $path_pages = array();
     if (db::rows() > 0) {
         while ($row = mysql_fetch_assoc($res)) {
             $t_pages[] = $row;
         }
     }
     $max_level = arrays::maxKey($t_pages, 'page_level');
     $new_array = arrays::sliceByKey($t_pages, $max_level, 'page_level');
     $tested = array();
     $et = explode('/', string::clearBoth(URI_SELF));
     /*
     	Data of current page
     */
     if ($new_array) {
         foreach ($new_array as $k => $v) {
             $folder = explode('/', string::clearBoth($v['page_folder']));
             $tested[$k] = 0;
             foreach ($folder as $d => $f) {
                 if (isset($et[$d])) {
                     if ($f == $et[$d]) {
                         $tested[$k]++;
                     }
                 }
             }
         }
         $path_pages[] = self::$page = $t_pages[arrays::maxValueKey($tested)];
     } else {
         $path_pages[] = self::$page = arrays::lastValue($t_pages);
     }
     $t_pages = array_reverse($t_pages);
     $parent = self::$page['page_parent'];
     if ($parent != 0) {
         foreach ($t_pages as $k => $v) {
             if ($v['page_id'] != $parent && $v['page_folder'] != '/') {
                 unset($t_pages[$k]);
             } else {
                 $path_pages[] = $v;
                 $parent = $v['page_parent'];
             }
         }
     }
     self::$pages = array_reverse($path_pages);
     unset($t_pages, $path_pages);
 }