Trying to create a simple rss feed in zend framework2 by using Zend\Feed\Writer\Feed:
$feed = new \Zend\Feed\Writer\Feed();
...
$out = $feed->export('rss');
echo $out;
And this will output:
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
<channel>
<title>example</title>
<description>example</description>
<generator>Zend_Feed_Writer 2 (http://framework.zend.com)</generator>
<link>http://www.google.com</link>
<item>
<title>article1</title>
<pubDate>Fri, 11 Apr 2014 06:32:53 +0000</pubDate>
<slash:comments>0</slash:comments>
</item>
<item>
<title>article2</title>
<pubDate>Fri, 11 Apr 2014 06:32:53 +0000</pubDate>
<slash:comments>0</slash:comments>
</item>
</channel>
</rss>
My question is:
how to disable xmlns:slash extension <slash:comments>0</slash:comments>?
It's quite a mess in the Zend\Feed component with extensions. I have been messing around with it for a while.
What happens?
You construct a Zend\Feed\Writer\Feed. The Feed extends the Zend\Feed\Writer\AbstractFeed. In the __construct() of AbstractFeed happens this:
public function __construct()
{
Writer::registerCoreExtensions();
$this->_loadExtensions();
}
Writer is here the Zend\Feed\Writer\Writer. The registerCoreExtensions looks as follows:
public static function registerCoreExtensions()
{
static::registerExtension('DublinCore');
static::registerExtension('Content');
static::registerExtension('Atom');
static::registerExtension('Slash');
static::registerExtension('WellFormedWeb');
static::registerExtension('Threading');
static::registerExtension('ITunes');
}
Here, you see the different extens are added to the static Writer instance. From there on, the _loadExtensions() call fetches all extensions registered from the Writer and imports them into the Feed. The same happens by the way in the AbstractRenderer.
How to fix?
Because internally inside the Feed and Renderer the registerCoreExtensions() is called, you cannot overwrite the default list of extensions. Also, the Feed and the Renderer do not have getters/setters for the extension. The only way I came up with is to write your own Feed object and Renderer object.
For the Feed object you create a getter/setter to remove the extensions you want. You also override export where you copy the contents of the method, but overwrite the $renderClass variable name to the render class of your own.
For the Renderer class you create a getter/setter to remove the extensions you want as well. This way, you can tune the extensions you need. It's not that pretty, but hopefully it's something improved upon in ZF3 :)
Related
At first, I saw a topic Symfony Twig and xml - Document is empty error and my case is similar, but provided answers there, did not help me.
So my problem is: sometimes I got parsing error in a browser.
In chrome it is:
This page contains the following errors:
error on line 38 at column 21: Opening and ending tag mismatch: link line 19 and head
Below is a rendering of the page up to the first error.
But on firefox things get a little bit more accurate? (I got non-english version so here is my translation of this error):
Error parsing XML: wrong tag. Expected </link>
So my guess is, Symfony somehow provide XML document to the browser, instead of HTML.
But looking at the source code, or even at Inspector, there is nothing that would indicate XML. I got <!DOCTYPE html> tag at start, and proper tags.
When this error occur document in Inspector in Chrome is parsed, like <LINK> tags should have end tags (</LINK>) and everything under this tag is considered as be inside this <LINK> tag. But message in Firefox gave me answer: XML document, so <LINK> tag is treated like tag with closure.
But what is more important, this happening only sometimes, not always. For most of the time I got good looking website, with everything working, all tags parsed, all assets loaded, Javascripts working well.
Why this could happen that sometimes, Symfony put XML file instead of HTML to a browser?
I have an idea, that this could be because of HTTP-CACHE I have inserted in my app in the controller action. Maybe I configured something in a wrong way.
Or maybe there is something else wrong in here? Maybe in other YAML configuration file?
public function index()
{
$categories = [ ... ];
$articlesByCategory = [ ... ]; // is readed correctly - checked
return CacheService::buildCachedResponse($this->render('pages/home.html.twig', [
'categories' => $categories,
'articles' => $articlesByCategory,
...
]), self::CACHE_TIME);
}
class CacheService
{
public static function buildCachedResponse(Response $response, int $expirationSeconds)
{
$response->setPublic();
$response->setMaxAge($expirationSeconds);
$response->headers->addCacheControlDirective('must-revalidate', true);
return $response;
}
}
class CacheKernel extends HttpCache
{
protected function getOptions(): array
{
return [
'default_ttl' => HttpCacheTimesPerController::DEFAULT,
];
}
}
Kernel switched to "CacheKernel" in "public/index.php", as showed in Symfony documentation.
INFO: currently app is running on symfony 5.x, and php 7.4.
1 - Any idea if we can switch between Light & Dark themes using the Xamarin.Forms themes introduced in version 2.3.x (link below). Any workaround?
https://developer.xamarin.com/guides/xamarin-forms/user-interface/themes/
2 - Also I see this release is in preview ever since it was introduced. Are there any issues and we cannot use it in production?
The accepted answer doesn't adhere to the convention demonstrated by Microsoft.
Assuming you've installed the packages, Xamarin.Forms.Themes.Base, Xamarin.Forms.Themes.Light, and Xamarin.Forms.Themes.Dark, and your App.xaml looks like,
<?xml version="1.0" encoding="utf-8" ?>
<Application
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:light="clr-namespace:Xamarin.Forms.Themes;assembly=Xamarin.Forms.Theme.Light"
xmlns:dark="clr-namespace:Xamarin.Forms.Themes;assembly=Xamarin.Forms.Theme.Dark"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyNamespace.MyApp">
<Application.Resources>
<ResourceDictionary MergedWith="light:LightThemeResources">
...
</ResourceDictionary>
</Application.Resources>
</Application>
you can change the theme at run time with the following:
public enum Themes
{
Dark,
Light
}
var origin = App.Current.Resources;
switch (theme)
{
case Themes.Dark:
origin.MergedWith = typeof(DarkThemeResources);
break;
case Themes.Light:
origin.MergedWith = typeof(LightThemeResources);
break;
}
Yes is possible, adding the Resources by code in the App.cs class you can switch which Theme to use.
In the class constructor you set the default Theme:
Resources = new Xamarin.Forms.Themes.DarkThemeResources ();
You then expose a method is this class SwitchTheme() where you will assign the other theme:
public void SwitchTheme ()
{
if (Resources?.GetType () == typeof (DarkThemeResources))
{
Resources = new LightThemeResources ();
return;
}
Resources = new DarkThemeResources ();
}
Be aware that if you have defined styles the code above won't work as it will override your Resources Dictionary. For that you could create your own themes based on these two, adding your define styles and use your implementations for switching.
I have installed a particular module in my SilverStripe installation. The following is the directory structure
- Root
- framework
- cms
- mymodule
- code
- extensions
- CustomClass.php
Here is an example of CustomClass.php
class CustomClass extends Extension {
public function init() {
}
public function customMethod() {
}
}
I need to override the customMethod method of the CustomClass class. I could easily change this method, but changing here will cause trouble in the future if the modules get updated. All the changes made will be lost.
So for this I want to extend the extension class used in modules.
I have created an extension /mysite/extensions/MyCustomClass.php
class MyCustomClass extends Extension {
public function customMethod() {
//do my code here
}
}
but I have no idea how to apply this. I thought CustomClass::add_extension("MyCustomClass ") but surely this will not work because add_extension method doesn't exist in CustomClass.
How do we cope with this scenario? Can I use Injector instead? If yes, how can it be called in mysite/_config.php instead of _config.yml?
Using injector does solve the problem but have to use _config.yml as well. Here is what I did.
File /mysite/extensions/MyCustomClass.php
class MyCustomClass extends CustomClass {
public function customMethod() {
//do my code here
}
}
in /mysite/_config/config.yml I added following lines
Injector:
CustomClass:
class: MyCustomClass
And in /mysite/_config.php I added following line
$object = Injector::inst()->create('CustomClass');
And it all worked fine.
There is another way to achieve similar functionality without straight up replacing a previous extension. With SilverStripe's extension system, we can control not only what configuration settings are loaded but the order they are loaded. This is important to note because the customMethod function from an extension, it uses the first one it finds from all the extensions loaded.
Because of this, it can be only a matter of controlling when your MyCustomClass extension is loaded so you can have your own customMethod function run.
Let's say the "MyModule" module has the following YAML file defined:
---
Name: MyModuleExtensions
After:
- 'framework/*'
- 'cms/*'
---
Page:
extensions:
- CustomClass
All we need to do is specify a separate YAML file to run before this "MyModule" one. This can be accomplished like:
---
Name: MyCustomModule
Before:
- MyModule/#MyModuleExtensions
---
Page:
extensions:
- MyCustomClass
Now, when you call your customMethod function on whatever class you have your extensions on (so in my example, the Page class), it will call the one from your MyCustomClass extension.
i have create one html help page like CMS and stored in database.
<content>
Contact us
</content>
In html file write this code
{{{helpPage}}}
Is it possible call dynamicUrl in html right now in <a> tag show
Contact us
I think the issue is that you want to be able to parse Spacebars template tags from a template string? If so,
Add carlevans719:dynamic-templates, then change
{{{helpPage}}}
to:
{{Template.dynamic template=dynamicTemplate}}
And in your template helpers, add:
dynamicTemplate: function () {
var content = getContentFromDB();
var template = new DynamicTemplate(content);
return template.name;
}
See: https://atmospherejs.com/carlevans719/dynamic-templates
I am working with ActionScript 3 and I need to add a simple tag to one of my XML nodes.
I am trying to add xml:space=preserve tag to one of my text nodes.
var tSpan : XML = new XML ( "<tspan xml:space=\"preserve\"></tspan>" );
My problem is, the moment I add the tSpan node to my main XML, the tag is automatically converted to something like this:
<tspan aaa:space="preserve" xmlns:aaa="http://www.w3.org/XML/1998/namespace">.....
Any idea on how to add xml:... values to an XML node with Actionscript?
Thanks in advance.
Simply create a namespace definition for xml: within your node. It would look like this.
var tSpan : XML = new XML ( "<tspan xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xml:space=\"preserve\"></tspan>" );
The xml:space attribute requires the a namespace definition. See this document for more details. http://www.w3.org/XML/1998/namespace