Hi,
I'm using Essential (version 2.7) theme in moodle. In settings section, I'd like to use html editor with the option to upload images. My solution:
In settings.php file:
global $CFG;
require_once($CFG->dirroot.'/local/icsbcn/lib/admin_setting_confightmleditor_icsbcn.class.php');
$setting = new admin_setting_confightmleditor_icsbcn($name, $title, $description, $default);
In admin_setting_confightmleditor_icsbcn.class.php file:
<?php
global $CFG;
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/filelib.php');
/**
* General text area with html editor.
*/
class admin_setting_confightmleditor_icsbcn extends admin_setting_configtext {
private $rows;
private $cols;
private $options;
/**
* @param string $name
* @param string $visiblename
* @param string $description
* @param mixed $defaultsetting string or array
* @param mixed $paramtype
*/
public function __construct($name, $visiblename, $description, $defaultsetting, $paramtype=PARAM_RAW, $cols='60', $rows='8') {
$this->rows = $rows;
$this->cols = $cols;
parent::__construct($name, $visiblename, $description, $defaultsetting, $paramtype);
editors_head_setup();
}
private function get_options() {
global $USER;
$ctx = context_user::instance($USER->id);
$default = array();
$default['noclean'] = false;
$default['context'] = $ctx;
$default['maxbytes'] = 0;
$default['maxfiles'] = -1;
$default['forcehttps'] = false;
$default['subdirs'] = false;
$default['changeformat'] = 0;
$default['areamaxbytes'] = FILE_AREA_MAX_BYTES_UNLIMITED;
$default['return_types'] = (FILE_INTERNAL | FILE_EXTERNAL);
return $default;
}
/**
* Returns an XHTML string for the editor
*
* @param string $data
* @param string $query
* @return string XHTML string for the editor
*/
public function output_html($data, $query='') {
global $USER;
$default = $this->get_defaultsetting();
$defaultinfo = $default;
if (!is_null($default) and $default !== '') {
$defaultinfo = "\n".$default;
}
$ctx = context_user::instance($USER->id);
$editor = editors_get_preferred_editor(FORMAT_HTML);
$options = $this->get_options();
$draftitemid = file_get_unused_draft_itemid();
$component = is_null($this->plugin) ? 'core' : $this->plugin;
$data = file_prepare_draft_area($draftitemid, $options['context']->id, $component, $this->get_full_name().'_draftitemid', $draftitemid, $options, $data);
$fpoptions = array();
$args = new stdClass();
// need these three to filter repositories list
$args->accepted_types = array('web_image');
$args->return_types = $options['return_types'];
$args->context = $ctx;
$args->env = 'filepicker';
// advimage plugin
$image_options = initialise_filepicker($args);
$image_options->context = $ctx;
$image_options->client_id = uniqid();
$image_options->maxbytes = $options['maxbytes'];
$image_options->areamaxbytes = $options['areamaxbytes'];
$image_options->env = 'editor';
$image_options->itemid = $draftitemid;
// moodlemedia plugin
$args->accepted_types = array('video', 'audio');
$media_options = initialise_filepicker($args);
$media_options->context = $ctx;
$media_options->client_id = uniqid();
$media_options->maxbytes = $options['maxbytes'];
$media_options->areamaxbytes = $options['areamaxbytes'];
$media_options->env = 'editor';
$media_options->itemid = $draftitemid;
// advlink plugin
$args->accepted_types = '*';
$link_options = initialise_filepicker($args);
$link_options->context = $ctx;
$link_options->client_id = uniqid();
$link_options->maxbytes = $options['maxbytes'];
$link_options->areamaxbytes = $options['areamaxbytes'];
$link_options->env = 'editor';
$link_options->itemid = $draftitemid;
$fpoptions['image'] = $image_options;
$fpoptions['media'] = $media_options;
$fpoptions['link'] = $link_options;
$editor->use_editor($this->get_id(), $options, $fpoptions);
return format_admin_setting($this, $this->visiblename,
'<div class="form-textarea"><textarea rows="'. $this->rows .'" cols="'. $this->cols .'" id="'. $this->get_id() .'" name="'. $this->get_full_name() .'" spellcheck="true">'. s($data) .'</textarea></div>
<input value="'.$draftitemid.'" name="'.$this->get_full_name().'_draftitemid" type="hidden" />',
$this->description, true, '', $defaultinfo, $query);
}
public function write_setting($data) {
global $CFG;
if ($this->paramtype === PARAM_INT and $data === '') {
// do not complain if '' used instead of 0
$data = 0;
}
// $data is a string
$validated = $this->validate($data);
if ($validated !== true) {
return $validated;
}
$options = $this->get_options();
$fs = get_file_storage();
$component = is_null($this->plugin) ? 'core' : $this->plugin;
$wwwroot = $CFG->wwwroot;
if ($options['forcehttps']) {
$wwwroot = str_replace('http://', 'https://', $wwwroot);
}
$draftitemid = $_REQUEST[$this->get_full_name().'_draftitemid'];
$draftfiles = $fs->get_area_files($options['context']->id, 'user', 'draft', $draftitemid, 'id');
foreach ($draftfiles as $file) {
if (!$file->is_directory()) {
$strToSearch = "$wwwroot/draftfile.php/".$options['context']->id."/user/draft/$draftitemid/".$file->get_filename();
if (stripos($data, $strToSearch) !== false) {
$file_record = array(
'contextid' => context_system::instance()->id,
'component' => $component,
'filearea' => 'icsbcnmarketingimages',
'itemid' => 0,
'timemodified' => time()
);
$newfile = $fs->create_file_from_storedfile($file_record, $file);
$url = moodle_url::make_pluginfile_url($newfile->get_contextid(), $newfile->get_component(), $newfile->get_filearea(), $newfile->get_itemid(), $newfile->get_filepath(), $newfile->get_filename());
$data = str_ireplace($strToSearch, $url, $data);
}
}
}
return ($this->config_write($this->name, $data) ? '' : get_string('errorsetting', 'admin'));
}
}
In theme/icsbcn/lib.php:
I added these lines in function theme_icsbcn_pluginfile:
else if ($filearea === 'icsbcnmarketingimages') {
return $theme->setting_file_serve($filearea, $args, $forcedownload, $options);
}
Best regards!
Iban Cardona.
Monday, 23 March 2015
Saturday, 31 January 2015
Easy clock with Javascript (jQuery)
Hello,
An easy and fast way to develope a clock that is updated every minute:
An easy and fast way to develope a clock that is updated every minute:
<div class="clock"> <i class="fa fa-clock-o"> </i><span>15:51</span><script type="text/javascript"> var intervalclock = 0; function startClock() { setTimeout(function() { print_clock(); intervalclock = 60; setInterval(function() { print_clock(); }, intervalclock * 1000); }, intervalclock * 1000); } function print_clock() { var now = new Date(); var hour = now.getHours(); var minute = now.getMinutes(); if (minute < 10) { minute = "0" + minute; }; var timeString = hour + ':' + minute; $('.clock\ > span').text(timeString); } $(window).load(function() { var timeclock = new Date(); intervalclock = 60 - timeclock.getSeconds(); if(intervalclock == 60) { intervalclock = 0; } startClock(); }); </script> </div>
Best regards!
Thursday, 8 January 2015
Moodle: Number of courses in which a user is enrolled
Hello,
Moodle is a software designed to create online courses. You can add a lot of tailor-made plugins.
One of the most interesting info that would be interesting could be... The number of courses in which a user is enrolled. We can know it by (tested with version 2.6.2):
Regards!
Moodle is a software designed to create online courses. You can add a lot of tailor-made plugins.
One of the most interesting info that would be interesting could be... The number of courses in which a user is enrolled. We can know it by (tested with version 2.6.2):
global $DB;
$sql_count = 'SELECT COUNT(c.id)
FROM mdl_course AS c
JOIN mdl_context AS ct ON c.id = ct.instanceid
JOIN mdl_role_assignments AS ra ON ra.contextid = ct.id
JOIN mdl_user AS u ON u.id = ra.userid
JOIN mdl_role AS r ON r.id = ra.roleid
WHERE u.id = ?';
$courses_count = $DB->count_records_sql($sql_count, array($idUser));
Regards!
Friday, 2 January 2015
tt_news: Modify query to database
tt_news is an extension of TYPO3 designed to publish news in our website. It's a very popular extension and it allows publish and manage news about our company, association, etc. You can find extension manual here.
Suppose that we have our own extension with our own plugins and we want to indicate that in the news list we only want news with ID greater than 100... So we should use a hook that is prepared for the extension in order to modify the database query.
In this example we used TYPO3 4.4.4 and tt_news 3.0.1. Files to modify are:
ext_localconf.php
user_t3_test_selectHook.php
I hope you find it useful! Regards!
Suppose that we have our own extension with our own plugins and we want to indicate that in the news list we only want news with ID greater than 100... So we should use a hook that is prepared for the extension in order to modify the database query.
In this example we used TYPO3 4.4.4 and tt_news 3.0.1. Files to modify are:
ext_localconf.php
if (TYPO3_MODE == 'FE') {
require_once(t3lib_extMgm::extPath('user_t3_test').'user_t3_test_selectHook.php');
}
$TYPO3_CONF_VARS['EXTCONF']['tt_news']['selectConfHook'][] = 'user_t3_test_selectHook';
user_t3_test_selectHook.php
class user_t3_test_selectHook {
public function processSelectConfHook(&$parentObject, $selectConf) {
$selectConf['where'] .= ' AND uid > 100 ';
return $selectConf;
}
I hope you find it useful! Regards!
Thursday, 1 January 2015
Overwrite title tag with TypoScript
TYPO3 is a powerful CMS that uses its own configuration language called TypoScript.
This article does not explain what or how to configure TYPO3. In this case only show you how to override the title tag of a page using TypoScript.
To develop this example we used a quite old version of TYPO3: 4.2.14 but this solution is also valid for newer versions.
Suppose we want new title "Test", then the TypoScript of our template should be:
config.noPageTitle = 2In the first line we say that we don't want to print the default title. More info here. In the other 3 lines we change the page header adding our title. I hope you find it useful! Regards!
page = PAGE
page.headerData.10 = TEXT
page.headerData.10.wrap = <title>Test</title>
Sunday, 7 December 2014
Moodle: custom CSS in Essential theme
When you want to custom a moodle instance, you could need to modify Essential theme, for example, I don't want to see headers in SCORM content. The best option is use customcss property.
We go to admin/settings.php?section=theme_essential_generic in our site and we search for customcss textarea. To avoid seeing headers in SCORM, we add:
Best regards!
We go to admin/settings.php?section=theme_essential_generic in our site and we search for customcss textarea. To avoid seeing headers in SCORM, we add:
#page-mod-scorm-player div[role=main] h2 {display: none;}
#page-mod-scorm-player header[role=banner] {display: none;}
Best regards!
Tuesday, 2 December 2014
Install MAMP + Laravel 4
Hello,
Today I installed in Mac OS X (10.7.5) server MAMP (3.0.4) + Laravel 4. I did these steps:
Today I installed in Mac OS X (10.7.5) server MAMP (3.0.4) + Laravel 4. I did these steps:
- First, I downloaded and installed MAMP from http://www.mamp.info. I modified default conf changin ports to 80 and 3306.
- Next, I modified file bash_profile (vim ~/.bash_profile):
export PATH=/Applications/MAMP/bin/php/php5.5.10/bin:$PATH alias composer="php /usr/bin/composer.phar" alias laravel="~/.composer/vendor/bin/laravel" - Then, I reset terminal and downloaded composer:
curl -sS getcomposer.org/installer | php. - Next step, move composer.phar:
sudo mv composer.phar /usr/bin/ - I donwloaded Laravel 4 installer:
composer global require "laravel/installer=~1.1" - I went to /Applications/MAMP/htdocs and I created a new Laravel project:
laravel new ibancardonasubiela.tk - Then, I created a new virtual host in my MAMP. To do that, I edited file Applications/MAMP/conf/apache/httpd.conf and I uncommented "Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf". Then I edited file Applications/MAMP/conf/apache/extra/httpd-vhosts.conf and I added:
<VirtualHost *:80>DocumentRoot /Applications/MAMP/htdocs/ibancardonasubiela.tk/public ServerName wwww.ibancardonasubiela.local </VirtualHost> - I restarted MAMP service.
- I edited file /etc/hosts (
sudo vim /etc/hosts) adding: 127.0.0.1 www.ibancardonasubiela.local - And, finally, Laravel installed in http://www.ibancardonasubiela.local/
Subscribe to:
Posts (Atom)