We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31337
    • 258 Posts
    Ok now I am really confused as to what the problem is grin

    Please explain what you’re trying to accomplish -- feel free to post in Russian and I can translate it for the rest of the gang.
      • 32241
      • 1,495 Posts
      When I’m about to post a reply, you already replied to this post. Anyway, here is the reply that suppose to be my reply to openagate wink


      Now I understand your problem. Basically victor’s and my solution cannot be combined, beccause it will cause the error to still reappearing. Am I right?

      I tried applying cleanDocumentIdentifier and getDocumentObject from the one on this forum, and it works on mine though. I’m not sure about what Victors did to the function, considering he has a better understanding of the core code than me, so it’s better to ask for his help wink

      Help victor grin
        Wendy Novianto
        [font=Verdana]PT DJAMOER Technology Media
        [font=Verdana]Xituz Media
        • 22301
        • 1,084 Posts
        Hi, Vic smiley

        So...


        .htaccess
        php_flag zlib.output_compression On
        php_value zlib.output_compression_level 5
        RewriteEngine On
        RewriteBase /
        RewriteCond %{HTTP_HOST} !^jurist-info.ru$
        RewriteRule ^ http://jurist-info.ru%{REQUEST_URI} [R=301,L]
        RewriteRule ^index/ http://jurist-info.ru/ [R=301,L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
        


        MODx CMS
        Friendly URL: on
        Prefix for friendly URLs: none 
        Suffix for friendly URLs: /
        Use friendly aliases: Yes
        Use friendly alias path: Yes
        


        document.parser.class.inc.php from Victor

        Problem

        Example:

        http://jurist-info.ru/reorganisation/reo_out/  -- ID=20


        http://jurist-info.ru/whatafuck/20 =
        = http://jurist-info.ru/reorganisation/reo_out/ =
        = http://jurist-info.ru/oopsididitagain/20 =
        = http://jurist-info.ru/oopsididitagain/20. = http://jurist-info.ru/oopsididitagain/20/

        Certainly, there are no realy pages with aliases "whatafuck" and  "oopsididitagain"



        if http://jurist-info.ru/oopsididitagain/ -- right error message, 404 status
        if http://jurist-info.ru/oopsididitagain/20.html -- « MODx Parse Error »

        if document does not exist and id is mismatches any realy page in modx_base, example, http://jurist-info.ru/oopsididitagain/20000000000.html or http://jurist-info.ru/oopsididitagain/20000000000 -- right error message, 404 status

        If will look at addresses (links) all becomes clear, click’em all




          [img]http://jurist-info.ru/pic/rrr.jpg[/img]

          Безжалостный пияр!
          Artima -- неуч!
          Осторожно: преступная локализация -- modx-cms.ru
          Баштанник Андрей -- мегапрограммер из Белоруссии и поедатель говна, очень критично настроенный молодой человек!

          Дисклеймер для общительных: даю сам себе право транслировать в открытый эфир содержание лички, just for fun
          • 31337
          • 258 Posts
          Ugh. The Russian encoding got screwed up when you posted. Can’t read it >:(
            • 22301
            • 1,084 Posts
            I have done a small update, see above...
              [img]http://jurist-info.ru/pic/rrr.jpg[/img]

              Безжалостный пияр!
              Artima -- неуч!
              Осторожно: преступная локализация -- modx-cms.ru
              Баштанник Андрей -- мегапрограммер из Белоруссии и поедатель говна, очень критично настроенный молодой человек!

              Дисклеймер для общительных: даю сам себе право транслировать в открытый эфир содержание лички, just for fun
              • 31337
              • 258 Posts
              Ok,

              I got an email from openagate detailing the problem. Let me translate it here for anyone following this thread:

              With the above rewrite rules, friendly URLs work just fine.
              BUT, if you enter a URL like this:

              http://jurist-info.ru/oopsididitagain/20 (where "oopsididitagain" is a non-existant folder) it brings up the page with the id of 20 regardless of where in the hierarchy that page actually resides.

              http://jurist-info.ru/oopsididitagain by itself brings up a 404

              And doing this URL:
              http://jurist-info.ru/oopsididitagain/20.html brings up a Modx parse error

              So clearly we have 2 bugs in the URL parser:
              1) Nonexistant directories should produce a 404
              2) Nonexistant directories + a .html file should not produce parse errors

                • 32241
                • 1,495 Posts
                Quote from: vbrilon at Mar 20, 2006, 04:46 PM

                So clearly we have 2 bugs in the URL parser:
                1) Nonexistant directories should produce a 404
                2) Nonexistant directories + a .html file should not produce parse errors

                Ok, so the changes in the function cleanDocumentIdentofier basically will tackle the non-existance directory to be displayed correctly. It also prohibit possibility of having suffix and prefix word located in the middle of the alias to be removed unexpectedly.

                Now with the changes on getDocumentObject, it will tackled the problem of displaying parser errors when document id being passed in a incorrect format caused by the previous fixed, instead it will send the user to the error page.

                Both fixed functions are located on the first page of this topic. I tried it on my testing site, so far everything works just fine, but I’m not a core coder, and I should admit that I’ve been toying with PHP in less than 6 months. I also heard that this problem had beein fixed by someone for release 0.9.2. So anyway, Victor, please check my solution, and if you know the right solution to it, it will be great to post them in this topic, coz I’m really interested in having this problem fixed with the right patch. grin
                  Wendy Novianto
                  [font=Verdana]PT DJAMOER Technology Media
                  [font=Verdana]Xituz Media
                  • 31337
                  • 258 Posts
                  Wendy,

                  Any chance you can send me a diff file of just your changes so I can take a look at it? I am not terrbly familiar with that piece of code, so a diff is easier to read.

                  If you can’t make diffs, just email me the files you changed, and I’ll figure out the changes on my end. My email is: victor AT victorland DOT com (I hate spammers and their stupid bots :/)
                    • 32241
                    • 1,495 Posts
                    This will be a lot easier for me, coz I don’t know how to make diff grin Heheee..

                    Anyway, I commented the line that I modified with capital word on the first few words of the comments.

                    <?php
                    	function cleanDocumentIdentifier($qOrig) { // modx updates
                    		$q = $qOrig;
                    		// First remove any / before or after
                    		if ($q[ strlen( $q) - 1] == '/') $q = substr( $q,0,-1);
                    		if ($q[ 0 ] == '/') $q = substr($q,1);
                    		// Save path if any
                    		$this->virtualDir = dirname($q);
                    		$this->virtualDir = ($this->virtualDir == '.' ? '' : $this->virtualDir);
                    		$q = basename($q);
                    		// BEGIN FIXED - Fixed problem with alias that contains the same word with suffix or prefix (by Wendy Novianto)
                    		$qprefix = $this->config['friendly_url_prefix'];
                    		$qsuffix = $this->config['friendly_url_suffix'];
                    		$qslength = strlen($qsuffix);
                    		$plength = strlen($q) - $qslength;
                    		if($qprefix != null && trim($qprefix) != '' && strpos($q, $qprefix) == 0) $q = substr($q, strlen($qprefix));
                    		if($qsuffix != null && trim($qsuffix) != '' && substr($q, $plength) == $qsuffix) $q = substr($q, 0, $plength);
                    		//$q = str_replace($this->config['friendly_url_prefix'], "", $q);
                    		//$q = str_replace($this->config['friendly_url_suffix'], "", $q);
                    		// ENDED FIXED
                    		// ADDED $this->virtualDir == '' in if statement, and add else if statement, instead of else
                    		if(is_numeric($q) && !$this->documentListing[$q] && $this->virtualDir == '') { // we got an ID returned, check to make sure it;s no an alias
                    			$this->documentMethod = 'id';
                    			return $q;
                    		}
                    		else if($q != ((string) ((int) $q))) { // we didn't get an ID back, so instead we assume it's an alias
                    			if($this->config['friendly_alias_urls']!=1) {
                    				$q = $qOrig;
                    			}
                    			$this->documentMethod = 'alias';
                    			return $q;
                    		}
                    	}
                    ?>
                    


                    <?php
                    	/**
                    	 * name: getDocumentObject  - used by parser
                    	 * desc: returns a document object - $method: alias, id
                    	 */
                    	function getDocumentObject($method,$identifier){
                    		$tblsc = $this->getFullTableName("site_content");
                    		$tbldg = $this->getFullTableName("document_groups");
                    		// BEGIN FIXED - Check document id validity - Added by Wendy Novianto
                    		if($method == 'id' && (!is_numeric($identifier) || $identifier != ((int)$identifier))) {
                    			$this->sendErrorPage();
                    			exit; // stop here
                    		}
                    		// ENDED FIXED
                    		// get document groups for current user
                    		if($docgrp = $this->getUserDocGroups()) $docgrp = implode(",",$docgrp);
                    		// get document
                    		$access = ($this->isFrontend() ? "sc.privateweb=0":"1='".$_SESSION['mgrRole']."' OR sc.privatemgr=0").
                    				  (!$docgrp ? "":" OR dg.document_group IN ($docgrp)");
                    		$sql = "SELECT sc.*
                    				FROM $tblsc sc
                    				LEFT JOIN $tbldg dg ON dg.document = sc.id
                    				WHERE sc.".$method." = '".$identifier."'
                    				AND ($access) LIMIT 1;";
                    		$result = $this->db->query($sql);
                    		$rowCount = $this->recordCount($result);
                    		if($rowCount<1) {
                    			if ($this->config['unauthorized_page']) {
                    				// check if file is not public
                    				$secrs = $this->dbQuery("SELECT id FROM $tbldg WHERE document = '".$identifier."' LIMIT 1;");
                    				if($secrs) $seclimit = mysql_num_rows($secrs);
                    			}
                    			if ($seclimit>0)  {
                    				// match found but not publicly accessible, send the visitor to the unauthorized_page
                    				$this->sendUnauthorizedPage();
                    				exit; // stop here
                    			}
                    			else {
                    				// no match found, send the visitor to the error_page
                    				$this->sendErrorPage();
                    				exit; // stop here
                    			}
                    		}
                    		if($rowCount>1) {
                    		 	// too many matches found, send the visitor to the error page
                    			$this->messageQuit("More than one result returned when attempting to translate `alias` to `id` - there are multiple documents using the same alias");
                    		}
                    		# this is now the document :) #
                    		$documentObject = $this->fetchRow($result);
                    
                    		// load TVs and merge with document - Orig by Apodigm - Docvars
                    		$tbn = $this->dbConfig['dbase'].".".$this->dbConfig['table_prefix'];
                    		$sql = "SELECT tv.*, IF(tvc.value!='',tvc.value,tv.default_text) as value ";
                    		$sql.= "FROM ".$tbn."site_tmplvars tv ";
                    		$sql.= "INNER JOIN ".$tbn."site_tmplvar_templates tvtpl ON tvtpl.tmplvarid = tv.id ";
                    		$sql.= "LEFT JOIN ".$tbn."site_tmplvar_contentvalues tvc ON tvc.tmplvarid=tv.id AND tvc.contentid = '".$this->documentIdentifier."' ";
                    		$sql.= "WHERE tvtpl.templateid = '".$documentObject['template']."'";
                    		$rs = $this->dbQuery($sql);
                    		$rowCount = $this->recordCount($rs);
                    		if($rowCount>0) {
                    			for($i=0;$i<$rowCount;$i++) {
                    				$row = $this->fetchRow($rs);
                    				$tmplvars[$row['name']] = array($row['name'],$row['value'],$row['display'],$row['display_params'],$row['type']);
                    			}
                    			$documentObject = array_merge($documentObject,$tmplvars);
                    		}
                    		return $documentObject;
                    	}
                    ?>
                    
                      Wendy Novianto
                      [font=Verdana]PT DJAMOER Technology Media
                      [font=Verdana]Xituz Media
                      • 31337
                      • 258 Posts
                      Wendy can you please just zip up the files you changed and email them to me? Sorry, but it’s pretty difficult otherwise to look at code you’re not familar with and get context of what’s going on.

                      If you have access to the command line (either in Linux or OS X) I can show you how to make diffs btw wink