Example #1
0
function ajax_box($content, $title = '系统消息', $close_time = 0, $forward = '')
{
    if (is_debug()) {
        return $content;
    } else {
        require_once AROOT . 'view/layout/ajax/box.tpl.html';
    }
}
Example #2
0
function nebula_register_script($handle = null, $src = null, $exec = null, $deps = array(), $ver = false, $in_footer = false)
{
    if (!is_debug()) {
        $path = !empty($exec) ? $src . '?' . $exec : $src;
    } else {
        $path = $src;
    }
    wp_register_script($handle, $path, $deps, $ver, $in_footer);
}
Example #3
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     }
     if ($e instanceof NotFoundHttpException) {
         return response()->view('errors/404');
     }
     if (($e instanceof FatalErrorException || $e instanceof BadMethodCallException) && !is_debug()) {
         return response()->view('errors/503');
     }
     return parent::render($request, $e);
 }
Example #4
0
function fatal_error($text)
{
    @header("HTTP/1.0 500 Internal Server Error");
    @header("Content-type: text/html");
    $text_print = $text;
    if (is_object($text) && method_exists($text, 'getMessage')) {
        $text_print = basename($text->getFile()) . ':' . $text->getLine() . ' : ' . $text->getMessage();
        if (is_debug() && method_exists($text, 'getTraceAsString')) {
            $text_print .= "\n\n" . $text->getTraceAsString();
        }
    }
    echo '<h3>Fatal error!</h3>';
    echo '<pre>' . $text_print . '</pre>';
    exit;
}
Example #5
0
 public function render()
 {
     $buffer = (string) '';
     // add doctype
     $buffer .= $this->__getDoctype() . PHP_EOL;
     // open head
     $buffer .= '<head>' . PHP_EOL;
     // set title
     $buffer .= $this->__getTitle() . PHP_EOL;
     // add metatags
     foreach ($this->__MetaTags as $data) {
         $buffer .= $data . PHP_EOL;
     }
     // flush javascripts into one file
     if (count($this->__Library_Stylesheet) > 0) {
         $libs = implode(',', $this->__Library_Stylesheet);
         $buffer .= '<link rel="stylesheet" href="/system.css?libs=' . $libs . '" type="text/css" />' . PHP_EOL;
     }
     // add stylesheets
     foreach ($this->__Stylesheet as $data) {
         $buffer .= $data . PHP_EOL;
     }
     // flush javascripts into one file
     if (count($this->__Library_JavaScript) > 0) {
         $libs = implode(',', $this->__Library_JavaScript);
         $buffer .= '<script type="text/javascript" src="/system.js?libs=' . $libs . '"></script>' . PHP_EOL;
     }
     // add javascripts
     foreach ($this->__JavaScript as $data) {
         $buffer .= $data . PHP_EOL;
     }
     // add jGrowl Scripts if debug mode is enabled
     if (is_debug()) {
         $buffer .= '<link rel="stylesheet" href="/jgrowl.css" type="text/css" />' . PHP_EOL;
         //$buffer .= '<script type="text/javascript" src="/jquery-current.min.js"></script>'.PHP_EOL;
         $buffer .= '<script type="text/javascript" src="/jquery-jgrowl.min.js"></script>' . PHP_EOL;
     }
     // add favicon parameter
     $buffer .= '<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />' . PHP_EOL;
     $buffer .= '<link rel="icon" href="/favicon.ico" type="image/x-icon" />' . PHP_EOL;
     // close head, open body
     $buffer .= '</head>' . PHP_EOL;
     $buffer .= '<!--[if IE]>' . PHP_EOL;
     $buffer .= '<body class="ie">' . PHP_EOL;
     $buffer .= '<![endif]-->' . PHP_EOL;
     $buffer .= '<!--[if !IE]>-->' . PHP_EOL;
     $buffer .= '<body>' . PHP_EOL;
     $buffer .= '<!--<![endif]-->' . PHP_EOL;
     return $buffer;
     // end functions
 }
Example #6
0
<?php

if (!defined('ABSPATH')) {
    //Redirect (for logging) if accessed directly
    header('Location: http://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['PHP_SELF'], 0, strpos($_SERVER['PHP_SELF'], "wp-content/")) . '?ndaat=' . basename($_SERVER['PHP_SELF']));
    die('Error 403: Forbidden.');
}
?>


<?php 
/*==========================
	 Favicons
	 Favicons for various usage. PNG icons are used as needed by browsers in addition to Android homescreen bookmarks.
	 ===========================*/
$cache_query = is_debug() ? '?nocache' . mt_rand(1000, 99999) . '=debug' . mt_rand(1000, 99999) : '';
//Add a random query string when debugging to force-clear the cache.
?>
<link rel="shortcut icon" href="<?php 
echo get_template_directory_uri();
?>
/images/meta/favicon.ico<?php 
echo $cache_query;
?>
"><?php 
//@TODO "Graphics" 5: Need to create a 16x16 ICO favicon. Consider transparent BG.
?>
<link rel="icon" type="image/png" href="<?php 
echo get_template_directory_uri();
?>
/images/meta/favicon-16x16.png<?php 
Example #7
0
     $business_open = 'Non-Business Hours';
     echo 'clientinfo.businessopen = false;';
 }
 if (nebula_option('nebula_cd_businesshours')) {
     echo 'ga("set", gaCustomDimensions["businessHours"], "' . $business_open . '");';
 }
 //Relative time ("Late Morning", "Early Evening")
 if (nebula_option('nebula_cd_relativetime')) {
     $relative_time = nebula_relative_time();
     $time_description = implode(' ', $relative_time['description']);
     $time_range = $relative_time['standard'][0] . ':00' . $relative_time['ampm'] . ' - ' . $relative_time['standard'][2] . ':59' . $relative_time['ampm'];
     echo 'ga("set", gaCustomDimensions["relativeTime"], "' . ucwords($time_description) . ' (' . $time_range . ')");';
 }
 //Session ID
 if (nebula_option('nebula_cd_sessionid')) {
     $session_info = is_debug() ? 'Dbg.' : '';
     $session_info .= nebula_is_option_enabled('wireframing') ? 'Wr.' : '';
     if (is_client()) {
         $session_info .= 'Cl.';
     } elseif (is_dev()) {
         $session_info .= 'Dv.';
     }
     $session_info .= is_user_logged_in() ? 'Li.' : '';
     $session_info .= nebula_is_bot() ? 'Bt.' : '';
     echo 'clientinfo.sessionid = new Date().getTime() + ".' . $session_info . '" + Math.random().toString(36).substring(5);';
     echo 'ga("set", gaCustomDimensions["sessionID"], clientinfo.sessionid);';
 }
 //WordPress User ID
 $current_user = wp_get_current_user();
 if ($current_user && nebula_option('nebula_cd_userid')) {
     echo 'ga("set", gaCustomDimensions["userID"], "' . $current_user->ID . '");';
function nebula_autocomplete_search()
{
    if (!wp_verify_nonce($_POST['nonce'], 'nebula_ajax_nonce')) {
        die('Permission Denied.');
    }
    ini_set('memory_limit', '256M');
    $_POST['data']['term'] = trim($_POST['data']['term']);
    if (empty($_POST['data']['term'])) {
        return false;
        exit;
    }
    //Test for close or exact matches. Use: $suggestion['classes'] .= nebula_close_or_exact($suggestion['similarity']);
    function nebula_close_or_exact($rating = 0, $close_threshold = 80, $exact_threshold = 95)
    {
        if ($rating > $exact_threshold) {
            return ' exact-match';
        } elseif ($rating > $close_threshold) {
            return ' close-match';
        }
        return '';
    }
    //Standard WP search (does not include custom fields)
    $q1 = new WP_Query(array('post_type' => array('any'), 'post_status' => 'publish', 'posts_per_page' => 4, 's' => $_POST['data']['term']));
    //Search custom fields
    $q2 = new WP_Query(array('post_type' => array('any'), 'post_status' => 'publish', 'posts_per_page' => 4, 'meta_query' => array(array('value' => $_POST['data']['term'], 'compare' => 'LIKE'))));
    //Combine the above queries
    $autocomplete_query = new WP_Query();
    $autocomplete_query->posts = array_unique(array_merge($q1->posts, $q2->posts), SORT_REGULAR);
    $autocomplete_query->post_count = count($autocomplete_query->posts);
    //Loop through the posts
    if ($autocomplete_query->have_posts()) {
        while ($autocomplete_query->have_posts()) {
            $autocomplete_query->the_post();
            if (!get_the_title()) {
                //Ignore results without titles
                continue;
            }
            $post = get_post();
            $suggestion = array();
            similar_text(strtolower($_POST['data']['term']), strtolower(get_the_title()), $suggestion['similarity']);
            //Determine how similar the query is to this post title
            $suggestion['label'] = get_the_title();
            $suggestion['link'] = get_permalink();
            $suggestion['classes'] = 'type-' . get_post_type() . ' id-' . get_the_id() . ' slug-' . $post->post_name . ' similarity-' . str_replace('.', '_', number_format($suggestion['similarity'], 2));
            if (get_the_id() == get_option('page_on_front')) {
                $suggestion['classes'] .= ' page-home';
            } elseif (is_sticky()) {
                //@TODO "Nebula" 0: If sticky post. is_sticky() does not work here?
                $suggestion['classes'] .= ' sticky-post';
            }
            $suggestion['classes'] .= nebula_close_or_exact($suggestion['similarity']);
            $suggestions[] = $suggestion;
        }
    }
    //Find media library items
    $attachments = get_posts(array('post_type' => 'attachment', 's' => $_POST['data']['term'], 'numberposts' => 10, 'post_status' => null));
    if ($attachments) {
        $attachment_count = 0;
        foreach ($attachments as $attachment) {
            if (strpos(get_attachment_link($attachment->ID), '?attachment_id=')) {
                //Skip if media item is not associated with a post.
                continue;
            }
            $suggestion = array();
            $attachment_meta = wp_get_attachment_metadata($attachment->ID);
            $path_parts = pathinfo($attachment_meta['file']);
            $attachment_search_meta = get_the_title($attachment->ID) != '' ? get_the_title($attachment->ID) : $path_parts['filename'];
            similar_text(strtolower($_POST['data']['term']), strtolower($attachment_search_meta), $suggestion['similarity']);
            if ($suggestion['similarity'] >= 50) {
                $suggestion['label'] = get_the_title($attachment->ID) != '' ? get_the_title($attachment->ID) : $path_parts['basename'];
                $suggestion['classes'] = 'type-attachment file-' . $path_parts['extension'];
                $suggestion['classes'] .= nebula_close_or_exact($suggestion['similarity']);
                if (in_array(strtolower($path_parts['extension']), array('jpg', 'jpeg', 'png', 'gif', 'bmp'))) {
                    $suggestion['link'] = get_attachment_link($attachment->ID);
                } else {
                    $suggestion['link'] = wp_get_attachment_url($attachment->ID);
                    $suggestion['external'] = true;
                    $suggestion['classes'] .= ' external-link';
                }
                $suggestion['similarity'] = $suggestion['similarity'] - 0.001;
                //Force lower priority than posts/pages.
                $suggestions[] = $suggestion;
                $attachment_count++;
            }
            if ($attachment_count >= 2) {
                break;
            }
        }
    }
    //Find menu items
    $menus = get_transient('nebula_autocomplete_menus');
    if (empty($menus) || is_debug()) {
        $menus = get_terms('nav_menu');
        set_transient('nebula_autocomplete_menus', $menus, 60 * 60);
        //1 hour cache
    }
    foreach ($menus as $menu) {
        $menu_items = wp_get_nav_menu_items($menu->term_id);
        foreach ($menu_items as $key => $menu_item) {
            $suggestion = array();
            similar_text(strtolower($_POST['data']['term']), strtolower($menu_item->title), $menu_title_similarity);
            similar_text(strtolower($_POST['data']['term']), strtolower($menu_item->attr_title), $menu_attr_similarity);
            if ($menu_title_similarity >= 65 || $menu_attr_similarity >= 65) {
                if ($menu_title_similarity >= $menu_attr_similarity) {
                    $suggestion['similarity'] = $menu_title_similarity;
                    $suggestion['label'] = $menu_item->title;
                } else {
                    $suggestion['similarity'] = $menu_attr_similarity;
                    $suggestion['label'] = $menu_item->attr_title;
                }
                $suggestion['link'] = $menu_item->url;
                $path_parts = pathinfo($menu_item->url);
                $suggestion['classes'] = 'type-menu-item';
                if ($path_parts['extension']) {
                    $suggestion['classes'] .= ' file-' . $path_parts['extension'];
                    $suggestion['external'] = true;
                } elseif (!strpos($suggestion['link'], nebula_url_components('domain'))) {
                    $suggestion['classes'] .= ' external-link';
                    $suggestion['external'] = true;
                }
                $suggestion['classes'] .= nebula_close_or_exact($suggestion['similarity']);
                $suggestion['similarity'] = $suggestion['similarity'] - 0.001;
                //Force lower priority than posts/pages.
                $suggestions[] = $suggestion;
                break;
            }
        }
    }
    //Find categories
    $categories = get_transient('nebula_autocomplete_categories');
    if (empty($categories) || is_debug()) {
        $categories = get_categories();
        set_transient('nebula_autocomplete_categories', $categories, 60 * 60);
        //1 hour cache
    }
    foreach ($categories as $category) {
        $suggestion = array();
        $cat_count = 0;
        similar_text(strtolower($_POST['data']['term']), strtolower($category->name), $suggestion['similarity']);
        if ($suggestion['similarity'] >= 65) {
            $suggestion['label'] = $category->name;
            $suggestion['link'] = get_category_link($category->term_id);
            $suggestion['classes'] = 'type-category';
            $suggestion['classes'] .= nebula_close_or_exact($suggestion['similarity']);
            $suggestions[] = $suggestion;
            $cat_count++;
        }
        if ($cat_count >= 2) {
            break;
        }
    }
    //Find tags
    $tags = get_transient('nebula_autocomplete_tags');
    if (empty($tags) || is_debug()) {
        $tags = get_tags();
        set_transient('nebula_autocomplete_tags', $tags, 60 * 60);
        //1 hour cache
    }
    foreach ($tags as $tag) {
        $suggestion = array();
        $tag_count = 0;
        similar_text(strtolower($_POST['data']['term']), strtolower($tag->name), $suggestion['similarity']);
        if ($suggestion['similarity'] >= 65) {
            $suggestion['label'] = $tag->name;
            $suggestion['link'] = get_tag_link($tag->term_id);
            $suggestion['classes'] = 'type-tag';
            $suggestion['classes'] .= nebula_close_or_exact($suggestion['similarity']);
            $suggestions[] = $suggestion;
            $tag_count++;
        }
        if ($tag_count >= 2) {
            break;
        }
    }
    //Find authors (if author bios are enabled)
    if (nebula_is_option_enabled('authorbios')) {
        $authors = get_transient('nebula_autocomplete_authors');
        if (empty($authors) || is_debug()) {
            $authors = get_users(array('role' => 'author'));
            //@TODO "Nebula" 0: This should get users who have made at least one post. Maybe get all roles (except subscribers) then if postcount >= 1?
            set_transient('nebula_autocomplete_authors', $authors, 60 * 60);
            //1 hour cache
        }
        foreach ($authors as $author) {
            $author_name = $author->first_name != '' ? $author->first_name . ' ' . $author->last_name : $author->display_name;
            //might need adjusting here
            if (strtolower($author_name) == strtolower($_POST['data']['term'])) {
                //todo: if similarity of author name and query term is higher than X. Return only 1 or 2.
                $suggestion = array();
                $suggestion['label'] = $author_name;
                $suggestion['link'] = 'http://google.com/';
                $suggestion['classes'] = 'type-user';
                $suggestion['classes'] .= nebula_close_or_exact($suggestion['similarity']);
                $suggestion['similarity'] = '';
                //todo: save similarity to array too
                $suggestions[] = $suggestion;
                break;
            }
        }
    }
    if (sizeof($suggestions) >= 1) {
        //Order by match similarity to page title (DESC).
        function autocomplete_similarity_compare($a, $b)
        {
            return $b['similarity'] - $a['similarity'];
        }
        usort($suggestions, "autocomplete_similarity_compare");
        //Remove any duplicate links (higher similarity = higher priority)
        $outputArray = array();
        //This array is where unique results will be stored
        $keysArray = array();
        //This array stores values to check duplicates against.
        foreach ($suggestions as $suggestion) {
            if (!in_array($suggestion['link'], $keysArray)) {
                $keysArray[] = $suggestion['link'];
                $outputArray[] = $suggestion;
            }
        }
    }
    //Link to search at the end of the list
    //@TODO "Nebula" 0: The empty result is not working for some reason... (Press Enter... is never appearing)
    $suggestion = array();
    $suggestion['label'] = sizeof($suggestions) >= 1 ? '...more results for "' . $_POST['data']['term'] . '"' : 'Press enter to search for "' . $_POST['data']['term'] . '"';
    $suggestion['link'] = home_url('/') . '?s=' . str_replace(' ', '%20', $_POST['data']['term']);
    $suggestion['classes'] = sizeof($suggestions) >= 1 ? 'more-results search-link' : 'no-results search-link';
    $outputArray[] = $suggestion;
    echo json_encode($outputArray, JSON_PRETTY_PRINT);
    exit;
}
Example #9
0
function enqueue_nebula_frontend()
{
    global $upload_dir, $localize_bloginfo, $localize_postinfo, $localize_clientinfo, $localize_nebula_options;
    //Stylesheets
    wp_enqueue_style('nebula-normalize');
    wp_enqueue_style('nebula-gumby');
    wp_enqueue_style('nebula-mmenu');
    //wp_enqueue_style('nebula-animate_css');
    wp_enqueue_style('nebula-jquery_ui');
    wp_enqueue_style('nebula-font_awesome');
    wp_enqueue_style('nebula-google_font');
    wp_enqueue_style('nebula-main');
    if (!nebula_option('nebula_wireframing', 'disabled')) {
        wp_enqueue_style('nebula-wireframing');
        wp_enqueue_script('nebula-wireframing');
    }
    //Scripts
    wp_enqueue_script('jquery');
    wp_enqueue_script('nebula-jquery_ui');
    //wp_enqueue_script('swfobject');
    //wp_enqueue_script('hoverIntent');
    //wp_enqueue_script('nebula-modernizr_dev');
    wp_enqueue_script('nebula-modernizr');
    wp_enqueue_script('nebula-mmenu');
    //wp_enqueue_script('nebula-doubletaptogo');
    wp_enqueue_script('nebula-headroom');
    wp_enqueue_script('nebula-gumby');
    wp_enqueue_script('nebula-main');
    wp_localize_script('nebula-main', 'bloginfo', $localize_bloginfo);
    wp_localize_script('nebula-main', 'postinfo', $localize_postinfo);
    wp_localize_script('nebula-main', 'clientinfo', $localize_clientinfo);
    wp_localize_script('nebula-main', 'nebula_options', $localize_nebula_options);
    //Conditionals
    if (is_debug()) {
        //When ?debug query string is used
        wp_enqueue_script('nebula-performance_timing');
        //wp_enqueue_script('nebula-mmenu_debugger');
    }
    if (nebula_is_browser('ie', '9', '<=')) {
        //Old IE
        wp_enqueue_script('nebula-respond');
        wp_enqueue_script('nebula-html5shiv');
        //wp_deregister_script('jquery'); //Uncomment the next jQuery lines if WordPress bundles jQuery 2.0+ (currently bundles jQuery 1.11.2)
        //wp_enqueue_script('nebula-jquery_old'); //Uncomment the next jQuery lines if WordPress bundles jQuery 2.0+ (currently bundles jQuery 1.11.2)
    }
    if (!empty($GLOBALS['ga']) && nebula_option('nebula_cd_adblocker')) {
        wp_enqueue_script('nebula-adblockcheck');
        //Detect if user is blocking ads. If the custom dimension is active- removing this line will cause false positives.
    }
    if (is_page_template('tpl-search.php') || is_page(9999)) {
        //Form pages (that use selects) or Advanced Search Template. The Chosen library is also dynamically loaded in main.js.
        wp_enqueue_style('nebula-chosen');
        wp_enqueue_script('nebula-chosen');
    }
    if (is_page(9999)) {
        //Datatables pages. The Datatables library is also dynamically loaded in main.js
        wp_enqueue_style('nebula-datatables');
        wp_enqueue_script('nebula-datatables');
    }
    if (is_page(9999)) {
        //Twitter pages (conditional may need to change depending on type of page it's used on)
        wp_enqueue_script('nebula-twitter');
        //wp_enqueue_script('nebula-moment'); //Uncomment if using moment.js instead of Date.parse() for times.
    }
    if (nebula_is_desktop()) {
        //Desktop traffic only
        //wp_enqueue_script('nebula-skrollr');
    }
}
Example #10
0
<div class="row">
	<div class="sixteen columns">

		<?php 
$new_date_time_cache = false;
//This variable is for example purposes only and is NOT NEEDED when using transients normally!
$the_date_time = get_transient('nebula_transient_example');
if (empty($the_date_time) || is_debug()) {
    $new_date_time_cache = true;
    //This variable is for example purposes only and is NOT NEEDED when using transients normally!
    $the_date_time = date('l, F j, Y - g:ia', strtotime('now'));
    set_transient('nebula_transient_example', $the_date_time, 60 * 10);
    //10 minute cache
}
?>

		<h3>Super Duper Time Cacher</h3>
		<?php 
if ($new_date_time_cache) {
    ?>
			<p>
				<strong>A winner is you!</strong><br />
				You are storing a <span style="color: green;">brand new</span> transient!<br />
				This transient is now set to: <strong style="color: green;"><?php 
    echo $the_date_time;
    ?>
</strong>
			</p>
		<?php 
} else {
    ?>
Example #11
0
<div class="row">
	<div class="sixteen columns">

		<?php 
$cached_query = get_transient('example_cached_query');
if (empty($cached_query) || is_debug()) {
    $cached_query = new WP_Query(array('post_type' => 'event', 'category_name' => 'concert', 'showposts' => 2, 'paged' => get_query_var('paged')));
    set_transient('example_cached_query', $cached_query, 60 * 60);
    //1 hour cache
}
while ($cached_query->have_posts()) {
    $cached_query->the_post();
    ?>

		    <div class="home-feed-item event-feed-item">
		        <h3><a href="<?php 
    echo get_the_permalink();
    ?>
"><?php 
    echo get_the_title();
    ?>
</a></h3>
		        <?php 
    echo nebula_the_excerpt('Read More &raquo;', 35, 1);
    ?>
		    </div>

		<?php 
}
?>
Example #12
0
function admin_favicon()
{
    $cache_buster = is_debug() ? '?r' . mt_rand(1000, 99999) : '';
    echo '<link rel="shortcut icon" href="' . get_template_directory_uri() . '/images/meta/favicon.ico' . $cache_buster . '" />';
}
Example #13
0
function nebula_sass_color($color = 'primary')
{
    $scss_variables = get_transient('nebula_scss_variables');
    if (empty($menus) || is_debug()) {
        $variables_file = get_template_directory() . '/stylesheets/scss/partials/_variables.scss';
        if (!file_exists($variables_file)) {
            return false;
        }
        $scss_variables = file_get_contents($variables_file);
        set_transient('nebula_scss_variables', $scss_variables, 60 * 60);
        //1 hour cache
    }
    switch (str_replace(array('$', ' ', '_', '-'), '', $color)) {
        case 'primary':
        case 'primarycolor':
        case 'first':
        case 'main':
        case 'brand':
            $color_search = 'primary_color';
            break;
        case 'secondary':
        case 'secondarycolor':
        case 'second':
            $color_search = 'secondary_color';
            break;
        case 'tertiary':
        case 'tertiarycolor':
        case 'third':
            $color_search = 'tertiary_color';
            break;
        default:
            return false;
            break;
    }
    preg_match('/\\$' . $color_search . ': (\\S*)(;| !default;)/', $scss_variables, $matches);
    return $matches[1];
}
Example #14
0
File: routes.php Project: newset/gd
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
    return view('welcome');
});
/* view route */
Route::get('_/{page?}', 'CookController@page')->where('page', '(.*)');
Route::post('q/{ctl}/{action}/{params?}', 'CookController@cook')->where('params', '(.*)');
if (is_debug()) {
    Route::get('q/{ctrl}/{action}/{params?}', 'CookController@cook')->where('params', '(.*)');
}
Example #15
0
 *
 * @author Gino Dola <*****@*****.**>
 * @copyright 2014 Gino Dola
 *
 * This source file is protected by copyright favour of
 * Gino Dola. You have no right to copy, edit or publish
 * this file without a certain permission of the author.
 *
 * @version 1.0.0
 */
// -------------------------------------------------
// set timezone
// -------------------------------------------------
$timezone = tellme('timezone') !== false ? tellme('timezone') : 'Europe/Berlin';
date_default_timezone_set($timezone);
// --------------------------------------------------
// php configuration
// --------------------------------------------------
ini_set('register_globals', '0');
ini_set('magic_quotes_gpc', '0');
ini_set('magic_quotes_runtime', '0');
$set = is_debug() === true ? '1' : '0';
ini_set('display_errors', $set);
ini_set('display_startup_errors', $set);
ini_set('html_errors', $set);
ini_set('log_errors', '1');
ini_set('error_log', LOG_PATH . '/php-error.log');
ini_set('ignore_repeated_errors', '0');
// --------------------------------------------------
// session configuration
// --------------------------------------------------
/*==========================
 This file includes functions that are currently being developed and tested. Once finished they will be moved to the appropriate function file.
 It is recommended that the require_once() for this file remain commented out from functions.php (or feel free to delete the entire line).
 ===========================*/
//@TODO "Nebula" 0: Prevent Wordpress SEO (Yoast) from altering the title on the homepage.
//This would be moved to header.php once it works...
if (!file_exists(WP_PLUGIN_DIR . '/wordpress-seo') || is_front_page()) {
    //echo '<title>' wp_title('-', true, 'right') . '</title>';
} else {
    //echo '<title>' . wp_title('-', true, 'right') . '</title>';
}
//Display WordPress debug messages for Devs who are admins with ?debug query string is used.
//It appears WP_DEBUG can only be defined true in wp-config.php
//When it's true, it can be tested with: if ( WP_DEBUG ) ...
if (is_debug() && current_user_can('manage_options')) {
    define('WP_DEBUG', true);
    define('WP_DEBUG_DISPLAY', true);
}
//Upload a file to the Media Library //@TODO "Nebula" 0: In progress
function nebula_upload_to_media_library($filepath)
{
    if (!file_exists($filepath) || strlen(trim($filepath)) == 0) {
        return;
    }
    $result = wp_handle_upload($filepath);
}
//Upload data from JS via nebula_upload_data();
add_action('wp_ajax_nebula_upload_data', 'nebula_upload_data');
add_action('wp_ajax_nopriv_nebula_upload_data', 'nebula_upload_data');
function nebula_upload_data()
Example #17
0
 private function renderLibrary()
 {
     $this->res->clear();
     $this->res->setStatus(200);
     $type = null;
     switch ($this->uri) {
         case 'system.css':
             $this->res->addHeader('Content-Type', 'text/css');
             $dir = 'css';
             break;
         case 'system.js':
             $this->res->addHeader('Content-Type', 'text/javascript');
             $dir = 'js';
             break;
     }
     $application = RESOURCE_PATH . '/data/pres/template/source/' . $dir;
     $preset = PRESET_PATH . '/source/' . $dir;
     $files = explode(',', filter_input(INPUT_GET, 'libs'));
     $hash = hash('md5', filter_input(INPUT_GET, 'libs'));
     self::initCache();
     if (tellme('use_cache') === true && $this->__Cache->isStored($hash)) {
         // filesize of cachefile
         $info = $this->__Cache->getFileInfo($hash);
         // set header
         $this->res->addHeader('Cache-Control', 'public, must-revalidate, max-age=0');
         $this->res->addHeader('Pragma', 'no-cache');
         $this->res->addHeader('Content-Length', $info['filesize']);
         $this->res->addHeader('Content-Transfer-Encoding', 'binary');
         $this->res->addHeader('Last-Modified', time());
         // read cache
         $this->res->write($this->__Cache->read($hash));
     } else {
         $replace = null;
         if (file_exists($application . '/preprocessor.ini')) {
             $replace = parse_ini_file($application . '/preprocessor.ini');
         }
         $buffer = '';
         $temp = '';
         foreach ($files as $file) {
             if (file_exists($application . '/' . $file)) {
                 $buffer .= file_get_contents($application . '/' . $file);
             } else {
                 if (file_exists($preset . '/' . $file)) {
                     $buffer .= file_get_contents($preset . '/' . $file);
                 } else {
                     $buffer .= '/*** NOT FOUND: ' . $file . ' ***/';
                 }
             }
             if ($dir == 'css' && strpos($buffer, '@import') !== false) {
                 $temp = (string) '';
                 while (strpos($buffer, '@import') !== false) {
                     $found = substr($buffer, strpos($buffer, '@import'));
                     $found = substr($found, 0, strpos($found, ';') + strlen(';'));
                     $temp .= $found . PHP_EOL;
                     $buffer = str_replace($found, '', $buffer);
                 }
             }
             if (!is_null($replace)) {
                 foreach ($replace as $key => $val) {
                     $buffer = str_replace('%' . $key . '%', $val, $buffer);
                 }
             }
         }
         $buffer = $temp . PHP_EOL . $buffer;
         $this->res->write($buffer);
         if (tellme('use_cache') === true && !is_debug()) {
             $this->__Cache->write($this->res->getContent(), $hash);
         }
     }
     // end function
 }
Example #18
0
function CustomException($e)
{
    $args = array('message' => $e->getMessage(), 'code' => $e->getCode(), 'severity' => $e->getSeverity(), 'file' => $e->getFile(), 'line' => $e->getLine());
    switch ($args['severity']) {
        case E_NOTICE:
        case E_USER_NOTICE:
            $type = 'NOTICE';
            break;
        case E_WARNING:
        case E_USER_WARNING:
        case E_COMPILE_WARNING:
            $type = 'WARNING';
            break;
        case E_ERROR:
        case E_USER_ERROR:
            $type = 'ERROR';
            break;
        case E_DEPRECATED:
        case E_USER_DEPRECATED:
            $type = 'DEPRECATED';
            break;
        case E_PARSE:
            $type = 'PARSE ERROR';
            break;
        case E_CORE_ERROR:
            $type = 'CORE ERROR';
            break;
        case E_COMPILE_ERROR:
            $type = 'COMPILE ERROR';
            break;
        case E_STRICT:
            $type = 'STRICT';
            break;
        default:
            $type = 'UNDEFINED';
            break;
    }
    $args['type'] = $type . ' (' . $args['severity'] . ')';
    $hash = hash('md5', implode('.', $args));
    $args['time'] = date('d.m.Y - H:i:s');
    $err_msg = PHP_EOL . $args['message'] . PHP_EOL . PHP_EOL;
    $err_msg .= '- - - - - - - - - - - - - - - - - - - -' . PHP_EOL . PHP_EOL;
    $err_msg .= $args['type'] . ' [Code: ' . $args['code'] . ']' . PHP_EOL . PHP_EOL;
    $err_msg .= '- - - - - - - - - - - - - - - - - - - -' . PHP_EOL . PHP_EOL;
    $err_msg .= 'Server: ' . preg_replace('/www./i', '', filter_input(INPUT_SERVER, 'HTTP_HOST')) . PHP_EOL . PHP_EOL;
    $err_msg .= 'File: ' . $args['file'] . PHP_EOL . PHP_EOL;
    $err_msg .= 'Line: ' . $args['line'] . PHP_EOL . PHP_EOL;
    $err_msg .= '- - - - - - - - - - - - - - - - - - - -' . PHP_EOL . PHP_EOL;
    $err_msg .= 'PHP Version: ' . phpversion() . PHP_EOL . PHP_EOL;
    $err_msg .= '- - - - - - - - - - - - - - - - - - - -' . PHP_EOL . PHP_EOL;
    $err_msg .= 'Remote Address: ' . filter_input(INPUT_SERVER, 'REMOTE_ADDR') . PHP_EOL . PHP_EOL;
    $err_msg .= 'Request URI: ' . filter_input(INPUT_SERVER, 'REQUEST_URI') . PHP_EOL . PHP_EOL;
    $err_msg .= 'User Agent: ' . filter_input(INPUT_SERVER, 'HTTP_USER_AGENT') . PHP_EOL . PHP_EOL;
    $err_msg .= '- - - - - - - - - - - - - - - - - - - -' . PHP_EOL . PHP_EOL;
    $err_msg .= $e->getTraceAsString() . PHP_EOL . PHP_EOL;
    $err_msg .= '- - - - - - - - - - - - - - - - - - - -' . PHP_EOL . PHP_EOL;
    $err_msg .= 'End of report - ' . $args['time'];
    if (function_exists('is_debug') && is_debug()) {
        ob_clean();
        header('Content-Type: text/plain');
        exit($err_msg);
    } else {
        $excHash = array();
        if (isset($_COOKIE['EXC_HASH']) && !is_null($_COOKIE['EXC_HASH'])) {
            $excHash = unserialize($_COOKIE['EXC_HASH']);
        }
        if (!in_array($hash, $excHash)) {
            global $tellme;
            // check if log classes are available
            if (class_exists('LogWriterStream') && class_exists('Log')) {
                $logfile = RESOURCE_PATH . '/logs/exception.log';
                $format = '[%date% %time%] [%type%] [client %client%] [host %host%] [uri %uri%] [file %file%] [line %line%] %msg%';
                $writer = new LogWriterStream($logfile, $format);
                $logger = new Log();
                $logger->setEventItem('file', $args['file']);
                $logger->setEventItem('line', $args['line']);
                $logger->setEventItem('type', $type);
                $logger->addWriter($writer);
                $logger->logEvent($args['message'], 0);
            } else {
                $err_msg .= PHP_EOL . PHP_EOL . '- - - - - - - - - - - - - - - - - - - -' . PHP_EOL . PHP_EOL;
                $err_msg .= 'No log report has been written for this error.' . PHP_EOL;
                $err_msg .= 'The corresponding PHP classes (Log, LogWriterStream)' . PHP_EOL;
                $err_msg .= 'were not available yet.';
            }
            $to = isset($tellme['debug_mail']) ? $tellme['debug_mail'] : null;
            if (!is_null($to)) {
                $server = preg_replace('/www./i', '', filter_input(INPUT_SERVER, 'HTTP_HOST'));
                $from = $server . ' <exception@' . $server . '>';
                $subject = $args['type'] . ' - ' . $server;
                $header = "From: " . $from . PHP_EOL;
                $header .= "Message-Id: <" . sha1(microtime()) . "@" . $server . ">" . PHP_EOL;
                $header .= "X-Mailer: PHP " . phpversion() . PHP_EOL;
                $header .= "MIME-Version: 1.0" . PHP_EOL;
                $header .= "X-Priority: 1" . PHP_EOL;
                $header .= "Importance: High" . PHP_EOL;
                $header .= "Content-Type: text/plain; charset=UTF-8" . PHP_EOL;
                $header .= "Content-Transfer-Encoding: 8bit" . PHP_EOL;
                if (mail($to, $subject, $err_msg, $header)) {
                    $cookie = array_merge(array($hash), $excHash);
                    setcookie('EXC_HASH', serialize($cookie), 0, '/');
                }
            }
        }
        ob_clean();
        if (defined('ABS_PATH')) {
            header('Content-Type: text/html');
            $site = file_get_contents(ABS_PATH . '/sites/error.htm');
            $site = str_replace('[TITLE]', $args['type'], $site);
            $site = str_replace('[CONTENT]', 'An error occurred in the application and your page could not be served. Please try again in a few moments.', $site);
        } else {
            header('Content-Type: text/plain');
            $site = file_get_contents('An error occurred in the application and your page could not be served.' . PHP_EOL . 'Please try again in a few moments.');
        }
        exit($site);
    }
    // end function
}
function nebula_sass_color($color = 'primary', $theme = 'child')
{
    $override = apply_filters('pre_nebula_sass_color', false, $color, $theme);
    if ($override !== false) {
        return $override;
    }
    if (is_child_theme() && $theme == 'child') {
        $stylesheets_directory = get_stylesheet_directory() . '/stylesheets';
        $transient_name = 'nebula_scss_child_variables';
    } else {
        $stylesheets_directory = get_template_directory() . '/stylesheets';
        $transient_name = 'nebula_scss_variables';
    }
    $scss_variables = get_transient($transient_name);
    if (empty($menus) || is_debug()) {
        $variables_file = $stylesheets_directory . '/scss/partials/_variables.scss';
        if (!file_exists($variables_file)) {
            return false;
        }
        WP_Filesystem();
        global $wp_filesystem;
        $scss_variables = $wp_filesystem->get_contents($variables_file);
        set_transient($transient_name, $scss_variables, 60 * 60);
        //1 hour cache
    }
    switch (str_replace(array('$', ' ', '_', '-'), '', $color)) {
        case 'primary':
        case 'primarycolor':
        case 'first':
        case 'main':
        case 'brand':
            $color_search = 'primary_color';
            break;
        case 'secondary':
        case 'secondarycolor':
        case 'second':
            $color_search = 'secondary_color';
            break;
        case 'tertiary':
        case 'tertiarycolor':
        case 'third':
            $color_search = 'tertiary_color';
            break;
        default:
            return false;
            break;
    }
    preg_match('/\\$' . $color_search . ': (\\S*)(;| !default;)/', $scss_variables, $matches);
    return $matches[1];
}
Example #20
0
function nebula_domain_prevention()
{
    $domain_blacklist_json_file = get_template_directory() . '/includes/data/domain_blacklist.txt';
    $domain_blacklist = get_transient('nebula_domain_blacklist');
    if (empty($domain_blacklist) || is_debug()) {
        WP_Filesystem();
        global $wp_filesystem;
        $domain_blacklist = $wp_filesystem->get_contents('https://raw.githubusercontent.com/piwik/referrer-spam-blacklist/master/spammers.txt');
        //@TODO "Nebula" 0: Consider using: FILE_SKIP_EMPTY_LINES (works with file() dunno about get_contents())
        if (empty($domain_blacklist)) {
            $domain_blacklist = $wp_filesystem->get_contents('https://raw.githubusercontent.com/chrisblakley/Nebula/master/includes/data/domain_blacklist.txt');
            //In case piwik is not available (or changes).
        }
        if (!empty($domain_blacklist)) {
            $wp_filesystem->put_contents($domain_blacklist_json_file, $domain_blacklist);
            set_transient('nebula_domain_blacklist', $domain_blacklist, 60 * 60);
            //1 hour cache
        } else {
            $domain_blacklist = $wp_filesystem->get_contents($domain_blacklist_json_file);
        }
    }
    if (!empty($domain_blacklist)) {
        $GLOBALS['domain_blacklist'] = array();
        foreach (explode("\n", $domain_blacklist) as $line) {
            //@TODO "Nebula" 0: continue; if empty line.
            $GLOBALS['domain_blacklist'][] = $line;
        }
        //Additional blacklisted domains
        $additional_blacklisted_domains = array();
        $GLOBALS['domain_blacklist'] = array_merge($GLOBALS['domain_blacklist'], $additional_blacklisted_domains);
        if (count($GLOBALS['domain_blacklist']) > 1) {
            if (isset($_SERVER['HTTP_REFERER']) && contains(strtolower($_SERVER['HTTP_REFERER']), $GLOBALS['domain_blacklist'])) {
                ga_send_event('Security Precaution', 'Blacklisted Domain Prevented', 'Referring Domain: ' . $_SERVER['HTTP_REFERER'] . ' (IP: ' . $_SERVER['REMOTE_ADDR'] . ')');
                do_action('nebula_spambot_prevention');
                header('HTTP/1.1 403 Forbidden');
                die;
            }
            if (isset($_SERVER['REMOTE_HOST']) && contains(strtolower($_SERVER['REMOTE_HOST']), $GLOBALS['domain_blacklist'])) {
                ga_send_event('Security Precaution', 'Blacklisted Domain Prevented', 'Hostname: ' . $_SERVER['REMOTE_HOST'] . ' (IP: ' . $_SERVER['REMOTE_ADDR'] . ')');
                do_action('nebula_spambot_prevention');
                header('HTTP/1.1 403 Forbidden');
                die;
            }
            if (isset($_SERVER['SERVER_NAME']) && contains(strtolower($_SERVER['SERVER_NAME']), $GLOBALS['domain_blacklist'])) {
                ga_send_event('Security Precaution', 'Blacklisted Domain Prevented', 'Server Name: ' . $_SERVER['SERVER_NAME'] . ' (IP: ' . $_SERVER['REMOTE_ADDR'] . ')');
                do_action('nebula_spambot_prevention');
                header('HTTP/1.1 403 Forbidden');
                die;
            }
            if (isset($_SERVER['REMOTE_ADDR']) && contains(strtolower(gethostbyaddr($_SERVER['REMOTE_ADDR'])), $GLOBALS['domain_blacklist'])) {
                ga_send_event('Security Precaution', 'Blacklisted Domain Prevented', 'Network Hostname: ' . $_SERVER['SERVER_NAME'] . ' (IP: ' . $_SERVER['REMOTE_ADDR'] . ')');
                do_action('nebula_spambot_prevention');
                header('HTTP/1.1 403 Forbidden');
                die;
            }
        } else {
            ga_send_event('Security Precaution', 'Error', 'spammers.txt has no entries!');
        }
        //Use this to generate a regex string of common referral spambots (or a custom passes array of strings). Unfortunately Google Analytics limits filters to 255 characters.
        function nebula_spambot_regex($domains = null)
        {
            $domains = $domains ? $domains : $GLOBALS['domain_blacklist'];
            $domains = str_replace(array('.', '-'), array('\\.', '\\-'), $domains);
            return implode("|", $domains);
        }
    } else {
        ga_send_event('Security Precaution', 'Error', 'spammers.txt was not available!');
    }
}
Example #21
0
 function display()
 {
     $index_tpl = 'index';
     $tpl = new ltpl($index_tpl);
     // fatal errors?
     if ($this->global_msg) {
         // Show global message (login error?)
         $this->mainhref = $this->global_msg;
     }
     // Errors & warnings
     if ($this->error) {
         // Add fatal errors
         $out = '';
         $out .= '<div class="error_div">';
         $out .= '<h3>' . lang('e_title') . '</h3>';
         if (count($this->error) > 1) {
             $out .= '<ul>';
             foreach ($this->error as $k => $e) {
                 $out .= '<li>' . $e . '</li>';
             }
             $out .= '</ul>';
         } else {
             $out .= '<p>' . $this->error[0] . '</p>';
         }
         $out .= '</div>';
         $this->mainhref = $out . $this->mainhref;
     }
     $tpl->v('main', $this->mainhref);
     // Site title
     if (!$this->site_title) {
         $this->site_title = $GLOBALS['siteconfig']['site_title'];
     } else {
         $this->site_title = $GLOBALS['siteconfig']['site_title'] . ' : ' . $this->site_title;
     }
     if ($this->page_title) {
         $this->page_title[count($this->page_title) - 1] = '<b>' . $this->page_title[count($this->page_title) - 1] . '</b>';
         $this->page_title = implode(' / ', $this->page_title);
     }
     if (!$this->meta_kw && !$this->meta_desc) {
         //$metad = db_select_one ('site_pages', array('meta_kw','meta_desc'),'index','name');
         $this->meta_kw = @$metad['meta_kw'];
         $this->meta_desc = @$metad['meta_desc'];
     }
     $tpl->v('main', $this->mainhref);
     $tpl->v('meta_kw', $this->meta_kw);
     $tpl->v('meta_desc', $this->meta_desc);
     $tpl->v('site_title', $this->site_title);
     $tpl->v('page_title', $this->page_title);
     $tpl->v('public_wdg', $this->public_wdg);
     $tpl->v('cookie_domain', COOKIE_DOMAIN);
     $tpl->v('code_bottom', @$GLOBALS['siteconfig']['code_bottom']);
     if (@cfg('debug') || is_debug()) {
         $tpl->v('debug', ldb_log_html());
     }
     echo $tpl->get();
 }
Example #22
0
<?php

$debug_class = is_debug() ? 'debug' : '';
?>
<!doctype html <?php 
echo nebula_option('nebula_appcache_manifest') ? 'manifest="' . get_template_directory_uri() . '/includes/manifest.appcache"' : '';
?>
>
<!--[if lt IE 7]><html <?php 
language_attributes();
?>
 class="<?php 
echo $debug_class;
?>
 no-js ie ie6 lt-ie7 lte-ie7 lt-ie8 lte-ie8 lt-ie9 lte-ie9 lt-ie10"><![endif]-->
<!--[if IE 7]><html <?php 
language_attributes();
?>
 class="<?php 
echo $debug_class;
?>
 no-js ie ie7 lte-ie7 lt-ie8 lte-ie8 lt-ie9 lte-ie9 lt-ie10"><![endif]-->
<!--[if IE 8]><html <?php 
language_attributes();
?>
 class="<?php 
echo $debug_class;
?>
 no-js ie ie8 lte-ie8 lt-ie9 lte-ie9 lt-ie10"><![endif]-->
<!--[if IE 9]><html <?php 
language_attributes();
Example #23
0
    function nebula_theme_json()
    {
        $override = apply_filters('pre_nebula_theme_json', false);
        if ($override !== false) {
            return;
        }
        //Initialize the update checker.
        require get_template_directory() . '/includes/libs/theme-update-checker.php';
        $example_update_checker = new ThemeUpdateChecker('Nebula-master', 'https://raw.githubusercontent.com/chrisblakley/Nebula/master/includes/data/nebula_theme.json');
        //Create/Write a theme info file
        if (is_writable(get_template_directory())) {
            $nebula_theme_json_file = get_template_directory() . '/includes/data/nebula_theme.json';
            if (!file_exists($nebula_theme_json_file) || filemtime($nebula_theme_json_file) > time() - 60 * 60 * 24 || is_debug()) {
                $nebula_theme_json = '{
	"version": "' . nebula_version('full') . '",
	"details_url": "https://github.com/chrisblakley/Nebula/commits/master",
	"download_url": "https://github.com/chrisblakley/Nebula/archive/master.zip"
}';
                WP_Filesystem();
                global $wp_filesystem;
                $wp_filesystem->put_contents($nebula_theme_json_file, $nebula_theme_json);
            }
        }
    }