Blocked - frame because it set 'X-Frame-Options' to 'sameorigin' - web-scraping

I've created a srapping script in PHP to scrape data from https://bluelivetv.com/ site. but it is
showing "Refused to display 'https://reystream.tv/' in a frame because it set 'X-Frame-Options' to 'sameorigin'."
enter image description here
So, is there any solution for this to bypass/unblock or to set X-Frame_options allowAll
Thanks
Here is my code
`
require_once 'simple_html_dom.php';
$html_dom = file_get_html( 'https://bluelivetv.com/html/game_list/show_45733.html' );
$table_rows = $html_dom->find('.card.game-itme.border-0.mt-4');
if ( isset( $table_rows ) && ! empty ( $table_rows ) ) {
foreach( $table_rows as $table_row ) {
echo $table_row->innertext;
}
}
`

Related

how added new Condition (if) wordpress costum field

We have this code to display the custom field in WordPress
if( isset($digi) && !empty($digi) )
Now we want to add a new condition (check in terms of being categorized)
That's how we did it
if( isset(product_categories=55,56,57,58) || isset($digi) && !empty($digi) )
Is it correct?
I am not sure in what file or loop you perform this code, but your solution might be something similair to this:
$your_category = "THE CATEGORY YOU WANT TO CHECK FOR";
$product_categories = array(55,56,57,58);
if( in_array($your_categroy, $product_categories) || ( isset($digi) && !empty($digi) ) )

T_OBJECT_OPERATOR - Drupal 7

this is the php code:
<?php
$tid = $job_node->field_job_cv_destination['und'][0]['tid'];
$term = taxonomy_term_load($tid);
$name = $term->name;
?>
and that is the error:
ParseError: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in -
rules_php_eval() (line 2 -/web/maavarim/sites/all/modules/contrib/rules/modules/php.eval.inc(125) : eval()'d code)
can anyonw know what to do?
Try to implement your code as below
function mytheme_preprocess_page(&$vars, $hook) {
if (isset($vars['node']) && in_array($vars['node']->type, array('article', 'column'))) {
// Set header to topic for articles and columns
// #TODO: consider primary topic field (no multiselect), default to below if empty
$term = taxonomy_term_load($vars['node']->field_topic_ref[LANGUAGE_NONE][0]['tid']);
$vars['head_title'] = $term->name;
}
else {
$vars['head_title'] = $vars['title'];
}
}

Display a rounded count of Custom Post Type

I'd like display a rounded up count of the total number of custom post types.
Currently I am using this
<?php
$count_posts = wp_count_posts('listing');
$published_posts = $count_posts->publish;
echo $published_posts;
?>
but would like to round the number to nearest hundred, so for example,
if the count was 120 it would show 100
if the count was 158 it would show 200
if the count was 1088 it would show 1000
Thanks
This question not related to WordPress, but you will get solution by follow
PHP Custom functions: add into functions.php
if( !function_exists('ceiling') )
{
function ceiling($number, $significance = 1)
{
return ( is_numeric($number) && is_numeric($significance) ) ? (round($number/$significance)*$significance) : false;
}
}
if( !function_exists('ceilNumber') )
{
function ceilNumber($number)
{
return ceiling($number, (int)'1'.str_repeat('0', strlen($number)-1));
}
}
Call above function into your code
$count_posts = wp_count_posts('listing');
$published_posts = $count_posts->publish;
echo ceilNumber($published_posts);

GAPI google analytics

How can I get my events data from GA using gapi?
I have some sample code that retrieves "source" and "visits".
I want my events from a category called "Videos" with action called "Play", each having the file name as the label.
Here is my current working code for plain visits:
<?php
require 'gapi-1.3/gapi.class.php';
/* Set your Google Analytics credentials */
define('ga_account' ,'dadadadad');
define('ga_password' ,'adadadad');
define('ga_profile_id' ,'dadadadad');
$ga = new gapi(ga_account,ga_password);
/* We are using the 'source' dimension and the 'visits' metrics */
$dimensions = array('source');
$metrics = array('visits');
/* We will sort the result be desending order of visits,
and hence the '-' sign before the 'visits' string */
$ga->requestReportData(ga_profile_id, $dimensions, $metrics,'-visits');
$gaResults = $ga->getResults();
$i=1;
foreach($gaResults as $result)
{
printf("%-4d %-40s %5d\n",
$i++,
$result->getSource(),
$result->getVisits());
echo '<br/>';
}
echo "\n-----------------------------------------\n";
echo "Total Results : {$ga->getTotalResults()}";
?>
I was able to surmise what the function names would be.
This is working for me:
$ga = new gapi(ga_account,ga_password);
/* We are using the 'source' dimension and the 'visits' metrics */
$dimensions = array('eventLabel');
//$metrics = array('totalEvents','uniqueEvents','eventsPerVisitWithEvent');
$metrics = array('totalEvents');
$sort_metric = '-totalEvents';
/* We will sort the result be desending order of visits,
and hence the '-' sign before the 'visits' string */
$ga->requestReportData(ga_profile_id, $dimensions, $metrics,'-totalEvents');
$gaResults = $ga->getResults();
$i=1;
foreach($gaResults as $result)
{
printf("%-4d %-40s %5d\n",
$i++,
$result->getEventLabel(),
$result->getTotalEvents()/*,
//$result->getUniqueEvents(),
//$result->getEventsPerVisitWithEvent() */);
echo '<br/>';
}
echo "\n-----------------------------------------\n";
echo "Total Results : {$ga->getTotalResults()}";

Rename files during upload within Wordpress

I am trying to rename upload filenames match the Post Title.
This other thread shows how to rename to hash:
Rename files during upload within Wordpress backend
Using this code:
function make_filename_hash($filename) {
$info = pathinfo($filename);
$ext = empty($info['extension']) ? '' : '.' . $info['extension'];
$name = basename($filename, $ext);
return md5($name) . $ext;
}
add_filter('sanitize_file_name', 'make_filename_hash', 10);
Does anyone know the code to rename the file to match Post Title.extension?
barakadam's answer is almost correct, just a little correction based on the comment I left below his answer.
function new_filename($filename, $filename_raw) {
global $post;
$info = pathinfo($filename);
$ext = empty($info['extension']) ? '' : '.' . $info['extension'];
$new = $post->post_title . $ext;
// the if is to make sure the script goes into an indefinate loop
if( $new != $filename_raw ) {
$new = sanitize_file_name( $new );
}
return $new;
}
add_filter('sanitize_file_name', 'new_filename', 10, 2);
Explanation of code:
Lets assume you upload a file with the original filename called picture one.jpg to a post called "My Holiday in Paris/London".
When you upload a file, WordPress removes special characters from the original filename using the sanitize_file_name() function.
Right at the bottom of the function is where the filter is.
// line 854 of wp-includes/formatting.php
return apply_filters('sanitize_file_name', $filename, $filename_raw);
At this point, $filename would be picture-one.jpg. Because we used add_filter(), our new_filename() function will be called with $filename as picture-one.jpg and $filename_raw as picture one.jpg.
Our new_filename() function then replaces the filename with the post title with the original extension appended. If we stop here, the new filename $new would end up being My Holiday in Paris/London.jpg which all of us know is an invalid filename.
Here is when we call the sanitize_file_name function again. Note the conditional statement there. Since $new != $filename_raw at this point, it tries to sanitize the filename again.
sanitize_file_name() will be called and at the end of the function, $filename would be My-Holiday-in-Paris-London.jpg while $filename_raw would still be My Holiday in Paris/London.jpg. Because of the apply_filters(), our new_filename() function runs again. But this time, because $new == $filename_raw, thats where it ends.
And My-Holiday-in-Paris-London.jpg is finally returned.
Something like this? (considering $post is your post variable, make it global):
function new_filename($filename) {
global $post;
$info = pathinfo($filename);
$ext = empty($info['extension']) ? '' : '.' . $info['extension'];
return $post->post_title . $ext;
}
add_filter('sanitize_file_name', 'new_filename', 10);
Did I understand you?

Resources