public function Mail($addresses, $content, $isHtml = true, $attachment = array()) { $mail = new PHPMailer(); if (isset($content['body']) && $content['body'] != '') { $mail->Body = trim($content['body']); } if (isset($content['altbody']) && $content['altbody'] != '') { $mail->AltBody = $content['altbody']; } else { if ($isHtml) { $mail->IsHTML(true); } $mail->AltBody = ''; } if (isset($content['subject']) && $content['subject'] != '') { $mail->Subject = $content['subject']; } if (isset($content['from']) && $content['from'] != '') { $mail->From = $content['from']; $mail->Sender = $content['from']; } if (isset($content['fromName']) && $content['fromName'] != '') { $mail->FromName = $content['fromName']; } if (!empty($attachment)) { !isset($attachment['path']) && ($attachment['path'] = null); !isset($attachment['name']) && ($attachment['name'] = null); !isset($attachment['encoding']) && ($attachment['encoding'] = 'base64'); !isset($attachment['type']) && ($attachment['type'] = 'application/octet-stream'); $mail->AddAttachment($attachment['path'], $attachment['name'], $attachment['encoding'], $attachment['type']); } $sendFailed = false; if ($addresses) { foreach ($addresses as $address) { $mail->AddAddress($address['email'], $address['name']); } if (!$mail->Send()) { $sendFailed = true; RDD::Log('RDM_Mail: In PHPMailer an error occured: ' . $mail->ErrorInfo, ERROR); } $mail->ClearAddresses(); } else { RDD::Log('RDM_Mail: No mail addresses passed to method Mail()', ERROR); $sendFailed = true; } return !$sendFailed; }
public function Setup() { $this->LoadDataobject2(); $options =& PEAR::getStaticProperty('DB_DataObject2', 'options'); if (!is_array($options)) { $options = array(); } $locations = array(); foreach ($this->getRoots() as $ROOT) { if (is_dir($ROOT . DIR_SEP . 'daos')) { $locations[] = $ROOT . DIR_SEP . 'daos'; } } if (empty($locations)) { RDD::Log('DAO needs a location to work'); return; } $options['db_driver'] = $this->Driver; $options['schema_location'] = $locations; $options['class_location'] = $locations; // TODO // $options['require_prefix'] = $options['class_prefix'] = $this->Prefix; $options['extends'] = $this->Extends; $options['extends_location'] = ''; $options['debug'] = 0; $options['generator_class_rewrite'] = true; $options['quote_identifiers'] = 1; $options['proxy'] = false; RD::RequireClass($this->Extends); return; }
public function __construct($main) { self::$Self = $this; parent::__construct($main); RDD::Log('Loading PEAR', TRACE, 1201); $PEARLibs = $this->Dirs('libs/pear'); foreach ($PEARLibs as $PEARLib) { $this->AddIncludePath($PEARLib); } require_once 'PEAR.php'; }
/** * Creates needed object and loads all needed methods for the object **/ public function CallPage() { if ($this->PagesAllowed === false) { return; } if (!$this->GoToCheck()) { return; } if ($this->PagesAllowed !== true && is_array($this->PagesAllowed)) { $Access = false; foreach ($this->PagesAllowed as $PageAllowed) { $Length = strlen($PageAllowed); if (substr($this->Page, 0, $Length) == $PageAllowed) { $Access = true; break; } } if (!$Access) { throw new Exception('RDM_Page: not allowed to access the Page: "' . $this->Page . '"'); } } $this->Hook('PageStart'); $RunCache = array(); foreach ($this->Pages as $Key => $PagePart) { $FileName = self::$Directory; $ClassName = self::$ClassPrefix; for ($i = 0; $i <= $Key; $i++) { $FileName .= DIR_SEP . $this->Pages[$i]; $ClassName .= '_' . ucfirst($this->Pages[$i]); } if (!isset($this->PageCache[$ClassName])) { try { RD::RequireClass($ClassName); } catch (Exception $e) { $FileName .= '.php'; if ($File = $this->File($FileName)) { require_once $File; } } if (class_exists($ClassName)) { RDD::Log('Page class ' . $ClassName . ' loaded into RunCache', TRACE, 1221); $this->PageCache[$ClassName] = new $ClassName($this->main); } else { RDD::Log('Page class ' . $ClassName . ' or file ' . $FileName . ' not exist', WARN); continue; } } $RunCache[$ClassName] = $this->PageCache[$ClassName]; } if (!empty($RunCache)) { $MethodStack = array(self::$PageStart); $PageDepth = count($this->Pages); $TempPageStack = array(); for ($i = 0; $i < $PageDepth - 1; $i++) { $TempPageStack[] = $this->Pages[$i]; $MethodStack[] = implode(self::$FunctionSeparator, $TempPageStack) . self::$FunctionSeparator . self::$PageStart; } $MethodStack[] = implode(self::$FunctionSeparator, $this->Pages); while (!empty($TempPageStack)) { $MethodStack[] = implode(self::$FunctionSeparator, $TempPageStack) . self::$FunctionSeparator . self::$PageEnd; array_pop($TempPageStack); } $MethodStack[] = self::$PageEnd; foreach ($MethodStack as $Method) { foreach ($RunCache as $PageClass) { $PageMethod = self::$FunctionPrefix . $Method; RDD::Log('Trying PageMethod: "' . $PageMethod . '" on "' . get_class($PageClass) . '"', TRACE, 1211); if ($PageClass->MethodExists($PageMethod)) { $PageClass->{$PageMethod}(); if (!$this->GoToCheck()) { return; } } } } } }
public function ElementStart($ElementName, $Config = array(), $Fetch = false) { if ($this->ElementRequire($ElementName)) { $Element = $this->ElementCreate($ElementName); $ElementScope = $this->GetElementScope($ElementName); if (!isset($this->ElementViews[$ElementScope])) { $this->ElementViews[$ElementScope] = array(); } $ElementNumber = count($this->ElementViews[$ElementScope]); $RD_Viewname = 'Element_' . $ElementName . '_' . $ElementNumber; if ($Element->MethodExists('HTMLCacheKey') && $Element->MethodExists('HTMLCacheTTL')) { $Key = $Element->HTMLCacheKey(); $CacheTTL = $Element->HTMLCacheTTL(); if ($Key && $CacheTTL) { $Data = $this->CacheTTL('Element/HTMLCache/' . $Key); if ($Data && isset($Data['HTML'])) { $HTML = $Data['HTML']; } } } if (isset($HTML) && STAGE != 'dev') { $this->ViewEcho($HTML); if ($Fetch) { return $HTML; } else { return $Element; } } $this->View($RD_Viewname); $this->Assign('RD_Context', $RD_Viewname); $this->Assign('element', $ElementName); if (!isset($Config['element'])) { $Config['element'] = $ElementName; } $this->Hook('PreElementSetup', $Element); if (method_exists($Element, 'Setup')) { $Return = $Element->Setup($Config); } $this->Hook('PostElementSetup', $Element); if (isset($Return) && $Return === false) { $Config['nodisplay'] = true; } else { $this->Hook('PreElementStart', $Element); $Return = ''; if (method_exists($Element, 'Start')) { $Return = $Element->Start(); } $this->Hook('PostElementStart', $Element); if ($Return === false) { $Config['nodisplay'] = true; } $this->SetTemplate('empty.tpl'); if (isset($Config['nodisplay']) || isset($Config['no_template'])) { $this->SetTemplate('empty.tpl'); } elseif (isset($Config['template'])) { $this->SetTemplate($Config['template']); } elseif (method_exists($Element, 'Template')) { $this->SetTemplate($Element->Template()); } else { $TemplateNames = array(); $TemplateNames[] = 'element' . DIR_SEP . $ElementName . '.tpl'; $Splitted = explode('_', $ElementName); $Last = array_pop($Splitted); $ReverseName = $Last . '_' . implode('_', $Splitted); $TemplateNames[] = 'element' . DIR_SEP . $ReverseName . '.tpl'; $ReverseNameDir = $Last . DIR_SEP . implode('_', $Splitted); $TemplateNames[] = 'element' . DIR_SEP . $ReverseNameDir . '.tpl'; # HA HA $ReverseNameDirDir = $Last . DIR_SEP . implode(DIR_SEP, $Splitted); $TemplateNames[] = 'element' . DIR_SEP . $ReverseNameDirDir . '.tpl'; foreach ($TemplateNames as $TemplateName) { if ($this->TemplateExist($TemplateName)) { $this->SetTemplate($TemplateName); break; } } } } if (isset($Element->no_template) && $Element->no_template) { $Config['no_template'] = true; } $Element_View = $this->GetView(); $this->ElementViews[$ElementScope][] = $Element_View; if (isset($CacheTTL) && $CacheTTL) { $Return = $this->ViewFinish(true); $Data = array(); $Data['HTML'] = $Return; $this->CacheTTL('Element/HTMLCache/' . $Key, $Data, $CacheTTL); if (true === $Fetch) { return $Return; } echo $Return; return $Element; } $Return = $this->ViewFinish($Fetch); if (true === $Fetch) { return $Return; } return $Element; RDD::Log('element prepare finished'); } else { RDD::Log('dont have an executable for the element ' . $ElementName, WARN); } return; }
/** * Creates an array from a given xml file * * @param String $FileName * @return Array */ public function LoadFormXML($FileName) { $Form = array(); $xml = new XMLReader(); $xml->open($FileName); while ($xml->read()) { if ($xml->name == 'form' && $xml->nodeType == XMLReader::ELEMENT) { RDD::Log('Found Formtag', TRACE, 1203); // This will create the $Form Array while ($xml->moveToNextAttribute()) { if ($xml->name == 'name' || $xml->name == 'submitvalue') { $Form[$xml->name] = T($xml->value); } else { $Form[$xml->name] = $xml->value; } } $Form['elements'] = array(); while ($xml->read()) { // The $EmptyElement and $EmtyData stuff is for the 2 different cases with <element></element> and <element /> $EmptyElement = false; if ($xml->name == 'element' && $xml->nodeType == XMLReader::ELEMENT) { if ($xml->isEmptyElement) { $EmptyElement = true; } $NewElement = array(); $Validators = array(); $Transforms = array(); $Prepares = array(); $Datas = array(); $Values = array(); $EmptyValue; $DataCounter = 0; $ValueCounter = 0; $dataName = $DataCounter; $valuename = $DataCounter; while ($xml->moveToNextAttribute()) { if ($xml->name == 'name' || substr($xml->name, 0, 4) == 'text') { $NewElement[$xml->name] = T($xml->value); } else { $NewElement[$xml->name] = $xml->value; } } $Form['elements'][$NewElement['id']] = $NewElement; if (!$EmptyElement) { while ($xml->read()) { // This part is for the parsing of the data elements within an "element" element $EmptyData = false; if ($xml->name == 'data' && $xml->nodeType == XMLReader::ELEMENT) { if ($xml->isEmptyElement) { $EmptyData = true; } $Joins = array(); $NewData = array(); while ($xml->moveToNextAttribute()) { $NewData[$xml->name] = $xml->value; } if (isset($NewData['id'])) { $dataName = $NewData['id']; } else { $dataName = $DataCounter; } $Form['elements'][$NewElement['id']]['datas'][$dataName] = $NewData; if (!$EmptyData) { // This will create the join array while ($xml->read()) { if ($xml->name == 'join' && $xml->nodeType == XMLReader::ELEMENT) { $NewJoin = array(); while ($xml->moveToNextAttribute()) { if ($xml->name == 'addempty') { $NewJoin[$xml->name] = T($xml->value); } else { $NewJoin[$xml->name] = $xml->value; } } $Joins[] = $NewJoin; } elseif ($xml->name == 'data' && $xml->nodeType == XMLReader::END_ELEMENT) { break; } } // This will add the join array (if it exists) to the $form array if (!empty($Joins)) { $Form['elements'][$NewElement['id']]['datas'][$dataName]['joins'] = $Joins; } } // This is for the counter of data element, it only counts if no id is given if (!isset($NewData['id'])) { $DataCounter++; } } if ($xml->name == 'value' && $xml->nodeType == XMLReader::ELEMENT) { $NewValue = array(); while ($xml->moveToNextAttribute()) { $NewValue[$xml->name] = $xml->value; } if (isset($NewValue['id'])) { $ValueName = $NewValue['id']; } else { $ValueName = $ValueCounter; } $Form['elements'][$NewElement['id']]['values'][$ValueName] = $NewValue; // This is for the counter ofvalue element, it only counts if no id is given if (!isset($NewValue['id'])) { $ValueCounter++; } } if ($xml->name == 'validator' && $xml->nodeType == XMLReader::ELEMENT) { $NewValidator = array(); while ($xml->moveToNextAttribute()) { $NewValidator[$xml->name] = $xml->value; } $Validators[] = $NewValidator; } elseif ($xml->name == 'prepare' && $xml->nodeType == XMLReader::ELEMENT) { $NewPrepare = array(); while ($xml->moveToNextAttribute()) { $NewPrepare[$xml->name] = $xml->value; } $Prepares[] = $NewPrepare; } elseif ($xml->name == 'transform' && $xml->nodeType == XMLReader::ELEMENT) { $NewTransform = array(); while ($xml->moveToNextAttribute()) { $NewTransform[$xml->name] = $xml->value; } $Transforms[] = $NewTransform; } elseif ($xml->name == 'element' && $xml->nodeType == XMLReader::END_ELEMENT) { break; } } if (!empty($Validators)) { $Form['elements'][$NewElement['id']]['validators'] = $Validators; } if (!empty($Transforms)) { $Form['elements'][$NewElement['id']]['transforms'] = $Transforms; } if (!empty($Prepares)) { $Form['elements'][$NewElement['id']]['prepares'] = $Prepares; } if (!empty($Datas)) { $Form['elements'][$NewElement['id']]['datas'] = $Datas; } } } } return $Form; } } }
public function Logout() { if ($this->GetUser()) { if (!isset($this->DataObject)) { $DB = RDM_Dao::SDB($this->UserDatabase, $this->UserTable); } else { $DB = clone $this->DataObject; } if (array_key_exists('Online', $DB->table())) { // in some projects we dont have this column! $DB->ID = $this->GetUser('ID'); if ($DB->find() == 1) { RDD::Log('Usermodule found user', TRACE, 1410); $DB->fetch(); $DB->Online = 0; $DB->update(); } } $this->UnsetSession($this->SessionName); $this->UnsetSession('LastLoginSaved'); $this->Hook('UserLogout'); } }
public static function Error($ErrNo, $ErrStr, $ErrFile, $ErrLine) { if ($ErrNo == E_STRICT) { return; } // catch smarty TODO if (strstr($ErrFile, 'core.get_include_path.php')) { return; } // catch double session_start() if (strstr($ErrStr, 'session_start()')) { return; } // catch stupid PHP 5.1 error if (strstr($ErrStr, 'Indirect modification of overloaded property')) { return; } // catch smarty_compile TODO if (strstr($ErrFile, 'smarty_compile')) { return; } // catch mysql_escape_string() if (strstr($ErrStr, 'mysql_real_escape_string()')) { return; } // catch the noob programmers notices from vB if (self::$PreventErrorsByPath && strstr($ErrFile, '/' . self::$PreventErrorsByPath . '/')) { RDD::Log('[[' . self::$ErrorMap[$ErrNo] . ':' . $ErrFile . ':' . $ErrLine . ']] ' . $ErrStr, ERROR); return; } // catch akismet warnings if (!defined('AKISMET_WARNINGS') && stristr($ErrStr, 'akismet')) { RDD::Log($ErrStr, WARN); return; } $params = array(); $params['text'] = '[[' . self::$ErrorMap[$ErrNo] . ':' . $ErrFile . ':' . $ErrLine . ']] ' . $ErrStr; if (!self::$DisableTime) { if (!isset(self::$FirstTime)) { self::$FirstTime = microtime(true); $params['time'] = 0; } else { $params['time'] = microtime(true) - self::$FirstTime; } } if (self::$MemUsage && function_exists('memory_get_usage')) { $params['mem'] = memory_get_usage(); } $params['level'] = ERROR; $params['from'] = self::CallFrom(2); $params['fulltrace'] = debug_backtrace(); self::AddLog($params); if (self::$ShowError) { echo "<b style='color: red'>ERROR: " . $params['text'] . "</b>\n"; // $trace = debug_backtrace(); // echo "<pre>Backtrace:\n".self::EchoDebugDump($trace)."</pre>"; } return; }
public function __destruct() { if ($this->CoreCache) { $this->SetFileVarDump('RDFileCache', $this->FileCache); $this->SetFileVarDump('RDDirsCache', $this->DirsCache); } RDD::Log('Destructing RD - bye bye', INFO); return; }
public function ViewExecute($RD_View, $Fetch = false) { RDD::Log('Smarty Finish Run', TRACE, 1200); RDD::Log('ViewName: ' . $RD_View->GetName()); $this->Hook('ViewExecute', $RD_View); $Key = array_search($RD_View, $this->ViewCache, true); unset($this->ViewCache[$Key]); if (isset($this->ExecuteView)) { $this->ExecuteStack[] = $this->ExecuteView; $ExecuteViewAssigns = $this->ExecuteView->GetAssigns(); foreach ($ExecuteViewAssigns as $Key => $Value) { $RD_View->AssignIfUnset($Key, $Value); } } $this->ExecuteView = $RD_View; RDD::Log('Smarty Execute Template Start', TRACE, 1200); $RD_View->Assign('RandomValue', rand(1, 999999999)); $old_error_reporting = error_reporting(); if ($this->ConsoleDebug) { $RD_View->ResetDebugging()->StartDebugging(); RDD::Log('Preparing Smarty Execute Template ConsoleDebug', TRACE, 1200); $ConsoleDebugCache = array(); $ConsoleDebugCache['Name'] = $RD_View->GetName(); $ConsoleDebugCache['Class'] = get_class($RD_View); $ConsoleDebugCache['Vars'] = $RD_View->GetAssigns(); $this->ConsoleDebugData[] =& $ConsoleDebugCache; } error_reporting(error_reporting() & ~E_NOTICE); if ($Fetch) { $Return = $RD_View->Fetch(); } else { $Return = $RD_View->Display(); } error_reporting($old_error_reporting); if ($this->ConsoleDebug) { $ConsoleDebugCache['Templates'] = $RD_View->GetDebugging(); } $RD_View->StopDebugging(); RDD::Log('Smarty Execute Template End', TRACE, 1200); if (!empty($this->ExecuteStack)) { $this->ExecuteView = array_pop($this->ExecuteStack); } else { unset($this->ExecuteView); } return $Return; }
public function ProcessExecutor($CommandList, $OutputHandling = self::OUT_IGNORE, &$Error = NULL) { if (!$this->IsCLI()) { return $this->main; } $Count = count($CommandList); RDD::Log('Executing ' . $Count . ' Commands with max. ' . $this->CPUCount . ' running.', INFO); $Running = array(); $End = false; $NothingLeft = false; $CommandList = array_reverse($CommandList); if ($OutputHandling === self::OUT_RETURN) { $Return = array(); } while (!$End) { foreach ($Running as $Key => $ProcessKey) { if ($OutputHandling === self::OUT_ECHO) { $StdOut = $this->ProcessStdOut($ProcessKey); echo $StdOut; if (strlen($StdOut) > 0) { echo "\n"; } } elseif ($OutputHandling === self::OUT_RETURN) { if (!isset($Return[$Key])) { $Return[$Key] = ''; } $Return[$Key] .= $this->ProcessStdOut($ProcessKey); } if ($Error !== NULL) { if (is_array($Error)) { if (!isset($Error[$Key])) { $Error[$Key] = ''; } $Error[$Key] .= $this->ProcessStdErr($ProcessKey); } elseif (is_string($Error)) { $Error .= $this->ProcessStdErr($ProcessKey); } } } if (count($Running) < $this->CPUCount && !$NothingLeft) { $NextCommand = array_pop($CommandList); if ($NextCommand !== NULL) { $Running[] = $this->ProcessOpen($NextCommand); } else { $NothingLeft = true; } } else { sleep(self::$ExecutorWaitingTime); RDD::Log('Running ' . count($Running)); foreach ($Running as $Key => $ProcessKey) { $Status = $this->ProcessStatus($ProcessKey); if (!$Status['running']) { unset($Running[$Key]); } } if ($NothingLeft && count($Running) == 0) { $End = true; } } } if (isset($Return)) { return $Return; } else { return $this->main; } }
protected function _query($string) { RDD::Log($this->_database . ' | ' . $string, TRACE, 9999); $this->last_query = $string; return parent::_query($string); }