1 | <?php |
---|
2 | if (!defined('LINKEDPAGES_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | /** |
---|
5 | * add a tab on album properties page |
---|
6 | */ |
---|
7 | function linked_pages_tabsheet_before_select($sheets, $id) |
---|
8 | { |
---|
9 | if ($id == 'album') |
---|
10 | { |
---|
11 | $sheets['linked_pages'] = array( |
---|
12 | 'caption' => l10n('Linked Pages'), |
---|
13 | 'url' => LINKEDPAGES_ADMIN.'-album-'.$_GET['cat_id'], |
---|
14 | ); |
---|
15 | } |
---|
16 | |
---|
17 | return $sheets; |
---|
18 | } |
---|
19 | |
---|
20 | /** |
---|
21 | * display menu a album page/additional page |
---|
22 | */ |
---|
23 | function linked_pages_loc_end_index() |
---|
24 | { |
---|
25 | global $page, $user, $template, $conf; |
---|
26 | |
---|
27 | if (isset($page['section']) and $page['section']=='categories' and isset($page['category'])) |
---|
28 | { |
---|
29 | $where_clauses = array('category_id = '.$page['category']['id']); |
---|
30 | |
---|
31 | if (!is_admin()) |
---|
32 | { |
---|
33 | if ($conf['AP']['language_perm']) |
---|
34 | { |
---|
35 | $where_clauses[] = '(ap.lang = NULL OR ap.lang = "'.$user['language'].'")'; |
---|
36 | } |
---|
37 | if ($conf['AP']['level_perm']) |
---|
38 | { |
---|
39 | $where_clauses[] = 'ap.level <= '.$user['level']; |
---|
40 | } |
---|
41 | if ($conf['AP']['user_perm']) |
---|
42 | { |
---|
43 | $where_clauses[] = 'ap.users LIKE "%'.$user['status'].'%"'; |
---|
44 | } |
---|
45 | if ($conf['AP']['group_perm']) |
---|
46 | { |
---|
47 | $query = ' |
---|
48 | SELECT group_id |
---|
49 | FROM '.USER_GROUP_TABLE.' |
---|
50 | WHERE user_id = '.$user['id'].' |
---|
51 | ;'; |
---|
52 | $user_groups = query2array($query, null, 'group_id'); |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | $query = ' |
---|
57 | SELECT |
---|
58 | lp.*, |
---|
59 | ap.lang, |
---|
60 | ap.title, |
---|
61 | ap.standalone, |
---|
62 | ap.permalink, |
---|
63 | ap.groups |
---|
64 | FROM '.LINKEDPAGES_TABLE.' AS lp |
---|
65 | INNER JOIN '.ADD_PAGES_TABLE.' AS ap |
---|
66 | ON lp.page_id = ap.id |
---|
67 | WHERE |
---|
68 | '.implode("\n AND ", $where_clauses).' |
---|
69 | ORDER BY lp.pos |
---|
70 | ;'; |
---|
71 | $result = pwg_query($query); |
---|
72 | |
---|
73 | if (!pwg_db_num_rows($result)) |
---|
74 | { |
---|
75 | return; |
---|
76 | } |
---|
77 | |
---|
78 | while ($row = pwg_db_fetch_assoc($result)) |
---|
79 | { |
---|
80 | if (!is_admin() and $conf['AP']['group_perm'] and !empty($row['groups'])) |
---|
81 | { |
---|
82 | $authorized = false; |
---|
83 | foreach (explode(',',$row['groups']) as $group_id) |
---|
84 | { |
---|
85 | if (in_array($group_id, $user_groups)) |
---|
86 | { |
---|
87 | $authorized = true; |
---|
88 | break; |
---|
89 | } |
---|
90 | } |
---|
91 | if (!$authorized) continue; |
---|
92 | } |
---|
93 | |
---|
94 | $row['U_PAGE'] = make_index_url(array('section'=>'page')).'/'.(isset($row['permalink']) ? $row['permalink'] : $row['page_id']); |
---|
95 | $row['TITLE'] = trigger_change('AP_render_title', $row['title']); |
---|
96 | $template->append('category_pages', $row); |
---|
97 | } |
---|
98 | |
---|
99 | $template->assign('LINKEDPAGES_PATH', LINKEDPAGES_PATH); |
---|
100 | $template->set_filename('linked_pages_content', realpath(LINKEDPAGES_PATH . 'template/index_menu.tpl')); |
---|
101 | $template->assign('PLUGIN_INDEX_CONTENT_BEGIN', $template->parse('linked_pages_content',true).$template->get_template_vars('PLUGIN_INDEX_CONTENT_BEGIN')); |
---|
102 | |
---|
103 | } |
---|
104 | else if (isset($page['section']) and $page['section']=='additional_page' and isset($page['additional_page'])) |
---|
105 | { |
---|
106 | $where_clauses = array('page_id = '.$page['additional_page']['id']); |
---|
107 | |
---|
108 | if (!is_admin()) |
---|
109 | { |
---|
110 | $where_clauses[] = 'lp.category_id NOT IN('.$user['forbidden_categories'].')'; |
---|
111 | } |
---|
112 | |
---|
113 | $query = ' |
---|
114 | SELECT |
---|
115 | lp.*, |
---|
116 | cat.name, |
---|
117 | cat.permalink |
---|
118 | FROM '.LINKEDPAGES_TABLE.' AS lp |
---|
119 | INNER JOIN '.CATEGORIES_TABLE.' AS cat |
---|
120 | ON lp.category_id = cat.id |
---|
121 | WHERE |
---|
122 | '.implode("\n AND ", $where_clauses).' |
---|
123 | ORDER BY lp.pos |
---|
124 | ;'; |
---|
125 | $result = pwg_query($query); |
---|
126 | |
---|
127 | if (!pwg_db_num_rows($result)) |
---|
128 | { |
---|
129 | return; |
---|
130 | } |
---|
131 | |
---|
132 | while ($row = pwg_db_fetch_assoc($result)) |
---|
133 | { |
---|
134 | $row['U_PAGE'] = make_index_url( |
---|
135 | array( |
---|
136 | 'category' => array( |
---|
137 | 'id' => $row['category_id'], |
---|
138 | 'name' => $row['name'], |
---|
139 | 'permalink' => $row['permalink'], |
---|
140 | ) |
---|
141 | ) |
---|
142 | ); |
---|
143 | $row['TITLE'] = trigger_change('render_category_name', $row['name']); |
---|
144 | $template->append('category_pages', $row); |
---|
145 | } |
---|
146 | |
---|
147 | $template->assign('LINKEDPAGES_PATH', LINKEDPAGES_PATH); |
---|
148 | $template->set_filename('linked_pages_content', realpath(LINKEDPAGES_PATH . 'template/index_menu.tpl')); |
---|
149 | $template->assign('PLUGIN_INDEX_CONTENT_BEGIN', $template->parse('linked_pages_content',true).$template->get_template_vars('PLUGIN_INDEX_CONTENT_BEGIN')); |
---|
150 | } |
---|
151 | } |
---|