DIY وسائل الإعلام الرئيسية الشعار

الموقع النهائي لتصميم وإنشاء مسرح منزلي الخاص ومرحبا فاي الإعداد الخاصة.

0ورد مخبأ غرفتر المحلي

أحب أن يكون الآلهة يظهر للأشخاص الذين التعليق على بلدي بلوق. وورد يدعم خدمة غرفتر أصلا حتى تمكن هذا أمر سهل جدا. ولكن لأنه يأتي مع التكلفة - الوصول إلى الملفات الخارجية من مجال آخر يضيف الكثير من وقت التحميل الإضافي في شكل جديد DNS عمليات البحث, جديد 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(). العناوين الرئيسية للصحف الآلهة الثانية من غرفتر وجوجل عندما يطلب منها ذلك, 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 3بحث وتطوير 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, $بحجم, $الافتراضي, $بديل)
{
$root_path = get_template_directory_uri() . '/ مكتبة / صور / gravatars /';
$root_path_local = get_template_directory() . '/ مكتبة / صور / gravatars /';
$gravatar_path = $ root_path . "default_avatar";
$gravatar_path_hidpi = 'بيانات غرفتر-hidpi =". $ root_path . "default_avatar-hidpi.png"';

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

$email = '';
إذا ( is_numeric($id_or_email) )
{
$معرف = (الباحث) $id_or_email;
$المستخدم = get_userdata($هوية شخصية);
إذا ( $المستعمل ) $البريد الإلكتروني = $ من قبل المستخدم>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->معرف المستخدم) )
{
$معرف = (الباحث) $id_or_email->معرف المستخدم;
$المستخدم = get_userdata($هوية شخصية);
إذا ( $المستعمل) $البريد الإلكتروني = $ من قبل المستخدم>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 . "بابوا نيو غينيا"))
{
//if we have a local cache then use it
$gravatar_path= $root_path . $email_hash ;
$gravatar_path_hidpi = 'بيانات غرفتر-hidpi =". $ root_path . $email_hash . "-hidpi.png"';
}
}
إذا($بحجم >= 47) $الصورة الرمزية = '<IMG الطبقة ="الحمل غرفتر الصورة الرمزية الصورة الرمزية - '. حجم $ ". صورة فوتوغرافية" العرض =". $ حجم "." ارتفاع =". $ حجم "." SRC ="' . $gravatar_path . "-hidpi.png" بديل ="غرفتر" />';
آخر $ الصورة الرمزية = '<IMG الطبقة ="الحمل غرفتر الصورة الرمزية الصورة الرمزية - '. حجم $ ". صورة فوتوغرافية" العرض =". $ حجم "." ارتفاع =". $ حجم "." SRC ="' . $gravatar_path . "بابوا نيو غينيا" بديل ="غرفتر" ' . $gravatar_path_hidpi . '/>';

عودة $ الرمزية;
}

add_filter("get_avatar", "bones_gravatar", 10, 5);






/***********************\
* إنشاء مخبأ غرفتر *
\***********************/
وظيفة grab_avatar($comment_id,$التعليق,$تحديث = كاذبة,$البريد الإلكتروني = '')
{
انت نائم(20);
$root_path = get_template_directory_uri() . '/ مكتبة / صور / gravatars /';
$root_path_local = get_template_directory() . '/ مكتبة / صور / gravatars /';
إذا($تحديث == كاذبة) $img_name = MD5( get_comment_author_email($comment_id) );
آخر $ img_name = MD5( $البريد الإلكتروني );
إذا(!الملف موجود($root_path_local . $img_name . "بابوا نيو غينيا") || $تحديث == صحيح)
{
إذا($تحديث == كاذبة) $bgauthemail = get_comment_author_email();
آخر $ bgauthemail = $ البريد الإلكتروني;
//try google first
$domain= explode("@",$bgauthemail);
إذا($مجال[1]=="gmail.com")
{
$الفصل = curl_init();
curl_setopt($الفصل, CURLOPT_SSL_VERIFYPEER, خاطئة);
curl_setopt($الفصل, CURLOPT_RETURNTRANSFER, حقيقية);
curl_setopt($الفصل, CURLOPT_URL, "https://picasaweb.google.com/data/entry/api/user/" . $bgauthemail . "?بديل = سلمان");
$النتيجة = curl_exec($الفصل);
curl_close($الفصل);

$الكائنات = json_decode($نتيجة,حقيقية);
$avatar_from_gmail = $ الكائنات['دخول']["GPhoto $ المصغرة"]['$ ر'];

$تمديد = strrchr($avatar_from_gmail, '.');

$الفصل = curl_init($avatar_from_gmail);
curl_setopt( $الفصل, CURLOPT_NOBODY, حقيقية );
curl_setopt( $الفصل, CURLOPT_RETURNTRANSFER, خاطئة );
curl_setopt( $الفصل, CURLOPT_HEADER, خاطئة );
curl_setopt( $الفصل, CURLOPT_FOLLOWLOCATION, حقيقية );
curl_setopt( $الفصل, CURLOPT_MAXREDIRS, 3 );
curl_exec( $الفصل );
$رؤوس = curl_getinfo( $الفصل );
curl_close( $الفصل );
إذا($رؤوس["HTTP_CODE"] === 200)
{
$الفصل = curl_init($avatar_from_gmail);
$FP = الدالة fopen($root_path_local . $img_name . "-hidpi" . $تمديد, "البنك الدولي");
curl_setopt($الفصل,CURLOPT_USERAGENT,"موزيلا / 5.0 (ويندوز NT 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","صورة / بابوا نيو غينيا");
$small_image->تغيير(40, 40, حقيقية);
$small_image->set_quality( 10 );
$small_image->حفظ($root_path_local . $img_name . "بابوا نيو غينيا","صورة / بابوا نيو غينيا");
إذا($تمديد ==".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&د = 404";
$الفصل = curl_init($avatar_from_gravatar);
curl_setopt( $الفصل, CURLOPT_NOBODY, حقيقية );
curl_setopt( $الفصل, CURLOPT_RETURNTRANSFER, خاطئة );
curl_setopt( $الفصل, CURLOPT_HEADER, خاطئة );
curl_setopt( $الفصل, CURLOPT_FOLLOWLOCATION, حقيقية );
curl_setopt( $الفصل, CURLOPT_MAXREDIRS, 3 );
curl_exec( $الفصل );
$رؤوس = curl_getinfo( $الفصل );
curl_close( $الفصل );
إذا($رؤوس["HTTP_CODE"] === 200)
{
$الفصل = curl_init($avatar_from_gravatar);
$FP = الدالة fopen($root_path_local . $img_name . "-hidpi.png", "البنك الدولي");
curl_setopt($الفصل,CURLOPT_USERAGENT,"موزيلا / 5.0 (ويندوز NT 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, حقيقية);
$small_image->حفظ($root_path_local . $img_name . "بابوا نيو غينيا");
}
}
}
}
}
ADD_ACTION("wp_insert_comment", "grab_avatar");






/********************************************\
* تحديث مخبأ غرفتر في الخلفية يوميا *
\********************************************/
ADD_ACTION( "الفسفور الابيض", "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->الحصول على النتائج( "SELECT DISTINCT(comment_author_email) من عند " . $wpdb->اختصار . "تعليقات" );
foreach($comment_author_emails كمفتاح $ => $فال)
{
foreach($فال من $ A => $ب)
{
grab_avatar('','',حقيقية,$ب);
}
}
}

اترك رد