Beispiel #1
0
function projects($options = "")
{
    global $clerk, $project;
    if (!is_array($options)) {
        $options = prepare_settings($options);
    }
    // Defaults
    $defaults = array('id' => '', 'template' => '', 'show' => 'small', 'tags' => '', 'section' => '', 'sticky' => 'true', 'order' => 'pos', 'orderHow' => 'asc', 'limit' => '');
    $options = merge_settings($options, $defaults);
    $project_count = 0;
    if (!empty($options['func'])) {
        if (is_callable($options['func'])) {
            ob_start();
            call_user_func($options['func'], $options);
            $contents = ob_get_contents();
            ob_end_clean();
            return $contents;
        }
    }
    if (!empty($_GET[getRemappedVar("projects")]) && $options['sticky'] == "false") {
        return;
    }
    $options['orderHow'] = strtoupper($options['orderHow']);
    // Handle tags option
    if (!empty($_GET['project_tags'])) {
        $options['tags'] = $_GET['project_tags'];
    }
    if (!empty($options['tags'])) {
        $options['show'] = "small";
        $tags = explode(",", str_replace(", ", ",", $options['tags']));
        // First, collect the category IDs...
        $total = count($tags);
        $count = 0;
        foreach ($tags as $t) {
            $tag = $clerk->complex_name($t);
            $where .= $count == 0 ? "tag= '{$tag}'" : " OR tag= '{$tag}'";
            $count++;
        }
        $where = $count > 0 ? "WHERE " . $where : "";
        $getTags = $clerk->query_select("projects_to_tags", "", $where);
        // And then construct the join...
        $count = 0;
        $where = "";
        while ($tag = $clerk->query_fetchArray($getTags)) {
            $where .= $count == 0 ? "tag= '" . $tag['tag'] . "'" : " OR tag= '" . $tag['tag'] . "'";
            $count++;
        }
        $from = "projects_to_tags join projects on projects_to_tags.projectid= projects.id";
        if (empty($where)) {
            $from = "projects";
        }
    } else {
        $from = "projects";
        if (!empty($options['id'])) {
            $id = $options['id'];
            $where = "id= '{$id}' OR slug= '{$id}' OR title= '{$id}'";
        }
    }
    if (empty($options['template'])) {
        if ($options['show'] == "big") {
            $options['template'] = "projects_view.html";
        } else {
            $options['template'] = "projects_list.html";
        }
        if ($options['sticky'] == "true") {
            $options['template'] = $options['show'] == "small" ? "projects_list.html" : "projects_view.html";
        }
    }
    if (file_exists(HQ . "site/themes/" . THEME . "/templates/" . $options['template']) == false) {
        return "Oops! Looks like your theme is missing the template file, <em>" . $options['template'] . "</em><br /><br />Create this file and upload it to the \"templates\" folder in your theme's folder. Don't forget to fill it with template tags and your custom HTML!";
    }
    // Handle section
    if (!empty($options['section']) && empty($_GET['project_tags'])) {
        if (!empty($options['tags'])) {
            $where .= " AND ";
        }
        $sec = $options['section'];
        $section = $clerk->query_fetchArray($clerk->query_select("project_sections", "", "WHERE name= '{$sec}' OR slug= '{$sec}' OR id='{$sec}'"));
        $where .= "section= '" . $section['id'] . "'";
    }
    // Get sections, foreach section get projects where section = $section, loop out like normal
    // (to preserve section AND project ordering)
    $order = $options['order'] == "random" ? "ORDER BY rand()" : "ORDER BY section, " . $options['order'] . " " . $options['orderHow'];
    $limit = empty($options['limit']) ? "" : "LIMIT " . $options['limit'];
    // Pagination
    if ($options['pagination'] == "true") {
        $page = !isset($_GET['p']) || !is_numeric($_GET['p']) ? 1 : (int) $_GET['p'];
        $offset = ($page - 1) * $options['limit'];
        $limit = 'LIMIT ' . $offset . ', ' . $options['limit'];
    }
    // Spit it out!
    ob_start();
    if (!empty($_GET['project_tags'])) {
        echo '<div class="tags">Searching Tags: ' . currentProjectTags() . '</div>';
    }
    if (empty($options['id']) && projectSelected()) {
        $where = empty($where) ? "WHERE publish= 1" : "WHERE (" . $where . ") AND publish= 1";
        $projects = array();
        $getProjects = $clerk->query_select("{$from}", "", "{$where} {$order} {$limit}");
        while ($p = $clerk->query_fetchArray($getProjects)) {
            $projects[$p['id']] = $p;
        }
        $getSections = $clerk->query_select("project_sections", "", "ORDER BY pos ASC");
        while ($section = $clerk->query_fetchArray($getSections)) {
            foreach ($projects as $id => $data) {
                if ($data['section'] == $section['id']) {
                    $project = $projects[$id];
                    include HQ . "site/themes/" . THEME . "/templates/" . $options['template'];
                    unset($projects[$id]);
                }
            }
        }
    } elseif (!empty($options['id']) && projectSelected()) {
        $where = empty($where) ? "" : "WHERE (" . $where . ")";
        $options['template'] = "projects_view.html";
        $get = $clerk->query_select("{$from}", "", "{$where} {$order} {$limit}");
        while ($project = $clerk->query_fetchArray($get)) {
            include HQ . "site/themes/" . THEME . "/templates/" . $options['template'];
        }
    } else {
        $where = empty($where) ? "WHERE publish= 1" : "WHERE " . $where . " AND publish= 1";
        $projects = array();
        $getProjects = $clerk->query_select("{$from}", "", "{$where} {$order} {$limit}");
        while ($p = $clerk->query_fetchArray($getProjects)) {
            $projects[$p['id']] = $p;
        }
        $getSections = $clerk->query_select("project_sections", "", "ORDER BY pos ASC");
        while ($section = $clerk->query_fetchArray($getSections)) {
            foreach ($projects as $id => $data) {
                if ($data['section'] == $section['id']) {
                    $project = $projects[$id];
                    if (pageSelected() == true) {
                        projectDisplayers($id);
                    }
                    include HQ . "site/themes/" . THEME . "/templates/" . $options['template'];
                    unset($projects[$id]);
                }
            }
        }
    }
    $contents = ob_get_contents();
    ob_end_clean();
    return $contents;
}
Beispiel #2
0
function prev_post($return_data = false)
{
    global $clerk, $blog;
    $post_list = array();
    $current_post = postInfo(selectedPost());
    $current_index = 0;
    $count = 0;
    $page = pageInfo(currentPage());
    $options = prepare_settings($page['content_options']);
    $defaults = array('order' => 'date', 'orderHow' => 'desc');
    $options = merge_settings($options, $defaults);
    $posts = $clerk->query_select("secretary_blog", "", "WHERE status= 1 ORDER BY {$options['order']} {$options['orderHow']}");
    while ($post = $clerk->query_fetchArray($posts)) {
        $post_list[] = $post;
        if ($post['id'] == $current_post['id']) {
            $current_index = $count;
        }
        $count++;
    }
    if ($current_index == 0) {
        $prev_post = $post_list[count($post_list) - 1];
    } else {
        $prev_post = $post_list[$current_index - 1];
    }
    if ($return_data) {
        $prev_post['link'] = post_link(false, $prev_post['id']);
        return $prev_post;
    }
    return post_link(false, $prev_post['id']);
}