/** * Add a line of data to this graph. * * @param array $points * @param string $label * @param array $options * * @throws \UnexpectedValueException */ public function add_data_set($points, $label = '', $options = array()) { if (count($points) !== count($this->labels)) { throw new \UnexpectedValueException('usage: count($points) == count($labels)'); } $defaults = array('data' => $points, 'label' => $label); $this->data_sets[] = \ITUtility::merge_defaults($options, $defaults); }
function builder_theme_settings_set_defaults($defaults) { global $builder_theme_feature_options; $new_defaults = array('include_pages' => array('home'), 'include_cats' => array(), 'javascript_code_header' => '', 'javascript_code_footer' => '', 'identify_widget_areas' => 'admin', 'identify_widget_areas_method' => 'empty', 'enable_comments_page' => '', 'enable_comments_post' => '1', 'comments_disabled_message' => 'none', 'tag_as_keyword' => 'yes', 'cat_index' => 'no', 'google_analytics_enable' => '', 'woopra_enable' => '', 'gosquared_enable' => '', 'gallery_default_render_method' => 'columns', 'activation_child_theme_setup' => 'ask', 'activation_default_layouts' => 'ask'); foreach ((array) $builder_theme_feature_options as $features) { foreach ((array) $features as $feature => $details) { $new_defaults["theme_supports_{$feature}"] = $details['default_enabled']; } } $defaults = ITUtility::merge_defaults($defaults, $new_defaults); $defaults = apply_filters('builder_filter_theme_settings_defaults', $defaults); // Legacy $defaults = apply_filters('builder_filter_default_settings', $defaults); return $defaults; }
function builder_get_builder_core_default_layouts() { $layouts = array(); $default_data_path = dirname(__FILE__) . '/default-data'; if (is_callable('json_decode')) { $defaults = json_decode(file_get_contents("{$default_data_path}/default-layouts.json"), true); } else { if (is_callable('base64_decode')) { $defaults = @unserialize(base64_decode(file_get_contents("{$default_data_path}/default-layouts.base64"))); } else { $defaults = unserialize(file_get_contents("{$default_data_path}/default-layouts.txt")); } } include_once dirname(__FILE__) . '/upgrade-storage.php'; $data = apply_filters('it_storage_upgrade_layout_settings', array('data' => $defaults)); $defaults = $data['data']; require_once dirname(__FILE__) . '/layout-settings-guid-randomizer.php'; $defaults = BuilderLayoutSettingsGUIDRandomizer::randomize_guids($defaults); return ITUtility::merge_defaults($layouts, $defaults); }
/** * Create an update record. * * @api * * @since 1.0 * * @param array $args * * @return \ITELIC\Update|WP_Error */ function itelic_create_update($args) { $defaults = array('activation' => '', 'release' => '', 'update_date' => '', 'previous_version' => ''); $args = ITUtility::merge_defaults($args, $defaults); $activation = is_numeric($args['activation']) ? itelic_get_activation($args['activation']) : $args['activation']; if (!$activation) { return new WP_Error('invalid_activation', __("Invalid activation record.", \ITELIC\Plugin::SLUG)); } $release = is_numeric($args['release']) ? itelic_get_release($args['release']) : $args['release']; if (!$release) { return new WP_Error('invalid_release', __("Invalid release object.", \ITELIC\Plugin::SLUG)); } if (!empty($args['update_date'])) { $update_date = is_string($args['update_date']) ? \ITELIC\make_date_time($args['update_date']) : $args['update_date']; if (!$update_date instanceof DateTime) { return new WP_Error("invalid_update_date", __("Invalid update date.", \ITELIC\Plugin::SLUG)); } } else { $update_date = null; } return \ITELIC\Update::create($activation, $release, $update_date, $args['previous_version']); }
function run_import($settings = array(), $use_post_data = true, $return_data = false, $db_data = false) { $default_settings = array('data_sources' => array('layouts-views' => array('method' => 'add'), 'theme-settings' => array('method' => 'skip'))); $settings = ITUtility::merge_defaults($settings, $default_settings); if ($use_post_data) { $post_data = ITForm::get_post_data(true); $settings = ITUtility::merge_defaults($post_data, $settings); } it_classes_load('it-file-utility.php'); $info = $this->get_info(); $errors = array(); $results = array(); $attachments = $this->get_attachments(); $new_attachments = array(); foreach ((array) $attachments as $id => $file) { $attachment = ITFileUtility::add_to_media_library($file); $new_attachments[$id] = $attachment; } foreach ((array) $info['data_sources'] as $var => $data_source) { if (isset($this->_data_sources[$var])) { if (is_callable(array($this->_data_sources[$var], 'run_import'))) { if (!isset($settings['data_sources'][$var])) { $settings['data_sources'][$var] = array(); } else { if (isset($settings['data_sources'][$var]['method']) && 'skip' == $settings['data_sources'][$var]['method']) { continue; } } $db_settings = isset($db_data[$var]) ? $db_data[$var] : false; $result = $this->_data_sources[$var]->run_import($info['data_sources'][$var], $this->get_data($var), $settings['data_sources'][$var], $new_attachments, $return_data, $db_settings); if ($return_data) { $results[$var] = $result; } if (false === $result) { $errors[] = "{$var}:failed_run_import"; } } else { $errors[] = "{$var}:missing_run_import"; } } } if ($return_data) { return $results; } if (!empty($errors)) { return $errors; } return true; }
function _get_defaults($defaults) { $new_defaults = array('title_type' => 'default', 'title_custom' => '', 'tagline_type' => 'default', 'tagline_custom' => '', 'seo_type' => 'default', 'seo_title_home' => 'h1', 'seo_title_other' => 'div', 'seo_tagline_home' => 'div', 'seo_tagline_other' => 'div', 'sidebar' => 'none'); return ITUtility::merge_defaults($new_defaults, $defaults); }
function _get_defaults($defaults) { $new_defaults = array('type' => '3', 'widget_percents' => '33.333,33.333,33.333', 'custom_widget_percents' => ''); return ITUtility::merge_defaults($new_defaults, $defaults); }
function _modify_layout() { $defaults = array('guid' => '', 'description' => '', 'width' => '960', 'hide_widths' => 'no'); $defaults = apply_filters('builder_filter_layout_editor_default_values', $defaults); $layout_widths = array('600' => __('Narrow (600 pixels)', 'it-l10n-Builder-Paige'), '780' => __('Medium (780 pixels)', 'it-l10n-Builder-Paige'), '960' => __('Wide (960 pixels)', 'it-l10n-Builder-Paige')); $layout_widths = apply_filters('builder_filter_layout_editor_width_options', $layout_widths); foreach ((array) $layout_widths as $width => $description) { if ((string) intval($width) != (string) $width) { unset($layout_widths[$width]); } } $layout_widths['custom'] = __('Custom...', 'it-l10n-Builder-Paige'); if (builder_theme_supports('builder-extensions')) { $extensions_data = apply_filters('builder_get_extensions_data', array()); $extensions = array('' => __('-- No Extension --', 'it-l10n-Builder-Paige')); $extension_descriptions = array(); foreach ((array) $extensions_data as $extension => $extension_data) { $extensions[$extension] = $extension_data['name']; $description = $extension_data['description']; if (!empty($description)) { $description = "<p>{$description}</p>"; } if ($extension_data['disable_theme_style']) { $description .= __('<p><strong>Notice:</strong> This Extension replaces theme styling with its own.</p>', 'it-l10n-Builder-Paige'); } $extension_descriptions[] = '"' . str_replace('"', '\\"', $extension) . '": "' . str_replace('"', '\\"', $description) . '"'; } } /* $layouts = array(); foreach ( (array) $this->_options['layouts'] as $layout_id => $layout_data ) { if ( isset( $_REQUEST['layout'] ) && ( $layout_id == $_REQUEST['layout'] ) ) continue; $layouts[$layout_id] = $layout_data['description']; } sort( $layouts );*/ $layout = array(); if (isset($this->_cached_layout) && is_array($this->_cached_layout)) { $layout = $this->_cached_layout; } else { if (isset($_REQUEST['layout']) && isset($this->_options['layouts'][$_REQUEST['layout']])) { $layout = $this->_options['layouts'][$_REQUEST['layout']]; } } $layout = ITUtility::merge_defaults($layout, $defaults); if (isset($layout['width']) && (string) intval($layout['width']) == (string) $layout['width'] && !isset($layout_widths[$layout['width']])) { $layout['custom_width'] = $layout['width']; $layout['width'] = 'custom'; } if (!empty($layout['extension']) && false !== strpos($layout['extension'], '%WP_CONTENT_DIR%')) { $layout['extension'] = basename($layout['extension']); } $form = new ITForm($layout); ?> <div class="wrap"> <?php ITUtility::screen_icon(); ?> <?php if (!empty($_REQUEST['layout'])) { ?> <h2><?php _e('Edit Layout', $this->_var); ?> </h2> <?php } else { ?> <h2><?php _e('Add New Layout', $this->_var); ?> </h2> <?php } ?> <?php $form->start_form(); ?> <h3 class="title"><?php _e('Settings', 'it-l10n-Builder-Paige'); ?> </h3> <table class="form-table"> <tr><th scope="row"><label for="description"><?php _e('Name', 'it-l10n-Builder-Paige'); ?> </label></th> <td> <?php $form->add_text_box('description', array('size' => '15', 'maxlength' => '15')); ?> <?php ITUtility::add_tooltip(__('The name helps identify this Layout\'s widget areas. Choose a descriptive, short name.', 'it-l10n-Builder-Paige')); ?> </td> </tr> <tr><th scope="row"><label for="width"><?php _e('Width', 'it-l10n-Builder-Paige'); ?> </label></th> <td> <?php $form->add_drop_down('width', $layout_widths); ?> <?php ITUtility::add_tooltip(__('The width determines how wide the Layout is. Typically, a wider width is better for more complex Layouts that have multiple sidebars while a more narrow width is better for minimalistic Layouts such as one that does not use any sidebars.')); ?> <div id="layout-width-custom" style="display:none;"> <label> <?php _e('Custom Width', 'it-l10n-Builder-Paige'); ?> <?php $form->add_text_box('custom_width', array('size' => '4', 'maxlength' => '5')); ?> <?php _e('pixels', 'it-l10n-Builder-Paige'); ?> </label> </div> </td> </tr> <?php if (builder_theme_supports('builder-extensions')) { ?> <tr><th scope="row"><label for="extension"><?php _e('Extension', 'it-l10n-Builder-Paige'); ?> </label></th> <td> <?php $form->add_drop_down('extension', $extensions); ?> <?php ITUtility::add_tooltip(__('Extensions can provide additional code that changes the content, provides additional features, or modifies the styling of the Layout.<br /><br />You can find Extensions in your theme\'s directory inside a directory named "extensions".', 'it-l10n-Builder-Paige')); ?> <div id="extension-details"></div> </td> </tr> <?php } ?> <tr><th scope="row"><label for="hide_widgets"><?php _e('Hide Widget Areas', 'it-l10n-Builder-Paige'); ?> </label></th> <td> <?php $form->add_drop_down('hide_widgets', array('no' => __('No', 'it-l10n-Builder-Paige'), 'yes' => __('Yes', 'it-l10n-Builder-Paige'))); ?> <?php ITUtility::add_tooltip(__('Use this option to hide this Layout\'s widget areas from the <strong>Appearance > Widgets</strong> editor. This makes it easier to work with other Layout\'s widget areas.', 'it-l10n-Builder-Paige')); ?> </td> </tr> <?php do_action('builder_editor_add_custom_settings', $layout); ?> </table> <h3 class="title">Design</h3> <table class="form-table layout-modules"> <tr class="add-module-help"><td colspan="2"><?php _e('In order to start building your layout, please click the Add Module link below.', 'it-l10n-Builder-Paige'); ?> </td></tr> <?php $position = 1; $max_id = 0; if (isset($layout['modules'])) { foreach ((array) $layout['modules'] as $id => $module) { if (false !== $this->_add_module_fields($module, $id, $position)) { $position++; } if ($id > $max_id) { $max_id = $id; } } } ?> </table> <p class="submit"> <?php $form->add_submit('save', array('value' => __('Save Layout', 'it-l10n-Builder-Paige'), 'class' => 'button-primary')); ?> <?php $form->add_submit('save_and_continue', array('value' => __('Save Layout and Continue Editing', 'it-l10n-Builder-Paige'), 'class' => 'button-secondary')); ?> <?php $form->add_submit('cancel', array('value' => __('Cancel', 'it-l10n-Builder-Paige'), 'class' => 'button-secondary cancel')); ?> </p> <input type="hidden" name="next-position" value="<?php echo $position; ?> " /> <input type="hidden" name="current-position" value="0" /> <input type="hidden" name="next-id" value="<?php echo $max_id + 1; ?> " /> <?php $form->add_hidden('self-link', $this->_self_link); ?> <?php if (isset($_REQUEST['layout'])) { $form->add_hidden('layout', $_REQUEST['layout']); } ?> <?php if (isset($_REQUEST['layout'])) { $form->add_hidden('layout-guid', $layout['guid']); } ?> <?php if (isset($_REQUEST['add_layout'])) { $form->add_hidden('add_layout', $_REQUEST['add_layout']); } ?> <?php $form->add_hidden('base_url', "{$this->_plugin_url}"); ?> <?php $form->end_form(); ?> </div> <?php foreach ((array) $this->_modules as $var => $module) { echo "<table id=\"module-editor-{$var}\" style=\"display:none;\">"; $this->_add_module_fields(array('module' => $var, 'data' => array()), '%id%', '%position%'); echo '</table>'; $form->add_hidden("module-name-{$var}", $module->_name); $form->add_hidden("module-editable-{$var}", method_exists($module, 'edit') ? '1' : '0'); $form->add_hidden("module-max-{$var}", $module->_max); } $module_image_paths = array(); if (is_dir("{$this->_plugin_path}/modules") && ($readdir = opendir("{$this->_plugin_path}/modules"))) { while (($module = readdir($readdir)) !== false) { if (preg_match('/^\\.{1,2}$/', $module)) { continue; } if (is_dir("{$this->_plugin_path}/modules/{$module}") && is_dir("{$this->_plugin_path}/modules/{$module}/images")) { $module_image_paths[] = "modules/{$module}/images"; } } } echo "<div class=\"preload-images\">\n"; foreach ((array) $module_image_paths as $path) { if ($readdir = opendir("{$this->_plugin_path}/{$path}")) { while (($image = readdir($readdir)) !== false) { if (is_file("{$this->_plugin_path}/{$path}/{$image}") && preg_match('/\\.(png|jpg|jpeg|gif)$/i', $image)) { echo "<img src=\"{$this->_plugin_url}/{$path}/{$image}\" alt=\"preload image\" />\n"; } } } } echo "</div>\n"; ?> <script type="text/javascript"> <?php if (isset($extension_descriptions)) { ?> var builder_extension_details = {<?php echo implode(",\n", $extension_descriptions); ?> }; <?php } ?> init_layout_editor(); </script> <?php }
/** * Create a license key. * * @api * * @param array $args { * * @type string $key The license key to be used. If empty, one will be * generated. * @type int $transaction Transaction ID. If empty, one will be manually * generated * @type int $product Product ID. * @type int $customer Customer ID. * @type string $status The key's status. Accepts 'active', 'expired', * 'disabled' * @type float $paid If manually generating a transaction, the amount * paid. * @type int $limit Activation limit. * @type string $expires Expiration date. Pass null or empty string for * forever. * @type string $date When the transaction occurred. GMT. * } * * @return \ITELIC\Key|WP_Error */ function itelic_create_key($args) { $defaults = array('key' => '', 'transaction' => '', 'product' => '', 'customer' => '', 'status' => '', 'paid' => ''); $args = ITUtility::merge_defaults($args, $defaults); $product = itelic_get_product($args['product']); if (!$product->has_feature('licensing')) { return new WP_Error('invalid_product', __("Product does not have licensing enabled.", \ITELIC\Plugin::SLUG)); } $customer = it_exchange_get_customer($args['customer']); if (!$customer) { return new WP_Error('invalid_customer', __("Invalid customer", \ITELIC\Plugin::SLUG)); } $transaction = it_exchange_get_transaction($args['transaction']); if (!$args['transaction']) { if (!function_exists('it_exchange_manual_purchases_addon_transaction_uniqid')) { return new WP_Error('no_manual_purchases', __("Manual purchases add-on is not installed.", \ITELIC\Plugin::SLUG)); } // Grab default currency $settings = it_exchange_get_option('settings_general'); $currency = $settings['default-currency']; $description = array(); $product_id = $product->ID; $itemized_data = apply_filters('it_exchange_add_itemized_data_to_cart_product', array(), $product_id); if (!is_serialized($itemized_data)) { $itemized_data = maybe_serialize($itemized_data); } $key = $product_id . '-' . md5($itemized_data); $products[$key]['product_base_price'] = $product->get_feature('base-price'); $products[$key]['product_subtotal'] = $products[$key]['product_base_price']; //need to add count $products[$key]['product_name'] = get_the_title($product_id); $products[$key]['product_id'] = $product_id; $products[$key]['count'] = 1; $description[] = $products[$key]['product_name']; $description = apply_filters('it_exchange_get_cart_description', join(', ', $description), $description); // Package it up and send it to the transaction method add-on $total = empty($args['paid']) ? 0 : it_exchange_convert_to_database_number($args['paid']); $object = new stdClass(); $object->total = number_format(it_exchange_convert_from_database_number($total), 2, '.', ''); $object->currency = $currency; $object->description = $description; $object->products = $products; remove_action('it_exchange_add_transaction_success', 'ITELIC\\on_add_transaction_generate_license_keys'); $uniquid = it_exchange_manual_purchases_addon_transaction_uniqid(); $txn_args = array(); if (isset($args['date'])) { $date = \ITELIC\make_date_time($args['date']); $txn_args['post_date'] = \ITELIC\convert_gmt_to_local($date)->format('Y-m-d H:i:s'); $txn_args['post_date_gmt'] = $date->format('Y-m-d H:i:s'); } $tid = it_exchange_add_transaction('manual-purchases', $uniquid, 'Completed', $customer->id, $object, $txn_args); add_action('it_exchange_add_transaction_success', 'ITELIC\\on_add_transaction_generate_license_keys'); $transaction = it_exchange_get_transaction($tid); } $factory = new \ITELIC\Key\Factory($product, $customer, $transaction); $key = \ITELIC\generate_key_for_transaction_product($transaction, $product, $factory, $args['status'], $args['key']); if (isset($args['limit'])) { if (empty($args['limit']) || $args['limit'] == '-') { $limit = ''; } else { $limit = $args['limit']; } $key->set_max($limit); } if (isset($args['expires'])) { if (is_string($args['expires'])) { $expires = \ITELIC\make_date_time($args['expires']); } else { $expires = $args['expires']; } if (!$expires instanceof DateTime) { $expires = null; } $key->set_expires($expires); } return $key; }
/** * Return the product's features. * * @since 1.5 * * @param mixed $existing the values passed in by the WP Filter API. Ignored here. * @param integer $product_id the WordPress post ID * @param array $options * * @return string product feature */ function get_feature($existing, $product_id, $options = array()) { $defaults = array('rate' => '', 'disabled' => false); $values = array('rate' => get_post_meta($product_id, '_affwp_it-exchange_product_rate', true), 'disabled' => (bool) get_post_meta($product_id, '_affwp_it-exchange_referrals_disabled', true)); $values = ITUtility::merge_defaults($values, $defaults); if (!isset($options['field'])) { // if we aren't looking for a particular field return $values; } $field = $options['field']; if (isset($values[$field])) { // if the field exists with that name just return it return $values[$field]; } else { if (strpos($field, ".") !== false) { // if the field name was passed using array dot notation $pieces = explode('.', $field); $context = $values; foreach ($pieces as $piece) { if (!is_array($context) || !array_key_exists($piece, $context)) { // error occurred return null; } $context =& $context[$piece]; } return $context; } else { return null; // we didn't find the data specified } } }
/** * Set default variables * * @param $defaults * * @return mixed */ function _get_defaults($defaults) { $new_defaults = array('view' => '', 'expires' => 0, 'cache_mode' => 'none'); return ITUtility::merge_defaults($new_defaults, $defaults); }
function _get_defaults($defaults) { $new_defaults = array('html' => '', 'sidebar' => 'none', 'sidebar_widths' => '', 'enable_eval' => 'no'); return ITUtility::merge_defaults($new_defaults, $defaults); }
/** * Outputs a renew link. * * @since 1.0 * * @param array $options * * @return string */ public function renew_link($options = array()) { $defaults = array('format' => 'html', 'label' => __("Renew this license key", ITELIC\Plugin::SLUG)); $options = ITUtility::merge_defaults($options, $defaults); if (!$this->license) { return ''; } if (!$this->license->is_renewable()) { return ''; } $link = itelic_generate_auto_renewal_url($this->license); switch ($options['format']) { case 'link': return $link; case 'label': return $options['label']; case 'html': default: return '<a href="' . $link . '">' . $options['label'] . '</a>'; } }
/** * Outputs a deactivation link. * * @since 1.0 * * @param array $options * * @return string */ public function deactivate_link($options = array()) { $defaults = array('format' => 'html', 'label' => __('Deactivate', ITELIC\Plugin::SLUG), 'working' => __("Deactivating", ITELIC\Plugin::SLUG)); if (!$this->activation) { return ''; } $options = ITUtility::merge_defaults($options, $defaults); $label = $options['label']; $id = $this->activation->get_id(); $nonce = wp_create_nonce("itelic-deactivate-{$id}"); $working = $options['working']; $link = "<a href=\"javascript:\" class=\"deactivate-location\" data-id=\"{$id}\" data-nonce=\"{$nonce}\" data-working=\"{$working}\">"; $link .= $label; $link .= "</a>"; return $link; }
/** * Set default variables * * @param $defaults * * @return mixed */ function _get_defaults($defaults) { $new_defaults = array('pod_type' => '', 'slug' => '', 'fields' => '', 'label' => __('Submit', 'pods'), 'thank_you' => '', 'sidebar' => 'none'); return ITUtility::merge_defaults($new_defaults, $defaults); }
function load($merge_defaults = true) { if (isset($GLOBALS["it_storage_cache_{$this->_var}"])) { return $GLOBALS["it_storage_cache_{$this->_var}"]; } $data = $original_data = @get_option($this->_option_name); if (true === $merge_defaults) { $defaults = apply_filters("it_storage_get_defaults_{$this->_var}", array()); if (!is_array($defaults)) { $defaults = array(); } $data = ITUtility::merge_defaults($data, $defaults); } if (!isset($data['storage_version'])) { $data['storage_version'] = '0'; // $data = $this->_migrate_old_data( $data ); } $data = apply_filters("it_storage_filter_load_{$this->_var}", $data); if (version_compare($this->_storage_version, $data['storage_version'], '>')) { do_action("it_storage_do_upgrade_{$this->_var}"); $upgrade_data = apply_filters("it_storage_upgrade_{$this->_var}", array('data' => $data, 'current_version' => $this->_storage_version)); $data = $upgrade_data['data']; } $this->_data = $data; $GLOBALS["it_storage_cache_{$this->_var}"] = $data; if ($original_data !== $data) { $this->save($data); } return $data; }
/** * Return the product's features * * @since 1.0 * * @param mixed $existing the values passed in by the WP Filter API. Ignored here. * @param integer $product_id the WordPress post ID * @param array $options * * @return string product feature */ public function get_feature($existing, $product_id, $options = array()) { $defaults = array('enable' => false, 'base_path' => ''); $values = get_post_meta($product_id, '_it_exchange_itelic_upgrade', true); $raw_meta = \ITUtility::merge_defaults($values, $defaults); if (!isset($options['field'])) { // if we aren't looking for a particular field return $raw_meta; } $field = $options['field']; if (isset($raw_meta[$field])) { // if the field exists with that name just return it return $raw_meta[$field]; } else { if (strpos($field, ".") !== false) { // if the field name was passed using array dot notation $pieces = explode('.', $field); $context = $raw_meta; foreach ($pieces as $piece) { if (!is_array($context) || !array_key_exists($piece, $context)) { // error occurred return null; } $context =& $context[$piece]; } return $context; } else { return null; // we didn't find the data specified } } }
/** * Render the page. * * @since 1.0 */ public function render() { $df = it_exchange_php_date_format_to_jquery_datepicker_format(get_option('date_format')); $options = it_exchange_get_option('settings_general'); $position = $options['currency-symbol-position']; $decimals = $options['currency-decimals-separator']; $thousands = $options['currency-thousands-separator']; $symbol = it_exchange_get_currency_symbol($options['default-currency']); $form = \ITUtility::merge_defaults($_POST, array('product' => '', 'customer' => '', 'username' => '', 'email' => '', 'first' => '', 'last' => '', 'activations' => '', 'expiration' => '', 'license' => '', 'paid' => '', 'customer-type' => 'existing')); ?> <form method="POST" action="<?php echo esc_attr(add_query_arg('view', 'add-new', Dispatch::get_tab_link('licenses'))); ?> "> <div class="main-editor"> <?php do_action('itelic_add_new_license_screen_before_steps'); ?> <ol> <?php do_action('itelic_add_new_license_screen_begin_steps'); ?> <li> <label for="product"><?php _e("Select a Product", Plugin::SLUG); ?> </label> <div class="product-container"> <select id="product" name="product"> <?php foreach ($this->products as $product) { ?> <option value="<?php echo $product->ID; ?> " <?php selected($form['product'], $product->ID); ?> > <?php echo $product->post_title; ?> </option> <?php } ?> </select> </div> </li> <li> <fieldset id="customer-type"> <label><?php _e("Select a Customer", Plugin::SLUG); ?> </label> <div class="new-customer-container"> <p> <input type="radio" id="new-customer" name="customer-type" value="new" <?php checked($form['customer-type'], 'new'); ?> > <label for="new-customer"><?php _e("New Customer", Plugin::SLUG); ?> </label> </p> </div> <div class="existing-customer-container"> <p> <input type="radio" id="existing-customer" name="customer-type" value="existing" <?php checked($form['customer-type'], 'existing'); ?> > <label for="existing-customer"><?php _e("Existing Customer", Plugin::SLUG); ?> </label> </p> </div> </fieldset> <fieldset class="new-customer-form <?php echo $form['customer-type'] == 'new' ? '' : 'hide-if-js'; ?> "> <p> <label for="username"><?php _e("Username", Plugin::SLUG); ?> </label> <input type="text" id="username" name="username" value="<?php echo $form['username']; ?> "> </p> <p> <label for="email"><?php _e("Email", Plugin::SLUG); ?> </label> <input type="email" id="email" name="email" value="<?php echo $form['email']; ?> "> </p> <p> <label for="first"><?php _e("First Name", Plugin::SLUG); ?> </label> <input type="text" id="first" name="first" value="<?php echo $form['first']; ?> "> </p> <p> <label for="last"><?php _e("Last Name", Plugin::SLUG); ?> </label> <input type="text" id="last" name="last" value="<?php echo $form['last']; ?> "> </p> </fieldset> <fieldset class="existing-customer-form <?php echo $form['customer-type'] == 'existing' ? '' : 'hide-if-js'; ?> "> <p> <label for="customer" class="screen-reader-text"><?php _e('Customer', Plugin::SLUG); ?> </label> <select id="customer" name="customer"> <?php foreach (get_users() as $user) { ?> <option value="<?php echo $user->ID; ?> " <?php selected($form['customer'], $user->ID); ?> > <?php echo $user->user_login; ?> </option> <?php } ?> </select> </p> </fieldset> </li> <li> <div class="activations-container"> <label for="activations"><?php _e("Activation Limit", Plugin::SLUG); ?> </label> <input type="number" id="activations" name="activations" min="0" value="<?php echo $form['activations']; ?> "> <p class="description"><?php _e("Leave blank for unlimited activations."); ?> </p> </div> </li> <li> <div class="expiration-container"> <label for="expiration"><?php _e("Expiration Date", Plugin::SLUG); ?> </label> <input type="date" id="expiration" name="expiration" value="<?php echo $form['expiration']; ?> " data-format="<?php echo esc_attr($df); ?> "> </div> </li> <li> <div class="key-container"> <label for="license"><?php _e('License Key', Plugin::SLUG); ?> </label> <p> <a href="javascript:" id="trigger-manual-key" class="<?php echo empty($form['license']) ? '' : 'hide-if-js'; ?> "> <?php _e("Set the license key manually.", Plugin::SLUG); ?> </a> <a href="javascript:" id="trigger-automatic-key" class="<?php echo empty($form['license']) ? 'hide-if-js' : ''; ?> "> <?php _e("Let Exchange automatically generate a license key for you.", Plugin::SLUG); ?> </a> </p> <input type="text" name="license" id="license" value="<?php echo $form['license']; ?> " class="<?php echo empty($form['license']) ? 'hide-if-js' : ''; ?> "> </div> </li> <li> <div class="paid-container"> <label for="paid"><?php _e("Amount Paid", Plugin::SLUG); ?> </label> <input type="text" name="paid" id="paid" value="<?php echo $form['paid']; ?> " data-symbol="<?php echo $symbol; ?> " data-symbol-position="<?php echo $position; ?> " data-thousands-separator="<?php echo $thousands; ?> " data-decimals-separator="<?php echo $decimals; ?> "> </div> </li> <?php do_action('itelic_add_new_license_screen_end_steps'); ?> </ol> <?php do_action('itelic_add_new_license_screen_after_steps'); ?> <p class="buttons"> <?php submit_button(__("Create", Plugin::SLUG), 'primary', 'itelic-add-new-key', false); ?> </p> </div> <?php wp_nonce_field('itelic-add-new-key'); ?> </form> <?php }
/** * Add a line of data to this graph. * * @param string $value * @param string $label * @param array $options * * @throws \UnexpectedValueException */ public function add_data_set($value, $label = '', $options = array()) { $defaults = array('value' => $value, 'label' => $label); $this->data_sets[] = \ITUtility::merge_defaults($options, $defaults); }
public static function merge_defaults($values, $defaults, $force = false) { if (!ITUtility::is_associative_array($defaults)) { if (!isset($values)) { return $defaults; } if (false === $force) { return $values; } if (isset($values) || is_array($values)) { return $values; } return $defaults; } foreach ((array) $defaults as $key => $val) { if (!isset($values[$key])) { $values[$key] = null; } $values[$key] = ITUtility::merge_defaults($values[$key], $val, $force); } return $values; }
function _get_simple_input($var, $options, $override_value) { if (empty($options['type'])) { return "<!-- _get_simple_input called without a type option set. -->\n"; } $scrublist['textarea']['value'] = true; $scrublist['file']['value'] = true; $scrublist['dropdown']['value'] = true; $scrublist['dropdown']['type'] = true; $defaults = array(); if (isset($this->_args['widget_instance']) && @method_exists($this->_args['widget_instance'], 'get_field_name')) { $defaults['name'] = $this->_args['widget_instance']->get_field_name($var); } else { if (empty($this->_args['prefix'])) { $defaults['name'] = $var; } else { $defaults['name'] = "{$this->_args['prefix']}-{$var}"; } } $input_group_name = $defaults['name']; $var = str_replace('[]', '', $var); $clean_var = trim(preg_replace('/[^a-z0-9_]+/i', '-', $var), '-'); if (!empty($this->_input_group)) { if (false === strpos($defaults['name'], '[')) { $defaults['name'] = "[{$defaults['name']}]"; } else { $defaults['name'] = preg_replace('/^([^\\[]+)\\[/', '[$1][', $defaults['name']); } $input_group_name = $defaults['name']; $defaults['name'] = "{$this->_input_group}{$defaults['name']}"; $clean_var = trim(preg_replace('/[^a-z0-9_]+/i', '-', $defaults['name']), '-'); } if (isset($this->_args['widget_instance']) && @method_exists($this->_args['widget_instance'], 'get_field_id')) { $defaults['id'] = $this->_args['widget_instance']->get_field_id($var); } else { $defaults['id'] = $clean_var; } if (!empty($options['append_val_to_id']) && true === $options['append_val_to_id'] && !empty($options['value'])) { unset($options['append_val_to_id']); $defaults['id'] .= '-' . trim(preg_replace('/[^a-z0-9_]+/i', '-', $options['value']), '-'); } $options = ITUtility::merge_defaults($options, $defaults); if (false === $override_value && isset($this->_options[$var])) { if (in_array($options['type'], array('checkbox', 'radio'))) { if (is_array($this->_options[$var]) && in_array($options['value'], $this->_options[$var]) || !is_array($this->_options[$var]) && (string) $this->_options[$var] === (string) $options['value']) { $options['checked'] = 'checked'; } } else { if ('dropdown' !== $options['type']) { $options['value'] = $this->_options[$var]; } } } if (!empty($this->_args['prefix']) && preg_match("|^{$this->_args['prefix']}-|", $options['name']) || empty($this->_args['prefix'])) { if (!isset($this->_used_inputs[$this->_input_group]) || !in_array($input_group_name, $this->_used_inputs[$this->_input_group])) { $this->_used_inputs[$this->_input_group][] = $input_group_name; } } $attributes = ''; if (false !== $options) { foreach ((array) $options as $name => $val) { if (!is_array($val) && (!isset($scrublist[$options['type']][$name]) || true !== $scrublist[$options['type']][$name])) { if ('value' == $name) { $val = ITForm::esc_value_attr($val); } else { if (!in_array($options['type'], array('submit', 'button'))) { $val = esc_attr($val); } } $attributes .= "{$name}=\"{$val}\" "; } } } $retval = ''; if ('textarea' === $options['type']) { if (!isset($options['value'])) { $options['value'] = ''; } $retval = "<textarea {$attributes} >" . ITForm::esc_value_attr($options['value']) . '</textarea>'; } else { if ('dropdown' === $options['type']) { $retval = "<select {$attributes}>\n"; if (isset($options['value']) && is_array($options['value'])) { foreach ((array) $options['value'] as $val => $name) { if (is_array($name)) { $options = $name; if (preg_match('/^__optgroup_\\d+$/', $val)) { $retval .= "<optgroup class='it-classes-optgroup-separator'>\n"; } else { $retval .= "<optgroup label='" . esc_attr($val) . "'>\n"; } foreach ((array) $options as $val => $name) { $selected = isset($this->_options[$var]) && (string) $this->_options[$var] === (string) $val ? ' selected="selected"' : ''; $retval .= "<option value=\"" . ITForm::esc_value_attr($val) . "\"{$selected}>{$name}</option>\n"; } $retval .= "</optgroup>\n"; } else { $selected = isset($this->_options[$var]) && (string) $this->_options[$var] === (string) $val ? ' selected="selected"' : ''; $retval .= "<option value=\"" . ITForm::esc_value_attr($val) . "\"{$selected}>{$name}</option>\n"; } } } $retval .= "</select>\n"; } else { $retval = '<input ' . $attributes . '/>'; } } return $retval; }
/** * Set default variables * * @param $defaults * * @return mixed */ function _get_defaults($defaults) { $new_defaults = array('pod_type' => '', 'slug' => '', 'field' => '', 'sidebar' => 'none'); return ITUtility::merge_defaults($new_defaults, $defaults); }
function _get_defaults($defaults) { $new_defaults = array('image' => '', 'attachment' => '', 'height_type' => 'auto', 'height' => '150', 'image_alt' => '', 'url' => '', 'new_window' => '', 'sidebar' => 'none'); return ITUtility::merge_defaults($new_defaults, $defaults); }
/** * Create an activation record. * * @api * * @since 1.0 * * @param array $args * * @return \ITELIC\Activation|WP_Error */ function itelic_create_activation($args) { $defaults = array('key' => '', 'location' => '', 'activation' => '', 'release' => '', 'status' => '', 'track' => 'stable'); $args = ITUtility::merge_defaults($args, $defaults); $key = is_string($args['key']) ? itelic_get_key($args['key']) : $args['key']; if (!$key) { return new WP_Error('invalid_key', __("Invalid Key", \ITELIC\Plugin::SLUG)); } $location = $args['location']; if (!empty($args['activation'])) { if (is_string($args['activation'])) { $activation = \ITELIC\make_date_time($args['activation']); } else { $activation = $args['activation']; } if (!$activation instanceof DateTime) { return new WP_Error('invalid_activation', __("Invalid activation date.", \ITELIC\Plugin::SLUG)); } } else { $activation = null; } if (!empty($args['release'])) { if (is_string($args['release'])) { $release = itelic_get_release($args['release']); } else { $release = $args['release']; } if (!$release instanceof \ITELIC\Release) { return new WP_Error('invalid_release', __("Invalid release.", \ITELIC\Plugin::SLUG)); } } else { $release = null; } $status = $args['status']; try { $activation = \ITELIC\Activation::create($key, $location, $activation, $release, $status); $activation->add_meta('track', $args['track']); } catch (Exception $e) { return new WP_Error('exception', $e->getMessage()); } return $activation; }
function builder_create_child_theme($args = array()) { $default_args = array('child_directory' => false, 'overwrite_existing' => false, 'name' => false, 'source_directory' => get_template_directory(), 'source_type' => 'parent', 'parent_directory' => get_template_directory()); extract(ITUtility::merge_defaults($args, $default_args)); if (empty($name)) { $name = sprintf(__('%s - Custom', 'it-l10n-Builder-Paige'), $themes[basename($parent_directory)]->get('Name')); } $name = preg_replace('/^\\s+/', '', $name); $name = preg_replace('/\\s+$/', '', $name); $themes = wp_get_themes(); $names = array(); foreach ($themes as $theme) { $names[] = $theme->get('Name'); } if (in_array($name, $names)) { $count = 2; while (in_array("{$name} {$count}", $names)) { $count++; } $name = "{$name} {$count}"; } if (empty($child_directory)) { $child_directory = preg_replace('/[^a-z0-9]+/i', '-', ucfirst($name)); if (!preg_match('/^builder/i', $child_directory)) { $child_directory = "Builder-{$child_directory}"; } $child_directory = dirname($parent_directory) . "/{$child_directory}"; } if (is_dir($child_directory) && !$overwrite_existing) { $count = 2; while (is_dir("{$child_directory}-{$count}")) { $count++; } $child_directory .= "-{$count}"; } it_classes_load('it-file-utility.php'); if ('copy' == $source_type) { ITFileUtility::copy($source_directory, $child_directory, array('folder_mode' => 0775, 'file_mode' => 0664)); $stylesheet = file_get_contents("{$child_directory}/style.css"); $stylesheet = preg_replace('/(Theme Name:\\s*).*/i', "\$1{$name}", $stylesheet); file_put_contents("{$child_directory}/style.css", $stylesheet); } else { ITFileUtility::mkdir($child_directory, array('create_index' => false)); $files = array('style.css' => '', 'style-mobile.css' => '', 'style-tablet.css' => '', 'style-responsive.css' => '', 'rtl.css' => '', 'functions-child.php' => 'functions.php', 'screenshot.png' => '', 'screenshot.jpg' => '', 'screenshot.gif' => '', 'images' => '', 'lang' => '', 'plugin-features' => ''); $files = apply_filters('builder-filter-files-to-copy-to-child', $files); $stylesheet_data_headers = array('name' => 'Theme Name', 'theme_uri' => 'Theme URI', 'description' => 'Description', 'author' => 'Author', 'author_uri' => 'Author URI', 'version' => 'Version', 'license' => 'License', 'license_uri' => 'License URI', 'tags' => 'Tags', 'text_domain' => 'Text Domain', 'domain_path' => 'Domain Path', 'template' => 'Template'); $stylesheet_data = get_file_data("{$parent_directory}/style.css", $stylesheet_data_headers); $stylesheet_data['description'] = sprintf(__('This is a generated child theme for the %1$s theme. You should activate and modify this theme instead of %1$s. Doing so allows you to modify this child theme while allowing automatic upgrades for %1$s.', 'it-l10n-Builder-Paige'), $stylesheet_data['name']); $stylesheet_data['name'] = $name; $stylesheet_data['template'] = basename($parent_directory); $child_header = "/*\n"; foreach ($stylesheet_data_headers as $index => $header) { $child_header .= "{$header}: {$stylesheet_data[$index]}\n"; } $child_header .= '*/'; if (isset($files['style.css'])) { $stylesheet = file_get_contents("{$parent_directory}/style.css"); $stylesheet = preg_replace('|/\\*.*Theme Name:.*?\\*/|si', $child_header, $stylesheet); } else { $stylesheet = "{$child_header}\n\n\n@import url('../" . basename($parent_directory) . "/style.css');"; } file_put_contents("{$child_directory}/style.css", $stylesheet); foreach ($files as $source => $destination) { if ('style.css' == $source) { continue; } if (!file_exists("{$parent_directory}/{$source}")) { continue; } if (empty($destination)) { $destination = $source; } ITFileUtility::copy("{$parent_directory}/{$source}", "{$child_directory}/{$destination}", array('folder_mode' => 0775, 'file_mode' => 0664)); } } add_option('builder_manually_switched_theme', true); switch_theme(basename($child_directory)); }
/** * Create a renewal transaction key. * * @api * * @param array $args { * * @type string $key The license key to be used. If empty, one will be * generated. * @type float $paid If manually generating a transaction, the amount paid. * @tpye string $date When the transaction occurred. GMT. * } * * @return IT_Exchange_Transaction */ function itelic_create_renewal_transaction($args) { $defaults = array('key' => '', 'paid' => '', 'date' => ''); $args = ITUtility::merge_defaults($args, $defaults); $key = itelic_get_key($args['key']); if (!$key) { return new WP_Error('invalid_key', __("Invalid key", \ITELIC\Plugin::SLUG)); } $product = $key->get_product(); if (!function_exists('it_exchange_manual_purchases_addon_transaction_uniqid')) { return new WP_Error('no_manual_purchases', __("Manual purchases add-on is not installed.", \ITELIC\Plugin::SLUG)); } // Grab default currency $settings = it_exchange_get_option('settings_general'); $currency = $settings['default-currency']; $description = array(); $product_id = $product->ID; $itemized_data = apply_filters('it_exchange_add_itemized_data_to_cart_product', array(), $product_id); if (!is_serialized($itemized_data)) { $itemized_data = maybe_serialize($itemized_data); } $i = $product_id . '-' . md5($itemized_data); $discounted = new \ITELIC\Renewal\Discount($key); $discounted = $discounted->get_discount_price(); $products[$i]['product_base_price'] = $discounted; $products[$i]['product_subtotal'] = $products[$i]['product_base_price']; //need to add count $products[$i]['product_name'] = get_the_title($product_id); $products[$i]['product_id'] = $product_id; $products[$i]['count'] = 1; $description[] = $products[$i]['product_name']; $description = apply_filters('it_exchange_get_cart_description', join(', ', $description), $description); // Package it up and send it to the transaction method add-on $total = empty($args['paid']) ? $discounted : it_exchange_convert_to_database_number($args['paid']); $object = new stdClass(); $object->total = number_format(it_exchange_convert_from_database_number($total), 2, '.', ''); $object->currency = $currency; $object->description = $description; $object->products = $products; remove_action('it_exchange_add_transaction_success', 'ITELIC\\renew_key_on_renewal_purchase'); $uniquid = it_exchange_manual_purchases_addon_transaction_uniqid(); $txn_args = array(); if (isset($args['date'])) { $date = \ITELIC\make_date_time($args['date']); $txn_args['post_date'] = \ITELIC\convert_gmt_to_local($date)->format('Y-m-d H:i:s'); $txn_args['post_date_gmt'] = $date->format('Y-m-d H:i:s'); } $customer = $key->get_customer()->id; $tid = it_exchange_add_transaction('manual-purchases', $uniquid, 'Completed', $customer, $object, $txn_args); add_action('it_exchange_add_transaction_success', 'ITELIC\\renew_key_on_renewal_purchase'); return it_exchange_get_transaction($tid); }
function filter_default_theme_settings($defaults) { $new_defaults = array('widget_content_the_content_filter' => 'no', 'widget_content_edit_link' => 'yes'); $defaults = ITUtility::merge_defaults($defaults, $new_defaults); return $defaults; }
/** * Return the product's features * * @since 1.0 * * @param mixed $existing the values passed in by the WP Filter API. * Ignored here. * @param integer $product_id the WordPress post ID * @param array $options * * @return string product feature */ public function get_feature($existing, $product_id, $options = array()) { $settings = it_exchange_get_option('addon_itelic'); $defaults = array('enabled' => false, 'online-software' => $settings['sell-online-software'], 'limit' => '', 'key-type' => '', 'update-file' => '', 'version' => '', 'enabled_variant_activations' => false, 'activation_variant' => array()); $values = get_post_meta($product_id, '_it_exchange_itelic_feature', true); $raw_meta = \ITUtility::merge_defaults($values, $defaults); if (!function_exists('it_exchange_variants_addon_create_inital_presets')) { $raw_meta['enabled_variant_activations'] = false; } if (!isset($options['field'])) { // if we aren't looking for a particular field return $raw_meta; } if ($options['field'] == 'limit' && isset($options['for_hash'])) { $hash = $options['for_hash']; if (isset($raw_meta['activation_variant'][$hash])) { return $raw_meta['activation_variant'][$hash]; } else { $atts = it_exchange_get_variant_combo_attributes_from_hash($product_id, $hash); $alt_hashes = it_exchange_addon_get_selected_variant_alts($atts['combo'], $product_id); foreach ($alt_hashes as $alt_hash) { if (isset($raw_meta['activation_variant'][$alt_hash])) { return $raw_meta['activation_variant'][$alt_hash]; } } return null; } } $field = $options['field']; if (isset($raw_meta[$field])) { // if the field exists with that name just return it return $raw_meta[$field]; } else { if (strpos($field, ".") !== false) { // if the field name was passed using array dot notation $pieces = explode('.', $field); $context = $raw_meta; foreach ($pieces as $piece) { if (!is_array($context) || !array_key_exists($piece, $context)) { // error occurred return null; } $context =& $context[$piece]; } return $context; } else { return null; // we didn't find the data specified } } }
/** * Output the settings form for the 'list' key type. * * @since 1.0 * * @param int $product * @param string $prefix * @param array $values */ function render_key_type_list_settings($product, $prefix, $values = array()) { $defaults = array('keys' => ''); $values = \ITUtility::merge_defaults($values, $defaults); ?> <label for="itelic-key-type-list"><?php _e("License Keys", Plugin::SLUG); ?> </label> <textarea id="itelic-key-type-list" name="<?php echo $prefix; ?> [keys]"><?php echo $values['keys']; ?> </textarea> <p class="description"> <?php _e("Enter in license keys, one per line. If empty, a key will be randomly generated.", Plugin::SLUG); ?> </p> <?php }
/** * Set default variables * * @param $defaults * * @return mixed */ function _get_defaults($defaults) { $new_defaults = array('pod_type' => '', 'template' => '', 'template_custom' => '', 'limit' => 15, 'orderby' => '', 'where' => '', 'expires' => 60 * 5, 'cache_mode' => 'transient', 'sidebar' => 'none'); return ITUtility::merge_defaults($new_defaults, $defaults); }