public static function start() { global $argv, $theme_name; parent::initialize(); require_once Wordless::join_paths(self::$plugin_dir, "wordless", "theme_builder.php"); $theme_name = $argv[1] ? $argv[1] : 'wordless'; $permissions = substr(sprintf('%o', fileperms(self::$plugin_dir)), -4); $builder = new WordlessThemeBuilder($theme_name, $theme_name, intval($permissions, 8)); $builder->build(); }
/** * Overrides WordlessPreprocessor::process_file() */ protected function process_file($file_path, $result_path, $temp_path) { $this->validate_executable_or_die($this->preference("sprockets.ruby_path")); // On cache miss, we build the JS file from scratch $pb = new ProcessBuilder(array($this->preference("sprockets.ruby_path"), Wordless::join_paths(dirname(__FILE__), "sprockets_preprocessor.rb"))); // Fix for MAMP environments, see http://goo.gl/S5KFe for details $pb->setEnv("DYLD_LIBRARY_PATH", ""); $pb->add(Wordless::theme_static_javascripts_path()); $pb->add(Wordless::theme_javascripts_path()); $pb->add($file_path); $proc = $pb->getProcess(); $code = $proc->run(); if ($code != 0) { $this->die_with_error($proc->getErrorOutput()); } return $proc->getOutput(); }
function render_template($name) { $tmp_dir = Wordless::theme_temp_path(); $template_path = Wordless::join_paths(Wordless::theme_views_path(), "{$name}.haml"); if (!is_file($template_path)) { render_error("Template missing", "<strong>Ouch!!</strong> It seems that <code>{$template_path}</code> doesn't exist!"); } if (!file_exists($tmp_dir)) { mkdir($tmp_dir, 0760); } if (!is_writable($tmp_dir)) { chmod($tmp_dir, 0760); } if (is_writable($tmp_dir)) { $haml = new HamlParser(array('style' => 'expanded', 'ugly' => false)); include $haml->parse($template_path, $tmp_dir); } else { render_error("Temp dir not writable", "<strong>Ouch!!</strong> It seems that the <code>{$tmp_dir}</code> directory is not writable by the server! Go fix it!"); } }
/** * Renders a template and its contained plartials. Accepts * a list of locals variables which will be available inside * the code of the template * * @param string $name The template filenames (those not starting * with an underscore by convention) * * @param array $locals An associative array. Keys will be variables' * names and values will be variable values inside * the template * * @see php.bet/extract * */ function render_template($name, $locals = array()) { $valid_filenames = array("{$name}.html.haml", "{$name}.haml", "{$name}.html.php", "{$name}.php"); foreach ($valid_filenames as $filename) { $path = Wordless::join_paths(Wordless::theme_views_path(), $filename); if (is_file($path)) { $template_path = $path; $arr = explode('.', $path); $format = array_pop($arr); break; } } if (!isset($template_path)) { render_error("Template missing", "<strong>Ouch!!</strong> It seems that <code>{$name}.html.haml</code> or <code>{$name}.html.php</code> doesn't exist!"); } extract($locals); switch ($format) { case 'haml': $tmp_dir = Wordless::theme_temp_path(); if (!file_exists($tmp_dir)) { mkdir($tmp_dir, 0760); } if (!is_writable($tmp_dir)) { chmod($tmp_dir, 0760); } if (is_writable($tmp_dir)) { $haml = new HamlParser(array('style' => 'expanded', 'ugly' => false)); include $haml->parse($template_path, $tmp_dir); } else { render_error("Temp dir not writable", "<strong>Ouch!!</strong> It seems that the <code>{$tmp_dir}</code> directory is not writable by the server! Go fix it!"); } break; case 'php': include $template_path; break; } }
/** * Overrides WordlessPreprocessor::process_file() */ protected function process_file($file_path, $temp_path) { $this->validate_executable_or_throw($this->preference("js.ruby_path")); // On cache miss, we build the JS file from scratch $pb = new ProcessBuilder(array($this->preference("js.ruby_path"), Wordless::join_paths(dirname(__FILE__), "sprockets_preprocessor.rb"), "compile")); // Fix for MAMP environments, see http://goo.gl/S5KFe for details $pb->setEnv("DYLD_LIBRARY_PATH", ""); $pb->add($file_path); $pb->add("--paths"); $pb->add(Wordless::theme_static_javascripts_path()); $pb->add(Wordless::theme_javascripts_path()); if ($this->preference("js.yui_compress")) { $pb->add("--compress"); } if ($this->preference("js.yui_munge")) { $pb->add("--munge"); } $proc = $pb->getProcess(); $code = $proc->run(); if ($code != 0) { throw new WordlessCompileException("Failed to run the following command: " . $proc->getCommandLine(), $proc->getErrorOutput()); } return $proc->getOutput(); }
/** * Require one directory * @param string $path */ public static function require_once_dir($path) { $list_files = glob(Wordless::join_paths($path, "*.php")); if (is_array($list_files)) { foreach ($list_files as $filename) { require_once $filename; } } }
<?php require_once Wordless::join_paths(dirname(dirname(dirname(__FILE__))), 'vendor/lorem/LoremIpsum.class.php'); Wordless::require_once_dir(Wordless::join_paths(dirname(__FILE__), "placeholder_images")); /** * This module provides methods for use of placeholders (images or text). * * @copyright welaika © 2011 - MIT License * * @ingroup helperclass */ class FakerHelper { /** * Generate a placeholder image. * * Using the specified sevice provide a placeholder image. * * Placeholder Services available are described here @ref placeholders. * * To implement your service please check the @ref placeholderservices. * * @param int $width * The width of the placeholder image. * @param int $height * The height of the placeholder image. * @param array $options * (optional) An option array to be passed to the PHP Class handling the * placeholder service. See the placeholder service docs for details. * * @return @e string
/** * Returns the path for the file that caches a the result * of a previous compilation of the same asset file. * * @param string $file_path * The path of the asset file to be retrieved from cache. * * @return string * The path of the cached compilation result. * * @see Wordless::join_paths() * @see WordlessPreprocessor::asset_hash() * @see WordlessPreprocessor::class_name() */ private function cached_file_path($file_path, $cache_path) { $cached_file_path = $this->class_name() . "_" . $this->asset_hash($file_path); return Wordless::join_paths($cache_path, $cached_file_path); }
public function build() { $source_path = Wordless::join_paths(dirname(__FILE__), "theme_builder", "vanilla_theme"); $this->copy($source_path, $this->theme_dir); }
function get_template_directory() { return Wordless::join_paths(getcwd(), "wp-content", "themes", WordlessBridge::$theme_name); }
<?php Wordless::require_once_dir(Wordless::join_paths(dirname(dirname(dirname(__FILE__))), "vendor/lorem")); Wordless::require_once_dir(Wordless::join_paths(dirname(dirname(dirname(__FILE__))), "vendor/lorem/PlaceholderImage")); /** * Provides methods for use of placeholders (images or text). * * @copyright welaika (c) 2011-2014 - MIT License * * @ingroup helperclass */ class FakerHelper { /** * Generate a placeholder image. * * Using the specified sevice provide a placeholder image. * * Placeholder Services available are described here @ref placeholders. * * To implement your service please check the @ref placeholderservices. * * @param int $width * The width of the placeholder image. * @param int $height * The height of the placeholder image. * @param array $options * (optional) An option array to be passed to the PHP Class handling the * placeholder service. See the placeholder service docs for details. * * @return @e string
<?php require_once Wordless::join_paths(dirname(dirname(__FILE__)), 'vendor/phamlp/haml/HamlParser.php'); Wordless::require_once_dir(Wordless::join_paths(dirname(__FILE__), "helpers"));
/** * Resizes the specified image to the specified dimensions. * * The crop will be centered relative to the image. * * @param string $src * The path to the image to be resized * @param int $width * The width at which the image will be cropped * @param int $height * The height at which the image will be cropped * * @return string * The valid URL to the image * * Cropped images are stored in template tmp folder. * * @ingroup helperfunc */ function resize_image($src, $width, $height) { // initializing $save_path = Wordless::theme_temp_path(); $img_filename = Wordless::join_paths($save_path, md5($width . 'x' . $height . '_' . basename($src)) . '.jpg'); // if file doesn't exists, create it if (!file_exists($img_filename)) { $to_scale = 0; $to_crop = 0; // Get orig dimensions list($width_orig, $height_orig, $type_orig) = getimagesize($src); // get original image ... to improve! switch ($type_orig) { case IMAGETYPE_JPEG: $image = imagecreatefromjpeg($src); break; case IMAGETYPE_PNG: $image = imagecreatefrompng($src); break; case IMAGETYPE_GIF: $image = imagecreatefromgif($src); break; default: return; } // which is the new smallest? if ($width < $height) { $min_dim = $width; } else { $min_dim = $height; } // which is the orig smallest? if ($width_orig < $height_orig) { $min_orig = $width_orig; } else { $min_orig = $height_orig; } // image of the right size if ($height_orig == $height && $width_orig == $width) { } else { if ($width_orig < $width) { $to_scale = 1; $ratio = $width / $width_orig; } else { if ($height_orig < $height) { $to_scale = 1; $ratio = $height / $height_orig; } else { if ($height_orig > $height && $width_orig > $width) { $to_scale = 1; $ratio_dest = $width / $height; $ratio_orig = $width_orig / $height_orig; if ($ratio_dest > $ratio_orig) { $ratio = $width / $width_orig; } else { $ratio = $height / $height_orig; } } else { if ($width == $width_orig && $height_orig > $height || $height == $height_orig && $width_orig > $width) { $to_crop = 1; } else { echo "ALARM"; } } } } } // we need to zoom to get the right size if ($to_scale == 1) { $new_width = $width_orig * $ratio; $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)); }