Ejemplo n.º 1
0
 private function _makePublicUrl($fieldname, $filename)
 {
     // ensure the publicly visible folder exists
     if (!file_exists(Config::GetInstance()->getStorageFolder(4))) {
         mkdir(Config::GetInstance()->getStorageFolder(4));
     }
     // use the rules to find out where the file is
     if (Config::GetInstance()->GetRulePropertyByName($fieldname, 'files') == true) {
         if (!copy(Config::GetInstance()->getStorageFolder(1) . $filename, Config::GetInstance()->getStorageFolder(4) . $filename)) {
             writeErrorLog('MailChimp plugin couldn\'t copy the uploaded file to a public folder', $filename);
             $this->setError(_T('Failed to copy the uploaded file %s to a publicly visible folder.', $filename));
             return;
         }
     } else {
         // look for it in the uploads table
         if (isset($_FILES[$fieldname]) && file_exists($_FILES[$fieldname]['tmp_name'])) {
             $filename = SaveUploadAsFile(Config::GetInstance()->getStorageFolder(4), $_FILES[$fieldname]);
             if ($filename == false) {
                 writeErrorLog('MailChimp plugin couldn\'t move the uploaded file to a public folder', $filename);
                 $this->setError(_T('Failed to move the uploaded file %s to a publicly visible folder.', $filename));
                 return;
             }
         }
     }
     $servername = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
     $path = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF'];
     $path = substr($path, 0, strrpos($path, '/'));
     // encode the folders, not the '/'!
     $tmp = explode('/', $path);
     for ($i = 0; $i < count($tmp); ++$i) {
         $tmp[$i] = rawurlencode($tmp[$i]);
     }
     $path = implode('/', $tmp);
     // windows servers may set [HTTPS] => off, linux server usually don't set [HTTPS] at all
     if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
         $protocol = 'https';
     } else {
         $protocol = 'http';
     }
     $url = $protocol . '://' . $servername;
     // only add the serverport when it differs from the default
     if (strpos($servername, ':') === false && ($_SERVER['SERVER_PORT'] != '80' || $protocol != 'http')) {
         $url .= ':' . $_SERVER['SERVER_PORT'];
     }
     return $url . $path . '/' . FormPage::GetInstance()->GetFormName() . CC_FB_STORAGE_FOLDER . CC_FB_PUBLIC_DIRECTORY . $filename;
 }
Ejemplo n.º 2
0
 private function _SaveUploadsAsFiles()
 {
     $dest = Config::GetInstance()->GetStorageFolder(1);
     $tempuploads = array();
     if (!is_dir($dest) && !mkdir($dest, 0755)) {
         $this->errors[] = array("err" => _T('Could not create file upload directory "%s"', $dest));
         return;
     }
     foreach ($_FILES as $fieldname => $filedata) {
         if (empty($filedata['tmp_name'])) {
             continue;
         }
         // it isn't a upload if the file isn't mentioned in the rules
         if (Config::GetInstance()->GetRulePropertyByName($fieldname, 'fieldtype') != 'fileupload') {
             continue;
         }
         // check if the file must be saved on the server
         if (!Config::GetInstance()->GetRulePropertyByName($fieldname, 'files')) {
             // store the name in post
             $this->post[strtolower($fieldname)] = $filedata['name'];
             // without payments - emailer looks for the file in its temp storage
             // with payments and JS - emailer is called from the checkout screen, thus we need
             // 		to move the file to our own temp storage.
             if (Config::GetInstance()->UsePayments() && Config::GetInstance()->GetSessionVariable(CC_FB_JSENABLED) && Config::GetInstance()->GetRulePropertyByName($fieldname, 'attach')) {
                 $tempname = SaveUploadAsFile(Config::GetInstance()->GetStorageFolder(5), $filedata);
                 if ($tempname !== false) {
                     $tempuploads[strtolower($fieldname)] = $tempname;
                 }
             }
             continue;
         }
         $storedname = SaveUploadAsFile($dest, $filedata);
         // add it to post, mailer needs it if the file is to be attached
         if ($storedname !== false) {
             $this->post[strtolower($fieldname)] = $storedname;
         }
         // remember which files are stored for which fields, we need that info
         // when reporting data, because in that context we don't have access to the rules
         $this->uploads[] = array('orgname' => $filedata['name'], 'storedname' => $storedname, 'fieldname' => strtolower($fieldname));
     }
     if (count($tempuploads) > 0) {
         Config::GetInstance()->SetSessionVariable(CC_FB_TEMPUPLOADS, $tempuploads);
     }
 }