Exemple #1
0
 /**
  * produce a HTML version of the product
  *
  * @param string  $product     the product to render
  * @param string  $template    multi-view product or single-view?
  * @param boolean $add_wrapper wrap in div.products-product before return
  *
  * @return string html of the product
  */
 function render($product, $template = 'singleview', $add_wrapper = true)
 {
     global $DBVARS, $PAGEDATA;
     $GLOBALS['products_template_used'] = $template;
     if (isset($DBVARS['online_store_currency'])) {
         $csym = $DBVARS['online_store_currency'];
     }
     $smarty = Products_setupSmarty();
     $smarty->assign('product', $product);
     $smarty->assign('product_id', $product->get('id'));
     $smarty->assign('_name', __FromJson($product->name));
     $smarty->assign('_stock_number', $product->stock_number);
     if (!is_array(@$this->data_fields)) {
         $this->data_fields = array();
     }
     $productVals = array();
     foreach ($this->data_fields as $f) {
         $f->n = preg_replace('/[^a-zA-Z0-9\\-_]/', '_', $f->n);
         $val = $product->get($f->n);
         $required = @$f->r ? ' required' : '';
         switch ($f->t) {
             case 'checkbox':
                 // {
                 $val = $val ? __('Yes') : __('No');
                 $smarty->assign($f->n, $val);
                 break;
                 // }
             // }
             case 'colour':
                 // {
                 if (@$f->u) {
                     // user-definable
                     WW_addScript('/j/mColorPicker/mColorPicker.js');
                     $h = '<input class="color-picker" ' . 'name="products_values_' . $f->n . '" ' . 'style="height:20px;width:20px;" ' . 'value="' . htmlspecialchars($val) . '" ' . 'data-text="hidden"/>' . '<style>#mColorPickerFooter,#mColorPickerImg{display:none}</style>';
                     WW_addInlineScript('$(".color-picker")' . '.mColorPicker({"imageFolder":"/j/mColorPicker/images/"});');
                 } else {
                     $h = 'TODO';
                 }
                 $smarty->assign($f->n, $h);
                 break;
                 // }
             // }
             case 'date':
                 // {
                 if (@$f->u) {
                     // user-definable
                     $smarty->assign($f->n, '<input class="product-field date ' . $f->n . $required . '" name="' . 'products_values_' . $f->n . '"/>');
                     $format = @$f->e ? $f->e : 'yy-mm-dd';
                     $y = date('Y');
                     WW_addInlineScript('$("input[name=products_values_' . $f->n . ']").datepicker({' . '"dateFormat":"' . $format . '",' . 'changeYear:true,changeMonth:true,yearRange:"1900:' . $y . '"' . '});');
                     WW_addInlineScript('$("input.hasDatepicker").each(function() {' . 'if (this.value!="") return;' . '$(this).datepicker("setDate", "+0");' . '});');
                 } else {
                     $val = Core_dateM2H($val);
                     $smarty->assign($f->n, $val);
                 }
                 break;
                 // }
             // }
             case 'hidden':
                 // {
                 $smarty->assign($f->n, '<input type="hidden" name="products_values_' . $f->n . '" value="' . htmlspecialchars($val) . '"/>');
                 break;
                 // }
             // }
             case 'selectbox':
                 // {
                 if (@$f->u) {
                     $valid_entries = explode("\n", $val);
                     foreach ($valid_entries as $k => $v) {
                         $v = trim($v);
                         if ($v == '') {
                             unset($valid_entries[$k]);
                         } else {
                             $valid_entries[$k] = $v;
                         }
                     }
                     if (!count($valid_entries)) {
                         $valid_entries = explode("\n", $f->e);
                     }
                     $h = '<select name="products_values_' . $f->n . '" class="' . $required . '">';
                     $translateable = @$f->tr && 1;
                     foreach ($valid_entries as $e) {
                         $e = trim($e);
                         if ($e == '' || !in_array($e, $valid_entries)) {
                             continue;
                         }
                         $o = $e;
                         $p = '';
                         if (strpos($e, '|') !== false) {
                             $bits = explode('|', $e);
                             $e = $bits[0];
                             $p = 'price="' . (int) $bits[1] . '"';
                         }
                         $h .= '<option ' . $p . ' value="' . htmlspecialchars($o) . '"';
                         if ($translateable) {
                             $h .= ' class="__"';
                         }
                         $h .= '>' . htmlspecialchars($e) . '</option>';
                     }
                     $h .= '</select>';
                 } else {
                     $val = preg_replace('/\\|.*/', '', $val);
                     $h = $val;
                 }
                 $smarty->assign($f->n, $h);
                 break;
                 // }
             // }
             case 'selected-image':
                 // {
                 $smarty->assign($f->n, '<input type="hidden" name="products_values_' . $f->n . '" ' . 'class="product-field ' . $f->n . $required . '"/>');
                 break;
                 // }
             // }
             case 'textarea':
                 // { textarea
                 if (@$f->u) {
                     $val = trim(preg_replace('/<[^>]*>/', '', $val));
                     $smarty->assign($f->n, '<textarea class="product-field ' . $f->n . $required . '" name="products_values_' . $f->n . '">' . htmlspecialchars($val) . '</textarea>');
                 } else {
                     $smarty->assign($f->n, $val);
                 }
                 break;
                 // }
             // }
             case 'user':
                 // {
                 $u = User::getInstance($val, false, false);
                 $val = $u ? $u->get('name') : 'no name';
                 $smarty->assign($f->n, $val);
                 break;
                 // }
             // }
             default:
                 // { everything else
                 if (@$f->u) {
                     $smarty->assign($f->n, '<input class="product-field ' . $f->n . $required . '" value="' . htmlspecialchars($val) . '" name="products_values_' . $f->n . '"/>');
                 } else {
                     $smarty->assign($f->n, $val);
                 }
                 // }
         }
         $productVals[$f->n] = $val;
         $PAGEDATA->title = str_replace('{{$' . $f->n . '}}', $val, $PAGEDATA->title);
     }
     if (isset($PAGEDATA->vars['products_pagedescriptionoverride']) && $PAGEDATA->vars['products_pagedescriptionoverride']) {
         $desc = preg_replace('/<[^>]*>/', '', $productVals['description']);
         $desc = trim(preg_replace('/\\s+/m', ' ', $desc));
         $PAGEDATA->description = substr($desc, 0, 153) . '...';
     }
     if (isset($product->ean)) {
         $smarty->assign('_ean', $product->ean);
     }
     // { $_name, $_stock_number, $_ean
     $PAGEDATA->title = str_replace(array('{{$_name}}', '{{$_stock_number}}', '{{$_ean}}'), array($product->get('_name'), $product->get('_stock_number'), $product->vals['ean']), $PAGEDATA->title);
     // }
     $html = '';
     if ($add_wrapper) {
         $classes = array('products-product');
         if ($this->stock_control) {
             $classes[] = 'stock-control';
         }
         $html .= '<div class="' . join(' ', $classes) . '" id="products-' . $product->get('id') . '">';
     }
     $html .= $smarty->fetch(USERBASE . '/ww.cache/products/templates/types_' . $template . '_' . $this->id);
     if ($template == 'singleview') {
         $PAGEDATA->vars['header_html'] = (isset($PAGEDATA->vars['header_html']) ? $PAGEDATA->vars['header_html'] : '') . '<link rel="canonical" href="' . htmlspecialchars($product->getRelativeUrl()) . '" />';
         if ($this->allow_comments) {
             $html .= Core_commentsShow('http://' . $_SERVER['HTTP_HOST'] . $product->getRelativeURL());
         }
     }
     if ($add_wrapper) {
         $html .= '</div>';
     }
     return $html;
 }
Exemple #2
0
 *
 * @category   None
 * @package    None
 * @subpackage None
 * @author     Kae Verens <*****@*****.**>
 * @license    GPL Version 2
 * @link       www.kvweb.me
 */
$bits = explode('/', $unused_uri);
$user_id = (int) $bits[0];
$date = $bits[1];
$titlelike = str_replace('-', '_', $bits[2]);
$sql = 'select * from blog_entry where user_id=' . $user_id . ' and cast(cdate as date)' . '="' . addslashes($date) . '" and title like "' . addslashes($titlelike) . '"';
$r = dbRow($sql, 'blog_entry');
if (!$r) {
    $c = '<div class="blog-article-error">Error: article not found.</div>';
    return;
}
$c = '<div class="blog-article-wrapper" id="blog-entry-' . $r['id'] . '">';
$c .= '<h1 class="blog-header">' . htmlspecialchars($r['title']) . '</h1>';
$user = User::getInstance($r['user_id']);
$name = $user ? $user->name : 'unknown';
$c .= '<div class="blog-meta">' . '<span class="blog-author" data-uid="' . $r['user_id'] . '">' . $name . '</span>' . '<span class="blog-spacing"> ~ </span>' . '<span class="blog-date-published">' . Core_dateM2H($r['cdate']) . '</span>' . '</div>';
$c .= '<div class="blog-body">' . $r['body'] . '</div>';
$date = preg_replace('/ .*/', '', $r['cdate']);
$c .= '</div>';
WW_addScript('blog');
WW_addInlineScript('window.blog_comments=0;');
if ($r['allow_comments']) {
    $c .= Core_commentsShow($PAGEDATA->getAbsoluteUrl() . '/' . $r['user_id'] . '/' . $date . '/' . preg_replace('/[^a-zA-Z0-9]/', '-', transcribe($r['title'])));
}