function init(&$c)
 {
     $errors = pfcContainerInterface::init($c);
     // generate the container parameters from other config parameters
     $this->loadPaths($c);
     $errors = array_merge($errors, @test_writable_dir($c->container_cfg_chat_dir, "container_cfg_chat_dir"));
     $errors = array_merge($errors, @test_writable_dir($c->container_cfg_server_dir, "container_cfg_chat_dir/serverid"));
     // test the filemtime php function because it doesn't work on special filesystem
     // example : NFS, VZFS
     $filename = $c->data_private_path . '/filemtime.test';
     $timetowait = 2;
     if (is_writable(dirname($filename))) {
         file_put_contents($filename, 'some-data1-' . time(), LOCK_EX);
         clearstatcache();
         $time1 = filemtime($filename);
         sleep($timetowait);
         file_put_contents($filename, 'some-data2-' . time(), LOCK_EX);
         clearstatcache();
         $time2 = filemtime($filename);
         unlink($filename);
         if ($time2 - $time1 != $timetowait) {
             $errors[] = "filemtime php fuction is not usable on your filesystem. Please do not use the 'file' container (try the 'mysql' container) or swith to another filesystem.";
         }
     }
     return $errors;
 }
Example #2
0
 function init(&$c)
 {
     $errors = pfcContainerInterface::init($c);
     // generate the container parameters from other config parameters
     $this->loadPaths($c);
     $errors = array_merge($errors, @test_writable_dir($c->container_cfg_chat_dir, "container_cfg_chat_dir"));
     $errors = array_merge($errors, @test_writable_dir($c->container_cfg_server_dir, "container_cfg_chat_dir/serverid"));
     return $errors;
 }
 /**
  * Initialize the phpfreechat configuration
  * this initialisation is done once at startup then it is stored into a session cache
  */
 function init()
 {
     $ok = true;
     // check the parameters types
     $array_params = $this->_params_type["array"];
     foreach ($array_params as $ap) {
         if (!is_array($this->{$ap})) {
             $this->errors[] = _pfc("'%s' parameter must be an array", $ap);
         }
     }
     $numerical_positive_params = $this->_params_type["positivenumeric"];
     foreach ($numerical_positive_params as $npp) {
         if (!is_int($this->{$npp}) || $this->{$npp} < 0) {
             $this->errors[] = _pfc("'%s' parameter must be a positive number", $npp);
         }
     }
     $boolean_params = $this->_params_type["bool"];
     foreach ($boolean_params as $bp) {
         if (!is_bool($this->{$bp})) {
             $this->errors[] = _pfc("'%s' parameter must be a boolean", $bp);
         }
     }
     $string_params = $this->_params_type["string"];
     foreach ($string_params as $sp) {
         if (!is_string($this->{$sp})) {
             $this->errors[] = _pfc("'%s' parameter must be a charatere string", $sp);
         }
     }
     if ($this->title == "") {
         $this->title = _pfc("My Chat");
     }
     // first of all, check the used functions
     $f_list["file_get_contents"] = _pfc("You need %s", "PHP 4 >= 4.3.0 or PHP 5");
     $err_session_x = "You need PHP 4 or PHP 5";
     $f_list["session_start"] = $err_session_x;
     $f_list["session_destroy"] = $err_session_x;
     $f_list["session_id"] = $err_session_x;
     $f_list["session_name"] = $err_session_x;
     $err_preg_x = _pfc("You need %s", "PHP 3 >= 3.0.9 or PHP 4 or PHP 5");
     $f_list["preg_match"] = $err_preg_x;
     $f_list["preg_replace"] = $err_preg_x;
     $f_list["preg_split"] = $err_preg_x;
     $err_ob_x = _pfc("You need %s", "PHP 4 or PHP 5");
     $f_list["ob_start"] = $err_ob_x;
     $f_list["ob_get_contents"] = $err_ob_x;
     $f_list["ob_end_clean"] = $err_ob_x;
     $f_list["get_object_vars"] = _pfc("You need %s", "PHP 4 or PHP 5");
     $this->errors = array_merge($this->errors, check_functions_exist($f_list));
     //    $this->errors = array_merge($this->errors, @test_writable_dir($this->data_public_path, "data_public_path"));
     $this->errors = array_merge($this->errors, @test_writable_dir($this->data_private_path, "data_private_path"));
     $this->errors = array_merge($this->errors, @test_writable_dir($this->data_private_path . "/cache", "data_private_path/cache"));
     // install the public directory content
     $dir = dirname(__FILE__) . "/../data/public/js";
     $dh = opendir($dir);
     while (false !== ($file = readdir($dh))) {
         $f_src = $dir . '/' . $file;
         $f_dst = $this->data_public_path . '/js/' . $file;
         if ($file == "." || $file == ".." || !is_file($f_src)) {
             continue;
         }
         // skip . and .. generic files
         // install js files only if the destination doesn't exists or if the destination timestamp is older than the source timestamp
         if (!file_exists($f_dst) || filemtime($f_dst) < filemtime($f_src)) {
             mkdir_r($this->data_public_path . '/js/');
             copy($f_src, $f_dst);
         }
         if (!file_exists($f_dst)) {
             $this->errors[] = _pfc("%s doesn't exist, data_public_path cannot be installed", $f_dst);
         }
     }
     closedir($dh);
     // ---
     // test client script
     // try to find the path into server configuration
     if ($this->client_script_path == '') {
         $this->client_script_path = pfc_GetScriptFilename();
     }
     if ($this->server_script_url == '' && $this->server_script_path == '') {
         $filetotest = $this->client_script_path;
         // do not take into account the url parameters
         if (preg_match("/(.*)\\?(.*)/", $filetotest, $res)) {
             $filetotest = $res[1];
         }
         if (!file_exists($filetotest)) {
             $this->errors[] = _pfc("%s doesn't exist", $filetotest);
         }
         $this->server_script_url = './' . basename($filetotest) . $this->_query_string;
     }
     // calculate datapublic url
     if ($this->data_public_url == "") {
         $this->data_public_url = pfc_RelativePath($this->client_script_path, $this->data_public_path);
     }
     if ($this->server_script_path == '') {
         $this->server_script_path = $this->client_script_path;
     }
     // ---
     // test server script
     if ($this->server_script_url == '') {
         $filetotest = $this->server_script_path;
         // do not take into account the url parameters
         if (preg_match("/(.*)\\?(.*)/", $this->server_script_path, $res)) {
             $filetotest = $res[1];
         }
         if (!file_exists($filetotest)) {
             $this->errors[] = _pfc("%s doesn't exist", $filetotest);
         }
         $this->server_script_url = pfc_RelativePath($this->client_script_path, $this->server_script_path) . '/' . basename($filetotest) . $this->_query_string;
     }
     // check if the theme_path parameter are correctly setup
     if ($this->theme_default_path == '' || !is_dir($this->theme_default_path)) {
         $this->theme_default_path = dirname(__FILE__) . '/../themes';
     }
     if ($this->theme_path == '' || !is_dir($this->theme_path)) {
         $this->theme_path = $this->theme_default_path;
     }
     // If the user didn't give any theme_default_url value,
     // copy the default theme resources in a public directory
     if ($this->theme_default_url == '') {
         mkdir_r($this->data_public_path . '/themes/default');
         if (!is_dir($this->data_public_path . '/themes/default')) {
             $this->errors[] = _pfc("cannot create %s", $this->data_public_path . '/themes/default');
         } else {
             $ret = copy_r(dirname(__FILE__) . '/../themes/default', $this->data_public_path . '/themes/default');
             if (!$ret) {
                 $this->errors[] = _pfc("cannot copy %s in %s", dirname(__FILE__) . '/../themes/default', $this->data_public_path . '/themes/default');
             }
         }
         $this->theme_default_url = $this->data_public_url . '/themes';
     }
     if ($this->theme_url == '') {
         mkdir_r($this->data_public_path . '/themes/' . $this->theme);
         if (!is_dir($this->data_public_path . '/themes/' . $this->theme)) {
             $this->errors[] = _pfc("cannot create %s", $this->data_public_path . '/themes/' . $this->theme);
         } else {
             $ret = copy_r($this->theme_path . '/' . $this->theme, $this->data_public_path . '/themes/' . $this->theme);
             if (!$ret) {
                 $this->errors[] = _pfc("cannot copy %s in %s", $this->theme_path . '/' . $this->theme, $this->data_public_path . '/themes/' . $this->theme);
             }
         }
         $this->theme_url = $this->theme_default_url;
     }
     // if the user do not have an existing prototype.js library, we use the embeded one
     if ($this->prototypejs_url == '') {
         $this->prototypejs_url = $this->data_public_url . '/js/prototype.js';
     }
     // ---
     // run specific container initialisation
     $ct =& pfcContainer::Instance();
     $ct_errors = $ct->init($this);
     $this->errors = array_merge($this->errors, $ct_errors);
     // check the language is known
     $lg_list = pfcI18N::GetAcceptedLanguage();
     if ($this->language != "" && !in_array($this->language, $lg_list)) {
         $this->errors[] = _pfc("'%s' parameter is not valid. Available values are : '%s'", "language", implode(", ", $lg_list));
     }
     // calculate the proxies chaine
     $this->proxies = array();
     foreach ($this->pre_proxies as $px) {
         if (!in_array($px, $this->skip_proxies) && !in_array($px, $this->proxies)) {
             $this->proxies[] = $px;
         }
     }
     foreach ($this->_sys_proxies as $px) {
         if (!in_array($px, $this->skip_proxies) && !in_array($px, $this->proxies)) {
             $this->proxies[] = $px;
         }
     }
     foreach ($this->post_proxies as $px) {
         if (!in_array($px, $this->skip_proxies) && !in_array($px, $this->proxies)) {
             $this->proxies[] = $px;
         }
     }
     // save the proxies path
     $this->proxies_path_default = dirname(__FILE__) . '/proxies';
     // check the customized proxies path
     if ($this->proxies_path != '' && !is_dir($this->proxies_path)) {
         $this->errors[] = _pfc("'%s' directory doesn't exist", $this->proxies_path);
     }
     if ($this->proxies_path == '') {
         $this->proxies_path = $this->proxies_path_default;
     }
     // save the commands path
     $this->cmd_path_default = dirname(__FILE__) . '/commands';
     if ($this->cmd_path == '') {
         $this->cmd_path = $this->cmd_path_default;
     }
     // load smileys from file
     $this->loadSmileyTheme();
     // load version number from file
     $this->version = trim(file_get_contents(dirname(__FILE__) . "/../version.txt"));
     $this->is_init = count($this->errors) == 0;
 }