DIY মিডিয়া হোম লোগো

আপনার নিজের হোম থিয়েটার এবং হাই ফাই সেটআপ নকশা ও নির্মাণের জন্য চূড়ান্ত সাইট.

0ওয়ার্ডপ্রেস স্থানীয় Gravatar ক্যাশে

আমি মানুষের জন্য দেখানো অবতার আমার ব্লগে মন্তব্য যারা করে দিন. ওয়ার্ডপ্রেস সমর্থন Gravatar সেবা নেটিভ তাই সক্রিয় এই খুব সহজ. তবে এটি একটি খরচ দিয়ে আসে - অন্য ডোমেন থেকে বহিরাগত ফাইল অ্যাক্সেস নতুন আকারে অতিরিক্ত লোড সময় প্রচুর যোগ ডিএনএস লুক-, নতুন SSL এর সংযোগ করতে, ইত্যাদি. Would­n’t it be nice to have gravatars stored loc­ally and served from your own serv­er. ভাল যে আমি এখন কিছু সময়ের জন্য কাজ করা হয়েছে করেছি, আপনাকে জানতে হবে কিভাবে চান তাহলে, পড়তে…

In case you’re still won­der­ing just why you’d want to do this, let me offer a few more bene­fits — images served loc­ally can be com­pressed before serving them, for example ‑all my images are con­ver­ted into webp ver­sions, and any browser which sup­ports webp gets the webp ver­sion. This is in addi­tion to the reduc­tion from not hav­ing to con­nect to an extern­al serv­er. The loc­al resources can also have a cach­ing head­er set on them so that browsers will cache them. Gravatar does­n’t provide for a very long cache time.

I have cre­ated 3 cus­tom func­tions, যা আমি কেবল আমার থিমের থিমের functions.php স্থান. The first is a cus­tom fil­ter for the nat­ive word­press get_avatar(). Gravatar এবং Google থেকে দ্বিতীয় দখল অবতার যখন প্রতি আহ্বান, and the third cre­ates a daily cronjob which refreshes the gravatars — in case they’ve been changed, or a pre­vi­ously unavail­able one is now available.

You will need to do a little bit of tinker­ing to make it com­pat­ible with your theme — I use the “bones” frame­work as you’ll notice in the 3rd func­tion I’ve reused some code that it provided. You will also need to cre­ate, or cus­tom­ise the path to store the gravatars, which in my case are stored in the theme folder in the sub­path “/library/images/gravatars/”

/*********************************************\
* স্থানীয় অবতার শুধুমাত্র ব্যবহার করতে get_avatar ফিল্টার *
\*********************************************/
ফাংশন bones_gravatar($অবতার, $id_or_email, $আকার, $ডিফল্ট, $Alt)
{
$root_path = get_template_directory_uri() . '/ গ্রন্থাগার / ছবি / গ্রাভাটার /';
$root_path_local = get_template_directory() . '/ গ্রন্থাগার / ছবি / গ্রাভাটার /';
$gravatar_path = $ root_path . 'Default_avatar';
$gravatar_path_hidpi = 'ডেটা-Gravatar-HiDPI ="'। $ Root_path . 'Default_avatar-hidpi.png"';

//shamelessly reuse original code to get the e-mail address

$email = '';
যদি ( is_numeric($id_or_email) )
{
$আইডি = (int- এ) $id_or_email;
$ব্যবহারকারী = get_userdata($দী);
যদি ( $ব্যবহারকারী ) $ই-মেইল = $ user->USER_EMAIL;
}
elseif ( is_object($id_or_email) )
{
// No avatar for pingbacks or trackbacks
$allowed_comment_types = apply_filters( 'Get_avatar_comment_types', শ্রেণীবিন্যাস( 'মন্তব্য' ) );
যদি ( ! খালি( $id_or_email->comment_type ) && ! in_array( $id_or_email->comment_type, (শ্রেণীবিন্যাস) $allowed_comment_types ) ) মিথ্যা ফিরে;
যদি ( !খালি($id_or_email->ব্যবহারকারী আইডি) )
{
$আইডি = (int- এ) $id_or_email->ব্যবহারকারী আইডি;
$ব্যবহারকারী = get_userdata($দী);
যদি ( $ব্যবহারকারী) $ই-মেইল = $ user->USER_EMAIL;
}
elseif ( !খালি($id_or_email->comment_author_email) )
{
$ই-মেইল = $ id_or_email->comment_author_email;
}
}
অন্যথায়
{
$ই-মেইল = $ id_or_email;
}

যদি ( !খালি($ই-মেইল) )
{
$email_hash = MD5( strtolower( ছাঁটা( $ই-মেইল ) ) );
যদি(ফাইলটি আছে($root_path_local . $email_hash . '.png'))
{
//if we have a local cache then use it
$gravatar_path= $root_path . $email_hash ;
$gravatar_path_hidpi = 'ডেটা-Gravatar-HiDPI ="'। $ Root_path . $email_hash . '-hidpi.png"';
}
}
যদি($আকার >= 47) $অবতার = '<চিত্র শ্রেণী ="লোড Gravatar অবতার অবতার - '। $ আকার।' ছবি" প্রস্থ ="'। $ আকার।'" উচ্চতা ="'। $ আকার।'" src ="' . $gravatar_path . '-hidpi.png" Alt ="Gravatar" />';
অন্য $ অবতার = '<চিত্র শ্রেণী ="লোড Gravatar অবতার অবতার - '। $ আকার।' ছবি" প্রস্থ ="'। $ আকার।'" উচ্চতা ="'। $ আকার।'" src ="' . $gravatar_path . '.png" Alt ="Gravatar" ' . $gravatar_path_hidpi . '/>';

রিটার্ন $ অবতার;
}

add_filter('Get_avatar', 'Bones_gravatar', 10, 5);






/***********************\
* Gravatar ক্যাশে তৈরি করুন *
\***********************/
ফাংশন grab_avatar($comment_id,$মন্তব্য,$= মিথ্যা রিফ্রেশ,$ই-মেইল = '')
{
তুমি ঘুমাও(20);
$root_path = get_template_directory_uri() . '/ গ্রন্থাগার / ছবি / গ্রাভাটার /';
$root_path_local = get_template_directory() . '/ গ্রন্থাগার / ছবি / গ্রাভাটার /';
যদি($== মিথ্যা রিফ্রেশ) $img_name = MD5( get_comment_author_email($comment_id) );
অন্য $ img_name MD5 =( $ই-মেইল );
যদি(!ফাইলটি আছে($root_path_local . $img_name . '.png') || $== সত্য রিফ্রেশ)
{
যদি($== মিথ্যা রিফ্রেশ) $bgauthemail = get_comment_author_email();
অন্য $ bgauthemail = $ ইমেল;
//try google first
$domain= explode("@",$bgauthemail);
যদি($ডোমেইন[1]=="gmail.com")
{
$CH = curl_init();
curl_setopt($সিএইচ, CURLOPT_SSL_VERIFYPEER, মিথ্যা);
curl_setopt($সিএইচ, CURLOPT_RETURNTRANSFER, true);
curl_setopt($সিএইচ, CURLOPT_URL, "https://picasaweb.google.com/data/entry/api/user/" . $bgauthemail . "?Alt = JSON");
$ফলাফলের = curl_exec($সিএইচ);
curl_close($সিএইচ);

$obj = json_decode($ফল,true);
$avatar_from_gmail = $ obj['এন্ট্রি']["GPhoto $ থাম্বনেল"]['$ T'];

$এক্সটেনশন = strrchr($avatar_from_gmail, '।');

$CH = curl_init($avatar_from_gmail);
curl_setopt( $সিএইচ, CURLOPT_NOBODY, true );
curl_setopt( $সিএইচ, CURLOPT_RETURNTRANSFER, মিথ্যা );
curl_setopt( $সিএইচ, CURLOPT_HEADER, মিথ্যা );
curl_setopt( $সিএইচ, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $সিএইচ, CURLOPT_MAXREDIRS, 3 );
curl_exec( $সিএইচ );
$হেডার = curl_getinfo( $সিএইচ );
curl_close( $সিএইচ );
যদি($হেডার['Http_code'] === 200)
{
$CH = curl_init($avatar_from_gmail);
$FP = হয় fopen($root_path_local . $img_name . '-hidpi' . $প্রসার, 'WB');
curl_setopt($সিএইচ,CURLOPT_USERAGENT,'মোজিলা / 5.0 (উইন্ডোজ এনটি 6.1; Win64; x64) AppleWebKit / 537,36 (KHTML অত্যন্ত, গেকো মত) ক্রোম / 39.0.2171.62 সাফারি / 537,36 ');
curl_setopt($সিএইচ, CURLOPT_FILE, $FP);
curl_setopt($সিএইচ, CURLOPT_HEADER, 0);

curl_exec($সিএইচ);
curl_close($সিএইচ);

fclose সাথে($FP);

$usegravatar = মিথ্যা;

$small_image = wp_get_image_editor($root_path_local . $img_name . '-hidpi' . $প্রসার);
যদি ( ! is_wp_error( $small_image ) )
{
//পরীক্ষা এটা একটি ফাঁকা মানুষ চিত্র নয়, যদি তাই, delete it
if (md5_file($root_path_local . $img_name . '-hidpi.jpg') == strtolower("686E5C46776BA0E5C488853C1C0B492C"))
{
//delete
unlink($root_path_local . $img_name . '-hidpi.jpg');
//try gravatar
$usegravatar=true;
}
অন্যথায় যদি (md5_file($root_path_local . $img_name . '-hidpi.jpg') == strtolower("6D4083BE95FB32358A5110F5A83B9979"))
{
//delete
unlink($root_path_local . $img_name . '-hidpi.jpg');
//try gravatar
$usegravatar=true;
}
অন্যথায়
{
//always convert to png because some plugins expect all gravatars to be pngs
$small_image->রক্ষা($root_path_local . $img_name . '-hidpi.png','Image / jpeg');
$small_image->মাপ পরিবর্তন(40, 40, true);
$small_image->set_quality( 10 );
$small_image->রক্ষা($root_path_local . $img_name . '.png','Image / jpeg');
যদি($এক্সটেনশন ==".JPG") লিঙ্কমুক্ত($root_path_local . $img_name . '-hidpi.jpg');
}
}
}

}
//check e-mail isnt a blank generic one
else if($bgauthemail!=="noemail@intensedebate.com" || $usegravatar == সত্য)
{
$avatar_from_gravatar = "https://www.gravatar.com/avatar/" . $img_name . "?গুলি = 80&D = 404";
$CH = curl_init($avatar_from_gravatar);
curl_setopt( $সিএইচ, CURLOPT_NOBODY, true );
curl_setopt( $সিএইচ, CURLOPT_RETURNTRANSFER, মিথ্যা );
curl_setopt( $সিএইচ, CURLOPT_HEADER, মিথ্যা );
curl_setopt( $সিএইচ, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $সিএইচ, CURLOPT_MAXREDIRS, 3 );
curl_exec( $সিএইচ );
$হেডার = curl_getinfo( $সিএইচ );
curl_close( $সিএইচ );
যদি($হেডার['Http_code'] === 200)
{
$CH = curl_init($avatar_from_gravatar);
$FP = হয় fopen($root_path_local . $img_name . '-hidpi.png', 'WB');
curl_setopt($সিএইচ,CURLOPT_USERAGENT,'মোজিলা / 5.0 (উইন্ডোজ এনটি 6.1; Win64; x64) AppleWebKit / 537,36 (KHTML অত্যন্ত, গেকো মত) ক্রোম / 39.0.2171.62 সাফারি / 537,36 ');
curl_setopt($সিএইচ, CURLOPT_FILE, $FP);
curl_setopt($সিএইচ, CURLOPT_HEADER, 0);

curl_exec($সিএইচ);
curl_close($সিএইচ);

fclose সাথে($FP);

$small_image = wp_get_image_editor($root_path_local . $img_name . '-hidpi.png');
যদি ( ! is_wp_error( $small_image ) )
{
$small_image->মাপ পরিবর্তন(40, 40, true);
$small_image->রক্ষা($root_path_local . $img_name . '.png');
}
}
}
}
}
ADD_ACTION('Wp_insert_comment', 'Grab_avatar');






/********************************************\
* ব্যাকগ্রাউন্ডে Gravatar ক্যাশে রিফ্রেশ দৈনন্দিন *
\********************************************/
ADD_ACTION( 'WP', 'Bones_setup_schedule' );
ফাংশন bones_setup_schedule() {
যদি ( ! wp_next_scheduled( 'Bones_daily_event' ) ) {
wp_schedule_event( সময়(), 'দৈনিক', 'Bones_daily_event');
}
}

ADD_ACTION( 'Bones_daily_event', 'Bones_refresh_gravatars' );
ফাংশন bones_refresh_gravatars()
{
//get list of gravatars somehow
global $wpdb;
$comment_author_emails = $ wpdb->get_results( "স্বতন্ত্র নির্বাচন(comment_author_email) থেকে " . $wpdb->উপসর্গ . "মন্তব্য" );
প্রতিটির জন্য($$ কী-এর মত comment_author_emails => $Val)
{
প্রতিটির জন্য($Val $ হিসেবে => $খ)
{
grab_avatar('','',true,$খ);
}
}
}

উত্তর দিন