Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../public_h.../wp-conte.../plugins/network-.../componen...
File: NetsPostsTemplateRenderer.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Created by PhpStorm.
[2] Fix | Delete
* User: Andrew
[3] Fix | Delete
* Date: 31.05.2018
[4] Fix | Delete
* Time: 9:01
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
namespace NetworkPosts\Components;
[8] Fix | Delete
[9] Fix | Delete
use RuntimeException;
[10] Fix | Delete
//use Twig\Loader\FilesystemLoader;
[11] Fix | Delete
[12] Fix | Delete
class NetsPostsTemplateRenderer {
[13] Fix | Delete
[14] Fix | Delete
private static $instance;
[15] Fix | Delete
private static $twig = null;
[16] Fix | Delete
private static $views_path;
[17] Fix | Delete
[18] Fix | Delete
protected function __construct( $views_path ) {
[19] Fix | Delete
self::$views_path = $views_path;
[20] Fix | Delete
//$loader = new \Twig_Loader_Filesystem( self::$views_path );
[21] Fix | Delete
//self::$twig = new \Twig_Environment( $loader );
[22] Fix | Delete
}
[23] Fix | Delete
[24] Fix | Delete
public static function render( $template_relative_path, $data = [] ) {
[25] Fix | Delete
//if ( self::$twig ) {
[26] Fix | Delete
$full_path = self::$views_path . $template_relative_path;
[27] Fix | Delete
if ( file_exists( $full_path ) ) {
[28] Fix | Delete
return self::render_template( $full_path, $data );
[29] Fix | Delete
} else {
[30] Fix | Delete
return '';
[31] Fix | Delete
}
[32] Fix | Delete
//} else {
[33] Fix | Delete
//throw new RuntimeException( 'Class ' . self::class . ' is not initialized.' );
[34] Fix | Delete
//}
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
private static function render_template( $template, $data ) {
[38] Fix | Delete
$tmpl = '';
[39] Fix | Delete
$h = fopen( $template, 'r+' );
[40] Fix | Delete
while ( ( $line = fgets( $h, 4096 ) ) !== false ) {
[41] Fix | Delete
foreach ( $data as $key => $value ) {
[42] Fix | Delete
$line = str_replace( "%${key}%", $value, $line );
[43] Fix | Delete
}
[44] Fix | Delete
$tmpl .= $line;
[45] Fix | Delete
}
[46] Fix | Delete
fclose( $h );
[47] Fix | Delete
return $tmpl;
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
public static function init( $views_path ) {
[51] Fix | Delete
self::$instance = new NetsPostsTemplateRenderer( $views_path );
[52] Fix | Delete
}
[53] Fix | Delete
}
[54] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function