~vcs-imports/almidon/trunk

« back to all changes in this revision

Viewing changes to core/pub/default.php

  • Committer: christian
  • Date: 2010-09-11 20:55:52 UTC
  • Revision ID: svn-v4:924a4236-293c-0410-b38f-c0813de1d4fd:trunk:381
Change name to pub directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * default.php
 
4
 *
 
5
 * rewrite magic: para generar pagina publica automaticamente (via mod_rewrite)
 
6
 * FIXME: magic is messy and not so useful. use objects! gallery.picasa.php...
 
7
 *
 
8
 * @copyright &copy; 2005-2008 Guegue Comunicaciones - guegue.com
 
9
 * @license http://opensource.org/licenses/gpl-3.0.html GNU Public License
 
10
 * @version $Id: default.php,v 2008032801 javier $
 
11
 * @package almidon
 
12
 */
 
13
 
 
14
require($_SERVER['DOCUMENT_ROOT'] . '/../classes/app.class.php');
 
15
 
 
16
# lee parametros, obj nunca esta vacio, tpl y php son opcionales
 
17
#$params = explode("/", $_SERVER['REQUEST_URI']);
 
18
if (isset($_GET['obj'])) $obj = strtolower(preg_replace("/[^A-Za-z0-9_]/", "", $_GET['obj']));
 
19
if (isset($_GET['id'])) $id = strtolower(preg_replace("/[^A-Za-z0-9_]/", "", $_GET['id']));
 
20
if (isset($_GET['tpl'])) $tpl = strtolower(preg_replace("/[^A-Za-z0-9_]/", "", $_GET['tpl']));
 
21
if (isset($_GET['php'])) $php = strtolower(preg_replace("/[^A-Za-z0-9_]/", "", $_GET['php']));
 
22
if (!empty($tpl)) $tpl = $smarty->template_dir.$tpl;
 
23
if (!empty($php)) $php = ROOTDIR.$php;
 
24
#if (!empty($obj)) $obj = $obj;
 
25
 
 
26
# intenta leer registro de pagina
 
27
$pagina = (defined('PAGINA')) ? PAGINA : 'pagina';
 
28
 
 
29
# si no hay objeto, es portada
 
30
if (empty($obj) || ($obj == 'defaultphp')) {
 
31
  if (file_exists('portada.php')) {
 
32
    require('portada.php');
 
33
  } else {
 
34
    $idpagina = (defined('IDPAGINA')) ? IDPAGINA : 'portada';
 
35
  }
 
36
}
 
37
$object = $obj.'Table';
 
38
if (!class_exists($object)) {
 
39
  $pagina_object = $pagina.'Table';
 
40
  if (class_exists($pagina_object)) {
 
41
    $pagina_data = new $pagina_object;
 
42
    if (!isset($idpagina)) $idpagina = $obj;
 
43
    $row = $pagina_data->readRecord($idpagina);
 
44
    if ($row) {
 
45
      $smarty->assign('row', $row);
 
46
      if (file_exists($smarty->template_dir . $idpagina . '.tpl'))
 
47
      $tpl = $idpagina . '.tpl';
 
48
    } else {
 
49
      error_log("FIXME: que hacer?");
 
50
    }
 
51
  }
 
52
}
 
53
 
 
54
# especificar el tpl
 
55
#if (empty($tpl)) $tpl = $php.'.tpl';
 
56
if (empty($tpl)) $tpl = $obj.'.tpl';
 
57
if (!file_exists($smarty->template_dir . $tpl))
 
58
  $tpl = ALMIDONDIR.'/tpl/default.tpl';
 
59
 
 
60
# cargar archivo extra php
 
61
if (empty($php)) $php = $obj.'.php';
 
62
if (file_exists($php))
 
63
  require($php);
 
64
 
 
65
# carga archivo extra si existe
 
66
if (file_exists('include.php'))
 
67
  require('include.php');
 
68
 
 
69
# carga el objeto: lee datos o dato
 
70
$object = $obj.'Table';
 
71
if (!empty($obj) && class_exists($object)) {
 
72
  $data = new $object;
 
73
  if (!empty($data->template))
 
74
    $tpl = $data->template;
 
75
  $rows = $data->readData();
 
76
 
 
77
  # si hay parametros, interpretarlos, ver detalle
 
78
  $data->readEnv();
 
79
  if (isset($data->request[$data->key]))
 
80
    $row = $data->readRecord();
 
81
 
 
82
  # si es galeria, carga fotos
 
83
  if ($obj == 'galeria' && !empty($row)) {
 
84
    $foto = new fotoTable();
 
85
    $fotos = $foto->readDataFilter("foto.idgaleria='".$row['idgaleria']."'");
 
86
    $smarty->assign('fotos', $fotos);
 
87
    $smarty->assign('galeria', $obj);
 
88
  }
 
89
 
 
90
  # si es foto de galeria, carga foto y galeria
 
91
  if ($obj == 'foto' && !empty($row)) {
 
92
    $fotos = $data->readDataFilter("foto.idgaleria='".$row['idgaleria']."'");
 
93
    $smarty->assign('fotos', $fotos);
 
94
    $smarty->assign('imagen', $row);
 
95
    $data = new galeriaTable();
 
96
    $row = $data->readRecord($row['idgaleria']);
 
97
    $obj = 'galeria';
 
98
  }
 
99
 
 
100
  # solo pone titulo si el objeto no es tipo "pagina"
 
101
  if ($obj != $pagina)
 
102
    $smarty->assign('title', $data->title);
 
103
 
 
104
  $smarty->assign('key', $data->key);
 
105
  $data->destroy();
 
106
 
 
107
  # finalmente asigna row
 
108
  if (isset($row))
 
109
    $smarty->assign('row', $row);
 
110
 
 
111
  # tabla con fotos y su key
 
112
  $smarty->assign('foto', 'foto');
 
113
  $smarty->assign('idfoto', 'idfoto');
 
114
}
 
115
 
 
116
# asgina variables a smarty
 
117
$smarty->assign('obj', $obj);
 
118
if (isset($rows)) $smarty->assign('rows', $rows);
 
119
 
 
120
# especifica display
 
121
$smarty->display($tpl);