From 3b5b1f9541f321e7ea70af618909cbfa0d9f93ea Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Mon, 28 Oct 2013 08:41:52 +1100 Subject: [PATCH] Brought up to standard for 2.6 release --- ajax.php | 6 +++-- block_css_theme_tool.php | 17 +++++++------- colourpicker_image.php | 3 +-- lib.php | 51 ++++++++++++++++++++++++---------------- version.php | 6 ++--- 5 files changed, 47 insertions(+), 36 deletions(-) diff --git a/ajax.php b/ajax.php index d1c1ee1..2a90c6b 100644 --- a/ajax.php +++ b/ajax.php @@ -8,7 +8,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define('AJAX_SCRIPT', 1); +define('AJAX_SCRIPT', true); require_once('../../config.php'); require_once($CFG->dirroot.'/blocks/css_theme_tool/lib.php'); @@ -31,15 +31,17 @@ $styles = required_param_array('styles', PARAM_NOTAGS); css_theme_tool::update_via_ajax($rules, $styles); break; + case 'purge': // Purge the rules in the database css_theme_tool::purge_rules(); break; + case 'exportcss': // Export the CSS $blockid = required_param('id', PARAM_INT); $blockinstance = $DB->get_record('block_instances', array('id'=>$blockid), '*', MUST_EXIST); - $blockcontext = get_context_instance(CONTEXT_BLOCK, $blockinstance->id); + $blockcontext = context_block::instance($blockinstance->id); css_theme_tool::cache_css($blockcontext); $filepath = css_theme_tool::get_cached_file_url($blockcontext); echo $filepath; diff --git a/block_css_theme_tool.php b/block_css_theme_tool.php index 413834b..550a2ae 100644 --- a/block_css_theme_tool.php +++ b/block_css_theme_tool.php @@ -19,23 +19,21 @@ */ class block_css_theme_tool extends block_base { - protected $visualversion = '0.3.0'; + protected $visualversion = '0.4.0'; - function init() { + public function init() { $this->title = get_string('pluginname', 'block_css_theme_tool'); } - function applicable_formats() { + public function applicable_formats() { return array('all' => true); } - function instance_allow_multiple() { + public function instance_allow_multiple() { return false; } - function get_content() { - global $USER; - + public function get_content() { if ($this->content !== NULL) { return $this->content; } @@ -148,9 +146,10 @@ public function initialise_javascript() { public function send_file($context, $filearea, $itemid, $filepath, $filename) { $fs = get_file_storage(); - $file = $fs->get_file($context->id, $filearea, $itemid, $filepath, $filename); + $file = $fs->get_file($context->id, 'block_css_theme_tool', $filearea, $itemid, $filepath, $filename); if ($file) { - session_get_instance()->write_close(); // unlock session during fileserving + $session = new \core\session\manager(); + $session->write_close(); // unlock session during file serving. send_stored_file($file, 0, 0, true); // must force download - security! } else { send_file_not_found(); diff --git a/colourpicker_image.php b/colourpicker_image.php index 08143d3..dbc1455 100644 --- a/colourpicker_image.php +++ b/colourpicker_image.php @@ -34,8 +34,7 @@ function produce_colorpicker() { $matrixcount = count($matrices); $limit = ceil($width/$matrixcount); $heightbreak = floor($height/2); - $heightgap = 0; - + header("Content-type: image/png"); $image = imagecreatetruecolor($width, $height); imagecolorallocate($image, 0, 0, 0); diff --git a/lib.php b/lib.php index 6cbbbbc..de56d5a 100644 --- a/lib.php +++ b/lib.php @@ -50,15 +50,15 @@ public function get_rules() { } /** - * Gets all of the rules for this css theme tool and returns them in - * an array suitable for return as JSON + * Gets all of the rules for this css theme tool and returns them in an array suitable for return as JSON. + * * @return array */ public static function get_rules_for_json($currentuseronly=false) { global $USER; $tool = new self(); $rules = $tool->get_rules(); - foreach ($rules as $key=>&$rule) { + foreach ($rules as $key => &$rule) { if ($currentuseronly && $rule->userid != $USER->id) { unset($rules[$key]); continue; @@ -105,13 +105,14 @@ public static function get_cached_file_url($context) { } /** - * Caches the CSS and returns the file so it can be used + * Caches the CSS and returns the file so it can be used. + * * @return stored_file */ public static function cache_css($blockcontext) { $tool = new self(); $rules = $tool->get_rules(); - $css = "/** Created by CSS theme tool **/\n"; + $css = "/** Created by the CSS theme tool block **/\n"; foreach ($rules as $rule) { $css .= $rule->selector.' {'; foreach ($rule->styles as $style) { @@ -121,14 +122,15 @@ public static function cache_css($blockcontext) { } $cssfile = array( - 'contextid'=>$blockcontext->id, + 'contextid' => $blockcontext->id, 'component' => 'block_css_theme_tool', - 'filearea'=>'cached_css', - 'itemid'=>0, - 'filepath'=>'/', - 'filename'=>'css_theme_tool_export.css', - 'timecreated'=>time(), - 'timemodified'=>time()); + 'filearea' => 'cached_css', + 'itemid' => 0, + 'filepath' => '/', + 'filename' => 'css_theme_tool_export.css', + 'timecreated' => time(), + 'timemodified' => time() + ); $fs = get_file_storage(); if ($file = $fs->get_file($cssfile['contextid'], $cssfile['component'], $cssfile['filearea'], $cssfile['itemid'], $cssfile['filepath'], $cssfile['filename'])) { $file->delete(); @@ -140,7 +142,7 @@ public static function cache_css($blockcontext) { * Updates the rules stored in the database with those you have created * * @global moodle_database $DB - * @param array $rules + * @param css_theme_tool_rule[] $rules */ public function update_rules($rules) { global $DB; @@ -179,7 +181,7 @@ public function update_rules($rules) { */ public static function update_via_ajax($ajaxrules, $ajaxstyles) { $rules = array(); - foreach ($ajaxrules as $key=>$selector) { + foreach ($ajaxrules as $key => $selector) { $rule = new css_theme_tool_rule(); $rule->create($selector, explode('@@@', $ajaxstyles[$key])); $rules[] = $rule; @@ -213,21 +215,25 @@ class css_theme_tool_rule { * @var int */ public $id = null; + /** * The selector as a string * @var string */ public $selector; + /** * The time this rule was last modified * @var int */ public $timemodified; + /** * The ID of the user who created this rule * @var int */ public $userid; + /** * All of the styles associated with this object {@see css_theme_tool_style} * @var array @@ -243,7 +249,7 @@ class css_theme_tool_rule { * @param array $styles * @return bool */ - public function load($id, stdClass $rule=null, array $styles = null) { + public function load($id, stdClass $rule = null, array $styles = null) { global $DB; if ($rule == null) { $rule = $DB->get_record('block_css_theme_tool', array('id'=>$id), '*', MUST_EXIST); @@ -255,6 +261,7 @@ public function load($id, stdClass $rule=null, array $styles = null) { $this->styles = css_theme_tool_style::load_for_rule($this, $styles); return true; } + /** * Creates this object from the given selector and rules * @param string $selector @@ -268,6 +275,7 @@ public function create($selector, array $styles) { $this->userid = $USER->id; $this->styles = css_theme_tool_style::create_for_rule($this, $styles); } + /** * Inserts or Updates the rule in the database * @global moodle_database $DB @@ -281,7 +289,7 @@ public function save() { $this->id = $DB->insert_record('block_css_theme_tool', $this); } - $DB->delete_records('block_css_theme_tool_styles', array('ruleid'=>$this->id)); + $DB->delete_records('block_css_theme_tool_styles', array('ruleid' => $this->id)); foreach ($this->styles as $style) { $style->ruleid = $this->id; $style->save(); @@ -302,21 +310,25 @@ class css_theme_tool_style { * @var int */ public $id; + /** * The ID of the rule this style belongs too * @var int */ public $ruleid; + /** * The rule this style belongs too * @var css_theme_tool_rule */ public $rule; + /** * The name of this style * @var string */ public $name; + /** * The value for this style * @var string @@ -331,7 +343,7 @@ class css_theme_tool_style { * @param array $dbstyles * @return array */ - public static function load_for_rule(css_theme_tool_rule $rule, array $dbstyles=null) { + public static function load_for_rule(css_theme_tool_rule $rule, array $dbstyles = null) { global $DB; $styles = Array(); if ($dbstyles == null) { @@ -405,8 +417,6 @@ function block_css_theme_tool_pluginfile($course, $birecord, $context, $filearea } $fs = get_file_storage(); - - $filename = array_pop($args); $itemid = array_pop($args); $filepath = $args ? '/'.implode('/', $args).'/' : '/'; @@ -415,6 +425,7 @@ function block_css_theme_tool_pluginfile($course, $birecord, $context, $filearea send_file_not_found(); } - session_get_instance()->write_close(); + $session = new \core\session\manager(); + $session->write_close(); // unlock session during file serving. send_stored_file($file, 60*60, 0, $forcedownload); } \ No newline at end of file diff --git a/version.php b/version.php index 9bf37ab..2a14c15 100644 --- a/version.php +++ b/version.php @@ -6,8 +6,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$plugin->version = 2013012500; -$plugin->release = '0.3.0 (beta)'; +$plugin->version = 2013102800; +$plugin->release = '0.4.0 (beta)'; $plugin->component = 'block_css_theme_tool'; -$plugin->requires = 2011120502; // Moodle 2.2 release +$plugin->requires = 2013102500; // Moodle 2.6 beta release $plugin->maturity = MATURITY_BETA;