This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Checks that the file has allowed MIME type. | |
* | |
* @param $file | |
* A Drupal file object. | |
* @param $mimetypes_string | |
* A string with a space separated list of allowed MIME types. | |
* | |
* @return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Sometimes we need to submit only part of the form. Sure, if form has #required fields, all they will be highlighted with red, | |
//and form will not be submitted if these elements have no value. | |
//To workaround this, we can use '#limit_validation_errors' option AND custom submit function for every 'Partial Submit' button. | |
//Interesting note: when we use '#limit_validation_errors', we will see ALL form fields in _validate function, | |
//but in _submit function will be visible ONLY elements, included in '#limit_validation_errors' array!!! | |
//Case 1. The most simple. | |
//We want to make a 'reset' button, or 'previous step' button, so it must work even if some REQUIRED form elements are empty: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function _nxte_redeem_is_email_valid($email) { | |
if (empty ($email)) {return false;} | |
list($user_name, $mail_domain) = explode('@', $email); | |
if (empty($user_name) || empty($mail_domain)) {return false;} | |
$is_syntax_ok = (bool) filter_var($email, FILTER_VALIDATE_EMAIL); | |
$is_MX_exists = checkdnsrr($mail_domain, 'MX'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This function generates simple table with header row from specified data (tableContent, headerLabels). | |
* tableContent is 2-D array with DOM Elements as values: | |
* [ | |
* 0 => [0 => DOM_Obj_1cell_1row, 1 => DOM_Obj_2cell_1row, 2 => DOM_Obj_3cell_1row, ...], <- first row | |
* 1 => [0 => DOM_Obj_1cell_2row, 1 => DOM_Obj_2cell_2row, 2 => DOM_Obj_3cell_2row, ...], <- second row | |
* ]; | |
* headerLabels is 1-D array, also with DOM Elements as values (not just strings!); | |
* [ | |
* 0 => DOM_Obj_headerlabel_1, 1 => DOM_Obj_headerlabel_2, ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//This function checks if specified date IS IN acceptable interval from NOW to some moment in the past. | |
//$date_to_check need to be in classic datetime format, like in mySQL; | |
//$interval sets like here http://php.net/manual/en/dateinterval.construct.php, but without 'P', | |
//'P' will be added automatically. | |
function is_date_acceptable($date_to_check, $interval) { | |
$now = new DateTime(); | |
$interval = 'P'.$interval; | |
$min_acceptable_date = $now->sub(new DateInterval($interval)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Array with connection credentials. This is the same structured array like in "settings.local.php" file in your Drupal set up. | |
$db_connection_data = [ | |
'host' => 'localhost', | |
'database' => 'example_db', | |
'username' => 'root', | |
'password' => '', | |
'driver' => 'mysql', | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$db_connection_data = = [ | |
'host' => 'localhost', | |
'database' => 'example_db', | |
'username' => 'root', | |
'password' => '', | |
'driver' => 'mysql', | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Generate a random string, using a cryptographically secure | |
* pseudorandom number generator (random_int) | |
* | |
* For PHP 7, random_int is a PHP core function | |
* For PHP 5.x, depends on https://github.com/paragonie/random_compat | |
* | |
* @param int $length How many characters do we want? | |
* @param string $keyspace A string of all possible characters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Function filters out not-allowed symbols from string and return 'cleaned' string. | |
* Allowed symbols specified as array of UTF-8 address ranges. | |
* When it needs to change allowed range, consider this resource for all UTF-8 characters code sets: https://unicode-table.com/en/blocks/ | |
* @param string $text input string to filter | |
* @param bool $stripTags remove HTML tags or not | |
* @param array $allowed_utf8_ranges array with ranges of allowed symbols | |
* @return mixed|null|string | |
* @throws Exception |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$form['#tree'] = TRUE; | |
$form['part_of_the_form'] = [ | |
'#type' => 'container', | |
]; | |
$form['part_of_the_form']['field_1'] = [ | |
'#type' => 'textfield', | |
'#title' => 'Field-1', |
OlderNewer