예제 #1
0
 /**
  * Prepare and sanitise the table prior to saving.
  *
  * @since	3.4.0
  */
 protected function prepareTable($table)
 {
     $app = JFactory::getApplication();
     $date = JFactory::getDate();
     $user = JFactory::getUser();
     if (empty($table->id)) {
         // Set the values
         $table->created = $date->toSql();
         // Set ordering to the last item if not set
         if (empty($table->ordering)) {
             $db = JFactory::getDbo();
             $query = $db->getQuery(true)->select('MAX(ordering)')->from($db->quoteName('#__icagenda_customfields'));
             $db->setQuery($query);
             $max = $db->loadResult();
             $table->ordering = $max + 1;
         }
     } else {
         // Set the values
         $table->modified = $date->toSql();
         $table->modified_by = $user->get('id');
     }
     // Alter the title for save as copy
     if ($app->input->get('task') == 'save2copy') {
         $table->title = iCString::increment($table->title);
         $table->alias = iCString::increment($table->alias, 'dash');
         $table->slug = iCString::increment($table->slug, 'underscore');
         $table->state = '0';
     }
 }
예제 #2
0
파일: submit.php 프로젝트: madcsaba/li-de
 protected function frontendImageUpload($image)
 {
     // Get Joomla Images PATH set
     $params = JComponentHelper::getParams('com_media');
     $image_path = $params->get('image_path');
     // Clean up filename
     $imagename = JFile::makeSafe($image['name']);
     // Process filename
     while (JFile::exists(JPATH_ROOT . '/' . $image_path . '/icagenda/frontend/images/' . $imagename)) {
         $src = $image['tmp_name'];
         // Get Image title and extension type
         $decomposition = explode('/', $imagename);
         // in each parent
         $i = 0;
         while (isset($decomposition[$i])) {
             $i++;
         }
         $i--;
         $imgname = $decomposition[$i];
         $fichier = explode('.', $decomposition[$i]);
         $imgtitle = $fichier[0];
         $imgextension = isset($fichier[1]) ? $fichier[1] : '';
         // Increment filename if already exists
         $imagename = iCString::increment($imgtitle, 'dash') . '.' . $imgextension;
         // Controls image mimetype, and fixes file extension if missing in filename
         $allowed_mimetypes = array('jpg', 'jpeg', 'png', 'gif');
         if (!in_array($imgextension, $allowed_mimetypes)) {
             $fileinfos = getimagesize($src);
             $mimeType = $fileinfos['mime'];
             $ex_mimeType = explode('/', $mimeType);
             $file_extension = $ex_mimeType[1];
             $imagename = $imagename . '.' . $file_extension;
         }
     }
     if ($imagename != '') {
         //Set up the source and destination of the file
         $src = $image['tmp_name'];
         $dest = JPATH_SITE . '/images/icagenda/frontend/images/' . $imagename;
         // Create Folder iCagenda in ROOT/IMAGES_PATH/icagenda and sub-folders if do not exist
         $folder[0][0] = 'icagenda/frontend/';
         $folder[0][1] = JPATH_ROOT . '/' . $image_path . '/' . $folder[0][0];
         $folder[1][0] = 'icagenda/frontend/images/';
         $folder[1][1] = JPATH_ROOT . '/' . $image_path . '/' . $folder[1][0];
         $error = array();
         foreach ($folder as $key => $value) {
             if (!JFolder::exists($value[1])) {
                 if (JFolder::create($value[1], 0755)) {
                     $this->data = "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>";
                     JFile::write($value[1] . "/index.html", $this->data);
                     $error[] = 0;
                 } else {
                     $error[] = 1;
                 }
             } else {
                 $error[] = 0;
             }
         }
         if (JFile::upload($src, $dest, false)) {
             return 'images/icagenda/frontend/images/' . $imagename;
         }
     }
 }