Thread: AutoOpenGraph?

Page 1 of 2 12 LastLast
Results 1 to 10 of 18
  1. #1
    Join Date
    Jan 2004
    Posts
    144
    Plugin Contributions
    0

    Default AutoOpenGraph?

    Can anyone help with this AutoOpenGraph code that seems to appear in a few add ons? It appears to be the main part of the AutoFacebook OG add on, but while searching for help, I've found it referenced elsewhere, as well.

    I'd like a simple way to get OpenGraph working on my site. This code might just work, except that, well, the main reason I'd like to install it is to get the appropriate product image to show up when someone decides to share a product URL to Facebook.

    FB's Open Graph Object Debugger scrapes the product info well enough, but, unfortunately my main product image is too small for it. It wants a minimum 200px x 200px.

    So, the AutoOpenGraph code that does this appears to be:
    //get defined image or default
    $myImage= zen_get_products_image((int)$_GET['products_id']);
    $img = simplexml_load_string($myImage);
    $img = $img['src'];

    It looks to me like it's pulling the main image. Is there code that can be swapped in so that it would return the product image from the "large" images subdirectory? That might solve my problem.

    Thanks!

  2. #2
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: AutoOpenGraph?

    So, one way to figure this out is to take a look at the code that returns the variable $myimage. If you goto http://www.zen-cart.com/docs/phpdoc-1-5-0/ you can navigate to the function and see how it builds the variable. If not mistaken it is an array, and sou would want to then modify the path of the image to obtain the large image path and possibly other characteristics of the image that are stored in the variable...

    Also, could look at how the image informationis built in the tpl_product_info.php file and the header leading to it.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: AutoOpenGraph?

    Just thought of this: (slow tonight), if uused Image Handler (version 4), the default image is the largest image and would be the ideal situation for you... No modification should be necessary... (I think).
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  4. #4
    Join Date
    Jan 2004
    Posts
    144
    Plugin Contributions
    0

    Default Re: AutoOpenGraph?

    I am indeed using Image Handler, but the code above is returning the main image, which is 120x156.

    The main image, which the OG debugger finds, is images/subfolder/cover.jpg

    I suspect it would prefer the large image at images/large/subfolder/cover_LRG.jpg

    Thanks for the pointer to the phpdoc. I will investigate

  5. #5
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: AutoOpenGraph?

    Only done a cursory inspection, but it somewhat looks like you would want to change the call to a zen_image call instead of a zen_get_products_image call...

    May require a little bit more upfront work similar to what is done in includes/modules/YOUR_TEMPLATE/main_product_image.php (modified by IH4) in obtaining the path to the products_image_large file... Once that path is designated, the response from zen_image should provide the image for the large version. Otherwise, the way it seems to read is that the small image will be returned as written above. Otherwise could provide dimensions to try to get a larger image, but I don't think that will provide the result(s) needed by the receiving application.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  6. #6
    Join Date
    Jan 2004
    Posts
    144
    Plugin Contributions
    0

    Default Re: AutoOpenGraph?

    That's help! Thanks. I tried something with no luck. Looked in my debug logs and found these two lines just above the $myImage content:

    extract($product_info_metatags->fields);
    extract($category_metatags->fields);

    were kicking back "extract() expects parameter 1 to be array, null given "

    Maybe this was the problem all along

  7. #7
    Join Date
    Jan 2004
    Posts
    144
    Plugin Contributions
    0

    Default Re: AutoOpenGraph?

    Here's the as it stand in MY_TEMPLATE/common/html_header.php

    ################ start of AutoOpenGraph ###################

    $og_store_name = "NAME"; //e.g. "Samanthas Power Tools", or "Gus' China Shop".
    $og_store_url = "SITE"; //url to your store (no trailing '/')
    $og_product_type = "product"; //type of product you're selling (see tutorial)
    $og_use_addr = 0; //use address? if yes, set $use_addr = 1; (no quotes). edit lines 31-34.
    $og_use_email = 0; //use email address? if yes, set $use_email = 1; (no quotes) edit line 37.
    $og_use_phone = 0; //use phone number? if yes, set $use_phone = 1; (no quotes) edit line 40.

    //if $use_addr is set to 1;
    $og_street = "123 Main St"; //change to your street address.
    $og_city = "Richmond"; //your city
    $og_state = "VA"; //Your State. Facebook exaple uses abbreviation.
    $og_zip = "23220"; //you're zip/postal code.
    $og_country = "USA"; //your country. Facebook example uses acronym.

    //if $use_email is set to 1;
    $og_email_address = "[email protected]"; // your email

    //if use_phone is set to 1
    $og_phone_number = "+1-800-555-1234"; //format: +country code - area code - number.

    //no need to edit below this line:
    extract($product_info_metatags->fields);
    extract($category_metatags->fields);
    $og_prod_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

    //get defined image or default
    //$myImage = zen_get_products_image((int)$_GET['products_id']);

    $myImage = DIR_WS_IMAGES . 'large/' . $products_image_base . IMAGE_SUFFIX_LARGE . $products_image_extension;



    $img = simplexml_load_string($myImage);
    $img = $img['src'];
    if($this_is_home_page){ $depends = $store_name; $product_type = "website"; }
    else if ($categories_name){ $depends = $categories_name; $product_type = "website"; }
    else if ($products_name){ $depends = $products_name; }
    else { $depends = META_TAG_TITLE; $product_type = "website"; }
    //print_r($product_info_metatags);
    ################# end of AutoOpenGraph ####################

  8. #8
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: AutoOpenGraph?

    Quote Originally Posted by Randolph Hoppe View Post
    Here's the as it stand in MY_TEMPLATE/common/html_header.php

    Code:
    ################ start of AutoOpenGraph ###################
     
    $og_store_name = "NAME"; //e.g. "Samanthas Power Tools", or "Gus' China Shop".
    $og_store_url = "SITE"; //url to your store (no trailing '/')
    $og_product_type = "product"; //type of product you're selling (see tutorial)
    $og_use_addr = 0; //use address? if yes, set $use_addr = 1; (no quotes). edit lines 31-34.
    $og_use_email = 0; //use email address? if yes, set $use_email = 1; (no quotes) edit line 37.
    $og_use_phone = 0; //use phone number? if yes, set $use_phone = 1; (no quotes) edit line 40.
     
    //if $use_addr is set to 1;
    $og_street = "123 Main St";  //change to your street address.
    $og_city = "Richmond"; //your city
    $og_state = "VA"; //Your State. Facebook exaple uses abbreviation.
    $og_zip = "23220"; //you're zip/postal code.
    $og_country = "USA"; //your country. Facebook example uses acronym.
     
    //if $use_email is set to 1;
    $og_email_address = "[email protected]"; // your email
     
    //if use_phone is set to 1
    $og_phone_number = "+1-800-555-1234"; //format: +country code - area code - number.
     
    //no need to edit below this line:
    extract($product_info_metatags->fields);
    extract($category_metatags->fields);
    $og_prod_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     
    //get defined image or default
    //$myImage = zen_get_products_image((int)$_GET['products_id']);
    
    $myImage = DIR_WS_IMAGES . 'large/' . $products_image_base . IMAGE_SUFFIX_LARGE .  $products_image_extension;
    
    
    
    $img = simplexml_load_string($myImage);
    $img = $img['src'];
    if($this_is_home_page){ $depends = $store_name; $product_type = "website"; }
    else if ($categories_name){  $depends = $categories_name; $product_type = "website";  }
    else if ($products_name){ $depends = $products_name; }
    else { $depends = META_TAG_TITLE; $product_type = "website"; }
    //print_r($product_info_metatags);
    ################# end of AutoOpenGraph ####################
    So me this still does not work. A couple of things, one is that the variable product_image_base would not be defined unless on the product page. This causes the variable result to be an image name made up primarily on the constants. Further, the function that process $myimage parses the string looking for src and the content that follows... The current code does not generate aa similar html output, so really the next two steps can be omitted as well and $myImage simply changed to $img.

    As to the issue with the metatags, I'm thinking that the logged info, which was not provided in full, is that this is a warning not an error... That section of code could be prefaced with something like:

    Code:
    if (is_array($product_info_metatags->fields)) {
      extract($product_info_metatags->fields);
    }
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  9. #9
    Join Date
    Jan 2004
    Posts
    144
    Plugin Contributions
    0

    Default Re: AutoOpenGraph?

    $myImage = DIR_WS_IMAGES . 'large/' . $products_image_base . IMAGE_SUFFIX_LARGE . $products_image_extension;


    The above did not work.

  10. #10
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: AutoOpenGraph?

    Okay, regroup on thoughts.

    Because IH4 I being used, the actual file doesn't exist as identified in that assignment. The real filename (rewritten by the image handler) needs to be obtained through the use of zen_image with the source being $myImage and whatever additional attributes/information is needed/desired.

    Then the response wouldneed to be processed like it is in the above code to determine the value of the key src.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 
Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg