How to automatically update google index when content website has changed - php

Yesterday, i post an 'ad' on an ebay site (marktplaats.nl) and the ad was immediately visible in google when i search for this ad on Google.
How do they do this?
Because it is a very large site, i don't think they repost the sitemap. I have made such function to update the sitemap but don't know this is a good method. What i have is this (part of my library):
// returns false when input invalid, returns a number (array index) when url is invalid or // request fails, returns true when complete:
function suSubmitSitemap( $sXmlUrl, $asSearchEnginePingUrl = 'http://www.google.com/ping?sitemap=%s', $bContinueOnError = false )
{
if( !suIsValidString( $sXmlUrl ) || ( !suIsValidString( $asSearchEnginePingUrl ) && !suIsValidArray( $asSearchEnginePingUrl )))
{ return false; }
$a = (is_array($asSearchEnginePingUrl))?$asSearchEnginePingUrl:explode(',', $asSearchEnginePingUrl );
$sXmlUrl = urlencode( $sXmlUrl );
$ret = false;
foreach( $a as $i=>$sUrl )
{
$sUri = str_replace( '%s', $sXmlUrl, $sUrl );
$bValid = (!is_bool( strpos( $sUrl, '%s' )) && suGetUrlContent( $sUri ));
if( !$bValid )
{
if( !$bContinueOnError )
{ return $i; }
if( !is_array( $ret ))
{ $ret = array(); }
$ret[$i] = $sUri;
}
}
return ret;
}
Is this a safe way to do this (Google will not ban you when frequently called), when this is not the way to do it, does anyone know how implement such index update functionality in PHP?

Google will constantly crawl frequently updated/popular sites and update their search results. This has the benefit of making Google more relevant.
Resubmitting your site map will not help you get crawled as fast as Ebay. Get more visitors and post content more frequently to get Google to visit your site more often.
Also, check out:
http://www.google.com/support/webmasters/bin/answer.py?answer=48620
http://www.searchenginejournal.com/10-ways-to-increase-your-site-crawl-rate/7159/

Related

How would I keep the slash in my $domain when using wpmu_create_blog to create a site

I am currently working on an automated site creation function on my local installation of wordpress. In essence, a form is filled out on an already existing site and that info is pulled to create a new site automatically via an endpoint that activates some queries. So far I have been able to successfully pull the information into an array and then pass that to the wpmu_create_blog function. The issue is that the $domain isn't being called correctly(that is to say, how I intend it to be called), the '/' is lost between 'localhost' and 'wordpress'.
public function create_endpoint($request) {
$key = $request['key'];
if ($this->validate_key($key)) {
$newsite = array (
$title = $request['name'],
$path = $request['slug'],
$admin_user = $request['admin_user'],
);
$domain = 'localhost/wordpress';
$site_id = get_blog_id_from_url($domain, $path);
$user_id = get_user_by('login', $admin_user);
if ( !empty($title) and !empty($domain) and !empty($path) and empty($user_id) ) {
return wpmu_create_blog($domain, $path, $title, $user_id, $site_id);
}
else {
return "Not enough information";
}
}
else {
return $this->invalid_key_message;
}
}
Everything but the domain being called as intended is working as intended. This is also just the static prototype, my end goal is that this is entirely dynamic including the $domain variable.
I'm just totally lost on where to go from here. I've tried some appendage stuff and moving syntax around in all types of ways but keep hitting a wall. Any input or suggestions are happily accepted.
I have a solution implemented. In the array $path has been changed to $slug (use of slug is specific to my code). The $domain now only calls 'localhost' and I create $path using plain text the 'wordpress' and then add the slug via a $request.
$newsite = array (
$title = $request['name'],
$slug = $request['slug'],
$admin_user = $request['admin_user'],
);
$domain = 'localhost';
$path = 'wordpress/'.$request['slug'];

Identify Which Item is the Non-Object (PHP Notice: Trying to get property of non-object)

I'm relatively new to PHP and WordPress and this one error message "PHP Notice: Trying to get property of non-object" has been plaguing me, and I'm sure there is an easy fix. Can anybody scan the following code and let me know what could be the source of this error? I'm confident I've narrowed it down to this block of code. Thanks in advance for any help!
// REDIRECT USERS IF THEY ARE IN THE WRONG SPOT
add_action ('template_redirect', 'bee_security');
function bee_security() {
// set the page that people end up on if they try to access the wrong page
$bee_redirecturl = '/private-page/home/';
// get basic user information
$bee_masteruserid = get_user_meta(get_current_user_id(), 'wpcf-user-masteruser', true);
$bee_temppost = get_post($post = get_the_id());
$bee_authorid = $bee_temppost->post_author;
// determine if the current post type is related to households
$bee_posttype_household = substr(get_post_type(), 0, 9);
if ( $bee_posttype_household == "household") {
$bee_posttype_household = true;
} else {
$bee_posttype_household = false;
}
// redirect the user if they are logged in and accessing the front page
if ( is_front_page() && is_user_logged_in() ) {
wp_redirect($bee_redirecturl);
exit;
// redirect the user if they try to access somebody else's househould besides their own
} elseif ( $bee_posttype_household == true ) {
if ( $bee_authorid != get_current_user_id() && $bee_authorid != $bee_masteruserid ) {
wp_redirect($bee_redirecturl);
exit;
}
// redirect the user if they try to make a review on someone else's behalf
} elseif ( get_the_id() == 347 ) {
$bee_childpost = get_post($_GET['childid']);
$bee_childauthor = $bee_childpost->post_author;
if ( $bee_childauthor != get_current_user_id() && $bee_childauthor != $bee_masteruserid ) {
wp_redirect($bee_redirecturl);
}
}
}
one of following values producing a error
$bee_authorid = $bee_temppost->post_author;
OR
$bee_childauthor = $bee_childpost->post_author;
get_post() not returning values, this is could be the reason
I think I finally figured it out. Of course, the minute I finally give up and ask for help, I figure it out! I changed this line:
$bee_authorid = $bee_temppost->post_author;
To this:
$bee_authorid = get_post_field( 'post_author', get_the_id() );
I guess on some pages where a post might not be loading the line was returning null instead of as an object.

User agent in php

I'm trying to get a little script working. It shouldn't be hard, but I'm kind of a n00b when it comes to PHP (my last experiments were many years ago).
So, basically, I want a little script that IF the client uses a mobile device, it gives a link to Facebook as an app link. IF the client has a regular laptop, the script should output a regular Facebook.
Okay, so I'm just going to show my screwed up code, to make it (hopefully) more clear what I'm trying (some might notice that I grabbed part of the code from another thread):
<?php
function check_user_agent ( $type = NULL ) {
$user_agent = strtolower ( $_SERVER['HTTP_USER_AGENT'] );
if ( $type == 'mobile' ) {
if ( preg_match ( "/phone|iphone|itouch|ipod|symbian|android|htc_|htc-|palmos|blackberry|opera mini|iemobile|windows ce|nokia|fennec|hiptop|kindle|mot |mot-|webos\/|samsung|sonyericsson|^sie-|nintendo/", $user_agent ) ) {
echo "fb://groups/334257489999204";
} else if ( preg_match ( "/mobile|pda;|avantgo|eudoraweb|minimo|netfront|brew|teleca|lg;|lge |wap;| wap /", $user_agent ) ) {
echo "fb://groups/123456789";
}
}
else {
echo "https://www.facebook.com/groups/123456789";
};
echo "https://www.facebook.com/groups/123456789";
};
?>" />
This code is in a html anchor href tag, inside a .php file (mainly HTML though).
Thanks!
This should set you on the right path
$user_agent = strtolower ( $_SERVER['HTTP_USER_AGENT'] );
if ( empty($user_agent) ) {
$is_mobile = false;
} elseif ( preg_match ( "/mobile|pda;|avantgo|eudoraweb|minimo|netfront|brew|teleca|lg;|lge |wap;| wap|phone|iphone|itouch|ipod|symbian|android|htc_|htc-|palmos|blackberry|opera mini|iemobile|windows ce|nokia|fennec|hiptop|kindle|mot |mot-|webos\/|samsung|sonyericsson|^sie-|nintendo/", $user_agent ) ) {
$is_mobile = true;
} else {
$is_mobile = false;
}
echo (is_mobile) ? 'I am a mobile !' : 'I am not a mobile :(';

getting return data from url

I'm trying to submit user information to a URL using GET, and then get the errors (if there any) and use them to tell the customer what went wrong. So, currently I have a form that submits this customer info into an iframe (so the page is not redirected and I can see the response from my shopping cart software). when the info is submitted, this is the response I get from the shopping cart server:
errorFound=1&responseCode=329&...etc.
I need to get this response code, and was wondering what the most simple way would be to do it. Once I get it I can tell the customer what the problem is... Should I use java to read the
data in the iframe once it loads? or can I use something like Fopen to open the URL and get the return data (can't enable fopen on my server though, but something like it?).
Java != javascript
A quick way to do it:
$errorcodes = array("329" => "Wrong blabla");
if( isset( $_GET['errorFound'] ) && isset( $_GET['responseCode'] ) ){
$errorNr = (int) $_GET['responseCode'];
$error = getErrorFromDB();
//OR
//$error = isset( $erorCodes[ $errorNr ] )? $errorcodes[ $errorNr] : false;
if( $error !== false){
exit( "<script type='text/javascript'>
alert( '".htmlspecialchars($error)."' )
</script>");
}
}
function getError( $code )
{
$code = (int) $code;
$db = getYourPdoInstance();
$q = $db->prepare("SELECT `message` FROM `errorCodes` WHERE `errorCode` = ?");
$q->execute( array( $code) );
$return = $q->fetch(2);
return isset($return['message'])?$return['message']:false;
}

Why doesn't PHP's get_meta_tags work on some URL's?

Why does the code below work great on most websites (such as www.apple.com), but doesn't work for others (such as www.yahoo.com)?
$tags = get_meta_tags( $webpage );
if( $tags )
{
if( $tags['description'] )
{
$link_description = $tags['description'];
}
else
{
$link_description = '';
}
}
When I say that it doesn't work, what I mean is that the script just stalls. My program is left hanging. Is there a way to catch when get_meta_tags() doesn't work and handle this with an alternative block of code? I thought I was doing this when I wrote
$tags = get_meta_tags( $webpage );
if( $tags )
{
// stuff
}
else
{
// handle the case when the above doesn't work.
}
However, it still stalls on sites like www.yahoo.com. Any ideas on how to handle these troublesome URL's?

Categories