/** * Converts an underscored or CamelCase word into a English * sentence. * * The titleize function converts text like "WelcomePage", * "welcome_page" or "welcome page" to this "Welcome * Page". * If second parameter is set to 'first' it will only * capitalize the first character of the title. * * @access public * @static * @param string $word Word to format as tile * @param string $uppercase If set to 'first' it will only uppercase the * first character. Otherwise it will uppercase all * the words in the title. * @return string Text formatted as title */ function titleize($word, $uppercase = '') { $uppercase = $uppercase == 'first' ? 'ucfirst' : 'ucwords'; return $uppercase(WOOF_Inflector::humanize(WOOF_Inflector::underscore($word))); }
public static function icon_select($val, $id, $name, $uploader_id) { global $wf; // check if the value is a library-derived icon $is_lib = false; if (preg_match("/lib-(.+)--(.+)/", $val, $matches)) { $val = $matches[1].WOOF_DIR_SEP.$matches[2]; $is_lib = true; } ?> <style type="text/css"> <?php //if ($is_lib) { // echo '#'.$uploader_id.' { display: none; } '; //} $iterator = new DirectoryIterator(MASTERPRESS_EXTENSIONS_ICONS_DIR); foreach ($iterator as $file) { $file_name = $file->getFileName(); if (substr($file_name, 0, 1) == ".") { continue; } if ($file->isDir()) { $icon_select = true; $sub_iterator = new DirectoryIterator(MASTERPRESS_EXTENSIONS_ICONS_DIR.WOOF_DIR_SEP.$file_name); foreach ($sub_iterator as $sub) { $sub_file_name = $sub->getFileName(); $pi = pathinfo($sub_file_name); $sub_ext = $pi["extension"]; $sub_base_name = $pi["filename"]; if (substr($sub_file_name, 0, 1) == ".") { continue; } $url = $wf->root_relative_url(MASTERPRESS_EXTENSIONS_ICONS_URL."/".$file_name."/".$sub_file_name); echo ".icon-".sanitize_title_with_dashes($file_name."-".$sub_file_name)." { background-image: url(".$url."); }"; } } } ?> </style> <?php if (isset($icon_select)) : ?> <div class="icon-select-wrap"> <select id="<?php echo $id ?>" name="<?php echo $name ?>" data-uploader="<?php echo $uploader_id ?>" data-no_icon="<?php echo MPU::img_url("icon-no-icon.png") ?>" data-base="<?php echo MASTERPRESS_EXTENSIONS_ICONS_URL ?>" data-placeholder="<?php _e("-- OR select an icon --", MASTERPRESS_DOMAIN) ?>" class="select2-source icon-select with-icons"> <option value=""></option> <?php foreach (new DirectoryIterator(MASTERPRESS_EXTENSIONS_ICONS_DIR) as $file) { $file_name = $file->getFileName(); if (substr($file_name, 0, 1) == ".") { continue; } if ($file->isDir()) { ?> <optgroup label="<?php echo WOOF_Inflector::humanize($file_name) ?>"> <?php foreach (new DirectoryIterator(MASTERPRESS_EXTENSIONS_ICONS_DIR.WOOF_DIR_SEP.$file_name) as $sub) { $sub_file_name = $sub->getFileName(); $pi = pathinfo($sub_file_name); $sub_ext = $pi["extension"]; $sub_base_name = $pi["filename"]; $path = $file_name.WOOF_DIR_SEP.$sub_file_name; if (substr($sub_file_name, 0, 1) == ".") { continue; } $selected = WOOF_HTML::selected_attr($val == $path); ?> <option value="<?php echo $path ?>" <?php echo $selected ?> data-icon="mp-icon icon-<?php echo sanitize_title_with_dashes($file_name."-".$sub_file_name) ?>" class=""><?php echo WOOF_Inflector::titleize($sub_base_name) ?></option> <?php } } ?> </optgroup> <?php } ?> </select> </div> <?php endif; }