Giter Site home page Giter Site logo

framework-26's People

Contributors

acpmasquerade avatar suraj-kumar-adhikari avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

seanrow

framework-26's Issues

Database Fix Required in get method

public function get($table_name = NULL, $where = array(), $select = NULL, $limit = NULL, $offset = NULL, $order_by = NULL, $group_by = NULL) {
        if (!$table_name) {
            return FALSE;
        }

        if ($select) {

            if(is_array($select) OR is_object($select)){
                $select = "`".implode("`,`" , $select)."`";
            }

            $query = "SELECT {$select} FROM `{$table_name}` ";
        } else {
            $query = "SELECT * FROM `{$table_name}` ";
        }


        if ($where) {
            $query .= "WHERE ".$this->_where($where);
        }

        if($group_by){
            $query .= " GROUP BY {$group_by}";
        }
        if($order_by){
            $query .= " ORDER BY {$order_by}";
        }
        if($limit){
            if(!$offset){
                $offset = 0;
            }
           $query .= " LIMIT {$offset}, {$limit}";
        }

        return $this->get_results($query);
    }

404 enhancement for custom message

Helper_Template

class Helper_Template extends Helper{
        public static function page_not_found($message){
            $view_data = array();
            $view_data["message"] = $message;
            Config::set("header", "");
            Template::set("404", $view_data);
            return;
        }
    }

404.php

<?php
    $message = Template::getvar("message");
    $message_parts = array();
    if($message){
        $message_parts = explode(",", $message);
    }
?>
<div class="row-fluid">
    <div class="http-error">
        <?php if($message_parts):?>
            <h1><?php echo $message_parts[0];?>!</h1>
            <p class="info"><?php echo $message_parts[1];?></p>
        <?php else:?>
            <h1>Oops!</h1>
            <p class="info">This page doesn't exist.</p>
        <?php endif;?>
            <p><a href="<?php echo Config::url("");?>"><i class="icon-home"></i></a></p>
    </div>
</div>

Usage:

Helper_Template::page_not_found("Sorry, Requested page not found!");

Pagination helper fix required for form post

public static function build_pagination_links($page_number = 1, 
                                        $limit = DB::default_limit, 
                                        $max_results, 
                                        $page_prefix, 
                                        $page_suffix = "", 
                                        $postdata = null, 
                                        $show_title = true, 
                                        $is_get = FALSE, 
                                        $search_query_string = "") {

            # calcuate last page
            $last_page = ceil($max_results / $limit);

            echo "<div 
                    class=\"pagination max-results-{$max_results} page-number-{$page_number} last-page-{$last_page}\" 
                    data-max-results=\"{$max_results}\" 
                    data-page-number=\"{$page_number}\"
                    data-last-page=\"{$last_page}\"
                    data-id=\"pagination\">";

            if (is_array($postdata)) {
                echo "<form name='pagination_form' method='post' style='display:none'>";
                foreach ($postdata as $key => $value) {
                    echo "<input type='hidden' name='{$key}' value='{$value}'>";
                }
                echo "</form>";

                # building jquery for form submission
                ?>
                <script type='text/javascript'>
                    $(function(){
                        $("div.pagination a").click(function(){
                            var pagination_form = $("div.pagination form[name=pagination_form]");
                            var action_path = $(this).attr("href");

                            pagination_form.attr("action",$(this).attr("href"));

                            var event = jQuery.Event("submit");
                            pagination_form.trigger(event);

                            // This is very important,
                            // Event trigger worked only after I returned false.
                            return false;
                        });


                    });
                </script>
                <?php

            }

            if ($last_page > 1) {
                echo "<ul>";
                if ($show_title):
                    echo "<h2>Pages</h2>";
                endif;
                # generate first and previous links
                if ($page_number != 1) {
                    if ($is_get) {
                        echo '<li>';
                        echo anchor( build_link($page_prefix , "{$page_prefix}&page_number=1&limit=" . $limit . "&max_results={$max_results}"), "&laquo; " . _t("first"), "class=\"first left\"");
                        echo "</li>";
                        echo '<li>';
                        echo anchor( build_link($page_prefix ,  "{$page_prefix}&page_number=" . ($page_number - 1) . "&limit=" . $limit . "&max_results={$max_results}") , "&laquo; " . _t("previous"), "class\"prev left\"");
                        echo '</li>';
                    } else {
                        echo '<li>';
                        echo anchor($page_prefix . "1/" . $limit . "/" . $page_suffix, "&laquo; " . ("first"), "class\"first left\"");
                        echo '</li>';
                        echo '<li>';
                        echo anchor($page_prefix . ($page_number - 1) . "/" . $limit . "/" . $page_suffix, "&laquo; " . ("previous"), "class\"prev left\"");
                        echo '</li>';
                    }
                }

                # trim the pagination, currently set to 20 for maximum
                # generate the links

                $trim = array();

                if ($last_page > 20) {

                    $a = 1;
                    $b = 4;

                    $c = $page_number - 4;
                    $d = $page_number;

                    $e = $page_number + 4;
                    $f = $last_page - 4;
                    $g = $last_page;

                    $trim[] = array($a, $b);
                    $trim[] = array($c, $d);
                    $trim[] = array($d, $e);
                    $trim[] = array($f, $g);
                } else {
                    $trim[] = array(1, $last_page);
                }

                $trim[] = array($last_page, $last_page + 1);

                # generate links

                $previous = 1;

                foreach ($trim as $x) {

                    $start = $x[0];
                    $end = $x[1];

                    if ($previous > $start)
                        $start = $previous;

                    if ($end < $start)
                        continue;

                    if ($end < $previous) {
                        continue;
                    }


                    if (($start - $previous) > 1) {
                        echo "<li><a href=#>...</a></li>";
                    }

                    for ($i = $start; $i < $end; $i++) {
                        if ($i > $last_page)
                            continue;
                        if ($page_number == $i) {
                            echo "<li class=\"active\">";
                            if ($is_get) {
                                echo anchor(build_link($page_prefix ,  "{$page_prefix}&page_number=" . $i . "&limit=" . $limit . "&max_results={$max_results}") , $i, "class='number current active'");
                            } else {
                                echo anchor($page_prefix . $i . "/" . $limit . "/" . $page_suffix, $i, "class='number active current'");
                            }
                            echo "</li>";
                        } else {
                            echo "<li>";
                            if ($is_get) {
                                echo anchor( build_link($page_prefix ,  "{$page_prefix}&page_number=" . $i . "&limit=" . $limit . "&max_results={$max_results}") , $i, "class='number'");
                            } else {
                                echo anchor($page_prefix . $i . "/" . $limit . "/" . $page_suffix, $i, "class='number'");
                            }
                            echo "</li>";
                        }
                    }

                    $previous = $end;
                }

                # generate last and next links
                if ($page_number != $last_page) {
                    if ($is_get) {
                        echo '<li>';
                        echo anchor(build_link($page_prefix , "{$page_prefix}&page_number=" . ($page_number + 1) . "&limit=" . $limit . "&max_results={$max_results}" ) , _t("next") . " &raquo;", "class\"next right\"");
                        echo '</li>';
                        echo '<li>';
                        echo anchor(build_link($page_prefix . "{$page_prefix}&page_number=" . ($last_page) . "&limit=" . $limit . "&max_results={$max_results}") , _t("last") . " &raquo;", "class\"last right\"");
                        echo '</li>';
                    } else {
                        echo '<li>';
                        echo anchor($page_prefix . ($page_number + 1) . "/" . $limit . "/" . $page_suffix, ("next") . " &raquo;", "class\"next right\"");
                        echo '</li>';
                        echo '<li>';
                        echo anchor($page_prefix . $last_page . "/" . $limit . "/" . $page_suffix, ("last") . " &raquo;", "class\"last right\"");
                        echo '</li>';
                    }
                }
            }
            echo "</ul></div>";
        }

is_ajax() function does not exist

function is_ajax() {
        if (!defined("REQUEST_AJAX")) {
            if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == "XMLHttpRequest") {
                define("REQUEST_AJAX", TRUE);
                return TRUE;
            } else {
                define("REQUEST_AJAX", FALSE);
                return FALSE;
            }
        } else {
            return REQUEST_AJAX;
        }
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.