Skip to content

Commit

Permalink
Better code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
RexDude committed Nov 15, 2015
1 parent 41d3790 commit 5f9a900
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 69 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ Features
* Ausgabe einer Breadcrumb Navigation möglich
* Codebeispiele in der Hilfe des Addons

Codebeispiele
-------------

Die Codebeispiele sind direkt im Addon als Menüpunkt aufrufbar. Alternativ im `docs` Ordner des Addons.

Hinweise
--------

* Getestet mit REDAXO 4.6
* AddOn-Ordner lautet: `navigation_factory`

Codebeispiele
-------------

siehe [CODEEXAMPLES.md](CODEEXAMPLES.md)

Changelog
---------

Expand Down
12 changes: 9 additions & 3 deletions classes/class.rex_navigation_factory_utils.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,21 @@ public static function convertVarType($originalValue, $newValue) {
}
}

public static function getHtmlFromMDFile($mdFile, $search = array(), $replace = array(), $setBreaksEnabled = true) {
public static function getHtmlFromMDFile($mdFile, $search = array(), $replace = array(), $setBreaksEnabled = true, $useDocsDir = false) {
global $REX;

$curLocale = strtolower($REX['LANG']);

if ($useDocsDir) {
$rootPath = $REX['INCLUDE_PATH'] . '/addons/navigation_factory/docs/';
} else {
$rootPath = $REX['INCLUDE_PATH'] . '/addons/navigation_factory/';
}

if ($curLocale == 'de_de') {
$file = $REX['INCLUDE_PATH'] . '/addons/navigation_factory/' . $mdFile;
$file = $rootPath . $mdFile;
} else {
$file = $REX['INCLUDE_PATH'] . '/addons/navigation_factory/lang/' . $curLocale . '/' . $mdFile;
$file = $rootPath . 'lang/' . $curLocale . '/' . $mdFile;
}

if (file_exists($file)) {
Expand Down
3 changes: 2 additions & 1 deletion config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
if ($REX['REDAXO']) {
// add subpages
$REX['ADDON']['navigation_factory']['SUBPAGES'] = array(
array('', $I18N->msg('navigation_factory_help'))
array('', $I18N->msg('navigation_factory_codeexamples')),
array('help', $I18N->msg('navigation_factory_help'))
);

// add css/js files to page header
Expand Down
15 changes: 15 additions & 0 deletions docs/rex_breadcrumb_nav.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Breadcrumb Navigation
=====================

Ausgabe einer Breadcrumb Navigation
-----------------------------------

```php
$breadcrumbNav = new rex_breadcrumb_nav();

$nav->setCssClass("breadcrumb"); // ul klasse: "breadcrumb"
$nav->setOlList(false); // es wird eine ul liste ausgegeben
$nav->setStartArticleName("<i class='fa fa-home'></i>"); // ausgabe mit font-awesome icon

echo $breadcrumbNav->getNavigation();
```
19 changes: 19 additions & 0 deletions docs/rex_lang_nav.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Sprachnavigation
================

Ausgabe einer einfachen Sprachnavigation
----------------------------------------

```php
$langNav = new rex_lang_nav();

$nav->setUlId("lang-nav"); // ul id: "lang-nav"
$nav->setUlClass("my-lang-class"); // ul class: "my-lang-class"
$nav->setselectedClass("current"); // li klasse für selektierten menüpunkt: "current"
$nav->setshowLiIds(true); // zusätzliche, eindeutige li id's werden ausgegeben
$nav->sethideLiIfOfflineArticle(false); // bei einem offline artikel li nicht verstecken sondern auf startartikel der website verlinken
$nav->setuseLangCodeAsLinkText(true); // langcode anstelle sprachname als linktext ausgeben
$nav->setupperCaseLinkText(true); // linktext in großbuchstaben anzeigen

echo $langNav->getNavigation();
```
46 changes: 9 additions & 37 deletions CODEEXAMPLES.md → docs/rex_nav.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Codebeispiele
=============
Hauptnavigation
===============

Ausgabe des 1. Navigationslevels
--------------------------------
Expand Down Expand Up @@ -39,17 +39,17 @@ echo $nav->getNavigation();
```


Alle Methoden und Paramater der rex_nav Klasse
----------------------------------------------
Alle möglichen Methoden und Paramater der rex_nav Klasse
--------------------------------------------------------

```php
$nav = new rex_nav();

$nav->setStartCategory(42);
$nav->setLevelDepth(2); // 2 level tief
$nav->setShowAll(true); // alle unterebenen werden angezeigt
$nav->setIgnoreOfflines(true); // offline artikel werden nicht angezeigt
$nav->setHideWebsiteStartArticle(false); // startartikel der website wird nicht ausgeblendet
$nav->setIgnoreOfflines(false); // offline artikel werden angezeigt
$nav->setHideWebsiteStartArticle(true); // startartikel der website wird ausgeblendet
$nav->setHideIds(array(42, 108)); // kategorien mit ids 42 und 108 werden ausgeblendet
$nav->setSelectedClass("current"); // li klasse für selektierte menüpunkte: "current"
$nav->setActiveClass("current active"); // li klasse für gerade aktiven menüpunkt: "current active"
Expand All @@ -60,43 +60,15 @@ $nav->setLiIdFromMetaField("cat_css_id"); // li id aus metainfo feld: "cat_css_i
$nav->setLiClassFromMetaField("cat_css_class"); // li klasse aus metainfo feld: "cat_css_class"
$nav->setLiIdFromCategoryId(array(42 => "foo", 108 => "bar")); // li id anhand artikel id
$nav->setLiClassFromCategoryId(array(42 => "the-class")); // li klasse anhand artikel id
$nav->setCustomLink(function($cat, $depth) { // php funktion die den link zurückgibt (hier als beispiel: erste ebene ohne verlinkung)
$nav->setCustomLink(function($cat, $depth) { // gesamter link anhand php funktion
if ($depth == 1) {
// hier als beispiel: erste ebene ohne verlinkung
return htmlspecialchars($cat->getName());
} else {
// alle anderen ebenen werden normal verlinkt
return '<a href="' . $cat->getUrl() . '">' . htmlspecialchars($cat->getName()) . '</a>';
}
});

echo $nav->getNavigation();
```

Ausgabe einer einfachen Sprachnavigation
----------------------------------------

```php
$langNav = new rex_lang_nav();

$nav->setUlId("lang-nav"); // ul id: "lang-nav"
$nav->setUlClass("my-lang-class"); // ul class: "my-lang-class"
$nav->setselectedClass("current"); // li klasse für selektierten menüpunkt: "current"
$nav->setshowLiIds(true); // zusätzliche, eindeutige li id's werden ausgegeben
$nav->sethideLiIfOfflineArticle(false); // bei einem offline artikel li nicht verstecken sondern auf startartikel der website verlinken
$nav->setuseLangCodeAsLinkText(true); // langcode anstelle sprachname als linktext ausgeben
$nav->setupperCaseLinkText(true); // linktext in großbuchstaben anzeigen

echo $langNav->getNavigation();
```

Ausgabe einer Breadcrumb Navigation
-----------------------------------

```php
$breadcrumbNav = new rex_breadcrumb_nav();

$nav->setCssClass("breadcrumb"); // ul klasse: "breadcrumb"
$nav->setOlList(false); // es wird eine ul liste ausgegeben
$nav->setStartArticleName("<i class='fa fa-home'></i>"); // ausgabe mit font-awesome icon

echo $breadcrumbNav->getNavigation();
```
21 changes: 4 additions & 17 deletions lang/de_de.lang
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
navigation_factory_addon_help =

navigation_factory_start = Start
navigation_factory_settings = Einstellungen
navigation_factory_setup = Setup
navigation_factory_codeexamples = Codebeispiele
navigation_factory_help = Hilfe

navigation_factory_start_title = Navigation Factory für REDAXO
navigation_factory_start_example_link_internal = Interner Beispiellink
navigation_factory_start_example_link_external = Externer Beispiellink
navigation_factory_codeexamples_chapter_rex_nav = Hauptnavigation
navigation_factory_codeexamples_chapter_rex_lang_nav = Sprachnavigation
navigation_factory_codeexamples_chapter_rex_breadcrumb_nav = Breadcrumb Navigation

navigation_factory_help_chapter_readme = Readme
navigation_factory_help_chapter_changelog = Changelog
navigation_factory_help_chapter_codeexamples = Codebeispiele
navigation_factory_help_chapter_license = Lizenz

navigation_factory_setup_step1 = Schritt 1: Mach dies
navigation_factory_setup_step1_desc1 = Beschreibungstext 1
navigation_factory_setup_step2 = Schritt 2: Mach das
navigation_factory_setup_step2_desc1 = Beschreibungstext 2
navigation_factory_setup_step3 = Schritt 3: Mach jenes
navigation_factory_setup_step3_desc1 = Beschreibungstext 3

navigation_factory_config_ok = Einstellungen wurden aktualisiert.
navigation_factory_config_error = Einstellungen konnte nicht gespeichert werden!
navigation_factory_install_make_dir = Der Ordner "/redaxo/include/{0}/" kann nicht angelegt werden, überprüfen Sie die Schreibrechte oder legen Sie den Ordner von Hand an und geben ihm Schreibrechte.
navigation_factory_install_perm_dir = Der Ordner "/redaxo/include/{0}/" benötigt Schreibrechte!

navigation_factory_settings_foo = Foo
navigation_factory_settings_foo2 = Foo2
navigation_factory_settings_save = Einstellungen speichern
73 changes: 73 additions & 0 deletions pages/codeexamples.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

$mypage = rex_request('page','string');
$subpage = rex_request('subpage', 'string');
$chapter = rex_request('chapter', 'string');
$func = rex_request('func', 'string');

if ($chapter == '') {
$chapter = '';
}

// include markdwon parser
if (!class_exists('Parsedown')) {
require($REX['INCLUDE_PATH'] . '/addons/navigation_factory/classes/class.parsedown.inc.php');
}

// chapters
$chapterpages = array (
'' => array($I18N->msg('navigation_factory_codeexamples_chapter_rex_nav'), 'pages/codeexamples/rex_nav.inc.php'),
'rex_lang_nav' => array($I18N->msg('navigation_factory_codeexamples_chapter_rex_lang_nav'), 'pages/codeexamples/rex_lang_nav.inc.php'),
'rex_breadcrumb_nav' => array($I18N->msg('navigation_factory_codeexamples_chapter_rex_breadcrumb_nav'), 'pages/codeexamples/rex_breadcrumb_nav.inc.php')
);

// build chapter navigation
$chapternav = '';

foreach ($chapterpages as $chapterparam => $chapterprops) {
if ($chapterprops[0] != '') {
if ($chapter != $chapterparam) {
$chapternav .= ' | <a href="?page=' . $mypage . '&amp;subpage=' . $subpage . '&amp;chapter=' . $chapterparam . '">' . $chapterprops[0] . '</a>';
} else {
$chapternav .= ' | <a class="rex-active" href="?page=' . $mypage . '&amp;subpage=' . $subpage . '&amp;chapter=' . $chapterparam . '">' . $chapterprops[0] . '</a>';
}
}
}
$chapternav = ltrim($chapternav, " | ");

// build chapter output
$addonroot = $REX['INCLUDE_PATH']. '/addons/'.$mypage.'/';
$source = $chapterpages[$chapter][1];

// output
echo '
<div class="rex-addon-output" id="subpage-' . $subpage . '">
<h2 class="rex-hl2" style="font-size:1em">' . $chapternav . '</h2>
<div class="rex-addon-content">
<div class= "addon-template">
';

include($addonroot . $source);

echo '
</div>
</div>
</div>';

?>

<script type="text/javascript">
jQuery(document).ready(function($) {
// make external links clickable
$("#subpage-help").delegate("a", "click", function(event) {
var host = new RegExp("/" + window.location.host + "/");

if (!host.test(this.href)) {
event.preventDefault();
event.stopPropagation();

window.open(this.href, "_blank");
}
});
});
</script>
4 changes: 4 additions & 0 deletions pages/codeexamples/rex_breadcrumb_nav.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

echo rex_navigation_factory_utils::getHtmlFromMDFile('rex_breadcrumb_nav.md', array(), array(), true, true);

4 changes: 4 additions & 0 deletions pages/codeexamples/rex_lang_nav.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

echo rex_navigation_factory_utils::getHtmlFromMDFile('rex_lang_nav.md', array(), array(), true, true);

4 changes: 4 additions & 0 deletions pages/codeexamples/rex_nav.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

echo rex_navigation_factory_utils::getHtmlFromMDFile('rex_nav.md', array(), array(), true, true);

1 change: 0 additions & 1 deletion pages/help.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
$chapterpages = array (
'' => array($I18N->msg('navigation_factory_help_chapter_readme'), 'pages/help/readme.inc.php'),
'changelog' => array($I18N->msg('navigation_factory_help_chapter_changelog'), 'pages/help/changelog.inc.php'),
'codeexamples' => array($I18N->msg('navigation_factory_help_chapter_codeexamples'), 'pages/help/codeexamples.inc.php'),
'license' => array($I18N->msg('navigation_factory_help_chapter_license'), 'pages/help/license.inc.php'),
);

Expand Down
4 changes: 0 additions & 4 deletions pages/help/codeexamples.inc.php

This file was deleted.

2 changes: 1 addition & 1 deletion pages/index.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

// if no subpage specified, use this one
if ($subpage == '') {
$subpage = 'help';
$subpage = 'codeexamples';
}

// layout top
Expand Down

0 comments on commit 5f9a900

Please sign in to comment.