subtype = "news"; // Set its owner to the current user $news->owner_guid = $_SESSION['user']->getGUID(); // Set access according to user role $news->access_id = $access_id; // Set its title and description appropriately $news->title = $title; $news->description = $body; // Before we can set metadata, we need to save the news if (!$news->save()) { /*translation:Error occured, object could not be saved.*/ register_error(elgg_echo("koolielu:error_not_saved")); forward("mod/info/add_news.php"); } // Now let's add tags. We can pass an array directly to the object property! Easy. if (is_array($tagarray)) { $news->tags = $tagarray; } // Custom metadata $news->categories = $categories; $news->subjects = $subjects; $news->targetgroup = $targetgroup; $news->shortdescription = $short_description; // Convert any date format into timestamp if (!empty($deadline)) $deadline = dateIntoTimestamp($deadline); $news->deadline = $deadline; if (!empty($publishing_end)) $publishing_end = dateIntoTimestamp($publishing_end); $news->publishing_end = $publishing_end; if (!empty($begin)) $begin = dateIntoTimestamp($begin); $news->begin = $begin; if (!empty($end)) $end = dateIntoTimestamp($end); $news->end = $end; $news->approved = $approved; $news->frontpage = 0; $news->archived = 0; unassociate_prioval($prioval); $news->prioval = $prioval; // Send data to base $sql = "INSERT INTO {$CONFIG->dbprefix}koolielu_calendar_objects (guid, type, title, description, approved, time2_begin, time2_end, time1_begin, time1_end) VALUES (".$news->getGUID().",'".$news->subtype."','".mysql_real_escape_string($news->title)."','".mysql_real_escape_string($news->shortdescription)."',".(int)$news->approved.",'".$news->deadline."','".$news->publishing_end."','".$news->begin."','".$news->end."')"; insert_data($sql); foreach ($subjects as $s) { $sql = "INSERT INTO {$CONFIG->dbprefix}koolielu_calendar_subject_refs (cal_object_id, subject_id) VALUES (".$news->getGUID().", ".$s.")"; insert_data($sql); } // Deal with image if ((isset($_FILES['newsimage'])) && (substr_count($_FILES['newsimage']['type'],'image/'))) { $supported_formats = getSupportedImageFormats(); $image = get_uploaded_file('newsimage'); // See if we even support the format first if (in_array(exif_imagetype($_FILES['newsimage']['tmp_name']),$supported_formats)) { // Save it $original = saveImageFile($news->getGUID() . '.original', $image, $news->getOwner()); // Write original file name into objects metadata $news->original_file_name = $_FILES['newsimage']['name']; if (!original) { /*translation:Original image could not be saved.*/ register_error(elgg_echo('koolielu:error_original_image_not_saved')); } $resized_image = get_resized_image_from_uploaded_file('newsimage', 150, 150, false); // Save it $resized = saveImageFile("small_" . $news->getGUID() . ".jpg", $resized_image, $news->getOwner()); if (!$resized) { /*translation:Resized image could not be saved.*/ register_error(elgg_echo('koolielu:error_resized_image_not_saved')); } $resized_listing_image = get_resized_image_from_uploaded_file('newsimage', 40, 40, false); // Save it $resized_listing = saveImageFile("listing_" . $news->getGUID() . ".jpg", $resized_listing_image, $news->getOwner()); if (!$resized_listing) { /*translation:Resized image could not be saved.*/ register_error(elgg_echo('koolielu:error_resized_image_not_saved')); } } else { /*translation:Image format not supported. Supported formats are: .jpg, .png, .jpeg and .gif.*/ register_error(elgg_echo('koolielu:error_supported_image_formats')); } } // Setting access and sending message if needed if (!(isEditor() || isModerator())) { $send_message = true; // Sending message to Editors $recipient_users = getAllEditors(); if (is_array($recipient_users) && sizeof($recipient_users) > 0) { foreach($recipient_users as $recipient) { // Prepare message content /*translation:News moderation notification.*/ $mess_title= elgg_echo('koolielu:news_moderation_notification_title'); /*translation:A news %s has been added and requires your approval. You can find see all the news waiting to be reviewed here: Unapproved news.*/ $mess_description = sprintf(elgg_echo('koolielu:news_moderation_notification_body'), $news->getURL(), $news->title, $CONFIG->wwwroot . "pg/info/unapproved"); $messages = array('title' => $mess_title, 'description' => $mess_description); // Send message send_system_message($recipient->getGUID(), $messages); } } } // Success message /*translation:News added.*/ system_message(elgg_echo("koolielu:message_news_added")); if ($send_message) { /*translation:Moderation notification sent.*/ system_message(elgg_echo('koolielu:message_moderation_notification_sent')); } else { // river add_to_river('river/object/news/create','create',$_SESSION['user']->guid,$news->guid); } // Remove the news cache unset($_SESSION['newstitle']); unset($_SESSION['newsbody']); unset($_SESSION['newsshortdescription']); unset($_SESSION['newstags']); unset($_SESSION['newscategories']); unset($_SESSION['newssubjects']); unset($_SESSION['newstargetgroup']); unset($_SESSION['newsdeadline']); unset($_SESSION['newspublishingend']); unset($_SESSION['newsbegin']); unset($_SESSION['newsend']); // Forward to the main info page forward($news->getURL()); } ?>