public function get_contacts_through_file($userId, $fileLocation, $format, $return = 'list', $existingEmails = array()) { #Save user contact in local variable $this->userId = $userId; $this->existingContacts = $existingEmails; #Get contents only if the file exists if (!empty($fileLocation)) { #Save file contents into a local variable without saving the file in another location $this->filecontent = remove_quotes(preg_replace("/[\r]/", "", file_get_contents($fileLocation))); $this->fileLocation = $fileLocation; } #Save format in local variable $this->format = $format; #Parse contacts $this->get_contacts_from_file(); #Check and remove duplicate email ids $this->check_dup_emailids(); #Return Contacts data to caller for displaying to user to select if ($this->filecontent == "" && count($this->data) == 0) { return array("result" => FALSE, "message" => "No Data found in Input"); } else { if ($this->filecontent != "" && count($this->data) == 0) { return array("result" => FALSE, "message" => "Invalid data"); } else { if ($return == 'array') { return $this->get_email_array(); } else { return array("result" => TRUE, "message" => "", "data" => $this->data); } } } }
} //load our stuff require_once "config.php"; require_once "app/views/helper.php"; require_once "app/base.php"; date_default_timezone_set("UTC"); #overridden later if user specify his try { Zend_Session::start(); ini_set('error_log', config()->error_logfile); ini_set('display_errors', 0); ini_set('log_errors', 1); ini_set('display_startup_errors', 1); ini_set('default_charset', 'UTF-8'); ini_set('default_socket_timeout', 120); remove_quotes(); fix_eol(); setup_logs(); greet(); cert_authenticate(); /* if(!date_default_timezone_set(user()->getTimeZone())) { addMessage("Your timezone '".user()->getTimeZone()."' is not valid. Please try using location based timezone such as 'America/Chicago'. Reverting to UTC."); } */ error_reporting(E_ALL | E_STRICT); } catch (exception $e) { /* //when a catastrohpic failure occure (like disk goes read-only..) emailing is the only way we got.. if(!config()->debug) { mail(config()->elog_email_address, "[gocticket] Caught exception during bootstrap", $e, "From: ".config()->email_from);
function executeSelectQuery(&$sqlQuery) { global $g_sqlGroupingFuncs; global $g_sqlSingleRecFuncs; $resultSets = array(); // create a copy $aliases = $sqlQuery->colAliases; $funcs = $sqlQuery->colFuncs; // Read all Tables for ($i = 0; $i < count($sqlQuery->tables); ++$i) { debug_printb("<br>[executeSelectQuery] Reading table " . $sqlQuery->tables[$i] . "<br>"); if (!($resultSets[$i] = $this->readTable($sqlQuery->tables[$i]))) { print_error_msg("Reading Table " . $sqlQuery->tables[$i] . " failed"); return false; } $resultSets[$i]->setColumnTableForAll($sqlQuery->tables[$i]); $resultSets[$i]->setColumnTableAliasForAll($sqlQuery->tableAliases[$i]); // set all functions to the ResultSet of the current table // if table and column name matches debug_printb("[executeSelectQuery] Setting functions for the current table:<br>"); for ($j = 0; $j < count($funcs); ++$j) { if (!$funcs[$j] || !$sqlQuery->colNames[$j]) { continue; } if ($sqlQuery->colTables[$j] == $sqlQuery->tables[$i] || $sqlQuery->colTables[$j] == $sqlQuery->tableAliases[$i]) { $colNr = $resultSets[$i]->findColNrByAttrs($sqlQuery->colNames[$j], $sqlQuery->colTables[$j], ""); if ($colNr == NOT_FOUND) { continue; } // create a new column for each function $resultSets[$i]->addColumn($sqlQuery->colNames[$j], $sqlQuery->colAliases[$j], $sqlQuery->colTables[$j], "", "str", "", $funcs[$j], "", true); $funcs[$j] = ""; } } // set all aliases where table, column name and function matches debug_printb("[executeSelectQuery] Setting aliases for the current table:<br>"); for ($j = 0; $j < count($aliases); ++$j) { if (!$aliases[$j]) { continue; } if ($sqlQuery->colTables[$j] == $sqlQuery->tables[$i] || $sqlQuery->colTables[$j] == $sqlQuery->tableAliases[$i]) { if (($colNr = $resultSets[$i]->findColNrByAttrs($sqlQuery->colNames[$j], $sqlQuery->colTables[$j], $sqlQuery->colFuncs[$j])) != NOT_FOUND) { $resultSets[$i]->setColumnAlias($colNr, $aliases[$j]); $aliases[$j] = ""; } } } if (TXTDBAPI_DEBUG) { debug_printb("<br>[executeSelectQuery] Dump of Table {$i} (" . $sqlQuery->tables[$i] . "):<br>"); $resultSets[$i]->dump(); } } // set remaining functions to the ResultSet where column name matches debug_printb("[executeSelectQuery] Setting remaining functions where column name matches:<br>"); for ($i = 0; $i < count($resultSets); ++$i) { for ($j = 0; $j < count($funcs); ++$j) { if (!$funcs[$j] || !$sqlQuery->colNames[$j]) { continue; } $colNr = $resultSets[$i]->findColNrByAttrs($sqlQuery->colNames[$j], "", ""); if ($colNr == NOT_FOUND) { // 'text' or 123 ? => add column if (!(is_numeric($sqlQuery->colNames[$j]) || has_quotes($sqlQuery->colNames[$j]))) { continue; } debug_print("Adding function with quoted string or number paremeter!<br>"); } // create a new column for each function $resultSets[$i]->addColumn($sqlQuery->colNames[$j], $sqlQuery->colAliases[$j], $sqlQuery->colTables[$j], "", "str", "", $funcs[$j], "", true); $funcs[$j] = ""; } } // set remaining aliases where column name and function matches debug_printb("[executeSelectQuery] Setting remaining aliases where column name and function matches:<br>"); for ($i = 0; $i < count($resultSets); ++$i) { for ($j = 0; $j < count($aliases); ++$j) { if (!$aliases[$j]) { continue; } if (($colNr = $resultSets[$i]->findColNrByAttrs($sqlQuery->colNames[$j], "", $sqlQuery->colFuncs[$j])) != NOT_FOUND) { $resultSets[$i]->setColumnAlias($colNr, $aliases[$j]); $aliases[$j] = ""; } } } debug_printb("[executeSelectQuery] Executing single-rec functions (on the separate ResultSet's):<br>"); // execute single-rec functions (on the separate ResultSet's) for ($i = 0; $i < count($resultSets); ++$i) { $resultSets[$i]->executeSingleRecFuncs(); } // A query without tables ? => make a dummy ResultSet $dummyResultSet = false; if (count($sqlQuery->tables) == 0) { $dummyResultSet = true; $rsMaster = new ResultSet(); $rsMaster->addColumn("(dummy)", "(dummy)", "(dummy)", "(dummy)", "str", "(dummy)", "", "", true); $rsMaster->append(); // else: real ResultSet } else { $dummyResultSet = false; // join the ResultSet's $rsMaster = $resultSets[0]; for ($i = 1; $i < count($resultSets); ++$i) { $rsMaster = $rsMaster->joinWithResultSet($resultSets[$i]); } } // from here we only work with $rsMaster and can free the other ResultSet's unset($resultSets); $resultSets = ""; // generate additional columns for the remaining functions (functions without params) for ($i = 0; $i < count($funcs); ++$i) { if ($funcs[$i]) { $rsMaster->addColumn($sqlQuery->colNames[$i], $sqlQuery->colAliases[$i], "", "", "str", "", $funcs[$i], execFunc($funcs[$i], "")); } } // generate additional columns from the WHERE-expression $rsMaster->generateAdditionalColumnsFromWhereExpr($sqlQuery->where_expr); // generate additional columns from ORDER BY $rsMaster->generateAdditionalColumnsFromArray($sqlQuery->orderColumns); // generate additional columns from GROUP BY $rsMaster->generateAdditionalColumnsFromArray($sqlQuery->groupColumns); // execute the new single-rec functions (on the Master ResultSet) $rsMaster->executeSingleRecFuncs(); // set row id's $rsMaster->reset(); $rId = -1; while (++$rsMaster->pos < count($rsMaster->rows)) { $rsMaster->rows[$rsMaster->pos]->id = ++$rId; } --$rsMaster->pos; debug_printb("<br>[executeSelectQuery] Master ResultSet:</b><br>"); if (TXTDBAPI_DEBUG) { $rsMaster->dump(); } // apply WHERE expression if ($sqlQuery->where_expr) { $ep = new ExpressionParser(); $rsMaster = $ep->getFilteredResultSet($rsMaster, $sqlQuery); } // free $ep unset($ep); $ep = ""; // stop if the WHERE expression failed if (txtdbapi_error_occurred()) { return false; } // check if we can use some optimization // (use the limit in group by, but only if there are no grouping function // in the groupRows. To be able to do this we must order before grouping) $optimizedPath = true; if (!$sqlQuery->limit || !$sqlQuery->orderColumns) { $optimizedPath = false; } else { for ($i = 0; $i < count($sqlQuery->colFuncs); ++$i) { if (in_array($sqlQuery->colFuncs[$i], $g_sqlGroupingFuncs)) { $optimizedPath = false; break; } } } if ($optimizedPath) { debug_printb("[executeSelectQuery] Using optimized path!<br>"); } else { debug_printb("[executeSelectQuery] Using normal path!<br>"); } // Order ResultSet (if optimizedPath) if ($optimizedPath) { debug_printb("[executeSelectQuery] Calling orderRows() (optimized path)..<br>"); if (count($sqlQuery->orderColumns) > 0) { $rsMaster->orderRows($sqlQuery->orderColumns, $sqlQuery->orderTypes); } } // Group ResultSet (process GROUP BY) $numGroupingFuncs = 0; for ($i = 0; $i < count($sqlQuery->colFuncs); ++$i) { if ($sqlQuery->colFuncs[$i] && in_array($sqlQuery->colFuncs[$i], $g_sqlGroupingFuncs)) { ++$numGroupingFuncs; break; } } if ($numGroupingFuncs > 0 || count($sqlQuery->groupColumns) > 0) { debug_printb("[executeSelectQuery] Calling groupRows()..<br>"); $rsMaster = $rsMaster->groupRows($sqlQuery, $optimizedPath); } // Order ResultSet (if NOT optimizedPath) if (!$optimizedPath) { debug_printb("[executeSelectQuery] Calling orderRows() (normal path)..<br>"); if (count($sqlQuery->orderColumns) > 0) { $rsMaster->orderRows($sqlQuery->orderColumns, $sqlQuery->orderTypes); } } // add direct value columns debug_printb("[executeSelectQuery] Adding direct value columns..<br>"); for ($i = 0; $i < count($sqlQuery->colNames); ++$i) { if ($sqlQuery->colNames[$i] && (is_numeric($sqlQuery->colNames[$i]) || has_quotes($sqlQuery->colNames[$i])) && !$sqlQuery->colTables[$i] && !$sqlQuery->colFuncs[$i] && $rsMaster->findColNrByAttrs($sqlQuery->colNames[$i], "", "") == NOT_FOUND) { $value = $sqlQuery->colNames[$i]; if (has_quotes($value)) { remove_quotes($value); } $rsMaster->addColumn($sqlQuery->colNames[$i], $sqlQuery->colAliases[$i], "", "", "str", "", "", $value, true); } } // return only the requested columns debug_printb("[executeSelectQuery] Removing unwanted columns...<br>"); $rsMaster->filterByColumnNamesInSqlQuery($sqlQuery); // order columns (not their data) debug_printb("[executeSelectQuery] Ordering columns (amog themself)...<br>"); if (!$rsMaster->orderColumnsBySqlQuery($sqlQuery)) { print_error_msg("Ordering the Columns (themself) failed"); return false; } // process DISTINCT if ($sqlQuery->distinct == 1) { $rsMaster = $rsMaster->makeDistinct($sqlQuery->limit); } // Apply Limit $rsMaster->reset(); $rsMaster = $rsMaster->limitResultSet($sqlQuery->limit); verbose_debug_print("<br>Limited ResultSet:<br>"); if (TXTDBAPI_VERBOSE_DEBUG) { $rsMaster->dump(); } $rsMaster->reset(); return $rsMaster; }
function check_for_set_map($line) { global $config; global $red; global $black; global $xpath; global $classNode; if (!preg_match('/^\\s*\\$this\\->fields\\[\'(.*)\'\\]\\->setMap\\(\\s*(.*)\\s*\\);\\s*$/', $line, $matches)) { if (preg_match('/setMap/', $line)) { echo "{$red}Found setMap() but don't know how to deal with it at:{$black}\n\t{$line}\n"; } return false; } $args = array(); $matches[2] = trim($matches[2]); if (!empty($matches[2])) { $args = explode(',', $matches[2]); } if (count($args) > 3) { echo "{$red}Too many arguements at:{$black}\n\t{$line}\n"; } for ($i = 0; $i < count($args); $i++) { if (!remove_quotes($args[$i])) { echo "{$red}Problem removing quotes {$i}:{$black}\n\t{$line}\n"; echo count($args); return false; } } $fieldNode = $xpath->query('./configurationGroup/configurationGroup[@name="' . $matches[1] . '"]', $classNode); if ($fieldNode->length !== 1) { echo "{$red}Cannot deteremine the node for the field " . $matches[1] . "for:{$black}\n\t{$line}\n"; echo "\tFound " . $fieldNode->length . " nodes\n"; return false; } $fieldNode = $fieldNode->item(0); $node = createConfigGroup('setMap', 'Configuration on mapping the field values'); $fieldNode->appendChild($node); $valNode = createConfig('useMap', 'Whether or not to use a map', 'true', null, 'boolean'); $node->appendChild($valNode); if (count($args) >= 1) { $valNode = createConfig('form', 'The form to use', $args[0]); $node->appendChild($valNode); } if (count($args) >= 2) { $valNode = createConfig('lookup_func', 'The function to lookup values with', $args[1]); $node->appendChild($valNode); } if (count($args) == 3) { $valNode = createConfig('list_func', 'The function to list values with', $args[2]); $node->appendChild($valNode); } return true; }
function executeSingleRecFuncs() { global $g_sqlSingleRecFuncs; global $g_sqlMathOps; debug_printb("[executeSingleRecFuncs] executing singlerec functions...<br>"); for ($i = 0; $i < count($this->colFuncs); ++$i) { if (!$this->colFuncs[$i] || $this->colFuncsExecuted[$i]) { continue; } if (!in_array($this->colFuncs[$i], $g_sqlSingleRecFuncs)) { continue; } debug_print($this->colFuncs[$i] . "(" . $this->colNames[$i] . "): "); // EVAL if ($this->colFuncs[$i] == "EVAL") { $eval_str = $this->colNames[$i]; $out_str = ""; if (has_quotes($eval_str)) { remove_quotes($eval_str); } debug_print("EVAL function, eval String is {$eval_str}!<br>"); $sp = new StringParser(); $sp->specialElements = $g_sqlMathOps; $sp->setString($eval_str); while (!is_empty_str($elem = $sp->parseNextElement())) { debug_print("ELEM: {$elem}\n"); if (is_numeric($elem) || in_array($elem, $g_sqlMathOps)) { $out_str .= $elem . " "; } else { $origColNr = $this->findColNrByAttrs($elem, "", ""); if ($origColNr == NOT_FOUND) { print_error_msg("EVAL: Column '" . $elem . "' not found!"); return false; } $out_str .= "%{$origColNr}%"; } } debug_print("New Eval String: {$out_str}\n"); $val_str = ""; // apply function (use values from the original column as input) $rowCount = count($this->rows); $colCount = count($this->colNames); for ($j = 0; $j < $rowCount; ++$j) { $val_str = $out_str; for ($k = 0; $k < $colCount; ++$k) { if (!is_false(strpos($val_str, "%{$k}%"))) { $val_str = str_replace("%{$k}%", $this->rows[$j]->fields[$k], $val_str); } } debug_print("VAL_STR={$val_str}\n"); $this->rows[$j]->fields[$i] = execFunc($this->colFuncs[$i], $val_str); } $this->colFuncsExecuted[$i] = true; // function with paramater, but the parameter is not a column } else { if ($this->colNames[$i] && !is_empty_str($this->colNames[$i]) && (is_numeric($this->colNames[$i]) || has_quotes($this->colNames[$i]))) { $param = $this->colNames[$i]; if (has_quotes($param)) { remove_quotes($param); } $result = execFunc($this->colFuncs[$i], $param); $rowCount = count($this->rows); debug_print("a function with a non-column parameter! (result={$result})<br>"); for ($j = 0; $j < $rowCount; ++$j) { $this->rows[$j]->fields[$i] = $result; } $this->colFuncsExecuted[$i] = true; // function with parameter? =>execute function with the values form the original column } else { if ($this->colNames[$i]) { debug_print("a function with a column parameter!<br>"); // find original column (without function) $origColNr = $this->findColNrByAttrs($this->colNames[$i], $this->colTables[$i], ""); if ($origColNr == NOT_FOUND) { print_error_msg("Column '" . $this->colNames[$i] . "' not found!"); return false; } // copy some column header data from the original $this->colTables[$i] = $this->colTables[$origColNr]; $this->colTableAliases[$i] = $this->colTableAliases[$origColNr]; // apply function (use values from the original column as input) $rowCount = count($this->rows); for ($j = 0; $j < $rowCount; ++$j) { $this->rows[$j]->fields[$i] = execFunc($this->colFuncs[$i], $this->rows[$j]->fields[$origColNr]); } $this->colFuncsExecuted[$i] = true; // function without parameter: just execute! } else { debug_print("a function with no parameters!<br>"); $result = execFunc($this->colFuncs[$i], ""); $rowCount = count($this->rows); for ($j = 0; $j < $rowCount; ++$j) { $this->rows[$j]->fields[$i] = $result; } $this->colFuncsExecuted[$i] = true; } } } } }
function parseCreateTableQuery() { $colNames = array(); $colTypes = array(); $colDefaultValues = array(); $tables = array(); $tables[0] = $this->parseNextElement(); if ($this->parseNextElement() != "(") { print_error_msg("( expected"); return null; } $index = 0; $arrElements = array(); while ($this->parseNextElements(",", array(";"), $arrElements)) { $colNames[] = $arrElements[0]; $colTypes[] = $arrElements[1]; if (count($arrElements) > 3 && strtoupper($arrElements[2]) == "DEFAULT") { if (has_quotes($arrElements[3])) { remove_quotes($arrElements[3]); } $colDefaultValues[] = $arrElements[3]; } else { $colDefaultValues[] = ""; } } $sqlObj = new SqlQuery(); $sqlObj->type = "CREATE TABLE"; $sqlObj->colNames = $colNames; $sqlObj->colTypes = $colTypes; $sqlObj->fieldValues = $colDefaultValues; $sqlObj->tables = $tables; return $sqlObj; }
if (!isset($_POST['template'])) { header('Location: install.php'); exit; } $data = array('template' => "'" . $_POST['template'] . "'", 'phptype' => "'" . $_POST['phptype'] . "'", 'hostspec' => "'" . $_POST['hostspec'] . "'", 'port' => "''", 'socket' => "''", 'database' => "'" . $_POST['database'] . "'", 'username' => "'" . $_POST['username'] . "'", 'password' => "'" . $_POST['password'] . "'", 'db_table_prefix' => "'" . $_POST['db_table_prefix'] . "'", 'site_short_title' => "'" . $_POST['site_short_title'] . "'", 'site_long_title' => "'" . $_POST['site_long_title'] . "'", 'prefix_short_title' => $_POST['prefix_short_title'] == 'on' ? 1 : 0, 'rss_url' => "'" . preg_replace('/\\/$/', '', $_POST['rss_url']) . "'", 'rss_title' => "'" . $_POST['rss_title'] . "'", 'rss_desc' => "'" . $_POST['rss_desc'] . "'", 'rss_entries' => !isset($_POST['rss_entries']) || $_POST['rss_entries'] < 1 ? 15 : $_POST['rss_entries'], 'secret_salt' => "'" . $_POST['secret_salt'] . "'", 'language' => "'" . $_POST['language'] . "'", 'captcha' => "'" . $_POST['captcha'] . "'", 'use_captcha' => "array(" . (isset($_POST['use_captcha']) ? "'" . implode("'=>1, '", $_POST['use_captcha']) . "'=>1" : '') . ")", 'spam_regex' => "'" . $_POST['spam_regex'] . "'", 'auto_block_spam_ip' => $_POST['auto_block_spam_ip'], 'spam_expire_time' => $_POST['spam_expire_time'], 'admin_email' => "'" . $_POST['admin_email'] . "'", 'quote_limit' => $_POST['quote_limit'], 'page_limit' => $_POST['page_limit'], 'quote_list_limit' => $_POST['quote_list_limit'], 'min_latest' => $_POST['min_latest'], 'min_quote_length' => $_POST['min_quote_length'], 'moderated_quotes' => isset($_POST['moderated_quotes']) && $_POST['moderated_quotes'] == 'on' ? 1 : 0, 'login_required' => isset($_POST['login_required']) && $_POST['login_required'] == 'on' ? 1 : 0, 'auto_flagged_quotes' => $_POST['auto_flagged_quotes'] == 'on' ? 0 : 1, 'public_queue' => isset($_POST['public_queue']) && $_POST['public_queue'] == 'on' ? 0 : 1, 'timezone' => "'" . $_POST['timezone'] . "'", 'news_time_format' => "'" . $_POST['news_time_format'] . "'", 'quote_time_format' => "'" . $_POST['quote_time_format'] . "'", 'GET_SEPARATOR' => "ini_get('arg_separator.output')", 'GET_SEPARATOR_HTML' => 'htmlspecialchars($CONFIG[\'GET_SEPARATOR\'], ENT_QUOTES)'); if (!write_settings('settings.php', $data)) { die("Sorry, cannot write settings.php"); } if (!file_exists('settings.php')) { die("settings.php does not exist."); } $salt = str_rand(); $sqldata = array_merge($data, array('QUOTETABLE' => db_tablename('quotes'), 'QUEUETABLE' => db_tablename('queue'), 'USERSTABLE' => db_tablename('users'), 'TRACKINGTABLE' => db_tablename('tracking'), 'NEWSTABLE' => db_tablename('news'), 'SPAMTABLE' => db_tablename('spamlog'), 'DUPETABLE' => db_tablename('dupes'), 'ADMINUSER' => "'" . $_POST['adminuser'] . "'", 'ADMINPASS' => "'\\\$1" . crypt($_POST['adminpass'], "\$1\$" . substr($salt, 0, 8) . "\$") . "'", 'ADMINSALT' => '\'\\$1\\$' . $salt . '\\$\'')); $sql = mangle_sql('install.sql', $sqldata); print '<pre>' . $sql . '</pre>'; $CONFIG = remove_quotes($data); include 'db.php'; $db = get_db($CONFIG); if ($db) { db_query($sql); $db = null; } else { print '<p>Sorry, cannot access the database. You may need to do the commands manually.'; } } else { if (!file_exists('settings.php')) { if (!write_settings('settings.php', null)) { die('Cannot write settings.'); } @unlink('settings.php'); function mk_rss_url()
function array_walk_remove_quotes(&$value, &$key) { if (has_quotes($value)) { remove_quotes($value); } }