Skip to content

Instantly share code, notes, and snippets.

@focux
Created January 19, 2013 20:25
Show Gist options
  • Save focux/4574861 to your computer and use it in GitHub Desktop.
Save focux/4574861 to your computer and use it in GitHub Desktop.

Revisions

  1. focux created this gist Jan 19, 2013.
    67 changes: 67 additions & 0 deletions File Upload
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,67 @@
    <?PHP
    class paginar {
    private $text;
    private $configure = '1-2'; # 0 = Parrafos 1 = Oraciones 1-X = X numeros de oraciones 1-X = X numeros de parrafos
    private $error;
    private $actually;
    private $separator;
    public function __construct($text, $configure) {
    $this->text = htmlentities($text);
    $this->actually = (isset($_GET['page']) ? (is_numeric($_GET['page']) ? stripslashes($_GET['page']) : 0) : 0);
    $this->separator = (reset(explode('-', $this->configure)) == 1 ? '.' : (next(explode('-', $this->configure)) == 0 ? '
    ' : NULL));
    }
    public function paginarTexto() {
    if (strlen($this->text) < 20) {
    echo $this->error = 20035;
    } else {
    if (!preg_match("/^[\d]{1}-[\d]{1}/i", $this->configure)) {
    echo $this->error = 45081;
    } else {
    $numeros = explode('-', $this->configure);
    $paginar = explode($this->separator, $this->text);
    for ($i = $this->actually;$i < $this->actually + $numeros[1];$i++) {
    echo $paginar[$i] . $this->separator;
    }
    }
    }
    }
    public function showPages() {
    $numeros = explode('-', $this->configure);
    for ($i = 0;$i < count(explode($this->separator, $this->text)) / $numeros[1];$i++) {
    echo '<a href="'.$_SERVER['PHP_SELF'].'?page=' . $i . '">' . ($_GET['page'] == $i ? '<strong>[' . $i . ']</strong>' : '[' . $i . ']') . '</a> ';
    }
    }
    public function showError($int) { # 0 = Mostrar numero de error, 1 = Mostrar el error (para el modo depurador)
    if (!is_numeric($int)) {
    $this->error = 45647;
    } else {
    if ($int == 0) {
    switch ($this->error) {
    case 20035:
    echo 'El texto no puede ser menor a los 20 caracteres';
    break;
    case 45081:
    echo 'La configuracion del paginador debe cumplir con el patron asignado';
    break;
    case 45647:
    echo 'El nivel de error debe ser especificado con los parametros permitidos.';
    break;
    }
    } elseif ($int == 1) {
    switch ($this->error) {
    case 20035:
    echo 20035;
    break;
    case 45081:
    echo 45081;
    break;
    case 45647:
    echo 45647;
    break;
    }
    }
    }
    }
    }
    ?>