<?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/"
	>

<channel>
	<title>邪罗刹的菠萝阁 &#187; curl</title>
	<atom:link href="http://www.evlos.org/tag/curl/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.evlos.org</link>
	<description>A straw shows which way the wind blows ..</description>
	<lastBuildDate>Sun, 05 Sep 2010 20:37:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>突破防盗链抓取漫画文件方法简述</title>
		<link>http://www.evlos.org/2010/05/04/download-comic/</link>
		<comments>http://www.evlos.org/2010/05/04/download-comic/#comments</comments>
		<pubDate>Mon, 03 May 2010 17:43:01 +0000</pubDate>
		<dc:creator>小邪</dc:creator>
				<category><![CDATA[小程序 [Lit Work]]]></category>
		<category><![CDATA[comic]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[download]]></category>

		<guid isPermaLink="false">http://www.evlos.org/?p=1955</guid>
		<description><![CDATA[> 嘿嘿，小邪最近想批量下载某个网站的漫画，因为那里的广告实在是太多了，- -，漫画都遮住了。 > 广告就算是被 Chrome 屏蔽了，居然还带声音，要是多开几个页面就那个诡异啊，0.0，狂汗。 一. 如何突破防盗链： > 一般的防盗链都是检测头部的 Referer 属性，也就是我们正在访问的调用图片的那个页面的地址。 > 通过这个地址来检测你是否是从此页面（即允许调用图片的网站）来访问图片的，然后进行判断。 > 看看是输出防盗链防御图片，O(∩_∩)O，还是输出你要浏览的漫画文件内容，嘎嘎，╮(╯▽╰)╭。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 $url = 'http://xx.xxxxxcomic.com/xxx/xxxx/xxxxx/act_001/001Xsss.JPG'; //这个变量是要下载的图片地址 $referer = 'http://www.xxxxxcomic.com/manhua/xxxx/xxxxxx/?a=1'; //这个变量是我们需要伪造的头部 Referer 属性内容，也就是显示此图片的页面地址 function downloader&#40;$url,$referer,$name&#41; &#123; $curl = curl_init&#40;$url&#41;; $useragent=&#34;Mozilla/5.0 (Windows; [...]]]></description>
			<content:encoded><![CDATA[<p>> 嘿嘿，小邪最近想批量下载某个网站的漫画，因为那里的广告实在是太多了，- -，漫画都遮住了。<br />
> 广告就算是被 Chrome 屏蔽了，居然还带声音，要是多开几个页面就那个诡异啊，0.0，狂汗。</p>
<p><img src='http://www.evlos.org/ev-box/myimg/uploads/old/Cap0000383.png' /></p>
<p><span id="more-1955"></span><strong>一. 如何突破防盗链：</strong></p>
<p>> 一般的防盗链都是检测头部的 Referer 属性，也就是我们正在访问的调用图片的那个页面的地址。<br />
> 通过这个地址来检测你是否是从此页面（即允许调用图片的网站）来访问图片的，然后进行判断。<br />
> 看看是输出防盗链防御图片，O(∩_∩)O，还是输出你要浏览的漫画文件内容，嘎嘎，╮(╯▽╰)╭。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://xx.xxxxxcomic.com/xxx/xxxx/xxxxx/act_001/001Xsss.JPG'</span><span style="color: #339933;">;</span>
<span style="color: #096;">//这个变量是要下载的图片地址</span>
<span style="color: #000088;">$referer</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.xxxxxcomic.com/manhua/xxxx/xxxxxx/?a=1'</span><span style="color: #339933;">;</span>
<span style="color: #096;">//这个变量是我们需要伪造的头部 Referer 属性内容，也就是显示此图片的页面地址</span>
<span style="color: #000000; font-weight: bold;">function</span> downloader<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span><span style="color: #000088;">$referer</span><span style="color: #339933;">,</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$curl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$useragent</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.4) Gecko/20100413 Firefox/3.6.4&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_USERAGENT<span style="color: #339933;">,</span> <span style="color: #000088;">$useragent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_REFERER<span style="color: #339933;">,</span> <span style="color: #000088;">$referer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #096;">//以上构造一个 Curl 函数来下载图片的内容</span>
	<span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'w+'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #096;">//再用 fopen fwrite fclose 来将内容保存为文件</span>
<span style="color: #009900;">&#125;</span>
downloader<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span><span style="color: #000088;">$referer</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'1.jpg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #096;">//'1.jpg' 则是图片的文件名，这样调用就可以成功下载了喔</span></pre></td></tr></table></div>

<p>> 咱点到即止哈，这种事情不能讲得太细的，毕竟影响到了这些站点的生意了，这样很不好呢。<br />
> 所以我们以研究 PHP 代码技术的角度简单注释一下，希望对大家有用喔，O(∩_∩)O 嘻嘻。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> ServerList<span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #990000;">Array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
ServerList<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://21.xxxxxcomic.com/xxx1/&quot;</span><span style="color: #339933;">;</span>
ServerList<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://21.xxxxxcomic.com/xxx2/&quot;</span><span style="color: #339933;">;</span>
ServerList<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://32.xxxxxcomic.com/xxx3/&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>> 如果图片是延迟载入的，即页面载入完成才载入图片，那在某 JS 文件可能找到上面内容喔。<br />
> 这是基本地址，随机读取的，一般是漫画文件 URL 的前半部分，嘎嘎，可能随时更换的。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;script language</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;javascript&quot;</span><span style="color: #339933;">&gt;</span> 
<span style="color: #000000; font-weight: bold;">var</span> ComicListID<span style="color: #339933;">=</span><span style="color: #cc66cc;">41870</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">var</span> ComicID<span style="color: #339933;">=</span><span style="color: #cc66cc;">5165</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">var</span> PicListUrl <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/xxx001.JPG|/xxx002.JPG&quot;</span><span style="color: #339933;">;</span>
<span style="color: #096;">//在漫画浏览页面代码中还可能找到这样的地址，表示此章节漫画文件名称，接在基本地址后边即可</span>
<span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></pre></td></tr></table></div>

<p>> 嘻嘻，那么祝大家玩得开心哈，小邪闪人咯。嘎嘎嘎嘎。╮(╯-╰)╭╮(╯o╰)╭╮(╯O╰)╭╮(╯▽╰)╭。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evlos.org/2010/05/04/download-comic/feed/</wfw:commentRss>
		<slash:comments>98</slash:comments>
		</item>
		<item>
		<title>Photobucket抓取图片下载程序</title>
		<link>http://www.evlos.org/2010/01/14/photobucket-downloader/</link>
		<comments>http://www.evlos.org/2010/01/14/photobucket-downloader/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 15:38:52 +0000</pubDate>
		<dc:creator>小邪</dc:creator>
				<category><![CDATA[小程序 [Lit Work]]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[photobucket]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.evlos.org/?p=1898</guid>
		<description><![CDATA[> 最近小邪抓取抓上瘾鸟，感觉 Curl 与 正则式 的组合很爽，╮(╯▽╰)╭，拦都拦不住自己呐。 > 所以今天小邪要送大家一个 Photobucket 抓取程序，可以很方便地抓取整个相册喔。 > 程序的运行过程是这个样子的，先读取相册页面，然后用正则式找到文件名与地址。 > 最后用 set_time_limit(0) 设置防止超时，并用 File_get_contents 函数把图片下载下来。 一. PBK Downloader 程序简介： > 在变量 album_url 里填上相册地址，然后在变量 album_pagen 里填上页数即可。 > 程序会自动生成一个 Img 文件夹，并将图片下载到里面，就完成咯，O(∩_∩)O 嘻嘻！ 1 2 $album_url = 'http://photobucket.com/images/avatar%20movie/'; //相册 $album_pagen = 1; //页数 二. 抓取实例： > 相册地址 - http://photobucket.com/images/avatar%20movie/ > 呵呵，小邪在页数那里只填了1页，然后就抓取下来咯。小邪文件名前面加了序号来着。 > 因为有些图片名字相同，但是内容却是不同的，所以这样子防止出现漏掉文件。 三. 源代码： [...]]]></description>
			<content:encoded><![CDATA[<p>> 最近小邪抓取抓上瘾鸟，感觉 Curl 与 正则式 的组合很爽，╮(╯▽╰)╭，拦都拦不住自己呐。<br />
> 所以今天小邪要送大家一个 Photobucket 抓取程序，可以很方便地抓取整个相册喔。</p>
<p><img src='http://www.evlos.org/ev-box/myimg/uploads/old/Capture1141.jpg' /></p>
<p>> 程序的运行过程是这个样子的，先读取相册页面，然后用正则式找到文件名与地址。<br />
> 最后用 set_time_limit(0) 设置防止超时，并用 File_get_contents 函数把图片下载下来。</p>
<p><span id="more-1898"></span><strong>一. PBK Downloader 程序简介：</strong></p>
<p>> 在变量 album_url 里填上相册地址，然后在变量 album_pagen 里填上页数即可。<br />
> 程序会自动生成一个 Img 文件夹，并将图片下载到里面，就完成咯，O(∩_∩)O 嘻嘻！</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$album_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://photobucket.com/images/avatar%20movie/'</span><span style="color: #339933;">;</span> <span style="color: #096;">//相册</span>
<span style="color: #000088;">$album_pagen</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #096;">//页数</span></pre></td></tr></table></div>

<p><strong>二. 抓取实例：</strong></p>
<p>> 相册地址 - <a target='_blank' rel='nofollow' href='http://photobucket.com/images/avatar%20movie/'>http://photobucket.com/images/avatar%20movie/</a></p>
<p><img src='http://www.evlos.org/ev-box/myimg/uploads/old/Capture1140.jpg' /></p>
<p>> 呵呵，小邪在页数那里只填了1页，然后就抓取下来咯。小邪文件名前面加了序号来着。<br />
> 因为有些图片名字相同，但是内容却是不同的，所以这样子防止出现漏掉文件。</p>
<p><img src='http://www.evlos.org/ev-box/myimg/uploads/old/Capture1143.jpg' /></p>
<p><strong>三. 源代码：</strong></p>
<p>> 把下面两个变量填一下就好，小邪已经把超时设置为无限，但是如果出现意外状况。<br />
> 直接刷新接着来就好，程序如果发现已经下载了就不会下第二遍咯，O(∩_∩)O。</p>
<p>> <a target='_blank' rel='nofollow' href='http://code.google.com/p/evlosbox/downloads/detail?name=pbk_getpic.txt&#038;can=2&#038;q='>http://code.google.com/p/evlosbox/downloads/detail?name=pbk_getpic.txt</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.evlos.org/2010/01/14/photobucket-downloader/feed/</wfw:commentRss>
		<slash:comments>110</slash:comments>
		</item>
		<item>
		<title>如何抓取Flickr相片集中的图片URL</title>
		<link>http://www.evlos.org/2010/01/10/get-the-files-and-urls-from-flickr/</link>
		<comments>http://www.evlos.org/2010/01/10/get-the-files-and-urls-from-flickr/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 18:13:45 +0000</pubDate>
		<dc:creator>小邪</dc:creator>
				<category><![CDATA[PHP编程 [PHP Build]]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.evlos.org/?p=1893</guid>
		<description><![CDATA[> 最近小邪准备把博客的图片地址都换成 Flickr 上面的图片地址，所以需要用抓取来节省时间。 > 恩恩，纯粹是节省时间，抓取对很多盆友都是不好的事情，小邪的站也被抓过，很杯具。 > 那么，在这里小邪就讲解一下如何使用 PHP 的 CURL 函数和正则式抓取 Flickr 的图片。 > 首先用 Curl 带 Cookies 地抓页面代码，然后用正则分离出图片Code，最后得到大尺寸地址。 > Rencently, Evlos prepare to change the image urls in my article to the image urls in Flickr. > So, I think I should use php program to catch urls in Flickr for saving time. [...]]]></description>
			<content:encoded><![CDATA[<p>> 最近小邪准备把博客的图片地址都换成 Flickr 上面的图片地址，所以需要用抓取来节省时间。<br />
> 恩恩，纯粹是节省时间，抓取对很多盆友都是不好的事情，小邪的站也被抓过，很杯具。</p>
<p><img src='http://www.evlos.org/ev-box/myimg/uploads/old/Capture1105.jpg' /></p>
<p>> 那么，在这里小邪就讲解一下如何使用 PHP 的 CURL 函数和正则式抓取 Flickr 的图片。<br />
> 首先用 Curl 带 Cookies 地抓页面代码，然后用正则分离出图片Code，最后得到大尺寸地址。</p>
<p><span id="more-1893"></span>> Rencently, Evlos prepare to change the image urls in my article to the image urls in Flickr.<br />
> So, I think I should use php program to catch urls in Flickr for saving time.<br />
> Um .. Just for saving time, curl isn't a good tools for lots of people.<br />
> Because it can get the whole data in website and make a mirror site for gaining money.<br />
> And I suffered this last month, it's a tragedy.</p>
<p>> First of all, use curl get the html data. We should post some cookies in same time.<br />
> Then use regex to get the code for images. At last, we use image code to get image url.</p>
<p><strong>一. 分析一下地址 Analyse url：</strong></p>
<p><strong>1. 用户地址 User url -</strong></p>
<p>> http://www.flickr.com/photos/46051661@N04<br />
> 比如小邪的用户地址就是这个样子的，很规则，处理有规则的东西是最方便的鸟。</p>
<p>> For example, this is my album url. It's very regular and can easy to deal with it.</p>
<p><strong>2. 相片集地址 Album url -</strong></p>
<p>> http://www.flickr.com/photos/46051661@N04/sets/72157623167782492<br />
> 恩恩，后面是一个 Sets 表示相片集，然后是相片集本身的 Code。<br />
> 小邪喜欢把这些唯一性的字符称为 Code，呵呵，这样比较好说一点儿。</p>
<p>> Um .. It contains a sets code rearward and a user code in der mitte.<br />
> Evlos like called the unique character as code. Haha, it's easily explained.</p>
<p><strong>3. 单张相片地址 Single image url -</strong></p>
<p>> http://www.flickr.com/photos/46051661@N04/4259923860/<br />
> http://www.flickr.com/photos/46051661@N04/4259923860/in/set-72157623167782492<br />
> 嘎嘎，有两种，其实都是一模一样的页面来着，所以咱挑上面的短的。</p>
<p>> :), Flickr offer two kinds of url, but it will heading us to a same page.<br />
> So, certainly, we choose the shorter url.</p>
<p><strong>4. 单张相片大尺寸地址 Single image url for big size -</strong></p>
<p>> http://www.flickr.com/photos/46051661@N04/4259923860/sizes/o/<br />
> 一般来说小邪的 600px 宽度，高度在 600px 以下的，都用地址 O 来查看全图的。<br />
> http://www.flickr.com/photos/46051661@N04/4259923860/sizes/l/<br />
> 因为 Flickr 不提供大图全图，而 L 是图片尺寸过大后被裁减的地址，所以只好用 L 咯。<br />
> 嘎嘎，还有四个尺寸，依次减小，这样子 - M S T SQ，OK可以开工了。</p>
<p>> In general, my image is limit in 600px and i can get the full size by "o".<br />
> Bacause Flickr limit the size of image by 1024px for free users.<br />
> And "L" is a code for the image exceed 1024px and offer 1024px image.<br />
> Haha, and the remaining four size. Like M S T SQ, so let's beginning. </p>
<p><strong>二. 开始抓取 Begin to catch：</strong></p>
<p><strong>1. 抓取相片 Code 代码 Catch the code of image：</strong></p>
<p>> $sa[0] 里面储存的是相片的 Code，$sa[1] 储存的是相片的标题。<br />
> 而 $sa[2][0] 储存的是相片个数，因为这里是二维数组，小邪不想要 Foreach。<br />
> 虽然双层 Foreach 可以遍历二维数组，不过这里只需要作为两个一维数组就好。</p>
<p>> Put the codes of image in $sa[0]. And put the title of image in $sa[1].<br />
> And put the numbers of images into $sa[2][0], bacause it's 2d array.<br />
> And Evlos don't want to use foreach. Though i can use double-layer foreach.<br />
> I just need to use two 1d array, it's enough.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> app_get_set_info<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$regex</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;%\/photos\/46051661@N04\/(\d+)\/in\/set\-\d+\/<span style="color: #000099; font-weight: bold;">\&quot;</span> 
title=<span style="color: #000099; font-weight: bold;">\&quot;</span>([a-z0-9A-Z-_]*)<span style="color: #000099; font-weight: bold;">\&quot;</span> class%i&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$regex</span><span style="color: #339933;">,</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span><span style="color: #000088;">$save</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$sa</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$save</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$sa</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$save</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$sa</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> array_count<span style="color: #009900;">&#40;</span><span style="color: #000088;">$save</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$sa</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>> $save[1] 是储存第一个括号中匹配内容的数组，而 $save[2] 则是第二个括号的。<br />
> 那么还有一个，是 $save[0]，这个当然就是整串正则式匹配的字符咯，O(∩_∩)O。</p>
<p>> We put the content in firstly bracket into $save[1].<br />
> And the same meaning to content in secendly bracket.<br />
> So, the $save[0] is use to putting the whole content that get by regex.</p>
<p><strong>2. 抓取图片地址：</strong></p>
<p>> 恩，这里整个页面也就一张 JPG 或者 PNG 的大图了（页面元素是 GIF）。<br />
> 所以咱们这样子抓下来。╮(╯▽╰)╭，可怜的 Flickr，被偶剥得半裸了。<br />
> 嘎嘎，差不多就 619 那根全裸男一样了（619 童鞋一定要小邪给他开个裸奔帝国<a target='_blank' rel='nofollow' href='http://liuyijun.com/'>传送门</a>）。</p>
<p>> Um .. The whole image page is just include one jpg or one png url.<br />
> So we can easily get it by regex like the following content.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> app_get_ourl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$pagelist_regex</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;%&lt;img src=<span style="color: #000099; font-weight: bold;">\&quot;</span>(.+.jpg)<span style="color: #000099; font-weight: bold;">\&quot;</span>%i&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pagelist_regex</span><span style="color: #339933;">,</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span><span style="color: #000088;">$save</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #096;">//print_r($save);</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$save</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$pagelist_regex</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;%&lt;img src=<span style="color: #000099; font-weight: bold;">\&quot;</span>(.+.png)<span style="color: #000099; font-weight: bold;">\&quot;</span>%i&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pagelist_regex</span><span style="color: #339933;">,</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span><span style="color: #000088;">$save</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$save</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>3. 带 Cookies 的 Curl：</strong></p>
<p>> 因为登陆后在相片集页面可以看到全部照片，所以咱们用 Curl 把  Cookies 传过去。<br />
> 嘎嘎，老样子，大家都喜欢模拟 FF 的访问头部。然后是一些必要的参数。</p>
<p>> Because if we login, we can see the all images in set page.<br />
> So we post the cookies to Flickr, and get the html code.<br />
> Haha .. Same as ever, we like simulate the header of firefox.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> app_get_html<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span><span style="color: #000088;">$cookie</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$curl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$useragent</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; 
rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_USERAGENT<span style="color: #339933;">,</span> <span style="color: #000088;">$useragent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$cookie</span><span style="color: #339933;">&lt;&gt;</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">curl_setopt</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_COOKIE<span style="color: #339933;">,</span> <span style="color: #000088;">$cookie</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #096;">// 用法如下，Cookies 信息麻烦自行找到，小邪太懒了╮(╯▽╰)╭。</span>
<span style="color: #096;">// The example method like the following content. Please get the cookies by yourself.</span>
app_get_html<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://www.flickr.com/photos/46051661@N04/sets/72157623167782492'</span><span style="color: #339933;">,</span>
<span style="color: #000088;">$cookie</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'cookie_accid=16212532;cookie_epass=816e23c7b24aa6q9f13713e7503de07f;'</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p><strong>4. 程序运行过程 The process of running：</strong></p>
<p>> 首先麻烦自行搞到 Flickr 的 Cookies，然后把相片集页面包含的相片 Code 全部抓取来。<br />
> 保存到数据库之类的地方（因为咱们可能会经常超时），一条一条读取数据库中保存的 Code。</p>
<p>> 然后获取图片页面中的 Url，保存到数据库，如果 Url 已经储存就不去抓取了。<br />
> 因为 100% 会出现超时，所以得这样，然后到时候刷新下接着干就好了，嘿嘿。</p>
<p>> 请原谅小邪没有把完整源代码贴出来，因为怕引起 Flickr 官方的注意，虽然可能性不会很大。<br />
> 但是还是小心一点儿为好。而且全部的主要代码已经贴出来了，储存数据库相信你能搞定的。<br />
> 呵呵，时间又到两点多钟了，小邪很想睡觉鸟 Zzzzzzzzzz 晚安喔，小邪这就去把床给上了。</p>
<p>> First of all, get the cookies for yourself. Then get the codes for images.<br />
> Save them into database or something like that. And read data one by one.</p>
<p>> Get the url for single image file and save to db, if it's exist, just skip up.<br />
> Beacuse we will reach the time excceed. So just need to refresh the page.</p>
<p><strong>三. 这难道是水军路过？！：</strong></p>
<p><img src='http://www.evlos.org/ev-box/myimg/uploads/old/Capture1104.jpg' /></p>
<p>> 截图留念，╮(╯▽╰)╭，人家都是拍照留念，但小邪没事最喜欢截图留念了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evlos.org/2010/01/10/get-the-files-and-urls-from-flickr/feed/</wfw:commentRss>
		<slash:comments>114</slash:comments>
		</item>
		<item>
		<title>制作好一个输出PR图片的API</title>
		<link>http://www.evlos.org/2009/12/09/made-a-api-can-output-pr-image/</link>
		<comments>http://www.evlos.org/2009/12/09/made-a-api-can-output-pr-image/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 06:35:07 +0000</pubDate>
		<dc:creator>小邪</dc:creator>
				<category><![CDATA[小程序 [Lit Work]]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[pr]]></category>

		<guid isPermaLink="false">http://www.evlos.org/?p=1490</guid>
		<description><![CDATA[> ╮(╯▽╰)╭ 昨天白夜三更写的，糊涂地忘记了已经有蛮多网站提供这个功能了，结果就杯具了。 > 不过也没什么，这篇文章刚刚好总结一下 Curl 函数和 File_get_contents 函数的用法。 > 好多服务器为了防采集都禁止 File_get_contents，所以介绍一下俩函数互相替代的方法。 > 话说，昨天给 619 的模板导航栏上加上了分类目录的显示，但我觉得那个模板的函数有点奇怪。 P.s. 呵呵，使用方法如图，作为图片显示即可，有兴趣的童鞋可以调用过去玩玩 O(∩_∩)O。 1. File_get_contents 函数： > 使用如下的代码可以将变量 $GontenPRURL 里的路径指向的文件读入字符串 $filecontent 中。 > 只要在 Url 中传递参数即可到 Google 获取到 PR 的数值，然后转换为相对的图片文件名称。 1 $filecontent = file_get_contents&#40;$prurl&#41;; > 我简单的使用下面的函数代码过滤了一下 Url 地址。 > 因为没法过滤引号，所以后面再使用 Preg_match 的正则式过滤文件头。 1 2 $evlos_re = array&#40;&#34;\&#34;&#34;,&#34;'&#34;,&#34;!&#34;,&#34;@&#34;,&#34;#&#34;,&#34;$&#34;,&#34;%&#34;,&#34;^&#34;,&#34;&#38;&#34;,&#34;*&#34;,&#34;(&#34;,&#34;)&#34;,&#34;+&#34;,&#34;=&#34;&#41;; $website = [...]]]></description>
			<content:encoded><![CDATA[<p>> ╮(╯▽╰)╭ 昨天白夜三更写的，糊涂地忘记了已经有蛮多网站提供这个功能了，结果就杯具了。<br />
> 不过也没什么，这篇文章刚刚好总结一下 Curl 函数和 File_get_contents 函数的用法。</p>
<p><img src="http://www.evlos.org/ev-box/myimg/uploads/old/Capture0704.jpg" /></p>
<p>> 好多服务器为了防采集都禁止 File_get_contents，所以介绍一下俩函数互相替代的方法。<br />
> 话说，昨天给 619 的模板导航栏上加上了分类目录的显示，但我觉得那个模板的函数有点奇怪。</p>
<p>P.s. 呵呵，使用方法如图，作为图片显示即可，有兴趣的童鞋可以调用过去玩玩 O(∩_∩)O。</p>
<p><span id="more-1490"></span>1. <strong>File_get_contents 函数</strong>：</p>
<p><img src="http://www.evlos.org/ev-box/myimg/uploads/old/Capture0703.jpg" /></p>
<p>> 使用如下的代码可以将变量 $GontenPRURL 里的路径指向的文件读入字符串 $filecontent 中。<br />
> 只要在 Url 中传递参数即可到 Google 获取到 PR 的数值，然后转换为相对的图片文件名称。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$filecontent</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$prurl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>> 我简单的使用下面的函数代码过滤了一下 Url 地址。<br />
> 因为没法过滤引号，所以后面再使用 Preg_match 的正则式过滤文件头。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$evlos_re</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;!&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;@&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;#&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;$&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;%&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;^&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&amp;&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;*&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;(&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;+&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;=&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$website</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$evlos_re</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$website</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>> 最后再输出一个文件头，再把作为字符串的图片接着输出即可。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: image/jpeg; charset=UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>2. <strong>Curl 函数</strong>：</p>
<p>> <strong>注意！！</strong>CURLOPT_URL 参数是不支持相对路径的，网上没看到有人提到，害我差点没折腾挂掉。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$ch1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$timeout1</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">15</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch1</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$prurl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch1</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch1</span><span style="color: #339933;">,</span> CURLOPT_CONNECTTIMEOUT<span style="color: #339933;">,</span> <span style="color: #000088;">$timeout1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$filecontent</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>> 这里就得用那么长的代码来代替上面 File_get_contents 函数的那一行代码了。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$fixurl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://'</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_SELF'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fixurl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_SELF'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$fixurl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pic</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$fixurl</span><span style="color: #339933;">.</span><span style="color: #000088;">$pic</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>> $pic 是我的 PR 图片文件，这里通过上面代码把相对路径转换为 Url 路径。<br />
> 最后也差不多，输出一个文件头，再把作为字符串的图片接着输出即可。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$ch2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$timeout2</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">15</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch2</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$pic</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch2</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch2</span><span style="color: #339933;">,</span> CURLOPT_CONNECTTIMEOUT<span style="color: #339933;">,</span> <span style="color: #000088;">$timeout2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>3. <strong>同行输出日志分类与博客页面列表</strong>：</p>
<p>> 话说原先 Sandbox 只输出博客页面列表的时候 Header.php 只调用了一个函数：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> sandbox_globalnav<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>> 然后在主题函数 Functions.php 里面加了一大段这个代码：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> sandbox_globalnav<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$menu</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> 
wp_list_pages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title_li=&amp;sort_column=menu_order&amp;echo=0'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$menu</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;ul&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$menu</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/ul&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$menu</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;div id=&quot;menu&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$menu</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;/div&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> apply_filters<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'globalnav_menu'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$menu</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>> 我觉得其实没啥必要的样子，因为下面使用 WP 自带的函数输出一个 Li 列表也是可以达到相同效果的。<br />
> 博客页面是 Wp_list_pages，文章分类是 Wp_list_categories。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;div id=&quot;menu&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_list_categories<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title_li=0&amp;orderby=name&amp;show_count=0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
wp_list_pages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title_li=0&amp;sort_column=menu_order'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/div&gt;</pre></td></tr></table></div>

<p>> 然后在 CSS 文件里面把 Li 变成行内元素即可，话说 Li 真是一个神奇的东西。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#access</span> li <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">8px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>4. <strong>调用说明页面传送门</strong>：</p>
<p>> <a target="_blank" href="http://tool.evlos.org/primg/">http://tool.evlos.org/primg/</a></p>
<p>5. <strong>欢迎来 Follow 我的 Twitter <a target="_blank" rel="nofollow" href="http://twitter.com/angelsolo">@AngelSolo</a></strong> 。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.evlos.org/2009/12/09/made-a-api-can-output-pr-image/feed/</wfw:commentRss>
		<slash:comments>70</slash:comments>
		</item>
	</channel>
</rss>
