Exemplo n.º 1
0
 /**
  * Adds email to the queue
  * 
  * Even if there is a big amount of emails, there is always reserved 20% of traffic for immediate emails.
  * Such emails are: registration cofirmation, contact form data and other.
  * Newsletters, greetings always can wait a litle. So they are not immediate and will not be send if is less than 20% of traffic left.   
  *
  * @param string $from email address from whish an email should be send
  * @param string @from_name
  * @param string $to email address where an email should be send
  * @param string @to_name
  * @param string $email email html text
  * @param bool $immediate indicate hurry of an email.
  * @param bool $html true if email message should be send as html
  * @param array $files files that should be attached to the email. Files should be accessible for php at this moment. They will be cached until send time.      
  */
 function addEmail($from, $fromName, $to, $toName, $subject, $email, $immediate, $html, $files = null)
 {
     $cached_files = array();
     $cached_file_names = array();
     $cached_file_mime_types = array();
     if ($files) {
         foreach ($files as $key => $file) {
             $new_name = 'contact_form_' . rand();
             $new_name = \Library\Php\File\Functions::genUnocupiedName($new_name, TMP_FILE_DIR);
             if (copy($file['real_name'], TMP_FILE_DIR . $new_name)) {
                 $cached_files[] = TMP_FILE_DIR . $new_name;
                 $cached_file_names[] = $file['required_name'];
                 $tmpMimeType = \Library\Php\File\Functions::getMimeType($file['real_name']);
                 if ($tmpMimeType == null) {
                     $tmpMimeType = 'Application/octet-stream';
                 }
                 $cached_file_mime_types[] = $tmpMimeType;
             } else {
                 trigger_error('File caching failed');
             }
         }
     }
     $cachedFilesStr = implode("\n", $cached_files);
     $cachedFileNamesStr = implode("\n", $cached_file_names);
     $cachedFileMimeTypesStr = implode("\n", $cached_file_mime_types);
     $email = str_replace('src="' . BASE_URL, 'src="', $email);
     Db::addEmail($from, $fromName, $to, $toName, $subject, $email, $immediate, $html, $cachedFilesStr, $cachedFileNamesStr, $cachedFileMimeTypesStr);
 }
Exemplo n.º 2
0
 private function writeParametersToFile()
 {
     $parameters = new Parameters($_POST['language'], $_POST['types']);
     $fileName = '';
     foreach ($_POST['modules'] as $groupKey => $group) {
         foreach ($group as $moduleKey => $value) {
             if ($fileName == '') {
                 $fileName = "ip_" . htmlspecialchars($groupKey) . "_" . htmlspecialchars($moduleKey) . " " . date("Y-m-d") . ".php";
             }
             $parameters->loadParameters($value);
         }
     }
     $fileName = \Library\Php\File\Functions::genUnocupiedName($fileName, TMP_FILE_DIR);
     $fh = fopen(TMP_FILE_DIR . $fileName, 'w');
     if ($fh) {
         fwrite($fh, $this->generateConfigurationFile($parameters));
         fclose($fh);
         return $fileName;
     } else {
         trigger_error("can't open file " . $TMP_FILE_DIR . $fileName);
     }
     return false;
 }
Exemplo n.º 3
0
 function update_photo($photo_id, $number, $values)
 {
     $new_name = $values['new_photo' . $number];
     if (isset($values['new_photo' . $number]) && $values['new_photo' . $number] != null) {
         $new_name = \Library\Php\File\Functions::genUnocupiedName($new_name, BASE_DIR . IMAGE_DIR);
         copy(TMP_IMAGE_DIR . $values['new_photo' . $number], IMAGE_DIR . $new_name);
     }
     $sql = "update `" . DB_PREF . "mc_text_photos_logo_gallery_logo` set link = '" . mysql_real_escape_string($values['title' . $number]) . "', row_number = '" . (int) $number . "' where id = '" . (int) $photo_id . "'";
     $rs = mysql_query($sql);
     if (!$rs) {
         $this->set_error("Can't update new photo " . $sql);
     }
 }
Exemplo n.º 4
0
 function processUpdate($prefix, $id, $area)
 {
     if ($this->visibleOnUpdate && !$this->disabledOnUpdate) {
         if (isset($_POST[$prefix . '_delete']) && !$this->required || isset($this->memFile) && $this->memFile != '') {
             $sql = "select `" . $this->dbField . "` as existing_file from `" . DB_PREF . "" . $area->dbTable . "` where `" . $area->dbPrimaryKey . "` = '" . mysql_real_escape_string($id) . "' ";
             $rs = mysql_query($sql);
             if ($rs) {
                 if ($lock = mysql_fetch_assoc($rs)) {
                     if ($lock['existing_file'] != "" && file_exists($this->destDir . $lock['existing_file'])) {
                         unlink($this->destDir . $lock['existing_file']);
                     }
                 }
             } else {
                 trigger_error("Can't get field to update " . $sql);
                 return;
             }
         }
         // delete file selected
         if (isset($_POST[$prefix . '_delete']) && !$this->required) {
             $sql = "update `" . DB_PREF . "" . $area->dbTable . "` set `" . $this->dbField . "` = NULL where `" . $area->dbPrimaryKey . "` = '" . mysql_real_escape_string($id) . "' ";
             $rs = mysql_query($sql);
             if (!$rs) {
                 trigger_error("Can't update photo field " . $sql);
             }
         }
         // eof delete file selected
         if (isset($this->memFile) && $this->memFile != '') {
             require_once LIBRARY_DIR . 'php/file/functions.php';
             $newName = \Library\Php\File\Functions::genUnocupiedName($this->memFile, $this->destDir);
             if (copy(TMP_FILE_DIR . $this->memFile, $this->destDir . $newName)) {
                 $sql = "update `" . DB_PREF . "" . $area->dbTable . "` set `" . $this->dbField . "` = '" . $newName . "' where `" . $area->dbPrimaryKey . "` = '" . mysql_real_escape_string($id) . "' ";
                 $rs = mysql_query($sql);
                 if (!$rs) {
                     trigger_error("Can't update photo field " . $sql);
                 }
             } else {
                 trigger_error("Can't copy file from " . htmlspecialchars(TMP_FILE_DIR . $this->memFile) . " to " . htmlspecialchars($this->destDir . $newName));
             }
         }
     }
 }
Exemplo n.º 5
0
 function update($values)
 {
     if (isset($values['new_photo']) && $values['new_photo'] != null) {
         if (isset($values['existing_photo']) && $values['existing_photo'] != null) {
             if ($values['existing_photo'] != '' && file_exists(IMAGE_DIR . $values['existing_photo'])) {
                 if (!unlink(IMAGE_DIR . $values['existing_photo'])) {
                     $this->set_error("Can't delete old photo.");
                 }
             }
         }
         if (isset($values['existing_bigphoto']) && $values['existing_bigphoto'] != null) {
             if ($values['existing_bigphoto'] != '' && file_exists(IMAGE_DIR . $values['existing_bigphoto'])) {
                 if (!unlink(IMAGE_DIR . $values['existing_bigphoto'])) {
                     $this->set_error("Can't delete old photo.");
                 }
             }
         }
         $new_name = $values['new_photo'];
         if ($new_name != "") {
             $new_name = \Library\Php\File\Functions::genUnocupiedName($new_name, BASE_DIR . IMAGE_DIR);
             copy(TMP_IMAGE_DIR . $values['new_photo'], IMAGE_DIR . $new_name);
         }
         $new_bigname = $values['new_bigphoto'];
         if ($new_bigname != "") {
             $new_bigname = \Library\Php\File\Functions::genUnocupiedName($new_bigname, BASE_DIR . IMAGE_DIR);
             copy(TMP_IMAGE_DIR . $values['new_bigphoto'], IMAGE_DIR . $new_bigname);
         }
     } else {
         $new_name = $values['existing_photo'];
         $new_bigname = $values['existing_bigphoto'];
     }
     $sql = "update `" . DB_PREF . "content_element_to_modules` set visible='" . (int) $values['visible'] . "', row_number = '" . (int) $values['row_number'] . "' where module_id = '" . (int) $values['id'] . "' and group_key = '" . mysql_real_escape_string(GROUP_KEY) . "' and module_key = '" . mysql_real_escape_string(MODULE_KEY) . "'   ";
     if (!mysql_query($sql)) {
         return "Can't update module row number" . $sql;
     } else {
         $sql = "update `" . DB_PREF . "mc_text_photos_text_photo` set title = '" . mysql_real_escape_string($values['title']) . "', layout = '" . mysql_real_escape_string($values['layout']) . "', `text` = '" . mysql_real_escape_string($values['text']) . "', photo = '" . mysql_real_escape_string($new_name) . "', photo_big = '" . mysql_real_escape_string($new_bigname) . "' where id = '" . (int) $values['id'] . "'  ";
         if (!mysql_query($sql)) {
             $this->set_error("Can't update module " . $sql);
         }
     }
     return;
 }
Exemplo n.º 6
0
 /**
  * @param string $post_name
  * @param string $destDir typicaly IMAGE_URL or TMP_IMAGE_URL
  * @return int error code. UPLOAD_ERR_OK on success
  */
 function upload($postName, $destDir)
 {
     $this->fileName = '';
     $answer['name'] = '';
     $error = $this->getError($postName);
     if ($error == UPLOAD_ERR_OK) {
         //if($this->is_uploaded($postName)){
         $newName = \Library\Php\File\Functions::genUnocupiedName($_FILES[$postName]['name'], $destDir);
         if (move_uploaded_file($_FILES[$postName]['tmp_name'], $destDir . $newName)) {
             $this->fileName = $newName;
             return UPLOAD_ERR_OK;
         } else {
             return UPLOAD_ERR_CANT_WRITE;
         }
     } else {
         return $error;
     }
     return false;
 }
Exemplo n.º 7
0
 /**
  * @param string $postName
  * @param int $widthT required width
  * @param int $heightT required height
  * @param string $destDir typicaly IMAGE_URL or TMP_IMAGE_URL
  * @param string $type
  * Available types:
  *  fit - resize to fit
  *  crop - crop image if it don't fit
  *  width - resize to width
  *  height - resize to height   
  * @param bool $forced if true, resizes image even if she fits to specified size (is smaller than required)
  * @param int $quality from 0 (biggest compression) to  100 (best quality)
  * @return int error code. UPLOAD_ERR_OK on success
  */
 function upload($postName, $widthT, $heightT, $destDir, $type, $forced, $quality)
 {
     $this->fileName = '';
     $answer['name'] = '';
     $error = $this->getError($postName);
     if ($error == UPLOAD_ERR_OK) {
         $imageSize = getimagesize($_FILES[$postName]['tmp_name']);
         if ($this->resizeRequired($imageSize[0], $imageSize[1], $widthT, $heightT, $type, $forced)) {
             $memory_success = $this->getMemmoryNeeded($imageSize);
             if (!$memory_success) {
                 return UPLOAD_ERR_INI_SIZE;
             }
             if ($image = $this->createImage($postName)) {
                 if ($forced || $widthT < $imageSize[0] || $heightT < $imageSize[1]) {
                     $image = $this->resize($image, $widthT, $heightT, $imageSize[0], $imageSize[1], $type);
                 }
                 //generate unocupied file name
                 $newName = $_FILES[$postName]['name'];
                 if ($_FILES[$postName]['type'] == "image/gif") {
                     $newName = substr($newName, -4, 4) . '.png';
                 }
                 //gif are converted top PNG
                 $newName = \Library\Php\File\Functions::genUnocupiedName($newName, $destDir);
                 switch ($_FILES[$postName]['type']) {
                     case 'image/gif':
                     case 'image/png':
                         //png quality is from 0 (no compression) to 9
                         $tmpQuality = $quality / 10;
                         $tmpQuality = 9 - $tmpQuality;
                         if ($tmpQuality < 0) {
                             $tmpQuality = 0;
                         }
                         if (imagepng($image, $destDir . $newName, $tmpQuality)) {
                             $this->fileName = $newName;
                             return UPLOAD_ERR_OK;
                         } else {
                             return UPLOAD_ERR_CANT_WRITE;
                         }
                         break;
                     case 'image/pjpeg':
                     case 'image/jpeg':
                     default:
                         if (imagejpeg($image, $destDir . $newName, $quality)) {
                             $this->fileName = $newName;
                             return UPLOAD_ERR_OK;
                         } else {
                             return UPLOAD_ERR_CANT_WRITE;
                         }
                         break;
                 }
             } else {
                 return UPLOAD_ERR_CANT_WRITE;
             }
         } else {
             $newName = \Library\Php\File\Functions::genUnocupiedName($_FILES[$postName]['name'], $destDir);
             copy($_FILES[$postName]['tmp_name'], $destDir . $newName);
             $this->fileName = $newName;
             return UPLOAD_ERR_OK;
         }
     } else {
         return $error;
     }
     return false;
 }
Exemplo n.º 8
0
 function process_update($prefix, $area, $id)
 {
     global $parametersMod;
     // delete photo selected
     if (isset($_POST[$prefix . '_delete']) && !$this->required) {
         foreach ($this->copies as $key => $copy) {
             $sql = "select `" . $copy['db_field'] . "` as existing_photo from `" . DB_PREF . "" . $area->get_db_table() . "` where " . $area->get_db_key() . " = '" . $id . "' ";
             $rs = mysql_query($sql);
             if ($rs) {
                 if ($lock = mysql_fetch_assoc($rs)) {
                     if ($lock['existing_photo'] != "" && file_exists($copy['dest_dir'] . $lock['existing_photo'])) {
                         unlink($copy['dest_dir'] . $lock['existing_photo']);
                     }
                 }
             } else {
                 trigger_error("Can't get field to update " . $sql);
                 return;
             }
         }
         foreach ($this->copies as $key => $copy) {
             $sql = "update `" . DB_PREF . "" . $area->get_db_table() . "` set `" . $copy['db_field'] . "` = NULL where " . $area->get_db_key() . " = '" . $id . "' ";
             $rs = mysql_query($sql);
             if (!$rs) {
                 trigger_error("Can't update photo field " . $sql);
             }
         }
     }
     // eof delete photo selected
     if (sizeof($this->mem_images) == sizeof($this->copies)) {
         require_once LIBRARY_DIR . 'php/file/functions.php';
         foreach ($this->copies as $key => $copy) {
             $new_name = \Library\Php\File\Functions::genUnocupiedName($this->mem_images[$key], $copy['dest_dir']);
             if (copy(TMP_IMAGE_DIR . $this->mem_images[$key], $copy['dest_dir'] . $new_name)) {
                 $sql = "update `" . DB_PREF . "" . $area->get_db_table() . "` set `" . $copy['db_field'] . "` = '" . $new_name . "' where " . $area->get_db_key() . " = '" . $id . "' ";
                 $rs = mysql_query($sql);
                 if (!$rs) {
                     trigger_error("Can't update photo field " . $sql);
                 }
             } else {
                 trigger_error("Can't copy file from " . htmlspecialchars(TMP_IMAGE_DIR . $this->mem_images[$key]) . " to " . htmlspecialchars($copy['dest_dir'] . $new_name));
             }
         }
     }
 }
Exemplo n.º 9
0
 function update($values)
 {
     if (isset($values['new_photo']) && $values['new_photo'] != null) {
         if (isset($values['existing_photo']) && $values['existing_photo'] != null) {
             if (file_exists(FILE_DIR . $values['existing_photo'])) {
                 if ($values['existing_photo'] != '' && file_exists(FILE_DIR . $values['existing_photo'])) {
                     if (!unlink(FILE_DIR . $values['existing_photo'])) {
                         $this->set_error("Can't delete old photo.");
                     }
                 }
             }
         }
         $new_name = $values['new_photo'];
         if ($new_name != "") {
             $new_name = \Library\Php\File\Functions::genUnocupiedName($new_name, BASE_DIR . FILE_DIR);
             copy(TMP_FILE_DIR . $values['new_photo'], FILE_DIR . $new_name);
         }
     } else {
         $new_name = $values['existing_photo'];
     }
     $sql = "update `" . DB_PREF . "content_element_to_modules` set `visible`='" . (int) $values['visible'] . "',`row_number` = '" . (int) $values['row_number'] . "' where `module_id` = '" . (int) $values['id'] . "' and `group_key` = '" . mysql_real_escape_string(GROUP_KEY) . "' and `module_key` = '" . mysql_real_escape_string(MODULE_KEY) . "'   ";
     if (!mysql_query($sql)) {
         return "Can't update module row number" . $sql;
     } else {
         $sql = "update `" . DB_PREF . "mc_misc_file` set `layout` = '" . mysql_real_escape_string($values['layout']) . "', `title` = '" . mysql_real_escape_string($values['title']) . "', `photo` = '" . mysql_real_escape_string($new_name) . "' where `id` = '" . (int) $values['id'] . "' ";
         if (!mysql_query($sql)) {
             $this->set_error("Can't update module " . $sql);
         }
     }
     return;
 }