Пример #1
0
/**
 * Mediboard class autoloader
 * 
 * @param string $class Class to be loaded
 * 
 * @return bool
 */
function mbAutoload($class)
{
    $file_exists = false;
    $time = microtime(true);
    // Entry already in cache
    if (isset(CApp::$classPaths[$class])) {
        // The class is known to not be in MB
        if (CApp::$classPaths[$class] === false) {
            return false;
        }
        // Load it if we can
        if ($file_exists = file_exists(CApp::$classPaths[$class])) {
            CApp::$performance["autoloadCount"]++;
            return include_once CApp::$classPaths[$class];
        }
    }
    // File moved ?
    if (!$file_exists) {
        unset(CApp::$classPaths[$class]);
    }
    // CSetup* class
    if (preg_match('/^CSetup(.+)$/', $class, $matches)) {
        $dirs = array("modules/{$matches['1']}/setup.php");
    } else {
        $class_file = $class;
        $suffix = ".class";
        // Namespaced class
        if (strpos($class_file, "\\") !== false) {
            $namespace = explode("\\", $class_file);
            // Mediboard class
            if ($namespace[0] === "Mediboard") {
                array_shift($namespace);
                $class_file = implode("/", $namespace);
            } else {
                $class_file = "vendor/" . implode("/", $namespace);
                $suffix = "";
            }
        }
        $class_file .= $suffix;
        $dirs = array("classes/{$class_file}.php", "classes/*/{$class_file}.php", "mobile/*/{$class_file}.php", "modules/*/classes/{$class_file}.php", "modules/*/classes/*/{$class_file}.php", "modules/*/classes/*/*/{$class_file}.php", "install/classes/{$class_file}.php");
    }
    $rootDir = CAppUI::conf("root_dir");
    $class_path = false;
    foreach ($dirs as $dir) {
        $files = glob("{$rootDir}/{$dir}");
        foreach ($files as $filename) {
            include_once $filename;
            // The class was found
            if (class_exists($class, false) || interface_exists($class, false)) {
                $class_path = $filename;
                break 2;
            }
        }
    }
    // Class not found, it is not in MB
    CApp::$classPaths[$class] = $class_path;
    SHM::put("class-paths", CApp::$classPaths);
    CApp::$performance["autoload"][$class] = (microtime(true) - $time) * 1000;
    return $class_path !== false;
}
Пример #2
0
 /**
  * Get an instance from the code
  *
  * @param string $code Code
  *
  * @return CIntervenantCdARR
  **/
 static function get($code)
 {
     if (!$code) {
         return new self();
     }
     if ($intervenant = SHM::get("intervenant_{$code}")) {
         return $intervenant;
     }
     $intervenant = new self();
     $intervenant->load($code);
     SHM::put("intervenant_{$code}", $intervenant);
     return $intervenant;
 }
Пример #3
0
 /**
  * Get an instance from the code
  *
  * @param string $code Code CdARR
  *
  * @return CTypeActiviteCdARR
  **/
 static function get($code)
 {
     if (!$code) {
         return new self();
     }
     if ($type = SHM::get("type_activite_{$code}")) {
         return $type;
     }
     $type = new self();
     $type->load($code);
     SHM::put("type_activite_{$code}", $type);
     return $type;
 }
 /**
  * @see parent::init()
  */
 function init()
 {
     if (class_exists('Memcached', false)) {
         $conn = new Memcached();
         $servers = SHM::getServerAddresses();
         foreach ($servers as $_server) {
             $conn->addServer($_server[0], $_server[1]);
         }
         return (bool) ($this->conn = $conn);
     }
     //include __DIR__."/../../lib/xenzilla-memcached/Memcached.php";
     //$conn = new \Xenzilla\Memcached();
     //$conn->addServer("127.0.0.1", 11211);
     //return (bool) $this->conn = $conn;
     return false;
 }
Пример #5
0
 /**
  * Initialize the shared memory
  *
  * @return void
  */
 static function init()
 {
     global $dPconfig;
     // Must be the same here and in CApp
     // We don't use CApp because it can be called in /install
     $root_dir = $dPconfig['root_dir'];
     $prefix = preg_replace("/[^\\w]+/", "_", $root_dir);
     self::$prefix = "{$prefix}-";
     /* ----- Local shared memory ----- */
     $engine_name = $dPconfig['shared_memory'];
     if (!isset(self::$availableEngines[$engine_name])) {
         $engine_name = "disk";
     }
     $class_name = self::$availableEngines[$engine_name];
     include_once __DIR__ . "/shm/{$class_name}.class.php";
     /** @var ISharedMemory $engine */
     $engine = new $class_name();
     if (!$engine->init()) {
         $class_name = self::$availableEngines["disk"];
         include_once __DIR__ . "/shm/{$class_name}.class.php";
         $engine = new $class_name();
         $engine->init();
     }
     self::$engine = $engine;
     /* ----- Multi server shared memory ----- */
     $engine_name_distributed = $dPconfig['shared_memory_distributed'];
     if (!$engine_name_distributed || !isset(self::$availableEngines[$engine_name_distributed])) {
         $engine_name_distributed = $engine_name;
     }
     $class_name = self::$availableEngines[$engine_name_distributed];
     include_once __DIR__ . "/shm/{$class_name}.class.php";
     /** @var ISharedMemory $engine_distributed */
     $engine_distributed = new $class_name();
     if (!$engine_distributed->init()) {
         $class_name = self::$availableEngines["disk"];
         include_once __DIR__ . "/shm/{$class_name}.class.php";
         $engine_distributed = new $class_name();
         $engine_distributed->init();
     }
     self::$engineDistributed = $engine_distributed;
 }
Пример #6
0
 /**
  * @see parent::init()
  */
 function init()
 {
     // Don't use autloader
     include_once __DIR__ . "/../CRedisClient.class.php";
     $client = null;
     $list = SHM::getServerAddresses();
     foreach ($list as $_server) {
         try {
             $client = new CRedisClient($_server[0], $_server[1]);
             $client->connect();
             break;
         } catch (Exception $e) {
             $client = null;
         }
     }
     if ($client) {
         $this->conn = $client;
         return true;
     }
     return false;
 }
 protected static function _emptySHM($class, $key)
 {
     if (!SHM::get($key)) {
         CAppUI::stepAjax("{$class}-shm-none", UI_MSG_OK);
     } else {
         if (!SHM::rem($key)) {
             CAppUI::stepAjax("{$class}-shm-rem-ko", UI_MSG_WARNING);
         }
         CAppUI::stepAjax("{$class}-shm-rem-ok", UI_MSG_OK);
     }
 }
Пример #8
0
        }
        // In case the setup has added some user prefs
        CAppUI::buildPrefs();
        break;
    case "upgrade":
        if ($module->mod_version = $setup->upgrade($module->mod_version)) {
            $module->mod_type = $setup->mod_type;
            $module->store();
            if ($setup->mod_version == $module->mod_version) {
                CAppUI::setMsg("Installation de '%s' à la version %s", UI_MSG_OK, $module->mod_name, $setup->mod_version);
            } else {
                CAppUI::setMsg("Installation de '{$module->mod_name}' à la version {$module->mod_version} sur {$setup->mod_version}", UI_MSG_WARNING, true);
            }
        } else {
            CAppUI::setMsg("Module '%s' non mis à jour", UI_MSG_WARNING, $module->mod_name);
        }
        // In case the setup has added some user prefs
        CAppUI::buildPrefs();
        break;
    default:
        CAppUI::setMsg("Unknown Command", UI_MSG_ERROR);
}
// en cas d'un appel en Ajax (mobile)
if (CValue::get("ajax") || CValue::post("ajax")) {
    echo CAppUI::getMsg();
    CApp::rip();
}
SHM::rem("modules");
if (!$mobile) {
    CAppUI::redirect("m=system&tab=view_modules");
}
Пример #9
0
 /**
  * Get an instance from the code
  *
  * @param string $code Code
  *
  * @return self
  **/
 static function get($code)
 {
     if (!$code) {
         return new self();
     }
     if ($hierarchie = SHM::get("hierarchie_{$code}")) {
         return $hierarchie;
     }
     $hierarchie = new self();
     $hierarchie->load($code);
     SHM::put("hierarchie_{$code}", $hierarchie);
     return $hierarchie;
 }
Пример #10
0
}
CApp::$chrono->stop();
CApp::preparePerformance();
// Unlocalized strings
if (!$suppressHeaders || $ajax) {
    CAppUI::$unlocalized = array_map("utf8_encode", CAppUI::$unlocalized);
    $unloc = new CSmartyDP("modules/system");
    $unloc->display("inc_unlocalized_strings.tpl");
}
// Inclusion du footer
if (!$suppressHeaders) {
    //$address = get_remote_address();
    if ($infosystem = CAppUI::pref("INFOSYSTEM")) {
        $latest_cache_key = "{$user->_guid}-latest_cache";
        $latest_cache = array("meta" => array("module" => $m, "action" => $action, "user" => $user->_view), "totals" => Cache::$totals, "hits" => Cache::$hits);
        SHM::put($latest_cache_key, $latest_cache, true);
    }
    $tplFooter = new CSmartyDP("style/{$uistyle}");
    $tplFooter->assign("offline", false);
    $tplFooter->assign("performance", CApp::$performance);
    $tplFooter->assign("infosystem", $infosystem);
    $tplFooter->assign("errorMessage", CAppUI::getMsg());
    $tplFooter->assign("navigatory_history", CViewHistory::getHistory());
    $tplFooter->display("footer.tpl");
}
// Ajax performance
if ($ajax) {
    $tplAjax = new CSmartyDP("modules/system");
    $tplAjax->assign("performance", CApp::$performance);
    $tplAjax->assign("requestID", CValue::get("__requestID"));
    $tplAjax->display("ajax_errors.tpl");
Пример #11
0
require_once "../classes/SHM.class.php";
// Remove locales
foreach (glob("../locales/*", GLOB_ONLYDIR) as $localeDir) {
    $localeName = basename($localeDir);
    $sharedName = "locales-{$localeName}";
    if (!SHM::get("{$sharedName}-.__prefixes__")) {
        echo "Table absente en mémoire pour langage '{$localeName}'<br />";
        continue;
    }
    if (!SHM::remKeys("{$sharedName}-*")) {
        echo "Impossible de supprimer la table pour le langage '{$localeName}'<br />";
        continue;
    }
    echo "Table supprimée pour langage '{$localeName}'<br />";
}
if (!SHM::rem("class-paths")) {
    echo "Impossible de supprimer la table des classes<br />";
    return;
}
echo "Table des classes supprimée<br />";
$classes = array("CApp");
foreach ($classes as $_class) {
    $count = SHM::remKeys("{$_class}*");
    echo "Suppression dans le cache de {$count} items pour le préfixe {$_class}";
}
echo "Table des classes filles supprimée<br />";
if (!SHM::rem("modules")) {
    echo "Impossible de supprimer la table des classes<br />";
    return;
}
echo "Table des modules supprimée<br />";
Пример #12
0
 /**
  * Remove a value from all defined layers of the cache
  *
  * @return void
  */
 public function rem()
 {
     $layers = $this->layers;
     // Inner cache
     if ($layers & Cache::INNER) {
         unset(self::$data[$this->prefix][$this->key]);
     }
     // Flat key for outer and distributed layers
     $key = "{$this->prefix}-{$this->key}";
     // Outer cache
     if ($layers & Cache::OUTER) {
         SHM::rem($key);
     }
     // Distributed cache
     if ($layers & Cache::DISTR) {
         DSHM::rem($key);
     }
 }
Пример #13
0
<?php

/**
 * $Id: about.php 20799 2013-10-29 11:43:54Z phenxdesign $
 *
 * @package    Mediboard
 * @subpackage System
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 20799 $
 */
CCanDo::checkRead();
$user = CAppUI::$user;
$latest_cache_key = "{$user->_guid}-latest_cache";
$latest_cache = SHM::get($latest_cache_key);
foreach ($latest_cache["hits"] as &$keys) {
    ksort($keys);
}
//mbTrace($latest_cache["totals"]);
$smarty = new CSmartyDP();
$smarty->assign("all_layers", Cache::$all_layers);
$smarty->assign("latest_cache", $latest_cache);
$smarty->display("latest_cache_hits.tpl");
Пример #14
0
 /**
  * Charge une activité par le code
  *
  * @param string $code Code d'activité
  *
  * @return self
  */
 static function get($code)
 {
     if (!$code) {
         return new self();
     }
     if ($activite = SHM::get("activite_cdarr_{$code}")) {
         return $activite;
     }
     $activite = new self();
     $activite->load($code);
     SHM::put("activite_cdarr_{$code}", $activite);
     return $activite;
 }
Пример #15
0
 * $Id: cache_tester_users.php 24615 2014-09-01 10:52:44Z phenxdesign $
 *
 * @package    Mediboard
 * @subpackage developpement
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 24615 $
 */
CCanDo::checkRead();
$chrono = new Chronometer();
$chrono->start();
if (CView::get("purge", "bool default|0")) {
    SHM::rem("mediusers");
    $chrono->step("purge");
}
if (!SHM::exists("mediusers")) {
    $chrono->step("acquire (not yet)");
    $mediuser = new CMediusers();
    $mediusers = $mediuser->loadListFromType();
    $chrono->step("load");
    SHM::put("mediusers", $mediusers, true);
    $chrono->step("put");
}
/** @var CMediusers[] $mediusers */
$mediusers = SHM::get("mediusers");
$chrono->step("get");
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("mediusers", $mediusers);
$smarty->assign("chrono", $chrono);
$smarty->display("cache_tester_users.tpl");
////////// Smarty templates
// DO NOT use CMbPath::removed because it must be used in the installer
$templates = array_merge(glob("tmp/templates_c/*/*/*/*/*"), glob("tmp/templates_c/*/*/*/*"), glob("tmp/templates_c/*/*/*"));
foreach ($templates as $_template) {
    if (is_file($_template)) {
        unlink($_template);
    }
}
$template_dirs = array_merge(glob("tmp/templates_c/*/*/*/*", GLOB_ONLYDIR), glob("tmp/templates_c/*/*/*", GLOB_ONLYDIR), glob("tmp/templates_c/*/*", GLOB_ONLYDIR));
foreach ($template_dirs as $_dir) {
    rmdir($_dir);
}
CAppUI::stepAjax("template-cache-removed", UI_MSG_OK, count($templates));
////////// Module specific removals
foreach (glob("modules/*/empty_shared_memory.php") as $script) {
    include $script;
}
// Remove locales, at the end because otherwise, next message aren't translated
foreach (glob("locales/*", GLOB_ONLYDIR) as $localeDir) {
    $localeName = basename($localeDir);
    $sharedName = "locales-{$localeName}";
    if (!SHM::get("{$sharedName}-" . CAppUI::LOCALES_PREFIX)) {
        CAppUI::stepAjax("Locales-shm-none", UI_MSG_OK, $localeName);
        continue;
    }
    if (!SHM::remKeys("{$sharedName}-*")) {
        CAppUI::stepAjax("Locales-shm-rem-ko", UI_MSG_WARNING, $localeName);
        continue;
    }
    CAppUI::stepAjax("Locales-shm-rem-ok", UI_MSG_OK, $localeName);
}
Пример #17
0
 /**
  * Get a flattened version of all cached locales
  *
  * @param string $lang Language: fr, en
  *
  * @return array
  */
 static function flattenCachedLocales($lang)
 {
     $shared_name = "locales-{$lang}";
     $prefixes = SHM::get("{$shared_name}-" . self::LOCALES_PREFIX);
     $locales = array();
     foreach ($prefixes as $_hash => $_prefix) {
         $prefixed = SHM::get("{$shared_name}-{$_hash}");
         if ($_prefix === "__common__") {
             $_prefix = "";
         }
         foreach ($prefixed as $_key => $_value) {
             $locales["{$_prefix}{$_key}"] = $_value;
         }
     }
     return $locales;
 }
Пример #18
0
<?php

/**
 * $Id$
 *  
 * @category CCAM
 * @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
 */
$classes = array("CCodeCIM10");
foreach ($classes as $_class) {
    $count = SHM::remKeys("{$_class}*");
    CAppUI::stepAjax("module-system-msg-cache-removal", UI_MSG_OK, $count, $_class);
}
Пример #19
0
 *
 * @package    Mediboard
 * @subpackage developpement
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
CCanDo::checkRead();
$chrono = new Chronometer();
$chrono->start();
$classes = CApp::getChildClasses("CModelObject");
//$classes = array_keys(CModelObject::$spec);
foreach ($classes as $_class) {
    /** @var CModelObject $object */
    $object = new $_class();
    $object->makeAllBackSpecs();
    $chrono->step("make");
}
foreach ($classes as $_class) {
    $ballot = array("spec" => CModelObject::$spec[$_class], "props" => CModelObject::$props[$_class], "specs" => CModelObject::$specs[$_class], "backProps" => CModelObject::$backProps[$_class], "backSpecs" => CModelObject::$backSpecs[$_class]);
    SHM::put("ballot-{$_class}", $ballot, true);
    $chrono->step("put");
}
foreach ($classes as $_class) {
    SHM::get("ballot-{$_class}");
    $chrono->step("get");
}
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("chrono", $chrono);
$smarty->display("cache_tester_metamodel.tpl");
Пример #20
0
 /**
  * Load the list of visible modules
  *
  * @param bool $shm Use shared memory
  *
  * @return void
  */
 static function loadModules($shm = true)
 {
     // @todo Experiment, then remove test if no problem
     if ($shm) {
         $modules = SHM::get("modules");
         if (!$modules) {
             $module = new self();
             $modules = $module->loadList(null, "mod_ui_order");
             SHM::put("modules", $modules);
         }
     } else {
         $module = new self();
         $modules = $module->loadList(null, "mod_ui_order");
     }
     /** @var $module CModule */
     foreach ($modules as &$module) {
         $module->checkModuleFiles();
         self::$installed[$module->mod_name] =& $module;
         if ($module->mod_active == 1) {
             self::$active[$module->mod_name] =& $module;
         }
         if ($module->mod_ui_active == 1) {
             self::$visible[$module->mod_name] =& $module;
         }
         if ($module->_files_missing) {
             self::$absent[$module->mod_name] =& $module;
         }
     }
 }
    foreach ($locales as &$_locale) {
        $_locale = CMbString::unslash($_locale);
    }
    $path = "./tmp/locales-{$localeName}.js";
    if (!is_file($path)) {
        CAppUI::stepAjax("Locales-javascript-cache-none", UI_MSG_OK, $localeName);
        continue;
    }
    $fp = fopen($path, 'r');
    preg_match('#^//(\\d+)#', fgets($fp), $v);
    if ($v[1] < $version['build']) {
        CAppUI::stepAjax("Locales-javascript-cache-ko", UI_MSG_WARNING, $localeName);
        fclose($fp);
        continue;
    }
    if (null == SHM::get("locales-{$localeName}-" . CAppUI::LOCALES_PREFIX)) {
        CAppUI::stepAjax("Locales-shm-none", UI_MSG_OK, $localeName);
        continue;
    }
    // Load overwritten locales if the table exists
    $overwrite = new CTranslationOverwrite();
    if ($overwrite->isInstalled()) {
        $locales = $overwrite->transformLocales($locales);
    }
    $cached_locales = CAppUI::flattenCachedLocales($localeName);
    if ($cached_locales != $locales) {
        CAppUI::stepAjax("Locales-shm-ko", UI_MSG_WARNING, $localeName);
        continue;
    }
    CAppUI::stepAjax("Locales-shm-ok", UI_MSG_OK, $localeName);
}
<?php

/**
 * AED translation overwrite
 *  
 * @category System
 * @package  Mediboard
 * @author   SARL OpenXtrem <*****@*****.**>
 * @license  GNU General Public License, see http://www.gnu.org/licenses/gpl.html 
 * @version  SVN: $Id:\$ 
 * @link     http://www.mediboard.org
 */
$language = CValue::post("language", "fr");
$do = new CDoObjectAddEdit("CTranslationOverwrite", "translation_id");
$do->doIt();
SHM::remKeys("locales-{$language}-*");
 /**
  * Get the values cache status
  *
  * @return string The values can be self::STATUS_EMPTY, self::STATUS_DIRTY or self::STATUS_OK
  */
 static function getValuesCacheStatus()
 {
     $hosts = SHM::get("config-values-__HOSTS__");
     if (!$hosts) {
         return self::STATUS_EMPTY;
     }
     if (self::_isValuesCacheDirty($hosts["date"])) {
         return self::STATUS_DIRTY;
     }
     return self::STATUS_OK;
 }
Пример #24
0
 /**
  * Charge une activité par le code
  *
  * @param string $code Code d'activité
  *
  * @return self
  */
 static function get($code)
 {
     if (!$code) {
         return new self();
     }
     if ($activite = SHM::get("activite_csarr_{$code}")) {
         $activite->loadRefReference();
         $activite->loadRefsModulateurs();
         return $activite;
     }
     $activite = new self();
     $activite->load($code);
     SHM::put("activite_csarr_{$code}", $activite);
     $activite->loadRefReference();
     $activite->loadRefsModulateurs();
     return $activite;
 }