853 |
853 |
854 function get_page_groups($page_id, $namespace) |
854 function get_page_groups($page_id, $namespace) |
855 { |
855 { |
856 global $db, $session, $paths, $template, $plugins; // Common objects |
856 global $db, $session, $paths, $template, $plugins; // Common objects |
857 |
857 |
858 $page_id = $db->escape(sanitize_page_id($page_id)); |
858 static $cache = array(); |
|
859 |
|
860 if ( count($cache) == 0 ) |
|
861 { |
|
862 foreach ( $this->nslist as $key => $_ ) |
|
863 { |
|
864 $cache[$key] = array(); |
|
865 } |
|
866 } |
|
867 |
859 if ( !isset($this->nslist[$namespace]) ) |
868 if ( !isset($this->nslist[$namespace]) ) |
860 die('$paths->get_page_groups(): HACKING ATTEMPT: namespace "'. htmlspecialchars($namespace) .'" doesn\'t exist'); |
869 die('$paths->get_page_groups(): HACKING ATTEMPT: namespace "'. htmlspecialchars($namespace) .'" doesn\'t exist'); |
861 |
870 |
|
871 $page_id_unescaped = $paths->nslist[$namespace] . |
|
872 dirtify_page_id($page_id); |
|
873 $page_id_str = $paths->nslist[$namespace] . |
|
874 sanitize_page_id($page_id); |
|
875 |
|
876 $page_id = $db->escape(sanitize_page_id($page_id)); |
|
877 |
|
878 if ( isset($cache[$namespace][$page_id]) ) |
|
879 { |
|
880 return $cache[$namespace][$page_id]; |
|
881 } |
|
882 |
862 $group_list = array(); |
883 $group_list = array(); |
863 |
884 |
864 // What linked categories have this page? |
885 // What linked categories have this page? |
865 $q = $db->sql_query('SELECT g.pg_id FROM '.table_prefix.'page_groups AS g |
886 $q = $db->sql_unbuffered_query('SELECT g.pg_id, g.pg_type, g.pg_target FROM '.table_prefix.'page_groups AS g |
866 LEFT JOIN '.table_prefix.'categories AS c |
887 LEFT JOIN '.table_prefix.'categories AS c |
867 ON ( ( c.category_id = g.pg_target AND g.pg_type = ' . PAGE_GRP_CATLINK . ' ) OR c.category_id IS NULL ) |
888 ON ( ( c.category_id = g.pg_target AND g.pg_type = ' . PAGE_GRP_CATLINK . ' ) OR c.category_id IS NULL ) |
868 LEFT JOIN '.table_prefix.'page_group_members AS m |
889 LEFT JOIN '.table_prefix.'page_group_members AS m |
869 ON ( ( g.pg_id = m.pg_id AND g.pg_type = ' . PAGE_GRP_NORMAL . ' ) OR ( m.pg_id IS NULL ) ) |
890 ON ( ( g.pg_id = m.pg_id AND g.pg_type = ' . PAGE_GRP_NORMAL . ' ) OR ( m.pg_id IS NULL ) ) |
870 LEFT JOIN '.table_prefix.'tags AS t |
891 LEFT JOIN '.table_prefix.'tags AS t |
871 ON ( ( t.tag_name = g.pg_target AND pg_type = ' . PAGE_GRP_TAGGED . ' ) OR t.tag_name IS NULL ) |
892 ON ( ( t.tag_name = g.pg_target AND pg_type = ' . PAGE_GRP_TAGGED . ' ) OR t.tag_name IS NULL ) |
872 WHERE |
893 WHERE |
873 ( c.page_id=\'' . $page_id . '\' AND c.namespace=\'' . $namespace . '\' ) OR |
894 ( c.page_id=\'' . $page_id . '\' AND c.namespace=\'' . $namespace . '\' ) OR |
874 ( t.page_id=\'' . $page_id . '\' AND t.namespace=\'' . $namespace . '\' ) OR |
895 ( t.page_id=\'' . $page_id . '\' AND t.namespace=\'' . $namespace . '\' ) OR |
875 ( m.page_id=\'' . $page_id . '\' AND m.namespace=\'' . $namespace . '\' );'); |
896 ( m.page_id=\'' . $page_id . '\' AND m.namespace=\'' . $namespace . '\' ) OR |
|
897 ( g.pg_type = ' . PAGE_GRP_REGEX . ' );'); |
876 if ( !$q ) |
898 if ( !$q ) |
877 $db->_die(); |
899 $db->_die(); |
878 |
900 |
879 while ( $row = $db->fetchrow() ) |
901 while ( $row = $db->fetchrow() ) |
880 { |
902 { |
881 $group_list[] = $row['pg_id']; |
903 if ( $row['pg_type'] == PAGE_GRP_REGEX ) |
|
904 { |
|
905 //echo "<debug> matching page " . htmlspecialchars($page_id_unescaped) . " against regex <tt>" . htmlspecialchars($row['pg_target']) . "</tt>."; |
|
906 if ( @preg_match($row['pg_target'], $page_id_unescaped) || @preg_match($row['pg_target'], $page_id_str) ) |
|
907 { |
|
908 //echo "..matched"; |
|
909 $group_list[] = $row['pg_id']; |
|
910 } |
|
911 //echo "<br />"; |
|
912 } |
|
913 else |
|
914 { |
|
915 $group_list[] = $row['pg_id']; |
|
916 } |
882 } |
917 } |
883 |
918 |
884 $db->free_result(); |
919 $db->free_result(); |
885 |
920 |
886 /* |
921 $cache[$namespace][$page_id] = $group_list; |
887 // Static-page groups |
|
888 $q = $db->sql_query('SELECT g.pg_id FROM '.table_prefix.'page_groups AS g |
|
889 LEFT JOIN '.table_prefix.'page_group_members AS m |
|
890 ON ( g.pg_id = m.pg_id ) |
|
891 WHERE m.page_id=\'' . $page_id . '\' AND m.namespace=\'' . $namespace . '\' |
|
892 GROUP BY g.pg_id;'); |
|
893 |
|
894 if ( !$q ) |
|
895 $db->_die(); |
|
896 |
|
897 while ( $row = $db->fetchrow() ) |
|
898 { |
|
899 $group_list[] = $row['pg_id']; |
|
900 } |
|
901 |
|
902 // Tag groups |
|
903 |
|
904 $q = $db->sql_query('SELECT g.pg_id FROM '.table_prefix.'page_groups AS g |
|
905 LEFT JOIN '.table_prefix.'tags AS t |
|
906 ON ( t.tag_name = g.pg_target AND pg_type = ' . PAGE_GRP_TAGGED . ' ) |
|
907 WHERE t.page_id = \'' . $page_id . '\' AND t.namespace = \'' . $namespace . '\';'); |
|
908 if ( !$q ) |
|
909 $db->_die(); |
|
910 |
|
911 while ( $row = $db->fetchrow() ) |
|
912 { |
|
913 $group_list[] = $row['pg_id']; |
|
914 } |
|
915 */ |
|
916 |
922 |
917 return $group_list; |
923 return $group_list; |
918 |
924 |
919 } |
925 } |
920 |
926 |