Пример #1
0
/**
 * Github Profile shortcode.
 * @param $atts
 * @return string
 */
function ghprofile_shortcode($atts)
{
    $a = shortcode_atts(array('username' => get_option('wpgithub_defaultuser', 'seinoxygen')), $atts);
    // Init the cache system.
    $cache = new WpGithubCache();
    // Set custom timeout in seconds.
    $cache->timeout = get_option('wpgithub_cache_time', 600);
    $profile = $cache->get($a['username'] . '.json');
    if ($profile == NULL) {
        $github = new Github($a['username']);
        $profile = $github->get_profile();
        $cache->set($a['username'] . '.json', $profile);
    }
    $html = '<div class="wpgithub-profile">';
    $html .= '<div class="wpgithub-user">';
    $html .= '<a class="wp-github-gravatar" target="_blank" href="' . $profile->html_url . '" title="View ' . $a['username'] . '\'s Github"><img width="80" src="' . $profile->avatar_url . '" alt="View ' . $a['username'] . '\'s Github" /></a>';
    $html .= '<div class="wp-github-usr">';
    $html .= '<h3 class="wpgithub-username"><a href="' . $profile->html_url . '" title="View ' . $a['username'] . '\'s Github">' . $a['username'] . '</a></h3>';
    $html .= '<p class="wpgithub-name">' . $profile->name . '</p>';
    $html .= '<p class="wpgithub-location">' . $profile->location . '</p>';
    $html .= '</div></div>';
    $html .= '<a target="_blank" class="wpgithub-bblock" href="https://github.com/' . $a['username'] . '?tab=repositories"><span class="wpgithub-count">' . $profile->public_repos . '</span><span class="wpgithub-text">Public Repos</span></a>';
    $html .= '<a target="_blank" class="wpgithub-bblock" href="https://gist.github.com/' . $a['username'] . '"><span class="wpgithub-count">' . $profile->public_gists . '</span><span class="wpgithub-text">Public Gists</span></a>';
    $html .= '<a target="_blank" class="wpgithub-bblock" href="https://github.com/' . $a['username'] . '/followers"><span class="wpgithub-count">' . $profile->followers . '</span><span class="wpgithub-text">Followers</span></a>';
    $html .= '</div>';
    return $html;
}
Пример #2
0
 function widget($args, $instance)
 {
     extract($args);
     $title = $this->get_title($instance);
     $username = $this->get_username($instance);
     echo $before_widget;
     echo $before_title . $title . $after_title;
     // Init the cache system.
     $cache = new Cache();
     // Set custom timeout in seconds.
     $cache->timeout = get_option('wpgithub_cache_time', 600);
     $profile = $cache->get($username . '.json');
     if ($profile == null) {
         $github = new Github($username);
         $profile = $github->get_profile();
         $cache->set($username . '.json', $profile);
     }
     echo '<div class="wpgithub-profile">';
     echo '<div class="wpgithub-user">';
     echo '<a href="' . $profile->html_url . '" title="View ' . $username . '\'s Github"><img src="//gravatar.com/avatar/' . $profile->gravatar_id . '?s=56" alt="View ' . $username . '\'s Github" /></a>';
     echo '<h3 class="wpgithub-username"><a href="' . $profile->html_url . '" title="View ' . $username . '\'s Github">' . $username . '</a></h3>';
     echo '<p class="wpgithub-name">' . $profile->name . '</p>';
     echo '<p class="wpgithub-location">' . $profile->location . '</p>';
     echo '</div>';
     echo '<a class="wpgithub-bblock" href="https://github.com/' . $username . '?tab=repositories"><span class="wpgithub-count">' . $profile->public_repos . '</span><span class="wpgithub-text">Public Repos</span></a>';
     echo '<a class="wpgithub-bblock" href="https://gist.github.com/' . $username . '"><span class="wpgithub-count">' . $profile->public_gists . '</span><span class="wpgithub-text">Public Gists</span></a>';
     echo '<a class="wpgithub-bblock" href="https://github.com/' . $username . '/followers"><span class="wpgithub-count">' . $profile->followers . '</span><span class="wpgithub-text">Followers</span></a>';
     echo '</div>';
     echo $after_widget;
 }