Changeset 1270122
- Timestamp:
- 10/21/2015 08:17:26 AM (10 years ago)
- Location:
- wp-h5p-xapi/trunk
- Files:
-
- 3 edited
-
src/utils/Template.php (modified) (3 diffs)
-
src/utils/WpUtil.php (modified) (1 diff)
-
wp-h5p-xapi.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wp-h5p-xapi/trunk/src/utils/Template.php
r1268539 r1270122 6 6 * Echo for attribute. 7 7 */ 8 function echo_attr($s) { 9 echo htmlspecialchars($s); 8 if (!function_exists("h5pxapi\\echo_attr")) { 9 function echo_attr($s) { 10 echo htmlspecialchars($s); 11 } 10 12 } 11 13 … … 13 15 * Echo for html. 14 16 */ 15 function echo_html($s) { 16 echo htmlspecialchars($s); 17 if (!function_exists("h5pxapi\\echo_attr")) { 18 function echo_html($s) { 19 echo htmlspecialchars($s); 20 } 17 21 } 18 22 … … 39 43 * </code> 40 44 */ 41 class Template { 45 if (!class_exists("h5pxapi\\Template")) { 46 class Template { 42 47 43 private $filename;44 private $vars;48 private $filename; 49 private $vars; 45 50 46 /**47 * Create a Template for the specified file.48 * @param mixed $filename The file to use as template.49 */50 public function __construct($filename) {51 $this->filename=$filename;52 $this->vars=array();53 }51 /** 52 * Create a Template for the specified file. 53 * @param mixed $filename The file to use as template. 54 */ 55 public function __construct($filename) { 56 $this->filename=$filename; 57 $this->vars=array(); 58 } 54 59 55 /**56 * Set a variable that can be accessed by the template.57 *58 * The variable will be available to the template in the global scope.59 * @param mixed $name The name of the variable.60 * @param mixed $value The value that the variable should take.61 */62 public function set($name, $value) {63 $this->vars[$name]=$value;64 }60 /** 61 * Set a variable that can be accessed by the template. 62 * 63 * The variable will be available to the template in the global scope. 64 * @param mixed $name The name of the variable. 65 * @param mixed $value The value that the variable should take. 66 */ 67 public function set($name, $value) { 68 $this->vars[$name]=$value; 69 } 65 70 66 /**67 * Render the template and output it to the browser.68 */69 public function show() {70 foreach ($this->vars as $key=>$value)71 $$key=$value;71 /** 72 * Render the template and output it to the browser. 73 */ 74 public function show() { 75 foreach ($this->vars as $key=>$value) 76 $$key=$value; 72 77 73 require $this->filename;74 }78 require $this->filename; 79 } 75 80 76 /**77 * Render template, but don't ouput it to the browser.78 *79 * This is useful if we want to80 * use a template inside another template. For example, we might have a81 * page template that defaines header and footer for our page. Inside the page82 * template we want to display the content generated by a content template.83 * We can do this by first rendering the content template:84 *85 * <code>86 * $contentTemplate=new Template("the_content_templte.php");87 * // Set any variables used by the content template.88 * $content=$contentTemplate->render();89 * </code>90 *91 * Now, we use the rendered content as input for our page template and output92 * everything to the browser:93 *94 * <code>95 * $pageTemplate=new Template("the_page_template.php");96 * $pageTemplate->set("content",$content);97 * $pageTemplate->show();98 * </code>99 */100 public function render() {101 foreach ($this->vars as $key=>$value)102 $$key=$value;81 /** 82 * Render template, but don't ouput it to the browser. 83 * 84 * This is useful if we want to 85 * use a template inside another template. For example, we might have a 86 * page template that defaines header and footer for our page. Inside the page 87 * template we want to display the content generated by a content template. 88 * We can do this by first rendering the content template: 89 * 90 * <code> 91 * $contentTemplate=new Template("the_content_templte.php"); 92 * // Set any variables used by the content template. 93 * $content=$contentTemplate->render(); 94 * </code> 95 * 96 * Now, we use the rendered content as input for our page template and output 97 * everything to the browser: 98 * 99 * <code> 100 * $pageTemplate=new Template("the_page_template.php"); 101 * $pageTemplate->set("content",$content); 102 * $pageTemplate->show(); 103 * </code> 104 */ 105 public function render() { 106 foreach ($this->vars as $key=>$value) 107 $$key=$value; 103 108 104 ob_start(); 105 require $this->filename; 106 return ob_get_clean(); 109 ob_start(); 110 require $this->filename; 111 return ob_get_clean(); 112 } 107 113 } 108 114 } -
wp-h5p-xapi/trunk/src/utils/WpUtil.php
r1268539 r1270122 6 6 * Wordpress utils. 7 7 */ 8 class WpUtil { 8 if (!class_exists("h5pxapi\\WpUtil")) { 9 class WpUtil { 9 10 10 /**11 * Bootstrap from inside a plugin.12 */13 public static function getWpLoadPath() {14 $path=$_SERVER['SCRIPT_FILENAME'];11 /** 12 * Bootstrap from inside a plugin. 13 */ 14 public static function getWpLoadPath() { 15 $path=$_SERVER['SCRIPT_FILENAME']; 15 16 16 for ($i=0; $i<4; $i++)17 $path=dirname($path);17 for ($i=0; $i<4; $i++) 18 $path=dirname($path); 18 19 19 return $path."/wp-load.php";20 }20 return $path."/wp-load.php"; 21 } 21 22 22 /**23 * Create a PDO object that is compatible with the current24 * wordpress install.25 */26 public static function getCompatiblePdo() {27 static $pdo;23 /** 24 * Create a PDO object that is compatible with the current 25 * wordpress install. 26 */ 27 public static function getCompatiblePdo() { 28 static $pdo; 28 29 29 if (!$pdo)30 $pdo=new PDO("mysql:host=".DB_HOST.";dbname=".DB_NAME,DB_USER,DB_PASSWORD);30 if (!$pdo) 31 $pdo=new PDO("mysql:host=".DB_HOST.";dbname=".DB_NAME,DB_USER,DB_PASSWORD); 31 32 32 return $pdo; 33 return $pdo; 34 } 33 35 } 34 36 } -
wp-h5p-xapi/trunk/wp-h5p-xapi.php
r1270064 r1270122 9 9 Plugin URI: http://github.com/tunapanda/wp-h5p-xapi 10 10 Description: Send H5P achievements to an xAPI repo. 11 Version: 0.0. 311 Version: 0.0.4 12 12 */ 13 13
Note: See TracChangeset
for help on using the changeset viewer.