Plugin Directory

Changeset 1270122


Ignore:
Timestamp:
10/21/2015 08:17:26 AM (10 years ago)
Author:
Tunapanda
Message:

new version

Location:
wp-h5p-xapi/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wp-h5p-xapi/trunk/src/utils/Template.php

    r1268539 r1270122  
    66     * Echo for attribute.
    77     */
    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        }
    1012    }
    1113
     
    1315     * Echo for html.
    1416     */
    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        }
    1721    }
    1822
     
    3943     * </code>
    4044     */
    41     class Template {
     45    if (!class_exists("h5pxapi\\Template")) {
     46        class Template {
    4247
    43         private $filename;
    44         private $vars;
     48            private $filename;
     49            private $vars;
    4550
    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            }
    5459
    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            }
    6570
    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;
    7277
    73             require $this->filename;
    74         }
     78                require $this->filename;
     79            }
    7580
    76         /**
    77         * Render template, but don't ouput it to the browser.
    78         *
    79         * This is useful if we want to
    80         * use a template inside another template. For example, we might have a
    81         * page template that defaines header and footer for our page. Inside the page
    82         * 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 output
    92         * 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;
    103108
    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            }
    107113        }
    108114    }
  • wp-h5p-xapi/trunk/src/utils/WpUtil.php

    r1268539 r1270122  
    66     * Wordpress utils.
    77     */
    8     class WpUtil {
     8    if (!class_exists("h5pxapi\\WpUtil")) {
     9        class WpUtil {
    910
    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'];
    1516
    16             for ($i=0; $i<4; $i++)
    17                 $path=dirname($path);
     17                for ($i=0; $i<4; $i++)
     18                    $path=dirname($path);
    1819
    19             return $path."/wp-load.php";
    20         }
     20                return $path."/wp-load.php";
     21            }
    2122
    22         /**
    23         * Create a PDO object that is compatible with the current
    24         * 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;
    2829
    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);
    3132
    32             return $pdo;
     33                return $pdo;
     34            }
    3335        }
    3436    }
  • wp-h5p-xapi/trunk/wp-h5p-xapi.php

    r1270064 r1270122  
    99Plugin URI: http://github.com/tunapanda/wp-h5p-xapi
    1010Description: Send H5P achievements to an xAPI repo.
    11 Version: 0.0.3
     11Version: 0.0.4
    1212*/
    1313
Note: See TracChangeset for help on using the changeset viewer.