Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Add default parameters value to make sharing simpler via RestAPI. Sim…
Browse files Browse the repository at this point in the history
…ple call via /share/public/path/to/file.ext or /share/private/path/to/file.ext?guest_user_pass=password

Fix URL detection on API case (remove all after API).
  • Loading branch information
cdujeu committed Feb 7, 2015
1 parent e49304c commit 5c0a9b1
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
8 changes: 7 additions & 1 deletion core/src/core/classes/class.AJXP_Utils.php
Expand Up @@ -871,7 +871,13 @@ public static function detectServerURL($withURI = false)
if (!$withURI) {
return "$protocol://$name$port";
} else {
return "$protocol://$name$port".dirname($_SERVER["REQUEST_URI"]);
$uri = dirname($_SERVER["REQUEST_URI"]);
$api = ConfService::currentContextIsRestAPI();
if(!empty($api)){
// Keep only before api base
$uri = array_shift(explode("/".$api."/", $uri));
}
return "$protocol://$name$port".$uri;
}
}

Expand Down
20 changes: 20 additions & 0 deletions core/src/core/classes/class.ConfService.php
Expand Up @@ -164,6 +164,26 @@ public static function currentContextIsCommandLine()
{
return php_sapi_name() === "cli";
}

protected static $restAPIContext;

/**
* Set or get if we are currently running REST
* @static
* @param null $set
* @param string $baseUrl
* @return bool
*/
public static function currentContextIsRestAPI($restBase = '')
{
if(!empty($restBase)){
self::$restAPIContext = $restBase;
return $restBase;
}else{
return self::$restAPIContext;
}
}

/**
* Check the presence of mcrypt and option CMDLINE_ACTIVE
* @static
Expand Down
27 changes: 26 additions & 1 deletion core/src/plugins/action.share/class.ShareCenter.php
Expand Up @@ -182,6 +182,12 @@ public function switchAction($action, $httpVars, $fileVars)
//------------------------------------
case "share":
$subAction = (isSet($httpVars["sub_action"])?$httpVars["sub_action"]:"");
if(empty($subAction) && isSet($httpVars["simple_share_type"])){
$subAction = "create_minisite";
if(!isSet($httpVars["simple_right_read"]) && !isSet($httpVars["simple_right_download"])){
$httpVars["simple_right_read"] = $httpVars["simple_right_download"] = "true";
}
}
$file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
$ajxpNode = new AJXP_Node($this->urlBase.$file);
if (!file_exists($ajxpNode->getUrl())) {
Expand Down Expand Up @@ -223,6 +229,12 @@ public function switchAction($action, $httpVars, $fileVars)
} else if ($subAction == "create_minisite") {
header("Content-type:text/plain");
if(isSet($httpVars["hash"]) && !empty($httpVars["hash"])) $httpHash = $httpVars["hash"];
if(isSet($httpVars["simple_share_type"])){
$httpVars["create_guest_user"] = "true";
if($httpVars["simple_share_type"] == "private" && !isSet($httpVars["guest_user_pass"])){
throw new Exception("Please provide a guest_user_pass for private link");
}
}
$res = $this->createSharedMinisite($httpVars, $this->repository, $this->accessDriver);
if (!is_array($res)) {
$url = $res;
Expand Down Expand Up @@ -971,13 +983,22 @@ public static function loadMinisite($data, $hash = '', $error = null)
$minisiteLogo = "index_shared.php?get_action=get_global_binary_param&binary_id=". $logoPath;
}
}
$templateName = "ajxp_shared_folder";
// Default value
if(isSet($data["AJXP_TEMPLATE_NAME"])){
$templateName = $data["AJXP_TEMPLATE_NAME"];
if($templateName == "ajxp_film_strip" && AJXP_Utils::userAgentIsMobile()){
$templateName = "ajxp_shared_folder";
}
}
if(!isSet($templateName)){
$repoObject = ConfService::getRepositoryById($repository);
$filter = $repoObject->getContentFilter();
if(!empty($filter) && count($filter->virtualPaths) == 1){
$templateName = "ajxp_unique_strip";
}else{
$templateName = "ajxp_shared_folder";
}
}
// UPDATE TEMPLATE
$html = file_get_contents(AJXP_INSTALL_PATH."/".AJXP_PLUGINS_FOLDER."/action.share/res/minisite.php");
AJXP_Controller::applyHook("tpl.filter_html", array(&$html));
Expand Down Expand Up @@ -1538,6 +1559,10 @@ public function createSharedMinisite($httpVars, $repository, $accessDriver)
if($setFilter){
$httpVars["filter_nodes"] = $userSelection->buildNodes($this->accessDriver);
}
if(!isSet($httpVars["repo_label"])){
$first = $userSelection->getUniqueNode($this->accessDriver);
$httpVars["repo_label"] = SystemTextEncoding::toUTF8($first->getLabel());
}
}
$newRepo = $this->createSharedRepository($httpVars, $repository, $accessDriver, $uniqueUser);

Expand Down
5 changes: 3 additions & 2 deletions core/src/plugins/action.share/manifest.xml
Expand Up @@ -243,8 +243,9 @@
if(action) action.selectionContext.dir = false;
}
]]></clientListener>
<serverCallback methodName="switchAction" developerComment="Main action for sharing a file or a folder">
<input_param description="Path of the resource to share" name="file" type="path" mandatory="true"/>
<serverCallback methodName="switchAction" restParams="/simple_share_type/file+" developerComment="Main action for sharing a file or a folder">
<input_param description="Path of the resource to share" name="nodes" type="AJXP_NODE[]" mandatory="true"/>
<input_param description="Simple type for sharing via the REST api, always links, public or private" name="simple_share_type" type="public|private" mandatory="false"/>
<input_param description="Specific type of sharing" name="sub_action" type="delegate_repo|create_minisite|public_link" mandatory="true"/>
<input_param description="For editing the data of an existing workspace/minisite" name="repository_id" type="string" mandatory="false"/>
<input_param description="For a workspace, directly set a watch on this for the current user" name="self_watch_folder" type="boolean"/>
Expand Down
2 changes: 1 addition & 1 deletion core/src/rest.php
Expand Up @@ -44,7 +44,7 @@
exit;
}
$authDriver = ConfService::getAuthDriverImpl();

ConfService::currentContextIsRestAPI("api");

$uri = $_SERVER["REQUEST_URI"];
$scriptUri = ltrim(dirname($_SERVER["SCRIPT_NAME"]),'/')."/api/";
Expand Down

0 comments on commit 5c0a9b1

Please sign in to comment.