public function testForceDirHasRightReturn() { // To test the return values, disable conversion of errors into exceptions $warningEnabledOrig = PHPUnit_Framework_Error_Warning::$enabled; PHPUnit_Framework_Error_Warning::$enabled = false; $this->assertTrue($this->stub->forceDir("/")); $this->assertTrue($this->stub->forceDir(__DIR__ . "/dir")); $this->assertFileExists(__DIR__ . "/dir"); @rmdir(__DIR__ . "/dir"); $this->assertFalse($this->stub->forceDir(null)); PHPUnit_Framework_Error_Warning::$enabled = $warningEnabledOrig; }
/** * @see parent::init() */ function init() { if (!CMbPath::forceDir($this->dir)) { trigger_error("Shared memory could not be initialized, ensure that '{$this->dir}' is writable"); CApp::rip(); } return true; }
/** * @see parent::__construct() */ function __construct($key, $label = null) { parent::__construct($key, $label); $this->path = CAppUI::conf("root_dir") . "/tmp/locks"; $this->process = getmypid(); $this->filename = "{$this->path}/" . $this->getLockKey(); CMbPath::forceDir(dirname($this->filename)); }
/** * CMbSemaphore Constructor * * @param string $key semaphore identifier */ function __construct($key) { $this->path = CAppUI::conf("root_dir") . "/tmp/locks"; CMbPath::forceDir($this->path); $this->process = getmypid(); $prefix = CApp::getAppIdentifier(); $this->key = "{$prefix}-sem-{$key}"; }
/** * Construct * * @param string $key lock identifier */ function __construct($key) { $this->path = CAppUI::conf("root_dir") . "/tmp/locks"; $this->process = getmypid(); $prefix = CApp::getAppIdentifier(); $this->key = "{$prefix}-lock-{$key}"; $this->filename = "{$this->path}/{$this->key}"; CMbPath::forceDir(dirname($this->filename)); }
/** * Returns the temp directory * * @return string The temp directory path */ static function getTmpDir() { $root_dir = dirname(__FILE__); include_once "{$root_dir}/CMbPath.class.php"; $tmp_dir = "{$root_dir}/../tmp/socket_server"; CMbPath::forceDir($tmp_dir); return $tmp_dir; }
/** * Force directories creation for file upload * * @return void */ function forceDir() { // Check global directory if (!CMbPath::forceDir(self::$directory)) { trigger_error("Files directory is not writable : " . self::$directory, E_USER_WARNING); return; } // Checks complete file directory CMbPath::forceDir($this->_absolute_dir); }
/** * Get all stats for one file * * @param string $file File name * * @return null */ function stat($file) { /** * Recursive increment routine * * @param array &$stats Stats * @param array $parts Parts * * @return array */ function increment(&$stats, $parts) { if (!isset($stats)) { $stats = array("count" => null, "items" => null); } $stats["count"]++; if ($first = array_shift($parts)) { increment($stats["items"][$first], $parts); } } // Recursive call $stats = null; foreach ($this->getFlattenAlerts() as $_alert) { $parts = explode(".", $_alert["source"]); increment($stats, $parts); } // Create the file $path = $this->makeReportPath($file, "json"); CMbPath::forceDir(dirname($path)); touch($path); file_put_contents($path, json_encode($stats)); return $stats; }
if (null == ($remote_name = $clCconfig["remote_name"])) { CAppUI::stepAjax("Remote name not configured", UI_MSG_ERROR); } if (null == ($remote_url = $clCconfig["remote_url"])) { CAppUI::stepAjax("Remote URL not configured", UI_MSG_ERROR); } if (false === ($content = file_get_contents($remote_url))) { CAppUI::stepAjax("Couldn't connect to remote url", UI_MSG_ERROR); } // Check imported catalogue document $doc = new CMbXMLDocument(); if (!$doc->loadXML($content)) { CAppUI::stepAjax("Document is not well formed", UI_MSG_ERROR); } $tmpPath = "tmp/dPlabo/import_catalogue.xml"; CMbPath::forceDir(dirname($tmpPath)); $doc->save($tmpPath); $doc->load($tmpPath); if (!$doc->schemaValidate("modules/{$m}/remote/catalogue.xsd")) { CAppUI::stepAjax("Document is not valid", UI_MSG_ERROR); } CAppUI::stepAjax("Document is valid", UI_MSG_OK); // Check access to idSante400 $canSante400 = CModule::getCanDo("dPsante400"); if (!$canSante400->edit) { CAppUI::stepAjax("No permission for module 'dPsante400' or module not installed", UI_MSG_ERROR); } // Import catalogue $cat = new SimpleXMLElement($content); try { importCatalogue($cat);
/** * Get embeddable URL * * @param string $src Original URL * @param string $content File content * @param string $subpath Subpath to store the file to * * @return string */ private static function getEmbedURL($src, $content, $subpath) { $hash = md5($src); $subpath .= "/"; CMbPath::forceDir(self::$_path . $subpath); file_put_contents(self::$_path . $subpath . $hash, $content); return "{$subpath}{$hash}"; }
<?php /** * $Id$ * * @package Mediboard * @subpackage System * @author SARL OpenXtrem <*****@*****.**> * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html * @version $Revision$ */ CCanDo::checkAdmin(); // Size in KB $size = CValue::get("size", 100); $size = min($size, 10 * 1024); // Cap it to 10MB MAX $big_file = CAppUI::getTmpPath("bandwidth_test/big.bin"); CMbPath::forceDir(dirname($big_file)); file_put_contents($big_file, str_pad("", 1024 * $size, "a")); // Must be a "normal" char so that it's not url encoded $empty_file = CAppUI::getTmpPath("bandwidth_test/empty.bin"); file_put_contents($empty_file, "");
/** * Construction * Directories initialisation * Standard data assignment * * @param string $dir The template directory */ function __construct($dir = null) { global $version, $can, $m, $a, $tab, $g, $action, $actionType, $dialog, $ajax, $suppressHeaders, $uistyle; $rootDir = CAppUI::conf("root_dir"); $extraPath = self::$extraPath; if (!$dir) { $root = $extraPath ? "{$rootDir}/{$extraPath}" : $rootDir; $dir = "{$root}/modules/{$m}"; } $this->compile_dir = "{$rootDir}/tmp/templates_c/"; // Directories initialisation $this->template_dir = "{$dir}/templates/"; // Check if the cache dir is writeable if (!is_dir($this->compile_dir)) { CMbPath::forceDir($this->compile_dir); } // Delimiter definition $this->left_delimiter = "{{"; $this->right_delimiter = "}}"; // Default modifier for security reason $this->default_modifiers = array("@cleanField"); // Register mediboard functions $this->register_block("tr", array($this, "tr")); $this->register_block("main", array($this, "main")); $this->register_function("mb_default", array($this, "mb_default")); $this->register_function("mb_ditto", array($this, "mb_ditto")); $this->register_function("mb_class", array($this, "mb_class")); $this->register_function("mb_value", array($this, "mb_value")); $this->register_function("mb_include", array($this, "mb_include")); $this->register_function("mb_script", array($this, "mb_script")); $this->register_function("thumb", array($this, "thumb")); $this->register_function("unique_id", array($this, "unique_id")); $this->register_function("mb_didacticiel", array($this, "mb_didacticiel")); $this->register_modifier("idex", array($this, "idex")); $this->register_modifier("conf", array($this, "conf")); $this->register_modifier("pad", array($this, "pad")); $this->register_modifier("json", array($this, "json")); $this->register_modifier("purify", array($this, "purify")); $this->register_modifier("markdown", array($this, "markdown")); $this->register_modifier("iso_date", array($this, "iso_date")); $this->register_modifier("iso_time", array($this, "iso_time")); $this->register_modifier("iso_datetime", array($this, "iso_datetime")); $this->register_modifier("rel_datetime", array($this, "rel_datetime")); $this->register_modifier("week_number_month", array($this, "week_number_month")); $this->register_modifier("const", array($this, "_const")); $this->register_modifier("static", array($this, "_static")); $this->register_modifier("static_call", array($this, "static_call")); $this->register_modifier("cleanField", array($this, "cleanField")); $this->register_modifier("stripslashes", array($this, "stripslashes")); $this->register_modifier("emphasize", array($this, "emphasize")); $this->register_modifier("ireplace", array($this, "ireplace")); $this->register_modifier("ternary", array($this, "ternary")); $this->register_modifier("trace", array($this, "trace")); $this->register_modifier("currency", array($this, "currency")); $this->register_modifier("percent", array($this, "percent")); $this->register_modifier("spancate", array($this, "spancate")); $this->register_modifier("float", array($this, "float")); $this->register_modifier("integer", array($this, "integer")); $this->register_modifier("decabinary", array($this, "decabinary")); $this->register_modifier("decasi", array($this, "decasi")); $this->register_modifier("module_installed", array($this, "module_installed")); $this->register_modifier("module_active", array($this, "module_active")); $this->register_modifier("JSAttribute", array($this, "JSAttribute")); $this->register_modifier("nozero", array($this, "nozero")); $this->register_modifier("ide", array($this, "ide")); $this->register_function("mb_token", array($this, "mb_token")); $modules = CModule::getActive(); foreach ($modules as $mod) { $mod->canDo(); } // Standard data assignment $this->assign("style", $uistyle); $this->assign("app", CAppUI::$instance); $this->assign("conf", CAppUI::conf()); $this->assign("user", CAppUI::$instance->user_id); // shouldn't be necessary $this->assign("version", $version); $this->assign("suppressHeaders", $suppressHeaders); $this->assign("can", $can); $this->assign("m", $m); $this->assign("a", $a); $this->assign("tab", $tab); $this->assign("action", $action); $this->assign("actionType", $actionType); $this->assign("g", $g); $this->assign("dialog", $dialog); $this->assign("ajax", $ajax); $this->assign("modules", $modules); $this->assign("base_url", CApp::getBaseUrl()); $this->assign("current_group", CGroups::loadCurrent()); $this->assign("dnow", CMbDT::date()); $this->assign("dtnow", CMbDT::dateTime()); $this->assign("tnow", CMbDT::time()); }
private function _getFile($source_file, $destination_file = null) { $source_base = basename($source_file); if (!$destination_file) { $destination_file = "tmp/{$source_base}"; } $destination_info = pathinfo($destination_file); CMbPath::forceDir($destination_info["dirname"]); if (!$this->connexion) { throw new CMbException("CSourceFTP-connexion-failed", $this->hostname); } // Download the file if (!@ftp_get($this->connexion, $destination_file, $source_file, constant($this->mode))) { throw new CMbException("CSourceFTP-download-file-failed", $source_file, $destination_file); } return $destination_file; }
} if (md5($pass) != "aa450aff6d0f4974711ff4c5536ed4cb") { CAppUI::stepAjax("Mot de passe incorrect.\nAttention, fonctionnalité à utiliser avec une extrême prudence", UI_MSG_ERROR); } // Chrono start $chrono = new Chronometer(); $chrono->start(); $segment = CValue::get("segment", 1000); $step = CValue::get("step", 1); $from = $step > 1 ? 100 + $segment * ($step - 2) : 0; $to = $step > 1 ? 100 + ($step - 1) * $segment : 100; $padded = str_pad($step, "3", "0", STR_PAD_LEFT); $htmpath = "tmp/ordre/medecin{$padded}.htm"; $xmlpath = "tmp/ordre/medecin{$padded}.xml"; $csvpath = "tmp/ordre/medecin{$padded}.csv"; CMbPath::forceDir(dirname($htmpath)); $mode = CValue::get("mode"); // Step 1: Emulates an HTTP request if ($mode == "get") { $departement = CValue::get("departement"); $cookiepath = CAppUI::getTmpPath("cookie.txt"); $page = $step - 1; $url_ch1 = "http://www.conseil-national.medecin.fr/annuaire"; $url_ch2 = "http://www.conseil-national.medecin.fr/annuaire/resultats?page={$page}"; $post = array("sexe" => 3, "departement" => $departement, "op" => "Recherche", "form_build_id" => "form-c2b45a67c53fdd389338ffee58d2c1c2", "form_id" => "cn_search_med_advanced_form"); $ch = curl_init(); $ch2 = curl_init(); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiepath); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiepath); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
<?php /** * $Id$ * * @package Mediboard * @subpackage System * @author SARL OpenXtrem <*****@*****.**> * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html * @version $Revision$ */ CCanDo::checkEdit(); $file = $_FILES["fileupload"]; $token = str_replace(".", "", uniqid("imp_", true)); $new_path = CAppUI::getTmpPath("object_import/{$token}"); CMbPath::forceDir(dirname($new_path)); move_uploaded_file($file["tmp_name"], $new_path); $dom = new CMbXMLObjectExport(); $dom->load($new_path); $smarty = new CSmartyDP(); $smarty->assign("token", $token); $smarty->assign("dom", $dom); $smarty->display("inc_object_import_configure.tpl");
$export = new CMbObjectExport($_patient, $backrefs_tree); $callback = function (CStoredObject $object, $node, $depth) use($export, $dir, $ignore_files, $generate_pdfpreviews) { switch ($object->_class) { case "CCompteRendu": /** @var CCompteRendu $object */ if ($generate_pdfpreviews) { $object->makePDFpreview(true); } break; case "CFile": if ($ignore_files) { break; } /** @var CFile $object */ $_dir = "{$dir}/{$object->object_class}/{$object->object_id}"; CMbPath::forceDir($_dir); file_put_contents($_dir . "/" . $object->file_real_filename, @$object->getBinaryContent()); break; default: // Do nothing } }; $export->empty_values = false; $export->setObjectCallback($callback); $export->setForwardRefsTree($fwdrefs_tree); $xml = $export->toDOM()->saveXML(); file_put_contents("{$dir}/export.xml", $xml); //CMbPath::zip($dir, dirname($dir)."/export-$date.zip"); } catch (CMbException $e) { $e->stepAjax(UI_MSG_ERROR); }
<?php /** * $Id$ * * @category Files * @package Mediboard * @author SARL OpenXtrem <*****@*****.**> * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html * @version $Revision$ * @link http://www.mediboard.org */ $dir = CFile::$directory . "/test"; CAppUI::stepAjax("Test de création de répertoire et d'un fichier dans ce répertoire", UI_MSG_WARNING); // Création d'un répertoire $directory_create = CMbPath::forceDir($dir); if (!$directory_create) { CAppUI::stepAjax("Création de répertoire échoué", UI_MSG_ERROR); CApp::rip(); } CAppUI::stepAjax("Création de répertoire Ok", UI_MSG_OK); // Création d'un fichier $file_create = file_put_contents($dir . "/test_file", "a"); if (!$file_create) { CAppUI::stepAjax("Création de fichier échoué", UI_MSG_ERROR); @unlink($dir); CApp::rip(); } CAppUI::stepAjax("Création de fichier Ok", UI_MSG_OK); // Suppression du fichier et du dossier @unlink($dir . "/test_file");
CAppUI::setMsg("Certaines informations sont manquantes au traitement de la traduction.", UI_MSG_ERROR); redirect(); return; } $translateModule = new CMbConfig(); $translateModule->sourcePath = null; // Ecriture du fichier $translateModule->options = array("name" => "locales"); if ($module_name != "common") { $translateModule->targetPath = "modules/{$module_name}/locales/{$language}.php"; } else { $translateModule->targetPath = "locales/{$language}/common.php"; } $translateModule->sourcePath = $translateModule->targetPath; if (!is_file($translateModule->targetPath)) { CMbPath::forceDir(dirname($translateModule->targetPath)); file_put_contents($translateModule->targetPath, '<?php $locales["module-' . $module_name . '-court"] = "' . $module_name . '";'); } $translateModule->load(); foreach ($strings as $key => $valChaine) { if ($valChaine !== "") { $translateModule->values[$key] = CMbString::purifyHTML(stripslashes($valChaine)); } else { unset($translateModule->values[$key]); } } uksort($translateModule->values, "strnatcmp"); $error = $translateModule->update($translateModule->values, false); SHM::remKeys("locales-{$language}-*"); if ($error instanceof PEAR_Error) { CAppUI::setMsg("Error while saving locales file : {$error->message}", UI_MSG_ERROR);
<?php /** * $Id$ * * @category Search * @package Mediboard * @author SARL OpenXtrem <*****@*****.**> * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html * @link http://www.mediboard.org */ CCanDo::checkAdmin(); $lock_file = CAppUI::getTmpPath("search_indexing"); CMbPath::forceDir($lock_file); $lock_file .= "/search_indexing.lock"; $lock_timeout = 100; if (file_exists($lock_file)) { if (filemtime($lock_file) + $lock_timeout > time()) { echo "Script locked search_indexing\n"; return; } else { echo "Lock file present, but too old, we continue search_indexing\n"; } } /** * remove the lock * * @param string $lock_file The file which lock traitement * * @return void */
/** * @see parent::saveFinalFile */ function saveFinalFile() { $this->documentfinalfilename = "{$this->finalpath}/{$this->documentfinalprefix}-{$this->now}.xml"; CMbPath::forceDir(dirname($this->documentfinalfilename)); parent::save($this->documentfinalfilename); }
* @category Forms * @package Mediboard * @author SARL OpenXtrem <*****@*****.**> * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html * @version $Revision$ * @link http://www.mediboard.org */ CCanDo::checkEdit(); $tmp_filename = $_FILES["import"]["tmp_name"]; $dom = new DOMDocument(); $dom->load($tmp_filename); $xpath = new DOMXPath($dom); if ($xpath->query("/mediboard-export")->length == 0) { CAppUI::js("window.parent.ExClass.uploadError()"); CApp::rip(); } $temp = CAppUI::getTmpPath("ex_class_import"); $uid = preg_replace('/[^\\d]/', '', uniqid("", true)); $filename = "{$temp}/{$uid}"; CMbPath::forceDir($temp); move_uploaded_file($tmp_filename, $filename); // Cleanup old files (more than 4 hours old) $other_files = glob("{$temp}/*"); $now = time(); foreach ($other_files as $_other_file) { if (filemtime($_other_file) < $now - 3600 * 4) { unlink($_other_file); } } CAppUI::js("window.parent.ExClass.uploadSaveUID('{$uid}')"); CApp::rip();
//$PHPTHUMB_CONFIG['document_root'] = 'c:\\webroot\\example.com\\www'; //$PHPTHUMB_CONFIG['document_root'] = $_SERVER['DOCUMENT_ROOT']; //$PHPTHUMB_CONFIG['document_root'] = realpath((@$_SERVER['DOCUMENT_ROOT'] && file_exists(@$_SERVER['DOCUMENT_ROOT'].$_SERVER['PHP_SELF'])) ? $_SERVER['DOCUMENT_ROOT'] : str_replace(dirname(@$_SERVER['PHP_SELF']), '', str_replace(DIRECTORY_SEPARATOR, '/', realpath('.')))); $PHPTHUMB_CONFIG['document_root'] = realpath(getenv('DOCUMENT_ROOT') && preg_match('$^' . preg_quote(realpath(getenv('DOCUMENT_ROOT'))) . '$', realpath(__FILE__)) ? getenv('DOCUMENT_ROOT') : str_replace(dirname(@$_SERVER['PHP_SELF']), '', str_replace(DIRECTORY_SEPARATOR, '/', dirname(__FILE__)))); //$PHPTHUMB_CONFIG['document_root'] = dirname($PHPTHUMB_CONFIG['mediboard_root']); // * Cache directory configuration (choose only one of these - leave the other lines commented-out): // Note: this directory must be writable (usually chmod 777 is neccesary) for caching to work. // If the directory is not writable no error will be generated but caching will be disabled. //$PHPTHUMB_CONFIG['cache_directory'] = dirname(__FILE__).'/cache/'; // set the cache directory relative to the phpThumb() installation //$PHPTHUMB_CONFIG['cache_directory'] = $PHPTHUMB_CONFIG['document_root'].'/phpthumb/cache/'; // set the cache directory to an absolute directory for all source images //$PHPTHUMB_CONFIG['cache_directory'] = './cache/'; // set the cache directory relative to the source image - must start with '.' (will not work to cache URL- or database-sourced images, please use an absolute directory name) //$PHPTHUMB_CONFIG['cache_directory'] = null; // disable thumbnail caching (not recommended) //$PHPTHUMB_CONFIG['cache_directory'] = '/tmp/persistent/phpthumb/cache/'; $PHPTHUMB_CONFIG['cache_directory'] = $PHPTHUMB_CONFIG['mediboard_root'] . "/tmp/phpthumb/"; require_once $PHPTHUMB_CONFIG['mediboard_root'] . "/classes/CMbPath.class.php"; CMbPath::forceDir($PHPTHUMB_CONFIG['cache_directory']); $PHPTHUMB_CONFIG['cache_disable_warning'] = true; // If [cache_directory] is non-existant or not writable, and [cache_disable_warning] is false, an error image will be generated warning to either set the cache directory or disable the warning (to avoid people not knowing about the cache) $PHPTHUMB_CONFIG['cache_directory_depth'] = 5; // If this larger than zero, cache structure will be broken into a broad directory structure based on cache filename. For example "cache_src012345..." will be stored in "/0/01/012/0123/cache_src012345..." when (cache_directory_depth = 4) // * Cache culling: phpThumb can automatically limit the contents of the cache directory // based on last-access date and/or number of files and/or total filesize. //$PHPTHUMB_CONFIG['cache_maxage'] = null; // never delete cached thumbnails based on last-access time $PHPTHUMB_CONFIG['cache_maxage'] = 86400 * 30; // delete cached thumbnails that haven't been accessed in more than [30 days] (value is maximum time since last access in seconds to avoid deletion) //$PHPTHUMB_CONFIG['cache_maxsize'] = null; // never delete cached thumbnails based on byte size of cache directory $PHPTHUMB_CONFIG['cache_maxsize'] = 10 * 1024 * 1024; // delete least-recently-accessed cached thumbnails when more than [10MB] of cached files are present (value is maximum bytesize of all cached files) //$PHPTHUMB_CONFIG['cache_maxfiles'] = null; // never delete cached thumbnails based on number of cached files $PHPTHUMB_CONFIG['cache_maxfiles'] = 200; // delete least-recently-accessed cached thumbnails when more than [200] cached files are present (value is maximum number of cached files to keep)