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