sirjeff 2 ay önce
işleme
960c7ca275

+ 15 - 0
.editorconfig

@@ -0,0 +1,15 @@
+# For more information about the properties used in this file,
+# please see the EditorConfig documentation:
+# http://editorconfig.org
+
+[*]
+charset = utf-8
+end_of_line = lf
+indent_size = 4
+indent_style = space
+insert_final_newline = true
+trim_trailing_whitespace = true
+
+[{*.yml,package.json}]
+indent_size = 2
+

+ 6 - 0
.travis.yml

@@ -0,0 +1,6 @@
+language: php
+php:
+  - 5.6
+  - 7.0
+  - 7.1
+  - 7.2

+ 1 - 0
_config.php

@@ -0,0 +1 @@
+<?php

+ 7 - 0
_config/config.yml

@@ -0,0 +1,7 @@
+---
+Name: linkage
+After:
+  - 'cms/*'
+---
+AdminRootController:
+  default_panel: 'LinkageAdmin'

+ 8 - 0
changelog.md

@@ -0,0 +1,8 @@
+
+Being a very small and simple SS Add-on, I've decided to use GitHubs
+commit log and history for change information.
+
+Should this project grow, I will start to maintain a change log of some sort.
+
+- cheers
+ Dwayne

+ 148 - 0
code/Linkage.php

@@ -0,0 +1,148 @@
+<?php
+
+/**
+ * Main Linkage object setup.
+ *
+ * Sets up the main Linkage object and create editable fields in the CMS.
+ *
+ * @author S.Dwayne Pivac, OMI Ltd.
+ *
+ */
+class Linkage extends DataObject
+{
+    private static $db = array(
+        'Title' => 'Text',
+        'URL' => 'Text',
+        'External' => 'Boolean',
+        'Sorder' => 'Varchar',
+    );
+    private static $summary_fields = array('HTMLDescription');
+    static $singular_name = 'Link';
+    static $plural_name = 'Links';
+    public static $default_sort = 'Sorder ASC';
+    function fieldLabels($includerelations = true)
+    {
+        $labels = parent::fieldLabels($includerelations);
+        $labels['HTMLDescription'] = 'Links';
+        return $labels;
+    }
+    private static $casting = array('HTMLDescription' => 'HTMLText');
+    function HTMLDescription()
+    {
+        return $this->getHTMLDescription();
+    }
+    public function getHTMLDescription()
+    {
+        $ShowExt = 'self';
+        if ($this->External) {
+            $ShowExt = 'blank';
+        }
+        $data = new ArrayData(array(
+            'ID' => $this->ID,
+            'Title' => $this->Title,
+            'URL' => $this->URL,
+            'ShowExt' => $ShowExt,
+        ));
+        $output = HTMLText::create();
+        $output->setValue($data->renderWith('Links'));
+        return $output;
+    }
+    public function getCMSfields(){
+        $f=FieldList::create(TabSet::create('Root'));
+        $f->addFieldToTab('Root.Main', TextField::create('Title', 'Link/button name'));
+        $f->addFieldToTab('Root.Main', TextField::create('URL', 'URL/Link'));
+        $f->addFieldToTab('Root.Main', CheckboxField::create('External', 'External linkage?')->setDescription('Open in a new window?'));
+        $f->addFieldToTab('Root.Main', TextField::create('Sorder', 'Sort Order')->setDescription('Links are sorted by this field using alphanumeric sorting. You can use numbers or letters.'));
+        return $f;
+    }
+}
+
+
+/**
+ * Create Linkage menu.
+ *
+ * Create the Linkage link on the 'Left' hand side of the ModelAdmin.
+ *
+ * @author S.Dwayne Pivac, OMI Ltd.
+ *
+ */
+class LinkageAdmin extends ModelAdmin
+{
+    private static $menu_title = 'Linkage';
+    private static $url_segment = 'linkage';
+    private static $managed_models = array('Linkage');
+    private static $menu_icon = 'linkage/img/linkage.gif';
+    private static $page_length = 50;
+    private static $menu_priority = 110;#2Do: can this be configurable?
+    private static $url_priority = 30;
+    public function init()
+    {
+        parent::init();
+        Requirements::css('linkage/css/linkage.css');
+    }
+    public function getEditForm($id=null, $fields=null)
+    {
+        $gridFieldTitle = 'Your Linkage';
+        $listField=GridField::create(
+            $this->sanitiseClassName($this->modelClass), $gridFieldTitle, $this->getList(),
+            $fieldConfig=GridFieldConfig_RecordViewer::create($this->stat('page_length'))
+                ->removeComponentsByType('GridFieldPageCount')
+                ->removeComponentsByType('GridFieldPaginator')
+                ->removeComponentsByType('GridFieldSortableHeader')
+                ->removeComponentsByType('GridFieldViewButton')
+                ->removeComponentsByType('GridFieldToolbarHeader')
+                ->addComponent(new GridFieldEditLinkage())
+                ->addComponent(new GridFieldAddNewButton())
+            );
+        return CMSForm::create(
+            $this, 
+            'EditForm', 
+            new FieldList($listField), 
+            new FieldList() 
+        )->setHTMLID('Form_EditForm')->addExtraClass('cms-edit-form cms-panel-padded center');
+    }
+}
+
+
+/**
+ * Linkage Edit Buttons.
+ *
+ * Custom Edit Buttons to avoid the default behaviour of linking via the GridField.
+ *
+ * @author S.Dwayne Pivac, OMI Ltd.
+ *
+ */
+class GridFieldEditLinkage implements GridField_ColumnProvider
+{
+
+    public function augmentColumns($gridField, &$columns) {
+        if(!in_array('Actions', $columns)) {
+            $columns[] = 'Actions';
+        }
+    }
+
+    public function getColumnAttributes($gridField, $record, $columnName) {
+        return array('class' => 'col-buttons');
+    }
+
+    public function getColumnMetadata($gridField, $columnName) {
+        if($columnName == 'Actions') {
+            return array('title' => '');
+        }
+    }
+
+    public function getColumnsHandled($gridField) {
+        return array('Actions');
+    }
+
+    public function getColumnContent($gridField, $record, $columnName) {
+        $data = new ArrayData(array(
+            'Link' => Controller::join_links($gridField->Link('item'), $record->ID, 'edit')
+        ));
+        return $data->renderWith('LinkageEditButton');
+    }
+
+}
+
+#~/linkage/code/Linkage.php
+

+ 26 - 0
composer.json

@@ -0,0 +1,26 @@
+{
+  "name": "sirjeff/linkage",
+  "description": "Linkage add-on for SilverStripe",
+  "type": "silverstripe-module",
+  "homepage": "https://github.com/sirjeff/linkage",
+  "keywords": ["silverstripe","url","links","speed dial","bookmarks","landing page"],
+  "license": "BSD-3-Clause",
+  "authors": [{
+    "name": "Dwayne",
+    "email": "dwayne@omi.nz",
+    "role": "Developer"
+  }],
+  "support": {"issues": "https://github.com/sirjeff/linkage/issues"},
+  "require": {
+    "silverstripe/cms": ">=3.0 <4.0",
+    "silverstripe/framework": ">=3.0 <4.0"
+  },
+  "extra": {
+    "installer-name": "linkage",
+    "screenshots": [
+      "img/SSv3.5.3.png",
+      "img/SSv3.1.10.png"
+    ]
+  }
+}
+

+ 12 - 0
contributing.md

@@ -0,0 +1,12 @@
+# Contributing
+
+Please feel free to contribute to this project.
+You can start by following it on GitHub : https://github.com/sirjeff/linkage (use the follow button)
+and we'll take it from there.
+
+If you don't use GitHub that's cool, please send me your code, code ideas, ideas or any goodies via email : sirjeff at omi dot nz
+
+- cheers
+ Dwayne
+
+

+ 23 - 0
css/linkage.css

@@ -0,0 +1,23 @@
+/* Linkage */
+
+h4.linkage{padding:0;margin:2px auto;width:100%;text-align:center}
+h4.linkage a{color:#222;display:inline-block;margin:0 auto;padding:3px 0;background:rgb(250,255,250);width:98%;text-align:center;border:solid 1px #999;line-height:1.5;border-radius:5px;}
+h4.linkage a:hover{background:rgb(245,250,245)}
+h4.linkage a img{margin-left:10px;vertical-align:sub;display:none}
+h4.linkage a img.blank{display:inline-block;opacity:0.3}
+
+.cms #Form_EditForm_Linkage table.ss-gridfield-table{margin-top:10px}
+
+.cms table.ss-gridfield-table tbody{background-color:transparent !important}
+.cms #Form_EditForm_Linkage table.ss-gridfield-table tr,
+.cms #Form_EditForm_Linkage table.ss-gridfield-table tr.even,
+.cms #Form_EditForm_Linkage table.ss-gridfield-table tr.odd{background-color:transparent !important}
+.cms #Form_EditForm_Linkage table.ss-gridfield-table td:last-child,
+.cms #Form_EditForm_Linkage table.ss-gridfield-table td:first-child,
+.cms #Form_EditForm_Linkage table.ss-gridfield-table tr td{border:0 none !important}
+
+td.col-HTMLDescription{padding:2px !important}
+td.col-buttons img{opacity:0.6;border:0;padding:0;margin:0;cursor:pointer}
+td.col-buttons img:hover{opacity:1}
+
+.cms #Form_EditForm_Linkage .ss-ui-button.ss-ui-action-constructive{position:absolute;bottom:10px;}

+ 19 - 0
docs/en/UserGuide.md

@@ -0,0 +1,19 @@
+# How to ..
+
+## Use this add-on
+
+Add, remove, modify your links in the CMS, under the "Linkage" link on the left-hand side menu.
+Your links should appear when you log into the CMS (as the default start page replacing "Pages")
+
+
+## Stop being the landing page...
+
+Ok then I will!!
+Remove the file `/linkage/_config/config.yml` and then flush your cache ?flush=all
+That'll do it.
+
+## Changing the HTML
+
+See `/linkage/templates/Includes/Links.ss`
+
+This uses SilverStripes templating language mixed with HTML

BIN
img/SSv3.1.10.png


BIN
img/SSv3.5.3.png


BIN
img/edit.gif


BIN
img/external.gif


BIN
img/linkage.gif


BIN
img/screen-grabs/SSv3.1.10.png


BIN
img/screen-grabs/SSv3.5.3.png


+ 24 - 0
license.md

@@ -0,0 +1,24 @@
+Copyright (c) 2019 Dwayne Pivac and OMI Ltd.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+    * Neither the name of OMI Ltd. nor the
+      names of its contributors may be used to endorse or promote products
+      derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL OMI LTD. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 69 - 0
readme.md

@@ -0,0 +1,69 @@
+# Linkage
+Linkage add-on for SilverStripe
+
+## Introduction
+
+Linkage is a very simple landing page SilverStripe add-on.
+
+It provides a place to add your own custom links that appear on the CMS landing page (GridField style).
+
+
+![Screenshot](https://github.com/sirjeff/linkage/blob/master/img/screen-grabs/SSv3.1.10.png)
+*ScreenShot from SilverStripe 3.1.10*
+
+
+![Screenshot](https://github.com/sirjeff/linkage/blob/master/img/screen-grabs/SSv3.5.3.png)
+*ScreenShot from SilverStripe 3.5.3 with a custom OMI Ltd. theme*
+
+Note: This is early days and the add-on is NOT all that 'flash' at the mo.
+
+Feel free to comment with ideas!
+
+## Requirements
+
+SilverStripe Framework 3.0+
+
+(No SilverStripe4 version available .... yet)
+
+## Installation
+
+Please follow the [standard module installation documentation](https://docs.silverstripe.org/en/3/developer_guides/extending/modules/)
+
+The module should reside in a top-level directory called `linkage/`
+
+Don't forget, no matter how you choose to install, once done you must build and flush `/dev/build?flush=all`
+
+### Manual
+- Download the latest (v1.0.0) version on Linkage
+- Unzip in the root directory of your project (that should be where all your SilverStripe files are (cms,framework,reports etc))
+- rename the Linkage directory to "linkage"
+- perform a little dance
+
+### Composer
+`composer require sirjeff/linkage 1.0.0`
+
+or if you don't have Composer you can download composer.phar and then run:
+
+`php composer.phar require sirjeff/linkage 1.1.0`
+
+Note: don't forget to change the version to the one which you're after,
+- dev-master Always the latest code ... can be risky but!
+- 1.0.0 The first version, not realy worth it.
+- 1.1.0 Major code tidy and minor style changes.
+
+## Issues
+There is a problem in the way the module holds focus in the CMS. I'm looking at this now ... it might mean that I cannot have linkage as the default landing page without the user having to modify their _config.yml file
+Please use the [issues](https://github.com/sirjeff/linkage/issues) link to add any bungness you find, or check to see what's going on in the funky functions world.
+
+## The Future...
+- Nicer look'n'feel
+- Settings such as 'Don't be default landing' or 'x Links per page'
+- Proper link adding. Currently they be text fields. Would prefer something more 'URL-esque'
+- Import and Export
+- URL test when adding a link
+
+## Maintainers
+
+Dwayne &lt;dwayne at omi dot nz&gt;
+
+OMI Ltd. &lt;adm at omi dot nz&gt;

+ 1 - 0
templates/Includes/LinkageEditButton.ss

@@ -0,0 +1 @@
+<img src="linkage/img/edit.gif" class="action action-detail edit-link" onclick='location.href="$Link"' border="0" alt="edit link">

+ 6 - 0
templates/Includes/Links.ss

@@ -0,0 +1,6 @@
+<h4 class="linkage">
+ <a href="$URL" target="_$ShowExt">
+  $Title<img class="$ShowExt" src="linkage/img/external.gif" border="0" alt="external link">
+ </a>
+</h4>
+