Jump to content

Andy_Kemp

Members
  • Posts

    21
  • Joined

  • Last visited

Posts posted by Andy_Kemp

  1. In Wordpress there is this code

    <?php $user_info = get_userdata(1);
          echo 'Username: ' . $user_info->user_login . "\n";
          echo 'User roles: ' . implode(', ', $user_info->roles) . "\n";
          echo 'User ID: ' . $user_info->ID . "\n";
    ?>
    

    My question is how they get this?

    $user_info->user_login 

    My code

    class Config {
    	
        private $db;
    	
        public function __construct($db) {
    		
            $this->db = $db;
    		
        }
    	
        public function get() {
    		
    	$query = 'SELECT * FROM config';
    	$select = $this->db->query($query);
    		
    	$config = array();
    	while ($row = $select->fetch(PDO::FETCH_OBJ)) {
    	    $config[$row->config] = $row->value;	
    	}
    		
    	return $config;
    		
        }
    	
    }
    
    $config = new Config($db);
    $conf = $config->get();
    print $conf['test'];
    

    Now i liked to do same way like wordpress

     

    Instead of this

    $conf['test'];
    

    i'd like to get result like this

    $conf->test;
    
  2.  

    Looks like you example was not meant to be implemented, but only to educate yourself, true?

     

    While print_r() is helpful to quickly view data, var_dump() gives you more information.  Try the following, you will will see what is going on

    $_get = array_merge($_get, $_GET); 
    var_dump($_get);

    Yes thats true

  3. <?php
    
    declare(strict_types = 1);
    
    function test(string $username, int $age, float $price) : array {
        return array('Username' => $username, 'Age' => $age, 'Price' => $price);
    }
    
    $_get = array(
        'username' => '',
        'age' => '',
        'price' => '',
    );
    
    $_get = array_merge($_get, $_GET); 
    
    print_r(test($_get['username'], $_get['age'], $_get['price']));
    

    I am new with php7

     

    So when i looked those examples i see test('test_username', 20, 20.01) but int and float are absolutely useless with $_POST, $_GET, Its always error. WITH int - must be of the type integer, string given. WITH float - must be of the type float, string given

  4. Whats the best method to determine who can access to admin panel?

    <?php
    
    if (!defined('Test_script')) {
        exit('You don\'t have right permission to access this file directly.');
    }
    
    if (!is_logged_in($ui)) {
        redirect_to('../index.php?do=login');
    }
    
    # By user role
    if (!user_has_role($db, $ui['id'], return_role_id($db, 'user'))) {
        redirect_to('../index.php?do=home');
    }
    # Or by permission
    if (!user_has_permission($db, $ui['id'], return_permission_id($db, 'admin_access'))) {
        redirect_to('../index.php?do=home');
    }
    
    /* ............................... */
    
    ?>
    
  5. Added role_id to user table

    + -- + -------- + --------- + --------------- + ------- + ---------- + ----------- +           + ------- + -------- +
    | id | username | password  | email           | last_ip | last_login | last_active | ......... | role_id | status   |
    + -- + -------- + --------- + --------------- + ------- + ---------- + ----------- +           + ------- + -------- +
    | 1  | user_1   | long_hash | email@email.com | ::1     | 0123456789 | 0123456789  | ......... | 1       | active   |
    + -- + -------- + --------- + --------------- + ------- + ---------- + ----------- +           + ------- + -------- +
    | 2  | user_2   | long_hash | email@email.com | ::1     | 0123456789 | 0123456789  | ......... | 2       | inactive |
    + -- + -------- + --------- + --------------- + ------- + ---------- + ----------- +           + ------- + -------- +
    

    Table name: role

    + -- + ----------- + ----------- + 
    | id | name        | description | 
    + -- + ----------- + ----------- + 
    | 1  | super_admin | Super Admin | 
    + -- + ----------- + ----------- + 
    | 2  | user        | User        | 
    + -- + ----------- + ----------- + 
    

    Table name: permission

    + -- + ----------- + ----------- + 
    | id | name        | description | 
    + -- + ----------- + ----------- + 
    | 1  | edit_news   | Edit News   | 
    + -- + ----------- + ----------- + 
    | 2  | manage_news | Manage News | 
    + -- + ----------- + ----------- + 
    

    Table name: role_permission

    + -- + -------- + ------------ + 
    | id | role_id | permission_id | 
    + -- + ------- + ------------- + 
    | 1  | 1       | 1             | 
    + -- + ------- + ------------- + 
    | 2  | 1       | 2             | 
    + -- + ------- + ------------- + 
    

    Do i need to add login page to user and admin side?

    I have no idea what to do next.

  6. Admin panel login. Am I doing it right?

    $query = 'SELECT a.id, a.username, b.password AS admin_password, b.status AS admin_status
    	  FROM user AS a
    	  INNER JOIN admin AS b
    	  ON a.id = b.user_id
    	  WHERE a.username = :username';
    

    Table name: user
    status - active, inactive, un-verified, suspended

    + -- + -------- + --------- + --------------- + ------- + ---------- + ----------- +           + -------- +
    | id | username | password  | email           | last_ip | last_login | last_active | ......... | status   |
    + -- + -------- + --------- + --------------- + ------- + ---------- + ----------- +           + -------- +
    | 1  | user_1   | long_hash | email@email.com | ::1     | 0123456789 | 0123456789  | ......... | active   |
    + -- + -------- + --------- + --------------- + ------- + ---------- + ----------- +           + -------- +
    | 2  | user_2   | long_hash | email@email.com | ::1     | 0123456789 | 0123456789  | ......... | inactive |
    + -- + -------- + --------- + --------------- + ------- + ---------- + ----------- +           + -------- +
    

    Table name: admin
    status - enabled, disabled

    + -- + -------- + --------- + ------- + ---------- + ----------- + -------- +
    | id | user_id  | password  | last_ip | last_login | last_active | status   |
    + -- + -------- + --------- + ------- + ---------- + ----------- + -------- +
    | 1  | 1        | long_hash | ::1     | 0123456789 | 0123456789  | enabled  |
    + -- + -------- + --------- + ------- + ---------- + ----------- + -------- +
    | 2  | 2        | long_hash | ::1     | 0123456789 | 0123456789  | disabled |
    + -- + -------- + --------- + ------- + ---------- + ----------- + -------- +
    
  7. Its fixed now. I dont know why but i need to recreate those files.

    require ROOT_DIR . 'includes/language_changer/a_panel/index.php'; This index.php
    require ROOT_DIR . 'includes/template_changer/a_panel/index.php'; This index.php
    require_once ROOT_DIR . 'languages/a_panel/' . $language . '/main/index.php'; This index.php
    
  8. Dont know what do do with this issue.

     

    Inside php

    <?php
    
    $smarty->display('test.tpl');
    
    ?>
    

    Output

    post-179814-0-94845800-1453987822_thumb.png

     

    When i put test.tpl content to test.html and open it to firefox. Then everything is ok.

  9. Where should i set setcookie() to remember what language is selected?

     

    includes/configs/a_panel/index.php

    <?php
    /* ---------------------------------- */
    require ROOT_DIR . 'includes/language_changer/a_panel/index.php';
    
    if (is_file(ROOT_DIR . 'languages/a_panel/'.Language::get_language($db, $config).'/main/index.php') && file_exists(ROOT_DIR . 'languages/a_panel/'.Language::get_language($db, $config).'/main/index.php')) {
        $language = Language::get_language($db, $config);
        $charset = Language::get_charset($db, $language);
        require_once(ROOT_DIR . 'languages/a_panel/'.$language.'/main/index.php');
    }
    
    else {
        $language = 'en';
        $charset = 'utf-8';
        require_once(ROOT_DIR . 'languages/a_panel/'.$language.'/main/index.php');
    }
    /* ---------------------------------- */
    
    $smarty->assign('db', $db);
    $smarty->assign('config', $config);
    $smarty->assign('ui', $ui);
    $smarty->assign('lang', $lang);
    $smarty->assign('language', $language);
    $smarty->assign('charset', $charset);
    ?>
    

    includes/language_changer/a_panel/index.php

    <?php
    
    class Language {
    	
        public static function get_language($db, $config) {
    		
    	if ($config['ap_allow_language_changing'] === 'true') {
    	
    	    if (isset($_GET['language']) && self::is_language_supported($db, $config, $_GET['language'])) {
    	        return $_GET['language'];
    	    }
    	
    	    else if (isset($_COOKIE['admin_language']) && self::is_language_supported($db, $config, $_COOKIE['admin_language'])) {
    		return $_COOKIE['admin_language'];
    	    }
    		
    	}
    	
    	return $config['ap_default_language'];
    		
        }
    	
        private static function is_language_supported($db, $config, $language) {
    		
    	$query = 'SELECT folder_name AS lang_code FROM language WHERE panel = "a_panel" AND version = :version';
    	$select = $db->prepare($query);
    	$select->bindParam(':version', $config['script_version'], PDO::PARAM_STR);
    	$select->execute();
    	
    	$supported_languages = array();
    	while($row = $select->fetch(PDO::FETCH_ASSOC)){
       	    $supported_languages[] = $row['lang_code'];
            }
    	
    	if (in_array($language, $supported_languages)) {
    	    return true;
    	}
    	
    	return false;
    		
        }
    	
        public static function get_charset($db, $language) {
    		
    	$query = 'SELECT charset FROM language WHERE panel = "a_panel" AND folder_name = :language';
    	$select = $db->prepare($query);
    	$select->bindParam(':language', $language, PDO::PARAM_STR);
    	$select->execute();
    	$row = $select->fetch(PDO::FETCH_ASSOC);
    		
    	return $row['charset'];
    		
        }
    	
    }
    
    ?>
    
  10. I dont know if its right way to do this. If you would do it in a different way pleas let me know.

     

    Create unix timestamp with admin selected timezone else use server default timezone.

    function create_timestamp($config) {
    	
        $time_zone = ($config['site_time_zone'] === 'default') ? date_default_timezone_get() : $config['site_time_zone'];
        $date = date_create(NULL, timezone_open($time_zone));
        return date_timestamp_get($date);
    
    }
    

    Format unix timestamp to user selected timezone and date format else use default timezone and date format.

    function format_timestamp($config, $ui, $timestamp) {
    	
        $time_zone = (is_logged_in($ui) && $ui['time_zone'] !== 'default') ? $ui['time_zone'] : date_default_timezone_get();
        $date_format = (is_logged_in($ui) && $ui['date_format'] !== 'default') ? $ui['date_format'] : $config['default_date_format']; 
        $date = date_create('@'.$timestamp);
        date_timezone_set($date, timezone_open($time_zone));
        return date_format($date, $date_format);
    	
    }
    

    Add interval to unix timestamp.

    function add_interval_timestamp($config, $interval, $timestamp = NULL) {
    	
        $timestamp = ($timestamp === NULL) ? NULL : '@'.$timestamp;
        $time_zone = ($config['site_time_zone'] === 'default') ? date_default_timezone_get() : $config['site_time_zone'];
        $date = date_create($timestamp, timezone_open($time_zone));
        date_add($date, date_interval_create_from_date_string($interval));
        return date_timestamp_get($date);
    	
    }
    

    Substract interval from unix timestamp.

    function sub_interval_timestamp($config, $interval, $timestamp = NULL) {
    	
        $timestamp = ($timestamp === NULL) ? NULL : '@'.$timestamp;
        $time_zone = ($config['site_time_zone'] === 'default') ? date_default_timezone_get() : $config['site_time_zone'];
        $date = date_create($timestamp, timezone_open($time_zone));
        date_sub($date, date_interval_create_from_date_string($interval));
        return date_timestamp_get($date);
    	
    }
    
  11. You don't need any of this. When the script is terminated, PHP automatically closes the connection and frees all memory.

     

    By the way, you should move the prepare() call before the foreach loop. Prepared statements can be reused (that's pretty much the whole point), so you should create it once and then use it for every configuration item.

    You mean something like this

    $query = 'UPDATE config SET value = :value WHERE config = :key';
    $update = $db->prepare($query);
    $update->bindParam(':value', $value, PDO::PARAM_STR);
    $update->bindParam(':key', $key, PDO::PARAM_STR);
    	
    foreach($post as $key => $value) {
    		
        $value = $value;
        $key = $key;
        $bool = $update->execute();
    		
    }	
    
  12. TABLE NAME config 
    id = INT(11), config = varchar(255), value = varchar(255)
    +----------+--------------------------------+----------------------------------+
    |    id    |	config	                    |	value	                       |
    +----------+--------------------------------+----------------------------------+
    | 1        | captcha_type  	            | disabled                         | # disabled, recaptcha_version_2, solvemedia 
    +----------+--------------------------------+----------------------------------+
    | 2        | captcha_login  	            | true	                       | # false, true
    +----------+--------------------------------+----------------------------------+
    | 3        | captcha_pass_recovery  	    | true	                       | # false, true
    +----------+--------------------------------+----------------------------------+
    | 4        | captcha_reset_pass  	    | false	                       | # false, true
    +----------+--------------------------------+----------------------------------+
    | 5        | recaptcha_version_2_site_key   | K7ERoXZln9UvnD.NaOksQEDlfkRWMlYz |
    +----------+--------------------------------+----------------------------------+
    | 6        | recaptcha_version_2_secret_key | K7ERoXZln9UvnD.NaOksQEDlfkRWMlYz |
    +----------+--------------------------------+----------------------------------+
    | 7        | recaptcha_version_2_type  	    | image	                       | # audio, image
    +----------+--------------------------------+----------------------------------+
    | 8        | recaptcha_version_2_theme      | light	                       | # dark, light
    +----------+--------------------------------+----------------------------------+
    | 9        | recaptcha_version_2_size  	    | normal	                       | # compact, normal
    +----------+--------------------------------+----------------------------------+
    | 10       | solvemedia_public_key          | K7ERoXZln9UvnD.NaOksQEDlfkRWMlYz |
    +----------+--------------------------------+----------------------------------+
    | 11       | solvemedia_private_key  	    | K7ERoXZln9UvnD.NaOksQEDlfkRWMlYz |
    +----------+--------------------------------+----------------------------------+
    | 12       | solvemedia_hash_key            | K7ERoXZln9UvnD.NaOksQEDlfkRWMlYz |
    +----------+--------------------------------+----------------------------------+
    | 13       | site_name                      | Testing site name                |
    +----------+--------------------------------+----------------------------------+
    | 14       | site_title                     | Testing site title               |
    +----------+--------------------------------+----------------------------------+
    | 15       | site_description               |                                  |
    +----------+--------------------------------+----------------------------------+
    | 16       | site_keywords                  |                                  |
    +----------+--------------------------------+----------------------------------+
    | 17       | site_url                       | www.testingsite.com/test         |
    +----------+--------------------------------+----------------------------------+
    

    .....................................................................................................................................................................

  13. Changed this block

    $defs = array(
        'captcha_type' => FILTER_SANITIZE_STRING,
        'captcha_login' => FILTER_DEFAULT,
        'captcha_pass_recovery' => FILTER_DEFAULT,
        'captcha_reset_pass' => FILTER_DEFAULT
    );
    	
    $post = filter_input_array(INPUT_POST, $defs);
    

    to

    $post = array(
        'captcha_type' => $_POST['captcha_type'],
        'captcha_login' => isset($_POST['captcha_login']) ? 'true' : 'false',
        'captcha_pass_recovery' => isset($_POST['captcha_pass_recovery']) ? 'true' : 'false',
        'captcha_reset_pass' => isset($_POST['captcha_reset_pass']) ? 'true' : 'false'
    );
    

    Now i have another question. When is right time to close db connection?

    Do i really need all of this at the end of page?

    $db = NULL;	
    $config = NULL;
    $ui = NULL;
    $lang = NULL;
    
  14. How to do it? If checkbox is checked insert "yes" to db else "no". And what else should i change in this code?

    <?php
    
    if(!defined('test_project')) {
    	die('Hacking attempt ...');
    }
    
    if(!logged_in($ui)) {
    	redirect_to('index.php?do=login');	
    }
    
    $errors = array();
    $alert = NULL;
    
    // Form is not submitted display db values.
    $post = array(
    	'captcha_type' => $config['captcha_type'],
    	'captcha_login' => $config['captcha_login'],
    	'captcha_pass_recovery' => $config['captcha_pass_recovery'],
    	'captcha_reset_pass' => $config['captcha_reset_pass']
    );
    
    if(filter_has_var(INPUT_POST, 'submit_form')) {
    	
    	$defs = array(
    		'captcha_type' => FILTER_SANITIZE_STRING,
    		'captcha_login'	=> FILTER_DEFAULT,
    		'captcha_pass_recovery' => FILTER_DEFAULT,
    		'captcha_reset_pass' => FILTER_DEFAULT
    	);
    	
    	$post = filter_input_array(INPUT_POST, $defs);
    	
    	if(demo_version($config)) {
    		$errors[] = $lang['error']['h_0000'];
    	}
    	
    	else {
    		
    		if(!NoCSRF::valid_token($lang, 'csrf_token', $_POST)) {
    			$errors[] = NoCSRF::get_error();
    		}
    		
    		else {
    			
    			if(!user_has_permission($db, $ui, 'edit_captcha_settings')) {
    				$errors[] = $lang['error']['h_0001'];
    			}
    			
    		}
    		
    	}
    			
    }
    
    if(filter_has_var(INPUT_POST, 'submit_form') && empty($errors)) {
    	
    	foreach($post as $key => $value) {
    		
    		$query = 'UPDATE config SET value = :value WHERE config = :key';
      		$update = $db->prepare($query);
    		$update->bindParam(':value', $value, PDO::PARAM_STR);
    		$update->bindParam(':key', $key, PDO::PARAM_STR);
    		$bool = $update->execute();
    		
    	}
    	
    	if($bool) {
    		$alert = array('type' => 'success', 'message' => $lang['success']['h_0000']);
    	}
    	
    	else {
    		$alert = array('type' => 'error', 'message' => $lang['error']['h_0000']);
    	}
    	
    }
    
    $smarty->assign('post', $post);
    $smarty->assign('errors', $errors);
    $smarty->assign('alert', $alert);
    $smarty->assign('csrf_token', NoCSRF::generate('csrf_token'));
    $smarty->display('captcha_settings.tpl');
    
    $db = NULL;	
    $config = NULL;
    $ui = NULL;
    $lang = NULL;
    
    ?>
    
    <input type="checkbox" name="captcha_login" value="1">Captcha login page enabled<br>
    <input type="checkbox" name="captcha_pass_recovery" value="1">Captcha password recovery page enabled<br> 
    <input type="checkbox" name="captcha_reset_pass" value="1">Captcha reset password page enabled
    
  15. Paginator shows page links even there is no data.
    30li5op.png
     

    Paginator Class

    <?php
    
    // ==================================================================
    	//  Author: Ted Kappes (pesoto74@soltec.net)
    	//	Web: 	http://tkap.org/paginator/
    	//	Name: 	Paginator
    	// 	Desc: 	Class to help make pagination more easy.
    	//
    	// 7/21/2003
    	//
    	//  Please send me a mail telling me what you think of Paginator
    	//  and what your using it for. [ pesoto74@soltec.net]
    	//
    // ==================================================================
    class Paginator {
    				//all variables are pivate.
    					var $previous;	
    					var $current;
    					var $next;
    					var $page;
    					var $total_pages;
    					var $link_arr;
    					var $range1;
    					var $range2;
    					var $num_rows;
    					var $first;
    					var $last;
    					var $first_of;
    					var $second_of;
    					var $limit;
    					var $prev_next;
    					var $base_page_num;
    					var $extra_page_num;
    					var $total_items;
    					var $pagename;
    			//Constructor for Paginator.  Takes the current page and the number of items
    			//in the source data and sets the current page ($this->page) and the total
    			//items in the source ($this->total_items).
    			function Paginator($page,$num_rows) 
    			{ 
    			    if(!$page)
    					{
    			    $this->page=1;
    					} else {
    				  $this->page=$page;
    				  }
    				  $this->num_rows=$num_rows;
    					$this->total_items = $this->num_rows;
    			}
    			//Takes  $limit and sets $this->limit. Calls private mehods
    			//setBasePage() and setExtraPage() which use $this->limit.
    			function set_Limit($limit=5)
    			{
    			    $this->limit = $limit;
    					$this->setBasePage();
    					$this->setExtraPage();
    			}
    			//This method creates a number that setExtraPage() uses to if there are
    			//and extra pages after limit has divided the total number of pages.
    			function setBasePage()
    			{
    			    $div=$this->num_rows/$this->limit;	
    				  $this->base_page_num=floor($div);
    			}
    			function setExtraPage()
    			{
    				  $this->extra_page_num=$this->num_rows - ($this->base_page_num*$this->limit);
    			}
    			//Used in making numbered links.  Sets the number of links behind and 
    			//ahead of the current page.  For example if there were a possiblity of
    			//20 numbered links and this was set to 5 and the current link was 10
    			//the result would be this 5 6 7 8 9 10 11 12 13 14 15.
    			
    			function set_Links($prev_next=5)
    			{
    			    $this->prev_next = $prev_next;
    			}
    			//method to get the total items.
    			function getTotalItems()
    			{
    			$this->total_items = $this->num_rows;
    			return $this->total_items;
    			}
    			//method to get the base number to use in queries and such.
    			function getRange1()
    			{
    			    $this->range1=($this->limit*$this->page)-$this->limit;	
    			    return $this->range1;
    			}
    			//method to get the offset.
    			function getRange2()
    			{
    			    if($this->page==$this->base_page_num + 1)
     	        {
    	        $this->range2=$this->extra_page_num;
    				  } else { $this->range2=$this->limit;
    					}
    				  return $this->range2;
    			}
    			//method to get the first of number as in 5 of .
    			function getFirstOf()
    			{
    			    $this->first_of=$this->range1 + 1;
    			    return $this->first_of;
    			}
    			//method to get the second number in a series as in 5 of 8.
    			function getSecondOf()
    			{
    			    if($this->page==$this->base_page_num + 1)
     	        {
    				  $this->second_of=$this->range1 + $this->extra_page_num;
    				  } else { $this->second_of=$this->range1 + $this->limit;
    					       }
    				  return $this->second_of;
    			}
    			//method to get the total number of pages.
    			function getTotalPages()
    			{
    			    if($this->extra_page_num)
    					{
    					$this->total_pages = $this->base_page_num + 1;
    					} else {
    				  $this->total_pages = $this->base_page_num;
    					       }
    					return $this->total_pages;
    			}
    			//method to get the first link number.
    			function getFirst()
    			{
    			    $this->first=1;
    			    return $this->first;
    			}
    			//method to get the last link number.
    			function getLast()
    			{
    			    if($this->page == $this->total_pages)
    					{
    					$this->last=0;
    					}else { $this->last = $this->total_pages;
    					      }
    					return $this->last;  
    			}
    			function getPrevious()
    			{
    			    if($this->page > 1)
    	        {
    	        $this->previous = $this->page - 1;
    	        }
    					return $this->previous;
    			}
    			//method to get the number of the link previous to the current link.
    			function getCurrent()
    			{
    			    $this->current = $this->page;
    					return $this->current;
    			}
    			//method to get the current page name. Is mostly used in links to the next 
    			//page.
    			function getPageName()
    			{
    			    $this->pagename = $_SERVER['PHP_SELF'];;
    					return $this->pagename;
    			}
    			//method to get the number of the link after the current link.
    			function getNext()
    			{   
    			    $this->getTotalPages();
    			    if($this->total_pages != $this->page)
    				  {
    				  $this->next = $this->page + 1;
    				  }
    					return $this->next;
    			}
    			//method that returns an array of the numbered links that should be 
    			//displayed.   
    			function getLinkArr()
          {
           //gets the top range   
           $top = $this->getTotalPages()- $this->getCurrent();
           if($top <= $this->prev_next)
             {
             $top = $top;
    	       $top_range = $this->getCurrent() + $top;
    	       } else { $top = $this->prev_next; $top_range = $this->getCurrent() + $top; }
    				 
    				//gets the bottom range
    	     $bottom = $this->getCurrent() -1;
           if($bottom <= $this->prev_next)
    	       {
    	       $bottom = $bottom;
    	       $bottom_range = $this->getCurrent() - $bottom;
    	       } else { $bottom = $this->prev_next; $bottom_range = $this->getCurrent() - $bottom; } 
    	 
    	       $j=0;
           foreach(range($bottom_range, $top_range) as $i)
    	       {
    	       $this->link_arr[$j] = $i;
    		     $j++;
    		     }
    		   return $this->link_arr;
          }
    			
    	}//ends Paginator class
    	?>	
    

    Paginator html

    <?php 
    // ==================================================================
    	//  Author: Ted Kappes (pesoto74@soltec.net)
    	//	Web: 	http://tkap.org/paginator/
    	//	Name: 	Paginator_html
    	// 	Desc: 	Class extension for Paginator. Adds pre-made link sets.
    	//
    	// 7/21/2003
    	//
    	//  Please send me a mail telling me what you think of Paginator
    	//  and what your using it for. [ pesoto74@soltec.net]
    	//
    // ==================================================================
          
    			class Paginator_html extends Paginator { 
    			
    			  //outputs a link set like this 1 of 4 of 25 First | Prev | Next | Last |              
    				function firstLast()
    			  {				
    					 if($this->getCurrent()==1)
    		         {
    		         $first = "First | ";
    		         } else { $first="<a href=\"" .  $this->getPageName() . "?page=" . $this->getFirst() . "\">First</a> |"; }  
    		       if($this->getPrevious())
    		         {
    		         $prev = "<a href=\"" .  $this->getPageName() . "?page=" . $this->getPrevious() . "\">Prev</a> | ";
    		         } else { $prev="Prev | "; }
    		
    	         if($this->getNext())
    		         {
    		         $next = "<a href=\"" . $this->getPageName() . "?page=" . $this->getNext() . "\">Next</a> | ";
    		         } else { $next="Next | "; }
    		
    		
    		       if($this->getLast())
    		         {
    		         $last = "<a href=\"" . $this->getPageName() . "?page=" . $this->getLast() . "\">Last</a> | ";
    		         } else { $last="Last | "; }
    		         echo $this->getFirstOf() . " of " .$this->getSecondOf() . " of " . $this->getTotalItems() . " ";
    		         echo $first . " " . $prev . " " . $next . " " . $last;
    				} 
    				//outputs a link set like this Previous 1 2 3 4 5 6 Next   
    				function previousNext()
    				{
    					if($this->getPrevious())
    		        {
    		        echo "<a href=\"" . $this->getPageName() . "?page=" . $this->getPrevious() . "\">Previous</a> ";
    		        }
    						$links = $this->getLinkArr();
    		      foreach($links as $link)
    	          {
    	          if($link == $this->getCurrent())
    					    {
    					     echo " $link ";
    					    } else { echo "<a href=\"" . $this->getPageName() . "?page=$link\">" . $link . "</a> ";
    					    }
    		          } 
    						if($this->getNext())
    		          {
    		          echo "<a href=\"" . $this->getPageName() . "?page=" . $this->getNext() . "\">Next</a> ";
    		          }
    		        }  
    	}//ends class
    
    
             ?>
    				 
    

    Example page

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <html>
    <head>
    <title>Example 2</title>
    <style type="text/css">
    <!-- 
    body { margin-top: 20px;
    			 margin-left: 150px;
    			 margin-right: 150px;
    			 background-color: #FFFF99; 
    			 font-family: Verdana;
     } 
    h1 { font-size: 150%;
     }
    -->
    </style>
    </head>
    <center>
    <body>
    <h1>Example 2</h1>
    <?php
      //=================================================================================
    	//This shows how to set things up to get your input from an array.  This could be
    	//used to make an image gallery or to display anything else you might store in
    	//an array. This page uses  Paginator_html for the pre-made links.  The results
    	//are pretty basic.  You should be able to use something like CSS to customize these
    	//for you own site. This page uses the previousNext() method. 
    	//==================================================================================
      //include the main class
    	include("include/paginator.php");
    	//include the extension that makes the pre-made links
    	include("include/paginator_html.php");
    	//Makes the array used in this example.
    		for($i=0; $i < 0; $i++)
    			{
    			$p=$i+1;
    			$pictures[$i]="pict" . $p . ".jpg";
    			}
    		//gets the total number of items
        $num_rows = count($pictures);
    		//========================================================================
    		//Parts used to make a new paginator 
    		//========================================================================
    		//Makes new Paginator_html.  Current page here is sent by the get method. 
    		//$num_rows is the total items in the source.
        $a =& new Paginator_html($_GET['page'],$num_rows);
        //sets the number of records displayed
    		//defaults to five
    		$a->set_Limit(4); 
    		// if using numbered links this will set the number before and behind 
    		//the current page.
    		//defaults to five
    		$a->set_Links(3);  
    		//gets starting point.
    		$limit1 = $a->getRange1();  
    		//gets number of items displayed on page.
    		$limit2 = $a->getRange2();  
    		//=========================================================================
    		//Printing out the items in the array
    		for($j=$limit1; $j < $limit1 + $limit2; $j++)
    			{
    			echo "<strong>" . $pictures[$j] . "</strong></p>";
    			}
    		//=========================================================
    		//Put this where you want your links to appear
    			$a->previousNext();
    		//=========================================================
    			//uncomment for some info that may be helpful in debugging.
    			//echo '<pre>'; print_r($a); echo '</pre>';
    ?>
    </center>
    <p>This is an example of one of the pre-made set of links. It uses the Paginator
    class and the Paginator_html extension class. I use an array here to show that you 
    can use this class with sources other then a database. Also I did this so you could
    get an idea of how this works without having to go to the trouble of setting up a
    database. This output is fairly plain which should make it easier to use something like
    CSS to fit it into the look of your own site.
    </p>
    <p>
    Check the source code of this page to see how to set something like this up.</p>
    <a href="index.php">Back to Index</a>
    </body>
    </html>
    
    

    Url For paginator files http://www.phpclasses.org/package/1239-PHP-Spliting-database-query-result-sets-between-pages-.html

  16. Site Structure

    htdocs/ or www/ or public_html/
        |
        | ==> frontend/
        | 	    |
        |       | ==> pages/
        |       | ==> templates/
        |       | ==> templates_c/
        |       | ==> index.php
        |           
        | ==> backend/
        | 	    |
        |       | ==> pages/
        |       | ==> templates/
        |       | ==> templates_c/
        |       | ==> index.php
        |
        | ==> ajax/   
        | ==> cron/
        | ==> files/
        | ==> includes/
        | ==> install/
        | ==> languages/
        | ==> .htaccess
    

    I want to access frontend directory when url is www.site.com not www.site.com/frontend

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.