/**
  * Sanitize the given key/value pair, passing any error to $errs if given.
  *
  * @param string $key The key to reference the current value in the defaults array.
  * @param mixed $value The value to be sanitized.
  * @param string[] $errs The array of errors, which will be appended with any errors found.
  *
  * @return mixed The sanitized value, falling back to the current default value when invalid value given.
  */
 public static function sanitizeParameter($key, $value, &$errs = null)
 {
     // all sanitize methods must be in the following form: sanitize<UpperCamelCaseKey>
     $funct = $key;
     $funct[0] = strtoupper($funct[0]);
     $funct = 'sanitize' . preg_replace_callback('/_([a-z])/', array(__CLASS__, 'secondCharToUpper'), $funct);
     $callable = array(__CLASS__, $funct);
     // avoid looking for method beforehand unless we're running in debug mode -- expensive call
     if (DG_Logger::logEnabled() && !method_exists(__CLASS__, $funct)) {
         DG_Logger::writeLog(DG_LogLevel::Error, __('Attempted to call invalid function: ', 'document-gallery') . implode('::', $callable), true);
     }
     // call param-specific sanitization
     $ret = call_user_func_array($callable, array($value, &$err));
     // check for error and return default
     if (isset($err)) {
         $defaults = DG_Gallery::getOptions();
         $ret = $defaults[$key];
         if (!is_null($errs)) {
             $errs[$key] = $err;
         }
     }
     return $ret;
 }
Exemplo n.º 2
0
    /**
     * Render the Logging table.
     */
    public static function renderLoggingSection()
    {
        $log_list = DG_Logger::readLog();
        if ($log_list) {
            $levels = array_map(array(__CLASS__, 'getLogLabelSpan'), array_keys(DG_LogLevel::getLogLevels()));
            $fmt = '<tr>' . '<th scope="col" class="manage-column column-date sorted desc"><a href="javascript:void(0);">' . '<span>%s</span><span class="sorting-indicator"></span></a>' . '</th>' . '<th scope="col" class="manage-column column-level"><span>%s</span></th>' . '<th scope="col" class="manage-column column-message"><span>%s</span></th>' . '</tr>';
            $thead = sprintf($fmt, __('Date', 'document-gallery'), __('Level', 'document-gallery'), __('Message', 'document-gallery'));
            ?>
			<div class="log-list-wrapper">
				<div>
					<div class="tablenav top">
						<div class="alignleft bulkactions">
							<button class="action expandAll">
								<?php 
            echo __('Expand All', 'document-gallery');
            ?>
							</button>
							<button class="action collapseAll">
								<?php 
            echo __('Collapse All', 'document-gallery');
            ?>
							</button>
						</div>
						<div class="levelSelector">
							<input type="checkbox" id="allLevels" name="lswitch" value="all" checked/>
							<label for="allLevels" class="allLevels">ALL</label>
							<?php 
            foreach (array_keys(DG_LogLevel::getLogLevels()) as $k) {
                ?>
								<?php 
                $lower = strtolower($k);
                $upper = strtoupper($k);
                ?>
								<input type="checkbox" id="<?php 
                echo $lower;
                ?>
Level" name="lswitch"
								       value="<?php 
                echo $lower;
                ?>
" checked/>
								<label for="<?php 
                echo $lower;
                ?>
Level"
								       class="<?php 
                echo $lower;
                ?>
Level"><?php 
                echo $upper;
                ?>
</label>
							<?php 
            }
            ?>
						</div>
					</div>
					<table id="LogTable" class="wp-list-table widefat fixed media" cellpadding="0" cellspacing="0">
						<thead>
						<?php 
            echo $thead;
            ?>
						</thead>
						<tfoot>
						<?php 
            echo $thead;
            ?>
						</tfoot>
						<tbody><?php 
            for ($i = count($log_list); $i > 0; $i--) {
                $log_entry = $log_list[$i - 1];
                $date = DocumentGallery::localDateTimeFromTimestamp($log_entry[0]);
                // convert attachment names to links
                $log_entry[2] = preg_replace('/[ ^](attachment #)(\\d+)[.,: ]/i', ' <a href="' . home_url() . '/?attachment_id=\\2" target="_blank">\\1<strong>\\2</strong></a> ', $log_entry[2]);
                // bold the place where log entry was submitted
                $log_entry[2] = preg_replace('/^(\\((?:\\w+(?:::|->))?\\w+\\)) /', '<strong>\\1</strong> ', $log_entry[2]);
                // italicize any function references within log entry
                $log_entry[2] = preg_replace('/(\\(?\\w+(?:::|->)\\w+\\)?)/m', '<i>\\1</i>', $log_entry[2]);
                echo '<tr><td class="date column-date" data-sort-value="' . $log_entry[0] . '"><span class="logLabel date">' . $date . '</span></td>' . '<td class="column-level">' . $levels[$log_entry[1]] . '</td>' . '<td class="column-entry">' . (empty($log_entry[3]) ? '<pre>' . $log_entry[2] . '</pre>' : '<div class="expander" title="Click to Expand"><pre>' . $log_entry[2] . '</pre><div><span class="dashicons dashicons-arrow-down-alt2"></span></div></div><div class="spoiler-body"><pre>' . $log_entry[3] . '</pre></div>') . '</td>' . '</tr>' . PHP_EOL;
            }
            ?>
						</tbody>
					</table>
					<div class="tablenav bottom">
						<div class="alignright bulkactions">
							<button class="button action clearLog" name='<?php 
            echo DG_OPTION_NAME;
            ?>
[clearLog]'
							        value='true'>
								<?php 
            echo __('Clear Log', 'document-gallery');
            ?>
							</button>
						</div>
					</div>
				</div>
			</div>
		<?php 
        } else {
            echo '<div class="noLog">' . __('There are no log entries at this time.', 'document-gallery') . '<br />' . __('For Your information:', 'document-gallery') . ' <strong><i>' . __('Logging', 'document-gallery') . '</i></strong> ' . (DG_Logger::logEnabled() ? '<span class="loggingON">' . __('is turned ON', 'document-gallery') . '!</span>' : '<span class="loggingOFF">' . __('is turned OFF', 'document-gallery') . '!</span>') . '</div>';
        }
    }
Exemplo n.º 3
0
 /**
  * @filter dg_thumbers Allows developers to filter the Thumbers used
  * for specific filetypes. Index is the regex to match file extensions
  * supported and the value is anything that can be accepted by call_user_func().
  * The function must take two parameters, 1st is the int ID of the attachment
  * to get a thumbnail for, 2nd is the page to take a thumbnail of
  * (may not be relevant for some filetypes).
  *
  * @return array
  */
 private static function getThumbers()
 {
     static $thumbers = null;
     if (is_null($thumbers)) {
         $options = self::getOptions();
         $active = $options['active'];
         $thumbers = array();
         // Audio/Video embedded images
         if ($active['av']) {
             $exts = implode('|', self::getAudioVideoExts());
             $thumbers[$exts] = array(__CLASS__, 'getAudioVideoThumbnail');
         }
         // Ghostscript
         if ($active['gs'] && self::isGhostscriptAvailable()) {
             $exts = implode('|', self::getGhostscriptExts());
             $thumbers[$exts] = array(__CLASS__, 'getGhostscriptThumbnail');
         }
         // Imagick
         if ($active['imagick'] && self::isImagickAvailable()) {
             include_once DG_PATH . 'inc/class-image-editor-imagick.php';
             if ($exts = DG_Image_Editor_Imagick::query_formats()) {
                 $exts = implode('|', $exts);
                 $thumbers[$exts] = array(__CLASS__, 'getImagickThumbnail');
             }
         }
         // allow users to filter thumbers used
         $thumbers = apply_filters('dg_thumbers', $thumbers);
         // strip out anything that can't be called
         $thumbers = array_filter($thumbers, 'is_callable');
         // log which thumbers are being used
         if (DG_Logger::logEnabled()) {
             if (count($thumbers) > 0) {
                 $entry = __('Thumbnail Generators: ', 'document-gallery');
                 foreach ($thumbers as $k => $v) {
                     $thumber = is_array($v) ? implode('::', $v) : print_r($v, true);
                     // TODO: The following works for all internal regexes, but may have unpredictable
                     // results if developer adds additional thumbnail generators using different regexes
                     $filetypes = str_replace('|', ', ', $k);
                     $entry .= PHP_EOL . "{$thumber}: {$filetypes}";
                 }
             } else {
                 $entry = __('No thumbnail generators enabled.', 'document-gallery');
             }
             DG_Logger::writeLog(DG_LogLevel::Detail, $entry);
         }
     }
     return $thumbers;
 }
 /**
  * @filter dg_thumbers Allows developers to filter the Thumbers used
  * for specific filetypes. Index is the regex to match file extensions
  * supported and the value is anything that can be accepted by call_user_func().
  * The function must take two parameters, 1st is the int ID of the attachment
  * to get a thumbnail for, 2nd is the page to take a thumbnail of
  * (may not be relevant for some filetypes).
  *
  * @return DG_AbstractThumber[]
  */
 private static function getThumbers()
 {
     static $thumbers = null;
     if (is_null($thumbers)) {
         // allow users to filter thumbers used
         $thumbers = apply_filters('dg_thumbers', array());
         $thumbers = array_filter($thumbers, array(__CLASS__, 'isThumber'));
         usort($thumbers, array('DG_AbstractThumber', 'cmpThumberByPriority'));
         // log which thumbers are being used
         if (DG_Logger::logEnabled()) {
             if (count($thumbers) > 0) {
                 $names = array_map('get_class', $thumbers);
                 $entry = __('Thumbnail Generators: ', 'document-gallery') . implode(', ', $names);
             } else {
                 $entry = __('No thumbnail generators enabled.', 'document-gallery');
             }
             DG_Logger::writeLog(DG_LogLevel::Detail, $entry);
         }
     }
     return $thumbers;
 }