/**
  * AJAX callback for assigning media ID fetched from media library to user
  */
 public function ajax_assign_simple_local_avatar_media()
 {
     // check required information and permissions
     if (empty($_POST['user_id']) || empty($_POST['media_id']) || !current_user_can('upload_files') || !current_user_can('edit_user', $_POST['user_id']) || empty($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'assign_simple_local_avatar_nonce')) {
         die;
     }
     $media_id = (int) $_POST['media_id'];
     $user_id = (int) $_POST['user_id'];
     // ensure the media is real is an image
     if (wp_attachment_is_image($media_id)) {
         $this->assign_new_user_avatar($media_id, $user_id);
     }
     if ($a_sizes = get_theme_support('simple_local_avatars_sizes')) {
         if (!empty($a_sizes[0]) && is_array($a_sizes[0])) {
             $a_sizes = $a_sizes[0];
         }
         foreach ((array) $a_sizes as $a_size) {
             echo '<div style="display:table-cell">';
             echo get_simple_local_avatar($user_id, $a_size);
             get_simple_local_avatar($user_id, intval($a_size) * 2);
             echo '</div>';
         }
     } else {
         echo get_simple_local_avatar($user_id);
     }
     die;
 }
 /**
  * AJAX callback for assigning media ID fetched from media library to user
  */
 public function ajax_assign_simple_local_avatar_media()
 {
     // check required information and permissions
     if (empty($_POST['user_id']) || empty($_POST['media_id']) || !current_user_can('upload_files') || !current_user_can('edit_user', $_POST['user_id']) || empty($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'assign_simple_local_avatar_nonce')) {
         die;
     }
     $media_id = (int) $_POST['media_id'];
     $user_id = (int) $_POST['user_id'];
     // ensure the media is real is an image
     if (wp_attachment_is_image($media_id)) {
         $this->assign_new_user_avatar($media_id, $user_id);
     }
     echo get_simple_local_avatar($user_id);
     die;
 }
Beispiel #3
0
 public function update_messages_ajax_handler()
 {
     global $wpdb;
     $quick_chat_messages_table_name = $wpdb->prefix . 'quick_chat_messages';
     ob_start();
     header("Content-Type: application/json");
     header("Cache-Control: no-cache, must-revalidate");
     header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
     $rooms = implode('", "', esc_sql((array) $_POST['rooms']));
     $startTime = time();
     while (time() - $startTime <= 20) {
         $sql = 'SELECT id, wpid, room, timestamp, UNIX_TIMESTAMP(timestamp) AS unix_timestamp, alias, status, message FROM ' . $quick_chat_messages_table_name . ' WHERE room IN ("' . $rooms . '") ' . ' AND timestamp > FROM_UNIXTIME(' . esc_sql($_POST['last_timestamp']) . ') ' . ' ORDER BY unix_timestamp ASC';
         $messages = $wpdb->get_results($sql);
         if ($messages) {
             foreach ($messages as $v) {
                 $v->timestring = date_i18n($this->date_format . ' - ' . $this->time_format, $v->unix_timestamp + $this->gmt_offset);
                 if (function_exists('get_simple_local_avatar')) {
                     $v->avatar = get_simple_local_avatar($v->wpid, $this->options['avatar_size'], '', $v->alias);
                 } else {
                     $v->avatar = get_avatar($v->wpid, $this->options['avatar_size'], '', $v->alias);
                 }
             }
             $response = json_encode(array('no_participation' => $this->no_participation, 'success' => 1, 'messages' => $messages));
             echo $response;
             ob_flush();
             flush();
             exit;
         } else {
             sleep($this->options['timeout_refresh_messages']);
         }
     }
     $response = json_encode(array('no_participation' => $this->no_participation, 'success' => 0));
     echo $response;
     ob_flush();
     flush();
     exit;
 }
Beispiel #4
0
<?php

$author_id = get_the_author_meta('ID');
if ($author_id !== '') {
    $author = get_userdata($author_id);
    $author_name = $author->data->display_name;
    $author_nice_name = $author->data->user_nicename;
    $author_profile_url = home_url() . '/author/' . $author_nice_name;
    $author_avatar = get_simple_local_avatar($author_id, 120, 'http://assets.tumblr.com/images/default_avatar_128.png', 'author-avatar');
    $author_avatar = get_simple_local_avatar($author_id, 120, 'http://assets.tumblr.com/images/default_avatar_128.png', 'author-avatar');
    $author_description = get_the_author_meta('description', $author_id);
    $author_website = $author->data->user_url;
    $author_twitter = get_user_meta($author_id, 'twitter', true);
    $author_facebook = get_user_meta($author_id, 'face', true);
    $author_gplus = get_user_meta($author_id, 'gplus', true);
    $author_youtube = get_user_meta($author_id, 'youtube', true);
    $author_pinterest = get_user_meta($author_id, 'pinterest', true);
    $author_instagram = get_user_meta($author_id, 'instagram', true);
    $author_rss = get_user_meta($author_id, 'rss', true);
    ?>
		
		<div class="post-author">
			<div class="author-image">
				<a href="<?php 
    echo $author_profile_url;
    ?>
" title="<?php 
    _e('A szerzőről:', THEME_DOMAIN);
    echo esc_attr($author_name);
    ?>
 " rel="author"><?php 
 //usort sorts our $users array with our function cmp()
 usort($users, 'cmp');
 $first = true;
 for ($i = 0; $i < sizeof($users); $i++) {
     $u = $users[$i];
     $disp = get_user_meta($u->ID, "no_display_user", true);
     if ($disp != "1") {
         if ($first == false) {
             $html .= "<div class='author_sep'></div>";
         } else {
             $first = false;
         }
         $html .= "<div class='author' id='member-" . $u->ID . "'>";
         $html .= "<div class='author_avatar'>";
         $html .= "";
         $html .= get_simple_local_avatar($u->ID, '75', '', false, false);
         $html .= "";
         $html .= "</div>";
         $html .= "<div class='author_infos'>";
         $html .= "<a href='" . $u->user_url . "' target='_blank'><h3>" . $u->display_name . "</h3></a>";
         $datas = get_userdata($u->ID);
         $html .= "<h5>" . str_replace("\n", "<br />", $datas->user_description) . "</h5>";
         $more = false;
         $html .= "<div id='member-infos-" . $u->ID . "' class='author_more_infos'>";
         $last_run = get_user_meta($u->ID, "last_run", true);
         if (!empty($last_run)) {
             $more = true;
             $html .= "<b>Ses derni&egrave;res courses :</b><br /><br />";
             $html .= str_replace("\n", "<br />", $last_run);
             $html .= "<br /><br /><br />";
         }
function sp_UserAvatar($args = '', $contextData = '')
{
    global $spThisUser;
    $defs = array('tagClass' => 'spAvatar', 'imgClass' => 'spAvatar', 'size' => '', 'link' => 'profile', 'context' => 'current', 'wp' => '', 'echo' => 1, 'get' => 0);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_Avatar_args', $a);
    extract($a, EXTR_SKIP);
    # sanitize before use
    $tagClass = esc_attr($tagClass);
    $imgClass = esc_attr($imgClass);
    $link = esc_attr($link);
    $size = (int) $size;
    $echo = (int) $echo;
    $get = (int) $get;
    $wp = esc_attr($wp);
    # init some vars
    $forceWidth = false;
    # make sure we are displaying avatars
    $spAvatars = sp_get_option('sfavatars');
    if ($spAvatars['sfshowavatars'] == true) {
        $avatarData = new stdClass();
        $avatarData->object = false;
        $avatarData->userId = 0;
        # need user id OR email
        $avatarData->email = '';
        $avatarData->avatar = '';
        $avatarData->admin = '';
        # determine avatar size
        $avatarData->size = !empty($size) ? $size : $spAvatars['sfavatarsize'];
        # get the appropriate user id and email address
        switch ($context) {
            case 'current':
                # we want the avatar for the current user
                global $spThisUser;
                $avatarData->userId = $spThisUser->ID;
                $avatarData->email = !empty($avatarData->userId) ? $spThisUser->user_email : '';
                break;
            case 'user':
                # determine if we have user object, id or email address
                if (is_object($contextData)) {
                    # sp user object passed in
                    # can contain anything, but must contain id or email, avatar array and admin flag
                    $avatarData->object = true;
                    $avatarData->userId = $contextData->ID;
                    $avatarData->avatar = $contextData->avatar;
                    $avatarData->admin = $contextData->admin;
                    # get email address handling sp user objects with type of guest
                    if ($contextData instanceof spUser && $contextData->guest) {
                        $avatarData->email = $contextData->guest_email;
                    } else {
                        $avatarData->email = $contextData->user_email;
                    }
                } else {
                    if (is_numeric($contextData)) {
                        # user id passed in
                        $user = get_userdata((int) $contextData);
                    } else {
                        # email address passed in
                        $user = get_user_by('email', sp_esc_str($contextData));
                    }
                    if ($user) {
                        $avatarData->userId = $user->ID;
                        $avatarData->email = $user->user_email;
                    }
                }
                break;
            default:
                # allow themes/plugins to add new avatar user types
                $avatarData = apply_filters('sph_Avatar_' . $context, $avatarData, $a);
                break;
        }
        # loop through prorities until we find an avatar to use
        foreach ($spAvatars['sfavatarpriority'] as $priority) {
            switch ($priority) {
                case 0:
                    # Gravatars
                    if (function_exists('sp_get_gravatar_cache_url')) {
                        $avatarData->url = sp_get_gravatar_cache_url(strtolower($avatarData->email), $avatarData->size);
                        if (empty($avatarData->url)) {
                            $gravatar = false;
                        } else {
                            $gravatar = true;
                            $forceWidth = true;
                            # force width to request since we only cache one size
                        }
                    } else {
                        $rating = $spAvatars['sfgmaxrating'];
                        switch ($rating) {
                            case 1:
                                $grating = 'g';
                                break;
                            case 2:
                                $grating = 'pg';
                                break;
                            case 3:
                                $grating = 'r';
                                break;
                            case 4:
                            default:
                                $grating = 'x';
                                break;
                        }
                        $avatarData->url = 'http://www.gravatar.com/avatar/' . md5(strtolower($avatarData->email)) . "?d=404&size={$avatarData->size}&rating={$grating}";
                        # Is there an gravatar?
                        $headers = wp_get_http_headers($avatarData->url);
                        if (!is_array($headers)) {
                            $gravatar = false;
                        } elseif (isset($headers['content-disposition'])) {
                            $gravatar = true;
                        } else {
                            $gravatar = false;
                        }
                    }
                    # ignore gravatar blank images
                    if ($gravatar == true) {
                        break 2;
                        # if actual gravatar image found, show it
                    }
                    break;
                case 1:
                    # WP avatars
                    # if wp avatars being used, handle slightly different since we get image tags
                    $avatar = "<div class='{$tagClass}'>";
                    if (!empty($wp)) {
                        $avatar .= sp_build_avatar_display($avatarData->userId, $wp, $link);
                    } else {
                        if ($avatarData->userId) {
                            $avatarData->email = $avatarData->userId;
                        }
                        $size = $link == 'profile' ? $avatarData->size : 96;
                        $avatar .= sp_build_avatar_display($avatarData->userId, get_simple_local_avatar($avatarData->email, $size), $link);
                    }
                    $avatar .= '</div>';
                    if ($get) {
                        return $avatarData;
                    }
                    # for wp avatars, we need to display/return and bail
                    if (empty($echo)) {
                        return $avatar;
                    } else {
                        echo $avatar . "\n";
                        return;
                    }
                case 2:
                    # Uploaded avatars
                    $userAvatar = $avatarData->avatar;
                    if (empty($userAvatar) && !empty($avatarData->userId) && isset($spThisUser)) {
                        $userAvatar = $avatarData->userId == $spThisUser->ID ? $spThisUser->avatar : sp_get_member_item($avatarData->userId, 'avatar');
                    }
                    if (!empty($userAvatar['uploaded'])) {
                        $avfile = $userAvatar['uploaded'];
                        $avatarData->url = SFAVATARURL . $avfile;
                        if (file_exists(SFAVATARDIR . $avfile)) {
                            $avatarData->path = SFAVATARDIR . $avfile;
                            break 2;
                            # if uploaded avatar exists, show it
                        }
                    }
                    break;
                case 3:
                    # SPF default avatars
                # SPF default avatars
                default:
                    if (empty($avatarData->userId)) {
                        $image = 'guestdefault.png';
                    } else {
                        if ($avatarData->object) {
                            $image = $avatarData->admin ? 'admindefault.png' : 'userdefault.png';
                        } else {
                            $image = sp_is_forum_admin($avatarData->userId) ? 'admindefault.png' : 'userdefault.png';
                        }
                    }
                    $avatarData->url = SFAVATARURL . $image;
                    $avatarData->path = SFAVATARDIR . $image;
                    break 2;
                    # defaults, so show it
                # defaults, so show it
                case 4:
                    # Pool avatars
                    $userAvatar = $avatarData->avatar;
                    if (empty($userAvatar) && !empty($avatarData->userId) && isset($spThisUser)) {
                        $userAvatar = $avatarData->userId == $spThisUser->ID ? $spThisUser->avatar : sp_get_member_item($avatarData->userId, 'avatar');
                    }
                    if (!empty($userAvatar['pool'])) {
                        $pavfile = $userAvatar['pool'];
                        $avatarData->url = SFAVATARPOOLURL . $pavfile;
                        if (file_exists(SFAVATARPOOLDIR . $pavfile)) {
                            $avatarData->path = SFAVATARPOOLDIR . $pavfile;
                            break 2;
                            # if pool avatar exists, show it
                        }
                    }
                    break;
                case 5:
                    # Remote avatars
                    $userAvatar = $avatarData->avatar;
                    if (empty($userAvatar) && !empty($avatarData->userId) && isset($spThisUser)) {
                        $userAvatar = $avatarData->userId == $spThisUser->ID ? $spThisUser->avatar : sp_get_member_item($avatarData->userId, 'avatar');
                    }
                    if (!empty($userAvatar['remote'])) {
                        $ravfile = $userAvatar['remote'];
                        $avatarData->url = $ravfile;
                        # see if file exists
                        $response = wp_remote_get($avatarData->url);
                        if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) == 200) {
                            $avatarData->path = $avatarData->url;
                            break 2;
                            # if remote avatar exists, show it
                        }
                    }
                    break;
            }
        }
        # allow themes/plugins to filter the final avatar data
        $avatarData = apply_filters('sph_Avatar', $avatarData, $a);
        if ($get) {
            return $avatarData;
        }
        # now display the avatar
        $width = $forceWidth ? " width='{$avatarData->size}'" : "";
        $maxwidth = $avatarData->size > 0 ? " style='max-width: {$avatarData->size}px'" : '';
        $avatar = sp_build_avatar_display($avatarData->userId, "<img src='" . esc_url($avatarData->url) . "' class='{$imgClass}'{$width}{$maxwidth} alt='' />", $link);
        $avatar = "<div class='{$tagClass}'>{$avatar}</div>\n";
        if ($echo) {
            echo $avatar;
        } else {
            return $avatar;
        }
    }
}
function rss_parsing_rss($nb)
{
    $rss_tab = array();
    $date_tab = array();
    $flux = array();
    $images = array();
    $images_def = array();
    $ids = array();
    $args = array('exclude' => array(), 'orderby' => 'login', 'order' => 'ASC', 'fields' => 'all');
    $users = get_users($args);
    foreach ($users as $usr) {
        $uid = $usr->ID;
        if (get_user_meta($uid, "rss_active", true) == "1") {
            //Admin enable this RSS
            $rss = get_user_meta($uid, "rss_address", true);
            if (!empty($rss)) {
                $flux[] = stripslashes($rss);
                $images[] = 1;
                $images_def[] = get_simple_local_avatar($uid, '96', '', false, true);
                $ids[] = $uid;
            }
        }
    }
    $html = "";
    $n = 1;
    for ($j = 0; $j < sizeof($flux); $j++) {
        $error = 0;
        $rss_web = dirname(__FILE__) . "/cron/xml_v2/rss-" . $ids[$j] . ".xml";
        if (!file_exists($rss_web)) {
            $error = 1;
        } else {
            if (!@($fluxrss = simplexml_load_file($rss_web, 'SimpleXMLElement', LIBXML_NOCDATA))) {
                $error = 1;
            }
            if (@file_get_contents($rss_web) == "") {
                $error = 1;
            }
        }
        if (empty($fluxrss->channel->title) || empty($fluxrss->channel->item->title)) {
            $error = 1;
        }
        if ($error == 0) {
            $i = 0;
            $rss_item = array();
            foreach ($fluxrss->channel->item as $item) {
                $i++;
                if ($i <= $nb) {
                    $rss_item = array();
                    $rss_item['blog_title'] = '' . $fluxrss->channel->title;
                    $rss_item['blog_link'] = '' . $fluxrss->channel->link;
                    $rss_item['title'] = '' . $item->title;
                    $rss_item['link'] = '' . $item->link;
                    $rss_item['description'] = '' . truncate_str(strip_tags('' . $item->description), 0, 300, $item->link);
                    $rss_item['date'] = date(get_option('date_format'), strtotime($item->pubDate));
                    $rss_item['pub_date'] = '' . $item->pubDate . ' +0000';
                    //enclosure !
                    if ('' . $item->enclosure[0]['url'] != '') {
                        $rss_item['enclosure'] = '' . $item->enclosure[0]['url'];
                    } else {
                        $rss_item['enclosure'] = $images_def[$j];
                    }
                    $rss_tab[] = $rss_item;
                    $index = sizeof($rss_tab) - 1;
                    $date_tab[strtotime($item->pubDate)] = $index;
                }
            }
        }
    }
    krsort($date_tab);
    //GO TO FLUX RSS
    $page = get_page_by_path('blogs-de-runners');
    $page_link = get_page_link($page->ID);
    $page_title = $page->post_title;
    $html .= '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>';
    $html .= '<channel>';
    $html .= '<title>' . get_bloginfo('title') . ' - ' . $page_title . '</title>';
    $html .= '<atom:link href="' . get_bloginfo('url') . '/runners-rss/' . '" rel="self" type="application/rss+xml" />';
    $html .= '<link>' . $page_link . '</link>';
    $html .= '<description>Le flux RSS des blogs de la runnosphère</description>';
    $html .= '<lastBuildDate>' . date("D, d M Y H:i:s") . ' +0000</lastBuildDate>';
    $html .= '<language>fr</language>';
    $html .= '<sy:updatePeriod>hourly</sy:updatePeriod> ';
    $html .= '<sy:updateFrequency>1</sy:updateFrequency>';
    $html .= '';
    $html .= '';
    foreach ($date_tab as $d => $id) {
        $my_item = $rss_tab[$id];
        $html .= '<item>';
        $html .= '<title><![CDATA[' . $my_item['blog_title'] . ' - ' . str_replace("&", "&#x26;", $my_item['title']) . ']]></title>';
        $html .= '<link>' . str_replace("&", "&amp;", $my_item['link']) . '</link>';
        $html .= '<guid isPermaLink="true">' . str_replace("&", "&amp;", $my_item['link']) . '</guid>';
        $html .= '<description><![CDATA[' . $my_item['description'] . ']]></description>';
        $date_base = $my_item['pub_date'];
        $new = date("D, d M Y H:i:s", strtotime($date_base)) . ' +0000';
        $html .= '<pubDate>' . $new . '</pubDate>';
        //Enclosure
        if ($my_item['enclosure'] != '') {
            $t = explode(".", $my_item['enclosure']);
            $ext = $t[sizeof($t) - 1];
            if ($ext == 'jpg') {
                $ext = "jpeg";
            }
            //TODO : Length for image
            $html .= '<enclosure url="' . str_replace("https", "http", $my_item['enclosure']) . '" type="image/' . $ext . '"></enclosure>';
        }
        $html .= '</item>';
        $n++;
    }
    $html .= '</channel></rss>';
    return $html;
}