/** * Produces a .dot file for the given modules as a string * @param array $modules of string the modules */ public function dot($modules) { $mod_factory = I2CE_ModuleFactory::instance(); $nodes = array(); $paths = array(); $scheme_details = $this->getSchemeDetails('dot'); $config = I2CE::getConfig(); if (array_key_exists('colors', $scheme_details) && is_array($scheme_details['colors'])) { $mod_groups = $scheme_details['colors']; } else { $mod_groups = array(); } $node_groups = array(); $config = I2Ce::getConfig(); $mod_config = $config->config->data; foreach ($modules as $module) { if (!$mod_config->is_parent($module)) { continue; } $color = 'ivory3'; foreach ($mod_groups as $m_module => $m_color) { if (strpos($module, $m_module) !== false) { $color = $m_color; break; } } $className = $mod_factory->getClassName($module); if ($className) { $className = ' (' . $className . ')'; } $mod_data = array(); foreach (array('displayName') as $key) { if (!$mod_config->is_scalar("{$module}/{$key}")) { continue; } $mod_data[] = $mod_config->{$module}->{$key}; } foreach ($mod_data as &$d) { $d = '<tr><td ALIGN=\'LEFT\'>' . $d . '</td></tr>'; } $label = '<table border=\'0\' cellborder=\'0\'><tr><td BGCOLOR=\'white\' BORDER=\'1\'>' . $module . $className . '</td></tr>' . implode('', $mod_data) . '</table>'; if (!array_key_exists($color, $node_groups) || !is_array($node_groups[$color])) { $node_groups[$color] = array(); } $node_groups[$color][$module] = "\"{$module}\" [style=filled fillcolor = {$color} label =<{$label}> shape = \"Mrecord\" ];"; if ($mod_config->is_parent("{$module}/requirement")) { $requirements = array_intersect($modules, $mod_config->getKeys("{$module}/requirement")); } else { $requirements = array(); } if ($mod_config->is_parent("{$module}/conflict")) { $conflicts = array_intersect($modules, $mod_config->getKeys("{$module}/conflict")); } else { $conflicts = array(); } if ($mod_config->is_parent("{$module}/enable")) { $enabled = array_intersect($modules, $mod_config->getKeys("{$module}/enable")); } else { $enabled = array(); } foreach ($requirements as $req) { $paths[] = "\"{$module}\" -> \"{$req}\";"; } foreach ($enabled as $end) { $paths[] = "\"{$module}\" -> \"{$end}\" [color=forestgreen];"; } foreach ($conflicts as $con) { $paths[] = "\"{$module}\" -> \"{$con}\" [color=yellow];"; } } $config = I2CE::getConfig(); $module = $config->config->site->module; if (!$module) { I2CE::raiseError("No site module"); return $graph; } if (array_key_exists('graph_options', $scheme_details) && is_array($scheme_details['graph_options'])) { $graph_options = $scheme_details['graph_options']; } else { $graph_options = array(); } if (!array_key_exists('label', $graph_options) || !$graph_options['label'] || $graph_options['label'] == "''" || $graph_options['label'] == '""') { $title = 'Module Documentor'; $version = ''; $u_version = ''; if ($config->setIfIsSet($title, "/config/data/{$module}/displayName")) { $title = str_ireplace('Demonstration', '', $title); $title = str_ireplace('Demo', '', $title); $title = trim($title); if ($config->setIfIsSet($version, "/config/data/{$module}/version")) { $title .= ' - ' . $version; $u_version = '_' . strtr($version, '.', '_'); } } $graph_options['label'] = '"' . $title . '"'; } $bgcolor = 'white'; if (array_key_exists('bgcolor', $graph_options)) { $bgcolor = $graph_options['bgcolor']; } $graph_details = "graph ["; foreach ($graph_options as $key => $val) { $graph_details .= "\n\t\t" . $key . '=' . $val; } $graph_details .= "\n\t];\n\tratio = auto;\n"; foreach ($node_groups as $colors => $ns) { foreach ($ns as $n) { $nodes[] = $n; } } $graph = "digraph g {\n\t{$graph_details}\n\t" . implode("\n\t", $nodes) . implode("\n\t", $paths) . "\n}\n"; $dot = trim(`which dot`); $unflatten = trim(`which unflatten`); if (!$dot || !$unflatten) { I2CE::raiseError("the dot utility was not found on your system. cannot create the imate. try sudo apt-get install dot"); return $graph; } $output_file = '/tmp/modules_' . $module . $u_version . '.gif'; $dot = "{$unflatten} -f -l 2 -c 2 | {$dot} -T gif "; $composite = trim(`which composite`); $composite = false; if ($composite) { $watermark_file = I2CE::getFileSearch()->search('IMAGES', 'module_documentor_legend.gif'); $watermark = ''; if ($watermark_file) { $bgcolor_change = ''; if (strtolower($bgcolor) != 'white') { $bgcolor_change = "-fuzz 5% -fill {$bgcolor} -opaque white"; } $watermark = " |{$composite} gif:- -gravity SouthEast {$bgcolor_change} {$watermark_file} "; } $exec = $dot . $watermark . $output_file; } else { I2CE::raiseError("Imagemagick utitilies were not found on your system. cannot watermark the file. try sudo apt-get isntall imagemagick"); $exec = $dot . '-o ' . $output_file; } I2CE::raiseError("Attempting to execute:\n\t" . $exec); $proc = popen($exec, "w"); if (!is_resource($proc)) { I2CE::raiseError("Could not start execute"); } else { fwrite($proc, $graph); fclose($proc); } return $graph; }
protected function actionRolesSave() { if (count($this->request_remainder) == 0) { //adding new role if (!$this->post_exists('role_short_name')) { $this->userMessage("No role short name set", 'notice', false); return; } $role = $this->post('role_short_name'); if (array_key_exists($role, self::$fixed_roles)) { $this->userMessage("Invalid Role {$role} short name specified", 'notice', false); return; } if (!$role || !I2CE_MagicDataNode::checkKey($role) || I2CE::getConfig()->is_parent("/I2CE/formsData/forms/role/{$role}")) { $this->userMessage("Bad role short name {$role}", 'notice', false); return; } if (!$this->post_exists('role_name') || !$this->post('role_name')) { $this->userMessage("No role display name set", 'notice', false); return; } //we are good to go. I2CE::getConfig()->I2CE->formsData->forms->role->{$role}->fields->name = $this->post('role_name'); I2CE::getConfig()->I2CE->formsData->forms->role->{$role}->last_modified = I2CE_Date::now(I2CE_Date::DATE_TIME)->dbFormat(); } else { if (count($this->request_remainder) == 1) { $role = $this->request_remainder[0]; if (!$role || array_key_exists($role, self::$fixed_roles)) { $this->userMessage("Invalid Role {$role} specified", 'notice', false); return; } $roleBaseConfig = I2CE::getConfig()->traverse("/I2CE/formsData/forms/role/", false); if (!$roleBaseConfig instanceof I2CE_MagicDataNode) { $this->userMessage("System Error", 'notice', false); return; } $roleConfig = $roleBaseConfig->traverse("{$role}/fields", false); if (!$roleConfig instanceof I2CE_MagicDataNode) { $this->userMessage("Invalid Role {$role} specified", 'notice', false); return; } $post = $this->post(); if (!array_key_exists('role_name', $post) || !$post['role_name']) { $this->userMessage("No role display name set", 'notice', false); return; } if ($roleConfig->is_translatable("name")) { $locale = I2CE_Locales::getPreferredLocale(); $roleConfig->setTranslation($locale, $post['role_name'], "name"); if ($locale == I2CE_Locales::DEFAULT_LOCALE) { $roleConfig->name = $post['role_name']; } } else { $roleConfig->name = $post['role_name']; } $roleBaseConfig->{$role}->last_modified = I2CE_Date::now(I2CE_Date::DATE_TIME)->dbFormat(); if (array_key_exists('homepage', $post) && !is_array($post['homepage'])) { $roleConfig->homepage = $post['homepage']; } if (array_key_exists('role_roles', $post) && is_array($post['role_roles'])) { //make sure the roles are valid. $roles = $post['role_roles']; foreach ($roles as $i => $r) { if (!$roleBaseConfig->is_parent("{$r}") || array_key_exists($r, self::$fixed_roles)) { unset($roles[$i]); } } $roles[] = 'admin'; //make sure that admin inherits this role. $trickleConfig = $roleConfig->traverse("trickle_up", true, false); $trickleConfig->erase(); $roleConfig->traverse('trickle_up', true, false); //recreate what we just erased $roleConfig->trickle_up = implode(',', $roles); } if (array_key_exists('role_tasks', $post) && is_array($post['role_tasks'])) { $taskConfig = I2Ce::getConfig()->I2CE->tasks->role_trickle_down; if (isset($taskConfig, $role)) { $taskConfig->{$role}->erase(); $taskConfig->traverse($role, true, false); } $taskConfig->{$role} = $post['role_tasks']; } } } $this->setRedirect('tasks-roles/roles'); }
/** * Migrate a given form from one storage method to the current storage method. * This should only be used when upgrading a module that moved a form storage * from one type to another. * @param string $form_name * @param string $storage The old storage mechanism * @param I2CE_User $user The user object to use to save the new forms. * @param string $migrate_path The full path in MagicData to save the old to new mappings. * @param string $id_field The old field name to use the value of for the new form id. * @param array $skip_fields A list of fields to not migrate to the new form. * @param array $migrate_fields A list of fields that have already been migrated and need to use * the migrate path to convert the data. Format is array( "field" => "map_form" ) * These forms and fields should have already been passed to {@link storeMigrateData} * so the data can be retrieved from there. * @return boolean */ public static function migrateForm($form_name, $storage, $user, $migrate_path = false, $id_field = false, $skip_fields = array(), $migrate_fields = array(), $callback = null) { I2CE::longExecution(); // Make sure that when the new form saves it uses the correct storage type if it was already // cached by a pre upgrade. self::getStorage($form_name, true); $factory = I2CE_FormFactory::instance(); $factory->clearFieldData($form_name); $old_storage = self::getMechanismByStorage($storage); if (!$old_storage instanceof I2CE_FormStorage_Mechanism) { I2CE::raiseError("No storage mechanism found for {$storage}"); return false; } I2CE::raiseError("Migrate form {$form_name} from {$storage} to " . self::getStorage($form_name)); $migrate_data = null; if ($migrate_path) { $migrate_data = I2CE::getConfig()->traverse($migrate_path, true, false); } else { if (count($migrate_fields) > 0) { I2CE::raiseError("Migrate fields have been passed to migrateForm without a migrate_data path in magic data."); return false; } } $use_fields = array(); $obj = $factory->createContainer($form_name, true); if (!$obj instanceof I2CE_Form) { I2Ce::raiseError("Could not instantiate form {$form_name}"); return false; } foreach ($obj as $field => $fieldObj) { if (in_array($field, $skip_fields) || array_key_exists($field, $migrate_fields)) { continue; } $use_fields[] = $field; } $obj->cleanup(); unset($obj); if (count($migrate_fields) > 0 && !$migrate_data->__isset("fields/{$form_name}")) { I2CE::raiseError("No old migrate data set for {$form_name}\n"); } $old_data = $old_storage->listFields($form_name, $use_fields, true); foreach ($old_data as $old_id => $fields) { if ($migrate_data instanceof I2CE_MagicDataNode) { if ($migrate_data->__isset("forms/{$form_name}/{$old_id}")) { I2CE::raiseError("Already migrated {$form_name} {$old_id}. Did something fail earlier? Skipping it."); continue; } } $obj = $factory->createContainer($form_name, true); foreach ($skip_fields as $skip_field) { $obj->removeField($skip_field); } if ($id_field && array_key_exists($id_field, $fields)) { if ($callback === null) { $new_id = $fields[$id_field]; } elseif ($callback === true) { $new_id = strtolower(str_replace(' ', '_', $fields[$id_field])); } else { $new_id = call_user_func($callback, $fields[$id_field]); } $obj->setId($new_id); } foreach ($fields as $key => $value) { if (!isset($value)) { continue; } if ($key == "parent") { $obj->setParent($value); if ($migrate_data instanceof I2CE_MagicDataNode) { $parent_form = $obj->getParentForm(); $parent_id = $obj->getParentID(); $new_parent = $migrate_data->forms->{$parent_form}->{$parent_id}; $obj->setParent($new_parent); //I2CE::raiseError( "Setting parent for $form_name $old_id to $new_parent (was $value)." ); } else { //I2CE::raiseError( "Setting parent for $form_name $old_id to $value." ); } continue; } $fieldObj = $obj->getField($key); if (!$fieldObj instanceof I2CE_FormField) { continue; } $fieldObj->setFromDB($value); } foreach ($migrate_fields as $field => $map_form) { $new_value = self::getMigratedValue($migrate_data, $form_name, $old_id, $field, $map_form); if (is_array($new_value) && array_key_exists('new_value', $new_value) && $new_value['new_value']) { $fieldObj = $obj->getField($field); if (!$fieldObj instanceof I2CE_FormField) { continue; } $fieldObj->setFromDB($new_value['new_value']); } } if ($obj->save($user)) { if ($migrate_data instanceof I2CE_MagicDataNode) { $migrate_data->forms->{$form_name}->{$old_id} = $form_name . "|" . $obj->getId(); } else { I2CE::raiseError("Moved over {$form_name}: {$old_id} to " . $obj->getId()); } } else { return false; } $obj->cleanup(); unset($obj); } if ($migrate_data instanceof I2CE_MagicDataNode) { $child_forms = I2CE_Form::getChildFormsByForm($form_name); foreach ($child_forms as $child_form) { $children = $factory->getRecords($child_form); $bad_ids = array(); foreach ($children as $child_id) { $child_obj = $factory->createContainer($child_form . '|' . $child_id, true); if (!$child_obj instanceof I2CE_Form) { $bad_ids[] = $child_id; continue; } $child_obj->populate(); $old_id = $child_obj->getParentID(); $new_id = $migrate_data->forms->{$form_name}->{$old_id}; $child_obj->setParent($new_id); if ($child_obj->save($user)) { } $child_obj->cleanup(); unset($child_obj); } if (count($bad_ids) > 0) { I2CE::raiseError("Bad Child ids " . implode(',', $bad_ids) . " for child form {$child_form} of form {$form_name}"); } I2CE::raiseError("Migrated parent for {$child_form} to {$form_name}."); } } $migrate_data->unpopulate(true, true); return true; }
/** * Create and load data for the objects used for this form. * * Create the index object and if this is a form submission the load * the data from the $_POST array. */ protected function loadObjects() { $resend = $this->request_exists('resend') && $this->request('resend'); $factory = I2CE_FormFactory::instance(); if ($resend) { if (!($this->requested_user = $factory->createContainer('user_request')) instanceof I2CE_User_Form) { I2Ce::raiseError("Bad load of user_request "); $this->requested_user = false; return false; } if ($this->isPost()) { $this->requested_user->load($this->post, false, false); $msg = "The requested email address \"%1\$s\" is invalid"; I2CE::getConfig()->setIfIsSet($msg, "/modules/RequestAccount-VerifyEmail/user_messages/invalid_email"); $email = $this->requested_user->email; $msg = sprintf($msg, $email); if (!$email) { $this->userMessage($msg); $this->setRedirect($this->pageRoot()); return false; } //see if we can find a user request for this account $where = array('field' => 'email', 'operator' => 'FIELD_LIMIT', 'style' => 'equals', 'data' => array('value' => $email)); $requested_users = I2CE_FormStorage::search('user_request', false, $where); if (count($requested_users) != 1) { $this->userMessage($msg); $this->setRedirect($this->pageRoot()); return false; } $this->requested_user->cleanup(); $this->requested_user = false; $req_id = current($requested_users); if (!($this->requested_user = $factory->createContainer('user_request|' . $req_id)) instanceof I2CE_Form) { $this->userMessage($msg); $this->setRedirect($this->pageRoot()); return false; } $this->requested_user->populate(); } } else { if (!($this->requested_user = $factory->createContainer('user_request')) instanceof I2CE_User_Form || !($usernameField = $this->requested_user->getField('username')) instanceof I2CE_FormField_STRING_LINE || !($emailField = $this->requested_user->getField('email')) instanceof I2CE_FormField_STRING_LINE) { I2Ce::raiseError("Bad load of user_request "); $this->requested_user = false; return false; } if ($this->isPost()) { $post = I2CE_Module_UserRequest::manipulatePostForm($this->post, 'user', 'user_request'); $this->requested_user->load($post, true, false); $req_num = uniqid(); $this->requested_user->getField('request_number')->setValue($req_num); $username = $usernameField->getValue(); $email = $emailField->getValue(); $details = array('email' => $email); if (!I2CE_Module_UserRequest::canAddUser($this->requested_user, false, true)) { $this->requested_user = false; $msg = "The requested username \"%1\$s\" or email address \"%2\$s\" is invalid or already in use"; I2CE::getConfig()->setIfIsSet($msg, "/modules/RequestAccount-VerifyEmail/user_messages/invalid_username"); $msg = sprintf($msg, $username, $email); $this->userMessage($msg); $this->setRedirect($this->pageRoot()); } } } if ($this->requested_user) { $this->setObject($this->requested_user); } return true; }
/** * Create a check function boolean expression based on the where data. * The function takes on argument which is an array indexed by the field names and with values the value of the field. * @param I2CE_Form $form * @param mixed $expr array or class implementing ArrayAccess, Iterator, and Countable (e.g. MagicDataNode) . the where data. * @param callback $field_refernece_callback. A callback function whose first arguement is the form, the second arguements * is the field and which returns the way the field value should be references as a field. If the callback is null (the default) then * the reference used is $data["$field'] * @returns false on failure a string to which can be evalued as true/false on success. */ public function createCheckFunctionString($formObj, $expr, $field_reference_callback = null) { I2Ce::raiseError("Creaging Check Function string on " . $formObj->getName() . " from:\n" . print_r($expr, true)); if (!(is_array($expr) || $expr instanceof ArrayAccess && $expr instanceof Countable && $expr instanceof Iterator)) { I2CE::raiseError("array was not found while processing the where clause \n"); return false; } if (!isset($expr['operator']) || !is_string($expr['operator'])) { I2CE::raiseError("No operator set"); return false; } switch ($expr['operator']) { case 'FIELD_LIMIT': $subExpr = $this->createCheckLimitString($formObj, $expr, $field_reference_callback); if ($subExpr === false || !is_string($subExpr)) { I2CE::raiseError("Could not generate check function for " . print_R($expr, true)); return false; } $subExpr = trim($subExpr); if (strlen($subExpr) > 0) { $subExpr = ' ( ' . $subExpr . ')'; } return $subExpr; case 'AND': //we are allowing these to be n-ary operators //we are allowing these to be n-ary operators case 'OR': case 'XOR': if (!isset($expr['operand'])) { I2CE::raiseError("No operands set"); return false; } if (!(is_array($expr['operand']) || $expr['operand'] instanceof ArrayAccess && $expr['operand'] instanceof Iterator && $expr['operand'] instanceof Countable)) { I2CE::raiseError("Invalid operands set"); return false; } $subExpr = array(); foreach ($expr['operand'] as $sub) { $tmpExpr = $this->createCheckFunctionString($formObj, $sub, $field_reference_callback); if ($tmpExpr == false || !is_string($tmpExpr)) { I2CE::raiseError("GOT BAD subexpression from: " . print_r($sub, true)); return false; } $tmpExpr = trim($tmpExpr); if (strlen($tmpExpr) > 0) { $subExpr[] = $tmpExpr; } } if (count($subExpr) > 0) { return ' ( ' . implode(' ' . self::$checkOperatorMap[$expr['operator']] . ' ', $subExpr) . ' ) '; } else { return ''; } case 'NOT': if (!isset($expr['operand'])) { I2CE::raiseError("No operands set"); return false; } if (!(is_array($expr['operand']) || $expr['operand'] instanceof ArrayAccess && $expr['operand'] instanceof Iterator && $expr['operand'] instanceof Countable)) { I2CE::raiseError("Invalid operands set"); return false; } if (count($expr['operand']) != 1) { I2CE::raiseError("Expecing one operand but did not receive"); return false; } reset($expr['operand']); $subExpr = $this->createCheckFunctionString($formObj, current($expr['operand']), $field_reference_callback); if ($subExpr === false || !is_string($subExpr)) { I2CE::raiseError("got bad subexpression from :" . print_r(current($expr['operand']), true)); return false; } $subExpr = trim($subExpr); if (strlen($subExpr) > 0) { $subExpr = ' (!( ' . $subExpr . ' )) '; } return $subExpr; default: I2CE::raiseError("Unrecognzied operator " . $expr['operator'] . "\n"); return false; } }
/** * Raise an error and redirect the user for any critical errors. * * The default redirect will go to the home page for the site. * @param string/mixed $message The error message. * @param integer $type The error type. * @param string $redirect The page to redirect to for critical errors. * @global array */ public static function raiseError($message = null, $type = E_USER_NOTICE, $redirect = "") { if ($message === null) { if (!is_null($e = error_get_last())) { if (substr($e['message'], 0, 19) == "Allowed memory size") { // Memory limit has been reached so display // something if we still can. print_r($e); } foreach (self::$ignoreErrors as $part) { if (strpos($e['message'], $part) !== false) { return; } } foreach (self::$ignoreErrorsFromFilesMatching as $part) { if (strpos($e['file'], $part) !== false) { return; } } $message = "Fatal Error:" . print_r($e, true); } else { return; } if (array_key_exists('HTTP_HOST', $_SERVER)) { $contents = preg_replace('/{{ERRORMESSAGE}}/', htmlentities($message), self::$badness); if (is_array(self::$stored_messages)) { $trace = array(); foreach (self::$stored_messages as $i => $m) { if (!is_array($m) || !array_key_exists('msg', $m) || !$m['msg']) { continue; } $trace[] = $m['trace'] . "\n" . $m['msg'] . "\n"; } $trace = htmlentities(print_r($trace, true)); } else { $trace = ''; } $contents = preg_replace('/{{ERRORTRACE}}/', $trace, $contents); if (is_string(I2CE::$email) && strlen(I2CE::$email) > 0) { $email = I2CE::$email; } else { $email = '*****@*****.**'; } $contents = preg_replace('/{{EMAIL}}/', htmlentities($email), $contents); $contents = preg_replace('/{{REQUESTURI}}/', htmlentities($_SERVER['REQUEST_URI']), $contents); echo $contents; echo self::$errorImage; flush(); } } $num = self::$error_num++; $warning_level = 'Warning'; if (array_key_exists($type, self::$errorType)) { $warning_level = self::$errorType[$type]; } if (self::$trace_depth == 0) { $trace = 'I2CE: '; } else { $debug = debug_backtrace(); $trace = 'I2CE: ' . self::getPrevMethod($debug, 1, self::$trace_depth) . ':'; } if (count(self::$errorHandler) > 0) { call_user_func(self::$errorHandler[0], $trace, $message, $type); } else { if (array_key_exists('HTTP_HOST', $_SERVER)) { error_log($trace . $message . "\nError Type=" . $type, 0); if (in_array($type, self::$noticeErrors)) { $msg_level = '<b style="display:block;">' . $warning_level . '</b>'; } else { self::$site_warnings++; $msg_level = '<b style="display:block;color:red">' . $warning_level . '</b>'; } $js_message = '<script type="text/javascript">addMessage("' . str_replace("\n", '<br/>', addcslashes($msg_level . $message, '"\\')) . '","' . str_replace("\n", '<br/>', addcslashes(rtrim($trace, "\n\t :"), '"\\')) . '");</script>' . "\n"; if (in_array($type, self::$noticeErrors)) { //a notice error if (I2CE::siteInitialized()) { self::$stored_messages[] = array('msg' => $message, 'trace' => $trace, 'level' => $msg_level); } else { if (!self::$started_errors) { echo self::$errorStart; echo self::$errorImage; self::$started_errors = true; } echo $js_message; flush(); } } else { if (!I2Ce::siteInitialized()) { //we have a non notice error //show any stored messages or warnings to give the user a clue as to what is going on if (!self::$started_errors) { echo self::$errorStart; echo self::$errorImage; self::$started_errors = true; } if (is_array(self::$stored_messages)) { foreach (self::$stored_messages as $m) { if (!is_array($m) || !array_key_exists('msg', $m) || !$m['msg']) { continue; } $js_m = '<script type="text/javascript">addMessage("' . str_replace("\n", '<br/>', addcslashes($m['level'] . $m['msg'], '"\\')) . '","' . str_replace("\n", '<br/>', addcslashes(rtrim($m['trace'], "\n\t :"), '"\\')) . '");</script>' . "\n"; echo $js_m; flush(); } } self::$stored_messages = array(); if (!($redirect === null || is_string($redirect) && strlen($redirect) == 0)) { header("Location: " . $redirect); exit; } if (!in_array($type, self::$warningErrors)) { //this is an actual erros so exit exit; } } } } else { // we are on the command line //$blue = "\033[34m"; //$green = "\033[32m"; //$black = "\033[0m"; //$red = "\033[31m"; $message = str_replace(array("\n"), array("\n\t"), $message); $trace = "[34m" . $trace . "[0m\n"; if (in_array($type, self::$warningErrors)) { fwrite(STDERR, $trace . "\t[31m\t" . $message . "[0m\n"); fflush(STDERR); exit(102); } else { if (!in_array($type, self::$noticeErrors)) { fwrite(STDERR, $trace . "\t[32m\t" . $message . "[0m\n"); fflush(STDERR); exit(101); } else { fwrite(STDERR, $trace . "\t[32m" . $message . "[0m\n"); fflush(STDERR); } } } } }