Zunächst muss man im Admin Bereich den Link zum "Product image folder" angeben. Für OSC wäre dies "www.samplesite.com/catalog/images/" Hier bin ich mir schon mal unsicher, wie der bei webs genau heissen würde. Doch auch wenn ich diesen korrekt angebe, würde es wahrscheinlich irgendwo noch blocken. Soviel ich weiss, wurde bei Webs ja einiges umgestellt. Deshalb bin ich mal so frei um hier die zwei Dateien zu publizieren:
Code: Alles auswählen
<?php
/*
Plugin Name: OSCommerce Product Generator
Plugin URI: http://www.gavinflood.com
Description: Plugin used to display products from an OSCommerce database on a WordPress site. Idea based on C. Lupu's NetTuts tutorial.
Author: Gavin Flood
Version: 1.0
Author URI: http://www.gavinflood.com
*/
function oscommerce_generate_products($number_to_show) {
/* Connect to the OSCommerce database. */
$oscommerce_database = new wpdb(get_option('oscommerce_db_user'),get_option('oscommerce_db_password'), get_option('oscommerce_db_name'), get_option('oscommerce_db_host'));
$generated_html = '';
/* Array holds previous products to ensure no repetition occurs when generating. */
$previous_products = array();
for ($i = 0; $i < $number_to_show; $i++) {
/* Retreive a random product. */
$product_id = $oscommerce_database->get_var("SELECT products_id FROM products where products_image != '' ORDER BY RAND() LIMIT 1");
/* Repeat the product_id generator until a unique id is generated. */
while (in_array($product_id, $previous_products)) {
$product_id = $oscommerce_database->get_var("SELECT products_id FROM products where products_image != '' ORDER BY RAND() LIMIT 1");
}
/* Add product_id to array of previous products */
array_push($previous_products, $product_id);
/* Get the string value of the product's image, name, url and folder. */
$product_image = $oscommerce_database->get_var("SELECT products_image FROM products WHERE products_id = $product_id");
$product_name = $oscommerce_database->get_var("SELECT products_name FROM products_description WHERE products_id = $product_id");
$store_url = get_option('oscommerce_store_url');
$image_folder = get_option('oscommerce_product_image_folder');
/* Generate the HTML code for the product. */
$generated_html .= '<p class="oscommerce-product-display-p">';
$generated_html .= '<a class="oscommerce-product-display-a" href="'.$store_url.'product_info.php?products_id='.$product_id.'">'.$product_name.'</a>';
$generated_html .= '<img src="'.$image_folder.$product_image.'" alt="" class="oscommerce-product-display-img" /></p>';
}
echo $generated_html;
}
/* Display user specified content around generated HTML. */
function widget_oscommerce_product_display($args) {
extract($args);
$options = get_option("widget_oscommerce_product_display");
if (!is_array($options)) {
$options = array(
'title' => 'In Store',
'num_products' => 3
);
}
echo $before_widget;
echo $before_title;
echo $options['title'];
echo $after_title;
oscommerce_generate_products($options['num_products']);
echo $after_widget;
}
/* User controls for widget. */
function oscommerce_product_display_control() {
$options = get_option('widget_oscommerce_product_display');
if (!is_array($options)) {
$options = array(
'title' => 'In Store',
'num_products' => 3
);
}
if ($_POST['oscommerce_product_display_submit']) {
$options['title'] = htmlspecialchars($_POST['oscommerce_product_display_title']);
$options['num_products'] = htmlspecialchars($_POST['oscommerce_num_products']);
update_option('widget_oscommerce_product_display', $options);
}
echo '<p>';
echo '<label for="oscommerce_product_display_title">Title: </label><br />';
echo '<input type="text" id="oscommerce_product_display_title" name="oscommerce_product_display_title" value="'.$options['title'].'" /><br /><br />';
echo '<label for="oscommerce_num_products">Number Of Products To Show: </label><br />';
echo '<input type="text" id="oscommerce_num_products" name="oscommerce_num_products" value="'.$options['num_products'].'" />';
echo '<input type="hidden" id="oscommerce_product_display_submit" name="oscommerce_product_display_submit" value="1" />';
}
/* Initialise the product generator */
function product_generator_init() {
register_sidebar_widget(__('Product Generator'), 'widget_oscommerce_product_display');
register_widget_control( ('Product Generator'), 'oscommerce_product_display_control', 300, 300);
}
/*
* Admin Functions.
*/
function oscommerce_admin_include() {
include('oscommerce_product_display_admin.php');
}
function oscommerce_admin_options() {
add_options_page("Product Generator", "Product Generator", 1, "Product-Generator", "oscommerce_admin_include");
}
add_action('admin_menu', 'oscommerce_admin_options');
add_action('plugins_loaded', 'product_generator_init');
?>
Code: Alles auswählen
<?php
if($_POST['oscommerce_hidden'] == 'Y') {
/* Send form data. */
$database_host = $_POST['oscommerce_db_host'];
update_option('oscommerce_db_host', $database_host);
$database_name = $_POST['oscommerce_db_name'];
update_option('oscommerce_db_name', $database_name);
$database_user = $_POST['oscommerce_db_user'];
update_option('oscommerce_db_user', $database_user);
$database_password = $_POST['oscommerce_db_password'];
update_option('oscommerce_db_password', $database_password);
$product_image_folder = $_POST['oscommerce_product_image_folder'];
update_option('oscommerce_product_image_folder', $product_image_folder);
$store_url = $_POST['oscommerce_store_url'];
update_option('oscommerce_store_url', $store_url);
?>
<div class="updated"><p><strong><?php _e('Options saved.' ); ?></strong></p></div>
<?php
} else {
/* Display page normally. */
$database_host = get_option('oscommerce_db_host');
$database_name = get_option('oscommerce_db_name');
$database_user = get_option('oscommerce_db_user');
$database_password = get_option('oscommerce_db_password');
$product_image_folder = get_option('oscommerce_product_image_folder');
$store_url = get_option('oscommerce_store_url');
}
?>
<!-- The HTML form for the admin page. -->
<div class="wrap">
<?php echo "<h2>".__('OSCommerce Product Generator Options', 'oscommerce_trdom')."</h2>"; ?>
<form name="oscommerce_form" method="post" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?>">
<input type="hidden" name="oscommerce_hidden" value="Y" />
<?php echo "<h4>".__('OSCommerce Database Settings', 'oscommerce_trdom')."</h4>"; ?>
<p>
<?php _e("Database host: "); ?>
<input type="text" name="oscommerce_db_host" value="<?php echo $database_host; ?>" size="20" />
<?php _e(" ex: localhost"); ?>
</p>
<p>
<?php _e("Database name: "); ?>
<input type="text" name="oscommerce_db_name" value="<?php echo $database_name; ?>" size="20" />
<?php _e(" ex: oscommerce_shop"); ?>
</p>
<p>
<?php _e("Database user: "); ?>
<input type="text" name="oscommerce_db_user" value="<?php echo $database_user; ?>" size="20" />
<?php _e(" ex: admin"); ?>
</p>
<p>
<?php _e("Database password: "); ?>
<input type="text" name="oscommerce_db_password" value="<?php echo $database_password; ?>" size="20" />
<?php _e(" ex: SamplePassword"); ?>
</p>
<hr />
<?php echo "<h4>".__( 'OSCommerce Store Settings', 'oscommerce_trdom')."</h4>"; ?>
<p>
<?php _e("Store URL: "); ?>
<input type="text" name="oscommerce_store_url" value="<?php echo $store_url; ?>" size="20" />
<?php _e(" ex: http://www.samplesite.com/catalog/"); ?>
</p>
<p>
<?php _e("Product image folder: "); ?>
<input type="text" name="oscommerce_product_image_folder" value="<?php echo $product_image_folder; ?>" size="20" />
<?php _e(" ex: http://www.samplesite.com/catalog/images/" ); ?>
</p>
<p class="submit">
<input type="submit" name="Submit" value="<?php _e('Update Options', 'oscommerce_trdom' ) ?>" />
</p>
</form>
</div>
Grüsse Kopernikus