function errorHandler($error_level, $error_message, $error_file, $error_line, $error_context) { $error = array("lvl" => $error_level, "msg" => $error_message, "file" => $error_file, "ln" => $error_line); switch ($error_level) { case E_ERROR: case E_CORE_ERROR: case E_COMPILE_ERROR: case E_PARSE: __log($error, "FATAL ERROR"); break; case E_USER_ERROR: case E_RECOVERABLE_ERROR: __log($error, "Error"); break; case E_WARNING: case E_CORE_WARNING: case E_COMPILE_WARNING: case E_USER_WARNING: __log($error, "WARNING"); break; case E_NOTICE: case E_USER_NOTICE: __log($error, "NOTICE"); break; case E_STRICT: __log($error, "DEBUG"); break; default: __log($error, "WARNING"); } }
/** * Execute a plugin * * @param type $plugin * @param type $object * @param type $raw * * @return stdClass */ function executePlugin($plugin, $object, $raw) { global $ALLOW_PLUGINS; if (!$ALLOW_PLUGINS) { return $object; } $plugins = explode(':', $plugin); if (!$plugins[0] == 'plugin') { return false; } $plugin = trim($plugins[1]); $plugin = preg_replace("/[^a-zA-Z0-9\\s]/", "", $plugin); $file = strtolower($plugin); if (!file_exists(dirname(__FILE__) . "/plugins/{$file}.php")) { __log("Plugin file {$file}.php could not be located"); return false; } require_once dirname(__FILE__) . "/plugins/{$file}.php"; $plugin_class = new $plugin(); if ($plugin_class) { __log("Plugin {$plugin} triggered"); return $plugin_class->execute($plugin, $object, $raw); } __log("Plugin is invalid"); return false; }
public function execute($plugin, $object, $raw) { __log("Raw JSON string passed: '{$object->description}'"); $json = json_decode($object->description); if (!$json) { __log("Invalid JSON payload '{$json}'", 'ERROR'); return false; } return $json; }
function curlContinue(){ $mrc=&$this->Active[0]; $act=&$this->Active[1]; $stp=&$this->Active[2]; $mch=&$this->Active[3]; $ch1=&$this->Active[4]; if($stp==0){//начало //echo "curl init!\n"; // создаём ресурс cURL $ch1=$this->curlCreateResource(); //создаем набор дескрипторов cURL $mch = curl_multi_init(); //добавляем дескриптор curl_multi_add_handle($mch,$ch1); ++$stp; } //запускаем дескрипторы if($stp==1){ //echo "curl stp 1!\n"; $mrc=curl_multi_exec($mch, $act); if($mrc!=CURLM_CALL_MULTI_PERFORM) ++$stp; } if($stp==2){ //echo "curl stp 2!\n"; if($act){// and $mrc == CURLM_OK || $mrc == CURLM_CALL_MULTI_PERFORM){ //if($mrc==CURLM_CALL_MULTI_PERFORM || curl_multi_select($mch, 0.001)>0){ $mrc=curl_multi_exec($mch, $act); //}else echo $mrc; }else ++$stp; /* $info = curl_multi_info_read($mch); if (false !== $info) { var_dump($info); } */ } //закрываем дескрипторы if($stp==3){ //echo "curl stp 3!\n"; if($this->lastUpdated XoR $this->lastUpdated=$this->curlMathContent($ch1)) __log($this->lastUpdated ? 'Lobby обновлён' : 'Падение Lobby'); curl_multi_remove_handle($mch, $ch1); curl_multi_close($mch); curl_close($ch1); $stp=0; $this->Inited=false; $this->LastTime=microtime(true); } return $stp; }
function shutdownHandler() { $lasterror = error_get_last(); switch ($lasterror['type']) { case E_ERROR: case E_CORE_ERROR: case E_COMPILE_ERROR: case E_USER_ERROR: case E_RECOVERABLE_ERROR: case E_CORE_WARNING: case E_COMPILE_WARNING: case E_PARSE: $error = array("lvl" => $lasterror['type'], "msg" => $lasterror['message'], "file:" => $lasterror['file'], "ln" => $lasterror['line']); __log($error, "FATAL ERROR"); } }
function myErrorHandler($errno, $errstr, $errfile, $errline) { switch ($errno) { case E_USER_NOTICE: // echo "<pre>";print_r(debug_backtrace());echo "</pre>"; if (WB_DA) { __workerBee()->attach(new __wbMessage($type, $errno, $errstr, $errfile, $errline, debug_backtrace())); } $type = "log"; __log("[{$errno}] ({$errfile}) {$errstr}<br />\n"); break; default: $type = "errror"; // __error("[$errno] ($errfile) $errstr<br />\n"); break; } /* Don't execute PHP internal error handler */ return true; }
public static function debug($name) { die(__log($name)); }
public function load() { if (isset($this->class)) { preg_match($this->preg, $this->class, $a); foreach ($a as $match) { if ($match != $this->class) { continue; } } if ($match) { $file = preg_replace('/{class}/', strtolower($match), $this->file); if (is_array($this->path)) { foreach ($this->path as $path) { $full_path = $path . DS . $file; if (file_exists($full_path)) { include $full_path; continue; } } } else { $full_path = $this->path . DS . $file; // create teh full path __log("full path {$full_path}"); if (file_exists($full_path)) { include $full_path; } else { __log("autoload {$full_path} does not exists."); } } } } }
public function initMVC() { $controller = current($this->controllers); $controller = $this->attached_objects[$controller]; if (method_exists($controller, 'attach')) { $this->attach($controller); } else { // throw error? } $active_modules = array(); /* if (count($this->modules) > 0) // make sure we have some modules { foreach ((array) $this->modules as $module) { $active_modules[] = &$module; if (method_exists($module,'controllerLoad')) { $module->controllerLoad($controller); } } } */ // set hook sequence array. this is the order all system/application hooks will be called. $hook_sequence = array(HOOK_SEQ_MASTER, HOOK_SEQ_SYSTEM, HOOK_SEQ_INIT, HOOK_SEQ_MODELS, HOOK_SEQ_INDEX, HOOK_SEQ_FINISHED); if (count($hook_sequence) < 1) { throw new Exception('*** Hook Sequence array unset.'); } __log("*** INIT APP: " . get_class($controller)); $models = array(); // if (array_key_exists(get_class($controller),$this->model)) { $models = & $this->model[get_class($controller)]; } foreach ((array) $hook_sequence as $sequence) { $method = ''; $object_order = array('models', 'application', 'controller'); switch ($sequence) { case HOOK_SEQ_MASTER: $method = '__initMaster'; $object_order = array('controller'); break; case HOOK_SEQ_INIT: $method = '__init'; break; case HOOK_SEQ_SYSTEM: $method = 'initSystem'; break; case HOOK_SEQ_INDEX: $method = '__index'; break; case HOOK_SEQ_FINISHED: $method = array('__finishedMaster', '__finished'); break; default: // throw exception } $i = 0; while (1) { if (100 < $i) { throw new Exception(); } $i++; if (is_array($method)) { $_method = current($method); if ($i > count($method)) { break; } } else { $_method = $method; } foreach ((array) $object_order as $obj) { // set the order which we envoke the methods switch ($obj) { case 'application': if (method_exists($this, $_method)) { $this->{$_method}(); } break; case 'models': if (count($models) > 0) { foreach ($models as $_model) { if (method_exists($_model, $_method)) { $_model->{$_method}(); } } } break; case 'controller': if (method_exists($controller, $_method)) { $controller->{$_method}(); } break; } } if (is_array($method)) { next($method); } else { break; } } } }
$categories = []; foreach ($data->xpath('value/array/data/value/string') as $cat) { array_push($categories, (string) $cat); } $obj->categories = $categories; break; //this is used for title/description //this is used for title/description default: $obj->{$data->name} = (string) $data->value->string; } } //authenticate fitbit connection $fitbit = new FitBitPHP($conskey, $conssec); $fitbit->setOAuthDetails($user['FitBitToken'], $user['FitBitSecret']); __log("{$xml->params}->param[3]->value->struct->member[0]->value->string: " . $xml->params->param[3]->value->struct->member[0]->value->string); $body = $xml->params->param[3]->value->struct->member[1]->value->string; switch ($xml->params->param[3]->value->struct->member[0]->value->string) { case 'logBody': list($date, $weight, $fat, $bicep, $calf, $chest, $forearm, $hips, $neck, $thigh, $waist) = explode(",", $body); $date = dateconverter($date); $xml = $fitbit->logWeight($weight, $date); success('<string>' . $response->status_code . '</string>'); break; case 'logActivity': list($date, $activityId, $duration, $calories, $distance, $distanceUnit, $activityName) = explode(",", $body); $date = dateconverter($date); $xml = $fitbit->logActivity($date, $activityId, $duration, $calories, $distance, $distanceUnit, $activityName); success('<string>' . $response->status_code . '</string>'); break; case 'logFood':
if (!$errmsg) { if ($e0) { $output["msg"] = "邮箱已被使用"; } else { if ($e1) { $output["msg"] = "用户名已被注册"; } else { $mysqli = getMysqli(); $hash = sha1($user . time() . $email . rand(10, 30) + "Ajbo2./OJI"); $expire = "NOW() + INTERVAL 1 DAY"; $p = $password; $password = password_hash($password, PASSWORD_DEFAULT); trigger_error(password_verify($p, $password) ? "true" : "false"); $q = "INSERT INTO nonactivatedUser VALUES ('{$user}', '{$email}', '{$password}', '{$hash}', {$expire}, 'false')"; if ($mysqli->query($q)) { __sendmail($user); __log($user); $output["msg"] = "已提交注册信息!激活邮件将发送到所填邮箱,请24小时内进入邮箱激活,否则注册无效"; $output["result"] = true; } else { trigger_error("Failed to {$q} caused by : \r\n\t" . $mysqli->error); } } } } } } } } header("content-type:text/json;charset=utf-8"); echo json_encode($output, JSON_UNESCAPED_UNICODE);
function failure($status) { __log("Failure: {$status}", 'ERROR'); $xml = <<<EOD <?xml version="1.0"?> <methodResponse> <fault> <value> <struct> <member> <name>faultCode</name> <value><int>{$status}</int></value> </member> <member> <name>faultString</name> <value><string>Request was not successful.</string></value> </member> </struct> </value> </fault> </methodResponse> EOD; output($xml); }
<?php DEFINE('CACHE_PATH', APPLICATION_PATH . DS . DIRECTORY_CACHE); $CACHE_PATH = CACHE_PATH; if (is_dir($CACHE_PATH) && is_writeable($CACHE_PATH)) { // WOOT! we have a writeable cache path __cache(CACHE_DIRECTORY, $CACHE_PATH); __log('init cache'); } else { // throw error } function __cache() { if (func_num_args() == 0) { return new __cache(); } else { $args = func_get_args(); switch ($args[0]) { case CACHE_DIRECTORY: if (isset($args[1])) { __cache::setDirectory($args[1]); } else { return __cache::getDirectory(); } break; default: } } } class __cache {
function uploadAvatar($oMasthead, $mUser, $nypath, $city_id) { global $wgTmpDirectory, $UNLINK_OLD, $TEST; $result = false; $filename = wfBasename($nypath); $sFilePath = $oMasthead->getFullPath(); $user_id = $mUser->getId(); $__path = str_replace($filename, "", $nypath); $__files = $__path . "/*_" . $user_id . "_*"; if ( $TEST == 1 ) { saveDataInDB($user_id, $city_id, $__files, $sFilePath); return true; } if( !isset( $wgTmpDirectory ) || !is_dir( $wgTmpDirectory ) ) { $wgTmpDirectory = '/tmp'; } $sTmpFile = sprintf("%s/avatars/%s", $wgTmpDirectory, $filename); if ( copy( $nypath, $sTmpFile ) ) { $iFileSize = filesize($sTmpFile); if ( empty( $iFileSize ) ) { __log("Empty file {$input} reported size {$iFileSize}"); return $result; } __log("Temp file set to {$sTmpFile}"); if ( file_exists( $sTmpFile ) ) { $aImgInfo = getimagesize($sTmpFile); $aAllowMime = array( 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png', 'image/jpg' ); if (!in_array($aImgInfo['mime'], $aAllowMime)) { __log("Invalid mime type " . $aImgInfo['mime'] . ", allowed: " . implode(',', $aAllowMime)); return $result; } switch ($aImgInfo['mime']) { case 'image/gif': $oImgOrig = @imagecreatefromgif($sTmpFile); break; case 'image/pjpeg': case 'image/jpeg': case 'image/jpg': $oImgOrig = @imagecreatefromjpeg($sTmpFile); break; case 'image/x-png': case 'image/png': $oImgOrig = @imagecreatefrompng($sTmpFile); break; } $aOrigSize = array('width' => $aImgInfo[0], 'height' => $aImgInfo[1]); /** * generate new image to png format */ $addedAvatars = array(); /** * calculate new image size - should be 100 x 100 */ $iImgW = AVATAR_DEFAULT_WIDTH; $iImgH = AVATAR_DEFAULT_HEIGHT; /* WIDTH > HEIGHT */ if ( $aOrigSize['width'] > $aOrigSize['height'] ) { $iImgH = $iImgW * ( $aOrigSize['height'] / $aOrigSize['width'] ); } /* HEIGHT > WIDTH */ if ( $aOrigSize['width'] < $aOrigSize['height'] ) { $iImgW = $iImgH * ( $aOrigSize['width'] / $aOrigSize['height'] ); } /* empty image with thumb size on white background */ $oImg = @imagecreatetruecolor($iImgW, $iImgH); $white = imagecolorallocate($oImg, 255, 255, 255); imagefill($oImg, 0, 0, $white); imagecopyresampled( $oImg, $oImgOrig, floor ( ( AVATAR_DEFAULT_WIDTH - $iImgW ) / 2 ) /*dx*/, floor ( ( AVATAR_DEFAULT_HEIGHT - $iImgH ) / 2 ) /*dy*/, 0 /*sx*/, 0 /*sy*/, $iImgW /*dw*/, $iImgH /*dh*/, $aOrigSize['width']/*sw*/, $aOrigSize['height']/*sh*/ ); /** * save to new file ... but create folder for it first */ if ( !is_dir( dirname( $sFilePath ) ) && !wfMkdirParents( dirname( $sFilePath ) ) ) { __log( sprintf("Cannot create directory %s", dirname( $sFilePath ) ) ); return $result; } if ( !imagepng( $oImg, $sFilePath ) ) { __log( sprintf("Cannot save png Avatar: %s", $sFilePath ) ); return $result; } /* remove tmp file */ imagedestroy($oImg); $sUserText = $mUser->getName(); $mUserPage = Title::newFromText( $sUserText, NS_USER ); if ( $ADD_TO_USER_LOG == 1 ) { $oLogPage = new LogPage( AVATAR_LOG_NAME ); $oLogPage->addEntry( 'avatar_chn', $mUserPage, ''); } unlink($sTmpFile); /** * notify image replication system */ $newAvatarPath = $oMasthead->getLocalPath(); __log(sprintf("New avatar path -> %s", $newAvatarPath)); global $wgEnableUploadInfoExt; if( $wgEnableUploadInfoExt ) { UploadInfo::log( $mUserPage, $sFilePath, $newAvatarPath ); } $errorNo = UPLOAD_ERR_OK; if ( !empty($newAvatarPath) ) { /* set user option */ __log(sprintf("Set %s = %s in user preferences", AVATAR_USER_OPTION_NAME, $newAvatarPath)); $mUser->setOption( AVATAR_USER_OPTION_NAME, $newAvatarPath ); $mUser->saveSettings(); } if ( $UNLINK_OLD ) { $files = glob($__files); if ( $files ) { foreach ( $files as $file ) { __log("Unlink $file"); unlink($file); } } } saveDataInDB($user_id, $city_id, $__files, $sFilePath); $result = true; } else { __log(sprintf("File %s doesn't exist", $sTmpFile )); return $result; } } else { __log("Cannot copy $nypath to $sTmpFile"); return $result; } return $result; }
private function _loadModules() { $modules = (array) $this->modules; if (count($modules) > 0 && defined('INIT_MODULES') && INIT_MODULES) { // start module init $_paths = array(); require_once 'system.modules.php'; // application users modules - lets load up the system module file. __log("Loading " . count($modules) . " modules."); // report how many modules we are loading. foreach ((array) $modules as $_module) { if (is_dir(BASE_SYSTEM . DS . DIRECTORY_MODULES . DS . '_' . $_module)) { // any module contained in a directory with _ in front is considered a must load over any modules in use directory $module_directory = BASE_SYSTEM . DS . DIRECTORY_MODULES . DS . '_' . $_module; } else { if (is_dir(APPLICATION_PATH . DS . DIRECTORY_MODULES . DS . $_module)) { // rule off thumb always use modules in users application path before we use modules in system directory $module_directory = APPLICATION_PATH . DS . DIRECTORY_MODULES . DS . $_module; } else { if (is_dir(BASE_SYSTEM . DS . DIRECTORY_MODULES . DS . $_module)) { $module_directory = BASE_SYSTEM . DS . DIRECTORY_MODULES . DS . $_module; } else { throw new Exception('Tried loading a system module that does not exists'); } } } if (file_exists($module_directory . DS . $_module . '.module.php')) { include $module_directory . DS . $_module . '.module.php'; $_paths[$_module] = $module_directory . DS . $_module . '.module.php'; } else { throw new Exception("required system file was not install module.init.php was not found in {$module_directory}."); } } $modules = modules::find(); // find all loaded module classes // interate through each module and execute foreach ((array) $modules as $module) { $module_object =& new $module(); $name = $module_object->__name(); if (key_exists($name, $this->_modules)) { throw new Exception($module . ": fatal Conflict with the module name: " . $name . " taken by the class: " . get_class($this->modules[$name])); } __log("Loading module: {$name}"); $module_object->attach($this); $this->_modules[$name] = $module_object; if (method_exists($module_object, '__init')) { __log("Initializing module. "); $module_object->__init(); } // odd a module should have an init } // end of module init } }