Changeset 1801403
- Timestamp:
- 01/11/2018 10:07:36 PM (8 years ago)
- Location:
- knowledge-tags-from-yext/trunk
- Files:
-
- 2 deleted
- 2 edited
-
format.php (deleted)
-
settings.php (modified) (2 diffs)
-
tests (deleted)
-
yext-schema.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
knowledge-tags-from-yext/trunk/settings.php
r1730703 r1801403 96 96 if (gettype($location_error)=="string") { 97 97 ?> 98 <p class="error"><?php esc_html_e("ERROR: ". $location_error, 'KTFY-yext-schema'); ?></p>98 <pre class="error"><?php esc_html_e("ERROR: ". $location_error, 'KTFY-yext-schema'); ?></pre> 99 99 <?php 100 100 } 101 101 if (gettype($schema_error)=="string") { 102 102 ?> 103 <p class="error"><?php esc_html_e("ERROR: ". $schema_error, 'KTFY-yext-schema'); ?></p>103 <pre class="error"><?php esc_html_e("ERROR: ". $schema_error, 'KTFY-yext-schema'); ?></pre> 104 104 <?php 105 105 } … … 133 133 <p id="<?php echo esc_attr($args['id']); ?>"><?php esc_html_e('[yext-data yext-location-id=1001 yext-field=locationName]', 'KTFY_yext_schema_shortcodes'); ?></p> 134 134 <?php 135 $host = KTFY_get_yext_host_name(); 136 $supported_field_url = sprintf("%s/supportedfields", $host); 135 137 $account_options = get_option('KTFY_yext_sub_account_options'); 136 $fields = array( 137 "locationName" =>array("locationName", "Name of your yext location", "Business Name"), 138 "logo.url" =>array("logo.url", "Image corresponding to your Yext Location", "Logo"), 139 "id" =>array("id", "Store ID", "Store ID"), 140 "description" =>array("description", "Business Description", "Business Description"), 141 "email" =>array("email", "Email Address", "Contact Email"), 142 "address1" =>array("address1", "Street Address", "Business Address"), 143 "address2" =>array("address2", "Floor, Suite, Unit", "Business Floor, Suite, Unit"), 144 "city" =>array("city", "City/Locality", "Business City"), 145 "state" =>array("state", "Region", "Business State"), 146 "zip" =>array("zip", "Postal Code", "Business Postal Code"), 147 "countryCode" =>array("countryCode", "Country", "Business Country"), 148 "phone" =>array("phone", "Phone number for location", "Business Phone"), 149 "paymentOptions" =>array("paymentOptions", "The payment options for the location", "Payment Methods, comma-separated"), 150 "hours" =>array("hours", "Hours of Operation, for all days", "Business Hours"), 151 "hours-monday" =>array("hours-monday", "Hours of operation for Monday", ""), 152 "hours-tuesday" =>array("hours-tuesday", "Hours of operation for Tuesday", ""), 153 "hours-wednesday" =>array("hours-wednesday", "Hours of operation for Wednesday", ""), 154 "hours-thursday" =>array("hours-thursday", "Hours of operation for Thursday", ""), 155 "hours-friday" =>array("hours-friday", "Hours of operation for Friday", ""), 156 "hours-saturday" =>array("hours-saturday", "Hours of operation for Saturday", ""), 157 "hours-sunday" =>array("hours-sunday", "Hours of operation for Sunday", ""), 158 "get-directions-link" =>array("get-directions-link", "The link for a given location", "Get Directions"), 159 ); ?> 138 $supported_fields = @file_get_contents($supported_field_url); 139 $KTFY_knowlege_tag_supported_fields = json_decode($supported_fields); 140 $fields = array(); 141 foreach ($KTFY_knowlege_tag_supported_fields as $key => $value) { 142 $fields[$key] = $value; 143 } 144 ?> 145 160 146 <p class=""> 161 147 <?php esc_html_e('Accepted Shortcode Fields', 'KTFY_yext_schema_shortcodes'); ?> -
knowledge-tags-from-yext/trunk/yext-schema.php
r1730703 r1801403 12 12 */ 13 13 include "settings.php"; 14 include "format.php";15 14 global $KTFY_page_location_Ids; 16 15 $KTFY_page_location_Ids=array(); 17 18 19 // fomatting location data to accepted knowledge tags20 function KTFY_schema_formater($locId, $loc_data)21 {22 global $KTFY_knowlege_tag_data;23 $loc_data = $loc_data->{"response"};24 $KTFY_knowlege_tag_data = new StdClass;25 $KTFY_knowlege_tag_data->{$locId} = new StdClass;26 $hours = $loc_data->{"hours"};27 $KTFY_knowlege_tag_data->{$locId}->{"locationName"} = $loc_data->{"locationName"};28 $KTFY_knowlege_tag_data->{$locId}->{"id"} = $loc_data->{"id"};29 $KTFY_knowlege_tag_data->{$locId}->{"description"} = $loc_data->{"description"};30 $KTFY_knowlege_tag_data->{$locId}->{"email"} = KTFY_get_email_format($loc_data->{"emails"});31 $KTFY_knowlege_tag_data->{$locId}->{"address1"} = $loc_data->{"address"};32 $KTFY_knowlege_tag_data->{$locId}->{"address2"} = $loc_data->{"address2"};33 $KTFY_knowlege_tag_data->{$locId}->{"city"} = $loc_data->{"city"};34 $KTFY_knowlege_tag_data->{$locId}->{"state"} = $loc_data->{"state"};35 $KTFY_knowlege_tag_data->{$locId}->{"zip"} = $loc_data->{"zip"};36 $KTFY_knowlege_tag_data->{$locId}->{"countryCode"} = $loc_data->{"countryCode"};37 $KTFY_knowlege_tag_data->{$locId}->{"phone"} = $loc_data->{"phone"};38 $KTFY_knowlege_tag_data->{$locId}->{"hours"} = KTFY_get_hours_format($hours);39 $KTFY_knowlege_tag_data->{$locId}->{"hours-monday"} = KTFY_get_hours_weekday_format(2, $hours);40 $KTFY_knowlege_tag_data->{$locId}->{"hours-tuesday"} = KTFY_get_hours_weekday_format(3, $hours);41 $KTFY_knowlege_tag_data->{$locId}->{"hours-wednesday"} = KTFY_get_hours_weekday_format(4, $hours);42 $KTFY_knowlege_tag_data->{$locId}->{"hours-thursday"} = KTFY_get_hours_weekday_format(5, $hours);43 $KTFY_knowlege_tag_data->{$locId}->{"hours-friday"} = KTFY_get_hours_weekday_format(6, $hours);44 $KTFY_knowlege_tag_data->{$locId}->{"hours-saturday"} = KTFY_get_hours_weekday_format(7, $hours);45 $KTFY_knowlege_tag_data->{$locId}->{"hours-sunday"} = KTFY_get_hours_weekday_format(1, $hours);46 $KTFY_knowlege_tag_data->{$locId}->{"paymentOptions"} = KTFY_get_payment_options_format($loc_data->{"paymentOptions"});47 $KTFY_knowlege_tag_data->{$locId}->{"logo.url"} = KTFY_get_logo_url_format($loc_data->{"logo"});48 $KTFY_knowlege_tag_data->{$locId}->{"get-directions-link"} = KTFY_get_get_directions_link_format($loc_data);49 }50 16 51 17 /** … … 64 30 $KTFY_page_location_Ids = $locationIds; 65 31 $KTFY_yext_schema_data = new StdClass; 32 $KTFY_knowlege_tag_data = new StdClass; 33 delete_option('KTFY_yext_location_error_option'); 34 66 35 if (is_null($account_Id) || $account_Id == ""){ 67 36 $account_Id = "me"; … … 72 41 if (!is_null($locationId) && !is_null($apikey) && !is_null($account_Id)) { 73 42 $locationId = trim($locationId); 74 // get schema data 75 $schema_data= KTFY_get_schema_data($apikey, $account_Id, $locationId); 76 if ($schema_data) { 77 $KTFY_yext_schema_data->{$locationId} = $schema_data; 78 } 79 //get location data 80 $loc_data = KTFY_get_location_data($apikey, $account_Id, $locationId); 81 if ($loc_data) { 82 KTFY_schema_formater($locationId, $loc_data); 83 $loc_data->{$locationId} = $loc_data; 43 $KTFY_knowlege_tag_data->{$locationId} = new StdClass; 44 $data = KTFY_get_yext_data($apikey, $account_Id, $locationId); 45 if ($data) { 46 $KTFY_yext_schema_data->{$locationId} = $data->{"locations"}[0]->{"schema"}; 47 $KTFY_knowlege_tag_data->{$locationId} = $data->{"locations"}[0]->{"location"}; 84 48 } 85 49 } … … 88 52 } 89 53 90 91 // querying for schema data 92 function KTFY_get_schema_data($apiKey, $account_Id, $locationId) 54 // querying for data 55 function KTFY_get_yext_data($apiKey, $account_Id, $locationId) 93 56 { 94 $ date = date("Ymd");95 $schema_url = sprintf("%s/ v2/accounts/%s/locations/%s/schema?api_key=%s&v=%s", KTFY_get_yext_api_host(), $account_Id, $locationId, $apiKey, $date);57 $host = KTFY_get_yext_host_name(); 58 $schema_url = sprintf("%s/jsondata?account_id=%s&location_id=%s&key=%s", $host, urlencode($account_Id), urlencode($locationId), urlencode($apiKey)); 96 59 $schema_data = @file_get_contents($schema_url); 97 60 if (!$schema_data){ … … 103 66 } 104 67 105 // querying for location data 106 function KTFY_get_location_data($apiKey, $account_Id, $locationId) 107 { 108 $date = date("Ymd"); 109 $location_url = sprintf("%s/v2/accounts/%s/locations/%s?api_key=%s&v=%s", KTFY_get_yext_api_host(), $account_Id, $locationId, $apiKey, $date); 110 $KTFY_knowlege_tag_data = @file_get_contents($location_url); 111 if (!$KTFY_knowlege_tag_data){ 112 //display error here 113 echo "<h3 style='color:red;'> ERROR: Unable to retrieve Location Data - Please check your plugin configuration and your server's network configuration. If this issue persists please contact the plugin authors and/or your network admin.</h3>"; 114 115 } 116 $KTFY_knowlege_tag_data = json_decode($KTFY_knowlege_tag_data); 117 return $KTFY_knowlege_tag_data; 118 } 119 120 function KTFY_get_yext_api_host() 121 { 122 return "https://liveapi.yext.com"; 68 function KTFY_get_yext_host_name(){ 69 if ( $_SERVER["HTTP_HOST"] === '192.168.99.100:8080' ){ 70 // testing url 71 return "http://10.254.254.254:9090"; 72 } 73 // live url 74 return "https://knowledgetags.yextpages.net"; 123 75 } 124 76 … … 133 85 if (is_null($KTFY_knowlege_tag_data)) { 134 86 add_option('KTFY_yext_location_error_option', 'Location Data is Empty'); 135 } else{136 delete_option('KTFY_yext_location_error_option');137 87 } 138 $response = @$KTFY_knowlege_tag_data->{$locationId}->{$field_name}; 88 if (array_key_exists($field_name, $KTFY_knowlege_tag_data->{$locationId})){ 89 $response = @$KTFY_knowlege_tag_data->{$locationId}->{$field_name}; 90 } else { 91 $option_value = get_option('KTFY_yext_location_error_option'); 92 update_option('KTFY_yext_location_error_option', $option_value."\n". "\"".$field_name . '" is not present in this location, please double check if this field is still supported.'); 93 } 94 139 95 return $response; 140 96 } … … 149 105 echo '<script type="application/ld+json">'."\r\n"; 150 106 foreach ($KTFY_page_location_Ids as $locationId) { 151 $ld_json = @json_encode($KTFY_yext_schema_data->{$locationId} ->{"response"}, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);107 $ld_json = @json_encode($KTFY_yext_schema_data->{$locationId}, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); 152 108 // only write to html if we have data 153 109 if (!is_null($ld_json) && $ld_json !="null") { … … 157 113 echo "\r\n".'</script>'; 158 114 delete_option('KTFY_yext_schema_error_option'); 159 } else {160 add_option('KTFY_yext_schema_error_option', 'Schema Data is Empty ');115 } elseif (is_null($KTFY_yext_schema_data) && !is_null($KTFY_page_location_Ids)) { 116 add_option('KTFY_yext_schema_error_option', 'Schema Data is Empty for '+ get_the_title()); 161 117 } 162 118 }
Note: See TracChangeset
for help on using the changeset viewer.