I'm just starting to explore the functionalities of Google Glass.
What I'm trying to do is a simple Glassware that receives a video from the user, when the default 'Share' function is used.
I have seen the Quickstart project guide and I managed to upload my video in the python demo project; I also managed to implement the example PHP project code in my server.
However, I still can't figure out what exactly is happening where i tap the "Share" button on my Glass: where is sent the data? To my Glassware, to the generic Mirror API, or somewhere else? I suppose the Share function is doing something similar to what is described in the media upload page, but it's not clear how.
The code of the demo project seems to update the timeline event when I upload a picture/video; but if I'm not wrong, this code is just updating an already existing item with the "I have received your data!" caption.
(I'll report here the relevant code from the Google's notify.php sample: )
switch ($request['collection']) {
case 'timeline':
// Verify that it's a share
foreach ($request['userActions'] as $i => $user_action) {
if ($user_action['type'] == 'SHARE') {
$timeline_item_id = $request['itemId'];
$timeline_item = $mirror_service->timeline->get($timeline_item_id);
// Patch the item. Notice that since we retrieved the entire item above
// in order to access the caption, we could have just changed the text
// in place and used the update method, but we wanted to illustrate the
// patch method here.
$patch = new Google_TimelineItem();
$patch->setText("PHP Quick Start got your photo! " .
$timeline_item->getText());
$mirror_service->timeline->patch($timeline_item_id, $patch);
break;
}
}
...
Where and when is actually received the video? I need to know this in order to perform additional operations when I receive the data.
The shared picture or video is downloaded through the download_attachment function in mirror-client.php of the Quickstart PHP project.
Here is the function:
/**
* Download an attachment's content.
*
* #param string item_id ID of the timeline item the attachment belongs to.
* #param Google_Attachment $attachment Attachment's metadata.
* #return string The attachment's content if successful, null otherwise.
*/
function download_attachment($item_id, $attachment) {
$request = new Google_HttpRequest($attachment->getContentUrl(), 'GET', null, null);
$httpRequest = Google_Client::$io->authenticatedRequest($request);
if ($httpRequest->getResponseHttpCode() == 200) {
return $httpRequest->getResponseBody();
} else {
// An error occurred.
return null;
}
}
Related
I have recently completed the task of setting up database notifications with Laravel. I am now able to send notifications. What I want to do now, however, is: when I send a notification, I want an icon (such as a bell) to appear on my website, where users can hover over this icon and see the notification header, or click on it to read the full content. Is this possible?
Also, is there a way that I can get a database to see all notifications that I have sent? Perhaps using MySQL.
For the first question:
Yes, you can fetch the notification for every user like this:
In controller that you want to pass the result of notification for every user
$user = App\User::find(1);
foreach ($user->unreadNotifications as $notification) {
echo $notification->type;
}
For the second question you should add a value to toArray function like th
And you can count the notification and show the message on header on anywhere you want with helping Ajax call or by every refresh html page,
In notification file
public function toArray($notifiable)
{
return [
'sender_id' => $this->user->id,
];
}
After that when you want to fetch this data (query on notification table to find notifications that you send) you can use JSON Where Clauses
I hope it will help you,
It's super easy get the latest notification and count .. Though the only differentiating factor here is how do you know there is a new notification from all your notifications. So I would suggest this design on your database.
Database
[id, name, latest]
Note: latest colunm is an integer type .eg. 0 or 1, where 0 is not latest and 1 is latest.
Inserting a Notification
So when you insert data save new notification in the db as latest e.g
$notification = new Notification();
$notification->name = 'whatever';
$notification->latest = 1; // important part
$notification->save()
Retrieving latest notification and Displaying a Bell
$latest_notification = Notification::where('latest', 1)->first(); // latest
//before responding to view - save notification as 0
$latest_notification->latest = 0;
$latest_notification->save();
if(latest_notification->isNotNull) {
return["latest" => latest_notification]
}else{
return["latest" => 0];
}
Front End Displaying Bell
<span id="notifier"></span>
Javascript -- Jquery
// if your response is not 0 then you have notification
// After post request to the server post or axios whatever you use
if(response.latest !== 0) {
$('#notifier').html('<i class="fas fa-bell"></i>' + '1')
} else {
$('#notifier').html('0')
}
Sorry have not had time to test this but this sure point you somewhere, all the best.
In Prestashop 1.6, from a FrontController, I have to send a mail to the administrator of the Shop.
This part works well but I got problems to include a link to the administration page of a specific customer.
The only thing I miss is the name of the administration directory. I would be able to parse and concatenate the PS_ADMIN_DIR constant but it is not available from the FrontController.
I'm kinda stuck here.
Here is the code :
$admin_customer_link =
_PS_BASE_URL_
.__PS_BASE_URI__
/* Missing the Administration directory name here */
.$this->context->link->getAdminLink('AdminCustomers', false)
."&id_customer=".(int)$customer->id."&viewcustomer";
The output I got :
http://127.0.0.1:8080/prestashop/index.php?controller=AdminCustomers&id_customer=2&viewcustomer
The output I need :
http://127.0.0.1:8080/prestashop/administration/index.php?controller=AdminCustomers&id_customer=2&viewcustomer
Any help will be appreciated.
There is no (standard) way to know the administration folder from a front controller, otherwise all the security will flushed down the toilet :).
What you can do is to retrieve the administration folder from the module 'configuration' or when you install it, and save it somewhere, at the moment I suggest into the database but maybe there is a more safely mode.
Something like:
public function install()
{
// your stuff
$current_dir = $_SERVER['PHP_SELF']; // this give you the current dir (administration folder included)
$administration_folder = /* Clean your string with a string replace or preg */
Configuration::updateValue('PS_MYMOD_ADMIN_DIR', $administration_folder);
return true;
}
Then in your front controller retrieve it by:
$adminfolder = Configuration::get('PS_MYMOD_ADMIN_DIR');
However I hope you know that you're creating a security breach through e-mail...
Hope it helps
Since the use of the administration directory name from the Front End and sending a link to the administration in e-mail is not a good idea for security purpose, I choose to implement this another way.
Instead of send the administration customer's page link to the webmaster by e-mail, I create a new customer Thread and message. After that, I send an e-mail to the customer service. So, when they log in the Back Office, they see a new notification who leads them to the specific user.
Here is the code :
ModuleFrontController
// Create a new Customer Thread
$ct = new CustomerThread();
if (isset($customer->id)) {
$ct->id_customer = (int)$customer->id;
}
$ct->id_shop = (int)$this->context->shop->id;
$ct->id_contact = $contact->id;
$ct->id_lang = (int)$this->context->language->id;
$ct->email = $customer->email;
$ct->status = 'open';
$ct->token = Tools::passwdGen(12);
$ct->add();
// Add a new message to the Customer Thread
if ($ct->id) {
$cm = new CustomerMessage();
$cm->id_customer_thread = $ct->id;
$cm->message = $message;
$cm->ip_address = (int)ip2long(Tools::getRemoteAddr());
$cm->user_agent = $_SERVER['HTTP_USER_AGENT'];
$cm->add();
}
Hope it helps someone in the same situation.
i'm using this api:
public function getUserMedia($id = 'self', $limit = 0) {
return $this->_makeCall('users/'.$id.'/media/recent', true, array('count' => $limit));
}
to fetch the photo of a user logged in my site using php
it works, and all other api works.
the problem is that i want to retrieve ALL the photo of a user (such as printstagr.am).
i've searched in the api but without success: it seems that you can take the recents or the populars, but the site mentioned above takes all. any idea?
thanks!
Not sure what the max count is (saw someone mention 20 was the max on another question, but can't find any limit in the docs from a quick scan), but essentially what you have to do is request as many as possible, then follow the pagination links to collect more.
So from the api docs they provide this:
{
...
"pagination": {
"next_url": "https://api.instagram.com/v1/tags/puppy/media/recent?access_token=fb2e77d.47a0479900504cb3ab4a1f626d174d2d&max_id=13872296",
"next_max_id": "13872296"
}
}
Your application needs to store the objects from the request (i.e. an array), then fire a new request to the "next_url", put those objects into the same store (i.e. array), then follow the link again, until you reach the end or until you get enough to satisfy your needs.
Currently, newly created Google spreadsheets seem to default to having 20 columns.
I am able to create new column headers through the cell feed, but only for those existing 20 columns. Beyond that, I cannot create new columns, much less new column headers, as I get the following error:
Expected response code 200, got 403It looks like someone else already deleted this cell.
Using the Zend GData API, this is what I'm doing:
<?php
/*
* Given:
*
* $columnNames, e.g. array('FirstName', 'LastName', 'DateOfBirth')
* $lastColumnOnSpreadsheet, e.g. 20
* $spreadsheetService
* $spreadsheetKey
* $worksheetId
*/
foreach ($columnNames as $columnName)
{
if (!array_key_exists($columnName, $columnsAlreadyOnSpreadsheet))
{
$spreadsheetService->updateCell(1 /* first row */,
++$lastColumnOnSpreadsheet,
$columnName,
$spreadsheetKey,
$worksheetId);
}
}
?>
So, beyond $lastColumnOnSpreadsheet being 19, I get the aforementioned error. Currently, the only workaround is to manually insert columns to the right, one by one, which, besides being tedious, kind of destroys the purpose of automation via GData.
Is it possible to insert columns via the GData API? If so, how, in particular through the Zend framework?
Java/.net: This shows how to set the size of the sheet, you can use it to append rows and cols
https://developers.google.com/google-apps/spreadsheets/
But I found the OAuth hard. For OAuth I used the GDrive tutorial "DrEdit", is the best OAuth tutorial I have seen.
I want to write PHP script (standalone) for comment approval.
Objective:
I use Aksimet for comment filtering. After Akismet's filtering, few comments get passed and come to my email for approval. I will get comment ID from there and pass it to the script in get parameter (manually).
This way I do not need to login to WP every time. The script will just approve comment so there is not much risk or harm. If script works then It will take less time and I can approve comment any time even from office.
I tried setting the moderation bit in MySQL directly to see if it works or not! The answer is yes and no. It approves the comment but it does not refresh the post. So, my cache show post without new comment. I use Super cache plugin.
The challenge is to write script OUTSIDE of WP environment. So, that I can access the script without Admin login.
Please suggest trick for this and how to start for this.
I spent a little time and got this working. The key is that you can use the WP API in your script by including wp-load.php.
I have tested this below and it works in my Wordpress. It uses GET parameters 'commentid' and 'status'. I leave it to you to extend, test for error conditions, provide appropriate security mechanisms, etc.
<?php
include('wp-load.php');
echo 'Running comment approval...<br>';
$wp_error = false;
if(isset($_GET['commentid']) && isset($_GET['status']) )
{
$comment_id = $_GET['commentid'];
$comment_status_to_set = $_GET['status'];
$current_status = wp_get_comment_status( $comment_id );
echo 'Current comment status is ' . $current_status .'<br>';
echo 'Setting status to ' . $comment_status_to_set . '<br>';
$res = wp_set_comment_status($comment_id, $comment_status_to_set, $wp_error);
$new_current_status = wp_get_comment_status( $comment_id );
echo 'Now status is ' . $new_current_status . '<br>';
}
else
{
echo 'No comment parameters passed in url';
}
?>
And here is the usage for wp_set_comment_status, from the source code:
#param int $comment_id Comment ID.
#param string $comment_status New comment status, either 'hold', 'approve', 'spam', or 'delete'.
#param bool $wp_error Whether to return a WP_Error object if there is a failure. Default is false.
#return bool False on failure or deletion and true on success.
Also, so those who are curious know how I went about solving this... basically I checked the /wp-includes/ directory of WP to see if there were any comment related files. There is a file called comment.php in there, which has most, if not all, of the main comment manipulation functions that the wordpress API uses.
#param int $comment_id Comment ID.
#param string $comment_status New comment status, either 'hold', 'approve', 'spam', or 'delete'.
#param bool $wp_error Whether to return a WP_Error object if there is a failure. Default is false.
#return bool False on failure or deletion and true on success.