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

Commit

Permalink
Move editor php classes to dedicated namespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Jun 22, 2016
1 parent 7ec6edf commit eaa9c50
Show file tree
Hide file tree
Showing 21 changed files with 268 additions and 63 deletions.
2 changes: 1 addition & 1 deletion core/src/plugins/action.share/src/ShareCenter.php
Expand Up @@ -1131,7 +1131,7 @@ private function findMirrorNodesInShares($node, $direction){
if($node->getRepository()->hasParent()){
$parentRepoId = $node->getRepository()->getParentId();
$parentRepository = RepositoryService::getRepositoryById($parentRepoId);
if(!empty($parentRepository) && !$parentRepository->isTemplate){
if(!empty($parentRepository) && !$parentRepository->isTemplate()){
$currentRoot = $node->getRepository()->getContextOption($crtContext, "PATH");
$newContext = $crtContext->withRepositoryId($parentRepoId);
$owner = $node->getRepository()->getOwner();
Expand Down
@@ -0,0 +1,44 @@
<?php
/*
* Copyright 2007-2016 Abstrium <contact (at) pydio.com>
* This file is part of Pydio.
*
* Pydio 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.
*
* Pydio 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 Pydio. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <https://pydio.com/>.
*/
namespace Pydio\Access\Core\Exception;

use Pydio\Core\Exception\PydioException;

defined('AJXP_EXEC') or die('Access not allowed');

/**
* Class FileNotFoundException
* @package Pydio\Access\Core\Exception
*/
class FileNotFoundException extends PydioException
{
private $filePath;

/**
* FileNotFoundException constructor.
* @param string $filePath
*/
public function __construct($filePath)
{
$this->filePath = $filePath;
parent::__construct("Cannot find file!", false, 5015);
}
}
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2007-2013 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
* Copyright 2007-2016 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
* This file is part of Pydio.
*
* Pydio is free software: you can redistribute it and/or modify
Expand All @@ -19,10 +19,13 @@
* The latest code can be found at <http://pyd.io/>.
*/

namespace Pydio\Plugins\Editor;

use Pydio\Access\Core\AJXP_MetaStreamWrapper;
use Pydio\Access\Core\Exception\FileNotFoundException;
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\Model\UserSelection;
use Pydio\Core\Services\AuthService;
use Pydio\Core\Http\Middleware\SecureTokenMiddleware;

use Pydio\Core\Controller\Controller;
use Pydio\Core\Utils\Utils;
Expand All @@ -32,9 +35,9 @@
defined('AJXP_EXEC') or die( 'Access not allowed');

/**
* Class AudioPreviewer
* Streams MP3 files to a client
* @package AjaXplorer_Plugins
* @subpackage Editor
* @package Pydio\Plugins\Editor
*/
class AudioPreviewer extends Plugin
{
Expand All @@ -43,7 +46,7 @@ class AudioPreviewer extends Plugin
* Action Controller
* @param \Psr\Http\Message\ServerRequestInterface $requestInterface
* @param \Psr\Http\Message\ResponseInterface $responseInterface
* @throws Exception
* @throws FileNotFoundException
*/
public function switchAction(\Psr\Http\Message\ServerRequestInterface $requestInterface, \Psr\Http\Message\ResponseInterface &$responseInterface)
{
Expand All @@ -67,15 +70,15 @@ public function switchAction(\Psr\Http\Message\ServerRequestInterface $requestIn
if(!$exist && strpos($httpVars["file"], "base64encoded:") === false){
$file = Utils::decodeSecureMagic(base64_decode($httpVars["file"]));
if(!file_exists($destStreamURL.$file)){
throw new Exception("Cannot find file!");
throw new FileNotFoundException($file);
}else{
$user = $node->getUserId();
$node = new AJXP_Node($destStreamURL.$file);
$node->setUserId($user);
}
}
if(!is_readable($node->getUrl())){
throw new Exception("Cannot find file!");
throw new FileNotFoundException($node->getPath());
}


Expand Down Expand Up @@ -112,21 +115,22 @@ public function switchAction(\Psr\Http\Message\ServerRequestInterface $requestIn
// Transform the XML into XSPF
$xmlString = $responseInterface->getBody()->getContents();
$responseInterface->getBody()->rewind();
$xmlDoc = new DOMDocument();
$xmlDoc = new \DOMDocument();
$xmlDoc->loadXML($xmlString);
$xElement = $xmlDoc->documentElement;
$xmlBuff = "";
header("Content-Type:application/xspf+xml;charset=UTF-8");
$xmlBuff.='<?xml version="1.0" encoding="UTF-8"?>';
$xmlBuff.='<playlist version="1" xmlns="http://xspf.org/ns/0/">';
$xmlBuff.="<trackList>";
/** @var \DOMElement $child */
foreach ($xElement->childNodes as $child) {
$isFile = ($child->getAttribute("is_file") == "true");
$label = $child->getAttribute("text");
$ar = explode(".", $label);
$ext = strtolower(end($ar));
if(!$isFile || $ext != "mp3") continue;
$xmlBuff.="<track><location>".AJXP_SERVER_ACCESS."?secure_token=".AuthService::getSecureToken()."&get_action=audio_proxy&file=".base64_encode($child->getAttribute("filename"))."</location><title>".$label."</title></track>";
$xmlBuff.="<track><location>".AJXP_SERVER_ACCESS."?secure_token=".SecureTokenMiddleware::getSecureToken()."&get_action=audio_proxy&file=".base64_encode($child->getAttribute("filename"))."</location><title>".$label."</title></track>";
}
$xmlBuff.="</trackList>";
$xmlBuff.= "</playlist>";
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/editor.audio/manifest.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<editor id="editor.audio" order="1000" enabled="true" modalOnly="true" openable="false" previewProvider="true" text="186" title="136" icon="frame_image.png" className="AudioPreviewer" mimes="mp3" label="CONF_MESSAGE[Audio Player]" description="CONF_MESSAGE[Inserts a flash player for reading mp3 files online, and playing a whole folder in a separate window.]" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:../core.ajaxplorer/ajxp_registry.xsd">
<class_definition filename="plugins/editor.audio/class.AudioPreviewer.php" classname="AudioPreviewer"/>
<class_definition filename="plugins/editor.audio/AudioPreviewer.php" classname="Pydio\Plugins\Editor\AudioPreviewer"/>
<client_settings>
<resources>
<js file="plugins/editor.audio/class.AudioPreviewer.js" className="AudioPreviewer"/>
Expand Down
16 changes: 12 additions & 4 deletions ...s/editor.browser/class.FileMimeSender.php → ...plugins/editor.browser/FileMimeSender.php 100755 → 100644
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2007-2013 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
* Copyright 2007-2016 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
* This file is part of Pydio.
*
* Pydio is free software: you can redistribute it and/or modify
Expand All @@ -19,6 +19,8 @@
* The latest code can be found at <http://pyd.io/>.
*/

namespace Pydio\Plugins\Editor;

use Pydio\Access\Core\AJXP_MetaStreamWrapper;
use Pydio\Access\Core\Model\UserSelection;

Expand All @@ -31,12 +33,18 @@
defined('AJXP_EXEC') or die( 'Access not allowed');

/**
* Class FileMimeSender
* Extract the mimetype of a file and send it to the browser
* @package AjaXplorer_Plugins
* @subpackage Editor
* @package Pydio\Plugins\Editor
*/
class FileMimeSender extends Plugin
{
/**
* @param \Psr\Http\Message\ServerRequestInterface $requestInterface
* @param \Psr\Http\Message\ResponseInterface $responseInterface
* @throws \Pydio\Core\Exception\AuthRequiredException
* @throws \Pydio\Core\Exception\PydioException
*/
public function switchAction(\Psr\Http\Message\ServerRequestInterface $requestInterface, \Psr\Http\Message\ResponseInterface &$responseInterface)
{
if($requestInterface->getAttribute("action") !== "open_file"){
Expand Down Expand Up @@ -71,7 +79,7 @@ public function switchAction(\Psr\Http\Message\ServerRequestInterface $requestIn

//Get mimetype with fileinfo PECL extension
if (class_exists("finfo")) {
$finfo = new finfo(FILEINFO_MIME);
$finfo = new \finfo(FILEINFO_MIME);
$fileMime = $finfo->buffer(fread($fp, 2000));
}
//Get mimetype with (deprecated) mime_content_type
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/editor.browser/manifest.xml
Expand Up @@ -28,8 +28,8 @@
<!-- Stream Wrapper Access -->
<activePlugin pluginName="access.AJXP_STREAM_PROVIDER"/>
</dependencies>
<class_definition filename="plugins/editor.browser/class.FileMimeSender.php"
classname="FileMimeSender" />
<class_definition filename="plugins/editor.browser/FileMimeSender.php"
classname="Pydio\Plugins\Editor\FileMimeSender" />
<registry_contributions>
<actions>
<action name="open_file" skipSecureToken="true">
Expand Down
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2007-2013 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
* Copyright 2007-2016 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
* This file is part of Pydio.
*
* Pydio is free software: you can redistribute it and/or modify
Expand All @@ -18,6 +18,7 @@
*
* The latest code can be found at <http://pyd.io/>.
*/
namespace Pydio\Plugins\Editor;

use Pydio\Access\Core\AJXP_MetaStreamWrapper;
use Pydio\Access\Core\Model\AJXP_Node;
Expand All @@ -31,14 +32,21 @@
defined('AJXP_EXEC') or die( 'Access not allowed');

/**
* Class ImagePreviewer
* Generate an image thumbnail and send the thumb/full version to the browser
* @package AjaXplorer_Plugins
* @subpackage Editor
* @package Pydio\Plugins\Editor
*/
class ImagePreviewer extends Plugin
{
private $currentDimension;

/**
* @param $action
* @param $httpVars
* @param $filesVars
* @param \Pydio\Core\Model\ContextInterface $contextInterface
* @throws \Exception
*/
public function switchAction($action, $httpVars, $filesVars, \Pydio\Core\Model\ContextInterface $contextInterface)
{
if (!isSet($this->pluginConf)) {
Expand Down Expand Up @@ -130,7 +138,7 @@ public function generateThumbnail(\Pydio\Core\Model\ContextInterface $ctx, $mast
{
$size = $this->currentDimension;
require_once(AJXP_INSTALL_PATH."/plugins/editor.diaporama/PThumb.lib.php");
$pThumb = new PThumb($this->getContextualOption($ctx, "THUMBNAIL_QUALITY"), $this->getContextualOption($ctx, "EXIF_ROTATION"));
$pThumb = new \PThumb($this->getContextualOption($ctx, "THUMBNAIL_QUALITY"), $this->getContextualOption($ctx, "EXIF_ROTATION"));

if (!$pThumb->isError()) {
$pThumb->remote_wrapper = "Pydio\\Access\\Core\\AJXP_MetaStreamWrapper";
Expand Down Expand Up @@ -191,7 +199,7 @@ public function extractImageMetadata(&$ajxpNode)

if($this->getContextualOption($context, "EXIF_ROTATION")){
require_once(AJXP_INSTALL_PATH."/plugins/editor.diaporama/PThumb.lib.php");
$pThumb = new PThumb($this->getContextualOption($context, "THUMBNAIL_QUALITY"),$this->getContextualOption($context, "EXIF_ROTATION"));
$pThumb = new \PThumb($this->getContextualOption($context, "THUMBNAIL_QUALITY"),$this->getContextualOption($context, "EXIF_ROTATION"));
$orientation = $pThumb->exiforientation($realFile, false);
if ($pThumb->rotationsupported($orientation))
{
Expand All @@ -214,6 +222,10 @@ public function extractImageMetadata(&$ajxpNode)
//$this->logDebug("CURRENT NODE IN EXTRACT IMAGE METADATA ", $ajxpNode);
}

/**
* @param $filename
* @return bool
*/
protected function handleMime($filename)
{
$mimesAtt = explode(",", $this->getXPath()->query("@mimes")->item(0)->nodeValue);
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/editor.diaporama/manifest.xml
Expand Up @@ -8,7 +8,7 @@
<global_param name="THUMBNAIL_QUALITY" type="integer" label="CONF_MESSAGE[Quality]" description="CONF_MESSAGE[Thumbs quality]" default="2"/>
<global_param name="EXIF_ROTATION" type="boolean" label="CONF_MESSAGE[Exif Rotation]" description="CONF_MESSAGE[Rotate image using exif rotation]" default="true"/>
</server_settings>
<class_definition filename="plugins/editor.diaporama/class.ImagePreviewer.php" classname="ImagePreviewer"/>
<class_definition filename="plugins/editor.diaporama/ImagePreviewer.php" classname="Pydio\Plugins\Editor\ImagePreviewer"/>
<client_settings>
<resources>
<js file="plugins/editor.diaporama/class.Diaporama.js" className="Diaporama"/>
Expand Down

0 comments on commit eaa9c50

Please sign in to comment.