Ejemplo n.º 1
0
 function query($soqlQuery, $queryAction, $queryLocator = null, $suppressScreenOutput = false)
 {
     if (!WorkbenchConfig::get()->value("allowParentRelationshipQueries") && preg_match("/SELECT.*?(\\w+\\.\\w+).*FROM/i", $soqlQuery, $matches)) {
         $msg = "Parent relationship queries are disabled in Workbench: " . $matches[1];
         if (WorkbenchConfig::get()->overrideable("allowParentRelationshipQueries")) {
             $msg .= "\n\nDue to issues rendering query results, parent relationship queries are disabled by default. " . "If you understand these limitations, parent relationship queries can be enabled under Settings. " . "Alternatively, parent relationship queries can be run with REST Explorer under the Utilities menu without issue.";
         }
         throw new WorkbenchHandledException($msg);
     }
     try {
         if ($queryAction == 'Query') {
             $queryResponse = WorkbenchContext::get()->getPartnerConnection()->query($soqlQuery);
         }
         if ($queryAction == 'QueryAll') {
             $queryResponse = WorkbenchContext::get()->getPartnerConnection()->queryAll($soqlQuery);
         }
     } catch (SoapFault $e) {
         foreach (array("MALFORMED_QUERY", "INVALID_FIELD", "INVALID_TYPE", "INVALID_QUERY_FILTER_OPERATOR", "QUERY_TIMEOUT", "EXCEEDED_ID_LIMIT") as $known) {
             if (strpos($e->getMessage(), $known) > -1) {
                 throw new WorkbenchHandledException($e->getMessage(), 0, $e);
             }
         }
         throw $e;
     }
     if ($queryAction == 'QueryMore' && isset($queryLocator)) {
         $queryResponse = WorkbenchContext::get()->getPartnerConnection()->queryMore($queryLocator);
     }
     if (stripos($soqlQuery, "count()") && $suppressScreenOutput == false) {
         return $queryResponse->size;
     } else {
         if (!isset($queryResponse->records)) {
             return null;
         }
     }
     $records = $queryResponse->records;
     $this->totalQuerySize = $queryResponse->size;
     if (!$queryResponse->done) {
         $this->nextQueryLocator = $queryResponse->queryLocator;
     }
     //correction for documents and attachments with body. issue #176
     if ($queryResponse->size > 0 && !is_array($records)) {
         $records = array($records);
     }
     $memLimitBytes = toBytes(ini_get("memory_limit"));
     $memWarningThreshold = WorkbenchConfig::get()->value("memoryUsageWarningThreshold") / 100;
     while (($suppressScreenOutput || WorkbenchConfig::get()->value("autoRunQueryMore")) && !$queryResponse->done) {
         if ($memLimitBytes != 0 && memory_get_usage() / $memLimitBytes > $memWarningThreshold) {
             displayError("Workbench almost exhausted all its memory after only processing " . count($records) . " rows of data.\n                When performing a large queries, it is recommended to export as Bulk CSV or Bulk XML.", $suppressScreenOutput, true);
             return;
             // bail out
         }
         $queryResponse = WorkbenchContext::get()->getPartnerConnection()->queryMore($queryResponse->queryLocator);
         if (!is_array($queryResponse->records)) {
             $queryResponse->records = array($queryResponse->records);
         }
         $records = array_merge($records, $queryResponse->records);
         //todo: do memory check here
     }
     return $records;
 }
Ejemplo n.º 2
0
 public function init()
 {
     $fileMaxSize['postSize'] = toBytes(ini_get('post_max_size'));
     $fileMaxSize['uploadSize'] = toBytes(ini_get('upload_max_filesize'));
     $this->fileMaxSize = min($fileMaxSize);
     parent::init();
 }
Ejemplo n.º 3
0
 public function init()
 {
     $fileMaxSize['postSize'] = toBytes(ini_get('post_max_size'));
     $fileMaxSize['uploadSize'] = toBytes(ini_get('upload_max_filesize'));
     $this->maxImageSize = min($fileMaxSize);
     $this->maxImageSizeMb = round($this->maxImageSize / (1024 * 1024));
     parent::init();
 }
Ejemplo n.º 4
0
 public function init()
 {
     $this->preparePaths();
     $this->publishAssets();
     $fileMaxSize['postSize'] = toBytes(ini_get('post_max_size'));
     $fileMaxSize['uploadSize'] = toBytes(ini_get('upload_max_filesize'));
     $this->fileMaxSize = min($fileMaxSize);
     $this->fileMaxSizeMessage = self::formatBytes($this->fileMaxSize);
     parent::init();
 }
Ejemplo n.º 5
0
/**
 * get the maximum upload size as defined by php ini
 * @since  3.4
 * @return int max bytes
 */
function getMaxUploadSize()
{
    $max_upload = toBytes(ini_get('upload_max_filesize'));
    $max_post = toBytes(ini_get('post_max_size'));
    $memory_limit = toBytes(ini_get('memory_limit'));
    $upload_mb = min($max_upload, $max_post, $memory_limit);
    return $upload_mb;
}
Ejemplo n.º 6
0
/**
 * Read a CSV file and return a PHP array
 *
 * @param csv $file
 * @return PHP array
 */
function convertCsvFileToArray($file)
{
    ini_set("auto_detect_line_endings", true);
    //detect mac os line endings too
    $csvArray = array();
    $handle = fopen($file, "r");
    $memLimitBytes = toBytes(ini_get("memory_limit"));
    $memWarningThreshold = WorkbenchConfig::get()->value("memoryUsageWarningThreshold") / 100;
    $headerCount = 0;
    for ($row = 0; ($data = fgetcsv($handle)) !== FALSE; $row++) {
        if ($memLimitBytes != 0 && memory_get_usage() / $memLimitBytes > $memWarningThreshold) {
            displayError("Workbench almost exhausted all its memory after only processing {$row} rows of data.\n            When performing a large data load, it is recommended to use a zipped request for processing with the Bulk API.\n            To do so, rename your CSV file to 'request.txt', zip it, and try uploading again to Workbench.", false, true);
            fclose($handle);
            return;
        }
        if ($row == 0) {
            $headerCount = count($data);
        } else {
            $colCount = count($data);
            if ($headerCount != $colCount) {
                fclose($handle);
                throw new WorkbenchHandledException("Invalid CSV file. All rows must have same number of columns.\n" . "Header contains " . amt($headerCount, "column") . ", but data row {$row} contains " . amt($colCount, "column") . ".");
            }
        }
        for ($col = 0; $col < count($data); $col++) {
            $csvArray[$row][$col] = $data[$col];
        }
    }
    fclose($handle);
    if ($csvArray !== NULL) {
        return $csvArray;
    } else {
        displayError("There were errors parsing the CSV file. Please try again.", false, true);
    }
}
Ejemplo n.º 7
0
function getUploadedFile($FieldName, $MaxSize = 0, $FileTypes = 'csv|txt', $NoRename = false, $dir = '')
{
    $currDir = dirname(__FILE__);
    if (is_array($_FILES)) {
        $f = $_FILES[$FieldName];
    } else {
        return 'Your php settings don\'t allow file uploads.';
    }
    if (!$MaxSize) {
        $MaxSize = toBytes(ini_get('upload_max_filesize'));
    }
    if (!is_dir("{$currDir}/csv")) {
        @mkdir("{$currDir}/csv");
    }
    $dir = is_dir($dir) && is_writable($dir) ? $dir : "{$currDir}/csv/";
    if ($f['error'] != 4 && $f['name'] != '') {
        if ($f['size'] > $MaxSize || $f['error']) {
            return 'File size exceeds maximum allowed of ' . intval($MaxSize / 1024) . 'KB';
        }
        if (!preg_match('/\\.(' . $FileTypes . ')$/i', $f['name'], $ft)) {
            return 'File type not allowed. Only these file types are allowed: ' . str_replace('|', ', ', $FileTypes);
        }
        if ($NoRename) {
            $n = str_replace(' ', '_', $f['name']);
        } else {
            $n = microtime();
            $n = str_replace(' ', '_', $n);
            $n = str_replace('0.', '', $n);
            $n .= $ft[0];
        }
        if (!@move_uploaded_file($f['tmp_name'], $dir . $n)) {
            return 'Couldn\'t save the uploaded file. Try chmoding the upload folder "' . $dir . '" to 777.';
        } else {
            @chmod($dir . $n, 0666);
            return $dir . $n;
        }
    }
    return 'An error occured while uploading the file. Please try again.';
}
Ejemplo n.º 8
0
</div>

</body>

<script type="text/javascript" src="<?php 
echo getPathToStaticResource('/script/wz_tooltip.js');
?>
"></script>

<?php 
if (isset($_REQUEST["footerScripts"])) {
    foreach ($_REQUEST["footerScripts"] as $script) {
        print $script . "\n";
    }
}
?>

</html>

<?php 
$peak = memory_get_peak_usage();
workbenchLog(LOG_INFO, "MemoryUsageCheck", array("measure.memory.peak" => $peak . "byte"));
if (WorkbenchContext::isEstablished() && $peak / toBytes(ini_get("memory_limit")) > 0.7) {
    WorkbenchContext::get()->clearCache();
    workbenchLog(LOG_INFO, "MemoryUsageCacheClear", array("measure.memory.cache_clear" => 1));
}
if (isset($GLOBALS['REDIS'])) {
    redis()->close();
}
//USAGE: debug($showSuperVars = true, $showSoap = true, $customName = null, $customValue = null)
debug(true, true, null, null);
Ejemplo n.º 9
0
 public function getSizeLimit()
 {
     $min = min(toBytes(ini_get('post_max_size')), toBytes(ini_get('upload_max_filesize')));
     return min($min, param('maxImgFileSize', 8 * 1024 * 1024));
 }
Ejemplo n.º 10
0
		<div id="uploadify"></div>
	<?php 
    // create Uploadify uploader
    $debug = defined('GSDEBUG') && GSDEBUG == 1 ? 'true' : 'false';
    $fileSizeLimit = toBytes(ini_get('upload_max_filesize')) / 1024;
    echo "\r\n\t<script type=\"text/javascript\">\r\n\tjQuery(document).ready(function() {\r\n\t\tif(jQuery().uploadify) {\r\n\t\t\$('#uploadify').uploadify({\r\n\t\t\t'debug'\t\t\t: " . $debug . ",\r\n\t\t\t'buttonText'\t: '" . i18n_r('UPLOADIFY_BUTTON') . "',\r\n\t\t\t'buttonCursor'\t: 'pointer',\r\n\t\t\t'uploader'\t\t: 'upload-uploadify.php',\r\n\t\t\t'swf'\t\t\t: 'template/js/uploadify/uploadify.swf',\r\n\t\t\t'multi'\t\t\t: true,\r\n\t\t\t'auto'\t\t\t: true,\r\n\t\t\t'height'\t\t: '25',\r\n\t\t\t'width'\t\t\t: '100%',\r\n\t\t\t'requeueErrors'\t: false,\r\n\t\t\t'fileSizeLimit'\t: '" . $fileSizeLimit . "', // expects input in kb\r\n\t\t\t'cancelImage'\t: 'template/images/cancel.png',\r\n\t\t\t'checkExisting'\t: 'uploadify-check-exists.php?path=" . $path . "',\r\n\t\t\t'postData'\t\t: {\r\n\t\t\t\t'sessionHash' : '" . $SESSIONHASH . "',\r\n\t\t\t\t'path' : '" . $path . "'\r\n\t\t\t},\r\n\t\t\tonUploadProgress: function() {\r\n\t\t\t\t\$('#loader').show();\r\n\t\t\t},\r\n\t\t\tonUploadComplete: function() {\r\n\t\t\t\t\$('#loader').fadeOut(500);\r\n\t\t\t\t\$('#maincontent').load(location.href+' #maincontent', function() {\r\n\t\t\t\t\tattachFilterChangeEvent();\r\n\t\t\t\t});\r\n\t\t\t},\r\n\t\t\tonSelectError: function(file,errorCode,errorMsg) {\r\n\t\t\t\t//alert(file + ' Error ' + errorCode +':'+errorMsg);\r\n\t\t\t},\r\n\t\t\tonUploadError: function(file,errorCode,errorMsg, errorString) {\r\n\t\t\t\talert(errorMsg);\r\n\t\t\t}\r\n\t\t});\r\n\t\t}\r\n\t});\r\n\t</script>";
    ?>
	</li>
<?php 
}
?>
	<li style="float:right;" id="sb_filesize" ><small><?php 
i18n('MAX_FILE_SIZE');
?>
: <strong><?php 
echo toBytes(ini_get('upload_max_filesize')) / 1024 / 1024;
?>
MB</strong></small></li>
</ul>


<?php 
# show normal upload form if Uploadify is turned off
if (defined('GSNOUPLOADIFY')) {
    ?>
	<form class="uploadform" action="upload.php?path=<?php 
    echo $path;
    ?>
" method="post" enctype="multipart/form-data">
		<p><input type="file" name="file[]" id="file" style="width:220px;" multiple /></p>
		<input type="hidden" name="hash" id="hash" value="<?php 
Ejemplo n.º 11
0
    {
        $val = trim($str);
        $last = strtolower($str[strlen($str) - 1]);
        switch ($last) {
            case 'g':
                $val *= 1024;
            case 'm':
                $val *= 1024;
            case 'k':
                $val *= 1024;
        }
        return $val;
    }
    // create Uploadify uploader
    $debug = GSDEBUG == 1 ? 'true' : 'false';
    $fileSizeLimit = toBytes(ini_get('upload_max_filesize')) / 1024;
    echo "\r\n\t<script type=\"text/javascript\">\r\n\tjQuery(document).ready(function() {\r\n\t\tif(jQuery().uploadify) {\r\n\t\t\$('#uploadify').uploadify({\r\n\t\t\t'debug'\t\t\t: " . $debug . ",\r\n\t\t\t'buttonText'\t: '" . i18n_r('UPLOADIFY_BUTTON') . "',\r\n\t\t\t'buttonCursor'\t: 'pointer',\r\n\t\t\t'uploader'\t\t: 'upload-uploadify.php',\r\n\t\t\t'swf'\t\t\t: 'template/js/uploadify/uploadify.swf',\r\n\t\t\t'multi'\t\t\t: true,\r\n\t\t\t'auto'\t\t\t: true,\r\n\t\t\t'height'\t\t: '25',\r\n\t\t\t'width'\t\t\t: '100%',\r\n\t\t\t'requeueErrors'\t: false,\r\n\t\t\t'fileSizeLimit'\t: '" . $fileSizeLimit . "', // expects input in kb\r\n\t\t\t'cancelImage'\t: 'template/images/cancel.png',\r\n\t\t\t'checkExisting'\t: 'uploadify-check-exists.php?path=" . $path . "',\r\n\t\t\t'postData'\t\t: {\r\n\t\t\t\t'sessionHash' : '" . $SESSIONHASH . "',\r\n\t\t\t\t'path' : '" . $path . "'\r\n\t\t\t},\r\n\t\t\tonUploadProgress: function() {\r\n\t\t\t\t\$('#loader').show();\r\n\t\t\t},\r\n\t\t\tonUploadComplete: function() {\r\n\t\t\t\t\$('#loader').fadeOut(500);\r\n\t\t\t\t\$('#maincontent').load(location.href+' #maincontent', function() {\r\n\t\t\t\t\tattachFilterChangeEvent();\r\n\t\t\t\t});\r\n\t\t\t},\r\n\t\t\tonSelectError: function(file,errorCode,errorMsg) {\r\n\t\t\t\t//alert(file + ' Error ' + errorCode +':'+errorMsg);\r\n\t\t\t},\r\n\t\t\tonUploadError: function(file,errorCode,errorMsg, errorString) {\r\n\t\t\t\talert(errorMsg);\r\n\t\t\t}\r\n\t\t});\r\n\t\t}\r\n\t});\r\n\t</script>";
    ?>
	</li>
<?php 
}
?>
	<li style="float:right;"><small><?php 
i18n('MAX_FILE_SIZE');
?>
: <strong><?php 
echo ini_get('upload_max_filesize');
?>
B</strong></small></li>
</ul>
Ejemplo n.º 12
0
function formatBytes($bytes, $precision = 2)
{
    $units = array('', 'k', 'M', 'G', 'T');
    $bytes = max(toBytes($bytes), 0);
    $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
    $pow = min($pow, count($units) - 1);
    $bytes /= pow(1024, $pow);
    return round($bytes, $precision) . $units[$pow];
}
Ejemplo n.º 13
0
// Upload process
require_once dirname(__FILE__) . "/qqUploadedFileXhr.class.php";
if (isset($_GET['qqfile'])) {
    $file = new qqUploadedFileXhr();
} elseif (isset($_FILES['qqfile'])) {
    $file = new qqUploadedFileForm();
} else {
    $file = false;
}
$pathinfo = pathinfo(strtolower($file->getName()));
$filename = JApplication::stringURLSafe($pathinfo['filename']);
$ext = $pathinfo['extension'];
// Max size to upload (10MB)
$sizeLimit = 10 * 1024 * 1024;
$postSize = toBytes(ini_get('post_max_size'));
$uploadSize = toBytes(ini_get('upload_max_filesize'));
// allowed extensions to upload
$allowedExtensions = array('jpg', 'jpeg', 'png', 'gif');
$response = array('success' => false, 'message' => '');
$moduleID = JRequest::getInt('id', 0);
$dir = JPATH_BASE . '/images';
$user = JFactory::getUser();
if ($user->guest) {
    $response['message'] = "This function only for logged users!";
} else {
    if (!$file) {
        $response['message'] = "No files are found!";
    } else {
        if ($file->getSize() == 0) {
            $response['message'] = "File is empty, check your file and try again";
        } else {
function get_memory_limit()
{
    if (!function_exists('ini_get')) {
        return -1;
    }
    return toBytes(ini_get('memory_limit'));
}
Ejemplo n.º 15
0
}
print "Workbench " . ($GLOBALS["WORKBENCH_VERSION"] != "trunk" ? $GLOBALS["WORKBENCH_VERSION"] : "") . "<br/>\n";
?>
</div>

</body>

<script type="text/javascript" src="<?php 
echo getPathToStaticResource('/script/wz_tooltip.js');
?>
"></script>

<?php 
if (isset($_REQUEST["footerScripts"])) {
    foreach ($_REQUEST["footerScripts"] as $script) {
        print $script . "\n";
    }
}
?>

</html>

<?php 
if (WorkbenchContext::isEstablished() && memory_get_peak_usage() / toBytes(ini_get("memory_limit")) > 0.7) {
    WorkbenchContext::get()->clearCache();
}
if (isset($GLOBALS['REDIS'])) {
    redis()->close();
}
//USAGE: debug($showSuperVars = true, $showSoap = true, $customName = null, $customValue = null)
debug(true, true, null, null);
Ejemplo n.º 16
0
<?php
$_CONFIG['BASE_MOD'] = '..';
$_CONFIG['DB_POPULATE'] = true;
require_once('../config.inc.php');

if (!$_ENV['INSTALLED']) header('Location: install.php') and exit;
else if (!$_ENV['LOGGED_IN']) header('Location: login.php') and exit;

$tpl->maxUpload = min(toBytes(ini_get('upload_max_filesize')), toBytes(ini_get('post_max_size')));

$tpl->songlist = $_ENV['DB_DATA']['songs'];
$tpl->config = $_ENV['DB_DATA']['config'];
$tpl->links = $_ENV['DB_DATA']['links'];

$tpl->title = (isset($_ENV['DB_DATA']['config']['sitename'])) ? $_ENV['DB_DATA']['config']['sitename'] : '';
$tpl->introduction = (isset($_ENV['DB_DATA']['config']['introduction'])) ? $_ENV['DB_DATA']['config']['introduction'] : '';
$tpl->about = (isset($_ENV['DB_DATA']['config']['aboutme'])) ? $_ENV['DB_DATA']['config']['aboutme'] : '';

$tpl->display('adm/index.tpl.php');