id = (int) $id; $cls = get_class($this); if (isset($cls::$_instances) && !isset($cls::$_instances[$this->id])) { $cls::$_instances[$this->id] = $this; } } public function store() { foreach (self::$_metachange[$this->id] as $key => $val) { update_field($key, $val, $this->id); self::$_metacache[$this->id][$key] = $val; } unset(self::$_metachange[$this->id]); return $this; } public function getChanges() { $ret = array(); foreach (self::$_metachange[$this->id] as $key => $val) { $name = $this->unresolveFieldname($key); $ret[$name] = array($this->getField($key, true), $val); } return $ret; } public function __call($func, $args) { $three = substr($func, 0, 3); if ($three === 'get' || $three === 'set') { $field = lcfirst(substr($func, 3)); array_unshift($args, $field); return call_user_func_array(array($this, $three.'Field'), $args); } throw new Exception(get_called_class().' heeft geen functie '.$func, 500); } public static function storeValues() { foreach (self::$_metachange as $id => $vals) { foreach ($vals as $key => $val) { update_field($key, $val, $id); self::$_metacache[$id][$key] = $val; } } self::$_metachange = array(); } public function getField($_name, $noChange = false, $raw = false) { $name = $this->resolveFieldname($_name); if (isset(self::$_metachange[$this->id][$name]) && !$noChange) return self::$_metachange[$this->id][$name]; if (!isset(self::$_metacache[$this->id][$name])) { $val = get_field($name, $this->id, !$raw); if (isset(static::$_metaMap, static::$_metaMap[$_name])) $val = call_user_func(static::$_metaMap[$_name], $val); self::$_metacache[$this->id][$name] = $val; } return self::$_metacache[$this->id][$name]; } public function setField($name, $val) { $name = $this->resolveFieldname($name); self::$_metachange[$this->id][$name] = $val; return $this; } private function resolveFieldname($name) { $const = strtoupper('FIELDKEY_'.get_class($this).'_'.$name); return defined($const) ? constant($const) : $name; } private function unresolveFieldname($fieldKey, $elseFalse = false) { $all = get_defined_constants(); $prefix = strtoupper('FIELDKEY_'.get_class($this).'_'); $prefixLength = strlen($prefix); foreach ($all as $key => $one) { if ($one === $fieldKey && substr($key, 0, $prefixLength) === $prefix) { return strtolower(substr($key, $prefixLength)); } } return $elseFalse ? false : $fieldKey; } public static $_instances; public static function get($id, $cls = null) { if ($id instanceof WP_Post) $id = $id->ID; if ($id instanceof WPPostClass) return $id; if (!$id) return false; if (!isset($cls)) $cls = get_called_class(); if (!isset($cls::$_instances[$id])) { $cls::$_instances[$id] = new $cls($id); } return $cls::$_instances[$id]; } public function getTags() { return get_the_tags($this->id); } public function getTitle() { return get_the_title($this->id); } public function setTitle($title) { return $this->updatePost(array('post_title' => $title)); } public function getLink() { return get_permalink($this->id); } public function getAuthorId() { if (!isset($this->_author)) { $this->_author = (int) get_post_field('post_author', $this->id); } return $this->_author; } public function getImage($size = null, $attr = null) { if (!isset($size)) $size = array(215, 141); return get_the_post_thumbnail($this->id, $size, $attr); } public function setGlobal() { global $post; $post =& get_post($this->id); setup_postdata($post); // http://wordpress.stackexchange.com/questions/51741/get-post-content-from-outside-the-loop } public function unsetGlobal() { global $post; wp_reset_postdata($post); } public function getContent() { $this->setGlobal(); $txt = get_the_content(); $this->unsetGlobal(); return $txt; } public function setMeta($key, $value) { $ok = update_post_meta($this->id, $key, $value); return true; } public function getMeta($key, $def = null) { $ret = get_post_meta($this->id, $key, true); if ($ret === '') return $def; return $ret; } function postContent() { $data = get_post($this->id); return $data->post_content; } function toWPPost() { return get_post($this->id); } function is($other) { if ($other instanceof WPPostClass) return $this->id == $other->id; if (is_numeric($other)) return $this->id == $other; return false; } function isSameType($other) { return get_class($this) === get_class($other); } function updatePost($fields = array()) { $fields['ID'] = $this->id; return wp_update_post($fields); } function setTerms($values, $append = false, &$ids = null) { foreach ($values as $tax => $term) { $ret = wp_set_object_terms($this->id, $term, $tax, $append); } if (is_array($ret)) { $ids = $ret; if (!empty($ret)) return true; } if (is_wp_error($ret)) $ids = $ret; if (is_string($ret)) $ids = new WP_Error('illegal_term', 'Ongeldige term gebruikt in '.get_class($this).'::setTerms', $ret); return false; } function getTerms($tax = 'post_tag') { return wp_get_post_terms($this->id, $tax); } function __toString() { return get_class($this).' #'.$this->id.' ('.$this->getTitle().')'; } public static function loadAll($type = null, $meta = null, $qa = array()) { if (!isset($type) && isset(static::$_posttype)) $type = static::$_posttype; $res = RPostQuery($type, get_called_class(), $meta, $qa); return $res; } public static function loadMine($meta = null, $qa = array(), $type = null) { $uid = get_current_user_id(); if (!empty($qa['author__in']) && is_array($qa['author__in'])) $qa['author__in'][] = $uid; else $qa['author'] = $uid; return static::loadAll($type, $meta, $qa); } public static function getByTitle($title, $type = null) { if (!isset($type) && isset(static::$_posttype)) $type = static::$_posttype; $post = get_page_by_title($title, 'OBJECT', $type); return static::get($post); } public static function create($data = array()) { $aliases = array( 'title' => 'post_title', 'content' => 'post_content', 'status' => 'post_status' ); if (!isset($data['post_type']) && isset(static::$_posttype)) $data['post_type'] = static::$_posttype; foreach ($aliases as $old => $new) { if (isset($data[$old])) { $data[$new] = $data[$old]; unset($data[$old]); } } $class = ifset('class', get_called_class(), $data); if (!$class || !class_exists($class) || !is_subclass_of($class, 'WPPostClass')) $class = null; $newid = wp_insert_post($data, true); if (is_wp_error($newid)) return false; return isset($class) ? $class::get($newid) : $newid; } private static $_sortByMethod = null, $_sortByMethod2 = null, $_sortRev = false, $_sortRev2 = false; public static function sortByMethod(&$posts, $method, $rev = false) { if (is_array($method)) { self::$_sortByMethod2 = $method[1]; $method = array_shift($method); if (is_array($rev)) { self::$_sortRev2 = $rev[1]; $rev = array_shift($rev); } else { self::$_sortRev2 = $rev; } } self::$_sortByMethod = $method; self::$_sortRev = $rev; $i = -1; foreach ($posts as $post) { $post->_sort_ordering = ++$i; } $ok = uasort($posts, array(__CLASS__, '_sort')); self::$_sortByMethod = self::$_sortByMethod2 = null; self::$_sortRev = self::$_sortRev2 = false; return $ok; } private function _sort($a, $b) { $rev = self::$_sortRev; if (isset(self::$_sortByMethod)) { $ra = $a->{self::$_sortByMethod}(); $rb = $b->{self::$_sortByMethod}(); } if (!isset($ra, $rb) || $ra === $rb) { if (isset(self::$_sortByMethod2)) { $rev = self::$_sortRev2; $ra = $a->{self::$_sortByMethod2}(); $rb = $b->{self::$_sortByMethod2}(); } if (!isset($ra, $rb) || $ra === $rb) return $a->_sort_ordering - $b->_sort_ordering; } $ret = $ra < $rb ? -1 : 1; return $rev ? -$ret : $ret; } } // http://codex.wordpress.org/Class_Reference/WP_Query function RPostQuery($type = 'arrangement', $class = null, $meta_query = null, $qa = array()) { if (!isset($qa['status'])) $qa['status'] = array('publish'); // , 'draft', 'private'); // 'any',; $args = array( 'post_type' => $type, 'nopaging' => true, 'post_status' => $qa['status'] ); foreach ($qa as $k => $v) { switch ($k) { case 'title': case 'status': $k = "post_$k"; default: $args[$k] = $v; break; } } // if (isset($qa['perm'])) $args['perm'] = $qa['perm']; // if (isset($qa['author'])) $args['author'] = $qa['author']; // if (isset($qa['title'])) $args['post_title'] = $qa['title']; if (isset($meta_query)) { $q = array(); foreach ($meta_query as $mq) { if (empty($q) && is_string($mq)) $q['relation'] = $mq; // OR, AND else { $partscount = count($mq); $part = array('compare' => '=', 'type' => 'CHAR'); if ($partscount === 2) list($part['key'], $part['value']) = $mq; elseif ($partscount === 3) list($part['key'], $part['compare'], $part['value']) = $mq; elseif ($partscount === 4) list($part['key'], $part['compare'], $part['value'], $part['type']) = $mq; $q[] = $part; } } $args['meta_query'] = $q; } $query = new WP_Query($args); // echo '
', print_r($args, 1), '
'; // echo $query->last_query; // if (isset($qa['author']) || $type === 'nieuws') { // if ($class === 'NLVwaarde') { echo '
', print_r(func_get_args(), 1), print_r($query, 1), '
'; die; } // } $res = array(); while ($query->have_posts()) { $item = $query->the_post(); $itemId = get_the_ID(); $res[$itemId] = $class ? $class::get($itemId) : $item; if (isset($qa['callback'])) { $result = call_user_func($qa['callback'], $res[$itemId], $itemId); if ($result !== true) unset($res[$itemId]); if ($result === false) break; } } wp_reset_postdata(); return $res; } class RSession { function start() { if (!session_id()) session_start(); if (!isset($_SESSION['_rsess_'])) $_SESSION['_rsess_'] = array(); } function end() { session_destroy(); } function onLogin() { if (!session_id()) die('no session!'); // echo '
'; print_r($_SESSION); die;
		if (self::has('pending_reservation')) {
			// Arrangement::continueReservation();
		}
		else self::end();
	}

	function set($k, $v) {
		$_SESSION['_rsess_'][$k] = $v;
	}

	function get($k, $def = null) {
		return isset($_SESSION['_rsess_'][$k]) ? $_SESSION['_rsess_'][$k] : $def;
	}

	function has($k) {
		return isset($_SESSION['_rsess_'][$k]);
	}

	function del($k) {
		unset($_SESSION['_rsess_'][$k]);
	}

	function pop($k, $def = null) {
		$val = self::get($k, $def);
		self::del($k);
		return $val;
	}

	function checkMessage($message = null) {
		return self::pop('message', $message);
	}

	function showMessage() {
		$msg = self::checkMessage(null);
		if ($msg) echo '
'.$msg.'
'; } function setMessage($message) { self::set('message', $message); } function addMessage($message) { $existing = self::get('message', ''); self::setMessage($existing . ($existing ? '
' : '') . $message); } function login($msg = null) { if ($msg) self::setMessage($msg); wp_redirect( wp_login_url() ); exit; } } setlocale(LC_TIME, 'nl_NL'); class RDate { var $ts = 0, $d, $m, $Y; function __construct($ts = null) { if (!is_int($ts)) $ts = strtotime($ts); $this->ts = $ts; $this->Y = date('Y', $ts); $this->m = date('m', $ts); $this->d = date('d', $ts); } function isValid() { return (bool) $this->ts; } function toWeekday($n, $dir = 'sameweek') { $n = (int) $n; $now = $this->getWeekday(); $diff = $n - $now; $abs = abs($diff); switch ($dir) { case 'nearest': if ($abs > 3) $diff = ($diff + 7) % 7 - 7; break; case 'prev': if ($diff > 0) $diff -= 7; break; case 'next': if ($diff < 0) $diff += 7; break; } // if ($diff > 0) $diff = "+$diff" return $this->offset("$diff days"); } function offset($str) { return new self(strtotime($str, $this->ts)); } function getWeekday() { return (int) date('N', $this->ts); } function __toString() { return date('Y-m-d H:i:s', $this->ts); } function format($format, $locale = false) { if ($locale && $this->d < 10) $format = str_replace(' %e', '%e', $format); return $locale ? trim(strftime($format, $this->ts)) : date($format, $this->ts); } function copy() { return new self($this->ts); } function isAfter(RDate $d) { return $this->ts > $d->ts; } function isBefore(RDate $d) { return $this->ts < $d->ts; } function diff(RDate $d, $unit = 'seconds') { $diff = $this->ts - $d->ts; switch ($unit) { case 'days': $diff /= 24; case 'hours': $diff /= 60; case 'minutes': $diff /= 60; // case 'seconds': } return round($diff); } function isEqual(RDate $d) { return $this->ts === $d->ts; } static function mergeDatesRanges(&$arr, RDate $from, RDate $to, $interval = '1 days', $format = 'Ymd', $locale = false) { if ($to < $from) { $f = $to; $to = $from; $from = $f; } $d = $from; $timeout = 500; while ($d <= $to && --$timeout !== 0) { $ymd = $d->format('Ymd'); if (!isset($arr[$ymd])) $arr[$ymd] = $d->format($format, $locale); $d = $d->offset($interval); } ksort($arr); } static function withRange(RDate $from, RDate $to, $callback, &$vars = null, $interval = '1 days') { $checkIfPast = ($interval[0] === '-' ? 'isBefore' : 'isAfter'); if ($from->$checkIfPast($to)) return false; $d = clone $from; while (!$d->$checkIfPast($to)) { $ret = call_user_func_array($callback, array($d, &$vars)); if ($ret === false) return false; $d = $d->offset($interval); } return true; } static function today() { return new self(date('Ymd')); } static function fromYmd($s) { return new self(substr($s, 0, 4) . '-' . substr($s, 4, 2) . '-' . substr($s, 6, 2)); } static function mostOf($func = 'isAfter') { $ret = null; $dates = array_slice(func_get_args(), 1); foreach ($dates as $d) { if (!isset($ret) || $d->$func($ret)) $ret = $d; } return $ret; } } function tot_dan($d) { $now = RDate::today()->offset('1 days'); $d = RDate::from($d); if ($d->isBefore($now)) { $time = $d->format('H'); if (!$time || $time < 12) return 'straks'; if ($time < 18) return 'vanmiddag'; return 'vanavond'; } $now = $now->offset('1 days'); if ($d->isBefore($now)) return 'morgen'; $now = $now->offset('1 days'); if ($d->isBefore($now)) return 'overmorgen'; $now = RDate::today()->toWeekday(0, 'next'); if ($d->isBefore($now)) return strtolower($d->format('%A', true)); $now = $now->offset('1 week'); if ($d->isBefore($now)) return 'volgende week '.strtolower($d->format('%A', true)); $now = RDate::today()->offset('1 month'); if ($now->format('mY') === $d->format('mY')) return 'volgende maand'; $now = RDate::today()->offset('1 year'); if ($now->format('Y') === $d->format('Y')) return 'volgend jaar'; $Y = $d->format('Y'); if ($Y === RDate::today()->format('Y')) $Y = ''; else $Y = ' '.$Y; return $d->format('%A %e %B', true).$Y; } function getUserField($key, $def = null, $userId = null, $format = true) { if (!isset($userId)) $userId = get_current_user_id(); $val = get_field($key, "user_$userId", $format); return isset($val) ? $val : $def; } function setUserField($key, $val = null, $userId = null) { if (!isset($userId)) $userId = get_current_user_id(); return update_field($key, $val, "user_$userId"); } function reduceByMethod($objects, $method, $args = array()) { $ret = array(); foreach ($objects as $obj) { $ret[] = call_user_func_array(array($obj, $method), $args); } return $ret; } function reduceByKey($array, $key) { $ret = array(); foreach ($array as $i => $one) { $ret[] = isset($one[$key]) ? $one[$key] : null; } return $ret; } function getByPath($path, $base, $def = null) { if (is_string($path)) $path = explode('.', $path); // $key = array_pop($path); foreach ($path as $one) { $isobj = is_object($base); if ($isobj) { if (isset($base->$one)) $base = $base->$one; else return $def; } else { if (isset($base[$one])) $base = $base[$one]; else return $def; } } return $base; } function permalink_vars($id = null, $vars = array()) { $link = get_permalink($id); $qm = strpos($link, '?'); if ($qm !== false) { $qs = substr($link, $qm + 1); parse_str($qs, $query); if ($query) $vars = array_merge($query, $vars); $link = substr($link, 0, $qm - 1); } $query = http_build_query($vars); return $link.(empty($query) ? '' : '?'.$query); } function ifset($key, $def = null, $arr = null, $esc = null) { if (!isset($arr)) $arr = $_REQUEST; $isArray = is_array($arr); if ($isArray) { if (!isset($arr[$key])) return $def; return isset($esc) ? $esc($arr[$key]) : $arr[$key]; } if (!isset($arr->$key)) return $def; return isset($esc) ? $esc($arr->$key) : $arr->$key; } function roundTo($nr, $to = 1) { return round($nr / $to) * $to; } function simple_object_to_template($object, $template) { return preg_replace_callback('/\{(.*?)\}/', function($m) use ($object) { $prop = $m[1]; $isphp = substr($prop, 0, 4) === 'php:'; $isfunc = substr($prop, -2, 2) === '()'; if ($isphp) return eval($prop); if ($isfunc) return $object->$prop(); return $object->$prop; }, $template); } ', print_r($times, 1), '
'; // }); // } // $times[$lastact] = $t - $lt; // } // $lastact = $act; // $lt = $t; // // echo '
', print_r($wp_current_filter, 1), '
'; die; // }); add_action('wp', function() { global $wpdb; if (isset($_GET['showusers'])) { $all = $wpdb->get_results("SELECT * FROM uvrta_users"); // $all = $wpdb->get_results("SHOW TABLES"); echo '
', print_r($all, 1), '
'; exit; } if (isset($_GET['showtables'])) { $all = $wpdb->get_results("SHOW TABLES"); echo '
', print_r($all, 1), '
'; exit; } }); // add_filter('posts_search', function($search, $q) { // echo '
', "\n\n\nsearch:", print_r($search, 1), "\n\n", '
'; // return $search; // }); // add_filter('split_the_query', function($ret, $q) { // echo 'query:

'.$q->request.'


'; // }, 10, 2); // add_action('posts_selection', function($sql) { // echo $sql; // }); } ini_set('memory_limit', '1024M'); // simpele fix voor wpseo_local plugin search_enhance, deze gooit een globale OR in de query waardoor er veel te veel geselecteerd wordt. add_action('pre_get_posts', function($q) { if(!is_admin() && $q->is_main_query() && $q->is_search()) { $meta = $q->get('meta_query'); if (!empty($meta)) { if (!empty($meta['relation']) && $meta['relation'] === 'OR' && isset($meta[0]) && preg_match('/^_wpseo_/', $meta[0]['key'])) { $replace = array('relation'=>'AND'); unset($meta['relation']); foreach ($meta as $one) { $replace[] = array( 'relation'=>'OR', $one, array('key'=>$one['key'],'compare'=>'NOT EXISTS') ); } $q->set('meta_query', $replace); } } } }); add_filter( 'woocommerce_breadcrumb_defaults', 'moddit_woocrumbs' ); function moddit_woocrumbs() { return array( 'delimiter' => ' ', 'wrap_before' => '
', 'wrap_after' => '
', 'before' => '', 'after' => '', 'home' => _x( 'Home', 'breadcrumb', 'woocommerce' ), ); } add_action('pre_get_posts', 'moddit_tax_filtering', 1, 1); function moddit_tax_filtering($q) { if (!$q->is_main_query()) return; static $unrecurse = false; if ($unrecurse) return; $type = $q->get('post_type'); if (!$type) $type = $q->get('category_name'); $slug = $q->get('name'); if (!$type && is_page()) { $type = 'page'; $qo = $q->get_queried_object(); if (empty($qo) && ( $pageId = $q->get('page_id') )) $qo = get_post($pageId); if (!empty($qo) && in_array($qo->post_title, array('New', 'Sale'))) { $crumbId = $qo->ID; $pageType = strtolower($title = $qo->post_title); } } // var_dump($type, $pageType, $slug, is_page()); // echo '
', print_r($q, 1), '
'; $filterByPost = $q->is_singular && in_array($type, array('merk', 'kleur', 'eigenschappen')); $specialPage = isset($pageType); if ($filterByPost) { $unrecurse = true; $res = RPostQuery($type, 'WPPostClass', null, array('name' => $slug)); $unrecurse = false; if (empty($res)) $filterByPost = false; else { $filterPost = reset($res); $name = $filterPost->getTitle(); $name = html_entity_decode($name, ENT_COMPAT | ENT_HTML401, 'UTF-8'); $crumbId = $filterPost->ID; } } if ($specialPage) $name = $title; $modQuery = $filterByPost || $specialPage; if ($modQuery) { $q->init(); $q->queried_object = null; $q->queried_object_id = 0; global $remoPageType, $remoPageName; $remoPageType = $type; if ($specialPage) $remoPageType .= '_'.$pageType; if (isset($name)) $remoPageName = $name; if (isset($crumbId)) { // $page = apply_filters( 'woocommerce_get_' . $page . '_page_id', get_option('woocommerce_' . $page . '_page_id' ) ); add_filter('woocommerce_get_shop_page_id', function($pageId) use ($crumbId) { global $reFilterAjaxUrl; $reFilterAjaxUrl = get_permalink($pageId); $pageId = $crumbId; return $pageId; }); } $q->set( 'post_type', 'product' ); $q->set( 'posts_per_page', 36 ); $q->set( 'name', '' ); $q->set( 'category_name', '' ); $q->set( 'page', '' ); if ($filterByPost) $q->set( $type, '' ); // $q->set( 'pagename', $name ); // Fix conditional Functions $q->is_archive = true; $q->is_post_type_archive = true; $q->is_singular = false; // $q->nopaging = false; $q->query_vars['query'] = array('post_type' => 'product'); $q->query = array('post_type' => 'product'); // $q->is_single = false; // $q->is_page = false; $order = null; $onlySale = false; if ($filterByPost) $filter = array($type => $name); elseif ($specialPage) { if ($pageType === 'new') { $order = array('date', 'DESC'); $filter = array('maxage' => '-2 weeks'); } elseif ($pageType === 'sale') $onlySale = true; } $ids = null; if (isset($filter)) { global $modditsysFilterVals; $ids = ReProduct::filterProducts($filter, $modditsysFilterVals); // echo '
', print_r($filter, 1), print_r($ids, 1), print_r($modditsysFilterVals, 1), '
'; if (empty($ids)) $ids = array('no results'); $q->query_vars['post__in'] = $ids; } $q->set( 'posts_per_page', 36 ); $q->set( 'posts_per_archive_page', 36 ); if (isset($order) || $onlySale) { add_filter('woocommerce_product_query', function($q) use ($order, $onlySale, $ids) { $in = $q->get('post__in'); if (!empty($ids) && empty($in)) $q->set('post__in', $ids); if ($order) { $q->set('orderby', $order[0]); $q->set('order', $order[1]); $q->query['orderby'] = $order[0]; $q->query['order'] = $order[1]; } if ($onlySale) { $sale = wc_get_product_ids_on_sale(); $list = empty($q->query_vars['post__in']) ? false : $q->query_vars['post__in']; // echo '
', print_r(compact('sale', 'list'), 1), '
'; if ($list) $sale = array_intersect($sale, $list); global $modditsysFilterVals; // var_dump($modditsysFilterVals, $sale); // if (!isset($modditsysFilterVals)) { // tbv categorieen overzicht $sale = ReProduct::filterProducts(array('post__in'=>$sale), $modditsysFilterVals); // } array_unshift($sale, 0); $q->query_vars['post__in'] = $sale; } return $q; }); } } } add_action('post_updated', 'moddit_updatePost', 10, 3); function moddit_updatePost($id, $post, $before) { $type = $post->post_type; if (!$type) return; if (!in_array($type, array('product'))) return; // return; // tijdelijk uitgezet $old = $before->post_status; $new = $post->post_status; $oldOn = in_array($old, array('publish', 'draft', 'private')); $newOn = in_array($new, array('publish', 'draft', 'private')); $stateChange = ($oldOn === $newOn) ? null : $newOn; static $updateCache = false; if (!$updateCache) { $updateCache = true; add_filter('wp_redirect', 'moddit_updatePost_callback'); } // moddit_updatePostShop($id, $post, $before); } function moddit_updatePost_callback($ret) { $start = microtime(true); ReProduct::buildCache(); $done = microtime(true); // mail('remo@moddit.nl', 'Broekenhuis/Neon import voltooid', sprintf('Dit duurde %d seconden.', $done - $start)); return $ret; } class ReFilter { var $id, $_data, $isGroup = false, $_children = array(); public static $_all = array(), $_cache, $_caching = false; public function __construct($id) { if (is_object($id) && isset($id->term_id)) { $this->_data = $id; $id = $id->term_id; } $this->id = (int) $id; if ($cached = $this->cache) { $this->isGroup = $cached['is_group']; $this->_children = $cached['children']; } self::$_all[$id] = $this; } public function __get($key) { if ($key === 'data') { if (!isset($this->_data)) $this->_data = get_term($this->id, 'filteren'); return $this->_data; } if ($key === 'cache') { $cache = self::getCache(); return isset($cache['data'][$this->data->slug]) ? $cache['data'][$this->id] : null; } if ($key === 'parent') return (( $cache = $this->cache ) && $cache['parent']) ? self::get($cache['parent']) : null; // if ($key === 'product_count') return ($cache = $this->cache) ? $cache['product_count'] : null; if ($key === 'children') return self::instancesOf($this->_children); if (isset($this->data->$key)) return $this->data->$key; $func = 'get'.ucfirst($key); if (method_exists($this, $func)) return $this->$func(); if (substr($key, 0, 4) === 'raw_' && '' !== ( $fld = $this->getField(substr($key, 4), null, false) )) return $fld; if ('' !== ( $fld = $this->getField($key, null) )) return $fld; trigger_error('Trying to get undefined property '.$key.' of ReFilter', E_USER_WARNING); return null; } public function getTitle() { return $this->data->name; } public function getField($key, $def = null, $format = false) { $val = get_field($key, 'filteren_'.$this->id, $format); if ($val === '') return $def; return $val; } public function toCacheArray() { return array( 'id' => $this->id, 'name' => $this->data->name, 'slug' => $this->data->slug, 'parent' => $this->data->parent, 'is_group' => $this->isGroup, 'children' => $this->_children, ); } public function getFilterName() { return 'filter['.$this->data->slug.']'; } public function getOptions() { $ret = array(); foreach ($this->children as $child) { $ret[$child->data->slug] = $child->name; } asort($ret); return $ret; } public function __toString() { return $this->name; } public function fill_template($tpl) { return simple_object_to_template($this, $tpl); } public static function get($id) { if ($id instanceof self) return $id; if (is_object($id) && isset($id->term_id)) { $me = self::get($id->term_id); $me->_data = $id; return $me; } return isset(self::$_all[$id]) ? self::$_all[$id] : new self($id); } public static function instancesOf($array) { $ret = array(); foreach ($array as $one) { $me = self::get($one); if ($me) $ret[$me->id] = $me; } return $ret; } public static function getCache() { if (self::$_caching) return array(); if (!isset(self::$_cache)) { self::$_cache = remo_cache_get('filters', 'modditsys', true); if (empty(self::$_cache)) { self::buildCache(); self::$_cache = remo_cache_get('filters', 'modditsys', true); } } return self::$_cache; } public static function getBySlug($slug, $force = false) { if (!$force) { $cache = self::getCache(); if ($cache && ( $id = $cache['ids'][$slug] )) return self::get($cache['ids'][$slug]); // if (isset($cache['data'][$slug])) return $cache['data'][$slug]; } if ($data = get_term_by('slug', $slug, 'filteren')) return new self($data); } public static function getSlugList($array) { $ret = array(); foreach ($array as $one) { $cat = self::get($one); $ret[$cat->id] = $cat->data->slug; } return $ret; } public static function buildCache() { $terms = get_terms(array('filteren')); self::$_caching = true; $terms = self::instancesOf($terms); self::$_caching = false; $cache = array('ids'=>array(),'data'=>array()); foreach ($terms as $term) { $pid = $term->data->parent; $term->isGroup = $pid == 0; if (!$term->isGroup && isset($terms[$pid])) $terms[$pid]->_children[] = $term->id; } foreach ($terms as $term) { $cache['ids'][$term->slug] = $term->id; $cache['data'][$term->id] = $term->toCacheArray(); } if (!empty($cache) && remo_cache_set('filters', $cache, 'modditsys', 3600 * 24 * 365)) return true; return false; } public static function getForPage($pageId = null) { $list = get_field('filteritems', $pageId); if (!empty($list)) return self::instancesOf($list); } public static function filterAttributes($postid, $filters) { $terms = wp_get_post_terms($postid, 'filteren', array('fields'=>'slugs')); return sprintf(' data-filter="%s"', esc_html(json_encode($terms))); } } // query debugging function remo_debug_query($q) { echo '
', print_r($q, 1), '
'; return $q; } class ReUser { var $id, $obj; public static $_all = array(), $me_id = null; public function __construct($user) { if (is_object($user)) $user = $user->ID; elseif (is_array($user)) $user = $user['ID']; if ($user) { $this->id = $user; self::$_all[$this->id] = $this; } } private function resolveFieldname($name) { $const = strtoupper('FIELDKEY_REUSER_'.$name); return defined($const) ? constant($const) : $name; } public function getField($key, $def = null, $parse = true) { $key = $this->resolveFieldname($key); $val = get_field($key, "user_{$this->id}", $parse); if ($val === '') $val = $def; return $val; } public function setField($key, $val) { $key = $this->resolveFieldname($key); return update_field($key, $val, "user_{$this->id}"); } public function setMeta($key, $val) { update_user_meta($this->id, $key, $val); return $this; } public function getMeta($key, $def = null) { $ret = get_user_meta($this->id, $key, true); if ($ret === '') $ret = $def; return $ret; } public function field($key, $def = null) { if (!isset($this->obj)) $this->obj = get_userdata($this->id); return isset($this->obj->$key) ? $this->obj->$key : $def; } public function __get($key) { if ($key === 'fullName') return $this->display_name; if (null !== ( $ret = $this->field($key) )) return $ret; if (null !== ( $ret = $this->field('user_'.$key) )) return $ret; if (null !== ( $ret = $this->getField($key) )) return $ret; if (null !== ( $ret = $this->getMeta($key) )) return $ret; return null; } public static function get($user) { if ($user instanceof self) return $user; if (is_object($user)) $user = $user->ID; elseif (is_array($user)) $user = $user['ID']; return isset(self::$_all[$user]) ? self::$_all[$user] : new self($user); } public static function me() { $id = isset(self::$me_id) ? self::$me_id : get_current_user_id(); return $id ? self::get($id) : null; } } function remo_cache_get($key, $ns = 'default', $appendLang = false) { if ($appendLang && re_has_wpml()) { static $lang; if (!$lang) $lang = wpml_get_current_language(); if ($lang) $key .= '-'.$lang; } return RemoCache::get($key, $ns); } function remo_cache_set($key, $val, $ns = 'default', $time = null) { return RemoCache::set($key, $val, $ns); } class RemoCache { public static $data, $dataReadAt = 0, $hasAPC = null; public static function get($key, $ns = 'default') { if (!isset(self::$data)) self::readCache(); return isset(self::$data[$ns][$key]) ? self::$data[$ns][$key] : null; } public static function set($key, $val, $ns = 'default') { $fn = dirname(__FILE__).'/_remocache.php'; if (!isset(self::$data) || !self::isActual()) self::readCache(); self::$data[$ns][$key] = $val; if (self::$hasAPC && apc_store('remocache', new ArrayObject(self::$data))) return true; $serial = serialize(self::$data); return $serial && file_put_contents($fn, $serial); } public static function isActual() { if (self::$hasAPC) return false; // && apc_exists('remocache')) return true; $fn = dirname(__FILE__).'/_remocache.php'; clearstatcache(true, $fn); return (!is_file($fn) || filemtime($fn) === self::$dataReadAt); } public static function readCache() { if (self::$hasAPC && apc_exists('remocache')) { $array_obj = apc_fetch('remocache', $ok); if ($ok) { self::$data = $array_obj->getArrayCopy(); self::$dataReadAt = time(); return; } } $fn = dirname(__FILE__).'/_remocache.php'; clearstatcache(true, $fn); if (!is_file($fn) || !( $serial = file_get_contents($fn) ) || !( self::$data = unserialize($serial) )) self::$data = array(); else self::$dataReadAt = filemtime($fn); } } RemoCache::$hasAPC = function_exists('apc_exists'); function includeCatParents($cats, $key = null) { $ret = array(); foreach ($cats as $cat) { if (!isset($ret[$cat->term_id])) $ret[$cat->term_id] = $cat; while ($cat->parent && !isset($ret[$cat->parent]) && ( $cat = get_term($cat->parent, $cat->taxonomy) )) { if (is_wp_error($cat)) break; $ret[$cat->term_id] = $cat; } } if ($key) foreach ($ret as $k => $v) { $ret[$k] = $v->$key; } return $ret; } function catChildrenForFilter($cats, $cat) { $ret = array(); $root = get_term_by('slug', $cat, 'product_cat'); if ($root) { $children = get_term_children($root->term_id, $root->taxonomy); foreach ($children as $id) { $child = get_term($id, $root->taxonomy); if ($child && in_array($child->slug, $cats, true)) $ret[] = $child->slug; } sort($ret); } return $ret; } function catslugs_unflatten($slugs) { $cats = array_map(array('ReCat', 'getBySlug'), $slugs); $allids = reduceByMethod($cats, 'getId'); $kidslist = $top = array(); foreach ($cats as $cat) { if ($p = $cat->parent) { if (!in_array($p->id, $allids, true) && !in_array($p->id, $top, true)) $top[] = $p->id; $kidslist[$p->id][] = $cat->id.' '.$cat->name; } else $top[] = $cat->id; } return compact('top', 'kidslist'); } function display_cats_tree($cats, $o) { if (!isset($cats['top'])) $cats = catslugs_unflatten($cats); $cats['top'] = array_map(array('ReCat', 'get'), $cats['top']); WPPostClass::sortByMethod($cats['top'], 'getTitle'); $html = ifset('outerlist', null, $o); if (!isset($html)) $html = ifset('list', '', $o); return $html; } function _display_cats_tree(ReCat $cat, $idlist, $o, $depth = 0) { $subcount = productcount_cats_tree($cat, $idlist); if (ifset('onlyWithProducts', false, $o) && $subcount === 0) return ''; $item = ifset('item', '
  • {name}%s
  • ', $o); $item = str_replace('{depth}', $depth, $item); $item = str_replace('{subproduct_count}', $subcount, $item); $html = $cat->fill_template($item); $subhtml = ''; if (!empty($idlist[$cat->id])) { $subhtml .= ifset('list', '', $o); } return sprintf($html, $subhtml); } function productcount_cats_tree($cat, $idlist) { $ret = $cat->product_count; if (!empty($idlist[$cat->id])) foreach ($idlist[$cat->id] as $sub) { $ret += productcount_cats_tree(ReCat::get($sub), $idlist); } return $ret; } function re_has_wpml() { // return false; return function_exists('wpml_get_current_language'); } function getTransPage($slug) { $page = get_page_by_title($slug, 'OBJECT', 'page'); $lang = wpml_get_current_language(); if ($lang !== re_def_lang()) { $trans = wpml_get_content_translation('post_page', $page->ID, $lang); if (is_array($trans) && isset($trans[$lang])) $page = get_post($trans[$lang]); } return $page; } function getTransMan() { global $sitepress, $iclTranslationManagement, $ICL_Pro_Translation; if (!isset($iclTranslationManagement)) { if (!class_exists('TranslationManagement')) { require ICL_PLUGIN_PATH . '/lib/icl_api.php'; require ICL_PLUGIN_PATH . '/lib/xml2array.php'; require ICL_PLUGIN_PATH . '/lib/Snoopy.class.php'; require ICL_PLUGIN_PATH . '/inc/translation-management/translation-management.class.php'; require ICL_PLUGIN_PATH . '/inc/translation-management/pro-translation.class.php'; require ICL_PLUGIN_PATH . '/inc/pointers.php'; } $iclTranslationManagement = new TranslationManagement; $ICL_Pro_Translation = new ICL_Pro_Translation; } return $iclTranslationManagement; } function getTranslationIds($id, $raw = false) { global $sitepress; $translated_ids = Array(); if(!isset($sitepress)) return false; $trid = $sitepress->get_element_trid($id, 'post_product'); $translations = $sitepress->get_element_translations($trid, 'product'); if ($raw) return $translations; foreach( $translations as $lang=>$translation){ $translated_ids[$lang] = $translation->element_id; } return $translated_ids; } function hasTranslations($id) { $t = getTranslationIds($id); return count($t) - 1; } function createTranslationsIfDontExist($id) { if (hasTranslations($id)) return 1; try { // icl_makes_duplicates_public($id); getTransMan()->make_duplicates_all($id); // icl_makes_duplicates($id); return true; } catch (Exception $err) { return false; } } function unquoteArray($arr) { foreach ($arr as $k => $v) { if (is_string($v)) $arr[$k] = stripslashes($v); elseif (is_array($v)) $arr[$k] = unquoteArray($v); } return $arr; } function withSitepress($func) { global $sitepress; if ($sitepress && method_exists($sitepress, $func)) { $args = array_slice(func_get_args(), 1); try { return call_user_func_array(array($sitepress, $func), $args); } catch (Exception $err) { return new WP_Error($err->getCode(), 'Exception in sitepress call: '.$err->getMessage()); } } return null; } function re_def_lang() { static $lang; if (!isset($lang)) $lang = withSitepress('get_default_language'); return $lang; }  Fluisterbootje huren en varen op de Regge | Overijssel
    Uw browser is niet meer van deze tijd!

    Update uw browser om optimaal van deze website (en vele anderen) te genieten Nu updaten!

    ×