All pastes #617221 Raw Edit

Mine

public text v1 · immutable
·published 2007-07-13 03:12 UTC
rendered paste body
<?php
/*
Plugin Name: deviantArt Last deviation
PLugin URI: http://www.mkp.aplus.pl
Description: Show thumbnail/text-link/the both to the most recent deviation on specified dA account
Author: Tadeusz Hucał
Version: 0.1.1
Stable tag: 0.1.1
Author URI: http://www.mkp.aplus.pl/?page_id=5
*/

/*
Types:
 1 - thumbnail + textlink
 2 - thumbnail
 3 - textlink
*/

function show_last_dev($user, $type = 1, $new_win = false) {
   //Ini CURL
   $ch_da = curl_init('http://'.$user.'.deviantart.com');
   
   if (!$ch_da) {
   	return ;
   }
   //Set options
   curl_setopt($ch_da, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch_da, CURLOPT_CONNECTTIMEOUT, 10);
   curl_setopt($ch_da, CURLOPT_TIMEOUT, 10);
   //Get site content
   $site = curl_exec($ch_da);
   //Check
   if (empty($site)) {
   	return ;
   }
   //Close connection
   @curl_close($ch_da);
   //Find recent deviations tab
   $recent_pos = strpos($site, 'Recent Deviations');
   //Check...
   if ($recent_pos === false) {
   	return ;
   }
   //Delete body before recent deviations
   $site = substr($site, $recent_pos);
   //$site = str_replace('/', '', $site);
   //Grap links
   preg_match('/href="(http:\/\/+[a-zA-Z0-9_\.\/\-]+)"/i', $site, $link);
   preg_match('/src="(http:\/\/+[a-zA-Z0-9_\.\/\-]+)"/i', $site, $img);
   preg_match('/title="+[^"]+">/i', $site, $title);
   //Put them into array
   $link = array($link[1], $img[1], substr($title[0], 7, (strrpos($title[0], 'by') - 8)));

   if ($new_win === true) {
   	$new_w_add = ' target="_blank"';
   }else {
   	$new_w_add = ' target="_blank"';
   }
   //Echo results
   switch ($type) {
   	case 2:
   		echo '<a href="'.$link[0].'"'.$new_w_add.' style="padding 0px; background: none;"><img src="'.$link[1].'" alt="'.$link[2].'" style="border:none;" /></a>';
   		break;
      case 3:
         echo '<a href="'.$link[0].'"'.$new_w_add.' style="padding 0px; background: none;" title="'.$link[2].'">'.$link[2].'</a>';
         break;
   	default:
   	   echo '<a href="'.$link[0].'"'.$new_w_add.' style="padding 0px; background: none;"><img src="'.$link[1].'" alt="'.$link[2].'" style="border:1px solid #0066cc; margin: auto;" /> <br>'.$link[2].'</a>';
   		break;
   }
}
/* Example of simple using
show_last_dev('m-k-p');*/
?>