Skip to content

Commit

Permalink
Merge pull request #6 from MFreakNL/moodle35
Browse files Browse the repository at this point in the history
Moodle35
  • Loading branch information
luukverhoeven authored Nov 14, 2019
2 parents 538085b + 43b0c53 commit 1b8c53e
Show file tree
Hide file tree
Showing 490 changed files with 33,422 additions and 234 deletions.
59 changes: 59 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
language: php

# Workaround for fixing that Selenium server is not running and therefore javascript Behat tests are not working:
# https://github.com/moodlerooms/moodle-plugin-ci/issues/70
sudo: required

addons:
firefox: "47.0.1"
postgresql: "9.4"
apt:
packages:
- openjdk-8-jre-headless

cache:
directories:
- $HOME/.composer/cache
- $HOME/.npm

php:
# PHP 5.6 gives errors because of the provider.php needs to be PHP7
- 7.0
- 7.1

env:
global:
- MOODLE_BRANCH=MOODLE_32_STABLE
- MOODLE_BRANCH=MOODLE_35_STABLE
- MOODLE_BRANCH=MOODLE_36_STABLE
- MOODLE_BRANCH=MOODLE_37_STABLE
- MOODLE_BRANCH=MASTER

matrix:
- DB=pgsql
- DB=mysqli

before_install:
- phpenv config-rm xdebug.ini
- nvm install 8.9
- nvm use 8.9
- cd ../..
- composer create-project -n --no-dev --prefer-dist moodlerooms/moodle-plugin-ci ci ^2
- export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH"

install:
- moodle-plugin-ci add-plugin moodlehq/moodle-local_moodlecheck
- moodle-plugin-ci install

script:
- php moodle/local/moodlecheck/cli/moodlecheck.php --path=blocks/mfavatar --format=text
- moodle-plugin-ci phplint
- moodle-plugin-ci phpcpd
- moodle-plugin-ci phpmd
- moodle-plugin-ci codechecker
- moodle-plugin-ci validate
- moodle-plugin-ci savepoints
- moodle-plugin-ci mustache
- moodle-plugin-ci grunt
- moodle-plugin-ci phpunit
- moodle-plugin-ci behat
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## Moodle MFavatar Snapshot/Webcam tool for user profile picture

In brief, the Mfreak Plugin Avatar gives the user the possibility to take a snapshot with a live webcam. The user can then upload the picture and modify his profile picture at any time.
Besides this, there is also the facility to customize texts within the plugin.

## Author
![MFreak.nl](https://MFreak.nl/logo_small.png)

* Author: Luuk Verhoeven, [MFreak.nl](https://www.MFreak.nl/)
* Min. required: Moodle 3.5.x
* Supports PHP: 7.0 | 7.1 | 7.2

[![Build Status](https://travis-ci.org/MFreakNL/moodle-block_mfavatar.svg?branch=moodle35)](https://travis-ci.org/MFreakNL/moodle-block_mfavatar)

## List of features
- WebRTC, make snapshot with webcam.
- Flash, make snapshot with webcam.
- Feature for making automatically user avatars. Thanks to `laravolt/avatar`
<!-- copy and paste. Modify height and width if desired. --> <a href="https://content.screencast.com/users/LuukVerhoeven/folders/Default/media/3cab1cd8-f5f0-448e-955d-ab8f3bc4cbb2/06.07.2018-18.36.png"><img class="embeddedObject" src="https://content.screencast.com/users/LuukVerhoeven/folders/Default/media/3cab1cd8-f5f0-448e-955d-ab8f3bc4cbb2/06.07.2018-18.36.png" width="500" border="0" /></a>

## Installation
1. Copy this plugin to the `block\mfavatar` folder on the server
2. Login as administrator
3. Go to Site Administrator > Notification
4. Install the plugin
5. You will need to fill out the settings.

## Security

If you discover any security related issues, please email [[email protected]](mailto:[email protected]) instead of using the issue tracker.

## License

The GNU GENERAL PUBLIC LICENSE. Please see [License File](LICENSE) for more information.

## Contributing

Contributions are welcome and will be fully credited. We accept contributions via Pull Requests on Github.

- 2018092600 Thanks for updating WEBRTC @[eglescout](https://github.com/eglescout)
- 2019051400 Thanks for solving issue in image override @[matasarei](https://github.com/matasarei)
10 changes: 0 additions & 10 deletions README.txt

This file was deleted.

34 changes: 17 additions & 17 deletions upload.php → ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,57 +15,57 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* snapshot upload handler
* Snapshot upload handler
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* @package block_mfavatar
* @copyright 2015 MoodleFreak.com
* @copyright 2015 MFreak.nl
* @author Luuk Verhoeven
**/

if (!defined('AJAX_SCRIPT')) {
define('AJAX_SCRIPT', true);
}
define('AJAX_SCRIPT', true);
define('NO_DEBUG_DISPLAY', true);

require('../../config.php');
require_once(__DIR__ . '/../../config.php');
defined('MOODLE_INTERNAL') || die;

require_once("$CFG->libdir/gdlib.php");
$PAGE->set_url('/blocks/mfavatar/upload.php');

require_login(get_site(), true, null, true, true);
$file = required_param('file', PARAM_RAW);
$sessionid = required_param('sesskey', PARAM_RAW);
$systemcontext = context_system::instance();
$array = array('errors' => array(), 'status' => false);
$array = ['errors' => [], 'status' => false];

echo $OUTPUT->header(); // Send headers.

if ($CFG->disableuserimages) {

$array['errors'][] = get_string('failed:disableuserimages', 'block_mfavatar');

} elseif (!has_capability('moodle/user:editownprofile', $systemcontext)) {
} else if (!has_capability('moodle/user:editownprofile', $systemcontext)) {

$array['errors'][] = get_string('failed:permission_editownprofile', 'block_mfavatar');

} elseif (!confirm_sesskey($sessionid)) {
} else if (!confirm_sesskey($sessionid)) {

$array['errors'][] = get_string('failed:sesskey', 'block_mfavatar');
}

if(empty($array['errors'])) {
if (empty($array['errors'])) {

if(stristr($file , 'base64,' )){
//convert webrtc
$file = explode('base64,',$file);
if (stristr($file, 'base64,')) {
// Convert webrtc.
$file = explode('base64,', $file);
$file = end($file);
}

//decode
// Decode.
$file = base64_decode($file);

if(empty($file)){
if (empty($file)) {
$array['errors'][] = get_string('failed', 'block_mfavatar');
die(json_encode($array));
}
Expand All @@ -77,7 +77,7 @@

$newpicture = (int)process_new_icon($context, 'user', 'icon', 0, $tempfile);
if ($newpicture != $USER->picture) {
$DB->set_field('user', 'picture', $newpicture, array('id' => $USER->id));
$DB->set_field('user', 'picture', $newpicture, ['id' => $USER->id]);
$array['status'] = true;
} else {
$array['errors'][] = get_string('failed', 'block_mfavatar');
Expand Down
78 changes: 60 additions & 18 deletions block_mfavatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,60 +17,101 @@
/**
* Snapshot block contains the button to go to snapshot view page
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* @package block_mfavatar
* @copyright 2015 MoodleFreak.com
* @copyright 2015 MFreak.nl
* @author Luuk Verhoeven
**/
defined('MOODLE_INTERNAL') || die();
defined('MOODLE_INTERNAL') || die;

/**
* Class block_mfavatar
*/
class block_mfavatar extends block_base {

function init() {
/**
* init
*
* @throws coding_exception
*/
public function init() {
$this->title = get_string('pluginname', 'block_mfavatar');
}

function instance_allow_multiple() {
/**
* instance_allow_multiple
*
* @return bool
*/
public function instance_allow_multiple() {
return false;
}

function has_config() {
/**
* has_config
*
* @return bool
*/
public function has_config() {
return true;
}

function applicable_formats() {
return array(
/**
* applicable_formats
*
* @return array
*/
public function applicable_formats() {
return [
'my' => true,
'all' => true,
);
];
}

function instance_allow_config() {
/**
* instance_allow_config
*
* @return bool
*/
public function instance_allow_config() {
return true;
}

function specialization() {
/**
* specialization
*
* @throws coding_exception
*/
public function specialization() {

// load userdefined title and make sure it's never empty
// Load userdefined title and make sure it's never empty.
if (empty($this->config->title)) {
$this->title = get_string('pluginname', 'block_mfavatar');
} else {
$this->title = $this->config->title;
}
}

function get_content() {
/**
* get_content
*
* @return stdClass|stdObject
* @throws coding_exception
* @throws dml_exception
*/
public function get_content() {
global $CFG, $COURSE;

require_once $CFG->libdir . '/formslib.php';
require_once($CFG->libdir . '/formslib.php');

if ($this->content !== null) {
return $this->content;
}

$systemcontext = context_system::instance();
if ((!isloggedin() || isguestuser() || !has_capability('block/mfavatar:view', $systemcontext)) || !has_capability('moodle/user:editownprofile', $systemcontext) || $CFG->disableuserimages) {
if ((!isloggedin() || isguestuser() || !has_capability('block/mfavatar:view', $systemcontext)) ||
!has_capability('moodle/user:editownprofile', $systemcontext) || $CFG->disableuserimages) {
$this->content = new stdClass();
$this->content->text = '';

Expand All @@ -79,16 +120,17 @@ function get_content() {

$this->content = new stdClass();
$this->content->text = '<div class="singlebutton">
<form action="' . $CFG->wwwroot . '/blocks/mfavatar/view.php" method="get">
<form action="' . $CFG->wwwroot . '/blocks/mfavatar/view/view.php" method="get">
<div>
<input type="hidden" name="blockid" value="' . $this->instance->id . '"/>
<input type="hidden" name="courseid" value="' . $COURSE->id . '"/>
<input class="singlebutton" type="submit" value="' . get_string('makesnapshot', 'block_mfavatar') . '"/>
<input class="singlebutton btn btn-primary" type="submit" value="' .
get_string('makesnapshot', 'block_mfavatar') . '"/>
</div>
</form>
</div>';
$this->content->footer = '';

return $this->content;
}
}
}
Loading

0 comments on commit 1b8c53e

Please sign in to comment.