function hj_framework_process_inputs($hook, $type, $return, $params) { $entity = elgg_extract('entity', $params, false); $field = elgg_extract('field', $params, false); if (!$entity || !$field || !elgg_instanceof($entity)) { return true; } $type = $entity->getType(); $subtype = $entity->getSubtype(); switch ($field->input_type) { case 'file': if (elgg_is_logged_in()) { global $_FILES; $field_name = $field->name; $file = $_FILES[$field_name]; // Maybe someone doesn't want us to save the file in this particular way if (!empty($file['name']) && !elgg_trigger_plugin_hook('hj:framework:form:fileupload', 'all', array('entity' => $entity, 'file' => $file, 'field_name' => $field_name), false)) { hj_framework_process_file_upload($file, $entity, $field_name); } } break; case 'entity_icon': $field_name = $field->name; global $_FILES; if (isset($_FILES[$field_name]) && substr_count($_FILES[$field_name]['type'], 'image/')) { hj_framework_generate_entity_icons($entity, $field_name); $entity->{$field_name} = null; } break; case 'relationship_tags': $field_name = $field->name; $tags = get_input('relationship_tag_guids'); $relationship_name = get_input('relationship_tags_name', 'tagged_in'); $current_tags = elgg_get_entities_from_relationship(array('relationship' => $relationship_name, 'relationship_guid' => $entity->guid, 'inverse_relationship' => true)); if (is_array($current_tags)) { foreach ($current_tags as $current_tag) { if (!in_array($current_tag->guid, $tags)) { remove_entity_relationship($current_tag->guid, $relationship_name, $entity->guid); } } } if (is_array($tags)) { foreach ($tags as $tag_guid) { add_entity_relationship($tag_guid, $relationship_name, $entity->guid); } $tags = implode(',', $tags); } $entity->{$field_name} = $tags; break; case 'multifile': if (elgg_is_logged_in()) { $values = get_input($field->name); if (is_array($values)) { foreach ($values as $value) { create_metadata($entity->guid, $field->name, $value, '', $entity->owner_guid, $entity->access_id, true); if (!elgg_trigger_plugin_hook('hj:framework:form:multifile', 'all', array('entity' => $entity, 'file_guid' => $value, 'field_name' => $field_name), false)) { make_attachment($entity->guid, $value); } } } } break; } return true; }
function hj_framework_process_file_input($hook, $type, $return, $params) { if (!elgg_is_logged_in()) { return false; } // Maybe someone doesn't want us to save the file in this particular way if (!elgg_trigger_plugin_hook('process:upload', 'form:input:type:file', $params, false)) { hj_framework_process_file_upload($params['name'], $params['entity']); } return true; }
<?php /** * An action to process temporary file uploads. * Creates new entities and disables them * * @uses $_FILES['file_temp'] Looks for file_temp uploads */ $guids = hj_framework_process_file_upload('file_temp'); if ($guids) { foreach ($guids as $name => $guid) { $response[$name] = $guid; $entity = get_entity($guid); if ($entity) { $entity->disable('temp_file_upload'); } } } if (elgg_is_xhr()) { print json_encode($response); } forward('', 'action');