/** * This function initializes the configuration array (i.e. $_CONF) and * will return a reference to the newly created array. The class keeps * track of this reference, and the set function will mutate it. * * @return array(string => mixed) This is a reference to the * config array */ function &initConfig() { global $_TABLES, $_CONF, $_SYSTEM; // Reads from a cache file if there is one if (isset($_SYSTEM['no_cache_config']) && !$_SYSTEM['no_cache_config']) { if (function_exists('COM_isWritable')) { if (COM_isWritable($_CONF['path'] . 'data/layout_cache/' . CONFIG_CACHE_FILE_NAME)) { if ($this->_readFromCache()) { $this->_post_configuration(); return $this->config_array; } } } } $false_str = serialize(false); $sql = "SELECT name, value, group_name FROM {$_TABLES['conf_values']} WHERE (type <> 'subgroup') AND (type <> 'fieldset')"; $result = DB_query($sql); while ($row = DB_fetchArray($result)) { if ($row[1] !== 'unset') { if (!array_key_exists($row[2], $this->config_array) || !array_key_exists($row[0], $this->config_array[$row[2]])) { $row[1] = preg_replace_callback('!s:(\\d+):"(.*?)";!', function ($match) { return $match[1] == strlen($match[2]) ? $match[0] : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; }, $row[1]); $value = @unserialize($row[1]); if ($value === false && $row[1] != $false_str) { if (function_exists('COM_errorLog')) { COM_errorLog("Unable to unserialize {$row[1]} for {$row[2]}:{$row[0]}"); } } else { $this->config_array[$row[2]][$row[0]] = $value; } } } } $this->_writeIntoCache(); $this->_post_configuration(); return $this->config_array; }
function _pi_test_copy($srcdir, $dstdir) { $num = 0; $fail = 0; $sizetotal = 0; $fifail = ''; $createdDst = 0; $ret = ''; $verbose = 0; $failedFiles = array(); if (!@is_dir($dstdir)) { $rc = fusion_io_mkdir_p($dstdir); if ($rc == false) { $failedFiles[] = $dstdir; COM_errorLog("PLG-INSTALL: Error: Unable to create directory " . $dstdir); return array(1, $failedFiles); } $createdDst = 1; } if ($curdir = @opendir($srcdir)) { while (false !== ($file = readdir($curdir))) { if ($file != '.' && $file != '..') { $srcfile = $srcdir . '/' . $file; $dstfile = $dstdir . '/' . $file; if (is_file($srcfile)) { if (!COM_isWritable($dstfile)) { $failedFiles[] = $dstfile; COM_errorLog("PLG-INSTALL: Error: File '{$dstfile}' cannot be written"); $fail++; $fifail = $fifail . $srcfile . '|'; } } else { if (@is_dir($srcfile)) { $res = explode(',', $ret); list($ret, $failed) = _pi_test_copy($srcfile, $dstfile, $verbose); $failedFiles = array_merge($failedFiles, $failed); $mod = explode(',', $ret); $imp = array($res[0] + $mod[0], $mod[1] + $res[1], $mod[2] + $res[2], $mod[3] . $res[3]); $ret = implode(',', $imp); } } } } closedir($curdir); } if ($createdDst == 1) { @rmdir($dstdir); } $red = explode(',', $ret); if (count($red) > 1) { $ret = $num + $red[0] . ',' . ($fail + $red[1]) . ',' . ($sizetotal + $red[2]) . ',' . $fifail . $red[3]; } return array($fail, $failedFiles); }
function COM_isWritable($path) { if ($path[strlen($path) - 1] == '/') { return COM_isWritable($path . uniqid(mt_rand()) . '.tmp'); } if (@file_exists($path)) { if (!($f = @fopen($path, 'r+'))) { return false; } @fclose($f); return true; } if (!($f = @fopen($path, 'w'))) { return false; } @fclose($f); @unlink($path); return true; }