Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1.  
  2. <?php
  3. // Need to add those functions in a common functions.php file
  4. function unparse_url($parsed_url) {
  5. $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
  6. $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
  7. $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
  8. $user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
  9. $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
  10. $pass = ($user || $pass) ? "$pass@" : '';
  11. $path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
  12. $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
  13. $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
  14. return "$scheme$user$pass$host$port$path$query$fragment";
  15. }
  16.  
  17.  
  18. // Because if URL already is Page URL (?page=), Need to remove page param from URL
  19. function removeQueryParam($url, $param_to_remove) {
  20. $parsed = parse_url($url);
  21. if ($parsed && isset($parsed['query'])) {
  22. $parsed['query'] = implode('&', array_filter(explode('&', $parsed['query']), function($param) use ($param_to_remove) {
  23. return explode('=', $param)[0] !== $param_to_remove;
  24. }));
  25. if ($parsed['query'] === '') unset($parsed['query']);
  26. return unparse_url($parsed);
  27. } else {
  28. return $url;
  29. }
  30. }
  31.  
  32. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  33. $url = removeQueryParam($actual_link,'page');
  34. preg_match("/[^\/]+$/", $url, $matches);
  35. $last_word = $matches[0];
  36.  
  37. $total_count = getTotalCount($sql_sub);
  38.  
  39. $display_list_limit = $view_count;
  40. $offset = ($page - 1) * $display_list_limit;
  41.  
  42. // This way, We don't need to HARDCODE pages name it done dynamically
  43. pageing_link_build2($last_word);
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement