From ab72b53ad94bbded430da76ea0f0dd2ec1638e25 Mon Sep 17 00:00:00 2001
From: lolandese <lolandese@210402.no-reply.drupal.org>
Date: Sun, 21 Jun 2015 10:26:56 +0200
Subject:  lolandese: Generated with Drush iq

---
 block/flickr_block.admin.inc   |    8 ++-
 filter/flickr_filter.admin.inc |    2 +
 flickr.admin.inc               |   63 +++++++++++++----
 flickr.css                     |    4 ++
 flickr.module                  |    5 +-
 flickr.php                     |  152 ++++++++++++++++++++++++++++++++++++++++
 sets/flickr_sets.admin.inc     |    8 +--
 tags/flickr_tags.admin.inc     |    4 +-
 8 files changed, 223 insertions(+), 23 deletions(-)
 create mode 100644 flickr.php

diff --git a/block/flickr_block.admin.inc b/block/flickr_block.admin.inc
index 2ccc42b..8dc4a16 100644
--- a/block/flickr_block.admin.inc
+++ b/block/flickr_block.admin.inc
@@ -21,6 +21,8 @@ function flickr_block_form_flickr_admin_settings_alter(&$form, &$form_state) {
     '#required' => TRUE,
     '#default_value' => variable_get('flickr_block_heading', 'h2'),
     '#description' => t("Use 'p' for no style, e.g. 'h2' for a heading or 'none' to not display an album title."),
+    '#field_prefix' => t('<'),
+    '#field_suffix' => t('>'),
     '#size' => 4,
     '#maxlength' => 4,
   );
@@ -32,6 +34,7 @@ function flickr_block_form_flickr_admin_settings_alter(&$form, &$form_state) {
     '#field_suffix' => t('hours.'),
     '#size' => 3,
     '#maxlength' => 3,
+    '#attributes' => array('class' => array('flickr-form-align')),
   );
   $cache_warming = l(t('cache warming'), 'https://drupal.org/node/1576686/', array(
     'attributes' => array(
@@ -48,6 +51,7 @@ function flickr_block_form_flickr_admin_settings_alter(&$form, &$form_state) {
     '#field_suffix' => t('hours.'),
     '#size' => 3,
     '#maxlength' => 3,
+    '#attributes' => array('class' => array('flickr-form-align')),
   );
   $form['block_settings']['flickr_block_photos_per_set'] = array(
     '#type' => 'textfield',
@@ -77,7 +81,7 @@ function flickr_block_admin_settings_validate($form, &$form_state) {
     form_set_error('flickr_block_refresh_others', t('Set a number from 2 to 999.'));
   }
   // Validate photos per set.
-  if (!is_numeric($limit10) || $limit10 < 1) {
-    form_set_error('flickr_block_photos_per_set', t('Set a number from 1 to 99.'));
+  if (!ctype_digit($limit10) || $limit10 < 1) {
+    form_set_error('flickr_block_photos_per_set', t('Set an integer from 1 to 99.'));
   }
 }
diff --git a/filter/flickr_filter.admin.inc b/filter/flickr_filter.admin.inc
index 511ab04..10430c9 100644
--- a/filter/flickr_filter.admin.inc
+++ b/filter/flickr_filter.admin.inc
@@ -40,6 +40,8 @@ function flickr_filter_form_flickr_admin_settings_alter(&$form, &$form_state) {
     '#required' => TRUE,
     '#default_value' => variable_get('flickr_filter_heading', 'p'),
     '#description' => t("Use 'p' for no style, e.g. 'h3' for a heading or 'none' to not display an album title."),
+    '#field_prefix' => t('<'),
+    '#field_suffix' => t('>'),
     '#size' => 4,
     '#maxlength' => 4,
   );
diff --git a/flickr.admin.inc b/flickr.admin.inc
index b8a82b3..d39f6b4 100644
--- a/flickr.admin.inc
+++ b/flickr.admin.inc
@@ -109,6 +109,7 @@ function flickr_admin_settings() {
     '#field_suffix' => t('px'),
     '#size' => 3,
     '#maxlength' => 3,
+    '#attributes' => array('class' => array('flickr-form-align')),
   );
   $form['info_settings']['flickr_metadata_suppress_on_small'] = array(
     '#type' => 'textfield',
@@ -119,6 +120,7 @@ function flickr_admin_settings() {
     '#field_suffix' => t('px'),
     '#size' => 3,
     '#maxlength' => 3,
+    '#attributes' => array('class' => array('flickr-form-align')),
   );
   $rubular = l(t('http://rubular.com/r/RhKjj9Thy1'), 'http://rubular.com/r/RhKjj9Thy1', array(
       'attributes' => array(
@@ -131,7 +133,7 @@ function flickr_admin_settings() {
     '#type' => 'textfield',
     '#title' => t("Replace photo titles matching this Regular Expression with 'View on Flickr'"),
     '#default_value' => variable_get('flickr_regex', '^[a-zA-Z]+[^\s][0-9]+$'),
-    '#description' => t("Avoids camera generated titles like e.g. 'IMG_4259'. Try your own RegEx first with !rubular. Leave empty to NOT replace any titles.", array('!rubular' => $rubular)),
+    '#description' => t("Avoids camera generated titles like 'IMG_4259'. Try your own RegEx first with !rubular. Leave empty to NOT replace any titles.", array('!rubular' => $rubular)),
     '#field_prefix' => t('/'),
     '#field_suffix' => t('/'),
     '#size' => 60,
@@ -213,8 +215,8 @@ function flickr_admin_settings() {
     '#title' => t('Counter thousands separator'),
     '#default_value' => variable_get('flickr_thousands_sep', ','),
     '#description' => t('Common values are NULL, a dot ("."), a comma (",") or a space (" ").'),
-    '#field_prefix' => t('E.g. 4 out of 23'),
-    '#field_suffix' => t('473'),
+    '#field_prefix' => t('For example <em>4 out of 23</em>'),
+    '#field_suffix' => t('<em>473</em>'),
     '#size' => 1,
     '#maxlength' => 1,
   );
@@ -363,11 +365,41 @@ function flickr_admin_settings() {
       ),
   ));
   $form['css_settings']['flickr_css'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Use flickr.css'),
+    '#type' => 'radios',
+    '#title' => t('CSS source'),
+    '#options' => array(
+      0 => t("Exclude the module's CSS"),
+      1 => t("Use the module's default CSS"),
+      2 => t("Use the module's CSS with configurable settings (N.B.: Excluded from CSS aggregation)"),
+    ),
     '#default_value' => variable_get('flickr_css', 1),
-    '#description' => t("Uncheck to take care of the styling yourself in custom CSS.<br />If you use Flickr Filter, you might find the !autofloat_module useful.", array('!autofloat_module' => $autofloat_module)),
+    '#description' => t("Use configurable settings <strong>OR</strong> copy the used module's CSS files to your theme folder, make your changes and mention them in your [theme].info file.<br />If you use Flickr Filter, you might find the !autofloat_module useful.", array('!autofloat_module' => $autofloat_module)),
   );
+  $form['css_settings']['css_variables'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('CSS variables'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+  if (variable_get('flickr_css', 1) == 2) {
+    $form['css_settings']['css_variables']['#collapsed'] = FALSE;
+    $form['css_settings']['css_variables']['flickr_capsize'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Photo caption font size'),
+      '#default_value' => variable_get('flickr_capsize', 80),
+      '#description' => t('Relative to the font size for the normal text. Remember that a minimum font size setting of your browser might limit it. Do test on different browsers.'),
+      '#field_suffix' => t('%'),
+      '#size' => 3,
+      '#maxlength' => 3,
+      '#attributes' => array('class' => array('flickr-form-align')),
+    );
+  }
+  else {
+    $form['css_settings']['css_variables']['flickr_note'] = array(
+      '#markup' => t("Choose '<em>configurable settings</em>' above to get them exposed here. They consist of:
+        <ul><li>the photo caption font size</li></ul>"),
+    );
+  }
   $flickr_style = l(t('Flickr Style'), 'admin/modules', array(
       'attributes' => array(
         'title' => t('Extra configuration options.'),
@@ -404,7 +436,7 @@ function flickr_admin_settings() {
     '#title' => t('Update interval'),
     '#options' => $ageoptions,
     '#default_value' => variable_get('flickr_cache_duration', 3600),
-    '#description' => t('The refresh interval indicating how often you want to check cached Flickr API calls are up to date.'),
+    '#description' => t("The refresh interval indicating how often you want to check cached Flickr API calls are up to date. This only kicks in when a repeating request with the same query is made, e.g. when re-saving a Flickr block without changing the parameters within the specified interval. A Flickr API request is usually avoided anyway by a higher level page or block cache, therefore it is pretty safe to set it to '<em>1 hour</em>'."),
   );
   $cache_warming = l(t('cache warming'), 'https://drupal.org/node/1576686', array(
     'attributes' => array(
@@ -561,7 +593,8 @@ function flickr_admin_settings_validate($form, &$form_state) {
   $limit1 = trim($form_state['values']['flickr_photos_per_page']);
   $limit2 = trim($form_state['values']['flickr_title_suppress_on_small']);
   $limit3 = trim($form_state['values']['flickr_metadata_suppress_on_small']);
-  $limit7 = trim($form_state['values']['flickr_per_page']);
+  $limit4 = trim($form_state['values']['flickr_capsize']);
+  $limit5 = trim($form_state['values']['flickr_per_page']);
   if ($key && (preg_match('/^[A-Fa-f\d]{32}$/', $key) != 1)) {
     form_set_error('flickr_api_key', t('This does not appear to be a Flickr API key.'));
   }
@@ -575,8 +608,8 @@ function flickr_admin_settings_validate($form, &$form_state) {
     }
   }
   // Validate the number of photos.
-  if (!is_numeric($limit1) || $limit1 < 1) {
-    form_set_error('flickr_photos_per_page', t('Set a number from 1 to 999.'));
+  if (!ctype_digit($limit1) || $limit1 < 1) {
+    form_set_error('flickr_photos_per_page', t('Set an integer from 1 to 999.'));
   }
   // Validate the minimum width to suppress title caption.
   if (!is_numeric($limit2) || $limit2 < 0) {
@@ -586,9 +619,13 @@ function flickr_admin_settings_validate($form, &$form_state) {
   if (!is_numeric($limit3) || $limit3 < 0) {
     form_set_error('flickr_metadata_suppress_on_small', t('Set a width from 0 to 999 px.'));
   }
-  // Validate the number to return on a random or views sorted API requests.
-  if (!is_numeric($limit7) || $limit7 < 20 || $limit7 > 500) {
-    form_set_error('flickr_per_page', t('Set a number from 20 to 500.'));
+  // Validate the caption font size.
+  if (!is_numeric($limit4) || $limit4 < 0) {
+    form_set_error('flickr_capsize', t('Set a percentage from 0 to 999 %.'));
+  }
+  // Validate the number to return on 'random' or 'views' sorted API requests.
+  if (!ctype_digit($limit5) || $limit5 < 20 || $limit5 > 500) {
+    form_set_error('flickr_per_page', t('Set an integer from 20 to 500.'));
   }
 }
 
diff --git a/flickr.css b/flickr.css
index 809bec6..1126fda 100644
--- a/flickr.css
+++ b/flickr.css
@@ -104,3 +104,7 @@ span.grayed-out {
 span.grayed-out-help {
   color: #666;
 }
+
+.flickr-form-align {
+  text-align: right;
+}
diff --git a/flickr.module b/flickr.module
index 47909a0..82d196b 100644
--- a/flickr.module
+++ b/flickr.module
@@ -23,8 +23,9 @@ function flickr_help($path, $arg) {
  */
 function flickr_page_build(&$page) {
   // Determine the setting to use flickr.css or not.
-  if (variable_get('flickr_css', 1)) {
-    drupal_add_css(drupal_get_path('module', 'flickr') . '/flickr.css', array(
+  if (variable_get('flickr_css')) {
+    $extension = variable_get('flickr_css') == 2 ? 'php' : 'css';
+    drupal_add_css(drupal_get_path('module', 'flickr') . '/flickr.' . $extension, array(
       'group' => CSS_DEFAULT,
       'every_page' => TRUE,
     ));
diff --git a/flickr.php b/flickr.php
new file mode 100644
index 0000000..464a6f5
--- /dev/null
+++ b/flickr.php
@@ -0,0 +1,152 @@
+<?php
+/**
+ * This as PHP 'disguised' CSS file allows for the use of Drupal defined
+ * variables inside CSS. There are some down sides:
+ * - The CSS won't get aggregated.
+ * - A Right-To-Left CSS style sheet will be ignored.
+ * - It has a slight performance impact.
+ *
+ * The regular CSS files are also provided with an option in the settings of the
+ * module to use CSS variables. If not, override CSS yourself by moving the CSS
+ * files to your theme folder and mention them in the [yourtheme].info file.
+ */
+
+  // Changes the header to be recognized as a CSS file instead of PHP.
+  header("Content-type: text/css; charset: UTF-8");
+
+  // Iterates up from the current folder until the Drupal root is found.
+  function dirroot() {
+    if ( strstr( __FILE__, $_SERVER['DOCUMENT_ROOT']) ) {
+      $dir = $_SERVER['DOCUMENT_ROOT'];
+    } else {
+      $dir = dirname(__FILE__);
+      while ( ! file_exists($dir . '/install.php') ) {
+        $dir = dirname($dir);
+      }
+    }
+    return $dir;
+  }
+
+  // Initializes Drupal's variable system.
+  define('DRUPAL_ROOT', dirroot());
+  require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
+  drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES);
+
+  // Sets the used variables in the CSS below.
+  $capsize = variable_get('flickr_capsize', 80);
+?>
+
+/**
+ * CSS part: Float images found in the target alternately right and left.
+ */
+
+.flickr-photo-img {
+  vertical-align: text-bottom;
+}
+
+.flickr-photo-box {
+  float: left;
+  width: 260px;
+  height: 260px;
+  padding: 10px;
+  text-align: center;
+}
+
+.flickr-photoset-img {
+  vertical-align: text-bottom;
+}
+
+.flickr-photoset-box {
+  float: left;
+  padding: 10px;
+  text-align: center;
+}
+
+span.flickr-wrap,
+span.flickr-photoset-single {
+  position: relative;
+  display: inline-block;
+  margin: 0 5px 5px 0;
+  vertical-align: top;
+}
+
+span.flickr-credit {
+  display: block;
+  overflow: hidden;
+  padding: 0 0 4px 4px;
+  font-size: <?php echo $capsize; ?>%;
+  line-height: 100%;
+}
+
+.flickr-slideshow {
+  position: relative;
+  overflow: hidden;
+  width: 100%;
+  height: 0;
+  /*Change percentage below to change ratio. Currently 16:9 (as most screens).*/
+  padding-bottom: 56.25%;
+}
+
+.flickr-slideshow object {
+  position: absolute;
+  top: 0;
+  left: 0;
+}
+
+.flickr-block-photosets .flickr-block-photoset {
+  margin-top: 0.5em;
+  padding-top: 0.5em;
+  border-top: 1px solid #dfdfdf;
+}
+
+span.floatleft {
+  float: left; /* LTR */
+  margin: 5px 5px 0 0; /* LTR */
+}
+span.floatright {
+  float: right; /* LTR */
+  margin: 5px 0 0 10px; /* LTR */
+}
+
+span.flickr-tags {
+  font-style: italic;
+}
+
+.flickr-wrap,
+.flickr-wrap img,
+.flickr-wrap .flickr-credit {
+  /*See http://stackoverflow.com/a/11390432/523688*/
+  -webkit-box-sizing: border-box;
+     -moz-box-sizing: border-box;
+          box-sizing: border-box;
+  max-width: 100%;
+}
+
+div.flickr-photoset {
+  clear: both;
+}
+
+span.flickr-empty {
+  display: inline-block;
+  margin: 10px;
+}
+
+.page-flickr-sets h1#page-title {
+  display: none;
+}
+
+.tips span.ctools-toggle {
+  float: none !important;
+}
+
+span.grayed-out {
+  color: darkgray;
+}
+
+span.grayed-out-help {
+  color: #666;
+}
+
+.flickr-form-align {
+  text-align: right;
+}
diff --git a/sets/flickr_sets.admin.inc b/sets/flickr_sets.admin.inc
index f482bea..fbf6b3c 100644
--- a/sets/flickr_sets.admin.inc
+++ b/sets/flickr_sets.admin.inc
@@ -61,11 +61,11 @@ function flickr_sets_admin_settings_validate($form, &$form_state) {
   $limit8 = trim($form_state['values']['flickr_sets_per_page']);
   $limit9 = trim($form_state['values']['flickr_sets_photos_per_set']);
   // Validate sets per page.
-  if (!is_numeric($limit8) || $limit8 < 1) {
-    form_set_error('flickr_sets_per_page', t('Set a number from 1 to 99.'));
+  if (!ctype_digit($limit8) || $limit8 < 1) {
+    form_set_error('flickr_sets_per_page', t('Set an integer from 1 to 99.'));
   }
   // Validate photos per set.
-  if (!is_numeric($limit9) || $limit9 < 1) {
-    form_set_error('flickr_sets_photos_per_set', t('Set a number from 1 to 99.'));
+  if (!ctype_digit($limit9) || $limit9 < 1) {
+    form_set_error('flickr_sets_photos_per_set', t('Set an integer from 1 to 99.'));
   }
 }
diff --git a/tags/flickr_tags.admin.inc b/tags/flickr_tags.admin.inc
index 6963d63..2dc5241 100644
--- a/tags/flickr_tags.admin.inc
+++ b/tags/flickr_tags.admin.inc
@@ -33,7 +33,7 @@ function flickr_tags_form_flickr_admin_settings_alter(&$form, &$form_state) {
 function flickr_tags_admin_settings_validate($form, &$form_state) {
   $limit = trim($form_state['values']['flickr_tags_in_cloud']);
   // Validate tags in cloud.
-  if (!is_numeric($limit) || $limit < 1) {
-    form_set_error('flickr_tags_in_cloud', t('Set a number from 1 to 999.'));
+  if (!ctype_digit($limit) || $limit < 1) {
+    form_set_error('flickr_tags_in_cloud', t('Set an integer from 1 to 999.'));
   }
 }
-- 
1.7.9.5

