PageRenderTime 48ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/nonus/theme/shortcodes/graph/ctGraphCircleShortcode.class.php

https://github.com/alniko009/magic
PHP | 99 lines | 58 code | 16 blank | 25 comment | 5 complexity | d937ec157dcc1f21ec8b036f88a3c4fb MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Bar shortcode
  4. */
  5. class ctGraphCircleShortcode extends ctShortcode {
  6. /**
  7. * Enqueue scripts
  8. */
  9. public function enqueueScripts() {
  10. wp_register_script('jquery-easy-pie', CT_THEME_ASSETS . '/js/jquery.easy-pie-chart.js', array('jquery'));
  11. wp_enqueue_script('jquery-easy-pie');
  12. }
  13. /**
  14. * Returns name
  15. * @return string|void
  16. */
  17. public function getName() {
  18. return 'Circle';
  19. }
  20. /**
  21. * Shortcode name
  22. * @return string
  23. */
  24. public function getShortcodeName() {
  25. return 'graph_circle';
  26. }
  27. /**
  28. * Handles shortcode
  29. * @param $atts
  30. * @param null $content
  31. * @return string
  32. */
  33. public function handle($atts, $content = null) {
  34. extract(shortcode_atts($this->extractShortcodeAttributes($atts), $atts));
  35. $percent = floatval($percent);
  36. $animate == floatval($animate);
  37. $size = (int)$size;
  38. $hasFontSize = $fontsize ? true : false;
  39. $hasVerPosition = $vertposition ? true : false;
  40. $fontsize = $hasFontSize ? $fontsize : ceil(($size / 10) * 2);
  41. //we try to fix position of icons
  42. if (!$hasVerPosition && $icon) {
  43. $vertposition = '-' . floor($size / 10 / 3);
  44. $hasVerPosition = true;
  45. }
  46. $verStyle = $hasVerPosition ? ' style="top:' . (int)$vertposition . 'px;"' : '';
  47. $text = '<span' . $verStyle . ' class="text">' . $text . '</span>';
  48. if ($icon) {
  49. $text = '<span' . $verStyle . '><i class="' . $icon . '"></i></span>';
  50. if (!$hasFontSize) {
  51. $fontsize *= 2;
  52. }
  53. }
  54. $scalecolor = $scalecolor ? $scalecolor : 'false';
  55. $trackacolor = $trackcolor ? $trackcolor : 'false';
  56. return '<div style="' . ($fontcolor ? 'color:' . esc_attr($fontcolor) . ';' : '') . 'font-size:' . esc_attr($fontsize) . 'px" class="graph-circle-' . ($icon ? 'icon' : 'text') . ' graph-circle-size-' . $size . ' graph-circle" data-percent="' . $percent . '" data-barcolor="' . esc_attr($barcolor) . '" data-trackcolor="' . esc_attr($trackcolor) . '" data-scalecolor="' . esc_attr($scalecolor) . '" data-linecap="' . esc_attr($linecap) . '" data-linewidth="' . esc_attr($linewidth) . '" data-size="' . esc_attr($size) . '" data-animate="' . esc_attr($animate) . '">' . $text . '</div>';
  57. }
  58. /**
  59. * Returns config
  60. * @return null
  61. */
  62. public function getAttributes() {
  63. return array(
  64. 'percent' => array('label' => __('percent', 'ct_theme'), 'default' => '', 'type' => 'input', 'help' => __('in %', 'ct_theme')),
  65. 'text' => array('label' => __("text inside circle", 'ct_theme'), 'help' => __('if icon selected, text will not be displayed', 'ct_theme')),
  66. 'icon' => array('label' => __('entypo icon', 'ct_theme'), 'type' => "icon", 'default' => '', 'link' => CT_THEME_ASSETS . '/shortcode/awesome/index.html'),
  67. 'barcolor' => array('label' => __('bar color', 'ct_theme'), 'default' => '#2db7ff', 'type' => 'colorpicker', 'help' => __('The color of the curcular bar.', 'ct_theme')),
  68. 'trackcolor' => array('label' => __('track color', 'ct_theme'), 'default' => '#e6e6e6', 'type' => 'colorpicker', 'help' => __('The color of the track for the bar, leave it blank to disable rendering.', 'ct_theme')),
  69. 'scalecolor' => array('label' => __('scale color', 'ct_theme'), 'default' => 'false', 'type' => 'colorpicker', 'help' => __('The color of the scale lines, leave it blank to disable rendering.', 'ct_theme')),
  70. 'linecap' => array('label' => __('line cap', 'ct_theme'), 'default' => 'default', 'type' => "select", 'choices' =>
  71. array('butt' => __('button', 'ct_theme'), 'round' => __('round', 'ct_theme'), 'square' => __('square', 'ct_theme')),
  72. 'help' => __('defines how the ending of the bar line looks like', 'ct_theme')
  73. ),
  74. 'linewidth' => array('label' => __("Width of the bar line", 'ct_theme'), 'default' => '15', 'help' => __('in px', 'ct_theme')),
  75. 'size' => array('label' => __("size of chart", 'ct_theme'), 'default' => '170', 'help' => __('in px', 'ct_theme')),
  76. 'fontsize' => array('label' => __("font/icon size", 'ct_theme'), 'default' => '', 'help' => __("in px.", 'ct_theme')),
  77. 'fontcolor' => array('label' => __('font/icon color', 'ct_theme'), 'default' => '', 'type' => 'colorpicker'),
  78. 'vertposition' => array('label' => "vertical position", 'default' => '0', 'help' => __('useful for positioning icons. Negative value will move content up, position down. Value in px.', 'ct_theme')),
  79. 'animate' => array('label' => __('animation speed', 'ct_theme'), 'default' => '1000', 'help' => __('Time in milliseconds (1000 is 1 second) for a eased animation of the bar growing, or 0 to deactivate.', 'ct_theme')),
  80. );
  81. }
  82. }
  83. new ctGraphCircleShortcode();