Commit 4a686e84 authored by theo lem's avatar theo lem
Browse files

updated installation profile with latest version of modules

parent 9e513d3c
......@@ -51,7 +51,8 @@ function framaforms_install () {
framaforms_set_variables_mail();
framaforms_set_variables_pages();
$now = date('Y/m/d/ h:m:s', time());
variable_set('framaforms_cron_last', strtotime($now)); // the last framforms cron run
variable_set('framaforms_cron_last', new DateTime()); // the last framforms cron run
variable_set('framaforms_cron_frequency', '1 second');
variable_set('framaforms_expiration_period_default_value', 26); // default creation-expiration time interval
variable_set('framaforms_deletion_period_value', 9); // default expiration-deletion time interval
variable_set('framaforms_notification_period_value', 2); // default notification-expiration time interval
......@@ -105,16 +106,24 @@ function framaforms_uninstall () {
function framaforms_set_variables_mail () {
// sprintf-ready mail for notifying a user of his⋅her form expiration.
$framaforms_mail_user_notification_body = t("
<p>Bonjour,</p>
<p>Votre formulaire intitul&eacute; [form_title] expirera dans deux semaines, soit en date du [form_expires_on] .</p>
<p><strong>Les utilisateurs ne pourront plus r&eacute;pondre &agrave; votre formulaire</strong>. Vous aurez toujours acc&egrave;s aux r&eacute;sultats pendant une p&eacute;riode de deux mois, avant qu'il ne soit <strong>d&eacute;finitivement supprim&eacute; de notre base de donn&eacute;es</strong> en date du [form_delete_on] .</p>
<p>Si vous souhaitez repousser l'expiration de votre formulaire, c'est possible : il suffit de vous rendre sur la page d'administration de votre formulaire ([form_url]) et de modifier la date d'expiration.</p>
<p>&nbsp;</p>
<p>Cordialement,</p>
<p>Framasoft</p>
<p><em>\" La route est longue, mais la voie est libre. \"</em></p>
Bonjour,
Votre formulaire intitulé « [form_title] » expirera dans deux semaines, soit en date du [form_expires_on].
Les utilisateurs ne pourront plus répondre à votre formulaire, mais vous aurez toujours accès aux résultats jusqu'au [form_delete_on]. Ensuite, les données seront définitivement supprimées de notre base de données.
Si vous souhaitez repousser l'expiration de votre formulaire, c'est possible.
: il suffit de vous identifier sur Framaforms, puis de vous rendre sur la page d'administration de votre formulaire [form_url] et de modifier la date d'expiration comme indiqué ici : https://framaforms.org/limitations.
Ce message est un message automatique, il est inutile d'utiliser la fonctionnalité « Répondre ». Si vous avez des questions concernant l'usage de Framaforms, notre forum d'entraide <Framacolibri> est à votre disposition. Pour toute autre question, vous pouvez aussi nous contacter en passant par notre espace de support : https://contact.framasoft.org.
Nous en profitons pour vous rappeler que Framasoft est une petite association à but non-lucratif, dédiée aux enjeux du numérique, qui ne vit que de vos dons. Si Framaforms vous est utile, merci d'envisager de faire un don (défiscalisable) à l'association : https://soutenir.framasoft.org
Librement,
Framasoft
« La route est longue, mais la voie est libre. »
");
$framaforms_mail_user_notification_subject = t("Framaforms : Votre formulaire \"%s\" expirera dans deux semaines.");
$framaforms_mail_user_notification_subject = t("Framaforms : Votre formulaire « [form_title] » expirera dans deux semaines.");
variable_set('framaforms_mail_user_notification_subject', $framaforms_mail_user_notification_subject);
variable_set('framaforms_mail_user_notification_body', $framaforms_mail_user_notification_body);
}
......
......@@ -10,11 +10,11 @@ function framaforms_menu () {
$items = array();
$items['admin/config/system/framaforms'] = array(
'title' => 'Configurer Framaforms',
'description' => t('Configuration for Framaforms module'),
'description' => t('Configuration du module Framaforms'),
'page callback' => 'drupal_get_form',
'page arguments' => array('framaforms_config_form'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
'type' => MENU_CALLBACK,
'file' => 'includes/framaforms.admin.inc',
);
$items['admin/framaforms/dashboard'] = array(
......@@ -42,14 +42,6 @@ function framaforms_menu () {
'access arguments' => array('access content'),
'file' => 'includes/framaforms.pages.inc',
);
$items['admin/framaforms/create_default_pages'] = array(
'title' => t('Créer les pages par défaut'),
'description' => t("Accéder à ce menu déclenche la création des pages par défaut (page d'accueil, de fonctionnalités, etc.)"),
'page callback' => 'create_all_pages',
'type' => MENU_NORMAL_ITEM,
'access arguments' => array('access administration pages'),
'file' => 'includes/framaforms.pages.inc',
);
return $items;
}
......@@ -81,7 +73,7 @@ function framaforms_block_info () {
);
// block : General header with Framaforms title
$blocks['framaforms_header'] = array(
'info' => t('Header général'),
'info' => t('En-tête général'),
'cache' => DRUPAL_CACHE_PER_PAGE,
'status' => TRUE,
'region' => 'highlighted',
......@@ -239,6 +231,9 @@ function framaforms_block_view ($delta) {
if(isset($matches[1])){
$nid = $matches[1] ? $matches[1] : NULL;
}
else {
$nid = NULL;
}
// generate content by block ID
switch($delta) {
case 'framaforms_contact_form_block':
......@@ -330,7 +325,7 @@ function framaforms_block_view ($delta) {
$block['content']['#markup'] .= '</ul>';
break;
case 'framaforms_create_form':
$block['content']['#markup'] = t("<p>Vous allez créer ou modifier un formulaire framaforms.<br />
$block['content']['#markup'] = t("<p>Vous allez créer ou modifier un formulaire.<br />
Commencez par remplir les champs ci-dessous, puis cliquez sur « Enregistrer ».<br />
<b>NB : le titre est important, car il sera partiellement repris dans le titre. Le changer changera l'adresse du formulaire !</b></p>");
break;
......@@ -548,20 +543,21 @@ function framaforms_cron(){
module_load_include('inc', 'framaforms', 'includes/framaforms.expiration');
global $user;
/**
* Parameters for adjusting the expiration and deletion period,
* as well as the cron frequency.
* Parameter for adjusting cron frequency.
*/
$cron_last = date('Y/m/d/ h:m:s', variable_get('framaforms_cron_last')); // the last time the cron task was run.
$cron_limit = date('Y/m/d/ h:m:s', strtotime('-'. variable_get('framaforms_cron_limit')));
$now = date('Y/m/d/ h:m:s', time());
$framaforms_cron_last = variable_get('framaforms_cron_last'); // the last time the cron task was run.
$cron_limit = new DateTime();
$cron_limit->setTimestamp($framaforms_cron_last);
$cron_limit->modify('+'.variable_get('framaforms_cron_frequency'));
$now = new DateTime();
// if the cron was executed less than 24h ago, do nothing.
if(strtotime($cron_last) > strtotime($cron_limit)){
return;
if($now < $cron_limit){
return;
}
// else, proceed to cron.
watchdog('framaforms', "Running framaforms cron.");
variable_set('framaforms_cron_last', strtotime($now));
watchdog('framaforms', "Tâche cron lancée.");
variable_set('framaforms_cron_last', $now->getTimestamp());
/**
* Handle expired nodes
......@@ -581,4 +577,4 @@ function framaforms_node_delete ($node) {
->condition('source', 'node/'.$node->nid)
->execute();
}
}
}
\ No newline at end of file
......@@ -159,22 +159,54 @@ function framaforms_config_form ($form, &$form_state) {
'#description' => t("Vous pouvez ici configurer le contenu de la page d'expiration des formulaires : il s'agit de la page sur laquelle seront redirigé⋅e⋅s les utilisateurices se rendant sur un formulaire dont la date d'expiration est passée. Vous pouvez utiliser les jetons suivants : <strong>[my_forms_url]</strong> (lien vers la page « Mes formulaires »)"),
'#default_value' => variable_get('framaforms_expiration_page_content'),
'#required' => TRUE,
);
return system_settings_form($form);
);
$form['create-default-pages'] = array(
'#type' => 'button',
'#value' => t('Générer les pages par défaut'),
'#description' => t("En cliquant sur ce bouton, vous créerez des pages par défaut pour votre site : page d'accueil, pages d'erreur 404/403, etc. Vous pourrez les modifier ou les supprimer par la suite."),
'#submit' => array('admin_menu_create_pages_callback'),
'#executes_submit_callback' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Enregistrer'),
'#submit' => array('system_settings_form_submit'),
);
return $form;
}
/**
* Inplements hook_form_validate : checks the values for the Framaofrms module configuration form
* @return void
*/
function framaforms_config_form_validate ($form, &$form_state) {
//assert that time interval values are numeric
$expiration_interval = $form_state['values']['framaforms_expiration_default_value'];
if(!is_numeric($expiration_interval)){
form_set_error(t('Les valeurs de temps doivent être exprimées en chiffres.'));
}
$deletion_interval = $form_state['values']['framaforms_deletion_period_value'];
if(!is_numeric($deletion_interval)){
form_set_error(t('Les valeurs de temps doivent être exprimées en chiffres.'));
}
}
\ No newline at end of file
/**
* Secondary callback for the "Generate pages" button
*
* @return void
*/
function admin_menu_create_pages_callback () {
module_load_include('inc', 'framaforms', 'includes/framaforms.pages');
create_all_pages();
drupal_set_message("Les pages ont bien été créées.");
}
/**
* Inplements hook_form_validate : checks the values of expiration and deletion period
* and checks they are numeric.
* @return void
*/
function framaforms_config_form_validate ($form, &$form_state) {
$values = $form_state['values'];
if(!is_numeric($values['framaforms_deletion_period_value'])){
drupal_set_message(t("Erreur dans les valeurs administratives de Framaforms."));
form_set_error('framaforms_deletion_period_value', t("a période de suppression doit être numérique."));
}
if(!is_numeric($values['framaforms_expiration_period_default_value'])){
drupal_set_message(t("Erreur dans les valeurs administratives de Framaforms."));
form_set_error('framaforms_expiration_period_default_value', t("La période d'expiration doit être numérique."));
}
}
/**
* Implements hook_form_submit
* @return void
*/
function framaforms_config_form_submit ($form, &$form_state) {
drupal_set_message('form submitted !');
}
\ No newline at end of file
......@@ -32,7 +32,7 @@ function get_contact_form_content ($nid) {
}
}
catch(Exception $e){
watchdog('framaforms', 'Error in contact form block' . $e);
watchdog('framaforms', 'Erreur dans le block de formulaire de contact (modules/framaforms/includes/framaforms.block.inc)' . $e);
}
return $content;
}
......
......@@ -11,26 +11,28 @@
* @return void
*/
function make_forms_expire(){
$expiration_period = variable_get('framaforms_expiration_period_default_value');
$expiration_period = variable_get('framaforms_notification_period_value');
// If the user set the expiration period to 0, don't make the nodes expire.
if($expiration_period == 0 || (!is_numeric($expiration_period)) ){
if($expiration_period == 0){
return;
}
$expiration_period .= ' weeks';
$transaction = db_transaction();
try{
// Look for nodes expiring in a interval of time set in the global varialbe 'framaforms_expiration_period_default_value'
// Select nodes expiring within the two next weeks.
// Limit query to batch of 1000 rows in order to avoid errors
db_query(sprintf("
insert into framaforms_expired (nid)
select node.nid
from node
inner join field_data_field_form1_expiration
on field_data_field_form1_expiration.entity_id = node.nid
where node.type='form1'
and field_data_field_form1_expiration.field_form1_expiration_value <= date_trunc('day', NOW() + interval'%s')
and field_data_field_form1_expiration.field_form1_expiration_value > date_trunc('day', NOW())
on conflict do nothing;
INSERT INTO framaforms_expired (nid)
(SELECT n.nid
FROM node n
INNER JOIN field_data_field_form1_expiration fex
ON fex.entity_id = n.nid
AND fex.field_form1_expiration_value <= date_trunc('day', NOW() + interval'{$expiration_period}')
AND fex.entity_id NOT IN
(SELECT nid FROM framaforms_expired)
LIMIT 1000)
ON CONFLICT DO NOTHING;
",$expiration_period));
}
catch(Exception $e){
......@@ -41,20 +43,19 @@
/* Get all the webforms that are about to expire and whose owner wasn't yet notified */
try{
$results = db_query("
select framaforms_expired.nid, users.mail, node.title
from framaforms_expired
inner join node
on framaforms_expired.nid = node.nid
inner join users
on users.uid = node.uid
where framaforms_expired.notified = 0"
) ;
SELECT fex.nid, u.mail, n.title
FROM framaforms_expired fex
INNER JOIN node n
ON fex.nid = n.nid
INNER JOIN users u
ON u.uid = n.uid
WHERE fex.notified = 0
LIMIT 1000;
") ;
// Notify the users of their forms expiration
watchdog('framaforms', "Notifying users of their expired forms.");
foreach ($results as $record){
watchdog('framaforms', "Sending email to " . (string)$record->mail .
" because of expired webform node (nid = " . (string)$record->nid . ")"
);
$user_notified = notify_user_of_expiration($record);
// Update the database with the notification date and set notified to 1
if($user_notified){
......@@ -67,9 +68,11 @@
->execute();
}
}
watchdog('framaforms', "Notified all users of their expired forms.");
}
catch(Exception $e){
$transaction->rollback();
watchdog('framaforms', "There was an error notifying users.");
watchdog('framaforms', $e);
}
}
......@@ -87,8 +90,14 @@ function notify_user_of_expiration ($record) {
global $base_url; //use the global variable of Drupal for the site's URL
$expiration_period = variable_get('framaforms_notification_period_value') .' weeks';
$deletion_period = variable_get('framaforms_deletion_period_value') .' weeks';
$expiration_date = date("d/m/Y", strtotime('+'.$expiration_period));
$delete_date = date("d/m/Y", strtotime('+'.$deletion_period));
$expiration_date = new DateTime();
$expiration_date->modify("+".$expiration_period);
$delete_date = clone $expiration_date;
$delete_date->modify($deletion_period);
$delete_date = date("d/m/Y", $delete_date->getTimestamp());
$expiration_date = date("d/m/Y", $expiration_date->getTimestamp());
$node_url = $base_url . url('node/'.$record->nid);
$mail_body = variable_get('framaforms_mail_user_notification_body');
$mail_subject = variable_get('framaforms_mail_user_notification_subject');
......@@ -103,43 +112,41 @@ function notify_user_of_expiration ($record) {
'subject' => $mail_subject,
'headers' => array(),
);
watchdog('framaforms', "Sending following email to " . (string)$record->mail . " : " . $body);
$message = drupal_mail('framaforms', 'expired_webform', (string)$record->mail, user_preferred_language($user), $mail_params);
return $message['send'];
}
/**
* Looksup webform nodes in the database that were marked as
* Looks up webform nodes in the database that were marked as
* "expired" but whose expiration date * got changed by the user.
*
* @return void
*/
function update_modified_nodes () {
$expiration_period = variable_get('framaforms_notification_period_value');
if($expiration_period == 0 || (!is_numeric($expiration_period)) ){
if($expiration_period == 0){
return;
}
$expiration_period .= ' weeks';
$transaction = db_transaction();
watchdog('framaforms', "Suppression des formulaires dans la table framaforms_expired après que leur date d'expiration ait été repoussée.");
try{
//Delete nodes from the framaforms_notified table if their expiration date was pushed back by the user
$modified_nodes = db_query(sprintf("
select node.nid
from node
inner join field_data_field_form1_expiration
on field_data_field_form1_expiration.entity_id = node.nid
inner join framaforms_expired
on node.nid=framaforms_expired.nid
where field_data_field_form1_expiration.field_form1_expiration_value
> to_timestamp(framaforms_expired.date_notified) + interval'%s'
SELECT n.nid
FROM node n
INNER JOIN field_data_field_form1_expiration f_exdate
ON f_exdate.entity_id = n.nid
INNER JOIN framaforms_expired fex
ON n.nid = fex.nid
WHERE f_exdate.field_form1_expiration_value
> to_timestamp(fex.date_notified) + interval'{$expiration_period}'
AND n.nid NOT IN (SELECT nid from framaforms_expired)
", $expiration_period));
$nid_changed= 0 ;
foreach($modified_nodes as $node){
$nid_changed = $node->nid;
watchdog('framaforms', "Updating framaforms_expired, deleting the modified webform " .
(string)$node->nid . " from the framaforms_expired table.");
db_delete('framaforms_expired')
->condition('nid', (int)$nid_changed)
->execute() ;
......@@ -163,19 +170,20 @@ function update_modified_nodes () {
function delete_expired_nodes () {
// if the user set the deletion period to 0, don't delete the forms
$deletion_period = variable_get('framaforms_deletion_period_value');
if($deletion_period == 0 || (!is_numeric($deletion_period)) ){
if($deletion_period == 0){
return;
}
$deletion_period .= ' weeks';
$deleted_nodes = [];
$deleted_nodes = array();
watchdog('framaforms', "Suppression des formulaires après notification.");
$transaction = db_transaction();
try{
$query = db_query(sprintf("
select framaforms_expired.nid
from framaforms_expired
where notified=1
and to_timestamp(framaforms_expired.date_notified) < date_trunc('day', NOW() - interval'%s') ;
", $deletion_period));
$query = db_query("
SELECT fex.nid
FROM framaforms_expired fex
WHERE fex.notified = 1
AND to_timestamp(fex.date_notified) < date_trunc('day', NOW() - interval'{$deletion_period}')
");
$expired_nodes= $query->fetchAll();
foreach($expired_nodes as $record){
node_delete($record->nid);
......@@ -184,14 +192,14 @@ function delete_expired_nodes () {
->condition('nid', $record->nid)
->execute();
$deleted_nodes[] = $record->nid;
array_push($deleted_nodes, $record->nid);
}
if(!empty($deleted_nodes)){
watchdog("framaforms", "Deleted following expired webforms : " . explode($deleted_nodes));
watchdog("framaforms", "Les formulaires suivant ont été supprimés : " . explode($deleted_nodes));
return;
}
watchdog("framaforms", "No expired webform to delete.");
watchdog("framaforms", "Aucun formulaire à supprimer.");
}
catch(Exception $e){
$transaction->rollback();
......
......@@ -23,7 +23,7 @@ function create_custom_page ($page_title, $file_name){
->execute()
->fetchAssoc();
if($query){
watchdog('framaforms', 'returning from query in create_custom_page()');
// early return if a page with the same title is found in the database.
return -1;
}
$custom_node = new stdClass();
......@@ -58,7 +58,7 @@ function create_custom_page ($page_title, $file_name){
node_save($custom_node);
}
catch(Exception $e){
watchdog('framaforms', 'Error creating custom page' .$title . ' : '. $e);
watchdog('framaforms', "Erreur lors de la création de la page « {$title} » : {$e}");
return -1;
}
......@@ -94,7 +94,7 @@ function create_all_pages (){
if($forbidden_nid != -1){
variable_set('site_403', 'node/'.$forbidden_nid);
}
$notfound_nid = create_custom_page('Page not found / Page introuvable','404.html');
$notfound_nid = create_custom_page('Page introuvable / Page not found','404.html');
if($notfound_nid != -1){
variable_set('site_404', 'node/'.$notfound_nid);
}
......@@ -112,7 +112,6 @@ function create_all_pages (){
// return to frontpage
drupal_goto('/');
drupal_set_message(t("Les pages par défaut ont bien été crées. Rendez-vous sur <a href='/admin/content'>ce menu</a> pour les visualiser."), 'stat us');
return;
}
......
<?php
/**
* @file
* framaforms_feature.captcha.inc
*/
/**
* Implements hook_captcha_default_points().
*/
function framaforms_feature_captcha_default_points() {
$export = array();
$captcha = new stdClass();
$captcha->disabled = FALSE; /* Edit this to true to make a default captcha disabled initially */
$captcha->api_version = 1;
$captcha->form_id = 'comment_node_article_form';
$captcha->module = '';
$captcha->captcha_type = '';
$export['comment_node_article_form'] = $captcha;
$captcha = new stdClass();
$captcha->disabled = FALSE; /* Edit this to true to make a default captcha disabled initially */
$captcha->api_version = 1;
$captcha->form_id = 'comment_node_form1_form';
$captcha->module = '';
$captcha->captcha_type = '';
$export['comment_node_form1_form'] = $captcha;
$captcha = new stdClass();
$captcha->disabled = FALSE; /* Edit this to true to make a default captcha disabled initially */
$captcha->api_version = 1;
$captcha->form_id = 'comment_node_page_form';
$captcha->module = '';
$captcha->captcha_type = '';
$export['comment_node_page_form'] = $captcha;
$captcha = new stdClass();
$captcha->disabled = FALSE; /* Edit this to true to make a default captcha disabled initially */
$captcha->api_version = 1;
$captcha->form_id = 'comment_node_webform_form';
$captcha->module = '';
$captcha->captcha_type = '';
$export['comment_node_webform_form'] = $captcha;
$captcha = new stdClass();
$captcha->disabled = FALSE; /* Edit this to true to make a default captcha disabled initially */
$captcha->api_version = 1;
$captcha->form_id = 'comment_node_webform_report_form';
$captcha->module = '';
$captcha->captcha_type = 'default';
$export['comment_node_webform_report_form'] = $captcha;
$captcha = new stdClass();
$captcha->disabled = FALSE; /* Edit this to true to make a default captcha disabled initially */
$captcha->api_version = 1;
$captcha->form_id = 'contact_personal_form';
$captcha->module = '';
$captcha->captcha_type = 'default';
$export['contact_personal_form'] = $captcha;
$captcha = new stdClass();
$captcha->disabled = FALSE; /* Edit this to true to make a default captcha disabled initially */
$captcha->api_version = 1;
$captcha->form_id = 'contact_site_form';
$captcha->module = '';
$captcha->captcha_type = 'default';
$export['contact_site_form'] = $captcha;
$captcha = new stdClass();
$captcha->disabled = FALSE; /* Edit this to true to make a default captcha disabled initially */
$captcha->api_version = 1;
$captcha->form_id = 'user_login';
$captcha->module = '';
$captcha->captcha_type = '';
$export['user_login'] = $captcha;
$captcha = new stdClass();
$captcha->disabled = FALSE; /* Edit this to true to make a default captcha disabled initially */
$captcha->api_version = 1;
$captcha->form_id = 'user_login_block';
$captcha->module = '';
$captcha->captcha_type = '';
$export['user_login_block'] = $captcha;
$captcha = new stdClass();
$captcha->disabled = FALSE; /* Edit this to true to make a default captcha disabled initially */
$captcha->api_version = 1;
$captcha->form_id = 'user_pass';
$captcha->module = '';
$captcha->captcha_type = 'default';
$export['user_pass'] = $captcha;
$captcha = new stdClass();
$captcha->disabled = FALSE; /* Edit this to true to make a default captcha disabled initially */
$captcha->api_version = 1;
$captcha->form_id = 'user_register_form';
$captcha->module = 'riddler';
$captcha->captcha_type = 'Riddler';
$export['user_register_form'] = $captcha;
return $export;
}
<?php
/**
* @file
* framaforms_feature.default_field_validation_rules.inc
*/
/**
* Implements hook_default_field_validation_rule().
*/
function framaforms_feature_default_field_validation_rule() {
$export = array();
$rule = new stdClass();
$rule->disabled = FALSE; /* Edit this to true to make a default rule disabled initially */
$rule->api_version = 2;
$rule->rulename = 'date expiration validation';