Esempio n. 1
0
/**
 * metaWeblog.newMediaObject
 *
 * @param array $params Contains blog id, username, password and file
 */
function metaweblog_newMediaObject($params)
{
    global $PIVOTX, $xmlrpcerruser;
    $conv = $params->getParam(0);
    $blogid = $conv->scalarval();
    $conv = $params->getParam(1);
    $user = $conv->scalarval();
    $conv = $params->getParam(2);
    $pass = $conv->scalarval();
    $conv = $params->getParam(3);
    $file = php_xmlrpc_decode($conv);
    // Check password
    $login = pivotx_get_userid($user, $pass);
    $uid = $login['uid'];
    if ($uid != -1) {
        if (!empty($file['name'])) {
            $filename = basename($file['name']);
            // Clean up file name (only lowercase letters, numbers, underscores and hyphens)
            $filename = preg_replace("/[^a-z0-9._-]/", "", str_replace(array(' ', '%20'), '-', strtolower($filename)));
            $filename = makeUploadFolder($filename) . $filename;
            // Always write to a new file if the name already exists
            if (file_exists($filename)) {
                $fileext = getExtension($filename);
                $tmp = substr($filename, 0, -strlen(".{$fileext}"));
                while (file_exists($filename)) {
                    $i++;
                    $filename = $tmp . '_' . $i . ".{$fileext}";
                }
            }
            $url = str_replace($PIVOTX['paths']['upload_base_path'], $PIVOTX['paths']['upload_base_url'], $filename);
            writeFile($filename, $file['bits'], 'wb');
        } else {
            debug("Media object has no name.");
            $err = "Media object has no name.";
        }
    } else {
        $err = $login['err'];
    }
    if ($err) {
        return new xmlrpcresp(0, $xmlrpcerruser + 1, $err);
    } else {
        $myResp = php_xmlrpc_encode(array('url' => $PIVOTX['paths']['host'] . $url));
        return new xmlrpcresp($myResp);
    }
}
Esempio n. 2
0
// Make sure we're logged in..
require_once dirname(__FILE__) . '/lib.php';
initializePivotX(false);
$PIVOTX['session']->minLevel(PIVOTX_UL_NORMAL);
// Settings
$targetDir = $PIVOTX['paths']['cache_path'] . 'plupload';
$cleanupTargetDir = true;
// Remove old files
$maxFileAge = 60 * 60;
// Temp file age in seconds
switch ($_GET['type']) {
    case 'image':
    case 'images':
    case 'file':
    case 'files':
        $targetDir = makeUploadFolder();
        $cleanupTargetDir = false;
        break;
}
if (isset($_GET['path']) && $_GET['path'] != '') {
    /* Using same user level as in fileOperations (in lib.php) */
    $PIVOTX['session']->minLevel(PIVOTX_UL_ADVANCED);
    $path = cleanPath($_GET['path']);
    // Don't ever allow uploading outside the images, templates and db folders.
    if (!uploadAllowed($path)) {
        die('{"jsonrpc" : "2.0", "error" : {"code": 104, "message": "Uploading to illegal directory."}, "id" : "id"}');
    }
    $targetDir = stripTrailingSlash($path);
    $cleanupTargetDir = false;
}
// 5 minutes execution time