本文整理汇总了PHP中Utils类的典型用法代码示例。如果您正苦于以下问题:PHP Utils类的具体用法?PHP Utils怎么用?PHP Utils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Utils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createSettingsFile
public static function createSettingsFile($dbHostname, $dbName, $dbUsername, $dbPassword, $tablePrefix)
{
$encryptionSalt = Utils::generateRandomAlphanumericStr("DDD");
$dbUsername = Utils::sanitize($dbUsername);
$dbPassword = Utils::sanitize($dbPassword);
$tablePrefix = Utils::sanitize($tablePrefix);
$content = <<<END
<?php
\$dbHostname = '{$dbHostname}';
\$dbName = '{$dbName}';
\$dbUsername = '{$dbUsername}';
\$dbPassword = '{$dbPassword}';
\$dbTablePrefix = '{$tablePrefix}';
\$encryptionSalt = '{$encryptionSalt}';
END;
$file = __DIR__ . "/../../settings.php";
$handle = @fopen($file, "w");
if ($handle) {
fwrite($handle, $content);
fclose($handle);
return array(true, "");
}
// no such luck! we couldn't create the file on the server. The user will need to do it manually
return array(false, $content);
}
示例2: signin
public function signin()
{
if ($this->get_request_method() != "POST") {
$this->response('', 406);
}
$email = $this->_request['email'];
$password = $this->_request['pwd'];
$db = new DB();
$ultis = new Utils();
// Input validations
if (!empty($email) and !empty($password)) {
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
$sql = "SELECT _uid, _email FROM users WHERE _email = '{$email}' AND _password = '" . md5($password) . "' LIMIT 1";
$rs = $db->query($sql);
if ($rs->num_rows > 0) {
// If success return authenticated key (sample)
$result = array('access_token' => "633uq4t0qdtd1mdllnv2h1vs32");
$this->response($ultis->json($result), 200);
}
}
}
// If invalid inputs "Bad Request" status message and reason
$error = array('status' => "Failed", "msg" => "Invalid Email address or Password");
$this->response($ultis->json($error), 400);
}
示例3: smarty_function_apretaste_email
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsFunction
*/
function smarty_function_apretaste_email($params, $template)
{
// get a valid apretaste email address
$utils = new Utils();
$validEmailAddress = $utils->getValidEmailAddress();
return $validEmailAddress;
}
示例4: login
public static function login($usu_usuario, $usu_contrasena)
{
$conn = new Connect();
$u = new Utils();
$query = 'SELECT * FROM ' . self::DB_TBL_USUARIO . ' WHERE usu_usuario = :usu_usuario';
$consult = $conn->prepare($query);
$consult->bindParam(':usu_usuario', $usu_usuario);
$consult->execute();
$row = $consult->fetch();
if ($consult->rowCount() > 0) {
$passValidate = $u->passValidate($usu_contrasena, $row['usu_contrasena']);
if ($passValidate == true) {
if ($row['usu_id_rol'] == 1) {
session_start();
$_SESSION['session'] = $row['usu_usuario'];
echo "<script>location.href='../../mod_admin/vista/administrador.php'</script>";
} else {
session_start();
$_SESSION['session'] = $row['usu_usuario'];
echo "<script>location.href='../../mod_admin/vista/tecnico.php'</script>";
}
} else {
echo "<script>alert('Error de autenticación. Por favor verifique sus credenciales de acceso.')</script>";
echo "<script>location.href = '../vista/form_login.php' </script>";
return false;
}
} else {
echo "<script>alert('Error de autenticación.')</script>";
echo "<script>location.href = '../vista/form_login.php' </script>";
return false;
}
}
示例5: execute
public function execute()
{
$utils = new Utils();
$c = new Convertor();
$c->connect($this->config->getServer(), $this->config->getUser(), $this->config->getPassword(), $this->config->getDBName());
//Requesting all the borough
$requestRue = "\n\t\t\t\tSELECT idRue ,nom , prefixe\n\t\t\t\tFROM rue\n\t\t\t\tWHERE nom != ''\n\t\t\t\tGROUP BY idRue\n\t\t\t\tORDER BY idRue\n\t\t\t\t";
$res = $c->execute($requestRue);
$listeQuartier = array();
$ruesByQuartier = array();
$i = 0;
while ($fetch = mysql_fetch_assoc($res)) {
$rue = array();
$rue['prefixe'] = $fetch['prefixe'];
$rue['nom'] = $fetch['nom'];
$request = "\n\t\t\t\t\tSELECT hi.idHistoriqueImage, hi.dateUpload\n\t\t\t\t\tFROM _evenementImage ei\n\t\t\t\t\tLEFT JOIN _evenementEvenement ee on ee.idEvenementAssocie = ei.idEvenement\n\t\t\t\t\tLEFT JOIN _adresseEvenement ae on ae.idEvenement = ee.idEvenement\n\t\t\t\t\tLEFT JOIN historiqueAdresse ha on ha.idAdresse = ae.idAdresse\n\t\t\t\t\tLEFT JOIN historiqueImage hi on hi.idImage = ei.idImage\n\t\t\t\t\tWHERE ha.idRue = " . $fetch['idRue'] . "\n\t\t\t\t\t\t\t";
$resProcess = $c->processRequest($request, 'url');
$j = 0;
$urlImage = array();
foreach ($resProcess as $infoImage) {
$indice = 'url' . $j++;
$urlImage[$indice] = $utils->createArchiWikiPhotoUrl($infoImage['idHistoriqueImage'], $infoImage['dateUpload'], 'http://archi-strasbourg.org', 'grand');
}
$rue['url'] = $urlImage;
$label = 'rue' . $i++;
$ruesByQuartier[$label] = $rue;
}
$c->complexArrayToXML($ruesByQuartier, "xml/urlPhotosRue.xml", 'urlPhotosRue', 'urlPhoto');
$c->complexArrayToCSV($ruesByQuartier, "csv/urlPhotosRue.csv", 'urlPhotosRue', 'urlPhoto');
}
示例6: droppedAction
public function droppedAction()
{
// do not allow empty calls
if (empty($_POST)) {
die("EMPTY CALL");
}
// get the params from post
$email = $_POST['recipient'];
$domain = $_POST['domain'];
$reason = $_POST['reason'];
$code = isset($_POST['code']) ? $_POST['code'] : "";
$desc = isset($_POST['description']) ? str_replace("'", "", $_POST['description']) : "";
// do not save Spam as hardfail
if (stripos($desc, 'spam') !== false) {
$reason = "spam";
}
// mark as bounced if the email is part of the latest campaign
$connection = new Connection();
$campaign = $connection->deepQuery("\n\t\t\tSELECT campaign, email FROM (\n\t\t\t\tSELECT * FROM `campaign_sent`\n\t\t\t\tWHERE campaign = (SELECT id FROM campaign WHERE status='SENT' ORDER BY sending_date DESC LIMIT 1)\n\t\t\t) A WHERE email = '{$email}'");
if (count($campaign) > 0) {
// increase the bounce number for the campaign
$campaign = $campaign[0];
$connection->deepQuery("\n\t\t\t\tUPDATE campaign SET\tbounced=bounced+1 WHERE id={$campaign->campaign};\n\t\t\t\tUPDATE campaign_sent SET status='BOUNCED', date_opened=CURRENT_TIMESTAMP WHERE id={$campaign->campaign} AND email='{$email}'");
// unsubscribe from the list
$utils = new Utils();
$utils->unsubscribeFromEmailList($email);
}
// save into the database
$sql = "INSERT INTO delivery_dropped(email,sender,reason,code,description) VALUES ('{$email}','{$domain}','{$reason}','{$code}','{$desc}')";
$connection->deepQuery($sql);
// echo completion message
echo "FINISHED";
}
示例7: _main
/**
* Function executed when the service is called
*
* @param Request
* @return Response
* */
public function _main(Request $request)
{
// display help for an specific service
if (!empty($request->query)) {
// check if the query passed is a service
$connection = new Connection();
$res = $connection->deepQuery("SELECT * FROM service WHERE name = '{$request->query}'");
if (count($res) > 0) {
$service = $res[0];
// update the valid email on the usage text
$utils = new Utils();
$validEmailAddress = $utils->getValidEmailAddress();
$usage = str_replace('{APRETASTE_EMAIL}', $validEmailAddress, $service->usage_text);
// send variables to the template
$responseContent = array("name" => $service->name, "description" => $service->description, "category" => $service->category, "usage" => nl2br($usage));
// create response for an specific service
$response = new Response();
$response->subject = "Ayuda para el servicio " . ucfirst($service->name);
$response->createFromTemplate("service.tpl", $responseContent);
return $response;
}
}
// create response
$responseContent = array("userEmail" => $request->email);
$response = new Response();
$response->subject = "Ayuda de Apretaste";
$response->createFromTemplate("basic.tpl", $responseContent);
return $response;
}
示例8: deployServiceFromZip
/**
* Extracts and deploys a new service to the service directory
*
* @param String $path, path to the zip file of the service
* @param String $deployKey, hash to avoid unauthorize updating of the service
* @return array, results of the deploy [serviceName, creatorEmail, deployKey]
*/
public function deployServiceFromZip($pathToZip, $deployKey, $zipName)
{
// extract file to the temp folder
$pathToService = $this->extractServiceZip($pathToZip);
$pathToXML = "{$pathToService}/config.xml";
// get the service data from the XML
$service = $this->loadFromXML($pathToXML);
// remove the current project if it exist
$utils = new Utils();
if ($utils->serviceExist($service['serviceName'])) {
// check if the deploy key is valid
if (!$this->checkDeployValidity($service['serviceName'], $deployKey)) {
throw new Exception("Deploy key is invalid");
}
// clean database and files if the service existed before
$this->removeService($service);
}
// create a new deploy key
$utils = new Utils();
$deployKey = $utils->generateRandomHash();
// add the new service
$this->addService($service, $deployKey, $pathToZip, $pathToService);
// remove temp service folder
@system("rmdir " . escapeshellarg($dir) . " /s /q");
// windows version
@system("rm -rfv " . escapeshellarg($pathToService));
// linux version
// return deploy results
return array("serviceName" => $service["serviceName"], "creatorEmail" => $service["creatorEmail"], "deployKey" => $deployKey);
}
示例9: mainAction
public function mainAction()
{
// inicialize supporting classes
$timeStart = time();
$connection = new Connection();
$email = new Email();
$service = new Service();
$service->showAds = true;
$render = new Render();
$response = new Response();
$utils = new Utils();
$wwwroot = $this->di->get('path')['root'];
$log = "";
// people who were invited but never used Apretaste
$invitedPeople = $connection->deepQuery("\n\t\t\tSELECT invitation_time, email_inviter, email_invited\n\t\t\tFROM invitations \n\t\t\tWHERE used=0 \n\t\t\tAND DATEDIFF(CURRENT_DATE, invitation_time) > 15 \n\t\t\tAND email_invited NOT IN (SELECT DISTINCT email from delivery_dropped)\n\t\t\tAND email_invited NOT IN (SELECT DISTINCT email from remarketing)\n\t\t\tORDER BY invitation_time DESC\n\t\t\tLIMIT 450");
// send the first remarketing
$log .= "\nINVITATIONS (" . count($invitedPeople) . ")\n";
foreach ($invitedPeople as $person) {
// check number of days since the invitation was sent
$datediff = time() - strtotime($person->invitation_time);
$daysSinceInvitation = floor($datediff / (60 * 60 * 24));
// validate old invitations to avoid bounces
if ($daysSinceInvitation > 60) {
// re-validate the email
$res = $utils->deepValidateEmail($person->email_invited);
// if response not ok or temporal, delete from invitations list
if ($res[0] != "ok" && $res[0] != "temporal") {
$connection->deepQuery("DELETE FROM invitations WHERE email_invited = '{$person->email_invited}'");
$log .= "\t --skiping {$person->email_invited}\n";
continue;
}
}
// send data to the template
$content = array("date" => $person->invitation_time, "inviter" => $person->email_inviter, "invited" => $person->email_invited, "expires" => strtotime('next month'));
// create html response
$response->createFromTemplate('pendinginvitation.tpl', $content);
$response->internal = true;
$html = $render->renderHTML($service, $response);
// send the invitation email
$subject = "Su amigo {$person->email_inviter} esta esperando por usted!";
$email->sendEmail($person->email_invited, $subject, $html);
// insert into remarketing table
$connection->deepQuery("INSERT INTO remarketing(email, type) VALUES ('{$person->email_invited}', 'INVITE')");
// display notifications
$log .= "\t{$person->email_invited}\n";
}
// get final delay
$timeEnd = time();
$timeDiff = $timeEnd - $timeStart;
// printing log
$log .= "EXECUTION TIME: {$timeDiff} seconds\n\n";
echo $log;
// saving the log
$logger = new \Phalcon\Logger\Adapter\File("{$wwwroot}/logs/remarketing_invitation.log");
$logger->log($log);
$logger->close();
// save the status in the database
$connection->deepQuery("UPDATE task_status SET executed=CURRENT_TIMESTAMP, delay='{$timeDiff}' WHERE task='invitation'");
}
示例10: mainAction
public function mainAction()
{
// inicialize supporting classes
$timeStart = time();
$utils = new Utils();
$connection = new Connection();
$sender = new Email();
// get the first campaign created that is waiting to be sent
$campaign = $connection->deepQuery("\n\t\t\tSELECT id, subject, content\n\t\t\tFROM campaign\n\t\t\tWHERE sending_date < CURRENT_TIMESTAMP\n\t\t\tAND status = 'WAITING'\n\t\t\tGROUP BY sending_date ASC\n\t\t\tLIMIT 1");
// check if there are not campaigns
if (empty($campaign)) {
return;
} else {
$campaign = $campaign[0];
}
// check campaign as SENDING
$connection->deepQuery("UPDATE campaign SET status='SENDING' WHERE id = {$campaign->id}");
// get the list of people in the list who hsa not receive this campaign yet
// so in case the campaign fails when it tries again starts from the same place
$people = $connection->deepQuery("\n\t\t\tSELECT email FROM person\n\t\t\tWHERE mail_list=1 AND active=1\n\t\t\tAND email NOT IN (SELECT email FROM campaign_sent WHERE campaign={$campaign->id})");
// show initial message
$total = count($people);
echo "\nSTARTING COUNT: {$total}\n";
// email people one by one
$counter = 1;
foreach ($people as $person) {
// show message
echo "{$counter}/{$total} - {$person->email}\n";
$counter++;
// replace the template variables
$content = $utils->campaignReplaceTemplateVariables($person->email, $campaign->content, $campaign->id);
// send test email
$sender->trackCampaign = $campaign->id;
$result = $sender->sendEmail($person->email, $campaign->subject, $content);
// add to bounced and unsubscribe if there are issues sending
$bounced = "";
$status = "SENT";
if (!$result) {
$utils->unsubscribeFromEmailList($person->email);
$bounced = "bounced=bounced+1,";
$status = "BOUNCED";
}
// save status before moving to the next email
$connection->deepQuery("\n\t\t\t\tINSERT INTO campaign_sent (email, campaign, status) VALUES ('{$person->email}', '{$campaign->id}', '{$status}');\n\t\t\t\tUPDATE campaign SET {$bounced} sent=sent+1 WHERE id='{$campaign->id}'");
}
// set the campaign as SENT
$connection->deepQuery("UPDATE campaign SET status='SENT' WHERE id='{$campaign->id}'");
// get final delay
$timeEnd = time();
$timeDiff = $timeEnd - $timeStart;
// saving the log
$wwwroot = $this->di->get('path')['root'];
$logger = new \Phalcon\Logger\Adapter\File("{$wwwroot}/logs/campaigns.log");
$logger->log("ID: {$campaign->id}, RUNTIME: {$timeDiff}, SUBJECT: {$campaign->subject}");
$logger->close();
// save the status in the database
$connection->deepQuery("UPDATE task_status SET executed=CURRENT_TIMESTAMP, delay='{$timeDiff}' WHERE task='campaign'");
}
示例11: up
public function up()
{
$this->dbforge->add_field(array('id_program_area' => array('type' => 'INT', 'auto_increment' => true), 'area_name' => array('type' => 'varchar(100)')));
$this->dbforge->add_key('id_program_area', TRUE);
$this->dbforge->create_table('program_area', TRUE);
$addColumn = "ALTER TABLE program ADD id_area INT NULL DEFAULT NULL , ADD INDEX (id_area)";
$this->db->query($addColumn);
$addConstraint = "ALTER TABLE program ADD CONSTRAINT PROGRAM_AREAID_FK FOREIGN KEY (id_area) REFERENCES program_area(id_program_area) ON DELETE RESTRICT ON UPDATE RESTRICT";
$this->db->query($addConstraint);
$populate = new Utils();
$populate->loadAvaliationAreas();
}
示例12: mainAction
public function mainAction()
{
// inicialize supporting classes
$timeStart = time();
$connection = new Connection();
$email = new Email();
$service = new Service();
$service->showAds = true;
$render = new Render();
$response = new Response();
$utils = new Utils();
$wwwroot = $this->di->get('path')['root'];
$log = "";
// people in the list to be automatically invited
$people = $connection->deepQuery("\n\t\t\tSELECT * FROM autoinvitations\n\t\t\tWHERE email NOT IN (SELECT email FROM person)\n\t\t\tAND email NOT IN (SELECT DISTINCT email FROM delivery_dropped)\n\t\t\tAND email NOT IN (SELECT DISTINCT email from remarketing)\n\t\t\tAND error=0\n\t\t\tLIMIT 450");
// send the first remarketing
$log .= "\nAUTOMATIC INVITATIONS (" . count($people) . ")\n";
foreach ($people as $person) {
// if response not ok, check the email as error
$res = $utils->deepValidateEmail($person->email);
if ($res[0] != "ok") {
$connection->deepQuery("UPDATE autoinvitations SET error=1, processed=CURRENT_TIMESTAMP WHERE email='{$person->email}'");
$log .= "\t --skiping {$person->email}\n";
continue;
}
// create html response
$content = array("email" => $person->email);
$response->createFromTemplate('autoinvitation.tpl', $content);
$response->internal = true;
$html = $render->renderHTML($service, $response);
// send invitation email
$subject = "Dos problemas, y una solucion";
$email->sendEmail($person->email, $subject, $html);
// mark as sent
$connection->deepQuery("\n\t\t\t\tSTART TRANSACTION;\n\t\t\t\tDELETE FROM autoinvitations WHERE email='{$person->email}';\n\t\t\t\tINSERT INTO remarketing(email, type) VALUES ('{$person->email}', 'AUTOINVITE');\n\t\t\t\tCOMMIT;");
// display notifications
$log .= "\t{$person->email}\n";
}
// get final delay
$timeEnd = time();
$timeDiff = $timeEnd - $timeStart;
// printing log
$log .= "EXECUTION TIME: {$timeDiff} seconds\n\n";
echo $log;
// saving the log
$logger = new \Phalcon\Logger\Adapter\File("{$wwwroot}/logs/remarketing_autoinvitation.log");
$logger->log($log);
$logger->close();
// save the status in the database
$connection->deepQuery("UPDATE task_status SET executed=CURRENT_TIMESTAMP, delay='{$timeDiff}' WHERE task='autoinvitation'");
}
示例13: processAction
/**
* Process the page when its submitted
*
* @author kuma, salvipascual
* @version 1.0
* */
public function processAction()
{
// get the values from the post
$captcha = trim($this->request->getPost('captcha'));
$name = trim($this->request->getPost('name'));
$inviter = trim($this->request->getPost('email'));
$guest = trim($this->request->getPost('guest'));
if (!isset($_SESSION['phrase'])) {
$_SESSION['phrase'] = uniqid();
}
// throw a die()
// check all values passed are valid
if (strtoupper($captcha) != strtoupper($_SESSION['phrase']) || $name == "" || !filter_var($inviter, FILTER_VALIDATE_EMAIL) || !filter_var($guest, FILTER_VALIDATE_EMAIL)) {
die("Error procesando, por favor valla atras y comience nuevamente.");
}
// params for the response
$this->view->name = $name;
$this->view->email = $inviter;
// create classes needed
$connection = new Connection();
$email = new Email();
$utils = new Utils();
$render = new Render();
// do not invite people who are already using Apretaste
if ($utils->personExist($guest)) {
$this->view->already = true;
return $this->dispatcher->forward(array("controller" => "invitar", "action" => "index"));
}
// send notification to the inviter
$response = new Response();
$response->setResponseSubject("Gracias por darle internet a un Cubano");
$response->setEmailLayout("email_simple.tpl");
$response->createFromTemplate("invitationThankYou.tpl", array('num_notifications' => 0));
$response->internal = true;
$html = $render->renderHTML(new Service(), $response);
$email->sendEmail($inviter, $response->subject, $html);
// send invitations to the guest
$response = new Response();
$response->setResponseSubject("{$name} le ha invitado a revisar internet desde su email");
$responseContent = array("host" => $name, "guest" => $guest, 'num_notifications' => 0);
$response->createFromTemplate("invitation.tpl", $responseContent);
$response->internal = true;
$html = $render->renderHTML(new Service(), $response);
$email->sendEmail($guest, $response->subject, $html);
// save all the invitations into the database at the same time
$connection->deepQuery("INSERT INTO invitations (email_inviter,email_invited,source) VALUES ('{$inviter}','{$guest}','abroad')");
// redirect to the invite page
$this->view->message = true;
return $this->dispatcher->forward(array("controller" => "invitar", "action" => "index"));
}
示例14: fieldControl
public static function fieldControl($field, array $fields, $default = '')
{
if (Utils::in_arrayi($field, $fields)) {
return $field;
}
return $default;
}
示例15: action
public function action()
{
if (!isset($this->parameters->teamInfo)) {
Utils::forDebug($this->parameters, true);
}
return $actionResult = $this->install(isset($this->parameters->teamInfo) ? $this->parameters->teamInfo : NULL);
}