We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4532
    • 11 Posts
    I am getting a 404 error page when I try to save a Plugin huh
    The 404 page is coming from http://www.mydomain.com/ and not from http://www.mydomain.com/manager/

    In going through the code line by line it seems to be this that is stopping it.

    $sql = "SELECT tvc.contentid as id, tvc.value as value FROM" . $modx->getFullTableName(’site_tmplvars’) . "tv";

    if I remove "SELECT" the plugin will save — I am not sure what is happening here.

    If any one has a solution to this problem it would be very much appreciated. smiley

    PS. Here is the link to the plugin that I am trying to install. http://www.stanback.net/code/modx/virtual-aliases.html
      • Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 4532
        • 11 Posts
        I have tried what was mentioned in you post but it did not seem to do any thing except block me out of the manager.?

        Now I am getting an error with some information showing up hope this might be able to explain it a little.

        « MODx Parse Error »
        MODx encountered the following error while attempting to parse the requested resource:
        « Execution of a query to the database failed - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INNER JOIN `DB_name`.`modx_site_tmplvar_templates` tvtpl ON tvtpl.tmplvarid ' at line 1 »
              SQL: INNER JOIN `DB_name`.`modx_site_tmplvar_templates` tvtpl ON tvtpl.tmplvarid = tv.id LEFT JOIN `DB_name`.`modx_site_tmplvar_contentvalues` tvc ON tvc.tmplvarid = tv.id LEFT JOIN `DB_name`.`modx_site_content` sc ON sc.id = tvc.contentid WHERE sc.published = 1 AND tvtpl.templateid = sc.template AND tv.name = 'Aliases' AND tvc.value LIKE '%500.shtml%' 
              
         
        Parser timing
          MySQL:	0.0036 s	(0 Requests)
          PHP:	0.0254 s	 
          Total:	0.0289 s


        Here is all the code for the plugin, from my experimentation it seems to be the sql call that is giving the trouble and in particular the first line of the sql call. (I am still trying to learn PHP)

        Thanks for you help.
        Cameron

        //<?php
        // Virtual Aliases
        // version 0.0.1
        // Allows for an unlimited number of custom aliases per page.
        // By Brian Stanback @ www.stanback.net
         
        // On Install: Check the the "OnPageNotFound" box in the System Events tab.
        // Plugin configuration: &aliasesTV=Aliases TV name;string;Aliases
         
        // For overriding documents, create a new template variabe (TV) named
        // Aliases with the following option:
        //    Input Type: Textarea (Smaller)
        // 
        // Aliases should be added to the TV, one per line. 
        // Omit any leading or trailing slashes as well as the default suffix (usaully .html)
         
        // Begin plugin code
        $e = &$modx->event;
         
        if ($e->name == "OnPageNotFound") 
        {
           // Retrieve requested path + alias
           $documentAlias = $modx->documentIdentifier;
           $documentAlias = ($modx->virtualDir == "") ? $documentAlias : $modx->virtualDir . '/' . $documentAlias;
         
           // Search TVs for potential alias matches
           $sql = "SELECT tvc.contentid as id, tvc.value as value FROM " . $modx->getFullTableName('site_tmplvars') . " tv ";
           $sql .= "INNER JOIN " . $modx->getFullTableName('site_tmplvar_templates') . " tvtpl ON tvtpl.tmplvarid = tv.id ";
           $sql .= "LEFT JOIN " . $modx->getFullTableName('site_tmplvar_contentvalues') . " tvc ON tvc.tmplvarid = tv.id ";
           $sql .= "LEFT JOIN " . $modx->getFullTableName('site_content') . " sc ON sc.id = tvc.contentid ";
           $sql .= "WHERE sc.published = 1 AND tvtpl.templateid = sc.template AND tv.name = '$aliasesTV' AND tvc.value LIKE '%" . $modx->db->escape($documentAlias) . "%'";
           $results = $modx->dbQuery($sql);
         
           // Attempt to find an exact match
           $found = 0;
           while ($found == 0 && $row = $modx->db->getRow($results))
           {
              $pageAliases = explode("\n", $row["value"]);
              while ($found == 0 && $alias = each($pageAliases))
              {
                 if (trim($alias[1]) == $documentAlias)  // Check for a match
                    $found = $row["id"];
              }
           }
         
           if ($found)  // Redirect to new document, if an alias was found
           {
              $pageUrl = $modx->makeUrl($found, '', '', "full");
              $modx->sendRedirect($pageUrl, 0, "REDIRECT_HEADER", "301");  // Send a permanent redirect
              exit(0);
           }
         
           header("HTTP/1.0 404 Not Found");
           header("Status: 404 Not Found");
        }

        • It looks like that first line of the query got chopped off somehow. Try this immediately after building the $sql string:
          echo $sql; exit();

          and see if it displays the entire sql query properly.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 4532
            • 11 Posts
            Hi sottwell

            After I inserted the code that you suggested it still would not let me save the plugin the only way I can get it in is by pasting it in through Sequel Pro in to the data base. (it has worked with others in the past)
            Could it have anything to do with settings on the server as it is running on my local server OK? (MAMP)

            Thanks for your help.
            Cameron
            • Ah, it won’t let you save the plugin. I thought the plugin just wasn’t working! Sounds like you’ve run into the dreaded mod_security! http://wiki.modxcms.com/index.php/What_is_mod_security_and_how_does_it_affect_me
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 4532
                • 11 Posts
                Hi sottwell

                Yes it is the dreaded mod_security! I am still working on getting it fixed with my hosting provider.

                Thanks for you help.
                Cameron