public function check() { $this->title = trim($this->title); if (empty($this->title)) { return false; } if (empty($this->name)) { $this->name = $this->title; $this->name = JCckDev::toSafeSTRING($this->name); if (trim(str_replace('_', '', $this->name)) == '') { $datenow = JFactory::getDate(); $this->name = $datenow->format('Y_m_d_H_i_s'); } } return true; }
public function onCCK_FieldPrepareStore(&$field, $value = '', &$config = array(), $inherit = array(), $return = false) { if (self::$type != $field->type) { return; } // Init $app = JFactory::getApplication(); $options2 = JCckDev::fromJSON($field->options2); if (count($inherit)) { $name = isset($inherit['name']) && $inherit['name'] != '' ? $inherit['name'] : $field->name; $xk = isset($inherit['xk']) ? $inherit['xk'] : -1; $xi = isset($inherit['xi']) ? $inherit['xi'] : -1; $parent = isset($inherit['parent']) ? $inherit['parent'] : ''; $array_x = isset($inherit['array_x']) ? $inherit['array_x'] : 0; $itemPath = isset($inherit['post']) ? $inherit['post'][$name . '_hidden'] : @$config['post'][$name . '_hidden']; $deleteBox = isset($inherit['post']) ? @$inherit['post'][$name . '_delete'] : @$config['post'][$name . '_delete']; $imageTitle = isset($inherit['post']) ? @$inherit['post'][$name . '_title'] : @$config['post'][$name . '_title']; $imageDesc = isset($inherit['post']) ? @$inherit['post'][$name . '_description'] : @$config['post'][$name . '_description']; $imageCustomDir = isset($inherit['post']) ? @$inherit['post'][$name . '_path'] : @$config['post'][$name . '_path']; } else { $name = $field->name; $xk = -1; $xi = -1; $parent = ''; $array_x = 0; $itemPath = @$config['post'][$name . '_hidden']; $deleteBox = @$config['post'][$name . '_delete']; $imageTitle = @$config['post'][$name . '_title']; $imageDesc = @$config['post'][$name . '_description']; $imageCustomDir = @$config['post'][$name . '_path']; } // Prepare $legal_ext = isset($options2['media_extensions']) ? $options2['media_extensions'] : 'custom'; if ($legal_ext == 'custom') { $legal_ext = $options2['legal_extensions']; } else { $legal_ext = JCck::getConfig_Param('media_' . $legal_ext . '_extensions'); if (!$legal_ext) { $legal_ext = $options2['legal_extensions']; } } $legal_ext = explode(',', $legal_ext); $userfile = $array_x ? JRequest::getVar($parent, NULL, 'files', 'array') : JRequest::getVar($name, NULL, 'files', 'array'); if (is_array($userfile['name'])) { if ($array_x) { $userfile_name = $userfile['name'][$xk][$name]; $userfile_type = $userfile['type'][$xk][$name]; $userfile_tmp_name = $userfile['tmp_name'][$xk][$name]; $userfile_error = $userfile['error'][$xk][$name]; $userfile_size = $userfile['size'][$xk][$name]; $userfile = null; $userfile = array(); $userfile['name'] = $userfile_name; $userfile['type'] = $userfile_type; $userfile['tmp_name'] = $userfile_tmp_name; $userfile['error'] = $userfile_error; $userfile['size'] = $userfile_size; } else { $userfile_name = $userfile['name'][$xk]; $userfile_type = $userfile['type'][$xk]; $userfile_tmp_name = $userfile['tmp_name'][$xk]; $userfile_error = $userfile['error'][$xk]; $userfile_size = $userfile['size'][$xk]; $userfile = null; $userfile = array(); $userfile['name'] = $userfile_name; $userfile['type'] = $userfile_type; $userfile['tmp_name'] = $userfile_tmp_name; $userfile['error'] = $userfile_error; $userfile['size'] = $userfile_size; if (is_array($itemPath)) { $itemPath = trim($itemPath[$xk]); } if (is_array($imageTitle)) { $imageTitle = trim($imageTitle[$xk]); } if (is_array($imageDesc)) { $imageDesc = trim($imageDesc[$xk]); } if (is_array($imageCustomDir)) { $imageCustomDir = trim($imageCustomDir[$xk]); } if (is_array($deleteBox)) { $deleteBox = $deleteBox[$xk]; } } } if ($deleteBox == 1) { $title = strrpos($itemPath, '/') ? substr($itemPath, strrpos($itemPath, '/') + 1) : $itemPath; if (self::_checkPath($config['pk'], $options2, $itemPath, $legal_ext)) { if ($itemPath != $field->defaultvalue) { if ($options2['path_user']) { $user_folder = substr($itemPath, 0, strrpos($itemPath, '/')); if ($options2['path_content']) { $user_folder = substr($user_folder, 0, strrpos($user_folder, '/')); } $user_folder = substr($user_folder, strrpos($user_folder, '/') + 1) . '/'; } else { $user_folder = ''; } $content_folder = $options2['path_content'] ? $config['pk'] . '/' : ''; for ($i = 1; $i < 11; $i++) { if (JFile::exists(JPATH_SITE . '/' . $options2['path'] . $user_folder . $content_folder . '_thumb' . $i . '/' . $title)) { JFile::delete(JPATH_SITE . '/' . $options2['path'] . $user_folder . $content_folder . '_thumb' . $i . '/' . $title); } } if (JFile::exists(JPATH_SITE . '/' . $options2['path'] . $user_folder . $content_folder . $title)) { JFile::delete(JPATH_SITE . '/' . $options2['path'] . $user_folder . $content_folder . $title); } } $itemPath = ''; } } $file_path = ''; $process = false; switch (@$options2['size_unit']) { case '0': $unit_prod = 1; break; case '1': $unit_prod = 1000; break; case '2': $unit_prod = 1000000; break; default: $unit_prod = 1; break; } $maxsize = floatval($options2['max_size']) * $unit_prod; $filename = JFile::stripExt($userfile['name']); $userfile['name'] = str_replace($filename, JCckDev::toSafeSTRING($filename, JCck::getConfig_Param('media_characters', '-'), JCck::getConfig_Param('media_case', 0)), $userfile['name']); if (!$maxsize || $maxsize && $userfile['size'] < $maxsize) { if ($userfile && $userfile['name'] && $userfile['tmp_name']) { $ImageCustomName = $userfile['name']; $ImageCustomPath = ''; if (@$options2['custom_path']) { if (strrpos($imageCustomDir, '.') === false) { $ImageCustomPath = $imageCustomDir == '' ? substr($itemPath, 0, strrpos($itemPath, '/') + 1) : ($imageCustomDir[strlen($imageCustomDir) - 1] == '/' ? $imageCustomDir : $imageCustomDir . '/'); } else { $ImageCustomPath = substr($itemPath, 0, strrpos($itemPath, '/') + 1); } } if (count($legal_ext)) { $old_legal = strrpos($userfile['name'], '.') ? substr($userfile['name'], strrpos($userfile['name'], '.') + 1) : ''; $legal = $ImageCustomName == $userfile['name'] ? $old_legal : substr($ImageCustomName, strrpos($ImageCustomName, '.') + 1); if ($old_legal && array_search($old_legal, $legal_ext) === false) { JFactory::getApplication()->enqueueMessage($ImageCustomName . ' - ' . JText::_('COM_CCK_ERROR_LEGAL_EXTENSIONS'), 'notice'); $field->error = true; } else { if (trim($legal) != trim($old_legal)) { $ImageCustomName .= '.' . trim($old_legal); } } } $file_path = $ImageCustomPath ? $ImageCustomPath : $options2['path']; $current_user = JFactory::getUser(); $current_user_id = $current_user->id; if (strpos($file_path, '/' . $current_user_id . '/') === false) { $file_path .= $options2['path_user'] && $current_user_id ? $current_user_id . '/' : ''; } if (strpos($file_path, '/' . $config['pk'] . '/') === false) { $file_path .= $options2['path_content'] && $config['pk'] > 0 ? $config['pk'] . '/' : ''; } $value = $file_path . $ImageCustomName; $process = true; } else { if ($deleteBox == 1) { $imageTitle = ''; $imageDesc = ''; } if ($imageCustomDir != '' && strrpos($imageCustomDir, '.') > 0 && JFile::exists(JPATH_SITE . '/' . $imageCustomDir)) { if (count($legal_ext)) { $legal = strrpos($imageCustomDir, '.') ? substr($imageCustomDir, strrpos($imageCustomDir, '.') + 1) : ''; if ($legal && array_search($legal, $legal_ext) === false) { JFactory::getApplication()->enqueueMessage($imageCustomDir . ' - ' . JText::_('COM_CCK_ERROR_LEGAL_EXTENSIONS'), 'notice'); $field->error = true; } } $value = $imageCustomDir; } else { if ($userfile['name']) { JFactory::getApplication()->enqueueMessage(JText::_('COM_CCK_ERROR_INVALID_FILE'), "error"); $field->error = true; } if ($options2['path'] == $itemPath) { $value = ''; } else { if ($xk != -1 && !$array_x) { $value = $itemPath == $options2['path'] ? '' : $itemPath; } else { $value = $itemPath; } } } } } else { JFactory::getApplication()->enqueueMessage($userfile['name'] . ' - ' . JText::_('COM_CCK_ERROR_MAX_SIZE'), 'notice'); $field->error = true; } // Validate parent::g_onCCK_FieldPrepareStore_Validation($field, $name, $value, $config); if (isset($field->error) && $field->error === true) { return; } $imageTitle = $imageTitle ? addcslashes($imageTitle, '"') : ''; $imageDesc = $imageDesc ? addcslashes($imageDesc, '"') : ''; // Add Process if ($process === true) { $content_folder = $options2['path_content'] ? $options2['path_content'] : 0; $process_params = array('field_name' => $name, 'true_name' => $field->name, 'array_x' => $array_x, 'parent_name' => $parent, 'field_type' => $field->type, 'file_path' => $file_path, 'file_name' => $ImageCustomName, 'tmp_name' => $userfile['tmp_name'], 'xi' => $xi, 'content_folder' => $content_folder, 'options2' => $options2, 'storage' => $field->storage, 'storage_field' => $field->storage_field, 'storage_field2' => $field->storage_field2 ? $field->storage_field2 : $field->name, 'storage_table' => $field->storage_table, 'file_title' => $imageTitle, 'file_descr' => $imageDesc); parent::g_addProcess('afterStore', self::$type, $config, $process_params); } $value = !$options2['multivalue_mode'] || $imageTitle == '' && $imageDesc == '' ? $value : '{"image_location":"' . $value . '","image_title":"' . $imageTitle . '","image_description":"' . $imageDesc . '"}'; if ($return === true) { return $value; } $field->value = $value; parent::g_onCCK_FieldPrepareStore($field, $name, $value, $config); }