Get template author and license - php

Based on this sample code, on Joomla 3.9.5
$app = JFactory::getApplication();
$getTemplateId = $app->getTemplate('template')->id;
I'm trying to get template author and license from the XML/SQLdb
$app = JFactory::getApplication();
$getTemplateAuthor = $app->getTemplate('template')->author;
$getTemplateLicense = $app->getTemplate('template')->license;
This of course doesn't work so I would be happy with any suggestion.

After investigating the database in phpMyAdmin, I came up with this solution
// get app
$app = JFactory::getApplication();
// get template
$templateName = $app->getTemplate();
// hook Joomla Database API
$db = JFactory::getDbo();
// set query
$db->setQuery("SELECT manifest_cache FROM #__extensions where `type` = 'template' AND `element` = '".$templateName."'");
// extract the manifest_cache column
$templateMETA = $db->loadObject()->manifest_cache;
// decode JSON and build an object
$templateMETA = json_decode( $templateMETA );
// set author&license
$author = $templateMETA->author;
$license = $templateMETA->license;
The manifest_cache holds the template and possibly any Joomla extension meta information.
Hope this helps someone.

Related

Evernote php - get notes from linked notebook

I am using this SDK - https://github.com/evernote/evernote-cloud-sdk-php
I can find notes in the my own notebooks, something like this:
$client = new \Evernote\Client($token, false);
$search = new \Evernote\Model\Search('*');
$notebook = $client->getNotebook('notebook_id');
$scope = \Evernote\Client::SEARCH_SCOPE_ALL;
$order = \Evernote\Client::SORT_ORDER_REVERSE | \Evernote\Client::SORT_ORDER_RECENTLY_CREATED;
$results = $client->findNotesWithSearch($search, $notebook, $scope, $order, 20);
It works, but if I try get notes from linked notebooks, it get empty result all time.
Tried implement this - https://dev.evernote.com/doc/articles/sharing.php
$adClient = new \Evernote\AdvancedClient($token ,false);
$store = $adClient->getSharedNoteStore('linked_notbook_id');
$client = new \Evernote\Client($store->getToken(), false);
$search = new \Evernote\Model\Search('*');
$notebook = $carrier->getLinkedNotebooks()[0];
$scope = \Evernote\Client::SEARCH_SCOPE_ALL;
$order = \Evernote\Client::SORT_ORDER_REVERSE | \Evernote\Client::SORT_ORDER_RECENTLY_CREATED;
$results = $client->findNotesWithSearch($search, $notebook, $scope, $order, 20);
The same, empty result.
Where did this $carrier come from?
$notebook = $carrier->getLinkedNotebooks()[0];
Assuming it's $client, LinkedNotebook from the SharedNoteStore is assigned to $notebook and it is passed to findNotesWithSearch, which doesn't seem right.
The LinkedNotebook object is for the user who is shared a notebook with. So calling that API with SharedNoteStore is probably not what you want. See https://dev.evernote.com/doc/articles/sharing.php
The type of second argument of findNotesWithSearch is Notebook. notebookGuid can be found in SharedNotebook.

How to create an addon domain using xmlapi-php?

I am trying to create an addon domain using xmlapi-php. I have a shared hosting account.
This sample code is from github
<?php
include '../xmlapi.php';
$ip = getenv('REMOTE_HOST');
$root_pass = getenv('REMOTE_PASSWORD');
$domain = "somedns.com";
$xmlapi = new xmlapi($ip);
$xmlapi->password_auth("root",$root_pass);
$xmlapi->set_http_client('curl');
$xmlapi->set_port(2086);
$xmlapi->set_debug(1);
print $xmlapi->adddns($domain,$ip);
?>
I am having trouble getting this code to work to create an addon domain. How can it be done?
Well I've figured it out to the best of my ability and here is the solution for all the lost souls out there:
Authentication
You need run the following code at least once for authentication and xml api wrapper:
// AUTHENTICATION -------------------------
include("xmlapi.php");
$host = "Host ip address or Site.com";
$my_user = "Your cPanel user ID";
$my_pass = "Your cPanel password";
$xmlapi = new xmlapi($host);
$xmlapi->set_port(2083);
$xmlapi->password_auth($my_user, $my_pass);
$xmlapi->set_output('json');
$xmlapi->set_debug(1);
Now you can start using the functions provided in the xmlapi.php but you are not limited to them.
Email Creation Example
// Calling on the function "addpop" "email_user#email_domain" -------------------------
$email_user = "apitest";
$email_password = "adfm90f";
$email_domain = "somesite.com";
$email_query = '10';
$email_quota = '600';
//$result will be set equal to the JSON output returned by the call
//api1_query is the function
//in the array is where you pass the required parameters
$result = $xmlapi->api1_query($my_user, "Email", "addpop",
array($email_user, $email_password, $email_quota, $email_domain));
Displaying the results
$result = json_decode($result, true); //Decoding the JSON results to PHP
print_r($result); //Printing the array onto the page
//example of displaying a particular array key, in this example its "result"
echo $result['data']['result'];

How to export Exchange Web Services Item to a *.eml file? (PHP)

I'm developing a web interface for Exchange Web Services which should be able to save a mail item to eml format. I use PHP-EWS (https://github.com/jamesiarmes/php-ews) to establish a connection to the Exchange Server.
I know how such a file looks like, so I could download a mail item and generate an eml template with the data.
But I found this post: Save mail to msg file using EWS API. Colin talks about a mechanism which directly export a mail item into eml file. Is that possible in PHP, too?
Additionally I found another thing: https://github.com/jamesiarmes/php-ews/wiki/Email:-Set-Extended-MAPI-Properties. In this example somebody generates a mime content and set it to a new item. Is it possible to get the mime type (which looks like an eml file to me) for an existing item?
Thanks for any help!
To save a mail item in eml format you have to set the IncludeMimeContent property to true in the ItemShape element of the GetItem operation.
By doing so, you will get in the GetItem response a MimeContent element:
The MimeContent element contains the native Multipurpose Internet Mail
Extensions (MIME) stream of an object that is represented in
base64Binary format.
As an example, consider the following code:
<?php
function __autoload($class_name) {
$base_path = 'php-ews-master';
$include_file = $base_path . '/' . str_replace('_', '/', $class_name) . '.php';
return (file_exists($include_file) ? require_once $include_file : false);
}
/*
** Adjust these variables before running the script!
*/
$server = 'your_server';
$username = 'your_user';
$password = 'your_password';
$message_id = 'your_message_id';
$ews = new ExchangeWebServices($server, $username, $password);
//print_r($ews);
$request = new EWSType_GetItemType();
$request->ItemShape = new EWSType_ItemResponseShapeType();
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::ALL_PROPERTIES;
$request->ItemShape->IncludeMimeContent = true;
$request->ItemIds = new EWSType_NonEmptyArrayOfBaseItemIdsType();
$request->ItemIds->ItemId = new EWSType_ItemIdType();
$request->ItemIds->ItemId->Id = $message_id;
$response = $ews->GetItem($request);
//echo '<pre>'.print_r($response, true).'</pre>';
if (($response->ResponseMessages->GetItemResponseMessage->ResponseCode == 'NoError') &&
($response->ResponseMessages->GetItemResponseMessage->ResponseClass == 'Success')) {
file_put_contents("test.eml", base64_decode($response->ResponseMessages->GetItemResponseMessage->Items->Message->MimeContent->_));
}
?>

Retrieving Contact photo with Zend Gdata with PHP

When querying for contacts I use the code below to retrieve all my contacts
$gdata = new Zend_Gdata($client);
$gdata->setMajorProtocolVersion(3);
$query = new Zend_Gdata_Query(
"http://www.google.com/m8/feeds/contacts/default/full");
$feed = $gdata->getFeed($query);
As I look through each entry of the $feed I can get access to the contactId and according to the Contacts API I should be able to retrieve the picture by doing a GET on the following URL:
http://www.google.com/m8/feeds/photos/media/default/contactId
So I use the same mechanism to retrieve contacts and try to get a photo after setting $id:
$query = new Zend_Gdata_Query(
"http://www.google.com/m8/feeds/photos/media/default/$id");
$entryFeed = $gdata->getFeed($query);
But I get an error "DOMDocument cannot parse XML". Am I doing something wrong? Are there any example docs?
To get the photo use DOMXpath and search for the "//atom:link" tag, then use $gdata->get(href) to grab the photo. Check for the etag attribute for each link, this tells you whether or not there is a profile photo associated with this contact.
$doc = new DOMDocument;
$doc->recover = true;
$doc->loadXML($entry->getXML());
$xpath = new DOMXPath($doc);
$links = $xpath->query('//atom:link');
foreach($links as $link) {
if($link->getAttribute('etag') != "") {
$http_response = $gdata->get($link->getAttribute('href'));
$rawImage = $http_response->getBody();
$fp = fopen("/var/www/profile/$id.jpg", "w");
fwrite($fp, $rawImage);
fclose($fp);
break;
}
}

Cannot instantiate a Note object using Evernote API in PHP

I am trying to develop a script (using the PHP example app as a basis) that will post a note to Evernote based on GET values.
When I insert this to the end of functions.php's listNotebooks()
$note_obj = new Note(array(
'contents' => $note_contents,
'title' => $title
));
It throws a 500 error. (In my code, $title & $note_contents are defined earlier. I have spent a lot of time trying to find proper documentation for the PHP API but it just seems non-existent. Any information on this topic would be greatly appreciated
Update: I did not realize the API was using PHP Namespaces: This fixed the issue:
//import Note class
use EDAM\Types\Note;
use EDAM\Types\NoteAttributes;
use EDAM\NoteStore\NoteStoreClient;
My code to add a note still does not work but I'll post it here once I figure it out.
These classes need to be imported:
//import Note class
use EDAM\Types\Note;
use EDAM\Types\NoteAttributes;
use EDAM\NoteStore\NoteStoreClient;
This will define our new note:
$noteAttr = new NoteAttributes();
$noteAttr->sourceURL = "http://www.example.com";
$note = new Note();
$note->guid = null;
$note->title = "My Title";
$note->content = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml.dtd"><en-note>My Content</en-note>';
$note->contentHash = null;
$note->contentLength = null;
$note->created = time()*1000;
$note->updated = time()*1000;
$note->deleted = null;
$note->active = null;
$note->updateSequenceNum = null;
$note->notebookGuid = null;
$note->tagGuids = null;
$note->resources = null;
$note->attributes = $noteAttr;
$note->tagNames = null;
addNote($note);
This function will add a new note:
function addNote($newnote) {
global $noteRet;
if (empty($noteRet)) {
define("noteStoreHost", "sandbox.evernote.com");
define("noteStorePort", "80");
define("noteStoreProto", "https");
define("noteStoreUrl", "edam/note/");
$noteStoreTrans = new THttpClient(noteStoreHost, noteStorePort, noteStoreUrl . $_SESSION['shardId'], noteStoreProto);
$noteStoreProt = new TBinaryProtocol($noteStoreTrans);
$noteStore = new NoteStoreClient($noteStoreProt, $noteStoreProt);
$noteRet = $noteStore->createNote($_SESSION['accessToken'], $newnote);
return $noteRet;
}
}

Categories