Ejemplo n.º 1
0
/**
 * Get properties of an icon.
 *
 * Note: to get a file type icon, use {@link File::get_icon()} instead.
 *
 * @uses get_icon_info()
 * @param string icon for what? (key)
 * @param string what to return for that icon ('imgtag', 'alt', 'legend', 'file', 'url', 'size' {@link imgsize()})
 * @param array additional params
 *   - 'class' => class name when getting 'imgtag',
 *   - 'size' => param for 'size',
 *   - 'title' => title attribute for 'imgtag'
 * @param boolean true to include this icon into the legend at the bottom of the page (works for 'imgtag' only)
 * @return mixed False on failure, string on success.
 */
function get_icon($iconKey, $what = 'imgtag', $params = NULL, $include_in_legend = false)
{
    global $admin_subdir, $Debuglog, $use_strict;
    global $conf_path;
    global $rsc_path, $rsc_uri;
    if (!function_exists('get_icon_info')) {
        require_once $conf_path . '_icons.php';
    }
    $icon = get_icon_info($iconKey);
    if (!$icon) {
        $Debuglog->add('No image defined for ' . var_export($iconKey, true) . '!', 'icons');
        return false;
    }
    if (!isset($icon['file']) && $what != 'imgtag') {
        $icon['file'] = 'icons/icons_sprite.png';
    }
    switch ($what) {
        case 'rollover':
            if (isset($icon['rollover'])) {
                // Image has rollover available
                return $icon['rollover'];
            }
            return false;
            /* BREAK */
        /* BREAK */
        case 'file':
            return $rsc_path . $icon['file'];
            /* BREAK */
        /* BREAK */
        case 'alt':
            if (isset($icon['alt'])) {
                // alt tag from $map_iconfiles
                return $icon['alt'];
            } else {
                // fallback to $iconKey as alt-tag
                return $iconKey;
            }
            /* BREAK */
        /* BREAK */
        case 'legend':
            if (isset($icon['legend'])) {
                // legend tag from $map_iconfiles
                return $icon['legend'];
            } else {
                if (isset($icon['alt'])) {
                    // alt tag from $map_iconfiles
                    return $icon['alt'];
                } else {
                    // fallback to $iconKey as alt-tag
                    return $iconKey;
                }
            }
            /* BREAK */
        /* BREAK */
        case 'class':
            if (isset($icon['class'])) {
                return $icon['class'];
            } else {
                return '';
            }
            /* BREAK */
        /* BREAK */
        case 'url':
            return $rsc_uri . $icon['file'];
            /* BREAK */
        /* BREAK */
        case 'size':
            if (!isset($icon['size'])) {
                $Debuglog->add('No iconsize for [' . $iconKey . ']', 'icons');
                $icon['size'] = imgsize($rsc_path . $icon['file']);
            }
            switch ($params['size']) {
                case 'width':
                    return $icon['size'][0];
                case 'height':
                    return $icon['size'][1];
                case 'widthxheight':
                    return $icon['size'][0] . 'x' . $icon['size'][1];
                case 'width':
                    return $icon['size'][0];
                case 'string':
                    return 'width="' . $icon['size'][0] . '" height="' . $icon['size'][1] . '"';
                default:
                    return $icon['size'];
            }
            /* BREAK */
        /* BREAK */
        case 'xy':
            if (isset($icon['xy'])) {
                // Return data for style property "background-position"
                return "-" . $icon['xy'][0] . "px -" . $icon['xy'][1] . "px";
            }
            return false;
        case 'sprite':
            if (isset($icon['xy'])) {
                // Image uses spite file
                return true;
            }
            return false;
            /* BREAK */
        /* BREAK */
        case 'imgtag':
            if (!isset($icon['file'])) {
                // Use span tag with sprite instead of img
                $styles = array();
                if (isset($params['xy'])) {
                    // Get background position from params
                    $styles[] = "background-position: " . $params['xy'][0] . "px " . $params['xy'][1] . "px";
                    unset($params['xy']);
                } else {
                    if (isset($icon['xy'])) {
                        // Set background position in the icons_sprite.png
                        $styles[] = "background-position: -" . $icon['xy'][0] . "px -" . $icon['xy'][1] . "px";
                    }
                }
                if (isset($params['size'])) {
                    // Get sizes from params
                    $icon['size'] = $params['size'];
                    unset($params['size']);
                }
                if (isset($icon['size'])) {
                    // Set width & height
                    if ($icon['size'][0] != 16) {
                        $styles[] = "width: " . $icon['size'][0] . "px";
                    }
                    if ($icon['size'][1] != 16) {
                        $styles[] = "height: " . $icon['size'][1] . "px; line-height: " . $icon['size'][1] . "px";
                    }
                }
                if (isset($params['style'])) {
                    // Get styles from params
                    $styles[] = $params['style'];
                }
                if (count($styles) > 0) {
                    $params['style'] = implode('; ', $styles);
                }
                if (!isset($params['title'])) {
                    // Use 'alt' for 'title'
                    if (isset($params['alt'])) {
                        $params['title'] = $params['alt'];
                        unset($params['alt']);
                    } else {
                        if (!isset($params['alt']) && isset($icon['alt'])) {
                            $params['title'] = $icon['alt'];
                        }
                    }
                }
                if (isset($params['class'])) {
                    // Get class from params
                    $params['class'] = 'icon ' . $params['class'];
                } else {
                    // Set default class
                    $params['class'] = 'icon';
                }
                // Add all the attributes:
                $params = get_field_attribs_as_string($params, false);
                $r = '<span' . $params . '>&nbsp;</span>';
            } else {
                // Use img tag
                $r = '<img src="' . $rsc_uri . $icon['file'] . '" ';
                if (!$use_strict) {
                    // Include non CSS fallbacks - transitional only:
                    $r .= 'border="0" align="top" ';
                }
                // Include class (will default to "icon"):
                if (!isset($params['class'])) {
                    if (isset($icon['class'])) {
                        // This icon has a class
                        $params['class'] = $icon['class'];
                    } else {
                        $params['class'] = '';
                    }
                }
                // Include size (optional):
                if (isset($icon['size'])) {
                    $r .= 'width="' . $icon['size'][0] . '" height="' . $icon['size'][1] . '" ';
                }
                // Include alt (XHTML mandatory):
                if (!isset($params['alt'])) {
                    if (isset($icon['alt'])) {
                        // alt-tag from $map_iconfiles
                        $params['alt'] = $icon['alt'];
                    } else {
                        // $iconKey as alt-tag
                        $params['alt'] = $iconKey;
                    }
                }
                // Add all the attributes:
                $r .= get_field_attribs_as_string($params, false);
                // Close tag:
                $r .= '/>';
                if ($include_in_legend && ($IconLegend =& get_IconLegend())) {
                    // This icon should be included into the legend:
                    $IconLegend->add_icon($iconKey);
                }
            }
            return $r;
            /* BREAK */
        /* BREAK */
        case 'noimg':
            // Include size (optional):
            if (isset($icon['size'])) {
                $params['size'] = $icon['size'];
            }
            $params['style'] = 'margin: 0 2px';
            return get_icon('pixel', 'imgtag', $params);
            /* BREAK */
            /*
            			$blank_icon = get_icon_info('pixel');
            
            			$r = '<img src="'.$rsc_uri.$blank_icon['file'].'" ';
            
            			// TODO: dh> add this only for !$use_strict, like above?
            			// Include non CSS fallbacks (needed by bozos... and basic skin):
            			$r .= 'border="0" align="top" ';
            
            			// Include class (will default to "noicon"):
            			if( ! isset( $params['class'] ) )
            			{
            				if( isset($icon['class']) )
            				{	// This icon has a class
            					$params['class'] = $icon['class'];
            				}
            				else
            				{
            					$params['class'] = 'no_icon';
            				}
            			}
            
            			// Include size (optional):
            			if( isset( $icon['size'] ) )
            			{
            				$r .= 'width="'.$icon['size'][0].'" height="'.$icon['size'][1].'" ';
            			}
            
            			// Include alt (XHTML mandatory):
            			if( ! isset( $params['alt'] ) )
            			{
            				$params['alt'] = '';
            			}
            
            			// Add all the attributes:
            			$r .= get_field_attribs_as_string( $params, false );
            
            			// Close tag:
            			$r .= '/>';
            
            			return $r;*/
            /* BREAK */
    }
}
Ejemplo n.º 2
0
 /**
  * Generate a general input element.
  *
  * @param array Optional params.
  *    Additionally to {@link $_common_params} you can use:
  *    - input_prefix: Text before <input /> (string, default '')
  *    - input_suffix: Text after <input /> (string, default "\n")
  *    - input_help: Gets used as default value on empty input (type=text)
  *      elements. It gets attached through JavaScript (onfocus, onblur and form.onsubmit).
  *
  * @return string The <input /> element.
  */
 function get_input_element($field_params = array(), $parse_common = true)
 {
     if ($parse_common) {
         $this->handle_common_params($field_params);
     }
     if (isset($field_params['input_prefix'])) {
         $input_prefix = $field_params['input_prefix'];
         unset($field_params['input_prefix']);
         // no HTML attribute
     } else {
         $input_prefix = '';
     }
     if (isset($field_params['input_suffix'])) {
         $input_suffix = $field_params['input_suffix'];
         unset($field_params['input_suffix']);
         // no HTML attribute
     } else {
         $input_suffix = "\n";
     }
     if (isset($field_params['input_help']) && (empty($field_params['type']) || $field_params['type'] == 'text')) {
         $this->append_javascript[] = 'input_decorated_help( "' . $field_params['id'] . '", "' . format_to_output($field_params['input_help'], 'formvalue') . '" );';
         unset($field_params['input_help']);
         // no HTML attribute
     }
     $r = $input_prefix . '<input' . get_field_attribs_as_string($field_params) . ' />' . $input_suffix;
     return $r;
 }
Ejemplo n.º 3
0
/**
 * Template function: Display locale flag
 *
 * @param string locale to use, '' for current
 * @param string DEPRECATED PARAM - NOT USED IN THE FUNCTION ANYMORE !!
 * @param string name of class for IMG tag   !! OLD PARAM - NOT USED IN THE FUNCTION ANYMORE !!
 * @param string deprecated HTML align attribute   !! OLD PARAM - NOT USED IN THE FUNCTION ANYMORE !!
 * @param boolean to echo or not
 * @param mixed use absolute url (===true) or path to flags directory (used in installer)   !! OLD PARAM - NOT USED IN THE FUNCTION ANYMORE !!
 */
function locale_flag($locale = '', $collection = 'deprecated_param', $class = 'flag', $align = '', $disp = true, $absoluteurl = true)
{
    global $locales, $current_locale, $country_flags_bg;
    if (empty($locale)) {
        $locale = $current_locale;
    }
    // extract flag name:
    $country_code = strtolower(substr($locale, 3, 2));
    $flag_attribs = array('class' => 'flag', 'title' => isset($locales[$locale]['name']) ? $locales[$locale]['name'] : $locale);
    if (isset($country_flags_bg[$country_code])) {
        // Set background-position from config
        $flag_attribs['style'] = 'background-position:' . $country_flags_bg[$country_code];
    }
    $r = '<span' . get_field_attribs_as_string($flag_attribs) . '></span>';
    if ($disp) {
        echo $r;
    } else {
        return $r;
    }
    // return it
}
Ejemplo n.º 4
0
 /**
  * Event handler: Called when displaying item attachment.
  *
  * @param array Associative array of parameters. $params['File'] - attachment, $params['data'] - output
  * @param boolean TRUE - when render in comments
  * @return boolean true if plugin rendered this attachment
  */
 function RenderItemAttachment(&$params, $in_comments = false)
 {
     $File = $params['File'];
     if (!$this->is_flp_video($File)) {
         // This file cannot be played with this player
         return false;
     }
     $Item =& $params['Item'];
     $item_Blog = $Item->get_Blog();
     $width = intval($this->get_coll_setting('width', $item_Blog));
     if (empty($width)) {
         // Set default width
         $width = 'max-width:100%;';
     } else {
         // Set width from blog plugin setting
         $width = 'width:' . $width . 'px;max-width:100%;';
     }
     // Set height from blog plugin setting
     $height = intval($this->get_coll_setting('height', $item_Blog));
     $height = 'height:' . $height . 'px;';
     if ($File->exists()) {
         if ($in_comments) {
             $params['data'] .= '<div style="clear: both; height: 0px; font-size: 0px"></div>';
         }
         $params['data'] .= '<div class="flowplayer_block" style="' . $width . $height . '">';
         $source_files = array($File);
         if (!isset($params['Comment'])) {
             // Get the fallback files for Item's content
             $source_files = array_merge($source_files, $Item->get_fallback_files($File));
         }
         $sources = array();
         foreach ($source_files as $f => $source_File) {
             $sources[$f] = array('src' => $source_File->get_url());
             if (($Filetype =& $source_File->get_Filetype()) && isset($Filetype->mimetype)) {
                 // Get mime type of the video file
                 $sources[$f]['type'] = $Filetype->mimetype;
             }
         }
         if ($placeholder_File =& $Item->get_placeholder_File($File)) {
             // Display placeholder/poster when image file is linked to the Item with same name as current video File
             $video_placeholder_attr = ' poster="' . $placeholder_File->get_url() . '"';
         } else {
             // No placeholder for current video File
             $video_placeholder_attr = '';
         }
         $params['data'] .= '<div class="flowplayer ' . $this->get_skin($item_Blog) . '" style="background-color:inherit;' . $width . $height . '"><video' . $video_placeholder_attr . '>';
         foreach ($sources as $source) {
             $params['data'] .= '<source' . get_field_attribs_as_string($source, false) . ' />' . "\n";
         }
         $params['data'] .= '</video></div>' . "\n";
         if ($File->get('desc') != '' && $this->get_coll_setting('disp_caption', $item_Blog)) {
             // Display caption
             $params['data'] .= '<div class="flowplayer_text">' . $File->get('desc') . '</div>' . "\n";
         }
         $params['data'] .= '</div>' . "\n";
         if ($this->get_coll_setting('allow_download', $item_Blog)) {
             // Allow to download the video files
             $params['data'] .= '<div class="flowplayer_text"><a href="' . $File->get_url() . '">' . T_('Download this video') . '</a></div>';
         }
         return true;
     }
     return false;
 }
Ejemplo n.º 5
0
 /**
  * Get link from defined userfields
  *
  * @param array Template params
  * @return string Link
  */
 function get_field_link($params = array())
 {
     $params = array_merge(array('target' => '_blank', 'rel' => 'nofollow'), $params);
     $link = '<a href="' . $this->get_field_url() . '"' . get_field_attribs_as_string($params, false) . '>' . $this->get_field_url() . '</a>';
     return $link;
 }
Ejemplo n.º 6
0
 /**
  * Get a link (<a href>) to the tag page of a given tag.
  *
  * @param string Tag
  * @param string Link text (defaults to tag name)
  * @param array Additional attributes for the A tag (href gets overridden).
  * @return string The <a href> link
  */
 function get_tag_link($tag, $text = NULL, $attribs = array())
 {
     if ($this->get_setting('tag_rel_attrib') && $this->get_setting('tag_links') == 'prefix-only') {
         // add rel=tag attrib -- valid only if the last part of the url is the tag name
         if (!isset($attribs['rel'])) {
             $attribs['rel'] = 'tag';
         } else {
             $attribs['rel'] .= ' tag';
         }
     }
     $attribs['href'] = $this->gen_tag_url($tag);
     if (is_null($text)) {
         $text = $tag;
     }
     return '<a' . get_field_attribs_as_string($attribs) . '>' . $text . '</a>';
 }
Ejemplo n.º 7
0
/**
 * Get link tag
 *
 * @param string Url
 * @param string Link Text
 * @param string Link class
 * @param integer Max length of url when url is used as link text
 * @return string HTML link tag
 */
function get_link_tag($url, $text = '', $class = '', $max_url_length = 50)
{
    if (empty($text)) {
        // Link text is empty, Use url
        $text = $url;
        if (strlen($text) > $max_url_length) {
            // Crop url text
            $text = substr($text, 0, $max_url_length) . '&hellip;';
        }
    }
    $link_attrs = array('href' => $url);
    if (!empty($class)) {
        if (strpos($class, '.') === false) {
            // Simple class name
            $link_attrs['class'] = $class;
        } else {
            // This class name is used for email template
            $link_attrs['style'] = emailskin_style($class, false);
        }
    }
    return '<a' . get_field_attribs_as_string($link_attrs) . '>' . $text . '</a>';
}
Ejemplo n.º 8
0
 /**
  * Displays a preview thumbnail which is clickable and opens a view popup
  *
  * @param string what do do with files that are not images? 'fulltype'
  * @param array colorbox plugin params:
  *   - 'init': set true to init colorbox plugin for images and show preview thumb in colorbox
  *   - 'lightbox_rel': set a specific group id string if the displayed image belongs to a group of images
  *   - 'link_id': this must be set only if the displayed file belongs to a Link object
  * @return string HTML to display
  */
 function get_preview_thumb($format_for_non_images = '', $cbox_params = array())
 {
     if ($this->is_image()) {
         // Ok, it's an image:
         $type = $this->get_type();
         $size_name = 'fit-80x80';
         $img_attribs = $this->get_img_attribs($size_name, $type, $type);
         if ($this->check_image_sizes($size_name, 64, $img_attribs)) {
             // If image larger than 64x64 add class to display animated gif during loading
             $img_attribs['class'] = 'loadimg';
         }
         $img = '<img' . get_field_attribs_as_string($img_attribs) . ' />';
         $cbox_params = array_merge(array('init' => false, 'lightbox_rel' => 'lightbox', 'link_id' => 'f' . $this->ID), $cbox_params);
         if ($cbox_params['init']) {
             // Create link to preview image by colorbox plugin
             $link = '<a href="' . $this->get_url() . '" rel="' . $cbox_params['lightbox_rel'] . '" id="' . $cbox_params['link_id'] . '">' . $img . '</a>';
         } else {
             // Get link to view the file (fallback to no view link - just the img):
             $link = $this->get_view_link($img);
         }
         if (!$link) {
             // no view link available:
             $link = $img;
         }
         return $link;
     }
     // Not an image...
     switch ($format_for_non_images) {
         case 'fulltype':
             // Full: Icon + File type:
             return $this->get_view_link($this->get_icon()) . ' ' . $this->get_type();
             break;
     }
     return '';
 }
Ejemplo n.º 9
0
/**
 * Template function: Display/Get country flag
 *
 * @todo factor with locale_flag()
 *
 * @param string country code to use
 * @param string country name to use
 * @param string collection name (subdir of img/flags)   !! OLD PARAM - NOT USED IN THE FUNCTION ANYMORE !!
 * @param string name of class for IMG tag   !! OLD PARAM - NOT USED IN THE FUNCTION ANYMORE !!
 * @param string deprecated HTML align attribute   !! OLD PARAM - NOT USED IN THE FUNCTION ANYMORE !!
 * @param boolean to echo or not
 * @param mixed use absolute url (===true) or path to flags directory   !! OLD PARAM - NOT USED IN THE FUNCTION ANYMORE !!
 * @param string Flag style properties
 * @param boolean TRUE - to display even empty flag
 * @return string Country flag
 */
function country_flag($country_code, $country_name, $collection = 'w16px', $class = 'flag', $align = '', $disp = true, $absoluteurl = true, $flag_style = '', $display_empty = true)
{
    global $country_flags_bg;
    $flag_attribs = array('class' => 'flag', 'title' => $country_name, 'style' => $flag_style);
    if (isset($country_flags_bg[$country_code])) {
        // Set background-position from config
        $flag_attribs['style'] .= 'background-position:' . $country_flags_bg[$country_code];
    }
    if ($display_empty || isset($country_flags_bg[$country_code])) {
        // Init a country flag
        $r = '<span' . get_field_attribs_as_string($flag_attribs) . '>&nbsp;</span>';
    } else {
        // Don't display empty flag when bg-position is not defined in config by country code
        $r = '';
    }
    if ($disp) {
        echo $r;
    } else {
        return $r;
    }
    // return it
}
Ejemplo n.º 10
0
/**
 * Get avatar <img> tag with default picture
 *
 * @param avatar size
 * @param style class of image
 * @param image align
 * @return <img> tag
 */
function get_avatar_imgtag_default($size = 'crop-top-15x15', $class = '', $align = '', $params = array())
{
    global $Settings, $thumbnail_sizes;
    if (!$Settings->get('allow_avatars')) {
        // Avatars are not allowed, Exit here
        return '';
    }
    // Default params:
    $params = array_merge(array('email' => '', 'username' => '', 'default' => ''), $params);
    if (!$Settings->get('use_gravatar')) {
        // Gravatars are not allowed, Use default avatars instead
        global $default_avatar;
        $img_url = $default_avatar;
        $gravatar_width = isset($thumbnail_sizes[$size]) ? $thumbnail_sizes[$size][1] : '15';
        $gravatar_height = isset($thumbnail_sizes[$size]) ? $thumbnail_sizes[$size][2] : '15';
    } else {
        // Gravatars are enabled
        $default_gravatar = $Settings->get('default_gravatar');
        if (empty($params['default'])) {
            // Set default gravatar
            if ($default_gravatar == 'b2evo') {
                // Use gravatar from b2evo default avatar image
                global $default_avatar;
                $params['default'] = $default_avatar;
            } else {
                // Use a selected gravatar type
                $params['default'] = $default_gravatar;
            }
        }
        if (empty($img_url)) {
            $img_url = 'http://www.gravatar.com/avatar/' . md5($params['email']);
            $gravatar_width = isset($thumbnail_sizes[$size]) ? $thumbnail_sizes[$size][1] : '15';
            $gravatar_height = $gravatar_width;
            $img_url_params = array();
            if (!empty($params['rating'])) {
                // Rating
                $img_url_params[] = 'rating=' . $params['rating'];
            }
            if (!empty($gravatar_width)) {
                // Size
                $img_url_params[] = 'size=' . $gravatar_width;
            }
            if (!empty($params['default'])) {
                // Type
                $img_url_params[] = 'default=' . urlencode($params['default']);
            }
            if (count($img_url_params) > 0) {
                // Append url params to request gravatar
                $img_url .= '?' . implode('&', $img_url_params);
            }
        }
    }
    $img_params = array('src' => $img_url, 'width' => $gravatar_width, 'height' => $gravatar_height);
    if (!empty($params['username'])) {
        // Add alt & title
        $img_params['alt'] = $params['username'];
        $img_params['title'] = $params['username'];
    }
    if (!empty($class)) {
        // Add class
        $img_params['class'] = $class;
    }
    if (!empty($align)) {
        // Add align
        $img_params['align'] = $align;
    }
    return '<img' . get_field_attribs_as_string($img_params) . ' />';
}
Ejemplo n.º 11
0
 /**
  * Start a column (data).
  *
  * @param array Additional attributes for the <td> tag (attr_name => attr_value).
  */
 function display_col_start($extra_attr = array())
 {
     // Get colum definitions for current column:
     $col = $this->cols[$this->displayed_cols_count];
     if (isset($col['td_class'])) {
         // We have a class for the total column
         $class = $col['td_class'];
     } else {
         // We have no class for the total column
         $class = '';
     }
     /**
      * Update class and add a fadeout ID for fadeout list results
      */
     if ($this->is_fadeout_line) {
         // echo ' fadeout '.$this->fadeout_count;
         $class .= ' fadeout-ffff00" id="fadeout-' . $this->fadeout_count;
         $this->fadeout_count++;
     }
     if ($this->displayed_cols_count == 0 && isset($this->params['col_start_first'])) {
         // Display first column column start:
         $output = $this->params['col_start_first'];
         // Add the total column class in the col start first param class:
         $output = str_replace('$class$', $class, $output);
     } elseif ($this->displayed_cols_count == count($this->cols) - 1 && isset($this->params['col_start_last'])) {
         // Last column can get special formatting:
         $output = $this->params['col_start_last'];
         // Add the total column class in the col start end param class:
         $output = str_replace('$class$', $class, $output);
     } else {
         // Display regular colmun start:
         $output = $this->params['col_start'];
         // Replace the "class_attrib" in the total col start param by the td column class
         $output = str_replace('$class_attrib$', 'class="' . $class . '"', $output);
     }
     // Custom attributes:
     // Tblue> TODO: Make this more elegant (e. g.: replace "$extra_attr$" with the attributes string).
     if ($extra_attr) {
         if (!isset($extra_attr['format_to_output'])) {
             $output = substr($output, 0, -1) . get_field_attribs_as_string($extra_attr) . '>';
         } else {
             $format_to_output = $extra_attr['format_to_output'];
             unset($extra_attr['format_to_output']);
             $output = substr($output, 0, -1) . get_field_attribs_as_string($extra_attr, $format_to_output) . '>';
         }
     }
     // Check variables in column declaration:
     $output = $this->parse_class_content($output);
     echo $output;
 }
Ejemplo n.º 12
0
/**
 * Get properties of an icon.
 *
 * Note: to get a file type icon, use {@link File::get_icon()} instead.
 *
 * @uses get_icon_info()
 * @param string icon for what? (key)
 * @param string what to return for that icon ('imgtag', 'alt', 'legend', 'file', 'url', 'size' {@link imgsize()})
 * @param array additional params (
 *              'class' => class name when getting 'imgtag',
 *              'size' => param for 'size',
 *              'title' => title attribute for 'imgtag')
 * @param boolean true to include this icon into the legend at the bottom of the page (works for 'imgtag' only)
 */
function get_icon($iconKey, $what = 'imgtag', $params = NULL, $include_in_legend = false)
{
    global $admin_subdir, $Debuglog, $IconLegend, $use_strict;
    global $conf_path;
    global $rsc_path, $rsc_url;
    if (!function_exists('get_icon_info')) {
        require_once $conf_path . '_icons.php';
    }
    $icon = get_icon_info($iconKey);
    if (!$icon || !isset($icon['file'])) {
        return '[no image defined for ' . var_export($iconKey, true) . '!]';
    }
    switch ($what) {
        case 'rollover':
            if (isset($icon['rollover'])) {
                // Image has rollover available
                return $icon['rollover'];
            }
            return false;
            /* BREAK */
        /* BREAK */
        case 'file':
            return $rsc_path . $icon['file'];
            /* BREAK */
        /* BREAK */
        case 'alt':
            if (isset($icon['alt'])) {
                // alt tag from $map_iconfiles
                return $icon['alt'];
            } else {
                // fallback to $iconKey as alt-tag
                return $iconKey;
            }
            /* BREAK */
        /* BREAK */
        case 'legend':
            if (isset($icon['legend'])) {
                // legend tag from $map_iconfiles
                return $icon['legend'];
            } else {
                if (isset($icon['alt'])) {
                    // alt tag from $map_iconfiles
                    return $icon['alt'];
                } else {
                    // fallback to $iconKey as alt-tag
                    return $iconKey;
                }
            }
            /* BREAK */
        /* BREAK */
        case 'class':
            if (isset($icon['class'])) {
                return $icon['class'];
            } else {
                return '';
            }
            /* BREAK */
        /* BREAK */
        case 'url':
            return $rsc_url . $icon['file'];
            /* BREAK */
        /* BREAK */
        case 'size':
            if (!isset($icon['size'])) {
                $Debuglog->add('No iconsize for [' . $iconKey . ']', 'icons');
                $icon['size'] = imgsize($rsc_path . $icon['file']);
            }
            switch ($params['size']) {
                case 'width':
                    return $icon['size'][0];
                case 'height':
                    return $icon['size'][1];
                case 'widthxheight':
                    return $icon['size'][0] . 'x' . $icon['size'][1];
                case 'width':
                    return $icon['size'][0];
                case 'string':
                    return 'width="' . $icon['size'][0] . '" height="' . $icon['size'][1] . '"';
                default:
                    return $icon['size'];
            }
            /* BREAK */
        /* BREAK */
        case 'imgtag':
            $r = '<img src="' . $rsc_url . $icon['file'] . '" ';
            if (!$use_strict) {
                // Include non CSS fallbacks - transitional only:
                $r .= 'border="0" align="top" ';
            }
            // Include class (will default to "icon"):
            if (!isset($params['class'])) {
                if (isset($icon['class'])) {
                    // This icon has a class
                    $params['class'] = $icon['class'];
                } else {
                    $params['class'] = '';
                }
            }
            // Include size (optional):
            if (isset($icon['size'])) {
                $r .= 'width="' . $icon['size'][0] . '" height="' . $icon['size'][1] . '" ';
            }
            // Include alt (XHTML mandatory):
            if (!isset($params['alt'])) {
                if (isset($icon['alt'])) {
                    // alt-tag from $map_iconfiles
                    $params['alt'] = $icon['alt'];
                } else {
                    // $iconKey as alt-tag
                    $params['alt'] = $iconKey;
                }
            }
            // Add all the attributes:
            $r .= get_field_attribs_as_string($params, false);
            // Close tag:
            $r .= '/>';
            if ($include_in_legend && isset($IconLegend)) {
                // This icon should be included into the legend:
                $IconLegend->add_icon($iconKey);
            }
            return $r;
            /* BREAK */
        /* BREAK */
        case 'noimg':
            $blank_icon = get_icon_info('pixel');
            $r = '<img src="' . $rsc_url . $blank_icon['file'] . '" ';
            // Include non CSS fallbacks:
            $r .= 'border="0" align="top" ';
            // Include class (will default to "noicon"):
            if (!isset($params['class'])) {
                if (isset($icon['class'])) {
                    // This icon has a class
                    $params['class'] = $icon['class'];
                } else {
                    $params['class'] = 'no_icon';
                }
            }
            // Include size (optional):
            if (isset($icon['size'])) {
                $r .= 'width="' . $icon['size'][0] . '" height="' . $icon['size'][1] . '" ';
            }
            // Include alt (XHTML mandatory):
            if (!isset($params['alt'])) {
                $params['alt'] = '';
            }
            // Add all the attributes:
            $r .= get_field_attribs_as_string($params, false);
            // Close tag:
            $r .= '/>';
            return $r;
            /* BREAK */
    }
}
Ejemplo n.º 13
0
/**
 * Get properties of an icon.
 *
 * Note: to get a file type icon, use {@link File::get_icon()} instead.
 *
 * @uses get_icon_info()
 * @param string icon for what? (key)
 * @param string what to return for that icon ('imgtag', 'alt', 'legend', 'file', 'url', 'size' {@link imgsize()})
 * @param array additional params
 *   - 'class' => class name when getting 'imgtag',
 *   - 'size' => param for 'size',
 *   - 'title' => title attribute for 'imgtag'
 * @param boolean true to include this icon into the legend at the bottom of the page (works for 'imgtag' only)
 * @return mixed False on failure, string on success.
 */
function get_icon($iconKey, $what = 'imgtag', $params = NULL, $include_in_legend = false)
{
    global $admin_subdir, $Debuglog, $use_strict;
    global $conf_path;
    global $rsc_path, $rsc_uri;
    if (!function_exists('get_icon_info')) {
        require_once $conf_path . '_icons.php';
    }
    $icon = get_icon_info($iconKey);
    if (!$icon) {
        $Debuglog->add('No image defined for ' . var_export($iconKey, true) . '!', 'icons');
        return false;
    }
    if (!isset($icon['file']) && $what != 'imgtag') {
        $icon['file'] = 'icons/icons_sprite.png';
    }
    switch ($what) {
        case 'rollover':
            if (isset($icon['rollover'])) {
                // Image has rollover available
                global $b2evo_icons_type;
                if (isset($b2evo_icons_type) && (!empty($icon['glyph']) || !empty($icon['fa']))) {
                    // Glyph and font-awesome icons don't have rollover effect
                    return false;
                }
                return $icon['rollover'];
            }
            return false;
            /* BREAK */
        /* BREAK */
        case 'file':
            return $rsc_path . $icon['file'];
            /* BREAK */
        /* BREAK */
        case 'alt':
            if (isset($icon['alt'])) {
                // alt tag from $map_iconfiles
                return $icon['alt'];
            } else {
                // fallback to $iconKey as alt-tag
                return $iconKey;
            }
            /* BREAK */
        /* BREAK */
        case 'legend':
            if (isset($icon['legend'])) {
                // legend tag from $map_iconfiles
                return $icon['legend'];
            } else {
                if (isset($icon['alt'])) {
                    // alt tag from $map_iconfiles
                    return $icon['alt'];
                } else {
                    // fallback to $iconKey as alt-tag
                    return $iconKey;
                }
            }
            /* BREAK */
        /* BREAK */
        case 'class':
            if (isset($icon['class'])) {
                return $icon['class'];
            } else {
                return '';
            }
            /* BREAK */
        /* BREAK */
        case 'url':
            return $rsc_uri . $icon['file'];
            /* BREAK */
        /* BREAK */
        case 'size':
            if (!isset($icon['size'])) {
                $Debuglog->add('No iconsize for [' . $iconKey . ']', 'icons');
                $icon['size'] = imgsize($rsc_path . $icon['file']);
            }
            switch ($params['size']) {
                case 'width':
                    return $icon['size'][0];
                case 'height':
                    return $icon['size'][1];
                case 'widthxheight':
                    return $icon['size'][0] . 'x' . $icon['size'][1];
                case 'width':
                    return $icon['size'][0];
                case 'string':
                    return 'width="' . $icon['size'][0] . '" height="' . $icon['size'][1] . '"';
                default:
                    return $icon['size'];
            }
            /* BREAK */
        /* BREAK */
        case 'xy':
            if (isset($icon['xy'])) {
                // Return data for style property "background-position"
                return "-" . $icon['xy'][0] . "px -" . $icon['xy'][1] . "px";
            }
            return false;
        case 'sprite':
            if (isset($icon['xy'])) {
                // Image uses spite file
                return true;
            }
            return false;
            /* BREAK */
        /* BREAK */
        case 'imgtag':
            global $b2evo_icons_type;
            if (isset($b2evo_icons_type)) {
                // Specific icons type is defined
                $current_icons_type = $b2evo_icons_type;
                if ($current_icons_type == 'fontawesome-glyphicons') {
                    // Use fontawesome icons as a priority over the glyphicons
                    $current_icons_type = isset($icon['fa']) ? 'fontawesome' : 'glyphicons';
                }
                switch ($current_icons_type) {
                    case 'glyphicons':
                        // Use glyph icons of bootstrap
                        $icon_class_prefix = 'glyphicon glyphicon-';
                        $icon_param_name = 'glyph';
                        $icon_content = '&nbsp;';
                        break;
                    case 'fontawesome':
                        // Use the icons from http://fortawesome.github.io/Font-Awesome/icons/
                        $icon_class_prefix = 'fa fa-';
                        $icon_param_name = 'fa';
                        $icon_content = '';
                        break;
                }
            }
            if (isset($icon_class_prefix) && !empty($icon[$icon_param_name])) {
                // Use glyph or fa icon if it is defined in icons config
                if (isset($params['class'])) {
                    // Get class from params
                    $params['class'] = $icon_class_prefix . $icon[$icon_param_name] . ' ' . $params['class'];
                } else {
                    // Set default class
                    $params['class'] = $icon_class_prefix . $icon[$icon_param_name];
                }
                $styles = array();
                if (isset($icon['color-' . $icon_param_name])) {
                    // Set a color for icon only for current type
                    if ($icon['color-' . $icon_param_name] != 'default') {
                        $styles[] = 'color:' . $icon['color-' . $icon_param_name];
                    }
                } elseif (isset($icon['color'])) {
                    // Set a color for icon for all types
                    if ($icon['color'] != 'default') {
                        $styles[] = 'color:' . $icon['color'];
                    }
                }
                if (isset($icon['color-over'])) {
                    // Set a color for mouse over event
                    $params['data-color'] = $icon['color-over'];
                }
                if (isset($icon['toggle-' . $icon_param_name])) {
                    // Set a color for mouse over event
                    $params['data-toggle'] = $icon['toggle-' . $icon_param_name];
                }
                if (!isset($params['title'])) {
                    // Use 'alt' for 'title'
                    if (isset($params['alt'])) {
                        $params['title'] = $params['alt'];
                        unset($params['alt']);
                    } else {
                        if (!isset($params['alt']) && isset($icon['alt'])) {
                            $params['title'] = $icon['alt'];
                        }
                    }
                }
                if (isset($icon['size-' . $icon_param_name])) {
                    // Set a size for icon only for current type
                    if (isset($icon['size-' . $icon_param_name][0])) {
                        // Width
                        $styles['width'] = 'width:' . $icon['size-' . $icon_param_name][0] . 'px';
                    }
                    if (isset($icon['size-' . $icon_param_name][1])) {
                        // Height
                        $styles['width'] = 'height:' . $icon['size-' . $icon_param_name][1] . 'px';
                    }
                }
                if (isset($params['style'])) {
                    // Keep styles from params
                    $styles[] = $params['style'];
                }
                if (!empty($styles)) {
                    // Init attribute 'style'
                    $params['style'] = implode(';', $styles);
                }
                // Add all the attributes:
                $params = get_field_attribs_as_string($params, false);
                $r = '<span' . $params . '>' . $icon_content . '</span>';
            } elseif (!isset($icon['file'])) {
                // Use span tag with sprite instead of img
                $styles = array();
                if (isset($params['xy'])) {
                    // Get background position from params
                    $styles[] = "background-position: " . $params['xy'][0] . "px " . $params['xy'][1] . "px";
                    unset($params['xy']);
                } else {
                    if (isset($icon['xy'])) {
                        // Set background position in the icons_sprite.png
                        $styles[] = "background-position: -" . $icon['xy'][0] . "px -" . $icon['xy'][1] . "px";
                    }
                }
                if (isset($params['size'])) {
                    // Get sizes from params
                    $icon['size'] = $params['size'];
                    unset($params['size']);
                }
                if (isset($icon['size'])) {
                    // Set width & height
                    if ($icon['size'][0] != 16) {
                        $styles[] = "width: " . $icon['size'][0] . "px";
                    }
                    if ($icon['size'][1] != 16) {
                        $styles[] = "height: " . $icon['size'][1] . "px; line-height: " . $icon['size'][1] . "px";
                    }
                }
                if (isset($params['style'])) {
                    // Get styles from params
                    $styles[] = $params['style'];
                }
                if (count($styles) > 0) {
                    $params['style'] = implode('; ', $styles);
                }
                if (!isset($params['title'])) {
                    // Use 'alt' for 'title'
                    if (isset($params['alt'])) {
                        $params['title'] = $params['alt'];
                        unset($params['alt']);
                    } else {
                        if (!isset($params['alt']) && isset($icon['alt'])) {
                            $params['title'] = $icon['alt'];
                        }
                    }
                }
                if (isset($params['class'])) {
                    // Get class from params
                    $params['class'] = 'icon ' . $params['class'];
                } else {
                    // Set default class
                    $params['class'] = 'icon';
                }
                // Add all the attributes:
                $params = get_field_attribs_as_string($params, false);
                $r = '<span' . $params . '>&nbsp;</span>';
            } else {
                // Use img tag
                $r = '<img src="' . $rsc_uri . $icon['file'] . '" ';
                if (!$use_strict) {
                    // Include non CSS fallbacks - transitional only:
                    $r .= 'border="0" align="top" ';
                }
                // Include class (will default to "icon"):
                if (!isset($params['class'])) {
                    if (isset($icon['class'])) {
                        // This icon has a class
                        $params['class'] = $icon['class'];
                    } else {
                        $params['class'] = '';
                    }
                }
                // Include size (optional):
                if (isset($icon['size'])) {
                    $r .= 'width="' . $icon['size'][0] . '" height="' . $icon['size'][1] . '" ';
                }
                // Include alt (XHTML mandatory):
                if (!isset($params['alt'])) {
                    if (isset($icon['alt'])) {
                        // alt-tag from $map_iconfiles
                        $params['alt'] = $icon['alt'];
                    } else {
                        // $iconKey as alt-tag
                        $params['alt'] = $iconKey;
                    }
                }
                // Add all the attributes:
                $r .= get_field_attribs_as_string($params, false);
                // Close tag:
                $r .= '/>';
                if ($include_in_legend && ($IconLegend =& get_IconLegend())) {
                    // This icon should be included into the legend:
                    $IconLegend->add_icon($iconKey);
                }
            }
            return $r;
            /* BREAK */
        /* BREAK */
        case 'noimg':
            global $b2evo_icons_type;
            if (isset($b2evo_icons_type)) {
                // Specific icons type is defined
                $current_icons_type = $b2evo_icons_type;
                if ($current_icons_type == 'fontawesome-glyphicons') {
                    // Use fontawesome icons as a priority over the glyphicons
                    $current_icons_type = isset($icon['fa']) ? 'fontawesome' : 'glyphicons';
                }
                switch ($current_icons_type) {
                    case 'glyphicons':
                        // Use glyph icons of bootstrap
                        $icon_param_name = 'glyph';
                        break;
                    case 'fontawesome':
                        // Use the icons from http://fortawesome.github.io/Font-Awesome/icons/
                        $icon_param_name = 'fa';
                        break;
                }
            }
            $styles = array();
            if (isset($icon_param_name) && !empty($icon[$icon_param_name])) {
                // Use glyph or fa icon if it is defined in icons config
                if (isset($icon['size-' . $icon_param_name])) {
                    // Set a size for icon only for current type
                    if (isset($icon['size-' . $icon_param_name][0])) {
                        // Width
                        $styles['width'] = 'width:' . $icon['size-' . $icon_param_name][0] . 'px';
                    }
                    if (isset($icon['size-' . $icon_param_name][1])) {
                        // Height
                        $styles['width'] = 'height:' . $icon['size-' . $icon_param_name][1] . 'px';
                    }
                    if (isset($icon['size'])) {
                        // Unset size for sprite icon
                        unset($icon['size']);
                    }
                }
            }
            // Include size (optional):
            if (isset($icon['size'])) {
                $params['size'] = $icon['size'];
            }
            $styles[] = 'margin:0 2px';
            if (isset($params['style'])) {
                // Keep styles from params
                $styles[] = $params['style'];
            }
            if (!empty($styles)) {
                // Init attribute 'style'
                $params['style'] = implode(';', $styles);
            }
            return get_icon('pixel', 'imgtag', $params);
            /* BREAK */
            /*
            			$blank_icon = get_icon_info('pixel');
            
            			$r = '<img src="'.$rsc_uri.$blank_icon['file'].'" ';
            
            			// TODO: dh> add this only for !$use_strict, like above?
            			// Include non CSS fallbacks (needed by bozos... and basic skin):
            			$r .= 'border="0" align="top" ';
            
            			// Include class (will default to "noicon"):
            			if( ! isset( $params['class'] ) )
            			{
            				if( isset($icon['class']) )
            				{	// This icon has a class
            					$params['class'] = $icon['class'];
            				}
            				else
            				{
            					$params['class'] = 'no_icon';
            				}
            			}
            
            			// Include size (optional):
            			if( isset( $icon['size'] ) )
            			{
            				$r .= 'width="'.$icon['size'][0].'" height="'.$icon['size'][1].'" ';
            			}
            
            			// Include alt (XHTML mandatory):
            			if( ! isset( $params['alt'] ) )
            			{
            				$params['alt'] = '';
            			}
            
            			// Add all the attributes:
            			$r .= get_field_attribs_as_string( $params, false );
            
            			// Close tag:
            			$r .= '/>';
            
            			return $r;*/
            /* BREAK */
    }
}
Ejemplo n.º 14
0
 /**
  * Generate a general button element.
  *
  * @param array Optional params.
  *    Additionally to {@link $_common_params} you can use:
  *    - input_prefix: Text before <input /> (string, default '')
  *    - input_suffix: Text after <input /> (string, default "\n")
  *    - input_help: Gets used as default value on empty input (type=text)
  *      elements. It gets attached through JavaScript (onfocus, onblur and form.onsubmit).
  *    - format_to_output: Use format_to_output in get_field_attribs_as_string? (boolean, default True)
  *
  * @return string The <input /> element.
  */
 function get_button_element($field_params = array(), $parse_common = true)
 {
     if ($parse_common) {
         $this->handle_common_params($field_params);
     }
     if (isset($field_params['input_prefix'])) {
         $input_prefix = $field_params['input_prefix'];
         unset($field_params['input_prefix']);
         // no HTML attribute
     } else {
         $input_prefix = '';
     }
     if (isset($field_params['input_suffix'])) {
         $input_suffix = $field_params['input_suffix'];
         unset($field_params['input_suffix']);
         // no HTML attribute
     } else {
         $input_suffix = "\n";
     }
     if (isset($field_params['input_help']) && (empty($field_params['type']) || $field_params['type'] == 'text')) {
         $this->append_javascript[] = 'input_decorated_help( "' . $field_params['id'] . '", "' . format_to_output($field_params['input_help'], 'formvalue') . '" );';
         unset($field_params['input_help']);
         // no HTML attribute
     }
     if (isset($field_params['format_to_output'])) {
         $format_to_output = $field_params['format_to_output'];
         unset($field_params['format_to_output']);
     } else {
         $format_to_output = true;
     }
     if (isset($field_params['inline'])) {
         // Delete 'inline' param from attributes list
         unset($field_params['inline']);
     }
     if (isset($field_params['input_required'])) {
         // Set html attribute "required" (used to highlight input with red border/shadow by bootstrap)
         $field_params['required'] = $field_params['input_required'];
         unset($field_params['input_required']);
     }
     $r = $input_prefix;
     if ($field_params['tag'] == 'button') {
         $value = $field_params['value'];
         unset($field_params['value']);
         unset($field_params['tag']);
         $r .= '<button' . get_field_attribs_as_string($field_params, $format_to_output) . '>' . $value . '</button>';
     } else {
         $r .= '<input' . get_field_attribs_as_string($field_params, $format_to_output) . ' />';
     }
     $r .= $input_suffix;
     return $r;
 }
Ejemplo n.º 15
0
/**
 * Template tag: Get a link to logout
 *
 * @param string
 * @param string
 * @param string link text can include %s for current user login
 * @return string
 */
function get_user_logout_link($before = '', $after = '', $link_text = '', $link_title = '#', $params = array())
{
    global $admin_url, $baseurl, $htsrv_url_sensitive, $current_User, $is_admin_page, $Blog;
    if (!is_logged_in()) {
        return false;
    }
    if ($link_text == '') {
        $link_text = T_('Logout');
    }
    if ($link_title == '#') {
        $link_title = T_('Logout from your account');
    }
    if ($is_admin_page) {
        if (isset($Blog)) {
            // Go to the home page of the blog that was being edited:
            $redirect_to = $Blog->get('url');
        } else {
            // We were not editing a blog...
            // return to global home:
            $redirect_to = url_rel_to_same_host($baseurl, $htsrv_url_sensitive);
            // Alternative: return to the login page (fp> a basic user would be pretty lost on that login page)
            // $redirect_to = url_rel_to_same_host($admin_url, $htsrv_url_sensitive);
        }
    } else {
        // Return to current blog page:
        $redirect_to = url_rel_to_same_host(regenerate_url('', '', '', '&'), $htsrv_url_sensitive);
    }
    $r = $before;
    $r .= '<a href="' . $htsrv_url_sensitive . 'login.php?action=logout&amp;redirect_to=' . rawurlencode($redirect_to) . '"';
    $r .= get_field_attribs_as_string($params, false);
    $r .= ' title="' . $link_title . '">';
    $r .= sprintf($link_text, $current_User->login);
    $r .= '</a>';
    $r .= $after;
    return $r;
}
Ejemplo n.º 16
0
 /**
  * @param array Smiley
  * @param array Override params, e.g. "class"
  */
 function get_smiley_img_tag($smiley, $override_fields = array())
 {
     $attribs = array('src' => $smiley['image'], 'title' => format_to_output($smiley['code'], 'htmlattr'), 'alt' => format_to_output($smiley['code'], 'htmlattr'), 'class' => 'middle');
     if ($smiley_wh = imgsize($smiley['path'], 'widthheight_assoc')) {
         $attribs += $smiley_wh;
     }
     if ($override_fields) {
         $attribs = $override_fields + $attribs;
     }
     return '<img' . get_field_attribs_as_string($attribs) . ' />';
 }
Ejemplo n.º 17
0
 /**
  * Displays a preview thumbnail which is clickable and opens a view popup
  *
  * @param string what do do with files that are not images? 'fulltype'
  * @param boolean TRUE - to init colorbox plugin for images
  * @return string HTML to display
  */
 function get_preview_thumb($format_for_non_images = '', $preview_image = false)
 {
     if ($this->is_image()) {
         // Ok, it's an image:
         $type = $this->get_type();
         $img_attribs = $this->get_img_attribs('fit-80x80', $type, $type);
         $img = '<img' . get_field_attribs_as_string($img_attribs) . ' />';
         if ($preview_image) {
             // Create link to preview image by colorbox plugin
             $link = '<a href="' . $this->get_url() . '" rel="lightbox" id="f' . $this->ID . '">' . $img . '</a>';
         } else {
             // Get link to view the file (fallback to no view link - just the img):
             $link = $this->get_view_link($img);
         }
         if (!$link) {
             // no view link available:
             $link = $img;
         }
         return $link;
     }
     // Not an image...
     switch ($format_for_non_images) {
         case 'fulltype':
             // Full: Icon + File type:
             return $this->get_view_link($this->get_icon()) . ' ' . $this->get_type();
             break;
     }
     return '';
 }