Пример #1
0
function renrenFetch($renrenURL = 'fdoings.html')
{
    $html = file_get_html($renrenURL);
    $ariticle_list = array();
    foreach ($html->find('div.p-status-content dl') as $element) {
        $ariticle_data = array('aid' => '', 'content' => '', 'img' => '', 'date' => '');
        $ariticle_data['aid'] = $element->id;
        $ariticle_data['aid'] = str_replace('sta_', '', $ariticle_data['aid']);
        $ariticle_data['content'] = strval($element->find('span.status-info', 0));
        $ariticle_data['img'] = select_image($element->find('span.status-info', 0)->plaintext);
        $ariticle_data['date'] = trim($element->find('span.pulish-time', 0)->plaintext);
        $ariticle_list[] = $ariticle_data;
    }
    return $ariticle_data;
}
Пример #2
0
 function widget($args, $instance)
 {
     extract($args, EXTR_SKIP);
     echo $before_widget;
     $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
     $count = $instance['count'];
     $category = $instance['category'];
     if (!empty($title)) {
         echo '<div class="headline no-margin"><h4>' . $title . '</h4></div>';
     }
     if ($instance['type'] == "user") {
         $rss_url = 'http://api.flickr.com/services/feeds/photos_public.gne?id=' . $instance['id'] . '&tags=' . $instance['tags'] . '&format=rss_200';
     } elseif ($instance['type'] == "favorite") {
         $rss_url = 'http://api.flickr.com/services/feeds/photos_faves.gne?id=' . $instance['id'] . '&format=rss_200';
     } elseif ($instance['type'] == "set") {
         $rss_url = 'http://api.flickr.com/services/feeds/photoset.gne?set=' . $instance['set'] . '&nsid=' . $instance['id'] . '&format=rss_200';
     } elseif ($instance['type'] == "group") {
         $rss_url = 'http://api.flickr.com/services/feeds/groups_pool.gne?id=' . $instance['id'] . '&format=rss_200';
     } elseif ($instance['type'] == "public" || $instance['type'] == "community") {
         $rss_url = 'http://api.flickr.com/services/feeds/photos_public.gne?tags=' . $instance['tags'] . '&format=rss_200';
     } else {
         print '<strong>No "type" parameter has been setup. Check your flickr widget settings.</strong>';
     }
     // Check if another plugin is using RSS, may not work
     include_once ABSPATH . WPINC . '/class-simplepie.php';
     error_reporting(E_ERROR);
     $feed = new SimplePie($rss_url);
     $feed->handle_content_type();
     $items = array_slice($rss->items, 0, $instance['count']);
     $print_flickr = '<div class="flickr-widget-blog"><ul>';
     $i = 0;
     foreach ($feed->get_items() as $item) {
         if (++$i > $count) {
             break;
         }
         if ($enclosure = $item->get_enclosure()) {
             $img = image_from_description($item->get_description());
             $thumb_url = select_image($img, 0);
             $full_url = select_image($img, 4);
             $print_flickr .= '<li><a  href="' . $item->get_link() . '" title="' . $enclosure->get_title() . '"><img alt="' . $enclosure->get_title() . '" id="photo_' . $i . '" src="' . $thumb_url . '" /></a></li>' . "\n";
         }
     }
     echo $print_flickr . '</ul></div>';
     echo $after_widget;
 }
Пример #3
0
function get_flickr($settings)
{
    if (!function_exists('MagpieRSS')) {
        // Check if another plugin is using RSS, may not work
        include_once ABSPATH . WPINC . '/class-simplepie.php';
    }
    if (!isset($settings['items']) || empty($settings['items'])) {
        $settings['items'] = 9;
    }
    // get the feeds
    if ($settings['type'] == "user") {
        $rss_url = 'http://api.flickr.com/services/feeds/photos_public.gne?id=' . $settings['id'] . '&per_page=' . $settings['items'] . '&format=rss_200';
    } elseif ($settings['type'] == "favorite") {
        $rss_url = 'http://api.flickr.com/services/feeds/photos_faves.gne?id=' . $settings['id'] . '&format=rss_200';
    } elseif ($settings['type'] == "set") {
        $rss_url = 'http://api.flickr.com/services/feeds/photoset.gne?set=' . $settings['set'] . '&nsid=' . $settings['id'] . '&format=rss_200';
    } elseif ($settings['type'] == "group") {
        $rss_url = 'http://api.flickr.com/services/feeds/groups_pool.gne?id=' . $settings['id'] . '&format=rss_200';
    } elseif ($settings['type'] == "public" || $settings['type'] == "community") {
        $rss_url = 'http://api.flickr.com/services/feeds/photos_public.gne?tags=' . $settings['tags'] . '&format=rss_200';
    } else {
        print '<strong>No "type" parameter has been setup. Check your settings, or provide the parameter as an argument.</strong>';
        die;
    }
    $flickr_cache_path = THEMEUPLOAD . '/flickr_' . $settings['id'] . '_' . $settings['items'] . '.cache';
    if (file_exists($flickr_cache_path)) {
        $flickr_cache_timer = intval((time() - filemtime($flickr_cache_path)) / 60);
    } else {
        $flickr_cache_timer = 0;
    }
    $photos_arr = array();
    if (!file_exists($flickr_cache_path) or $flickr_cache_timer > 15) {
        # get rss file
        $feed = new SimplePie();
        $feed->set_feed_url($rss_url);
        $feed->enable_cache(FALSE);
        $feed->init();
        $feed->handle_content_type();
        foreach ($feed->get_items() as $key => $item) {
            $enclosure = $item->get_enclosure();
            $img = image_from_description($item->get_description());
            $thumb_url = select_image($img, 1);
            $large_url = select_image($img, 4);
            $photos_arr[] = array('title' => $enclosure->get_title(), 'thumb_url' => $thumb_url, 'url' => $large_url, 'link' => $item->get_link());
            $current = intval($key + 1);
            if ($current == $settings['items']) {
                break;
            }
        }
        if (!empty($photos_arr)) {
            if (file_exists($flickr_cache_path)) {
                unlink($flickr_cache_path);
            }
            $myFile = $flickr_cache_path;
            $fh = fopen($myFile, 'w') or die("can't open file");
            $stringData = serialize($photos_arr);
            fwrite($fh, $stringData);
            fclose($fh);
        }
    } else {
        $file = file_get_contents($flickr_cache_path, true);
        if (!empty($file)) {
            $photos_arr = unserialize($file);
        }
    }
    return $photos_arr;
}
Пример #4
0
    function widget($args, $instance)
    {
        // outputs the content of the widget
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance);
        $flickrrss = isset($instance['flickrrss']) ? esc_attr($instance['flickrrss']) : '';
        $thumbs = isset($instance['thumbs']) ? esc_attr($instance['thumbs']) : '';
        ?>
		<?php 
        if ($title == "") {
            $title = "My Flickr";
        }
        ?>
		<?php 
        echo $before_widget;
        ?>
		<?php 
        if ($title) {
            echo $before_title . $title . $after_title;
        }
        ?>
						<ul class="instagram-tiles large-block-grid-3 medium-block-grid-6 small-block-grid-3">
							<?php 
        // simple pie
        require_once ABSPATH . 'wp-includes/class-simplepie.php';
        $upload_dir = wp_upload_dir();
        $feed = new SimplePie();
        if ($flickrrss == '') {
            $feed->set_feed_url('http://api.flickr.com/services/feeds/photos_public.gne?id=62068972@N08&lang=en-us&format=rss_200');
        } else {
            $feed->set_feed_url($flickrrss);
        }
        $feed->set_cache_location($upload_dir['basedir']);
        $feed->set_cache_duration(1800);
        $feed->init();
        $feed->handle_content_type();
        if (!function_exists('image_from_description')) {
            function image_from_description($data)
            {
                preg_match_all('/<img src="([^"]*)"([^>]*)>/i', $data, $matches);
                return $matches[1][0];
            }
        }
        $size = '1';
        if (!function_exists('select_image')) {
            function select_image($img, $size)
            {
                $img = explode('/', $img);
                $filename = array_pop($img);
                $s = array('_s.', '_t.', '_m.', '.', '_b.');
                $img[] = preg_replace('/(_(s|t|m|b))?\\./i', $s[$size], $filename);
                return implode('/', $img);
            }
        }
        foreach ($feed->get_items(0, $thumbs) as $item) {
            if ($enclosure = $item->get_enclosure()) {
                $img = image_from_description($item->get_description());
                $full_url = $item->get_permalink();
                $thumb_url = select_image($img, $size);
                echo '<li class="instagram-tile"><a href="' . $full_url . '" target="_blank" title="' . $enclosure->get_title() . '"><img width="100" height="75" alt="" src="' . $thumb_url . '" /></a></li>' . "\n";
            }
        }
        ?>

						</ul>
			<?php 
        echo $after_widget;
        ?>
		<?php 
    }
Пример #5
0
function get_flickr($settings)
{
    if (!function_exists('MagpieRSS')) {
        // Check if another plugin is using RSS, may not work
        include_once ABSPATH . WPINC . '/class-simplepie.php';
        error_reporting(E_ERROR);
    }
    if (!isset($settings['items']) || empty($settings['items'])) {
        $settings['items'] = 9;
    }
    // get the feeds
    if ($settings['type'] == "user") {
        $rss_url = 'http://api.flickr.com/services/feeds/photos_public.gne?id=' . $settings['id'] . '&tags=' . $settings['tags'] . '&per_page=' . $settings['items'] . '&format=rss_200';
    } elseif ($settings['type'] == "favorite") {
        $rss_url = 'http://api.flickr.com/services/feeds/photos_faves.gne?id=' . $settings['id'] . '&format=rss_200';
    } elseif ($settings['type'] == "set") {
        $rss_url = 'http://api.flickr.com/services/feeds/photoset.gne?set=' . $settings['set'] . '&nsid=' . $settings['id'] . '&format=rss_200';
    } elseif ($settings['type'] == "group") {
        $rss_url = 'http://api.flickr.com/services/feeds/groups_pool.gne?id=' . $settings['id'] . '&format=rss_200';
    } elseif ($settings['type'] == "public" || $settings['type'] == "community") {
        $rss_url = 'http://api.flickr.com/services/feeds/photos_public.gne?tags=' . $settings['tags'] . '&format=rss_200';
    } else {
        print '<strong>No "type" parameter has been setup. Check your settings, or provide the parameter as an argument.</strong>';
        die;
    }
    # get rss file
    $feed = new SimplePie($rss_url);
    $photos_arr = array();
    foreach ($feed->get_items() as $key => $item) {
        $enclosure = $item->get_enclosure();
        $img = image_from_description($item->get_description());
        $thumb_url = select_image($img, 0);
        $large_url = select_image($img, 4);
        $photos_arr[] = array('title' => $enclosure->get_title(), 'thumb_url' => $thumb_url, 'url' => $large_url);
        $current = intval($key + 1);
        if ($current == $settings['items']) {
            break;
        }
    }
    return $photos_arr;
}