public function test_backup_with_errors()
 {
     $this->assertTrue($this->backup->backup());
     $this->assertFileExists($this->backup->get_backup_filepath());
     $this->backup->error(get_class($this->backup), 'foobar');
     $this->assertFalse($this->backup->verify_backup());
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function request($uri, $method = 'GET', $parameters = [], $headers = [])
 {
     $this->requestArguments = ['uri' => $uri, 'method' => $method, 'parameters' => $parameters, 'headers' => $headers];
     $this->requestHeader = array_merge($this->requestHeader, $headers);
     $response = null;
     try {
         if ('GET' == $method) {
             $response = $this->client->get($uri, ['query' => $parameters, 'headers' => $this->requestHeader]);
         }
         if ('POST' == $method) {
             $response = $this->client->post($uri, ['form_params' => $parameters, 'headers' => $this->requestHeader]);
         }
     } catch (\Exception $e) {
         $response = $e->getResponse();
         $this->responseClientError = $e->getMessage();
     }
     if (!$this->responseClientError) {
         $this->responseBody = $response->getBody();
         $this->responseHttpCode = $response->getStatusCode();
         $this->responseHeader = $response->getHeaders();
     }
     if ($this->logger) {
         $this->logger->debug("HttpClient\\Guzzle::request( {$uri}, {$method} ), response:", $this->getResponse());
         if ($this->responseClientError) {
             $this->logger->error("HttpClient\\Guzzle::request( {$uri}, {$method} ), GuzzleHttp error: ", [$this->responseClientError]);
         }
     }
     return $this->responseBody;
 }
Example #3
0
    /**
     * 处理错误信息
     *
     * @access  private
     * @param   string      $query_item     SQL查询项
     * @return  boolean     成功返回true,失败返回false。
     */
    function handle_error($query_item)
    {
        $mysql_error = 'ERROR NO: ' . $this->db->errno()
                    . "\r\nERROR MSG: " . $this->db->error();

        $error_str = "SQL Error:\r\n " . $mysql_error
                . "\r\n\r\n"
                . "Query String:\r\n ". $query_item
                . "\r\n\r\n"
                . "File Path:\r\n ". $this->current_file
                . "\r\n\r\n\r\n\r\n";

        /* 过滤一些错误 */
        if (!in_array($this->db->errno(), $this->ignored_errors))
        {
            $this->error = $error_str;
        }

        if ($this->log_path)
        {
            $f = @fopen($this->log_path, 'ab+');
            if (!$f)
            {
                return false;
            }
            if (!@fwrite($f, $error_str))
            {
                return false;
            }
        }

        return true;
    }
Example #4
0
 /**
  * Запуск задачи на выполнение
  *
  * @param bool $force
  * @throws Exception
  * @return mixed
  */
 public function run($force = false)
 {
     if (!$this->_Client->runTasks()) {
         throw new Exception('Не удалось запустить выполнение задач: ' . $this->_Client->error());
     }
     return $this->_config['background'] || $force ? true : $this->_out;
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function request($uri, $method = 'GET', $parameters = [], $headers = [])
 {
     $this->requestArguments = ['uri' => $uri, 'method' => $method, 'parameters' => $parameters, 'headers' => $headers];
     $curl = curl_init();
     if ('GET' == $method) {
         unset($this->curlOptions[CURLOPT_POST]);
         unset($this->curlOptions[CURLOPT_POSTFIELDS]);
         $uri = $uri . (strpos($uri, '?') ? '&' : '?') . http_build_query($parameters);
     }
     if ('POST' == $method) {
         $this->curlOptions[CURLOPT_POST] = true;
         $this->curlOptions[CURLOPT_POSTFIELDS] = $parameters;
     }
     $this->requestHeader = array_merge($this->requestHeader, $headers);
     $this->requestArguments['headers'] = $this->requestHeader;
     $this->curlOptions[CURLOPT_URL] = $uri;
     $this->curlOptions[CURLOPT_HTTPHEADER] = $this->prepareRequestHeaders();
     $this->curlOptions[CURLOPT_HEADERFUNCTION] = [$this, 'fetchResponseHeader'];
     foreach ($this->curlOptions as $opt => $value) {
         curl_setopt($curl, $opt, $value);
     }
     $response = curl_exec($curl);
     $this->responseBody = $response;
     $this->responseHttpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     $this->responseClientError = curl_error($curl);
     $this->responseClientInfo = curl_getinfo($curl);
     if ($this->logger) {
         $this->logger->debug("HttpClient\\Curl::request( {$uri}, {$method} ), response:", $this->getResponse());
         if (false === $response) {
             $this->logger->error("HttpClient\\Curl::request( {$uri}, {$method} ), curl_exec error: ", [$this->responseClientError]);
         }
     }
     curl_close($curl);
     return $this->responseBody;
 }
Example #6
0
 /**
  * Set pageno
  *
  * @param int $pageno Pagenumber to use
  */
 function setPageno($pageno)
 {
     $pageno = (int) $pageno - 1;
     if ($pageno < 0 || $pageno >= $this->getPageCount()) {
         $this->fpdi->error('Pagenumber is wrong!');
     }
     $this->pageno = $pageno;
 }
Example #7
0
 public function testFormErrorWithRecordAndSpecificKey()
 {
     $record = new Record();
     $record->errors(array('name' => array('Please enter a name')));
     $this->form->create($record);
     $result = $this->form->error('name', 0);
     $this->assertTags($result, array('div' => array('class' => 'error'), 'Please enter a name', '/div'));
 }
Example #8
0
 /**
  * validates the data passed to the setValue method
  *
  * @access private
  * @return boolean, status of the validation
  */
 private function validate($name, $value, $rules)
 {
     try {
         $this->_validator->reset()->setName($name)->setValue($value)->setRules($rules)->validate();
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     return $this->_validator->error();
 }
Example #9
0
 /**
  * Handle error/s for specific error codes
  *
  * @param  object $f3 FatFree instance
  * @return mixed      Custom error/Default FatFree error
  */
 public static function handler($f3)
 {
     $error = $f3->get('ERROR');
     switch ($error['code']) {
         default:
             $f3->mset(array('ONERROR' => null, 'ERROR' => null));
             $f3->error($error['code'], $error['text'], $error['trace']);
     }
 }
Example #10
0
 /**
  * Remove a message from the queue
  *
  * @param string $mid
  * @return mixed
  */
 public function remove($mid)
 {
     $ret = $this->implement->delete($mid);
     if ($ret === false || $this->implement->error()) {
         $this->error = $this->implement->error();
         return false;
     }
     return true;
 }
Example #11
0
    /**
     * Rebuild content-streams
     * only non-compressed streams and /FlateDecode are ready!
     *
     * @param array $obj
     * @return string
     */
    function rebuildContentStream($obj) {
        $filters = array();
        
        if (isset($obj[1][1]['/Filter'])) {
            $_filter = $obj[1][1]['/Filter'];

            if ($_filter[0] == PDF_TYPE_TOKEN) {
                $filters[] = $_filter;
            } else if ($_filter[0] == PDF_TYPE_ARRAY) {
                $filters = $_filter[1];
            }
        }

        $stream = $obj[2][1];
                          
        foreach ($filters AS $_filter) {
            switch ($_filter[1]) {
                case "/FlateDecode":
                if (function_exists('gzuncompress')) {
                          $stream = @gzuncompress($stream);
                   } else {
                       $this->fpdi->error(sprintf("To handle %s filter, please compile php with zlib support.",$_filter[1]));
                   }
                   if ($stream === false) {
                       $this->fpdi->error("Error while decompressing string.");
                   }

                break;
                case "/LZWDecode":
                    @include_once("decoders/lzw.php");
                    if (class_exists("LZWDecode")) {
                        $lzwdec = new LZWDecode($this->fpdi);
                        $stream = $lzwdec->decode($stream);
                    } else {
                        $this->fpdi->error(sprintf("Unsupported Filter: %s",$_filter[1]));
                    }
                break;
                case "/ASCII85Decode":
                    @include_once("decoders/ascii85.php");
                    if (class_exists("ASCII85Decode")) {
                        $ascii85 = new \ASCII85Decode($this->fpdi);
                        $stream = $ascii85->decode(trim($stream));
                    } else {
                        $this->fpdi->error(sprintf("Unsupported Filter: %s",$_filter[1]));
                    }
                break;
                case null:
                   $stream = $stream;
                break;
                default:
                   $this->fpdi->error(sprintf("Unsupported Filter: %s",$_filter[1]));
            }
        }
        
        return $stream;
    }
 /**
  * Creates a new DB instance and clean some data.
  * 
  * @param object $f3 A f3 instance.
  */
 function beforeRoute($f3)
 {
     $base = 'data/' . $f3->get('PARAMS.game') . '.sqlite';
     $this->playername = $f3->get('sanidad')->sanitize($f3->get('PARAMS.playername'));
     if (file_exists($base)) {
         $this->db = new DB\SQL('sqlite:' . $base);
     } else {
         $f3->error(500);
     }
 }
Example #13
0
 /**
  * Resolve an object
  *
  * @param object $c pdf_context
  * @param array $obj_spec The object-data
  * @param boolean $encapsulate Must set to true, cause the parsing and fpdi use this method only without this para
  */
 function pdf_resolve_object(&$c, $obj_spec, $encapsulate = true)
 {
     // Exit if we get invalid data
     if (!is_array($obj_spec)) {
         return false;
     }
     if ($obj_spec[0] == PDF_TYPE_OBJREF) {
         // This is a reference, resolve it
         if (isset($this->xref['xref'][$obj_spec[1]][$obj_spec[2]])) {
             // Save current file position
             // This is needed if you want to resolve
             // references while you're reading another object
             // (e.g.: if you need to determine the length
             // of a stream)
             $old_pos = ftell($c->file);
             // Reposition the file pointer and
             // load the object header.
             $c->reset($this->xref['xref'][$obj_spec[1]][$obj_spec[2]]);
             $header = $this->pdf_read_value($c, null, true);
             if ($header[0] != PDF_TYPE_OBJDEC || $header[1] != $obj_spec[1] || $header[2] != $obj_spec[2]) {
                 $this->fpdi->error("Unable to find object ({$obj_spec[1]}, {$obj_spec[2]}) at expected location");
             }
             // If we're being asked to store all the information
             // about the object, we add the object ID and generation
             // number for later use
             if ($encapsulate) {
                 $result = array(PDF_TYPE_OBJECT, 'obj' => $obj_spec[1], 'gen' => $obj_spec[2]);
             } else {
                 $result = array();
             }
             // Now simply read the object data until
             // we encounter an end-of-object marker
             while (1) {
                 $value = $this->pdf_read_value($c);
                 if ($value === false) {
                     return false;
                 }
                 if ($value[0] == PDF_TYPE_TOKEN && $value[1] === 'endobj') {
                     break;
                 }
                 $result[] = $value;
             }
             $c->reset($old_pos);
             if (isset($result[2][0]) && $result[2][0] == PDF_TYPE_STREAM) {
                 $result[0] = PDF_TYPE_STREAM;
             }
             return $result;
         }
     } else {
         return $obj_spec;
     }
 }
Example #14
0
 /**
  * Send message to queue
  *
  * @return bool
  */
 public function sendMessage($message)
 {
     if ($this->error()) {
         return false;
     }
     $ret = $this->queue->push($message);
     if ($ret === false || $this->queue->error()) {
         $this->error('Send messages failure,error:' . $this->queue->error());
         Logger::error($this->error());
         return false;
     }
     return true;
 }
 /**
  * do the resizes like Pageimage does it
  *
  * @param object $caller
  * @param pageimage $img
  * @param string $targetFilename
  * @param array $options1
  * @param array $options2
  * @return pageimage
  */
 public static function renderImage(&$caller, &$img, $sourceFilename, $targetFilename, $width, $height, $options)
 {
     $filenameFinal = $targetFilename;
     $filenameUnvalidated = $img->pagefiles->page->filesManager()->getTempPath() . basename($targetFilename);
     if (file_exists($filenameFinal)) {
         @unlink($filenameFinal);
     }
     if (file_exists($filenameUnvalidated)) {
         @unlink($filenameUnvalidated);
     }
     if (@copy($sourceFilename, $filenameUnvalidated)) {
         try {
             $sizer = new ImageSizer($filenameUnvalidated);
             $sizer->setOptions($options);
             if ($sizer->resize($width, $height) && @rename($filenameUnvalidated, $filenameFinal)) {
                 // if script runs into a timeout while in ImageSizer, we never will reach this line and we will stay with $filenameUnvalidated
                 if ($caller->config->chmodFile) {
                     chmod($filenameFinal, octdec($caller->config->chmodFile));
                 }
             } else {
                 $caller->error = "ImageSizer::resize({$width}, {$height}) failed for {$filenameUnvalidated}";
             }
         } catch (Exception $e) {
             $caller->error = $e->getMessage();
         }
     } else {
         $caller->error("Unable to copy {$sourceFilename} => {$filenameUnvalidated}");
     }
     $pageimage = clone $img;
     // if desired, user can check for property of $pageimage->error to see if an error occurred.
     // if an error occurred, that error property will be populated with details
     if ($caller->error) {
         // error condition: unlink copied file
         if (is_file($filenameFinal)) {
             @unlink($filenameFinal);
         }
         if (is_file($filenameUnvalidated)) {
             @unlink($filenameUnvalidated);
         }
         // write an invalid image so it's clear something failed
         $data = "This is intentionally invalid image data.\n{$caller->error}";
         if (file_put_contents($filenameFinal, $data) !== false) {
             wireChmod($filenameFinal);
         }
         // we also tell PW about it for logging and/or admin purposes
         $caller->error($caller->error);
     }
     $pageimage->setFilename($filenameFinal);
     $pageimage->setOriginal($img);
     return $pageimage;
 }
    /**
     * Rebuild content-streams
     *
     * @param array $obj
     * @return string
     */
    function _rebuildContentStream($obj) {
        $filters = array();
        
        if (isset($obj[1][1]['/Filter'])) {
            $_filter = $obj[1][1]['/Filter'];

            if ($_filter[0] == PDF_TYPE_TOKEN) {
                $filters[] = $_filter;
            } else if ($_filter[0] == PDF_TYPE_ARRAY) {
                $filters = $_filter[1];
            }
        }

        $stream = $obj[2][1];

        foreach ($filters AS $_filter) {
            switch ($_filter[1]) {
                case "/FlateDecode":
			if (function_exists('gzuncompress')) {
                        $stream = (strlen($stream) > 0) ? @gzuncompress($stream) : '';                        
			} else {
                        $this->fpdi->error(sprintf("To handle %s filter, please compile php with zlib support.",$_filter[1]));
			}
			if ($stream === false) { 
                        $this->fpdi->error("Error while decompressing stream.");
			}
                break;
			// mPDF 4.2.003
                case '/LZWDecode': 
			include_once(_MPDF_PATH . 'mpdfi/filters/FilterLZW.php');
			// mPDF 5.0 Removed pass by reference =&
			$decoder = new FilterLZW();
			$stream = $decoder->decode($stream);
			break;
                case '/ASCII85Decode':
			include_once(_MPDF_PATH . 'mpdfi/filters/FilterASCII85.php');
			// mPDF 5.0 Removed pass by reference =&
			$decoder = new FilterASCII85();
			$stream = $decoder->decode($stream);
			break;
                case null:
			$stream = $stream;
			break;
                default:
			$this->fpdi->error(sprintf("Unsupported Filter: %s",$_filter[1]));
            }
        }
        
        return $stream;
    }
Example #17
0
 /**
  * we have imported the old database, let's recalculate the forum statistics.
  *
  * @throws Exception
  * @return boolean
  */
 public function doStep2()
 {
     $this->response->step = $_GET['step'] = '2';
     $this->template->step2();
     try {
         $key = $this->importer->doStep2($_GET['substep']);
     } catch (DatabaseException $e) {
         $trace = $e->getTrace();
         $this->template->error($e->getMessage(), isset($trace[0]['args'][1]) ? $trace[0]['args'][1] : null, $e->getLine(), $e->getFile());
         // Forward back to the original caller to terminate the script
         throw new Exception($e->getMessage());
     }
     $this->template->status($key + 1, 1, false, true);
     return $this->doStep3();
 }
Example #18
0
 /**
  * Load the model of one module. After loaded, can use $this->modulename to visit the model object.
  * 
  * @param   string  $moduleName
  * @access  public
  * @return  object|bool  the model object or false if model file not exists.
  */
 public function loadModel($moduleName)
 {
     if (empty($moduleName)) {
         return false;
     }
     $modelFile = helper::setModelFile($moduleName);
     if (!helper::import($modelFile)) {
         return false;
     }
     $modelClass = class_exists('ext' . $moduleName . 'model') ? 'ext' . $moduleName . 'model' : $moduleName . 'model';
     if (!class_exists($modelClass)) {
         $this->app->error(" The model {$modelClass} not found", __FILE__, __LINE__, $exit = true);
     }
     $this->{$moduleName} = new $modelClass();
     return $this->{$moduleName};
 }
Example #19
0
 public function testFormErrorMultipleBindings()
 {
     $record1 = new Record(array('model' => $this->_model, 'data' => array('author_id' => '2', 'title' => 'New post', 'body' => 'New post body')));
     $record2 = new Record(array('model' => $this->_model2, 'data' => array('section' => 'New post section', 'notes' => 'New post notes')));
     $record1->errors(array('title' => 'Not a cool title'));
     $record2->errors(array('section' => 'Not a cool section'));
     $this->form->create(compact('record1', 'record2'));
     $result = $this->form->error('title');
     $this->assertTags($result, array('div' => array('class' => 'error'), 'Not a cool title', '/div'));
     $result = $this->form->error('body');
     $this->assertEmpty($result);
     $result = $this->form->error('record1.title');
     $this->assertTags($result, array('div' => array('class' => 'error'), 'Not a cool title', '/div'));
     $result = $this->form->error('record2.section');
     $this->assertTags($result, array('div' => array('class' => 'error'), 'Not a cool section', '/div'));
 }
Example #20
0
 /**
  * Get the output of one module's one method as a string, thus in one module's method, can fetch other module's content.
  * 
  * If the module name is empty, then use the current module and method. If set, use the user defined module and method.
  *
  * @param   string  $moduleName    module name.
  * @param   string  $methodName    method name.
  * @param   array   $params        params.
  * @access  public
  * @return  string  the parsed html.
  */
 public function fetch($moduleName = '', $methodName = '', $params = array())
 {
     if ($moduleName == '') {
         $moduleName = $this->moduleName;
     }
     if ($methodName == '') {
         $methodName = $this->methodName;
     }
     if ($moduleName == $this->moduleName and $methodName == $this->methodName) {
         $this->parse($moduleName, $methodName);
         return $this->output;
     }
     /* Set the pathes and files to included. */
     $modulePath = $this->app->getModulePath($moduleName);
     $moduleControlFile = $modulePath . 'control.php';
     $actionExtFile = $this->app->getModuleExtPath($moduleName, 'control') . strtolower($methodName) . '.php';
     $file2Included = file_exists($actionExtFile) ? $actionExtFile : $moduleControlFile;
     /* Load the control file. */
     if (!is_file($file2Included)) {
         $this->app->error("The control file {$file2Included} not found", __FILE__, __LINE__, $exit = true);
     }
     $currentPWD = getcwd();
     chdir(dirname($file2Included));
     if ($moduleName != $this->moduleName) {
         helper::import($file2Included);
     }
     /* Set the name of the class to be called. */
     $className = class_exists("my{$moduleName}") ? "my{$moduleName}" : $moduleName;
     if (!class_exists($className)) {
         $this->app->error(" The class {$className} not found", __FILE__, __LINE__, $exit = true);
     }
     /* Parse the params, create the $module control object. */
     if (!is_array($params)) {
         parse_str($params, $params);
     }
     $module = new $className($moduleName, $methodName);
     /* Call the method and use ob function to get the output. */
     ob_start();
     call_user_func_array(array($module, $methodName), $params);
     $output = ob_get_contents();
     ob_end_clean();
     /* Return the content. */
     unset($module);
     chdir($currentPWD);
     return $output;
 }
 /**
  * Rebuild content-streams
  *
  * @param array $obj
  * @return string
  */
 function _rebuildContentStream($obj)
 {
     $filters = array();
     if (isset($obj[1][1]['/Filter'])) {
         $_filter = $obj[1][1]['/Filter'];
         if ($_filter[0] == PDF_TYPE_TOKEN) {
             $filters[] = $_filter;
         } else {
             if ($_filter[0] == PDF_TYPE_ARRAY) {
                 $filters = $_filter[1];
             }
         }
     }
     $stream = $obj[2][1];
     foreach ($filters as $_filter) {
         switch ($_filter[1]) {
             case "/FlateDecode":
                 if (function_exists('gzuncompress')) {
                     $stream = strlen($stream) > 0 ? @gzuncompress($stream) : '';
                 } else {
                     $this->fpdi->error(sprintf("To handle %s filter, please compile php with zlib support.", $_filter[1]));
                 }
                 if ($stream === false) {
                     $this->fpdi->error("Error while decompressing stream.");
                 }
                 break;
             case null:
                 $stream = $stream;
                 break;
             default:
                 if (preg_match("/^\\/[a-z85]*\$/i", $_filter[1], $filterName) && @(include_once 'decoders' . $_filter[1] . '.php')) {
                     $filterName = substr($_filter[1], 1);
                     if (class_exists($filterName)) {
                         $decoder =& new $filterName($this->fpdi);
                         $stream = $decoder->decode(trim($stream));
                     } else {
                         $this->fpdi->error(sprintf("Unsupported Filter: %s", $_filter[1]));
                     }
                 } else {
                     $this->fpdi->error(sprintf("Unsupported Filter: %s", $_filter[1]));
                 }
         }
     }
     return $stream;
 }
Example #22
0
 /**
  * Get the defination of fields of the table.
  * 
  * @access private
  * @return array
  */
 private function getFieldsType()
 {
     try {
         $this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
         $sql = "DESC {$this->table}";
         $rawFields = $this->dbh->query($sql)->fetchAll();
         $this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
     } catch (PDOException $e) {
         $this->app->error($e->getMessage() . "<p>The sql is: {$sql}</p>", __FILE__, __LINE__, $exit = true);
     }
     foreach ($rawFields as $rawField) {
         $firstPOS = strpos($rawField->type, '(');
         $type = substr($rawField->type, 0, $firstPOS > 0 ? $firstPOS : strlen($rawField->type));
         $type = str_replace(array('big', 'small', 'medium', 'tiny', 'var'), '', $type);
         $field = array();
         if ($type == 'enum' or $type == 'set') {
             $rangeBegin = $firstPOS + 2;
             // Remove the first quote.
             $rangeEnd = strrpos($rawField->type, ')') - 1;
             // Remove the last quote.
             $range = substr($rawField->type, $rangeBegin, $rangeEnd - $rangeBegin);
             $field['rule'] = 'reg';
             $field['options']['reg'] = '/' . str_replace("','", '|', $range) . '/';
         } elseif ($type == 'char') {
             $begin = $firstPOS + 1;
             $end = strpos($rawField->type, ')', $begin);
             $length = substr($rawField->type, $begin, $end - $begin);
             $field['rule'] = 'length';
             $field['options']['max'] = $length;
             $field['options']['min'] = 0;
         } elseif ($type == 'int') {
             $field['rule'] = 'int';
         } elseif ($type == 'float' or $type == 'double') {
             $field['rule'] = 'float';
         } elseif ($type == 'date') {
             $field['rule'] = 'date';
         } else {
             $field['rule'] = 'skip';
         }
         $fields[$rawField->field] = $field;
     }
     return $fields;
 }
Example #23
0
File: Web.php Project: zhpe/zhpe
 /**
  * Result
  * @param $r
  */
 private static function result($r)
 {
     if (is_null(self::$action)) {
         var_dump($r);
         return;
     }
     if (is_null($r)) {
         return;
     }
     if (!is_array($r)) {
         $r = array('data' => $r, 'msg' => '');
     }
     $method = Zhpe_InputFilter::string('REQUEST_METHOD', INPUT_SERVER);
     if ($method == 'POST') {
         self::$action->json($r);
     } else {
         //GET
         self::$action->error($r['msg'], $r['data']);
     }
 }
Example #24
0
 /**
  * Send the request.
  * @return Curl
  * @throws PBMErrorException()
  */
 protected function send()
 {
     $this->log->debug('Checking connection certificates.');
     $this->checkCert($this->cainfo);
     $this->checkCert($this->sslcert);
     if (!$this->sslcertPwd) {
         throw new PBMErrorException('Missing certificate password!');
     }
     switch (strtolower($this->type)) {
         case 'get':
         case 'delete':
             if ($this->data) {
                 $this->url .= '?' . $this->data;
             }
             break;
         case 'post':
         case 'put':
             curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->data);
             break;
         default:
             throw new PBMErrorException('Unsupported request type: ' . $this->type);
     }
     $curl_file = tempnam('', 'res');
     $handle = fopen($curl_file, 'w');
     if ($this->debug) {
         curl_setopt($this->ch, CURLOPT_VERBOSE, true);
         curl_setopt($this->ch, CURLOPT_STDERR, $handle);
     }
     $this->body = curl_exec($this->ch);
     $this->status = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
     if ($error = curl_errno($this->ch)) {
         $this->log->error('cURL error code: ' . $error);
         $this->log->error('cURL message: ' . curl_error($this->ch));
     }
     if ($this->debug) {
         $this->log->debug('Curl result: ' . file_get_contents($curl_file));
     }
     fclose($handle);
     unlink($curl_file);
     return $this;
 }
Example #25
0
 /**
  * Handle error/s for specific error codes
  *
  * @param  object $f3 FatFree instance
  * @return mixed      Custom error/Default FatFree error
  */
 public static function handler($f3)
 {
     // F3 error: code, text, trace
     $error = $f3->get('ERROR');
     $domain = $f3->get("domain");
     error_log("Domain: " . $domain['domainname']);
     //test_array($_SERVER);
     $urls = isset($_SERVER['HTTP_X_ORIGINAL_URL']) ? $_SERVER['HTTP_X_ORIGINAL_URL'] : $_SERVER['REQUEST_URI'];
     $url = clean_url("http" . ($_SERVER['SERVER_PORT'] == 443 ? "s://" : "://") . $_SERVER['HTTP_HOST'] . $urls);
     error_log("URL: " . $url);
     $botText = "";
     if (is_bot()) {
         $botText = '---BOT--- ';
     }
     error_log("HTTP_USER_AGENT: " . $botText . $_SERVER['HTTP_USER_AGENT']);
     // custom error/s
     switch ($error['code']) {
         case 403:
             $f3->reroute("/user/login?return=" . $f3->get("return_here"));
             break;
         case 404:
             //test_array($error);
             $f3->set("SOFTERROR", true);
             $page = models\default_pages::get("error404");
             //$page['js'] = $page['js'].";".$domain['js'];
             //test_array($page);
             $p = new controllers\front\pages();
             $p->load($page, $error);
             break;
         default:
             $errorPath = dirname(ini_get('error_log'));
             ini_set("error_log", $errorPath . DIRECTORY_SEPARATOR . "LIN-Errors-php-error.log");
             // restore F3 error handler (hackish)
             $f3->mset(array('ONERROR' => null, 'ERROR' => null));
             $f3->error($error['code'], $error['text'], $error['trace']);
             exit;
             break;
     }
     // exit after custom action
 }
 /**
  * This returns/prints a error message regarding the active script. Intended to be used by the developer where exceptions are caught.
  *
  * @version 1.1
  * @date 20120308 (v1.1) (greg) switched to notifications queue
  *
  * @param string This is the message that will be displayed.
  * @param mixed default is print, can be set true, print, return.
  * @param mixed default is log, can be set true, print, return.
  * @return string Error string.
  * @author Jason Schoeman
  */
 public function error($error, $return = 'print', $log = 'log')
 {
     if ($log === true || $log == 'log') {
         // Log types are : ////////////////
         // 1 = OK /////////////////////////
         // 2 = Warning ////////////////////
         // 3 = Critical ///////////////////
         // 4 = Log-in /////////////////////
         // 5 = Log-out ////////////////////
         // 6 = Error //////////////////////
         ///////////////////////////////////
         $log_type = 6;
         ////////////////////
         // Log the event //////////////////
         $this->db->logArray[] = array('log_type' => $log_type, 'log_description' => $error);
     }
     // Create HTML.
     $html = $this->mod->error($error);
     // Return or print to browser.
     if ($return === 'print' || $return == false) {
         $this->notif->add(array('error', $html));
     } else {
         if ($return === 'return' || $return == true) {
             return $html;
         }
     }
 }
 /**
  * Render an element
  * @param object $element
  * @return string
  */
 protected function element($element)
 {
     // set id
     if (!isset($element->attributes['id'])) {
         $element->id = $this->id();
         $attributes = $element->attributes;
         $attributes['id'] = $element->id;
         $element->attributes = $attributes;
     } else {
         $element->id = $element->attributes['id'];
     }
     // set class
     if (!isset($element->attributes['class'])) {
         // set bootstap class
         $attributes['class'] = '';
     }
     // set label
     if (!$element->label) {
         if ($element->text) {
             $element->label = $this->_text->get($element->text);
         } else {
             $element->label = $this->_text->get('label.' . $element->key);
         }
     }
     // set error
     if ($error = $element->error()) {
         // create  errormessage
         $element->error = $this->_text->get('error.' . $element->key . '.' . $error);
     } else {
         $element->error = FALSE;
     }
     // set comment
     if (!isset($element->comment)) {
         if ($comment = $this->_text->get('comment.' . $element->key)) {
             $element->comment = $comment;
         } else {
             $element->comment = FALSE;
         }
     }
     // set default view
     $view = 'form/element';
     // render the element itself
     switch ($element->type) {
         case 'radio':
         case 'checkbox':
         case 'select':
             if (Arr::is_assoc($element->options) === FALSE) {
                 $options = array();
                 foreach ($element->options as $value => $label) {
                     $value = $label;
                     $label = $this->_text->get('option.' . $element->key . '.' . $value);
                     $options[$value] = $label;
                 }
                 $element->options = $options;
             }
             if ($element->type === 'radio') {
                 $view = 'form/radio';
             }
             if ($element->type === 'checkbox') {
                 $view = 'form/checkbox';
             }
             if ($element->type === 'select') {
                 if (isset($element->first_option)) {
                     $option = $element->first_option;
                     $value = is_array($option) && isset($option['value']) ? $option['value'] : $option;
                     $label = is_array($option) && isset($option['label']) ? $option['label'] : $this->_text->get('option.' . $element->key . '.' . $value);
                     // add to the beginning of options
                     $reverse = array_reverse($element->options, TRUE);
                     $reverse[$value] = $label;
                     $element->options = array_reverse($reverse, TRUE);
                 }
                 // set bootstap class
                 $attributes['class'] .= ' form-control';
                 $element->html = FormHTML::select($element->name, $element->options, $element->value, $attributes);
             }
             break;
         case 'hidden':
             $view = FALSE;
             $element->html = FormHTML::hidden($element->name, $element->value, $attributes);
             break;
         case 'submit':
             $view = FALSE;
             $label = isset($element->label) ? $element->label : $this->_text->get('label.' . $element->key);
             $element->html = FormHTML::submit($element->name, $label, $attributes);
             break;
         case 'btn':
             $view = FALSE;
             $label = isset($element->label) ? $element->label : $this->_text->get('label.' . $element->key);
             $href = isset($element->href) ? $element->href : '#';
             $element->html = HTML::anchor($href, $label, $attributes);
             break;
         case 'button':
             $view = FALSE;
             $label = isset($element->label) ? $element->label : $this->_text->get('label.' . $element->key);
             $element->html = FormHTML::button($element->name, $label, $attributes);
             break;
         case 'file':
             $element->html = FormHTML::file($element->name, $attributes);
             break;
         case 'image':
             $element->html = FormHTML::image($element->name, $element->value, $attributes, FALSE);
             break;
         case 'text':
         case 'password':
             if (!isset($attributes['placeholder'])) {
                 $attributes['placeholder'] = $this->_text->get('placeholder.' . $element->key);
             }
             // set bootstap class
             $attributes['class'] .= ' form-control';
             if ($element->type === 'text') {
                 $element->html = FormHTML::input($element->name, $element->value, $attributes);
             }
             if ($element->type === 'password') {
                 $element->html = FormHTML::password($element->name, $element->value, $attributes);
             }
             break;
         case 'textarea':
             $attributes['class'] .= ' form-control';
             $element->html = FormHTML::textarea($element->name, $element->value, $attributes, FALSE);
             break;
         default:
             $element->html = View::factory('form/' . $element->type, array('viewer' => $this, 'element' => $element))->render();
     }
     // wrap element
     if ($view) {
         $html = View::factory($view, array('element' => $element))->render();
     } else {
         $html = $element->html;
     }
     return $html;
 }
Example #28
0
 /**
  * 
  * função que faz a validação dos dados antes de salvar no banco de dados.
  * 
  * @return boolean
  */
 private function validar()
 {
     if (!empty($this->validacao)) {
         $this->_validacao = new Validacao($this->data, $this);
         foreach ($this->validacao as $key => $value) {
             if (is_array($value)) {
                 foreach ($value as $k => $v) {
                     $this->_validacao->add($key, $k, $v);
                 }
             } else {
                 $this->_validacao->add($key, $value);
             }
         }
         $this->validacao = [];
         $this->_validacao->run();
         if (count($this->_validacao->error()) > 0) {
             $this->validacao_error = $this->_validacao->error();
             return false;
         }
     }
     return true;
 }
 /**
  * Copy file from another volume.
  * Return new file path or false.
  *
  * @param  object $volume      source volume
  * @param  string $src         source file hash
  * @param  string $destination destination dir path
  * @param  string $name        file name
  *
  * @return string|false
  * @author Dmitry (dio) Levashov
  **/
 protected function copyFrom($volume, $src, $destination, $name)
 {
     if (($source = $volume->file($src)) == false) {
         return $this->setError(elFinder::ERROR_COPY, '#' . $src, $volume->error());
     }
     $errpath = $volume->path($src);
     if (!$this->nameAccepted($source['name'])) {
         return $this->setError(elFinder::ERROR_COPY, $errpath, elFinder::ERROR_INVALID_NAME);
     }
     if (!$source['read']) {
         return $this->setError(elFinder::ERROR_COPY, $errpath, elFinder::ERROR_PERM_DENIED);
     }
     if ($source['mime'] == 'directory') {
         $stat = $this->stat($this->_joinPath($destination, $name));
         $this->clearcache();
         if ((!$stat || $stat['mime'] != 'directory') && !$this->_mkdir($destination, $name)) {
             return $this->setError(elFinder::ERROR_COPY, $errpath);
         }
         $path = $this->_joinPath($destination, $name);
         foreach ($volume->scandir($src) as $entr) {
             if (!$this->copyFrom($volume, $entr['hash'], $path, $entr['name'])) {
                 return false;
             }
         }
     } else {
         // $mime = $source['mime'];
         // $w = $h = 0;
         if ($dim = $volume->dimensions($src)) {
             $s = explode('x', $dim);
             $source['width'] = $s[0];
             $source['height'] = $s[1];
         }
         if (($fp = $volume->open($src)) == false || ($path = $this->_save($fp, $destination, $name, $source)) == false) {
             $fp && $volume->close($fp, $src);
             return $this->setError(elFinder::ERROR_COPY, $errpath);
         }
         $volume->close($fp, $src);
     }
     return $path;
 }
Example #30
0
/**
 * バリデート処理
 *
 * @param  array   $check_data   バリデートチェック対象のデータ
 * @param  object  $Logger       Logger Object
 */
function _validate($check_data, $Logger)
{
    // 必須パラメータチェック
    if (!(isset($check_data["goo_car_id"]) || isset($check_data["stock_id"]))) {
        $Logger->error("goo_car_id or stock_id が指定されていません");
        _error(1);
        return false;
    }
    if (isset($check_data["goo_car_id"])) {
        if (trim($check_data["goo_car_id"]) == "") {
            $Logger->error("goo_car_id が空です");
            _error(1);
            return false;
        }
    }
    if (isset($check_data["stock_id"])) {
        if (trim($check_data["stock_id"]) == "") {
            $Logger->error("stock_id が空です");
            _error(1);
            return false;
        }
    }
    // ver パラメータのチェック (指定時)
    if (isset($check_data["ver"])) {
        if (!is_numeric($check_data["ver"])) {
            $Logger->error("バージョンが不正です:バージョン=" . $check_data["ver"]);
            _error(1);
            return false;
        }
    }
    return true;
}