acpmasquerade / framework-26 Goto Github PK
View Code? Open in Web Editor NEWAn ultra lightweight PHP framework
An ultra lightweight PHP framework
controllers/dashboard.php
Line 29
$where array is not passed as parameter
$announcements = Helper_Dashboard::get_announcements($where);
It would be better if the search function and user index function be merged together. And also the Template have the implementation of pagination in the user list.
framework-26 / templates / users / add.php
<option value="admin">User</option>
Lib/_Database.class.php Line No. 221
public function execute_query($query){
return $this->get_results($query);
}
helpers/pagination.php Line no. 215
echo "<li><span class=\"right\">Total <span class=\"badge badge-important\">{$max_results}</span></span></ul></div>";
return self::db()->update(DB::db_tbl_users, $data, $where);
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);
}
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!");
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}"), "« " . _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}") , "« " . _t("previous"), "class\"prev left\"");
echo '</li>';
} else {
echo '<li>';
echo anchor($page_prefix . "1/" . $limit . "/" . $page_suffix, "« " . ("first"), "class\"first left\"");
echo '</li>';
echo '<li>';
echo anchor($page_prefix . ($page_number - 1) . "/" . $limit . "/" . $page_suffix, "« " . ("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") . " »", "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") . " »", "class\"last right\"");
echo '</li>';
} else {
echo '<li>';
echo anchor($page_prefix . ($page_number + 1) . "/" . $limit . "/" . $page_suffix, ("next") . " »", "class\"next right\"");
echo '</li>';
echo '<li>';
echo anchor($page_prefix . $last_page . "/" . $limit . "/" . $page_suffix, ("last") . " »", "class\"last right\"");
echo '</li>';
}
}
}
echo "</ul></div>";
}
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;
}
}
function indexed_object_array($object_array, $index_param) {
$result_object_array = array();
foreach ($object_array as $some_key => $some_object) {
$index = $some_object->{$index_param};
$result_object_array["{$index}"] = $some_object;
}
return $result_object_array;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.