コード例 #1
0
ファイル: utils.php プロジェクト: slee124565/flh-pvstation
/**
 * Returns available resource files
 */
function amcharts_get_available_resources($type = 'remote', $paths = '')
{
    $res = '';
    if ('local' == $type) {
        $dirs = amcharts_split_libs($paths);
        // libraries
        $libs = array();
        foreach ($dirs as $path) {
            $libs = array_merge($libs, amcharts_get_resource_files(ABSPATH . $path, home_url($path)));
        }
        // maps
        reset($dirs);
        foreach ($dirs as $path) {
            $libs = array_merge($libs, amcharts_get_resource_files(ABSPATH . $path . 'maps/js/', home_url($path . 'maps/js/')));
        }
        // plugins
        reset($dirs);
        foreach ($dirs as $path) {
            $libs = array_merge($libs, amcharts_get_resource_files_deep(ABSPATH . $path . 'plugins/', home_url($path . 'plugins/')));
        }
        $res = implode("\n", $libs);
    } else {
        // load from amcharts.com (fall back to local hardocded list if url wrappers are disabled in PHP)
        if (!($res = @file_get_contents('http://www.amcharts.com/lib/3/resources.php'))) {
            $res = file_get_contents(AMCHARTS_DIR . '/defaults/resources.txt');
        }
    }
    return $res;
}
コード例 #2
0
ファイル: editing.php プロジェクト: slee124565/flh-pvstation
/**
 * Resources meta box
 */
function amcharts_resources_box($post)
{
    // nonce field
    wp_nonce_field(AMCHARTS_NONCE, 'amcharts_nonce');
    // get post data
    $post_resources = get_post_meta($post->ID, '_amcharts_resources', true);
    // get available resources
    $settings = get_option('amcharts_options', amcharts_get_defaults());
    // get libs
    $libs = amcharts_split_libs($settings['resources']);
    $libs = array_merge($libs, amcharts_split_libs($settings['custom_resources']));
    // new?
    if (amcharts_is_new_post() && $_GET['chart_type']) {
        $post_resources = $settings['chart_types'][$_GET['chart_type']]['default_resources'];
    }
    ?>

	<fieldset class="amcharts-resource-group">	
		<p>
			<textarea name="resources" id="amcharts-resources" class="widefat amcharts-resources"><?php 
    echo esc_textarea($post_resources);
    ?>
</textarea>
		</p>
	
		<select class="amcharts-select-resource">
			<option value=""><?php 
    _e('Select a resource', 'amcharts');
    ?>
</option>
			<?php 
    foreach ($libs as $lib) {
        ?>
<option value="<?php 
        echo esc_attr($lib);
        ?>
"><?php 
        echo $lib;
        ?>
</option><?php 
    }
    ?>
		</select>
		<input type="button" class="button amcharts-add-resource" value="<?php 
    _e('Add', 'amcharts');
    ?>
" />
	</fieldset>
	<?php 
}
コード例 #3
0
ファイル: setup.php プロジェクト: slee124565/flh-pvstation
function amcharts_shortcode($atts)
{
    extract(shortcode_atts(array('id' => ''), $atts));
    // try loading by slug first
    if ($chart = get_posts(array('post_type' => 'amchart', 'fields' => 'ids', 'posts_per_page' => 1, 'meta_query' => array(array('key' => '_amcharts_slug', 'value' => $id))))) {
        $id = $chart[0];
    } else {
        if (!($chart = get_post($id))) {
            return '';
        }
    }
    // increment instance
    amcharts_increment_instance();
    // get meta
    $resources = get_post_meta($id, '_amcharts_resources', true);
    $html = amcharts_parse_code(get_post_meta($id, '_amcharts_html', true));
    $javascript = amcharts_parse_code(get_post_meta($id, '_amcharts_javascript', true));
    // add data passed via shortcode
    $pass = array();
    foreach ($atts as $att) {
        if (0 === strpos($att, 'data-')) {
            list($key, $val) = explode('=', $att);
            $pass[substr($key, 5)] = str_replace('"', '', $val);
        }
    }
    if (sizeof($pass)) {
        $javascript = "AmCharts.wpChartData = " . json_encode($pass) . ";\n" . $javascript;
    }
    // wrap with exception code if necessary
    $settings = get_option('amcharts_options');
    if (isset($settings['wrap']) && '1' == $settings['wrap']) {
        $javascript = "try {\n" . $javascript . "\n}\ncatch( err ) { console.log( err ); }";
    }
    // enqueue resources
    $libs = amcharts_split_libs($resources);
    foreach ($libs as $lib) {
        if (preg_match('/\\.css/i', $lib)) {
            wp_enqueue_style('amcharts-external-' . md5(basename($lib)), $lib, array(), AMCHARTS_VERSION);
        } else {
            wp_enqueue_script('amcharts-external-' . md5(basename($lib)), $lib, array(), AMCHARTS_VERSION, true);
        }
    }
    // enqueue JavaScript part
    amcharts_enqueue_javascript($javascript);
    return $html;
}
コード例 #4
0
ファイル: charts.php プロジェクト: slee124565/flh-pvstation
        $( '#live-editor-url' ).addClass( 'error' ).prop( 'placeholder', '<?php 
echo esc_js(__('Please enter a chart URL', 'amcharts'));
?>
' );
        return;
      }
      var embed = '[embed';
      var width = $( '#live-editor-width' ).val();
      var height = $( '#live-editor-height' ).val();
      if ( '' != width ) embed += ' width="' + width + '"';
      if ( '' != height ) embed += ' height="' + height + '"';
      <?php 
// use our own libraries?
$settings = get_option('amcharts_options', array('own' => 0, 'paths' => ''));
if ('1' == $settings['own']) {
    $paths = amcharts_split_libs($settings['paths']);
    $path = array_shift($paths);
    if ('' == $path) {
        break;
    }
    $path = home_url($path);
    ?>
        embed += ' src="<?php 
    echo $path;
    ?>
" tkn="replaceDefault"';
        <?php 
}
?>
      embed += ']' + url + '[/embed]'
      window.parent.tinyMCE.activeEditor.execCommand( 'mceInsertContent', false, embed );
コード例 #5
0
ファイル: settings.php プロジェクト: slee124565/flh-pvstation
function amcharts_settings_show()
{
    // check permissions
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    // unqueue required scripts and styles
    wp_enqueue_style('jquery-ui-smoothness', plugins_url('lib/jquery-ui/css/smoothness/jquery-ui-1.10.4.custom.min.css', AMCHARTS_BASE), array(), AMCHARTS_VERSION);
    wp_enqueue_script('jquery-ui-tabs');
    // get chart type settings
    $chart_types = amcharts_get_chart_types();
    $chart_type_libs = amcharts_get_chart_type_libs();
    // load current settings
    $settings = get_option('amcharts_options', amcharts_get_defaults());
    // process save
    $errors = array();
    if (!empty($_POST) && wp_verify_nonce($_POST['amcharts_nonce'], AMCHARTS_NONCE)) {
        // save previous location setting for checking later
        $prev_location = $settings['location'];
        // get submited data
        $settings['own'] = isset($_POST['own']) && '1' == $_POST['own'] ? '1' : '0';
        $settings['wrap'] = isset($_POST['wrap']) && '1' == $_POST['wrap'] ? '1' : '0';
        $settings['location'] = isset($_POST['location']) ? trim($_POST['location']) : 'remote';
        $settings['paths'] = isset($_POST['paths']) ? trim($_POST['paths']) : '';
        $settings['custom_resources'] = isset($_POST['custom_resources']) ? trim($_POST['custom_resources']) : '';
        reset($chart_types);
        foreach ($chart_types as $chart_type => $chart_type_name) {
            $settings['chart_types'][$chart_type] = array('default_resources' => trim($_POST['chart_types'][$chart_type]['default_resources']), 'custom_resources' => (int) $_POST['chart_types'][$chart_type]['custom_resources'], 'default_html' => trim($_POST['chart_types'][$chart_type]['default_html']), 'default_javascript' => trim($_POST['chart_types'][$chart_type]['default_javascript']));
        }
        // strip slashes if any
        if (!get_magic_quotes_gpc()) {
            $settings = stripslashes_deep($settings);
        }
        // refresh built-in resources
        if ($prev_location != $settings['location'] || isset($_POST['refresh']) && '1' == $_POST['refresh']) {
            $settings['resources'] = amcharts_get_available_resources($settings['location'], $settings['paths']);
            reset($chart_type_libs);
            foreach ($chart_type_libs as $chart_type => $libs) {
                if (!$settings['chart_types'][$chart_type]['custom_resources']) {
                    $settings['chart_types'][$chart_type]['default_resources'] = amcharts_get_resources($libs, $settings['resources']);
                }
            }
        }
        // save settings
        if (0 === count($errors)) {
            update_option('amcharts_options', $settings);
            $success = __('Settings were successfully saved!');
        }
    }
    ?>
  
  <?php 
    screen_icon();
    ?>
  <h2><?php 
    echo __('amCharts: Settings');
    ?>
</h2>
  
  <?php 
    if (count($errors) > 0) {
        ?>
  <div class="message error"><?php 
        echo wpautop(implode("\n", $errors));
        ?>
</div>
  <?php 
    }
    ?>
  <?php 
    if (isset($success) && !empty($success)) {
        ?>
  <div class="message updated"><?php 
        echo wpautop($success);
        ?>
</div>
  <?php 
    }
    ?>
  
  <h3><?php 
    echo __('Resources', 'amcharts');
    ?>
</h3>
  
  <form method="post" action="">
    
  <table class="form-table">
    <tbody>
      <tr valign="top">
        <th scope="row"><?php 
    _e('Resource Storage', 'amcharts');
    ?>
</th>
        <td>
          <fieldset>
            <p>
              <label><input type="radio" name="location" value="remote" id="amcharts-location-remote" <?php 
    echo 'remote' == $settings['location'] ? ' checked="checked"' : '';
    ?>
 /> <?php 
    _e('Resources are stored remotely ', 'amcharts');
    ?>
</label>
            </p>
            <p class="description"><?php 
    _e('The free versions of libraries will be loaded from www.amcharts.com. These are fully functional but will show a small branding link on charts or maps.', 'amcharts');
    ?>
</p>
            <p class="description"><?php 
    _e('Want a link-free version? <a href="http://www.amcharts.com/online-store/" target="_blank">Purchase a commercial version</a> and help the development of this product as well as increase your karma points in the process.', 'amcharts');
    ?>
</p>
          </fieldset>
        </td>
      </tr>

      <tr valign="top">
        <th scope="row"></th>
        <td>
          <fieldset>
            <p>
              <label><input type="radio" name="location" value="local" id="amcharts-location-local" <?php 
    echo 'local' == $settings['location'] ? ' checked="checked"' : '';
    ?>
              /> <?php 
    _e('Resources are stored locally ', 'amcharts');
    ?>
</label>
            </p>
            <p class="description"><?php 
    _e('This allows you to load the libraries from the local server.', 'amcharts');
    ?>
</p>
          </fieldset>
        </td>
      </tr>

      <tr valign="top" id="amcharts-live-editor-group" <?php 
    echo 'remote' == $settings['location'] ? 'style="display: none;"' : '';
    ?>
>
        <th scope="row"><?php 
    _e('Live Editor Integration', 'amcharts');
    ?>
</th>
        <td>
          <fieldset>
            <p>
              <label><input type="checkbox" name="own" value="1" id="amcharts-own-libraries" <?php 
    echo '1' == $settings['own'] ? ' checked="checked"' : '';
    ?>
 /> <?php 
    _e('Use local amCharts libraries for Live Editor-hosted charts', 'amcharts');
    ?>
</label>
            </p>
            <p class="description"><?php 
    _e('If you want to display Live Editor-created charts without branding link:', 'amcharts');
    ?>
</p>
            <p class="description">- <?php 
    _e('Install commercial version of amCharts libraries.', 'amcharts');
    ?>
</p>
            <p class="description">- <?php 
    _e('Check "Resources are stored locally" above.', 'amcharts');
    ?>
</p>
            <p class="description">- <?php 
    _e('You may need to also click "Find them for me" button under "Local Paths".', 'amcharts');
    ?>
</p>
            <p class="description">- <?php 
    _e('Check "Use local amCharts libraries" above.', 'amcharts');
    ?>
</p>
          </fieldset>
        </td>
      </tr>

      <tr valign="top">
        <th scope="row"><?php 
    _e('Error Handling', 'amcharts');
    ?>
</th>
        <td>
          <fieldset>
            <p>
              <label><input type="checkbox" name="wrap" value="1" <?php 
    echo '1' == $settings['wrap'] ? ' checked="checked"' : '';
    ?>
 /> <?php 
    _e('Use exception handling on chart and map code (recommended)', 'amcharts');
    ?>
</label>
            </p>
            <p class="description"><?php 
    _e('If checked, the code for charts and maps will be wrapped with exception handling code (try / catch).', 'amcharts');
    ?>
</p>
            <p class="description"><?php 
    _e('This will make sure a faulty code does not prevent other JavaScript on the same page executing properly.', 'amcharts');
    ?>
</p>
          </fieldset>
        </td>
      </tr>
      
      <tr valign="top" id="amcharts-path-group" <?php 
    echo 'remote' == $settings['location'] ? 'style="display: none;"' : '';
    ?>
>
        <th scope="row">
          <?php 
    _e('Local Paths', 'amcharts');
    ?>
          <p class="description"><?php 
    _e('Enter paths to your amCharts folders. Separate them by line breaks. The paths must be relative to your web root.', 'amcharts');
    ?>
 (<?php 
    echo home_url();
    ?>
)</p>
        </th>
        <td>
          <fieldset>
            <p>
              <span class="description"><?php 
    echo home_url();
    ?>
</span>/
            </p>
            <p>
              <textarea name="paths" class="widefat" id="amcharts-path"><?php 
    echo esc_textarea($settings['paths']);
    ?>
</textarea>
              <p class="description"><?php 
    _e('If you are not sure what to do, just unzip the amCharts archive you have downloaded and put into some directory under your web root. Then click "Find them for me".', 'amcharts');
    ?>
</p>
            </p>
            <p>
              <input type="button" class="button" id="amcharts-find-path" value="<?php 
    echo esc_attr(__('Find them for me', 'amcharts'));
    ?>
" />
              <span class="amcharts-working" id="amcharts-path-working" style="display: none;"></span>
              <span class="amcharts-error" id="amcharts-find-path-error" style="display: none;"><?php 
    _e('amCharts library was not found on your server', 'amcharts');
    ?>
</span>
            </p>
          </fieldset>
        </td>
      </tr>
      
      <tr valign="top">
        <th scope="row">
          <?php 
    _e('Resource List', 'amcharts');
    ?>
          <p class="description"><?php 
    _e('This is a list of resources available for use. You will be able to select them while creating charts or maps.', 'amcharts');
    ?>
</p>
        </th>
        <td>
          <fieldset>
            <div class="amcharts-resource-list">
              <?php 
    echo nl2br($settings['resources']);
    ?>
            </div>
            <p>
              <input type="submit" class="button" id="amcharts-rescan-resources" value="<?php 
    echo esc_attr(__('Refresh the list', 'amcharts'));
    ?>
" />
              <span class="description"><?php 
    _e('Attention! Pressing this button will save current settings.', 'amcharts');
    ?>
</span>
            </p>
          </fieldset>
        </td>
      </tr>
      
      <tr valign="top">
        <th scope="row">
          <?php 
    _e('Custom Resources', 'amcharts');
    ?>
          <p class="description"><?php 
    _e('Add your own resources here. Full or relative URLs (we include them the way you have them here). Separate by line break.', 'amcharts');
    ?>
</p>
        </th>
        <td>
          <fieldset>
            <p>
              <textarea name="custom_resources" class="widefat" id="amcharts-custom-resources"><?php 
    echo esc_textarea($settings['custom_resources']);
    ?>
</textarea>
            </p>
          </fieldset>
        </td>
      </tr>
      
      <tr valign="top">
        <th scope="row">
          <?php 
    _e('Defaults', 'amcharts');
    ?>
          <p class="description"><?php 
    _e('This section allows setting default resources, HTML and JavaScript code per chart/map type.', 'amcharts');
    ?>
</p>
          <p class="description"><?php 
    _e('When creating new chart or map entry, you will be able to select from one of these presets.', 'amcharts');
    ?>
</p>
        </th>
        <td>
          <div id="amcharts-tabs">
            <ul>
              <?php 
    reset($chart_types);
    foreach ($chart_types as $chart_type => $chart_type_name) {
        ?>
<li><a href="#tabs-<?php 
        echo $chart_type;
        ?>
"><?php 
        echo $chart_type_name;
        ?>
</a></li><?php 
    }
    ?>
            </ul>
            <?php 
    reset($chart_types);
    foreach ($chart_types as $chart_type => $chart_type_name) {
        // let the user edit resource list?
        $edit = $settings['chart_types'][$chart_type]['custom_resources'] ? true : false;
        ?>
<div id="tabs-<?php 
        echo $chart_type;
        ?>
" class="amcharts-tab">

              <h4><?php 
        _e('Resources', 'amcharts');
        ?>
</h4>
              
              <div class="amcharts-resource-list" style="display: <?php 
        echo $edit ? 'none' : 'block';
        ?>
;">
                <?php 
        if ('' == $settings['chart_types'][$chart_type]['default_resources'] && 'local' == $settings['location']) {
            ?>
                  <p class="amcharts-notice"><?php 
            _e('We did not find libraries required for this chart type in your local storage.', 'amcharts');
            ?>
</p>
                  <p class="amcharts-notice"><?php 
            _e('Make sure you hit the "Refresh the list" button higher on this page when you install them.', 'amcharts');
            ?>
</p>
                <?php 
        } else {
            ?>
                  <?php 
            echo nl2br($settings['chart_types'][$chart_type]['default_resources']);
            ?>
                <?php 
        }
        ?>
              </div>
              
              <fieldset class="amcharts-resource-group" style="display: <?php 
        echo $edit ? 'block' : 'none';
        ?>
;">
                <p>
                  <textarea name="chart_types[<?php 
        echo $chart_type;
        ?>
][default_resources]" rows="4" class="widefat amcharts-resources"><?php 
        echo esc_textarea($settings['chart_types'][$chart_type]['default_resources']);
        ?>
</textarea>
                </p>
                <p>
                  <?php 
        $libs = amcharts_split_libs($settings['resources']);
        $libs = array_merge($libs, amcharts_split_libs($settings['custom_resources']));
        ?>
                  <select class="amcharts-select-resource">
                    <option value=""><?php 
        _e('Select a resource', 'amcharts');
        ?>
</option>
                    <?php 
        foreach ($libs as $lib) {
            ?>
<option value="<?php 
            echo esc_attr($lib);
            ?>
"><?php 
            echo $lib;
            ?>
</option><?php 
        }
        ?>
                  </select>
                  <input type="button" class="button amcharts-add-resource" value="<?php 
        _e('Add', 'amcharts');
        ?>
" />
                </p>
              </fieldset>
              
              <p>
                <label><input type="checkbox" name="chart_types[<?php 
        echo $chart_type;
        ?>
][custom_resources]" class="amcharts-edit-myself" value="1" <?php 
        if ($settings['chart_types'][$chart_type]['custom_resources']) {
            ?>
checked="checked"<?php 
        }
        ?>
/> <?php 
        _e('I want to manage resource list myself', 'amcharts');
        ?>
</label>
              </p>
              
              <p class="description">
                <?php 
        _e("If the above box unchecked, plugin will manage required resources and their urls for you. If this is checked, you're on your own ;)", 'amcharts');
        ?>
              </p>
              
              
              <h4><?php 
        _e('HTML', 'amcharts');
        ?>
</h4>
              <p>
                <textarea name="chart_types[<?php 
        echo $chart_type;
        ?>
][default_html]" class="widefat code code-html"><?php 
        echo esc_textarea($settings['chart_types'][$chart_type]['default_html']);
        ?>
</textarea>
              </p>
              <p>
                <p class="description"><?php 
        _e('Enter the default HTML to populate new entries with. Use <strong>%CHART%</strong> symbol for safe and unique chart ids and variables.');
        ?>
</p>
              </p>
              
              <h4><?php 
        _e('JavaScript', 'amcharts');
        ?>
</h4>
              
              <p>
                <textarea name="chart_types[<?php 
        echo $chart_type;
        ?>
][default_javascript]" class="widefat code code-javascript"><?php 
        echo esc_textarea($settings['chart_types'][$chart_type]['default_javascript']);
        ?>
</textarea>
              </p>
              <p>
                <p class="description"><?php 
        _e('Enter the default JavaScript to populate new entries with. Use <strong>%CHART%</strong> symbol for safe and unique chart ids and variables.');
        ?>
</p>
              </p>
              
            </div><?php 
    }
    ?>
          </div>
        </td>
      </tr>
      
    </tbody>
  </table>
  
  <p>
    <input type="submit" class="button-primary" value="Save Settings &raquo;" />
    <input type="hidden" id="amcharts-refresh" name="refresh" value="0" />
    <?php 
    wp_nonce_field(AMCHARTS_NONCE, 'amcharts_nonce');
    ?>
  </p>
  
  </form>
  
  <?php 
}
コード例 #6
0
ファイル: preview.php プロジェクト: slee124565/flh-pvstation
<?php

/**
 * The template for reviewing amCharts chart
 */
// enqueue resources
$libs = amcharts_split_libs(amcharts_stripslashes($_POST['amcharts_resources']));
foreach ($libs as $lib) {
    if (preg_match('/\\.css/i', $lib)) {
        wp_enqueue_style('amcharts-external-' . md5(basename($lib)), $lib, array(), AMCHARTS_VERSION);
    } else {
        wp_enqueue_script('amcharts-external-' . md5(basename($lib)), $lib, array(), AMCHARTS_VERSION, true);
    }
}
// enqueue JavaScript part
amcharts_increment_instance();
$javascript = amcharts_parse_code(amcharts_stripslashes($_POST['amcharts_javascript']));
$settings = get_option('amcharts_options');
if (isset($settings['wrap']) && '1' == $settings['wrap']) {
    $javascript = "try {\n" . $javascript . "\n}\ncatch( err ) { console.log( err ); }";
}
amcharts_enqueue_javascript($javascript);
?>

<!DOCTYPE html>
<html <?php 
language_attributes();
?>
>
	<head>
		<meta charset="<?php