function perform() { if (!is_writable($this->config->get('data_dir'))) { $this->ae->add('error', $this->config->get('data_dir') . 'に書き込み権限がありません'); return 'error'; } $constants = new Constants(); $constants->set('C_ADMIN_PASS', md5($this->af->get('admin_pass'))); $constants->set('C_ADMIN_MAIL', $this->af->get('admin_mail')); $constants->set('C_AUTO_SELECT', '0'); $fp = fopen($this->config->get('config_file'), 'w+b'); if (!$fp || !fwrite($fp, $constants->toString())) { $this->ae->add('error', $this->config->get('config_file') . 'に書き込めませんでした'); return 'error'; } fclose($fp); return 'login'; }
/** * Gets the XML and sets each of the nodes as constants * * @author Anthony Short * @return Void */ public static function pre_process() { $file = CSScaffold::config('XML_constants.xml_path'); # If the xml file doesn't exist if (!file_exists($file)) { throw new Scaffold_Exception('XML_constants.doesnt_exist', $file); } # Load the xml $xml = simplexml_load_file($file); # Loop through them and set them as constants foreach ($xml->constant as $key => $value) { Constants::set((string) $value->name, (string) $value->value); } }
/** * Parses @fors within the css * * @author Anthony Short * @param $string * @return string */ public static function parse($css) { if ($found = self::find_fors($css)) { foreach ($found[0] as $key => $value) { $s = ""; $constant = $found[1][$key]; $from = Constants::replace($found[2][$key]); $to = Constants::replace($found[3][$key]); $content = $found[6][$key]; for ($i = $from; $i <= $to; $i++) { Constants::set($constant, $i); $s .= Constants::replace($content); } $css = str_replace($found[0][$key], $s, $css); } } return $css; }
/** * The pre-processing function occurs after the importing, * but before any real processing. This is usually the stage * where we set variables and the like, getting the css ready * for processing. * * @author Anthony Short * @param $css */ public static function parse_grid() { # Find the @grid - this returns an array of 'groups' and 'values' if ($settings = CSS::find_at_group('grid')) { # All the @grids $groups = $settings['groups']; # Store it so it's easier to grab $settings = $settings['values']; # Make sure none of the required options are missing foreach (array('column-count', 'column-width') as $option) { if (!isset($settings[$option])) { throw new Scaffold_Exception('Layout module requires the column-count and column-width properties'); } } # Remove it from the css CSS::replace($groups, array()); # The number of columns, baseline and unit $cc = $settings['column-count']; $unit = isset($settings['unit']) ? $settings['unit'] : 'px'; $bl = isset($settings['baseline']) ? $settings['baseline'] : 18; $cw = $settings['column-width']; # Get the gutters $lgw = isset($settings['left-gutter-width']) ? $settings['left-gutter-width'] : 0; $rgw = isset($settings['right-gutter-width']) ? $settings['right-gutter-width'] : 0; # Get the total gutter width $gw = $settings['gutter-width'] = $lgw + $rgw; # The total grid width $grid = ($cw + $gw) * $cc; $grid_settings = array('column-count' => $cc, 'column-width' => $cw . $unit, 'gutter-width' => $gw . $unit, 'left-gutter-width' => $lgw . $unit, 'right-gutter-width' => $rgw . $unit, 'grid-width' => $grid . $unit, 'baseline' => $bl . $unit); # Set them as constants we can use in the css foreach ($grid_settings as $key => $value) { Constants::set($key, $value); } # Path to the image $img = CSScaffold::config('core.path.cache') . "Layout/{$lgw}_{$cw}_{$rgw}_{$bl}_grid.png"; # Generate the grid.png self::create_grid_image($cw, $bl, $lgw, $rgw, $img); $img = str_replace(CSScaffold::config('core.path.docroot'), '/', $img); CSS::append(".showgrid{background:url('" . $img . "');}"); # Round to baselines self::round_to_baseline($bl); # Make each of the column variables a member variable self::$column_count = $cc; self::$column_width = $cw; self::$gutter_width = $gw; self::$left_gutter_width = $lgw; self::$right_gutter_width = $rgw; self::$grid_width = $grid; self::$baseline = $bl; } }
/** * Replaces the mixins with their properties * * @author Anthony Short * @param $mixin_key - The bases array key corrosponding to the current mixin * @param $mixins - An array of found mixins * @return string */ public static function build_mixins($mixin_key, $mixins, $already_mixed = array()) { $bases =& self::$mixins; $mixin_name = $mixins[2][$mixin_key]; if (isset($bases[$mixin_name])) { $base_properties = $bases[$mixin_name]['properties']; # If there is no base for that mixin and we aren't in a recursion loop if (is_array($bases[$mixin_name]) and !in_array($mixin_name, $already_mixed)) { $already_mixed[] = $mixin_name; # Parse the parameters of the mixin $params = self::parse_params($mixins[0][$mixin_key], $mixins[4][$mixin_key], $bases[$mixin_name]['params']); # Set the parameters as constants foreach ($params as $key => $value) { Constants::set($key, (string) $value); } $new_properties = Constants::replace($base_properties); # Unset the parameters as constants foreach ($params as $key => $value) { Constants::remove($key); } # Parse conditionals if there are any in there $new_properties = self::parse_conditionals($new_properties); # Find nested mixins if ($inner_mixins = self::find_mixins($new_properties)) { # Loop through all the ones we found, skipping on recursion by passing # through the current mixin we're working on foreach ($inner_mixins[0] as $key => $value) { # Parse the mixin and replace it within the property string $new_properties = str_replace($value, self::build_mixins($key, $inner_mixins, $already_mixed), $new_properties); } } # Clean up memory unset($inner_mixins, $params, $mixins); return preg_replace('/^(\\s|\\n|\\r)*|(\\n|\\r|\\s)*$/', '', $new_properties); } elseif (in_array($mixin_name, $already_mixed)) { Scaffold::log('Recursion in mixin - ' . $mixin_name, 1); } } else { Scaffold::log('Missing mixin - ' . $mixin_name, 2); } }
/** * Parse the @grid rule and calculate the grid. * * @author Anthony Short * @param $css */ public static function import_process() { if ($settings = Scaffold::$css->find_at_group('grid')) { $groups = $settings['groups']; $settings = $settings['values']; # You really should only have one @grid if (count($groups) > 1) { Scaffold::error('Layout module can only use one @grid rule'); } # Make sure the groups have all the right properties self::check_grid($groups[0], $settings); # The number of columns $cc = $settings['column-count']; # The tyopgraphic baseline $bl = $settings['baseline']; # The left gutter on grid columns $lgw = isset($settings['left-gutter-width']) ? $settings['left-gutter-width'] : 0; # The right gutter on grid columns $rgw = isset($settings['right-gutter-width']) ? $settings['right-gutter-width'] : 0; # The combined gutter widths $gw = $settings['gutter-width'] = $lgw + $rgw; # The total width of the grid $grid = $settings['grid-width']; # The grid width minus all the gutter widths $netgridwidth = $grid - $cc * $gw; # The width of a single column $cw = floor($netgridwidth / $cc); self::$grid_settings = array('column_width' => $cw, 'gutter_width' => $gw, 'left_gutter_width' => $lgw, 'right_gutter_width' => $rgw, 'grid_width' => $grid, 'baseline' => $bl); /** * Set each of the column widths as Constants. They * can be accessed like this: $columns_1 */ if (class_exists('Constants')) { for ($i = 1; $i <= $cc; $i++) { Constants::set('columns_' . $i, $i * $cw + ($i * $gw - $gw) . 'px'); } } /** * Set them as constants we can use in the css. They can * be accessed like this: $column_count */ foreach (self::$grid_settings as $key => $value) { Constants::set($key, $value . 'px'); } # Set this seperately as it doesn't need px added to it self::$grid_settings['column_count'] = $cc; Constants::set('column_count', $cc); /** * Create the grid background image */ $img = self::create_grid_image($cw, $bl, $lgw, $rgw); Scaffold::$css->string .= "=grid-overlay{background:url('" . $img . "');} .grid-overlay { +grid-overlay; }"; /** * Include the mixin templates so you can access each of * the grid properties with mixins like this: +columns(4); */ $mixins = Scaffold::find_file('templates/mixins.css'); $classes = Scaffold::find_file('templates/classes.css'); if ($mixins !== false and $classes !== false) { Scaffold::$css->string .= file_get_contents($mixins); Scaffold::$css->string .= file_get_contents($classes); } } }