add_menu( array( 'id' => 'ecwid_main', 'title' => '', )); //add ecwid home page $wp_admin_bar->add_menu(array( "id" => "ecwid_home", "title" => "Ecwid Site", "parent" => "ecwid_main", 'href' => 'http://www.ecwid.com/' ) ); //add store page link $wp_admin_bar->add_menu(array( "id" => "ecwid_go_to_page", "title" => "My Ecwid Store", "parent" => "ecwid_main", 'href' => get_page_link(get_option("ecwid_store_page_id")) ) ); //add settings page link $wp_admin_bar->add_menu(array( "id" => "ecwid_settings", "title" => "Settings page", "parent" => "ecwid_main", 'href' => admin_url('options-general.php?page=ecwid_options_page' ) ) ); $wp_admin_bar->add_menu(array( "id" => "ecwid_fb_app", "title" => "→ Sell on Facebook", "parent" => "ecwid_main", 'href' => 'http://apps.facebook.com/ecwid-shop/?fb_source=wp' ) ); } function ecwid_ajax_crawling_fragment() { $ecwid_page_id = get_option("ecwid_store_page_id"); if (ecwid_is_api_enabled() && !isset($_GET['_escaped_fragment_']) && get_the_ID() == $ecwid_page_id) echo '' . PHP_EOL; } function ecwid_meta() { echo '' . PHP_EOL; echo '' . PHP_EOL; echo '' . PHP_EOL; $ecwid_page_id = get_option("ecwid_store_page_id"); if (get_the_ID() != $ecwid_page_id) { $page_url = get_page_link($ecwid_page_id); echo '' . PHP_EOL; echo '' . PHP_EOL; } } function ecwid_seo_title($content) { if (isset($_GET['_escaped_fragment_']) && ecwid_is_api_enabled()) { $params = ecwid_parse_escaped_fragment($_GET['_escaped_fragment_']); $ecwid_seo_title = ''; $api = ecwid_new_product_api(); if (isset($params['mode']) && !empty($params['mode'])) { if ($params['mode'] == 'product') { $ecwid_product = $api->get_product($params['id']); $ecwid_seo_title = $ecwid_product['name']; } elseif ($params['mode'] == 'category') { // define category's title. no API for that QQ } } if (!empty($ecwid_seo_title)) return $ecwid_seo_title . " | " . $content; else return $content; } else { return $content; } } function ecwid_get_scriptjs_code() { if (!defined('ECWID_SCRIPTJS')) { $ecwid_protocol = get_ecwid_protocol(); $store_id = get_ecwid_store_id(); $s = ""; define('ECWID_SCRIPTJS','Yep'); $s = $s . ecwid_sso(); return $s; } else { return; } } function ecwid_script_shortcode() { return '
' . ecwid_get_scriptjs_code() . '
'; } function ecwid_minicart_shortcode() { $ecwid_enable_minicart = get_option('ecwid_enable_minicart'); $ecwid_show_categories = get_option('ecwid_show_categories'); if (!empty($ecwid_enable_minicart) && !empty($ecwid_show_categories)) { $s = << EOT; return $s; } else { return ""; } } function ecwid_searchbox_shortcode() { $ecwid_show_search_box = get_option('ecwid_show_search_box'); if (!empty($ecwid_show_search_box)) { $s = << EOT; return $s; } else { return ""; } } function ecwid_categories_shortcode() { $ecwid_show_categories = get_option('ecwid_show_categories'); if (!empty($ecwid_show_categories)) { $s = << EOT; return $s; } else { return ""; } } function ecwid_parse_escaped_fragment($escaped_fragment) { $fragment = urldecode($escaped_fragment); $return = array(); if (preg_match('/^(\/~\/)([a-z]+)\/(.*)$/', $fragment, $matches)) { parse_str($matches[3], $return); $return['mode'] = $matches[2]; } return $return; } function ecwid_productbrowser_shortcode() { global $ecwid_seo_product_title; $store_id = get_ecwid_store_id(); $list_of_views = array('list','grid','table'); $ecwid_pb_categoriesperrow = get_option('ecwid_pb_categoriesperrow'); $ecwid_pb_productspercolumn_grid = get_option('ecwid_pb_productspercolumn_grid'); $ecwid_pb_productsperrow_grid = get_option('ecwid_pb_productsperrow_grid'); $ecwid_pb_productsperpage_list = get_option('ecwid_pb_productsperpage_list'); $ecwid_pb_productsperpage_table = get_option('ecwid_pb_productsperpage_table'); $ecwid_pb_defaultview = get_option('ecwid_pb_defaultview'); $ecwid_pb_searchview = get_option('ecwid_pb_searchview'); $ecwid_mobile_catalog_link = get_option('ecwid_mobile_catalog_link'); $ecwid_default_category_id = get_option('ecwid_default_category_id'); if (empty($ecwid_pb_categoriesperrow)) { $ecwid_pb_categoriesperrow = 3; } if (empty($ecwid_pb_productspercolumn_grid)) { $ecwid_pb_productspercolumn_grid = 3; } if (empty($ecwid_pb_productsperrow_grid)) { $ecwid_pb_productsperrow_grid = 3; } if (empty($ecwid_pb_productsperpage_list)) { $ecwid_pb_productsperpage_list = 10; } if (empty($ecwid_pb_productsperpage_table)) { $ecwid_pb_productsperpage_table = 20; } if (empty($ecwid_pb_defaultview) || !in_array($ecwid_pb_defaultview, $list_of_views)) { $ecwid_pb_defaultview = 'grid'; } if (empty($ecwid_pb_searchview) || !in_array($ecwid_pb_searchview, $list_of_views)) { $ecwid_pb_searchview = 'list'; } if (empty($ecwid_mobile_catalog_link)) { $ecwid_mobile_catalog_link = "http://" . APP_ECWID_COM . "/jsp/{$store_id}/catalog"; } if (empty($ecwid_default_category_id)) { $ecwid_default_category_str = ''; } else { $ecwid_default_category_str = ',"defaultCategoryId='. $ecwid_default_category_id .'"'; } $ecwid_open_product = ''; $plain_content = ''; if (ecwid_is_api_enabled()) { if (isset($_GET['_escaped_fragment_'])) { $params = ecwid_parse_escaped_fragment($_GET['_escaped_fragment_']); include_once WP_PLUGIN_DIR . '/ecwid-shopping-cart/lib/EcwidCatalog.php'; $ecwid_page_id = get_option("ecwid_store_page_id"); $page_url = get_page_link($ecwid_page_id); $catalog = new EcwidCatalog($store_id, $page_url); if (isset($params['mode']) && !empty($params['mode'])) { if ($params['mode'] == 'product') { $plain_content = $catalog->get_product($params['id']); $plain_content .= ''; } elseif ($params['mode'] == 'category') { $plain_content = $catalog->get_category($params['id']); $ecwid_default_category_str = ',"defaultCategoryId=' . $params['id'] . '"'; } } else { $plain_content = $catalog->get_category(0); } } } else { $plain_content = ''; } $s = << {$plain_content} EOT; return $s; } function ecwid_store_activate() { $my_post = array(); $content = << [ecwid_script] [ecwid_minicart] [ecwid_searchbox] [ecwid_categories] [ecwid_productbrowser] EOT; add_option("ecwid_store_page_id", '', '', 'yes'); add_option("ecwid_store_id", '1003', '', 'yes'); add_option("ecwid_enable_minicart", 'Y', '', 'yes'); add_option("ecwid_show_categories", 'Y', '', 'yes'); add_option("ecwid_show_search_box", '', '', 'yes'); add_option("ecwid_pb_categoriesperrow", '3', '', 'yes'); add_option("ecwid_pb_productspercolumn_grid", '3', '', 'yes'); add_option("ecwid_pb_productsperrow_grid", '3', '', 'yes'); add_option("ecwid_pb_productsperpage_list", '10', '', 'yes'); add_option("ecwid_pb_productsperpage_table", '20', '', 'yes'); add_option("ecwid_pb_defaultview", 'grid', '', 'yes'); add_option("ecwid_pb_searchview", 'list', '', 'yes'); add_option("ecwid_enable_ssl", '', '', 'yes'); add_option("ecwid_mobile_catalog_link", '', '', 'yes'); add_option("ecwid_default_category_id", '', '', 'yes'); add_option('ecwid_is_api_enabled', 'on', '', 'yes'); add_option('ecwid_api_check_time', 0, '', 'yes'); add_option("ecwid_sso_secret_key", '', '', 'yes'); $id = get_option("ecwid_store_page_id"); $_tmp_page = null; if (!empty($id) and ($id > 0)) { $_tmp_page = get_page($id); } if ($_tmp_page !== null) { $my_post = array(); $my_post['ID'] = $id; $my_post['post_status'] = 'publish'; wp_update_post( $my_post ); } else { $my_post['post_title'] = 'Store'; $my_post['post_content'] = $content; $my_post['post_status'] = 'publish'; $my_post['post_author'] = 1; $my_post['post_type'] = 'page'; $id = wp_insert_post( $my_post ); update_option('ecwid_store_page_id', $id); } } function ecwid_show_admin_message() { if (get_ecwid_store_id() != 1003) { return; } else { $ecwid_page_id = get_option("ecwid_store_page_id"); $page_url = get_page_link($ecwid_page_id); echo "

Ecwid shopping cart is almost ready. Please visit the created page to see your store with demo products. In order to finish the installation, please go to the Ecwid settings and configure the plugin.

"; } } function ecwid_store_deactivate() { $ecwid_page_id = get_option("ecwid_store_page_id"); $_tmp_page = null; if (!empty($ecwid_page_id) and ($ecwid_page_id > 0)) { $_tmp_page = get_page($ecwid_page_id); if ($_tmp_page !== null) { $my_post = array(); $my_post['ID'] = $ecwid_page_id; $my_post['post_status'] = 'draft'; wp_update_post( $my_post ); } else { update_option('ecwid_store_page_id', ''); } } } function ecwid_abs_intval($value) { return abs(intval($value)); } function ecwid_settings_api_init() { register_setting('ecwid_options_page', 'ecwid_store_id','ecwid_abs_intval' ); register_setting('ecwid_options_page', 'ecwid_enable_minicart'); register_setting('ecwid_options_page', 'ecwid_show_categories'); register_setting('ecwid_options_page', 'ecwid_show_search_box'); register_setting('ecwid_options_page', 'ecwid_pb_categoriesperrow', 'ecwid_abs_intval'); register_setting('ecwid_options_page', 'ecwid_pb_productspercolumn_grid', 'ecwid_abs_intval'); register_setting('ecwid_options_page', 'ecwid_pb_productsperrow_grid', 'ecwid_abs_intval'); register_setting('ecwid_options_page', 'ecwid_pb_productsperpage_list', 'ecwid_abs_intval'); register_setting('ecwid_options_page', 'ecwid_pb_productsperpage_table', 'ecwid_abs_intval'); register_setting('ecwid_options_page', 'ecwid_pb_defaultview'); register_setting('ecwid_options_page', 'ecwid_pb_searchview'); register_setting('ecwid_options_page', 'ecwid_enable_ssl'); register_setting('ecwid_options_page', 'ecwid_mobile_catalog_link'); register_setting('ecwid_options_page', 'ecwid_default_category_id'); register_setting('ecwid_options_page', 'ecwid_sso_secret_key'); if (isset($_POST['ecwid_store_id'])) { update_option('ecwid_is_api_enabled', 'off'); update_option('ecwid_api_check_time', 0); } } function ecwid_options_add_page() { add_options_page('Ecwid shopping cart settings', 'Ecwid shopping cart', 'manage_options', 'ecwid_options_page', 'ecwid_options_do_page'); } function ecwid_options_do_page() { $store_id = get_ecwid_store_id(); $ecwid_enable_minicart = get_option('ecwid_enable_minicart'); $ecwid_show_categories = get_option('ecwid_show_categories'); $ecwid_show_search_box = get_option('ecwid_show_search_box'); $ecwid_pb_categoriesperrow = get_option('ecwid_pb_categoriesperrow'); $ecwid_pb_productspercolumn_grid = get_option('ecwid_pb_productspercolumn_grid'); $ecwid_pb_productsperrow_grid = get_option('ecwid_pb_productsperrow_grid'); $ecwid_pb_productsperpage_list = get_option('ecwid_pb_productsperpage_list'); $ecwid_pb_productsperpage_table = get_option('ecwid_pb_productsperpage_table'); $ecwid_pb_defaultview = get_option('ecwid_pb_defaultview'); $ecwid_pb_searchview = get_option('ecwid_pb_searchview'); $ecwid_mobile_catalog_link = get_option('ecwid_mobile_catalog_link'); $ecwid_default_category_id = get_option('ecwid_default_category_id'); $ecwid_enable_ssl = get_option('ecwid_enable_ssl'); $ecwid_page_id = get_option("ecwid_store_page_id"); $ecwid_sso_secret_key = get_option("ecwid_sso_secret_key"); $ecwid_noscript_seo_catalog_disabled = false; $ecwid_noscript_seo_catalog_message = 'How it works'; $ecwid_settings_message = false; $_tmp_page = null; $disabled = false; if (!empty($ecwid_page_id) and ($ecwid_page_id > 0)) { $_tmp_page = get_page($ecwid_page_id); $content = $_tmp_page->post_content; if ( (strpos($content, "[ecwid_productbrowser]") === false) && (strpos($content, "xProductBrowser") !== false) ) $disabled = true; } if ($disabled) $disabled_str = 'disabled = "disabled"'; else $disabled_str = ""; ?>

Error. $ecwid_settings_message

"; ?>

Ecwid settings

General

Store ID  The Store ID isn\'t set up. Please enter your Store ID to assign your site with your Ecwid store and show your products. How to get this free ID.'; } ?>
/>
/>
/>      If you added minicart to your blog's sidebar, please disable this option.

Appearance

/>
/>
/>
/>
/>

SEO

     For example http://mdemo.ecwid.comInformation about Ecwid and mobile catalogs.

Advanced

 This feature allows your customers to sign into your WordPress site and fully use your store without having to sign into Ecwid. I.e. if a customer is logged in to your site, he/she is logged in to your store automatically, even if he/she didn't have an account in your store before. In order to enable this feature you should set the secret key that can be found on the "System Settings > API > Single Sign-on API" page in your Ecwid control panel. Please note that this API is available only to paid users.
/>      Information about Ecwid and SSL/HTTPS
     What is it?

Instruction on how to get your free Store ID

  • Go to the Ecwid control panel. Open this URL: https://my.ecwid.com/cp/#register. You will get to 'Sign In or Register' form.
  • Register an account at Ecwid. Use section "Using Ecwid account" for that. The registration is free.

    Or you can log in using your account at Gmail, Facebook, Twitter, Yahoo, or another provider. Choose one from the list of the providers (click on 'More providers' if you don't see your provider there). Click on the provider logo, you will be redirected to the account login page. Submit your username/password there to login to your Ecwid.

    Note: the login might take several seconds. Please, be patient.

  • Look at the right bottom corner of the page.
  • You will see the "Store ID: NNNNNN" text, where NNNNNN is your Store ID.

    For example if the text is Store ID: 1003, your Store ID is 1003.  


    You will also get your Store ID by email.

If you have any questions, feel free to ask them on Ecwid forums or contact Ecwid team.

Go to the Ecwid Control Panel

Ecwid Knowledge Base | Ecwid Forums"; } function ecwid_add_dashboard_widgets() { if (current_user_can('administrator')) { wp_add_dashboard_widget('ecwid_dashboard_widget','Ecwid Links', 'ecwid_dashboard_widget_function'); } } class EcwidMinicartWidget extends WP_Widget { function EcwidMinicartWidget() { $widget_ops = array('classname' => 'widget_ecwid_minicart', 'description' => __( "Your store's minicart") ); $this->WP_Widget('ecwidminicart', __('Ecwid Shopping Bag (Normal)'), $widget_ops); } function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title']); echo $before_widget; if ( $title ) echo $before_title . $title . $after_title; $store_id = get_ecwid_store_id(); $ecwid_protocol = get_ecwid_protocol(); echo '
'; echo ecwid_get_scriptjs_code(); //echo "
"; $ecwid_page_id = get_option("ecwid_store_page_id"); $page_url = get_page_link($ecwid_page_id); $_tmp_page = get_page($ecwid_page_id); if (!empty($page_url) && $_tmp_page != null) echo ""; echo << xMinicart("style=");
EOT; echo $after_widget; } function update($new_instance, $old_instance){ $instance = $old_instance; $instance['title'] = strip_tags(stripslashes($new_instance['title'])); return $instance; } function form($instance){ $instance = wp_parse_args( (array) $instance, array('title'=>'') ); $title = htmlspecialchars($instance['title']); echo '

'; } } class EcwidMinicartMiniViewWidget extends WP_Widget { function EcwidMinicartMiniViewWidget() { $widget_ops = array('classname' => 'widget_ecwid_minicart_miniview', 'description' => __( "Your store's minicart") ); $this->WP_Widget('ecwidminicart_miniview', __('Ecwid Shopping Bag (Mini view)'), $widget_ops); } function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title']); echo $before_widget; if ( $title ) echo $before_title . $title . $after_title; $store_id = get_ecwid_store_id(); $ecwid_protocol = get_ecwid_protocol(); echo '
'; echo ecwid_get_scriptjs_code(); //echo "
"; $ecwid_page_id = get_option("ecwid_store_page_id"); $page_url = get_page_link($ecwid_page_id); $_tmp_page = get_page($ecwid_page_id); if (!empty($page_url) && $_tmp_page != null) echo ""; echo << xMinicart("style=left:10px","layout=Mini");
EOT; echo $after_widget; } function update($new_instance, $old_instance){ $instance = $old_instance; $instance['title'] = strip_tags(stripslashes($new_instance['title'])); return $instance; } function form($instance){ $instance = wp_parse_args( (array) $instance, array('title'=>'') ); $title = htmlspecialchars($instance['title']); echo '

'; } } class EcwidSearchWidget extends WP_Widget { function EcwidSearchWidget() { $widget_ops = array('classname' => 'widget_ecwid_search', 'description' => __( "Your store's search box") ); $this->WP_Widget('ecwidsearch', __('Ecwid Search Box'), $widget_ops); } function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title']); echo $before_widget; if ( $title ) echo $before_title . $title . $after_title; $store_id = get_ecwid_store_id(); $ecwid_protocol = get_ecwid_protocol(); echo '
'; echo ecwid_get_scriptjs_code(); //echo "
"; $ecwid_page_id = get_option("ecwid_store_page_id"); $page_url = get_page_link($ecwid_page_id); $_tmp_page = get_page($ecwid_page_id); if (!empty($page_url) && $_tmp_page != null) echo ""; echo << xSearchPanel("style=");
EOT; echo $after_widget; } function update($new_instance, $old_instance){ $instance = $old_instance; $instance['title'] = strip_tags(stripslashes($new_instance['title'])); return $instance; } function form($instance){ $instance = wp_parse_args( (array) $instance, array('title'=>'') ); $title = htmlspecialchars($instance['title']); echo '

'; } } class EcwidVCategoriesWidget extends WP_Widget { function EcwidVCategoriesWidget() { $widget_ops = array('classname' => 'widget_ecwid_vcategories', 'description' => __( "Vertical menu of categories") ); $this->WP_Widget('ecwidvcategories', __('Ecwid Vertical Categories'), $widget_ops); } function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title']); echo $before_widget; if ( $title ) echo $before_title . $title . $after_title; $store_id = get_ecwid_store_id(); $ecwid_protocol = get_ecwid_protocol(); echo '
'; echo ecwid_get_scriptjs_code(); // echo "
"; $ecwid_page_id = get_option("ecwid_store_page_id"); $page_url = get_page_link($ecwid_page_id); $_tmp_page = get_page($ecwid_page_id); if (!empty($page_url) && $_tmp_page != null) echo ""; echo << xVCategories("style=");
EOT; echo $after_widget; } function update($new_instance, $old_instance){ $instance = $old_instance; $instance['title'] = strip_tags(stripslashes($new_instance['title'])); return $instance; } function form($instance){ $instance = wp_parse_args( (array) $instance, array('title'=>'') ); $title = htmlspecialchars($instance['title']); echo '

'; } } function ecwid_sidebar_widgets_init() { register_widget('EcwidMinicartWidget'); register_widget('EcwidSearchWidget'); register_widget('EcwidVCategoriesWidget'); register_widget('EcwidMinicartMiniViewWidget'); } add_action('widgets_init', 'ecwid_sidebar_widgets_init'); function ecwid_encode_json($data) { if(version_compare(PHP_VERSION,"5.2.0",">=")) { return json_encode($data); } else { include_once(ABSPATH . 'wp-content/plugins/ecwid-shopping-cart/lib/JSON.php'); $json_parser = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); return $json_parser->encode($data); } } function ecwid_sso() { $key = get_option('ecwid_sso_secret_key'); if (empty($key)) { return ""; } global $current_user; get_currentuserinfo(); if ($current_user->ID) { $user_data = array( 'appId' => "wp_" . get_ecwid_store_id(), 'userId' => "{$current_user->ID}", 'profile' => array( 'email' => $current_user->user_email, 'billingPerson' => array( 'name' => $current_user->display_name ) ) ); $user_data = base64_encode(ecwid_encode_json($user_data)); $time = time(); $hmac = ecwid_hmacsha1("$user_data $time", $key); return ""; } else { return ""; } } // from: http://www.php.net/manual/en/function.sha1.php#39492 function ecwid_hmacsha1($data, $key) { if (function_exists("hash_hmac")) { return hash_hmac('sha1', $data, $key); } else { $blocksize=64; $hashfunc='sha1'; if (strlen($key)>$blocksize) $key=pack('H*', $hashfunc($key)); $key=str_pad($key,$blocksize,chr(0x00)); $ipad=str_repeat(chr(0x36),$blocksize); $opad=str_repeat(chr(0x5c),$blocksize); $hmac = pack( 'H*',$hashfunc( ($key^$opad).pack( 'H*',$hashfunc( ($key^$ipad).$data ) ) ) ); return bin2hex($hmac); } } function ecwid_is_api_enabled() { $ecwid_is_api_enabled = get_option('ecwid_is_api_enabled'); $ecwid_api_check_time = get_option('ecwid_api_check_time'); $now = time(); if ($now > ($ecwid_api_check_time + 60 * 60 * 3)) { // check whether API is available once in 3 hours $ecwid = ecwid_new_product_api(); $ecwid_is_api_enabled = ($ecwid->is_api_enabled() ? 'on' : 'off'); update_option('ecwid_is_api_enabled', $ecwid_is_api_enabled); update_option('ecwid_api_check_time', $now); } if ('on' == $ecwid_is_api_enabled) return true; else return false; } function ecwid_new_product_api() { include_once WP_PLUGIN_DIR . '/ecwid-shopping-cart/lib/ecwid_product_api.php'; $ecwid_store_id = intval(get_ecwid_store_id()); $api = new EcwidProductApi($ecwid_store_id); return $api; } ?>