コード例 #1
0
ファイル: wp-d3.php プロジェクト: qdwwqxwn/www
/**
 * Creates a div around the javascript code to visualize it.
 * Accepts the canvas="xxx" parameter to specify the canvas name. By default it is
 * created with id='canvas' (so original uh ;-))
 */
function print_source($attr, $content)
{
    extract(shortcode_atts(array('canvas' => 'canvas'), $attr));
    $chartId = $canvas;
    $field_code = get_post_meta(get_the_ID(), $chartId, true);
    $code = "";
    $result = "";
    if (!empty($field_code)) {
        $jsonCode = json_decode($field_code, true);
        $code = preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n\\']+/", "\n", $jsonCode['code']);
        // remove empty lines
        foreach ($jsonCode['includes'] as $include) {
            if (substr_compare($include, "js", -strlen("js"), strlen("js")) === 0) {
                $result = $result . getJavaScriptInclude($include);
            }
            if (substr_compare($include, "css", -strlen("css"), strlen("css")) === 0) {
                $result = $result . getCssInclude($include);
            }
        }
    } else {
        $code = preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n\\']+/", "\n", $content);
        // remove empty lines
    }
    if (containsAutoIdFlag($code)) {
        $genChartId = genRandomId();
        $code = replaceAutoIdFlag($code, $genChartId);
        $chartId = $genChartId;
    }
    $code = wrapAsFunction($code, $chartId);
    $result = $result . '<div class="' . $chartId . '">' . '<script type="text/javascript">' . $code . '</script>' . '</div>';
    return $result;
}
コード例 #2
0
ファイル: utils.php プロジェクト: qdwwqxwn/www
function previewContent()
{
    $postId = $_REQUEST["postId"];
    $editorName = $_REQUEST["editor"];
    $val = get_post_custom_keys($postId);
    $keys = array();
    foreach ($val as $var) {
        if (!strcmp($editorName, $var)) {
            $content = get_post_custom_values($var, $postId);
            break;
        }
    }
    $code = json_decode($content[0], true);
    $genChartId = genRandomId();
    if (!containsAutoIdFlag($code["code"])) {
        $genChartId = $editorName;
    }
    $includes = $code["includes"];
    $code = replaceAutoIdFlag($code["code"], $genChartId);
    $result = "";
    foreach ($includes as $include) {
        if (substr_compare($include, "js", -strlen("js"), strlen("js")) === 0) {
            $result = $result . getJavaScriptInclude($include);
        }
        if (substr_compare($include, "css", -strlen("css"), strlen("css")) === 0) {
            $result = $result . getCssInclude($include);
        }
    }
    echo "<html><head>" . getJavaScriptInclude(plugins_url('wp-d3/js/d3.3.5.5.min.js')) . $result . "</head>" . "<body><div class=\"" . $genChartId . "\"\\>" . "<script type=\"text/javascript\">" . $code . "</script>" . "</body></html>";
    exit;
}