Exemple #1
0
function cron_run()
{
    $m = new moduleloader();
    $modules = $m->getAllModules();
    foreach ($modules as $module) {
        $name = $module['module_name'];
        $class = "\\modules\\{$name}\\cron";
        if (method_exists($class, 'run')) {
            moduleloader::includeModule($name);
            $c = new $class();
            $c->run();
        }
    }
}
 /**
  * Method for calling function or static method
  * @param type $call
  * @param type $matches
  * @return boolean $res if no function or method is found return false. 
  */
 public static function call($call)
 {
     $ary = explode('::', $call);
     $call_exists = null;
     ob_start();
     // call is a class
     if (count($ary) == 2) {
         $module = $ary[0];
         $method = $ary[1];
         $class = self::getModuleName($module);
         if (method_exists($class, $method)) {
             $call_exists = 1;
             $o = new $class();
             $o->{$method}();
             if (isset(moduleloader::$status[403])) {
                 moduleloader::includeModule('error');
                 $e = new errorModule();
                 $e->accessdeniedAction();
             }
             if (isset(moduleloader::$status[404])) {
                 moduleloader::includeModule('error');
                 $e = new errorModule();
                 $e->notfoundAction();
             }
         }
     }
     return ob_get_clean();
 }
Exemple #3
0
 /**
  * Check if user has access 
  * @return void
  */
 public function checkAccess()
 {
     if (!session::isUser()) {
         moduleloader::setStatus(403);
         return;
     }
 }
Exemple #4
0
 public function checkAccess()
 {
     if (!session::isAdmin()) {
         moduleloader::setStatus(403);
         return false;
     }
     return true;
 }
function multi_shared_all_up($options = null)
{
    $path = conf::pathBase() . "/config/multi/*";
    $dirs = file::getDirsGlob($path, array('basename' => 1));
    //print_r($options); die;
    moduleloader::includeModule('siteclone');
    foreach ($dirs as $domain) {
        $command = "./coscli.sh --domain={$domain} module --all-up";
        common::echoMessage("Updating: {$domain}");
        common::echoMessage($command);
        passthru($command, $return_var);
        $command = "./coscli.sh --domain={$domain} install --lang";
        common::echoMessage("Updating system language: {$domain}");
        common::echoMessage($command);
        passthru($command, $return_var);
    }
}
function cos_upgrade($options)
{
    moduleloader::includeModule('system');
    $p = new profile();
    if (git::isMaster()) {
        common::abort('Can not make upgrade from master branch');
    }
    $repo = conf::getModuleIni('system_repo');
    $remote = git::getTagsRemoteLatest($repo);
    if ($p->upgradePossible()) {
        common::echoMessage("Latest version/tag: {$remote}", 'y');
        $continue = common::readlineConfirm('Continue the upgrade');
        if ($continue) {
            cos_upgrade_to($remote);
        }
    } else {
        $locale = git::getTagsInstallLatest();
        common::echoMessage("Latest version/tag: {$locale}", 'y');
        $continue = common::readlineConfirm('Continue. Maybe your upgrade was interrupted. ');
        if ($continue) {
            cos_upgrade_to($remote);
        }
    }
}
 /**
  * Upgrade to a specific version of a module
  * @param float $specific, e.g. '5.06'
  * @return boolean $res
  */
 public function upgrade($specific = null)
 {
     // Only upgrade if module is installed
     if (!moduleloader::isInstalledModule($this->installInfo['NAME'])) {
         common::echoMessage("Notice: Can not upgrade. You will need to install module first");
         return;
     }
     // Get specific version
     if (!isset($specific)) {
         $specific = $this->installInfo['VERSION'];
     }
     // Get current module version from registry
     $row = $this->getModuleDbInfo();
     $current_version = $row['module_version'];
     // Same version. Return
     if ($current_version == $specific) {
         $this->confirm = "Module '" . $this->installInfo['NAME'] . "'. Version is '{$specific}'. No upgrade to perform";
         return true;
     }
     // Get a list of SQL updates to perform
     $updates = $this->getSqlFileListOrdered($this->installInfo['NAME'], 'up');
     // perform sql upgrade
     if (!empty($updates)) {
         foreach ($updates as $key => $val) {
             $possible_versions = '';
             $version = substr($val, 0, -4);
             if ($version == $specific) {
                 $version_exists = true;
             } else {
                 $possible_versions .= "{$version} ";
             }
         }
         if (!isset($version_exists)) {
             $this->error = 'Module SQL ' . $this->installInfo['NAME'] . " ";
             $this->error .= 'does not have such a version. Possible version are: ';
             $this->error .= $possible_versions;
         }
         // perform SQL updates found in .sql files
         foreach ($updates as $key => $val) {
             $version = substr($val, 0, -4);
             if ($current_version < $version) {
                 $this->executeSqlUpgrade($version);
             }
         }
     }
     // update registry
     $this->updateRegistry($specific, $row['id']);
     if ($specific > $current_version) {
         $this->confirm = "Module '" . $this->installInfo['NAME'] . "'. ";
         $this->confirm .= "Version '" . $specific . "' installed. ";
         $this->confirm .= "Upgraded from {$current_version}";
         return true;
     } else {
         $this->confirm = "Module '" . $this->installInfo['NAME'] . "'. Nothing to upgrade. Module version is still {$current_version}";
         return true;
     }
 }
 /**
  * inits a template
  * set template name and load init settings
  * @param string $template name of the template to init. 
  */
 public static function init($template)
 {
     self::$templateName = $template;
     if (!isset(conf::$vars['template'])) {
         conf::$vars['template'] = array();
     }
     moduleloader::setModuleIniSettings($template, 'template');
     $css = conf::getMainIni('css');
     if ($css) {
         assets::setTemplateCssIni($template, $css);
     }
 }
Exemple #9
0
 /**
  * loads all modules in database
  */
 public static function loadDbModules()
 {
     if (!self::tablesExists()) {
         common::echoMessage('No tables exists. We can not load all modules');
         return;
     }
     $mod_loader = new moduleloader();
     $modules = moduleloader::getAllModules();
     foreach ($modules as $val) {
         if (isset($val['is_shell']) && $val['is_shell'] == 1) {
             moduleloader::includeModule($val['module_name']);
             $path = conf::pathModules() . "/{$val['module_name']}/{$val['module_name']}.inc";
             if (file_exists($path)) {
                 include_once $path;
             }
         }
     }
 }
 /**
  * method for getting all parsed blocks
  * @todo clearify what is going on
  * @param string $block
  * @return array blocks containing strings with html to display
  */
 public static function parseBlock($block)
 {
     $blocks = array();
     if (isset(conf::$vars['coscms_main'][$block], conf::$vars['coscms_main']['module'][$block])) {
         $blocks = array_merge(conf::$vars['coscms_main'][$block], conf::$vars['coscms_main']['module'][$block]);
     } else {
         if (isset(conf::$vars['coscms_main'][$block])) {
             $blocks = conf::$vars['coscms_main'][$block];
         } else {
             if (isset(conf::$vars['coscms_main']['module'][$block])) {
                 $blocks = conf::$vars['coscms_main']['module'][$block];
             } else {
                 return $blocks;
             }
         }
     }
     $ret_blocks = array();
     foreach ($blocks as $val) {
         // numeric is custom block added to database
         if (is_numeric($val)) {
             moduleloader::includeModule('blocks');
             $row = blocks::getOne($val);
             $row['content_block'] = moduleloader::getFilteredContent(conf::getModuleIni('blocks_filters'), $row['content_block']);
             $row['title'] = htmlspecialchars($row['title']);
             $content = view::get('blocks', 'block_html', $row);
             $ret_blocks[] = $content;
             continue;
         }
         if ($val == 'module_menu') {
             $ret_blocks[] = self::getMainMenu();
             continue;
         }
         $func = explode('/', $val);
         $num = count($func) - 1;
         $func = explode('.', $func[$num]);
         $func = 'block_' . $func[0];
         $path_to_function = conf::pathModules() . "/{$val}";
         include_once $path_to_function;
         ob_start();
         $ret = $func();
         if ($ret) {
             $ret_blocks[] = $ret;
         } else {
             $ret_blocks[] = ob_get_contents();
             ob_end_clean();
         }
     }
     return $ret_blocks;
 }
Exemple #11
0
 public static function includeModules($methods = array())
 {
     foreach ($methods as $val) {
         $ary = explode('::', $val);
         $module = $class = $ary[0];
         //$method = $ary[1];
         if (moduleloader::isInstalledModule($module)) {
             moduleloader::includeModule($module);
         }
     }
     return;
 }
Exemple #12
0
 /**
  * Run the system 
  */
 public function run()
 {
     // Register an autoloader for loading modules from mopdules dir
     $m = new modules();
     $m->autoloadRegister();
     // define HTML constants
     common::defineConstants();
     // define global constants - based on base path
     conf::defineCommon();
     // set include paths
     conf::setIncludePath();
     // load config file
     conf::load();
     if (conf::getMainIni('debug')) {
         log::enableDebug();
     }
     // set public file folder in file class
     file::$basePath = conf::getFullFilesPath();
     // utf-8
     ini_set('default_charset', 'UTF-8');
     // load config/config.ini
     // check if there exists a shared ini file
     // shared ini is used if we want to enable settings between hosts
     // which share same code base.
     // e.g. when updating all sites, it is a good idea to set the following flag
     // site_update = 1
     // this flag will send correct 503 headers, when we are updating our site.
     // if site is being updaing we send temporarily headers
     // and display an error message
     if (conf::getMainIni('site_update')) {
         http::temporarilyUnavailable();
     }
     // set a unified server_name if not set in config file.
     $server_name = conf::getMainIni('server_name');
     if (!$server_name) {
         conf::setMainIni('server_name', $_SERVER['SERVER_NAME']);
     }
     // redirect to uniform server name is set in config.ini
     // e.g. www.testsite.com => testsite.com
     $server_redirect = conf::getMainIni('server_redirect');
     if (isset($server_redirect)) {
         http::redirectHeaders($server_redirect);
     }
     // redirect to https is set in config.ini
     // force anything into ssl mode
     $server_force_ssl = conf::getMainIni('server_force_ssl');
     if (isset($server_force_ssl)) {
         http::sslHeaders();
     }
     // catch all output
     ob_start();
     // Create a db connection
     $db_conn = array('url' => conf::getMainIni('url'), 'username' => conf::getMainIni('username'), 'password' => conf::getMainIni('password'), 'db_init' => conf::getMainIni('db_init'));
     // Other options
     // db_dont_persist = 0
     // dont_die = 0 // Set to one and the connection don't die because of
     // e.g. no database etc. This will return NO_DB_CONN as string
     //$url = conf::getMainIni('url');
     connect::connect($db_conn);
     // init module loader.
     $ml = new moduleloader();
     // initiate uri
     uri::getInstance();
     // runlevel 1: merge db config
     $ml->runLevel(1);
     // select all db settings and merge them with ini file settings
     $db_Settings = [];
     if (moduleloader::moduleExists('settings')) {
         $db_settings = q::select('settings')->filter('id =', 1)->fetchSingle();
     }
     // merge db settings with config/config.ini settings
     // db settings override ini file settings
     conf::$vars['coscms_main'] = array_merge(conf::$vars['coscms_main'], $db_settings);
     // run level 2: set locales
     $ml->runLevel(2);
     // set locales
     intl::setLocale();
     // set default timezone
     intl::setTimezone();
     // runlevel 3 - init session
     $ml->runLevel(3);
     // start session
     session::initSession();
     // Se if user is logged in with SESSION
     if (!session::isUser()) {
         // If not logged in check system cookie
         // This will start the session, if an appropiate cookie exists
         session::checkSystemCookie();
     }
     // Check account
     $res = session::checkAccount();
     if (!$res) {
         // Redirect to main page if user is not allowed
         // With current SESSION or COOKIE
         http::locationHeader('/');
     }
     // set account timezone if enabled - can only be done after session
     // as user needs to be logged in
     intl::setAccountTimezone();
     // run level 4 - load language
     $ml->runLevel(4);
     // load all language files
     $l = new lang();
     $base = conf::pathBase();
     $htdocs = conf::pathHtdocs();
     $l->setDirsInsideDir("{$base}/modules/");
     $l->setDirsInsideDir("{$htdocs}/templates/");
     $l->setSingleDir("{$base}/vendor/diversen/simple-php-classes");
     $l->setSingleDir("{$base}/vendor/diversen/simple-pager");
     $l->loadLanguage(conf::getMainIni('lang'));
     // runlevel 5
     $ml->runLevel(5);
     // load routes if any
     dispatch::setDbRoutes();
     // check db routes or load defaults
     $db_route = dispatch::getMatchRoutes();
     if (!$db_route) {
         $ml->setModuleInfo();
         $ml->initModule();
     } else {
         dispatch::includeModule($db_route['method']);
     }
     // After module has been loaded.
     // You can e.g. override module ini settings
     $ml->runLevel(6);
     // Init layout. Sets template name
     // load correct CSS. St menus if any. Etc.
     $layout = new layout();
     // we first load menus here so we can se what happened when we
     // init our module. In case of a 404 not found error we don't want
     // to load module menus
     $layout->loadMenus();
     // init blocks
     $layout->initBlocks();
     // if any matching route was found we check for a method or function
     if ($db_route) {
         $str = dispatch::call($db_route['method']);
     } else {
         // or we use default module parsing
         $str = $ml->getParsedModule();
     }
     // set view vars
     $vars['content'] = $str;
     // run level 7
     $ml->runLevel(7);
     // echo module content
     echo $str = \mainTemplate::view($vars);
     conf::$vars['final_output'] = ob_get_contents();
     ob_end_clean();
     // Last divine intervention
     // e.g. Dom or Tidy
     $ml->runLevel(8);
     echo conf::$vars['final_output'];
 }
/**
 * will purge module not found in a profile
 * @param array $options
 */
function cos_purge_from_profile($options)
{
    $pro = new profile();
    $pro->setProfileInfo($options['profile']);
    $mods = moduleloader::getAllModules();
    //print_r($mods); die;
    foreach ($mods as $module) {
        if (!$pro->isModuleInProfile($module['module_name'])) {
            purge_module($options = array('module' => $module['module_name']));
        }
    }
    $temps = layout::getAllTemplates();
    foreach ($temps as $template) {
        if (!$pro->isTemplateInProfile($template)) {
            purge_template($options = array('template' => $template));
        }
    }
}
Exemple #14
0
 /**
  * inits profile system. Include profile module
  */
 public static function initProfile()
 {
     if (!isset(self::$profile_object)) {
         $profile_system = conf::getMainIni('profile_module');
         if (!isset($profile_system) || !moduleloader::isInstalledModule($profile_system)) {
             self::$profile_object = new defaultProfile();
             return;
         } else {
             moduleloader::includeModule($profile_system);
             $class = "modules\\{$profile_system}\\module";
             self::$profile_object = new $class();
         }
     }
 }
Exemple #15
0
/**
 * will list lal modules in db table modules
 */
function module_list_all()
{
    $ml = new moduleloader();
    $modules = $ml->getAllModules();
    print_r($modules);
}
Exemple #16
0
 public function run()
 {
     // Register an autoloader for loading modules from mopdules dir
     $m = new modules();
     $m->autoloadRegister();
     // define HTML constants
     common::defineConstants();
     // define global constants - based on base path
     conf::defineCommon();
     // set include paths
     conf::setIncludePath();
     // load config file
     conf::load();
     // set log level - based on config.ini
     log::setLogLevel();
     // utf-8
     ini_set('default_charset', 'UTF-8');
     // load config/config.ini
     // check if there exists a shared ini file
     // shared ini is used if we want to enable settings between hosts
     // which share same code base.
     // e.g. when updating all sites, it is a good idea to set the following flag
     // site_update = 1
     // this flag will send correct 503 headers, when we are updating our site.
     // if site is being updaing we send temporarily headers
     // and display an error message
     if (conf::getMainIni('site_update')) {
         http::temporarilyUnavailable();
     }
     // set a unified server_name if not set in config file.
     $server_name = conf::getMainIni('server_name');
     if (!$server_name) {
         conf::setMainIni('server_name', $_SERVER['SERVER_NAME']);
     }
     // redirect to uniform server name is set in config.ini
     // e.g. www.testsite.com => testsite.com
     $server_redirect = conf::getMainIni('server_redirect');
     if (isset($server_redirect)) {
         http::redirectHeaders($server_redirect);
     }
     // redirect to https is set in config.ini
     // force anything into ssl mode
     $server_force_ssl = conf::getMainIni('server_force_ssl');
     if (isset($server_force_ssl)) {
         http::sslHeaders();
     }
     // catch all output
     ob_start();
     // Create a db connection
     $db = new db();
     // init module loader.
     $ml = new moduleloader();
     // initiate uri
     uri::getInstance();
     // runlevel 1: merge db config
     $ml->runLevel(1);
     // select all db settings and merge them with ini file settings
     $db_settings = $db->selectOne('settings', 'id', 1);
     // merge db settings with config/config.ini settings
     // db settings override ini file settings
     conf::$vars['coscms_main'] = array_merge(conf::$vars['coscms_main'], $db_settings);
     // run level 2: set locales
     $ml->runLevel(2);
     // set locales
     intl::setLocale();
     // set default timezone
     intl::setTimezone();
     // runlevel 3 - init session
     $ml->runLevel(3);
     // start session
     session::initSession();
     $res = session::checkAccount();
     if (!$res) {
         // To prevent
         http::locationHeader('/');
     }
     // set account timezone if enabled - can only be done after session
     // as user needs to be logged in
     intl::setAccountTimezone();
     // run level 4 - load language
     $ml->runLevel(4);
     // load all language files
     $l = new lang();
     $base = conf::pathBase();
     $htdocs = conf::pathHtdocs();
     $l->setDirsInsideDir("{$base}/modules/");
     $l->setDirsInsideDir("{$htdocs}/templates/");
     $l->setSingleDir("{$base}/vendor/diversen/simple-php-classes");
     $l->setSingleDir("{$base}/vendor/diversen/simple-pager");
     $l->loadLanguage(conf::getMainIni('language'));
     // runlevel 5
     $ml->runLevel(5);
     // load routes if any
     dispatch::setDbRoutes();
     // runlevel 6
     $ml->runLevel(6);
     // check db routes or load by defaults
     $db_route = dispatch::getMatchRoutes();
     if (!$db_route) {
         $ml->setModuleInfo();
         $ml->initModule();
     }
     // Init layout. Sets template name
     // load correct CSS. St menus if any. Etc.
     $layout = new layout();
     // we first load menus here so we can se what happened when we
     // init our module. In case of a 404 not found error we don't want
     // to load module menus
     $layout->loadMenus();
     // init blocks
     $layout->initBlocks();
     // if any matching route was found we check for a method or function
     if ($db_route) {
         $str = dispatch::call($db_route['method']);
     } else {
         // or we use default module parsing
         $str = $ml->getParsedModule();
     }
     // set view vars
     $vars['content'] = $str;
     // run level 7
     $ml->runLevel(7);
     // echo module content
     echo $str = \mainTemplate::view($vars);
     conf::$vars['final_output'] = ob_get_contents();
     ob_end_clean();
     // Last divine intervention
     // e.g. Dom or Tidy
     $ml->runLevel(8);
     echo conf::$vars['final_output'];
 }