root/afridex/plugins/Flutter/Ink/ink.php @ 21

Revision 21, 3.5 kB (checked in by admin, 18 years ago)
Line 
1<?php
2
3// CSS Functions
4
5function ink_elements($element_string) {
6                global $wpdb, $table_prefix;
7                $table = $table_prefix.'ink';
8                $element_string = chop(preg_replace('/,\s+/', '^^^', 'body, a:link, a:hover, a:visited, '.$element_string));
9                $elements = explode('^^^', $element_string);
10                $theme = get_option('template');
11       
12                foreach($elements as $element) {
13                        if(!$wpdb->get_var("SELECT element FROM ".$table." WHERE element = '$element' AND theme = '$theme'"))
14                                $wpdb->query("INSERT INTO ".$table." (element, theme) VALUES ('$element','$theme')");
15                }
16                if(!get_option('ink_css')) write_ink_definitions();
17}
18
19function ink_create_css($element, $index, $definition) {
20        $css_element = $element.' {'."\n";
21                if($index == 'color') $css_element .= "\t".'color: #'.$definition.';'."\n";
22                if($index == 'background') $css_element .= "\t".'background-color: #'.$definition.';'."\n";
23                if($index == 'border') $css_element .= "\t".'border-color: #'.$definition.';'."\n";
24                if($index == 'font_family' && $definition != 'none') $css_element .= "\t".'font-family: '.$definition.';'."\n";
25                if($index == 'font_size') $css_element .= "\t".'font-size: '.$definition.'px;'."\n";
26                if($index == 'font_style' && strstr($definition, 'normal') && $definition != 'none') $css_element .= "\t".'font-style: normal;'."\n"."\t".'font-weight: normal;'."\n";
27                if($index == 'font_style' && strstr($definition, 'italic') && $definition != 'none') $css_element .= "\t".'font-style: italic;'."\n";
28                if($index == 'font_style' && strstr($definition, 'bold') && $definition != 'none') $css_element .= "\t".'font-weight: bold;'."\n";
29                if($index == 'other') $css_element .= "\t".$definition."\n";
30        $css_element .= '}'."\n\n";
31       
32        return $css_element;
33}
34
35function write_ink_definitions() {
36        global $wpdb, $table_prefix;
37        $table = $table_prefix.'ink';
38        $theme = get_option('template');
39        $css = '/* CSS Generated by Ink - http://freshpursuits.com/ink */'."\n\n";
40        if($values = $wpdb->get_results("SELECT * FROM ".$table." WHERE theme = '$theme'")) {
41                foreach($values as $value) {
42                        $definitions = php4_clone($value);
43                        unset($definitions->element, $definitions->element_id, $definitions->theme);
44                        foreach($definitions as $index => $definition) {
45                                if(!empty($definition)) $css .= ink_create_css($value->element, $index, $definition);
46                        }
47                }
48                update_option('ink_css', '<style type="text/css" media="screen">'."\n".$css.'</style>');
49        }
50}
51
52function php4_clone($object) {
53  if (version_compare(phpversion(), '5.0') < 0) {
54   return $object;
55  } else {
56   return @clone($object);
57  }
58 }
59
60function output_ink() {
61        if(get_option('enableInk') == 'true') echo get_option('ink_css');
62        }
63
64// Admin Functions
65
66function get_ink_definition($element, $definition) {
67        global $wpdb, $table_prefix;
68        $table = $table_prefix.'ink';
69        $theme = get_option('template');
70        $value = $wpdb->get_var("SELECT ".$definition." FROM ".$table." WHERE element = '$element' AND theme = '$theme'");
71        return $value;
72}
73
74function set_ink_definition($element, $definition, $value) {
75        global $wpdb, $table_prefix;
76        $table = $table_prefix.'ink';
77        $theme = get_option('template');
78        $update = $wpdb->query("UPDATE ".$table." SET ".$definition."='$value' WHERE element = '$element' AND theme = '$theme'");
79        write_ink_definitions();
80        return $update;
81}
82
83function ink_clean_install() {
84        update_option('enableInk', 'false');
85        delete_option('ink_css');
86}
87
88function ink_highlight() {
89        if(isset($_GET["ink_highlight"])) {
90                echo '<style type="text/css" media="screen">'."\n".urldecode($_GET["ink_highlight"]).' { border: 1px solid red; } </style>';
91        }
92}
93
94require_once('ink-admin.php');
95?>
Note: See TracBrowser for help on using the browser.