| 1 |
<?php |
| 2 |
|
| 3 |
// +----------------------------------------------------------------------+ |
| 4 |
// | Copyright 2013 Madpixels (email : visualizer@madpixels.net) | |
| 5 |
// +----------------------------------------------------------------------+ |
| 6 |
// | This program is free software; you can redistribute it and/or modify | |
| 7 |
// | it under the terms of the GNU General Public License, version 2, as | |
| 8 |
// | published by the Free Software Foundation. | |
| 9 |
// | | |
| 10 |
// | This program is distributed in the hope that it will be useful, | |
| 11 |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 |
// | GNU General Public License for more details. | |
| 14 |
// | | |
| 15 |
// | You should have received a copy of the GNU General Public License | |
| 16 |
// | along with this program; if not, write to the Free Software | |
| 17 |
// | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, | |
| 18 |
// | MA 02110-1301 USA | |
| 19 |
// +----------------------------------------------------------------------+ |
| 20 |
// | Author: Eugene Manuilov <eugene@manuilov.org> | |
| 21 |
// +----------------------------------------------------------------------+ |
| 22 |
|
| 23 |
/** |
| 24 |
* Media view template rendering class. |
| 25 |
* |
| 26 |
* @category Visualizer |
| 27 |
* @package Render |
| 28 |
* |
| 29 |
* @since 1.0.0 |
| 30 |
*/ |
| 31 |
class Visualizer_Render_Templates extends Visualizer_Render { |
| 32 |
|
| 33 |
/** |
| 34 |
* The array of template names. |
| 35 |
* |
| 36 |
* @since 1.0.0 |
| 37 |
* |
| 38 |
* @access private |
| 39 |
* @var array |
| 40 |
*/ |
| 41 |
private $_templates = array( |
| 42 |
'library-chart', |
| 43 |
'library-empty', |
| 44 |
); |
| 45 |
|
| 46 |
/** |
| 47 |
* Renders concreate template and wraps it into script tag. |
| 48 |
* |
| 49 |
* @since 1.0.0 |
| 50 |
* |
| 51 |
* @param string $id The name of a template. |
| 52 |
* @param string $callback The name of the function to render a template. |
| 53 |
*/ |
| 54 |
private function _renderTemplate( $id, $callback ) { |
| 55 |
echo '<script id="tmpl-visualizer-', $id, '" type="text/html">'; |
| 56 |
call_user_func( array( $this, $callback ) ); |
| 57 |
echo '</script>'; |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Renders library-chart template. |
| 62 |
* |
| 63 |
* @since 1.0.0 |
| 64 |
* |
| 65 |
* @access protected |
| 66 |
*/ |
| 67 |
protected function _renderLibraryChart() { |
| 68 |
echo '<div class="visualizer-library-chart-footer visualizer-clearfix">'; |
| 69 |
echo '<a class="visualizer-library-chart-action visualizer-library-chart-delete" href="javascript:;" title="', esc_attr__( 'Delete', Visualizer_Plugin::NAME ), '"></a>'; |
| 70 |
echo '<a class="visualizer-library-chart-action visualizer-library-chart-insert" href="javascript:;" title="', esc_attr__( 'Insert', Visualizer_Plugin::NAME ), '"></a>'; |
| 71 |
|
| 72 |
echo '<span class="visualizer-library-chart-shortcode" title="', esc_attr__( 'Click to select', Visualizer_Plugin::NAME ), '"> [visualizer id="{{data.id}}"] </span>'; |
| 73 |
echo '</div>'; |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Renders library-empty template. |
| 78 |
* |
| 79 |
* @since 1.0.0 |
| 80 |
* |
| 81 |
* @access protected |
| 82 |
*/ |
| 83 |
protected function _renderLibraryEmpty() { |
| 84 |
echo '<div class="visualizer-library-chart">'; |
| 85 |
echo '<div class="visualizer-library-chart-canvas visualizer-library-nochart-canvas">'; |
| 86 |
echo '<div class="visualizer-library-notfound">', esc_html__( 'No charts found', Visualizer_Plugin::NAME ), '</div>'; |
| 87 |
echo '</div>'; |
| 88 |
echo '<div class="visualizer-library-chart-footer visualizer-clearfix">'; |
| 89 |
echo '<span class="visualizer-library-chart-action visualizer-library-nochart-delete"></span>'; |
| 90 |
echo '<span class="visualizer-library-chart-action visualizer-library-nochart-insert"></span>'; |
| 91 |
|
| 92 |
echo '<span class="visualizer-library-chart-shortcode">'; |
| 93 |
echo ' [visualizer] '; |
| 94 |
echo '</span>'; |
| 95 |
echo '</div>'; |
| 96 |
echo '</div>'; |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Renders templates. |
| 101 |
* |
| 102 |
* @since 1.0.0 |
| 103 |
* |
| 104 |
* @access protected |
| 105 |
*/ |
| 106 |
protected function _toHTML() { |
| 107 |
foreach ( $this->_templates as $template ) { |
| 108 |
$callback = '_render' . str_replace( ' ', '', ucwords( str_replace( '-', ' ', $template ) ) ); |
| 109 |
$this->_renderTemplate( $template, $callback ); |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
} |