We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13226
    • 953 Posts
    Hi all,

    Recently i've been hammering my head on the desk due to changes on a variety of client servers.

    It seems that out of the blue everyone wants to update to PHP5.4

    Me thinking no-problems, but what realy happend is a nightmare.

    As I am not a php'r the problems seem to be overwhelming

    A couple of problems: Ditto's "buildURL", timezone errors along with others

    Anyone else having stress with PHP5.4, if yes, what's been the problem(s) and how did you fix them.

    A couple of sources:

    MODx Forum post: Deprecated escape function message

    MODx Forum post: Error due to a PHP upgrade

    How to revert MODx Evo to operation in PHP 5.4

    An update on solutions:

    There are other database issues with some servers that have changed to PHP5.4

    Updating the mysql password (by using the old one) is apparantly a solution for some, as the new hashing mechanism is then used.

    I have to test this, but at the moment have not experienced this problem myself.

    All feedback is welcome smiley [ed. note: iusemodx last edited this post 11 years, 3 months ago.]
      • 13226
      • 953 Posts
      So, I am still working on this together with a great programmer smiley

      We have come to the conclusion that its not simply Evo, the majority of problems I have incurred arise from 3rd party code.

      After removing all snippets and plugins that are not a necessity we have come up with the bare essentials to get a site back up and running - at least, the sites I am running as well as client sites.

      The following modifications have been made on 7 sites, all running PHP5.4 - they all now work as they previously did.


      Root Folder & Manager Folder

      For problems with "timezone" we had to create a "php.ini" file with our time zone code in the root and the manager folder

      e.g date.timezone = Europe/London

      For a full list of European timezones Click Here

      For a full list of American timezones Click Here


      MANAGER Modifications:

      File: manager/includes/extenders/dbapi.mysql.class.inc.php

      Change:
      function escape($s) {
        if (function_exists('mysql_real_escape_string') && $this->conn) {
           $s = mysql_real_escape_string($s, $this->conn);
        } else {
           $s = mysql_escape_string($s);
        }
        return $s;
      }
      


      To:

      Updated code courtesy of Bogdanio
      function escape($s) {
        if ($this->conn) {
           $s = mysql_real_escape_string($s, $this->conn);
        } else {
           $s = mysql_real_escape_string($s);
        }
        return $s;
      }
      



      DITTO Modifications:

      File: assets/snippets/ditto/classes/ditto.class.inc.php

      Modification 1:

      // ---------------------------------------------------
      // Function: getAuthor
      // Get the author name, or if not available the username
      // ---------------------------------------------------
      // Change to PHP5.4 public static function
      // function getAuthor($createdby) {
      public static function getAuthor($createdby) {
          global $modx;
          
          $user = false;
          if ($createdby > 0) {
              $user = $modx->getUserInfo($createdby);
          } else {
              $user = $modx->getWebUserInfo(abs($createdby));
          }
          if ($user === false) {
              // get admin user name
              $user = $modx->getUserInfo(1);
          }
          return ($user['fullname'] != "") ? $user['fullname'] : $user['username'];
      }
      


      Modification 2:

      Updated code courtesy of kp52

      // ---------------------------------------------------
      // Function: buildURL
      // Build a URL with regard to Ditto ID
      // ---------------------------------------------------
      // Change to PHP5.4 public static function
      // function buildURL($args,$id=false,$dittoIdentifier=false) {
      public static function buildURL($args,$id=false,$dittoIdentifier=false) {
          global $modx, $dittoID;
              $dittoID = ($dittoIdentifier !== false) ? $dittoIdentifier : $dittoID;
              $query = array();
              foreach ($_GET as $param=>$value) {
                  if ($param != 'id' && $param != 'q') {
                      $query[htmlspecialchars($param, ENT_QUOTES)] = htmlspecialchars($value, ENT_QUOTES);
                  }
              }
              if (!is_array($args)) {
                  $args = explode("&",$args);
                  foreach ($args as $arg) {
                      $arg = explode("=",$arg);
                      $query[$dittoID.$arg[0]] = urlencode(trim($arg[1]));
                  }
              } else {
                  foreach ($args as $name=>$value) {
                      $query[$dittoID.$name] = urlencode(trim($value));
                  }
              }
              $queryString = "";
              foreach ($query as $param=>$value) {
                  $queryString .= '&'.$param.'='.(is_array($value) ? implode(",",$value) : $value);
              }
              $cID = ($id !== false) ? $id : $modx->documentObject['id'];
              $url = $modx->makeURL(trim($cID), '', $queryString);
              return ($modx->config['xhtml_urls']) ? $url : str_replace("&","&",$url);
      }
      


      File: assets/snippets/ditto/classes/template.class.inc.php

      // ---------------------------------------------------
      // Function: replace
      // Replcae placeholders with their values
      // ---------------------------------------------------
      // Change to PHP5.4 public static function
      // function replace( $placeholders, $tpl ) {
      public static function replace( $placeholders, $tpl ) {
          $keys = array();
          $values = array();
          foreach ($placeholders as $key=>$value) {
              $keys[] = '[+'.$key.'+]';
              $values[] = $value;
          }
          return str_replace($keys,$values,$tpl);
      }
      
      [ed. note: iusemodx last edited this post 11 years, 3 months ago.]
        • 16610
        • 634 Posts
        Thank you very much for sharing this!
          Mikko Lammi, Owner at Maagit
        • If you submit pull requests for these items it's possible they will be included in a future release, the other option would be looking into http://www.clippercms.com/ which is a fork of Evo being maintained by some of the community.
            Patrick | Server Wrangler
            About Me: Website | TweetsMODX Hosting
            • 13226
            • 953 Posts
            @Lammikko

            NO problem - I will continue to add information if I have further problems, I have a total of 25 sites that need to be looked at, so more information is possible.

            Quote from: AMDbuilder at Dec 10, 2012, 06:45 AM
            the other option would be looking into clippercms.com which is a fork of Evo being maintained by some of the community.

            Without mentioning names, I have had too much negative experience with the Clipper Dev team - one member in particular and I am no-longer interested in their community.

            Revolution is here and MODX 3 is supposedly around the corner, so I have no need for Clipper, any of my sites or my client sites that use Evo on long term will be self supported.

            Cheers
              • 30088
              • 47 Posts
              So, for the below, when you say "with our language code", did you mean timezone code?

              Quote from: iusemodx at Dec 08, 2012, 12:05 AM
              
              [b]Root Folder & Manager Folder[/b]
              
              For problems with the timezone we had to create a "php.ini" file with our language code in the root and the manager folder
              
              e.g date.timezone = Europe/London
              
              For a full list of European timezones [url=http://php.net/manual/en/timezones.europe.php]Click Here[/url]
              
              For a full list of American timezones [url=http://php.net/manual/en/timezones.america.php]Click Here[/url]
              
              
                • 13226
                • 953 Posts
                Quote from: tinuviel at Dec 16, 2012, 06:34 PM
                So, for the below, when you say "with our language code", did you mean timezone code?

                Although I thought this was / is apparent - yes, timezone

                I will change the wording in my original post.
                  • 3647
                  • 177 Posts
                  Does anyone know if these changes can be made OK on a site not running PHP5.4

                  i.e. make the changes now to future proof a site against an upgrade by the host?
                    • 13226
                    • 953 Posts
                    Quote from: bluespark at Jan 17, 2013, 03:12 PM
                    Does anyone know if these changes can be made OK on a site not running PHP5.4?

                    These changes work on (at least where I have tested) PHP version 5.2 +

                    I am using PHP 5.4.3 (local) and PHP 5.4.10 (live)

                    Hope that helps
                      • 3647
                      • 177 Posts
                      That's great thanks, I will have a go on a test site.