Koozali.org: home of the SME Server

PHP code to convert full URL to relative URL in an ibay

brthacker

PHP code to convert full URL to relative URL in an ibay
« on: March 31, 2009, 05:11:37 PM »
On SME 7.4, I have an install of moodle (1.9) in an ibay called "courses" and an installation of wikindx3 (3.8) in an ibay called "wikindx". There is a filter for Moodle that will call wikindx and list properly formatted bibliographics entires. However, this filter requires a "temp" folder in the moodle installation with read-write for the www account. I have set everything up according to the directions, but I think the PHP code in the filter is having issues with converting an absolute path to a relative path for the temp folder since I get an error that the file cannot be read (I have checked all the permissions). Maybe someone can help me with the snippet of code to see if it's causing my issues:

Quote
// Need to convert full URL of /temp file to a relative URL.
   
    $u = $CFG->wwwroot;

    if(preg_match('|https?://.*?/|', $u)){
        $relurl = preg_replace('|https?://.*?/|', '', $u);
    }else{
        $relurl = ''; // This will typically be the case if Moodle is the web root
    }
    $numdirs = substr_count($_SERVER['PHP_SELF'], '/') - 1;
    if($numdirs==0){
        $relurl = './' . $relurl;
    }else{
        $relurl = str_repeat('../', $numdirs) . $relurl;
    }

    // Setup relative and absolute filepaths

    $session_handle = session_id();
    $tempfilesubdirectory = '/temp/'; // directory where temporary file will be stored - chmod 777
    $tempfilename = "" . sha1($session_handle).".txt";
    $tempfilepathname = $relurl . $tempfilesubdirectory . $tempfilename;
    $oldpathfilename = $tempfilepathname;
    $serverpathtowiki = $CFG->filter_wikindx_baseurl;
    $serverpathtotempfile = $CFG->wwwroot . $tempfilesubdirectory . $tempfilename;
    // create handle for temporary file for link to Wikindx server

    if(!$handle = fopen($tempfilepathname, 'w')) {
        echo "Cannot open file ($tempfilename)";
        return $text;
    }

I've tried various locations in the "$relurl = ''; // This..." field to no avail.

Thanks for any help!

Brian Thacker

Offline chris burnat

  • *****
  • 1,135
  • +2/-0
    • http://www.burnat.com
Re: PHP code to convert full URL to relative URL in an ibay
« Reply #1 on: March 31, 2009, 10:35:45 PM »
Brian, welcome to Contribs.org.
Moving this post to the contributions section (as opposed to SMEserver 7.x section reserved for core issues).
- chris
If it does not work out of the box, please fill in a Bug Report @ Bugzilla (http://bugs.contribs.org)  - check: http://wiki.contribs.org/Bugzilla_Help .  Thanks.