Example #1
0
 function deleteItem($id)
 {
     global $wpdb;
     // check if there are listings using this profile
     $listings = WPLE_ListingQueryHelper::getAllWithProfile($id);
     if (!empty($listings)) {
         $this->showMessage('This profile is applied to ' . count($listings) . ' listings and can not be deleted.', 1, 1);
         return false;
     }
     $wpdb->query($wpdb->prepare("\n\t\t\tDELETE\n\t\t\tFROM {$this->tablename}\n\t\t\tWHERE profile_id = %s\n\t\t", $id));
 }
Example #2
0
function wple_get_listings_where($column, $value)
{
    return WPLE_ListingQueryHelper::getWhere($column, $value);
}
Example #3
0
 function woo_ce_product_item($product, $product_id)
 {
     $product->ebay_item_id = WPLE_ListingQueryHelper::getEbayIDFromPostID($product_id);
     $product->ebay_status = WPLE_ListingQueryHelper::getStatusFromPostID($product_id);
     return $product;
 }
Example #4
0
 private function saveProfile()
 {
     global $wpdb;
     $details = $this->getPreprocessedPostDetails();
     $profile_id = $this->getValueFromPost('profile_id');
     $account_id = $this->getValueFromPost('account_id');
     if (!$account_id) {
         $account_id = get_option('wplister_default_account_id');
     }
     // fix entered prices
     $details = self::fixProfilePrices($details);
     // process item specifics
     $item_specifics = array();
     $itmSpecs_name = @$_POST['itmSpecs_name'];
     $itmSpecs_value = @$_POST['itmSpecs_value'];
     $itmSpecs_attrib = @$_POST['itmSpecs_attrib'];
     if (is_array($itmSpecs_name)) {
         foreach ($itmSpecs_name as $key => $name) {
             #$name = str_replace('\\\\', '', $name );
             $name = stripslashes($name);
             $value = trim($itmSpecs_value[$key]);
             $attribute = trim($itmSpecs_attrib[$key]);
             if ($value != '' || $attribute != '') {
                 $spec = new stdClass();
                 $spec->name = $name;
                 $spec->value = $value;
                 $spec->attribute = $attribute;
                 $item_specifics[] = $spec;
             }
         }
     }
     $details['item_specifics'] = $item_specifics;
     // add category names
     $details['ebay_category_1_name'] = EbayCategoriesModel::getCategoryName($details['ebay_category_1_id']);
     $details['ebay_category_2_name'] = EbayCategoriesModel::getCategoryName($details['ebay_category_2_id']);
     $details['store_category_1_name'] = EbayCategoriesModel::getStoreCategoryName($details['store_category_1_id']);
     $details['store_category_2_name'] = EbayCategoriesModel::getStoreCategoryName($details['store_category_2_id']);
     // fix prices - already done in fixProfilePrices()
     // $details['start_price'] = str_replace(',', '.', $details['start_price'] );
     // $details['fixed_price'] = str_replace(',', '.', $details['fixed_price'] );
     // if the user enters only fixed price but no start price, move fixed price to start price
     if ($details['start_price'] == '' && $details['fixed_price'] != '') {
         $details['start_price'] = $details['fixed_price'];
         $details['fixed_price'] = '';
     }
     // fix quantities
     if (!$details['custom_quantity_enabled']) {
         $details['quantity'] = '';
         $details['max_quantity'] = '';
     }
     // do we have a primary category?
     if (intval($details['ebay_category_1_id']) != 0) {
         $primary_category_id = $details['ebay_category_1_id'];
     } else {
         // if not use default category
         $primary_category_id = self::getOption('default_ebay_category_id');
     }
     // // do we have ConditionDetails for primary category?
     // // $conditions = $this->fetchItemConditions( $primary_category_id, $profile_id, $account_id );
     // $conditions = EbayCategoriesModel::getConditionsForCategory( $primary_category_id, false, $account_id );
     // // do we have item specifics for primary category?
     // if ( intval($profile_id) != 0 ) {
     // 	// $saved_specifics = $wpdb->get_var('SELECT category_specifics FROM '.$wpdb->prefix.'ebay_profiles WHERE profile_id = '.$profile_id);
     // 	$saved_specifics = $wpdb->get_var( $wpdb->prepare( "SELECT category_specifics FROM {$wpdb->prefix}ebay_profiles WHERE profile_id = %d", $profile_id ) );
     // 	$saved_specifics = unserialize($saved_specifics);
     // }
     // // fetch required item specifics for primary category
     // if ( ( isset( $saved_specifics[ $primary_category_id ] ) ) && ( $saved_specifics[ $primary_category_id ] != 'none' ) ) {
     // 	$specifics = $saved_specifics;
     // } elseif ( (int)$primary_category_id != 0 ) {
     // 	$this->initEC( $account_id );
     // 	$specifics = $this->EC->getCategorySpecifics( $primary_category_id );
     // 	$this->EC->closeEbay();
     // } else {
     // 	$specifics = array();
     // }
     // // do we have item specifics for primary category?
     // (improved version of the above, using ebay_categories as cache)
     // $specifics = EbayCategoriesModel::getItemSpecificsForCategory( $primary_category_id, false, $account_id );
     // // $specifics = array( $primary_category_id => $specifics );
     if (WPLISTER_LIGHT) {
         $specifics = array();
     }
     // sql columns
     $item = array();
     $item['profile_id'] = $profile_id;
     $item['profile_name'] = $this->getValueFromPost('profile_name');
     $item['profile_description'] = $this->getValueFromPost('profile_description');
     $item['listing_duration'] = $this->getValueFromPost('listing_duration');
     $item['type'] = $this->getValueFromPost('auction_type');
     $item['sort_order'] = intval($this->getValueFromPost('sort_order'));
     $item['details'] = json_encode($details);
     // $item['conditions']			 		= serialize( $conditions );	// deprecated
     // $item['category_specifics']	 		= serialize( $specifics );	// deprecated
     $item['conditions'] = '';
     $item['category_specifics'] = '';
     $item['account_id'] = $account_id;
     $item['site_id'] = WPLE()->accounts[$item['account_id']]->site_id;
     // insert or update
     if ($item['profile_id'] == 0) {
         // insert new profile
         unset($item['profile_id']);
         $result = $wpdb->insert($wpdb->prefix . 'ebay_profiles', $item);
     } else {
         // update profile
         $result = $wpdb->update($wpdb->prefix . 'ebay_profiles', $item, array('profile_id' => $item['profile_id']));
     }
     // proper error handling
     if ($result === false) {
         $this->showMessage("There was a problem saving your profile.<br>SQL:<pre>" . $wpdb->last_query . '</pre>' . $wpdb->last_error, true);
     } else {
         $this->showMessage(__('Profile saved.', 'wplister'));
         // if we were updating this template as part of setup, move to next step
         if ('4' == self::getOption('setup_next_step')) {
             self::updateOption('setup_next_step', 5);
         }
     }
     // if this is a new profile, skip further processing
     if (!$profile_id) {
         return;
     }
     // handle delayed update option
     if (isset($_POST['wple_delay_profile_application'])) {
         update_option('wple_job_reapply_profile_id', $profile_id);
         return;
     }
     // prepare for updating items
     $listingsModel = new ListingsModel();
     $profilesModel = new ProfilesModel();
     $profile = $profilesModel->getItem($this->getValueFromPost('profile_id'));
     // re-apply profile to all prepared
     if ($this->getValueFromPost('apply_changes_to_all_prepared') == 'yes') {
         $items = WPLE_ListingQueryHelper::getAllPreparedWithProfile($item['profile_id']);
         $listingsModel->applyProfileToItems($profile, $items);
         $this->showMessage(sprintf(__('%s prepared items updated.', 'wplister'), count($items)));
     }
     // re-apply profile to all verified
     if ($this->getValueFromPost('apply_changes_to_all_verified') == 'yes') {
         $items = WPLE_ListingQueryHelper::getAllVerifiedWithProfile($item['profile_id']);
         $listingsModel->applyProfileToItems($profile, $items);
         $this->showMessage(sprintf(__('%s verified items updated.', 'wplister'), count($items)));
     }
     // re-apply profile to all published
     if ($this->getValueFromPost('apply_changes_to_all_published') == 'yes') {
         $items = WPLE_ListingQueryHelper::getAllPublishedWithProfile($item['profile_id']);
         $listingsModel->applyProfileToItems($profile, $items);
         $this->showMessage(sprintf(__('%s published items changed.', 'wplister'), count($items)));
     }
     // re-apply profile to all ended
     if ($this->getValueFromPost('apply_changes_to_all_ended') == 'yes') {
         $items = WPLE_ListingQueryHelper::getAllEndedWithProfile($item['profile_id']);
         $listingsModel->applyProfileToItems($profile, $items);
         $this->showMessage(sprintf(__('%s ended items updated.', 'wplister'), count($items)));
         // update ended listings - required for autorelist to be applied
         // $listingsModel->updateEndedListings();
         $this->initEC($account_id);
         $this->EC->updateListings();
         $this->EC->closeEbay();
     }
 }
Example #5
0
 public function previewListing($id)
 {
     // init model
     $ibm = new ItemBuilderModel();
     $account_id = WPLE_ListingQueryHelper::getAccountID($id);
     $account = WPLE_eBayAccount::getAccount($account_id);
     $this->initEC($account_id);
     $item = $ibm->buildItem($id, $this->EC->session, false, true);
     // if ( ! $ibm->checkItem($item) ) return $ibm->result;
     $ibm->checkItem($item);
     // $preview_html = $ibm->getFinalHTML( $id, $item, true );
     $preview_html = $item->Description;
     // echo $preview_html;
     // set condition name
     $item->ConditionName = $this->getConditionDisplayName($item->getConditionID());
     $aData = array('item' => $item, 'site_id' => $account ? $account->site_id : false, 'check_result' => $ibm->result, 'preview_html' => $preview_html);
     header('Content-Type: text/html; charset=utf-8');
     $this->display('listings_preview', $aData);
     exit;
 }
Example #6
0
 public function processAllTextShortcodes($post_id, $tpl_html, $max_length = false, $ItemObj = false)
 {
     // get item object
     $listing_id = WPLE_ListingQueryHelper::getListingIDFromPostID($post_id);
     $item = ListingsModel::getItem($listing_id);
     // main content - [[product_content]] (unless updating title when saving product...)
     if (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'editpost' || isset($_REQUEST['wpl_ebay_revise_on_update']) || isset($_REQUEST['wpl_ebay_relist_on_update'])) {
         $tpl_html = $this->processMainContentShortcode($post_id, $tpl_html, $item);
     }
     // product excerpt
     $product_id = $item['parent_id'] ? $item['parent_id'] : $item['post_id'];
     // maybe use parent post_id (for split variations)
     $tpl_html = str_replace('[[product_excerpt]]', WPLE_ListingQueryHelper::getRawPostExcerpt($product_id), $tpl_html);
     $tpl_html = str_replace('[[product_excerpt_nl2br]]', nl2br(WPLE_ListingQueryHelper::getRawPostExcerpt($product_id)), $tpl_html);
     $tpl_html = str_replace('[[product_additional_content]]', wpautop(WPLE_ListingQueryHelper::getRawPostExcerpt($product_id)), $tpl_html);
     $tpl_html = str_replace('[[product_additional_content_nl2br]]', nl2br(WPLE_ListingQueryHelper::getRawPostExcerpt($product_id)), $tpl_html);
     // product price
     $item_price = $item['price'];
     if ($ItemObj && $ItemObj->StartPrice) {
         $item_price = $ItemObj->StartPrice->value;
     }
     if ($ItemObj && $ItemObj->Variations) {
         $item_price = $ItemObj->Variations->Variation[0]->StartPrice;
     }
     $tpl_html = str_replace('[[product_price]]', number_format_i18n(floatval($item_price), 2), $tpl_html);
     $tpl_html = str_replace('[[product_price_raw]]', $item_price, $tpl_html);
     // product_category
     $tpl_html = str_replace('[[product_category]]', ProductWrapper::getProductCategoryName($post_id), $tpl_html);
     // SKU
     $tpl_html = str_replace('[[product_sku]]', ProductWrapper::getSKU($post_id), $tpl_html);
     // weight
     $tpl_html = str_replace('[[product_weight]]', ProductWrapper::getWeight($post_id, true), $tpl_html);
     // dimensions
     $dimensions = ProductWrapper::getDimensions($post_id);
     $width = @$dimensions['width'] . ' ' . @$dimensions['width_unit'];
     $height = @$dimensions['height'] . ' ' . @$dimensions['height_unit'];
     $length = @$dimensions['length'] . ' ' . @$dimensions['length_unit'];
     $tpl_html = str_replace('[[product_width]]', $width, $tpl_html);
     $tpl_html = str_replace('[[product_height]]', $height, $tpl_html);
     $tpl_html = str_replace('[[product_length]]', $length, $tpl_html);
     // attributes
     $tpl_html = $this->processAttributeShortcodes($post_id, $tpl_html, $max_length);
     // custom meta
     $tpl_html = $this->processCustomMetaShortcodes($post_id, $tpl_html, $max_length);
     return $tpl_html;
 }
Example #7
0
 public function checkSoldStock()
 {
     // get all sold listings
     $listings = WPLE_ListingQueryHelper::getAllWithStatus('sold');
     $out_of_stock_products = array();
     // process published listings
     foreach ($listings as $item) {
         // get wc product
         $_product = ProductWrapper::getProduct($item['post_id']);
         // check stock level
         // $stock = ProductWrapper::getStock( $item['post_id'] );
         $stock = $_product ? $_product->get_total_stock() : 0;
         if ($stock == 0) {
             continue;
         }
         // mark listing as changed
         // if ( isset( $_REQUEST['mark_as_changed'] ) && $_REQUEST['mark_as_changed'] == 'yes' ) {
         // 	ListingsModel::updateListing( $item['id'], array( 'status' => 'changed' ) );
         // 	$item['status'] = 'changed';
         // }
         // add to list of out of stock products
         $item['stock'] = $stock;
         $item['exists'] = $_product ? true : false;
         $out_of_stock_products[] = $item;
     }
     // return if empty
     if (empty($out_of_stock_products)) {
         $this->showMessage('No sold products have stock in WooCommerce.', 0, 1);
         return;
     }
     $msg = '<p>';
     $msg .= 'Warning: Some sold listings are still in stock in WooCommerce.';
     $msg .= '</p>';
     // table header
     $msg .= '<table style="width:100%">';
     $msg .= "<tr>";
     $msg .= "<th style='text-align:left'>Stock</th>";
     $msg .= "<th style='text-align:left'>SKU</th>";
     $msg .= "<th style='text-align:left'>Product</th>";
     $msg .= "<th style='text-align:left'>Qty</th>";
     $msg .= "<th style='text-align:left'>eBay ID</th>";
     $msg .= "<th style='text-align:left'>Ended at</th>";
     $msg .= "<th style='text-align:left'>Status</th>";
     $msg .= "</tr>";
     // table rows
     foreach ($out_of_stock_products as $item) {
         // get column data
         $qty = $item['quantity'] - $item['quantity_sold'];
         $sku = get_post_meta($item['post_id'], '_sku', true);
         $stock = $item['stock'] . ' x ';
         $title = $item['auction_title'];
         $post_id = $item['post_id'];
         $ebay_id = $item['ebay_id'];
         $status = $item['status'];
         $exists = $item['exists'];
         $date_ended = $item['date_finished'] ? $item['date_finished'] : $item['end_date'];
         // build links
         $ebay_url = $item['ViewItemURL'] ? $item['ViewItemURL'] : ($ebay_url = 'http://www.ebay.com/itm/' . $ebay_id);
         $ebay_link = '<a href="' . $ebay_url . '" target="_blank">' . $ebay_id . '</a>';
         $edit_link = '<a href="post.php?action=edit&post=' . $post_id . '" target="_blank">' . $title . '</a>';
         // mark non existent products
         if (!$exists) {
             $stock = 'N/A';
             $post_id .= ' missing!';
         }
         // build table row
         $msg .= "<tr>";
         $msg .= "<td>{$stock}</td>";
         $msg .= "<td>{$sku}</td>";
         $msg .= "<td>{$edit_link} (ID {$post_id})</td>";
         $msg .= "<td>{$qty} x </td>";
         $msg .= "<td>{$ebay_link}</td>";
         $msg .= "<td>{$date_ended}</td>";
         $msg .= "<td>{$status}</td>";
         $msg .= "</tr>";
     }
     $msg .= '</table>';
     // show 'check again' button
     $msg .= '<p>';
     $url = 'admin.php?page=wplister-tools&action=check_wc_sold_stock&_wpnonce=' . wp_create_nonce('e2e_tools_page');
     $msg .= '<a href="' . $url . '" class="button">' . __('Check again', 'wplister') . '</a> &nbsp; ';
     $msg .= '</p>';
     // $msg .= '<p>';
     // $url = 'admin.php?page=wplister-tools&action=check_wc_out_of_stock&mark_as_changed=yes&_wpnonce='.wp_create_nonce('e2e_tools_page');
     // $msg .= '<a href="'.$url.'" class="button">'.__('Mark all as changed','wplister').'</a> &nbsp; ';
     // $msg .= 'Click this button to mark all found listings as changed in WP-Lister, then revise all changed listings.';
     // $msg .= '</p>';
     $this->showMessage($msg, 1, 1);
 }
    function wplister_product_submitbox_imported_status()
    {
        global $post;
        global $woocommerce;
        $item_source = get_post_meta($post->ID, '_ebay_item_source', true);
        if (!$item_source) {
            return;
        }
        $ebay_id = get_post_meta($post->ID, '_ebay_item_id', true);
        // get ViewItemURL - fall back to generic url on ebay.com
        $ebay_url = WPLE_ListingQueryHelper::getViewItemURLFromPostID($post->ID);
        if (!$ebay_url) {
            $ebay_url = 'http://www.ebay.com/itm/' . $ebay_id;
        }
        ?>

		<div class="misc-pub-section" id="wplister-submit-options">

			<?php 
        _e('This product was imported', 'wplister');
        ?>
				<!-- <b><?php 
        echo $item->status;
        ?>
</b> &nbsp; -->
				<a href="<?php 
        echo $ebay_url;
        ?>
" target="_blank" style="float:right;">
					<?php 
        echo __('View on eBay', 'wplister');
        ?>
				</a>
			<br>

		</div>
		<?php 
    }
Example #9
0
 private function saveTemplate()
 {
     // set templates root folder
     $upload_dir = wp_upload_dir();
     $templates_dir = $upload_dir['basedir'] . '/wp-lister/templates/';
     // handle add_new_template
     // if ( $this->getValueFromPost('add_new_template') == 1 ) {
     if (isset($_REQUEST['wpl_add_new_template'])) {
         // check folder name
         $dirname = strtolower(sanitize_file_name($this->getValueFromPost('template_name')));
         if ($dirname == '') {
             $this->showMessage("Could not create template. No template name was provided.", 1);
             return false;
         }
         // tpl_dir is the full path to the template
         $tpl_dir = $templates_dir . $dirname;
         // if folder exists, append '-1', '-2', .. '-99'
         if (is_dir($tpl_dir)) {
             for ($i = 1; $i < 100; $i++) {
                 $new_tpl_dir = $tpl_dir . '-' . $i;
                 if (!is_dir($new_tpl_dir)) {
                     $tpl_dir = $new_tpl_dir;
                     break;
                 }
             }
         }
         // make new folder
         $result = @mkdir($tpl_dir);
         // handle errors
         if ($result === false) {
             $this->showMessage("Could not create template folder: " . $tpl_dir, 1);
             return false;
         } else {
             $this->showMessage(__('New template created in folder:', 'wplister') . ' ' . basename($tpl_dir));
         }
         // init default template to handle setting
         $templatesModel = new TemplatesModel();
         $templatesModel->folderpath = WPLISTER_PATH . '/templates/default/';
         $templatesModel->initTemplate();
         // save existing template
     } else {
         $dirname = $this->getValueFromPost('template_id');
         $tpl_dir = $templates_dir . $dirname;
         $changed = 0;
         // re-apply profile to all published
         $listingsModel = new ListingsModel();
         $items = WPLE_ListingQueryHelper::getAllPublishedWithTemplate($dirname);
         if (!empty($items)) {
             foreach ($items as $item) {
                 // don't mark locked items as changed
                 if (!$item['locked']) {
                     // ListingsModel::updateListing( $item['id'], array('status' => 'changed') ); // for some reason, this was messing up quantities
                     $listingsModel->reapplyProfileToItem($item['id']);
                     $changed++;
                 }
             }
             $this->showMessage(sprintf(__('%s published items marked as changed.', 'wplister'), $changed));
         }
         // init template to handle setting
         $templatesModel = new TemplatesModel($dirname);
         $templatesModel->initTemplate();
     }
     // destination files
     $file_html = $tpl_dir . '/template.html';
     $file_css = $tpl_dir . '/style.css';
     $file_header = $tpl_dir . '/header.php';
     $file_footer = $tpl_dir . '/footer.php';
     $file_functions = $tpl_dir . '/functions.php';
     $file_settings = $tpl_dir . '/config.json';
     $tpl_html = stripslashes($this->getValueFromPost('tpl_html'));
     $tpl_css = stripslashes($this->getValueFromPost('tpl_css'));
     $tpl_header = stripslashes($this->getValueFromPost('tpl_header'));
     $tpl_footer = stripslashes($this->getValueFromPost('tpl_footer'));
     $tpl_functions = stripslashes($this->getValueFromPost('tpl_functions'));
     $template_name = stripslashes($this->getValueFromPost('template_name'));
     $template_description = stripslashes($this->getValueFromPost('template_description'));
     $template_version = stripslashes($this->getValueFromPost('template_version'));
     // strip CDATA tags
     $tpl_html = $this->stripCDATA($tpl_html);
     $tpl_header = $this->stripCDATA($tpl_header);
     $tpl_footer = $this->stripCDATA($tpl_footer);
     // handle custom fields settings
     $settings = array();
     if (is_array($templatesModel->fields)) {
         foreach ($templatesModel->fields as $field_id => $field) {
             $value = $this->getValueFromPost('tpl_field_' . $field_id);
             if ($value) {
                 $settings[$field_id] = stripslashes($value);
             }
         }
     }
     // add template header
     $header_css = "/* \n";
     $header_css .= "Template: {$template_name}\n";
     $header_css .= "Description: {$template_description}\n";
     $header_css .= "Version: {$template_version}\n";
     $header_css .= "*/\n";
     $tpl_css = $header_css . $tpl_css;
     // update template files
     $result = file_put_contents($file_css, $tpl_css);
     $result = file_put_contents($file_functions, $tpl_functions);
     $result = file_put_contents($file_footer, $tpl_footer);
     $result = file_put_contents($file_header, $tpl_header);
     $result = file_put_contents($file_html, $tpl_html);
     $result = file_put_contents($file_settings, json_encode($settings));
     // catch any errors about permissions, safe mode, etc.
     global $php_errormsg;
     ini_set('track_errors', 1);
     if (!touch($file_css)) {
         $this->showMessage($php_errormsg, true);
     }
     // proper error handling
     if ($result === false) {
         $this->showMessage("WP-Lister failed to save your template because it could not write to the file <pre>{$file_css}</pre> Please check the file and folder permissions and make sure that PHP safe_mode is disabled.", true);
     } else {
         // hide double success message when adding new template
         if (!isset($_REQUEST['wpl_add_new_template'])) {
             $this->showMessage(__('Template saved.', 'wplister'));
         }
         // if we were updating this template as part of setup, move to next step
         if ('3' == self::getOption('setup_next_step')) {
             self::updateOption('setup_next_step', 4);
         }
     }
 }
Example #10
0
 function customize_toolbar($wp_admin_bar)
 {
     // check if current user can manage listings
     if (!current_user_can('manage_ebay_listings')) {
         return;
     }
     // top level 'eBay'
     $args = array('id' => 'wplister_top', 'title' => __('eBay', 'wplister'), 'href' => admin_url('admin.php?page=wplister'), 'meta' => array('class' => 'wplister-toolbar-top'));
     $wp_admin_bar->add_node($args);
     // Listings page
     $args = array('id' => 'wplister_listings', 'title' => __('Listings', 'wplister'), 'href' => admin_url('admin.php?page=wplister'), 'parent' => 'wplister_top', 'meta' => array('class' => 'wplister-toolbar-page'));
     $wp_admin_bar->add_node($args);
     // Profiles page
     $args = array('id' => 'wplister_profiles', 'title' => __('Profiles', 'wplister'), 'href' => admin_url('admin.php?page=wplister-profiles'), 'parent' => 'wplister_top', 'meta' => array('class' => 'wplister-toolbar-page'));
     $wp_admin_bar->add_node($args);
     $mode = get_option('wplister_ebay_update_mode', 'order');
     if ($mode == 'order') {
         // Orders page
         $args = array('id' => 'wplister_orders', 'title' => __('Orders', 'wplister'), 'href' => admin_url('admin.php?page=wplister-orders'), 'parent' => 'wplister_top', 'meta' => array('class' => 'wplister-toolbar-page'));
         $wp_admin_bar->add_node($args);
     } else {
         // Transactions page
         $args = array('id' => 'wplister_transactions', 'title' => __('Transactions', 'wplister'), 'href' => admin_url('admin.php?page=wplister-transactions'), 'parent' => 'wplister_top', 'meta' => array('class' => 'wplister-toolbar-page'));
         $wp_admin_bar->add_node($args);
     }
     // Tools page
     $args = array('id' => 'wplister_tools', 'title' => __('Tools', 'wplister'), 'href' => admin_url('admin.php?page=wplister-tools'), 'parent' => 'wplister_top', 'meta' => array('class' => 'wplister-toolbar-page'));
     $wp_admin_bar->add_node($args);
     if (current_user_can('manage_ebay_options')) {
         // Settings page
         $args = array('id' => 'wplister_settings', 'title' => __('Settings', 'wplister'), 'href' => admin_url('admin.php?page=wplister-settings'), 'parent' => 'wplister_top', 'meta' => array('class' => 'wplister-toolbar-page'));
         $wp_admin_bar->add_node($args);
         // Settings - General tab
         $args = array('id' => 'wplister_settings_general', 'title' => __('General Settings', 'wplister'), 'href' => admin_url('admin.php?page=wplister-settings'), 'parent' => 'wplister_settings', 'meta' => array('class' => 'wplister-toolbar-page'));
         $wp_admin_bar->add_node($args);
         // Settings - Accounts tab
         $args = array('id' => 'wplister_settings_accounts', 'title' => __('Accounts', 'wplister'), 'href' => admin_url('admin.php?page=wplister-settings&tab=accounts'), 'parent' => 'wplister_settings', 'meta' => array('class' => 'wplister-toolbar-page'));
         $wp_admin_bar->add_node($args);
         // Settings - Categories tab
         $args = array('id' => 'wplister_settings_categories', 'title' => __('Categories', 'wplister'), 'href' => admin_url('admin.php?page=wplister-settings&tab=categories'), 'parent' => 'wplister_settings', 'meta' => array('class' => 'wplister-toolbar-page'));
         $wp_admin_bar->add_node($args);
         // Settings - Advanced tab
         $args = array('id' => 'wplister_settings_advanced', 'title' => __('Advanced', 'wplister'), 'href' => admin_url('admin.php?page=wplister-settings&tab=advanced'), 'parent' => 'wplister_settings', 'meta' => array('class' => 'wplister-toolbar-page'));
         $wp_admin_bar->add_node($args);
         // Settings - Developer tab
         $args = array('id' => 'wplister_settings_developer', 'title' => __('Developer', 'wplister'), 'href' => admin_url('admin.php?page=wplister-settings&tab=developer'), 'parent' => 'wplister_settings', 'meta' => array('class' => 'wplister-toolbar-page'));
         $wp_admin_bar->add_node($args);
     }
     // if current_user_can('manage_ebay_options')
     if (current_user_can('manage_ebay_options') && get_option('wplister_log_to_db') == '1') {
         // Logs page
         $args = array('id' => 'wplister_log', 'title' => __('Logs', 'wplister'), 'href' => admin_url('admin.php?page=wplister-log'), 'parent' => 'wplister_top', 'meta' => array('class' => 'wplister-toolbar-page'));
         $wp_admin_bar->add_node($args);
     }
     // product page
     global $post;
     global $wp_query;
     global $pagenow;
     $post_id = false;
     if ($wp_query->in_the_loop && isset($wp_query->post->post_type) && $wp_query->post->post_type == 'product') {
         $post_id = $wp_query->post->ID;
     } elseif (is_object($post) && isset($post->post_type) && $post->post_type == 'product') {
         $post_id = $post->ID;
     }
     // skip product links on the main products page
     if ($pagenow == 'edit.php') {
         return;
     }
     // do we have a single product page?
     if (empty($post_id)) {
         return;
     }
     // get all items
     $listings = WPLE_ListingQueryHelper::getAllListingsFromPostID($post_id);
     if (sizeof($listings) > 0) {
         $ebay_id = WPLE_ListingQueryHelper::getEbayIDFromPostID($post_id);
         $url = WPLE_ListingQueryHelper::getViewItemURLFromPostID($post_id);
         // View on eBay link
         $args = array('id' => 'wplister_view_on_ebay', 'title' => __('View item on eBay', 'wplister'), 'href' => $url, 'parent' => 'wplister_top', 'meta' => array('target' => '_blank', 'class' => 'wplister-toolbar-link'));
         if ($url) {
             $wp_admin_bar->add_node($args);
         }
         foreach ($listings as $listing) {
             $args = array('id' => 'wplister_view_on_ebay_' . $listing->id, 'title' => '#' . $listing->ebay_id . ': ' . $listing->auction_title, 'href' => $listing->ViewItemURL, 'parent' => 'wplister_view_on_ebay', 'meta' => array('target' => '_blank', 'class' => 'wplister-toolbar-link'));
             if ($listing->ViewItemURL) {
                 $wp_admin_bar->add_node($args);
             }
         }
         // View in WP-Lister
         $url = admin_url('admin.php?page=wplister&s=' . $post_id);
         $args = array('id' => 'wplister_view_on_listings_page', 'title' => __('View item in WP-Lister', 'wplister'), 'href' => $url, 'parent' => 'wplister_top', 'meta' => array('target' => '_blank', 'class' => 'wplister-toolbar-link'));
         $wp_admin_bar->add_node($args);
     } else {
         // $args = $this->addPrepareActions( $args );
     }
     if (current_user_can('prepare_ebay_listings')) {
         $this->addPrepareActions($wp_admin_bar, $post_id);
     }
 }
Example #11
0
 public function checkProductImages()
 {
     // get all listings
     $listings = WPLE_ListingQueryHelper::getAll();
     $found_images = array();
     $found_products = array();
     // allow WP to upscale images
     if (isset($_REQUEST['resize_images'])) {
         add_filter('image_resize_dimensions', array($this, 'filter_image_resize_dimensions'), 10, 6);
     }
     // process published listings
     foreach ($listings as $item) {
         // get featured image id
         $post_id = $item['post_id'];
         $attachment_id = get_post_thumbnail_id($post_id);
         if (!$attachment_id) {
             continue;
         }
         // $image_attributes = wp_get_attachment_image_src( $attachment_id, 'full' );
         // $img_width  = $image_attributes[1];
         // $img_height = $image_attributes[2];
         // get attachment meta data
         $meta = wp_get_attachment_metadata($attachment_id);
         if (empty($meta)) {
             continue;
         }
         // echo "<pre>";print_r($meta);echo"</pre>";#die();
         // check if at least one side is 500px or longer
         if ($meta['width'] >= 500 || $meta['height'] >= 500) {
             continue;
         }
         // echo "<pre>";print_r($attachment_id);echo"</pre>";#die();
         // resize image
         if (isset($_REQUEST['resize_images'])) {
             $size = $this->upscaleImage($meta['file']);
             if ($size) {
                 // update attachment meta sizes
                 // echo "<pre>new size: ";print_r($size);echo"</pre>";#die();
                 $meta['width'] = $size['width'];
                 $meta['height'] = $size['height'];
                 // echo wp_update_attachment_metadata( $post_id, $meta );
                 update_post_meta($attachment_id, '_wp_attachment_metadata', $meta);
                 // clear EPS cache for listing item
                 ListingsModel::updateListing($item['id'], array('eps' => NULL));
                 $this->showMessage(sprintf('Resized image <code>%s</code> to %s x %s.', $meta['file'], $meta['width'], $meta['height']));
                 continue;
             }
         }
         // get image url
         $image_attributes = wp_get_attachment_image_src($attachment_id, 'full');
         $meta['url'] = $image_attributes[0];
         $meta['post_id'] = $post_id;
         $meta['ebay_id'] = $item['ebay_id'];
         $meta['ViewItemURL'] = $item['ViewItemURL'];
         // add to list of found images
         $found_images[$attachment_id] = $meta;
     }
     // echo "<pre>";print_r($found_images);echo"</pre>";
     // return if empty
     if (empty($found_images)) {
         $this->showMessage('All images are okay.');
         return;
     }
     $msg = '<p>';
     $msg .= 'Warning: Some product images do not meet the requirements.';
     $msg .= '</p>';
     // table header
     $msg .= '<table style="width:100%">';
     $msg .= "<tr>";
     $msg .= "<th style='text-align:left'>Width</th>";
     $msg .= "<th style='text-align:left'>Height</th>";
     $msg .= "<th style='text-align:left'>File</th>";
     $msg .= "<th style='text-align:left'>Product</th>";
     $msg .= "<th style='text-align:left'>eBay ID</th>";
     $msg .= "<th style='text-align:left'>ID</th>";
     $msg .= "</tr>";
     // table rows
     foreach ($found_images as $attachment_id => $item) {
         // get column data
         $post_id = $item['post_id'];
         $ebay_id = $item['ebay_id'];
         $width = $item['width'];
         $height = $item['height'];
         $file = $item['file'];
         $url = $item['url'];
         $title = get_the_title($item['post_id']);
         // build links
         $ebay_url = $item['ViewItemURL'] ? $item['ViewItemURL'] : ($ebay_url = 'http://www.ebay.com/itm/' . $ebay_id);
         $ebay_link = '<a href="' . $ebay_url . '" target="_blank">' . $ebay_id . '</a>';
         $edit_link = '<a href="post.php?action=edit&post=' . $post_id . '" target="_blank">' . $title . '</a>';
         $file_link = '<a href="' . $url . '" target="_blank">' . $file . '</a>';
         // build table row
         $msg .= "<tr>";
         $msg .= "<td>{$width}</td>";
         $msg .= "<td>{$height}</td>";
         $msg .= "<td>{$file_link}</td>";
         $msg .= "<td>{$edit_link} (ID {$post_id})</td>";
         $msg .= "<td>{$ebay_link}</td>";
         $msg .= "<td>{$attachment_id}</td>";
         $msg .= "</tr>";
     }
     $msg .= '</table>';
     $msg .= '<p>';
     $url = 'admin.php?page=wplister-tools&action=check_ebay_image_requirements&resize_images=yes&_wpnonce=' . wp_create_nonce('e2e_tools_page');
     $msg .= '<a href="' . $url . '" class="button">' . __('Resize all', 'wplister') . '</a> &nbsp; ';
     $msg .= 'Click this button to upscale all found images to 500px.';
     $msg .= '</p>';
     $this->showMessage($msg, 1);
 }
Example #12
0
 public function getPreviewHTML($template_id, $id = false)
 {
     // get item data
     if ($id) {
         $item = ListingsModel::getItem($id);
     } else {
         $item = WPLE_ListingQueryHelper::getItemForPreview();
     }
     if (!$item) {
         return '<div style="text-align:center; margin-top:5em;">You need to prepare at least one listing in order to preview a listing template.</div>';
     }
     // use latest post_content from product - moved to TemplatesModel
     // $post = get_post( $item['post_id'] );
     // if ( ! empty($post->post_content) ) $item['post_content'] = $post->post_content;
     // load template
     if (!$template_id) {
         $template_id = $item['template'];
     }
     $template = new TemplatesModel($template_id);
     $html = $template->processItem($item, false, true);
     // return html
     return $html;
 }
Example #13
0
 function get_current_ebay_item()
 {
     global $post;
     if ($this->_ebay_item === null) {
         $listings = WPLE_ListingQueryHelper::getAllListingsFromPostID($post->ID);
         $this->_ebay_item = is_array($listings) && !empty($listings) ? $listings[0] : false;
     }
     return $this->_ebay_item;
 }
 function is_published_on_ebay($post_id)
 {
     $listings = WPLE_ListingQueryHelper::getAllListingsFromPostID($post_id);
     foreach ($listings as $listing) {
         // check status
         if (!in_array($listing->status, array('published', 'changed'))) {
             continue;
         }
         // check end date
         if ($listing->end_date) {
             if (strtotime($listing->end_date) < time()) {
                 continue;
             }
         }
         return $listing;
     }
     return false;
 }
Example #15
0
 public function ajax_wpl_ebay_item_query()
 {
     $col = isset($_REQUEST['col']) ? intval($_REQUEST['col']) : 'ebay_id';
     $id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : false;
     if ($col != 'ebay_id') {
         return;
     }
     // limited to single use case for now
     if ($id == '') {
         return;
     }
     $items = WPLE_ListingQueryHelper::getWhere('id', $id);
     $result = $items ? reset($items)->ebay_id : false;
     // check if callback parameter is set
     if (isset($_REQUEST['callback'])) {
         // return JSONP
         header('content-type: application/javascript; charset=utf-8');
         echo $_REQUEST['callback'] . '(' . json_encode($result) . ')';
     } else {
         // return plain JSON
         header('content-type: application/json; charset=utf-8');
         echo json_encode($result);
     }
     exit;
 }
Example #16
0
 public function applyProfileToNewListings($profile, $items = false, $update_title = true)
 {
     // get selected items - if no items provided
     if (!$items) {
         $items = WPLE_ListingQueryHelper::getAllSelected();
     }
     $items = $this->applyProfileToItems($profile, $items, $update_title);
     return $items;
 }
Example #17
0
 /** ************************************************************************
  * REQUIRED! This is where you prepare your data for display. This method will
  * usually be used to query the database, sort and filter the data, and generally
  * get it ready to be displayed. At a minimum, we should set $this->items and
  * $this->set_pagination_args(), although the following properties and methods
  * are frequently interacted with here...
  * 
  * @uses $this->_column_headers
  * @uses $this->items
  * @uses $this->get_columns()
  * @uses $this->get_sortable_columns()
  * @uses $this->get_pagenum()
  * @uses $this->set_pagination_args()
  **************************************************************************/
 function prepare_items()
 {
     // process bulk actions
     $this->process_bulk_action();
     // get pagination state
     $current_page = $this->get_pagenum();
     $per_page = $this->get_items_per_page('listings_per_page', 20);
     // regard max table rows limit
     if ($max_per_page = get_option('wplister_force_table_items_limit')) {
         $per_page = min($per_page, $max_per_page);
     }
     // define columns
     $this->_column_headers = $this->get_column_info();
     // fetch listings from model - if no selected products were found
     if (!$this->selectedItems) {
         $result = WPLE_ListingQueryHelper::getPageItems($current_page, $per_page);
         $this->items = $result->items;
         $this->total_items = $result->total_items;
     } else {
         $this->items = $this->selectedItems;
         $this->total_items = count($this->selectedItems);
     }
     // register our pagination options & calculations.
     $this->set_pagination_args(array('total_items' => $this->total_items, 'per_page' => $per_page, 'total_pages' => ceil($this->total_items / $per_page)));
 }
Example #18
0
 public function reviseAllChangedItems()
 {
     $items = WPLE_ListingQueryHelper::getAllChangedItemsToRevise();
     foreach ($items as $item) {
         $sm->reviseItem($item['id'], $this->session);
     }
 }