how to use searchmailbox() to search emails by passing date in the criteria of this method? - yii2

This is my function and in this line of code * $mailIds = $mailbox->searchMailBox(); * i'm facing problem .. i want to search latest email but if i write anything in this method i'm facing the syntax problem or the blank page. please anyone can help me in solving this problem?
public function actionCreate1()
{
$imapConnection = new ImapConnection();
$imapConnection->imapPath = '{imap.gmail.com:993/imap/ssl}INBOX';
$imapConnection->imapLogin = 'example#gmail.com';
$imapConnection->imapPassword = 'password';
$imapConnection->serverEncoding = 'encoding'; // utf-8 default.
$imapConnection->attachmentsDir = '/';
$imapConnection->decodeMimeStr = true;
$mailbox = new Mailbox($imapConnection);
$mailbox->readMailParts = false;
$mailIds = $mailbox->searchMailBox();
foreach($mailIds as $mailId)
{
// Returns Mail contents
$mail = $mailbox->getMail($mailId);
// Read mail parts (plain body, html body and attachments
$mailObject = $mailbox->getMailParts($mail);
// Array with IncomingMail objects
echo '<pre>';
print_r($mailObject);
// Returns mail attachements if any or else empty array
$attachments = $mailObject->getAttachments();
foreach($attachments as $attachment){
echo ' Attachment:' . $attachment->name . PHP_EOL;
// Delete attachment file
unlink($attachment->filePath);
}
}}

Related

MediaWiki - Hook to edit/alter page title on creation

I'm looking to (programmatically) edit/alter the title of a page when its created and before its saved. I've tried a couple hooks to no avail. I can access the title being saved along with other info which ill be used to alter the title, but can not find the right call to save the altered title.
It is for a private/local lan wiki (currently MediaWiki version 1.38.1 ).
When a new article is created with in a certon category I want to number it with a prefix of #### - based on the number of articles already in the category. At the top of the category page itself I have a <inputbox> which pulls a template that has the wiki syntax for the category in it [[Category:BlaBla]]. When the article is saved I'm doing a check to make sure its a new article and some ofther checks for the info I need, which is working fine, but I can not save the new altered page name.
I've tried the following hooks to no avail.
onMultiContentSave
onArticlePrepareTextForEdit
https://www.mediawiki.org/wiki/Manual:Hooks/MultiContentSave
https://www.mediawiki.org/wiki/Manual:Hooks/ArticlePrepareTextForEdit
Heres acouple snippets ive been testing with, both do as i want, aside from saving the altered page name.
public static function onArticlePrepareTextForEdit( WikiPage $wikiPage, ParserOptions $parserOptions ) {
return;
$exists = $wikiPage->exists();
if ($exists == 1) {
#return true;
}
$getTitle = $wikiPage->getTitle();
# check if title starts with 0000, exit if so, no work needs to be done
if (self::titleCheck($getTitle)) {
#return true;
}
$checkCategories = $wikiPage->getCategories();
$inMalak = false;
foreach ($checkCategories as $value) {
if ($value == "Category:Malak") {
$inMalak = true;
}
}
if ($inMalak == 1) {
$newTitle = self::newTitlePre() . $getTitle;
#$wikiPage->setTitle($newTitle);
print(">" . $newTitle . "<br>");
}
self::pr($newTitle);
}
public static function onMultiContentSave(RenderedRevision $renderedRevision, UserIdentity $user, CommentStoreComment $summary, $flags, Status $hookStatus){
#return;
$revision = $renderedRevision->getRevision();
$getTitle = $revision->getPageAsLinkTarget();
if (self::titleCheck($getTitle)) {
return true;
}
#$titleOBJ = $revision->Title();
$title = $revision->getId();
$parent_id = $revision->getId();
$content = $revision->getContent( SlotRecord::MAIN );
$new_content = $content->getText();
#$test = $revision->ParserOutput();
$parent_id = "";
if ($parent_id == "") {
$pos = strpos($new_content, "[[Category:Malak]]");
if ($pos) {
$newTitle = self::newTitlePre() . $getTitle;
#$wikiPage->setTitle($newTitle);
}
}
self::pr($newTitle);
}
EDIT........
Still have not found the proper way to do this, but came up with a work around (hackery) which works for my needs.
Using the onEditFormPreloadText hook, change the url and added a new parameter ('MalakHere'), edited the 'title' parameter to the altered title, then do a redirect with the new page name. In the hook function there is a check for the 'MalakHere' parameter, if found (only cause of redirect) then it will exit the function so not to create a loop.
public static function onEditFormPreloadText(string &$text, Title &$title ) {
global $wgOut;
if ( isset( $_GET["MalakHere"] ) ) {
return true;
}
$pos = strpos($text, "[[Category:Malak]]");
if ($pos) {
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$urlTitle = urlencode($_GET["title"]);
$newURL = str_replace("title=" . $urlTitle,"MalakHere=yes",$url);
$newTitle = self::newTitlePre() . $title->prefixedText;
$url = $newURL . "&title=" . $newTitle;
return $wgOut->redirect($url);
}
return true;
}
Still have not found the proper way to do this, but came up with a work around (hackery) which works for my needs.
Using the onEditFormPreloadText hook, change the url and added a new parameter ('MalakHere'), edited the 'title' parameter to the altered title, then do a redirect with the new page name. In the hook function there is a check for the 'MalakHere' parameter, if found (only cause of redirect) then it will exit the function so not to create a loop.
public static function onEditFormPreloadText(string &$text, Title &$title ) {
global $wgOut;
if ( isset( $_GET["MalakHere"] ) ) {
return true;
}
$pos = strpos($text, "[[Category:Malak]]");
if ($pos) {
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$urlTitle = urlencode($_GET["title"]);
$newURL = str_replace("title=" . $urlTitle,"MalakHere=yes",$url);
$newTitle = self::newTitlePre() . $title->prefixedText;
$url = $newURL . "&title=" . $newTitle;
return $wgOut->redirect($url);
}
return true;
}

List of files from my google drive

I am writing PHP script which get files from my Google Drive folder and write list of them with download links on my website, but can not find solution which take files from my folder. Every solution I found need sign up from user, that is viewing page and get list of files from his google drive. Can anyone help me with solution?
Here is my code.
function printFilesInFolder($service, $folderId) {
$pageToken = NULL;
do {
try {
$parameters = array();
$parameters = array(
'q' => "'0B5NCdsbrL1VfQ00xY3pFS3BtOE0' in parents"
);
$children = $service->files->listFiles($parameters);
var_dump($children);
foreach ($children->getFiles() as $child) {
print 'File Id: ' . $child->getId();
}
$pageToken = $children->getNextPageToken();
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
$pageToken = NULL;
}
} while ($pageToken);
}
$client = new Google_Client();
$client->setApplicationName("Web client 1");
$client->setClientId('CLIENTID');
$client->setClientSecret('SECRET');
$client->setScopes(array('https://www.googleapis.com/auth/drive.file'));
$client->setRedirectUri('http://localhost/googledrive/drive/drive.php');
if (isset($_GET['code']) || (isset($_SESSION['access_token']) && $_SESSION['access_token'])) {
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
} else
$client->setAccessToken($_SESSION['access_token']);
$service = new Google_Service_Drive($client);
$ret = printFilesInFolder($service,"FOLDERID");
} else {
$authUrl = $client->createAuthUrl();
header('Location: ' . $authUrl);
exit();
}
But i still dont getting right data.
Second think is, that i want to remove need of authentication on every refresh of page, but i dont know how to do that.

SQL can't found any values

i'm having trouble returning values of sql rows, my SQL request work well on console but can't return a row of it with my code, any help ? thanks !
<?php
require_once 'sql.php';
$sqlConnexion = new mysqli($hn,$un,$pw,$db);
if($sqlConnexion->connect_error){
die ('Soucis de connexion SQL');}
$date = date("d/m/y G:i:s");
if(isset($_POST['zoneDeText'])){
$area = $_POST['zoneDeText'];
$queryone= "SELECT SortieTraitée FROM entry WHERE entréesUtilisateurs=?";
$instruction = $sqlConnexion->prepare($queryone);
if(!$instruction->prepare($queryone)){
echo "$instruction->errno";
}else{
$instruction->bind_param('s', $area);
$instruction->execute();
$result = $instruction->get_result();
while ($row = $result->fetch_array(MYSQLI_NUM)){
foreach ($row as $out){
if($out == $area){
echo $out;
}elseif($out != $area){
echo 'Still not found';
}
}
}
$instruction->close();
}
?>
You don't actually print anything, you just return the value, which makes no sense unless your code is inside a function.
if($out == $area){
return $out;
}
The documentation http://php.net/return says:
If return is called from within the main script file, then script execution ends.
Unless the code you show above has been included in another PHP script, that means it will just end the script and output nothing.
There are several other confusing things your script, but the above is probably the one directly responsible for the problem you're asking about.
Here's how I might write this code:
if (isset($_POST['zoneDeText'])) {
$area = $_POST['zoneDeText'];
$queryone = "SELECT SortieTraitée FROM entry WHERE entréesUtilisateurs=?";
$instruction = $sqlConnexion->prepare($queryone);
// if the prepare fails, it is false
if ($instruction === false) {
// false is not an object, it has no error attribute
// the error is an attribute of the connection
die($sqlConnexion->error);
}
$instruction->bind_param('s', $area);
$instruction->execute();
$result = $instruction->get_result();
// if there are zero rows in the result, the while loop
// will finish before it starts, so there will be no output
// so first check for a result of zero rows in the result
if ($result->num_rows == 0) {
echo("Found zero rows");
} else {
while ($row = $result->fetch_assoc()) {
echo $row["SortieTraitée"];
}
}
$instruction->close();
}

google drive api dont know where it saves the file but when fetched it shows the saved but not the others

I used the google drive api to insert a text file...
Build Service
function buildService() {
$DRIVE_SCOPE = 'https://www.googleapis.com/auth/drive';
$SERVICE_ACCOUNT_EMAIL = 'xxxx#developer.gserviceaccount.com';
if($_SERVER['HTTP_HOST'] == 'localhost')
$SERVICE_ACCOUNT_PKCS12_FILE_PATH = 'xxxxxxxx-privatekey.p12';
else
$SERVICE_ACCOUNT_PKCS12_FILE_PATH = $_SERVER['DOCUMENT_ROOT'].'/xxxxx-privatekey.p12';
$key = file_get_contents($SERVICE_ACCOUNT_PKCS12_FILE_PATH);
$auth = new Google_AssertionCredentials(
$SERVICE_ACCOUNT_EMAIL,
array($DRIVE_SCOPE),
$key);
$client = new Google_Client();
$client->setUseObjects(true);
$client->setAssertionCredentials($auth);
return new Google_DriveService($client);
}
Retrieve Files
function retrieveAllFiles($service) {
$result = array();
$pageToken = NULL;
do {
try {
$parameters = array();
if ($pageToken) {
$parameters['pageToken'] = $pageToken;
}
$files = $service->files->listFiles($parameters);
$result = array_merge($result, $files->getItems());
$pageToken = $files->getNextPageToken();
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
$pageToken = NULL;
}
} while ($pageToken);
return $result;
}
Creating an instance and inserting
$service = buildService();
$file = new Google_DriveFile();
$file->setTitle('My document');
$file->setDescription('A test document');
$file->setMimeType('text/plain');
$data = "contents";
$createdFile = $service->files->insert($file, array('data' => $data,'mimeType' =>'text/plain',));
print_r($createdFile);
echo '<br>------<br>';
Retrieving files
$ret = retrieveAllFiles($service);
echo '<pre>';
print_r($ret);
As in the fist call i insert a file...
in the second call i am trying to list all files...
when i try to list i could see only the inserted file but not the others which i could see in my drive by logging into docs.google.com. i am already having 6 files online
as per the documentation i created service account with the private keys and the service account email.
so where will that file be store and how do i list all other files in the root of google drive?
You are inserting files in the application-owned account represented by the service account.
If you want to manage (insert/list/...) files in another domain user's Drive account, you'll have to perform Domain-wide delegation: https://developers.google.com/drive/delegation

Connecting with a mysql

We are trying to interface between a MySQL database and Google API using ajax and php (on line 3 "phpsqlajax_dbinfo.php" dedfines the database info). We want to create a marker with the lat/long from Google API, but we get the fatal error on "add(Child)"
Actual error message : "Call to a member function addChild() on a non-object"
How can we get the db to register and store the info?
<?php
require_once("phpsqlajax_dbinfo.php");
$xml = ("mapPointInfo.xml") ;
$newLatLng = $_POST['latlng']; //new markers LatLng
$newLatLng = substr($newLatLng, 1, -1); //removes first and last characters of
newLatLng which are ( and )
list($newLat, $newLng) = explode(",", $newLatLng);
//$newLng = substr($newLng, 1, 0);
$locName = $_POST['geoNameMarker']; //geocoded or simple incremented site name
$markerComment = $_POST['createMarker']; //comment entered by user
$userName = $_POST['user']; //acquire username from session
$voteValue = "likes"; //acquire vote value if any
date_default_timezone_set('America/New_York');
$timeStamp = date("m/d/Y G:i"); //get timestamp
year:month:date:hour:minutes:seconds (example: 11:6:31:14:31:42)
if($markerComment == null || $markerComment == '' || $markerComment == ' '){
$markerComment = ' ';
}
$markerComment = htmlentities($markerComment, ENT_QUOTES);
$locName = htmlentities($locName, ENT_QUOTES);
$marker = $xml->addChild('marker');
$marker->addAttribute('lat', $newLat);
$marker->addAttribute('lng', $newLng);
$marker->addAttribute('name', $locName);
$marker->addAttribute('type', 'user-sug');
$comment = $marker->addChild('comment', $markerComment); //add information to
latest/last marker
$comment->addAttribute('user', $userName);
$comment->addAttribute('vote', 'likes');
$comment->addAttribute('time', $timeStamp);
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
header ('http://www.wmuhotspotmap.org/');
exit();
?>
The fatal error? You get a fatal error. What was it? I'm guessing it has something to do with the fact that $xml is a string, but you're for some reason doing $xml->addChild() as if it were an object with functions.