Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #10 from Flagbit/develop
Browse files Browse the repository at this point in the history
New Release 1.7
  • Loading branch information
Björn Meyer authored Aug 20, 2018
2 parents 960239c + 7bc905f commit 9649e87
Show file tree
Hide file tree
Showing 33 changed files with 1,861 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor
6 changes: 3 additions & 3 deletions Adapter/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function has($path)

/**
* @param string $path
* @param string $contents
* @param null|string $contents
* @param array $config
* @return bool
*/
Expand All @@ -56,7 +56,7 @@ public function writeStream($path, $resource, array $config = [])

/**
* @param string $path
* @param string $contents
* @param null|string $contents
* @param array $config
* @return bool
*/
Expand Down Expand Up @@ -87,7 +87,7 @@ public function readAndDelete($path)

/**
* @param string $path
* @param string $contents
* @param null|string $contents
* @param array $config
* @return bool
*/
Expand Down
12 changes: 12 additions & 0 deletions Adapter/FilesystemManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use \League\Flysystem\Adapter\Local as LocalAdapter;
use \League\Flysystem\Adapter\Ftp as FtpAdapter;
use \League\Flysystem\Adapter\NullAdapter as NullAdapter;
use \League\Flysystem\Sftp\SftpAdapter;

use \Magento\Framework\ObjectManagerInterface;

Expand All @@ -28,6 +29,17 @@ public function __construct(
$this->objectManager = $objectManager;
}

/**
* @param array $config
* @return mixed
*/
public function createSftpDriver(array $config)
{
return $this->objectManager->create(SftpAdapter::class, [
'config' => $config
]);
}

/**
* @param array $config
* @return mixed
Expand Down
20 changes: 20 additions & 0 deletions Block/Adminhtml/Filesystem/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ protected function _construct()
$this->buttonList->remove('back');
$this->buttonList->remove('edit');

if($this->getModalIdentifier() === 'flagbit_cms_modal') {
$this->buttonList->add(
'open_wysiwyg_browser',
['id' => 'open-wysiwyg-btn', 'label' => __('Open Default Browser'), 'type' => 'button'],
0,
0,
'header'
);
}

if($this->_authorization->isAllowed('Flagbit_Flysystem::folder_create')) {
$this->buttonList->add(
'new_folder',
Expand Down Expand Up @@ -161,6 +171,16 @@ public function getPreviewUrl()
return $this->getUrl('flagbit_flysystem/*/preview');
}

/**
* @return string
*/
public function getWysiwygModalUrl()
{
return $this->getUrl('cms/wysiwyg_images/index', [
'target_element_id' => $this->getTargetElementId()
]);
}

/**
* @return mixed
*/
Expand Down
5 changes: 4 additions & 1 deletion Controller/Adminhtml/Filesystem/OnInsert.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public function execute()
$filename = $this->getRequest()->getParam('filename');
$filename = $this->_flysystemHelper->idDecode($filename);

$as_is = $this->getRequest()->getParam('as_is');

$contents = $manager->getAdapter()->read($filename);

$this->_tmpManager->writeTmp($filename, $contents);
Expand All @@ -90,7 +92,8 @@ public function execute()
'controller' => $this,
'filename' => $filename,
'manager' => $manager,
'modal_id' => $identifier
'modal_id' => $identifier,
'as_is' => $as_is
]);

if (empty($this->_result)) {
Expand Down
90 changes: 90 additions & 0 deletions Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ class Config
const XPATH_CONFIG_FTP_SSL = 'flagbit_flysystem/ftp/ssl';
const XPATH_CONFIG_FTP_TIMEOUT = 'flagbit_flysystem/ftp/timeout';

const XPATH_CONFIG_SFTP_HOST = 'flagbit_flysystem/sftp/host';
const XPATH_CONFIG_SFTP_PORT = 'flagbit_flysystem/sftp/port';
const XPATH_CONFIG_SFTP_USERNAME = 'flagbit_flysystem/sftp/username';
const XPATH_CONFIG_SFTP_PASSWORD = 'flagbit_flysystem/sftp/password';
const XPATH_CONFIG_SFTP_PRIVATE_KEY_PATH = 'flagbit_flysystem/sftp/private_key_path';
const XPATH_CONFIG_SFTP_PRIVATE_KEY_CONTENT = 'flagbit_flysystem/sftp/private_key_content';
const XPATH_CONFIG_SFTP_ROOT = 'flagbit_flysystem/sftp/root';
const XPATH_CONFIG_SFTP_TIMEOUT = 'flagbit_flysystem/sftp/timeout';
const XPATH_CONFIG_SFTP_DIRECTORY_PERMISSIONS = 'flagbit_flysystem/sftp/directory_permissions';

const FLYSYSTEM_DIRECTORY = 'flagbit_flysystem';
const FLYSYSTEM_DIRECTORY_THUMBS = '.thumbs';
const FLYSYSTEM_DIRECTORY_TMP = '.tmp';
Expand Down Expand Up @@ -143,6 +153,86 @@ public function getFtpTimeout()
return (int)$this->_scopeConfig->getValue(self::XPATH_CONFIG_FTP_TIMEOUT);
}

/**
* @return mixed
*/
public function getSftpHost()
{
return $this->_scopeConfig->getValue(self::XPATH_CONFIG_SFTP_HOST);
}

/**
* @return int
*/
public function getSftpPort()
{
return (int)$this->_scopeConfig->getValue(self::XPATH_CONFIG_SFTP_PORT);
}

/**
* @return mixed
*/
public function getSftpUsername()
{
return $this->_scopeConfig->getValue(self::XPATH_CONFIG_SFTP_USERNAME);
}

/**
* @return mixed
*/
public function getSftpPassword()
{
return $this->_scopeConfig->getValue(self::XPATH_CONFIG_SFTP_PASSWORD);
}

/**
* @return mixed
*/
public function getSftpPrivateKeyPath()
{
return $this->_scopeConfig->getValue(self::XPATH_CONFIG_SFTP_PRIVATE_KEY_PATH);
}

/**
* @return mixed
*/
public function getSftpPrivateKeyContent()
{
return $this->_scopeConfig->getValue(self::XPATH_CONFIG_SFTP_PRIVATE_KEY_CONTENT);
}

/**
* @return mixed
*/
public function getSftpRoot()
{
return $this->_scopeConfig->getValue(self::XPATH_CONFIG_SFTP_ROOT);
}

/**
* @return mixed
*/
public function getSftpTimeout()
{
return $this->_scopeConfig->getValue(self::XPATH_CONFIG_SFTP_TIMEOUT);
}

/**
* @return int|null
*/
public function getSftpDirectoryPermissions()
{
$directoryPermissions = $this->_scopeConfig->getValue(self::XPATH_CONFIG_SFTP_DIRECTORY_PERMISSIONS);

if(empty($directoryPermissions)) return null;

/**
* 0 is used as base to let php decide how to convert the string value to an integer
* @see http://php.net/manual/de/function.intval.php,
*/
return intval($directoryPermissions, 0);
}

/**
* @return array
*/
Expand Down
1 change: 1 addition & 0 deletions Helper/Errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Errors extends AbstractHelper
*/
const ERR_NO_101 = "FTP connection failed. Please check your flysystem configuration.";
const ERR_NO_111 = "Adapter could not be initialized. Please check your flysystem configuration.";
const ERR_NO_121 = "SFTP connection failed. Please check your flysystem configuration.";

/**
* Errors while loading filesystem content
Expand Down
56 changes: 56 additions & 0 deletions Helper/Filesystem.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,44 @@
<?php
namespace Flagbit\Flysystem\Helper;

use \Magento\Cms\Helper\Wysiwyg\Images;
use \Magento\Framework\App\Helper\AbstractHelper;
use \Magento\Framework\App\Helper\Context;
use \Magento\Framework\UrlInterface;
use \Magento\Store\Model\StoreManagerInterface;

/**
* Class Config
* @package Flagbit\Flysystem\Helper
*/
class Filesystem extends AbstractHelper
{
/**
* @var StoreManagerInterface
*/
protected $_storeManager;

/**
* @var Images
*/
protected $_imageHelper;

/**
* @var string
*/
protected $_currentPath;


public function __construct(
Context $context,
StoreManagerInterface $storeManager,
Images $imageHelper
) {
$this->_storeManager = $storeManager;
$this->_imageHelper = $imageHelper;
parent::__construct($context);
}

/**
* Ext Tree node key name
*
Expand Down Expand Up @@ -85,4 +110,35 @@ public function getShortFilename($filename, $maxLength = 20)
}
return substr($filename, 0, $maxLength) . '...';
}

/**
* @param string $filename
* @param bool $renderAsTag
* @return string
*/
public function getImageHtmlDeclaration($filename, $renderAsTag = false)
{
$mediaUrl = $this->_storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA);
$mediaPath = '/'.trim($filename, '/');
$fileUrl = $mediaUrl.$filename;
$directive = sprintf('{{media url="%s"}}', $mediaPath);
if ($renderAsTag) {
$html = sprintf('<img src="%s" alt="" />', $this->_imageHelper->isUsingStaticUrlsAllowed() ? $fileUrl : $directive);
} else {
if ($this->_imageHelper->isUsingStaticUrlsAllowed()) {
$html = $fileUrl; // $mediaPath;
} else {
$directive = $this->urlEncoder->encode($directive);

$html = $this->_storeManager->getStore()->getUrl(
'cms/wysiwyg/directive',
[
'___directive' => $directive,
'_escape_params' => false,
]
);
}
}
return $html;
}
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Flagbit

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit 9649e87

Please sign in to comment.