Kos
February 23, 2023, 6:47pm
1
I installed the addon.
I have my Cockpit CMS in catalogue: “admin”
When I use url: https://mydomain/admin/api/feed/listFeeds
I get list of 2 collections that have View set to public.
When I click on the url of one of the collections in the listFeeds I get an error: {“error”: “500”, “message”: “system error”}
The url looks like this: https://mydomain/admin/api/feed/get/collectionName
If I try using url: mydomain/admin/feed/get/collectionName I get “Uuuups, Page not found.”
in config.php I added:
return [
‘feed’ => [
‘public’ => true
]
];
Could it be a file permission problem or a lack of some php module on the hosting server?
EDIT: just checked it localy on MAMP and there for localhost/site/cockpit/api/feed/get/Posts
I get error:
{“error”:“syntax error, unexpected ‘version’ (T_STRING)”,“file”:“E:\Software\MAMP\htdocs\site\cockpit\storage\tmp\rss.php.7efccab8971bc5eb0f461909e20ed167.lexy.php”,“line”:15}
EDIT_2: if I edit the view\rss.php on line 15 using echo like that:
<?php echo "<?xml version='1.0' encoding='UTF-8'?>"; ?>
p.s. I have short_tag Off in my php.ini
then the browser wants to save a file to drive without file format.
Still those links without “api” in them, don’t work:
url/to/cockpit/feed/get/collectionname
I’m trying to get a proper url to connect the website to Pinterest
Kos
March 6, 2023, 8:31am
2
I found a solution!
For Pinterest only RSS 1.0 and 2.0 will work, they don’t support ATOM.
From plugin template file I figured that it uses ATOM.
What worked for my scenario, you can see below:
<?php
$title = $collection['label'] ?? $collection['name'];
$description = $collection['description'] ?? 'no description';
header("Content-Type: text/xml;charset=iso-8859-1");
echo "<?xml version='1.0' encoding='UTF-8' ?>" . PHP_EOL;
echo "<rss version='2.0'>".PHP_EOL;
echo "<channel>".PHP_EOL;
echo "<title>".$title."</title>".PHP_EOL;
echo "<link>".preg_replace("/^http:/i", "https:", $app['site_url'])."</link>".PHP_EOL;
echo "<description><![CDATA[".substr($description, 0, 300) ."]]></description>".PHP_EOL;
echo "<language>".$app['i18n']."</language>".PHP_EOL;
$i = 0;
foreach($entries as $post):
$title = isset($post['title']) && !empty($post['title']) ? htmlspecialchars($post['title'], ENT_XML1, 'UTF-8') : 'entry' . $i++;
$account = $app->storage->findOne('cockpit/accounts', ['_id' => $post['_by']]);
$author = htmlspecialchars((!empty($account['name']) ? $account['name'] : $account['user']), ENT_XML1, 'UTF-8');
$featured = !empty($post['thumbnail']) ? preg_replace("/^http:/i", "https:", $app['site_url']) . $app['base_route'] . "/storage/uploads" . $post['thumbnail']['path'] : preg_replace("/^http:/i", "https:", $app['site_url']);
$sizePath = $_SERVER['DOCUMENT_ROOT'] . $app['base_route'] . '/storage/uploads' . $post['thumbnail']['path'];
$size = filesize($sizePath);
$opis = $post['paragraph_1'] . $post['paragraph_2'];
if (COCKPIT_API_REQUEST) {
$slug = isset($post['slug']) ? '?filter[slug]=' . $post['slug'] : '?filter[_id]=' . $post['_id'];
$url = preg_replace("/^http:/i", "https:", $app['site_url'] . $app['base_route'] . '/api/collections/get/' . $collection['name'] . $slug);
}
else {
$url = preg_replace("/^http:/i", "https:", $app['site_url'] . ($app['feed']['site_route'] ?? '') . '/' . ($post['slug'] ?? $post['_id']));
}
$postdate = date(DATE_ATOM, ($post['_modified'] ?? $post['_created']));
$linkUrl = preg_replace("/^http:/i", "https:", $app['site_url'] . "/" . strtolower($collection['label']) . "/" . $post['title_slug']);
$content = [];
foreach($post as $field => $value){
if (in_array($field, ['zdjecia'])) {
if(is_array($value)){
foreach($value as $element){
if (is_array($element)){
array_push($content, $element['value'][0]['path']);
}
}
}
}
}
$publish_Date = date("D, d M Y H:i:s T", strtotime($postdate));
echo "<item xmlns:dc='ns:1'>".PHP_EOL;
echo "<title>".$title."</title>".PHP_EOL;
echo "<link>".$linkUrl."</link>".PHP_EOL;
echo "<guid>".$post['_id']."</guid>".PHP_EOL;
echo "<pubDate>".$publish_Date."</pubDate>".PHP_EOL;
echo "<dc:creator>".$author."</dc:creator>".PHP_EOL;
echo "<description><![CDATA[". strip_tags(substr($opis, 0, 499)) ."]]></description>".PHP_EOL;
// echo "<enclosure url='image_path' type='image/jpg' />".PHP_EOL;
// foreach($content as $img){
// $size = filesize($imgUrl.$img);
// print_r( $size);
// echo "<enclosure url='".$imgUrl.$img."' type='image/jpg' length='".$size."'/>".PHP_EOL;
// }
echo "<enclosure url='".$featured."' type='image/jpeg' length='".$size."'/>".PHP_EOL;
echo "</item>".PHP_EOL;
endforeach;
echo '</channel>'.PHP_EOL;
echo '</rss>'.PHP_EOL;
The Feed addon was always experimental and never finished. I marked it as archived and unmaintained anymore 5 months ago.
But I’m glad, you found a working solution.
In a different project, that is based on cockpit v1, I switched to using XMLWriter
instead of that template file. Maybe you can use it as an inspiration (still only atom).
See: cockpit-cms-Multiplane/DotXml.php at main - cockpit-cms-Multiplane - Codeberg.org