Commit 43366f80 authored by Nahla Shiri's avatar Nahla Shiri

fiche technique PDF

parent b5c95c7f
copy.src.files=false
copy.src.on.open=false
copy.src.target=C:\\xampp\\htdocs\\PhpProject1
index.file=index.php
run.as=LOCAL
url=http://localhost/nap/
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/C:/wamp/www/nap/.htaccess</file>
<file>file:/C:/wamp/www/nap/wp-content/themes/nap/nav-list.php</file>
<file>file:/C:/wamp/www/nap/wp-content/.htaccess</file>
<file>file:/C:/wamp/www/nap/wp-content/themes/nap/sidebar.php</file>
<file>file:/C:/wamp/www/nap/wp-content/themes/nap/header.php</file>
<file>file:/C:/wamp/www/nap/integration/accessoires.php</file>
<file>file:/C:/wamp/www/nap/wp-content/themes/nap/functions.php</file>
<file>file:/C:/wamp/www/nap/wp-content/themes/twentyseventeen/archive.php</file>
<file>file:/C:/wamp/www/nap/wp-content/themes/nap/front-page.php</file>
<file>file:/C:/wamp/www/nap/integration/nav.php</file>
<file>file:/C:/wamp/www/nap/wp-content/themes/nap/legacy.php</file>
<file>file:/C:/wamp/www/nap/wp-content/themes/nap/stories.php</file>
<file>file:/C:/wamp/www/nap/wp-content/themes/nap/uniqpaper.php</file>
</group>
</open-files>
</project-private>
include.path=${php.global.include.path}
php.version=PHP_54
source.encoding=UTF-8
src.dir=.
tags.asp=false
tags.short=false
web.root=.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.php.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/php-project/1">
<name>nap</name>
</data>
</configuration>
</project>
/*
* jQuery UI Progressbar 1.7.2
*
* Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* http://docs.jquery.com/UI/Progressbar
*
* Depends:
* ui.core.js
*/
(function(a){a.widget("ui.progressbar",{_init:function(){this.element.addClass("ui-progressbar ui-widget ui-widget-content ui-corner-all").attr({role:"progressbar","aria-valuemin":this._valueMin(),"aria-valuemax":this._valueMax(),"aria-valuenow":this._value()});this.valueDiv=a('<div class="ui-progressbar-value ui-widget-header ui-corner-left"></div>').appendTo(this.element);this._refreshValue()},destroy:function(){this.element.removeClass("ui-progressbar ui-widget ui-widget-content ui-corner-all").removeAttr("role").removeAttr("aria-valuemin").removeAttr("aria-valuemax").removeAttr("aria-valuenow").removeData("progressbar").unbind(".progressbar");this.valueDiv.remove();a.widget.prototype.destroy.apply(this,arguments)},value:function(b){if(b===undefined){return this._value()}this._setData("value",b);return this},_setData:function(b,c){switch(b){case"value":this.options.value=c;this._refreshValue();this._trigger("change",null,{});break}a.widget.prototype._setData.apply(this,arguments)},_value:function(){var b=this.options.value;if(b<this._valueMin()){b=this._valueMin()}if(b>this._valueMax()){b=this._valueMax()}return b},_valueMin:function(){var b=0;return b},_valueMax:function(){var b=100;return b},_refreshValue:function(){var b=this.value();this.valueDiv[b==this._valueMax()?"addClass":"removeClass"]("ui-corner-right");this.valueDiv.width(b+"%");this.element.attr("aria-valuenow",b)}});a.extend(a.ui.progressbar,{version:"1.7.2",defaults:{value:0}})})(jQuery);;
\ No newline at end of file
/*
* jQuery UI Progressbar 1.8.6
*
* Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* http://docs.jquery.com/UI/Progressbar
*
* Depends:
* jquery.ui.core.js
* jquery.ui.widget.js
*/
(function(b,c){b.widget("ui.progressbar",{options:{value:0},min:0,max:100,_create:function(){this.element.addClass("ui-progressbar ui-widget ui-widget-content ui-corner-all").attr({role:"progressbar","aria-valuemin":this.min,"aria-valuemax":this.max,"aria-valuenow":this._value()});this.valueDiv=b("<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>").appendTo(this.element);this._refreshValue()},destroy:function(){this.element.removeClass("ui-progressbar ui-widget ui-widget-content ui-corner-all").removeAttr("role").removeAttr("aria-valuemin").removeAttr("aria-valuemax").removeAttr("aria-valuenow");
this.valueDiv.remove();b.Widget.prototype.destroy.apply(this,arguments)},value:function(a){if(a===c)return this._value();this._setOption("value",a);return this},_setOption:function(a,d){if(a==="value"){this.options.value=d;this._refreshValue();this._trigger("change");this._value()===this.max&&this._trigger("complete")}b.Widget.prototype._setOption.apply(this,arguments)},_value:function(){var a=this.options.value;if(typeof a!=="number")a=0;return Math.min(this.max,Math.max(this.min,a))},_refreshValue:function(){var a=
this.value();this.valueDiv.toggleClass("ui-corner-right",a===this.max).width(a+"%");this.element.attr("aria-valuenow",a)}});b.extend(b.ui.progressbar,{version:"1.8.6"})})(jQuery);
=== Regenerate Thumbnails ===
Contributors: Viper007Bond
Donate link: http://www.viper007bond.com/donate/
Tags: thumbnail, thumbnails
Requires at least: 2.8
Tested up to: 4.6
Stable tag: trunk
Allows you to regenerate your thumbnails after changing the thumbnail sizes.
== Description ==
Regenerate Thumbnails allows you to regenerate the thumbnails for your image attachments. This is very handy if you've changed any of your thumbnail dimensions (via Settings -> Media) after previously uploading images or have changed to a theme with different featured post image dimensions.
You can either regenerate the thumbnails for all image uploads, individual image uploads, or specific multiple image uploads.
See the [screenshots tab](http://wordpress.org/extend/plugins/regenerate-thumbnails/screenshots/) for more details.
== Installation ==
1. Go to your admin area and select Plugins -> Add new from the menu.
2. Search for "Regenerate Thumbnails".
3. Click install.
4. Click activate.
== Screenshots ==
1. The plugin at work regenerating thumbnails
2. You can resize single images by hovering over their row in the Media Library
2. You can resize specific multiples images using the checkboxes and the "Bulk Actions" dropdown
== ChangeLog ==
= Version 2.2.6 =
* PHP 7 compatibility.
= Version 2.2.5 =
* Updates relating to plugin language pack support.
= Version 2.2.4 =
* Better AJAX response error handling in the JavaScript. This should fix a long-standing bug in this plugin. Props Hew Sutton.
= Version 2.2.3 =
* Make the capability required to use this plugin filterable so themes and other plugins can change it. Props [Jackson Whelan](http://jacksonwhelan.com/).
= Version 2.2.2 =
* Don't check the nonce until we're sure that the action called was for this plugin. Fixes lots of "Are you sure you want to do this?" error messages.
= Version 2.2.1 =
* Fix the bottom bulk action dropdown. Thanks Stefan for pointing out the issue!
= Version 2.2.0 =
* Changes to the Bulk Action functionality were made shortly before the release of WordPress 3.1 which broke the way I implemented the specific multiple image regeneration feature. This version adds to the Bulk Action menu using Javascript as that's the only way to do it currently.
= Version 2.1.3 =
* Move the `error_reporting()` call in the AJAX handler to the beginning so that we're more sure that no PHP errors are outputted. Some hosts disable usage of `set_time_limit()` and calling it was causing a PHP warning to be outputted.
= Version 2.1.2 =
* When regenerating all images, newest images are done first rather than the oldest.
* Fixed a bug with regeneration error reporting in some browsers. Thanks to pete-sch for reporting the error.
* Supress PHP errors in the AJAX handler to avoid sending an invalid JSON response. Thanks to pete-sch for reporting the error.
* Better and more detailed error reporting for when `wp_generate_attachment_metadata()` fails.
= Version 2.1.1 =
* Clean up the wording a bit to better match the new features and just be easier to understand.
* Updated screenshots.
= Version 2.1.0 =
Lots of new features!
* Thanks to a lot of jQuery help from [Boris Schapira](http://borisschapira.com/), a failed image regeneration will no longer stop the whole process.
* The results of each image regeneration is now outputted. You can easily see which images were successfully regenerated and which failed. Was inspired by a concept by Boris.
* There is now a button on the regeneration page that will allow you to abort resizing images for any reason. Based on code by Boris.
* You can now regenerate single images from the Media page. The link to do so will show up in the actions list when you hover over the row.
* You can now bulk regenerate multiple from the Media page. Check the boxes and then select "Regenerate Thumbnails" form the "Bulk Actions" dropdown. WordPress 3.1+ only.
* The total time that the regeneration process took is now displayed in the final status message.
* jQuery UI Progressbar version upgraded.
= Version 2.0.3 =
* Switch out deprecated function call.
= Version 2.0.2 =
* Directly query the database to only fetch what the plugin needs (the attachment ID). This will reduce the memory required as it's not storing the whole row for each attachment.
= Version 2.0.1 =
* I accidentally left a `check_admin_referer()` (nonce check) commented out.
= Version 2.0.0 =
* Recoded from scratch. Now uses an AJAX request per attachment to do the resizing. No more PHP maximum execution time errors or anything like that. Also features a pretty progress bar to let the user know how it's going.
= Version 1.1.0 =
* WordPress 2.7 updates -- code + UI. Thanks to jdub and Patrick F.
= Version 1.0.0 =
* Initial release.
== Upgrade Notice ==
= 2.2.4 =
Better AJAX response error handling in the JavaScript. This should fix a long-standing bug in this plugin. Props Hew Sutton.
= 2.2.3 =
Make the capability required to use this plugin filterable so themes and other plugins can change it. Props [Jackson Whelan](http://jacksonwhelan.com/).
= 2.2.2 =
Fixes lots of "Are you sure you want to do this?" error messages.
= 2.2.1 =
Fix the bottom bulk action dropdown. Thanks Stefan for pointing out the issue!
\ No newline at end of file
<?php
/**
* Bootstrap file for setting the ABSPATH constant
* and loading the wp-config.php file. The wp-config.php
* file will then load the wp-settings.php file, which
* will then set up the WordPress environment.
*
* If the wp-config.php file is not found then an error
* will be displayed asking the visitor to set up the
* wp-config.php file.
*
* Will also search for wp-config.php in WordPress' parent
* directory to allow the WordPress directory to remain
* untouched.
*
* @package WordPress
*/
/** Define ABSPATH as this file's directory */
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', dirname( __FILE__ ) . '/' );
}
error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
/*
* If wp-config.php exists in the WordPress root, or if it exists in the root and wp-settings.php
* doesn't, load wp-config.php. The secondary check for wp-settings.php has the added benefit
* of avoiding cases where the current directory is a nested installation, e.g. / is WordPress(a)
* and /blog/ is WordPress(b).
*
* If neither set of conditions is true, initiate loading the setup process.
*/
if ( file_exists( ABSPATH . 'wp-config.php') ) {
/** The config file resides in ABSPATH */
require_once( ABSPATH . 'wp-config.php' );
} elseif ( @file_exists( dirname( ABSPATH ) . '/wp-config.php' ) && ! @file_exists( dirname( ABSPATH ) . '/wp-settings.php' ) ) {
/** The config file resides one level above ABSPATH but is not part of another install */
require_once( dirname( ABSPATH ) . '/wp-config.php' );
} else {
// A config file doesn't exist
define( 'WPINC', 'wp-includes' );
require_once( ABSPATH . WPINC . '/load.php' );
// Standardize $_SERVER variables across setups.
wp_fix_server_vars();
require_once( ABSPATH . WPINC . '/functions.php' );
$path = wp_guess_url() . '/wp-admin/setup-config.php';
/*
* We're going to redirect to setup-config.php. While this shouldn't result
* in an infinite loop, that's a silly thing to assume, don't you think? If
* we're traveling in circles, our last-ditch effort is "Need more help?"
*/
if ( false === strpos( $_SERVER['REQUEST_URI'], 'setup-config' ) ) {
header( 'Location: ' . $path );
exit;
}
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
require_once( ABSPATH . WPINC . '/version.php' );
wp_check_php_mysql_versions();
wp_load_translations_early();
// Die with an error message
$die = sprintf(
/* translators: %s: wp-config.php */
__( "There doesn't seem to be a %s file. I need this before we can get started." ),
'<code>wp-config.php</code>'
) . '</p>';
$die .= '<p>' . sprintf(
/* translators: %s: Codex URL */
__( "Need more help? <a href='%s'>We got it</a>." ),
__( 'https://codex.wordpress.org/Editing_wp-config.php' )
) . '</p>';
$die .= '<p>' . sprintf(
/* translators: %s: wp-config.php */
__( "You can create a %s file through a web interface, but this doesn't work for all server setups. The safest way is to manually create the file." ),
'<code>wp-config.php</code>'
) . '</p>';
$die .= '<p><a href="' . $path . '" class="button button-large">' . __( "Create a Configuration File" ) . '</a>';
wp_die( $die, __( 'WordPress &rsaquo; Error' ) );
}
<?php
function pmwi_admin_notices() {
// notify user if history folder is not writable
if ( ! class_exists( 'Woocommerce' )) {
?>
<div class="error"><p>
<?php printf(
__('<b>%s Plugin</b>: WooCommerce must be installed.', 'wpai_woocommerce_addon_plugin'),
PMWI_Plugin::getInstance()->getName()
) ?>
</p></div>
<?php
deactivate_plugins( PMWI_ROOT_DIR . '/wpai-woocommerce-add-on.php');
}
if ( ! class_exists( 'PMXI_Plugin' ) ) {
?>
<div class="error"><p>
<?php printf(
__('<b>%s Plugin</b>: WP All Import must be installed. Free edition of WP All Import at <a href="http://wordpress.org/plugins/wp-all-import/" target="_blank">http://wordpress.org/plugins/wp-all-import/</a> and the paid edition at <a href="http://www.wpallimport.com/">http://www.wpallimport.com/</a>', 'wpai_woocommerce_addon_plugin'),
PMWI_Plugin::getInstance()->getName()
) ?>
</p></div>
<?php
deactivate_plugins( PMWI_ROOT_DIR . '/wpai-woocommerce-add-on.php');
}
if ( class_exists( 'PMXI_Plugin' ) and ( version_compare(PMXI_VERSION, '4.1.4 RC5') < 0 and PMXI_EDITION == 'paid' or version_compare(PMXI_VERSION, '3.2.7') <= 0 and PMXI_EDITION == 'free') ) {
?>
<div class="error"><p>
<?php printf(
__('<b>%s Plugin</b>: Please update your WP All Import to the latest version', 'wpai_woocommerce_addon_plugin'),
PMWI_Plugin::getInstance()->getName()
) ?>
</p></div>
<?php
deactivate_plugins( PMWI_ROOT_DIR . '/wpai-woocommerce-add-on.php');
}
if ( class_exists( 'Woocommerce' ) and defined('WOOCOMMERCE_VERSION') and version_compare(WOOCOMMERCE_VERSION, '2.1') <= 0 ) {
?>
<div class="error"><p>
<?php printf(
__('<b>%s Plugin</b>: Please update your WooCommerce to the latest version', 'wpai_woocommerce_addon_plugin'),
PMWI_Plugin::getInstance()->getName()
) ?>
</p></div>
<?php
deactivate_plugins( PMWI_ROOT_DIR . '/wpai-woocommerce-add-on.php');
}
$input = new PMWI_Input();
$messages = $input->get('PMWI_nt', array());
if ($messages) {
is_array($messages) or $messages = array($messages);
foreach ($messages as $type => $m) {
in_array((string)$type, array('updated', 'error')) or $type = 'updated';
?>
<div class="<?php echo $type ?>"><p><?php echo $m ?></p></div>
<?php
}
}
}
\ No newline at end of file
<?php
function pmwi_pmxi_after_xml_import($import_id)
{
$import = new PMXI_Import_Record();
$import->getById($import_id);
if ( ! $import->isEmpty() and in_array($import->options['custom_type'], array('product', 'product_variation')) and $import->options['is_keep_former_posts'] == 'no' and ( $import->options['update_all_data'] == 'yes' or $import->options['is_update_categories']))
{
$product_cats = get_terms( 'product_cat', array( 'hide_empty' => false, 'fields' => 'id=>parent' ) );
_wc_term_recount( $product_cats, get_taxonomy( 'product_cat' ), true, false );
$product_tags = get_terms( 'product_tag', array( 'hide_empty' => false, 'fields' => 'id=>parent' ) );
_wc_term_recount( $product_tags, get_taxonomy( 'product_tag' ), true, false );
}
}
\ No newline at end of file
<?php
function pmwi_pmxi_before_xml_import( $import_id )
{
delete_option('wp_all_import_' . $import_id . '_parent_product');
delete_option('wp_all_import_not_linked_products_' . $import_id);
delete_option('wp_all_import_previously_updated_order_' . $import_id);
}
\ No newline at end of file
<?php
function pmwi_pmxi_confirm_data_to_import( $isWizard, $post )
{
// render order's view only for bundle and import with WP All Import featured
if ( $post['custom_type'] == 'shop_order' && class_exists('WooCommerce') ):
$pmwi_controller = new PMWI_Admin_Import();
$pmwi_controller->confirm( $isWizard, $post );
endif;
}
<?php
function pmwi_pmxi_do_not_update_existing($post_to_update_id, $import_id, $iteration){
$args = array(
'post_type' => 'product_variation',
'meta_query' => array(
array(
'key' => '_sku',
'value' => get_post_meta($post_to_update_id, '_sku', true),
)
)
);
$query = new WP_Query( $args );
if ( $query->have_posts() ){
$duplicate_id = $query->post->ID;
if ($duplicate_id) {
$postRecord = new PMXI_Post_Record();
$postRecord->clear();
$postRecord->getBy(array(
'post_id' => $duplicate_id,
'import_id' => $import_id
));
if ( ! $postRecord->isEmpty() ) $postRecord->set(array('iteration' => $iteration))->update();
}
}
}
?>
\ No newline at end of file
<?php
function pmwi_pmxi_extend_options_main($entry, $post = array())
{
if ( ! in_array($entry, array('product', 'shop_order')) and empty($post['is_override_post_type'])) return;
$woo_controller = new PMWI_Admin_Import();
$woo_controller->index($post);
}
<?php
function pmwi_pmxi_options_tab( $isWizard, $post )
{
// render order's view only for bundle and import with WP All Import featured
if ( $post['custom_type'] == 'shop_order' && class_exists('WooCommerce') ):
$pmwi_controller = new PMWI_Admin_Import();
$pmwi_controller->options( $isWizard, $post );
endif;
}
<?php
function pmwi_pmxi_reimport($post_type, $post){
if ( ! in_array($post_type, array('product')) and empty($post['is_override_post_type']) or ! class_exists('WooCommerce')) return;
switch ($post_type)
{
case 'product':
$all_existing_attributes = array();
$hide_taxonomies = array('product_type');
$post_taxonomies = array_diff_key(get_taxonomies_by_object_type(array($post_type), 'object'), array_flip($hide_taxonomies));
if (!empty($post_taxonomies)):
foreach ($post_taxonomies as $ctx): if ("" == $ctx->labels->name or strpos($ctx->name, "pa_") === false) continue;
$all_existing_attributes[] = $ctx->name;
endforeach;
endif;
if (!empty($existing_attributes)):
foreach ($existing_attributes as $key => $attr) {
$all_existing_attributes[] = $attr;
}
endif;
?>
<div class="input">
<input type="hidden" name="is_update_product_type" value="0" />
<input type="checkbox" id="is_update_product_type_<?php echo $post_type; ?>" name="is_update_product_type" value="1" <?php echo $post['is_update_product_type'] ? 'checked="checked"': '' ?> class="switcher"/>
<label for="is_update_product_type_<?php echo $post_type; ?>"><?php _e('Product Type', 'wpai_woocommerce_addon_plugin') ?></label>
</div>
<div class="input">
<input type="hidden" name="attributes_list" value="0" />
<input type="hidden" name="is_update_attributes" value="0" />
<input type="checkbox" id="is_update_attributes_<?php echo $post_type; ?>" name="is_update_attributes" value="1" <?php echo $post['is_update_attributes'] ? 'checked="checked"': '' ?> class="switcher"/>
<label for="is_update_attributes_<?php echo $post_type; ?>"><?php _e('Attributes', 'wpai_woocommerce_addon_plugin') ?></label>
<div class="switcher-target-is_update_attributes_<?php echo $post_type; ?>" style="padding-left:17px;">
<div class="input">
<input type="radio" id="update_attributes_logic_full_update_<?php echo $post_type; ?>" name="update_attributes_logic" value="full_update" <?php echo ( "full_update" == $post['update_attributes_logic'] ) ? 'checked="checked"': '' ?> class="switcher"/>
<label for="update_attributes_logic_full_update_<?php echo $post_type; ?>"><?php _e('Update all Attributes', 'wpai_woocommerce_addon_plugin') ?></label>
</div>
<div class="input">
<input type="radio" id="update_attributes_logic_only_<?php echo $post_type; ?>" name="update_attributes_logic" value="only" <?php echo ( "only" == $post['update_attributes_logic'] ) ? 'checked="checked"': '' ?> class="switcher"/>
<label for="update_attributes_logic_only_<?php echo $post_type; ?>"><?php _e('Update only these Attributes, leave the rest alone', 'wpai_woocommerce_addon_plugin') ?></label>
<div class="switcher-target-update_attributes_logic_only_<?php echo $post_type; ?> pmxi_choosen" style="padding-left:17px;">
<span class="hidden choosen_values"><?php if (!empty($all_existing_attributes)) echo implode(',', $all_existing_attributes);?></span>
<input class="choosen_input" value="<?php if (!empty($post['attributes_list']) and "only" == $post['update_attributes_logic']) echo implode(',', $post['attributes_list']); ?>" type="hidden" name="attributes_only_list"/>
</div>
</div>
<div class="input">
<input type="radio" id="update_attributes_logic_all_except_<?php echo $post_type; ?>" name="update_attributes_logic" value="all_except" <?php echo ( "all_except" == $post['update_attributes_logic'] ) ? 'checked="checked"': '' ?> class="switcher"/>
<label for="update_attributes_logic_all_except_<?php echo $post_type; ?>"><?php _e('Leave these attributes alone, update all other Attributes', 'wpai_woocommerce_addon_plugin') ?></label>
<div class="switcher-target-update_attributes_logic_all_except_<?php echo $post_type; ?> pmxi_choosen" style="padding-left:17px;">
<span class="hidden choosen_values"><?php if (!empty($all_existing_attributes)) echo implode(',', $all_existing_attributes);?></span>
<input class="choosen_input" value="<?php if (!empty($post['attributes_list']) and "all_except" == $post['update_attributes_logic']) echo implode(',', $post['attributes_list']); ?>" type="hidden" name="attributes_except_list"/>
</div>
</div>
</div>
</div>
<?php
break;
default:
# code...
break;
}
}
\ No newline at end of file
<?php
/**
* Class to load config files
*
* @author Pavel Kulbakin <p.kulbakin@gmail.com>
*/
class PMWI_Config implements IteratorAggregate {
/**
* Config variables stored
* @var array
*/
protected $config = array();
/**
* List of loaded files in order to avoid loading same file several times
* @var array
*/
protected $loaded = array();
/**
* Static method to create config instance from file on disc
* @param string $filePath
* @param string[optional] $section
* @return PMWI_Config
*/
public static function createFromFile($filePath, $section = NULL) {
$config = new self();
return $config->loadFromFile($filePath, $section);
}
/**
* Load config file
* @param string $filePath
* @param string[optional] $section
* @return PMWI_Config
*/
public function loadFromFile($filePath, $section = NULL) {
if ( ! is_null($section)) {
$this->config[$section] = self::createFromFile($filePath);
} else {
$filePath = realpath($filePath);
if ($filePath and ! in_array($filePath, $this->loaded)) {
require $filePath;
$sandbox = create_function('', "require '$filePath'; if(array_keys(get_defined_vars()) != array('config')) return array(); return \$config;");
$config = $sandbox();
$this->loaded[] = $filePath;
$this->config = array_merge($this->config, $config);
}
}
return $this;
}
/**
* Return value of setting with specified name
* @param string $field Setting name
* @param string[optional] $section Section name to look setting in
* @return mixed
*/
public function get($field, $section = NULL) {
return ! is_null($section) ? $this->config[$section]->get($field) : $this->config[$field];
}
/**
* Magic method for checking whether some config option are set
* @param string $field
* @return bool
*/
public function __isset($field) {
return isset($this->config[$field]);
}
/**
* Magic method to implement object-like access to config parameters
* @param string $field
* @return mixed
*/
public function __get($field) {
return $this->config[$field];
}
/**
* Return all config options as array
* @return array
*/
public function toArray($section = NULL) {
return ! is_null($section) ? $this->config[$section]->toArray() : $this->config;
}
public function getIterator() {
return new ArrayIterator($this->config);
}
}
\ No newline at end of file
<?php
/**
* Helper class which defnes a namespace for some commonly used functions
*
* @author Pavel Kulbakin <p.kulbakin@gmail.com>
*/
class PMWI_Helper {
const GLOB_MARK = 1;
const GLOB_NOSORT = 2;
const GLOB_ONLYDIR = 4;
const GLOB_NODIR = 256;
const GLOB_PATH = 512;
const GLOB_NODOTS = 1024;
const GLOB_RECURSE = 2048;
const FNM_PATHNAME = 1;
const FNM_NOESCAPE = 2;
const FNM_PERIOD = 4;
const FNM_CASEFOLD = 16;
/**
* A safe empowered glob().
*
* Function glob() is prohibited on some server (probably in safe mode)
* (Message "Warning: glob() has been disabled for security reasons in
* (script) on line (line)") for security reasons as stated on:
* http://seclists.org/fulldisclosure/2005/Sep/0001.html
*
* safe_glob() intends to replace glob() using readdir() & fnmatch() instead.
* Supported flags: self::GLOB_MARK, self::GLOB_NOSORT, self::GLOB_ONLYDIR
* Additional flags: self::GLOB_NODIR, self::GLOB_PATH, self::GLOB_NODOTS, self::GLOB_RECURSE
* (not original glob() flags)
* @author BigueNique AT yahoo DOT ca
* @updates
* - 080324 Added support for additional flags: self::GLOB_NODIR, self::GLOB_PATH,
* self::GLOB_NODOTS, self::GLOB_RECURSE
* - 100607 Recurse is_dir check fixed by Pavel Kulbakin <p.kulbakin@gmail.com>
*/
public static function safe_glob($pattern, $flags=0) {
$split = explode('/', str_replace('\\', '/', $pattern));
$mask = array_pop($split);
$path = implode('/', $split);
if (($dir = @opendir($path)) !== false or ($dir = @opendir($path . '/')) !== false) {
$glob = array();
while(($file = readdir($dir)) !== false) {
// Recurse subdirectories (self::GLOB_RECURSE)
if (($flags & self::GLOB_RECURSE) && is_dir($path . '/' . $file) && ( ! in_array($file, array('.', '..')))) {
$glob = array_merge($glob, self::array_prepend(self::safe_glob($path . '/' . $file . '/' . $mask, $flags), ($flags & self::GLOB_PATH ? '' : $file . '/')));
}
// Match file mask
if (self::fnmatch($mask, $file)) {
if ((( ! ($flags & self::GLOB_ONLYDIR)) || is_dir("$path/$file"))
&& (( ! ($flags & self::GLOB_NODIR)) || ( ! is_dir($path . '/' . $file)))
&& (( ! ($flags & self::GLOB_NODOTS)) || ( ! in_array($file, array('.', '..'))))
) {
$glob[] = ($flags & self::GLOB_PATH ? $path . '/' : '') . $file . ($flags & self::GLOB_MARK ? '/' : '');
}
}
}
closedir($dir);
if ( ! ($flags & self::GLOB_NOSORT)) sort($glob);
return $glob;
} else {
return false;
}
}
/**
* Prepends $string to each element of $array
* If $deep is true, will indeed also apply to sub-arrays
* @author BigueNique AT yahoo DOT ca
* @since 080324
*/
public static function array_prepend($array, $string, $deep=false) {
if(empty($array)||empty($string)) {
return $array;
}
foreach ($array as $key => $element) {
if (is_array($element)) {
if ($deep) {
$array[$key] = self::array_prepend($element,$string,$deep);
} else {
trigger_error(__METHOD__ . ': array element', E_USER_WARNING);
}
} else {
$array[$key] = $string.$element;
}
}
return $array;
}
/**
* non-POSIX complient remplacement for the fnmatch
*/
public static function fnmatch($pattern, $string, $flags = 0) {
$modifiers = null;
$transforms = array(
'\*' => '.*',
'\?' => '.',
'\[\!' => '[^',
'\[' => '[',
'\]' => ']',
'\.' => '\.',
'\\' => '\\\\',
'\-' => '-',
);
// Forward slash in string must be in pattern:
if ($flags & self::FNM_PATHNAME) {
$transforms['\*'] = '[^/]*';
}
// Back slash should not be escaped:
if ($flags & self::FNM_NOESCAPE) {
unset($transforms['\\']);
}
// Perform case insensitive match:
if ($flags & self::FNM_CASEFOLD) {
$modifiers .= 'i';
}
// Period at start must be the same as pattern:
if ($flags & self::FNM_PERIOD) {
if (strpos($string, '.') === 0 && strpos($pattern, '.') !== 0) return false;
}
$pattern = '#^'
.strtr(preg_quote($pattern, '#'), $transforms)
.'$#'
.$modifiers;
return (boolean)preg_match($pattern, $string);
}
}
<?php
class PMWI_Input {
protected $filters = array('stripslashes');
public function read($inputArray, $paramName, $default = NULL) {
if (is_array($paramName) and ! is_null($default)) {
throw new Exception('Either array of parameter names with default values as the only argument or param name and default value as seperate arguments are expected.');
}
if (is_array($paramName)) {
foreach ($paramName as $param => $def) {
if (isset($inputArray[$param])) {
$paramName[$param] = $this->applyFilters($inputArray[$param]);
}
}
return $paramName;
} else {
return isset($inputArray[$paramName]) ? $this->applyFilters($inputArray[$paramName]) : $default;
}
}
public function get($paramName, $default = NULL) {
$this->addFilter('strip_tags');
$this->addFilter('htmlspecialchars');
$this->addFilter('esc_sql');
$result = $this->read($_GET, $paramName, $default);
$this->removeFilter('strip_tags');
$this->removeFilter('htmlspecialchars');
$this->removeFilter('esc_sql');
return $result;
}
public function post($paramName, $default = NULL) {
return $this->read($_POST, $paramName, $default);
}
public function cookie($paramName, $default = NULL) {
return $this->read($_COOKIE, $paramName, $default);
}
public function request($paramName, $default = NULL) {
return $this->read($_GET + $_POST + $_COOKIE, $paramName, $default);
}
public function getpost($paramName, $default = NULL) {
return $this->read($_GET + $_POST, $paramName, $default);
}
public function server($paramName, $default = NULL) {
return $this->read($_SERVER, $paramName, $default);
}
public function addFilter($callback) {
if ( ! is_callable($callback)) {
throw new Exception(get_class($this) . '::' . __METHOD__ . ' parameter must be a proper callback function reference.');
}
if ( ! in_array($callback, $this->filters)) {
$this->filters[] = $callback;
}
return $this;
}
public function removeFilter($callback) {
$this->filters = array_diff($this->filters, array($callback));
return $this;
}
protected function applyFilters($val) {
if (is_array($val)) {
foreach ($val as $k => $v) {
$val[$k] = $this->applyFilters($v);
}
} else {
foreach ($this->filters as $filter) {
$val = call_user_func($filter, $val);
}
}
return $val;
}
}
\ No newline at end of file
This diff is collapsed.
<?php
/**
* List of plugin optins, contains only default values, actual values are stored in database
* and can be changed by corresponding wordpress function calls
*/
$config = array(
/*"info_api_url" => "http://www.wpallimport.com/adminpanel/wooco-update/info.php", */
);
<?php
/**
*
* @author Pavel Kulbakin <p.kulbakin@gmail.com>
*/
class PMWI_Admin_Import extends PMWI_Controller_Admin
{
public function index($post) {
$this->data['post'] =& $post;
switch ($post['custom_type'])
{
case 'product':
$this->render('admin/import/product/index');
break;
case 'shop_order':
$this->render('admin/import/shop_order/index');
break;
default:
# code...
break;
}
}
public function options( $isWizard = false, $post = array() )
{
$this->data['isWizard'] = $isWizard;
$this->data['post'] =& $post;
$this->data['existing_meta_keys'] = array();
if ( ! in_array($post['custom_type'], array('import_users'))){
global $wpdb;
// Get all meta keys for requested post type
$hide_fields = array('_wp_page_template', '_edit_lock', '_edit_last', '_wp_trash_meta_status', '_wp_trash_meta_time');
$records = get_posts( array('post_type' => $post['custom_type']) );
if ( ! empty($records)){
foreach ($records as $record) {
$record_meta = get_post_meta($record->ID, '');
if ( ! empty($record_meta)){
foreach ($record_meta as $record_meta_key => $record_meta_value) {
if ( ! in_array($record_meta_key, $this->data['existing_meta_keys']) and ! in_array($record_meta_key, $hide_fields)) $this->data['existing_meta_keys'][] = $record_meta_key;
}
}
}
}
}
$this->render();
}
public function confirm( $isWizard = false, $post = array() )
{
$this->data['isWizard'] = $isWizard;
$this->data['post'] =& $post;
$this->data['existing_meta_keys'] = array();
$this->render();
}
}
<?php
/**
* Common logic for all shortcodes plugin implements
*
* @author Pavel Kulbakin <p.kulbakin@gmail.com>
*/
abstract class PMWI_Controller {
/**
* Input class instance to retrieve parameters submitted during page request
* @var PMWI_Input
*/
protected $input;
/**
* Error messages
* @var WP_Error
*/
protected $errors;
/**
* Associative array of data which will be automatically available as variables when template is rendered
* @var array
*/
public $data = array();
/**
* Constructor
*/
public function __construct() {
$this->input = new PMWI_Input();
$this->input->addFilter('trim');
$this->errors = new WP_Error();
$this->init();
}
/**
* Method to put controller initialization logic to
*/
protected function init() {}
/**
* Checks wether protocol is HTTPS and redirects user to secure connection if not
*/
protected function force_ssl() {
if (force_ssl_admin() && ! is_ssl()) {
if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI'])); die();
} else {
wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); die();
}
}
}
/**
* Method returning resolved template content
*
* @param string[optional] $viewPath Template path to render
*/
protected function render($viewPath = null) {
// assume template file name depending on calling function
if (is_null($viewPath)) {
$trace = debug_backtrace();
$viewPath = str_replace('_', '/', preg_replace('%^' . preg_quote(PMWI_Plugin::PREFIX, '%') . '%', '', strtolower($trace[1]['class']))) . '/' . $trace[1]['function'];
}
// append file extension if not specified
if ( ! preg_match('%\.php$%', $viewPath)) {
$viewPath .= '.php';
}
$filePath = PMWI_Plugin::ROOT_DIR . '/views/' . $viewPath;
if (is_file($filePath)) {
extract($this->data);
include $filePath;
} else {
throw new Exception("Requested template file $filePath is not found.");
}
}
/**
* Display list of errors
*
* @param string|array|WP_Error[optional] $msgs
*/
protected function error($msgs = NULL) {
if (is_null($msgs)) {
$msgs = $this->errors;
}
if (is_wp_error($msgs)) {
$msgs = $msgs->get_error_messages();
}
if ( ! is_array($msgs)) {
$msgs = array($msgs);
}
$this->data['errors'] = $msgs;
$viewPathRel = str_replace('_', '/', preg_replace('%^' . preg_quote(PMWI_Plugin::PREFIX, '%') . '%', '', strtolower(get_class($this)))) . '/error.php';
if (is_file(PMWI_Plugin::ROOT_DIR . '/views/' . $viewPathRel)) { // if calling controller class has specific error view
$this->render($viewPathRel);
} else { // render default error view
$this->render('controller/error.php');
}
}
}
\ No newline at end of file
<?php
/**
* Introduce special type for controllers which render pages inside admin area
*
* @author Pavel Kulbakin <p.kulbakin@gmail.com>
*/
abstract class PMWI_Controller_Admin extends PMWI_Controller {
/**
* Admin page base url (request url without all get parameters but `page`)
* @var string
*/
public $baseUrl;
/**
* Parameters which is left when baseUrl is detected
* @var array
*/
public $baseUrlParamNames = array('page', 'pagenum', 'order', 'order_by', 'type', 's', 'f');
/**
* Whether controller is rendered inside wordpress page
* @var bool
*/
public $isInline = false;
/**
* Constructor
*/
public function __construct() {
$remove = array_diff(array_keys($_GET), $this->baseUrlParamNames);
if ($remove) {
$this->baseUrl = remove_query_arg($remove);
} else {
$this->baseUrl = $_SERVER['REQUEST_URI'];
}
parent::__construct();
// add special filter for url fields
$this->input->addFilter(create_function('$str', 'return "http://" == $str || "ftp://" == $str ? "" : $str;'));
// enqueue required sripts and styles
global $wp_styles;
if ( ! is_a($wp_styles, 'WP_Styles'))
$wp_styles = new WP_Styles();
wp_enqueue_style('pmwi-admin-style', PMWI_ROOT_URL . '/static/css/admin.css', array(), PMWI_VERSION);
if ( version_compare(get_bloginfo('version'), '3.8-RC1') >= 0 ){
wp_enqueue_style('pmwi-admin-style-wp-3.8', PMWI_ROOT_URL . '/static/css/admin-wp-3.8.css');
}
wp_enqueue_script('pmwi-script', PMWI_ROOT_URL . '/static/js/pmwi.js', array('jquery'));
wp_enqueue_script('pmwi-admin-script', PMWI_ROOT_URL . '/static/js/admin.js', array('jquery', 'jquery-ui-core', 'jquery-ui-resizable', 'jquery-ui-dialog', 'jquery-ui-datepicker', 'jquery-ui-draggable', 'jquery-ui-droppable', 'pmxi-admin-script'), PMWI_VERSION);
global $woocommerce;
$woocommerce_witepanel_params = array(
'remove_item_notice' => __("Remove this item? If you have previously reduced this item's stock, or this order was submitted by a customer, will need to manually restore the item's stock.", 'wpai_woocommerce_addon_plugin'),
'remove_attribute' => __('Remove this attribute?', 'wpai_woocommerce_addon_plugin'),
'name_label' => __('Name', 'wpai_woocommerce_addon_plugin'),
'remove_label' => __('Remove', 'wpai_woocommerce_addon_plugin'),
'click_to_toggle' => __('Click to toggle', 'wpai_woocommerce_addon_plugin'),
'values_label' => __('Value(s)', 'wpai_woocommerce_addon_plugin'),
'text_attribute_tip' => __('Enter some text, or some attributes by pipe (|) separating values.', 'wpai_woocommerce_addon_plugin'),
'visible_label' => __('Visible on the product page', 'wpai_woocommerce_addon_plugin'),
'used_for_variations_label' => __('Used for variations', 'wpai_woocommerce_addon_plugin'),
'new_attribute_prompt' => __('Enter a name for the new attribute term:', 'wpai_woocommerce_addon_plugin'),
'calc_totals' => __("Calculate totals based on order items, discount amount, and shipping? Note, you will need to (optionally) calculate tax rows and cart discounts manually.", 'wpai_woocommerce_addon_plugin'),
'calc_line_taxes' => __("Calculate line taxes? This will calculate taxes based on the customers country. If no billing/shipping is set it will use the store base country.", 'wpai_woocommerce_addon_plugin'),
'copy_billing' => __("Copy billing information to shipping information? This will remove any currently entered shipping information.", 'wpai_woocommerce_addon_plugin'),
'load_billing' => __("Load the customer's billing information? This will remove any currently entered billing information.", 'wpai_woocommerce_addon_plugin'),
'load_shipping' => __("Load the customer's shipping information? This will remove any currently entered shipping information.", 'wpai_woocommerce_addon_plugin'),
'featured_label' => __('Featured', 'wpai_woocommerce_addon_plugin'),
'tax_or_vat' => $woocommerce->countries->tax_or_vat(),
'prices_include_tax' => get_option('woocommerce_prices_include_tax'),
'round_at_subtotal' => get_option( 'woocommerce_tax_round_at_subtotal' ),
'meta_name' => __('Meta Name', 'wpai_woocommerce_addon_plugin'),
'meta_value' => __('Meta Value', 'wpai_woocommerce_addon_plugin'),
'no_customer_selected' => __('No customer selected', 'wpai_woocommerce_addon_plugin'),
'tax_label' => __('Tax Label:', 'wpai_woocommerce_addon_plugin'),
'compound_label' => __('Compound:', 'wpai_woocommerce_addon_plugin'),
'cart_tax_label' => __('Cart Tax:', 'wpai_woocommerce_addon_plugin'),
'shipping_tax_label' => __('Shipping Tax:', 'wpai_woocommerce_addon_plugin'),
'plugin_url' => $woocommerce->plugin_url(),
'ajax_url' => admin_url('admin-ajax.php'),
'add_order_item_nonce' => wp_create_nonce("add-order-item"),
'add_attribute_nonce' => wp_create_nonce("add-attribute"),
'calc_totals_nonce' => wp_create_nonce("calc-totals"),
'get_customer_details_nonce' => wp_create_nonce("get-customer-details"),
'search_products_nonce' => wp_create_nonce("search-products"),
'calendar_image' => $woocommerce->plugin_url().'/assets/images/calendar.png',
'post_id' => null
);
wp_localize_script( 'woocommerce_writepanel', 'woocommerce_writepanel_params', $woocommerce_witepanel_params );
wp_enqueue_style('pmwi-woo-style', $woocommerce->plugin_url() . '/assets/css/admin.css');
}
/**
* @see Controller::render()
*/
protected function render($viewPath = NULL)
{
// assume template file name depending on calling function
if (is_null($viewPath)) {
$trace = debug_backtrace();
$viewPath = str_replace('_', '/', preg_replace('%^' . preg_quote(PMWI_Plugin::PREFIX, '%') . '%', '', strtolower($trace[1]['class']))) . '/' . $trace[1]['function'];
}
// render contextual help automatically
$viewHelpPath = $viewPath;
// append file extension if not specified
if ( ! preg_match('%\.php$%', $viewHelpPath)) {
$viewHelpPath .= '.php';
}
$viewHelpPath = preg_replace('%\.php$%', '-help.php', $viewHelpPath);
$fileHelpPath = PMWI_Plugin::ROOT_DIR . '/views/' . $viewHelpPath;
if (is_file($fileHelpPath)) { // there is help file defined
ob_start();
include $fileHelpPath;
add_contextual_help(PMWI_Plugin::getInstance()->getAdminCurrentScreen()->id, ob_get_clean());
}
parent::render($viewPath);
}
}
\ No newline at end of file
<?php
function pmwi_pmxi_article_data($articleData, $import, $post_to_update){
if ( ! empty($articleData['post_type']) and $articleData['post_type'] == 'product' and $import->options['update_all_data'] == 'no' and ! $import->options['is_update_product_type'] and ! empty($post_to_update) ){
$articleData['post_type'] = $post_to_update->post_type;
}
if ( ! empty($articleData['post_type']) and $articleData['post_type'] == 'shop_order' and ! empty($post_to_update) ){
$articleData['post_status'] = $post_to_update->post_status;
}
return $articleData;
}
\ No newline at end of file
<?php
function pmwi_pmxi_custom_field($cf_value, $pid, $cf_key, $existing_meta_keys, $import_id){
if ($cf_key == 'total_sales')
{
delete_post_meta($pid, $cf_key);
}
return $cf_value;
}
\ No newline at end of file
<?php
function pmwi_pmxi_custom_field_to_delete($field_to_delete, $pid, $post_type, $options, $cur_meta_key){
if ($field_to_delete === false || $post_type != "product") return $field_to_delete;
if ($cur_meta_key == 'total_sales') return false;
if ($cur_meta_key == '_is_first_variation_created')
{
delete_post_meta($pid, $cur_meta_key);
return false;
}
// Do not update attributes
if ($options['update_all_data'] == 'no' and ! $options['is_update_attributes'] and (in_array($cur_meta_key, array('_default_attributes', '_product_attributes')) or strpos($cur_meta_key, "attribute_") === 0)) return false;
// Update only these Attributes, leave the rest alone
if ($options['update_all_data'] == 'no' and $options['is_update_attributes'] and $options['update_attributes_logic'] == 'only'){
if ($cur_meta_key == '_product_attributes'){
$current_product_attributes = get_post_meta($pid, '_product_attributes', true);
if ( ! empty($current_product_attributes) and ! empty($options['attributes_list']) and is_array($options['attributes_list']))
foreach ($current_product_attributes as $attr_name => $attr_value) {
if ( in_array($attr_name, array_filter($options['attributes_list'], 'trim'))) unset($current_product_attributes[$attr_name]);
}
update_post_meta($pid, '_product_attributes', $current_product_attributes);
return false;
}
if ( strpos($cur_meta_key, "attribute_") === 0 and ! empty($options['attributes_list']) and is_array($options['attributes_list']) and ! in_array(str_replace("attribute_", "", $cur_meta_key), array_filter($options['attributes_list'], 'trim'))) return false;
if (in_array($cur_meta_key, array('_default_attributes'))) return false;
}
// Leave these attributes alone, update all other Attributes
if ($options['update_all_data'] == 'no' and $options['is_update_attributes'] and $options['update_attributes_logic'] == 'all_except'){
if ($cur_meta_key == '_product_attributes'){
if (empty($options['attributes_list'])) { delete_post_meta($pid, $cur_meta_key); return false; }
$current_product_attributes = get_post_meta($pid, '_product_attributes', true);
if ( ! empty($current_product_attributes) and ! empty($options['attributes_list']) and is_array($options['attributes_list']))
foreach ($current_product_attributes as $attr_name => $attr_value) {
if ( ! in_array($attr_name, array_filter($options['attributes_list'], 'trim'))) unset($current_product_attributes[$attr_name]);
}
update_post_meta($pid, '_product_attributes', $current_product_attributes);
return false;
}
if ( strpos($cur_meta_key, "attribute_") === 0 and ! empty($options['attributes_list']) and is_array($options['attributes_list']) and in_array(str_replace("attribute_", "", $cur_meta_key), array_filter($options['attributes_list'], 'trim'))) return false;
if (in_array($cur_meta_key, array('_default_attributes'))) return false;
}
return true;
}
?>
\ No newline at end of file
<?php
function pmwi_pmxi_custom_field_to_update( $field_to_update, $post_type, $options, $m_key ){
if ($field_to_update === false || $post_type != 'product' || strpos($m_key, 'attribute_') === false) return $field_to_update;
// Do not update attributes
if ($options['update_all_data'] == 'no' and ! $options['is_update_attributes'] and ( ! in_array($cur_meta_key, array('_default_attributes', '_product_attributes')) or strpos($cur_meta_key, "attribute_") === false)) return true;
if ($options['is_update_attributes'] and $options['update_attributes_logic'] == 'full_update') return true;
if ($options['is_update_attributes'] and $options['update_attributes_logic'] == "only" and ! empty($options['attributes_list']) and is_array($options['attributes_list']) and in_array(str_replace("attribute_", "", $m_key), $options['attributes_list']) ) return true;
if ($options['is_update_attributes'] and $options['update_attributes_logic'] == "all_except" and ( empty($options['attributes_list']) or ! in_array(str_replace("attribute_", "", $m_key), $options['attributes_list']) )) return true;
return false;
}
?>
\ No newline at end of file
<?php
function pmwi_pmxi_custom_types($custom_types)
{
if (class_exists('WooCommerce'))
{
if ( ! empty($custom_types['product']) ) $custom_types['product']->labels->name = __('WooCommerce Products','wpai_woocommerce_addon_plugin');
if ( ! empty($custom_types['shop_order']) ) $custom_types['shop_order']->labels->name = __('WooCommerce Orders','wpai_woocommerce_addon_plugin');
if ( ! empty($custom_types['shop_coupon'])) $custom_types['shop_coupon']->labels->name = __('WooCommerce Coupons','wpai_woocommerce_addon_plugin');
if ( ! empty($custom_types['product_variation'])) unset($custom_types['product_variation']);
if ( ! empty($custom_types['shop_order_refund'])) unset($custom_types['shop_order_refund']);
$order = array('shop_order', 'shop_coupon', 'product');
$ordered_custom_types = array();
foreach ($order as $type)
{
if (isset($ordered_custom_types[$type])) continue;
foreach ($custom_types as $key => $custom_type)
{
if (isset($ordered_custom_types[$key])) continue;
if (in_array($key, $order))
{
if ($key == $type)
{
$ordered_custom_types[$key] = $custom_type;
}
}
else
{
$ordered_custom_types[$key] = $custom_type;
}
}
}
return $ordered_custom_types;
}
return $custom_types;
}
<?php
function pmwi_pmxi_save_options($post){
if ($post['update_attributes_logic'] == 'only'){
$post['attributes_list'] = explode(",", $post['attributes_only_list']);
}
elseif ($post['update_attributes_logic'] == 'all_except'){
$post['attributes_list'] = explode(",", $post['attributes_except_list']);
}
return $post;
}
?>
\ No newline at end of file
<?php
function pmwi_pmxi_unique_key( $unique_key, $options ){
if ( $options['custom_type'] == 'product' ){
$unique_key .= ( ! empty($options['attribute_value'])) ? implode('-', $options['attribute_value']) : '';
}
return $unique_key;
}
\ No newline at end of file
<?php
function pmwi_pmxi_visible_confirm_sections( $sections, $post_type )
{
// render order's template only for bundle and import with WP All Import featured
if ( 'shop_order' == $post_type && class_exists('WooCommerce') ) return array();
return $sections;
}
\ No newline at end of file
<?php
function pmwi_pmxi_visible_options_sections( $sections, $post_type )
{
// render order's options view only for bundle and import with WP All Import featured
if ( 'shop_order' == $post_type && class_exists('WooCommerce') ) return array('settings');
return $sections;
}
\ No newline at end of file
<?php
function pmwi_pmxi_visible_template_sections( $sections, $post_type )
{
// render order's template only for bundle and import with WP All Import featured
if ( 'shop_order' == $post_type && class_exists('WooCommerce') ) return array('main', 'cf');
return $sections;
}
\ No newline at end of file
<?php
function pmwi_wp_all_import_is_post_to_delete( $to_delete, $pid, $import )
{
if ( $import->options['custom_type'] == 'product')
{
$post_to_delete = get_post($pid);
if ( $to_delete and $post_to_delete->post_type == 'product' and class_exists('WooCommerce'))
{
$children = get_posts( array(
'post_parent' => $pid,
'posts_per_page'=> -1,
'post_type' => 'product_variation',
'fields' => 'ids',
'orderby' => 'ID',
'order' => 'ASC',
'post_status' => array('draft', 'publish', 'trash', 'pending', 'future', 'private')
) );
if ( count($children) ){
$to_delete = false;
}
}
}
return $to_delete;
}
\ No newline at end of file
<?php
function pmwi_adjust_price( $price, $field, $options ){
switch ($field) {
case 'variable_regular_price':
case 'regular_price':
if ( ! empty($options['single_product_regular_price_adjust']) ){
switch ($options['single_product_regular_price_adjust_type']) {
case '%':
$price = ($price/100) * $options['single_product_regular_price_adjust'];
break;
case '$':
$price += (double) $options['single_product_regular_price_adjust'];
break;
}
$price = ( (double) $price > 0) ? number_format( (double) $price, 2, '.', '' ) : 0;
}
break;
case 'variable_sale_price':
case 'sale_price':
if ( ! empty($options['single_product_sale_price_adjust']) ){
switch ($options['single_product_sale_price_adjust_type']) {
case '%':
$price = ($price/100) * $options['single_product_sale_price_adjust'];
break;
case '$':
$price += (double) $options['single_product_sale_price_adjust'];
break;
}
$price = ( (double) $price > 0) ? number_format( (double) $price, 2, '.', '' ) : 0;
}
break;
/*default:
return $price;*/
break;
}
return $price;
}
\ No newline at end of file
<?php
function pmwi_is_update_taxonomy( $articleData, $options, $tx_name ){
if ( ! empty($articleData['ID']) ){
if ($options['update_all_data'] == 'yes') return true;
if ( ! $options['is_update_categories'] ) return false;
if ($options['update_all_data'] == "no" and $options['update_categories_logic'] == "all_except" and !empty($options['taxonomies_list'])
and is_array($options['taxonomies_list']) and in_array($tx_name, $options['taxonomies_list'])) return false;
if ($options['update_all_data'] == "no" and $options['update_categories_logic'] == "only" and ((!empty($options['taxonomies_list'])
and is_array($options['taxonomies_list']) and ! in_array($tx_name, $options['taxonomies_list'])) or empty($options['taxonomies_list']))) return false;
}
return true;
}
\ No newline at end of file
<?php
function pmwi_prepare_price( $price, $disable_prepare_price, $prepare_price_to_woo_format, $convert_decimal_separator ){
if ( $disable_prepare_price ){
$price = preg_replace("/[^0-9\.,]/","", $price);
}
if ( $convert_decimal_separator and strlen($price) > 3)
{
$decimal_sep = get_option( 'woocommerce_price_decimal_sep', '.' );
$thousand_sep = get_option( 'woocommerce_price_thousand_sep', ',' );
$comma_position = strrpos($price, ",", strlen($price) - 3);
if ($comma_position !== false)
{
$price = str_replace(".", "", $price);
$comma_position = strrpos($price, ",");
$price = str_replace(",", "", substr_replace($price, ".", $comma_position, 1));
}
else
{
$comma_position = strrpos($price, ".", strlen($price) - 3);
if ($comma_position !== false)
{
$price = str_replace(",", "", $price);
}
elseif(strlen($price) > 4)
{
$comma_position = strrpos($price, ",", strlen($price) - 4);
if ($comma_position and strlen($price) - $comma_position == 4)
{
$price = str_replace(",", "", $price);
}
else
{
$comma_position = strrpos($price, ".", strlen($price) - 4);
if ($comma_position and strlen($price) - $comma_position == 4)
{
$price = str_replace(".", "", $price);
}
}
}
}
}
if ( $prepare_price_to_woo_format ){
$price = str_replace(",", ".", $price);
$price = str_replace(",", ".", str_replace(".", "", preg_replace("%\.([0-9]){1,2}?$%", ",$0", $price)));
$price = ("" != $price) ? number_format( (double) $price, 2, '.', '' ) : "";
}
return apply_filters('pmxi_price', $price);
}
\ No newline at end of file
<?php
function pmwi_sanitize_taxonomy_name($taxonomy){
$filtered = strtolower( remove_accents( stripslashes( strip_tags( $taxonomy ) ) ) );
$filtered = preg_replace( '/&.+?;/', '', $filtered ); // Kill entities
$filtered = str_replace( array( '.', '\'', '"' ), '', $filtered ); // Kill quotes and full stops.
$filtered = str_replace( array( ' ', '_' ), '-', $filtered ); // Replace spaces and underscores.
return apply_filters( 'sanitize_taxonomy_name', $filtered, $taxonomy );
}
?>
\ No newline at end of file
<?php
function pmwi_update_prices($pid){
update_post_meta( $pid, '_regular_price', $tmp = get_post_meta( $pid, '_regular_price_tmp', true) );
delete_post_meta( $pid, '_regular_price_tmp' );
update_post_meta( $pid, '_sale_price', $tmp = get_post_meta( $pid, '_sale_price_tmp', true ) );
delete_post_meta( $pid, '_sale_price_tmp' );
update_post_meta( $pid, 'pmxi_wholesale_price', $tmp = get_post_meta( $pid, 'pmxi_wholesale_price_tmp', true ) );
delete_post_meta( $pid, 'pmxi_wholesale_price_tmp' );
update_post_meta( $pid, '_sale_price_dates_from', $tmp = get_post_meta( $pid, '_sale_price_dates_from_tmp', true ) );
delete_post_meta( $pid, '_sale_price_dates_from_tmp' );
update_post_meta( $pid, '_sale_price_dates_to', $tmp = get_post_meta( $pid, '_sale_price_dates_to_tmp', true ) );
delete_post_meta( $pid, '_sale_price_dates_to_tmp' );
update_post_meta( $pid, '_price', $tmp = get_post_meta( $pid, '_price_tmp', true ) );
delete_post_meta( $pid, '_price_tmp' );
}
\ No newline at end of file
<?php
abstract class XmlImportWooCommerce {
public $import;
public $xml;
public $logger;
public $count;
public $chunk;
public $xpath;
public $wpdb;
public $data;
public $articleData = false;
function pushmeta( $pid, $meta_key, $meta_value )
{
if (empty($meta_key)) return;
if ( empty($this->articleData['ID']) or $this->is_update_cf($meta_key))
{
update_post_meta($pid, $meta_key, $meta_value);
}
}
function is_update_cf( $meta_key )
{
if ( $this->import->options['update_all_data'] == 'yes') return true;
if ( ! $this->import->options['is_update_custom_fields'] ) return false;
if ( $this->import->options['update_custom_fields_logic'] == "full_update" ) return true;
if ( $this->import->options['update_custom_fields_logic'] == "only"
and ! empty($this->import->options['custom_fields_list'])
and is_array($this->import->options['custom_fields_list'])
and in_array($meta_key, $this->import->options['custom_fields_list']) ) return true;
if ( $this->import->options['update_custom_fields_logic'] == "all_except"
and ( empty($this->import->options['custom_fields_list']) or ! in_array($meta_key, $this->import->options['custom_fields_list']) )) return true;
return false;
}
function filtering($var)
{
return ("" == $var) ? false : true;
}
}
\ No newline at end of file
<?php
require_once dirname(__FILE__) . '/XmlImportWooCommerceProduct.php';
require_once dirname(__FILE__) . '/XmlImportWooCommerceShopOrder.php';
/**
* Is used to parse XML using specified template and root node
*/
class XmlImportWooCommerceData {
public $importer = false;
public function __construct( $request )
{
switch ($request['import']->options['custom_type'])
{
case 'product':
$this->importer = new XmlImportWooCommerceProduct( $request );
break;
case 'shop_order':
$this->importer = new XmlImportWooCommerceShopOrder( $request );
break;
default:
# code...
break;
}
}
public function parse()
{
return ($this->importer) ? $this->importer->parse() : false;
}
public function import( $data )
{
return ($this->importer) ? $this->importer->import( $data ) : false;
}
public function after_save_post( $data )
{
return ($this->importer) ? $this->importer->after_save_post( $data ) : false;
}
}
\ No newline at end of file
<?php
class PMWI_Import_List extends PMWI_Model_List {
public function __construct() {
parent::__construct();
$this->setTable(PMWI_Plugin::getInstance()->getTablePrefix() . 'imports');
}
}
\ No newline at end of file
<?php
class PMWI_Import_Record extends PMWI_Model_Record {
/**
* Associative array of data which will be automatically available as variables when template is rendered
* @var array
*/
public $data = array();
public $importer = false;
/**
* Initialize model instance
* @param array[optional] $data Array of record data to initialize object with
*/
public function __construct($data = array()) {
parent::__construct($data);
$this->setTable(PMXI_Plugin::getInstance()->getTablePrefix() . 'imports');
}
/**
* Perform import operation
* @param string $xml XML string to import
* @param callback[optional] $logger Method where progress messages are submmitted
* @return PMWI_Import_Record
* @chainable
*/
public function parse($parsing_data = array()) {
if ( ! in_array($parsing_data['import']->options['custom_type'], array('product', 'shop_order')) ) return;
add_filter('user_has_cap', array($this, '_filter_has_cap_unfiltered_html')); kses_init(); // do not perform special filtering for imported content
$this->options = $parsing_data['import']->options;
$this->importer = new XmlImportWooCommerceData( $parsing_data );
$this->data = $this->importer->parse();
remove_filter('user_has_cap', array($this, '_filter_has_cap_unfiltered_html')); kses_init(); // return any filtering rules back if they has been disabled for import procedure
if ($this->options['put_variation_image_to_gallery'])
{
add_action('pmxi_gallery_image', array($this, 'wpai_gallery_image'), 10, 3);
}
return $this->data;
}
public function import( $importData = array() ){
if ( ! in_array($importData['post_type'], array('product', 'product_variation', 'shop_order')) ) return;
$this->importer->import( $importData );
}
public function saved_post( $importData )
{
if ( ! in_array($importData['import']->options['custom_type'], array('product', 'product_variation', 'shop_order'))) return;
$this->importer->after_save_post( $importData );
}
public function wpai_gallery_image($pid, $attid, $image_filepath){
$table = $this->wpdb->posts;
$p = $this->wpdb->get_row($this->wpdb->prepare("SELECT * FROM $table WHERE ID = %d;", (int) $pid));
if ($p and $p->post_parent){
$gallery = explode(",", get_post_meta($p->post_parent, '_product_image_gallery_tmp', true));
if (is_array($gallery)){
$gallery = array_filter($gallery);
if ( ! in_array($attid, $gallery) ) $gallery[] = $attid;
}
else{
$gallery = array($attid);
}
update_post_meta($p->post_parent, '_product_image_gallery_tmp', implode(',', $gallery));
}
}
public function _filter_has_cap_unfiltered_html($caps)
{
$caps['unfiltered_html'] = true;
return $caps;
}
}
<?php
/**
* Base class for models
*
* @author Pavel Kulbakin <p.kulbakin@gmail.com>
*/
abstract class PMWI_Model extends ArrayObject {
/**
* WPDB instance
* @var wpdb
*/
protected $wpdb;
/**
* Table name the model is linked to
* @var string
*/
protected $table;
/**
* Array of columns representing primary key
* @var array
*/
protected $primary = array('id');
/**
* Wether key field is auto_increment (sure make scence only if key s
* @var bool
*/
protected $auto_increment = FALSE;
/**
* Cached data retrieved from database
* @var array
*/
private static $meta_cache = array();
/**
* Initialize model
* @param array[optional] $data Array of record data to initialize object with
*/
public function __construct() {
$this->wpdb = $GLOBALS['wpdb'];
}
/**
* Read records from database by specified fields and values
* When 1st parameter is an array, it expected to be an associative array of field => value pairs to read data by
* If 2 parameters are set, first one is expected to be a field name and second - it's value
*
* @param string|array $field
* @param mixed[optional] $value
* @return PMWI_Model
*/
abstract public function getBy($field = NULL, $value = NULL);
/**
* Magic function to automatically resolve calls like $obj->getBy%FIELD_NAME%
* @param string $method
* @param array $args
* @return PMWI_Model
*/
public function __call($method, $args) {
if (preg_match('%^get_?by_?(.+)%i', $method, $mtch)) {
array_unshift($args, $mtch[1]);
return call_user_func_array(array($this, 'getBy'), $args);
} else {
throw new Exception("Requested method " . get_class($this) . "::$method doesn't exist.");
}
}
/**
* Bind model to database table
* @param string $tableName
* @return PMWI_Model
*/
public function setTable($tableName) {
if ( ! is_null($this->table)) {
throw new Exception('Table name cannot be changed once being set.');
}
$this->table = $tableName;
if ( ! isset(self::$meta_cache[$this->table])) {
$tableMeta = $this->wpdb->get_results("SHOW COLUMNS FROM $this->table", ARRAY_A);
$primary = array();
$auto_increment = false;
foreach ($tableMeta as $colMeta) {
if ('PRI' == $colMeta['Key']) {
$primary[] = $colMeta['Field'];
}
if ('auto_increment' == $colMeta['Extra']) {
$auto_increment = true;
break; // no point to iterate futher since auto_increment means corresponding primary key is simple
}
}
self::$meta_cache[$this->table] = array('primary' => $primary, 'auto_increment' => $auto_increment);
}
$this->primary = self::$meta_cache[$this->table]['primary'];
$this->auto_increment = self::$meta_cache[$this->table]['auto_increment'];
return $this;
}
/**
* Return database table name this object is bound to
* @return string
*/
public function getTable() {
return $this->table;
}
/**
* Return column name with table name
* @param string $col
* @return string
*/
public function getFieldName($col) {
return $this->table . '.' . $col;
}
/**
* Compose WHERE clause based on parameters provided
* @param string|array $field
* @param mixed[optional] $value
* @param string[optional] $operator AND or OR string, 'AND' by default
* @return string
*/
protected function buildWhere($field, $value = NULL, $operator = NULL) {
if ( ! is_array($field)) {
$field = array($field => $value);
} else { // shift arguments
$operator = $value;
}
! is_null($operator) or $operator = 'AND'; // apply default operator value
$where = array();
foreach ($field as $key => $val) {
if (is_int($key)) {
$where[] = '(' . call_user_func_array(array($this, 'buildWhere'), $val) . ')';
} else {
if ( ! preg_match('%^(.+?) *(=|<>|!=|<|>|<=|>=| (NOT +)?(IN|(LIKE|REGEXP|RLIKE)( BINARY)?))?$%i', trim($key), $mtch)) {
throw new Exception('Wrong field name format.');
}
$key = $mtch[1];
if (is_array($val) and (empty($mtch[2]) or 'IN' == strtoupper($mtch[4]))) {
$op = empty($mtch[2]) ? 'IN' : strtoupper(trim($mtch[2]));
$where[] = $this->wpdb->prepare("$key $op (" . implode(', ', array_fill(0, count($val), "%s")) . ")", $val);
} else {
$op = empty($mtch[2]) ? '=' : strtoupper(trim($mtch[2]));
$where[] = $this->wpdb->prepare("$key $op %s", $val);
}
}
}
return implode(" $operator ", $where);
}
/**
* Return associative array with record data
* @param bool[optional] $serialize Whether returned fields should be serialized
* @return array
*/
public function toArray($serialize = FALSE) {
$result = (array)$this;
if ($serialize) {
foreach ($result as $k => $v) {
if ( ! is_scalar($v)) {
$result[$k] = serialize($v);
}
}
}
return $result;
}
/**
* Check whether object data is empty
* @return bool
*/
public function isEmpty() {
return $this->count() == 0;
}
/**
* Empty object data
* @return PMWI_Model
*/
public function clear() {
$this->exchangeArray(array());
return $this;
}
/**
* Delete all content from model's table
* @return PMWI_Model
*/
public function truncateTable() {
if (FALSE !== $this->wpdb->query("TRUNCATE $this->table")) {
return $this;
} else {
throw new Exception($this->wpdb->last_error);
}
}
}
\ No newline at end of file
<?php
/**
* Incapsulates behavior for list of database records
*
* @author Pavel Kulbakin <p.kulbakin@gmail.com>
*/
class PMWI_Model_List extends PMWI_Model {
/**
* Total number of records in database which correspond last getBy rule without paging
* @var int
*/
protected $total = 0;
/**
* Joined tables
* @var array
*/
protected $joined = array();
/**
* Columns to select from database
* @var string
*/
protected $what = '*';
/**
* Sets table to use in conjuction with primary list table
* @param string $table Table to join
* @param string $on Condition to join
* @param string $type Join type (INNER, OUTER, etc)
* @return PMWI_Model_List
*/
public function join($table, $on, $type = 'INNER') {
$this->joined[] = ( ! is_null($type) ? $type . ' ' : '') . 'JOIN ' . $table . ' ON ' . $on;
return $this;
}
/**
* Set columns to be selected from database
* @param array $columns
* @return PMWI_Model_List
*/
public function setColumns($columns) {
is_array($columns) or $columns = func_get_args();
$this->what = implode(', ', $columns);
return $this;
}
/**
* Read records from database by specified fields and values
* When 1st parameter is an array, it's expected to be an associative array of field => value pairs to read data by
* When 2nd parameter is a scalar, it's expected to be a field name and second parameter - it's value
*
* @param string|array[optional] $field
* @param mixed[optional] $value
* @param string[optional] $orderBy Ordering rule
* @param int[optional] $page Paging paramter used to limit number of records returned
* @param int[optional] $perPage Page size when paging parameter is used (20 by default)
* @return PMWI_Model_List
*/
public function getBy($field = NULL, $value = NULL, $orderBy = NULL, $page = NULL, $perPage = NULL, $groupBy = NULL) {
if (is_array($field) or is_null($field)) { // when associative array is submitted, do not expect second paramter to be $value, but act as if there is no $value parameter at all
$groupBy = $perPage; $perPage = $page; $page = $orderBy; $orderBy = $value; $value = NULL;
}
! is_null($perPage) or $perPage = 20; // set default value for page length
$page = intval($page);
$sql = "FROM $this->table ";
$sql .= implode(' ', $this->joined);
if ( ! is_null($field)) {
$sql .= " WHERE " . $this->buildWhere($field, $value);
}
if ( ! is_null($groupBy)) {
$sql .= " GROUP BY $groupBy";
}
is_null($orderBy) and $orderBy = implode(', ', $this->primary); // default sort order is by primary key
$sql .= " ORDER BY $orderBy";
if ($page > 0) {
$sql = "SELECT SQL_CALC_FOUND_ROWS $this->what $sql LIMIT " . intval(($page - 1) * $perPage) . ", " . intval($perPage);
} else {
$sql = "SELECT $this->what $sql";
}
$result = $this->wpdb->get_results($sql, ARRAY_A);
if (is_array($result)) {
foreach ($result as $i => $row) {
foreach ($row as $k => $v) {
if (is_serialized($v)) {
$result[$i][$k] = unserialize($v);
}
}
}
if ($page > 0) {
$this->total = intval($this->wpdb->get_var('SELECT FOUND_ROWS()'));
} else {
$this->total = count($result);
}
$this->exchangeArray($result);
} else {
$this->total = 0;
$this->clear();
}
return $this;
}
/**
* Count records in table
* @param string|array $field
* @param mixed[optional] $value
* @return int
*/
public function countBy($field = NULL, $value = NULL) {
$sql = "SELECT COUNT(*) FROM $this->table ";
$sql .= implode(' ', $this->joined);
if ( ! is_null($field)) {
$sql .= " WHERE " . $this->buildWhere($field, $value);
}
return intval($this->wpdb->get_var($sql));
}
/**
* Method returns number of rows in database which correspond last getBy query
* @return int
*/
public function total() {
return $this->total;
}
/**
* Converts elements to instances of specifield class. If includeFields are provided only fields listed are included
* @param string[optoinal] $elementClass
* @param array[optional] $includeFields
* @return PMWI_Model_List
*/
public function convertRecords($elementClass = NULL, $includeFields = NULL) {
! is_null($elementClass) or $elementClass = preg_replace('%List$%', 'Record', get_class($this));
if ( ! is_subclass_of($elementClass, PMWI_Plugin::PREFIX . 'Model_Record')) {
throw new Exception("Provideded class name $elementClass must be a subclass of " . PMWI_Plugin::PREFIX . 'Model_Record');
}
$records = $this->exchangeArray(array());
foreach ($records as $r) {
$data = (array)$r;
if ( ! is_null($includeFields)) {
$data = array_intersect_key($data, array_flip($includeFields));
}
$this[] = new $elementClass($data);
}
return $this;
}
}
\ No newline at end of file
<?php
/**
* Base class for models
*
* @author Pavel Kulbakin <p.kulbakin@gmail.com>
*/
class PMWI_Model_Record extends PMWI_Model {
/**
* Initialize model
* @param array[optional] $data Array of record data to initialize object with
*/
public function __construct($data = array()) {
parent::__construct();
if (! is_array($data)) {
throw new Exception("Array expected as paramenter for " . get_class($this) . "::" . __METHOD__);
}
$data and $this->set($data);
}
/**
* @see PMWI_Model::getBy()
* @return PMWI_Model_Record
*/
public function getBy($field = NULL, $value = NULL) {
if (is_null($field)) {
throw new Exception("Field parameter is expected at " . get_class($this) . "::" . __METHOD__);
}
$sql = "SELECT * FROM $this->table WHERE " . $this->buildWhere($field, $value);
$result = $this->wpdb->get_row($sql, ARRAY_A);
if (is_array($result)) {
foreach ($result as $k => $v) {
if (is_serialized($v)) {
$result[$k] = unserialize($v);
}
}
$this->exchangeArray($result);
} else {
$this->clear();
}
return $this;
}
/**
* Ger records related to current one
* @param string $model Class name of model of related records
* @param array[optoinal] $keyAssoc
* @return PMWI_Model_List
*/
public function getRelated($model, $keyAssoc = NULL) {
$related = new $model();
if ( ! empty($this->id)) {
if (is_null($keyAssoc)) {
$defaultPrefix = strtolower(preg_replace('%^' . strtoupper(PMWI_Plugin::PREFIX) . '|_Record$%', '', get_class($this)));
$keyAssoc = array();
foreach ($this->primary as $key) {
$keyAssoc = array($defaultPrefix . '_' . $key => $key);
}
}
foreach ($keyAssoc as $foreign => $local) {
$keyAssoc[$foreign] = $this->$local;
}
$related->getBy($keyAssoc);
}
return $related instanceof PMWI_Model_List ? $related->convertRecords() : $related;
}
/**
* Saves currently set object data as database record
* @return PMWI_Model_Record
*/
public function insert() {
if ($this->wpdb->insert($this->table, $this->toArray(TRUE))) {
if (isset($this->auto_increment)) {
$this[$this->primary[0]] = $this->wpdb->insert_id;
}
return $this;
} else {
throw new Exception($this->wpdb->last_error);
}
}
/**
* Update record in database
* @return PMWI_Model_Record
*/
public function update() {
$record = $this->toArray(TRUE);
$this->wpdb->update($this->table, $record, array_intersect_key($record, array_flip($this->primary)));
if ($this->wpdb->last_error) {
throw new Exception($this->wpdb->last_error);
}
return $this;
}
/**
* Delete record form database
* @return PMWI_Model_Record
*/
public function delete() {
if ($this->wpdb->query("DELETE FROM $this->table WHERE " . $this->buildWhere(array_intersect_key($this->toArray(TRUE), array_flip($this->primary))))) {
return $this;
} else {
throw new Exception($this->wpdb->last_error);
}
}
/**
* Insert or Update the record
* WARNING: function doesn't check actual record presents in database, it simply tries to insert if no primary key specified and update otherwise
* @return PMWI_Model_Record
*/
public function save() {
if (array_intersect_key($this->toArray(TRUE), array_flip($this->primary))) {
$this->update();
} else {
$this->insert();
}
return $this;
}
/**
* Set record data
* When 1st parameter is an array, it expected to be an associative array of field => value pairs
* If 2 parameters are set, first one is expected to be a field name and second - it's value
*
* @param string|array $field
* @param mixed[optional] $value
* @return PMWI_Model_Record
*/
public function set($field, $value = NULL) {
if (is_array($field) and ( ! is_null($value) or 0 == count($field))) {
throw new Exception(__CLASS__ . "::set method expects either not empty associative array as the only paramter or field name and it's value as two seperate parameters.");
}
if (is_array($field)) {
$this->exchangeArray(array_merge($this->toArray(), $field));
} else {
$this[$field] = $value;
}
return $this;
}
/**
* Magic method to resolved object-like request to record values in format $obj->%FIELD_NAME%
* @param string $field
* @return mixed
*/
public function __get($field) {
if ( ! $this->offsetExists($field)) {
throw new Exception("Undefined field $field.");
}
return $this[$field];
}
/**
* Magic method to assign values to record fields in format $obj->%FIELD_NAME = value
* @param string $field
* @param mixed $value
*/
public function __set($field, $value) {
$this[$field] = $value;
}
/**
* Magic method to check wether some record fields are set
* @param string $field
* @return bool
*/
public function __isset($field) {
return $this->offsetExists($field);
}
/**
* Magic method to unset record fields
* @param string $field
*/
public function __unset($field) {
$this->offsetUnset($field);
}
}
\ No newline at end of file
<?php
/**
* Plugin database schema
* WARNING:
* dbDelta() doesn't like empty lines in schema string, so don't put them there;
* WPDB doesn't like NULL values so better not to have them in the tables;
*/
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
<?php include('options/_reimport_template.php'); ?>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment