function au_blog_url($input = '', $header = false)
{
    // Global the big $aulis
    global $aulis, $setting;
    // The input needs to be an array otherwise we will redirect to the blogindex
    if (!(is_array($input) and $input != '')) {
        return au_url($setting["enable_blog_url_rewriting"] == "1" ? 'blog' : '?', $header);
    }
    // If we are an array, we have to have the app value
    if (!array_key_exists("app", $input)) {
        return au_url($setting["enable_blog_url_rewriting"] == "1" ? 'blog' : '?', $header);
    }
    // Is blog rewriting enabled?
    if ($setting["enable_blog_url_rewriting"] == "1") {
        // entries/number/entry-name
        if ($input['app'] == "blogentry") {
            return au_url("entries/" . au_encrypt_blog_id($input['id']) . "/" . strtolower(str_replace(array(" ", "?", "!", "&"), array("-", "", "", ""), $input['title'])), $header);
        } else {
            if ($input['app'] == "blogindex" && array_key_exists('offset', $input)) {
                if (array_key_exists('search', $input)) {
                    return au_url('blog/search/' . $input['search'] . '/offset/' . $input['offset'], $header);
                } else {
                    if (array_key_exists('category', $input) && array_key_exists('category_name', $input)) {
                        return au_url('blog/category/' . $input['category'] . '/offset/' . $input['offset'] . '/' . au_string_clean($input['category_name'], '-'), $header);
                    } else {
                        return au_url('blog/offset/' . $input['offset'], $header);
                    }
                }
            } elseif ($input['app'] == 'blogindex' && array_key_exists('category', $input) && array_key_exists('category_name', $input)) {
                return au_url('blog/category/' . $input['category'] . '/' . au_string_clean($input['category_name'], '-'), $header);
            } elseif ($input['app'] == 'blogindex' && array_key_exists('search', $input)) {
                return au_url('blog/search/' . au_string_clean($input['search']), $header);
            } else {
                if ($input['app'] == 'blogindex' && count($input) == 1) {
                    return au_url('blog', $header);
                } else {
                    return au_url("?" . http_build_query($input), $header);
                }
            }
        }
    }
    // Otherwise just a normal url
    return au_url("?" . http_build_query($input), $header);
}
Example #2
0
function au_show_blogindex()
{
    // $aulis might come in handy here
    global $aulis, $setting;
    // Did our lovely user specify an offset?
    if (isset($_GET['offset']) && is_numeric($_GET['offset'])) {
        $offset = $_GET['offset'];
    } else {
        $offset = 0;
    }
    // Extra parameters, in case we need them
    $extra_parameters = '';
    // Are we searching?
    if (isset($_REQUEST['search']) && !isset($_REQUEST['category'], $_REQUEST['tag'])) {
        // Empty searches are not allowed
        if (trim($_REQUEST['search']) == '') {
            au_blog_url('', true);
        }
        // Do we maybe need to clean a search string before redirecting?
        if (isset($_POST['search']) && $_POST['search'] != '') {
            // Do we need to clean it or is urlencode enough?
            if ($setting['enable_blog_url_rewriting'] == 1) {
                $search_string = au_string_clean($_POST['search']);
            } else {
                $search_string = urlencode($_POST['search']);
            }
            // The cleaned string cannot be empty
            if ($search_string != '') {
                // Redirect to clean url if possible
                if ($setting['enable_blog_url_rewriting'] == 1) {
                    au_url('blog/search/' . $search_string, true);
                } else {
                    au_url('?app=blogindex&search=' . $search_string, true);
                }
            }
            // Nothing more here for us now
            die;
        }
        // Do we maybe need to unclean the search string?
        if (isset($_GET['search']) && isset($_GET['rewrite'])) {
            $aulis['blog_search'] = str_replace("+", " ", $_GET['search']);
            $aulis['blog_search'] = str_replace("-plus-", "+", $aulis['blog_search']);
        } else {
            if (isset($_GET['search'])) {
                $aulis['blog_search'] = urldecode($_GET['search']);
            } else {
                $aulis['blog_search'] = '';
            }
        }
        // Time to form the extra parameters
        $exploded_search = explode(' ', $aulis['blog_search']);
        foreach ($exploded_search as $keyword) {
            $regex = "REGEXP '[[:<:]]" . au_db_escape($keyword) . "[[:>:]]'";
            $extra_parameters .= " AND (entries.blog_name {$regex} OR entries.blog_intro {$regex} OR entries.blog_content {$regex})";
        }
    }
    // Do we have to add parameters for category or tag to the query?
    if (isset($_GET['category']) && is_numeric($_GET['category']) && !isset($_GET['search'], $_GET['tag']) && ($aulis['blog_category'] = $_GET['category'])) {
        $extra_parameters .= ' AND ' . (isset($_GET['category']) ? "entries.blog_category = {$_GET['category']}" : '');
    }
    // Let's build the query
    $query = "SELECT entries.*, COUNT(comments.comment_id) AS comment_count, categories.category_name AS category_name\n\tFROM blog_entries AS entries \n\tLEFT JOIN blog_comments AS comments ON entries.entry_id = comments.blog_id \n\tLEFT JOIN blog_categories AS categories ON entries.blog_category = categories.category_id \n\tWHERE entries.blog_activated = 1 and entries.blog_in_queue = 0 {$extra_parameters} GROUP BY entries.entry_id ORDER BY entries.blog_date DESC;";
    // We are building the simple version of the query now, because that's enough to get info from
    $query_simple_parameters = "entries.blog_activated = 1 and entries.blog_in_queue = 0 {$extra_parameters}";
    // We are getting the maximum offset and the initial row count right now
    $query_info = au_get_max_blog_offset($query_simple_parameters);
    // We need to check if our offset is, like, alright, otherwise we need to redirect
    if (!au_check_offset($offset, THEME_BLOG_ENTRIES_PER_PAGE, $query_info['max_offset'])) {
        $_GET['offset'] = au_validate_offset($offset, THEME_BLOG_ENTRIES_PER_PAGE, $query_info['max_offset']);
        au_blog_url($_GET, true);
    }
    // Let's load all blog entries that are activated and are not in the queue (thus are published)
    $entries = au_parse_pagination($query, true, $offset, THEME_BLOG_ENTRIES_PER_PAGE, $query_info['row_count']);
    // For each blog item, we want to show its preview
    while ($entry = $entries['paged']->fetchObject()) {
        au_show_blog_preview($entry);
    }
    // We might want to transfer the information about the pagination, so that it can be used in the template
    $aulis['blog_count'] = $query_info['row_count'];
    $aulis['blog_current_offset'] = $offset;
    $aulis['blog_next_offset'] = $entries['next_position'];
    $aulis['blog_previous_offset'] = $entries['previous_position'];
    $aulis['blog_max_offset'] = $query_info['max_offset'];
    // This will load the wrapper! :)
    return au_load_template('blog_index');
}