Skip to content

Commit

Permalink
Form's names changed and user variables added
Browse files Browse the repository at this point in the history
Form names changed to ‘type.name.ext’ (see theme discussions on the
forum);
user variables added to replace adi_variables and manage theme prefs.
  • Loading branch information
NicolasGraph committed Oct 31, 2015
1 parent ef464ee commit ce11cfd
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/Rah/Flat.php
Expand Up @@ -36,17 +36,20 @@ class Rah_Flat
public function __construct()
{
add_privs('prefs.rah_flat', '1');
add_privs('prefs.rah_flat_var', '1');
register_callback(array($this, 'install'), 'plugin_lifecycle.rah_flat', 'installed');
register_callback(array($this, 'uninstall'), 'plugin_lifecycle.rah_flat', 'deleted');

if (get_pref('rah_flat_path')) {

new Rah_Flat_Import_Variables('variables');
new Rah_Flat_Import_Prefs('prefs');
new Rah_Flat_Import_Sections('sections');
new Rah_Flat_Import_Pages('pages');
new Rah_Flat_Import_Forms('forms');
new Rah_Flat_Import_Styles('styles');

register_callback(array($this, 'injectVars'), 'pretext_end');
register_callback(array($this, 'endpoint'), 'textpattern');
register_callback(array($this, 'initWrite'), 'rah_flat.import');

Expand All @@ -57,6 +60,20 @@ public function __construct()
}
}

/**
* Inject Variables.
*/

public function injectVars()
{
global $variable;

$prefset = safe_rows('name, val', 'txp_prefs', 'event = "rah_flat_var"');
foreach ($prefset as $pref) {
$variable[$pref['name']] = $pref['val'];
}
}

/**
* Installer.
*/
Expand Down Expand Up @@ -86,6 +103,7 @@ public function install()
public function uninstall()
{
safe_delete('txp_prefs', "name like 'rah\_flat\_%'");
safe_delete('txp_prefs', "event like 'rah\_flat\_var%'");
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Rah/Flat/FormIterator.php
Expand Up @@ -33,15 +33,15 @@ class Rah_Flat_FormIterator extends Rah_Flat_TemplateIterator
* {@inheritdoc}
*/

protected $templateNamePattern = '/[a-z][a-z0-9_\-\.]{1,63}\.[a-z0-9]{1,28}\.[a-z0-9]+/i';
protected $templateNamePattern = '/[a-z0-9]{1,28}\.[a-z][a-z0-9_\-\.]{1,63}\.[a-z0-9]+/i';

/**
* {@inheritdoc}
*/

public function getTemplateName()
{
return pathinfo(pathinfo($this->getFilename(), PATHINFO_FILENAME), PATHINFO_FILENAME);
return pathinfo(pathinfo($this->getFilename(), PATHINFO_FILENAME), PATHINFO_EXTENSION);
}

/**
Expand All @@ -64,7 +64,7 @@ public function getTemplateName()

public function getTemplateType()
{
if ($type = pathinfo(pathinfo($this->getFilename(), PATHINFO_FILENAME), PATHINFO_EXTENSION)) {
if ($type = pathinfo(pathinfo(pathinfo($this->getFilename(), PATHINFO_BASENAME), PATHINFO_FILENAME), PATHINFO_FILENAME)) {
return $type;
}

Expand Down
92 changes: 92 additions & 0 deletions src/Rah/Flat/Import/Variables.php
@@ -0,0 +1,92 @@
<?php

/*
* rah_flat - Flat templates for Textpattern CMS
* https://github.com/gocom/rah_flat
*
* Copyright (C) 2014 Jukka Svahn
*
* This file is part of rah_flat.
*
* rah_flat is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, version 2.
*
* rah_flat is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rah_flat. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* Imports preferences.
*/

class Rah_Flat_Import_Variables extends Rah_Flat_Import_Prefs
{
/**
* {@inheritdoc}
*/

public function getPanelName()
{
return 'prefs';
}

/**
* {@inheritdoc}
*/

public function getTableName()
{
return 'txp_prefs';
}

/**
* {@inheritdoc}
*/

public function importTemplate(Rah_Flat_TemplateIterator $file)
{
extract(lAtts(array(
'value' => '',
'html' => 'text_input',
'position' => '',
), $file->getTemplateJSONContents(), false));

$name = $file->getTemplateName();

if (get_pref($name, false) === false) {
set_pref($name, $value, 'rah_flat_var', PREF_ADVANCED, $html, $position);
}
}

/**
* {@inheritdoc}
*/

public function dropRemoved(Rah_Flat_TemplateIterator $template)
{
$name = array();

while ($template->valid()) {
$name[] = "'".doSlash($template->getTemplateName())."'";
$template->next();
}

if ($name) {
safe_delete($this->getTableName(), 'event = "rah_flat_var" && name not in ('.implode(',', $name).')');
}
}

/**
* {@inheritdoc}
*/

public function dropPermissions()
{
}
}
5 changes: 5 additions & 0 deletions templates/variables/variable_1.json
@@ -0,0 +1,5 @@
{
"value": "1",
"html": "yesnoradio",
"position": 250
}

0 comments on commit ce11cfd

Please sign in to comment.