@@ -350,18 +350,26 @@ function customcert_extend_settings_navigation(settings_navigation $settings, na
350
350
if (has_capability ('mod/customcert:manage ' , $ settings ->get_page ()->cm ->context )) {
351
351
// Get the template id.
352
352
$ templateid = $ DB ->get_field ('customcert ' , 'templateid ' , ['id ' => $ settings ->get_page ()->cm ->instance ]);
353
- $ node = navigation_node::create (get_string ('editcustomcert ' , 'customcert ' ),
354
- new moodle_url ('/mod/customcert/edit.php ' , ['tid ' => $ templateid ]),
355
- navigation_node::TYPE_SETTING , null , 'mod_customcert_edit ' ,
356
- new pix_icon ('t/edit ' , '' ));
353
+ $ node = navigation_node::create (
354
+ get_string ('editcustomcert ' , 'customcert ' ),
355
+ new moodle_url ('/mod/customcert/edit.php ' , ['tid ' => $ templateid ]),
356
+ navigation_node::TYPE_SETTING ,
357
+ null ,
358
+ 'mod_customcert_edit ' ,
359
+ new pix_icon ('t/edit ' , '' )
360
+ );
357
361
$ customcertnode ->add_node ($ node , $ beforekey );
358
362
}
359
363
360
364
if (has_capability ('mod/customcert:verifycertificate ' , $ settings ->get_page ()->cm ->context )) {
361
- $ node = navigation_node::create (get_string ('verifycertificate ' , 'customcert ' ),
365
+ $ node = navigation_node::create (
366
+ get_string ('verifycertificate ' , 'customcert ' ),
362
367
new moodle_url ('/mod/customcert/verify_certificate.php ' , ['contextid ' => $ settings ->get_page ()->cm ->context ->id ]),
363
- navigation_node::TYPE_SETTING , null , 'mod_customcert_verify_certificate ' ,
364
- new pix_icon ('t/check ' , '' ));
368
+ navigation_node::TYPE_SETTING ,
369
+ null ,
370
+ 'mod_customcert_verify_certificate ' ,
371
+ new pix_icon ('t/check ' , '' )
372
+ );
365
373
$ customcertnode ->add_node ($ node , $ beforekey );
366
374
}
367
375
@@ -380,8 +388,10 @@ function customcert_extend_settings_navigation(settings_navigation $settings, na
380
388
function mod_customcert_myprofile_navigation (core_user \output \myprofile \tree $ tree , $ user , $ iscurrentuser , $ course ) {
381
389
global $ USER ;
382
390
383
- if (($ user ->id != $ USER ->id )
384
- && !has_capability ('mod/customcert:viewallcertificates ' , context_system::instance ())) {
391
+ if (
392
+ ($ user ->id != $ USER ->id )
393
+ && !has_capability ('mod/customcert:viewallcertificates ' , context_system::instance ())
394
+ ) {
385
395
return ;
386
396
}
387
397
@@ -392,8 +402,13 @@ function mod_customcert_myprofile_navigation(core_user\output\myprofile\tree $tr
392
402
$ params ['course ' ] = $ course ->id ;
393
403
}
394
404
$ url = new moodle_url ('/mod/customcert/my_certificates.php ' , $ params );
395
- $ node = new core_user \output \myprofile \node ('miscellaneous ' , 'mycustomcerts ' ,
396
- get_string ('mycertificates ' , 'customcert ' ), null , $ url );
405
+ $ node = new core_user \output \myprofile \node (
406
+ 'miscellaneous ' ,
407
+ 'mycustomcerts ' ,
408
+ get_string ('mycertificates ' , 'customcert ' ),
409
+ null ,
410
+ $ url
411
+ );
397
412
$ tree ->add_node ($ node );
398
413
}
399
414
@@ -431,8 +446,14 @@ function mod_customcert_inplace_editable($itemtype, $itemid, $newvalue) {
431
446
$ updateelement ->name = clean_param ($ newvalue , PARAM_TEXT );
432
447
$ DB ->update_record ('customcert_elements ' , $ updateelement );
433
448
434
- return new \core \output \inplace_editable ('mod_customcert ' , 'elementname ' , $ element ->id , true ,
435
- $ updateelement ->name , $ updateelement ->name );
449
+ return new \core \output \inplace_editable (
450
+ 'mod_customcert ' ,
451
+ 'elementname ' ,
452
+ $ element ->id ,
453
+ true ,
454
+ $ updateelement ->name ,
455
+ $ updateelement ->name
456
+ );
436
457
}
437
458
}
438
459
@@ -449,14 +470,14 @@ function mod_customcert_inplace_editable($itemtype, $itemid, $newvalue) {
449
470
* @param string $cert_code The unique code of the certificate.
450
471
* @return string The generated public URL for the certificate.
451
472
*/
452
- function generate_public_url_for_certificate (string $ cert_code ): string {
473
+ function generate_public_url_for_certificate (string $ certcode ): string {
453
474
global $ CFG ;
454
475
455
476
// Generate a security token for the certificate using a private function.
456
- $ token = calculate_signature ($ cert_code );
477
+ $ token = calculate_signature ($ certcode );
457
478
458
479
// Construct and return the public URL to view the certificate.
459
- return $ CFG ->wwwroot . '/mod/customcert/view_user_cert.php?cert_code= ' . urlencode ($ cert_code ) . '&token= ' . urlencode ($ token );
480
+ return $ CFG ->wwwroot . '/mod/customcert/view_user_cert.php?cert_code= ' . urlencode ($ certcode ) . '&token= ' . urlencode ($ token );
460
481
}
461
482
462
483
/**
@@ -467,22 +488,22 @@ function generate_public_url_for_certificate(string $cert_code): string {
467
488
* It prevents unauthorized access by ensuring that only valid certificates can
468
489
* be accessed through a generated URL.
469
490
*
470
- * The signature is generated using the HMAC (Hash-based Message Authentication Code)
491
+ * The signature is generated using the HMAC (Hash-based Message Authentication Code)
471
492
* method with SHA-256, ensuring strong security. It uses Moodle's `siteidentifier`
472
493
* as the secret key, making it unique to each Moodle installation.
473
494
*
474
495
* @param string $cert_code The unique certificate code.
475
496
* @return string The generated HMAC signature.
476
497
*/
477
- function calculate_signature (string $ cert_code ): string {
498
+ function calculate_signature (string $ certcode ): string {
478
499
global $ CFG ;
479
500
480
501
// Define a namespaced message prefix to avoid signature collisions.
481
- $ messagePrefix = 'mod_customcert:view_user_cert ' ;
502
+ $ messageprefix = 'mod_customcert:view_user_cert ' ;
482
503
483
504
// Construct the message that will be signed.
484
505
// This includes the prefix and the certificate code to create a unique hash.
485
- $ message = $ messagePrefix . '| ' . $ cert_code ;
506
+ $ message = $ messageprefix . '| ' . $ certcode ;
486
507
487
508
// Use Moodle's unique site identifier as the secret key for HMAC.
488
509
// This ensures that signatures are installation-specific.
0 commit comments