1 | <?php |
---|
2 | defined('MPS_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | |
---|
5 | |
---|
6 | |
---|
7 | /* |
---|
8 | * button on album and photos pages |
---|
9 | */ |
---|
10 | function mps_add_button() |
---|
11 | { |
---|
12 | global $template, $conf; |
---|
13 | |
---|
14 | $query='SELECT * FROM '.MPS_CONF_TABLE.';'; |
---|
15 | $result = pwg_query($query); |
---|
16 | while($row = pwg_db_fetch_assoc($result)){ |
---|
17 | $config = $row ; |
---|
18 | } |
---|
19 | |
---|
20 | $template->assign(array( |
---|
21 | 'mps_conf' => $config, |
---|
22 | 'MPS_PATH' => MPS_PATH, |
---|
23 | )); |
---|
24 | // $template->assign('MPS_PATH', MPS_PATH); |
---|
25 | $template->set_filename('mps_button', realpath(MPS_PATH.'template/button_basket.tpl')); |
---|
26 | // $template->assign('mps_conf' , $config); |
---|
27 | |
---|
28 | $button = $template->parse('mps_button', true); |
---|
29 | |
---|
30 | if (script_basename()=='index') |
---|
31 | { |
---|
32 | $template->add_index_button($button, EVENT_HANDLER_PRIORITY_NEUTRAL); |
---|
33 | } |
---|
34 | else |
---|
35 | { |
---|
36 | $template->add_picture_button($button, EVENT_HANDLER_PRIORITY_NEUTRAL); |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | /** |
---|
41 | * add a forms on photo page |
---|
42 | */ |
---|
43 | function mps_loc_end_picture() |
---|
44 | { |
---|
45 | global $template; |
---|
46 | $template->set_filename('MyPiwiShop', realpath(MPS_PATH.'template/MyPiwiShop.tpl')); |
---|
47 | $template->assign_var_from_handle('MPS_CONTENT', 'MyPiwiShop'); |
---|
48 | } |
---|
49 | |
---|
50 | function mps_picture_form($content) |
---|
51 | { |
---|
52 | $search = '#</div>(\s*)</div>(\s*){if isset\(\$COMMENT_COUNT\)}#s'; |
---|
53 | $replace = '</div>$1</div>$2<div id="MyPiwiShop">{$MPS_CONTENT}</div>{if isset(\$COMMENT_COUNT)}'; |
---|
54 | |
---|
55 | return preg_replace($search, $replace, $content); |
---|
56 | } |
---|
57 | |
---|
58 | function mps_picture_form_piwitheme($content) |
---|
59 | { |
---|
60 | $search = '#{/foreach}(\s*){/foreach}(\s*)</table>(\s*){/if}(\s*)</div>#s'; |
---|
61 | $replace = '{/foreach}$1{/foreach}$1</table>$1{/if}</div><div class="panelPP"><div id="MyPiwiShop">{$MPS_CONTENT}</div></div>'; |
---|
62 | |
---|
63 | $newcont = preg_replace($search, $replace, $content); |
---|
64 | |
---|
65 | $search = '#<a class="trigger" href="\#">(\s*)infos(\s*)</a>(\s*)#s'; |
---|
66 | $replace = '<a class="trigger" href="#">infos</a>$1<a class="triggerPP" href="#" >{\'Shop\'|@translate}</a>{footer_script}{literal}$(document).ready(function(){$(".triggerPP").click(function(){$(".panelPP").toggle("fast");$(this).toggleClass("active");return false;});});{/literal}{/footer_script}'; |
---|
67 | |
---|
68 | return preg_replace($search, $replace, $newcont); |
---|
69 | } |
---|
70 | |
---|
71 | function mps_picture_form_stripped($content) |
---|
72 | { |
---|
73 | $search = '#<div style="clear: both;"></div>(\s*)</div>(\s*)</div>(\s*)</div>(\s*){/if}(\s*)</div>#s'; |
---|
74 | $replace = '<div style="clear: both;"></div></div>$1</div></div>$2{/if}<div id="Tmps" class="tabBlock"><div id="MyPiwiShop">{$MPS_CONTENT}</div></div></div>'; |
---|
75 | |
---|
76 | $newcont = preg_replace($search, $replace, $content); |
---|
77 | |
---|
78 | $search = '#{/if}(\s*)</ul>(\s*)#s'; |
---|
79 | $replace = '{/if}$2<li id="tabTmps" class="tabTitle" title="{\'Shop\'|@translate}" name="shop">{\'Shop\'|@translate}</li></ul>'; |
---|
80 | |
---|
81 | return preg_replace($search, $replace, $newcont); |
---|
82 | } |
---|
83 | |
---|
84 | function mps_prepar_tpl() |
---|
85 | { |
---|
86 | global $conf, $template, $picture, $user; |
---|
87 | $image_id = $picture['current']['id']; |
---|
88 | |
---|
89 | $query='SELECT * FROM '.MPS_CONF_TABLE.';'; |
---|
90 | $result = pwg_query($query); |
---|
91 | while($row = pwg_db_fetch_assoc($result)){ |
---|
92 | $config = $row ; |
---|
93 | } |
---|
94 | |
---|
95 | $query = ' |
---|
96 | SELECT * |
---|
97 | FROM '.MPS_PROD_IMG_TABLE.' AS pi |
---|
98 | INNER JOIN '.MPS_PRODUCT_TABLE.' AS p ON pi.product_id = p.id |
---|
99 | WHERE image_id = '.$image_id .' |
---|
100 | ORDER BY `order` |
---|
101 | ;'; |
---|
102 | |
---|
103 | $result = pwg_query($query); |
---|
104 | $num_rows = pwg_db_num_rows($result); |
---|
105 | |
---|
106 | |
---|
107 | if ($num_rows != 0) |
---|
108 | { |
---|
109 | while($row = pwg_db_fetch_assoc($result)){ |
---|
110 | $product[$row['product']] = $row['product'].' '. $row['price'].' '. $config['currency']; |
---|
111 | |
---|
112 | $price[] = $row['price']; |
---|
113 | } |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | $query='SELECT pi.product_id, po.product_id, p.price, p.product, o.name, o.type, o.requi, o.order, po.opt_id, ov.val |
---|
118 | FROM '.MPS_PROD_IMG_TABLE.' AS pi |
---|
119 | LEFT JOIN '.MPS_PRODUCT_TABLE.' As p ON p.id = pi.product_id |
---|
120 | LEFT JOIN '.MPS_PROD_OPT_TABLE.' AS po ON po.product_id = p.id |
---|
121 | LEFT JOIN '.MPS_OPTION_TABLE.' AS o ON o.id = po.opt_id |
---|
122 | LEFT JOIN '.MPS_OPT_VAL_TABLE.' AS ov ON ov.select_id = o.id |
---|
123 | WHERE image_id = '.$image_id .' |
---|
124 | AND po.opt_id IS NOT NULL |
---|
125 | ORDER BY o.order |
---|
126 | |
---|
127 | ;'; |
---|
128 | $result = pwg_query($query); |
---|
129 | while($row = pwg_db_fetch_assoc($result)){ |
---|
130 | { |
---|
131 | if (!isset($products[ $row['product']]['options'][ $row['order'] ])) |
---|
132 | { |
---|
133 | $products[ $row['product'] ]['options'][ $row['order'] ] = array( |
---|
134 | 'name' => $row['name'], |
---|
135 | 'type' => $row['type'], |
---|
136 | 'requi' => $row['requi'], |
---|
137 | 'values' => array(), |
---|
138 | ); |
---|
139 | } |
---|
140 | |
---|
141 | $products[ $row['product'] ]['options'][ $row['order'] ]['values'][] = $row['val']; |
---|
142 | } |
---|
143 | } |
---|
144 | if(isset($products)){ |
---|
145 | $template->assign(array( |
---|
146 | 'mps_options' => $products, |
---|
147 | )); |
---|
148 | } |
---|
149 | |
---|
150 | $template->assign(array( |
---|
151 | 'mps_conf' => $config, |
---|
152 | 'mps_price' => $price, |
---|
153 | 'mps_product' => $product, |
---|
154 | )); |
---|
155 | |
---|
156 | |
---|
157 | |
---|
158 | |
---|
159 | $theme = $user['theme']; |
---|
160 | |
---|
161 | switch ($theme) { |
---|
162 | case 'stripped': |
---|
163 | $template->set_prefilter('picture', 'mps_picture_form_stripped'); |
---|
164 | break; |
---|
165 | case 'PwgCarbon_dft': |
---|
166 | case 'PwgCarbon': |
---|
167 | case 'Float': |
---|
168 | case 'wood': |
---|
169 | case 'Slimi': |
---|
170 | case 'Slim': |
---|
171 | $template->set_prefilter('picture', 'mps_picture_form_piwitheme'); |
---|
172 | $template->assign(array('bypiwitheme'=> 'bypiwitheme')); |
---|
173 | break; |
---|
174 | default: |
---|
175 | $template->set_prefilter('picture', 'mps_picture_form'); |
---|
176 | break; |
---|
177 | } |
---|
178 | |
---|
179 | |
---|
180 | } |
---|
181 | } |
---|
182 | |
---|
183 | |
---|
184 | |
---|
185 | |
---|
186 | |
---|
187 | |
---|
188 | |
---|
189 | |
---|
190 | |
---|
191 | |
---|
192 | |
---|
193 | |
---|
194 | |
---|
195 | |
---|
196 | |
---|
197 | |
---|
198 | |
---|
199 | |
---|
200 | |
---|
201 | |
---|
202 | |
---|
203 | |
---|
204 | |
---|
205 | |
---|