This repository has been archived by the owner on Jan 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b491ccd
commit 4264696
Showing
3 changed files
with
268 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,70 @@ | ||
# region-halland-acf-page-rss-links | ||
Hämta rss-flöden | ||
# Hämta RSS-flöden | ||
|
||
## Hur man använder Region Hallands plugin "region-halland-acf-page-rss-links" | ||
|
||
Nedan följer instruktioner hur du kan använda pluginet "region-halland-acf-page-rss-links". | ||
|
||
|
||
## Användningsområde | ||
|
||
Denna plugin hämtar valfritt rss-flöde | ||
|
||
|
||
## Installation och aktivering | ||
|
||
```sh | ||
A) Hämta pluginen via Git eller läs in det med Composer | ||
B) Installera Region Hallands plugin i Wordpress plugin folder | ||
C) Aktivera pluginet inifrån Wordpress admin | ||
``` | ||
|
||
|
||
## Hämta hem pluginet via Git | ||
|
||
```sh | ||
git clone https://github.com/RegionHalland/region-halland-acf-page-rss-links.git | ||
``` | ||
|
||
|
||
## Läs in pluginen via composer | ||
|
||
Dessa två delar behöver du lägga in i din composer-fil | ||
|
||
Repositories = var pluginen är lagrad, i detta fall på github | ||
|
||
```sh | ||
"repositories": [ | ||
{ | ||
"type": "vcs", | ||
"url": "https://github.com/RegionHalland/region-halland-acf-page-rss-links.git" | ||
}, | ||
], | ||
``` | ||
Require = anger vilken version av pluginen du vill använda, i detta fall version 1.0.0 | ||
|
||
OBS! Justera så att du hämtar aktuell version. | ||
|
||
```sh | ||
"require": { | ||
"regionhalland/region-halland-acf-page-rss-links": "1.0.0" | ||
}, | ||
``` | ||
|
||
|
||
## Visa länken i en i-frame via "Blade" | ||
|
||
```sh | ||
@php($myData = get_region_halland_acf_page_rss_link_items()) | ||
<h3>{{$myData['title']}}</h3><br> | ||
@foreach ($myData['rss'] as $data) | ||
<a href="{{ $data['link'] }}"><strong>{!! $data['title'] !!}</strong></a><br> | ||
<p>{{ $data['description'] }}</p> | ||
<p><i>{{ $data['date'] }}</i></p><br> | ||
@endforeach | ||
``` | ||
## Versionhistorik | ||
### 1.0.0 | ||
- Första version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "regionhalland/region-halland-acf-page-rss-links", | ||
"description": "Hämta RSS-flöden", | ||
"type": "wordpress-plugin", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Roland Hydén", | ||
"email": "Roland.Hyden@Regionhalland.se" | ||
} | ||
], | ||
"require": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
<?php | ||
|
||
/** | ||
* @package Region Halland ACF Page RSS Link | ||
*/ | ||
/* | ||
Plugin Name: Region Halland ACF Page RSS Link | ||
Description: ACF-fält för länk till RSS-flöde | ||
Version: 1.0.0 | ||
Author: Roland Hydén | ||
License: MIT | ||
Text Domain: regionhalland | ||
*/ | ||
|
||
// Anropa function om ACF är installerad | ||
add_action('acf/init', 'my_acf_add_page_rss_link_field_groups'); | ||
|
||
// Function för att lägga till "field groups" | ||
function my_acf_add_page_rss_link_field_groups() { | ||
|
||
// Om funktionen existerar | ||
if (function_exists('acf_add_local_field_group')): | ||
|
||
// Skapa formlärfält | ||
acf_add_local_field_group(array( | ||
|
||
'key' => 'group_2000200', | ||
'title' => 'RSS-flöde', | ||
'fields' => array( | ||
0 => array( | ||
'key' => 'field_1000205', | ||
'label' => 'Namn på RSS-flöde', | ||
'name' => 'name_1000206', | ||
'type' => 'text', | ||
'instructions' => '', | ||
'required' => 0, | ||
'conditional_logic' => 0, | ||
'wrapper' => [ | ||
'width' => '', | ||
'class' => '', | ||
'id' => '', | ||
], | ||
'default_value' => '', | ||
'placeholder' => '', | ||
'prepend' => '', | ||
'append' => '', | ||
'maxlength' => '', | ||
), | ||
1 => array( | ||
'key' => 'field_1000207', | ||
'label' => 'Url till RSS-flöde', | ||
'name' => 'name_1000208', | ||
'type' => 'url', | ||
'instructions' => '', | ||
'required' => 0, | ||
'conditional_logic' => 0, | ||
'wrapper' => [ | ||
'width' => '', | ||
'class' => '', | ||
'id' => '', | ||
], | ||
'default_value' => '', | ||
'placeholder' => '', | ||
), | ||
2 => array( | ||
'key' => 'field_1000209', | ||
'label' => 'Antal rss-poster', | ||
'name' => 'name_1000210', | ||
'type' => 'number', | ||
'instructions' => 'Ange antal rss-poster', | ||
'required' => 0, | ||
'conditional_logic' => 0, | ||
'wrapper' => [ | ||
'width' => '', | ||
'class' => '', | ||
'id' => '', | ||
], | ||
'default_value' => '', | ||
'placeholder' => '', | ||
'prepend' => '', | ||
'append' => '', | ||
'min' => '', | ||
'max' => '', | ||
'step' => '', | ||
), | ||
), | ||
'location' => array( | ||
0 => array( | ||
0 => array( | ||
'param' => 'post_type', | ||
'operator' => '==', | ||
'value' => 'page', | ||
), | ||
) | ||
), | ||
'menu_order' => 0, | ||
'position' => 'normal', | ||
'style' => 'default', | ||
'label_placement' => 'top', | ||
'instruction_placement' => 'label', | ||
'hide_on_screen' => '', | ||
'active' => 1, | ||
'description' => '', | ||
)); | ||
|
||
endif; | ||
|
||
} | ||
|
||
// Hämta ut rss-länkar | ||
function get_region_halland_acf_page_rss_link_items() { | ||
|
||
// Rss-sidans title | ||
$myRssTitle = get_field('name_1000206'); | ||
|
||
// Rss-url | ||
$myRssUrl = get_field('name_1000208'); | ||
|
||
// Hur många poster som ska visas | ||
$myRssAntal = intval(get_field('name_1000210')); | ||
|
||
// Koppla upp nytt DOM-document | ||
$myRss = new DOMDocument(); | ||
$myRss->load($myRssUrl); | ||
|
||
// Tmp-array för feeds | ||
$myFeeds = array(); | ||
|
||
// Räknare | ||
$myAntal = 0; | ||
|
||
// Loopa igenom alla poster | ||
foreach ($myRss->getElementsByTagName('item') as $myNode) { | ||
$myItem = array ( | ||
'title' => $myNode->getElementsByTagName('title')->item(0)->nodeValue, | ||
'link' => $myNode->getElementsByTagName('link')->item(0)->nodeValue, | ||
'description' => $myNode->getElementsByTagName('description')->item(0)->nodeValue, | ||
'date' => get_region_halland_page_rss_link_fix_date($myNode->getElementsByTagName('date')->item(0)->nodeValue), | ||
); | ||
|
||
// Pusha variabler tillbaka till Tmp-arrayen | ||
array_push($myFeeds, $myItem); | ||
|
||
// Iterera räknaren | ||
$myAntal++; | ||
|
||
// Om antal är valt och antal är uppnått, bryt foreach | ||
if ($myRssAntal <> 0) { | ||
if ($myAntal == $myRssAntal) { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
// Array för att samla ihop data | ||
$myData = array(); | ||
$myData['title'] = $myRssTitle; | ||
$myData['rss'] = $myFeeds; | ||
|
||
// Returnera data | ||
return $myData; | ||
|
||
} | ||
|
||
function get_region_halland_page_rss_link_fix_date($date) { | ||
return str_replace("T", " ", substr($date,0,16)); | ||
} | ||
|
||
|
||
// Metod som anropas när pluginen aktiveras | ||
function region_halland_acf_page_rss_link_activate() { | ||
} | ||
|
||
// Metod som anropas när pluginen avaktiveras | ||
function region_halland_acf_page_rss_link_deactivate() { | ||
// Ingenting just nu... | ||
} | ||
|
||
// Vilken metod som ska anropas när pluginen aktiveras | ||
register_activation_hook( __FILE__, 'region_halland_acf_page_rss_link_activate'); | ||
|
||
// Vilken metod som ska anropas när pluginen avaktiveras | ||
register_deactivation_hook( __FILE__, 'region_halland_acf_page_rss_link_deactivate'); | ||
|
||
?> |