API to publish articles on Joomla and Drupal - ruby-on-rails

Do Joomla and Drupal provide any kind of APIs to publish articles?
I have Ruby on Rails application for content authoring and need to publish articles to different sites which are runs on Joomla and Drupal.

It can be done via for example a CLI script running on a Joomla site using the articles Model.
One suggestion would be to publish an RSS or XML feed that you can then import periodically via a Joomla CLI script. An example CLI script is given below. Points to note:
In the below example data is imported from a CSV file you would have to modify this for whatever your data source is.
The catid is hardcoded - you may wish to post your articles to different categories in which case you would need to do more work to potentially look up category IDs.
It doesn't include tags etc
Is only a solution for Joomla not Drupal
I could go on but this is a Q&A site not a consultancy opportunity...;-)
<?php
/**
* #package Joomla.Cli
*
* #copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
* #license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Initialize Joomla framework
const _JEXEC = 1;
// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
require_once dirname(__DIR__) . '/defines.php';
}
if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(__DIR__));
require_once JPATH_BASE . '/includes/defines.php';
}
// Get the framework.
require_once JPATH_LIBRARIES . '/import.legacy.php';
// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';
/**
* Cron job to import data into articles
*
* #since 2.5
*/
class ImportArticlesCron extends JApplicationCli
{
/**
* Entry point for the script
*
* #return void
*
* #since 2.5
*/
public function doExecute()
{
// Import articles model
JControllerForm::addModelPath(JPATH_ADMINISTRATOR . '/components/com_content/models');
// Get an instance of the content model
$model = $this->getModel('Article', 'ContentModel');
// This example is using a csv file but there's no reason you couldn't import an XML file here
while (($line = fgetcsv($handle, 0, $delimiter = '|')) !== FALSE)
{
$data = array();
$data['introtext'] = '';
$data['fulltext'] = $output;
$data['id'] = '';
$data['state'] = ($line[1] == 'True') ? 1 : 0;
$data['title'] = iconv("ISO-8859-1", "UTF-8//TRANSLIT", $line[3]);
$data['created'] = $line[2];
$data['catid'] = 38;
$data['language'] = 'en-GB';
$data['metadesc'] = '';
$data['metakey'] = '';
//$data['publish_up'] = date('Y-m-d', strtotime($line[14]));
//$data['publish_down'] = date('Y-m-d', strtotime($line[15]));
$model = $this->getModel('Article', 'ContentModel');
if (!$model->save($data))
{
$error = $model->getError();
}
}
}
}
JApplicationCli::getInstance('ImportArticlesCron')->execute();
?>

The answer to the question for Joomla is no, there's no web API to publish articles from remote.
I never had to implement such a solution so I don't have a proven answer.
Being a developer, my first thought would be to build a custom API component.
Maybe, before that, I would look into the JED to see if someone already did it.

Related

Using an existing spreadsheet as a template PHPspreadsheet

Objective
I want to use an existing Excel sheet, as a template to create an invoice.
Cell styling, such as coloring have to be included
An image (logo) has to be included
Standard data such as company address has to be included
I've read something about cfspreadsheet, but I'm not entirely sure how to use it.
Question A:
Is there a way to use a template file? Or do you know any alternatives?
Question B
Is it possible to use $_POST data with this library?
Example
$data = $_POST['example'];
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', '$data');
I am not 100% sure, but according to PhpSpreadsheet's doc, you can read a local file (your pre-made template) with :
$inputFileName = './sampleData/example1.xls';
/** Load $inputFileName to a Spreadsheet Object **/
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);
Or in case you already know the file type (.xlsx or .xsl) :
$inputFileType = 'Xls'; // Xlsx - Xml - Ods - Slk - Gnumeric - Csv
$inputFileName = './sampleData/example1.xls';
/** Create a new Reader of the type defined in $inputFileType **/
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
/** Load $inputFileName to a Spreadsheet Object **/
$spreadsheet = $reader->load($inputFileName);
You can also wrap all of that in a try catch if you want.
Then you just have to make changes the same way you would populate a Spreadsheet you created, populating cells with data you get from pretty much where you want with php, examples :
Classic variable $foo = 'bar';
$_GET / $_POST / $_REQUEST
From a Database

TCPDF use within Cakephp

There are a lot posts about this subjects, but the link to any sloution are not working anymore... I followed this article.
I downloaded TCPDF master.
Upzipped it in the folder Vendor/ tcpdf
Eddited xtcpdf.php
<?php
App::import('Vendor','tcpdf/tcpdf');
class XTCPDF extends TCPDF{
}
Edit config.php (is this the right path?
/**
* Installation path (/var/www/tcpdf/).
* By default it is automatically calculated but you can also set it as a fixed string to improve performances.
*/
define ('K_PATH_MAIN', '/var/www/ppp/app/Vendor/tcpdf');
/**
* URL path to tcpdf installation folder (http://localhost/tcpdf/).
* By default it is automatically set but you can also set it as a fixed string to improve performances.
*/
define ('K_PATH_URL', 'http://localhost/ppp/Vendor/tcpdf');
Create app/View/Layouts/pdf/default.ctp
<?php
header("Content-type: application/pdf");
echo $content_for_layout;
?>
Then in the webpages controller:
public function newpdf(){
$users = $this->User->find('all');
$this->set(compact('users'));
$this->layout = '/pdf/default';
$this->render()->type('application/pdf');
}
and in de view/webcontroller
public function newpdf(){
$users = $this->User->find('all');
$this->set(compact('users'));
$this->layout = '/pdf/default';
$this->render()->type('application/pdf');
}
When i want to test it i get a blank page, without anything...
I made the function in Webpages. Is that all right? Or should I make the function somewhere else?
The path in the configuration file, I work on a localhost on linux. The path: /var/www/ppp/app/Vendor/tcpdf. Is that the right path?
The URL is set is http://localhost/ppp/app/Vendor/tcpdf Is that the right URL?
Thanks in advance
first of all did you checked whether the tcpdf is loaded or not
App::import('Vendor','tcpdf',array('file' => 'tcpdf/tcpdf.php'));
then on path where you want to put the pdf.It must be the real path
$path=realpath('../webroot/pdf/') . '/';
then initialize the tcpdf
$pdf= new tcpdf();
then set desired file options
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Your Name');
$pdf->SetTitle(title);
$pdf->SetSubject('TCPDF');
$pdf->SetKeywords(keywords);
// add a page
$pdf->AddPage();
then get the html which you want to convert to pdf
$html= $this->render('/Elements/Pdf');
write the html to pdf
$pdf->writeHTML($html, true, false, true, false, '');
then output it
$name='pdf.pdf';
$pdf->Output($path.$name, 'F');
Let me know if still have some issues.

Response code Null (0) today, app was working yesterday (API Integration)

I have integrated Asana task lists into my company's website for our development team. All was going well until today - the page I created now errors out with a response code of NULL (or 0). In my very limited experience, this is an issue with the Asana connection, correct? Is this something I can fix on my side or is Asana API currently down (considering this worked up until today)?
We are using the API key, not OAuth, as everyone who has access to this task list is on the same workspace.
Edit:
I have 2 api keys that I am working with - 1 for production, 1 for development. I switch them out when I hand over a branch for my boss to merge in.
Testing API key works just fine.
Production API key does not work - always a response code null when trying to pull back tasks.
I am brand new to API development and I do not know how to use curl to make these calls. I am using a library found here:
https://github.com/ajimix/asana-api-php-class/blob/master/asana.php
More specifically, here is my code:
/*
* We are only interested in the JVZoo workspace
* Unless we are testing, in which we will use Faith In Motion workspace
*/
$JVZ_workspace_id = 18868754507673;
$FIM_workspace_id = 47486153348950;
/*
* Which one are we using right now?
*/
$workspace = $FIM_workspace_id;
/*
* Now lets do the same thing with Projects
* There should only be one project - JVZoo.com
* Unless we are testing - More JVZoo Testing
*
* We do need to dynamically show the project name
* This will help on confusion if we are accidently in the
* wrong project
*
* Then start building an array with these pieces
*/
$JVZ_project = array();
$JVZ_project['id'] = 53244927972665;
$JVZ_project['name'] = "JVZoo.com";
$FIM_project = array();
$FIM_project['id'] = 54787074465868;
$FIM_project['name'] = "More JVZoo Testing";
/*
* Which one are we using?
*/
$project = $FIM_project;
/*
* In order to help reduce load time even more,
* we are not going to return the project name
*
* This way we do not need to ask Asana for the project information
* This does change the layout of the view, however
*
* And finally grab all tasks for each project
* Connection check
*
* Return all tasks from this workspace and hand-filter
* to show both assigned and followed tasks
*/
$tasksJson = $asana->getProjectTasks($project['id']);
if ($asana->responseCode != '200' || is_null($tasksJson))
{
$this->session->set_flashdata('error', 'Error while trying to get tasks from Asana, response code: ' . $asana->responseCode);
redirect_and_continue_processing('/dashboard');
return;
}
FIM is my test environment.
JVZ is my production environment.
/**
* Returns all unarchived tasks of a given project
*
* #param string $projectId
* #param array $opt Array of options to pass
* (#see https://asana.com/developers/documentation/getting-started/input-output-options)
*
* #return string JSON or null
*/
public function getProjectTasks($projectId, array $opts = array())
{
$options = http_build_query($opts);
return $this->askAsana($this->taskUrl . '?project=' . $projectId . '&' . $options);
}
I did a PR on the parameter passed in to line that is returned above. In my FIM environment, I get this:
https://app.asana.com/api/1.0/tasks?project=54787074465868&
For my production environment:
https://app.asana.com/api/1.0/tasks?project=53244927972665&

Drupal 7: Print pdf using dompdf

I need help in installation of dompdf. Where should I place the extracted zip file in the directory? I've followed the INSTALL.txt, and it says "Extract the contents of the downloaded package into one of the supported paths." Does it mean placing into "Modules" folder? if so, an error occurs requesting for ".info". And it's not supplied. Please help, I'm confused! Thanks!
The supported paths are listed in the install.txt file:
supported paths:
* print module lib directory (usually sites/all/modules/print/lib)
* libraries directory (sites/all/libraries)
I prefer the second option, it will keep you from having to do this every time you update the module.
In other words it should look like this sites/all/libraries/dompdf
here's how I loaded it
I moved the folder dompdf-0.5.1 to the /sites/all/libraries folder
I edited dompdf_config.inc.php by replacing the DOMPDF_autoload() function with:
Code:
function DOMPDF_autoload($class) {
/* Add this checking - START */
if (mb_strtolower($class)== 'firephp'){
return;
}
/* Add this checking - END */
$filename = mb_strtolower($class) . ".cls.php";
require_once(DOMPDF_INC_DIR . "/$filename");
}
if ( !function_exists("__autoload") ) {
/**
* Default __autoload() function
*
* #param string $class
*/
function __autoload($class) {
DOMPDF_autoload($class);
}
}
now you should be able use it like so in any other module
Code:
require_once(realpath('.')."/sites/all/libraries/dompdf-0.5.1/dompdf_config.inc.php");
spl_autoload_register('DOMPDF_autoload');
$obj = new DOMPDF();
This worked and I was able to use the DOMPDF object/class.

Magento multilanguage - double change in language resuts in 404 (or how to change language within stores not views)

I have a problem with a magento installation. I used Magento ver. 1.5.0.1, community edition to develop this website http://cissmarket.com/.
The problem appears when I change the language from the EU version to French and after that to German. The change to french is ok, but when in the same page i change to German i receive a 404 error. Also this is generation 404 errors in the Google webmaster tools and when i try for example to take this link and paste it in the browser it gives me also a 404 error. I have there some 50 products and ~550 404 errors in Google Webmaster tools. I understand that the problem is from what I described.
Moreover I have a SEO problem since I have this page in french:
http://cissmarket.com/de/cartouches-refilables.html
And when I switch to the german version of the website it takes me to this link
http://cissmarket.com/de/cartouches-refilables.html?___from_store=fr (if i try now to switch to uk I will get the 404 mentioned above)
instead of going to this one:
http://cissmarket.com/de/nachfullpatronen.html
Already checked this 404 error when switching between stores when in a category on magento but it does not relate to my problem.
About settings:
I use the caching service and also I did index all the content.
The product or category I am trying to access is available and set active for all the languages.
System > General > Web > URL options > Add Store Code to Urls is set
to yes.
System > General > Web > Search Engines Optimization > Use Web Server
Rewrites is set to yes.
No other changes has been made to the .htaccess file except for the
ones that the system itself made.
So to conclude: the problem is the 404 given by 2 succesive changes of the language and the bad url address when I switch from one page to another.
Any suggestions would be appreciated.
UPDATE: tried this http://www.activo.com/how-to-avoid-the-___from_store-query-parameter-when-switching-store-views-in-magento but it results in a 404 at the first language change
Edit #1:
Found the problem: file languages.phtml contained this code <?php echo str_replace ("/fr/","/de/",$_lang->getCurrentUrl()); ?> and actually did replace only the language code and not the whole url according to the corresponding translation.
So applied to this
http://cissmarket.com/fr/cartouches-refilables.html
it will return
http://cissmarket.com/de/cartouches-refilables.html
So does anyone know how to get the corresponding URL of the current page for the other languages available in the store?
Edit #2 (using #Vinai solution):
It works on the product pages but not on the category yet.
There is no such thing in the native Magento as far as I know.
That said, you can use the following code to get the current page URL for each store.
$resource = Mage::getSingleton('core/resource');
$requestPath = Mage::getSingleton('core/url')->escape(
trim(Mage::app()->getRequest()->getRequestString(), '/')
);
$select = $resource->getConnection('default_read')->select()
->from(array('c' => $resource->getTableName('core/url_rewrite')), '')
->where('c.request_path=?', $requestPath)
->where('c.store_id=?', Mage::app()->getStore()->getId())
->joinInner(
array('t' => $resource->getTableName('core/url_rewrite')),
"t.category_id=c.category_id AND t.product_id=c.product_id AND t.id_path=c.id_path",
array('t.store_id', 't.request_path')
);
$storeUrls = (array) $resource->getConnection('default_read')
->fetchPairs($select);
This will give you an array with the array key being the store IDs and the array values being the request path after the Magento base URL, e.g. assuming your French store has the ID 1 and the German one has the ID 2, you would get:
Array
(
[1] => cartouches-refilables.html
[2] => nachfullpatronen.html
)
Then, in the foreach loop where the URL for each store is output, use
<?php $url = isset($storeUrls[$_lang->getId()]) ? $_lang->getUrl($storeUrls[$_lang->getId()]) : $_lang->getCurrentUrl() ?>
The call to $_lang->getUrl() will add the base URL, so you will get the full URL for each store (e.g. http://cissmarket.com/de/nachfullpatronen.html). If no store view value is found in the core_url_rewrite table it will revert to the default behaviour.
You still need the ___store=fr query parameter because otherwise Magento will think you are trying to access the new path in the context of the old store. Luckily, the getUrl() call an the store model adds that for you automatically.
The code querying the database can be anywhere of course (since its PHP), even in the template, but please don't put it there. The correct place to have code that access the database is a resource model. I suggest you create a resource model and put it in a method there.
I've found an ugly patch until a better approach comes up.
In the admin section, i've added the following javascript inside the wysiwyg in CMS > PAGES > (My 404 pages) (at the beginning of the wysiwyg) :
<script type="text/javascript" language="javascript">// <![CDATA[
var lang = "en";
var rooturl = "{{config path="web/unsecure/base_url"}}"
var url = document.location.href;
if(!(url.match("/"+lang+"/")))
{
var newUrl = url.replace(rooturl , rooturl+lang+"/" );
window.location.href = newUrl;
}
// ]]></script>
(Note: you need to do this for all of your translated 404 pages. In each 404 page you need to modify lang="en" for your storeview url value)
Because the wysiwyg (tiny_mce) does not allow javascript to be threated, you'll have to modify js/mage/adminhtml/wysiwyg/tinymce/setup.js. Add the following code under line 97 (under "var settings = "):
extended_valid_elements : 'script[language|type|src]',
For Magento 1.7.0.2 and 1.8.0.0 this is the bugfix:
Starting from line 251 of /app/code/core/Mage/Core/Model/Url/Rewrite.php
:
Mage::app()->getCookie()->set(Mage_Core_Model_Store::COOKIE_NAME, $currentStore->getCode(), true);
// endur 02-03-2013 fix for missed store code
// $targetUrl = $request->getBaseUrl(). '/' . $this->getRequestPath();
if (Mage::getStoreConfig('web/url/use_store') && $storeCode = Mage::app()->getStore()>getCode()) {
$targetUrl = $request->getBaseUrl(). '/' . $storeCode . '/' .$this->getRequestPath();
} else {
$targetUrl = $request->getBaseUrl(). '/' . $this->getRequestPath();
}
// endur 02-03-2013 end
Make sure to create a custom copy of the file in:
/app/code/local/Mage/Core/Model/Url/Rewrite.php or:
/app/code/local/YourTheme/Mage/Core/Model/Url/Rewrite.php
source:
It looks like a bug in Magento 1.7. Here is a hack that worked for me.
It should work for a two language store with store code in URL
in var/www/html/shop1/app/code/core/Mage/Core/Model/Url/Rewrite.php
remove this line
// $targetUrl = $request->getBaseUrl(). '/' . $this->getRequestPath();
and add these:
$storecode = Mage::app()->getStore()->getCode();
if ($storecode='en')
{
$targetUrl = $request->getBaseUrl(). '/'.$storecode.'/' . $this->getRequestPath();
}
else
{
$targetUrl = $request->getBaseUrl(). '/' . $this->getRequestPath();
}
Here a another solution for this problem. Just add this code after "$this->load($pathInfo, 'request_path');" in app/code/core/Mage/Core/Model/Url/Rewrite.php:
if (!$this->getId() && !isset($_GET['___from_store'])) {
$db = Mage::getSingleton('core/resource')->getConnection('default_read');
$result = $db->query('select store_id from core_url_rewrite WHERE request_path = "' . $pathInfo . '"');
if ($result) {
$storeIds = array();
if($row = $result->fetch(PDO::FETCH_ASSOC)) {
$storeId = $row['store_id'];
$storeCode = Mage::app()->getStore($storeId)->getCode();
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://" . $_SERVER['HTTP_HOST'] . "/" . $pathInfo . "?___store=" . $storeCode);
exit();
}
}
}
guys. For this error there is magento module. It have rewrite 2 models
http://www.magentocommerce.com/magento-connect/fix-404-error-in-language-switching.html

Resources