public function printPage()
 {
     if ($this->prepared) {
         /*	$uri_address = $this->page->address['uri_address'];
         			if(!substr_count($uri_address,'.html')) 
         				{
         				 $dirname=LOCAL_PATH.'cache/cache'.$uri_address.((substr($uri_address,-1) != '/') ? '/':'');
         				 $filename='index';
         				 $extension='.html';			
         				}
         				else
         				{
         					$dirname=LOCAL_PATH.'cache/cache'.$dirname.((substr($dirname,-1) != '/') ? '/':'');
         					$filename.='.';
         				}
         			$cache_uri_address = $dirname.$filename.$extension;			
         			*/
         //	    $content = file_get_contents(LOCAL_PATH.'cache/'.$this->page->getPageId(), FALSE);
         $content = file_get_contents($this->cache_uri_address, FALSE);
         if ($content === FALSE) {
             Error::logError('CachedPageHandler - Bad permission', 'There is no permition to read cache content from file "' . $this->cache_uri_address . '".');
             return FALSE;
         }
         foreach ($this->page->getHeaders() as $header) {
             header($header);
         }
         print $content;
         return TRUE;
     }
     return FALSE;
 }
Esempio n. 2
0
 public static function get($index)
 {
     $instance = self::getInstance();
     if (!$instance->offsetExists($index)) {
         Error::logError('No entry is registered for key ' . $index);
         throw new VException('No entry is registered for key ' . $index);
     }
     return $instance->offsetGet($index);
 }
Esempio n. 3
0
 public function addHeader($headerBody)
 {
     $headerBody = trim($headerBody);
     if (strlen($headerBody)) {
         // checking for "Location" header - it must be the last one
         $hasLocation = FALSE;
         if (substr_count($this->headers[$tsize], 'Location:')) {
             $hasLocation = TRUE;
         }
         if (substr_count($headerBody, 'Location:')) {
             if ($hasLocation) {
                 Error::logError('Page.addHeader error', 'Error while adding header - "Location" header already exist', __FILE__, __LINE__);
                 return FALSE;
             }
             array_push($this->headers, $headerBody);
             return TRUE;
         }
         // checking for "HTTP" header (t.e. "HTTP/1.0 404 Not Found") - it must be the first one
         $hasHTTP = FALSE;
         if (substr_count($this->headers[$tsize], 'HTTP')) {
             $hasHTTP = TRUE;
         }
         if (substr_count($headerBody, 'HTTP')) {
             if ($hasHTTP) {
                 Error::logError('Page.addHeader error', 'Error while adding header - "HTTP" header already exist', __FILE__, __LINE__);
                 return FALSE;
             }
             $this->headers = array_merge((array) $headerBody, $this->headers);
             return TRUE;
         }
         // cheking for identical headers
         if (array_search($headerBody, $this->headers[$i]) !== FALSE) {
             Error::logError('Page.addHeader error', 'Error while adding header - header "' . $headerBody . '" already exist', __FILE__, __LINE__);
             return FALSE;
         }
         $tsize = sizeof($this->headers);
         if ($hasLocation) {
             $this->headers = array_merge(array_slice($this->headers, 0, $tsize - 1), (array) $headerBody, (array) $this->headers[$tsize]);
         } else {
             array_push($this->headers, $headerBody);
         }
         return TRUE;
     }
 }
Esempio n. 4
0
 private function _connect()
 {
     if (is_resource($this->_connection)) {
         return;
     }
     if (!empty($this->_settings['port'])) {
         $this->_settings['host'] .= ':' . $this->_settings['port'];
     }
     $this->_connection = mysql_connect($this->_settings['host'], $this->_settings['username'], $this->_settings['password']);
     if ($this->_connection === FALSE || mysql_errno()) {
         Error::logError('Fail to connect to database.', mysql_error());
         throw new VException(mysql_error());
     }
     if (!mysql_select_db($this->_settings['dbname'], $this->_connection)) {
         Error::logError('Fail to select database "' . $this->_settings['dbname'] . '". ', mysql_error($this->_connection));
         throw new VException(mysql_error($this->_connection));
     }
     if (!empty($this->_settings['charset'])) {
         mysql_query('SET NAMES ' . $this->_settings['charset'], $this->_connection);
     }
 }
Esempio n. 5
0
 public static function _get_few_data($name, $fields_arr = '*', $where_arr = array(), $num_page = '*', $order_arr = array('id' => 'ASC'))
 {
     $name = trim($name);
     $resResult = array();
     if (strlen($name)) {
         if (!isset(self::getInstance()->queries[$name])) {
             $resResult = self::getInstance()->_adapter->get_few_data($fields_arr, $where_arr, $num_page, $order_arr);
         } else {
             Error::logError('Execute Query Error', 'The unfetched query with the name "' . $name . '" already exist.');
         }
         if ($resResult) {
             self::getInstance()->queries[$name] = $resResult;
         }
     } else {
         Error::logError('Execute Query or Name Missing', 'The  query or name parameter was empty, please provide a name for the query.');
     }
     return $resResult;
 }
Esempio n. 6
0
 public function add_data()
 {
     $result = false;
     $data_info = $this->check_post();
     $fields_arr = $this->exist_field();
     if (count($data_info) > 0) {
         $keys = '';
         $values = '';
         foreach ($data_info as $key => $value) {
             if (isset($fields_arr[$key])) {
                 if (!empty($keys)) {
                     $keys .= ',';
                     $values .= ',';
                 }
                 $keys .= " {$key}";
                 $values .= " " . $this->_quote(is_array($value) ? implode(',', $value) : $value) . ' ';
             }
         }
         if (isset($fields_arr['date']) && !isset($data_info['date'])) {
             $keys .= ", date";
             $values .= ", NOW()";
         }
         if (isset($fields_arr['ip']) && !isset($data_info['ip'])) {
             $keys .= ", ip";
             $values .= ", '" . $_SERVER['REMOTE_ADDR'] . "'";
         }
         $sql = "INSERT INTO " . $this->table_name . "\n\t\t\t( {$keys} )\n\t\t\tVALUES ( {$values} )";
         //			var_dump($sql);
         $this->_connect();
         if ($res = $this->_connection->query($sql, false)) {
             $result = $this->lastInsertId();
             $res->close();
         } else {
             Error::logError('Query Failed', 'Q: ' . $sql . "\n" . $this->_connection->error);
         }
     }
     $this->closeConnection();
     //garbagecat76 06.01.2010
     return $result;
 }
Esempio n. 7
0
 public static function log($value, $module = NULL, $funcName = NULL, $extraInfo = NULL)
 {
     if ((bool) PHPWS_LOG_ERRORS == FALSE) {
         return;
     }
     if (!PHPWS_Error::isError($value)) {
         $error = PHPWS_Error::get($value, $module, $funcName, $extraInfo);
     } else {
         $error = $value;
     }
     $final = PHPWS_Error::printError($error);
     Error::logError($final);
 }