Ejemplo n.º 1
0
 /**
  * PHP error handler
  *
  * @return true
  * @access public
  */
 static function PHPErrorHandler($errno, $errstr, $errfile, $errline, $errcontext)
 {
     //if errno is not in the error_reporting scope, skip it
     //read it like this : "if errno bit is not in error_reporting"
     if ($errno & ~error_reporting()) {
         return true;
     }
     //define errors type table
     $errortype = array(E_ERROR => 'Error', E_WARNING => 'Warning', E_PARSE => 'Parse error', E_NOTICE => 'Notice', E_CORE_ERROR => 'Core Error', E_CORE_WARNING => 'Core Warning', E_COMPILE_ERROR => 'Compile Error', E_COMPILE_WARNING => 'Compile Warning', E_STRICT => 'Runtime Notice', E_RECOVERABLE_ERROR => 'Catchable Fatal Error', 8192 => 'Deprecated', 16384 => 'User deprecated');
     $errorLabel = isset($errortype[$errno]) ? $errortype[$errno] : 'Error ' . $errno;
     CMS_grandFather::_raiseError('PHP ' . $errorLabel . ' : ' . $errstr . ' line ' . $errline . ' of file ' . $errfile);
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Returns all the profile users, sorted by last name + first name.
  * Static function.
  *
  * @param boolean activeOnly : return only active users (default : false)
  * @param boolean withDeleted : return deleted users also (default false)
  * @param boolean returnObjects : return CMS_profile_user objects (default) or array of userId
  * @param array attrs : filter for search : array($attrName => $attrValue)
  * @return array(CMS_profile_user)
  * @access public
  */
 static function getAll($activeOnly = false, $withDeleted = false, $returnObjects = true, $attrs = array())
 {
     $attrWhere = '';
     $from = '';
     if ($attrs and is_array($attrs)) {
         $availableAttrs = array('id_pru', 'login_pru', 'firstName_pru', 'lastName_pru', 'contactData_pru', 'profile_pru', 'language_pru', 'textEditor_pru', 'email_cd');
         foreach ($attrs as $attrName => $attrValue) {
             // Check $attrName is available
             if (in_array($attrName, $availableAttrs)) {
                 $and = $attrWhere || !$attrWhere && (!$withDeleted || $activeOnly) ? " and " : "";
                 // Sanitize value and set operator
                 if (!is_array($attrValue)) {
                     if ($attrName == 'email_cd') {
                         // Special case : parameter is contactData email
                         $attrValue = sensitiveIO::sanitizeSQLString($attrValue);
                         if (SensitiveIO::isValidEmail($attrValue)) {
                             $attrWhere .= $and . " " . $attrName . " = '" . $attrValue . "' and contactData_pru=id_cd";
                             $from .= ',contactDatas';
                         }
                     } else {
                         $attrValue = sensitiveIO::sanitizeSQLString($attrValue);
                         $attrWhere .= $and . " " . $attrName . " = '" . $attrValue . "'";
                     }
                 } elseif (is_array($attrValue)) {
                     $attrValue = array_map(array('sensitiveIO', 'sanitizeSQLString'), $attrValue);
                     foreach ($attrValue as $key => $value) {
                         $attrValue[$key] = "'" . $value . "'";
                     }
                     $attrWhere .= $and . " " . $attrName . " in (" . implode(',', $attrValue) . ")";
                 }
             } else {
                 CMS_grandFather::_raiseError(__CLASS__ . ' : ' . __FUNCTION__ . ' : attrName must be in availableAttrs array');
             }
         }
     }
     $sql = "\n\t\t\tselect\n\t\t\t\tid_pru\n\t\t\tfrom\n\t\t\t\tprofilesUsers \n\t\t\t\t" . $from . "\n\t\t\t" . (!$withDeleted || $activeOnly || $attrWhere ? " where " : '') . "\n\t\t\t" . (!$withDeleted ? " deleted_pru='0'" : '') . "\n\t\t\t" . (!$withDeleted && $activeOnly ? " and " : '') . "\n\t\t\t" . ($activeOnly ? " active_pru='1' " : '') . "\n\t\t\t" . $attrWhere . "\n\t\t\torder by\n\t\t\t\tlastName_pru,\n\t\t\t\tfirstName_pru\n\t\t";
     $q = new CMS_query($sql);
     $users = array();
     while ($id = $q->getValue("id_pru")) {
         if ($returnObjects) {
             $usr = CMS_profile_usersCatalog::getByID($id);
             if (is_object($usr)) {
                 if ($activeOnly && $usr->isActive() || !$activeOnly) {
                     $users[] = $usr;
                 }
             }
         } else {
             $users[] = $id;
         }
     }
     return $users;
 }
Ejemplo n.º 3
0
 /**
  * Start the scripts process queue.
  * Remove the lock file then relaunch the script if force is true
  *
  * @param boolean $force Set to true if you wish to remove the lock file before launch
  * @return void
  * @access public
  * @static
  */
 static function startScript($force = false)
 {
     if (USE_BACKGROUND_REGENERATOR) {
         $forceRestart = '';
         if ($force) {
             $forceRestart = ' -F';
         } elseif (processManager::hasRunningScript()) {
             return false;
         }
         //test if we're on windows or linux, for the output redirection
         if (APPLICATION_IS_WINDOWS) {
             if (realpath(PATH_PHP_CLI_WINDOWS) === false) {
                 CMS_grandFather::raiseError("Unknown CLI location : " . PATH_PHP_CLI_WINDOWS . ", please check your configuration.");
                 return false;
             }
             // Create the BAT file
             $command = '@echo off' . "\r\n" . 'start /B /LOW ' . realpath(PATH_PHP_CLI_WINDOWS) . ' ' . realpath(PATH_PACKAGES_FS . '\\scripts\\script.php') . ' -m ' . REGENERATION_THREADS . $forceRestart;
             $replace = array('program files (x86)' => 'progra~2', 'program files' => 'progra~1', 'documents and settings' => 'docume~1');
             $command = str_ireplace(array_keys($replace), $replace, $command);
             if (!@touch(PATH_WINDOWS_BIN_FS . "/script.bat")) {
                 CMS_grandFather::_raiseError("CMS_scriptsManager : startScript : Create file error : " . PATH_WINDOWS_BIN_FS . "/script.bat");
                 return false;
             }
             $fh = @fopen(PATH_WINDOWS_BIN_FS . "/script.bat", "wb");
             if (is_resource($fh)) {
                 if (!@fwrite($fh, $command, io::strlen($command))) {
                     CMS_grandFather::raiseError("Save file error : script.bat");
                 }
                 @fclose($fh);
             }
             $WshShell = new COM("WScript.Shell");
             $oExec = $WshShell->Run(str_ireplace(array_keys($replace), $replace, realpath(PATH_WINDOWS_BIN_FS . '\\script.bat')), 0, false);
         } else {
             $error = '';
             if (!defined('PATH_PHP_CLI_UNIX') || !PATH_PHP_CLI_UNIX) {
                 $return = CMS_patch::executeCommand('which php 2>&1', $error);
                 if ($error) {
                     CMS_grandFather::raiseError('Error when finding php CLI with command "which php", please check your configuration : ' . $error);
                     return false;
                 }
                 if (io::substr($return, 0, 1) != '/') {
                     CMS_grandFather::raiseError('Can\'t find php CLI with command "which php", please check your configuration.');
                     return false;
                 }
                 $return = CMS_patch::executeCommand("cd " . PATH_REALROOT_FS . "; php " . PATH_PACKAGES_FS . "/scripts/script.php -m " . REGENERATION_THREADS . $forceRestart . " > /dev/null 2>&1 &", $error);
                 if ($error) {
                     CMS_grandFather::raiseError('Error during execution of script command (cd ' . PATH_REALROOT_FS . '; php ' . PATH_PACKAGES_FS . '/scripts/script.php -m ' . REGENERATION_THREADS . $forceRestart . '), please check your configuration : ' . $error);
                     return false;
                 }
             } else {
                 $return = CMS_patch::executeCommand(PATH_PHP_CLI_UNIX . ' -v 2>&1', $error);
                 if ($error) {
                     CMS_grandFather::raiseError('Error when testing php CLI with command "' . PATH_PHP_CLI_UNIX . ' -v", please check your configuration : ' . $error);
                     return false;
                 }
                 if (io::strpos(io::strtolower($return), '(cli)') === false) {
                     CMS_grandFather::raiseError(PATH_PHP_CLI_UNIX . ' is not the CLI version');
                     return false;
                 }
                 $return = CMS_patch::executeCommand("cd " . PATH_REALROOT_FS . "; " . PATH_PHP_CLI_UNIX . " " . PATH_PACKAGES_FS . "/scripts/script.php -m " . REGENERATION_THREADS . $forceRestart . " > /dev/null 2>&1 &", $error);
                 if ($error) {
                     CMS_grandFather::raiseError('Error during execution of script command (cd ' . PATH_REALROOT_FS . '; ' . PATH_PHP_CLI_UNIX . ' ' . PATH_PACKAGES_FS . '/scripts/script.php -m ' . REGENERATION_THREADS . $forceRestart . '), please check your configuration : ' . $error);
                     return false;
                 }
             }
             //CMS_grandFather::log($return);
             //CMS_grandFather::log("cd ".PATH_REALROOT_FS."; php ".PATH_PACKAGES_FS."/scripts/script.php -m ".REGENERATION_THREADS.$forceRestart." > /dev/null 2>&1 &");
             //@system("cd ".PATH_REALROOT_FS."; php ".PATH_PACKAGES_FS."/scripts/script.php -m ".REGENERATION_THREADS.$forceRestart." > /dev/null 2>&1 &");
         }
     } else {
         CMS_session::setSessionVar('start_script', true);
     }
 }
Ejemplo n.º 4
0
 /**
  * Move a page in the tree structure
  * Static function.
  *
  * @param CMS_page $page The page to move
  * @param CMS_page $newFather The new father of the page
  * @param array of CMS_page id $newSiblingOrder The sibling pages to move in the good order
  * @param CMS_profile_user $user The user operating the change.
  * @return string The error string (abbreviated) or false if no error
  * @access public
  */
 static function movePage(&$page, &$newFather, $newSiblingOrder, &$user)
 {
     //check arguments are pages
     if (!is_a($page, "CMS_page") || !is_a($newFather, "CMS_page")) {
         CMS_grandFather::_raiseError("CMS_tree : movePage : ancestor and page must be instances of CMS_page");
         return false;
     }
     //get page current father
     $father = CMS_tree::getAncestor($page, 1);
     //can't move page to the same father (useless...)
     if (is_object($father) && $newFather->getID() == $father->getID()) {
         CMS_grandFather::_raiseError("CMS_tree : movePage : can't move page under the same father (use changePagesOrder instead)");
         return false;
     }
     //check that the page to move ain't the root.
     $root = CMS_tree::getRoot();
     if ($root->getID() == $page->getID()) {
         CMS_grandFather::_raiseError("CMS_tree : movePage : can't move root");
         return false;
     }
     //check that the page to move ain't an ancestor of new father.
     $lineage = CMS_tree::getLineage($page, $newFather);
     if ($lineage) {
         CMS_grandFather::_raiseError("CMS_tree : movePage : can't move a page to a descendant of it");
         return false;
     }
     //detach the page from the edited tree
     CMS_tree::detachPageFromTree($page, false);
     //attach the page to the edited tree under the new father
     CMS_tree::attachPageToTree($page, $newFather, false);
     //set new pages order
     foreach ($newSiblingOrder as $newOrder => $sibling) {
         $newOrder += 1;
         //because array keys start to 0 and sibling number to 1
         //move the siblings order
         $sql = "\n\t\t\t\tupdate\n\t\t\t\t\tlinx_tree_edited\n\t\t\t\tset\n\t\t\t\t\torder_ltr='" . $newOrder . "'\n\t\t\t\twhere\n\t\t\t\t\tsibling_ltr='" . $sibling . "'\n\t\t\t";
         $q = new CMS_query($sql);
     }
     //set the page status editions
     $page->addEdition(RESOURCE_EDITION_MOVE, $user);
     $page->writeToPersistence();
     return true;
 }