admin.sef.php

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

Generated on Thu Apr 17 13:03:26 2008 for ALIRO by  doxygen 1.5.5