Skip to content

Commit

Permalink
add feature to have a shared options text file for all images in the …
Browse files Browse the repository at this point in the history
…same directory
  • Loading branch information
owzim committed Apr 18, 2015
1 parent 1c570b7 commit 05d80f5
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 44 deletions.
67 changes: 35 additions & 32 deletions Blick.module
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author Christian (owzim) Raunitschka <git@raunitschka.de>
* @copyright Copyright (c) 2015, Christian Raunitschka
*
* @version 0.7.0
* @version 0.8.0
*
* @filesource
*
Expand All @@ -31,6 +31,7 @@ class Blick extends Wire implements Module
'Versioning', 'VersioningFormat',
'Min', 'MinFormat',
'AppendNewLine',
'OptionsExtension', 'SharedOptionsName'
);

/**
Expand All @@ -50,7 +51,7 @@ class Blick extends Wire implements Module
return array(
'title' => 'Blick',
'summary' => 'A small helper module for including JS, CSS and image files',
'version' => '0.7.0',
'version' => '0.8.0',
'icon' => 'eye',
'requires' => array('PHP>=5.4','ProcessWire>=2.5.5'),
'singular' => true,
Expand Down Expand Up @@ -78,36 +79,38 @@ class Blick extends Wire implements Module
$urls = $config->urls;

return array(
'jsPath' => $paths->templates . 'scripts',
'jsUrl' => $urls->templates . 'scripts',
'jsMarkup' => '<script src="{url}" type="text/javascript" charset="utf-8"></script>',
'jsDefault' => 'markup',
'jsVersioning' => false,
'jsVersioningFormat' => '?v={version}',
'jsMin' => false,
'jsMinFormat' => "{file}.min.{ext}",

'cssPath' => $paths->templates . 'styles',
'cssUrl' => $urls->templates . 'styles',
'cssMarkup' => '<link href="{url}" rel="stylesheet" type="text/css">',
'cssDefault' => 'markup',
'cssVersioning' => false,
'cssVersioningFormat' => '?v={version}',
'cssMin' => false,
'cssMinFormat' => "{file}.min.{ext}",

'imgPath' => $paths->templates . 'images',
'imgUrl' => $urls->templates . 'images',
'imgMarkup' => '<img src="{url}" alt="{0}">',
'imgDefault' => 'markup',
'imgVariations' => array(),
'imgVariationSubDir' => 'variations',
'imgVersioning' => false,
'imgVersioningFormat' => '',
'imgMin' => false,
'imgMinFormat' => '',

'appendNewLine' => true,
'jsPath' => $paths->templates . 'scripts',
'jsUrl' => $urls->templates . 'scripts',
'jsMarkup' => '<script src="{url}" type="text/javascript" charset="utf-8"></script>',
'jsDefault' => 'markup',
'jsVersioning' => false,
'jsVersioningFormat' => '?v={version}',
'jsMin' => false,
'jsMinFormat' => "{file}.min.{ext}",

'cssPath' => $paths->templates . 'styles',
'cssUrl' => $urls->templates . 'styles',
'cssMarkup' => '<link href="{url}" rel="stylesheet" type="text/css">',
'cssDefault' => 'markup',
'cssVersioning' => false,
'cssVersioningFormat' => '?v={version}',
'cssMin' => false,
'cssMinFormat' => "{file}.min.{ext}",

'imgPath' => $paths->templates . 'images',
'imgUrl' => $urls->templates . 'images',
'imgMarkup' => '<img src="{url}" alt="{0}">',
'imgDefault' => 'markup',
'imgVariations' => array(),
'imgVariationSubDir' => 'variations',
'imgVersioning' => false,
'imgVersioningFormat' => '',
'imgMin' => false,
'imgMinFormat' => '',
'imgOptionsExtension' => 'txt',
'imgSharedOptionsName' => 'shared-options',

'appendNewLine' => true,
);
}

Expand Down
31 changes: 19 additions & 12 deletions owzim/blick/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @author Christian (owzim) Raunitschka <git@raunitschka.de>
* @copyright Copyright (c) 2015, Christian Raunitschka
*
* @version 0.4.0
* @version 0.5.0
*
* @filesource
*
Expand Down Expand Up @@ -291,25 +291,32 @@ public function height($n = 0, $options = array())
*/
protected function ___getTextOptions()
{
$config = \Blick::getConfig();
$imgConfig = $config->img;

$rtn = null;
$path = "{$this->dir}/{$this->name}";
$optsTxtFile = "$path.txt";
$fileOptsTxtFile = "$path.{$imgConfig->optionsExtension}";
$sharedOptsTxtFile = "{$this->dir}/{$imgConfig->sharedOptionsName}.{$imgConfig->optionsExtension}";

// save pased text options in a static array
static $textOptions = null;
if (is_null($textOptions)) $textOptions = array();
// return parsed options if already exist for that specific image
if (isset($textOptions[$optsTxtFile])) return $textOptions[$optsTxtFile];

if (file_exists($optsTxtFile)) {
$rtn = array();
$content = str_replace("\n", ',', trim(file_get_contents($optsTxtFile)));
$selectors = new \Selectors($content);
foreach ($selectors as $selector) {
$rtn[$selector->field] = $selector->value;
if (isset($textOptions[$fileOptsTxtFile])) return $textOptions[$fileOptsTxtFile];

foreach (array($sharedOptsTxtFile, $fileOptsTxtFile) as $optsTxtFile)
{
if (file_exists($optsTxtFile)) {
if (is_null($rtn)) $rtn = array();
$content = str_replace("\n", ',', trim(file_get_contents($optsTxtFile)));
$selectors = new \Selectors($content);
foreach ($selectors as $selector) {
$rtn[$selector->field] = $selector->value;
}
}
}
// return an save it to static array
return $textOptions[$optsTxtFile] = $rtn;

return $textOptions[$fileOptsTxtFile] = $rtn;
}
}

0 comments on commit 05d80f5

Please sign in to comment.