Changeset 1228038
- Timestamp:
- 08/22/2015 01:44:14 PM (10 years ago)
- Location:
- local-geo-search/trunk
- Files:
-
- 13 added
- 6 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
local-geo-search/trunk/admin/admin.geoseo.php
r1192182 r1228038 24 24 public function add_plugin_page() 25 25 { 26 add_menu_page( 'Local Geo Search', 'Local Geo Search', 'manage_options', 'geo_seo_admin', array( $this, 'create_admin_page' ), plugins_url( 'geoseo/images/icon.png' ), 6 );26 add_menu_page( 'Local Geo Search', 'Local Geo Search', 'manage_options', 'geo_seo_admin', array( $this, 'create_admin_page' ), 'dashicons-location', 6 ); 27 27 28 28 // This page will be under "Settings" … … 81 81 add_settings_section( 82 82 'geo_seo_login_section', // ID 83 ' 1) Log In', // Title84 array( $this, ' section_callback' ), // Callback83 'Authenticate with website token', // Title 84 array( $this, 'geo_seo_login_section' ), // Callback 85 85 'geo_seo_admin' // Page 86 86 ); 87 87 88 88 add_settings_field( 89 'username', // ID 90 'Username', // Title 91 array( $this, 'field_username_callback' ), // Callback 92 'geo_seo_admin', // Page 93 'geo_seo_login_section' // Section 94 ); 95 96 add_settings_field( 97 'password', 98 'Password', 99 array( $this, 'field_password_callback' ), 100 'geo_seo_admin', 101 'geo_seo_login_section' 102 ); 103 104 105 add_settings_section( 106 'geo_seo_website_section', // ID 107 '2) Choose Website', // Title 108 array( $this, 'section_callback' ), // Callback 109 'geo_seo_admin' // Page 110 ); 111 112 add_settings_field( 113 'organization', // ID 114 'Organization', // Title 115 array( $this, 'field_organization_callback' ), // Callback 116 'geo_seo_admin', // Page 117 'geo_seo_website_section' // Section 118 ); 119 120 add_settings_field( 121 'website', // ID 122 'Website', // Title 123 array( $this, 'field_website_callback' ), // Callback 124 'geo_seo_admin', // Page 125 'geo_seo_website_section' // Section 89 'token', 90 'Token', 91 array( $this, 'field_token_callback' ), 92 'geo_seo_admin', 93 'geo_seo_login_section' 94 ); 95 add_settings_field( 96 'websiteName', 97 '', 98 array( $this, 'field_websiteName_callback' ), 99 'geo_seo_admin', 100 'geo_seo_login_section' 101 ); 102 add_settings_field( 103 'websiteID', 104 '', 105 array( $this, 'field_websiteID_callback' ), 106 'geo_seo_admin', 107 'geo_seo_login_section' 108 ); 109 add_settings_field( 110 'orgID', 111 '', 112 array( $this, 'field_orgID_callback' ), 113 'geo_seo_admin', 114 'geo_seo_login_section' 126 115 ); 127 116 … … 129 118 add_settings_section( 130 119 'geo_seo_plugin_section', // ID 131 ' 3)Plugin Options', // Title120 'Plugin Options', // Title 132 121 array( $this, 'section_plugin_callback' ), // Callback 133 122 'geo_seo_admin' // Page … … 157 146 158 147 $apiURL = geo_seo_getData('api'); 148 $data = geo_seo_getData(); 159 149 160 150 $params = array( 161 'url'=>$apiURL.'/authentication', 151 'url'=>$apiURL.'/pluginhtml/auth', 152 'fields' => [ 153 'url' => $data['host'], 154 'slug' => $data['slug'] 155 ], 162 156 'authentication'=>array( 163 157 'basic' => true, 164 'user' => $input['username'],165 'password' =>$input['password']158 'user' => 'api', 159 'password' => $input['token'] 166 160 ) 167 161 ); … … 170 164 171 165 if($user['status']=='OK') { 172 $input['organization'] = $user['data']['org_id']; 173 if(!isset($input['website']) || $input['website']=='') { 174 add_settings_error( 175 'geo_seo_error', 176 'login-msg', 177 __('Authenticated successfully. Choose website.'), 178 'updated' 179 ); 180 } 181 else { 182 $this->options = get_option( 'geo_seo_option_name' ); 183 $url = get_site_url().'/'.$this->options['slug']; 184 add_settings_error( 185 'geo_seo_error', 186 'login-msg', 187 __('Successfully saved. Local GEO Search pages are now available at <a href="'.$url.'">'.$url.'</a>'), 188 'updated' 189 ); 190 } 191 192 } 193 else { 194 $input['organization'] = 0; 195 $input['website'] = 0; 166 167 delete_option( 'geo_seo_error' ); 168 169 $input['websiteName'] = $user['data']['website']['name']; 170 $input['websiteID'] = $user['data']['website']['id']; 171 $input['orgID'] = $user['data']['website']['org_id']; 172 196 173 add_settings_error( 197 174 'geo_seo_error', 198 175 'login-msg', 199 __('Incorrect username or password'), 176 __('Authenticated successfully with Local GEO Search website '.$user['data']['website']['name']), 177 'updated' 178 ); 179 180 } 181 else { 182 $input['websiteName'] = null; 183 $input['websiteID'] = null; 184 $input['orgID'] = null; 185 186 add_settings_error( 187 'geo_seo_error', 188 'login-msg', 189 __($user['data']['msg']), 200 190 'error' 201 191 ); 202 192 } 203 193 194 if($data['slug']!=$input['slug']) { 195 geo_seo_cacheSys::put('previousslug', $data['slug'], $data['slug']); 196 geo_seo_cacheSys::deleteCachedItem('sitemap', 'sitemapjson'); 197 } 198 199 204 200 return $input; 205 201 } … … 218 214 } 219 215 216 public function geo_seo_login_section() 217 { 218 $data = geo_seo_getData(); 219 220 $errorMessage = get_option( 'geo_seo_error' ); 221 222 if(isset($data['website']) && $data['website']!=null) { 223 if($errorMessage!==false) { 224 print '<div style="font-weight:bold;color:red;">This is a problem that prevented a user from seeing a Local GEO Search page: '.$errorMessage.'</div>'; 225 } 226 else { 227 print '<div style="font-weight:bold; color:#7ad03a;">Successfully authenticated with Local GEO Search website '.$data['websiteName'].'</div>'; 228 } 229 } 230 else { 231 print '<div style="font-weight:bold;color:red;">Your plugin isn\'t authenticated yet. Enter the Local GEO Search website token and click Save.</div>'; 232 } 233 234 235 236 } 220 237 221 238 /** 222 239 * Get the settings option array and print one of its values 223 240 */ 224 public function field_ username_callback()241 public function field_token_callback() 225 242 { 226 243 printf( 227 '<input type="text" id="username" name="geo_seo_option_name[username]" value="%s" />', 228 isset( $this->options['username'] ) ? esc_attr( $this->options['username']) : '' 229 ); 230 } 231 232 /** 233 * Get the settings option array and print one of its values 234 */ 235 public function field_password_callback() 236 { 237 printf( 238 '<input type="password" id="password" name="geo_seo_option_name[password]" value="%s" />', 239 isset( $this->options['password'] ) ? esc_attr( $this->options['password']) : '' 244 '<input type="token" id="token" name="geo_seo_option_name[token]" value="%s" />', 245 isset( $this->options['token'] ) ? esc_attr( $this->options['token']) : '' 240 246 ); 241 247 } … … 252 258 } 253 259 254 /** 255 * Get the settings option array and print one of its values 256 */ 257 public function field_website_callback() 258 { 259 if($this->options['username']!='') { 260 261 $apiURL = geo_seo_getData('api'); 262 263 $select = '<select id="website" name="geo_seo_option_name[website]"><option value="">Select site</option>'; 264 265 $organization = json_decode(geo_seo_easyCurl(array( 'url'=>$apiURL.'/organization/get/'.$this->options['organization'] )),true); 266 267 268 foreach($organization['data']['websites'] as $site) { 269 $selected = ''; 270 if($this->options['website']==$site['id']) { 271 $selected= 'selected="selected"'; 272 } 273 $select .= '<option value="'.$site['id'].'" '.$selected.'>'.$site['name'].' - '.$site['url'].'</option>'; 274 } 275 $select .= '</select>'; 276 277 echo $select; 278 } 279 else { 280 echo 'Log in for list of your websites.'; 281 } 282 } 283 284 /** 285 * Get the settings option array and print one of its values 286 */ 287 public function field_organization_callback() 288 { 289 290 if($this->options['username']!='') { 291 292 $apiURL = geo_seo_getData('api'); 293 294 $organization = json_decode(geo_seo_easyCurl(array( 'url'=>$apiURL.'/organization/get/'.$this->options['organization'] )),true); 295 296 printf( 297 '<input type="hidden" id="organization" name="geo_seo_option_name[organization]" value="%s" /> '.$organization['data']['name'], 298 isset( $this->options['organization'] ) ? esc_attr( $this->options['organization']) : '' 299 ); 300 } 301 else { 302 echo 'Log in for your organization.'; 303 } 304 305 } 260 public function field_websiteName_callback() { 261 printf( 262 '<input type="hidden" id="websiteName" name="geo_seo_option_name[websiteName]" value="%s" />', 263 isset( $this->options['websiteName'] ) ? esc_attr( $this->options['websiteName']) : '' 264 ); 265 } 266 267 public function field_websiteID_callback() { 268 printf( 269 '<input type="hidden" id="websiteID" name="geo_seo_option_name[websiteID]" value="%s" />', 270 isset( $this->options['websiteID'] ) ? esc_attr( $this->options['websiteID']) : '' 271 ); 272 } 273 274 public function field_orgID_callback() { 275 printf( 276 '<input type="hidden" id="orgID" name="geo_seo_option_name[orgID]" value="%s" />', 277 isset( $this->options['orgID'] ) ? esc_attr( $this->options['orgID']) : '' 278 ); 279 } 280 281 306 282 } 307 283 } -
local-geo-search/trunk/classes/class.virtualpage.php
r1192182 r1228038 1 1 <?php 2 2 3 if (!class_exists('GEOSEOVirtualPage')) 4 { 5 class GEOSEOVirtualPage 6 { 7 private $slug = NULL; 8 private $url = NULL; 9 private $title = NULL; 10 private $content = NULL; 11 private $author = NULL; 12 private $date = NULL; 13 private $type = NULL; 14 15 public function __construct($args) 16 { 17 18 $this->slug = $args['slug']; 19 $this->url = $args['url']; 20 $this->title = isset($args['title']) ? $args['title'] : ''; 21 $this->content = isset($args['content']) ? $args['content'] : ''; 22 $this->author = isset($args['author']) ? $args['author'] : 1; 23 $this->date = isset($args['date']) ? $args['date'] : current_time('mysql'); 24 $this->dategmt = isset($args['date']) ? $args['date'] : current_time('mysql', 1); 25 $this->type = isset($args['type']) ? $args['type'] : 'page'; 26 27 add_filter('the_posts', array(&$this, 'virtualPage')); 28 } 29 30 // filter to create virtual page content 31 public function virtualPage($posts) 32 { 33 global $wp, $wp_query; 34 //die(var_dump($posts)); 35 // if (count($posts) == 0 && 36 // (strcasecmp($wp->request, $this->slug) == 0 || $wp->query_vars['page_id'] == $this->slug)) 37 //{ 38 //create a fake post intance 39 $post = new stdClass; 40 // fill properties of $post with everything a page in the database would have 41 $post->ID = -1; // use an illegal value for page ID 42 $post->post_author = $this->author; // post author id 43 $post->post_date = $this->date; // date of post 44 $post->post_date_gmt = $this->dategmt; 45 $post->post_content = $this->content; 46 $post->post_title = $this->title; 47 $post->post_excerpt = ''; 48 $post->post_status = 'publish'; 49 $post->comment_status = 'closed'; // mark as closed for comments, since page doesn't exist 50 $post->ping_status = 'closed'; // mark as closed for pings, since page doesn't exist 51 $post->post_password = ''; // no password 52 $post->post_name = $this->url; 53 $post->to_ping = ''; 54 $post->pinged = ''; 55 $post->modified = $post->post_date; 56 $post->modified_gmt = $post->post_date_gmt; 57 $post->post_content_filtered = ''; 58 $post->post_parent = 0; 59 $post->guid = get_home_url('/' . $this->url); 60 $post->menu_order = 0; 61 $post->post_tyle = $this->type; 62 $post->post_mime_type = ''; 63 $post->comment_count = 0; 64 65 // set filter results 66 $posts = array($post); 67 68 // reset wp_query properties to simulate a found page 69 $wp_query->is_page = TRUE; 70 $wp_query->is_singular = TRUE; 71 $wp_query->is_home = FALSE; 72 $wp_query->is_archive = FALSE; 73 $wp_query->is_category = FALSE; 74 unset($wp_query->query['error']); 75 $wp_query->query_vars['error'] = ''; 76 $wp_query->is_404 = FALSE; 77 //} 78 79 return ($posts); 80 } 81 } 3 /* 4 * Virtual Themed Page class 5 * 6 * This class implements virtual pages for a plugin. 7 * 8 * It is designed to be included then called for each part of the plugin 9 * that wants virtual pages. 10 * 11 * It supports multiple virtual pages and content generation functions. 12 * The content functions are only called if a page matches. 13 * 14 * The class uses the theme templates and as far as I know is unique in that. 15 * It also uses child theme templates ahead of main theme templates. 16 * 17 * Example code follows class. 18 * 19 * August 2013 Brian Coogan 20 * 21 */ 22 23 24 25 26 // There are several virtual page classes, we want to avoid a clash! 27 // 28 // 29 if (!class_exists('geoseo_Virtual_Themed_Pages')) { 30 31 class geoseo_Virtual_Themed_Pages { 32 33 public $title = ''; 34 public $body = ''; 35 public $slug = ''; 36 private $vpages = array(); // the main array of virtual pages 37 private $mypath = ''; 38 public $blankcomments = "blank-comments.php"; 39 40 function __construct($plugin_path = null, $blankcomments = null) { 41 if (empty($plugin_path)) 42 $plugin_path = dirname(__FILE__); 43 $this->mypath = $plugin_path; 44 45 if (!empty($blankcomments)) 46 $this->blankcomments = $blankcomments; 47 48 // Virtual pages are checked in the 'parse_request' filter. 49 // This action starts everything off if we are a virtual page 50 add_action('parse_request', array(&$this, 'vtp_parse_request')); 51 } 52 53 function add($virtual_regexp, $contentfunction) { 54 $this->vpages[$virtual_regexp] = $contentfunction; 55 } 56 57 // Check page requests for Virtual pages 58 // If we have one, call the appropriate content generation function 59 // 60 function vtp_parse_request(&$wp) { 61 //global $wp; 62 //if (empty($wp->query_vars['pagename'])) 63 // return; // page isn't permalink 64 65 66 //$p = $wp->query_vars['pagename']; 67 $p = $_SERVER['REQUEST_URI']; 68 69 $matched = 0; 70 foreach ($this->vpages as $regexp => $func) { 71 if (preg_match($regexp, $p)) { 72 $matched = 1; 73 break; 74 } 75 } 76 // Do nothing if not matched 77 if (!$matched) 78 return; 79 80 // setup hooks and filters to generate virtual movie page 81 //add_action('template_redirect', array(&$this, 'template_redir')); 82 add_filter('the_posts', array(&$this, 'vtp_createdummypost')); 83 84 // we also force comments removal; a comments box at the footer of 85 // a page is rather meaningless. 86 // This requires the blank_comments.php file be provided 87 add_filter('comments_template', array(&$this, 'disable_comments'), 11); 88 89 // Call user content generation function 90 // Called last so it can remove any filters it doesn't like 91 // It should set: 92 // $this->body -- body of the virtual page 93 // $this->title -- title of the virtual page 94 // $this->template -- optional theme-provided template 95 // eg: page 96 // $this->subtemplate -- optional subtemplate (eg movie) 97 // Doco is unclear whether call by reference works for call_user_func() 98 // so using call_user_func_array() instead, where it's mentioned. 99 // See end of file for example code. 100 $this->template = $this->subtemplate = null; 101 $this->title = null; 102 unset($this->body); 103 call_user_func_array($func, array(&$this, $p)); 104 105 if (!isset($this->body)) //assert 106 wp_die("Virtual Themed Pages: must save ->body [VTP07]"); 107 108 return($wp); 109 } 110 111 // Setup a dummy post/page 112 // From the WP view, a post == a page 113 // 114 function vtp_createdummypost($posts) { 115 116 // have to create a dummy post as otherwise many templates 117 // don't call the_content filter 118 global $wp, $wp_query; 119 120 //unset($wp_query->query['attachment']); 121 122 123 //create a fake post intance 124 $p = new stdClass; 125 // fill $p with everything a page in the database would have 126 $p->ID = -1; 127 $p->post_author = 1; 128 $p->post_date = current_time('mysql'); 129 $p->post_date_gmt = current_time('mysql', $gmt = 1); 130 $p->post_content = $this->body; 131 $p->post_title = $this->title; 132 $p->post_excerpt = ''; 133 $p->post_status = 'publish'; 134 $p->ping_status = 'closed'; 135 $p->post_password = ''; 136 $p->post_name = $this->slug; // slug 137 $p->to_ping = ''; 138 $p->pinged = ''; 139 $p->modified = $p->post_date; 140 $p->modified_gmt = $p->post_date_gmt; 141 $p->post_content_filtered = ''; 142 $p->post_parent = 0; 143 $p->guid = get_home_url('/' . $p->post_name); // use url instead? 144 $p->menu_order = 0; 145 $p->post_type = 'page'; 146 $p->post_mime_type = ''; 147 $p->comment_status = 'closed'; 148 $p->comment_count = 0; 149 $p->filter = 'raw'; 150 $p->ancestors = array(); // 3.6 151 152 153 // reset wp_query properties to simulate a found page 154 $wp_query->is_page = TRUE; 155 $wp_query->is_singular = TRUE; 156 $wp_query->is_home = FALSE; 157 $wp_query->is_archive = FALSE; 158 $wp_query->is_category = FALSE; 159 unset($wp_query->query['error']); 160 $wp->query = array(); 161 $wp_query->query_vars['error'] = ''; 162 $wp_query->is_404 = FALSE; 163 164 $wp_query->current_post = $p->ID; 165 $wp_query->found_posts = 1; 166 $wp_query->post_count = 1; 167 $wp_query->comment_count = 0; 168 // -1 for current_comment displays comment if not logged in! 169 $wp_query->current_comment = null; 170 $wp_query->is_singular = 1; 171 172 //as 173 $wp_query->is_attachment = false; 174 175 $wp_query->post = $p; 176 $wp_query->posts = array($p); 177 $wp_query->queried_object = $p; 178 $wp_query->queried_object_id = $p->ID; 179 $wp_query->current_post = $p->ID; 180 $wp_query->post_count = 1; 181 182 return array($p); 183 } 184 185 // Virtual Movie page - tell wordpress we are using the given 186 // template if it exists; otherwise we fall back to page.php. 187 // 188 // This func gets called before any output to browser 189 // and exits at completion. 190 // 191 function template_redir() { 192 // $this->body -- body of the virtual page 193 // $this->title -- title of the virtual page 194 // $this->template -- optional theme-provided template eg: 'page' 195 // $this->subtemplate -- optional subtemplate (eg movie) 196 // 197 198 if (!empty($this->template) && !empty($this->subtemplate)) { 199 // looks for in child first, then master: 200 // template-subtemplate.php, template.php 201 get_template_part($this->template, $this->subtemplate); 202 } elseif (!empty($this->template)) { 203 // looks for in child, then master: 204 // template.php 205 get_template_part($this->template); 206 } elseif (!empty($this->subtemplate)) { 207 // looks for in child, then master: 208 // template.php 209 get_template_part($this->subtemplate); 210 } else { 211 get_template_part('page'); 212 } 213 214 // It would be possible to add a filter for the 'the_content' filter 215 // to detect that the body had been correctly output, and then to 216 // die if not -- this would help a lot with error diagnosis. 217 218 exit; 219 } 220 221 // Some templates always include comments regardless, sigh. 222 // This replaces the path of the original comments template with a 223 // empty template file which returns nothing, thus eliminating 224 // comments reliably. 225 function disable_comments($file) { 226 if (file_exists($this->blankcomments)) 227 return($this->mypath . '/' . $blankcomments); 228 return($file); 229 } 230 231 } 232 233 // class 234 // Example code - you'd use something very like this in a plugin 235 // 236 if (0) { 237 // require 'BC_Virtual_Themed_pages.php'; 238 // this code segment requires the WordPress environment 239 240 $vp = new Virtual_Themed_Pages_BC(); 241 $vp->add('#/mypattern/unique#i', 'mytest_contentfunc'); 242 243 // Example of content generating function 244 // Must set $this->body even if empty string 245 function mytest_contentfunc($v, $url) { 246 // extract an id from the URL 247 $id = 'none'; 248 if (preg_match('#unique/(\d+)#', $url, $m)) 249 $id = $m[1]; 250 // could wp_die() if id not extracted successfully... 251 252 $v->title = "My Virtual Page Title"; 253 $v->body = "Some body content for my virtual page test - id $id\n"; 254 $v->template = 'page'; // optional 255 $v->subtemplate = 'billing'; // optional 256 } 257 258 } 82 259 } -
local-geo-search/trunk/geoseo.php
r1215485 r1228038 4 4 * Plugin URI: https://www.localgeosearch.com 5 5 * Description: Local GEO Search creates hundreds of location specific pages on your site to target your services in your market. 6 * Version: 0.406 * Version: 1.0.0 7 7 * Author: Elite Impressions, LLC 8 8 * Author URI: http://www.localgeosearch.com 9 9 **/ 10 10 11 //start session 12 if (!session_id()) { 13 session_start(); 14 } 15 16 if(!isset($_SESSION['geoseoPlugin'])) { 17 $_SESSION['geoseoPlugin'] = array( 18 'sitemap'=>array(), 19 'organization'=>array(), 20 'website'=>array(), 21 'testing'=>false 22 ); 23 } 24 25 if($_SERVER['SERVER_NAME']=='it-as') { 26 $_SESSION['geoseoPlugin']['testing'] = true; 27 } 28 29 include_once('classes/cachesys.php'); 30 include_once('classes/fns.tools.php'); 11 31 include_once('classes/class.virtualpage.php'); 32 33 include_once('sitemapgen/fns.sitemap.php'); 34 35 include_once('pagegen/fns.pagegen.php'); 36 12 37 include_once('admin/admin.geoseo.php'); 13 38 … … 33 58 add_filter("plugin_action_links_$plugin", 'geo_seo_settings_link' ); 34 59 35 if (!session_id()) {36 session_start();37 }38 39 40 if(!isset($_SESSION['geoseoPlugin'])) {41 $_SESSION['geoseoPlugin'] = array(42 'sitemap'=>array(),43 'organization'=>array(),44 'website'=>array()45 );46 }47 48 49 60 // Add settings link on plugin page 50 61 function geo_seo_settings_link($links) { … … 55 66 56 67 57 function geo_seo_getData( $key=null ) {58 59 $settings = get_option('geo_seo_option_name');60 61 $data = array(62 'slug' => isset($settings['slug']) ? $settings['slug'] : 'local',63 'api' => 'https://api.localgeosearch.com',64 'organization' => $settings['organization'],65 'website' => $settings['website']66 );67 68 if($key===null) {69 return $data;70 }71 else {72 return $data[$key];73 }74 75 }76 77 function geo_seo_getTerms( $termSID=null ) {78 79 $apiURL = geo_seo_getData('api');80 81 if($termSID==null) {82 $results = json_decode(geo_seo_easyCurl(array( 'url'=>$apiURL.'/terms/get/'.geo_seo_getData('organization').'/'.geo_seo_getData('website').'/' )),true);83 }84 else {85 $params = array( 'url'=>$apiURL.'/magic/'.geo_seo_getData('organization').'/'.geo_seo_getData('website').'/'.$termSID );86 $rsp = geo_seo_easyCurl($params);87 $results = json_decode($rsp, true);88 }89 90 return $results;91 92 }93 94 function geo_seo_pageNew() {95 96 $slug = geo_seo_getData('slug');97 $apiURL = geo_seo_getData('api');98 99 $url = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');100 if (substr($url,0,strlen($slug)) == $slug)101 {102 103 remove_action('wp_head', 'rel_canonical');104 105 //load the organization into the session106 $orgID = geo_seo_getData('organization');107 $websiteID = geo_seo_getData('website');108 if(count($_SESSION['geoseoPlugin']['organization'])==0) {109 $rsp = json_decode(geo_seo_easyCurl(array( 'url'=>$apiURL.'/organization/get/'.$orgID )),true);110 if($rsp['status']=='OK') {111 112 $_SESSION['geoseoPlugin']['organization'] = $rsp['data'];113 114 foreach($_SESSION['geoseoPlugin']['organization']['websites'] as $website) {115 if($website['id']==$websiteID) {116 $_SESSION['geoseoPlugin']['website'] = $website;117 break;118 }119 }120 121 }122 else {123 return;124 }125 }126 127 if($_SESSION['geoseoPlugin']['organization']['active']==0 || $_SESSION['geoseoPlugin']['website']['active']==0) {128 return;129 }130 131 132 //check the url to figure out where we're at133 $urlParts = explode('/', $url);134 // foreach($urlParts as $i=>$urlPart) {135 // error_log('URL Part '.$i.': '.$urlPart);136 // }137 138 //get term and location139 $termSID = isset($urlParts[1]) ? $urlParts[1] : '';140 $locationSID = isset($urlParts[2]) ? $urlParts[2] : '';141 142 //if term is blank, we get a list of terms and locations143 if($termSID=='') {144 $pageType = 1;145 $rawTerms = json_decode(geo_seo_easyCurl(array( 'url'=>$apiURL.'/terms/get/'.geo_seo_getData('organization').'/'.geo_seo_getData('website').'/' )),true);146 $rawLocations = json_decode(geo_seo_easyCurl(array( 'url'=>$apiURL.'/locations/get/'.geo_seo_getData('organization').'/'.geo_seo_getData('website').'/' )), true);147 $results['status']='OK';148 }149 //if $term is filled but location is blank, $term can be a location or a term150 elseif($locationSID=='') {151 $pageType = 2;152 $params = array( 'url'=>$apiURL.'/magic/'.geo_seo_getData('organization').'/'.geo_seo_getData('website').'/'.$termSID );153 $rsp = geo_seo_easyCurl($params);154 $results = json_decode($rsp, true);155 }156 //both term and location are in157 else {158 $pageType = 3;159 $params = array( 'url'=>$apiURL.'/magic/'.geo_seo_getData('organization').'/'.geo_seo_getData('website').'/'.$termSID.'/'.$locationSID );160 $rsp = geo_seo_easyCurl( $params );161 $results = json_decode($rsp, true);162 }163 164 //return error if the status is not ok165 if($results['status']!='OK') {166 return;167 }168 169 170 //geo-search list171 if($pageType==1) {172 $title = get_bloginfo();173 174 $data = array(175 'term_links' => array(),176 'location_links'=> array()177 );178 179 foreach($rawTerms['data']['terms'] as $term) {180 $data['term_links'][] = array(181 'text' => $term['term'],182 'href' => '/'.$term['sid']183 );184 }185 186 foreach($rawLocations['data']['locations'] as $location) {187 $data['location_links'][] = array(188 'text' => $location['location'],189 'href' => '/'.$location['sid']190 );191 }192 193 $content = geo_seo_createView('view.links_blank.php', $data);194 195 }196 //location or terms links197 elseif($pageType==2) {198 if($results['data']['type']=='term') {199 $title = $results['data']['term']['text'];200 }201 elseif($results['data']['type']=='location') {202 $title = $results['data']['location']['name'];203 }204 205 $content = geo_seo_createView('view.links.php', $results['data']);206 207 }208 //magic page209 elseif($pageType==3) {210 $title = $results['data']['term'].' in '.$results['data']['location'];211 $content = geo_seo_createView('view.page.php', $results['data']);212 }213 214 215 $args = array(216 'slug' => $slug,217 'url' => $url,218 'title' => $title,219 'content' => $content);220 $pg = new GEOSEOVirtualPage($args);221 222 }223 }224 225 226 227 function geo_seo_createGenericSiteMapData() {228 229 $slug = geo_seo_getData('slug');230 $apiURL = geo_seo_getData('api');231 232 if(count($_SESSION['geoseoPlugin']['sitemap'])==0) {233 $rawTerms = json_decode(geo_seo_easyCurl(array( 'url'=>$apiURL.'/terms/get/'.geo_seo_getData('organization').'/'.geo_seo_getData('website').'/' )),true);234 235 $rawLocations = json_decode(geo_seo_easyCurl(array('url'=>$apiURL.'/locations/get/'.geo_seo_getData('organization').'/'.geo_seo_getData('website').'/' )), true);236 237 $lastChanged = date('Y-m-d H:i:s', strtotime('-1 day') );238 239 $url = array();240 241 $url[] = array(242 'url' => get_site_url().'/'.$slug.'/',243 'url_parts' => '/'.$slug.'/',244 'priority' => '1',245 'frequency' => 'always',246 'modification_date' => $lastChanged247 );248 249 if(isset($rawTerms) && isset($rawTerms['data']) && isset($rawTerms['data']['terms'])) {250 foreach($rawTerms['data']['terms'] as $term) {251 252 $url[] = array(253 'url' => get_site_url().'/'.$slug.'/'.$term['sid'].'/',254 'url_parts' => '/'.$slug.'/'.$term['sid'].'/',255 'priority' => '1',256 'frequency' => 'always',257 'modification_date' => $lastChanged258 );259 260 foreach($rawLocations['data']['locations'] as $location) {261 $url[] = array(262 'url' => get_site_url().'/'.$slug.'/'.$term['sid'].'/'.$location['sid'].'/',263 'url_parts' => '/'.$slug.'/'.$term['sid'].'/'.$location['sid'].'/',264 'priority' => '1',265 'frequency' => 'always',266 'modification_date' => $lastChanged267 );268 }269 270 }271 }272 273 if(isset($rawTerms) && isset($rawTerms['data']) && isset($rawTerms['data']['locations'])) {274 foreach($rawLocations['data']['locations'] as $location) {275 $url[] = array(276 'url' => get_site_url().'/'.$slug.'/'.$location['sid'].'/',277 'url_parts' => '/'.$slug.'/'.$location['sid'].'/',278 'priority' => '1',279 'frequency' => 'always',280 'modification_date' => $lastChanged281 );282 }283 }284 285 $_SESSION['geoseoPlugin']['sitemap'] = $url;286 287 }288 else {289 $url = $_SESSION['geoseoPlugin']['sitemap'];290 }291 292 return $url;293 294 }295 296 297 function geo_seo_yoastCanonicalTag( $canonical ) {298 $slug = geo_seo_getData('slug');299 300 $url = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));301 if (substr($url,0,strlen($slug)) == $slug)302 {303 $canonical = false;304 }305 306 return $canonical;307 }308 309 function geo_seo_allinoneCanonicalTag( $canonical ) {310 $slug = geo_seo_getData('slug');311 312 $url = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));313 if (substr($url,0,strlen($slug)) == $slug)314 {315 $canonical = false;316 }317 318 return $canonical;319 }320 321 //add pages to sitemap322 function geo_seo_yoastSitemap( $content ) {323 324 global $wpseo_sitemaps;325 326 $urls = geo_seo_createGenericSiteMapData();327 328 foreach( $urls as $data ) {329 330 $url = array(331 'loc' => $data['url'],332 'pri' => $data['priority'],333 'chf' => $data['frequency'],334 'mod' => $data['modification_date']335 );336 $content .= $wpseo_sitemaps->sitemap_url( $url );337 338 }339 340 return $content;341 }342 343 344 function geo_seo_allinoneSitemap( $option ) {345 346 if( !empty( $option ) && !empty( $option['modules'] ) && !empty( $option['modules']['aiosp_sitemap_options'])) {347 348 $settings = geo_seo_getData();349 350 $urls = geo_seo_createGenericSiteMapData();351 352 $my_sitemap_entries = array();353 354 //remove old geo seo stuff355 foreach($option['modules']['aiosp_sitemap_options']['aiosp_sitemap_addl_pages'] as $urlIndex=>$entry) {356 if(strpos($urlIndex, '/'.$settings['slug'])!==false) {357 unset($option['modules']['aiosp_sitemap_options']['aiosp_sitemap_addl_pages'][$urlIndex]);358 }359 elseif(strpos($urlIndex, '/'.$settings['slug'])!==false) {360 unset($option['modules']['aiosp_sitemap_options']['aiosp_sitemap_addl_pages'][$urlIndex]);361 }362 }363 364 365 foreach( $urls as $data ) {366 367 $my_sitemap_entries[ $data['url_parts'] ] = array(368 'prio' => $data['priority'],369 'freq' => $data['frequency'],370 'mod' => $data['modification_date']371 );372 373 }374 375 if ( empty( $option['modules']['aiosp_sitemap_options']['aiosp_sitemap_addl_pages'] ) ) {376 $option['modules']['aiosp_sitemap_options']['aiosp_sitemap_addl_pages'] = array();377 }378 379 foreach( $my_sitemap_entries as $k => $v ) {380 $option['modules']['aiosp_sitemap_options']['aiosp_sitemap_addl_pages'][$k] = $v;381 }382 383 }384 385 return $option;386 387 }388 389 390 391 392 function geo_seo_easyCurl($params) {393 394 $options = get_option('geo_seo_option_name');395 396 if(!isset($params['authentication'])) {397 $params['authentication'] = array(398 'basic' => true,399 'user' => $options['username'],400 'password'=>$options['password']401 );402 }403 404 //$params = [405 // 'url' => 'string',406 // 'fields' => 'array',407 // 'header' => 'array',408 // 'authentication' => [ 'user'=>'string', 'password'=>'string'],409 //];410 411 if(!isset($params['fields']) || !is_array($params['fields'])) {412 $params['fields'] = array();413 }414 $fields_string = http_build_query($params['fields']);415 416 //open connection417 $ch = curl_init();418 419 //set the url, number of POST vars, POST data420 curl_setopt($ch, CURLOPT_URL, $params['url']);421 curl_setopt($ch, CURLOPT_HEADER, false);422 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);423 curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);424 curl_setopt($ch, CURLOPT_POST, 1);425 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);426 curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);427 428 if(isset($params['header'])) {429 curl_setopt($ch, CURLOPT_HTTPHEADER, $params['header']);430 curl_setopt($ch, CURLINFO_HEADER_OUT, true);431 }432 433 if(isset($params['authentication'])) {434 if(!isset($params['authentication']['basic']) || $params['authentication']['basic']!=true) {435 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);436 }437 curl_setopt($ch, CURLOPT_USERPWD, $params['authentication']['user'].':'.$params['authentication']['password']);438 }439 440 //execute post441 $result = curl_exec($ch);442 443 //capture any errors from curl444 $curl_errno = curl_errno($ch);445 if($curl_errno) {446 // error_log('easyCURL error '.$curl_errno.' on url '.$params['url']);447 }448 else {449 // error_log('easyCURL success to url '.$params['url']);450 }451 452 //close connection453 curl_close($ch);454 455 return $result;456 457 }458 459 function geo_seo_createView( $view, $data ) {460 461 $settings = geo_seo_getData();462 463 foreach($data as $k=>$v) {464 $$k = $v;465 }466 467 ob_start();468 include($view);469 $content = ob_get_contents();470 ob_end_clean();471 472 return $content;473 474 } -
local-geo-search/trunk/readme.txt
r1215485 r1228038 1 1 === Local GEO Search === 2 2 Contributors: andrewsauder 3 Donate link: https:// www.localgeosearch.com/3 Donate link: https://localgeosearch.com/ 4 4 Tags: seo, marketing, geolocation 5 5 Requires at least: 3.0.1 6 Tested up to: 4. 2.26 Tested up to: 4.3 7 7 Stable tag: trunk 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 10 11 Local GEO Search creates hundreds of location specific pages on your site to target your services in your market.11 Local GEO Search creates hundreds of location specific pages on your site to target your services in your geographic market. 12 12 13 13 … … 27 27 1. Upload the zip file in Wordpress or unzip it and copy the geoseo directory into the wp-content/plugins directory 28 28 1. Activate the plugin through the 'Plugins' menu in WordPress 29 1. Visit the plugin settings to l og in to your Local GEO Search account and link up your website29 1. Visit the plugin settings to link your website with the terms and locations you've added (you'll need to know the website token from localgeosearch.com) 30 30 31 31 … … 51 51 == Changelog == 52 52 53 = 1.0.0 = 54 * Breaks backwards compatibility. If you already have the plugin installed, you will have to reauthenticate using the new method 55 * New authentication method with single token tied to specfic website instead of username password 56 * Site URL must match URL saved in Local GEO Search 57 * Enhanced integration with AllInOneSEO sitemap.xml 58 * Decreased required cloud calls per Local GEO Search page load 59 53 60 = 0.40 = 54 61 * Usbility tweaks
Note: See TracChangeset
for help on using the changeset viewer.