示例#1
0
function check_path_permissions()
{
    $paths = array();
    $rel = '..';
    $publishRoot = chart_publish_directory();
    $paths[] = $publishRoot . 'static';
    $paths[] = $publishRoot . 'data';
    $paths[] = $publishRoot . 'images';
    $paths[] = $publishRoot . 'data/tmp';
    $paths[] = ROOT_PATH . 'tmp';
    $err = array();
    foreach ($paths as $path) {
        if (!is_writable($path)) {
            $err[] = $path;
        }
    }
    if (count($err) > 0) {
        $msg = '<h2>The following folders on your server need to be writable:</h2><ul>';
        foreach ($paths as $path) {
            $msg .= '<li><code>' . htmlspecialchars($path, ENT_QUOTES, 'UTF-8') . '</code></li>';
        }
        $msg .= '</ul>';
        $msg .= 'Read more about <a href="http://codex.wordpress.org/Changing_File_Permissions#Using_an_FTP_Client">how to change file permissions</a>';
        return $msg;
    }
    return '';
}
示例#2
0
function publish_js($user, $chart)
{
    $cdn_files = array();
    $static_path = chart_publish_directory() . 'static/lib/';
    $data = get_chart_content($chart, $user, false, '../');
    // generate visualization script
    $vis = $data['visualization'];
    $vis_js = $data['vis_js'];
    // add comment
    $vis_js[1] = "/*\n * datawrapper / vis / {$vis['id']} v{$vis['version']}\n" . " * generated on " . date('c') . "\n */\n" . $vis_js[1];
    file_put_contents($static_path . $vis_js[0], $vis_js[1]);
    $cdn_files[] = array($static_path . $vis_js[0], 'lib/' . $vis_js[0], 'application/javascript');
    // generate theme script
    $theme = $data['theme'];
    $theme_js = $data['theme_js'];
    $theme_js[1] = "/*\n * datawrapper / theme / {$theme['id']} v{$theme['version']}\n" . " * generated on " . date('c') . "\n */\n" . $theme_js[1];
    file_put_contents($static_path . $theme_js[0], $theme_js[1]);
    $cdn_files[] = array($static_path . $theme_js[0], 'lib/' . $theme_js[0], 'application/javascript');
    // generate chart script
    $chart_js = $data['chart_js'];
    $chart_js[1] = "/*\n * datawrapper / chart \n" . " * generated on " . date('c') . "\n */\n" . $chart_js[1];
    file_put_contents($static_path . $chart_js[0], $chart_js[1]);
    $cdn_files[] = array($static_path . $chart_js[0], 'lib/' . $chart_js[0], 'application/javascript');
    return $cdn_files;
}
示例#3
0
        }
    });
});
/**
 * API: upload csv file to a chart
 *
 * @param chart_id chart id
 */
$app->post('/charts/:id/data', function ($chart_id) use($app) {
    disable_cache($app);
    if_chart_is_writable($chart_id, function ($user, $chart) use($app) {
        $allowedExtensions = array('txt', 'csv', 'tsv');
        $sizeLimit = 2 * 1024 * 1024;
        // byte
        $uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
        $result = $uploader->handleUpload(chart_publish_directory() . 'data/tmp/');
        // check and correct file encoding
        $detect_encoding = function ($string) {
            $charsets = array('utf-8', 'iso-8859-15', 'iso-8859-1', 'iso-8859-3', 'windows-1251');
            foreach ($charsets as $charset) {
                $sample = @iconv($charset, $charset, $string);
                if (md5($sample) == md5($string)) {
                    return $charset;
                }
            }
            return null;
        };
        try {
            if (isset($result['success'])) {
                $data = file_get_contents($uploader->filename);
                $enc = $detect_encoding($data);
示例#4
0
 public function redirectPreviousVersions()
 {
     $current_target = $this->getCDNPath();
     $redirect_html = '<html><head><meta http-equiv="REFRESH" content="0; url=/' . $current_target . '"></head></html>';
     $redirect_file = chart_publish_directory() . 'static/' . $this->getID() . '/redirect.html';
     file_put_contents($redirect_file, $redirect_html);
     $files = array();
     for ($v = 0; $v < $this->getPublicVersion(); $v++) {
         $files[] = array($redirect_file, $this->getCDNPath($v) . 'index.html', 'text/html');
     }
     DatawrapperHooks::execute(DatawrapperHooks::PUBLISH_FILES, $files);
 }