if (empty($core['mails'])) {
     continue;
 }
 $_GET['core'] = $coreName;
 $_SERVER['SERVER_NAME'] = $coreName . '.casebox.org';
 include $site_path . DIRECTORY_SEPARATOR . 'config.php';
 include $site_path . DIRECTORY_SEPARATOR . 'lib/language.php';
 $templateIds = Templates::getIdsByType('comment');
 if (empty($templateIds)) {
     \CB\debug('receive comments cron: no comment template defined');
     continue;
 }
 $templateId = array_shift($templateIds);
 $commentsObj = Objects::getCustomClassByType('comment');
 foreach ($core['mails'] as $mail) {
     if (!Objects::idExists($mail['pid'])) {
         \CB\debug('receive comments cron: target id not found for mail "' . $mail['subject'] . '"');
         continue;
     }
     $emailFrom = extractEmailFromText($mail['from']);
     // user email
     $emailTo = extractEmailFromText($mail['to']);
     // <*****@*****.**>
     $userId = DM\User::getIdByEmail($emailFrom);
     $_SESSION['user'] = array('id' => $userId);
     $data = array('id' => null, 'pid' => $mail['pid'], 'oid' => $userId, 'cid' => $userId, 'template_id' => $templateId, 'data' => array('_title' => removeContentExtraBlock($mail['content'], $emailFrom, $emailTo)), 'sys_data' => array('mailId' => $mail['id']));
     try {
         $commentId = $commentsObj->create($data);
         //add attachments
         if (!empty($mail['attachments'])) {
             saveObjectAttachments($commentId, $mail['attachments']);
Beispiel #2
0
 public function saveFile($p)
 {
     $incommingFilesDir = Config::get('incomming_files_dir');
     $files = new Files();
     /* clean previous unhandled uploads if any */
     $a = $files->getUploadParams();
     if ($a !== false && !empty($a['files'])) {
         @unlink($incommingFilesDir . $_SESSION['key']);
         $files->removeIncomingFiles($a['files']);
     }
     /* end of clean previous unhandled uploads if any */
     $F =& $_FILES;
     if (empty($p['pid'])) {
         return array('success' => false, 'msg' => L\get('Error_uploading_file'));
     }
     $p['pid'] = Path::detectRealTargetId($p['pid']);
     if (empty($F)) {
         //update only file properties (no files were uploaded)
         return $files->updateFileProperties($p);
     } else {
         foreach ($F as $k => $v) {
             $F[$k]['name'] = Purify::filename(@$F[$k]['name']);
         }
     }
     if (!Objects::idExists($p['pid'])) {
         return array('success' => false, 'msg' => L\get('TargetFolderDoesNotExist'));
     }
     /*checking if there is no upload error (for any type of upload: single, multiple, archive) */
     foreach ($F as $fn => $f) {
         if (!in_array($f['error'], array(UPLOAD_ERR_OK, UPLOAD_ERR_NO_FILE))) {
             return array('success' => false, 'msg' => L\get('Error_uploading_file') . ': ' . $f['error']);
         }
     }
     /* retreiving files list  */
     switch (@$p['uploadType']) {
         case 'archive':
             $archiveFiles = array();
             foreach ($F as $fk => $f) {
                 $files->extractUploadedArchive($F[$fk]);
                 $archiveFiles = array_merge($archiveFiles, $F[$fk]);
             }
             $F = $archiveFiles;
             break;
         default:
             $files->moveUploadedFilesToIncomming($F) or die('cannot move file to incomming dir');
             break;
     }
     $p['existentFilenames'] = $files->getExistentFilenames($F, $p['pid']);
     $p['files'] =& $F;
     if (!empty($p['existentFilenames'])) {
         //check if can write target file
         if (!Security::canWrite($p['existentFilenames'][0]['existentFileId'])) {
             return array('success' => false, 'msg' => L\get('Access_denied'));
         }
         // store current state serialized in a local file in incomming folder
         $files->saveUploadParams($p);
         if (!empty($p['response'])) {
             //it is supposed to work only for single files upload
             return $this->confirmUploadRequest($p);
         }
         $allow_new_version = false;
         foreach ($p['existentFilenames'] as $f) {
             $mfvc = Files::getMFVC($f['name']);
             if ($mfvc > 0) {
                 $allow_new_version = true;
             }
         }
         $rez = array('success' => false, 'type' => 'filesexist', 'allow_new_version' => $allow_new_version, 'count' => sizeof($p['existentFilenames']));
         if ($rez['count'] == 1) {
             $rez['msg'] = empty($p['existentFilenames'][0]['msg']) ? str_replace('{filename}', '"' . $p['existentFilenames'][0]['name'] . '"', L\get('FilenameExistsInTarget')) : $p['existentFilenames'][0]['msg'];
             //$rez['filename'] = $p['existentFilenames'][0]['name'];
             $rez['suggestedFilename'] = $p['existentFilenames'][0]['suggestedFilename'];
         } else {
             $rez['msg'] = L\get('SomeFilenamesExistsInTarget');
         }
         return $rez;
     } else {
         //check if can write in target folder
         if (!Security::canWrite($p['pid'])) {
             return array('success' => false, 'msg' => L\get('Access_denied'));
         }
     }
     $files->storeFiles($p);
     //if everithing is ok then store files
     Solr\Client::runCron();
     $rez = array('success' => true, 'data' => array('pid' => $p['pid']));
     $files->attachPostUploadInfo($F, $rez);
     return $rez;
 }