00001 <?php
00011 class sefAdminControllers extends aliroComponentAdminControllers {
00012 protected $database = null;
00013 protected $underscore = 0;
00014 protected $enabled = 1;
00015 protected $strip_chars = '';
00016 protected $lower_case = '0';
00017 protected $unique_id = '0';
00018 protected $use_cache = '0';
00019 protected $cache_time = '600';
00020 protected $buffer_size = '100';
00021 protected $log_transform = '0';
00022 protected $default_robots = 'index, follow';
00023 protected $home_title = 'Home';
00024 protected $title_separator = '|';
00025 protected $custom_code = array();
00026 protected $cutom_name = array();
00027 protected $sef_content_task = array();
00028 protected $sef_name_chars = array();
00029 protected $sef_translate_chars = array();
00030 protected $component_details = array();
00031 protected $sef_substitutions_exact = array();
00032 protected $sef_substitutions_exact_name = array();
00033 protected $sef_substitutions_exact_mod = array();
00034 protected $sef_substitutions_in = array();
00035 protected $sef_substitutions_out = array();
00036 protected $filters = array();
00037 protected $limit = 20;
00038 protected $limitstart = 0;
00039
00040 public $ignoreMagicQuotes = 1;
00041
00042 protected function __construct ($manager) {
00043 parent::__construct($manager);
00044 $this->database = aliroDatabase::getInstance();
00045 }
00046
00047 }
00048
00049 class sefAdminSef extends sefAdminControllers {
00050 protected static $instance = __CLASS__;
00051
00052 protected $view_class = 'sefAdminHTML';
00053
00054 public static function getInstance ($manager) {
00055 return is_object(self::$instance) ? self::$instance : (self::$instance = new self::$instance($manager));
00056 }
00057
00058 public function getRequestData () {
00059 }
00060
00061 public static function taskTranslator () {
00062 return array (
00063 'save' => T_('Save'),
00064 'listmeta' => T_('List Metadata'),
00065 'listuri' => T_('List URIs'),
00066 'list' => T_('Cancel'),
00067 'savecomponent' => T_('Save Codes')
00068 );
00069 }
00070
00071 public function toolbar () {
00072 $task = $this->getParam($_REQUEST, 'task');
00073 if ('component' == $task) {
00074 $this->toolBarButton('savecomponent');
00075 $this->toolBarButton('list');
00076 }
00077 else {
00078 $this->toolBarButton('save');
00079 $this->toolBarButton('listuri');
00080 $this->toolBarButton('listmeta');
00081 }
00082 }
00083
00084 public function listuriTask () {
00085 $this->redirect('index.php?core=cor_sef&act=uri');
00086 }
00087
00088 public function listmetaTask () {
00089 $this->redirect('index.php?core=cor_sef&act=metadata');
00090 }
00091
00092 public function listTask () {
00093 $view = new $this->view_class($this);
00094 echo $view->sefNotes();
00095 $this->getData();
00096 echo "\n<div id='remosefadmin'>";
00097 $this->showOptions();
00098 $this->showSubstitutions();
00099 $this->showSubstitutionsIn();
00100 $this->showSubstitutionsOut();
00101 $this->showCharacters();
00102 $this->showComponents();
00103 $this->showContentTasks();
00104 ?>
00105 <input type="hidden" name="core" value="cor_sef" />
00106 <?php
00107 echo "\n</div>";
00108 echo "\n\t</form>";
00109 echo "\n<!-- End of code from Remosef -->";
00110 }
00111
00112 private function getData () {
00113 $configs = $this->database->doSQLget ("SELECT * FROM #__remosef_config");
00114 $vars = get_object_vars($this);
00115 foreach ($configs as $item) {
00116 if ('options' == $item->type) {
00117 $name = $item->name;
00118 if (isset($vars[$name]) AND !is_array($this->$name)) $this->$name = $item->modified;
00119 }
00120 elseif ('components' == $item->type) {
00121 $this->custom_code[$item->name] = $item->modified;
00122 }
00123 elseif ('characters' == $item->type) {
00124 $this->sef_name_chars[] = $item->name;
00125 $this->sef_translate_chars[] = $item->modified;
00126 }
00127 elseif ('substitutions' == $item->type) {
00128 $this->sef_substitutions_exact_name[$item->id] = $item->name;
00129 $this->sef_substitutions_exact_mod[$item->id] = $item->modified;
00130 }
00131 elseif ('substitutions_in' == $item->type) {
00132 $this->sef_substitutions_in[$item->name] = $item->modified;
00133 }
00134 elseif ('substitutions_out' == $item->type) {
00135 $this->sef_substitutions_out[$item->name] = $item->modified;
00136 }
00137 elseif ('content' == $item->type) $this->sef_content_task[$item->name] = $item->modified;
00138 else $this->component_details[$item->type][$item->name] = $item->modified;
00139 }
00140 unset($configs);
00141 }
00142
00143 private function showOptions () {
00144 $this->headingLine('Remosef Options');
00145 $this->yesnoBox('Enable SEF', 'enabled', $this->enabled);
00146 $this->inputBox('Count of URI buffer entries', 'buffer_size', $this->buffer_size);
00147 $this->yesnoBox('Use Joomla cache (if enabled)', 'use_cache', $this->use_cache);
00148 $this->inputBox('Cache time in seconds', 'cache_time', $this->cache_time);
00149 $this->inputBox('Characters to be removed, separated by |', 'strip_chars', htmlspecialchars($this->strip_chars), 60);
00150 $this->yesnoBox('Make all URIs lowercase', 'lower_case', $this->lower_case);
00151 $this->yesnoBox('Force unique ID number in URIs', 'unique_id', $this->unique_id);
00152 $this->yesnoBox('Redirect underscore URLs to hyphen', 'underscore', $this->underscore);
00153 $this->yesnoBox('Log incoming transformations', 'log_transform', $this->log_transform);
00154 $this->inputBox('Home page title', 'home_title', $this->home_title);
00155 $this->inputBox('Robots default meta data', 'default_robots', $this->default_robots);
00156 $this->inputBox('Title separator (from site name)', 'title_separator', $this->title_separator);
00157 }
00158
00159 private function showSubstitutions () {
00160 $link = $this->getCfg('live_site').'/administrator/index2.php?option=com_sef&act=config&task=metadata&cid=';
00161 $this->headingLine('URI Substitutions - Exact');
00162 echo "\n\t<p>The left box should be the exact standard CMS URI (e.g. /index.php?option=com_content&task=view&id=21&Itemid=93), the right box what it is to be translated to (e.g. /about/john-smith/). The translation will be exact and will be applied immediately a URI is received.";
00163 foreach ($this->sef_substitutions_exact_name as $id=>$name) {
00164 $linkmeta = <<<LINK_META
00165
00166 <a href="$link$id">Edit metadata</a>
00167
00168 LINK_META;
00169 $this->translateLine('subst', $name, $this->sef_substitutions_exact_mod[$id], 50, $linkmeta);
00170 }
00171 for ($i = 0; $i < 5; $i++) $this->translateLine('subst', '', '',50);
00172 }
00173
00174 private function showSubstitutionsIn () {
00175 $this->headingLine('URI Substitutions - Inbound');
00176 echo "\n\t<p>The left box must be a valid regular expression that is to be applied to an incoming URI. The right box must be what it is to be translated to. The substitution will be applied immediately on receipt of a URI unless the URI has an exact match in the table above.</p>";
00177 echo "\n\t<p>This is designed to handle transformation of old URIs and care must be taken to avoid disrupting the normal decoding process.";
00178 echo "\n\t<p>Remember that regular expressions use metacharacters such as * or ? or ]. To use them as ordinary characters, they must be escaped with backslash.";
00179 foreach ($this->sef_substitutions_in as $key=>$name) $this->translateLine('subst_in', $key, $name, 50);
00180 for ($i = 0; $i < 5; $i++) $this->translateLine('subst_in', '', '',50);
00181 }
00182
00183 private function showSubstitutionsOut () {
00184 $this->headingLine('URI Substitutions - Outbound');
00185 echo "\n\t<p>The left box must be a valid regular expression. The right hand box will be substituted for it. The substitution will be applied after all other outgoing URI processing.";
00186 echo "\n\t<p>Remember that regular expressions use metacharacters such as * or ? or ]. To use them as ordinary characters, they must be escaped with backslash.";
00187 foreach ($this->sef_substitutions_out as $key=>$name) $this->translateLine('subst_out', $key, $name, 50);
00188 for ($i = 0; $i < 5; $i++) $this->translateLine('subst_out', '', '',50);
00189 }
00190
00191 private function showComponents () {
00192 $link = 'index.php?core=cor_sef&task=component&component=';
00193 $this->headingLine('Component names');
00194 echo "\n\t<p>If a component is listed here, its sef_ext.php (if any) will be used; the name will be translated in any case. Make sure the translated name does not conflict with content component tasks. Editing details depends on the sef_ext file being present and supporting the extended Remosef interface.</p>";
00195 foreach ($this->custom_code as $key=>$name) {
00196 $linkhtml = <<<COMP_LINK
00197
00198 <a href="$link$key">Edit details</a>
00199
00200 COMP_LINK;
00201
00202 $this->translateLine('comp', $key, $name, 30, $linkhtml);
00203 }
00204 for ($i = 0; $i < 5; $i++) $this->translateLine('comp', '', '', 30, '<span>Edit details</span>');
00205 }
00206
00207 private function showCharacters () {
00208 $this->headingLine('Character string translations');
00209 echo "\n\t<p>The box on the left must be a string of one or more characters; so must the box on the right. Any occurrences of left hand strings will be substituted by the corresponding right string. Character string translations are applied to names used to build the SEF URI.</p>";
00210 echo "\n\t<p>The dash (often created by MS Word) is always translated to hyphen, and single quote is always translated to hyphen</p>";
00211 echo "\n\t<p>Accents are automatically removed for accented characters in the Latin1 set; URL encoding is used if necessary</p>";
00212 foreach ($this->sef_name_chars as $key=>$name) $this->translateLine ('char', $name, $this->sef_translate_chars[$key]);
00213 for ($i = 0; $i < 5; $i++) $this->translateLine('char', '', '');
00214 }
00215
00216 private function showContentTasks () {
00217 $content_tasks = array ('findkey',
00218 'view',
00219 'section',
00220 'category',
00221 'blogsection',
00222 'blogcategorymulti',
00223 'blogcategory',
00224 'archivesection',
00225 'archivecategory',
00226 'save',
00227 'cancel',
00228 'emailform',
00229 'emailsend',
00230 'vote',
00231 'showblogsection'
00232 );
00233 $this->headingLine('Content task translations');
00234 echo "\n\t<p>You can give alternative names for the content component task words. Make sure that they do not conflict with component names.</p>";
00235 foreach ($this->sef_content_task as $key=>$name) $this->translateLine ('ctask', $key, $name);
00236 foreach ($content_tasks as $task) if (!isset($this->sef_content_task[$task])) $this->translateLine ('ctask', $task, '');
00237 for ($i = 0; $i < 3; $i++) $this->translateLine('ctask', '', '');
00238 }
00239
00240 private function headingLine ($title) {
00241 echo <<<HEADING
00242
00243 <div class="remosefhead">$title</div>
00244
00245 HEADING;
00246
00247 }
00248
00249 private function inputBox ($title, $name, $value, $width=25) {
00250 echo <<<INPUT_BOX
00251
00252 <div class="remosefinput">
00253 <label for="$name">$title</label>
00254 <input class="inputbox" type="text" id="$name" name="$name" size="$width" value="$value" />
00255 </div>
00256
00257 INPUT_BOX;
00258
00259 }
00260
00261 private function yesnoBox ($title, $name, $value) {
00262 $no = $yes = '';
00263 if ($value) $yes = "selected='selected'";
00264 else $no = "selected='selected'";
00265 echo <<<YES_NO
00266
00267 <div class="remosefinput">
00268 <label for="$name">$title</label>
00269 <select id="$name" name="$name">
00270 <option value="0" $no>No</option>
00271 <option value="1" $yes>Yes</option>
00272 </select>
00273 </div>
00274
00275 YES_NO;
00276
00277 }
00278
00279 private function translateLine ($type, $name, $modified, $size=30, $link='') {
00280 echo <<<TRANSLATE_LINE
00281
00282 <div class="remosefboxes">
00283 <input name="{$type}[]" value="$name" class="inputbox" size="$size"" />
00284 <input name="{$type}mod[]" value="$modified" class="inputbox" size="$size" />
00285 $link
00286 </div>
00287
00288 TRANSLATE_LINE;
00289
00290 }
00291
00292 public function saveTask () {
00293 $this->database->doSQL("DELETE FROM #__remosef_config WHERE type IN ('components', 'options', 'characters', 'content', 'substitutions', 'substitutions_in', 'substitutions_out')");
00294 $names = array_keys(get_object_vars($this));
00295 foreach ($names as $name) {
00296 if (is_array($this->$name) OR 'database' == $name) continue;
00297 $value = $this->getParam($_POST, $name);
00298 if (get_magic_quotes_gpc()) $value = stripslashes($value);
00299 if (null !== $value) {
00300 if ('strip_chars' == $name) $value = htmlspecialchars_decode ($value);
00301 if (is_numeric($this->$name)) $value = intval($value);
00302 else $value = $this->database->getEscaped($value);
00303 $this->$name = $value;
00304 }
00305 $this->database->setQuery("INSERT INTO #__remosef_config VALUES (0, 'options', '$name', '{$this->$name}')");
00306 $this->database->query();
00307 }
00308 $this->custom_code = $this->custom_name = array();
00309 $this->storeDataGroup ('components','comp','compmod');
00310 $this->sef_name_chars = $this->sef_translate_chars = array();
00311 $this->storeDataGroup ('characters', 'char', 'charmod');
00312 $this->sef_content_task = array();
00313 $this->storeDataGroup ('content', 'ctask', 'ctaskmod');
00314 $this->sef_substitutions_exact = array();
00315 $this->storeDataGroup ('substitutions', 'subst', 'substmod');
00316 $this->sef_substitutions_in = array();
00317 $this->storeDataGroup ('substitutions_in', 'subst_in', 'subst_inmod');
00318 $this->sef_substitutions_out = array();
00319 $this->storeDataGroup ('substitutions_out', 'subst_out', 'subst_outmod');
00320 aliroSEF::getInstance()->clearCache();
00321 $this->redirect('index.php?core=cor_sef', T_('SEF configuration saved'));
00322 }
00323
00324 private function storeDataGroup ($type, $namecode, $modcode) {
00325 $codes = $this->getParam($_POST, $namecode, array());
00326 $names = $this->getParam($_POST, $modcode, array());
00327
00328 foreach ($codes as $key=>$code) {
00329 // Probably better not to strip magic quotes - also removes deliberate escaping of regex characters
00330 // Should not be quotes in a URI
00331 /*
00332 if (get_magic_quotes_gpc()) {
00333 $code = stripslashes($code);
00334 if (!empty($names[$key])) $names[$key] = stripslashes($names[$key]);
00335 }
00336 */
00337 $code = $this->database->getEscaped($code);
00338 $name = !empty($names[$key]) ? $this->database->getEscaped($names[$key]) : '';
00339 if ($name AND $code) $this->database->doSQL("INSERT INTO #__remosef_config VALUES (0, '$type', '$code', '$name')");
00340 }
00341 }
00342
00343 public function componentTask () {
00344 $this->getData();
00345 $component = $this->getParam($_REQUEST, 'component');
00346 if (false !== strpos($component, '..')) die ('Illegal component specified');
00347 echo "\n\t\t<h3>Function codes for $component</h3>";
00348 $sefext = _ALIRO_ABSOLUTE_PATH.'/components/'.$component.'/sef_ext.php';
00349 if (file_exists($sefext)) {
00350 require_once($sefext);
00351 $class_name = str_replace('com', 'sef', $task);
00352 if (class_exists($class_name, false)) {
00353 if (method_exists($class_name, 'getInstance')) {
00354 $sef = call_user_func(array($class_name, 'getInstance'));
00355 if (method_exists($sef,'tags')) $tags = $sef->tags();
00356 }
00357 else {
00358 if (method_exists($class_name, 'tags')) $tags = call_user_func(array($class_name, 'tags'));
00359 }
00360 }
00361 }
00362 echo "\n<div id='remosefadmin'>";
00363 if (isset($tags)) {
00364 foreach ($tags as $tag) {
00365 if (isset($this->component_details[$task][$tag])) $translated = $this->component_details[$task][$tag];
00366 else $translated = '';
00367 $this->translateLine ($task, $tag, $translated);
00368 }
00369 }
00370 else echo "<p>No function codes found</p>";
00371 echo <<<END_FORM
00372 <input type="hidden" name="core" value="cor_sef" />
00373 <input type="hidden" name="component" value="$component" />
00374 </div>
00375 </form>
00376 <!-- End of code from Remosef -->
00377
00378 END_FORM;
00379
00380 }
00381
00382 }
00383
00384 class sefAdminUri extends sefAdminControllers {
00385 protected static $instance = __CLASS__;
00386
00387 protected $session_var = 'alirodoc_classid';
00388 protected $view_class = 'listUriHTML';
00389
00390 protected $cid = array();
00391 protected $uri = '';
00392 public $filters = null;
00393
00394 public static function getInstance ($manager) {
00395 return is_object(self::$instance) ? self::$instance : (self::$instance = new self::$instance($manager));
00396 }
00397
00398 public function getRequestData () {
00399 $this->cid = $this->getParam($_POST, 'cid', array());
00400 $this->uri = $this->getParam($_REQUEST, 'uri');
00401 }
00402
00403 public static function taskTranslator () {
00404 return array (
00405 'config' => T_('Configure'),
00406 'metadata' => T_('Metadata'),
00407 'save' => T_('Save metadata'),
00408 'remove' => T_('Delete'),
00409 'list' => T_('Cancel')
00410 );
00411 }
00412 public function toolbar () {
00413 if ('metadata' == $this->task) {
00414 $this->toolBarButton('save');
00415 $this->toolBarButton('list');
00416 }
00417 else {
00418 $this->toolBarButton('metadata');
00419 $this->toolBarButton('remove', true);
00420 }
00421 $this->toolBarButton('config');
00422 }
00423
00424 public function configTask () {
00425 $this->redirect('index.php?core=cor_sef');
00426 }
00427
00428 public function listTask () {
00429 $this->getListParams();
00430 $query = "SELECT COUNT(*) FROM #__remosef_uri";
00431 if ($this->filters['origuri']) $where[] = "uri LIKE '%{$this->filters['origuri']}%'";
00432 if ($this->filters['sefuri']) $where[] = "sef LIKE '%{$this->filters['sefuri']}%'";
00433 if (isset($where)) $query .= ' WHERE '.implode(' AND ', $where);
00434 $this->database->setQuery($query);
00435 $total = $this->database->loadResult();
00436 $this->makePageNav($total);
00437 $query = "SELECT * FROM #__remosef_uri";
00438 if (isset($where)) $query .= ' WHERE '.implode(' AND ', $where);
00439 $query .= " ORDER BY refreshed DESC LIMIT {$this->pageNav->limitstart}, {$this->pageNav->limit}";
00440 $uris = $this->database->doSQLget($query);
00441 $view = new sefAdminHTML();
00442 $view->listuris($uris, $this->pageNav, $this);
00443 }
00444
00445 private function getListParams () {
00446 $this->filters['sefuri'] = $this->database->getEscaped($this->getParam($_REQUEST, 'sefuri'));
00447 $this->filters['origuri'] = $this->database->getEscaped($this->getParam($_REQUEST, 'origuri'));
00448 }
00449
00450 public function removeTask () {
00451 foreach ($this->cid as &$selected) $selected = intval($selected);
00452 $slist = implode(',', $this->cid);
00453 if ($slist) $this->database->doSQL("DELETE FROM #__remosef_uri WHERE id IN ($slist)");
00454 $this->redirect('index.php?core=cor_sef&act=uri', T_('Deletion completed'));
00455 }
00456
00457 public function metadataTask () {
00458 }
00459
00460 public function saveTask () {
00461
00462 }
00463
00464 }
00465
00466 class sefAdminMetadata extends sefAdminControllers {
00467 protected static $instance = __CLASS__;
00468
00469 protected $session_var = 'alirodoc_classid';
00470 protected $view_class = 'listMetadataHTML';
00471
00472 protected $cid = array();
00473 protected $uri = '';
00474 public $filters = null;
00475
00476 public static function getInstance ($manager) {
00477 return is_object(self::$instance) ? self::$instance : (self::$instance = new self::$instance($manager));
00478 }
00479
00480 public function getRequestData () {
00481 $this->cid = $this->getParam($_POST, 'cid', array());
00482
00483 }
00484
00485 public static function taskTranslator () {
00486 return array (
00487 'cancel' => T_('Cancel'),
00488 'metadata' => T_('Metadata'),
00489 'save' => T_('Save metadata'),
00490 'remove' => T_('Delete')
00491 );
00492 }
00493 public function toolbar () {
00494 if ('metadata' == $this->task) $this->toolBarButton('save');
00495 else {
00496 $this->toolBarButton('metadata');
00497 $this->toolBarButton('remove', true);
00498 }
00499 $this->toolBarButton('cancel');
00500 }
00501
00502 public function listTask () {
00503 $this->getListParams();
00504 $query = "SELECT COUNT(*) FROM #__remosef_metadata AS m LEFT JOIN #__remosef_uri AS u ON m.uri = u.uri AND m.type = 'listuri'"
00505 ." LEFT JOIN #__remosef_config AS c ON c.type = 'substitutions' AND m.uri = c.name";
00506 if ($this->filters['origuri']) $where[] = "m.uri LIKE '%{$this->filters['origuri']}%'";
00507 if ($this->filters['sefuri']) $where[] = "u.sef LIKE '%{$this->filters['sefuri']}%' OR c.modified LIKE '%{$this->filters['sefuri']}%'";
00508 if (isset($where)) $query .= ' WHERE '.implode(' AND ', $where);
00509 $this->database->setQuery($query);
00510 $total = $this->database->loadResult();
00511 $this->makePageNav($total);
00512 $query = "SELECT m.*, u.sef, c.modified FROM #__remosef_metadata AS m LEFT JOIN #__remosef_uri AS u ON m.uri = u.uri AND m.type = 'listuri'"
00513 ." LEFT JOIN #__remosef_config AS c ON c.type = 'substitutions' AND m.uri = c.name";
00514 if (isset($where)) $query .= ' WHERE '.implode(' AND ', $where);
00515 $query .= " ORDER BY u.sef LIMIT {$this->pageNav->limitstart}, {$this->pageNav->limit}";
00516 $this->database->setQuery($query);
00517 $metas = $this->database->loadObjectList();
00518 $view = new sefAdminHTML();
00519 $view->listmeta($metas, $this->pageNav, $this);
00520 }
00521
00522 private function getListParams () {
00523 $this->filters['sefuri'] = $this->database->getEscaped($this->getParam($_REQUEST, 'sefuri'));
00524 $this->filters['origuri'] = $this->database->getEscaped($this->getParam($_REQUEST, 'origuri'));
00525 }
00526 }
00527
00528 class dummy {
00529
00530 public function editTask () {
00531 if ($this->errorid) {
00532 }
00533 else $this->redirect('index.php?core=cor_errors', T_('Please select an item for detailed display'), _ALIRO_ERROR_WARN);
00534 }
00535
00536 public function removeTask () {
00537 if (count($this->cid)) {
00538 foreach ($this->cid as &$item) $item = intval($item);
00539 $idlist = implode(',', $this->cid);
00540 $database = aliroCoreDatabase::getInstance();
00541 $database->doSQL("DELETE FROM #__error_log WHERE id IN ($idlist)");
00542 $this->redirect('index.php?core=cor_errors');
00543 }
00544 else $this->redirect('index.php?core=cor_errors', T_('Please select an item for deletion'), _ALIRO_ERROR_WARN);
00545 }
00546
00547 public function cancelTask () {
00548 $this->redirect('index.php?core=cor_sef');
00549 }
00550
00551 function sefAdminOldStuff () {
00552 global $database, $sefnotes;
00553 $this->database = $database;
00554 $act = mosGetParam($_REQUEST, 'act');
00555 $task = mosGetParam($_REQUEST, 'task');
00556 $this->cid = (array) mosGetParam($_REQUEST, 'cid', array());
00557 if ('metasave' == $task) $this->saveMetaData($act);
00558 if ('page404' == $task OR ('page404' == $act AND 'cancel' != $task)) {
00559 if ('remove' == $task) $this->delete404();
00560 $this->list404();
00561 return;
00562 }
00563 elseif ('listuri' == $task OR ('listuri' == $act AND 'cancel' != $task)) {
00564 if ('metadata' == $task AND 1 == count($this->cid)) {
00565 $this->editMetaData('listuri');
00566 return;
00567 }
00568 if ('remove' == $task) $this->deleteuri();
00569 $this->listuri();
00570 return;
00571 }
00572 elseif ('listmeta' == $task OR ('listmeta' == $act AND 'cancel' != $task)) {
00573 if ('metadata' == $task AND 1 == count($this->cid)) {
00574 $this->editMetaData('listmeta');
00575 return;
00576 }
00577 if ('remove' == $task) $this->deletemeta();
00578 $this->listmeta();
00579 return;
00580 }
00581 elseif ('components' == $act AND 'cancel' != $task) {
00582 $this->getData();
00583 if ($task) {
00584 if ('save' == $task) $this->saveComponentFuncs ();
00585 else $this->one_component ($task);
00586 }
00587 return;
00588 }
00589 if ('metadata' == $task AND 1 == count($this->cid)) {
00590 $type = mosGetParam($_REQUEST, 'type', 'config');
00591 $this->editMetaData($type);
00592 return;
00593 }
00594 if ('save' == $task) $this->storeData();
00595 }
00596
00597 function addCustomHeadTag ($tag) {
00598 global $mainframe;
00599 $mainframe->addCustomHeadTag ($tag);
00600 }
00601
00602 function getUserStateFromRequest ($array, $name, $default) {
00603 global $mainframe;
00604 return $mainframe->getUserStateFromRequest ($array, $name, $default);
00605 }
00606
00607 function getData () {
00608 $configs = $this->database->doSQLget ("SELECT * FROM #__remosef_config");
00609 $vars = get_object_vars($this);
00610 foreach ($configs as $item) {
00611 if ('options' == $item->type) {
00612 $name = $item->name;
00613 if (isset($vars[$name]) AND !is_array($this->$name)) $this->$name = $item->modified;
00614 }
00615 elseif ('components' == $item->type) {
00616 $this->custom_code[$item->name] = $item->modified;
00617 }
00618 elseif ('characters' == $item->type) {
00619 $this->sef_name_chars[] = $item->name;
00620 $this->sef_translate_chars[] = $item->modified;
00621 }
00622 elseif ('substitutions' == $item->type) {
00623 $this->sef_substitutions_exact_name[$item->id] = $item->name;
00624 $this->sef_substitutions_exact_mod[$item->id] = $item->modified;
00625 }
00626 elseif ('substitutions_in' == $item->type) {
00627 $this->sef_substitutions_in[$item->name] = $item->modified;
00628 }
00629 elseif ('substitutions_out' == $item->type) {
00630 $this->sef_substitutions_out[$item->name] = $item->modified;
00631 }
00632 elseif ('content' == $item->type) $this->sef_content_task[$item->name] = $item->modified;
00633 else $this->component_details[$item->type][$item->name] = $item->modified;
00634 }
00635 unset($configs);
00636 }
00637
00638
00639 function saveMetaData ($act) {
00640 $type = ('listmeta' == $act) ? mosGetParam ($_REQUEST, 'metatype', 'config') : $act;
00641 $id = intval(mosGetParam ($_POST, 'id', 0));
00642 $metadata = $this->getMetaData($act, $id);
00643 $setters[] = "type = '$type'";
00644 $values[] = $metadata->uri;
00645 $values[] = $type;
00646 $inames = 'uri, type';
00647 foreach (array('htmltitle','robots','description','keywords') as $fieldname) {
00648 $setters[] = $fieldname." = '".$this->database->getEscaped(mosGetParam($_POST, $fieldname))."'";
00649 $values[] = $this->database->getEscaped(mosGetParam($_POST, $fieldname));
00650 $inames .= ', '.$fieldname;
00651 }
00652 if ($metadata->id) $sql = "UPDATE #__remosef_metadata SET ".implode(', ', $setters)." WHERE id = $metadata->id";
00653 else $sql = "INSERT INTO #__remosef_metadata ($inames) VALUES('".implode("', '", $values)."')";
00654 $this->database->setQuery($sql);
00655 $this->database->query();
00656 }
00657
00658
00659 function translateLine ($type, $name, $modified, $size=30, $link='') {
00660 echo <<<TRANSLATE_LINE
00661
00662 <div class="remosefboxes">
00663 <input name="{$type}[]" value="$name" class="inputbox" size="$size"" />
00664 <input name="{$type}mod[]" value="$modified" class="inputbox" size="$size" />
00665 $link
00666 </div>
00667
00668 TRANSLATE_LINE;
00669
00670 }
00671
00672 function remosefCSS () {
00673 $css = <<<REMOSEF_CSS
00674
00675 <style type="text/css" media="all">
00676 .remosefhead {
00677 margin: 15px 0;
00678 padding: 6px 4px 2px 4px;
00679 height: 24px;
00680 background: url(templates/joomla_admin/images/background.jpg);
00681 background-repeat: repeat;
00682 font-size: 14px;
00683 font-weight: bold;
00684 color: #000;
00685 }
00686 .remosefinput {
00687 height: 24px;
00688 padding-top: 4px;
00689 border-bottom: 1px solid #DDD;
00690 }
00691 .remosefinput label {
00692 display: box;
00693 float: left;
00694 clear: left;
00695 text-align: right;
00696 width: 35%;
00697 }
00698 .remosefinput select, .remosefinput input {
00699 display: box;
00700 float: left;
00701 margin-left: 10px;
00702 }
00703 .remosefboxes{
00704 height: 24px;
00705 }
00706 </style>
00707
00708 REMOSEF_CSS;
00709
00710 $this->addCustomHeadTag($css);
00711 }
00712
00713
00714 // private function
00715 function htmlspecialchars_decode_php4 ($str, $quote_style = ENT_COMPAT) {
00716 return strtr($str, array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style)));
00717 }
00718
00719
00720
00721 function deleteuri () {
00722 $sql = $sql = "DELETE FROM #__remosef_uri WHERE id IN (%s)";
00723 $this->deleteByCid ($sql);
00724 }
00725
00726 function deletemeta () {
00727 $sql = $sql = "DELETE FROM #__remosef_metadata WHERE id IN (%s)";
00728 $this->deleteByCid ($sql);
00729 }
00730
00731 function deleteByCid ($sql) {
00732 if (count($this->cid)) {
00733 foreach ($this->cid as $i=>$id) $this->cid[$i] = intval($id);
00734 $sql = sprintf($sql, implode(',', $this->cid));
00735 $this->database->setQuery($sql);
00736 $this->database->query();
00737 }
00738 }
00739
00740 function editMetaData ($type) {
00741 $id = intval($this->cid[0]);
00742 $metadata = $this->getMetaData($type, $id);
00743 require_once($this->getCfg('absolute_path').'/administrator/components/com_sef/admin.sef.html.php');
00744 $view = new sefAdminHTML();
00745 $view->editMetaData($type, $id, $metadata, $this);
00746 }
00747
00748 // Internal function
00749 function getMetaData ($type, $id) {
00750 if ('config' == $type) {
00751 $sql = "SELECT c.name AS uri, c.modified AS sef, m.id, m.htmltitle, m.robots, m.description, m.keywords FROM #__remosef_config AS c LEFT JOIN #__remosef_metadata AS m ON m.uri = c.name WHERE c.id = $id";
00752 }
00753 elseif ('listuri' == $type) {
00754 $sql = "SELECT u.uri, u.sef, m.id, m.htmltitle, m.robots, m.description, m.keywords FROM #__remosef_uri AS u LEFT JOIN #__remosef_metadata AS m ON m.uri = u.uri WHERE u.id = $id";
00755 }
00756 // Remaining alternative is 'listmeta'
00757 else $sql = "SELECT m.*, u.sef, c.modified FROM #__remosef_metadata AS m LEFT JOIN #__remosef_uri AS u ON m.uri = u.uri AND m.type = 'listuri'"
00758 ." LEFT JOIN #__remosef_config AS c ON c.type = 'substitutions' AND m.uri = c.name WHERE m.id = $id";
00759 $this->database->setQuery($sql);
00760 $metadata = null;
00761 $this->database->loadObject($metadata);
00762 return $metadata;
00763 }
00764
00765 function one_component ($task) {
00766 }
00767
00768 function saveComponentFuncs () {
00769 mosCache::cleanCache('aliroSEF');
00770 $component = mosGetParam($_POST, 'component');
00771 if (0 === strpos($component,'com_')) {
00772 $this->database->setQuery("DELETE FROM #__remosef_config WHERE type = '$component'");
00773 $this->database->query();
00774 $this->component_details = array();
00775 $component = $this->database->getEscaped($component);
00776 $tags = mosGetParam($_POST, $component, array());
00777 $modified = mosGetParam($_POST, $component.'mod', array());
00778 foreach ($tags as $key=>$tag) {
00779 if (!empty($modified[$key])) {
00780 $tag = $this->database->getEscaped($tag);
00781 $mod = $this->database->getEscaped($modified[$key]);
00782 $this->database->setQuery("INSERT INTO #__remosef_config VALUES (0, '$component', '$tag', '$mod')");
00783 $this->database->query();
00784 $this->component_details[$component][$tag] = $mod;
00785 }
00786 }
00787 $this->one_component($component);
00788 }
00789 }
00790
00791 }