/** * Re-order */ public function re_add_cart_item_data($cart_item_meta, $product, $order) { // Disable validation remove_filter('woocommerce_add_to_cart_validation', array($this, 'validate_add_cart_item'), 10, 3); // Get addon data $frames = get_frames($product['product_id']); if (empty($cart_item_meta['addons'])) { $cart_item_meta['addons'] = array(); } if (is_array($frames) && !empty($frames)) { include_once 'abstract-class-frame-field.php'; foreach ($frames as $addon) { $value = ''; $field = ''; include_once 'class-frame-field-list.php'; $value = array(); foreach ($product['item_meta'] as $key => $meta) { if (stripos($key, $addon['name']) === 0) { if (1 < count($meta)) { $value[] = array_map('sanitize_title', $meta); } else { $value[] = sanitize_title($meta[0]); } } } if (empty($value)) { continue; } $field = new Grmpd_Frame_Field_List($addon, $value); // make sure a field is set (if not it could be product with no add-ons) if ($field) { $data = $field->get_cart_item_data(); if (is_wp_error($data)) { $this->add_error($data->get_error_message()); } elseif ($data) { // get the post data $post_data = $_POST; $cart_item_meta['addons'] = array_merge($cart_item_meta['addons'], apply_filters('grmpd_frame_reorder_cart_item_data', $data, $addon, $product['product_id'], $post_data)); } } } } return $cart_item_meta; }
function get_arch_content($buf, $name, $url, $chrSet) { global $index_framesets, $command_line, $no_log, $can_leave_domain, $index_rss; $suffix = substr(strtolower($name), strrpos($name, ".") + 1); // if special converter is required if ($suffix == 'pdf') { $buf = extract_text($buf, $file0, 'pdf', 0, $charSet); } if ($suffix == 'doc') { $buf = extract_text($buf, $file0, 'doc', 0, $chrSet); } if ($suffix == 'rtf') { $buf = extract_text($buf, $file0, 'rtf', 0, $chrSet); } if ($suffix == 'xls') { $buf = extract_text($buf, $file0, 'xls', 0, $chrSet); } if ($suffix == 'ptt') { $buf = extract_text($buf, $file0, 'ptt', 0, $chrSet); } if ($suffix == 'docx') { $buf = extract_text($buf, $file0, 'docx', 0, $chrSet); } if ($suffix == 'xlsx') { $buf = extract_text($buf, $file0, 'xlsx', 0, $chrSet); } // for extracting framesets of this file enter here. Iframes will be extracted later on for the complete $file if ($index_framesets == '1') { if (preg_match("@<frameset[^>]*>(.*?)<\\/frameset>@si", $buf, $regs)) { printStandardReport('newFrameset', $command_line, $no_log); // separate the <frameset> ....</frameset> part of this file $frame = $regs[1]; $replace = get_frames($frame, $url, $can_leave_domain); $replace = "<body>" . $replace . "</body>"; // create the body tags for $buf // include all replacements instead of the frameset tag into the actual file. This will become the body $buf = preg_replace("@<frameset.*?</frameset>@si", "{$replace}", $buf); } } // for extracting archived feeds enter here if (preg_match("/<rss|atom|<feed|<rdf|<rsd/si", substr($buf, 0, 400)) && $index_rss == '1') { $buf = get_arch_feeds($buf, $url); } return $buf; }
/** * Gets addons assigned to a product by ID * * @param int $post_id ID of the product to get addons for * @param string $prefix for addon field names. Defaults to postid- * @param bool $inc_parent Set to false to not include parent frames. * @param bool $inc_global Set to false to not include global addons. * @return array array of addons */ function get_frames($post_id, $prefix = false, $inc_parent = true, $inc_global = true) { if (!$post_id) { return array(); } $addons = array(); $raw_addons = array(); $product_terms = apply_filters('get_frames_product_terms', wp_get_post_terms($post_id, 'product_cat', array('fields' => 'ids')), $post_id); $exclude = get_post_meta($post_id, '_frames_exclude_global', true); // Product Parent Level Addons if ($inc_parent && ($parent_id = wp_get_post_parent_id($post_id))) { $raw_addons[10]['parent'] = apply_filters('get_parent_frames_fields', get_frames($parent_id, $parent_id . '-', false, false), $post_id, $parent_id); } // Product Level Addons $raw_addons[10]['product'] = apply_filters('get_frames_fields', array_filter((array) get_post_meta($post_id, '_frames', true)), $post_id); // Global level addons (all products) if ('1' !== $exclude && $inc_global) { $args = array('posts_per_page' => -1, 'orderby' => 'meta_value', 'order' => 'ASC', 'meta_key' => '_priority', 'post_type' => 'global_frames', 'post_status' => 'publish', 'suppress_filters' => true, 'meta_query' => array(array('key' => '_all_products', 'value' => '1'))); $grmpd_frames = get_posts($args); if ($grmpd_frames) { foreach ($grmpd_frames as $global_addon) { $priority = get_post_meta($global_addon->ID, '_priority', true); $raw_addons[$priority][$global_addon->ID] = apply_filters('get_frames_fields', array_filter((array) get_post_meta($global_addon->ID, '_frames', true)), $global_addon->ID); } } // Global level addons (categories) if ($product_terms) { $args = apply_filters('get_frames_global_query_args', array('posts_per_page' => -1, 'orderby' => 'meta_value', 'order' => 'ASC', 'meta_key' => '_priority', 'post_type' => 'global_frames', 'post_status' => 'publish', 'suppress_filters' => true, 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $product_terms, 'include_children' => false))), $product_terms); $grmpd_frames = get_posts($args); if ($grmpd_frames) { foreach ($grmpd_frames as $global_addon) { $priority = get_post_meta($global_addon->ID, '_priority', true); $raw_addons[$priority][$global_addon->ID] = apply_filters('get_frames_fields', array_filter((array) get_post_meta($global_addon->ID, '_frames', true)), $global_addon->ID); } } } } ksort($raw_addons); foreach ($raw_addons as $addon_group) { if ($addon_group) { foreach ($addon_group as $addon) { $addons = array_merge($addons, $addon); } } } // Generate field names with unqiue prefixes if (!$prefix) { $prefix = apply_filters('frames_field_prefix', "{$post_id}-", $post_id); } // Let's avoid exceeding the suhosin default input element name limit of 64 characters $max_addon_name_length = 45 - strlen($prefix); // if the frames_field_prefix filter results in a very long prefix, then // go ahead and enforce sanity, exceed the default suhosin limit, and just use // the prefix and the field counter for the input element name if ($max_addon_name_length < 0) { $max_addon_name_length = 0; } $addon_field_counter = 0; foreach ($addons as $addon_key => $addon) { if (empty($addon['name'])) { unset($addons[$addon_key]); continue; } if (empty($addons[$addon_key]['field-name'])) { $addon_name = substr($addon['name'], 0, $max_addon_name_length); $addons[$addon_key]['field-name'] = sanitize_title($prefix . $addon_name . "-" . $addon_field_counter); $addon_field_counter++; } } return apply_filters('get_frames', $addons); }
/** * check_required_addons function. * * @access private * @param mixed $product_id * @return void */ private function check_required_addons($product_id) { $addons = get_frames($product_id, false, false, true); // No parent addons, but yes to global if ($addons && !empty($addons)) { foreach ($addons as $addon) { if ('1' == $addon['required']) { return true; } } } return false; }