Example #1
0
 /**
  * @static
  * @return array
  */
 public static function createClassMappings()
 {
     $modelsDir = PIMCORE_PATH . "/models/";
     $files = rscandir($modelsDir);
     $includePatterns = array("/Webservice\\/Data/");
     foreach ($files as $file) {
         if (is_file($file)) {
             $file = str_replace($modelsDir, "", $file);
             $file = str_replace(".php", "", $file);
             $class = str_replace(DIRECTORY_SEPARATOR, "_", $file);
             if (\Pimcore\Tool::classExists($class)) {
                 $match = false;
                 foreach ($includePatterns as $pattern) {
                     if (preg_match($pattern, $file)) {
                         $match = true;
                         break;
                     }
                 }
                 if (strpos($file, "Webservice" . DIRECTORY_SEPARATOR . "Data") !== false) {
                     $match = true;
                 }
                 if (!$match) {
                     continue;
                 }
                 $classMap[str_replace("\\Pimcore\\Model\\Webservice\\Data\\", "", $class)] = $class;
             }
         }
     }
     return $classMap;
 }
Example #2
0
/**
 * recursive scandir extension
 * 
 * @param string $directory
 * @param mixed $filters - regex or array for filter patterns
 * @param array $excludes - exluded files or directories
 * @return array - array of founded files
 */
function rscandir($directory = '.', $filters = [], $excludes = [])
{
    $excludes = array_merge($excludes, ['.', '..']);
    if ($filters && is_array($filters)) {
        foreach ($filters as &$filter) {
            $filter = str_replace(['.', '*'], ['\\.', '(.*)'], $filter);
        }
        $filters = '/^(' . implode('|', $filters) . ')$/';
    }
    $files = scandir($directory);
    for ($i = 0; $i < count($files); $i++) {
        if (is_dir($directory . DIRECTORY_SEPARATOR . $files[$i]) && !in_array($files[$i], $excludes)) {
            $subfiles = rscandir($directory . DIRECTORY_SEPARATOR . $files[$i], $filters, $excludes);
            foreach ($subfiles as $subfile) {
                $addfile = $files[$i] . DIRECTORY_SEPARATOR . $subfile;
                if (!in_array($addfile, $files)) {
                    $files[] = $addfile;
                }
            }
        }
    }
    $ret = [];
    foreach ($files as $file) {
        if (!in_array($file, $excludes) && (is_dir($file) || !$filters || preg_match($filters, $file))) {
            $ret[] = $file;
        }
    }
    return $ret;
}
Example #3
0
	function getHierarchy ($titleSort=false) {
		
		$this->CI->load->helper(array('url', 'glib_directory', 'inflector'));
		
		$pathBase = realpath(APPPATH.'controllers'); 
		$pathThis = __FILE__;

		foreach (rscandir($pathBase) as $pathController) {
			if (
				($pathController != $pathThis) 
				&& (!strpos($pathController, 'index.html')) 
			) { 
				// Make Path Relative to Web Root
				$controller = rtrim(substr($pathController, strlen($pathBase) + 1 , -4 ), '/');
				
				// Clean The Default Controllers From The List
				$defaultController = $GLOBALS["CI"]->router->routes["default_controller"];
				if (strpos($controller,$defaultController)) $controller = 
					preg_replace("/\/$defaultController/i", "", $controller);
				elseif ($controller == $defaultController) $controller = '/';
				
				// Send As Output If Not a Private Controller
				if (substr($controller, 0, 1) != '_') {
					
					// Set The Title
					if ($controller == '/') {
						$title = 'Home';
					} else {
						$title = humanize(ltrim(substr($controller, strrpos($controller, '/')), '/'));
					}
					
					// Add The Directory
					$data["$controller"] = $title;
					
					// Get The Methods When Necessary
					if (!strpos($pathController, $defaultController.'.php')) {
						
						require_once $pathController;
						if (!strpos($controller, '/')) $className = $controller;
						else $className = substr($controller, strripos($controller, '/') + 1);

						$methods = $this->getMethods(ucfirst($className));
						foreach ($methods as $method) if ($method != 'index') {
							$data["$controller"] = $title;
						}
					}
					
				}
					 
			}
		}
		
		if ($titleSort) asort($data);
		else ksort($data);
		
		return $data;
		
	}	
Example #4
0
 public function OnScanDirectory($pData = null)
 {
     $Directory = $pData['Directory'];
     $Recursive = $pData['Recursive'];
     if ($Recursive == true) {
         $return = rscandir($Directory);
     } else {
         $return = scandir($Directory);
     }
     return $return;
 }
Example #5
0
 public function indexAction()
 {
     $errors = [];
     // check permissions
     $files = rscandir(PIMCORE_WEBSITE_VAR . "/");
     foreach ($files as $file) {
         if (is_dir($file) && !is_writable($file)) {
             $errors[] = "Please ensure that the entire /" . PIMCORE_WEBSITE_VAR . " directory is recursively writeable.";
             break;
         }
     }
     $this->view->errors = $errors;
 }
Example #6
0
 public function indexAction()
 {
     $errors = array();
     // check permissions
     $files = rscandir(PIMCORE_WEBSITE_VAR . "/");
     foreach ($files as $file) {
         if (is_dir($file) && !is_writable($file)) {
             $errors[] = "Please ensure that the whole /" . PIMCORE_WEBSITE_VAR . " folder is writeable (recursivly)";
             break;
         }
     }
     $this->view->errors = $errors;
 }
Example #7
0
 /**
  * @return bool
  */
 public static function isWriteable()
 {
     if (self::$dryRun) {
         return true;
     }
     // check permissions
     $files = rscandir(PIMCORE_PATH . "/");
     foreach ($files as $file) {
         if (!is_writable($file)) {
             return false;
         }
     }
     return true;
 }
Example #8
0
function rscandir($base='', &$data=array()) {
    $array = array_diff(scandir($base), array('.', '..', '.svn')); # remove ' and .. from the array */
    foreach($array as $value) { /* loop through the array at the level of the supplied $base */
        if (is_dir($base.$value)) { /* if this is a directory */
            $data[] = $base.$value.'/'; /* add it to the $data array */
            $data = rscandir($base.$value.'/', $data); /* then make a recursive call with the
            current $value as the $base supplying the $data array to carry into the recursion */

        } else if (is_file($base.$value)) { /* else if the current $value is a file */
            $data[] = $base.$value; /* just add the current $value to the $data array */
        }
    }
    return $data; // return the $data array
}
function rscandir($base = '', &$data = array())
{
    $array = array_diff(scandir($base), array('.', '..'));
    foreach ($array as $value) {
        if (is_dir($base . $value)) {
            $data = rscandir($base . $value . '/', $data);
        } elseif (is_file($base . $value)) {
            if (preg_match('/\\.lng\\.php$/i', $value) && $value != 'custom.lng.php') {
                $data[] = $base . $value;
            }
        }
    }
    return $data;
}
Example #10
0
function getApps($mounts)
{
    global $defaultFocusedIcon, $defaultUnfocusedIcon, $base;
    $appfolders = array();
    foreach ($mounts as $mount) {
        $appdir = $mount . "scripts/";
        if (is_dir($appdir)) {
            $appfolders = rscandir($appdir);
        }
    }
    foreach ($appfolders as $appfolder) {
        $appconfig = $appfolder . "version.xml";
        #print_r( $appconfig );
        if (is_dir($appfolder) && is_file($appconfig)) {
            $appxml = @simplexml_load_file($appconfig);
            if ($appxml) {
                $app["name"] = (string) $appxml->name;
                if (empty($app["name"])) {
                    $app["name"] = basename($appfolder);
                }
                $app["link"] = (string) $appxml->link;
                if ("index.php" == $app["link"] || !is_file($app["link"])) {
                    $testfile = $appfolder . (string) $appxml->link;
                    if (is_file($testfile)) {
                        $app["link"] = str_replace($base, "http://127.0.0.1/media/", $testfile);
                    } else {
                        $testfile = $appfolder . "index.php";
                        if (is_file($testfile)) {
                            $app["link"] = str_replace($base, "http://127.0.0.1/media/", $testfile);
                        }
                    }
                }
                $app["version"] = (string) $appxml->version;
                $app["update"] = (string) $appxml->updatelink;
                $app["focusedIcon"] = $appfolder . trim((string) $appxml->focusedIcon);
                $app["unfocusedIcon"] = $appfolder . trim((string) $appxml->unfocusedIcon);
                if ($appfolder == $app["focusedIcon"]) {
                    $app["focusedIcon"] = $defaultFocusedIcon;
                }
                if ($appfolder == $app["unfocusedIcon"]) {
                    $app["unfocusedIcon"] = $defaultUnfocusedIcon;
                }
                $apps[] = $app;
            }
        }
    }
    return $apps;
}
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $files = rscandir(PIMCORE_TEMPORARY_DIRECTORY . "/image-thumbnails/");
     $savedBytesTotal = 0;
     foreach ($files as $file) {
         if (file_exists($file)) {
             $originalFilesize = filesize($file);
             \Pimcore\Image\Optimizer::optimize($file);
             $savedBytes = $originalFilesize - filesize($file);
             $savedBytesTotal += $savedBytes;
             $this->output->writeln("Optimized image: " . $file . " saved " . formatBytes($savedBytes));
         }
     }
     $this->output->writeln("Finished!");
     $this->output->writeln("Saved " . formatBytes($savedBytesTotal) . " in total");
 }
Example #12
0
function rscandir($rootDir, $ext=array(), $allData=array()) {
    // set filenames invisible if you want
    $invisibleFileNames = array(".", "..", ".htaccess", ".htpasswd");
    // run through content of root directory
    $dirContent = scandir($rootDir);
    foreach($dirContent as $key => $content) {
        // filter all files not accessible
        $path = $rootDir.'/'.$content;
        if(!in_array($content, $invisibleFileNames)) {
            // if content is file & readable, add to array
            if(is_file($path) && is_readable($path)) {
                // save file name with path
                $allData[] = realpath($path);
            // if content is a directory and readable, add path and name
            }elseif(is_dir($path) && is_readable($path)) {
                // recursive callback to open new directory
                $allData = rscandir($path, $ext, $allData);
            }
        }
    }
    return $allData;
}
Example #13
0
<?php

$folderScan = "anim/perso-1/run/";
$web = WEB_RESSOURCES . $folderScan;
$list = rscandir(DIR_RESSOURCES . $folderScan);
?>
<ul class="no-padh ressources-preview">
    <li><strong>img</strong>
    	<ul>
    		<li>
    			<img src="<?php 
echo WEB_ROOT;
?>
/ressources/ressources/img/dot-grid-isometric-460.jpg">
        		<span class="filename small">dot-grid-isometric-460.jpg</span>
    		</li>
    	</ul>
    </li>
    <li><strong>Anim/run</strong>
        <ul>
            <?php 
foreach ($list as $key => $value) {
    ?>
                <li>
                    <img src="<?php 
    echo $web . $value;
    ?>
">
                    <span class="filename small"><?php 
    echo $value;
    ?>
function csp_po_get_theme_capabilities($theme, $values, $active) {
	$data = array();
	$data['locale'] = get_locale();
	$data['type'] = 'themes';
	$data['img_type'] = 'themes';	
	$data['type-desc'] = __('Theme',CSP_PO_TEXTDOMAIN);	
	$data['name'] = $values['Name'];
	$data['author'] = $values['Author'];
	$data['version'] = $values['Version'];
	$data['description'] = $values['Description'];
	$data['status'] = $theme == $active->name ? __("activated",CSP_PO_TEXTDOMAIN) : __("deactivated",CSP_PO_TEXTDOMAIN);
	$data['base_path'] = str_replace("\\","/", WP_CONTENT_DIR.str_replace('wp-content', '', dirname($values['Template Files'][0])).'/');
	if (file_exists($values['Template Files'][0])){
		$data['base_path'] = dirname(str_replace("\\","/",$values['Template Files'][0])).'/';
	}

	$data['special-path'] = '';
	foreach($values['Template Files'] as $themefile) {
		$main = '';
		if (!file_exists($themefile)) {
			$main = file_get_contents(WP_CONTENT_DIR.str_replace('wp-content', '', $themefile));
		}else {
			$main = file_get_contents($themefile);
		}
		if (preg_match("/load_theme_textdomain\s*\(\s*(\'|\"|)([\w\-_]+|[A-Z\-_]+)(\'|\"|)\s*(,|\))/", $main, $hits)) break;
	}
	$data['is-path-unclear'] = false;
	$data['gettext_ready'] = empty($hits) === false;
	if ($data['gettext_ready']) {
		$data['textdomain'] = array('identifier' => $hits[2], 'is_const' => empty($hits[1]) );
		$data['languages'] = array();
	
		$const_list = array();
		if (!($data['gettext_ready'] && !$data['textdomain']['is_const'])) {
			if (preg_match_all("/define\s*\(([^\)]+)\)/" , $main, $hits)) {
				$const_list = array_merge($const_list, $hits[1]);
			}
		}
		if ($data['gettext_ready']) {			
			if ($data['textdomain']['is_const']) {
				foreach($const_list as $e) {
					$a = split(',', $e);
					$c = trim($a[0], "\"' \t");
					if ($c == $data['textdomain']['identifier']) {
						$data['textdomain']['is_const'] = $data['textdomain']['identifier'];
						$data['textdomain']['identifier'] = trim($a[1], "\"' \t");
					}
				}
			}		
		}		
	
		$tmp = array();
		$dn = dirname(str_replace("\\","/",WP_CONTENT_DIR).str_replace('wp-content', '', $values['Template Files'][0]));
		if (file_exists($values['Template Files'][0])){
			$dn = dirname(str_replace("\\","/",$values['Template Files'][0]));
		}
		$files = rscandir($dn.'/', "/(.\mo|\.po|\.pot)$/", $tmp);
		$sub_dirs = array();
		foreach($files as $filename) {
			preg_match("/\/([a-z][a-z]_[A-Z][A-Z]).(mo|po)$/", $filename, $hits);
			if (empty($hits[1]) === false) {
				$data['languages'][$hits[1]][$hits[2]] = array(
					'class' => "-".(is_readable($filename) ? 'r' : '').(is_writable($filename) ? 'w' : ''),
					'stamp' => date(__('m/d/Y H:i:s',CSP_PO_TEXTDOMAIN), filemtime($filename))." ".file_permissions($filename)
				);
				$data['filename'] = '';
				$sd = dirname(str_replace($dn.'/', '', $filename));
				if ($sd == '.') $sd = '';
				if (!in_array($sd, $sub_dirs)) $sub_dirs[] = $sd;
			}
		}
		//completely other directories can be defined WP if >= 2.7.0
		global $wp_version;
		if (version_compare($wp_version, '2.7', '>=')) {
			if (count($data['languages']) == 0) {
				$data['is-path-unclear'] = has_subdirs($dn.'/');
				if ($data['is-path-unclear'] && (count($files) > 0)) {
					foreach($files as $file) {
						$f = str_replace($dn.'/', '', $file);
						if (preg_match("/^([a-z][a-z]_[A-Z][A-Z]).(mo|po|pot)$/", basename($f))) {
							$data['special_path'] = (dirname($f) == '.' ? '' : dirname($f));
							$data['is-path-unclear'] = false;
							break;
						}
					}
				}
			}
			else{
				if ($sub_dirs[0] != '') {
					$data['special_path'] = ltrim($sub_dirs[0], "/");
				}
			}
		}
	}
	
	$data['base_file'] = (empty($data['special_path']) ? '' : $data['special_path']."/");

	return $data;
}
Example #15
0
<?php

include "../../include.php";
$folder = "anim/" . $_POST["select-perso"] . "/" . $_POST["select-anim"];
$dir = DIR_RESSOURCES . $folder;
$list = rscandir($dir);
$d = ["list" => $list, "url" => WEB_RESSOURCES . $folder . "/"];
$r = array('infotype' => "success", 'msg' => "ok", 'data' => $d);
echo json_encode($r);
Example #16
0
function wpct_export_template($template)
{
    require_once WPCT_PATH . 'lib/pclzip.lib.php';
    if (!is_dir(WPCT_PATH . 'templates')) {
        @mkdir(WPCT_PATH . 'templates', 0755) or wpct_show_warn("I'm not able to create the directory '" . WPCT_PATH . "templates', please, check your permissons or create it manually.");
    }
    @chmod(WPCT_PATH . "templates", 0755);
    if (file_exists(WPCT_PATH . 'templates/' . $template . '.zip')) {
        @unlink(WPCT_PATH . 'templates/' . $template . '.zip') or wpct_show_warn("I'm not able to delete the file {$template}.zip in the directory 'templates', please, check your permissons or delete it manually.");
    }
    $export = new PclZip(WPCT_PATH . 'templates/' . $template . '.zip');
    $template_root = substr($_SERVER['SCRIPT_FILENAME'], 0, -19) . 'wp-content/themes/' . $template . '/';
    $files = rscandir($template_root);
    foreach ($files as $file) {
        if ($file[0] . $file[1] !== '/v' && (is_file($file[0] . $file[1]) or is_dir($file[0] . $file[1]))) {
            $add[] = $file[0] . $file[1];
        }
    }
    $add = implode(',', $add);
    $make = $export->add($add, PCLZIP_OPT_REMOVE_PATH, substr($_SERVER['SCRIPT_FILENAME'], 0, -19) . 'wp-content/themes');
    if ($make == 0) {
        die("Error : " . $export->errorInfo(true));
    }
    $_SESSION['wpct_buffer'] = true;
    wp_redirect(get_option('siteurl') . '/wp-content/plugins/' . plugin_basename(dirname(__FILE__)) . '/templates/' . $template . '.zip', 301);
    exit;
}
Example #17
0
/**
 * @param string $base
 * @param array $data
 * @return array
 */
function rscandir($base = '', &$data = array())
{
    $array = array_diff(scandir($base), array('.', '..', '.svn'));
    foreach ($array as $value) {
        if (is_dir($base . $value)) {
            $data[] = $base . $value . DIRECTORY_SEPARATOR;
            $data = rscandir($base . $value . DIRECTORY_SEPARATOR, $data);
        } elseif (is_file($base . $value)) {
            $data[] = $base . $value;
        }
    }
    return $data;
}
 public function importServerAction()
 {
     $success = true;
     $filesPerJob = 5;
     $jobs = array();
     $importDirectory = str_replace("/fileexplorer", PIMCORE_DOCUMENT_ROOT, $this->getParam("serverPath"));
     if (is_dir($importDirectory)) {
         $files = rscandir($importDirectory . "/");
         $count = count($files);
         $jobFiles = array();
         for ($i = 0; $i < $count; $i++) {
             if (is_dir($files[$i])) {
                 continue;
             }
             $jobFiles[] = preg_replace("@^" . preg_quote($importDirectory, "@") . "@", "", $files[$i]);
             if (count($jobFiles) >= $filesPerJob || $i >= $count - 1) {
                 $jobs[] = array(array("url" => "/admin/asset/import-server-files", "params" => array("parentId" => $this->getParam("parentId"), "serverPath" => $importDirectory, "files" => implode("::", $jobFiles))));
                 $jobFiles = array();
             }
         }
     }
     $this->_helper->json(array("success" => $success, "jobs" => $jobs));
 }
Example #19
0
 public function indexAction()
 {
     $checksPHP = array();
     $checksMySQL = array();
     $checksFS = array();
     $checksApps = array();
     // check for memory limit
     $memoryLimit = ini_get("memory_limit");
     $memoryLimit = filesize2bytes($memoryLimit . "B");
     $state = "ok";
     if ($memoryLimit < 67108000) {
         $state = "error";
     } else {
         if ($memoryLimit < 134217000) {
             $state = "warning";
         }
     }
     $checksPHP[] = array("name" => "memory_limit (in php.ini)", "link" => "http://www.php.net/memory_limit", "state" => $state);
     // mcrypt
     $checksPHP[] = array("name" => "mcrypt", "link" => "http://www.php.net/mcrypt", "state" => function_exists("mcrypt_encrypt") ? "ok" : "error");
     // pdo_mysql
     $checksPHP[] = array("name" => "PDO_Mysql", "link" => "http://www.php.net/pdo_mysql", "state" => @constant("PDO::MYSQL_ATTR_FOUND_ROWS") ? "ok" : "error");
     // pdo_mysql
     $checksPHP[] = array("name" => "Mysqli", "link" => "http://www.php.net/mysqli", "state" => class_exists("mysqli") ? "ok" : "error");
     // iconv
     $checksPHP[] = array("name" => "iconv", "link" => "http://www.php.net/iconv", "state" => function_exists("iconv") ? "ok" : "error");
     // dom
     $checksPHP[] = array("name" => "dom", "link" => "http://www.php.net/dom", "state" => class_exists("DOMDocument") ? "ok" : "error");
     // simplexml
     $checksPHP[] = array("name" => "SimpleXML", "link" => "http://www.php.net/simplexml", "state" => class_exists("SimpleXMLElement") ? "ok" : "error");
     // gd
     $checksPHP[] = array("name" => "GD", "link" => "http://www.php.net/gd", "state" => function_exists("gd_info") ? "ok" : "error");
     // exif
     $checksPHP[] = array("name" => "EXIF", "link" => "http://www.php.net/exif", "state" => function_exists("exif_read_data") ? "ok" : "error");
     // multibyte support
     $checksPHP[] = array("name" => "Multibyte String (mbstring)", "link" => "http://www.php.net/mbstring", "state" => function_exists("mb_get_info") ? "ok" : "error");
     // file_info support
     $checksPHP[] = array("name" => "File Information (file_info)", "link" => "http://www.php.net/file_info", "state" => function_exists("finfo_open") ? "ok" : "error");
     // zip
     $checksPHP[] = array("name" => "zip", "link" => "http://www.php.net/zip", "state" => class_exists("ZipArchive") ? "ok" : "error");
     // gzip
     $checksPHP[] = array("name" => "zlib / gzip", "link" => "http://www.php.net/zlib", "state" => function_exists("gzcompress") ? "ok" : "error");
     // bzip
     $checksPHP[] = array("name" => "Bzip2", "link" => "http://www.php.net/bzip2", "state" => function_exists("bzcompress") ? "ok" : "error");
     // openssl
     $checksPHP[] = array("name" => "OpenSSL", "link" => "http://www.php.net/openssl", "state" => function_exists("openssl_open") ? "ok" : "error");
     // Imagick
     $checksPHP[] = array("name" => "Imagick", "link" => "http://www.php.net/imagick", "state" => class_exists("Imagick") ? "ok" : "warning");
     // OPcache
     $checksPHP[] = array("name" => "OPcache", "link" => "http://www.php.net/opcache", "state" => function_exists("opcache_reset") ? "ok" : "warning");
     // memcache
     $checksPHP[] = array("name" => "Memcache", "link" => "http://www.php.net/memcache", "state" => class_exists("Memcache") ? "ok" : "warning");
     // Redis
     $checksPHP[] = array("name" => "Redis", "link" => "https://pecl.php.net/package/redis", "state" => class_exists("Redis") ? "ok" : "warning");
     // curl for google api sdk
     $checksPHP[] = array("name" => "curl", "link" => "http://www.php.net/curl", "state" => function_exists("curl_init") ? "ok" : "warning");
     $db = null;
     if ($this->getParam("mysql_adapter")) {
         // this is before installing
         try {
             $dbConfig = ['username' => $this->getParam("mysql_username"), 'password' => $this->getParam("mysql_password"), 'dbname' => $this->getParam("mysql_database")];
             $hostSocketValue = $this->getParam("mysql_host_socket");
             if (file_exists($hostSocketValue)) {
                 $dbConfig["unix_socket"] = $hostSocketValue;
             } else {
                 $dbConfig["host"] = $hostSocketValue;
                 $dbConfig["port"] = $this->getParam("mysql_port");
             }
             $db = \Zend_Db::factory($this->getParam("mysql_adapter"), $dbConfig);
             $db->getConnection();
         } catch (\Exception $e) {
             $db = null;
         }
     } else {
         // this is after installing, eg. after a migration, ...
         $db = \Pimcore\Db::get();
     }
     if ($db) {
         // storage engines
         $engines = array();
         $enginesRaw = $db->fetchAll("SHOW ENGINES;");
         foreach ($enginesRaw as $engineRaw) {
             $engines[] = strtolower($engineRaw["Engine"]);
         }
         // innodb
         $checksMySQL[] = array("name" => "InnoDB Support", "state" => in_array("innodb", $engines) ? "ok" : "error");
         // myisam
         $checksMySQL[] = array("name" => "MyISAM Support", "state" => in_array("myisam", $engines) ? "ok" : "error");
         // memory
         $checksMySQL[] = array("name" => "MEMORY Support", "state" => in_array("memory", $engines) ? "ok" : "error");
         // check database charset =>  utf-8 encoding
         $result = $db->fetchRow('SHOW VARIABLES LIKE "character\\_set\\_database"');
         $checksMySQL[] = array("name" => "Database Charset UTF8", "state" => $result['Value'] == "utf8" ? "ok" : "error");
         // create table
         $queryCheck = true;
         try {
             $db->query("CREATE TABLE __pimcore_req_check (\n                  id int(11) NOT NULL AUTO_INCREMENT,\n                  field varchar(255) CHARACTER SET latin1 NULL DEFAULT NULL,\n                  PRIMARY KEY (id)\n                ) DEFAULT CHARSET=utf8 COLLATE utf8_general_ci");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "CREATE TABLE", "state" => $queryCheck ? "ok" : "error");
         // alter table
         $queryCheck = true;
         try {
             $db->query("ALTER TABLE __pimcore_req_check ADD COLUMN alter_field varchar(255) NULL DEFAULT NULL");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "ALTER TABLE", "state" => $queryCheck ? "ok" : "error");
         // Manage indexes
         $queryCheck = true;
         try {
             $db->query("ALTER TABLE __pimcore_req_check\n                  CHANGE COLUMN id id int(11) NOT NULL,\n                  CHANGE COLUMN field field varchar(255) NULL DEFAULT NULL,\n                  CHANGE COLUMN alter_field alter_field varchar(255) NULL DEFAULT NULL,\n                  ADD KEY field (field),\n                  DROP PRIMARY KEY ,\n                 DEFAULT CHARSET=utf8");
             $db->query("ALTER TABLE __pimcore_req_check\n                  CHANGE COLUMN id id int(11) NOT NULL AUTO_INCREMENT,\n                  CHANGE COLUMN field field varchar(255) NULL DEFAULT NULL,\n                  CHANGE COLUMN alter_field alter_field varchar(255) NULL DEFAULT NULL,\n                  ADD PRIMARY KEY (id) ,\n                 DEFAULT CHARSET=utf8");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "Manage Indexes", "state" => $queryCheck ? "ok" : "error");
         // insert data
         $queryCheck = true;
         try {
             $db->insert("__pimcore_req_check", array("field" => uniqid(), "alter_field" => uniqid()));
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "INSERT", "state" => $queryCheck ? "ok" : "error");
         // update
         $queryCheck = true;
         try {
             $db->update("__pimcore_req_check", array("field" => uniqid(), "alter_field" => uniqid()));
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "UPDATE", "state" => $queryCheck ? "ok" : "error");
         // select
         $queryCheck = true;
         try {
             $db->fetchAll("SELECT * FROM __pimcore_req_check");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "SELECT", "state" => $queryCheck ? "ok" : "error");
         // create view
         $queryCheck = true;
         try {
             $db->query("CREATE OR REPLACE VIEW __pimcore_req_check_view AS SELECT * FROM __pimcore_req_check");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "CREATE VIEW", "state" => $queryCheck ? "ok" : "error");
         // select from view
         $queryCheck = true;
         try {
             $db->fetchAll("SELECT * FROM __pimcore_req_check_view");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "SELECT (from view)", "state" => $queryCheck ? "ok" : "error");
         // delete
         $queryCheck = true;
         try {
             $db->delete("__pimcore_req_check");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "DELETE", "state" => $queryCheck ? "ok" : "error");
         // show create view
         $queryCheck = true;
         try {
             $db->query("SHOW CREATE VIEW __pimcore_req_check_view");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "SHOW CREATE VIEW", "state" => $queryCheck ? "ok" : "error");
         // show create table
         $queryCheck = true;
         try {
             $db->query("SHOW CREATE TABLE __pimcore_req_check");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "SHOW CREATE TABLE", "state" => $queryCheck ? "ok" : "error");
         // drop view
         $queryCheck = true;
         try {
             $db->query("DROP VIEW __pimcore_req_check_view");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "DROP VIEW", "state" => $queryCheck ? "ok" : "error");
         // drop table
         $queryCheck = true;
         try {
             $db->query("DROP TABLE __pimcore_req_check");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "DROP TABLE", "state" => $queryCheck ? "ok" : "error");
     } else {
         die("Not possible... no or wrong database settings given.<br />Please fill out the MySQL Settings in the install form an click again on `Check Requirements´");
     }
     // filesystem checks
     // website/var writable
     $websiteVarWritable = true;
     $files = rscandir(PIMCORE_WEBSITE_VAR);
     foreach ($files as $file) {
         if (!is_writable($file)) {
             $websiteVarWritable = false;
         }
     }
     $checksFS[] = array("name" => "/website/var/ writeable", "state" => $websiteVarWritable ? "ok" : "error");
     // pimcore writeable
     $checksFS[] = array("name" => "/pimcore/ writeable", "state" => \Pimcore\Update::isWriteable() ? "ok" : "warning");
     // system & application checks
     // PHP CLI BIN
     try {
         $phpCliBin = (bool) \Pimcore\Tool\Console::getPhpCli();
     } catch (\Exception $e) {
         $phpCliBin = false;
     }
     $checksApps[] = array("name" => "PHP CLI Binary", "state" => $phpCliBin ? "ok" : "error");
     // FFMPEG BIN
     try {
         $ffmpegBin = (bool) \Pimcore\Video\Adapter\Ffmpeg::getFfmpegCli();
     } catch (\Exception $e) {
         $ffmpegBin = false;
     }
     $checksApps[] = array("name" => "FFMPEG (CLI)", "state" => $ffmpegBin ? "ok" : "warning");
     // WKHTMLTOIMAGE BIN
     try {
         $wkhtmltopdfBin = (bool) \Pimcore\Image\HtmlToImage::getWkhtmltoimageBinary();
     } catch (\Exception $e) {
         $wkhtmltopdfBin = false;
     }
     $checksApps[] = array("name" => "wkhtmltoimage (CLI)", "state" => $wkhtmltopdfBin ? "ok" : "warning");
     // HTML2TEXT BIN
     try {
         $html2textBin = (bool) \Pimcore\Mail::determineHtml2TextIsInstalled();
     } catch (\Exception $e) {
         $html2textBin = false;
     }
     $checksApps[] = array("name" => "mbayer html2text (CLI)", "state" => $html2textBin ? "ok" : "warning");
     // ghostscript BIN
     try {
         $ghostscriptBin = (bool) \Pimcore\Document\Adapter\Ghostscript::getGhostscriptCli();
     } catch (\Exception $e) {
         $ghostscriptBin = false;
     }
     $checksApps[] = array("name" => "Ghostscript (CLI)", "state" => $ghostscriptBin ? "ok" : "warning");
     // LibreOffice BIN
     try {
         $libreofficeBin = (bool) \Pimcore\Document\Adapter\LibreOffice::getLibreOfficeCli();
     } catch (\Exception $e) {
         $libreofficeBin = false;
     }
     $checksApps[] = array("name" => "LibreOffice (CLI)", "state" => $libreofficeBin ? "ok" : "warning");
     // PNG optimizer
     try {
         $pngOptimizer = (bool) \Pimcore\Image\Optimizer::getPngOptimizerCli();
     } catch (\Exception $e) {
         $pngOptimizer = false;
     }
     $checksApps[] = array("name" => "PNG Optimizer (pngcrush)", "state" => $pngOptimizer ? "ok" : "warning");
     // JPEG optimizer
     try {
         $jpgOptimizer = (bool) \Pimcore\Image\Optimizer::getJpegOptimizerCli();
     } catch (\Exception $e) {
         $jpgOptimizer = false;
     }
     $checksApps[] = array("name" => "JPEG Optimizer (imgmin, jpegoptim)", "state" => $jpgOptimizer ? "ok" : "warning");
     // timeout binary
     try {
         $timeoutBin = (bool) \Pimcore\Tool\Console::getTimeoutBinary();
     } catch (\Exception $e) {
         $timeoutBin = false;
     }
     $checksApps[] = array("name" => "timeout - (GNU coreutils)", "state" => $timeoutBin ? "ok" : "warning");
     // pdftotext binary
     try {
         $pdftotextBin = (bool) \Pimcore\Document\Adapter\Ghostscript::getPdftotextCli();
     } catch (\Exception $e) {
         $pdftotextBin = false;
     }
     $checksApps[] = array("name" => "pdftotext - (part of poppler-utils)", "state" => $pdftotextBin ? "ok" : "warning");
     $this->view->checksApps = $checksApps;
     $this->view->checksPHP = $checksPHP;
     $this->view->checksMySQL = $checksMySQL;
     $this->view->checksFS = $checksFS;
 }
Example #20
0
function rscandir($base = '', &$files = array())
{
    global $__rscandir_iteration;
    $__rscandir_iteration++;
    $array = array_diff(scandir($base), array('.', '..'));
    $array = scandir($base);
    foreach ($array as $value) {
        if ($value == '.' or $value == '..') {
            continue;
        }
        if (is_dir($base . $value)) {
            $files[] = $base . $value . '/';
            $files = rscandir($base . $value . '/', $files);
        } elseif (is_file($base . $value)) {
            $files[] = $base . $value;
        }
    }
    $__rscandir_iteration--;
    if ($__rscandir_iteration == 0) {
        foreach ($files as $f => $file) {
            $files[$f] = str_replace($base, '', $file);
        }
    }
    return $files;
}
Example #21
0
 public function getAvailableTemplatesAction()
 {
     $templates = [];
     $viewPath = PIMCORE_WEBSITE_PATH . DIRECTORY_SEPARATOR . "views" . DIRECTORY_SEPARATOR . "scripts";
     $files = rscandir($viewPath . DIRECTORY_SEPARATOR);
     foreach ($files as $file) {
         $dat = [];
         if (strpos($file, \Pimcore\View::getViewScriptSuffix()) !== false) {
             $dat["path"] = str_replace($viewPath, "", $file);
             $dat["path"] = str_replace("\\", "/", $dat["path"]);
             // unix directory separator are compatible with windows, not the reverse
             $templates[] = $dat;
         }
     }
     $this->_helper->json(["data" => $templates]);
 }
Example #22
0
 /**
  * @param $sourceDir
  * @param $destinationFile
  * @return array
  * @throws \Exception
  */
 protected static function prepareArchive($sourceDir, $destinationFile)
 {
     if (substr($sourceDir, -1, 1) != DIRECTORY_SEPARATOR) {
         $sourceDir .= DIRECTORY_SEPARATOR;
     }
     if (is_dir($sourceDir) && is_readable($sourceDir)) {
         $items = rscandir($sourceDir);
     } else {
         throw new \Exception("{$sourceDir} doesn't exits or is not readable!");
     }
     if (!$destinationFile || !is_string($destinationFile)) {
         throw new \Exception('No destinationFile provided!');
     } else {
         @unlink($destinationFile);
     }
     $destinationDir = dirname($destinationFile);
     if (!is_dir($destinationDir)) {
         File::mkdir($destinationDir);
     }
     return array($sourceDir, $destinationFile, $items);
 }
function csp_po_get_theme_capabilities($theme, $values, $active)
{
    $data = array();
    $data['dev-hints'] = null;
    $data['deny_scanning'] = false;
    //let's first check the whether we have a child or base theme
    if (is_object($values) && get_class($values) == 'WP_Theme') {
        //WORDPRESS Version 3.4 changes theme handling!
        $firstfile = array_shift(array_values($values['Template Files']));
        $data['base_path'] = str_replace("\\", "/", WP_CONTENT_DIR . str_replace('wp-content', '', dirname($firstfile)) . '/');
        if (file_exists($firstfile)) {
            $data['base_path'] = dirname(str_replace("\\", "/", $firstfile)) . '/';
        }
    } else {
        $data['base_path'] = str_replace("\\", "/", WP_CONTENT_DIR . str_replace('wp-content', '', dirname($values['Template Files'][0])) . '/');
        if (file_exists($values['Template Files'][0])) {
            $data['base_path'] = dirname(str_replace("\\", "/", $values['Template Files'][0])) . '/';
        }
    }
    $folder_filesys = end(explode('/', rtrim($data['base_path'], '/')));
    $folder_data = $values['Template'];
    $is_child_theme = $folder_filesys != $folder_data;
    $data['locale'] = get_locale();
    $data['type'] = 'themes';
    $data['img_type'] = $is_child_theme ? 'childthemes' : 'themes';
    $data['type-desc'] = $is_child_theme ? __('Childtheme', CSP_PO_TEXTDOMAIN) : __('Theme', CSP_PO_TEXTDOMAIN);
    $data['name'] = $values['Name'];
    $data['author'] = $values['Author'];
    $data['version'] = $values['Version'];
    $data['description'] = $values['Description'];
    $data['status'] = $theme == $active->name ? __("activated", CSP_PO_TEXTDOMAIN) : __("deactivated", CSP_PO_TEXTDOMAIN);
    if ($is_child_theme) {
        $data['status'] .= ' / <b></i>' . __('child theme of', CSP_PO_TEXTDOMAIN) . ' ' . $values['Parent Theme'] . '</i></b>';
    }
    $data['special-path'] = '';
    $data['is-path-unclear'] = false;
    $data['gettext_ready'] = false;
    $data['translation_template'] = null;
    $data['is-simple'] = false;
    $data['simple-filename'] = '';
    //now scanning the child's own files
    $parent_files = array();
    $files = array();
    $const_list = array();
    $tmp = array();
    $files = rscandir($data["base_path"], "/\\.(php|phtml)\$/", $tmp);
    foreach ($files as $themefile) {
        $main = file_get_contents($themefile);
        if (preg_match("/[^_^!]load_(child_theme_|theme_|)textdomain\\s*\\(\\s*(\\'|\"|)([\\w\\d\\-_]+|[A-Z\\d\\-_]+)(\\'|\"|)\\s*(,|\\))/", $main, $hits) || preg_match("/[^_^!]load_(child_theme_|theme_|)textdomain\\s*\\(\\s*/", $main, $hits)) {
            if (isset($hits[1]) && $hits[1] != 'child_theme_' && $hits[1] != 'theme_') {
                $data['dev-hints'] = __("<strong>Loading Issue: </strong>Author is using <em>load_textdomain</em> instead of <em>load_theme_textdomain</em> or <em>load_child_theme_textdomain</em> function. This may break behavior of WordPress, because some filters and actions won't be executed anymore. Please contact the Author about that.", CSP_PO_TEXTDOMAIN);
            }
            //fallback for variable names used to load textdomain, assumes theme name
            if (isset($hits[3]) && strpos($hits[3], '$') !== false) {
                unset($hits[3]);
                if (isset($data['dev-hints'])) {
                    $data['dev-hints'] .= "<br/><br/>";
                }
                $data['dev-hints'] = __("<strong>Textdomain Naming Issue: </strong>Author uses a variable to load the textdomain. It will be assumed to be equal to theme name now.", CSP_PO_TEXTDOMAIN);
            }
            //make it short
            $data['gettext_ready'] = true;
            if ($data['gettext_ready']) {
                if (!isset($hits[3])) {
                    $data['textdomain'] = array('identifier' => $values['Template'], 'is_const' => false);
                } else {
                    $data['textdomain'] = array('identifier' => $hits[3], 'is_const' => empty($hits[2]));
                }
                $data['languages'] = array();
            }
            $dn = $data["base_path"];
            $tmp = array();
            $lng_files = rscandir($dn, "/(\\.mo|\\.po|\\.pot)\$/", $tmp);
            $data['translation_template'] = csp_find_translation_template($lng_files);
            $sub_dirs = array();
            $naming_convention_error = false;
            foreach ($lng_files as $filename) {
                //somebody did place buddypress themes at sub folder hierarchy like:  themes/buddypress/bp-default
                //results at $values['Template'] to 'buddypress/bp-default' which damages the preg_match
                $theme_langfile_check = end(explode('/', $values['Template']));
                preg_match("/\\/(|" . preg_quote($theme_langfile_check) . "\\-)([a-z][a-z]_[A-Z][A-Z])\\.(mo|po)\$/", $filename, $hits);
                if (empty($hits[1]) === false) {
                    $naming_convention_error = true;
                    $data['filename'] = '';
                    $sd = dirname(str_replace($dn, '', $filename));
                    if ($sd == '.') {
                        $sd = '';
                    }
                    if (!in_array($sd, $sub_dirs)) {
                        $sub_dirs[] = $sd;
                    }
                } elseif (empty($hits[2]) === false) {
                    $data['languages'][$hits[2]][$hits[3]] = array('class' => "-" . (is_readable($filename) ? 'r' : '') . (is_writable($filename) ? 'w' : ''), 'stamp' => date(__('m/d/Y H:i:s', CSP_PO_TEXTDOMAIN), filemtime($filename)) . " " . file_permissions($filename));
                    $data['filename'] = '';
                    $sd = dirname(str_replace($dn, '', $filename));
                    if ($sd == '.') {
                        $sd = '';
                    }
                    if (!in_array($sd, $sub_dirs)) {
                        $sub_dirs[] = $sd;
                    }
                }
            }
            if ($naming_convention_error && count($data['languages']) == 0) {
                if (isset($data['dev-hints'])) {
                    $data['dev-hints'] .= "<br/><br/>";
                }
                $data['dev-hints'] .= sprintf(__("<strong>Naming Issue: </strong>Author uses unsupported language file naming convention! Instead of example <em>de_DE.po</em> the non theme standard version <em>%s</em> has been used. If you translate this Theme, only renamed language files will be working!", CSP_PO_TEXTDOMAIN), $values['Template'] . '-de_DE.po');
            }
            //completely other directories can be defined WP if >= 2.7.0
            global $wp_version;
            if (version_compare($wp_version, '2.7', '>=')) {
                if (count($data['languages']) == 0) {
                    $data['is-path-unclear'] = has_subdirs($dn);
                    if ($data['is-path-unclear'] && count($lng_files) > 0) {
                        foreach ($lng_files as $file) {
                            $f = str_replace($dn, '', $file);
                            if (preg_match("/^([a-z][a-z]_[A-Z][A-Z])\\.(mo|po|pot)\$/", basename($f)) || preg_match("/\\.po(t|)\$/", basename($f))) {
                                $data['special_path'] = dirname($f) == '.' ? '' : dirname($f);
                                $data['is-path-unclear'] = false;
                                break;
                            }
                        }
                    }
                } else {
                    if ($sub_dirs[0] != '') {
                        $data['special_path'] = ltrim($sub_dirs[0], "/");
                    }
                }
            }
        }
        if ($data['gettext_ready'] && !$data['textdomain']['is_const']) {
            break;
        }
        //make it short :-)
        if (preg_match_all("/define\\s*\\(([^\\)]+)\\)/", $main, $hits)) {
            $const_list = array_merge($const_list, $hits[1]);
        }
    }
    $data['base_file'] = empty($data['special_path']) ? '' : $data['special_path'] . "/";
    $constant_failed = false;
    if ($data['gettext_ready']) {
        if ($data['textdomain']['is_const']) {
            foreach ($const_list as $e) {
                $a = split(',', $e);
                $c = trim($a[0], "\"' \t");
                if ($c == $data['textdomain']['identifier']) {
                    $data['textdomain']['is_const'] = $data['textdomain']['identifier'];
                    $data['textdomain']['identifier'] = trim($a[1], "\"' \t");
                }
            }
        }
        //fallback for constants defined by variables! assume the theme name instead
        if (strpos($data['textdomain']['identifier'], '$') !== false || strpos($data['textdomain']['identifier'], '"') !== false || strpos($data['textdomain']['identifier'], '\'') !== false) {
            $constant_failed = true;
            $data['textdomain']['identifier'] = $values['Template'];
            if (isset($data['dev-hints'])) {
                $data['dev-hints'] .= "<br/><br/>";
            }
            $data['dev-hints'] = __("<strong>Textdomain Naming Issue: </strong>Author uses a variable to define the textdomain constant. It will be assumed to be equal to theme name now.", CSP_PO_TEXTDOMAIN);
        }
    }
    //check now known issues for themes
    if (isset($data['textdomain']['identifier']) && $data['textdomain']['identifier'] == 'woothemes') {
        if (isset($data['dev-hints'])) {
            $data['dev-hints'] .= "<br/><br/>";
        }
        $data['dev-hints'] .= __("<strong>WooThemes Issue: </strong>The Author is known for not supporting a translatable backend. Please expect only translations for frontend or contact the Author for support!", CSP_PO_TEXTDOMAIN);
    }
    if (isset($data['textdomain']['identifier']) && $data['textdomain']['identifier'] == 'ares' && $constant_failed) {
        if (isset($data['dev-hints'])) {
            $data['dev-hints'] .= "<br/><br/>";
        }
        $data['dev-hints'] .= __("<strong>Ares Theme Issue: </strong>This theme uses a textdomain defined by string concatination code. The textdomain will be patched to 'AresLanguage', please contact the theme author to change this into a fix constant value! ", CSP_PO_TEXTDOMAIN);
        $data['textdomain']['identifier'] = 'AresLanguage';
    }
    return $data;
}
 public function getUpdateInformationAction()
 {
     $id = $this->_getParam("id");
     $type = $this->_getParam("type");
     $excludes = explode("\n", $this->_getParam("exclude"));
     if (!$excludes[0]) {
         $excludes = array();
     }
     // always exclude the revision information
     $excludes[] = "/pimcore_extension_revision/";
     $steps = array();
     $actions = array();
     $filesTransferred = array();
     $actions["start"] = array("action" => "start-upload", "params" => array("id" => $id, "type" => $type));
     $extensionDir = Pimcore_ExtensionManager::getPathForExtension($id, $type);
     $extensionDir .= "/";
     // add trailing slash
     if ($type == "plugin") {
         $pathPrefix = PIMCORE_PLUGINS_PATH;
     } else {
         if ($type == "brick") {
             $tmpSplit = explode("areas/" . $id . "/", $extensionDir);
             $pathPrefix = $tmpSplit[0] . "areas";
         }
     }
     $pathPrefix = str_replace(DIRECTORY_SEPARATOR, "/", $pathPrefix);
     $files = rscandir($extensionDir);
     foreach ($files as $file) {
         if (is_file($file)) {
             $file = str_replace(DIRECTORY_SEPARATOR, "/", $file);
             // check for excludes
             try {
                 foreach ($excludes as $regexp) {
                     if (@preg_match($regexp, str_replace($pathPrefix, "", $file), $matches)) {
                         throw new Exception("Not allowed because of the regular expressions.");
                     }
                 }
             } catch (Exception $e) {
                 continue;
             }
             $steps[] = array("action" => "upload-file", "params" => array("path" => $file, "pathPrefix" => $pathPrefix, "id" => $id, "type" => $type));
             $filesTransferred[] = str_replace($pathPrefix, "", $file);
         }
     }
     $actions["verify"] = array("action" => "verify-upload", "params" => array("id" => $id, "type" => $type));
     $this->_helper->json(array("steps" => $steps, "files" => $filesTransferred, "actions" => $actions));
 }
 public function getAvailableTemplatesAction()
 {
     $templates = array();
     $viewPath = PIMCORE_WEBSITE_PATH . "/views/scripts";
     $files = rscandir($viewPath . "/");
     foreach ($files as $file) {
         $dat = array();
         if (strpos($file, Pimcore_View::getViewScriptSuffix()) !== false) {
             $dat["path"] = str_replace($viewPath, "", $file);
             $templates[] = $dat;
         }
     }
     $this->_helper->json(array("data" => $templates));
 }
Example #26
0
/**
 * @param string $base
 * @param array $data
 * @return array
 */
function rscandir($base = '', &$data = [])
{
    if (substr($base, -1, 1) != DIRECTORY_SEPARATOR) {
        //add trailing slash if it doesn't exists
        $base .= DIRECTORY_SEPARATOR;
    }
    $array = array_diff(scandir($base), ['.', '..', '.svn']);
    foreach ($array as $value) {
        if (is_dir($base . $value)) {
            $data[] = $base . $value . DIRECTORY_SEPARATOR;
            $data = rscandir($base . $value . DIRECTORY_SEPARATOR, $data);
        } elseif (is_file($base . $value)) {
            $data[] = $base . $value;
        }
    }
    return $data;
}
 protected function importFromFileSystem($path, $parentId)
 {
     $assetFolder = Asset::getById($parentId);
     $files = rscandir($path . "/");
     foreach ($files as $file) {
         if (is_file($file)) {
             $relativePath = $assetFolder->getFullPath() . str_replace($path, "", $file);
             $folder = $this->getOrCreateAssetFolderByPath(dirname($relativePath));
             $filename = basename($file);
             // check for dublicate filename
             $filename = Pimcore_File::getValidFilename($filename);
             $filename = $this->getSafeFilename($folder->getFullPath(), $filename);
             if ($assetFolder->isAllowed("create")) {
                 $asset = Asset::create($folder->getId(), array("filename" => $filename, "data" => file_get_contents($file), "userOwner" => $this->getUser()->getId(), "userModification" => $this->getUser()->getId()));
             } else {
                 Logger::debug("prevented creating asset because of missing permissions ");
             }
         }
     }
 }
Example #28
0
 public function uploadAction()
 {
     $success = true;
     $tmpId = uniqid();
     $zipPath = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/plugin-" . $tmpId . ".zip";
     $tempPath = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/plugin-" . $tmpId;
     mkdir($tempPath);
     copy($_FILES["zip"]["tmp_name"], $zipPath);
     $zip = new ZipArchive();
     if ($zip->open($zipPath) === TRUE) {
         $zip->extractTo($tempPath);
         $zip->close();
     } else {
         $success = false;
     }
     unlink($zipPath);
     // look for the plugin.xml
     $rootDir = null;
     $pluginName = null;
     $files = rscandir($tempPath);
     foreach ($files as $file) {
         if (preg_match("@/plugin.xml\$@", $file)) {
             $rootDir = dirname($file);
             $pluginConfig = new \Zend_Config_Xml($file);
             if ($pluginConfig->plugin->pluginName) {
                 $pluginName = $pluginConfig->plugin->pluginName;
             } else {
                 Logger::error("Unable to find 'pluginName' in " . $file);
             }
             break;
         }
     }
     if ($rootDir && $pluginName) {
         $pluginPath = PIMCORE_PLUGINS_PATH . "/" . $pluginName;
         // check for existing plugin
         if (is_dir($pluginPath)) {
             // move it to the backup directory
             rename($pluginPath, PIMCORE_BACKUP_DIRECTORY . "/" . $pluginName . "-" . time());
         }
         rename($rootDir, $pluginPath);
     } else {
         $success = false;
         Logger::err("No plugin.xml or plugin name found for uploaded plugin");
     }
     $this->_helper->json(array("success" => $success), false);
     // set content-type to text/html, otherwise (when application/json is sent) chrome will complain in
     // Ext.form.Action.Submit and mark the submission as failed
     $this->getResponse()->setHeader("Content-Type", "text/html");
 }
Example #29
0
 /**
  * @param array $options
  * @return array
  */
 public function init($options = array())
 {
     $this->setOptions($options);
     // create backup directory if not exists
     if (!is_dir(PIMCORE_BACKUP_DIRECTORY)) {
         if (!\Pimcore\File::mkdir(PIMCORE_BACKUP_DIRECTORY)) {
             \Logger::err("Directory " . PIMCORE_BACKUP_DIRECTORY . " does not exists and cannot be created.");
             exit;
         }
     }
     $errors = array();
     $this->setFileAmount(0);
     // cleanup old backups
     if (is_file(PIMCORE_SYSTEM_TEMP_DIRECTORY . "/backup-dump.sql")) {
         unlink(PIMCORE_SYSTEM_TEMP_DIRECTORY . "/backup-dump.sql");
     }
     // get steps
     $steps = array();
     // get available tables
     $db = Db::get();
     $tables = $this->getTables();
     $steps[] = array("mysql-tables", $this->options['mysql-tables']);
     // tables
     foreach ($tables as $table) {
         $name = current($table);
         $type = next($table);
         if ($type != "VIEW") {
             $steps[] = array("mysql", array("name" => $name, "type" => $type));
         }
     }
     // views
     foreach ($tables as $table) {
         reset($table);
         $name = current($table);
         $type = next($table);
         if ($type == "VIEW") {
             $steps[] = array("mysql", array("name" => $name, "type" => $type));
         }
     }
     $steps[] = array("mysql-complete", null);
     if (!$options['only-mysql-related-tasks']) {
         // check files
         $currentFileCount = 0;
         $currentFileSize = 0;
         $currentStepFiles = array();
         // check permissions
         $filesIn = rscandir(PIMCORE_DOCUMENT_ROOT . "/");
         clearstatcache();
         foreach ($filesIn as $fileIn) {
             if (!is_readable($fileIn)) {
                 $errors[] = $fileIn . " is not readable.";
             }
             if ($currentFileCount > 300 || $currentFileSize > 20000000) {
                 $currentFileCount = 0;
                 $currentFileSize = 0;
                 if (!empty($currentStepFiles)) {
                     $filesToBackup[] = $currentStepFiles;
                 }
                 $currentStepFiles = array();
             }
             if (file_exists($fileIn)) {
                 $currentFileSize += filesize($fileIn);
                 $currentFileCount++;
                 $currentStepFiles[] = $fileIn;
             }
         }
         if (!empty($currentStepFiles)) {
             $filesToBackup[] = $currentStepFiles;
         }
         $this->setFilesToBackup($filesToBackup);
         $fileSteps = count($filesToBackup);
         for ($i = 0; $i < $fileSteps; $i++) {
             $steps[] = array("files", array("step" => $i));
         }
         $steps[] = array("complete", null);
     }
     if (!empty($errors)) {
         $steps = null;
     }
     return array("steps" => $steps, "errors" => $errors);
 }
function csp_po_ajax_handle_merge_from_maintheme()
{
    csp_po_check_security();
    load_plugin_textdomain(CSP_PO_TEXTDOMAIN, PLUGINDIR . '/codestyling-localization/languages', 'codestyling-localization/languages');
    require_once 'includes/locale-definitions.php';
    require_once 'includes/class-filesystem-translationfile.php';
    //source|dest|basepath|textdomain|molist
    $tmp = array();
    $files = rscandir(str_replace("\\", "/", WP_CONTENT_DIR) . '/themes/' . strip_tags($_POST['source']) . '/', "/(\\.po|\\.mo)\$/", $tmp);
    foreach ($files as $file) {
        $pofile = new CspFileSystem_TranslationFile();
        $target = strip_tags($_POST['basepath']) . basename($file);
        if (preg_match('/\\.mo/', $file)) {
            $pofile->read_mofile($file, $csp_l10n_plurals, false, strip_tags($_POST['textdomain']));
            $pofile->write_mofile($target, strip_tags($_POST['textdomain']));
        } else {
            $pofile->read_pofile($file);
            if (file_exists($target)) {
                //merge it now
                $pofile->read_pofile($target);
            }
            $pofile->write_pofile($target, true, strip_tags($_POST['textdomain']));
        }
    }
    exit;
}