Skip to content

Instantly share code, notes, and snippets.

View mudrd8mz's full-sized avatar

David Mudrák mudrd8mz

View GitHub Profile
@mudrd8mz
mudrd8mz / gist:5508113
Created May 3, 2013 09:10
Proposal for format_text() check in Moodle
diff --git a/lib/weblib.php b/lib/weblib.php
index 647504a..28aef68 100644
--- a/lib/weblib.php
+++ b/lib/weblib.php
@@ -1174,6 +1174,14 @@ function format_text($text, $format = FORMAT_MOODLE, $options = NULL, $courseid_
// The only potential problem is that somebody might try to format
// the text before storing into database which would be itself big bug.
$text = str_replace("\"$CFG->httpswwwroot/draftfile.php", "\"$CFG->httpswwwroot/brokenfile.php#", $text);
+
+ // Before calling format_text(), the text must be processed with {@link file_rewrite_pluginfile_urls()}
@mudrd8mz
mudrd8mz / gist:5186295
Last active December 15, 2015 02:19
Simple Moodle YUI3 module
/**
* Check for write permission for the selected plugin type
*
* $this->page->requires->yui_module('moodle-tool_installaddon-permcheck', 'M.tool_installaddon.permcheck.init',
* array(array('aparam' => 'paramvalue')));
*
* @package tool_installaddon
* @subpackage yui
* @author David Mudrak <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
diff --git a/mod/workshop/renderer.php b/mod/workshop/renderer.php
index 3b67672..63570c2 100644
--- a/mod/workshop/renderer.php
+++ b/mod/workshop/renderer.php
@@ -712,7 +712,7 @@ class mod_workshop_renderer extends plugin_renderer_base {
public function perpage_selector($current=10) {
$options = array();
- foreach (array(10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 1000) as $option) {
+ foreach (array(1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 1000) as $option) {
diff --git a/lib/setuplib.php b/lib/setuplib.php
index 88fd5fd..d3b8a7e 100644
--- a/lib/setuplib.php
+++ b/lib/setuplib.php
@@ -137,14 +137,23 @@ class moodle_exception extends Exception {
if (get_string_manager()->string_exists($errorcode, $module)) {
$message = get_string($errorcode, $module, $a);
+ $haserrorstring = true;
} else {
test=# select * from files f left join refs r on f.refid = r.id left join repos p on r.repoid = p.id left join types t on t.id = p.typeid;
id | refid | id | repoid | id | typeid | id | name
----+-------+------+--------+------+--------+------+--------
2 | 1 | 1 | 2 | 2 | 3 | 3 | boxnet
3 | 2 | 2 | NULL | NULL | NULL | NULL | NULL
1 | NULL | NULL | NULL | NULL | NULL | NULL | NULL
(3 řádky)
test=# select * from files f left join refs r on f.refid = r.id join repos p on r.repoid = p.id join types t on t.id = p.typeid;
id | refid | id | repoid | id | typeid | id | name
@mudrd8mz
mudrd8mz / gist:2828474
Created May 29, 2012 13:49
Git pre-commit hook that does not allow committing a change containing DONOTCOMMIT text
$ cat .git/hooks/pre-commit
#!/bin/bash
FOUND=$(git diff-index --cached -U0 HEAD -- | grep DONOTCOMMIT | wc -l)
if [[ $FOUND -gt 0 ]]; then
echo "pre-commit hook: DONOTCOMMIT detected, commit not allowed"
exit 1
fi
diff --git a/lib/filelib.php b/lib/filelib.php
index ba19410..4569a86 100644
--- a/lib/filelib.php
+++ b/lib/filelib.php
@@ -602,8 +602,8 @@ function file_get_drafarea_files($draftitemid, $filepath = '/') {
$item->url = $itemurl->out();
$item->thumbnail = $OUTPUT->pix_url(file_extension_icon($item->filename, 32))->out(false);
if ($imageinfo = $file->get_imageinfo()) {
- $item->realthumbnail = $itemurl->out(false, array('preview' => 'thumb'));
- $item->realicon = $itemurl->out(false, array('preview' => 'tinyicon'));
diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php
index 918b693..3652010 100644
--- a/lib/outputcomponents.php
+++ b/lib/outputcomponents.php
@@ -340,13 +340,14 @@ class user_picture implements renderable {
// picture of not.
if (!empty($this->user->deleted) or !$context = context_user::instance($this->user->id, IGNORE_MISSING)) {
$hasuploadedfile = false;
+ } else if ($this->user->picture == 1) {
+ $hasuploadedfile = true;
$ time phpunit
PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from /home/mudrd8mz/public_html/moodle23/phpunit.xml
............................................................. 61 / 1070 ( 5%)
............................................................. 122 / 1070 ( 11%)
............................................................. 183 / 1070 ( 17%)
............................................................. 244 / 1070 ( 22%)
...........................E................................. 305 / 1070 ( 28%)
@mudrd8mz
mudrd8mz / locklib.sh
Created February 28, 2012 15:16
Simple bash locking based on file existence
#!/bin/bash
# Simple locking mechanism based on file existence
LOCK_ERR_ARGS=64
LOCK_EXISTS=1
LOCK_MISSING=2
LOCK_ROOT=/var/run/amos
#