Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question... PHP functions that'll work? - Solved
#5
yea but I don't want to use relative at all... :/

here.. this might paint a clearer picture.. here's my current plugin php file:
PHP Code:
<?php
/****************************************************
Plugin Name: FoundationNation Theme Settings
Description: Settings for the default GetSimple Theme: FoundationNation
Version: 1.1
* Theme Credits
* Theme FoundationNation developed by David AE Levy
* Title of Work: FoundationNation Theme for GetSimple MCMS
* Attribute work to name: David AE Levy
* Attribute work to URL: http://www.webdevandphoto.com
* Source work URL: http://www.webdevandphoto.com
* More permissions URL: http://www.levyimage.com
* Format of work: Multiple formats
* Copyright 2013, David AE Levy - http://www.webdevandphoto.com + http://www.levyimage.com
* Released under the Creative Commons Attribution-NonCommercial 3.0 Unported License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/3.0/
This plugin is inspired by the original plugin: Innovation by ccagle8 
Original Plugin Author URI: http://chriscagle.me
*****************************************************/

# get correct id for plugin
$thisfile_found=basename(__FILE__".php");
$foundation_file=GSDATAOTHERPATH .'FoundationSettings.xml';

# add in this plugin's language file
i18n_merge($thisfile_found) || i18n_merge($thisfile_found'en_US');

# register plugin
register_plugin(
    
$thisfile_found,                                                     # ID of plugin, should be filename minus php
    
i18n_r($thisfile_found.'/FOUNDATION_TITLE'),                 # Title of plugin
    
'1.1',                                                             # Version of plugin
    
'Levy Image',                                            # Author of plugin
    
'http://webdevandphoto.com',             # Author URL
    
i18n_r($thisfile_found.'/FOUNDATION_DESC'),                     # Plugin Description
    
'theme',                                                         # Page type of plugin
    
'foundation_show'                                      # Function that displays content
);

# include HTMLawed
define("FOUND_PATH"dirname(__FILE__));
include (
FOUND_PATH "/FoundationPlugin/htmLawed.php");

# Configure HTMLawed
$lawedconfig = array(
        
'safe'=>1//auto config maximum safety
        
'deny_attribute'=>'style, on*'//disable inline styles and on click to prevent click hijacking
        
'tidy'=>-1//minify any html data
        
'elements'=>'* -script'//disable script element
        
'keep_bad'=>//remove the bad tags
);
$lawedspec ''//allow elements override. see documentation

# hooks
add_action('theme-sidebar','createSideMenu',array($thisfile_foundi18n_r($thisfile_found.'/FOUNDATION_TITLE')));

# get XML data
if (file_exists($foundation_file)) {
    
$x getXML($foundation_file);
    
$webfont $x->webfont;
    
$rgbvalue1 $x->rgbvalue1;
    
$rgbvalue2 $x->rgbvalue2;
    
$rgbvalue3 $x->rgbvalue3;
    
$shortsitename $x->shortsitename;
    
$slogan $x->slogan;
    
$aboutpage $x->aboutpage;
    
$blogpage $x->blogpage;
    
$facebook $x->facebook;
    
$googleplus $x->googleplus;
    
$twitter $x->twitter;
    
$linkedin $x->linkedin;
    
$tumblr $x->tumblr;
    
$instagram $x->instagram;
    
$youtube $x->youtube;
    
$vimeo $x->vimeo;
    
$github $x->github;
} else {
    
$webfont ='';
    
$rgbvalue1 ='';
    
$rgbvalue2 ='';
    
$rgbvalue3 ='';
    
$shortsitename '';
    
$slogan '';
    
$aboutpage '';
    
$blogpage '';
    
$facebook '';
    
$googleplus '';
    
$twitter '';
    
$linkedin '';
    
$tumblr '';
    
$instagram '';
    
$youtube '';
    
$vimeo '';
    
$github '';
}


function 
foundation_show() {
    global 
$foundation_file$webfont$rgbvalue1$rgbvalue2$rgbvalue3$shortsitename$slogan$aboutpage$blogpage$facebook$googleplus$twitter$linkedin$tumblr$instagram$youtube$vimeo$github$thisfile_found;
    
$success=null;$error=null;
    
$poweredcss 0//initiate PHP Powered CSS check variable
    
    # Check if FoundationNation Plugin files exists
    
if ( (file_exists(GSROOTPATH "/plugins/FoundationPlugin/colorpicker.js")) && (file_exists(GSROOTPATH "/plugins/FoundationPlugin/colorpicker.css")) && (file_exists(GSROOTPATH "/plugins/FoundationPlugin/htmLawed.php")) ) {
    } else {
    
$error .= i18n_r($thisfile_found.'/THEMEPLUGIN_ERROR').' ';
    };
    
    
# Check if FoundationNation dir and files exists
    
if ( (is_dir(GSROOTPATH "/theme/FoundationNation")) && (file_exists(GSROOTPATH "/theme/FoundationNation/functions.php")) && (file_exists(GSROOTPATH "/theme/FoundationNation/header.php")) && (file_exists(GSROOTPATH "/theme/FoundationNation/footer.php")) && (file_exists(GSROOTPATH "/theme/FoundationNation/slider.php")) && (file_exists(GSROOTPATH "/theme/FoundationNation/social.php")) && (file_exists(GSROOTPATH "/theme/FoundationNation/template.php")) && (file_exists(GSROOTPATH "/theme/FoundationNation/style.php")) && (file_exists(GSROOTPATH "/theme/FoundationNation/appstyle.php")) ) {
    } else {
    
$error .= i18n_r($thisfile_found.'/THEME_ERROR').' ';
    };
    
    
// submitted form
    
if (isset($_POST['submit'])) {
        
$webfont=null$rgbvalue1=null$rgbvalue2=null$rgbvalue3=null$shortsitename=null$slogan=null$aboutpage=null$blogpage=null$facebook=null;    $googleplus=null$twitter=null$linkedin=null$tumblr=null$instagram=null$youtube=null$vimeo=null$github=null;
        
    
# This generates our PHP powered CSS files on demand
    
function generate_styles_css() {
        
$themeurl GSROOTPATH "theme/FoundationNation";
        
$stylefile_style $themeurl '/style.php';
        
$stylefile_app $themeurl '/appstyle.php';
        if(
file_exists($stylefile_style && $stylefile_app)){
            
ob_start(); // Capture all output
            
require($stylefile_style); // Generate CSS for style.php
            
require($stylefile_app); // Generate CSS for appstyle.php
            
$stylescss ob_get_clean(); // Get generated CSS (output buffering)
            
file_put_contents($themeurl 'style.css'$stylescssLOCK_EX); // Save it. LOCK_EX flag prevents anyone else from writing to the file at the same time
        
} else {
        
$error .= i18n_r($thisfile_found.'/STYLES_ERROR').' ';    
        }
    };

        
# check to see if the entries provided are valid
        
if ($_POST['webfont'] != '') {
            if ((
$_POST['webfont']) == (preg_replace("/[^a-zA-Z0-9+|:]+/""",($_POST['webfont'])))) {
                
$webfont $_POST['webfont']; //we want characters +|: allowed so used preg rep
            
} else {
                
$error .= i18n_r($thisfile_found.'/WEBFONT_ERROR').' ';
            }
        }
        if (
$_POST['rgbvalue1'] != '') {
            
$checkrgbvalue1 substr((preg_replace("/[^0-9,rgb()]+/""",($_POST['rgbvalue1']))),0,16);
            
$fixedrgbvalue1 substr((preg_replace("/[^0-9,]+/""",($_POST['rgbvalue1']))), 011);
            if ((
$_POST['rgbvalue1']) == $checkrgbvalue1 or $fixedrgbvalue1 ) {
                
$rgbvalue1 $fixedrgbvalue1//we want only numbers and commas within a total limit of 11 characters
                
$poweredcss 1//turn PHP Powered CSS check variable flag on, because a change has been made
            
} else {
                
$error .= i18n_r($thisfile_found.'/RGBVALUE1_ERROR').' ';
            }
        }
        if (
$_POST['rgbvalue2'] != '') {
            
$checkrgbvalue2 substr((preg_replace("/[^0-9,rgb()]+/""",($_POST['rgbvalue2']))),0,16);
            
$fixedrgbvalue2 substr((preg_replace("/[^0-9,]+/""",($_POST['rgbvalue2']))), 011);
            if ((
$_POST['rgbvalue2']) == $checkrgbvalue2 or $fixedrgbvalue2 ) {
                
$rgbvalue2 $fixedrgbvalue2//we want only numbers and commas within a total limit of 11 characters
                
$poweredcss 1//turn PHP Powered CSS check variable flag on, because a change has been made
            
} else {
                
$error .= i18n_r($thisfile_found.'/RGBVALUE2_ERROR').' ';
            }
        }
        if (
$_POST['rgbvalue3'] != '') {
            
$checkrgbvalue3 substr((preg_replace("/[^0-9,rgb()]+/""",($_POST['rgbvalue3']))),0,16);
            
$fixedrgbvalue3 substr((preg_replace("/[^0-9,]+/""",($_POST['rgbvalue3']))), 011);
            if ((
$_POST['rgbvalue3']) == $checkrgbvalue3 or $fixedrgbvalue3 ) {
                
$rgbvalue3 $fixedrgbvalue3//we want only numbers and commas within a total limit of 11 characters
                
$poweredcss 1//turn PHP Powered CSS check variable flag on, because a change has been made
            
} else {
                
$error .= i18n_r($thisfile_found.'/RGBVALUE3_ERROR').' ';
            }
        }
        if (
$_POST['shortsitename'] != '') {
            if (
ctype_alnum($_POST['shortsitename'])) {
                
$shortsitename $_POST['shortsitename']; //ctype does the trick since we don't want spaces and only alphanum
            
} else {
                
$error .= i18n_r($thisfile_found.'/SHORTSITENAME_ERROR').' ';
            }
        }
        if (
$_POST['aboutpage'] != '') {
            if (
validate_url($_POST['aboutpage'])) {
                
$aboutpage $_POST['aboutpage']; //we must validate if real url
            
} else {
                
$error .= i18n_r($thisfile_found.'/ABOUTPAGE_ERROR').' ';
            }
        }
        if (
$_POST['blogpage'] != '') {
            if (
validate_url($_POST['blogpage'])) {
                
$blogpage $_POST['blogpage'];
            } else {
                
$error .= i18n_r($thisfile_found.'/BLOGPAGE_ERROR').' ';
            }
        }
        if (
$_POST['slogan'] != '') {
            if ((
$_POST['slogan']) == (preg_replace("/[^a-zA-Z0-9 ]+/""",($_POST['slogan'])))) {
                
$slogan $_POST['slogan']; //we want spaces allowed so used preg rep
            
} else {
                
$error .= i18n_r($thisfile_found.'/SLOGAN_ERROR').' ';
            }
        }
        if (
$_POST['facebook'] != '') {
            if (
validate_url($_POST['facebook'])) {
                
$facebook $_POST['facebook'];
            } else {
                
$error .= i18n_r($thisfile_found.'/FACEBOOK_ERROR').' ';
            }
        }
        
        if (
$_POST['googleplus'] != '') {
            if (
validate_url($_POST['googleplus'])) {
                
$googleplus $_POST['googleplus'];
            } else {
                
$error .= i18n_r($thisfile_found.'/GOOGLEPLUS_ERROR').' ';
            }
        }
        
        if (
$_POST['twitter'] != '') {
            if (
validate_url($_POST['twitter'])) {
                
$twitter $_POST['twitter'];
            } else {
                
$error .= i18n_r($thisfile_found.'/TWITTER_ERROR').' ';
            }
        }
        
        if (
$_POST['linkedin'] != '') {
            if (
validate_url($_POST['linkedin'])) {
                
$linkedin $_POST['linkedin'];
            } else {
                
$error .= i18n_r($thisfile_found.'/LINKEDIN_ERROR').' ';
            }
        }
        if (
$_POST['tumblr'] != '') {
            if (
validate_url($_POST['tumblr'])) {
                
$tumblr $_POST['tumblr'];
            } else {
                
$error .= i18n_r($thisfile_found.'/TUMBLR_ERROR').' ';
            }
        }
        if (
$_POST['instagram'] != '') {
            if (
validate_url($_POST['instagram'])) {
                
$instagram $_POST['instagram'];
            } else {
                
$error .= i18n_r($thisfile_found.'/INSTAGRAM_ERROR').' ';
            }
        }
        if (
$_POST['youtube'] != '') {
            if (
validate_url($_POST['youtube'])) {
                
$youtube $_POST['youtube'];
            } else {
                
$error .= i18n_r($thisfile_found.'/YOUTUBE_ERROR').' ';
            }
        }
        if (
$_POST['vimeo'] != '') {
            if (
validate_url($_POST['vimeo'])) {
                
$vimeo $_POST['vimeo'];
            } else {
                
$error .= i18n_r($thisfile_found.'/VIMEO_ERROR').' ';
            }
        }
        if (
$_POST['github'] != '') {
            if (
validate_url($_POST['github'])) {
                
$github $_POST['github'];
            } else {
                
$error .= i18n_r($thisfile_found.'/GITHUB_ERROR').' ';
            }
        }
        
        
# if there are no errors, save data
        
if (!$error) {
            
$xml = @new SimpleXMLElement('<item></item>');
            
$xml->addChild('webfont'$webfont);
            
$xml->addChild('rgbvalue1'$rgbvalue1);
            
$xml->addChild('rgbvalue2'$rgbvalue2);
            
$xml->addChild('rgbvalue3'$rgbvalue3);
            
$xml->addChild('shortsitename'$shortsitename);
            
$xml->addChild('slogan'$slogan);
            
$xml->addChild('aboutpage'$aboutpage);
            
$xml->addChild('blogpage'$blogpage);
            
$xml->addChild('facebook'$facebook);
            
$xml->addChild('googleplus'$googleplus);
            
$xml->addChild('twitter'$twitter);
            
$xml->addChild('linkedin'$linkedin);
            
$xml->addChild('tumblr'$tumblr);
            
$xml->addChild('instagram'$instagram);
            
$xml->addChild('youtube'$youtube);
            
$xml->addChild('vimeo'$vimeo);
            
$xml->addChild('github'$github);
            
            if (! 
$xml->asXML($foundation_file)) {
                
$error i18n_r('CHMOD_ERROR');
            } else {
                
$x getXML($foundation_file);
                
$webfont $x->webfont;
                
$rgbvalue1 $x->rgbvalue1;
                
$rgbvalue2 $x->rgbvalue2;
                
$rgbvalue3 $x->rgbvalue3;
                
$shortsitename $x->shortsitename;
                
$slogan $x->slogan;
                
$aboutpage $x->aboutpage;
                
$blogpage $x->blogpage;
                
$facebook $x->facebook;
                
$googleplus $x->googleplus;
                
$twitter $x->twitter;
                
$linkedin $x->linkedin;
                
$tumblr $x->tumblr;
                
$instagram $x->instagram;
                
$youtube $x->youtube;
                
$vimeo $x->vimeo;
                
$github $x->github;
                
$success i18n_r('SETTINGS_UPDATED');
            }
        }
        
        
# check if PHP powered CSS variables where changed, if so generate CSS
        
if($poweredcss 1) {
        
generate_styles_css(); //generate our new CSS file
        
$poweredcss 0//reset check variable
        
}
    }
    
    
?>
    <h3><?php i18n($thisfile_found.'/FOUNDATION_TITLE'); ?></h3>
    <noscript>
    Please enable JavaScript to properly use this Theme Plugin
    </noscript>
    <?php 
    
if($success) { 
        echo 
'<p style="color:#5da423;"><b>'$success .'</b></p>';
    } 
    if(
$error) { 
        echo 
'<p style="color:#c60f13;"><b>'$error .'</b></p>';
    }
    
?>
    <?php 
    
if((file_exists(GSROOTPATH "/plugins/FoundationPlugin/colorpicker.js")) && (file_exists(GSROOTPATH "/plugins/FoundationPlugin/colorpicker.css")) ) {
        echo 
'<!-- This script will allow color picker to work -->';
        
$new_elm = ((file_get_contents(GSROOTPATH "/plugins/FoundationPlugin/colorpicker.css")).(file_get_contents(GSROOTPATH "/plugins/FoundationPlugin/colorpicker.js")));
        echo 
$new_elm;
    }
    if(
file_exists(GSROOTPATH "theme/FoundationNation/images/screenshot.png")) {
        
$screenshot "../theme/FoundationNation/images/screenshot.png";
        echo 
'<img style="border:2px solid #333;" src="'$screenshot .'" alt="Theme Screenshot"><br/><br/>';
    }
    
?>
    <div style="width: 100%;">
    <div id="mycolorpicker" class="cp-default"></div>
    <ul id="color-values">
            <li><label>RGB:</label><span id="rgb">rgb(255,0,0)</span></li>
            <li><label>HSV:</label><span id="hsv">hsv(0.2,1,1)</span></li>
            <li><label>HEX:</label><span id="hex">#FF0000</span></li>
    </ul>
    </div>
    <br clear="all"/>
    <form method="post" action="<?php    echo $_SERVER ['REQUEST_URI']?>">
        <p><label for="inn_rgbvalue1" ><?php i18n($thisfile_found.'/RGBVALUE1_TEXT'); ?></label><input id="inn_rgbvalue1" name="rgbvalue1" class="text" value="rgb(<?php echo $rgbvalue1?>)" type="text" /></p>
        <p><label for="inn_rgbvalue2" ><?php i18n($thisfile_found.'/RGBVALUE2_TEXT'); ?></label><input id="inn_rgbvalue2" name="rgbvalue2" class="text" value="rgb(<?php echo $rgbvalue2?>)" type="text" /></p>
        <p><label for="inn_rgbvalue3" ><?php i18n($thisfile_found.'/RGBVALUE3_TEXT'); ?></label><input id="inn_rgbvalue3" name="rgbvalue3" class="text" value="rgb(<?php echo $rgbvalue3?>)" type="text" /></p>
        <p><label for="inn_webfont" ><?php i18n($thisfile_found.'/WEBFONT_TEXT'); ?></label><input id="inn_webfont" name="webfont" class="text" value="<?php echo $webfont?>" type="text" /></p>
        <p><label for="inn_shortsitename" ><?php i18n($thisfile_found.'/SHORTSITENAME_TEXT'); ?></label><input id="inn_shortsitename" name="shortsitename" class="text" value="<?php echo $shortsitename?>" type="text" /></p>
        <p><label for="inn_aboutpage" ><?php i18n($thisfile_found.'/ABOUTPAGE_URL'); ?></label><input id="inn_aboutpage" name="aboutpage" class="text" value="<?php echo $aboutpage?>" type="url" /></p>
        <p><label for="inn_blogpage" ><?php i18n($thisfile_found.'/BLOGPAGE_URL'); ?></label><input id="inn_blogpage" name="blogpage" class="text" value="<?php echo $blogpage?>" type="url" /></p>
        <p><label for="inn_slogan" ><?php i18n($thisfile_found.'/SLOGAN_TEXT'); ?></label><input id="inn_slogan" name="slogan" class="text" value="<?php echo $slogan?>" type="text" /></p>
        <p><label for="inn_facebook" ><?php i18n($thisfile_found.'/FACEBOOK_URL'); ?></label><input id="inn_facebook" name="facebook" class="text" value="<?php echo $facebook?>" type="url" /></p>
        <p><label for="inn_googleplus" ><?php i18n($thisfile_found.'/GOOGLEPLUS_URL'); ?></label><input id="inn_googleplus" name="googleplus" class="text" value="<?php echo $googleplus?>" type="url" /></p>
        <p><label for="inn_twitter" ><?php i18n($thisfile_found.'/TWITTER_URL'); ?></label><input id="inn_twitter" name="twitter" class="text" value="<?php echo $twitter?>" type="url" /></p>
        <p><label for="inn_linkedin" ><?php i18n($thisfile_found.'/LINKEDIN_URL'); ?></label><input id="inn_linkedin" name="linkedin" class="text" value="<?php echo $linkedin?>" type="url" /></p>
        <p><label for="inn_tumblr" ><?php i18n($thisfile_found.'/TUMBLR_URL'); ?></label><input id="inn_tumblr" name="tumblr" class="text" value="<?php echo $tumblr?>" type="url" /></p>
        <p><label for="inn_instagram" ><?php i18n($thisfile_found.'/INSTAGRAM_URL'); ?></label><input id="inn_instagram" name="instagram" class="text" value="<?php echo $instagram?>" type="url" /></p>
        <p><label for="inn_youtube" ><?php i18n($thisfile_found.'/YOUTUBE_URL'); ?></label><input id="inn_youtube" name="youtube" class="text" value="<?php echo $youtube?>" type="url" /></p>
        <p><label for="inn_vimeo" ><?php i18n($thisfile_found.'/VIMEO_URL'); ?></label><input id="inn_vimeo" name="vimeo" class="text" value="<?php echo $vimeo?>" type="url" /></p>
        <p><label for="inn_github" ><?php i18n($thisfile_found.'/GITHUB_URL'); ?></label><input id="inn_github" name="github" class="text" value="<?php echo $github?>" type="url" /></p>
        
        <p><input type="submit" id="submit" class="submit" value="<?php i18n('BTN_SAVESETTINGS'); ?>" name="submit" /></p>
    </form>
    <script>
    ColorPicker(
    document.getElementById('mycolorpicker'), function(hex, hsv, rgb, mouseSlide, mousePicker) {
    document.getElementById('rgb').style.backgroundColor = rgb;
    document.getElementById('hex').innerHTML = hex;
    document.getElementById('rgb').innerHTML = 'rgb(' + rgb.r.toFixed() + ',' + rgb.g.toFixed() + ',' + rgb.b.toFixed() + ')';
    document.getElementById('hsv').innerHTML = 'hsv(' + hsv.h.toFixed() + ',' + hsv.s.toFixed(2) + ',' + hsv.v.toFixed(2) + ')';
    });
    </script>    
    <?php


Now the structure or placement and use of this function:
PHP Code:
# This generates our PHP powered CSS files on demand
    
function generate_styles_css() {
        
$themeurl GSROOTPATH "theme/FoundationNation";
        
$stylefile_style $themeurl '/style.php';
        
$stylefile_app $themeurl '/appstyle.php';
        if(
file_exists($stylefile_style && $stylefile_app)){
            
ob_start(); // Capture all output
            
require($stylefile_style); // Generate CSS for style.php
            
require($stylefile_app); // Generate CSS for appstyle.php
            
$stylescss ob_get_clean(); // Get generated CSS (output buffering)
            
file_put_contents($themeurl 'style.css'$stylescssLOCK_EX); // Save it. LOCK_EX flag prevents anyone else from writing to the file at the same time
        
} else {
        
$error .= i18n_r($thisfile_found.'/STYLES_ERROR').' ';    
        }
    }; 
Is just not working.... lol... so question 1 is asking how I could get that function to work....... ?

I get a variable undefined error on line 136 which is:
PHP Code:
$error .= i18n_r($thisfile_found.'/STYLES_ERROR').' '
and the CSS file isn't being rendered yet.
Reply


Messages In This Thread
RE: Question... PHP functions that'll work? - by WebDevandPhoto - 2013-02-25, 22:05:08



Users browsing this thread: 1 Guest(s)