Skip to content

Commit

Permalink
Merge pull request #5 from ivinteractive/dev
Browse files Browse the repository at this point in the history
Add widget and register blueprint; Assets workflow update; Fixed undefined variable errors
  • Loading branch information
ivi-admin authored May 5, 2017
2 parents 5e3b285 + 565292e commit 61cfdfc
Show file tree
Hide file tree
Showing 12 changed files with 2,539 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules/*
37 changes: 37 additions & 0 deletions assets/blueprints/redirects.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php if(!defined('KIRBY')) exit ?>

title: Redirects
pages: false
options:
preview: false
delete: false
template: false
status: false
deletable: false
hide: true
files:
type:
- code
- document
fields:
title:
label: Title
type: text
redirects:
label: Redirects
type: structure
style: table
fields:
old:
label: Old URL
type: text
icon: times
new:
label: New URL
type: text
icon: check
external:
label: External
text: Is it an external link?
type: checkbox
icon: share
1 change: 1 addition & 0 deletions assets/css/redirecty.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/css/widget.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
var gulp = require('gulp'),
sass = require('gulp-sass'),
csso = require('gulp-csso'),
autoprefixer = require('gulp-autoprefixer'),
shorthand = require('gulp-shorthand'),
notify = require('gulp-notify'),
plumber = require('gulp-plumber'),
watch = require('gulp-watch'),
runSequence = require('run-sequence');

var paths = {
scss: './resources/scss',
css: './assets/css'
};

gulp.task('view', function() {

gulp.src(paths.scss + '/redirecty.scss')
.pipe(plumber({errorHandler: notify.onError("SASS error: <%= error.message %> in <%= error.filename %>")}))
.pipe(sass({
outputStyle: 'expanded',
}))
.pipe(csso())
.pipe(autoprefixer({
browsers: ['> 1%'],
cascade: false
}))
.pipe(gulp.dest(paths.css));

});

gulp.task('widget', function() {

gulp.src(paths.scss + '/widget.scss')
.pipe(plumber({errorHandler: notify.onError("SASS error: <%= error.message %> in <%= error.filename %>")}))
.pipe(sass({
outputStyle: 'expanded',
}))
.pipe(csso())
.pipe(autoprefixer({
browsers: ['> 1%'],
cascade: false
}))
.pipe(gulp.dest(paths.css));

});

gulp.task('sass', function() {
runSequence('view', 'widget');
});

gulp.task('default', function() {
gulp.watch(paths.scss + '/*.scss', ['view', 'widget']);
});
15 changes: 9 additions & 6 deletions lib/redirectyFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ function updatePage($pages, $redirect, $num, $changeList, $multilang, $dryrun, $
foreach($multilang as $lang):

// Don't do the default language yet - if you do the non-default language last, the title will get updated to that language's title
if($lang['default'])
if(isset($lang['default']) && $lang['default'])
continue;

$return = returnResponse($return, multiLangPage($page, $redirect, $field, $value, $return['num'], $return['changeList'], $lang, $dryrun, $case));
$return = returnResponse($return, multiLangPage($page, $redirect, $return['num'], $return['changeList'], $lang, $dryrun, $case));

endforeach;

foreach($multilang as $lang):

// Do the default language now
if($lang['default']):
$return = returnResponse($return, multiLangPage($page, $redirect, $field, $value, $return['num'], $return['changeList'], $lang, $dryrun, $case));
$return = returnResponse($return, multiLangPage($page, $redirect, $return['num'], $return['changeList'], $lang, $dryrun, $case));
break;

else:
Expand All @@ -40,7 +40,7 @@ function updatePage($pages, $redirect, $num, $changeList, $multilang, $dryrun, $

else:

$return = returnResponse($return, singleLangPage($page, $redirect, $field, $value, $return['num'], $return['changeList'], $dryrun, $case));
$return = returnResponse($return, singleLangPage($page, $redirect, $return['num'], $return['changeList'], $dryrun, $case));

endif;

Expand Down Expand Up @@ -69,7 +69,7 @@ function returnResponse($return, $result) {
}

// Make sure that when we update the page, we're doing it with the correct language (files ending in .en.txt, .de.txt, etc)
function multiLangPage($page, $redirect, $field, $value, $num, $changeList, $lang, $dryrun, $case) {
function multiLangPage($page, $redirect, $num, $changeList, $lang, $dryrun, $case) {

$response = '';

Expand Down Expand Up @@ -103,7 +103,7 @@ function multiLangPage($page, $redirect, $field, $value, $num, $changeList, $lan
}

// When there's no multilanguage setup (files ending in just .txt)
function singleLangPage($page, $redirect, $field, $value, $num, $changeList, $dryrun, $case) {
function singleLangPage($page, $redirect, $num, $changeList, $dryrun, $case) {

$response = '';

Expand Down Expand Up @@ -171,6 +171,9 @@ function redirectReplace($page, $old, $new, $field, $value, $num, $lang=false, $

endif;

if(!isset($strCount))
$strCount = 0;

return array(
'response' => $response,
'num' => $strCount,
Expand Down
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "redirecty",
"version": "1.0.0",
"main": "index.js",
"repository": "https://github.com/ivinteractive/kirbycms-redirects.git",
"author": "iv-craig <cs@ivinteractive.com>",
"license": "MIT",
"dependencies": {
"gulp": "^3.9.1",
"gulp-autoprefixer": "^3.1.1",
"gulp-csso": "^3.0.0",
"gulp-notify": "^3.0.0",
"gulp-plumber": "^1.1.0",
"gulp-sass": "^3.1.0",
"gulp-shorthand": "^1.1.0",
"gulp-watch": "^4.3.11",
"run-sequence": "^1.2.2"
}
}
5 changes: 4 additions & 1 deletion redirecty.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
$auth = false;
endif;

$kirby->set('blueprint', 'redirects', __DIR__ . DS . 'assets' . DS . 'blueprints' . DS . 'redirects.yaml');
$kirby->set('widget', 'redirecty', __DIR__ . DS . 'widgets' . DS . 'redirecty');

if(c::get('redirecty') && ($auth || c::get('redirecty-noauth',false))):

require_once(__DIR__ . DS . 'lib' . DS . 'redirectyFunctions.php');
Expand All @@ -26,7 +29,7 @@
$response.= '<head>';
$response.= css('https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700');
$response.= css('https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css');
$response.= '<style>'.file_get_contents(__DIR__ . DS . 'assets' . DS . 'redirecty.css').'</style>';
$response.= '<style>'.file_get_contents(__DIR__ . DS . 'assets' . DS . 'css' . DS . 'redirecty.css').'</style>';
$response.= '</head>';
$response.= '<body>';

Expand Down
58 changes: 29 additions & 29 deletions assets/redirecty.css → resources/scss/redirecty.scss
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
body {
font-family: "Source Sans Pro", sans-serif;
max-width: 1150px;
margin: 0 auto;
position: relative;
}
a {
text-decoration: none !important;
}
h1 {
margin: 20px 0 5px;
}
h2 {
margin: 0 0 25px;
}
h1, h2, h3 {
font-weight: normal;
}
.error {
font-size: 3em;
margin: 1em auto 0.5em;
display: block;
width: 0;
}

download {
position: absolute;
right: 0;
bottom: 0;
body {
font-family: "Source Sans Pro", sans-serif;
max-width: 1150px;
margin: 0 auto;
position: relative;
}
a {
text-decoration: none !important;
}
h1 {
margin: 20px 0 5px;
}
h2 {
margin: 0 0 25px;
}
h1, h2, h3 {
font-weight: normal;
}
.error {
font-size: 3em;
margin: 1em auto 0.5em;
display: block;
width: 0;
}

download {
position: absolute;
right: 0;
bottom: 0;
}
16 changes: 16 additions & 0 deletions resources/scss/widget.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#redirecty-widget {
td {
padding: 0.5em;
span {
display: block;
text-overflow: ellipsis;
overflow: hidden;
}
}
p {
margin: 0.75em 0 0.75em;
}
.btn {
margin-right: 0.75em;
}
}
50 changes: 50 additions & 0 deletions widgets/redirecty/redirecty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

$options = [
[
'text' => 'View all',
'icon' => 'pencil',
'link' => '/panel/pages/'.c::get('redirects-list-uri', 'redirects').'/edit'
]
];

if(c::get('redirecty'))
$options[] = [
'text' => 'Link replacer',
'icon' => 'copy',
'link' => url(c::get('redirecty-uri', 'redirecty')),
'target' => '_blank'
];

return array(
'title' => 'Redirecty',
'options' => $options,
'html' => function() {

$limit = c::get('redirecty-widget-count', 5);

$redirects = page(c::get('redirects-list-uri', 'redirects'))->redirects()->toStructure()->flip();

$count = $redirects->count() - $limit;
$redirects = $redirects->limit($limit);

$content = brick('style', file_get_contents(__DIR__ . DS . '..' . DS . '..' . DS . 'assets' . DS . 'css' . DS . 'widget.css'));

if($redirects->count()):
$content.= brick('p', 'Recently added redirects'.r($count, ' <em>('.$count.' more...)</em>', ''));
$content.= '<table class="structure-table"><thead><tr><th>Old</th><th>New</th></tr></thead>';
$content.= '<tbody>';

foreach($redirects as $redirect)
$content.= '<tr><td><span>'.$redirect->old()->value().'</span></td><td><span>'.$redirect->new()->value().'</span></td></tr>';

$content.= '</tbody></table>';
endif;

if(c::get('redirecty') && $redirects->count())
$content.= brick('p', brick('a', 'Download CSV', ['href'=>url(c::get('redirecty-csv','redirecty-csv')), 'class'=>'btn btn-rounded']) . brick('a', 'Download JSON', ['href'=>url(c::get('redirecty-json','redirecty-json')), 'class'=>'btn btn-rounded']));

return brick('div', $content, ['class'=>'redirecty-widget']);

}
);
Loading

0 comments on commit 61cfdfc

Please sign in to comment.