Plugin Directory

Changeset 627435


Ignore:
Timestamp:
11/20/2012 12:25:33 AM (13 years ago)
Author:
techotronic
Message:

CHANGE: deleting all plugin settings now also deleted uploaded favicons
CHANGE: option "delete favicon" is only displayed if a favicon was already uploaded
also: code hygene, DRY, ...

Location:
all-in-one-favicon/trunk
Files:
1 deleted
5 edited
1 moved

Legend:

Unmodified
Added
Removed
  • all-in-one-favicon/trunk/all-in-one-favicon.php

    r626521 r627435  
    9797
    9898    if (is_admin()) {
     99      //mapping of favicon types to translatable Strings
     100      $this->aioFaviconFrontendMap = array(
     101        'frontendICO' => 'ICO',
     102        'frontendGIF' => 'GIF',
     103        'frontendPNG' => 'PNG',
     104        'frontendApple' => 'Apple Touch Icon'
     105      );
     106
     107      //mapping of favicon types to translatable Strings
     108      $this->aioFaviconBackendMap = array(
     109        'backendICO' => 'ICO',
     110        'backendGIF' => 'GIF',
     111        'backendPNG' => 'PNG',
     112        'backendApple' => 'Apple Touch Icon'
     113      );
     114
    99115      $donationLoader = new AIOFaviconDonationLoader();
    100       new AioFaviconBackend($this->aioFaviconSettings, $this->aioFaviconDefaultSettings(),$donationLoader);
     116      $backend = new AioFaviconBackend($this->aioFaviconSettings,
     117        $this->aioFaviconDefaultSettings(),
     118        $donationLoader,
     119        $this->aioFaviconFrontendMap,
     120        $this->aioFaviconBackendMap);
     121      $backend->init();
    101122    }
    102123    else {
    103       new AioFaviconFrontend($this->aioFaviconSettings);
     124      $frontend = new AioFaviconFrontend($this->aioFaviconSettings);
     125      $frontend->init();
    104126    }
    105127
  • all-in-one-favicon/trunk/includes/aio-favicon-backend.php

    r626519 r627435  
    2525   * @param array $aioFaviconDefaultSettings default plugin settings
    2626   * @param AIOFaviconDonationLoader $donationLoader the donationloader
     27   * @param array $faviconFrontendMap mapping of favicon types to translatable Strings
     28   * @param array $faviconBackendMap mapping of favicon types to translatable Strings
    2729   *
    2830   * @return void
    2931   */
    3032  //public static function AioFaviconBackend($aioFaviconSettings) {
    31   function AioFaviconBackend($aioFaviconSettings, $aioFaviconDefaultSettings, $donationLoader) {
     33  function AioFaviconBackend($aioFaviconSettings, $aioFaviconDefaultSettings, $donationLoader,
     34                              $faviconFrontendMap, $faviconBackendMap) {
    3235
    3336    $this->aioFaviconSettings = $aioFaviconSettings;
    3437    $this->aioFaviconDefaultSettings = $aioFaviconDefaultSettings;
    3538    $this->donationLoader = $donationLoader;
    36 
    3739    $this->faviconRenderHelper = new FaviconRenderHelper($this->aioFaviconSettings,AIOFAVICON_BACKEND);
     40    $this->faviconFrontendMap = $faviconFrontendMap;
     41    $this->faviconBackendMap = $faviconBackendMap;
     42    $this->faviconMap = array_merge($faviconFrontendMap,$faviconBackendMap);
     43  }
     44
     45  // AioFaviconBackend()
     46
     47
     48  /**
     49   * Initialize
     50   *
     51   * @since 4.0
     52   * @access public
     53   * @author Arne Franken
     54   *
     55   * @return void
     56   */
     57  //public function init() {
     58  function init() {
    3859    add_action('admin_head', array(& $this->faviconRenderHelper, 'renderFavicons'));
    3960
     
    4667    //only load JavaScript if we are on this plugin's settingspage
    4768    if (isset($_GET['page']) && $_GET['page'] == AIOFAVICON_PLUGIN_BASENAME) {
    48       add_action('admin_enqueue_scripts', array(& $donationLoader, 'registerDonationJavaScript'));
     69      add_action('admin_enqueue_scripts', array(& $this->donationLoader, 'registerDonationJavaScript'));
    4970      add_action('admin_enqueue_scripts', array(& $this, 'registerAdminScripts'));
    5071    }
    5172  }
    5273
    53   // AioFaviconBackend()
     74  //init()
    5475
    5576
     
    6788  function registerAdminScripts() {
    6889    $backendJavaScriptArray = array();
     90
    6991    if (!empty($this->aioFaviconSettings)) {
    7092      foreach ((array)$this->aioFaviconSettings as $type => $url) {
     
    173195    $this->aioFaviconSettings = wp_parse_args($usersettings, wp_parse_args((array)get_option(AIOFAVICON_SETTINGSNAME), $defaultArray));
    174196
     197    //don't show link in meta box by default any more.
    175198    if (!isset($usersettings['removeLinkFromMetaBox'])) {
    176199      $this->aioFaviconSettings['removeLinkFromMetaBox'] = false;
     
    196219    }
    197220
    198     //$debugger->dieWithVariable($_POST);
    199 
    200221    $this->updateSettingsInDatabase();
    201222    $referrer = str_replace(array('&aioFaviconUpdateSettings', '&aioFaviconDeleteSettings'), '', $_POST['_wp_http_referer']);
     
    222243      //cross check the given referer for nonce set in delete settings form
    223244      check_admin_referer('aio-favicon-delete_settings-form');
     245
     246      foreach($this->faviconMap as $key => $value) {
     247        $this->deleteFile($key);
     248      }
     249
    224250      $this->deleteSettingsFromDatabase();
    225     } else {
     251
     252    }
     253    else {
    226254      wp_die(sprintf(__('Did not delete %1$s settings. Either you dont have the nececssary rights or you didnt check the checkbox.', AIOFAVICON_TEXTDOMAIN), AIOFAVICON_NAME));
    227255    }
     
    274302      $regex = '#' . $uploads['baseurl'] . '/(.*)#i';
    275303      preg_match($regex, $url, $relativePath);
     304
    276305      if (count($relativePath) > 1) {
    277306        $pathToFile = $uploads['basedir'] . '/' . $relativePath[1];
     
    360389      $response = wp_remote_request($url, $options);
    361390
    362       if (is_wp_error($response))
     391      if (is_wp_error($response)) {
    363392        return false;
    364 
    365       if (200 != wp_remote_retrieve_response_code($response))
     393      }
     394
     395      if (200 != wp_remote_retrieve_response_code($response)) {
    366396        return false;
     397      }
    367398
    368399      return wp_remote_retrieve_body($response);
     
    388419    $currentLocation .= ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? "s" : "") . "://";
    389420    $currentLocation .= $_SERVER['SERVER_NAME'];
     421
    390422    if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
     423
    391424      if ($_SERVER['SERVER_PORT'] != '443') {
    392425        $currentLocation .= ":" . $_SERVER['SERVER_PORT'];
     
    394427    }
    395428    else {
     429
    396430      if ($_SERVER['SERVER_PORT'] != '80') {
    397431        $currentLocation .= ":" . $_SERVER['SERVER_PORT'];
    398432      }
    399433    }
     434
    400435    $currentLocation .= $_SERVER['REQUEST_URI'];
    401436    echo $currentLocation;
  • all-in-one-favicon/trunk/includes/aio-favicon-frontend.php

    r626519 r627435  
    2828
    2929    $this->aioFaviconSettings = $aioFaviconSettings;
     30    $this->faviconRenderHelper = new FaviconRenderHelper($this->aioFaviconSettings,AIOFAVICON_FRONTEND);
     31  }
    3032
    31     $this->faviconRenderHelper = new FaviconRenderHelper($this->aioFaviconSettings,AIOFAVICON_FRONTEND);
     33  // AioFaviconFrontend()
     34
     35  /**
     36   * Initialize
     37   *
     38   * @since 4.0
     39   * @access public
     40   * @author Arne Franken
     41   *
     42   * @return void
     43   */
     44  //public function init() {
     45  function init() {
    3246    add_action('wp_head', array(& $this->faviconRenderHelper, 'renderFavicons'));
    3347
     
    3650      add_action('wp_meta', array(& $this, 'renderMetaLink'));
    3751    }
    38 
    3952  }
    4053
    41   // AioFaviconFrontend()
     54  //init()
    4255
    4356  /**
  • all-in-one-favicon/trunk/includes/settings-page/sp-left-column.php

    r626518 r627435  
    1616    <div id="poststuff">
    1717<?php
    18       require_once 'sp-plugin-frontend-settings.php';
    19       require_once 'sp-plugin-backend-settings.php';
     18
     19      //TODO: still not ideal - since all settings page files are just "HTML templates" there is currently no clean way to handle DRY.
     20
     21      //set values for frontend favicon-settings-box
     22      $this->faviconMap = $this->faviconFrontendMap;
     23      $this->identifier = AIOFAVICON_FRONTEND;
     24      $this->translatedIdentifier = __('Frontend', AIOFAVICON_TEXTDOMAIN);
     25      require 'sp-plugin-favicon-settings.php';
     26
     27      //set values for backend favicon-settings-box
     28      $this->faviconMap = $this->faviconBackendMap;
     29      $this->identifier = AIOFAVICON_BACKEND;
     30      $this->translatedIdentifier = __('Backend', AIOFAVICON_TEXTDOMAIN);
     31      require 'sp-plugin-favicon-settings.php';
     32
    2033      require_once 'sp-plugin-meta-settings.php';
    2134    ?>
  • all-in-one-favicon/trunk/includes/settings-page/sp-plugin-favicon-settings.php

    r627007 r627435  
    1010 */
    1111?>
    12 <div id="aio-favicon-frontend-settings" class="postbox">
    13     <h3 id="frontend-settings"><?php _e('Frontend', AIOFAVICON_TEXTDOMAIN); echo " "; _e('Settings', AIOFAVICON_TEXTDOMAIN); ?></h3>
     12<div id="aio-favicon-<?php echo $this->identifier ?>-settings" class="postbox">
     13    <h3 id="<?php echo $this->identifier ?>-settings"><?php echo $this->translatedIdentifier; echo " "; _e('Settings', AIOFAVICON_TEXTDOMAIN); ?></h3>
    1414
    1515    <div class="inside">
    1616        <table class="form-table">
    1717<?php
    18           // The icons that we can set.
    19           $faviconMap = array(
    20             'frontendICO' => 'ICO',
    21             'frontendPNG' => 'PNG',
    22             'frontendGIF' => 'GIF',
    23             'frontendApple' => 'Apple Touch Icon');
    24 
    2518          // Loop over this list of icons.
    26           foreach ($faviconMap as $iconName => $iconType) { ?>
     19          foreach ($this->faviconMap as $iconName => $iconType) { ?>
    2720            <tr>
    2821                <th scope="row">
    29                     <label for="<?php echo AIOFAVICON_SETTINGSNAME .'-'. $iconName ?>"><?php printf(__('%1$s '.$iconType, AIOFAVICON_TEXTDOMAIN), __('Frontend', AIOFAVICON_TEXTDOMAIN)); ?>:</label>
     22                    <label for="<?php echo AIOFAVICON_SETTINGSNAME .'-'. $iconName ?>"><?php printf(__('%1$s '.$iconType, AIOFAVICON_TEXTDOMAIN), $this->translatedIdentifier); ?>:</label>
    3023                </th>
    3124                <td width="32">
     
    3730                    <input id="<?php echo AIOFAVICON_SETTINGSNAME .'-'. $iconName ?>-button" type="button" name="<?php echo $iconName ?>-button" class="button-secondary" value="<?php _e('Upload') ?>" />
    3831                    <br />
     32                    <?php //only display
     33                    if(!empty($this->aioFaviconSettings[$iconName])) { ?>
    3934                    <input type="checkbox" name="delete-<?php echo $iconName ?>"/><?php _e('Check box to delete favicon.',AIOFAVICON_TEXTDOMAIN) ?>
     35                    <?php } ?>
    4036                </td>
    4137            </tr>
  • all-in-one-favicon/trunk/readme.txt

    r627007 r627435  
    9797* NEW: Turkish translation by Selçuk Yahşi
    9898* CHANGE: Eddy Ernesto Ríos updated the Spanish translation
    99 
     99* CHANGE: deleting all plugin settings now also deleted uploaded favicons
     100* CHANGE: option "delete favicon" is only displayed if a favicon was already uploaded
    100101
    101102
Note: See TracChangeset for help on using the changeset viewer.