示例#1
0
 public function SendHttpRequest($url, $params, $type = 'POST')
 {
     try {
         $post_data = '';
         if ($params && is_array($params)) {
             $post_data = implode('&', $params);
         }
         $ch = curl_init();
         if ($type == 'POST') {
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_URL, $url);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
             ob_start();
             curl_exec($ch);
             $result = ob_get_contents();
             ob_end_clean();
         } else {
             if ($type == 'GET') {
                 if ($post_data && $post_data != '') {
                     $url = $url . '?' . $post_data;
                 }
                 curl_setopt($ch, CURLOPT_URL, $url);
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                 curl_setopt($ch, CURLOPT_HEADER, 0);
                 $result = curl_exec($ch);
                 curl_close($ch);
             }
         }
         return urldecode($result);
     } catch (Exception $e) {
         LogMessage($e->getMessage());
     }
 }
示例#2
0
 public static function ErrorHandler($Error, $Message = '', $File = '', $Line = '')
 {
     if (error_reporting() == 0) {
         return False;
     }
     $Object = 'PHP';
     $Method = 'Function';
     if (is_object($Error)) {
         $Info = False;
         foreach ($Error->GetTrace() as $Info) {
             break;
         }
         $Method = ArrayValue('function', $Info, $Method);
         $Object = ArrayValue('class', $Info, $Object);
         $Message = $Error->GetMessage();
         $File = $Error->GetFile();
         $Line = $Error->GetLine();
         $Error = -1;
     }
     $File = str_replace(PATH_ROOT . DS, '', $File);
     switch ($Error) {
         case E_NOTICE:
             $Code = 'NOTICE';
             break;
         case E_WARNING:
             $Code = 'WARNING';
             break;
         case -1:
             $Code = 'UNCAUGHT EXCEPTION';
             break;
         default:
             $Code = 'ERROR';
     }
     $Message = strip_tags($Message);
     self::Message('%s: %s in %s on line %s', $Code, $Message, $File, $Line);
     self::Message($Message);
     LogMessage($File, $Line, $Object, $Method, $Message, $Code);
     // send error to email
     $To = Gdn::Config('Plugins.UsefulFunctions.Console.ErrorsEmailToAddress');
     if (self::Check() && $To != False) {
         $Text = sprintf(Gdn::Translate('Error in console script %1$s %2$s %3$s %4$s'), $Code, $Message, $File, $Line);
         if (!class_exists('Gdn_Email')) {
             return error_log("Error ({$Code})", 1, $To, $Text);
         }
         $Email = new Gdn_Email();
         $Email->To($To)->Message($Text)->Subject("Error ({$Code})")->Send('ErrorInConsoleScript');
     }
     exit;
 }
示例#3
0
文件: Bearer.php 项目: noikiy/LINJU
 /**
  * This is a convenience function that can be used to get the token, which can then
  * be passed to getAccessTokenData(). The constraints specified by the draft are
  * attempted to be adheared to in this method.
  *
  * As per the Bearer spec (draft 8, section 2) - there are three ways for a client
  * to specify the bearer token, in order of preference: Authorization Header,
  * POST and GET.
  *
  * NB: Resource servers MUST accept tokens via the Authorization scheme
  * (http://tools.ietf.org/html/rfc6750#section-2).
  *
  * @todo Should we enforce TLS/SSL in this function?
  *
  * @see http://tools.ietf.org/html/rfc6750#section-2.1
  * @see http://tools.ietf.org/html/rfc6750#section-2.2
  * @see http://tools.ietf.org/html/rfc6750#section-2.3
  *
  * Old Android version bug (at least with version 2.2)
  * @see http://code.google.com/p/android/issues/detail?id=6684
  *
  */
 public function getAccessTokenParameter(RequestInterface $request, ResponseInterface $response)
 {
     $headers = $request->headers('AUTHORIZATION');
     // Check that exactly one method was used
     $methodsUsed = !empty($headers) + !is_null($request->query($this->config['token_param_name'])) + !is_null($request->request($this->config['token_param_name']));
     if ($methodsUsed > 1) {
         $response->setError(400, 'invalid_request', 'Only one method may be used to authenticate at a time (Auth header, GET or POST)');
         return null;
     }
     if ($methodsUsed == 0) {
         $response->setStatusCode(401);
         return null;
     }
     // HEADER: Get the access token from the header
     if (!empty($headers)) {
         if (!preg_match('/' . $this->config['token_bearer_header_name'] . '\\s(\\S+)/', $headers, $matches)) {
             $response->setError(400, 'invalid_request', 'Malformed auth header');
             return null;
         }
         return $matches[1];
     }
     if ($request->request($this->config['token_param_name'])) {
         // POST: Get the token from POST data
         if (strtolower($request->server('REQUEST_METHOD')) != 'post') {
             $response->setError(400, 'invalid_request', 'When putting the token in the body, the method must be POST');
             return null;
         }
         $contentType = $request->server('CONTENT_TYPE');
         if (false !== ($pos = strpos($contentType, ';'))) {
             $contentType = substr($contentType, 0, $pos);
         }
         LogMessage($request->request('upload_image'));
         LogMessage($contentType);
         if (!$request->files['Filedata']) {
             if ($contentType !== null && $contentType != 'application/x-www-form-urlencoded') {
                 // IETF specifies content-type. NB: Not all webservers populate this _SERVER variable
                 // @see http://tools.ietf.org/html/rfc6750#section-2.2
                 $response->setError(400, 'invalid_request', 'The content type for POST requests must be "application/x-www-form-urlencoded"');
                 return null;
             }
         }
         return $request->request($this->config['token_param_name']);
     }
     // GET method
     return $request->query($this->config['token_param_name']);
 }
示例#4
0
文件: log.fun.php 项目: noikiy/LINJU
function LogMessage($msg)
{
    //return;
    include_once __WEB_ROOT . '/setting/sitesetting.php';
    try {
        $path = __WEB_ROOT . "/log.txt";
        $ft = fopen($path, 'a');
        if (!$ft) {
            return;
        }
        $ms = getmillsecond();
        $msg = date('Y-m-d H:i:s:', time()) . $ms . ' - ' . $msg . "\r\n";
        fwrite($ft, $msg);
        fclose($ft);
    } catch (Exception $e) {
        LogMessage($e->getMessage());
    }
}
示例#5
0
 function GetPointByAddress($address)
 {
     $point = array();
     $gfullURL = $this->GeocoderBaseURL . 'output=' . $this->Output . '&key=' . $this->Key;
     $address = urlencode($address);
     $gfullURL .= '&address=' . $address;
     //$result=file_get_contents($gfullURL);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $gfullURL);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     $result = curl_exec($ch);
     curl_close($ch);
     $result = urldecode($result);
     LogMessage($result);
     $jobj = json_decode($result);
     if ($jobj->status == 'OK') {
         $point['lat'] = $jobj->result->location->lat;
         $point['lng'] = $jobj->result->location->lng;
     }
     return $point;
 }
示例#6
0
function Get_Curl($url)
{
    //Random sleep or delay in call of page to avoid risk of blocking of IP address
    sleep(rand(MinDelayTime, MaxDelayTime));
    LogMessage("URL requested : " . $url);
    $ch = curl_init();
    // Initialising cURL
    curl_setopt($ch, CURLOPT_URL, $url);
    // Setting cURL's URL option with the $url variable passed into the function
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
    // Setting cURL's option to return the webpage data
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, True);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    $data = curl_exec($ch);
    // Executing the cURL request and assigning the returned data to the $data variable
    if (curl_errno($ch)) {
        echo 'Curl error: ' . curl_error($ch);
    }
    curl_close($ch);
    // Closing cURL
    return $data;
    // Returning html content of site
}
/**
 * A custom error handler that displays much more, very useful information when
 * errors are encountered in Garden.
 *	@param Exception $Exception The exception that was thrown.
 */
function Gdn_ExceptionHandler($Exception)
{
    try {
        $ErrorNumber = $Exception->getCode();
        $Message = $Exception->getMessage();
        $File = $Exception->getFile();
        $Line = $Exception->getLine();
        if (method_exists($Exception, 'getContext')) {
            $Arguments = $Exception->getContext();
        } else {
            $Arguments = '';
        }
        $Backtrace = $Exception->getTrace();
        // Clean the output buffer in case an error was encountered in-page.
        @ob_end_clean();
        // prevent headers already sent error
        if (!headers_sent()) {
            header('Content-Type: text/html; charset=utf-8');
        }
        $SenderMessage = $Message;
        $SenderObject = 'PHP';
        $SenderMethod = 'Gdn_ErrorHandler';
        $SenderCode = FALSE;
        $SenderTrace = $Backtrace;
        $MessageInfo = explode('|', $Message);
        $MessageCount = count($MessageInfo);
        if ($MessageCount == 4) {
            list($SenderMessage, $SenderObject, $SenderMethod, $SenderCode) = $MessageInfo;
        } else {
            if ($MessageCount == 3) {
                list($SenderMessage, $SenderObject, $SenderMethod) = $MessageInfo;
            } elseif (function_exists('GetValueR')) {
                $IsError = GetValueR('0.function', $SenderTrace) == 'Gdn_ErrorHandler';
                // not exception
                $N = $IsError ? '1' : '0';
                $SenderMethod = GetValueR($N . '.function', $SenderTrace, $SenderMethod);
                $SenderObject = GetValueR($N . '.class', $SenderTrace, $SenderObject);
            }
        }
        $SenderMessage = strip_tags($SenderMessage);
        $Master = FALSE;
        // The parsed master view
        $CssPath = FALSE;
        // The web-path to the css file
        $ErrorLines = FALSE;
        // The lines near the error's line #
        $DeliveryType = defined('DELIVERY_TYPE_ALL') ? DELIVERY_TYPE_ALL : 'ALL';
        if (array_key_exists('DeliveryType', $_POST)) {
            $DeliveryType = $_POST['DeliveryType'];
        } else {
            if (array_key_exists('DeliveryType', $_GET)) {
                $DeliveryType = $_GET['DeliveryType'];
            }
        }
        // Make sure all of the required custom functions and variables are defined.
        $PanicError = FALSE;
        // Should we just dump a message and forget about the master view?
        if (!defined('DS')) {
            $PanicError = TRUE;
        }
        if (!defined('PATH_ROOT')) {
            $PanicError = TRUE;
        }
        if (!defined('APPLICATION')) {
            define('APPLICATION', 'Garden');
        }
        if (!defined('APPLICATION_VERSION')) {
            define('APPLICATION_VERSION', 'Unknown');
        }
        $WebRoot = '';
        // Try and rollback a database transaction.
        if (class_exists('Gdn', FALSE)) {
            $Database = Gdn::Database();
            if (is_object($Database)) {
                $Database->RollbackTransaction();
            }
        }
        if ($PanicError === FALSE) {
            // See if we can get the file that caused the error
            if (is_string($File) && is_numeric($ErrorNumber)) {
                $ErrorLines = @file($File);
            }
            // If this error was encountered during an ajax request, don't bother gettting the css or theme files
            if ($DeliveryType == DELIVERY_TYPE_ALL) {
                $CssPaths = array();
                // Potential places where the css can be found in the filesystem.
                $MasterViewPaths = array();
                $MasterViewName = 'error.master.php';
                $MasterViewCss = 'error.css';
                if (class_exists('Gdn', FALSE)) {
                    $CurrentTheme = '';
                    // The currently selected theme
                    $CurrentTheme = Gdn::Config('Garden.Theme', '');
                    $MasterViewName = Gdn::Config('Garden.Errors.MasterView', $MasterViewName);
                    $MasterViewCss = substr($MasterViewName, 0, strpos($MasterViewName, '.'));
                    if ($MasterViewCss == '') {
                        $MasterViewCss = 'error';
                    }
                    $MasterViewCss .= '.css';
                    if ($CurrentTheme != '') {
                        // Look for CSS in the theme folder:
                        $CssPaths[] = PATH_THEMES . DS . $CurrentTheme . DS . 'design' . DS . $MasterViewCss;
                        // Look for Master View in the theme folder:
                        $MasterViewPaths[] = PATH_THEMES . DS . $CurrentTheme . DS . 'views' . DS . $MasterViewName;
                    }
                }
                // Look for CSS in the dashboard design folder.
                $CssPaths[] = PATH_APPLICATIONS . DS . 'dashboard' . DS . 'design' . DS . $MasterViewCss;
                // Look for Master View in the dashboard view folder.
                $MasterViewPaths[] = PATH_APPLICATIONS . DS . 'dashboard' . DS . 'views' . DS . $MasterViewName;
                $CssPath = FALSE;
                $Count = count($CssPaths);
                for ($i = 0; $i < $Count; ++$i) {
                    if (file_exists($CssPaths[$i])) {
                        $CssPath = $CssPaths[$i];
                        break;
                    }
                }
                if ($CssPath !== FALSE) {
                    $CssPath = str_replace(array(PATH_ROOT, DS), array('', '/'), $CssPath);
                    $CssPath = ($WebRoot == '' ? '' : '/' . $WebRoot) . $CssPath;
                }
                $MasterViewPath = FALSE;
                $Count = count($MasterViewPaths);
                for ($i = 0; $i < $Count; ++$i) {
                    if (file_exists($MasterViewPaths[$i])) {
                        $MasterViewPath = $MasterViewPaths[$i];
                        break;
                    }
                }
                if ($MasterViewPath !== FALSE) {
                    include $MasterViewPath;
                    $Master = TRUE;
                }
            }
        }
        if ($DeliveryType != DELIVERY_TYPE_ALL) {
            // This is an ajax request, so dump an error that is more eye-friendly in the debugger
            echo '<h1>FATAL ERROR IN: ', $SenderObject, '.', $SenderMethod, "();</h1>\n<div class=\"AjaxError\">\"" . $SenderMessage . "\"\n";
            if ($SenderCode != '') {
                echo htmlentities($SenderCode, ENT_COMPAT, 'UTF-8') . "\n";
            }
            if (is_array($ErrorLines) && $Line > -1) {
                echo "LOCATION: ", $File, "\n";
            }
            $LineCount = count($ErrorLines);
            $Padding = strlen($Line + 5);
            for ($i = 0; $i < $LineCount; ++$i) {
                if ($i > $Line - 6 && $i < $Line + 4) {
                    if ($i == $Line - 1) {
                        echo '>>';
                    }
                    echo '> ' . str_pad($i + 1, $Padding, " ", STR_PAD_LEFT), ': ', str_replace(array("\n", "\r"), array('', ''), $ErrorLines[$i]), "\n";
                }
            }
            if (is_array($Backtrace)) {
                echo "BACKTRACE:\n";
                $BacktraceCount = count($Backtrace);
                for ($i = 0; $i < $BacktraceCount; ++$i) {
                    if (array_key_exists('file', $Backtrace[$i])) {
                        $File = $Backtrace[$i]['file'] . ' ' . $Backtrace[$i]['line'];
                    }
                    echo '[' . $File . ']', ' ', array_key_exists('class', $Backtrace[$i]) ? $Backtrace[$i]['class'] : 'PHP', array_key_exists('type', $Backtrace[$i]) ? $Backtrace[$i]['type'] : '::', $Backtrace[$i]['function'], '();', "\n";
                }
            }
            echo '</div>';
        } else {
            // If the master view wasn't found, assume a panic state and dump the error.
            if ($Master === FALSE) {
                echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
   <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-ca">
   <head>
      <title>Fatal Error</title>
   </head>
   <body>
      <h1>Fatal Error in ', $SenderObject, '.', $SenderMethod, '();</h1>
      <h2>', $SenderMessage, "</h2>\n";
                if ($SenderCode != '') {
                    echo '<code>', htmlentities($SenderCode, ENT_COMPAT, 'UTF-8'), "</code>\n";
                }
                if (is_array($ErrorLines) && $Line > -1) {
                    echo '<h3><strong>The error occurred on or near:</strong> ', $File, '</h3>
         <pre>';
                    $LineCount = count($ErrorLines);
                    $Padding = strlen($Line + 4);
                    for ($i = 0; $i < $LineCount; ++$i) {
                        if ($i > $Line - 6 && $i < $Line + 4) {
                            echo str_pad($i, $Padding, " ", STR_PAD_LEFT), ': ', htmlentities($ErrorLines[$i], ENT_COMPAT, 'UTF-8');
                        }
                    }
                    echo "</pre>\n";
                }
                echo '<h2>Need Help?</h2>
      <p>If you are a user of this website, you can report this message to a website administrator.</p>
      <p>If you are an administrator of this website, you can get help at the <a href="http://vanillaforums.org/discussions/" target="_blank">Vanilla Community Forums</a>.</p>
      <h2>Additional information for support personnel:</h2>
      <ul>
         <li><strong>Application:</strong> ', APPLICATION, '</li>
         <li><strong>Application Version:</strong> ', APPLICATION_VERSION, '</li>
         <li><strong>PHP Version:</strong> ', PHP_VERSION, '</li>
         <li><strong>Operating System:</strong> ', PHP_OS, "</li>\n";
                if (array_key_exists('SERVER_SOFTWARE', $_SERVER)) {
                    echo '<li><strong>Server Software:</strong> ', $_SERVER['SERVER_SOFTWARE'], "</li>\n";
                }
                if (array_key_exists('HTTP_REFERER', $_SERVER)) {
                    echo '<li><strong>Referer:</strong> ', $_SERVER['HTTP_REFERER'], "</li>\n";
                }
                if (array_key_exists('HTTP_USER_AGENT', $_SERVER)) {
                    echo '<li><strong>User Agent:</strong> ', $_SERVER['HTTP_USER_AGENT'], "</li>\n";
                }
                if (array_key_exists('REQUEST_URI', $_SERVER)) {
                    echo '<li><strong>Request Uri:</strong> ', $_SERVER['REQUEST_URI'], "</li>\n";
                }
                echo '</ul>
   </body>
   </html>';
            }
        }
        // Attempt to log an error message no matter what.
        LogMessage($File, $Line, $SenderObject, $SenderMethod, $SenderMessage, $SenderCode);
    } catch (Exception $e) {
        print get_class($e) . " thrown within the exception handler.<br/>Message: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine();
        exit;
    }
}
示例#8
0
文件: log.lib.php 项目: noikiy/LINJU
 function Write($msg)
 {
     if ($this->config['enable_log']) {
         LogMessage($msg);
     }
 }
 protected function extract_social_network_profile($reply)
 {
     // Check API result.
     //if (is_object ($reply) && property_exists ($reply, 'http_code') && $reply->http_code == 200 && property_exists ($reply, 'http_data'))
     // TODO check if this is sufficient:
     if (property_exists($reply, 'http_data')) {
         // Decode the social network profile Data.
         $social_data = json_decode($reply->http_data);
         // Make sur that the data has beeen decoded properly
         if (is_object($social_data)) {
             // Provider may report an error inside message:
             if (!empty($social_data->response->result->status->flag) && $social_data->response->result->status->code >= 400) {
                 LogMessage(__FILE__, __LINE__, __CLASS__, __METHOD__, $social_data->response->result->status->info . ' (' . $social_data->response->result->status->code . ')');
                 return FALSE;
             }
             // Container for user data
             $data = array();
             // Parse plugin data.
             if (isset($social_data->response->result->data->plugin)) {
                 // Plugin.
                 $plugin = $social_data->response->result->data->plugin;
                 //Add plugin data.
                 $data['plugin_key'] = $plugin->key;
                 $data['plugin_action'] = isset($plugin->data->action) ? $plugin->data->action : null;
                 $data['plugin_operation'] = isset($plugin->data->operation) ? $plugin->data->operation : null;
                 $data['plugin_reason'] = isset($plugin->data->reason) ? $plugin->data->reason : null;
                 $data['plugin_status'] = isset($plugin->data->status) ? $plugin->data->status : null;
             }
             // Do we have a user?
             if (isset($social_data->response->result->data->user) && is_object($social_data->response->result->data->user)) {
                 // User.
                 $user = $social_data->response->result->data->user;
                 //Add user data.
                 $data['user_token'] = $user->user_token;
                 // Do we have an identity ?
                 if (isset($user->identity) && is_object($user->identity)) {
                     // Identity.
                     $identity = $user->identity;
                     // Add identity data.
                     $data['identity_token'] = $identity->identity_token;
                     $data['identity_provider'] = !empty($identity->source->name) ? $identity->source->name : '';
                     $data['user_first_name'] = !empty($identity->name->givenName) ? $identity->name->givenName : '';
                     $data['user_last_name'] = !empty($identity->name->familyName) ? $identity->name->familyName : '';
                     $data['user_formatted_name'] = !empty($identity->name->formatted) ? $identity->name->formatted : '';
                     $data['user_location'] = !empty($identity->currentLocation) ? $identity->currentLocation : '';
                     $data['user_constructed_name'] = trim($data['user_first_name'] . ' ' . $data['user_last_name']);
                     $data['user_picture'] = !empty($identity->pictureUrl) ? $identity->pictureUrl : '';
                     $data['user_thumbnail'] = !empty($identity->thumbnailUrl) ? $identity->thumbnailUrl : '';
                     $data['user_current_location'] = !empty($identity->currentLocation) ? $identity->currentLocation : '';
                     $data['user_about_me'] = !empty($identity->aboutMe) ? $identity->aboutMe : '';
                     $data['user_note'] = !empty($identity->note) ? $identity->note : '';
                     // Birthdate - MM/DD/YYYY
                     if (!empty($identity->birthday) && preg_match('/^([0-9]{2})\\/([0-9]{2})\\/([0-9]{4})$/', $identity->birthday, $matches)) {
                         $data['user_birthdate'] = str_pad($matches[2], 2, '0', STR_PAD_LEFT);
                         $data['user_birthdate'] .= '/' . str_pad($matches[1], 2, '0', STR_PAD_LEFT);
                         $data['user_birthdate'] .= '/' . str_pad($matches[3], 4, '0', STR_PAD_LEFT);
                     } else {
                         $data['user_birthdate'] = '';
                     }
                     // Fullname.
                     if (!empty($identity->name->formatted)) {
                         $data['user_full_name'] = $identity->name->formatted;
                     } elseif (!empty($identity->name->displayName)) {
                         $data['user_full_name'] = $identity->name->displayName;
                     } else {
                         $data['user_full_name'] = $data['user_constructed_name'];
                     }
                     // Preferred Username.
                     if (!empty($identity->preferredUsername)) {
                         $data['user_login'] = $identity->preferredUsername;
                     } elseif (!empty($identity->displayName)) {
                         $data['user_login'] = $identity->displayName;
                     } else {
                         $data['user_login'] = $data['user_full_name'];
                     }
                     // phpBB does not like spaces here
                     $data['user_login'] = str_replace(' ', '', trim($data['user_login']));
                     // Website/Homepage.
                     $data['user_website'] = '';
                     if (!empty($identity->profileUrl)) {
                         $data['user_website'] = $identity->profileUrl;
                     } elseif (!empty($identity->urls[0]->value)) {
                         $data['user_website'] = $identity->urls[0]->value;
                     }
                     // Gender.
                     $data['user_gender'] = '';
                     if (!empty($identity->gender)) {
                         switch ($identity->gender) {
                             case 'male':
                                 $data['user_gender'] = 'm';
                                 break;
                             case 'female':
                                 $data['user_gender'] = 'f';
                                 break;
                         }
                     }
                     // Email Addresses.
                     $data['user_emails'] = array();
                     $data['user_emails_simple'] = array();
                     // Email Address.
                     $data['user_email'] = '';
                     $data['user_email_is_verified'] = FALSE;
                     // Extract emails.
                     if (property_exists($identity, 'emails') && is_array($identity->emails)) {
                         // Loop through emails.
                         foreach ($identity->emails as $email) {
                             // Add to simple list.
                             $data['user_emails_simple'][] = $email->value;
                             // Add to list.
                             $data['user_emails'][] = array('user_email' => $email->value, 'user_email_is_verified' => $email->is_verified);
                             // Keep one, if possible a verified one.
                             if (empty($data['user_email']) || $email->is_verified) {
                                 $data['user_email'] = $email->value;
                                 $data['user_email_is_verified'] = $email->is_verified;
                             }
                         }
                     }
                     // Addresses.
                     $data['user_addresses'] = array();
                     $data['user_addresses_simple'] = array();
                     // Extract entries.
                     if (property_exists($identity, 'addresses') && is_array($identity->addresses)) {
                         // Loop through entries.
                         foreach ($identity->addresses as $address) {
                             // Add to simple list.
                             $data['user_addresses_simple'][] = $address->formatted;
                             // Add to list.
                             $data['user_addresses'][] = array('formatted' => $address->formatted);
                         }
                     }
                     // Phone Number.
                     $data['user_phone_numbers'] = array();
                     $data['user_phone_numbers_simple'] = array();
                     // Extract entries.
                     if (property_exists($identity, 'phoneNumbers') && is_array($identity->phoneNumbers)) {
                         // Loop through entries.
                         foreach ($identity->phoneNumbers as $phone_number) {
                             // Add to simple list.
                             $data['user_phone_numbers_simple'][] = $phone_number->value;
                             // Add to list.
                             $data['user_phone_numbers'][] = array('value' => $phone_number->value, 'type' => isset($phone_number->type) ? $phone_number->type : null);
                         }
                     }
                     // URLs.
                     $data['user_interests'] = array();
                     $data['user_interests_simple'] = array();
                     // Extract entries.
                     if (property_exists($identity, 'interests') && is_array($identity->interests)) {
                         // Loop through entries.
                         foreach ($identity->interests as $interest) {
                             // Add to simple list.
                             $data['user_interests_simple'][] = $interest->value;
                             // Add to list.
                             $data['users_interests'][] = array('value' => $interest->value, 'category' => isset($interest->category) ? $interest->category : null);
                         }
                     }
                     // URLs.
                     $data['user_urls'] = array();
                     $data['user_urls_simple'] = array();
                     // Extract entries.
                     if (property_exists($identity, 'urls') && is_array($identity->urls)) {
                         // Loop through entries.
                         foreach ($identity->urls as $url) {
                             // Add to simple list.
                             $data['user_urls_simple'][] = $url->value;
                             // Add to list.
                             $data['user_urls'][] = array('value' => $url->value, 'type' => isset($url->type) ? $url->type : null);
                         }
                     }
                     // Certifications.
                     $data['user_certifications'] = array();
                     $data['user_certifications_simple'] = array();
                     // Extract entries.
                     if (property_exists($identity, 'certifications') && is_array($identity->certifications)) {
                         // Loop through entries.
                         foreach ($identity->certifications as $certification) {
                             // Add to simple list.
                             $data['user_certifications_simple'][] = $certification->name;
                             // Add to list.
                             $data['user_certifications'][] = array('name' => $certification->name, 'number' => isset($certification->number) ? $certification->number : null, 'authority' => isset($certification->authority) ? $certification->authority : null, 'start_date' => isset($certification->startDate) ? $certification->startDate : null);
                         }
                     }
                     // Recommendations.
                     $data['user_recommendations'] = array();
                     $data['user_recommendations_simple'] = array();
                     // Extract entries.
                     if (property_exists($identity, 'recommendations') && is_array($identity->recommendations)) {
                         // Loop through entries.
                         foreach ($identity->recommendations as $recommendation) {
                             // Add to simple list.
                             $data['user_recommendations_simple'][] = $recommendation->value;
                             // Build data.
                             $data_entry = array('value' => $recommendation->value);
                             // Add recommender
                             if (property_exists($recommendation, 'recommender') && is_object($recommendation->recommender)) {
                                 $data_entry['recommender'] = array();
                                 // Add recommender details
                                 foreach (get_object_vars($recommendation->recommender) as $field => $value) {
                                     $data_entry['recommender'][self::undo_camel_case($field)] = $value;
                                 }
                             }
                             // Add to list.
                             $data['user_recommendations'][] = $data_entry;
                         }
                     }
                     // Accounts.
                     $data['user_accounts'] = array();
                     // Extract entries.
                     if (property_exists($identity, 'accounts') && is_array($identity->accounts)) {
                         // Loop through entries.
                         foreach ($identity->accounts as $account) {
                             // Add to list.
                             $data['user_accounts'][] = array('domain' => isset($account->domain) ? $account->domain : null, 'userid' => isset($account->userid) ? $account->userid : null, 'username' => isset($account->username) ? $account->username : null);
                         }
                     }
                     // Photos.
                     $data['user_photos'] = array();
                     $data['user_photos_simple'] = array();
                     // Extract entries.
                     if (property_exists($identity, 'photos') && is_array($identity->photos)) {
                         // Loop through entries.
                         foreach ($identity->photos as $photo) {
                             // Add to simple list.
                             $data['user_photos_simple'][] = $photo->value;
                             // Add to list.
                             $data['user_photos'][] = array('value' => $photo->value, 'size' => $photo->size);
                         }
                     }
                     // Languages.
                     $data['user_languages'] = array();
                     $data['user_languages_simple'] = array();
                     // Extract entries.
                     if (property_exists($identity, 'languages') && is_array($identity->languages)) {
                         // Loop through entries.
                         foreach ($identity->languages as $language) {
                             // Add to simple list
                             $data['user_languages_simple'][] = $language->value;
                             // Add to list.
                             $data['user_languages'][] = array('value' => $language->value, 'type' => $language->type);
                         }
                     }
                     // Educations.
                     $data['user_educations'] = array();
                     $data['user_educations_simple'] = array();
                     // Extract entries.
                     if (property_exists($identity, 'educations') && is_array($identity->educations)) {
                         // Loop through entries.
                         foreach ($identity->educations as $education) {
                             // Add to simple list.
                             $data['user_educations_simple'][] = $education->value;
                             // Add to list.
                             $data['user_educations'][] = array('value' => $education->value, 'type' => $education->type);
                         }
                     }
                     // Organizations.
                     $data['user_organizations'] = array();
                     $data['user_organizations_simple'] = array();
                     // Extract entries.
                     if (property_exists($identity, 'organizations') && is_array($identity->organizations)) {
                         // Loop through entries.
                         foreach ($identity->organizations as $organization) {
                             // At least the name is required.
                             if (!empty($organization->name)) {
                                 // Add to simple list.
                                 $data['user_organizations_simple'][] = $organization->name;
                                 // Build entry.
                                 $data_entry = array();
                                 // Add all fields.
                                 foreach (get_object_vars($organization) as $field => $value) {
                                     $data_entry[self::undo_camel_case($field)] = $value;
                                 }
                                 // Add to list.
                                 $data['user_organizations'][] = $data_entry;
                             }
                         }
                     }
                 }
             }
             return $data;
         }
     }
     return FALSE;
 }
示例#10
0
<?php

require_once '../config/database.php';
require_once '../function__.php';
session_start();
LogMessage();
if (isset($_POST['name'], $_POST['mail'], $_POST['login'], $_POST['password'])) {
    $verif_user = $bdd->prepare('SELECT login FROM users');
    $verif_user->execute();
    $verif_user->setFetchMode(PDO::FETCH_ASSOC);
    $users_exist = $verif_user->fetchAll();
    LoginIsUnique($_POST['login'], $users_exist);
    FormatMdpIsOk($_POST['password']);
    $mdp = FormatMdpIsOk($_POST['password']);
    $req = $bdd->prepare('INSERT INTO users (name, mail, login, password, date_inscription) VALUES (:name, :mail, :login, :password, :date_inscription)');
    $req->execute(array('name' => $_POST['name'], 'mail' => $_POST['mail'], 'login' => $_POST['login'], 'password' => $mdp, 'date_inscription' => date('Y-m-d H:i:s')));
    $cle = md5(microtime(TRUE) * 100000);
    $login = $_POST['login'];
    $conf_user = $bdd->prepare("UPDATE users SET cle=:cle WHERE login like :login");
    $conf_user->bindParam(':cle', $cle);
    $conf_user->bindParam(':login', $login);
    $conf_user->execute();
    $sujet = "Activer votre compte";
    $entete = "From: \"Camagru\"<*****@*****.**>\n";
    $entete .= "Reply-To: moi@domaine.com\n";
    $entete .= "Content-Type: text/html; charset=\"iso-8859-1\"";
    $message = 'Bienvenue sur Camagru ' . $_POST['name'] . ',<br><br> Pour activer votre compte, merci de cliquer sur ce <a href="https://camagru42/activation.php?login='******'login']) . '&cle=' . urlencode($cle) . '">lien</a><br>
  <br>
  <br>
  --------------------------------------<br>
  Ceci est un mail automatique, merci de ne pas y repondre.';
示例#11
0
文件: set.mod.php 项目: noikiy/LINJU
 function RenderBasic($msg = '')
 {
     LogMessage('RrenderBasic Action in');
     $this->GotoLogin();
     $uid = $this->User['uid'];
     $this->User = $this->UserLogic->GetUser($uid);
     $year = array();
     $cYear = date('Y');
     for ($i = 1950; $i <= $cYear; $i++) {
         $year["'" . $i . "'"] = $i;
     }
     arsort($year, SORT_NUMERIC);
     $month = array();
     for ($j = 1; $j <= 12; $j++) {
         if ($j >= 10) {
             $month["'" . $j . "'"] = $j;
         } else {
             $month["'0" . $j . "'"] = $j;
         }
     }
     if ($this->User && is_array($this->User) && count($this->User) > 0) {
         if (isset($this->User['birthday']) && $this->User['birthday'] != '') {
             $myyear = date("Y", strtotime($this->User['birthday']));
             $mymonth = date("m", strtotime($this->User['birthday']));
             $myday = date("d", strtotime($this->User['birthday']));
         }
     }
     $gendar = array();
     $gendar['0'] = "保密";
     $gendar['1'] = "男";
     $gendar['2'] = "女";
     $years = $this->FormHandler->Form_Options($year, "'{$myyear}'");
     $months = $this->FormHandler->Form_Options($month, "'{$mymonth}'");
     $days = $this->GetDays($myyear, $mymonth);
     $days = $this->FormHandler->Form_Options($days, "'{$myday}'");
     $this->TemplateHandler->AssignValue('save_result', $msg);
     $this->TemplateHandler->AssignValue('user', $this->User);
     $this->TemplateHandler->AssignValue('title', "账户设置" . $this->Config['sitetitle']);
     $this->TemplateHandler->AssignValue('email', MEMBER_EMAIL);
     $this->TemplateHandler->AssignValue('username', MEMBER_NAME);
     $this->TemplateHandler->AssignValue('gendar', $this->FormHandler->Form_Options($gendar, trim($this->User['gendar'])));
     $this->TemplateHandler->AssignValue('years', $years);
     $this->TemplateHandler->AssignValue('months', $months);
     $this->TemplateHandler->AssignValue('days', $days);
     $provinces = '';
     $cities = '';
     $districts = '';
     $streets = '';
     $provinces = $this->DistrictLogic->GetDistrictKeyValuePair('', 1, 0);
     if (trim($this->User['province']) != trim($this->User['city'])) {
         $cities = $this->DistrictLogic->GetDistrictKeyValuePair('', 0, trim($this->User['province']));
     }
     if ($this->User['city'] != '') {
         $districts = $this->DistrictLogic->GetDistrictKeyValuePair('', 0, $this->User['city']);
     }
     if ($this->User['area'] != '') {
         $streets = $this->DistrictLogic->GetDistrictKeyValuePair('', 0, $this->User['area']);
     }
     $this->TemplateHandler->AssignValue('provinces', $this->FormHandler->Form_Options($provinces, "'" . $this->User['province'] . "'"));
     if ($cities == '') {
         $this->TemplateHandler->AssignValue('cities', '');
     } else {
         $this->TemplateHandler->AssignValue('cities', $this->FormHandler->Form_Options($cities, "'" . $this->User['city'] . "'"));
     }
     $this->TemplateHandler->AssignValue('districts', $this->FormHandler->Form_Options($districts, "'" . $this->User['area'] . "'"));
     $this->TemplateHandler->AssignValue('streets', $this->FormHandler->Form_Options($streets, "'" . $this->User['street'] . "'"));
     $this->TemplateHandler->AssignValue('title', '账户设置' . $this->Config['sitetitle']);
     $this->TemplateHandler->Display('account_basic_info.html');
 }
示例#12
0
 function _SendNotificationAcknowledgment()
 {
     $acknowledgement = "<notification-acknowledgment xmlns=\"" . $GLOBALS["schema_url"] . "\"/>";
     return $acknowledgment;
     // Log <notification-acknowledgment> was at least called from cake controller
     LogMessage($GLOBALS["logfile"], $acknowledgment);
 }
示例#13
0
/**
* EncodeCookie
* Takes a base cookie, adds the extra information so we can track it back to the origin more consistently.
*
* @param string Cookie Type (referrer, search, ppc, campaign)
* @param int The id of the cookie type.
*
* @return string The new encoded string.
*/
function EncodeCookie($cookietype = 'referrer', $id = 0)
{
    global $ip, $userid, $trackpoint_sessionid;
    $cookie = array('type' => $cookietype, 'id' => $id);
    $cookieid = md5(uniqid(rand(), true));
    $cookieid .= '-' . base64_encode(serialize($cookie));
    $cookieid = str_replace('-', '____', base64_encode($cookieid));
    LogMessage(__FILE__, __LINE__, $ip, $trackpoint_sessionid, 'encoding cookie. cookie type: ' . $cookietype . '; id: ' . $id . '; encoded cookieid: ' . $cookieid, $userid);
    return $cookieid;
}
示例#14
0
/**
 * A custom error handler that displays much more, very useful information when
 * errors are encountered in Garden.
 *
 * @param int The level of the error raised.
 * @param string The error message.
 * @param string The filename that the error was raised in.
 * @param string The line number the error was raised at.
 * @param string An array of every variable that existed in the scope the error was triggered in.
 */
function ErrorHandler($ErrorNumber, $Message, $File, $Line, $Arguments)
{
    // Ignore errors that have a @ before them (ie. @function();)
    if (error_reporting() == 0) {
        return FALSE;
    }
    // Clean the output buffer in case an error was encountered in-page.
    // ob_clean();
    $SenderMessage = $Message;
    $SenderObject = 'PHP';
    $SenderMethod = 'ErrorHandler';
    $SenderCode = FALSE;
    $MessageInfo = explode('|', $Message);
    $MessageCount = count($MessageInfo);
    if ($MessageCount == 4) {
        list($SenderMessage, $SenderObject, $SenderMethod, $SenderCode) = $MessageInfo;
    } else {
        if ($MessageCount == 3) {
            list($SenderMessage, $SenderObject, $SenderMethod) = $MessageInfo;
        }
    }
    $SenderMessage = strip_tags($SenderMessage);
    $Master = FALSE;
    // The parsed master view
    $CssPath = FALSE;
    // The web-path to the css file
    $ErrorLines = FALSE;
    // The lines near the error's line #
    $DeliveryType = 1;
    if (array_key_exists('DeliveryType', $_POST)) {
        $DeliveryType = $_POST['DeliveryType'];
    } else {
        if (array_key_exists('DeliveryType', $_GET)) {
            $DeliveryType = $_GET['DeliveryType'];
        }
    }
    // Make sure all of the required custom functions and variables are defined.
    $PanicError = FALSE;
    // Should we just dump a message and forget about the master view?
    if (!defined('DS')) {
        $PanicError = TRUE;
    }
    if (!defined('PATH_ROOT')) {
        $PanicError = TRUE;
    }
    if (!defined('APPLICATION')) {
        define('APPLICATION', 'Garden');
    }
    if (!defined('APPLICATION_VERSION')) {
        define('APPLICATION_VERSION', 'Unknown');
    }
    $WebRoot = class_exists('Url', FALSE) ? Gdn_Url::WebRoot() : '';
    if ($PanicError === FALSE) {
        // See if we can get the file that caused the error
        if (is_string($File) && is_numeric($ErrorNumber)) {
            $ErrorLines = @file($File);
        }
        // If this error was encountered during an ajax request, don't bother gettting the css or theme files
        if ($DeliveryType == 1) {
            $CssPaths = array();
            // Potential places where the css can be found in the filesystem.
            $MasterViewPaths = array();
            if (class_exists('Gdn', FALSE)) {
                $CurrentTheme = '';
                // The currently selected theme
                $CurrentTheme = Gdn::Config('Garden.Theme', '');
                if ($CurrentTheme != '') {
                    // Look for CSS in the theme folder:
                    $CssPaths[] = PATH_THEMES . DS . $CurrentTheme . DS . 'design' . DS . 'error.css';
                    // Look for Master View in the theme folder:
                    $MasterViewPaths[] = PATH_THEMES . DS . $CurrentTheme . DS . 'views' . DS . 'error.master';
                }
            }
            // Look for CSS in the garden design folder.
            $CssPaths[] = PATH_APPLICATIONS . DS . 'garden' . DS . 'design' . DS . 'error.css';
            // Look for Master View in the garden view folder.
            $MasterViewPaths[] = PATH_APPLICATIONS . DS . 'garden' . DS . 'views' . DS . 'error.master';
            $CssPath = FALSE;
            $Count = count($CssPaths);
            for ($i = 0; $i < $Count; ++$i) {
                if (file_exists($CssPaths[$i])) {
                    $CssPath = $CssPaths[$i];
                    break;
                }
            }
            if ($CssPath !== FALSE) {
                $CssPath = str_replace(array(PATH_ROOT, DS), array('', '/'), $CssPath);
                $CssPath = ($WebRoot == '' ? '' : '/' . $WebRoot) . $CssPath;
            }
            $MasterViewPath = FALSE;
            $Count = count($MasterViewPaths);
            for ($i = 0; $i < $Count; ++$i) {
                if (file_exists($MasterViewPaths[$i])) {
                    $MasterViewPath = $MasterViewPaths[$i];
                    break;
                }
            }
            if ($MasterViewPath !== FALSE) {
                include $MasterViewPath;
                $Master = TRUE;
            }
        }
    }
    if ($DeliveryType != 1) {
        // This is an ajax request, so dump an error that is more eye-friendly in the debugger
        echo 'FATAL ERROR IN: ', $SenderObject, '.', $SenderMethod, "();\n\"" . $SenderMessage . "\"\n";
        if ($SenderCode != '') {
            echo htmlentities($SenderCode, ENT_COMPAT, 'UTF-8') . "\n";
        }
        if (is_array($ErrorLines) && $Line > -1) {
            echo "LOCATION: ", $File, "\n";
        }
        $LineCount = count($ErrorLines);
        $Padding = strlen($Line + 5);
        for ($i = 0; $i < $LineCount; ++$i) {
            if ($i > $Line - 6 && $i < $Line + 4) {
                if ($i == $Line - 1) {
                    echo '>>';
                }
                echo '> ' . str_pad($i + 1, $Padding, " ", STR_PAD_LEFT), ': ', str_replace(array("\n", "\r"), array('', ''), $ErrorLines[$i]), "\n";
            }
        }
        $Backtrace = debug_backtrace();
        if (is_array($Backtrace)) {
            echo "BACKTRACE:\n";
            $BacktraceCount = count($Backtrace);
            for ($i = 0; $i < $BacktraceCount; ++$i) {
                if (array_key_exists('file', $Backtrace[$i])) {
                    $File = $Backtrace[$i]['file'] . ' ' . $Backtrace[$i]['line'];
                }
                echo '[' . $File . ']', ' ', array_key_exists('class', $Backtrace[$i]) ? $Backtrace[$i]['class'] : 'PHP', array_key_exists('type', $Backtrace[$i]) ? $Backtrace[$i]['type'] : '::', $Backtrace[$i]['function'], '();', "\n";
            }
        }
    } else {
        // If the master view wasn't found, assume a panic state and dump the error.
        if ($Master === FALSE) {
            echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-ca">
<head>
   <title>Fatal Error</title>
</head>
<body>
   <h1>Fatal Error in ', $SenderObject, '.', $SenderMethod, '();</h1>
   <h2>', $SenderMessage, "</h2>\n";
            if ($SenderCode != '') {
                echo '<code>', htmlentities($SenderCode, ENT_COMPAT, 'UTF-8'), "</code>\n";
            }
            if (is_array($ErrorLines) && $Line > -1) {
                echo '<h3><strong>The error occurred on or near:</strong> ', $File, '</h3>
      <pre>';
                $LineCount = count($ErrorLines);
                $Padding = strlen($Line + 4);
                for ($i = 0; $i < $LineCount; ++$i) {
                    if ($i > $Line - 6 && $i < $Line + 4) {
                        echo str_pad($i, $Padding, " ", STR_PAD_LEFT), ': ', htmlentities($ErrorLines[$i], ENT_COMPAT, 'UTF-8');
                    }
                }
                echo "</pre>\n";
            }
            echo '<h2>Need Help?</h2>
   <p>If you are a user of this website, you can report this message to a website administrator.</p>
   <p>If you are an administrator of this website, you can get help at the <a href="http://lussumo.com/community/" target="_blank">Lussumo Community Forums</a>.</p>
   <h2>Additional information for support personnel:</h2>
   <ul>
      <li><strong>Application:</strong> ', APPLICATION, '</li>
      <li><strong>Application Version:</strong> ', APPLICATION_VERSION, '</li>
      <li><strong>PHP Version:</strong> ', PHP_VERSION, '</li>
      <li><strong>Operating System:</strong> ', PHP_OS, "</li>\n";
            if (array_key_exists('HTTP_REFERER', $_SERVER)) {
                echo '<li><strong>Referer:</strong> ', $_SERVER['HTTP_REFERER'], "</li>\n";
            }
            if (array_key_exists('HTTP_USER_AGENT', $_SERVER)) {
                echo '<li><strong>User Agent:</strong> ', $_SERVER['HTTP_USER_AGENT'], "</li>\n";
            }
            if (array_key_exists('REQUEST_URI', $_SERVER)) {
                echo '<li><strong>Request Uri:</strong> ', $_SERVER['REQUEST_URI'], "</li>\n";
            }
            echo '</ul>
</body>
</html>';
        }
    }
    // Attempt to log an error message no matter what.
    LogMessage($File, $Line, $SenderObject, $SenderMethod, $SenderMessage, $SenderCode);
    die;
}
示例#15
0
 function UploadImage()
 {
     LogMessage("UploadImage");
     $this->GotoLogin();
     $imgId = $this->ImgLogic->AddNewImage();
     $this->Logger->Write($imgId);
     if (!$imgId || $imgId <= 0) {
         echo "0";
         return;
     }
     $uid = $this->User['uid'];
     $this->Logger->Write($uid);
     $this->User = $this->UserLogic->GetUser($uid);
     $IoHandler = new IoHandler();
     $item = $this->Post['item'] ? $this->Post['item'] : $this->Get['item'];
     $itemId = $this->Post['itemId'] ? $this->Post['itemId'] : $this->Get['itemId'];
     $imgtype = $this->Post['imgtype'] ? $this->Post['imgtype'] : $this->Get['imgtype'];
     $name = $_FILES['Filedata']['name'];
     $this->Logger->Write($name);
     $id = $imgId;
     $subfolder = 'topic';
     if ($item != '') {
         $subfolder = $item;
     } else {
     }
     $rpath = 'images/' . $subfolder . '/' . face_path($id);
     $image_path = __WEB_ROOT . '/' . $rpath;
     $image_name = $id . '_o.jpg';
     $image_file = $rpath . $image_name;
     $image_file_s = $rpath . $id . '_s.jpg';
     $image_file_t = $rpath . $id . '_t.jpg';
     $image_file_p = $rpath . $id . '_p.jpg';
     $image_file_tp = $rpath . $id . '_tp.jpg';
     $image_file_avt = '';
     $pic_field = 'Filedata';
     $UploadHandler = new UploadHandler($_FILES, $image_path, $pic_field, true, false);
     $UploadHandler->setMaxSize(3072);
     $UploadHandler->setNewName($image_name);
     $ret = $UploadHandler->doUpload();
     if (!$ret) {
         $rets = $UploadHandler->getError();
         $ret = $rets ? implode(" ", (array) $rets) : 'image upload is invalid';
         $r = array('error' => $ret, 'code' => -5);
         if ($r['code'] < 0 && $r['error']) {
             $this->ImgLogic->DeleteImage($imgId);
             $error = $UploadHandler->getError();
             $result = array();
             $result['status'] = "failed";
             $result['message'] = urlencode($error);
             echo urldecode(json_encode($result));
             exit;
         }
     }
     $image_type = $info['type'];
     list($image_width, $image_height, $image_type, $image_attr) = getimagesize($image_file);
     //this file used for topic list
     $Images = new ImagesHandler('Filedata');
     $Images->item_type = $item;
     $w = 120;
     $h = 120;
     if ($item == 'event') {
         $h = 105;
     }
     //if($image_width>1500){
     //	LogMessage('resize to 1500 size');
     //	resizeimage($image_file, $image_file_tp,1500,0,true);
     //	LogMessage('resize to 1500 size done');
     //	$image_file=$image_file_tp;
     //	list($image_width,$image_height,$image_type,$image_attr) = getimagesize($image_file_tp);
     //}
     LogMessage("uploaed completed,going to resize image");
     if ($image_width == $image_height) {
         LogMessage("Width is equal to height");
         $resize = $Images->thumb($image_file, false, 1, $rpath . $id, 0, 0, $image_width, $image_height, $w, $h, 'jpg');
     } else {
         if ($image_height > $image_width) {
             LogMessage("Width is less than height");
             $resize = $Images->thumb($image_file, false, 1, $rpath . $id, 0, 0, $image_width, $image_width, $w, $h, 'jpg');
         } else {
             if ($image_height < $image_width) {
                 LogMessage("Width is larger than height");
                 $resize = $Images->thumb($image_file, false, 1, $rpath . $id, 0, 0, $image_height, $image_height, $w, $h, 'jpg');
             }
         }
     }
     if (!$resize) {
         $result['status'] = "failed";
         $result['message'] = "图片上传失败";
         $this->ImgLogic->DeleteImage($imgId);
         $IoHandler->DeleteFile($image_file);
         echo json_encode($result);
         exit;
     }
     if ($this->CallType != 'open') {
         //reduce the photo quality, but keep photo original width and height
         resizeimage($image_file, $image_file_t, 1024, 0, true);
     } else {
         copy($image_file, $image_file_t);
     }
     if ($image_file_avt && $image_file_avt != '') {
         resizeimage($image_file, $image_file_avt, 50, 50, false);
     }
     //this file used for photo list
     resizeimage($image_file, $image_file_p, 200, 0, true);
     //update image table
     $datalist = array();
     $datalist['name'] = $name;
     $datalist['photo'] = $image_file_s;
     list($tWidth, $tHeight, $tType, $tAttr) = getimagesize($image_file_t);
     $datalist['width'] = $tWidth;
     $datalist['height'] = $tHeight;
     if ($item != '' && $itemId != '') {
         $datalist['item'] = $item;
         $datalist['itemid'] = $itemId;
     }
     $this->ImgLogic->UpdateImage($datalist, $imgId);
     $result = array();
     $result['status'] = "ok";
     $result['message'] = "图片上传成功";
     $item = array();
     $item['item_id'] = $imgId;
     $item['item_type'] = 'image';
     $item['item_src'] = $image_file_s;
     $item['item_name'] = $name;
     $item['item_width'] = $tWidth;
     $item['item_height'] = $tHeight;
     $result['item'] = $item;
     $IoHandler->DeleteFile($image_file);
     echo json_encode($result);
 }
示例#16
0
 function doUpload()
 {
     if (false == is_writable($this->_path)) {
         $this->_setError(504);
         return false;
     }
     if (false == isset($this->_file[$this->_field])) {
         $this->_setError(501);
         return false;
     }
     $name = $this->_file[$this->_field]['name'];
     $size = $this->_file[$this->_field]['size'];
     $type = $this->_file[$this->_field]['type'];
     $temp = $this->_file[$this->_field]['tmp_name'];
     $type = preg_replace("/^(.+?);.*\$/", "\\1", $type);
     $error = $this->_file[$this->_field]['error'];
     LogMessage($error);
     if (false == $name || $name == 'none') {
         $this->_setError(501);
         return false;
     }
     $this->_ext = strtolower(end(explode('.', $name)));
     if (false == $this->_ext) {
         $this->_setError(502);
         return false;
     }
     if (false == $this->_image) {
         if (false == $this->_attach) {
             if (false == in_array($this->_ext, array_merge($this->_image_types, $this->_ext_types))) {
                 $this->_setError(502);
                 return false;
             }
         } else {
             if (false == in_array($this->_ext, $this->_attach_types)) {
                 $this->_setError(508);
                 return false;
             }
         }
     } else {
         if (false == in_array($this->_ext, $this->_image_types)) {
             $this->_setError(507);
             return false;
         }
         if (function_exists('exif_imagetype') && !exif_imagetype($temp)) {
             $this->_setError(507);
             return false;
         } elseif (function_exists('getimagesize') && !getimagesize($temp)) {
             $this->_setError(507, ',size问题');
             return false;
         }
     }
     LogMessage('image size:' . $size);
     if ($this->_max_size && $this->_max_size * 1024 < $size) {
         $this->_setError(503);
         return false;
     }
     if (false == $this->_new_name) {
         $this->_save_name = $name;
         $full_path = $this->_path . $name;
     } else {
         $this->_save_name = $this->_new_name;
         $full_path = $this->_path . $this->_save_name;
     }
     LogMessage('image full path:' . $full_path);
     if (false == move_uploaded_file($temp, $full_path)) {
         if (false == copy($temp, $full_path)) {
             $this->_setError(505);
             return false;
         } else {
             LogMessage($full_path . ' is successfully moved');
         }
     } else {
         LogMessage($full_path . ' is successfully moved');
     }
     $this->_setError(506);
     return true;
 }
示例#17
0
 function Update($dataList, $condition = NULL, $table)
 {
     if (($sql = $this->BuildUpdate($table, $dataList, $condition, false)) == "") {
         LogMessage('MySqlUtility.Update--Failed to build SQL Text.');
         return false;
     }
     LogMessage($sql);
     if ($this->query($sql)) {
         return $this->AffectedRows();
     } else {
         return false;
     }
 }
示例#18
0
文件: Images.php 项目: noikiy/LINJU
 /**
 +----------------------------------------------------------
 * 生成缩略图
 +----------------------------------------------------------
 * @static
 * @access public
 +----------------------------------------------------------
 * @param string $image  原图
 * @param string $type 图像格式
 * @param string $thumbname 缩略图文件名
 * @param string $maxWidth  宽度
 * @param string $maxHeight  高度
 * @param string $position 缩略图保存目录
 * @param boolean $interlace 启用隔行扫描
 * @param boolean $is_save 是否保留原图
 +----------------------------------------------------------
 * @return void
 +----------------------------------------------------------
 */
 function thumb($image, $is_save = true, $suofang = 0, $image_path_prefix = '', $x = '', $y = '', $w = '', $h = '', $tw = '', $th = '', $type = '', $maxWidth = 500, $maxHeight = 500, $interlace = true)
 {
     // 获取原图信息
     $info = $this->getImageInfo($image);
     if ($info !== false) {
         $srcWidth = $info['width'];
         $srcHeight = $info['height'];
         $type = empty($type) ? $info['type'] : $type;
         $type = strtolower($type);
         $interlace = $interlace ? 1 : 0;
         unset($info);
         if ($suofang == 1) {
             $width = $srcWidth;
             $height = $srcHeight;
         } else {
             $scale = min($maxWidth / $srcWidth, $maxHeight / $srcHeight);
             // 计算缩放比例
             if ($scale >= 1) {
                 // 超过原图大小不再缩略
                 $width = $srcWidth;
                 $height = $srcHeight;
             } else {
                 // 缩略图尺寸
                 $width = (int) ($srcWidth * $scale);
                 //147
                 $height = (int) ($srcHeight * $scale);
                 //199
             }
         }
         // 载入原图
         $createFun = 'ImageCreateFrom' . ($type == 'jpg' ? 'jpeg' : $type);
         $srcImg = $createFun($image);
         LogMessage("original image is successfully loaded");
         //创建缩略图
         if ($type != 'gif' && function_exists('imagecreatetruecolor')) {
             try {
                 $thumbImg = imagecreatetruecolor($width, $height);
                 LogMessage("thumbImg is created");
             } catch (Exception $e) {
                 LogMessage($e->getMessage());
                 return false;
             }
         } else {
             $thumbImg = imagecreate($width, $height);
             LogMessage("thumbImg is created");
         }
         // 复制图片
         if (function_exists("ImageCopyResampled")) {
             imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
             LogMessage("thumbImg is loaded from original");
         } else {
             imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
             LogMessage("thumbImg is loaded from original");
         }
         if ('gif' == $type || 'png' == $type) {
             //imagealphablending($thumbImg, false);//取消默认的混色模式
             //imagesavealpha($thumbImg,true);//设定保存完整的 alpha 通道信息
             $background_color = imagecolorallocate($thumbImg, 0, 255, 0);
             //  指派一个绿色
             imagecolortransparent($thumbImg, $background_color);
             //  设置为透明色,若注释掉该行则输出绿色的图
         }
         // 对jpeg图形设置隔行扫描
         if ('jpg' == $type || 'jpeg' == $type) {
             imageinterlace($thumbImg, $interlace);
         }
         //$gray=ImageColorAllocate($thumbImg,255,0,0);
         //ImageString($thumbImg,2,5,5,"ThinkPHP",$gray);
         // 生成图片
         $imageFun = 'image' . ($type == 'jpg' ? 'jpeg' : $type);
         $length = strlen("00." . $type) * -1;
         $_type = substr($image, -4);
         $length = $type != $_type ? $length + 1 : $length;
         //裁剪
         if ($suofang == 1) {
             if (!$x || $x == '') {
                 $x = $_POST['x'];
             }
             if (!$y || $y == '') {
                 $y = $_POST['y'];
             }
             if (!$w || $w == '') {
                 $w = $_POST['w'];
             }
             if (!$h || $h == '') {
                 $h = $_POST['h'];
             }
             if ($this->item_type == 'user' || $this->item_type == 'building') {
                 $thumbname01 = substr_replace($image, "01." . $type, $length);
                 //大头像
                 $thumbname02 = substr_replace($image, "02." . $type, $length);
                 //小头像
                 if ($image_path_prefix != '') {
                     //$thumbname01
                     $thumbname01 = $image_path_prefix . "_p." . $type;
                     $thumbname02 = $image_path_prefix . "_s." . $type;
                 }
                 $imageFun($thumbImg, $thumbname01, 100);
                 $imageFun($thumbImg, $thumbname02, 100);
                 switch ($this->item_type) {
                     case "user":
                         $thumbImg01 = imagecreatetruecolor(180, 180);
                         imagecopyresampled($thumbImg01, $thumbImg, 0, 0, $x, $y, 180, 180, $w, $h);
                         break;
                     case "building":
                         $thumbImg01 = imagecreatetruecolor(120, 90);
                         imagecopyresampled($thumbImg01, $thumbImg, 0, 0, $x, $y, 120, 90, $w, $h);
                         break;
                 }
                 //小头像统一50*50
                 $thumbImg02 = imagecreatetruecolor(50, 50);
                 imagecopyresampled($thumbImg02, $thumbImg, 0, 0, $x, $y, 50, 50, $w, $h);
                 $imageFun($thumbImg01, $thumbname01, 100);
                 $imageFun($thumbImg02, $thumbname02, 100);
                 //				unlink($image);
                 imagedestroy($thumbImg01);
                 imagedestroy($thumbImg02);
                 imagedestroy($thumbImg);
                 imagedestroy($srcImg);
                 return array('big' => $thumbname01, 'small' => $thumbname02);
                 //返回包含大小头像路径的数组
             } else {
                 if ($this->item_type == 'topic' || $this->item_type == 'event') {
                     //裁剪topic 上涨的图片
                     $thumbname01 = $image_path_prefix . "_s." . $type;
                     $imageFun($thumbImg, $thumbname01, 100);
                     $thumbImg01 = imagecreatetruecolor($tw, $th);
                     imagecopyresampled($thumbImg01, $thumbImg, 0, 0, $x, $y, $tw, $th, $w, $h);
                     $imageFun($thumbImg01, $thumbname01, 100);
                     imagedestroy($thumbImg01);
                     imagedestroy($thumbImg);
                     imagedestroy($srcImg);
                     return $thumbname01;
                 }
             }
         } else {
             if ($is_save == false) {
                 //缩略图覆盖原图,缩略图的路径还是原图路径
                 $imageFun($thumbImg, $image, 100);
             } else {
                 $thumbname03 = substr_replace($image, "03." . $type, $length);
                 //缩略图与原图同时存在,
                 $imageFun($thumbImg, $thumbname03, 100);
                 imagedestroy($thumbImg);
                 imagedestroy($srcImg);
                 return $thumbname03;
                 //返回缩略图的路径,字符串
             }
         }
     }
     return false;
 }
示例#19
0
            $qry .= " searchid='" . $primaryid . "'";
        } else {
            $qry .= " searchenginename='" . addslashes($cookiefrom) . "' AND keywords='" . addslashes($cookiedetails) . "' AND cookieid='" . addslashes($cookieid) . "'";
        }
        break;
    default:
        if ($cookieid != 'unknowncookie') {
            $qry = "UPDATE " . TRACKPOINT_TABLEPREFIX . "referrers SET hasconversion=hasconversion+1, convtime='" . $time . "', amount=amount+" . (double) $amt . " WHERE ";
            if ($primaryid) {
                $qry .= " referrerid='" . $primaryid . "'";
            } else {
                $qry .= " domain='" . addslashes($cookiefrom) . "' AND url='" . addslashes($cookiedetails) . "' AND cookieid='" . addslashes($cookieid) . "'";
            }
        } else {
            $id = $db->NextId(TRACKPOINT_TABLEPREFIX . 'referrers_sequence');
            $qry = "INSERT INTO " . TRACKPOINT_TABLEPREFIX . "referrers(referrerid, domain, url, currtime, ip, landingpage, cookieid, userid, hasconversion, amount, convtime) VALUES ('" . $id . "', '', '', '" . $time . "', '" . addslashes($ip) . "', '', 'unknowncookie', '" . $userid . "', 1, '" . $amt . "', '" . $time . "')";
        }
}
/**
* why do we need to restrict the userid as well?
* If we have different conversions set up on the same site as different users (one tracking newsletter signups, the other tracking product purchases), then even though the cookie may match and the record may match, it might not be for the right user.
*/
if ($cookieid != 'unknowncookie') {
    $qry .= " AND userid='" . $userid . "'";
}
LogMessage(__FILE__, __LINE__, $ip, $trackpoint_sessionid, 'updating original visit: ' . $qry, $userid, 'conversion');
$db->Query($qry);
if (TRACKPOINT_DELETECOOKIE == 1) {
    LogMessage(__FILE__, __LINE__, $ip, $trackpoint_sessionid, 'deleting cookie', $userid, 'conversion');
    $TPUtil->DelTPCookie(TRACKPOINT_COOKIE_NAME, $cookieid);
}