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

Last change on this file since 27781 was 27781, checked in by Miklfe, 10 years ago
File size: 5.0 KB
RevLine 
[27568]1<?php
2defined('MPS_PATH') or die('Hacking attempt!');
3
[27781]4//button on album and photos pages
[27568]5function mps_add_button()
6{
7  global $template, $conf;
8 
[27781]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  }
[27568]18
[27781]19  $template->assign(array(
20   'mps_conf'   => $config,
21   'MPS_PATH'   => MPS_PATH,
22  ));   
23
[27568]24  $template->set_filename('mps_button', realpath(MPS_PATH.'template/button_basket.tpl'));
25  $button = $template->parse('mps_button', true);
26 
[27781]27  if (script_basename()=='index') {
[27568]28    $template->add_index_button($button, EVENT_HANDLER_PRIORITY_NEUTRAL);
[27781]29  } else {
[27568]30    $template->add_picture_button($button, EVENT_HANDLER_PRIORITY_NEUTRAL);
31  }
32}
33
[27781]34// add a forms on photo page
35function mps_init_form_picture()
[27568]36{
37  global $template;
[27781]38 
39  $template->set_filename('MyPiwiShop', realpath(MPS_PATH.'template/MyPiwiShop.tpl'));
40  $template->assign_var_from_handle('MPS_CONTENT', 'MyPiwiShop');
[27568]41}
42
[27781]43// place on picture page (default theme)
[27568]44function mps_picture_form($content)
45{
[27781]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)}';
[27568]48
[27781]49  return preg_replace($search, $replace, $content);
[27568]50}
51
[27781]52// place on picture page (piwitheme theme)
[27568]53function mps_picture_form_piwitheme($content)
54{
[27781]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>';
[27568]57
[27781]58  $newcont = preg_replace($search, $replace, $content);
[27568]59
[27781]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}';
[27568]62
[27781]63  return preg_replace($search, $replace, $newcont);
[27568]64}
65
[27781]66// place on picture page (stripped theme)
[27568]67function mps_picture_form_stripped($content)
68{
[27781]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>';
[27568]71
[27781]72  $newcont = preg_replace($search, $replace, $content);
[27568]73
[27781]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>';
[27568]76
[27781]77  return preg_replace($search, $replace, $newcont);
[27568]78}
79
80function mps_prepar_tpl()
81{
82  global $conf, $template, $picture, $user;
[27781]83 
84  $image_id = $picture['current']['id'];
[27568]85       
[27781]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  }
[27568]95
[27781]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`
[27568]102    ;';
[27781]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   } 
[27568]111
112 
[27781]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 
[27568]114   FROM '.MPS_PROD_IMG_TABLE.' AS pi
[27781]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   
[27568]136    }
[27781]137   }
[27568]138 
[27781]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   ));
[27568]150       
[27781]151   $theme = $user['theme'];
152   
153   switch ($theme) {
[27568]154    case 'stripped':
[27781]155     $template->set_prefilter('picture', 'mps_picture_form_stripped');
156     break;
[27568]157        case 'PwgCarbon_dft':
158        case 'PwgCarbon':
159        case 'Float':
160        case 'wood':
161        case 'Slimi':
162        case 'Slim':
[27781]163     $template->set_prefilter('picture', 'mps_picture_form_piwitheme');
164         $template->assign(array('bypiwitheme'=> 'bypiwitheme'));
165     break;
[27568]166    default:
[27781]167     $template->set_prefilter('picture', 'mps_picture_form');
168     break;
[27568]169   }
[27781]170  }
[27568]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.