| 1 | package Strehler::Element::RSS::RSSChannel; | ||||||||||
| 2 | 1 | $Strehler::Element::RSS::RSSChannel::VERSION = '1.1.2'; | |||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Cwd 'abs_path'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Dancer2 0.154000; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Strehler::Helpers; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use File::Copy; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | extends 'Strehler::Element'; | |||||||||
| 11 | 1 | with 'Strehler::Element::Role::Slugged'; | |||||||||
| 12 | 1 | with 'Strehler::Element::Role::Maintainer'; | |||||||||
| 13 | |||||||||||
| 14 | 1 | my $module_file_path = __FILE__; | |||||||||
| 15 | 1 | my $root_path = abs_path($module_file_path); | |||||||||
| 16 | 1 | $root_path =~ s/RSSChannel\.pm//; | |||||||||
| 17 | 1 | my $form_path = $root_path . "../../forms"; | |||||||||
| 18 | 1 | my $views_path = $root_path . "../../views"; | |||||||||
| 19 | |||||||||||
| 20 | sub metaclass_data | ||||||||||
| 21 | 158 | ▶ | { | ||||||||
|
Subroutine
metaclass_data: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 22 | 158 | my $self = shift; | |||||||||
| 23 | 158 | my $param = shift; | |||||||||
| 24 | 158 | my %element_conf = ( item_type => 'rsschannel', | |||||||||
| 25 | ORMObj => 'Rsschannel', | ||||||||||
| 26 | category_accessor => 'rsschannels', | ||||||||||
| 27 | multilang_children => 'rsschannel_headers' ); | ||||||||||
| 28 | 158 | return $element_conf{$param}; | |||||||||
| 29 | } | ||||||||||
| 30 | 3 | ▶ | sub form { return "$form_path/RSS/rsschannel.yml" } | ||||||||
|
Subroutine
form: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 31 | 3 | ▶ | sub multilang_form { return "$form_path/RSS/rsschannel_multilang.yml" } | ||||||||
|
Subroutine
multilang_form: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 32 | 1 | ▶ | sub categorized { return 1; } | ||||||||
|
Subroutine
categorized: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 33 | 7 | ▶ | sub publishable { return 1; } | ||||||||
|
Subroutine
publishable: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 34 | 1 | ▶ | sub add_main_column_span { return 8; } | ||||||||
|
Subroutine
add_main_column_span: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 35 | 1 | ▶ | sub entity_js { return '/strehler/js/rsschannel.js'; } | ||||||||
|
Subroutine
entity_js: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 36 | |||||||||||
| 37 | sub main_title | ||||||||||
| 38 | 7 | ▶ | { | ||||||||
|
Subroutine
main_title: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||
| 39 | 7 | my $self = shift; | |||||||||
| 40 | 7 | my @contents = $self->row->rsschannel_headers->search({ language => config->{Strehler}->{default_language} }); | |||||||||
| 41 | 7 | ▶ | if($contents[0]) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | { | ||||||||||
| 43 | 7 | return $contents[0]->title; | |||||||||
| 44 | } | ||||||||||
| 45 | else | ||||||||||
| 46 | { | ||||||||||
| 47 | #Should not be possible | ||||||||||
| 48 | 0 | return "*** no title ***"; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | } | ||||||||||
| 52 | sub fields_list | ||||||||||
| 53 | 1 | ▶ | { | ||||||||
|
Subroutine
fields_list: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 54 | 1 | my $self = shift; | |||||||||
| 55 | 1 | my @fields = ( { 'id' => 'id', | |||||||||
| 56 | 'label' => 'ID', | ||||||||||
| 57 | 'ordinable' => 1 }, | ||||||||||
| 58 | { 'id' => 'rsschannel_headers.title', | ||||||||||
| 59 | 'label' => 'Title', | ||||||||||
| 60 | 'ordinable' => 1 }, | ||||||||||
| 61 | { 'id' => 'category', | ||||||||||
| 62 | 'label' => 'Category', | ||||||||||
| 63 | 'ordinable' => 0 }, | ||||||||||
| 64 | { 'id' => 'entity_type', | ||||||||||
| 65 | 'label' => 'Entity', | ||||||||||
| 66 | 'ordinable' => 1 }, | ||||||||||
| 67 | { 'id' => 'published', | ||||||||||
| 68 | 'label' => 'Status', | ||||||||||
| 69 | 'ordinable' => 1 } | ||||||||||
| 70 | ); | ||||||||||
| 71 | 1 | return \@fields; | |||||||||
| 72 | } | ||||||||||
| 73 | sub custom_list_template | ||||||||||
| 74 | 2 | ▶ | { | ||||||||
|
Subroutine
custom_list_template: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 75 | 2 | return $views_path . "/admin/rss/rss_list_block.tt"; | |||||||||
| 76 | } | ||||||||||
| 77 | sub custom_snippet_add_position | ||||||||||
| 78 | 1 | ▶ | { | ||||||||
|
Subroutine
custom_snippet_add_position: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 79 | 1 | return "right"; | |||||||||
| 80 | } | ||||||||||
| 81 | sub custom_add_snippet | ||||||||||
| 82 | 0 | ▶ | { | ||||||||
|
Subroutine
custom_add_snippet: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||
| 83 | 0 | my $self = shift; | |||||||||
| 84 | 0 | ▶ | if(ref($self)) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | { | ||||||||||
| 86 | 0 | my @languages; | |||||||||
| 87 | 0 | ▶ | if(config->{Strehler}->{languages}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | { | ||||||||||
| 89 | 0 | @languages = @{config->{Strehler}->{languages}}; | |||||||||
| 90 | } | ||||||||||
| 91 | else | ||||||||||
| 92 | { | ||||||||||
| 93 | 0 | @languages = ('en'); | |||||||||
| 94 | } | ||||||||||
| 95 | 0 | my $explain = q{ | |||||||||
| 96 | <p>Link to RSS, you can copy them from here and use them on the frontend</p> | ||||||||||
| 97 | <p>If you want to click them, remember that they'll work only if the RSS Channel is published.</p> | ||||||||||
| 98 | }; | ||||||||||
| 99 | 0 | my $explain_default = q{ | |||||||||
| 100 | <p>Default RSS is the RSS in the default language</p> | ||||||||||
| 101 | }; | ||||||||||
| 102 | 0 | my $default_language = config->{Strehler}->{default_language}; | |||||||||
| 103 | 0 | my $default_link = "/rss/" . $self->get_attr_multilang('slug', $default_language) . ".xml"; | |||||||||
| 104 | 0 | my $out = "<h3>Links to RSS</h3>" . $explain . | |||||||||
| 105 | "<h5>Default</h5>" . $explain_default . | ||||||||||
| 106 | "<ul><li><a href=\"$default_link\">$default_link</a></li></ul>" . | ||||||||||
| 107 | "<h5>By language</h5><ul>"; | ||||||||||
| 108 | 0 | foreach my $lang (@languages) | |||||||||
| 109 | { | ||||||||||
| 110 | 0 | ▶ | if($self->get_attr_multilang('slug', $lang)) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 111 | { | ||||||||||
| 112 | 0 | my $link = "/rss/$lang/" . $self->get_attr_multilang('slug', $lang) . ".xml"; | |||||||||
| 113 | 0 | $out .= "<li>$lang: <a href=\"$link\">$link</a></li>" | |||||||||
| 114 | } | ||||||||||
| 115 | } | ||||||||||
| 116 | 0 | $out .= "</ul>"; | |||||||||
| 117 | 0 | return $out; | |||||||||
| 118 | } | ||||||||||
| 119 | else | ||||||||||
| 120 | { | ||||||||||
| 121 | 0 | return undef; | |||||||||
| 122 | } | ||||||||||
| 123 | } | ||||||||||
| 124 | |||||||||||
| 125 | sub install | ||||||||||
| 126 | 0 | ▶ | { | ||||||||
|
Subroutine
install: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 127 | 0 | my $self = shift; | |||||||||
| 128 | 0 | my $dbh = shift; | |||||||||
| 129 | 0 | $self->deploy_entity_on_db($dbh, ["Strehler::Schema::RSS::Result::Rsschannel", "Strehler::Schema::RSS::Result::RsschannelHeader"]); | |||||||||
| 130 | 0 | my $package_root = __FILE__; | |||||||||
| 131 | 0 | $package_root =~ s/RSSChannel\.pm$//; | |||||||||
| 132 | 0 | my $statics = $package_root . "../../public"; | |||||||||
| 133 | 0 | my $configured_public_directory = Strehler::Helpers::public_directory(); | |||||||||
| 134 | 0 | my $resource_file = 'rsschannel.js'; | |||||||||
| 135 | 0 | my $copy_from = $statics . "/strehler/js/" . $resource_file; | |||||||||
| 136 | 0 | my $copy_to = $configured_public_directory . "/strehler/js/" . $resource_file; | |||||||||
| 137 | 0 | ▶ | if(-f $copy_to) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 138 | { | ||||||||||
| 139 | 0 | chmod 777, $copy_to; | |||||||||
| 140 | 0 | unlink $copy_to; | |||||||||
| 141 | } | ||||||||||
| 142 | 0 | ▶ | copy($copy_from, $copy_to) || print "Failing copying from $copy_from to $copy_to\nError: " . $! . "\n"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 143 | 0 | return "RSS Channel entity available!\n\nJavascript resources copied under public directory!\n\nDeploy of database tables completed\n\nCheck above for errors\n\nRun strehler schemadump to update your model\n\n"; | |||||||||
| 144 | } | ||||||||||
| 145 | sub get_link | ||||||||||
| 146 | 1 | ▶ | { | ||||||||
|
Subroutine
get_link: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||
| 147 | 1 | my $self = shift; | |||||||||
| 148 | 1 | my $entity = shift; | |||||||||
| 149 | 1 | my $category = shift; | |||||||||
| 150 | 1 | my $lang = shift; | |||||||||
| 151 | 1 | my $result = $self->get_list({ search => { entity_type => $entity }, | |||||||||
| 152 | category => $category, | ||||||||||
| 153 | language => $lang, | ||||||||||
| 154 | ext => 1 }); | ||||||||||
| 155 | 1 | ▶ | if(exists $result->{'to_view'}->[0]) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 156 | { | ||||||||||
| 157 | 1 | my $rss = $result->{'to_view'}->[0]; | |||||||||
| 158 | 1 | my $out = "/rss"; | |||||||||
| 159 | 1 | ▶ | if($lang) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 160 | { | ||||||||||
| 161 | 1 | $out .= "/" . $lang; | |||||||||
| 162 | } | ||||||||||
| 163 | 1 | $out .= "/" . $rss->{'slug'} . ".xml"; | |||||||||
| 164 | 1 | return $out; | |||||||||
| 165 | } | ||||||||||
| 166 | else | ||||||||||
| 167 | { | ||||||||||
| 168 | 0 | return undef; | |||||||||
| 169 | } | ||||||||||
| 170 | } | ||||||||||
| 171 | |||||||||||
| 172 | =encoding utf8 | ||||||||||
| 173 | |||||||||||
| 174 | =head1 NAME | ||||||||||
| 175 | |||||||||||
| 176 | Strehler::Element::RSS::RSSChannel - RSS Channel | ||||||||||
| 177 | |||||||||||
| 178 | =head1 DESCRIPTION | ||||||||||
| 179 | |||||||||||
| 180 | RSS Channel, configuration of a RSS Channel to erogate a feed based on Strehler entity. | ||||||||||
| 181 | |||||||||||
| 182 | =head1 INSTALLATION | ||||||||||
| 183 | |||||||||||
| 184 | strehler initentity Strehler::Element::RSS::RSSChannel | ||||||||||
| 185 | |||||||||||
| 186 | Entity installation will create two new database tables to store channels. You'll need a schemadump. | ||||||||||
| 187 | |||||||||||
| 188 | A new javascript will be added to your public directory. | ||||||||||
| 189 | |||||||||||
| 190 | =head1 ATTRIBUTES | ||||||||||
| 191 | |||||||||||
| 192 | Many attributes are related to RSS 2.0 attributes, as defined by RSS 2.0 Specification: L<http://www.rssboard.org/rss-specification> | ||||||||||
| 193 | |||||||||||
| 194 | =over 4 | ||||||||||
| 195 | |||||||||||
| 196 | =item B<link> | ||||||||||
| 197 | |||||||||||
| 198 | Link for the Channel | ||||||||||
| 199 | |||||||||||
| 200 | =item B<entity_type> | ||||||||||
| 201 | |||||||||||
| 202 | The entity that will be used to generate the RSS | ||||||||||
| 203 | |||||||||||
| 204 | =item B<category> | ||||||||||
| 205 | |||||||||||
| 206 | The category of the contents of the RSS | ||||||||||
| 207 | |||||||||||
| 208 | =item B<deep> | ||||||||||
| 209 | |||||||||||
| 210 | If true will be retrieved contens from the category and from its subcategories. | ||||||||||
| 211 | |||||||||||
| 212 | =item B<title_field> | ||||||||||
| 213 | |||||||||||
| 214 | The field (from selected entity) that will be used as title of the feed. | ||||||||||
| 215 | |||||||||||
| 216 | =item B<description_field> | ||||||||||
| 217 | |||||||||||
| 218 | The field (from selected entity) that will be used as description of the feed. This content will be encoded and used for the field <content:encoded> | ||||||||||
| 219 | |||||||||||
| 220 | =item B<link_field> | ||||||||||
| 221 | |||||||||||
| 222 | The field (from selected entity) that will be used in the link_template (see below) to build the content link | ||||||||||
| 223 | |||||||||||
| 224 | =item B<link_template> | ||||||||||
| 225 | |||||||||||
| 226 | The way the content is reached in the site is indepentent from Strehler, based on how the frontend has been designed. You can write here the template to build a link to the content. Where the link_field will be used write just '%%'. | ||||||||||
| 227 | |||||||||||
| 228 | =item B<order_by> | ||||||||||
| 229 | |||||||||||
| 230 | The way contents will be ordered (to decide most recent). | ||||||||||
| 231 | |||||||||||
| 232 | =item B<title> | ||||||||||
| 233 | |||||||||||
| 234 | Multilanguage field. | ||||||||||
| 235 | |||||||||||
| 236 | The title of the channel | ||||||||||
| 237 | |||||||||||
| 238 | =item B<description> | ||||||||||
| 239 | |||||||||||
| 240 | Multilanguage field. | ||||||||||
| 241 | |||||||||||
| 242 | The description of the channel. | ||||||||||
| 243 | |||||||||||
| 244 | =back | ||||||||||
| 245 | |||||||||||
| 246 | RSS Channel is a Slugged entity. (see L<Strehler::Element::Role::Slugged>). | ||||||||||
| 247 | |||||||||||
| 248 | =head1 METHODS | ||||||||||
| 249 | |||||||||||
| 250 | =over 4 | ||||||||||
| 251 | |||||||||||
| 252 | =item get_link | ||||||||||
| 253 | |||||||||||
| 254 | Arguments: $entity, $category, $language | ||||||||||
| 255 | |||||||||||
| 256 | Return Values: $link | ||||||||||
| 257 | |||||||||||
| 258 | Class method that can be used to retrieve a link to a RSS, considering an entity and a category. If no language is provided the default link is returned. | ||||||||||
| 259 | |||||||||||
| 260 | Warning: using $entity and $category a unique result is not guarantee. The method will however return the first value found in the database. | ||||||||||
| 261 | |||||||||||
| 262 | Link structure is the one from L<Strehler::RSS>. | ||||||||||
| 263 | |||||||||||
| 264 | =back | ||||||||||
| 265 | |||||||||||
| 266 | =cut | ||||||||||
| 267 | |||||||||||
| 268 | |||||||||||
| 269 | |||||||||||
| 270 | |||||||||||