Page MenuHomePhorge

No OneTemporary

Size
24 KB
Referenced Files
None
Subscribers
None
diff --git a/plugins/database_attachments/database_attachments.php b/plugins/database_attachments/database_attachments.php
index 31747b35c..6bf1b2c56 100644
--- a/plugins/database_attachments/database_attachments.php
+++ b/plugins/database_attachments/database_attachments.php
@@ -1,170 +1,170 @@
<?php
/**
* Database Attachments
*
* This plugin which provides database backed storage for temporary
* attachment file handling. The primary advantage of this plugin
* is its compatibility with round-robin dns multi-server roundcube
* installations.
*
* This plugin relies on the core filesystem_attachments plugin
*
* @author Ziba Scott <ziba@umich.edu>
* @author Aleksander Machniak <alec@alec.pl>
* @version @package_version@
*/
require_once INSTALL_PATH . 'plugins/filesystem_attachments/filesystem_attachments.php';
class database_attachments extends filesystem_attachments
{
// Cache object
protected $cache;
// A prefix for the cache key used in the session and in the key field of the cache table
const PREFIX = "ATTACH";
/**
* Save a newly uploaded attachment
*/
function upload($args)
{
$args['status'] = false;
$cache = $this->get_cache();
$key = $this->_key($args);
$data = file_get_contents($args['path']);
if ($data === false) {
return $args;
}
$data = base64_encode($data);
$status = $cache->write($key, $data);
if ($status) {
$args['id'] = $key;
$args['status'] = true;
$args['path'] = null;
}
return $args;
}
/**
* Save an attachment from a non-upload source (draft or forward)
*/
function save($args)
{
$args['status'] = false;
$cache = $this->get_cache();
$key = $this->_key($args);
if ($args['path']) {
$args['data'] = file_get_contents($args['path']);
if ($args['data'] === false) {
return $args;
}
}
$data = base64_encode($args['data']);
$status = $cache->write($key, $data);
if ($status) {
$args['id'] = $key;
$args['status'] = true;
}
return $args;
}
/**
* Remove an attachment from storage
* This is triggered by the remove attachment button on the compose screen
*/
function remove($args)
{
$cache = $this->get_cache();
$status = $cache->remove($args['id']);
$args['status'] = true;
return $args;
}
/**
* When composing an html message, image attachments may be shown
* For this plugin, $this->get() will check the file and
* return it's contents
*/
function display($args)
{
return $this->get($args);
}
/**
* When displaying or sending the attachment the file contents are fetched
* using this method. This is also called by the attachment_display hook.
*/
function get($args)
{
$cache = $this->get_cache();
$data = $cache->read($args['id']);
if ($data) {
$args['data'] = base64_decode($data);
$args['status'] = true;
}
return $args;
}
/**
* Delete all temp files associated with this user
*/
function cleanup($args)
{
// check if cache object exist, it may be empty on session_destroy (#1489726)
if ($cache = $this->get_cache()) {
$cache->remove($args['group'], true);
}
}
/**
* Helper method to generate a unique key for the given attachment file
*/
protected function _key($args)
{
$uname = $args['path'] ? $args['path'] : $args['name'];
- return $args['group'] . md5(mktime() . $uname . $_SESSION['user_id']);
+ return $args['group'] . md5(time() . $uname . $_SESSION['user_id']);
}
/**
* Initialize and return cache object
*/
protected function get_cache()
{
if (!$this->cache) {
$this->load_config();
$rcmail = rcube::get_instance();
$ttl = 12 * 60 * 60; // default: 12 hours
$ttl = $rcmail->config->get('database_attachments_cache_ttl', $ttl);
$type = $rcmail->config->get('database_attachments_cache', 'db');
$prefix = self::PREFIX;
// Add session identifier to the prefix to prevent from removing attachments
// in other sessions of the same user (#1490542)
if ($id = session_id()) {
$prefix .= $id;
}
// Init SQL cache (disable cache data serialization)
$this->cache = $rcmail->get_cache($prefix, $type, $ttl, false);
}
return $this->cache;
}
}
diff --git a/plugins/debug_logger/runlog/runlog.php b/plugins/debug_logger/runlog/runlog.php
index 0c766a13c..0f43df83b 100644
--- a/plugins/debug_logger/runlog/runlog.php
+++ b/plugins/debug_logger/runlog/runlog.php
@@ -1,227 +1,233 @@
<?php
/**
- * runlog
- *
- * @author Ziba Scott <ziba@umich.edu>
+ * runlog
+ *
+ * @author Ziba Scott <ziba@umich.edu>
*/
class runlog {
- private $start_time = FALSE;
-
+ private $start_time = FALSE;
private $parent_stack = array();
-
- public $print_to_console = FALSE;
-
private $file_handles = array();
+ private $indent = 0;
+ private $run_log = array();
- private $indent = 0;
-
- public $threshold = 0;
-
- public $tag_count = array();
-
- public $timestamp = "d-M-Y H:i:s O";
-
- public $max_line_size = 150;
-
- private $run_log = array();
+ public $print_to_console = FALSE;
+ public $threshold = 0;
+ public $tag_count = array();
+ public $timestamp = "d-M-Y H:i:s O";
+ public $max_line_size = 150;
function runlog()
{
- $this->start_time = microtime( TRUE );
+ $this->start_time = microtime(true);
}
- public function start( $name, $tag = FALSE )
+ public function start($name, $tag = false)
{
- $this->run_log[] = array( 'type' => 'start',
- 'tag' => $tag,
- 'index' => count($this->run_log),
- 'value' => $name,
- 'time' => microtime( TRUE ),
- 'parents' => $this->parent_stack,
- 'ended' => false,
- );
+ $this->run_log[] = array(
+ 'type' => 'start',
+ 'tag' => $tag,
+ 'index' => count($this->run_log),
+ 'value' => $name,
+ 'time' => microtime(true),
+ 'parents' => $this->parent_stack,
+ 'ended' => false,
+ );
+
$this->parent_stack[] = $name;
$this->print_to_console("start: ".$name, $tag, 'start');
$this->print_to_file("start: ".$name, $tag, 'start');
$this->indent++;
}
public function end()
{
- $name = array_pop( $this->parent_stack );
- foreach ( $this->run_log as $k => $entry ) {
- if ( $entry['value'] == $name && $entry['type'] == 'start' && $entry['ended'] == false) {
+ $name = array_pop($this->parent_stack);
+ foreach ($this->run_log as $k => $entry) {
+ if ($entry['value'] == $name && $entry['type'] == 'start' && !$entry['ended']) {
$lastk = $k;
}
}
+
$start = $this->run_log[$lastk]['time'];
- $this->run_log[$lastk]['duration'] = microtime( TRUE ) - $start;
+ $this->run_log[$lastk]['duration'] = microtime(true) - $start;
$this->run_log[$lastk]['ended'] = true;
+ $this->run_log[] = array(
+ 'type' => 'end',
+ 'tag' => $this->run_log[$lastk]['tag'],
+ 'index' => $lastk,
+ 'value' => $name,
+ 'time' => microtime(true),
+ 'duration' => microtime(true) - $start,
+ 'parents' => $this->parent_stack,
+ );
- $this->run_log[] = array( 'type' => 'end',
- 'tag' => $this->run_log[$lastk]['tag'],
- 'index' => $lastk,
- 'value' => $name,
- 'time' => microtime( TRUE ),
- 'duration' => microtime( TRUE ) - $start,
- 'parents' => $this->parent_stack,
- );
$this->indent--;
- if($this->run_log[$lastk]['duration'] >= $this->threshold){
+ if ($this->run_log[$lastk]['duration'] >= $this->threshold) {
$tag_report = "";
- foreach($this->tag_count as $tag=>$count){
+ foreach($this->tag_count as $tag => $count){
$tag_report .= "$tag: $count, ";
}
- if(!empty($tag_report)){
+ if (!empty($tag_report)) {
// $tag_report = "\n$tag_report\n";
}
- $end_txt = sprintf("end: $name - %0.4f seconds $tag_report", $this->run_log[$lastk]['duration'] );
- $this->print_to_console($end_txt, $this->run_log[$lastk]['tag'] , 'end');
+ $end_txt = sprintf("end: $name - %0.4f seconds $tag_report", $this->run_log[$lastk]['duration']);
+ $this->print_to_console($end_txt, $this->run_log[$lastk]['tag'], 'end');
$this->print_to_file($end_txt, $this->run_log[$lastk]['tag'], 'end');
}
}
- public function increase_tag_count($tag){
- if(!isset($this->tag_count[$tag])){
- $this->tag_count[$tag] = 0;
- }
- $this->tag_count[$tag]++;
+ public function increase_tag_count($tag)
+ {
+ if (!isset($this->tag_count[$tag])) {
+ $this->tag_count[$tag] = 0;
+ }
+
+ $this->tag_count[$tag]++;
}
- public function get_text(){
+ public function get_text()
+ {
$text = "";
- foreach($this->run_log as $entry){
- $text .= str_repeat(" ",count($entry['parents']));
- if($entry['tag'] != 'text'){
- $text .= $entry['tag'].': ';
- }
- $text .= $entry['value'];
+ foreach ($this->run_log as $entry){
+ $text .= str_repeat(" ",count($entry['parents']));
+ if ($entry['tag'] != 'text'){
+ $text .= $entry['tag'].': ';
+ }
+ $text .= $entry['value'];
- if($entry['tag'] == 'end'){
- $text .= sprintf(" - %0.4f seconds", $entry['duration'] );
- }
+ if ($entry['tag'] == 'end') {
+ $text .= sprintf(" - %0.4f seconds", $entry['duration']);
+ }
- $text .= "\n";
+ $text .= "\n";
}
+
return $text;
}
- public function set_file($filename, $tag = 'master'){
- if(!isset($this->file_handle[$tag])){
+ public function set_file($filename, $tag = 'master')
+ {
+ if (!isset($this->file_handle[$tag])) {
$this->file_handles[$tag] = fopen($filename, 'a');
- if(!$this->file_handles[$tag]){
+ if (!$this->file_handles[$tag]) {
trigger_error('Could not open file for writing: '.$filename);
}
}
}
- public function note( $msg, $tag = FALSE )
+ public function note($msg, $tag = false)
{
- if($tag){
+ if ($tag) {
$this->increase_tag_count($tag);
}
- if ( is_array( $msg )) {
- $msg = '<pre>' . print_r( $msg, TRUE ) . '</pre>';
+ if (is_array($msg)) {
+ $msg = '<pre>' . print_r($msg, true) . '</pre>';
}
$this->debug_messages[] = $msg;
- $this->run_log[] = array( 'type' => 'note',
- 'tag' => $tag ? $tag:"text",
- 'value' => htmlentities($msg),
- 'time' => microtime( TRUE ),
- 'parents' => $this->parent_stack,
- );
-
- $this->print_to_file($msg, $tag);
- $this->print_to_console($msg, $tag);
-
+ $this->run_log[] = array(
+ 'type' => 'note',
+ 'tag' => $tag ? $tag:"text",
+ 'value' => htmlentities($msg),
+ 'time' => microtime(true),
+ 'parents' => $this->parent_stack,
+ );
+
+ $this->print_to_file($msg, $tag);
+ $this->print_to_console($msg, $tag);
}
- public function print_to_file($msg, $tag = FALSE, $type = FALSE){
- if(!$tag){
- $file_handle_tag = 'master';
- }
- else{
+ public function print_to_file($msg, $tag = false, $type = false)
+ {
+ if (!$tag) {
+ $file_handle_tag = 'master';
+ }
+ else{
$file_handle_tag = $tag;
- }
- if($file_handle_tag != 'master' && isset($this->file_handles[$file_handle_tag])){
- $buffer = $this->get_indent();
- $buffer .= "$msg\n";
- if(!empty($this->timestamp)){
- $buffer = sprintf("[%s] %s",date($this->timestamp, mktime()), $buffer);
- }
- fwrite($this->file_handles[$file_handle_tag], wordwrap($buffer, $this->max_line_size, "\n "));
- }
- if(isset($this->file_handles['master']) && $this->file_handles['master']){
- $buffer = $this->get_indent();
- if($tag){
- $buffer .= "$tag: ";
- }
- $msg = str_replace("\n","",$msg);
- $buffer .= "$msg";
- if(!empty($this->timestamp)){
- $buffer = sprintf("[%s] %s",date($this->timestamp, mktime()), $buffer);
- }
- if(strlen($buffer) > $this->max_line_size){
- $buffer = substr($buffer,0,$this->max_line_size - 3)."...";
- }
- fwrite($this->file_handles['master'], $buffer."\n");
- }
+ }
+
+ if ($file_handle_tag != 'master' && isset($this->file_handles[$file_handle_tag])) {
+ $buffer = $this->get_indent();
+ $buffer .= "$msg\n";
+ if (!empty($this->timestamp)) {
+ $buffer = sprintf("[%s] %s",date($this->timestamp, time()), $buffer);
+ }
+ fwrite($this->file_handles[$file_handle_tag], wordwrap($buffer, $this->max_line_size, "\n "));
+ }
+
+ if (isset($this->file_handles['master']) && $this->file_handles['master']) {
+ $buffer = $this->get_indent();
+ if ($tag) {
+ $buffer .= "$tag: ";
+ }
+ $msg = str_replace("\n","",$msg);
+ $buffer .= "$msg";
+ if (!empty($this->timestamp)) {
+ $buffer = sprintf("[%s] %s",date($this->timestamp, time()), $buffer);
+ }
+ if(strlen($buffer) > $this->max_line_size){
+ $buffer = substr($buffer,0,$this->max_line_size - 3) . "...";
+ }
+ fwrite($this->file_handles['master'], $buffer."\n");
+ }
}
- public function print_to_console($msg, $tag=FALSE){
- if($this->print_to_console){
- if(is_array($this->print_to_console)){
- if(in_array($tag, $this->print_to_console)){
+ public function print_to_console($msg, $tag = false)
+ {
+ if ($this->print_to_console) {
+ if (is_array($this->print_to_console)) {
+ if (in_array($tag, $this->print_to_console)) {
echo $this->get_indent();
- if($tag){
+ if ($tag) {
echo "$tag: ";
}
echo "$msg\n";
}
}
- else{
+ else {
echo $this->get_indent();
- if($tag){
+ if ($tag) {
echo "$tag: ";
}
echo "$msg\n";
}
}
}
- public function print_totals(){
+ public function print_totals()
+ {
$totals = array();
foreach ($this->run_log as $entry) {
- if ( $entry['type'] == 'start' && $entry['ended'] == true) {
+ if ($entry['type'] == 'start' && $entry['ended']) {
$totals[$entry['value']]['duration'] += $entry['duration'];
$totals[$entry['value']]['count'] += 1;
}
}
- if($this->file_handle){
- foreach($totals as $name=>$details){
- fwrite($this->file_handle,$name.": ".number_format($details['duration'],4)."sec, ".$details['count']." calls \n");
- }
+
+ if ($this->file_handle) {
+ foreach ($totals as $name => $details) {
+ fwrite($this->file_handle,$name.": ".number_format($details['duration'],4)."sec, ".$details['count']." calls \n");
+ }
}
}
- private function get_indent(){
- $buf = "";
- for($i = 0; $i < $this->indent; $i++){
- $buf .= " ";
- }
- return $buf;
+ private function get_indent()
+ {
+ $buf = "";
+ for ($i = 0; $i < $this->indent; $i++) {
+ $buf .= " ";
+ }
+ return $buf;
}
- function __destruct(){
- foreach($this->file_handles as $handle){
+ function __destruct()
+ {
+ foreach ($this->file_handles as $handle) {
fclose($handle);
}
}
-
}
-
-?>
diff --git a/plugins/redundant_attachments/redundant_attachments.php b/plugins/redundant_attachments/redundant_attachments.php
index fc7e06e6d..e202a86a5 100644
--- a/plugins/redundant_attachments/redundant_attachments.php
+++ b/plugins/redundant_attachments/redundant_attachments.php
@@ -1,232 +1,232 @@
<?php
/**
* Redundant attachments
*
* This plugin provides a redundant storage for temporary uploaded
* attachment files. They are stored in both the database backend
* as well as on the local file system.
*
* It provides also memcache store as a fallback (see config file).
*
* This plugin relies on the core filesystem_attachments plugin
* and combines it with the functionality of the database_attachments plugin.
*
* @author Thomas Bruederli <roundcube@gmail.com>
* @author Aleksander Machniak <machniak@kolabsys.com>
*
* Copyright (C) 2011, The Roundcube Dev Team
* Copyright (C) 2011, Kolab Systems AG
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
require_once(RCUBE_PLUGINS_DIR . 'filesystem_attachments/filesystem_attachments.php');
class redundant_attachments extends filesystem_attachments
{
// A prefix for the cache key used in the session and in the key field of the cache table
const PREFIX = "ATTACH";
// rcube_cache instance for SQL DB
private $cache;
// rcube_cache instance for memcache
private $mem_cache;
private $loaded;
/**
* Loads plugin configuration and initializes cache object(s)
*/
private function _load_drivers()
{
if ($this->loaded) {
return;
}
$rcmail = rcube::get_instance();
// load configuration
$this->load_config();
$ttl = 12 * 60 * 60; // 12 hours
$ttl = $rcmail->config->get('redundant_attachments_cache_ttl', $ttl);
$prefix = self::PREFIX;
if ($id = session_id()) {
$prefix .= $id;
}
// Init SQL cache (disable cache data serialization)
$this->cache = $rcmail->get_cache($prefix, 'db', $ttl, false);
// Init memcache (fallback) cache
if ($rcmail->config->get('redundant_attachments_memcache')) {
$this->mem_cache = $rcmail->get_cache($prefix, 'memcache', $ttl, false);
}
$this->loaded = true;
}
/**
* Helper method to generate a unique key for the given attachment file
*/
private function _key($args)
{
$uname = $args['path'] ? $args['path'] : $args['name'];
- return $args['group'] . md5(mktime() . $uname . $_SESSION['user_id']);
+ return $args['group'] . md5(time() . $uname . $_SESSION['user_id']);
}
/**
* Save a newly uploaded attachment
*/
function upload($args)
{
$args = parent::upload($args);
$this->_load_drivers();
$key = $this->_key($args);
$data = base64_encode(file_get_contents($args['path']));
$status = $this->cache->write($key, $data);
if (!$status && $this->mem_cache) {
$status = $this->mem_cache->write($key, $data);
}
if ($status) {
$args['id'] = $key;
$args['status'] = true;
}
return $args;
}
/**
* Save an attachment from a non-upload source (draft or forward)
*/
function save($args)
{
$args = parent::save($args);
$this->_load_drivers();
$data = $args['path'] ? file_get_contents($args['path']) : $args['data'];
$args['data'] = null;
$key = $this->_key($args);
$data = base64_encode($data);
$status = $this->cache->write($key, $data);
if (!$status && $this->mem_cache) {
$status = $this->mem_cache->write($key, $data);
}
if ($status) {
$args['id'] = $key;
$args['status'] = true;
}
return $args;
}
/**
* Remove an attachment from storage
* This is triggered by the remove attachment button on the compose screen
*/
function remove($args)
{
parent::remove($args);
$this->_load_drivers();
$status = $this->cache->remove($args['id']);
if (!$status && $this->mem_cache) {
$status = $this->cache->remove($args['id']);
}
// we cannot trust the result of any of the methods above
// assume true, attachments will be removed on cleanup
$args['status'] = true;
return $args;
}
/**
* When composing an html message, image attachments may be shown
* For this plugin, $this->get() will check the file and
* return it's contents
*/
function display($args)
{
return $this->get($args);
}
/**
* When displaying or sending the attachment the file contents are fetched
* using this method. This is also called by the attachment_display hook.
*/
function get($args)
{
// attempt to get file from local file system
$args = parent::get($args);
if ($args['path'] && ($args['status'] = file_exists($args['path'])))
return $args;
$this->_load_drivers();
// fetch from database if not found on FS
$data = $this->cache->read($args['id']);
// fetch from memcache if not found on FS and DB
if (($data === false || $data === null) && $this->mem_cache) {
$data = $this->mem_cache->read($args['id']);
}
if ($data) {
$args['data'] = base64_decode($data);
$args['status'] = true;
}
return $args;
}
/**
* Delete all temp files associated with this user
*/
function cleanup($args)
{
$this->_load_drivers();
if ($this->cache) {
$this->cache->remove($args['group'], true);
}
if ($this->mem_cache) {
$this->mem_cache->remove($args['group'], true);
}
parent::cleanup($args);
$args['status'] = true;
return $args;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Thu, Mar 19, 8:47 AM (20 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
458508
Default Alt Text
(24 KB)

Event Timeline