This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
661 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
class EtherpadClient extends AJXP_Plugin{ | ||
|
||
var $baseURL = "http://10.211.55.3:9001"; | ||
|
||
public function switchAction($actionName, $httpVars, $fileVars){ | ||
|
||
if(isSet($httpVars["file"])){ | ||
|
||
$repository = ConfService::getRepository(); | ||
if(!$repository->detectStreamWrapper(false)){ | ||
return false; | ||
} | ||
$plugin = AJXP_PluginsService::findPlugin("access", $repository->getAccessType()); | ||
$streamData = $plugin->detectStreamWrapper(true); | ||
$destStreamURL = $streamData["protocol"]."://".$repository->getId()."/"; | ||
$filename = $destStreamURL. AJXP_Utils::securePath($httpVars["file"]); | ||
|
||
if(!is_file($filename)){ | ||
throw new Exception("Cannot find file!"); | ||
} | ||
} | ||
|
||
require_once("etherpad-client/etherpad-lite-client.php"); | ||
$client = new EtherpadLiteClient("nl8VJIWXZMHNj7aWj6rWy4CLct1mu97v",$this->baseURL."/api"); | ||
|
||
if($actionName == "etherpad_create"){ | ||
|
||
if(isSet($httpVars["pad_name"])){ | ||
|
||
$padID = $httpVars["pad_name"]; | ||
$startContent = ""; | ||
|
||
}else if(isSet($httpVars["file"])){ | ||
|
||
$startContent = file_get_contents($filename); | ||
$padID = AJXP_Utils::slugify($httpVars["file"]); | ||
|
||
} | ||
|
||
$userName = AuthService::getLoggedUser()->getId(); | ||
|
||
$res = $client->createAuthorIfNotExistsFor($userName, $userName); | ||
$authorID = $res->authorID; | ||
|
||
$res2 = $client->createGroupIfNotExistsFor("ajaxplorer"); | ||
$groupID = $res2->groupID; | ||
|
||
$resP = $client->listPads($res2->groupID); | ||
|
||
$pads = $resP->padIDs; | ||
if(!in_array($groupID.'$'.$padID, $pads)){ | ||
$res3 = $client->createGroupPad($groupID, $padID, $startContent); | ||
} | ||
|
||
$res4 = $client->createSession($groupID, $authorID, time()+14400); | ||
$sessionID = $res4->sessionID; | ||
|
||
setcookie('sessionID', $sessionID, null, "/"); | ||
|
||
$padID = $groupID.'$'.$padID; | ||
|
||
$data = array( | ||
"url" => $this->baseURL."/p/".$padID, | ||
"padID" => $padID, | ||
"sessionID" => $sessionID, | ||
); | ||
|
||
HTMLWriter::charsetHeader('application/json'); | ||
echo(json_encode($data)); | ||
|
||
}else if ($actionName == "etherpad_save"){ | ||
|
||
$padID = $httpVars["pad_id"]; | ||
$res = $client->getText($padID); | ||
file_put_contents($filename, $res->text); | ||
|
||
}else if ($actionName == "etherpad_close"){ | ||
|
||
// WE SHOULD DETECT IF THERE IS NOBODY CONNECTED ANYMORE, AND DELETE THE PAD. | ||
$sessionID = $httpVars["session_id"]; | ||
$i = $client->getSessionInfo($sessionID); | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
} |
87 changes: 87 additions & 0 deletions
87
core/src/plugins/editor.etherpad/class.EtherpadLauncher.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2007-2011 Charles du Jeu <contact (at) cdujeu.me> | ||
* This file is part of AjaXplorer. | ||
* | ||
* AjaXplorer is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* AjaXplorer is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with AjaXplorer. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* The latest code can be found at <http://www.ajaxplorer.info/>. | ||
*/ | ||
Class.create("EtherpadLauncher", AbstractEditor, { | ||
|
||
padID:null, | ||
sessionID: null, | ||
node: null, | ||
|
||
initialize: function($super, oFormObject) | ||
{ | ||
$super(oFormObject); | ||
if(!ajaxplorer.user || ajaxplorer.user.canWrite()){ | ||
this.canWrite = true; | ||
this.actions.get("saveButton").observe('click', function(){ | ||
this.saveFile(); | ||
return false; | ||
}.bind(this)); | ||
}else{ | ||
this.canWrite = false; | ||
this.actions.get("saveButton").hide(); | ||
} | ||
this.actions.get("downloadFileButton").observe('click', function(){ | ||
if(!this.currentFile) return; | ||
ajaxplorer.triggerDownload(ajxpBootstrap.parameters.get('ajxpServerAccess')+'&action=download&file='+this.currentFile); | ||
return false; | ||
}.bind(this)); | ||
}, | ||
|
||
|
||
open : function($super, nodeOrNodes){ | ||
$super(nodeOrNodes); | ||
this.node = nodeOrNodes; | ||
var fileName = nodeOrNodes.getPath(); | ||
var conn = new Connexion(); | ||
conn.addParameter("get_action", "etherpad_create"); | ||
conn.addParameter("file", fileName); | ||
conn.onComplete = function(transport){ | ||
var data = transport.responseJSON; | ||
this.padID = data.padID; | ||
this.sessionID = data.sessionID; | ||
$("ether_box").down("#ether_box_frame").src = data.url; | ||
fitHeightToBottom($("ether_box").down("#ether_box_frame")); | ||
}.bind(this); | ||
conn.sendAsync(); | ||
|
||
if(window.ajxpMobile){ | ||
this.setFullScreen(); | ||
attachMobileScroll(this.textarea, "vertical"); | ||
} | ||
this.element.observeOnce("editor:close", function(){ | ||
var conn = new Connexion(); | ||
conn.addParameter("get_action", "etherpad_close"); | ||
conn.addParameter("file", this.node.getPath()); | ||
conn.addParameter("pad_id", this.padID); | ||
conn.addParameter("session_id", this.sessionID); | ||
conn.sendAsync(); | ||
}); | ||
}, | ||
|
||
|
||
saveFile : function(){ | ||
if(!this.padID) return; | ||
var conn = new Connexion(); | ||
conn.addParameter("get_action", "etherpad_save"); | ||
conn.addParameter("file", this.node.getPath()); | ||
conn.addParameter("pad_id", this.padID); | ||
conn.sendAsync(); | ||
} | ||
|
||
}); |
Oops, something went wrong.