wikidot_class.inc Details

Here is the source for the wikidot_class.inc file used in the API Methods examples.

There are 2 version of this file on the Downloads page. The one displayed below and used in the live samples has several PHP echo statements that were used to output various bits of information to make it easier to debug and see what was happening while developing this code.

The second version is cleaned up and will only output "Fault Code" (error) results on your page. You may prefer to use this "clean" version on your live sites (and you may prefer to change the error handling to something more suitable for your needs).

The wikidot_class.inc methods and classes are described in more detail here.

You can download the "development" version of the file here (right-click and save target/link as…)

The "clean" version of the file is here (right-click and save target/link as…)

<?php
/*
Wikidot API PHP Wrapper
 
Copyright 2012 by Jerad Whitaker
Beta v 0.5, 9/6/2012
 
Web Site: http://php-api.wikidot.com
 
This work is licenced under the Creative Commons Attribution-ShareAlike 3.0 License
http://creativecommons.org/licenses/by-sa/3.0/
 
You are free:
    to Share — to copy, distribute and transmit the work
    to Remix — to adapt the work
    to make commercial use of the work
 
Under the following conditions:
    Attribution — You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
    Share Alike — If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.
 
With the understanding that:
    Waiver — Any of the above conditions can be waived if you get permission from the copyright holder.
    Public Domain — Where the work or any of its elements is in the public domain under applicable law, that status is in no way affected by the license.
    Other Rights — In no way are any of the following rights affected by the license:
        Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations;
        The author's moral rights;
        Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights.
    Notice — For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page.
*/
//Wikidot classes have minimal error handling,
//error messages will be cryptic at best
//Wikidot parent class
class WikidotSite
{private $site;
private $client;
private $timeout = 30;
private $debug = 0;
private $name;
private $usertitle;
private $user;
//////////////////constructor destructor
function __construct($pSite, $pClient)
{    echo "Constructor called....</br>";
    $this->site = $pSite;
    $this->client = $pClient;
}
function __destruct()
{    echo "Destructor called....</br>";
    foreach ($this as $key => $value) {
        unset($this->$key);} 
}
//////////////////set functions
function setSite($pSite){$this->site = $pSite;}
function setTimeout($pTimeout){$this->timeout = $pTimeout;}
function setDebug($pDebug){$this->debug = $pDebug;}
function setClient($pClient){$this->client = $pClient;}
function setName($pName){$this->name = $pName;}
function setUsertitle($pUTitle){$this->usertitle = $pUTitle;}
function setUser($pUser){$this->user = $pUser;}
//////////////////get functions
function getClient(){return $this->client;}
function getSite(){return $this->site;}
function getTimeout(){return $this->timeout;}
function getDebug(){return $this->debug;}
//////////////////api wrapper functions
function php_categories_select($sSite, &$returnar)
{    echo "</br>Start New Categories Select</br>\n";
    $request = new xmlrpcmsg("categories.select");
    $request->addParam(new xmlrpcval(
            array("site" => new xmlrpcval($sSite, "string")),"struct"));
    $result = $this->client->send($request, $this->timeout, "https");
    $resultvalue = $result->value();
    if(!$result->faultCode()) { // SUCCESS!
        $returnar = $resultvalue;
        return true; }
    else {echo "<font color=\"red\"> <H1>Fault</H1><BR>\n"." Code: ".$result->faultCode()."\n<BR>".
        " Reason: ".$result->faultString()."'\n<BR></font>";
        return false;}
}
function php_tags_select($criteria, &$returnar)
{    echo "</br>Start New Tags Select</br>\n";
    $request = new xmlrpcmsg("tags.select");
    $selectors = array();
    $criteria[0] = ""; //forces $criteria to be an array
    $selectors['site'] = new xmlrpcval($this->site, "string");
//////////parse critera
    foreach($criteria as $key=>$data){
        switch($key){
            case "categories":
                $sCat = array();
                foreach($data as $dkey=>$cat){
                    $sCat[$dkey] = new xmlrpcval($cat);}
                $selectors['categories'] = new xmlrpcval($sCat, "array");
                break;
            case "page":
                $sPage = array();
                foreach($data as $dkey=>$cat){
                    $sPage[$dkey] = new xmlrpcval($cat);}
                $selectors['pages'] = new xmlrpcval($sPage, "array");
                break;}}  
    $request->addParam(new xmlrpcval($selectors, "struct"));
    $result = $this->client->send($request, $this->timeout, "https");
    $resultvalue = $result->value();
    if(!$result->faultCode()) { // SUCCESS!
        $returnar = $resultvalue;
        return true; }
    else {echo "<font color=\"red\"> <H1>Fault</H1><BR>\n"." Code: ".$result->faultCode()."\n<BR>".
        " Reason: ".$result->faultString()."'\n<BR></font>";
        return false;}
}
function php_posts_select($criteria, &$returnar)
{    echo "</br>Start New Posts Select</br>\n";
    $request = new xmlrpcmsg("posts.select");
    $selectors = array();
    $criteria[0] = ""; //forces $criteria to be an array
    $selectors['site'] = new xmlrpcval($this->site, "string");
//////////parse critera
    foreach($criteria as $key=>$data){
        switch($key){
            case "page": $selectors['page'] = new xmlrpcval($data, "string" );
                break;
            case "thread": $selectors['thread'] = new xmlrpcval($data, "string" );
                break;
            case "reply_to": $selectors['reply_to'] = new xmlrpcval($data, "string" );
                break;
            case "created_by": $selectors['created_by'] = new xmlrpcval($data, "string" );
                break;}}  
    $request->addParam(new xmlrpcval($selectors, "struct"));
    $result = $this->client->send($request, $this->timeout, "https");
    $resultvalue = $result->value();
    if(!$result->faultCode()) { // SUCCESS!
        $returnar = $resultvalue;
        return true; }
    else {echo "<font color=\"red\"> <H1>Fault</H1><BR>\n"." Code: ".$result->faultCode()."\n<BR>".
        " Reason: ".$result->faultString()."'\n<BR></font>";
        return false;}
}
function php_posts_get($posts, &$returnar)
{    echo "</br>Start New Posts Get</br>\n";
    $request = new xmlrpcmsg("posts.get");
    $temparray = array();
//    $posts['a'] = ""; //forces $posts to be an array
    foreach($posts as $key=>$data){
        $temparray[$key] = new xmlrpcval($data);}
    $xmlposts = new xmlrpcval($temparray, "array");    
    $request->addParam(new xmlrpcval(array(
        "site" => new xmlrpcval($this->site, "string"),
        "posts" => $xmlposts), "struct"));
    $result = $this->client->send($request, $this->timeout, "https");
    $resultvalue = $result->value();
    if(!$result->faultCode()) { // SUCCESS!
        $returnar = $resultvalue;
        return true; }
    else {echo "<font color=\"red\"> <H1>Fault</H1><BR>\n"." Code: ".$result->faultCode()."\n<BR>".
        " Reason: ".$result->faultString()."'\n<BR></font>";
        return false;}
}
function php_users_get_me(&$returnar)
{    echo "</br>Start New Users Get Me</br>\n";
    $request = new xmlrpcmsg("users.get_me");
    $result = $this->client->send($request, $this->timeout, "https");
    $resultvalue = $result->value();
    if(!$result->faultCode()) { // SUCCESS!
        $returnar = $resultvalue;
        return true; }
    else {echo "<font color=\"red\"> <H1>Fault</H1><BR>\n"." Code: ".$result->faultCode()."\n<BR>".
        " Reason: ".$result->faultString()."'\n<BR></font>";
        return false;}
}
}//end class WikidotSite
 
//////////////////pages classes
//////////////////parent WikidotMeta Class
class WikidotMeta extends WikidotSite
{//////////////////constructor destructor
function __construct($spSite, $spClient)
{    echo "Subclass Constructor called....</br>";
    WikidotSite::__construct($spSite, $spClient);
    $this->site = WikidotSite::getSite();
    $this->client = WikidotSite::getClient();
    $this->timeout = WikidotSite::getTimeout();
    $this->debug = WikidotSite::getDebug();
}
function __destruct()
{    echo "Subclass Destructor called....</br>";
    foreach ($this as $key => $value) {
        unset($this->$key);} 
}
//////////////////set functions
//////////////////meta properties
private $metapages;
private $fullname;
private $created_at;
private $created_by;
private $updated_at;
private $updated_by;
private $title;
private $parent_fullname; //was  = "-";
private $tags; //xmlrpcval array of tags
private $rating;
private $revisions;
private $metacomments;    //planned
private $files;        //planned
private $metachildren;    //planned
//////////////////set functions
function setFullname($pFName){$this->fullname = $pFName;}
function setCreatedAt($pCAt){$this->created_at = $pCAt;}
function setCreatedBy($pCBy){$this->created_by = $pCBy;}
function setUpdatedAt($pUAt){$this->updated_at = $pUAt;}
function setUpdatedBy($pUBy){$this->updated_by = $pUBy;}
function setTitle($pTitle){$this->title = $pTitle;}
function setParentFullname($pParent){$this->parent_fullname = $pParent;}
function setTags($tarray)
{    $temparray = array();
    foreach($tarray as $key=>$tval){
        $temparray[$key] = new xmlrpcval($tval);}
    $this->tags = new xmlrpcval($temparray, "array");
}
function setRating($pRate){$this->rating = $pRate;}
function setRevisions($pRev){$this->revision = $pRev;}
//////////////////get functions
function getMetapages(){return $this->metapages;}
function getFullname(){return $this->fullname;}
function getCreatedAt(){return $this->create_at;}
function getCreatedBy(){return $this->created_by;}
function getUpdatedAt(){return $this->updated_at;}
function getUpdatedBy(){return $this->updated_by;}
function getTitle(){return $this->title;}
function getParentFullname(){return $this->parent_fullname;}
function getTags(){return $this->tags;}
function getRating(){return $this->rating;}
function getRevisions(){return $this->revisions;}
function getMetacomments(){return $this->metacomments;}
function getFiles(){return $this->files;}
function getMetachildren(){return $this->metachildren;}
//////////////////api wrapper functions
function php_pages_get_meta($pArray, &$returnar)
{    echo "</br>Start New Pages Get Meta</br>\n";
    $request = new xmlrpcmsg("pages.get_meta");
    $temparray = array();
//    $pArray['a'] = ""; //forces $pArray to be an array
    foreach($pArray as $key=>$tval){
        $temparray[$key] = new xmlrpcval($tval);}
    $pagearray = new xmlrpcval($temparray, "array");
    $request->addParam(new xmlrpcval(
            array("site" => new xmlrpcval($this->site, "string"),
                "pages" => $pagearray),"struct"));
    $result = $this->client->send($request, $this->timeout, "https");
    $resultvalue = $result->value();
    if(!$result->faultCode()) { // SUCCESS!
        $returnar = $resultvalue;
        return true; }
    else {echo "<font color=\"red\"> <H1>Fault</H1><BR>\n"." Code: ".$result->faultCode()."\n<BR>".
        " Reason: ".$result->faultString()."'\n<BR></font>";
        return false;}
}
}//end class WikidotMeta
 
//////////////////Extended Classes to WikidotMeta
class WikidotPage extends WikidotMeta
{//////////////////constructor destructor
function __construct($spSite, $spClient)
{    echo "Subclass Constructor called....</br>";
    WikidotSite::__construct($spSite, $spClient);
    $this->site = WikidotSite::getSite();
    $this->client = WikidotSite::getClient();
    $this->timeout = WikidotSite::getTimeout();
    $this->debug = WikidotSite::getDebug();
    $this->metapages = WikidotMeta::getMetapages();
    $this->fullname = WikidotMeta::getFullname();
    $this->created_at = WikidotMeta::getCreatedAt();
    $this->created_by = WikidotMeta::getCreatedBy();
    $this->updated_at = WikidotMeta::getUpdatedAt();
    $this->updated_by = WikidotMeta::getUpdatedBy();
    $this->title = WikidotMeta::getTitle();
    $this->parent_fullname = WikidotMeta::getParentFullname();
    $this->tags  = WikidotMeta::getTags();
    $this->rating = WikidotMeta::getRating();
    $this->revisions = WikidotMeta::getRevisions();
    $this->metacomments = WikidotMeta::getMetacomments();
    $this->files = WikidotMeta::getFiles();
    $this->metachildren = WikidotMeta::getMetachildren();
}
function __destruct()
{    echo "Subclass Destructor called....</br>";
    foreach ($this as $key => $value) {
        unset($this->$key);} 
}
//////////////////page properties
private $page;
private $parent_title;
private $children;
private $content = "Empty Page";
private $html;
private $comments;
private $commented_at;
private $commented_by;
private $save_mode = "create_or_update";
private $rename_as;
private $revision_comment;
private $notify_watchers = "false";
//////////////////set functions
function setPage($pname){$this->page = $pname;}
function setParentTitle($pPTitle){$this->parent_title = $pPTitle;}
function setChildren($pChild){$this->children = $pChild;}
function setContent($pContent){$this->content = $pContent;}
function setHTML($pHTML){$this->html = $pHTML;}
function setComments($pCom){$this->comments = $pCom;}
function setCommentedAt($pCmAt){$this->commented_at = $pCmAt;}
function setCommentedBy($pCmBy){$this->commented_by = $pCmBy;}
function setSaveMode($pMode){$this->save_mode = $pMode;}
function setRenameAs($pRen){$this->rename_as = $pRen;}
function setRevisionComment($pRCom){$this->revision_comment = $pRCom;}
function setNotifyWatchers($pNotify){$this->notify_watchers = $pNotify;}
//////////////////get functions
function getPage(){return $this->page;}
function getParentTitle(){return $this->parent_title;}
function getChildren(){return $this->children;}
function getContent(){return $this->content;}
function getHTML(){return $this->html;}
function getComments(){return $this->comments;}
function getCommentedAt(){return $this->commented_at;}
function getCommentedBy(){return $this->commented_by;}
function getSaveMode(){return $this->save_mode;}
function getRenameAs(){return $this->rename_as;}
function getRevisionComment(){return $this->revision_comment;}
function getNotifyWatchers(){return $this->notify_watchers;}
//////////////////api wrapper functions
function php_pages_select($criteria, &$returnar)
{    echo "</br>Start New Pages Select</br>\n";
    $request = new xmlrpcmsg("pages.select");
    $selectors = array();
    $selectors['site'] = new xmlrpcval($this->site, "string");
//////////parse critera
    foreach($criteria as $key=>$data){
        switch($key){
            case "pagetype":  
            $selectors['pagetype'] = new xmlrpcval($data, "string" ); break;
            case "categories":
                $sCat = array();
                foreach($data as $dkey=>$cat){
                    $sCat[$dkey] = new xmlrpcval($cat);}
                $selectors['categories'] = new xmlrpcval($sCat, "array");
                break;
            case "tags_any":    
                $sYtag = array();
                foreach($data as $dkey=>$tag){
                    $sYtag[$dkey] = new xmlrpcval($tag);}
                $selectors['tags_any'] = new xmlrpcval($sYtag, "array");
                break;
            case "tags_all":    
                $sAtag = array();
                foreach($data as $dkey=>$tag){
                    $sAtag[$dkey] = new xmlrpcval($tag);}
                $selectors['tags_all'] = new xmlrpcval($sAtag, "array");
                break;
            case "tags_none":    
                $sNtag = array();
                foreach($data as $dkey=>$tag){
                    $sNtag[$dkey] = new xmlrpcval($tag);}
                $selectors['tags_none'] = new xmlrpcval($sNtag, "array");
                break;
            case "parent": 
                $selectors['parent'] = new xmlrpcval($data, "string" ); break; 
            case "created_at": 
                $selectors['created_at'] = new xmlrpcval($data, "string" ); break;
            case "created_by": 
                $selectors['created_by'] = new xmlrpcval($data, "string" ); break;
            case "rating": 
                $selectors['rating'] = new xmlrpcval($data, "string" ); break;
            case "order":  
                $selectors['order'] = new xmlrpcval($data, "string" ); break;
            case "link_to": 
                $selectors['link_to'] = new xmlrpcval($data, "string" ); break;
            case "offset": 
                $selectors['offset'] = new xmlrpcval($data, "string" ); break;
            case "range": 
                $selectors['range'] = new xmlrpcval($data, "string" ); break;
            case "datafield":  
                $selectors[$data[0]] = new xmlrpcval($data[1], "string" );
                break;}}
    $request->addParam(new xmlrpcval($selectors, "struct"));
    $result = $this->client->send($request, $this->timeout, "https");
    $resultvalue = $result->value();
    if(!$result->faultCode()) { // SUCCESS!
        $returnar = $resultvalue;
        return true; }
    else {echo "<font color=\"red\"> <H1>Fault</H1><BR>\n"." Code: ".$result->faultCode()."\n<BR>".
        " Reason: ".$result->faultString()."'\n<BR></font>";
        return false;}
}
function php_pages_get_one(&$returnar)
{    echo "</br>Start New Pages Get One</br>\n";
    $request = new xmlrpcmsg("pages.get_one");
    $request->addParam(new xmlrpcval(
            array("site" => new xmlrpcval($this->site, "string"),
                "page" => new xmlrpcval($this->page, "string")),"struct"));
    $result = $this->client->send($request, $this->timeout, "https");
    $resultvalue = $result->value();
    if(!$result->faultCode()) { // SUCCESS!
        $returnar = $resultvalue;
        return true; }
    else {echo "<font color=\"red\"> <H1>Fault</H1><BR>\n"." Code: ".$result->faultCode()."\n<BR>".
        " Reason: ".$result->faultString()."'\n<BR></font>";
        return false;}
}
function php_pages_save_one($svmode)
{    echo "</br>Start New Pages Save One</br>\n";
    $request = new xmlrpcmsg("pages.save_one");
    $temparray = array();
    $temparray['site'] = new xmlrpcval($this->site, "string");
    $temparray['page'] = new xmlrpcval($this->page, "string");
    $temparray['title'] = new xmlrpcval($this->title, "string");
    $temparray['content'] = new xmlrpcval($this->content, "string");
    $temparray['tags'] = $this->getTags();
    $temparray['save_mode'] = new xmlrpcval($svmode, "string");
    $temparray['rename_as'] = new xmlrpcval($this->rename_as, "string");
    $temparray['revision_comment'] = new xmlrpcval($this->revision_comment, "string");
    if(WikidotMeta::getParentFullname()){
        $parent = WikidotMeta::getParentFullname();
        $temparray['parent_fullname'] = new xmlrpcval($parent, "string");}
    $request->addParam(new xmlrpcval($temparray, "struct"));
    $result = $this->client->send($request, $this->timeout, "https");
    $resultvalue = $result->value();
    if(!$result->faultCode()) { // SUCCESS!
        return true; }
    else {echo "<font color=\"red\"> <H1>Fault</H1><BR>\n"." Code: ".$result->faultCode()."\n<BR>".
        " Reason: ".$result->faultString()."'\n<BR></font>";
        return false;}
}
}//end class WikidotPage
 
//////////////////files classes
//////////////////parent FilesWikidotMeta Class
class FilesWikidotMeta extends WikidotSite
{//////////////////constructor destructor
function __construct($spSite, $spClient)
{    echo "Subclass Constructor called....</br>";
    WikidotSite::__construct($spSite, $spClient);
    $this->site = WikidotSite::getSite();
    $this->client = WikidotSite::getClient();
    $this->timeout = WikidotSite::getTimeout();
    $this->debug = WikidotSite::getDebug();
}
function __destruct()
{    echo "Subclass Destructor called....</br>";
    foreach ($this as $key => $value) {
        unset($this->$key);} 
}
//////////////////meta properties
private $page;
private $files;
private $size;
private $comment;
private $mime_type;
private $mime_description;
private $uploaded_by;
private $uploaded_at;
private $download_url;
//////////////////set functions
function setPage($pname){$this->page = $pname;}
//////////////////get functions
function getPage(){return $this->page;}
//////////////////api wrapper functions
function php_files_select($category, &$returnar)
{    echo "</br>Start New Files Select</br>\n";
    $request = new xmlrpcmsg("files.select");
    $request->addParam(new xmlrpcval(
            array("site" => new xmlrpcval($this->site, "string"),
                "page" => new xmlrpcval($category, "string")),"struct"));
    $result = $this->client->send($request, $this->timeout, "https");
    $resultvalue = $result->value();
    if(!$result->faultCode()) { // SUCCESS!
        $returnar = $resultvalue;
        return true; }
    else {echo "<font color=\"red\"> <H1>Fault</H1><BR>\n"." Code: ".$result->faultCode()."\n<BR>".
        " Reason: ".$result->faultString()."'\n<BR></font>";
        return false;}
}
function php_files_get_meta($files, &$returnar)
{    echo "</br>Start New Files Get Meta</br>\n";
    $request = new xmlrpcmsg("files.get_meta");
    $temparray = array();
    $temparray['site'] = new xmlrpcval($this->site, "string");
    $temparray['page'] = new xmlrpcval($this->page, "string");
    $filearray = array();
    foreach($files as $key=>$data){
        $filearray[$key] = new xmlrpcval($data, "string");}
     $temparray['files'] = new xmlrpcval($filearray, "array");
     $request->addParam(new xmlrpcval($temparray, "struct"));
    $result = $this->client->send($request, $this->timeout, "https");
    $resultvalue = $result->value();
    if(!$result->faultCode()) { // SUCCESS!
        $returnar = $resultvalue;
        return true; }
    else {echo "<font color=\"red\"> <H1>Fault</H1><BR>\n"." Code: ".$result->faultCode()."\n<BR>".
        " Reason: ".$result->faultString()."'\n<BR></font>";
        return false;}
}
function php_files_get_one($file, &$returnar)
{    echo "</br>Start New Files Get One</br>\n";
    $request = new xmlrpcmsg("files.get_one");
    $temparray = array();
    $temparray['site'] = new xmlrpcval($this->site, "string");
    $temparray['page'] = new xmlrpcval($this->page, "string");
     $temparray['file'] = new xmlrpcval($file, "string");
     $request->addParam(new xmlrpcval($temparray, "struct"));
    $result = $this->client->send($request, $this->timeout, "https");
    $resultvalue = $result->value();
    if(!$result->faultCode()) { // SUCCESS!
        $returnar = $resultvalue;
        return true; }
    else {echo "<font color=\"red\"> <H1>Fault</H1><BR>\n"." Code: ".$result->faultCode()."\n<BR>".
        " Reason: ".$result->faultString()."'\n<BR></font>";
        return false;}
}
function php_files_save_one($criteria, &$returnar)
{    echo "</br>Start New Files Save One</br>\n";
    $request = new xmlrpcmsg("files.save_one");
    $selectors = array();
    $selectors['site'] = new xmlrpcval($this->site, "string");
//////////parse critera
    foreach($criteria as $key=>$data){
        switch($key){
            case "file": $selectors['file'] = new xmlrpcval($data, "string" );
            echo $key.": ".$data."</br>";
                break;
            case "page": $selectors['page'] = new xmlrpcval($data, "string" );
            echo $key.": ".$data."</br>";
                break;    
            case "comment": $selectors['comment'] = new xmlrpcval($data, "string" );
            echo $key.": ".$data."</br>";
                break;
            case "save_mode": $selectors['save_mode'] = new xmlrpcval($data, "string" );
            echo $key.": ".$data."</br>";
                break;
            case "content": $selectors['content'] = new xmlrpcval($data, "string" );
            //echo $key.": ".$data."</br>";
                break;
            case "notify_watchers": 
                $selectors['notify_watchers'] = new xmlrpcval($data, "string" );
            echo $key.": ".$data."</br>";
                break;
            case "revision_comment":
                $selectors['revision_comment'] = new xmlrpcval($data, "string" );
            echo $key.": ".$data."</br>";
                break;}}  
    $request->addParam(new xmlrpcval($selectors, "struct"));
    if($selectors['content']) $result = $this->client->send($request, $this->timeout, "https");
    else {echo "no content"; return false;}
    $resultvalue = $result->value();
    if(!$result->faultCode()) { // SUCCESS!
        return true; }
    else {echo "<font color=\"red\"> <H1>Fault</H1><BR>\n"." Code: ".$result->faultCode()."\n<BR>".
        " Reason: ".$result->faultString()."'\n<BR></font>";
        return false;}
}
}//end class FilesWkidotMeta
 
?>
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License