Location: PHPKode > scripts > Webs.com API Library > webs-com-api-library/webs_api.php
<?php
//////////////////////////////
// Webs.com API Version 1.0 //
// PHP Client Version 0.1 //
// cURL Support //
// © NewHaze.com //
// Info: devs.newhaze.com //
//////////////////////////////
class Webs {
private $username;
private $password;
private $apikey;
private $token;
public function __construct ($username, $password, $apikey) {
$this->username = $username;
$this->password = $password;
$this->apikey = $apikey;
$post=array("apikey"=>$apikey,"password"=>$password,"auth"=>"fr33w3bs".$apikey.$password);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.webs.com/v1/user/login/'.$username);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'FreeWebs PHP API V0.1');
$result = curl_exec($ch);
curl_close($ch);
$html = str_get_html($result);
$token=$html->find('token',0);
$this->token = $token->innertext;
}
///////////////////Site Manager Services/////////////////////////////////
public function listPages ($type='all') {
$url="http://api.webs.com/v1/sitemanager/".$this->username."/pages";
switch($type) {
case 'normal':$url.="/normal";break;
case 'albums':$url.="/albums";break;
case 'blog':$url.="/blog";break;
}
$url.="?apikey=".$this->apikey."&token=".$this->token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'FreeWebs PHP API V0.1');
$result = curl_exec($ch);
curl_close($ch);
$html = str_get_html($result);
$out=array();
foreach($html->find('page') as $e) {
$out[]=array("id"=>$e->id,"name"=>$e->name,"file"=>$e->fname,"type"=>$e->type);
}
return $out;
}
public function addPageContent ($page_id, $title="",$body="") {
$post=array("apikey"=>$this->apikey,"token"=>$this->token,"title"=>$title,"body"=>$body);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.webs.com/v1/sitemanager/".$this->username."/pages/normal/".$page_id);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'FreeWebs PHP API V0.1');
$result = curl_exec($ch);
curl_close($ch);
$html = str_get_html($result);
$response = $html->find('rsp',0);
if($response->stat=="ok") {
return 1;
}else{
return 0;
}
}
public function addAlbumPhoto ($page_id, $title="",$caption="",$imagesrc) {
$post=array("apikey"=>$this->apikey,"token"=>$this->token,"title"=>$title,"caption"=>$caption,"imagesrc"=>$imagesrc);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.webs.com/v1/sitemanager/".$this->username."/pages/albums/".$page_id);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'FreeWebs PHP API V0.1');
$result = curl_exec($ch);
curl_close($ch);
$html = str_get_html($result);
$response = $html->find('rsp',0);
if($response->stat=="ok") {
return 1;
}else{
return 0;
}
}
public function addBlogEntry ($title="",$body="") {
$post=array("apikey"=>$this->apikey,"token"=>$this->token,"title"=>$title,"body"=>$body);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.webs.com/v1/sitemanager/".$this->username."/pages/blog");
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'FreeWebs PHP API V0.1');
$result = curl_exec($ch);
curl_close($ch);
$html = str_get_html($result);
$response = $html->find('rsp',0);
if($response->stat=="ok") {
return 1;
}else{
return 0;
}
}
///////////////////File Manager Services/////////////////////////////////
public function listFiles ($path='',$filter='') {
$url="http://api.webs.com/v1/filemanager/".$this->username.$path."?apikey=".$this->apikey."&token=".$this->token;
switch($filter) {
case 'image':$url.="&filter=image";break;
case 'media':$url.="&filter=media";break;
case 'video':$url.="&filter=video";break;
case 'other':$url.="&filter=other";break;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'FreeWebs PHP API V0.1');
$result = curl_exec($ch);
curl_close($ch);
$html = str_get_html($result);
$out=array();
foreach($html->find('directory') as $e) {
$out[]=array("type"=>"dir","path"=>$e->path,"name"=>$e->innerhtml);
}
foreach($html->find('file') as $e) {
$out[]=array("type"=>"file","file"=>$e->fname,"url"=>$e->url,"size"=>$e->size,"path"=>$e->path);
}
return $out;
}
public function getFileInfo ($path='',$file='') {
$url="http://api.webs.com/v1/filemanager/".$this->username.$path."/".$file."?apikey=".$this->apikey."&token=".$this->token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'FreeWebs PHP API V0.1');
$result = curl_exec($ch);
curl_close($ch);
$html = str_get_html($result);
foreach($html->find('file') as $e) {
$out=array("type"=>"file","file"=>$e->fname,"url"=>$e->url,"size"=>$e->size,"path"=>$e->path);
}foreach($html->find('title') as $e) {
$out['title']=$e->innerhtml;
}foreach($html->find('tags') as $e) {
$out['tags']=$e->innerhtml;
}foreach($html->find('description') as $e) {
$out['description']=$e->innerhtml;
}foreach($html->find('private') as $e) {
$out['private']=$e->innerhtml;
}
return $out;
}
public function uploadFile ($file,$path='') {
$post=array("file"=>"@".$file,"apikey"=>$this->apikey,"token"=>$this->token);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.webs.com/v1/filemanager/'.$this->username.$path);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'FreeWebs PHP API V0.1');
$result = curl_exec($ch);
curl_close($ch);
$html = str_get_html($result);
foreach($html->find('file') as $e) {
$name = $e->fname;
$ch = curl_init();
$post=array("apikey"=>$this->apikey,"token"=>$this->token,"rename"=>end(split('[/]', $file)));
curl_setopt($ch, CURLOPT_URL, 'http://api.webs.com/v1/filemanager/'.$this->username.$path.'/'.$name);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'FreeWebs PHP API V0.1');
$result = curl_exec($ch);
curl_close($ch);
}
$html = str_get_html($result);
$response = $html->find('rsp',0);
if($response->stat=="ok") {
return 1;
}else{
return $result;
}
}
public function renameFile ($path='',$file,$rename='',$title='',$tags='',$description='',$private='') {
$ch = curl_init();
$post=array("apikey"=>$this->apikey,"token"=>$this->token);
if(strlen($rename)>0) {$post['rename']=$rename;}
if(strlen($title)>0) {$post['title']=$title;}
if(strlen($tags)>0) {$post['tags']=$tags;}
if(strlen($description)>0) {$post['description']=$description;}
if(strlen($private)>0) {$post['private']=$private;}
curl_setopt($ch, CURLOPT_URL, 'http://api.webs.com/v1/filemanager/'.$this->username.$path.'/'.$file);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'FreeWebs PHP API V0.1');
$result = curl_exec($ch);
curl_close($ch);
$html = str_get_html($result);
$response = $html->find('rsp',0);
if($response->stat=="ok") {
return 1;
}else{
return 0;
}
}
}
?>
Return current item: Webs.com API Library