Commit acdcd2a7 authored by Zot's avatar Zot

some more re-working of the chords addon/app to bring it more in line with and...

some more re-working of the chords addon/app to bring it more in line with and provide an example of current best practices, including using a custom Comanche layout and providing a plugin supplied widget.
parent 055c08ed
<?php
namespace Zotlabs\Module;
class Chords extends \Zotlabs\Web\Controller {
function get() {
$args = '';
$l = '';
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(isset($_POST['chord']) && strlen($_POST['chord']))
$args .= escapeshellarg(ucfirst(trim($_POST['chord'])));
if((strlen($args)) && (isset($_POST['tuning'])) && (strlen($_POST['tuning'])))
$args .= ' '.escapeshellarg($_POST['tuning']);
if((strlen($args)) && (isset($_POST['lefty'])))
$args .= ' lefty';
}
if((! $_POST['chord']) && argc() > 1) {
$_REQUEST['chord'] = argv(1);
$args = escapeshellarg(ucfirst(basename(argv(1))));
}
$tunings = [
'' => 'Em11 [Standard] (EADGBE)',
'openg' => 'G/D [Drop D] (DGDGBD)',
'opene' => 'Open E (EBEG#BE)',
'dadgad' => 'Dsus4 (DADGAD'
];
if(strlen($args)) {
$chords = '<pre>';
$chords .= shell_exec("addon/chords/chord ".$args);
$chords .= '</pre>';
}
$text .= <<< EOT
<p class="descriptive-text">
This is a fairly comprehensive and complete guitar chord dictionary which will list most of the available ways to play a certain chord, starting from the base of the fingerboard up to a few frets beyond the twelfth fret (beyond which everything repeats). A couple of non-standard tunings are provided for the benefit of slide players, etc.
<p />
<p class="descriptive-text">
Chord names start with a root note (A-G) and may include sharps (#) and flats (b). This software will parse most of the standard naming conventions such as maj, min, dim, sus(2 or 4), aug, with optional repeating elements.
</p>
<p class="descriptive-text">
Valid examples include A, A7, Am7, Amaj7, Amaj9, Ammaj7, Aadd4, Asus2Add4, E7b13b11 ...
</p>
EOT;
$o .= replace_macros(get_markup_template('chords.tpl','addon/chords'), [
'$header' => t('Guitar Chords'),
'$desc' => t('The complete online chord dictionary'),
'$text' => $text,
'$chords' => $chords,
'$tuning' => [ 'tuning', t('Tuning'), $_POST['tuning'], '', $tunings ],
'$chord' => [ 'chord', t('Chord name: example: Em7'), $_REQUEST['chord'], '' ],
'$lefty' => [ 'lefty', t('Show for left handed stringing'), $_POST['lefty'], '' ],
'$submit' => t('Submit'),
]
);
return $o;
}
}
......@@ -4,110 +4,44 @@
* Name: Chord Generator
* Description: Guitar Chord Generator Application
* Version: 1.0
* Author: Mike Macgirvin <mike@zothub.com>
* Author: Mike Macgirvin
* Maintainer: none
*/
require_once('addon/chords/Mod_Chords.php');
function chords_load() {
register_hook('app_menu', 'addon/chords/chords.php', 'chords_app_menu');
Zotlabs\Extend\Hook::register('load_pdl', 'addon/chords/chords.php', 'chords_pdl');
}
function chords_unload() {
unregister_hook('app_menu', 'addon/chords/chords.php', 'chords_app_menu');
Zotlabs\Extend\Hook::unregister_by_file('addon/chords/chords.php');
}
function chords_app_menu($a,&$b) {
$b['app_menu'][] = '<div class="app-title"><a href="chords">Guitar Chords</a></div>';
function chords_pdl(&$x) {
if($x['module'] === 'chords')
$x['layout'] = '[region=aside][widget=chords][/widget][/region]';
}
function widget_chords($args) {
function chords_module() {}
$keys = array('A','Bb','B', 'C','Db','D','Eb','E','F','Gb','G','Ab');
$chords = '<div class="widget"><h3>' . t('Quick Reference') . '</h3>';
function chords_content($a) {
$chords .= '<table border="1">';
$args = '';
$l = '';
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(isset($_POST['chord']) && strlen($_POST['chord']))
$args .= escapeshellarg(ucfirst(trim($_POST['chord'])));
if((strlen($args)) && (isset($_POST['tuning'])) && (strlen($_POST['tuning'])))
$args .= ' '.escapeshellarg($_POST['tuning']);
if((strlen($args)) && (isset($_POST['lefty'])))
$args .= ' lefty';
}
if((! $_POST['chord']) && argc() > 1) {
$_REQUEST['chord'] = argv(1);
$args = escapeshellarg(ucfirst(basename(argv(1))));
}
$tunings = [
'' => 'Em11 [Standard] (EADGBE)',
'openg' => 'G/D [Drop D] (DGDGBD)',
'opene' => 'Open E (EBEG#BE)',
'dadgad' => 'Dsus4 (DADGAD'
];
if(strlen($args)) {
$chords = '<pre>';
$chords .= shell_exec("addon/chords/chord ".$args);
$chords .= '</pre>';
foreach($keys as $k) {
$chords .= '<tr>';
$chords .= "<td><a href=\"chords/$k\"> $k </a></td>";
$chords .= "<td><a href=\"chords/{$k}m\"> {$k}m </a></td>";
$chords .= "<td><a href=\"chords/{$k}7\"> {$k}7 </a></td>";
$chords .= '</tr>';
}
else {
$chords .= <<< EOT
<p class="descriptive-text">
This is a fairly comprehensive and complete guitar chord dictionary which will list most of the available ways to play a certain chord, starting from the base of the fingerboard up to a few frets beyond the twelfth fret (beyond which everything repeats). A couple of non-standard tunings are provided for the benefit of slide players, etc.
<p />
<p class="descriptive-text">
Chord names start with a root note (A-G) and may include sharps (#) and flats (b). This software will parse most of the standard naming conventions such as maj, min, dim, sus(2 or 4), aug, with optional repeating elements.
</p>
<p class="descriptive-text">
Valid examples include A, A7, Am7, Amaj7, Amaj9, Ammaj7, Aadd4, Asus2Add4, E7b13b11 ...
</p>
Quick Reference:<br />
EOT;
$keys = array('A','Bb','B', 'C','Db','D','Eb','E','F','Gb','G','Ab');
$chords .= '<table border="1">';
$chords .= "<tr>";
foreach($keys as $k)
$chords .= "<td><a href=\"chords/$k\"> $k </a></td>";
$chords .= "</tr><tr>";
foreach($keys as $k)
$chords .= "<td><a href=\"chords/{$k}m\"> {$k}m </a></td>";
$chords .= "</tr><tr>";
foreach($keys as $k)
$chords .= "<td><a href=\"chords/{$k}7\"> {$k}7 </a></td>";
$chords .= "</tr>";
$chords .= "</table>";
$chords .= '</table></div>';
}
$o .= replace_macros(get_markup_template('chords.tpl','addon/chords'), [
'$header' => t('Guitar Chords'),
'$desc' => t('The complete online chord dictionary'),
'$chords' => $chords,
'$tuning' => [ 'tuning', t('Tuning'), $_POST['tuning'], '', $tunings ],
'$chord' => [ 'chord', t('Chord name: example: Em7'), $_REQUEST['chord'], '' ],
'$lefty' => [ 'lefty', t('Show for left handed stringing'), $_POST['lefty'], '' ],
'$submit' => t('Submit'),
]
);
return $o;
return $chords;
}
......@@ -116,7 +50,3 @@ $chords .= "</table>";
......@@ -2,7 +2,10 @@
<div>{{$desc}}</div>
<br /><br />
<br />
{{$text}}
<br />
<form action="chords" method="post">
{{include file="field_input.tpl" field=$chord}}
{{include file="field_select.tpl" field=$tuning}}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment