Ignore:
Timestamp:
Mar 16, 2014, 7:16:27 PM (10 years ago)
Author:
Miklfe
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/MyPiwiShop/include/public_events.inc.php

    r27743 r27781  
    22defined('MPS_PATH') or die('Hacking attempt!');
    33
    4 /*
    5  * button on album and photos pages
    6  */
     4//button on album and photos pages
    75function mps_add_button()
    86{
    97  global $template, $conf;
    108 
    11  $query='SELECT * FROM '.MPS_CONF_TABLE.';';
    12     $result     = pwg_query($query);
    13     while($row = pwg_db_fetch_assoc($result)){
    14     $config = $row ;
    15    }
     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  }
    1618
    17         $template->assign(array(
    18     'mps_conf'  => $config,
    19         'MPS_PATH'      => MPS_PATH,
    20     ));   
    21 //  $template->assign('MPS_PATH', MPS_PATH);
     19  $template->assign(array(
     20   'mps_conf'   => $config,
     21   'MPS_PATH'   => MPS_PATH,
     22  ));   
     23
    2224  $template->set_filename('mps_button', realpath(MPS_PATH.'template/button_basket.tpl'));
    23 //  $template->assign('mps_conf' , $config);
    24 
    2525  $button = $template->parse('mps_button', true);
    2626 
    27   if (script_basename()=='index')
    28   {
     27  if (script_basename()=='index') {
    2928    $template->add_index_button($button, EVENT_HANDLER_PRIORITY_NEUTRAL);
    30   }
    31   else
    32   {
     29  } else {
    3330    $template->add_picture_button($button, EVENT_HANDLER_PRIORITY_NEUTRAL);
    3431  }
    3532}
    3633
    37 /**
    38  * add a forms on photo page
    39  */
    40 function mps_loc_end_picture()
     34// add a forms on photo page
     35function mps_init_form_picture()
    4136{
    4237  global $template;
    43         $template->set_filename('MyPiwiShop', realpath(MPS_PATH.'template/MyPiwiShop.tpl'));
    44         $template->assign_var_from_handle('MPS_CONTENT', 'MyPiwiShop');
     38 
     39  $template->set_filename('MyPiwiShop', realpath(MPS_PATH.'template/MyPiwiShop.tpl'));
     40  $template->assign_var_from_handle('MPS_CONTENT', 'MyPiwiShop');
    4541}
    4642
     43// place on picture page (default theme)
    4744function mps_picture_form($content)
    4845{
    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)}';
     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)}';
    5148
    52         return preg_replace($search, $replace, $content);
     49  return preg_replace($search, $replace, $content);
    5350}
    5451
     52// place on picture page (piwitheme theme)
    5553function mps_picture_form_piwitheme($content)
    5654{
    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>';
     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>';
    5957
    60         $newcont = preg_replace($search, $replace, $content);
     58  $newcont = preg_replace($search, $replace, $content);
    6159
    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}';
     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}';
    6462
    65         return preg_replace($search, $replace, $newcont);
     63  return preg_replace($search, $replace, $newcont);
    6664}
    6765
     66// place on picture page (stripped theme)
    6867function mps_picture_form_stripped($content)
    6968{
    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>';
     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>';
    7271
    73         $newcont = preg_replace($search, $replace, $content);
     72  $newcont = preg_replace($search, $replace, $content);
    7473
    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>';
     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>';
    7776
    78         return preg_replace($search, $replace, $newcont);
     77  return preg_replace($search, $replace, $newcont);
    7978}
    8079
     
    8281{
    8382  global $conf, $template, $picture, $user;
    84         $image_id = $picture['current']['id'];
     83 
     84  $image_id = $picture['current']['id'];
    8585       
    86    $query='SELECT * FROM '.MPS_CONF_TABLE.';';
    87       $result   = pwg_query($query);
    88       while($row = pwg_db_fetch_assoc($result)){
    89       $config = $row ;
    90      }
     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  }
    9195
    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`
     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`
    98102    ;';
    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      }
     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   }
    106111
    107112 
    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 
     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 
    109114   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                 }
     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   }
    130138 
    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         ));
     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   ));
    145150       
    146 
    147        
    148        
    149         $theme = $user['theme'];
    150        
    151  switch ($theme) {
     151   $theme = $user['theme'];
     152   
     153   switch ($theme) {
    152154    case 'stripped':
    153         $template->set_prefilter('picture', 'mps_picture_form_stripped');
    154         break;
     155     $template->set_prefilter('picture', 'mps_picture_form_stripped');
     156     break;
    155157        case 'PwgCarbon_dft':
    156158        case 'PwgCarbon':
     
    159161        case 'Slimi':
    160162        case 'Slim':
    161         $template->set_prefilter('picture', 'mps_picture_form_piwitheme');
    162                 $template->assign(array('bypiwitheme'=> 'bypiwitheme'));
    163         break;
     163     $template->set_prefilter('picture', 'mps_picture_form_piwitheme');
     164         $template->assign(array('bypiwitheme'=> 'bypiwitheme'));
     165     break;
    164166    default:
    165         $template->set_prefilter('picture', 'mps_picture_form');
    166         break;
    167 }
    168 
    169 
     167     $template->set_prefilter('picture', 'mps_picture_form');
     168     break;
    170169   }
     170  }
    171171}
    172172
Note: See TracChangeset for help on using the changeset viewer.