source: extensions/MyPiwiShop/include/public_events.inc.php @ 27781

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