Archive for the ‘Web’ Category

Постим в твиттер через курл

Можно интегрировать в свой блог, и пост автоматом уйдет в твиттер, можно встроить в админку и писать в твиттер из админки вп. Применений масса.

<?php
// Set username and password
$username = 'username';
$password = 'password';
// The message you want to send
$message = 'is twittering from php using curl';
// The twitter API address
$url = 'http://twitter.com/statuses/update.xml';
// Alternative JSON version
// $url = 'http://twitter.com/statuses/update.json';
// Set up and execute the curl process
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
// check for success or failure
if (empty($buffer)) {
echo 'message';
} else {
echo 'success';
}
?>

Пример простой спамилки вордпресса

У курла есть много вариантов использования )

<?php
$postfields = array();
$postfields["action"] = "submit";
$postfields["author"] = "Spammer";
$postfields["email"] = "spammer@spam.com";
$postfields["url"] = "http://www.iamaspammer.com/";
$postfields["comment"] = "I am a stupid spammer.";
$postfields["comment_post_ID"] = "123";
$postfields["_wp_unfiltered_html_comment"] = "0d870b294b";
//Url of the form submission
$url = "http://www.ablogthatdoesntexist.com/blog/suggerer_site.php
?action=meta_pass&id_cat=0";
$useragent = "Mozilla/5.0";
$referer = $url;

//Initialize CURL session
$ch = curl_init($url);
//CURL options
curl_setopt($ch, CURLOPT_POST, 1);
//We post $postfields data
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
//We define an useragent (Mozilla/5.0)
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
//We define a refferer ($url)
curl_setopt($ch, CURLOPT_REFERER, $referer);
//We get the result page in a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//We exits CURL
$result = curl_exec($ch);
curl_close($ch);

//Finally, we display the result
echo $result;
?>

Пишем в вордпресс через curl

Данной функцией можно постить в вп.

function wpPostXMLRPC($title,$body,$rpcurl,$username,
$password,$category,$keywords='',$encoding='UTF-8')
{
$title = htmlentities($title,ENT_NOQUOTES,$encoding);
$keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);

$content = array(
'title'=>$title,
'description'=>$body,
'mt_allow_comments'=>0,  // 1 to allow comments
'mt_allow_pings'=>0,  // 1 to allow trackbacks
'post_type'=>'post',
'mt_keywords'=>$keywords,
'categories'=>array($category)
);
$params = array(0,$username,$password,$content,true);
$request = xmlrpc_encode_request('metaWeblog.newPost',$params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, $rpcurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
$results = curl_exec($ch);
curl_close($ch);
return $results;
?>

Как получить видео с вконтакте?

И вставить в блог.
Прямых возможностей нет, но если очень надо, то можно сделать ручками.
С самого контакта стянуть не получится, там авторизация нужна, получится вытащить с вкадре, если не стоит настроек приватности. Read On…

Отобразить PSD файл при помощи PHP

Есть оказывается, специальный класс для этого. Совместим с PHP4/5. Скачать тут

Используется так

<?php
// Send header to client browser
header("Content-type: image/jpeg");
// Includes the requested class
include_once('classPhpPsdReader.php');
// Finally display the PSD on the screen
imagejpeg(imagecreatefrompsd('yourPsdFile.psd'));
?>
 Read On…

Градиентный текст на CSS

Интересная техника по созданию градиентного текста. Суть в перекрытии текста прозрачным png. В заголовок h1 вставляется span, которому прописывается бекграунд.

screen1

Например вот так:
grad

Все примеры можно глянуть тут

Сам код:

<h1><span></span>CSS Gradient Text</h1>
h1 {
  font: bold 330%/100% "Lucida Grande";
  position: relative;
  color: #464646;
}
h1 span {
  background: url(gradient.png) repeat-x;
  position: absolute;
  display: block;
  width: 100%;
  height: 31px;
}

Сам оригинал

css.php