/** * Open a connection to MySQL & Select DB * * @version 1.0 * @since 1.0.0 * @author Dan Aldridge * * @param array $config * * @return bool */ public function connect() { // add check for port, and append it to the hostname if (isset($this->dbSettings['port']) && is_number($this->dbSettings['port'])) { $this->dbSettings['host'] .= ':' . $this->dbSettings['port']; } // if we have persistent enabled, we'll try that first if ($this->dbSettings['persistent'] === true) { $this->DBH = @mysql_pconnect($this->dbSettings['host'], $this->dbSettings['username'], $this->dbSettings['password']); if ($this->DBH === false) { $this->dbSettings['persistent'] = false; } } //persistent is off, lets try and connect normally if ($this->dbSettings['persistent'] === false) { $this->DBH = @mysql_connect($this->dbSettings['host'], $this->dbSettings['username'], $this->dbSettings['password']); } //we havent got a resource we need to bomb out now if ($this->DBH === false) { trigger_error('Cannot connect to the database - verify username and password.<br />', E_USER_ERROR); return false; } //select the DB if ($this->selectDB($this->dbSettings['database']) === false) { trigger_error('Cannot select database - check user permissions.<br />', E_USER_ERROR); return false; } $this->registerPrefix('#__', $this->dbSettings['prefix']); $this->query('SET CHARACTER SET utf8;'); $this->query('SET GLOBAL innodb_flush_log_at_trx_commit = 2;'); //and carry on return true; }
function decode($Type, $Key){ if(is_number($Type)) { // Element is a string // Get length of string $StrLen = $Type; while($this->Str[$this->Pos+1]!=':'){ $this->Pos++; $StrLen.=$this->Str[$this->Pos]; } $this->Val[$Key] = substr($this->Str, $this->Pos+2, $StrLen); $this->Pos+=$StrLen; $this->Pos+=2; } elseif($Type == 'i') { // Element is an int $this->Pos++; // Find end of integer (first occurance of 'e' after position) $End = strpos($this->Str, 'e', $this->Pos); // Get the integer, and - IMPORTANT - cast it as an int, so we know later that it's an int and not a string $this->Val[$Key] = (int)substr($this->Str, $this->Pos, $End-$this->Pos); $this->Pos = $End+1; } elseif($Type == 'l') { // Element is a list $this->Val[$Key] = new BENCODE_LIST(substr($this->Str, $this->Pos)); $this->Pos += $this->Val[$Key]->Pos; } elseif($Type == 'd') { // Element is a dictionary $this->Val[$Key] = new BENCODE_DICT(substr($this->Str, $this->Pos)); $this->Pos += $this->Val[$Key]->Pos; } else { die('Invalid torrent file'); } }
function goodinput($string) { if(is_number($string)) { $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="cryptum1_comments"; // Database name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $q = "SELECT * FROM homepage WHERE postid = ".$string; $resultb = mysql_query($q); if ($resultb) { return true; } if (!$resultb) { return false; } } else { return false; } }
function create_instance() { // Include module lib $modlib = '../../mod/' . $this->module_name() . '/lib.php'; if (file_exists($modlib)) { global $CFG; require_once $modlib; } else { return array(false, 'Module lib not found'); } $ret = $this->set_module_instance_params(); if (!$ret[0]) { return $ret; } // Add instance and update course_modules DB row $addinstancefunction = $this->module_name() . '_add_instance'; if ($this->get_num_instance_function_params() == 1) { $returnfromfunc = $addinstancefunction($this->moduleobj); } else { $returnfromfunc = $addinstancefunction($this->moduleobj, true); } if (!$returnfromfunc or !is_number($returnfromfunc)) { // undo everything we can $modcontext = context_module::instance($this->moduleobj->coursemodule); $modcontext->delete(); $DB->delete_records('course_modules', array('id' => $this->moduleobj->coursemodule)); if (!is_number($returnfromfunc)) { return array(false, "{$addinstancefunction} is not a valid function"); } else { return array(false, 'Cannot add new module'); } } $this->moduleobj->instance = $returnfromfunc; return array(true, ''); }
public function makeAccount($Username, $Password, $Email, $SendEmail = true, $Enabled = 1, $Quiet = false) { global $DB; if ($this->accountNameInUse($Username) || $this->accountEmailInUse($Email)) { return -3; } // Create the account $Secret = make_secret(); $TS = md5(time() . $Secret . time()); $DB->query("INSERT INTO users (Username, Password, Email, Enabled, Secret, AuthKey, JoinDate) VALUES('%s', '%s', '%s', %d, '%s', '%s')", db_string($Username), db_string(make_hash($Password, $Secret)), db_string($Email), db_string($Enabled), db_string($Secret), db_string($TS), sqltime()); $UserID = $DB->inserted_id(); if ($SendEmail == true) { $EmailTemplate = file_get_contents(SERVER_ROOT . '/res/confirm_account.tpl'); $EmailTemplate = str_replace('%Username%', $Username, $EmailTemplate); $EmailTemplate = str_replace('%AuthKey%', $TS, $EmailTemplate); $Subject = 'Redstone Mods Account Confirmation'; $Headers = 'From: "PTPIMG Mailer" <*****@*****.**>' . PHP_EOL . 'X-Mailer: PHP/' . phpversion() . PHP_EOL; if (mail($Email, $Subject, $EmailTemplate, $Headers)) { if (!$Quiet) { echo "Account created! Please check your email to confirm your account. You will not be able to login until you have confirmed your email address."; } } else { if (!$Quiet) { die("Unknown error, contact admins for additional help."); } else { die; } } } if (is_number($UserID)) { return $UserID; } else { return -1; } }
function check_error() { global $database; if ($_GET['id'] == NULL || !is_number($_GET['id']) || $database->clear_param()->select(array('*'), 'book')->where(array('id' => array('=', $_GET['id'])))->num_rows() == 0) { $this->error = 1; } }
function validateValue($value) { if ($this->mandatory && empty($value)) { return 'Mandatory!'; } if ($this->input_regexp && !preg_match('#' . $this->input_regexp . '#', $value)) { return 'Invalid format. Must be: ' . $this->input_regexp; } $options = $this->parseOptions($this->input_format); switch ($this->field_type) { case 'multistring': if (isset($options['options'])) { $selected = array_intersect($options['options'], (array) $value); if ($this->mandatory && !$selected) { return 'Mandatory!'; } else { if (isset($options['min']) && (int) $options['min'][0] > count($selected)) { return 'Too few options selected'; } else { if (isset($options['max']) && (int) $options['max'][0] < count($selected)) { return 'Too many options selected'; } } } } break; case 'integer': if ((string) (int) $value !== (string) $value) { return 'Invalid number'; } break; case 'float': if (!is_number($value)) { return 'Invalid number'; } break; case 'date': if (!preg_match('#^\\d\\d\\d\\d\\-\\d\\d?\\-\\d\\d?$#', $value)) { return 'Invalid date'; } break; case 'time': if (!preg_match('#^\\d\\d?:\\d\\d?(?::\\d\\d?)?$#', $value)) { return 'Invalid time'; } break; case 'dateandtime': if (!preg_match('#^\\d\\d\\d\\d\\-\\d\\d?\\-\\d\\d? \\d\\d?:\\d\\d?(?::\\d\\d?)?$#', $value)) { return 'Invalid date+time'; } break; case 'reference': if (!$this->getDbObject()->count('nodes', 'id = ' . (int) $value . ' AND node_type_id IN (' . implode(',', $options['node_types']) . ')')) { return 'Invalid reference (' . (int) $value . ' not found)'; } break; } return true; }
function handle_p() { if (isset($_GET['p']) && is_number($_GET['p']) && +$_GET['p'] > 0 && +$_GET['p'] <= $this->page) { $this->p = +$_GET['p']; } else { $this->p = 1; } }
public function getRowById($id) { if (!is_number($id)) { return false; } $select = $this->select(); $select->where('id = ?', (int) $id); return $this->fetchRow($select); }
public function __construct($data, $language = null) { if (is_number($data)) { $this->id = $data; $db = \TMDB\Client::getInstance(); $data = $this->l1st($language); } parent::__construct($data); }
/** * Search by input value */ public function sql() { global $DB; $preference = $this->preferences_get($this->name); if (!empty($preference) or is_number($preference)) { return array($DB->sql_like($this->field, '?', false, false), "%{$preference}%"); } return false; }
public function testIsNumberFalse() { // arrange $array = array(null, "three", "27"); // act // assert foreach ($array as $value) { $this->assertFalse(is_number($value), 'Expected value to not be identified as a number.'); } }
public function validation($data, $files) { global $CFG; $cost = $data['cost']; $errors = array(); if (!is_number($cost)) { $errors['cost'] = get_string('numericplease', 'mod_emarking'); return $errors; return $errors; } }
/** * Set the ID to null or to a positive whole number * * @throws coding_exception * @param int|null $id * @return mr_model_record_abstract */ public function set_id($id) { if (!is_number($id) and !is_null($id)) { throw new coding_exception('ID must be a number or NULL'); } if (!is_null($id) and $id < 1) { throw new coding_exception('ID must be a positive, non-zero number'); } $this->id = $id; return $this; }
public function filterBycountry($country) { if (is_object($country)) { $id = $country->getId(); } elseif (is_number($country)) { $id = $country; } else { return null; } return $this->leftJoin($this->getRootAlias() . '.District d')->leftJoin('d.Zone z')->andWhere('z.country_id = ?', $id); }
public function validation($data, $files) { $errors = array(); if (!is_number($data['cost'])) { $errors['cost'] = get_string('numericplease', 'mod_emarking'); } if (!is_number($data['costcenter'])) { $errors['costcenter'] = get_string('numericplease', 'mod_emarking'); } return $errors; }
function xmldb_enrol_imsenterprise_upgrade($oldversion) { global $CFG, $DB, $OUTPUT; $dbman = $DB->get_manager(); //NOTE: this file is not executed during upgrade from 1.9.x! if ($oldversion < 2011013000) { // this plugin does not use the new file api - lets undo the migration $fs = get_file_storage(); if ($DB->record_exists('course', array('id' => 1))) { //course 1 is hardcoded here intentionally! if ($context = get_context_instance(CONTEXT_COURSE, 1)) { if ($file = $fs->get_file($context->id, 'course', 'legacy', 0, '/', 'imsenterprise-enrol.xml')) { if (!file_exists("{$CFG->dataroot}/1/imsenterprise-enrol.xml")) { check_dir_exists($CFG->dataroot . '/'); $file->copy_content_to("{$CFG->dataroot}/1/imsenterprise-enrol.xml"); } $file->delete(); } } } if (!empty($CFG->enrol_imsfilelocation)) { if (strpos($CFG->enrol_imsfilelocation, "{$CFG->dataroot}/") === 0) { $location = str_replace("{$CFG->dataroot}/", '', $CFG->enrol_imsfilelocation); $location = str_replace('\\', '/', $location); $parts = explode('/', $location); $courseid = array_shift($parts); if (is_number($courseid) and $DB->record_exists('course', array('id' => $courseid))) { if ($context = get_context_instance(CONTEXT_COURSE, $courseid)) { $file = array_pop($parts); if ($parts) { $dir = '/' . implode('/', $parts) . '/'; } else { $dir = '/'; } if ($file = $fs->get_file($context->id, 'course', 'legacy', 0, $dir, $file)) { if (!file_exists($CFG->enrol_imsfilelocation)) { check_dir_exists($CFG->dataroot . '/' . $courseid . $dir); $file->copy_content_to($CFG->enrol_imsfilelocation); } $file->delete(); } } } } } upgrade_plugin_savepoint(true, 2011013000, 'enrol', 'imsenterprise'); } // Moodle v2.1.0 release upgrade line // Put any upgrade step following this // Moodle v2.2.0 release upgrade line // Put any upgrade step following this return true; }
/** * Callback to add filters on top of the result set * * @param Form */ function filter_tags(&$Form) { $Form->text_input('tag_filter', get_param('tag_filter'), 24, T_('Tag'), '', array('maxlength' => 50)); $item_ID_filter_note = ''; if ($filter_item_ID = get_param('tag_item_ID')) { // check item_Id filter. It must be a number if (!is_number($filter_item_ID)) { // It is not a number $item_ID_filter_note = T_('Must be a number'); } } $Form->text_input('tag_item_ID', $filter_item_ID, 9, T_('Post ID'), $item_ID_filter_note, array('maxlength' => 9)); }
/** * Logs with an arbitrary level. * * @param mixed $level * @param string $message * @param array $context * @return null */ public function log($level, $message, array $context = array()) { global $DB; $data = ''; foreach ($context as $key => $val) { $data .= $data != '' ? "\n\n" : ''; if (!is_number($key)) { $data .= $key . "\n\n"; } $data .= $val; $data .= "\n" . str_repeat('-', 80); } return $DB->insert_record('collaborate_log', (object) ['time' => time(), 'level' => $level, 'message' => $message, 'data' => $data]); }
/** * Constructor. * * @param \stdClass $structure Data structure from JSON decode * @throws \coding_exception If invalid data structure. */ public function __construct($structure) { // Get cmid. if (isset($structure->cm) && is_number($structure->cm)) { $this->cmid = (int) $structure->cm; } else { throw new \coding_exception('Missing or invalid ->cm for completion condition'); } // Get expected completion. if (isset($structure->e) && in_array($structure->e, array(COMPLETION_COMPLETE, COMPLETION_INCOMPLETE, COMPLETION_COMPLETE_PASS, COMPLETION_COMPLETE_FAIL))) { $this->expectedcompletion = $structure->e; } else { throw new \coding_exception('Missing or invalid ->e for completion condition'); } }
function validation($data, $files) { $errors = array(); $rooms = $data['room']; if (empty($data['room']) || is_null($data['room'])) { $errors['room'] = get_string('enteravalidnumericvalue', 'local_bookingrooms'); } if (!is_number($data['room'])) { $errors['room'] = get_string('enteravalidnumericvalue', 'local_bookingrooms'); } if ($data['room'] < 0) { $errors['room'] = get_string('enteravalidnumericvalue', 'local_bookingrooms'); } return $errors; }
function display_str($Str) { if (empty($Str)) { return ''; } if ($Str != '' && !is_number($Str)) { $Str = make_utf8($Str); $Str = mb_convert_encoding($Str, "HTML-ENTITIES", "UTF-8"); $Str = preg_replace("/&(?![A-Za-z]{0,4}\\w{2,3};|#[0-9]{2,5};)/m", "&", $Str); $Replace = array("'", '"', "<", ">", '€', '‚', 'ƒ', '„', '…', '†', '‡', 'ˆ', '‰', 'Š', '‹', 'Œ', 'Ž', '‘', '’', '“', '”', '•', '–', '—', '˜', '™', 'š', '›', 'œ', 'ž', 'Ÿ'); $With = array(''', '"', '<', '>', '€', '‚', 'ƒ', '„', '…', '†', '‡', 'ˆ', '‰', 'Š', '‹', 'Œ', 'Ž', '‘', '’', '“', '”', '•', '–', '—', '˜', '™', 'š', '›', 'œ', 'ž', 'Ÿ'); $Str = str_replace($Replace, $With, $Str); } return $Str; }
/** * Converts a value to a level value. * * If value is unknown, returns 0. * * @param mixed $value * @return int */ public static function toLevel($value) { $level = 0; switch (true) { case \is_number($value): case \is_numeric($value): $level = (int) $value; break; default: $const = self::class . '::' . \strtoupper($value); if (\defined($const)) { $level = \constant($const); } } return $level; }
function organizer_get_appointment_status($app) { global $DB; if (is_number($app) && $app == intval($app)) { $app = $DB->get_record('organizer_slot_appointmentss', array('id' => $app)); } if (!$app) { return 0; } $slot = $DB->get_record('organizer_slots', array('id' => $app->slotid)); $evaluated = isset($app->attended); $attended = $evaluated && (int) $app->attended === 1; $pending = !$evaluated && $slot->stattime < time(); $reapp = $app->allownewappointments; return $evaluated & $attended << 1 & $pending << 2 & $reapp << 3; }
public static function get_requests($RequestIDs, $Return = true) { $Found = $NotFound = array_fill_keys($RequestIDs, false); // Try to fetch the requests from the cache first. foreach ($RequestIDs as $i => $RequestID) { if (!is_number($RequestID)) { unset($RequestIDs[$i], $Found[$GroupID], $NotFound[$GroupID]); continue; } $Data = G::$Cache->get_value("request_{$RequestID}"); if (!empty($Data)) { unset($NotFound[$RequestID]); $Found[$RequestID] = $Data; } } // Make sure there's something in $RequestIDs, otherwise the SQL will break if (count($RequestIDs) === 0) { return array(); } $IDs = implode(',', array_keys($NotFound)); /* Don't change without ensuring you change everything else that uses get_requests() */ if (count($NotFound) > 0) { $QueryID = G::$DB->get_query_id(); G::$DB->query("\n\t\t\t\tSELECT\n\t\t\t\t\tID,\n\t\t\t\t\tUserID,\n\t\t\t\t\tTimeAdded,\n\t\t\t\t\tLastVote,\n\t\t\t\t\tCategoryID,\n\t\t\t\t\tTitle,\n\t\t\t\t\tYear,\n\t\t\t\t\tImage,\n\t\t\t\t\tDescription,\n\t\t\t\t\tCatalogueNumber,\n\t\t\t\t\tRecordLabel,\n\t\t\t\t\tReleaseType,\n\t\t\t\t\tBitrateList,\n\t\t\t\t\tFormatList,\n\t\t\t\t\tMediaList,\n\t\t\t\t\tLogCue,\n\t\t\t\t\tFillerID,\n\t\t\t\t\tTorrentID,\n\t\t\t\t\tTimeFilled,\n\t\t\t\t\tGroupID,\n\t\t\t\t\tOCLC\n\t\t\t\tFROM requests\n\t\t\t\tWHERE ID IN ({$IDs})\n\t\t\t\tORDER BY ID"); $Requests = G::$DB->to_array(false, MYSQLI_ASSOC, true); $Tags = self::get_tags(G::$DB->collect('ID', false)); foreach ($Requests as $Request) { unset($NotFound[$Request['ID']]); $Request['Tags'] = isset($Tags[$Request['ID']]) ? $Tags[$Request['ID']] : array(); $Found[$Request['ID']] = $Request; G::$Cache->cache_value('request_' . $Request['ID'], $Request, 0); } G::$DB->set_query_id($QueryID); // Orphan requests. There shouldn't ever be any if (count($NotFound) > 0) { foreach (array_keys($NotFound) as $GroupID) { unset($Found[$GroupID]); } } } if ($Return) { // If we're interested in the data, and not just caching it return $Found; } }
public static function update_event($ID, $Title, $Body, $Category, $Importance, $Team, $StartDate, $EndDate = null) { if (!is_number($ID) || empty($Title) || empty($Body) || !is_number($Category) || !is_number($Importance) || !is_number($Team) || empty($StartDate)) { error("Error updating event"); } $ID = (int) $ID; $Title = db_string($Title); $Body = db_string($Body); $Category = (int) $Category; $Importance = (int) $Importance; $Team = (int) $Team; $StartDate = db_string($StartDate); $EndDate = db_string($EndDate); $QueryID = G::$DB->get_query_id(); G::$DB->query("\n\t\t\t\t\t\tUPDATE calendar\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\tTitle = '{$Title}',\n\t\t\t\t\t\t\tBody = '{$Body}',\n\t\t\t\t\t\t\tCategory = '{$Category}',\n\t\t\t\t\t\t\tImportance = '{$Importance}',\n\t\t\t\t\t\t\tTeam = '{$Team}',\n\t\t\t\t\t\t\tStartDate = '{$StartDate}',\n\t\t\t\t\t\t\tEndDate = '{$EndDate}'\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tID = '{$ID}'"); G::$DB->set_query_id($QueryID); }
function xmldb_enrol_imsenterprise_install() { global $CFG, $DB; // NOTE: this file is executed during upgrade from 1.9.x! // this plugin does not use the new file api - lets undo the migration $fs = get_file_storage(); if ($DB->record_exists('course', array('id' => 1))) { //course 1 is hardcoded here intentionally! if ($context = get_context_instance(CONTEXT_COURSE, 1)) { if ($file = $fs->get_file($context->id, 'course', 'legacy', 0, '/', 'imsenterprise-enrol.xml')) { if (!file_exists("{$CFG->dataroot}/1/imsenterprise-enrol.xml")) { check_dir_exists($CFG->dataroot . '/'); $file->copy_content_to("{$CFG->dataroot}/1/imsenterprise-enrol.xml"); } $file->delete(); } } } if (!empty($CFG->enrol_imsfilelocation)) { if (strpos($CFG->enrol_imsfilelocation, "{$CFG->dataroot}/") === 0) { $location = str_replace("{$CFG->dataroot}/", '', $CFG->enrol_imsfilelocation); $location = str_replace('\\', '/', $location); $parts = explode('/', $location); $courseid = array_shift($parts); if (is_number($courseid) and $DB->record_exists('course', array('id' => $courseid))) { if ($context = get_context_instance(CONTEXT_COURSE, $courseid)) { $file = array_pop($parts); if ($parts) { $dir = '/' . implode('/', $parts) . '/'; } else { $dir = '/'; } if ($file = $fs->get_file($context->id, 'course', 'legacy', 0, $dir, $file)) { if (!file_exists($CFG->enrol_imsfilelocation)) { check_dir_exists($CFG->dataroot . '/' . $courseid . $dir); $file->copy_content_to($CFG->enrol_imsfilelocation); } $file->delete(); } } } } } // TODO: migrate old config settings }
/** * Returns list of available display options * @param array $enabled list of options enabled in module configuration * @param int $current current dispaly options for existing instances * @return array of key=>name pairs */ function resourcelib_get_displayoptions(array $enabled, $current = null) { if (is_number($current)) { $enabled[] = $current; } $options = array(RESOURCELIB_DISPLAY_AUTO => get_string('displayauto', 'resource'), RESOURCELIB_DISPLAY_EMBED => get_string('displayembed', 'resource'), RESOURCELIB_DISPLAY_FRAME => get_string('displayframe', 'resource'), RESOURCELIB_DISPLAY_NEW => get_string('displaynew', 'resource'), RESOURCELIB_DISPLAY_DOWNLOAD => get_string('displaydownload', 'resource'), RESOURCELIB_DISPLAY_OPEN => get_string('displayopen', 'resource'), RESOURCELIB_DISPLAY_POPUP => get_string('displaypopup', 'resource')); $result = array(); foreach ($options as $key => $value) { if (in_array($key, $enabled)) { $result[$key] = $value; } } if (empty($result)) { // there should be always something in case admin misconfigures module $result[RESOURCELIB_DISPLAY_OPEN] = $options[RESOURCELIB_DISPLAY_OPEN]; } return $result; }
function normalize_submitted_data($raw_submitted_data) { $ranges = array(); foreach ($raw_submitted_data as $k => $v) { $kparts = explode('_', $k); if ($kparts[0] != 'textgroup' || !is_number($kparts[1])) { if (!is_numeric($k) && $k !== 'finalize' && $k !== 'rowcount') { $ranges[$k] = $v; //to allow for additional information like the national average for prepworks } continue; //numeric keys may overwrite our processed numeric keys, so sorry, you're out of luck } $i = $kparts[1]; $ranges[$i] = array('rowid' => intval($v['rowid']), 'min' => $v['mininput'], 'max' => $v['maxinput'], 'name' => $v['nameinput']); } return $ranges; }
/** * Uses $_POST['sort'] values to update the DB. */ public function mass_update() { $SQL = array(); foreach ($_POST['sort'] as $GroupID => $Sort) { if (is_number($Sort) && is_number($GroupID)) { $SQL[] = sprintf('(%d, %d, %d)', $GroupID, $Sort, G::$LoggedUser['ID']); } } if (!empty($SQL)) { $SQL = sprintf(' INSERT INTO %s (GroupID, Sort, UserID) VALUES %s ON DUPLICATE KEY UPDATE Sort = VALUES (Sort)', $this->Table, implode(', ', $SQL)); $this->query_and_clear_cache($SQL); } }