public function validate($value) { if (is_array($value) && isset($value['path']) && isset($value['dataURL'])) { $fileName = str_replace('..', '', $value['path']); /* secure relative path */ /* find an unused name */ $fileInfo = pathinfo($fileName); $base = $fileInfo['filename']; $ext = $fileInfo['extension']; $dir = empty($fileInfo['dirname']) ? '' : $fileInfo['dirname'] . '/'; /* $fileInfo['dirname'] in case that filename contains a part of dirname */ $path = PROFILE_PATH . $this->entity->getModule() . '/' . $this->path . '/'; $nbn = 0; while (is_file($path . $fileName)) { $fileName = $dir . $base . '_' . $nbn . '.' . $ext; $nbn++; } if (!is_dir($path . $dir)) { \tools::createDirectory($path . $fileInfo['dirname'] . '/'); } /* decode dataURL */ $cut = explode(',', $value['dataURL']); $dataURL = $cut[1]; $dataURL = base64_decode(str_replace(' ', '+', $dataURL)); /* save and check image */ if (file_put_contents($path . $fileName, $dataURL)) { return $fileName; } else { return FALSE; /* can't write image */ } } else { return parent::validate($value); } }
/** * Create directory * @param string $directory * @param string $mask * @return string */ protected function createDirAction($directory, $mask = 0755) { return \tools::createDirectory($directory, $mask = 0755); }
/** * Generates the code to build a module * @static function * @param string $name module name * @param string $title module title */ public static function build($name, $title) { $reservedKeywords = array('__halt_compiler', 'abstract', 'and', 'array', 'as', 'break', 'callable', 'case', 'catch', 'class', 'clone', 'const', 'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'final', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'isset', 'list', 'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var', 'while', 'xor'); if (!is_dir('modules/' . $name) && !is_numeric($name) && !in_array($name, $reservedKeywords)) { $name = preg_replace('@[^a-zA-Z0-9]@', '', $name); $licence = str_replace('{{module}}', $name, file_get_contents("modules/admin/licence.txt")); tools::createDirectory('modules/' . $name); $template = '<?php ' . $licence . ' namespace ' . $name . '; /** * @title ' . str_replace('\'', '\\\'', $title) . ' * @description ' . str_replace('\'', '\\\'', $title) . ' * @copyright 1 * @browsers all * @php_version_min 5.3 */ class module extends \\module { protected $name = \'' . str_replace('\'', '\\\'', $name) . '\'; } ?>'; file_put_contents('modules/' . $name . '/module.php', $template); include 'modules/' . $name . '/module.php'; $name2 = $name . '\\module'; $mod = new $name2($name); $page = new \page(1, $name); $page->setModule($name); $page->setTitle('Index ' . $name); $page->setRegex('@^index$@'); /* Set rights forbidden for non admins, admins are allowed by default */ foreach (\app::getModule('core')->getEntity('role') as $role) { if ($role->permissions == 0) { $mod->setRights($role->id_role, 0); $page->setRights($role->id_role, 0); } } $mod->addPage($page); $mod->save(); $config = new \config('profiles/' . PROFILE . '/config.php', TRUE); $config->add('$config[\'modules\'][\'' . $name . '\']', '7'); return $config->save(); } else { return FALSE; } }
* @authors Julien Gras et Benoît Lorillot * @copyright Julien Gras et Benoît Lorillot * * @category Parsimony * @package core/blocks * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /* In case the file isn't in PROFILES/ */ $viewPath = $this->getConfig('viewPath'); if (!is_file(PROFILE_PATH . $viewPath) && is_file('modules/' . $viewPath)) { \tools::createDirectory(dirname(PROFILE_PATH . $viewPath)); copy('modules/' . $viewPath, PROFILE_PATH . $viewPath); } $this->viewPath = PROFILE_PATH . $this->getConfig('viewPath'); if (!file_exists($this->viewPath)) { tools::createDirectory(dirname($this->viewPath)); } if (!file_exists($this->viewPath)) { $this->generateViewAction(array()); } $view = $this->getConfig('view'); ?> <script src="<?php echo BASE_PATH; ?> lib/jquery-ui/jquery-ui-1.10.3.min.js"></script> <script type="text/javascript" src="<?php echo BASE_PATH; ?> lib/jsPlumb/jquery.jsPlumb-1.3.16-all-min.js"></script> <style>
/** * Upload a file * @param string $file * @return string|false */ public function upload($file) { if ($file["error"] == 0) { if (!empty($this->target)) { if ($file['size'] <= $this->maxSize) { if (empty($this->fileName)) { $this->fileName = strtolower($file['name']); } $fichier_info = pathinfo($this->target . $this->fileName); $extension = strtolower($fichier_info['extension']); $upload_ok = ''; foreach ($this->type as $type) { if ($extension == $type || $type == 'all') { $upload_ok = 'ok'; } } if (!empty($this->fileName)) { $root = $fichier_info['filename']; $nbn = 0; while (file_exists($this->target . $this->fileName)) { $this->fileName = $root . '_' . $nbn . '.' . $extension; $nbn++; } if ($upload_ok == 'ok') { if (!is_dir($this->target)) { \tools::createDirectory($this->target); } if (!move_uploaded_file($file['tmp_name'], $this->target . $this->fileName)) { throw new \Exception(t('Error : No file Uploaded', FALSE)); } else { return $this->fileName; } } else { throw new \Exception(t('Error : The file format is invalid', FALSE)); } } else { throw new \Exception(t('Error : the filename can\'t be empty', FALSE)); } } else { throw new \Exception(t('The uploaded file exceeds the MAX_FILE_SIZE :', FALSE) . ' ' . ceil($this->maxSize / 1024) . ' ko'); } } else { throw new \Exception(t('The target folder doesn\'t exist :', FALSE) . $this->target); } } else { throw new \Exception(t('The uploaded file exceeds the MAX_FILE_SIZE :', FALSE) . ' ' . ceil($this->maxSize / 1024) . ' ko'); } }
/** * Generates the code to build a block * @static * @param string $moduleName Module name where the block is created * @param string $blockName Block name to create * @param string $extends * @param string $configs */ public static function build($moduleName, $blockName, $extends, $configs, $viewPath) { $moduleName = tools::sanitizeString($moduleName); $blockName = tools::sanitizeString($blockName); $licence = str_replace('{{module}}', $blockName, file_get_contents("modules/admin/licence.txt")); $dir = 'modules/' . $moduleName . '/blocks/' . $blockName; tools::createDirectory('modules/' . $moduleName . '/blocks/' . $blockName); list($moduleFrom, $b, $nameFrom) = explode('\\', $extends); $template = '<?php ' . $licence . ' namespace ' . $moduleName . '\\blocks; /** * @title ' . $blockName . ' * @description ' . $blockName . ' * @copyright 1 * @browsers all * @php_version_min 5.3 * @block_category ' . $moduleName . ' * @modules_dependencies ' . $moduleFrom . ':1 */ class ' . $blockName . ' extends \\' . $extends . ' { public function __construct($id) { parent::__construct($id); $configs = \'' . $configs . '\'; $this->configs = unserialize(base64_decode($configs)); } public function getAdminView() { ob_start(); include(\'modules/' . $moduleFrom . '/blocks/' . $nameFrom . '/adminView.php\'); return ob_get_clean(); } } ?>'; if (is_dir($dir)) { file_put_contents('modules/' . $moduleName . '/blocks/' . $blockName . '/block.php', $template); file_put_contents('modules/' . $moduleName . '/blocks/' . $blockName . '/icon.png', file_get_contents('modules/' . $moduleFrom . '/blocks/' . $nameFrom . '/icon.png')); file_put_contents('modules/' . $moduleName . '/blocks/' . $blockName . '/view.php', file_get_contents($viewPath, FILE_USE_INCLUDE_PATH)); $return = array('eval' => '', 'notification' => t('Block has been created'), 'notificationType' => 'positive'); } else { $return = array('eval' => '', 'notification' => t('Block has\'nt been created', FALSE), 'notificationType' => 'negative'); } \app::$response->setHeader('X-XSS-Protection', '0'); \app::$response->setHeader('Content-type', 'application/json'); return json_encode($return); }
/** * Concat JS or CSS Files * @param array $module */ public function concatFiles(array $files, $format) { $hash = $format . 'concat_' . md5(implode('', $files)); $pathCache = 'profiles/' . PROFILE . '/modules/' . app::$config['defaultModule'] . '/' . $hash . '.' . $format; $dltCache = ''; if (!is_file($pathCache) || app::$config['dev']['status'] !== 'prod') { ob_start(); foreach ($files as $file) { $pathParts = pathinfo($file, PATHINFO_EXTENSION); if ($pathParts === 'js' || $pathParts === 'css') { $path = stream_resolve_include_path($file); if ($path) { if ($_SESSION['permissions'] & 16 && $pathParts === 'css') { echo '.parsimonyMarker{background-image: url(' . $file . ') }' . PHP_EOL; } include $path; } echo PHP_EOL; //in order to split JS script and avoid "}function" } else { return FALSE; } } $content = ob_get_clean(); \tools::createDirectory(dirname($pathCache)); file_put_contents($pathCache, $content); $dltCache = '?' . time(); } return $hash . '.' . $format . $dltCache; }
* that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to contact@parsimony-cms.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade Parsimony to newer * versions in the future. If you wish to customize Parsimony for your * needs please refer to http://www.parsimony.mobi for more information. * * @authors Julien Gras et Benoît Lorillot * @copyright Julien Gras et Benoît Lorillot * * @category Parsimony * @package core/blocks * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ if ($this->getConfig('mode') !== 'r') { $viewPath = $this->getConfig('viewPath'); /* In case the file isn't in PROFILES/ */ if (!is_file(PROFILE_PATH . $viewPath) && is_file('modules/' . $viewPath)) { \tools::createDirectory(dirname(PROFILE_PATH . $this->getConfig('viewPath'))); copy('modules/' . $viewPath, PROFILE_PATH . $viewPath); } $path = PROFILE_PATH . $viewPath; $editorMode = 'application/x-httpd-php'; include 'modules/admin/views/editor.php'; }
* This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to contact@parsimony-cms.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade Parsimony to newer * versions in the future. If you wish to customize Parsimony for your * needs please refer to http://www.parsimony.mobi for more information. * * @authors Julien Gras et Benoît Lorillot * @copyright Julien Gras et Benoît Lorillot * * @category Parsimony * @package core/blocks * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ if ($this->getConfig('mode') !== 'r') { $viewPath = $this->getConfig('viewPath'); /* In case the file isn't in PROFILES/ */ if (!is_file(PROFILE_PATH . $viewPath) && is_file('modules/' . $viewPath)) { \tools::createDirectory(dirname(PROFILE_PATH . $viewPath)); copy('modules/' . $viewPath, PROFILE_PATH . $viewPath); } $path = PROFILE_PATH . $viewPath; include 'modules/admin/views/editor.php'; }