Esempio n. 1
0
 /**
  * render a list of products to HTML
  *
  * @param object $PAGEDATA      the page object
  * @param int    $start         offset
  * @param int    $limit         how many products to show
  * @param string $order_by      what field to order the search by
  * @param int    $order_dir     order ascending or descending
  * @param int    $limit_start   lowest $start offset allowed
  * @param int    $enabledFilter whether to allow enabled/disabled products
  *
  * @return string the HTML of the products list
  */
 function render($PAGEDATA, $start = 0, $limit = 0, $order_by = '', $order_dir = 0, $limit_start = 0, $enabledFilter = 0)
 {
     global $cdnprefix;
     $c = '';
     // { sort based on $order_by
     $md5 = md5('ps-sorted-' . join(',', $this->product_ids) . '|' . $order_by . '|' . $order_dir . '|' . $enabledFilter);
     $tmpprods = -1;
     if ($order_dir != 2) {
         $tmpprods = Core_cacheLoad('products', $md5, -1);
     }
     if ($tmpprods == -1) {
         if ($order_by != '') {
             $native = substr($order_by, 0, 1) === '_';
             $tmpprods1 = array();
             $prods = $this->product_ids;
             $sql = 'select id';
             if (!$native) {
                 $sql .= ',data_fields';
             }
             $sql .= ' from products where id in (' . join(', ', $this->product_ids) . ')';
             if ($enabledFilter == 0) {
                 $sql .= ' and enabled';
             }
             if ($enabledFilter == 1) {
             }
             if ($enabledFilter == 2) {
                 $sql .= ' and !enabled';
             }
             if ($native) {
                 $sql .= ' order by ' . substr($order_by, 1, strlen($order_by) - 1);
                 if ($order_dir == 1) {
                     $sql .= ' desc';
                 }
             }
             $values = dbAll($sql, '', 'products');
             if ($native) {
                 $tmpprods = array();
                 if (is_array($values)) {
                     foreach ($values as $v) {
                         $tmpprods[] = $v['id'];
                     }
                     if ($order_dir == 2) {
                         shuffle($tmpprods);
                     }
                 }
             } else {
                 if (is_array($values)) {
                     foreach ($values as $v) {
                         $vals = json_decode($v['data_fields'], true);
                         $key2 = '';
                         foreach ($vals as $v2) {
                             if ($v2['n'] == $order_by) {
                                 $key2 = __FromJSON($v2['v']);
                             }
                         }
                         if (!isset($tmpprods1[$key2])) {
                             $tmpprods1[$key2] = array();
                         }
                         $tmpprods1[$key2][] = $v['id'];
                     }
                 }
                 if ($order_dir == 1) {
                     krsort($tmpprods1);
                 } else {
                     if ($order_dir == 0) {
                         ksort($tmpprods1);
                     } else {
                         if ($order_dir == 2) {
                             shuffle($tmpprods1);
                         }
                     }
                 }
                 $tmpprods = array();
                 foreach ($tmpprods1 as $pids) {
                     foreach ($pids as $pid) {
                         $tmpprods[] = $pid;
                     }
                 }
                 foreach ($prods as $key => $pid) {
                     $tmpprods[] = $pid;
                 }
             }
         } else {
             $tmpprods = $this->product_ids;
         }
         Core_cacheSave('products', $md5, $tmpprods);
     }
     // }
     // { sanitise the limits
     $cnt = count($tmpprods);
     if (!$limit) {
         $limit = $cnt;
         $start = 0;
     } else {
         if ($start && $start >= count($this->product_ids)) {
             $start = $cnt - $limit;
         }
     }
     // }
     // { build array of items
     $prevnext = '';
     $total_found = count($tmpprods);
     if ($cnt == $limit) {
         $prods =& $tmpprods;
     } else {
         $prods = array();
         for ($i = $start; $i < $limit + $start; ++$i) {
             if (isset($tmpprods[$i])) {
                 $prods[] = $tmpprods[$i];
             }
         }
         $prefix = '';
         if ($PAGEDATA->vars['products_what_to_show'] == 2) {
             $cat = ProductCategory::getInstance($PAGEDATA->vars['products_category_to_show']);
             if ($cat) {
                 $prefix = $cat->getRelativeUrl();
             }
         }
         if (!$prefix) {
             $prefix = $PAGEDATA->getRelativeUrl();
         }
         if ($start > $limit_start) {
             $prevnext .= '<a class="products-prev" href="' . $prefix . '?start=' . ($start - $limit) . '">' . __('Previous') . '</a>';
         }
         if ($limit && $start + $limit < $cnt) {
             if ($start) {
                 $prevnext .= ' | ';
             }
             $prevnext .= '<a class="products-next" href="' . $prefix . '?start=' . ($start + $limit) . '">' . __('Next') . '</a>';
         }
     }
     $prevnext = '<div class="products-pagination">' . $prevnext . '</div>';
     // }
     // { see if there are search results
     if (isset($PAGEDATA->vars['products_add_a_search_box']) && $PAGEDATA->vars['products_add_a_search_box']) {
         $c .= '<div class="products-num-results">' . __('<strong>%1</strong> results found.', array($total_found), 'core') . '</div>';
     }
     // }
     if (!isset($PAGEDATA->vars['products_show_multiple_with'])) {
         $PAGEDATA->vars['products_show_multiple_with'] = 0;
     }
     $prods = array_unique($prods);
     switch ($PAGEDATA->vars['products_show_multiple_with']) {
         case 1:
             // { horizontal table, headers on top
             $c .= Product_datatableMultiple($prods, 'horizontal');
             break;
             // }
         // }
         case 2:
             // { vertical table, headers on left
             $c .= Product_datatableMultiple($prods, 'vertical');
             break;
             // }
         // }
         case 3:
             // { map view
             WW_addScript('products');
             WW_addCSS('/ww.plugins/products/products.css');
             return '<div id="products-mapview"></div>';
             // }
         // }
         case 4:
             // { carousel
             WW_addScript('products');
             $c = '<div id="products-carousel"><ul id="products-carousel-slider">';
             foreach ($prods as $pid) {
                 $product = Product::getInstance($pid, false, $enabledFilter);
                 if ($product && isset($product->id) && $product->id) {
                     $typeID = $product->get('product_type_id');
                     $type = ProductType::getInstance($typeID);
                     if (!$type) {
                         $c .= '<li>' . __('Missing Product Type: %1', array($typeID), 'core') . '</li>';
                     } else {
                         $c .= '<li id="products-' . $product->id . '" class="products-product">' . $type->render($product, 'multiview', 0) . '</li>';
                     }
                 }
             }
             $c .= '</ul></div>';
             WW_addScript('/j/jsor-jcarousel-7bb2e0a/jquery.jcarousel.min.js');
             WW_addCSS('/ww.plugins/products/products.css');
             return $c;
             // }
         // }
         default:
             // { use template
             if (count($prods)) {
                 // display the first item's header
                 $product = Product::getInstance($prods[0], false, $enabledFilter);
                 $type = ProductType::getInstance($product->get('product_type_id'));
                 if ($type) {
                     $smarty = Products_setupSmarty();
                     $c .= $smarty->fetch(USERBASE . '/ww.cache/products/templates/types_multiview_' . $type->id . '_header');
                 }
             }
             foreach ($prods as $pid) {
                 $product = Product::getInstance($pid, false, $enabledFilter);
                 if ($product && isset($product->id) && $product->id) {
                     $typeID = $product->get('product_type_id');
                     $type = ProductType::getInstance($typeID);
                     if (!$type) {
                         $c .= __('Missing Product Type: %1', array($typeID), 'core');
                     } else {
                         if (isset($_REQUEST['product_id'])) {
                             $c .= $type->render($product, 'singleview');
                         } else {
                             $c .= $type->render($product, 'multiview');
                         }
                     }
                 }
             }
             if (isset($type) && $type && count($prods)) {
                 // display first item's header
                 $smarty = Products_setupSmarty();
                 $c .= $smarty->fetch(USERBASE . '/ww.cache/products/templates/types_multiview_' . $type->id . '_footer');
             }
             // }
     }
     $categories = '';
     if (!isset($_REQUEST['products-search']) && isset($this->subCategories) && count($this->subCategories) && !@$PAGEDATA->vars['products_dont_show_sub_categories']) {
         $categories = '<ul class="products-categories categories">';
         foreach ($this->subCategories as $cr) {
             $cat = ProductCategory::getInstance($cr['id']);
             $categories .= '<li><a href="' . $cat->getRelativeUrl() . '">';
             $icon = '/products/categories/' . $cr['id'] . '/icon.png';
             if (file_exists(USERBASE . 'f' . $icon)) {
                 $subcatW = (int) $cat->vals['thumbsize_w'];
                 $subcatH = (int) $cat->vals['thumbsize_h'];
                 $categories .= '<img src="' . $cdnprefix . '/a/f=getImg/w=' . $subcatW . '/h=' . $subcatH . '/fmt=' . filemtime(USERBASE . 'f' . $icon) . $icon . '"/>';
             }
             $categories .= '<span>' . htmlspecialchars($cr['name']) . '</span>' . '</a></li>';
         }
         $categories .= '</ul>';
     }
     return $categories . $prevnext . '<div class="products">' . $c . '</div>' . $prevnext;
 }
Esempio n. 2
0
$html .= '<select name="page_vars[userlogin_registration_type]">';
$html .= '<option>Moderated</option>';
$html .= '<option';
$emailVerified = @$page_vars['userlogin_registration_type'] == 'Email-verified';
if ($emailVerified) {
    $html .= ' selected="selected"';
}
$html .= '>Email-verified</option>';
$html .= '</select></td></tr>';
// }
// { redirect on login
$html .= '<tr><th>Redirect on login:</th><td>';
$html .= '<select id="page_vars_userlogin_redirect_to" name="' . 'page_vars[userlogin_redirect_to]">';
if (@$page_vars['userlogin_redirect_to']) {
    $parent = Page::getInstance($page_vars['userlogin_redirect_to']);
    $html .= '<option value="' . $parent->id . '">' . htmlspecialchars(__FromJSON($parent->name)) . '</option>';
} else {
    $page_vars['userlogin_redirect_to'] = 0;
    $html .= '<option value="0"> -- none -- </option>';
}
$html .= '</select></td></tr>';
// }
// { allow users to purchase credits
$html .= '<tr><th>Users can purchase site credits:</th><td>';
$html .= '<select id="page_vars_userlogin_can_purchase_credits" name="' . 'page_vars[userlogin_can_purchase_credits]">' . '<option value="0">No</option>' . '<option value="1"';
if (isset($page_vars['userlogin_can_purchase_credits']) && $page_vars['userlogin_can_purchase_credits']) {
    $html .= ' selected="selected"';
}
$html .= '>Yes</option></select></td></tr>';
// }
// { form source type