simple_html_dom: Call to a member function find() on a non-object in - simple-html-dom

This code has been working good for months. The output consisted of a few lines containing statistics for a given username. The website from which the html page is taken is not down, and the content of the page in file_get_html hasn't changed.
All of a sudden (I checked and nobody modified it) it stopped working. Here's the relevant part:
[...]if ($FileAge > ($expiretime * 60) || 0 == filesize($cachename))
{
include_once('simple_html_dom.php');
$html = file_get_html('http://www.foo.com/search?what=user%3A'.YOUR_USER.'&search=Search');
var_dump($html); //TEST
$link = $html->find('.likeh4 lightGrey.', 0)->find('a', 0)->href; // Get the last activity link
[...]
The error log says:
[02-Feb-2013 17:02:19 Europe/Berlin] PHP Fatal error: Call to a member function find() on a non-object in /foo.php on line 22 (the line with $link).
var_dump($html) gives bool(false)
I have a similar script which parses an html page from another website. It stopped working as well.
[...]include_once('simple_html_dom.php');
$html = file_get_html('http://my.flightmemory.com/'.FLIGHTMEMORY_USER);
$chilometri_table = $html->find('table', 2); [...]
I tried to save on my webserver one of those html pages and I don't get such error.
Did my host disable some php function for security reasons? (actually, file_get_html comes from simple_html_dom and not from php native functions)
Any hints?
Thanks

It is probably way too late but:
Simple_html_dom has a constant to check given html size - MAX_FILE_SIZE. by default it's 600KB. It's enough for most cases, but if your given html is bigger than that, it will fail and returns false and causes that fatal error.

If you try to get [href]
I had same problem and fixed it.
need valid it's a simple_html_dom_node
if(is_a($html->find('.likeh4 lightGrey. a', 0),'simple_html_dom_node' )
$link = $html->find('.likeh4 lightGrey. a', 0)->href;
OR
foreach ( $$html->find('.likeh4 lightGrey. a') as $links ) {
$link =$links->href;
}

Related

Wordpress wp_trash_post hooks not working as expected

This applies to all the hooks associated with wp_trash_post(); pre_trash_post, wp_trash_post, trashed_post and the transition hooks, eg publish_to_trash. All behave in exactly the same way.
I have a piece of code to run on this hook;
function to_fire_on_hook($post_id) {
... do stuff
// Get the slug of the $post_id above - the post being trashed
$slug = $post->post_name;
... more stuff that then
do_something(..., $slug, ...);
// doesn't work unless I put
die; //here
}
}
add_action('wp_trashed_post', 'to_fire_on_hook');
if I put die in the function, it completes OK, if I remove it the function doesn't complete.
I thought it might be to do with the fact that putting the post in the trash appends _trash to its name but appending that to $slug doesn't make any difference (neither does using the post ID).
I have swapped out all variables for static values and the result is the same. If the execution stops with die or wp_die() the last function executes, if not it doesn't.
Using echo statements before the die shows the correct values.
Any light on what could cause this behaviour?

After adding a hook in functions.php, limit login plugin doesn't display value

I am having trouble as I am not able to display counter values of "Limit Login Attempts Reloaded" plugin after adding a hook to change content of error message.
I am using hook below to change eroor content.
add_filter('login_errors', create_function('$a', "return '<b>Error: </b> Wron Username or Password';"));
If I don't use that hook it works well, but template is messed up. Any suggestions?
First, the create_function() function is deprecated. You could try it like this:
function my_login_errors_function(){
return 'Error: Wrong Username or Password';
}
add_filter('login_errors', 'my_login_errors_function');
However, this doesn't fix the main problem, which is that your function will change every login error text to the string we are returning.
Filters are like machines on a conveyor belt, receiving something and passing something along to the next step. But the way your function is written, it's a machine that completely disregards what comes in, and always spits out the same thing.
If you want to only replace a particular login error message, you would first have to check the existing text (the input to your filter machine) to see if it matched the one you want to replace, and then and only then would you return something else (otherwise returning the original argument's value).
function my_login_errors_function( $error ){
if( $error === 'The error message I want to replace' ){
return 'Error: Wrong Username or Password';
}
return $error;
}
add_filter( 'login_errors', 'my_login_errors_function' );
Likely what's happening is that plugin is using a login error to display the count, but since your function is overwriting every error message, that count is getting overwritten.

How can I add server field to post on data in PHP?

Welcome to use the WordPress template developer allows the addition of servers to watch movies I have some problems are when you add a server and update the article is updated but returns the right empty or not added and then when you delete the server is not deleted I checked the error record and this is the result
[21-Sep-2018 10:42:50 UTC] PHP Warning: array_combine() expects parameter 2 to be array, boolean given in /home3/mysite/public_html/wp-content/themes/movie/functions.php on line 154
File functions.php
https://3bdo.info/functions.zip
The linked zip file seams to be broken so I cannot extract the file.
But in general the error message says, that you have to use two arrays to call array_combine. You seam to try to combine an array (which is like a list) and a boolean (which is like yes/no). And that is not possible.
$android_servers_title2 = servers_get_meta( 'android_download_server_title' );
$android_servers_code2 = servers_get_meta( 'android_download_server_link' );
/* foreach($servers_title as $server_title)
{
echo "<label for='servers_server_title'>Server Title</label>";
echo " <br><input type='text' name='servers_server_title[]' id='servers_server_title' value='" . $server_title . "'><br>";
} */
if($android_servers_title2){
$android_arraye2 = array_combine($android_servers_title2, $android_servers_code2);
}else {
$android_arraye2 = false;
}
This is basically your problem. servers_get_meta is returning 'false' I would imagine. Check that 'android_download_server_link' is set. you may wish to change the if statement code to detect a false
if($android_servers_title2 && $android_servers_code2){

Wordpress: cant derive error

I've got a strange one going on here. Tried to implement is_wp_error in multiple situations, but it fails. Here's the thing, illustrated with my last attempt:
I want to login a user by wp_signon(), check if there are errors and if so, display them.
So I wrote the following lines of code:
$user = wp_signon();
if(is_wp_error($user)){
$result = 'Error-' .
$user->get_error_message();
} else {
$result = 'Login succeed';
}
echo $result;
The strange thing is, is_wp_error() doesn't return false (so there is an error). But $user->get_error_message(); is empty.
Tried it in different actions. When debugging, echo is_wp_error(); returns 0.
var_dump(wp_is_error()); returns empty arrays.
Furthermore, even when valid credentials are given, is_wp_error() still returns true. Also when testing in other circumstances (and on a clean WP installation)
Any thoughts?
I took a look through the wp_signon() code (located at http://core.trac.wordpress.org/browser/tags/3.5/wp-includes/user.php#L0 )
Looks like the error is blanked out if a blank username or password is passed in. (lines 56 and 57 of that file.)

"Missing argument"

I'm a PHP noob and have a question which seems to be simply - not as said, I'm a noob and can't solve it myself.
I have a wordpress blog running a template, and when searching without any searchresults, a error shows in the top of the page:
Warning: Missing argument 1 for get_page_id(), called in /var/www/titanen.dk/public_html/spillersmart/wp-content/themes/WPTube4/functions.php on line 262 and defined in /var/www/titanen.dk/public_html/spillersmart/wp-content/themes/WPTube4/functions.php on line 237
The functions.php can be seen here http://spillersmart.dk/functions.txt and a example of the page can be seen here http://spillersmart.dk/?s=xxx
Thanks in advance, guys! :-))
This problem sounds like it is somewhere within the theme, what the error means is: At line 262 inside functions.php this is happening.
function tube_getcustomfield($filedname, $page_current_id = NULL)
{
if($page_current_id==NULL)
$page_current_id = get_page_id(); //!HERE IS THE PROBLEM!
$value = get_post_meta($page_current_id, $filedname, true);
return $value;
}
The function get_page_id(); is being called without supplying an argument, and if you look at the definition for the function:
function get_page_id($page_name){
global $wpdb;
$page_name = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$page_name."' AND post_status = 'publish' AND post_type = 'page'");
return $page_name;
}
This function requires one argument. Without getting a better look at how the theme has been built I don't know exactly how the get_page_id() function is being used. I wonder whether that line of code should be changed to
$page_current_id = get_page_id($filedname);
If this doesn't work then see if you can get a more up to date version of the theme you are using.

Resources