createGroupIfNotExistsFor("John@McLear.co.uk");
$groupID = $mappedGroup->groupID;
} catch (Exception $e) {}
// Create a session
/* get Mapped Author ID based on a value from your web application such as the userID */
try {
$author = $instance->createAuthorIfNotExistsFor('John McLear', 'Cake');
$authorID = $author->authorID;
} catch (Exception $e) {
echo "\n\ncreateAuthorIfNotExistsFor Failed with message ". $e->getMessage();
}
$validUntil = mktime(0, 0, 0, date("m"), date("d")+1, date("y")); // One day in the future
$sessionID = $instance->createSession($groupID, $authorID, $validUntil);
$sessionID = $sessionID->sessionID;
setcookie("sessionID",$sessionID); // Set a cookie
// echo "New Session ID is $sessionID->sessionID\n\n";
// Run some logic based on the initial request
if ($action){ // if an action is set then lets do it.
if ($action == "newPad") // If the request is to create a new pad
{
$name = $_GET["name"];
if (!$name){
function genRandomString() { // A funtion to generate a random name if something doesn't already exist
$length = 10;
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$string = '';
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
}
return $string;
}
$name = genRandomString();
}
$contents = $_GET["contents"];
try {
$newPad = $instance->createGroupPad($groupID,$name,$contents);
$padID = $newPad->padID;
$newlocation = "$host/p/$padID"; // redirect to the new padID location
header( "Location: $newlocation" ) ;
} catch (Exception $e) {
echo "\n\ncreateGroupPad Failed with message ". $e->getMessage();
}
}
if ($action == "deletePad") // If teh request is to delete an existing pad
{
$name = $_GET["name"];
try {
// urldecode seems to be a historical problem
$name = urldecode($name);
$instance->deletePad($groupID . "\$" . $name);
} catch (Exception $e) {
// the pad doesn't exist?
echo "\n\ndeletePad Failed with message ". $e->getMessage();
}
}
if ($action == "makePublic") // If teh request is to delete an existing pad
{
$name = $_GET["name"];
try {
$instance->setPublicStatus($name,"true");
} catch (Exception $e) {
// the pad doesn't exist?
echo "\n\nMake Public Failed with message ". $e->getMessage();
}
}
if ($action == "makePrivate") // If teh request is to delete an existing pad
{
$name = $_GET["name"];
try {
$instance->setPublicStatus($name,"false");
} catch (Exception $e) {
// the pad doesn't exist?
echo "\n\nMake Private Failed with message ". $e->getMessage();
}
}
}
// Step 2, list Pads from this Group.
/* Example: List Pads from a group */
try {
$padList = $instance->listPads($groupID);
$padList = $padList->padIDs;
} catch (Exception $e) {
echo "\n\nlistPads Failed: ". $e->getMessage();
}
// Begin writing to the UI
// echo "Pads
";
echo "Create new Pad
";
$count = 0;
foreach($padList as $pad => $key){ // For each pad in the object
// This should really be ordered based on last modified
$padname = explode("$",$pad);
$group = $padname[0];
$padname = $padname[1];
$padContents = $instance->getText($pad); // Get the pad contents
$contents = $padContents->text;
// this should escape whitespaces at $padname. Note: whitespaces dosn't appear in new versions of etherpad-lite
$padnameEncoded = urlencode($padname);
$padUrl = $group . "\$" . $padnameEncoded;
echo "
";
echo "
";
echo " -
";
echo "
$contents
";
echo "
";
echo "
";
$readOnlyID = $instance->getReadOnlyID($pad);
$readOnlyID = $readOnlyID->readOnlyID;
echo "
Read only view";
$getpublicStatus = $instance->getPublicStatus($pad); // get Security status of the pad
if ($getpublicStatus->publicStatus === false){
echo "";
}
else{
echo "";
}
echo "
";
$count++;
}
echo "
";
?>