예제 #1
0
function photos_upload()
{
    require MODELS . "photo.php";
    require MODELS . "users.php";
    $cur_user = users_getCurrentUser();
    if ($cur_user['id'] > 0) {
        if ($_SERVER['REQUEST_METHOD'] == "POST") {
            if ($_FILES['file']['error'] == 0) {
                $name = $_POST['name'];
                $album = $_POST['album'];
                $filename = generate_filename($_FILES['file']['name']);
                if (move_uploaded_file($_FILES['file']['tmp_name'], ROOT . "files/{$filename}")) {
                    photos_insert($name, '', $filename, $cur_user['id'], $album);
                    header('location: ' . WEB);
                    exit;
                }
            }
        } else {
            require MODELS . "albums.php";
            $albums = albums_getByUser($cur_user);
            if (isset($_GET['albumId'])) {
                $album_id = $_GET['albumId'];
            } else {
                $album_id = -100500;
            }
            require VIEWS . "upload.php";
        }
    } else {
        header('location:' . WEB . '/login');
    }
}
예제 #2
0
 public function uploadImageAjax(Request $request)
 {
     $path = public_path('upload');
     if ($request->ajax()) {
         $file = $request->file('fileToUpload');
         $filename = generate_filename($path, $file->getClientOriginalExtension());
         try {
             $file->move($path, $filename);
             $file = '/upload/' . $filename;
             $data = ['message' => 'uploadSuccess', 'file' => $file];
         } catch (FileException $e) {
             $data = ['message' => 'uploadError'];
         }
     } else {
         $data = ['message' => 'uploadNotAjax', 'formData' => Input::all()];
     }
     return new JsonResponse($data);
 }
 /**
  * Generate the file name base on current user id, time
  * to get a unique file in present directory
  *
  * @param string $directory Path to the upload directory
  * @param string $extension File extension
  * @param array  $options   Prefix, suffix,...
  *
  * @return string
  */
 function generate_filename($directory, $extension, $options = [])
 {
     $userId = 0;
     $microtime = microtime(true);
     $randStr = str_random(10);
     if (auth()->check()) {
         $userId = user()->id;
     }
     $prefix = isset($options['prefix']) ? $options['prefix'] : '';
     $suffix = isset($options['suffix']) ? $options['suffix'] : '';
     $nameEncoding = md5($userId . $microtime . $randStr);
     $fileName = $prefix . $nameEncoding . $suffix . '.' . $extension;
     while (check_file($directory . $fileName)) {
         $fileName = generate_filename($directory, $extension . $prefix);
     }
     return $fileName;
 }
예제 #4
0
 private function _uploadMiniature($file)
 {
     $path = public_path('upload');
     $filename = generate_filename($path, $file->getClientOriginalExtension());
     $file->move($path, $filename);
     return $filename;
 }
function generate_final_video_frames($converted_avatars, $uid, $dir = 'data', $videos_frames)
{
    include get_template_directory() . '/video_libs/libs.php';
    $frames = array();
    $i = 1;
    $converted_path = $dir . "/{$uid}/frames";
    if (!file_exists("{$converted_path}")) {
        exec("mkdir -p {$converted_path}");
    }
    exec("chmod 777 -R {$converted_path}");
    exec("rm -rf {$converted_path}/*");
    #include get_template_directory() . '/video_libs/data.php';
    /*include get_template_directory() . '/video_libs/data_live.php';
    
        $videos_frames = get_data_videos($_REQUEST['uid'], $_REQUEST['eid']);*/
    foreach ($videos_frames as $key => $value) {
        $name = generate_filename($i);
        $filename = $value->imageFrame;
        $curr_frame = "{$converted_path}/{$name}";
        $frames[] = $curr_frame;
        $text_objs = isset($value->text) ? $value->text : array();
        $image_objs = isset($value->imageFace) ? $value->imageFace : array();
        if (array_key_exists($filename, $converted_avatars) && !empty($converted_avatars[$filename])) {
            if (!empty($image_objs)) {
                foreach ($image_objs as $image_obj) {
                    $order = $image_obj->order;
                    if ($order == 'back') {
                        $msg = exec("convert {$converted_avatars[$filename]} {$filename} -composite {$curr_frame}");
                    } else {
                        $msg = exec("convert {$filename} {$converted_avatars[$filename]} -composite {$curr_frame}");
                    }
                }
            }
        } else {
            exec("cp {$filename} {$curr_frame}");
        }
        $w = 210;
        if (!empty($text_objs)) {
            foreach ($text_objs as $text_obj) {
                $picin = new Imagick($curr_frame);
                $draw = new ImagickDraw();
                $draw->setTextEncoding('utf-8');
                $draw->setFillColor("rgba(255, 255, 255, {$text_obj->opacity})");
                $draw->setFont($text_obj->font);
                $draw->setFontSize($text_obj->size);
                $positions = explode(',', $text_obj->position);
                //list($lines, $lineHeight)= wordWrapAnnotation($picin, $draw, $text_obj->text, $w-10);
                if (!empty($text_obj->break) && $text_obj->break == 'yes') {
                    $y = $positions[1];
                    $line_height = 55;
                    $str = wordwrap($text_obj->text, 19, "\n");
                    $str_array = explode("\n", $str);
                    foreach ($str_array as $line) {
                        $picin->annotateImage($draw, $positions[0], $y, 0, $line);
                        $y += $line_height;
                    }
                } else {
                    $picin->annotateImage($draw, $positions[0], $positions[1], 0, $text_obj->text);
                }
                //$picin->annotateImage($draw, $positions[0], $positions[1], 0, $text_obj->text);
                //$picin->annotateImage($draw, $positions[0], $positions[1], 0, $lines);
                $picin->writeimage($curr_frame);
                /*if( strpos($filename, '110.png')){
                      echo '<pre>';
                      print_r($image_obj);
                      echo '</pre>';
                      echo 'aaaa';die;
                  }*/
            }
        }
        $i++;
    }
    return $frames;
}
예제 #6
0
파일: logs.php 프로젝트: rhotog/fabrik
 /**
  * perform log
  *
  * @param	object	$params
  * @param	object	form model
  * @param	string	message type
  * @returns	bool
  */
 protected function log($params, $formModel, $messageType)
 {
     $this->formModel = $formModel;
     $app = JFactory::getApplication();
     $db = FabrikWorker::getDBO();
     $query = $db->getQuery(true);
     $rowid = JRequest::getVar('rowid', '');
     $loading = strstr($messageType, 'form.load');
     $http_referrer = JRequest::getVar('HTTP_REFERER', 'no HTTP_REFERER', 'SERVER');
     $user = JFactory::getUser();
     $userid = $user->get('id');
     $username = $user->get('username');
     // Generate random filename
     if ($params->get('logs_random_filename') == 1) {
         function generate_filename($length)
         {
             $key = "";
             $possible = "0123456789bcdfghjkmnpqrstvwxyzBCDFGHJKLMNPQRTVWXYZ";
             $i = 0;
             while ($i < $length) {
                 $char = substr($possible, mt_rand(0, strlen($possible) - 1), 1);
                 $key .= $char;
                 $i++;
             }
             return $key;
         }
         $random_filename = '_' . generate_filename($params->get('logs_random_filename_length'));
     } else {
         $random_filename = '';
     }
     $w = new FabrikWorker();
     $logs_path = $w->parseMessageForPlaceHolder($params->get('logs_path'));
     if (strpos($logs_path, DS) !== 0) {
         $logs_path = JPATH_ROOT . DS . $logs_path;
     }
     $logs_path = rtrim($logs_path, DS);
     if (!JFolder::exists($logs_path)) {
         if (!JFolder::create($logs_path)) {
             return;
         }
     }
     $ext = $params->get('logs_file_format');
     $sep = $params->get('logs_separator');
     // Making complete path + filename + extension
     $w = new FabrikWorker();
     $logs_file = $logs_path . DS . $w->parseMessageForPlaceHolder($params->get('logs_file')) . $random_filename . '.' . $ext;
     $logs_mode = $params->get('logs_append_or_overwrite');
     $date_element = $params->get('logs_date_field');
     $date_now = $params->get('logs_date_now');
     // COMPARE DATA
     $result_compare = '';
     if ($params->get('compare_data')) {
         if ($ext == 'csv') {
             $sep_compare = '';
             $sep_2compare = '/ ';
         } else {
             if ($ext == 'txt') {
                 $sep_compare = "\n";
                 $sep_2compare = "\n";
             } else {
                 if ($ext == 'htm') {
                     $sep_compare = '<br/>';
                     $sep_2compare = '<br/>';
                 }
             }
         }
         if ($loading) {
             $result_compare = JText::_('COMPARE_DATA_LOADING') . $sep_2compare;
         } else {
             $data = $this->getEmailData();
             $newData = $this->getNewData($formModel);
             if (!empty($data)) {
                 $post = JRequest::get('post');
                 $elementModel = JModel::getInstance('element', 'FabrikModel');
                 $element = $elementModel->getElement(true);
                 $tableModel = $formModel->getTable();
                 $origDataCount = count(array_keys(JArrayHelper::fromObject($formModel->_origData[0])));
                 if ($origDataCount > 0) {
                     $c = 0;
                     $origData = $formModel->_origData;
                     $log_elements = explode(',', str_replace(' ', '', $params->get('logs_element_list', '')));
                     $groups = $formModel->getGroupsHiarachy();
                     foreach ($groups as $groupModel) {
                         $group = $groupModel->getGroup();
                         $elementModels = $groupModel->getPublishedElements();
                         foreach ($elementModels as $elementModel) {
                             $element = $elementModel->getElement();
                             $fullName = $elementModel->getFullName(false, true, false);
                             if (empty($log_elements) || in_array($fullName, $log_elements)) {
                                 if ($newData[$c]->{$fullName} != $origData[$c]->{$fullName}) {
                                     $result_compare .= JText::_('COMPARE_DATA_CHANGE_ON') . ' ' . $element->label . ' ' . $sep_compare . JText::_('COMPARE_DATA_FROM') . ' ' . $origData[0]->{$fullName} . ' ' . $sep_compare . JText::_('COMPARE_DATA_TO') . ' ' . $newData[$c]->{$fullName} . ' ' . $sep_2compare;
                                 }
                             }
                         }
                     }
                     if (empty($result_compare)) {
                         $result_compare = JText::_('COMPARE_DATA_NO_DIFFERENCES');
                     }
                 } else {
                     $result_compare .= "New record:" . $sep_2compare;
                     foreach ($data as $key => $val) {
                         if (isset($val) && substr($key, -4, 4) != '_raw') {
                             $result_compare .= "{$key} : {$val}" . $sep_2compare;
                         }
                     }
                 }
             } else {
                 $result_compare = "No data to compare!";
             }
         }
     }
     // Defining the date to use - Not used anymore as logs should really only record the current time_date
     if ($date_now != '') {
         $date = date("{$date_now}");
     } else {
         $date = date("Y-m-d H:i:s");
     }
     // Custom Message
     if ($params->get('custom_msg') != '') {
         $rep_add_edit = $messageType == 'form.add' ? JText::_('REP_ADD') : ($messageType == 'form.edit' ? JText::_('REP_EDIT') : JText::_('DETAILS'));
         $custom_msg = $params->get('custom_msg');
         $custom_msg = preg_replace('/{Add\\/Edit}/', $rep_add_edit, $custom_msg);
         $custom_msg = preg_replace('/{DATE}/', $date, $custom_msg);
         $excl_clabels = preg_replace('/([-{2}| |"][0-9a-zA-Z.:$_>]*)/', '', $custom_msg);
         $split_clabels = preg_split('/[+]{1,}/', $excl_clabels);
         $clabels = preg_replace('/[={2}]+[a-zA-Z0-9_-]*/', '', $split_clabels);
         $ctypes = preg_replace('/[a-zA-Z0-9_-]*[={2}]/', '', $split_clabels);
         $labtyp = array_combine($clabels, $ctypes);
         $w = new FabrikWorker();
         $custom_msg = $w->parseMessageForPlaceHolder($custom_msg);
         $excl_cdata = preg_replace('/((?!("[^"]*))([ |\\w|+|.])+(?=[^"]*"\\b)|(?!\\b"[^"]*)( +)+(?=([^"]*)$)|(?=\\b"[^"]*)( +)+(?=[^"]*"\\b))/', '', $custom_msg);
         $cdata = preg_split('/["]{1,}/', $excl_cdata);
         // Labels for CSV & for DB
         $clabels_csv_imp = implode("\",\"", $clabels);
         $clabels_csv_p1 = preg_replace('/^(",)/', '', $clabels_csv_imp);
         $clabels_csv = '';
         $clabels_csv .= preg_replace('/(,")$/', '', $clabels_csv_p1);
         if ($params->get('compare_data') == 1) {
             $clabels_csv .= ', "' . JText::_('PLG_FORM_LOG_COMPARE_DATA_LABEL_CSV') . '"';
         }
         $clabels_createdb_imp = '';
         foreach ($labtyp as $klb => $vlb) {
             $klb = $db->quoteName($klb);
             if ($vlb == 'varchar') {
                 $clabels_createdb_imp .= $klb . ' ' . $vlb . '(255) NOT NULL, ';
             } else {
                 if ($vlb == 'int') {
                     $clabels_createdb_imp .= $klb . ' ' . $vlb . '(11) NOT NULL, ';
                 } else {
                     if ($vlb == 'datetime') {
                         $clabels_createdb_imp .= $klb . ' ' . $vlb . ' NOT NULL, ';
                     }
                 }
             }
         }
         $clabels_createdb = substr_replace($clabels_createdb_imp, '', -2);
         if ($params->get('compare_data') == 1) {
             $clabels_createdb .= ', ' . $db->quoteName(JText::_('COMPARE_DATA_LABEL_DB')) . ' text NOT NULL';
         }
         // @todo - what if we use differnt db driver which doesnt name quote with `??
         $clabels_db_imp = implode("`,`", $clabels);
         $clabels_db_p1 = preg_replace('/^(`,)/', '', $clabels_db_imp);
         $clabels_db = preg_replace('/(,`)$/', '', $clabels_db_p1);
         if ($params->get('compare_data') == 1) {
             $clabels_db .= ', ' . $db->quoteName(JText::_('PLG_FORM_LOG_COMPARE_DATA_LABEL_DB'));
         }
         // data for CSV & for DB
         $cdata_csv_imp = implode("\",\"", $cdata);
         $cdata_csv_p1 = preg_replace('/^(",)/', '', $cdata_csv_imp);
         $cdata_csv = preg_replace('/(,")$/', '', $cdata_csv_p1);
         $cdata_csv = preg_replace('/={1,}",/', '', $cdata_csv);
         $cdata_csv = preg_replace('/""/', '"', $cdata_csv);
         if ($params->get('compare_data') == 1) {
             $cdata_csv .= ', "' . $result_compare . '"';
         }
         $cdata_db_imp = implode("','", $cdata);
         $cdata_db_p1 = preg_replace("/^(',)/", '', $cdata_db_imp);
         $cdata_db = preg_replace("/(,')\$/", '', $cdata_db_p1);
         $cdata_db = preg_replace("/={1,}',/", '', $cdata_db);
         $cdata_db = preg_replace("/''/", "'", $cdata_db);
         if ($params->get('compare_data') == 1 && !$loading) {
             $result_compare = preg_replace('/<br\\/>/', '- ', $result_compare);
             $result_compare = preg_replace('/\\n/', '- ', $result_compare);
             $cdata_db .= ", '" . $result_compare . "'";
         }
         $custom_msg = preg_replace('/([++][0-9a-zA-Z.:_]*)/', '', $custom_msg);
         $custom_msg = preg_replace('/^[ ]/', '', $custom_msg);
         $custom_msg = preg_replace('/  /', ' ', $custom_msg);
         $custom_msg = preg_replace('/"/', '', $custom_msg);
         if ($params->get('compare_data') == 1 && !$loading) {
             $custom_msg .= '<br />' . $result_compare;
         }
     } else {
         $clabelsCreateDb = array();
         $clabelsDb = array();
         $cdataDb = array();
         $clabelsCreateDb[] = $db->quoteName('date') . " datetime NOT NULL";
         $clabelsDb[] = $db->quoteName('date');
         $cdataDb[] = "NOW()";
         $clabelsCreateDb[] = $db->quoteName('ip') . " varchar(32) NOT NULL";
         $clabelsDb[] = $db->quoteName('ip');
         $cdataDb[] = $params->get('logs_record_ip') == '1' ? $db->Quote($_SERVER['REMOTE_ADDR']) : $db->Quote('');
         $clabelsCreateDb[] = $db->quoteName('referer') . " varchar(255) NOT NULL";
         $clabelsDb[] = $db->quoteName('referer');
         $cdataDb[] = $params->get('logs_record_referer') == '1' ? $db->Quote($http_referrer) : $db->Quote('');
         $clabelsCreateDb[] = $db->quoteName('user_agent') . " varchar(255) NOT NULL";
         $clabelsDb[] = $db->quoteName('user_agent');
         $cdataDb[] = $params->get('logs_record_useragent') == '1' ? $db->Quote($_SERVER['HTTP_USER_AGENT']) : $db->Quote('');
         $clabelsCreateDb[] = $db->quoteName('data_comparison') . " TEXT NOT NULL";
         $clabelsDb[] = $db->quoteName('data_comparison');
         $cdataDb[] = $params->get('compare_data') == '1' ? $db->Quote($result_compare) : $db->Quote('');
         $clabelsCreateDb[] = $db->quoteName('rowid') . " INT(11) NOT NULL";
         $clabelsDb[] = $db->quoteName('rowid');
         $cdataDb[] = $db->Quote((int) $rowid);
         $clabelsCreateDb[] = $db->quoteName('userid') . " INT(11) NOT NULL";
         $clabelsDb[] = $db->quoteName('userid');
         $cdataDb[] = $db->Quote((int) $userid);
         $clabelsCreateDb[] = $db->quoteName('tableid') . " INT(11) NOT NULL";
         $clabelsDb[] = $db->quoteName('tableid');
         $cdataDb[] = $db->Quote($formModel->getTableModel()->getId());
         $clabelsCreateDb[] = $db->quoteName('formid') . " INT(11) NOT NULL";
         $clabelsDb[] = $db->quoteName('formid');
         $cdataDb[] = $db->Quote($formModel->getId());
         $clabels_createdb = implode(", ", $clabelsCreateDb);
         $clabels_db = implode(", ", $clabelsDb);
         $cdata_db = implode(", ", $cdataDb);
     }
     /* For CSV files
      * If 'Append' method is used, you don't want to repeat the labels (Date, IP, ...)
      * each time you add a line in the file */
     $labels = !JFile::exists($logs_file) || $logs_mode == 'w' ? 1 : 0;
     $buffer = $logs_mode == 'a' && JFile::exists($logs_file) ? JFile::read($logs_file) : '';
     $send_email = $params->get('log_send_email') == '1';
     $make_file = $params->get('make_file') == '1';
     if ($send_email && !$make_file) {
         $ext = 'txt';
     }
     $email_msg = '';
     //@TODO redo all this with JFile API and only writing a string once - needless overhead doing fwrite all the time
     if ($make_file || $send_email) {
         // Opening or creating the file
         if ($params->get('custom_msg') != '') {
             if ($send_email) {
                 $email_msg = $custom_msg;
             }
             if ($make_file) {
                 $custMsg = $buffer;
                 if ($ext != 'csv') {
                     JFile::write($logs_file, $buffer . $custom_msg . "\n" . $sep . "\n");
                 } else {
                     // Making the CSV file
                     // If the file already exists, do not add the 'label line'
                     if ($labels == 1) {
                         $custMsg .= $clabels_csv;
                     }
                     // Inserting data in CSV with actual line break as row separator
                     $custMsg .= "\n" . $cdata_csv;
                     JFile::write($logs_file, $custMsg);
                 }
             }
         } else {
             // Making HTM File
             if ($ext == 'htm') {
                 $htmlMsg = "<b>Date:</b> " . $date . "<br/>";
                 if ($params->get('logs_record_ip') == 1) {
                     $htmlMsg .= "<b>IP Address:</b> " . $_SERVER['REMOTE_ADDR'] . "<br/>";
                 }
                 if ($params->get('logs_record_referer') == 1) {
                     $htmlMsg .= "<b>Referer:</b> " . $http_referrer . "<br/>";
                 }
                 if ($params->get('logs_record_useragent') == 1) {
                     $htmlMsg .= "<b>UserAgent: </b>" . $_SERVER['HTTP_USER_AGENT'] . "<br/>";
                 }
                 $htmlMsg .= $result_compare . $sep . "<br/>";
                 if ($send_email) {
                     $email_msg = $htmlMsg;
                 }
                 if ($make_file) {
                     $htmlMsg = $buffer . $htmlMsg;
                     $res = JFile::write($logs_file, $htmlMsg);
                     if (!$res) {
                         JError::raiseNotice(E_NOTICE, "error writing html to log file: " . $logs_file);
                     }
                 }
             } else {
                 if ($ext == 'txt') {
                     $txtMsg = "Date: " . $date . "\n";
                     $txtMsg .= "Form ID: " . $formModel->getId() . "\n";
                     $txtMsg .= "Table ID: " . $formModel->getListModel()->getId() . "\n";
                     $txtMsg .= "Row ID: " . (int) $rowid . "\n";
                     $txtMsg .= "User ID: {$userid} ({$username})\n";
                     if ($params->get('logs_record_ip') == 1) {
                         $txtMsg .= "IP Address: " . $_SERVER['REMOTE_ADDR'] . "\n";
                     }
                     if ($params->get('logs_record_referer') == 1) {
                         $txtMsg .= "Referer: " . $http_referrer . "\n";
                     }
                     if ($params->get('logs_record_useragent') == 1) {
                         $txtMsg .= "UserAgent: " . $_SERVER['HTTP_USER_AGENT'] . "\n";
                     }
                     $txtMsg .= $result_compare . $sep . "\n";
                     if ($send_email) {
                         $email_msg = $txtMsg;
                     }
                     if ($make_file) {
                         $txtMsg = $buffer . $txtMsg;
                         JFile::write($logs_file, $txtMsg);
                     }
                 } else {
                     // Making the CSV file
                     if ($ext == 'csv') {
                         $csvMsg = array();
                         // If the file already exists, do not add the 'label line'
                         if ($labels == 1) {
                             $csvMsg[] = "Date";
                             if ($params->get('logs_record_ip') == 1) {
                                 // Putting some "" around the label to avoid two different fields
                                 $csvMsg[] = "\"IP Address\"";
                             }
                             if ($params->get('logs_record_referer') == 1) {
                                 $csvMsg[] = "Referer";
                             }
                             if ($params->get('logs_record_useragent') == 1) {
                                 $csvMsg[] = "UserAgent";
                             }
                             if ($params->get('compare_data') == 1) {
                                 $csvMsg[] = "\"" . JText::_('COMPARE_DATA_LABEL_CSV') . "\"";
                             }
                         }
                         // Inserting data in CSV with actual line break as row separator
                         $csvMsg[] = "\n\"" . $date . "\"";
                         if ($params->get('logs_record_ip') == 1) {
                             $csvMsg[] = "\"" . $_SERVER['REMOTE_ADDR'] . "\"";
                         }
                         if ($params->get('logs_record_referer') == 1) {
                             $csvMsg[] = "\"" . $http_referrer . "\"";
                         }
                         if ($params->get('logs_record_useragent') == 1) {
                             $csvMsg[] = "\"" . $_SERVER['HTTP_USER_AGENT'] . "\"";
                         }
                         if ($params->get('compare_data') == 1) {
                             $csvMsg[] = "\"" . $result_compare . "\"";
                         }
                         $csvMsg = implode(",", $csvMsg);
                         if ($send_email) {
                             $email_msg = $csvMsg;
                         }
                         if ($make_file) {
                             if ($buffer !== '') {
                                 $csvMsg = $buffer . $csvMsg;
                             }
                             JFile::write($logs_file, $csvMsg);
                         }
                     }
                 }
             }
         }
     }
     if ($params->get('logs_record_in_db') == 1) {
         // In which table?
         if ($params->get('record_in') == '') {
             $rdb = '#__fabrik_log';
         } else {
             $db_suff = $params->get('record_in');
             $form = $formModel->getForm();
             $fid = $form->id;
             $db->setQuery("SELECT " . $db->quoteName('db_table_name') . " FROM " . $db->quoteName('#__fabrik_lists') . " WHERE " . $db->quoteName('form_id') . " = " . (int) $fid);
             $tname = $db->loadResult();
             $rdb = $db->quoteName($tname . $db_suff);
         }
         // Making the message to record
         if ($params->get('custom_msg') != '') {
             $message = preg_replace('/<br\\/>/', ' ', $custom_msg);
         } else {
             $message = $this->makeStandardMessage($params, $result_compare);
         }
         // $$$ hugh - FIXME - not sure about the option driven $create_custom_table stuff, as this won't work
         // if they add an option to an existing log table.  We should probably just create all the optional columns
         // regardless.
         if ($params->get('record_in') == '') {
             $in_db = "INSERT INTO {$rdb} (" . $db->quoteName('referring_url') . ", " . $db->quoteName('message_type') . ", " . $db->quoteName('message') . ") VALUES (" . $db->Quote($http_referrer) . ", " . $db->Quote($messageType) . ", " . $db->Quote($message) . ");";
             $db->setQuery($in_db);
             $db->query();
         } else {
             $create_custom_table = "CREATE TABLE IF NOT EXISTS {$rdb} (" . $db->quoteName('id') . " int(11) NOT NULL auto_increment PRIMARY KEY, {$clabels_createdb});";
             $db->setQuery($create_custom_table);
             $db->query();
             $in_db = "INSERT INTO {$rdb} ({$clabels_db}) VALUES ({$cdata_db});";
             $db->setQuery($in_db);
             if (!$db->query()) {
                 // $$$ changed to always use db fields even if not selected
                 // so logs already created may need optional fields added.
                 // try adding every field we should have, don't care if query fails.
                 foreach ($clabelsCreateDb as $insert) {
                     $db->setQuery("ALTER TABLE ADD {$insert} AFTER `id`");
                     $db->query();
                 }
                 // ... and try the insert query again
                 $db->setQuery($in_db);
                 $db->query();
             }
         }
     }
     if ($send_email) {
         jimport('joomla.mail.helper');
         $config =& JFactory::getConfig();
         $email_from = $config->getValue('mailfrom');
         $email_to = explode(',', $w->parseMessageForPlaceholder($params->get('log_send_email_to', '')));
         $subject = strip_tags($w->parseMessageForPlaceholder($params->get('log_send_email_subject', 'log event')));
         foreach ($email_to as $email) {
             $email = trim($email);
             if (empty($email)) {
                 continue;
             }
             if (JMailHelper::isEmailAddress($email)) {
                 $res = JUtility::sendMail($email_from, $email_from, $email, $subject, $email_msg, true);
             } else {
                 JError::raiseNotice(500, JText::sprintf('DID_NOT_SEND_EMAIL_INVALID_ADDRESS', $email));
             }
         }
     }
     return true;
 }
예제 #7
0
 /**
  * process the plugin, called when form is submitted
  *
  * @param object $params
  * @param object form model
  * @returns bol
  */
 function onLastProcess(&$params, &$formModel)
 {
     $app =& JFactory::getApplication();
     //$data 			=& $formModel->_fullFormData;
     //$data 			=& $formModel->_formData;
     // Generate random filename
     if ($params->get('logs_random_filename') == 1) {
         function generate_filename($length)
         {
             $key = "";
             $possible = "0123456789bcdfghjkmnpqrstvwxyzBCDFGHJKLMNPQRTVWXYZ";
             $i = 0;
             while ($i < $length) {
                 $char = substr($possible, mt_rand(0, strlen($possible) - 1), 1);
                 $key .= $char;
                 $i++;
             }
             return $key;
         }
         $random_filename = '_' . generate_filename($params->get('logs_random_filename_length'));
     } else {
         $random_filename = '';
     }
     $w = new FabrikWorker();
     $logs_path = $w->parseMessageForPlaceHolder($params->get('logs_path'));
     if (!file_exists($logs_path)) {
         JFolder::create($logs_path);
     }
     $ext = $params->get('logs_file_format');
     $sep = $params->get('logs_separator');
     // Making complete path + filename + extension
     $w = new FabrikWorker();
     $logs_file = $logs_path . $w->parseMessageForPlaceHolder($params->get('logs_file')) . $random_filename . '.' . $ext;
     $logs_mode = $params->get('logs_append_or_overwrite');
     $date_element = $params->get('logs_date_field');
     $date_now = $params->get('logs_date_now');
     // COMPARE DATA
     $result_compare = '';
     if ($params->get('compare_data') == 1) {
         $this->formModel =& $formModel;
         $data = $this->getEmailData();
         $post = JRequest::get('post');
         $elementModel =& JModel::getInstance('element', 'FabrikModel');
         $element =& $elementModel->getElement(true);
         $listModel =& $formModel->getTable();
         if ($ext == 'csv') {
             $sep_compare = '';
             $sep_2compare = '/ ';
         } else {
             if ($ext == 'txt') {
                 $sep_compare = '\\n';
                 $sep_2compare = '\\n';
             } else {
                 if ($ext == 'htm') {
                     $sep_compare = '<br/>';
                     $sep_2compare = '<br/>';
                 }
             }
         }
         //var_dump($listModel); exit;
         foreach ($data as $key => $val) {
             /* if (is_array($val)) {
             			foreach ($val as $v) {
             				if (is_array($v)) {
             					foreach ($v as $nval) {
             						if (($nval[0] != $formModel->_origData->$key) && (isset($formModel->_origData->$key)) && (isset($nval[0])) && (substr($key, -4, 4) != '_raw')) {
             							$result_compare .= JText::_('PLG_FORM_LOG_COMPARE_DATA_CHANGE_ON').' '.$key.' '.$sep_compare.JText::_('PLG_FORM_LOG_COMPARE_DATA_FROM').' '.$formModel->_origData->$key.' '.$sep_compare.JText::_('PLG_FORM_LOG_COMPARE_DATA_TO').' '.$nval[0].' '.$sep_2compare;
             						}
             					}
             				}else{
             					if (($val[0] != $formModel->_origData->$key) && (isset($formModel->_origData->$key)) && (isset($val[0])) && (substr($key, -4, 4) != '_raw')) {
             						$result_compare .= JText::_('PLG_FORM_LOG_COMPARE_DATA_CHANGE_ON').' '.$key.' '.$sep_compare.JText::_('PLG_FORM_LOG_COMPARE_DATA_FROM').' '.$formModel->_origData->$key.' '.$sep_compare.JText::_('PLG_FORM_LOG_COMPARE_DATA_TO').' '.$val[0].' '.$sep_2compare;
             					}
             				}
             			}
             		  } else {*/
             if ($val != $formModel->_origData->{$key} && isset($formModel->_origData->{$key}) && isset($val) && substr($key, -4, 4) != '_raw') {
                 $id_elementModel =& JModel::getInstance('element', 'FabrikModel');
                 $id_elementModel->setId($key);
                 $id_element =& $id_elementModel->getElement(true);
                 $formModel->_formData[$id_element->name] = $formModel->_fullFormData['rowid'];
                 $formModel->_formData[$id_element->name . '_raw'] = $formModel->_fullFormData['rowid'];
                 $test = $id_element->name->{$key};
                 $result_compare .= JText::_('PLG_FORM_LOG_COMPARE_DATA_CHANGE_ON') . ' ' . $key . ' ' . $sep_compare . JText::_('PLG_FORM_LOG_COMPARE_DATA_FROM') . ' ' . $formModel->_origData->{$key} . ' ' . $sep_compare . JText::_('PLG_FORM_LOG_COMPARE_DATA_TO') . ' ' . $val . ' ' . $sep_2compare;
             }
             // }
         }
     }
     // Defining the date to use - Not used anymore as logs should really only record the current time_date
     /*if ($date_element != '') {
     			$this->date_field 			= $this->getFieldName( $params, 'logs_date_field');
     			$date = $data[$this->date_field];
     		} else
     		*/
     if ($date_now != '') {
         $date = date("{$date_now}");
     } else {
         $date = date("Y-m-d H:i:s");
     }
     // Custom Message
     if ($params->get('custom_msg') != '') {
         $rowidPos = strpos($_SERVER['HTTP_REFERER'], 'rowid=');
         $idPos = $rowidPos + 6;
         $rowid = substr($_SERVER['HTTP_REFERER'], $idPos, 1);
         if ($rowid == "=" || $rowid == '&' || $rowid == '') {
             $rep_add_edit = JText::_('PLG_FORM_LOG_REP_ADD');
         } else {
             $rep_add_edit = JText::_('PLG_FORM_LOG_REP_EDIT');
         }
         $custom_msg = $params->get('custom_msg');
         $custom_msg = preg_replace('/{Add\\/Edit}/', $rep_add_edit, $custom_msg);
         $custom_msg = preg_replace('/{DATE}/', $date, $custom_msg);
         /* Using Fabrik's own placeholders {$_SERVER->FOO} instead
         			$custom_msg = preg_replace('/{IP}/', $_SERVER['REMOTE_ADDR'], $custom_msg);
         			$custom_msg = preg_replace('/{REFERER}/', $_SERVER['HTTP_REFERER'], $custom_msg);
         			$custom_msg = preg_replace('/{USERAGENT}/', $_SERVER['HTTP_USER_AGENT'], $custom_msg);*/
         $excl_clabels = preg_replace('/([-{2}| |"][0-9a-zA-Z.:$_>]*)/', '', $custom_msg);
         $split_clabels = preg_split('/[+]{1,}/', $excl_clabels);
         $clabels = preg_replace('/[={2}]+[a-zA-Z0-9_-]*/', '', $split_clabels);
         $ctypes = preg_replace('/[a-zA-Z0-9_-]*[={2}]/', '', $split_clabels);
         $labtyp = array_combine($clabels, $ctypes);
         /*$searchFor = array('date', 'fecha', 'data', 'datum');
         			foreach ($searchFor as $sdate) {
         				//if (in_array($sdate, $clabels)) {
         					foreach ($clabels as $keydate => $valdate) {
         						$valdate = strtolower($valdate);
             					if ($valdate == $sdate) {
                 					unset($clabels[$keydate]);
                 					$datefield = 1;
         							$labeldate = $sdate;
             					}
             					next($clabels);
         					}
         
         
         				//}
         			}*/
         $w = new FabrikWorker();
         $custom_msg = $w->parseMessageForPlaceHolder($custom_msg);
         $excl_cdata = preg_replace('/((?!("[^"]*))([ |\\w|+|.])+(?=[^"]*"\\b)|(?!\\b"[^"]*)( +)+(?=([^"]*)$)|(?=\\b"[^"]*)( +)+(?=[^"]*"\\b))/', '', $custom_msg);
         $cdata = preg_split('/["]{1,}/', $excl_cdata);
         // Labels for CSV & for DB
         $clabels_csv_imp = implode("\",\"", $clabels);
         $clabels_csv_p1 = preg_replace('/^(",)/', '', $clabels_csv_imp);
         $clabels_csv = '';
         //if ($datefield) {
         //	$clabels_csv .= '"'.$labeldate.'",';
         //}
         $clabels_csv .= preg_replace('/(,")$/', '', $clabels_csv_p1);
         if ($params->get('compare_data') == 1) {
             $clabels_csv .= ', "' . JText::_('PLG_FORM_LOG_COMPARE_DATA_LABEL_CSV') . '"';
         }
         $clabels_createdb_imp = '';
         foreach ($labtyp as $klb => $vlb) {
             if ($vlb == 'varchar') {
                 $clabels_createdb_imp .= '`' . $klb . '` ' . $vlb . '(255) NOT NULL, ';
             } else {
                 if ($vlb == 'int') {
                     $clabels_createdb_imp .= '`' . $klb . '` ' . $vlb . '(11) NOT NULL, ';
                 } else {
                     if ($vlb == 'datetime') {
                         $clabels_createdb_imp .= '`' . $klb . '` ' . $vlb . ' NOT NULL, ';
                     }
                 }
             }
         }
         //$clabels_createdb_imp = implode("`, `", $clabels_createdb_imp);
         //$clabels_createdb_p1 = substr($clabels_createdb_imp, 9);
         $clabels_createdb = substr_replace($clabels_createdb_imp, '', -2);
         //$clabels_createdb = '';
         //if ($datefield) {
         //	$clabels_createdb .= '`'.$labeldate.'` datetime NULL, ';
         //}
         //$clabels_createdb .= preg_replace('/(,`)$/', '', $clabels_createdb_p1);
         if ($params->get('compare_data') == 1) {
             $clabels_createdb .= ', `' . JText::_('PLG_FORM_LOG_COMPARE_DATA_LABEL_DB') . '` text NOT NULL';
         }
         $clabels_db_imp = implode("`,`", $clabels);
         $clabels_db_p1 = preg_replace('/^(`,)/', '', $clabels_db_imp);
         $clabels_db = '';
         //if ($datefield) {
         //	$clabels_db .= '`'.$labeldate.'`, ';
         //}
         $clabels_db .= preg_replace('/(,`)$/', '', $clabels_db_p1);
         if ($params->get('compare_data') == 1) {
             $clabels_db .= ', `' . JText::_('PLG_FORM_LOG_COMPARE_DATA_LABEL_DB') . '`';
         }
         // data for CSV & for DB
         $cdata_csv_imp = implode("\",\"", $cdata);
         $cdata_csv_p1 = preg_replace('/^(",)/', '', $cdata_csv_imp);
         $cdata_csv = preg_replace('/(,")$/', '', $cdata_csv_p1);
         $cdata_csv = preg_replace('/={1,}",/', '', $cdata_csv);
         $cdata_csv = preg_replace('/""/', '"', $cdata_csv);
         if ($params->get('compare_data') == 1) {
             $cdata_csv .= ', "' . $result_compare . '"';
         }
         $cdata_db_imp = implode("','", $cdata);
         $cdata_db_p1 = preg_replace("/^(',)/", '', $cdata_db_imp);
         $cdata_db = preg_replace("/(,')\$/", '', $cdata_db_p1);
         $cdata_db = preg_replace("/={1,}',/", '', $cdata_db);
         $cdata_db = preg_replace("/''/", "'", $cdata_db);
         if ($params->get('compare_data') == 1) {
             $result_compare = preg_replace('/<br\\/>/', '- ', $result_compare);
             $result_compare = preg_replace('/\\n/', '- ', $result_compare);
             $cdata_db .= ", '" . $result_compare . "'";
         }
         $custom_msg = preg_replace('/([++][0-9a-zA-Z.:_]*)/', '', $custom_msg);
         $custom_msg = preg_replace('/^[ ]/', '', $custom_msg);
         $custom_msg = preg_replace('/  /', ' ', $custom_msg);
         $custom_msg = preg_replace('/"/', '', $custom_msg);
         if ($params->get('compare_data') == 1) {
             $custom_msg .= '<br />' . $result_compare;
         }
     } else {
         if ($params->get('logs_record_ip') == 1) {
             $clabels_createdb = "`date` datetime NOT NULL, `ip` varchar(255) NOT NULL";
             $clabels_db = '`date`, `ip`';
             $cdata_db = "'{$date}', '" . $_SERVER['REMOTE_ADDR'] . "'";
         }
         if ($params->get('logs_record_referer') == 1) {
             if ($params->get('logs_record_ip') == 1) {
                 $clabels_createdb .= ", `referer` varchar(255) NOT NULL";
                 $clabels_db .= ', `referer`';
                 $cdata_db .= ", '" . $_SERVER['HTTP_REFERER'] . "'";
             } else {
                 $clabels_createdb = "`date` datetime NOT NULL, `referer` varchar(255) NOT NULL";
                 $clabels_db = '`date`, `referer`';
                 $cdata_db = "'{$date}', '" . $_SERVER['HTTP_REFERER'] . "'";
             }
         }
         if ($params->get('logs_record_useragent') == 1) {
             if ($params->get('logs_record_ip') == 1 || $params->get('logs_record_referer') == 1) {
                 $clabels_createdb .= ", `user_agent` varchar(255) NOT NULL";
                 $clabels_db .= ', `user_agent`';
                 $cdata_db .= ", '" . $_SERVER['HTTP_USER_AGENT'] . "'";
             } else {
                 $clabels_createdb = "`date` datetime NOT NULL, `user_agent` varchar(255) NOT NULL";
                 $clabels_db = '`date`, `user_agent`';
                 $cdata_db = "'{$date}', '" . $_SERVER['HTTP_USER_AGENT'] . "'";
             }
         }
         if ($params->get('compare_data') == 1) {
             if ($params->get('logs_record_ip') == 1 || $params->get('logs_record_referer') == 1 || $params->get('logs_record_useragent') == 1) {
                 $clabels_createdb .= ", `" . JText::_('PLG_FORM_LOG_COMPARE_DATA_LABEL_DB') . "` text NOT NULL";
                 $clabels_db .= ", `" . JText::_('PLG_FORM_LOG_COMPARE_DATA_LABEL_DB') . "`";
                 $cdata_db .= ", '" . $result_compare . "'";
             } else {
                 $clabels_createdb = "`date` datetime NOT NULL, `" . JText::_('PLG_FORM_LOG_COMPARE_DATA_LABEL_DB') . "` varchar(255) NOT NULL";
                 $clabels_db = '`date`, `user_agent`';
                 $cdata_db = "'{$date}', '" . $result_compare . "'";
             }
         }
     }
     /* For CSV files
      * If 'Append' method is used, you don't want to repeat the labels (Date, IP, ...)
      * each time you add a line in the file */
     if (!file_exists($logs_file) || $logs_mode == 'w') {
         $labels = 1;
     } else {
         $labels = 0;
     }
     if ($params->get('make_file') == 1) {
         // Opening or creating the file
         $open = fopen($logs_file, $logs_mode);
         if ($params->get('custom_msg') != '') {
             if ($ext != 'csv') {
                 fwrite($open, $custom_msg . "\n" . $sep . "\n");
             } else {
                 // Making the CSV file
                 // If the file already exists, do not add the 'label line'
                 if ($labels == 1) {
                     fwrite($open, $clabels_csv);
                 }
                 // Inserting data in CSV with actual line break as row separator
                 fwrite($open, "\n" . $cdata_csv . "");
             }
         } else {
             // Making HTM File
             if ($ext == 'htm') {
                 fwrite($open, "<b>Date:</b> " . $date . "<br/>");
                 if ($params->get('logs_record_ip') == 1) {
                     fwrite($open, "<b>IP Address:</b> " . $_SERVER['REMOTE_ADDR'] . "<br/>");
                 }
                 if ($params->get('logs_record_referer') == 1) {
                     fwrite($open, "<b>Referer:</b> " . $_SERVER['HTTP_REFERER'] . "<br/>");
                 }
                 if ($params->get('logs_record_useragent') == 1) {
                     fwrite($open, "<b>UserAgent: </b>" . $_SERVER['HTTP_USER_AGENT'] . "<br/>");
                 }
                 fwrite($open, $result_compare . $sep . "<br/>");
             } else {
                 if ($ext == 'txt') {
                     fwrite($open, "Date: " . $date . "\n");
                     if ($params->get('logs_record_ip') == 1) {
                         fwrite($open, "IP Address: " . $_SERVER['REMOTE_ADDR'] . "\n");
                     }
                     if ($params->get('logs_record_referer') == 1) {
                         fwrite($open, "Referer: " . $_SERVER['HTTP_REFERER'] . "\n");
                     }
                     if ($params->get('logs_record_useragent') == 1) {
                         fwrite($open, "UserAgent: " . $_SERVER['HTTP_USER_AGENT'] . "\n");
                     }
                     fwrite($open, $result_compare . $sep . "\n");
                 } else {
                     // Making the CSV file
                     if ($ext == 'csv') {
                         // If the file already exists, do not add the 'label line'
                         if ($labels == 1) {
                             fwrite($open, "Date,");
                             if ($params->get('logs_record_ip') == 1) {
                                 // Putting some "" around the label to avoid two different fields
                                 fwrite($open, "\"IP Address\"");
                             }
                             if ($params->get('logs_record_referer') == 1) {
                                 if ($params->get('logs_record_ip') == 1) {
                                     fwrite($open, ",Referer");
                                 } else {
                                     fwrite($open, "Referer");
                                 }
                             }
                             if ($params->get('logs_record_useragent') == 1) {
                                 if ($params->get('logs_record_ip') == 1 || $params->get('logs_record_referer') == 1) {
                                     fwrite($open, ",UserAgent");
                                 } else {
                                     fwrite($open, "UserAgent");
                                 }
                             }
                             if ($params->get('compare_data') == 1) {
                                 if ($params->get('logs_record_ip') == 1 || $params->get('logs_record_referer') == 1 || $params->get('logs_record_useragent') == 1) {
                                     fwrite($open, ",\"" . JText::_('PLG_FORM_LOG_COMPARE_DATA_LABEL_CSV') . "\"");
                                 } else {
                                     fwrite($open, "\"" . JText::_('PLG_FORM_LOG_COMPARE_DATA_LABEL_CSV') . "\"");
                                 }
                             }
                         }
                         // Inserting data in CSV with actual line break as row separator
                         fwrite($open, "\n\"" . $date . "\",");
                         if ($params->get('logs_record_ip') == 1) {
                             fwrite($open, "\"" . $_SERVER['REMOTE_ADDR'] . "\"");
                         }
                         if ($params->get('logs_record_referer') == 1) {
                             if ($params->get('logs_record_ip') == 1) {
                                 fwrite($open, ",\"" . $_SERVER['HTTP_REFERER'] . "\"");
                             } else {
                                 fwrite($open, "\"" . $_SERVER['HTTP_REFERER'] . "\"");
                             }
                         }
                         if ($params->get('logs_record_useragent') == 1) {
                             if ($params->get('logs_record_ip', '') == 1 || $params->get('logs_record_referer', '') == 1) {
                                 fwrite($open, ",\"" . $_SERVER['HTTP_USER_AGENT'] . "\"");
                             } else {
                                 fwrite($open, "\"" . $_SERVER['HTTP_USER_AGENT'] . "\"");
                             }
                         }
                         if ($params->get('compare_data') == 1) {
                             if ($params->get('logs_record_ip', '') == 1 || $params->get('logs_record_referer', '') == 1 || $params->get('logs_record_useragent', '') == 1) {
                                 fwrite($open, ",\"" . $result_compare . "\"");
                             } else {
                                 fwrite($open, "\"" . $result_compare . "\"");
                             }
                         }
                     }
                 }
             }
         }
         fclose($open);
     }
     // Record in DB
     if ($params->get('logs_record_in_db') == 1) {
         $db = FabrikWorker::getDbo();
         // In which table?
         if ($params->get('record_in') == '') {
             $rdb = '#__{package}_log';
         } else {
             $db_suff = $params->get('record_in');
             $this->formModel =& $formModel;
             $form =& $formModel->getForm();
             $fid = $form->id;
             $db->setQuery("SELECT `db_table_name` FROM `#__{package}_tables` WHERE `form_id` = '{$fid}'");
             $tname = $db->loadResult();
             $rdb = $tname . $db_suff;
         }
         // New record or edit?
         //if ((substr($_SERVER['HTTP_REFERER'], -1) == '=') || (substr($_SERVER['HTTP_REFERER'], -1) == '&')) {
         $rowidPos = strpos($_SERVER['HTTP_REFERER'], 'rowid=');
         $idPos = $rowidPos + 6;
         $rowid = substr($_SERVER['HTTP_REFERER'], $idPos, 1);
         if ($rowid == "=" || $rowid == '&' || $rowid == '') {
             $message_type = 'form.new';
         } else {
             $message_type = 'form.edit';
         }
         // Making the message to record
         if ($params->get('custom_msg') != '') {
             $message = preg_replace('/<br\\/>/', ' ', $custom_msg);
         } else {
             $message = '';
             if ($params->get('logs_record_ip') == 1) {
                 //$message .= 'IP: '.$_SERVER['REMOTE_ADDR'].GROUPSPLITTER2;
                 $message .= 'IP: ' . $_SERVER['REMOTE_ADDR'] . ',';
             }
             if ($params->get('logs_record_useragent') == 1) {
                 $message .= 'UserAgent: ' . $_SERVER['HTTP_USER_AGENT'] . GROUPSPLITTER2;
                 $message .= 'UserAgent: ' . $_SERVER['HTTP_USER_AGENT'] . ',';
             }
             if ($params->get('compare_data') == 1) {
                 $result_compare = preg_replace('/<br\\/>/', '- ', $result_compare);
                 $message .= preg_replace('/\\n/', '- ', $result_compare);
             }
         }
         if ($params->get('record_in') == '') {
             $in_db = "INSERT INTO `{$rdb}` (`referring_url`, `message_type`, `message`) VALUES ('" . $_SERVER['HTTP_REFERER'] . "', '{$message_type}', '{$message}');";
         } else {
             $create_custom_table = "CREATE TABLE IF NOT EXISTS `{$rdb}` (`id` int(11) NOT NULL auto_increment PRIMARY KEY, {$clabels_createdb});";
             $db->setQuery($create_custom_table);
             $db->query();
             $in_db = "INSERT INTO `{$rdb}` ({$clabels_db}) VALUES ({$cdata_db});";
         }
         // Insert in DB
         $db->setQuery($in_db);
         $db->query();
     }
     return true;
 }
예제 #8
0
 /**
  * Upload cover image.
  * 
  * @param Request $request
  * 
  * @return AJAX
  */
 function uploadCover(Request $request)
 {
     if ($request->isMethod('POST')) {
         $rules = $this->_getCoverRules();
         $messages = $this->_getCoverMessages();
         $validator = Validator::make($request->all(), $rules, $messages);
         if ($validator->fails()) {
             return file_pong(['messages' => $validator->errors()->first()], _error(), 403);
         }
         if ($request->file('__file')->isValid()) {
             $avatar = $request->file('__file');
             $storagePath = config('frontend.coversFolder');
             $mediumSizeW = (int) config('frontend.coverMediumW');
             $mediumSizeH = (int) config('frontend.coverMediumH');
             $mediumName = generate_filename($storagePath, $avatar->getClientOriginalExtension(), ['prefix' => 'cover_', 'suffix' => "_{$mediumSizeW}x{$mediumSizeH}"]);
             $avatar->move($storagePath, $mediumName);
             $image = ImageIntervention::make($storagePath . '/' . $mediumName)->orientate();
             $image->fit($mediumSizeW, $mediumSizeH, function ($constraint) {
                 $constraint->upsize();
             });
             $image->save();
             $userProfile = user()->userProfile;
             if (is_null($userProfile)) {
                 $userProfile = new UserProfile();
                 $userProfile->user_id = user()->id;
             } else {
                 $avatarImg = unserialize($userProfile->cover_image);
                 if (isset($avatarImg[$mediumSizeW])) {
                     delete_file($storagePath . '/' . $avatarImg[$mediumSizeW]);
                 }
             }
             $userProfile->cover_image = serialize(array($mediumSizeW => $mediumName));
             $userProfile->save();
             return file_pong(['cover_medium' => $storagePath . '/' . $mediumName]);
         }
         return file_pong(['messages' => _t('opps')], _error(), 403);
     }
 }
예제 #9
0
 public function appearanceSave(Request $request)
 {
     if ($request->hasFile('logo')) {
         $file = $request->file('logo');
         $path = public_path('upload');
         $filename = generate_filename($path, $file->getClientOriginalExtension());
         $file->move($path, $filename);
         Conf::set('appearance.logo', $filename);
     }
     if ($request->hasFile('background')) {
         $file = $request->file('background');
         $path = public_path('upload');
         $filename = generate_filename($path, $file->getClientOriginalExtension());
         $file->move($path, $filename);
         $bg = ['image' => $filename, 'horizontal' => $request->get('horizontal', 'left'), 'vertical' => $request->get('vertical', 'top'), 'repeat' => $request->get('repeat', 'repeat'), 'is_fixed' => $request->get('is_fixed', '')];
         Conf::set('appearance.bg', $bg);
     } else {
         Conf::set('appearance.bg.horizontal', $request->get('horizontal', 'left'));
         Conf::set('appearance.bg.vertical', $request->get('vertical', 'top'));
         Conf::set('appearance.bg.repeat', $request->get('repeat', 'repeat'));
         Conf::set('appearance.bg.is_fixed', $request->get('is_fixed', ''));
     }
     Conf::set('appearance.header.bg', $request->get('header_bg', '#FFFFFF'));
     Conf::set('appearance.menu.color', $request->get('menu_color', 'default'));
     Conf::set('appearance.footer.top_bg', $request->get('footer_top_bg', '#ecf0f1'));
     Conf::set('appearance.footer.top_text', $request->get('footer_top_text', '#2b4646'));
     Conf::set('appearance.footer.bottom_bg', $request->get('footer_bottom_bg', '#c7dae5'));
     Conf::set('appearance.footer.bottom_text', $request->get('footer_bottom_text', '#111111'));
     Notifications::add('Settings saved', 'success');
     return redirect()->route('root-settings-appearance');
 }
예제 #10
0
파일: upload.php 프로젝트: JoshuaGrams/wfpl
function save_uploaded_file($key, $path)
{
    if (substr($path, -1) == '/') {
        $filename = $path . generate_filename($_FILES[$key]['name'], $_FILES[$key]['type']);
    } else {
        $filename = $path;
    }
    if (!move_uploaded_file($_FILES[$key]['tmp_name'], $filename)) {
        return false;
    }
    return $filename;
}
예제 #11
0
 /**
  * Generate the file name base on current user id, time
  * to get a unique file in present directory
  *
  * @param string $directory Path to the upload directory
  * @param string $extension File extension
  * @param array  $options   Prefix, suffix,...
  *
  * @return string
  */
 function generate_filename($directory, $extension, $options = [])
 {
     $prefix = isset($options['prefix']) ? $options['prefix'] : '';
     $suffix = isset($options['suffix']) ? $options['suffix'] : '';
     $limit = isset($options['limit']) ? (int) $options['limit'] : 16;
     $randomStr = random_string($limit, $available_sets = 'lud');
     $fileName = $prefix . $randomStr . $suffix . '.' . $extension;
     while (check_file($directory . $fileName)) {
         $fileName = generate_filename($directory, $extension, $options);
     }
     return $fileName;
 }