compile() публичный Метод

public compile ( $code, $name = null )
Пример #1
0
 /**
  * Prints CSS styles in the header for meta options using wp_print_scripts
  *
  * @return	void
  * @since	1.3
  */
 public function printCSSForPagesAndPosts()
 {
     // This is for meta box options only, other types get generated normally
     if (TitanFrameworkOption::TYPE_META != $this->type) {
         return;
     }
     // For CSS langs only
     if ($this->settings['lang'] != 'css') {
         return;
     }
     // Don't generate CSS for non-pages and non-posts
     $id = get_the_ID();
     if (empty($id) || 1 == $id) {
         return;
     }
     // Check if a CSS was entered
     $css = $this->getFramework()->getOption($this->settings['id'], $id);
     if (empty($css)) {
         return;
     }
     // Print out valid CSS only
     require_once trailingslashit(dirname(dirname(__FILE__))) . 'inc/scssphp/scss.inc.php';
     $scss = new titanscssc();
     try {
         $css = $scss->compile($css);
         echo "<style type='text/css' media='screen'>{$css}</style>";
     } catch (Exception $e) {
     }
 }
 /**
  * Generates a CSS string of all the options
  *
  * @return  string A CSS string of all the values
  * @since   1.2
  */
 public function generateCSS()
 {
     $cssString = '';
     // These are the option types which are not allowed:
     $noCSSOptionTypes = array('text', 'textarea', 'editor');
     // Compile as SCSS & minify
     require_once trailingslashit(dirname(__FILE__)) . 'inc/scssphp/scss.inc.php';
     $scss = new titanscssc();
     // Get all the CSS
     foreach ($this->allOptionsWithIDs as $option) {
         // Only do this for the allowed types
         if (in_array($option->settings['type'], $noCSSOptionTypes)) {
             continue;
         }
         // Decide whether or not we should continue to generate CSS for this option
         if (!apply_filters('tf_continue_generate_css_' . $option->settings['type'] . '_' . $option->getOptionNamespace(), true, $option)) {
             continue;
         }
         // Custom generated CSS
         $generatedCSS = apply_filters('tf_generate_css_' . $option->settings['type'] . '_' . $option->getOptionNamespace(), '', $option);
         if (!empty($generatedCSS)) {
             try {
                 $testerForValidCSS = $scss->compile($generatedCSS);
                 $cssString .= $generatedCSS;
             } catch (Exception $e) {
             }
             continue;
         }
         // Don't render CSS for this option if it doesn't have a value
         $optionValue = $this->frameworkInstance->getOption($option->settings['id']);
         if ($optionValue == '' || $optionValue == false) {
             continue;
         }
         // Add the values as SaSS variables
         $generatedCSS = $this->formCSSVariables($option->settings['id'], $option->settings['type'], $optionValue);
         if (!empty($generatedCSS)) {
             try {
                 $testerForValidCSS = $scss->compile($generatedCSS);
                 $cssString .= $generatedCSS;
             } catch (Exception $e) {
             }
         }
         // Add the custom CSS
         if (!empty($option->settings['css'])) {
             // In the css parameter, we accept the term `value` as our current value,
             // translate it into the SaSS variable for the current option
             $generatedCSS = str_replace('value', '#{$' . $option->settings['id'] . '}', $option->settings['css']);
             if (!empty($generatedCSS)) {
                 try {
                     $testerForValidCSS = $scss->compile($generatedCSS);
                     $cssString .= $generatedCSS;
                 } catch (Exception $e) {
                 }
             }
         }
     }
     // Add additional CSS added via TitanFramework::createCSS()
     foreach ($this->additionalCSS as $css) {
         $cssString .= $css . "\n";
     }
     // Compile as SCSS & minify
     if (!empty($cssString)) {
         $scss->setFormatter(self::SCSS_COMPRESSION);
         try {
             $testerForValidCSS = $scss->compile($cssString);
             $cssString = $testerForValidCSS;
         } catch (Exception $e) {
         }
     }
     return $cssString;
 }