示例#1
0
        }
        if (is_single() || is_page()) {
            $title = get_the_title();
        }
        if (is_search()) {
            $title = sprintf(__("Search: %s", "wl"), get_search_query());
        }
        if (is_date()) {
            if (is_month()) {
                $date = get_the_date("F Y");
            } else {
                if (is_year()) {
                    $date = get_the_date("Y");
                } else {
                    $date = get_the_date();
                }
            }
            $title = sprintf(__("Archives: %s", "wl"), $date);
        }
        if (is_front_page() || is_home()) {
            $title = get_bloginfo("description", "display");
        }
        if ($title != "") {
            return "{$prefix}{$separator}{$title}";
        } else {
            return $prefix;
        }
    }
}
Wordless::register_helper("QueryHelper");
示例#2
0
    /**
     * Generate placeholder text.
     * 
     * Using the famous Lorem Ipsum base text, generate a dummy text based on 
     * specified options.
     * 
     * @param int $count
     *   The length in words of the dummy text.
     * @param array $options
     *   (optional) An array of options to manage text generation. Options 
     *   available are:
     *   - html: wheter to build HTML content or plain content. Default to false.
     *   - lorem: if the text must start with "Lorem ipsum..." or not.
     *     Default to true.
     * 
     * @return @e string 
     *   The generated dummy text.
     * 
     * @ingroup helperfunc
     */
    public function placeholder_text($count, $options = array())
    {
        $options = array_merge(array('html' => false, 'lorem' => true), $options);
        $generator = new LoremIpsumGenerator();
        $html_format = $options['html'] ? 'plain' : 'html';
        $start_with_lorem_ipsum = $options['lorem'];
        return ucfirst($generator->getContent($count, $html_format, $start_with_lorem_ipsum));
    }
}
Wordless::register_helper("FakerHelper");
    function link_to($text = '', $link = NULL, $attributes = NULL)
    {
        if (!is_string($link)) {
            $link = "#";
        }
        $options = array("href" => $link);
        if (is_array($attributes)) {
            $options = array_merge($options, $attributes);
        }
        return $this->content_tag("a", $text, $options);
    }
    function content_type_meta_tag($content = NULL)
    {
        $content = $content ? $content : get_bloginfo('html_type') . '; ' . 'charset=' . get_bloginfo('charset');
        $attrs = array("http-equiv" => "Content-type", "content" => $content);
        return content_tag("meta", NULL, $attrs);
    }
    function title_tag($title = NULL, $attributes = array())
    {
        $title = $title ? $title : get_page_title();
        return content_tag("title", $title, $attributes);
    }
    function pingback_link_tag($url = NULL)
    {
        $url = $url ? $url : get_bloginfo('pingback_url');
        $attributes = array("href" => $url);
        return content_tag("link", NULL, $attributes);
    }
}
Wordless::register_helper("TagHelper");
示例#4
0
    {
        ob_start();
        render_partial($name, $locals);
        $partial_content = ob_get_contents();
        ob_end_clean();
        return $partial_content;
    }
    function render_partial($name, $locals = array())
    {
        $parts = preg_split("/\\//", $name);
        if (!preg_match("/^_/", $parts[sizeof($parts) - 1])) {
            $parts[sizeof($parts) - 1] = "_" . $parts[sizeof($parts) - 1];
        }
        render_template(implode($parts, "/"), $locals);
    }
    function yield()
    {
        global $current_view;
        render_template($current_view);
    }
    function render_view($name, $layout = 'default')
    {
        ob_start();
        global $current_view;
        $current_view = $name;
        render_template("layouts/{$layout}");
        ob_flush();
    }
}
Wordless::register_helper("RenderHelper");
示例#5
0
        $options = array_merge(self::$DEFAULT_CURRENCY_VALUES, $options);
        $precision = $this->array_delete($options, 'precision');
        $significant = $this->array_delete($options, 'significant');
        $strip_insignificant_zeros = $this->array_delete($options, 'strip_insignificant_zeros');
        if ($significant && $precision > 0) {
            if ($number == 0) {
                $digits = 1;
                $rounded_number = 0;
            } else {
                $digits = floor(log10(abs($number)) + 1);
                $rounded_number = (double) round($number / (double) pow(10, $digits - $precision)) * pow(10, $digits - $precision);
                $digits = floor(log10(abs($rounded_number)) + 1);
            }
            $precision -= $digits;
            $precision = $precision > 0 ? $precision : 0;
            // don't let precision be negative
        } else {
            $rounded_number = (double) round($number, $precision);
        }
        $formatted_number = number_with_delimiter(sprintf("%01.{$precision}f", $rounded_number), $options);
        if ($strip_insignificant_zeros) {
            $escaped_separator = preg_quote($options['separator']);
            $formatted_number = preg_replace("/({$escaped_separator})(\\d*[1-9])?0+\\z/", '\\1\\2', $formatted_number);
            return preg_replace("/{$escaped_separator}\\z/", '', $formatted_number);
        } else {
            return $formatted_number;
        }
    }
}
Wordless::register_helper("NumberHelper");
示例#6
0
     *
     */
    function javascript_include_tag()
    {
        $sources = func_get_args();
        $attributes = NULL;
        if (is_array($sources[count($sources) - 1])) {
            $attributes = array_pop($sources);
        }
        $tags = array();
        foreach ($sources as $source) {
            // only http[s] or // (leading double slash to inherit the protocol)
            // are treated as absolute url
            if (!is_absolute_url($source)) {
                $source = javascript_url($source);
                if (!preg_match("/\\.js\$/", $source)) {
                    $source .= ".js";
                }
                $source = $this->asset_version($source);
            }
            $options = array("src" => $source, "type" => "text/javascript");
            if (is_array($attributes)) {
                $options = array_merge($options, $attributes);
            }
            $tags[] = content_tag("script", "", $options);
        }
        return join("\n", $tags);
    }
}
Wordless::register_helper("AssetTagHelper");
示例#7
0
        if (!is_array($name)) {
            $name = array("singular" => $name, "plural" => pluralize($name));
        }
        $uc_plural = __(ucwords(preg_replace("/_/", " ", $name["plural"])));
        $uc_singular = __(ucwords(preg_replace("/_/", " ", $name["singular"])));
        $labels = array('name' => $uc_plural, 'singular_name' => $uc_singular, 'add_new_item' => sprintf(__("Add new %s", "we"), $uc_singular), 'edit_item' => sprintf(__("Edit %s", "we"), $uc_singular), 'new_item' => sprintf(__("New %s", "we"), $uc_singular), 'view_item' => sprintf(__("View %s", "we"), $uc_singular), 'search_items' => sprintf(__("Search %s", "we"), $uc_plural), 'not_found' => sprintf(__("No %s found.", "we"), $uc_plural), 'not_found_in_trash' => sprintf(__("No %s found in Trash", "we"), $uc_plural), 'parent_item_colon' => ',', 'menu_name' => $uc_plural);
        register_post_type($name["singular"], array('labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'query_var' => true, 'has_archive' => true, 'rewrite' => array('slug' => $name["plural"]), 'capability_type' => 'post', 'hierarchical' => false, 'menu_position' => null, 'supports' => $supports));
    }
    /**
     * Create a new taxonomy.
     * 
     * @param string $name
     *   The name of the taxonomy.
     * @param $post_types
     * @param boolean $hierarchical (optional)
     * 
     * @ingroup helperfunc
     */
    function new_taxonomy($name, $post_types, $hierarchical = true)
    {
        if (!is_array($name)) {
            $name = array("singular" => $name, "plural" => pluralize($name));
        }
        $uc_plural = ucwords(preg_replace("/_/", " ", $name["plural"]));
        $uc_singular = ucwords(preg_replace("/_/", " ", $name["singular"]));
        $labels = array("name" => $uc_singular, "singular_name" => $uc_singular, "search_items" => sprintf(__("Search %s", "we"), $uc_plural), "all_items" => sprintf(__("All %s", "we"), $uc_plural), "parent_item" => sprintf(__("Parent %s", "we"), $uc_singular), "parent_item_colon" => sprintf(__("Parent %s:", "we"), $uc_singular), "edit_item" => sprintf(__("Edit %s", "we"), $uc_singular), "update_item" => sprintf(__("Update %s", "we"), $uc_singular), "add_new_item" => sprintf(__("Add new %s", "we"), $uc_singular), "new_item_name" => sprintf(__("New %n Name", "we"), $uc_singular), "menu_name" => $uc_plural);
        register_taxonomy($name["singular"], $post_types, array('hierarchical' => $hierarchical, 'labels' => $labels, 'show_ui' => true, 'query_var' => true, 'rewrite' => array('slug' => $name["plural"])));
    }
}
Wordless::register_helper("ModelHelper");
示例#8
0
        $metas = array();
        $groups = $connector["field_groups"];
        if (!$groups) {
            return array();
        }
        foreach ($groups as $group) {
            $metas[$group["name"]] = array();
            $fields = $group["fields"];
            foreach ($fields as $field) {
                if (sizeof($field["saved_values"]) == 1) {
                    $metas[$group["name"]][$field["name"]] = $field["saved_values"][0];
                } else {
                    $metas[$group["name"]][$field["name"]] = $field["saved_values"];
                }
            }
        }
        return $metas;
    }
    /**
     * @deprecated Dismissing support for simple field helper after adoption
     *             of Advanced Custom Field as default custom fileds creation
     *             plug-in
     */
    function simple_fields_meta($post, $group, $field)
    {
        $metas = simple_fields_metas($post);
        return $metas[$group][$field];
    }
}
Wordless::register_helper("SimpleFieldsHelper");
示例#9
0
                $new_height = $height_orig * $ratio;
                $image_scaled = imagecreatetruecolor($new_width, $new_height);
                // scaling!
                imagecopyresampled($image_scaled, $image, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
                $image = $image_scaled;
                if ($new_width > $width || $new_height > $height) {
                    $to_crop = TRUE;
                }
            } else {
                $new_width = $width_orig;
                $new_height = $height_orig;
            }
            // we need to crop the image
            if ($to_crop) {
                $image_cropped = imagecreatetruecolor($width, $height);
                // find margins for images
                $margin_x = ($new_width - $width) / 2;
                $margin_y = ($new_height - $height) / 2;
                // cropping!
                imagecopy($image_cropped, $image, 0, 0, $margin_x, $margin_y, $width, $height);
                $image = $image_cropped;
            }
            // Save image
            imagejpeg($image, $img_filename, 95);
        }
        // Return image URL
        return get_bloginfo("template_url") . '/tmp/' . basename($img_filename);
    }
}
Wordless::register_helper("ImageHelper");
示例#10
0
    function titleize($text)
    {
        $words = explode(" ", $text);
        $capitalized_words = array();
        foreach ($words as $word) {
            $capitalized_words[] = capitalize($word);
        }
        return join(" ", $capitalized_words);
    }
    /**
     * Check if the string passed as parameter is a valid URL.
     * 
     * NO SANITAZE IS PERFORMED on the URL! URL like this:
     *   http://example.com/"><script>alert(document.cookie)</script>
     * DO PASS validation (syntactically are valid URLs).
     * 
     * @param string $url
     *   A URL to be validated.
     * 
     * @return bool
     *   Return TRUE if the URL is valid, FALSE otherwise.
     * 
     * @ingroup helperfunc
     */
    function is_valid_url($url)
    {
        return (bool) filter_var($url, FILTER_VALIDATE_URL);
    }
}
Wordless::register_helper("TextHelper");
示例#11
0
<?php

class UrlHelper
{
    function asset_url($path)
    {
        return parse_url(get_bloginfo('stylesheet_directory'), PHP_URL_PATH) . "/assets/{$path}";
    }
    function image_url($path)
    {
        return asset_url("images/{$path}");
    }
    function stylesheet_url($path)
    {
        return asset_url("stylesheets/{$path}");
    }
    function javascript_url($path)
    {
        return asset_url("javascripts/{$path}");
    }
}
Wordless::register_helper("UrlHelper");
示例#12
0
     *   A valid HTML \<time /\> tag.
     *
     * @ingroup helperfunc
     *
     * @see TagHelper::content_tag()
     */
    function time_tag($date_or_time = NULL, $text = NULL, $attributes = array())
    {
        $date_or_time = $date_or_time ? date(DATE_W3C, $date_or_time) : date(DATE_W3C);
        $options = array("datetime" => $date_or_time);
        $text = $text ? $text : strftime("%F", $date_or_time);
        $options = array_merge($options, $attributes);
        return content_tag("time", $text, $options);
    }
    /**
     * Like distance_of_time_in_words() but with fixed value of $to_time.
     *
     * This functions is a shorthand for distance_of_time_in_words($from_time,
     * time(), $include_seconds).
     *
     * @ingroup helperfunc
     *
     * @see distance_of_time_in_words()
     */
    function time_ago_in_words($from_time, $include_seconds = false)
    {
        return distance_of_time_in_words($from_time, time(), $include_seconds);
    }
}
Wordless::register_helper("DateHelper");
示例#13
0
     * The function use the whole theme path to get only the folder name of the
     * current theme.
     * 
     * @return string
     *   The folder name for the current theme.
     * 
     * @ingroup helperfunc
     */
    function get_theme_name()
    {
        $temp = explode("wp-content/themes/", get_bloginfo("template_url"));
        return $temp[1];
        // The second value will be the theme name
    }
    /**
     * Returns the absolute path to the current theme.
     * 
     * Path without trailing slash.
     * 
     * @return string
     *   The absolute path to the current theme.
     * 
     * @ingroup helperfunc
     */
    function get_theme_path()
    {
        return get_theme_root() . '/' . get_theme_name();
    }
}
Wordless::register_helper("ThemeHelper");
示例#14
0
<?php

/**
 * This module provides methods for handling log and debug output.
 * 
 * @ingroup helperclass
 */
class DebugHelper
{
    /**
     * Prints the specified variable inside <pre> tags.
     * 
     * @param string $var
     *   The variable to be printed
     * 
     * @ingroup helperfunc
     */
    function dump($var)
    {
        echo "<pre style='font-family: Monaco, monospaced;'>";
        print_r($var);
        echo "</pre>";
    }
}
Wordless::register_helper("DebugHelper");
示例#15
0
     * @ingroup helperfunc
     *
     * @warning Page title is not page slug nor page ID :)
     */
    function is_page_wpml($page_title = array())
    {
        if (!function_exists('icl_object_id')) {
            return false;
        }
        if (empty($page_title)) {
            return false;
        }
        $pages = array();
        if (is_array($page_title)) {
            $pages = array_merge($pages, $page_title);
        } else {
            $pages[] = $page_title;
        }
        foreach ($pages as $page) {
            $pageObj = get_page_by_title($page);
            $icl_object_id = array();
            $icl_object_id = icl_object_id($pageObj->ID, 'page', true);
            if (is_page(array($icl_object_id, $page->ID))) {
                return true;
            }
        }
        return false;
    }
}
Wordless::register_helper("ConditionalHelper");
示例#16
0
                $new_height = $height_orig * $ratio;
                $image_scaled = imagecreatetruecolor($new_width, $new_height);
                // scaling!
                imagecopyresampled($image_scaled, $image, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
                $image = $image_scaled;
                if ($new_width > $width || $new_height > $height) {
                    $to_crop = 1;
                }
            } else {
                $new_width = $width_orig;
                $new_height = $height_orig;
            }
            // we need to crop the image
            if ($to_crop == 1) {
                $image_cropped = imagecreatetruecolor($width, $height);
                // find margins for images
                $margin_x = ($new_width - $width) / 2;
                $margin_y = ($new_height - $height) / 2;
                // cropping!
                imagecopy($image_cropped, $image, 0, 0, $margin_x, $margin_y, $width, $height);
                $image = $image_cropped;
            }
            // Save image
            imagejpeg($image, $img_filename, 95);
        }
        // Return image URL
        return Wordless::join_paths(Wordless::theme_temp_path(), basename($img_filename));
    }
}
Wordless::register_helper("MediaHelper");