function post($args, $options, $postfix = '') { global $wpdb; extract($args); $form_data = tdomf_get_form_data($tdomf_form_id); $modifypost = false; if ($options['post-title'] || $options['a'] || $options['img'] || $options['attach-a'] || $options['attach-thumb-a'] || $options['thumb-a']) { // Grab existing data $post = wp_get_single_post($post_ID, ARRAY_A); if (!empty($post['post_content'])) { $post = add_magic_quotes($post); } $content = $post['post_content']; $title = $post['post_title']; $cats = $post['post_category']; } $filecount = 0; $theirfiles = $form_data['uploadfiles_' . $tdomf_form_id . '_' . $postfix]; for ($i = 0; $i < $options['max']; $i++) { if (!file_exists($theirfiles[$i]['path'])) { unset($theirfiles[$i]); } else { $filecount++; // move file $postdir = $options['path'] . DIRECTORY_SEPARATOR . $post_ID; tdomf_recursive_mkdir($postdir, TDOMF_UPLOAD_PERMS); $newpath = $postdir . DIRECTORY_SEPARATOR . $theirfiles[$i]['name']; if (rename($theirfiles[$i]['path'], $newpath)) { $newpath = realpath($newpath); // to support multiple files, we have to avoid clashes without instances $j = $this->getFreeIndexPostMeta($post_ID, TDOMF_KEY_DOWNLOAD_PATH, $i); // store info about files on post // add_post_meta($post_ID, TDOMF_KEY_DOWNLOAD_COUNT . $j, 0, true); add_post_meta($post_ID, TDOMF_KEY_DOWNLOAD_TYPE . $j, $theirfiles[$i]['type'], true); // escape the "path" incase it contains '\' as WP will strip these out! add_post_meta($post_ID, TDOMF_KEY_DOWNLOAD_PATH . $j, $wpdb->escape($newpath), true); add_post_meta($post_ID, TDOMF_KEY_DOWNLOAD_NAME . $j, $theirfiles[$i]['name'], true); // keep a list of the uploaded/created files // $this->addToFileList($post_ID, $postfix, $newpath); tdomf_log_message("File " . $theirfiles[$i]['name'] . " saved from tmp area to " . $newpath . " with type " . $theirfiles[$i]['type'] . " for post {$post_ID}"); // Execute user command // if ($options['cmd'] != "") { $cmd_output = shell_exec($options['cmd'] . " " . $newpath); tdomf_log_message("Executed user command on file {$newpath}<br/><pre>{$cmd_output}</pre>"); add_post_meta($post_ID, TDOMF_KEY_DOWNLOAD_CMD_OUTPUT . $i, $cmd_output, true); } // Use direct links or wrapper // if ($options['nohandler'] && trim($options['url']) != "") { $uri = trailingslashit($options['url']) . "{$post_ID}/" . $theirfiles[$i]['name']; } else { $uri = trailingslashit(get_bloginfo('wpurl')) . '?tdomf_download=' . $post_ID . '&id=' . $i; } // Modify Post // // modify post title if ($options['post-title']) { $modifypost = true; $title = $theirfiles[$i]['name']; } // add download link (inc name and file size) if ($options['a']) { $modifypost = true; // $content .= "<p><a href=\"$uri\">".$theirfiles[$i]['name']." (".tdomf_filesize_format(filesize($newpath)).")</a></p>"; } // add image link (inc name and file size) if ($options['img']) { $modifypost = true; // Commented out image link in post by Alexander Rea 2/28/10 // $content .= "<p><img src=\"$uri\" /></p>"; } // Use user-defined custom key if ($options['custom'] && !empty($options['custom-key'])) { add_post_meta($post_ID, $options['custom-key'], $uri); } // Insert upload as an attachment to post! if ($options['attach']) { // Create the attachment (not sure if these values are correct) // $attachment = array("post_content" => "", "post_title" => $theirfiles[$i]['name'], "post_name" => sanitize_title($theirfiles[$i]['name']), "post_status" => 'inherit', "post_parent" => $post_ID, "guid" => $uri, "post_type" => 'attachment', "post_mime_type" => $theirfiles[$i]['type'], "menu_order" => $i, "post_category" => $cats); // I dont' know if this is a wp2.8 thing, but you have to // URI for it to be properly handled as an attachment, yet... // how does it know where to generate the thumbs? $attachment_ID = wp_insert_attachment($attachment, $uri, $post_ID); // Weirdly, I have to do this now to access the wp_generate_attachement_metadata // functino from within the widget class // require_once ABSPATH . 'wp-admin/includes/image.php'; // Generate meta data (which includes thumbnail!) // $attachment_metadata = wp_generate_attachment_metadata($attachment_ID, $newpath); // add link to attachment page if ($options['attach-a']) { $content .= "<p><a href=\"" . get_permalink($attachment_ID) . "\">" . $theirfiles[$i]['name'] . " (" . tdomf_filesize_format(filesize($newpath)) . ")</a></p>"; } if (tdomf_wp23()) { // Did Wordpress generate a thumbnail? if (isset($attachment_metadata['thumb'])) { // Wordpress 2.3 uses basename and generates only the "name" of the thumb, // in general it creates it in the same place as the file! $thumbpath = $postdir . DIRECTORY_SEPARATOR . $attachment_metadata['thumb']; if (file_exists($thumbpath)) { add_post_meta($post_ID, TDOMF_KEY_DOWNLOAD_THUMB . $j, $thumbpath, true); // add to list // $this->addToFileList($post_ID, $postfix, $thumbpath); // WARNING: Don't modify the 'thumb' as this is used by Wordpress to know // if there is a thumb by using basename and the file path of the actual file // attachment // // Use direct links *or* wrapper // if ($options['nohandler'] && trim($options['url']) != "") { $thumburi = $options['url'] . "/{$post_ID}/" . $attachment_metadata['thumb']; } else { $thumburi = get_bloginfo('wpurl') . '/?tdomf_download=' . $post_ID . '&id=' . $j . '&thumb'; } // store a copy of the thumb uri add_post_meta($post_ID, TDOMF_KEY_DOWNLOAD_THUMBURI . $j, $thumburi, true); //$attachment_metadata['thumb'] = $thumb_uri; //$attachment_metadata['thumb'] = $thumbpath; // add thumbnail link to attachment page if ($options['attach-thumb-a']) { $modifypost = true; $content .= "<p><a href=\"" . get_permalink($attachment_ID) . "\"><img src=\"{$thumburi}\" alt=\"" . $theirfiles[$i]['name'] . " (" . tdomf_filesize_format(filesize($newpath)) . ")\" /></a></p>"; } // add thumbnail link directly to file if ($options['thumb-a']) { $modifypost = true; $content .= "<p><a href=\"{$uri}\"><img src=\"{$thumburi}\" alt=\"" . $theirfiles[$i]['name'] . " (" . tdomf_filesize_format(filesize($newpath)) . ")\" /></a></p>"; } } else { tdomf_log_message("Could not find thumbnail {$thumbpath}!", TDOMF_LOG_ERROR); } } } else { // In Wordpress 2.5 the attachment data structure is changed, // it only generates a thumbnail if it needs to... // Medium sized images can also sometimes be created, make a note of it // if (isset($attachment_metadata['sizes']['medium'])) { $medpath = $postdir . DIRECTORY_SEPARATOR . $attachment_metadata['sizes']['medium']['file']; if (file_exists($medpath)) { $this->addToFileList($post_ID, $postfix, $medpath); } } if (isset($attachment_metadata['sizes']['thumbnail'])) { $thumbpath = $postdir . DIRECTORY_SEPARATOR . $attachment_metadata['sizes']['thumbnail']['file']; if (file_exists($thumbpath)) { add_post_meta($post_ID, TDOMF_KEY_DOWNLOAD_THUMB . $j, $thumbpath, true); // add to list // $this->addToFileList($post_ID, $postfix, $thumbpath); // Use direct links *or* wrapper // if ($options['nohandler'] && trim($options['url']) != "") { $thumburi = $options['url'] . "/{$post_ID}/" . $attachment_metadata['sizes']['thumbnail']['file']; } else { $thumburi = get_bloginfo('wpurl') . '/?tdomf_download=' . $post_ID . '&id=' . $j . '&thumb'; } // store a copy of the thumb uri add_post_meta($post_ID, TDOMF_KEY_DOWNLOAD_THUMBURI . $j, $thumburi, true); // add thumbnail link to attachment page if ($options['attach-thumb-a']) { $modifypost = true; $content .= "<p><a href=\"" . get_permalink($attachment_ID) . "\"><img src=\"{$thumburi}\" alt=\"" . $theirfiles[$i]['name'] . " (" . tdomf_filesize_format(filesize($newpath)) . ")\" /></a></p>"; } // add thumbnail link directly to file if ($options['thumb-a']) { $modifypost = true; $content .= "<p><a href=\"{$uri}\"><img src=\"{$thumburi}\" alt=\"" . $theirfiles[$i]['name'] . " (" . tdomf_filesize_format(filesize($newpath)) . ")\" /></a></p>"; } } else { tdomf_log_message("Could not find thumbnail {$thumbpath}!", TDOMF_LOG_ERROR); } } else { if (wp_attachment_is_image($attachment_ID) && ($options['attach-thumb-a'] || $options['thumb-a'])) { // Thumbnail not generated automatically, this means that the image // is smaller than a thumbnail => use as thumbnail tdomf_log_message("No thumbnail created => image is too small. Use image as thumbnail.", TDOMF_LOG_ERROR); $modifypost = true; $sizeit = ""; $h = get_option("thumbnail_size_h"); $w = get_option("thumbnail_size_w"); if ($attachment_metadata['height'] > $h || $attachment_metadata['width'] > $w) { if ($attachment_metadata['height'] > $attachment_metadata['width']) { $sizeit = " height=\"{$h}px\" "; } else { $sizeit = " height=\"{$w}px\" "; } } // store a the uri as a the thumburi add_post_meta($post_ID, TDOMF_KEY_DOWNLOAD_THUMBURI . $j, $uri, true); // add thumbnail link to attachment page if ($options['attach-thumb-a']) { $content .= "<p><a href=\"" . get_permalink($attachment_ID) . "\"><img src=\"{$uri}\" {$sizeit} alt=\"" . $theirfiles[$i]['name'] . " (" . tdomf_filesize_format(filesize($newpath)) . ")\" /></a></p>"; } // add just the image (no point linking to thumbnail) if ($options['thumb-a']) { $content .= "<p><img src=\"{$uri}\" {$sizeit} alt=\"" . $theirfiles[$i]['name'] . " (" . tdomf_filesize_format(filesize($newpath)) . ")\" /></p>"; } } } } // Add meta data // wp_update_attachment_metadata($attachment_ID, $attachment_metadata); tdomf_log_message("Added " . $theirfiles[$i]['name'] . " as attachment"); } } else { tdomf_log_message("Failed to move " . $theirfiles[$i]['name'] . "!", TDOMF_LOG_ERROR); return __("Failed to move uploaded file from temporary location!", "tdomf"); } } } if ($modifypost) { tdomf_log_message("Attempting to update post with file upload info"); $post = array("ID" => $post_ID, "post_content" => $content, "post_title" => $title, "post_name" => sanitize_title($title)); sanitize_post($post, "db"); wp_update_post($post); } return NULL; }
function tdomf_forms_under_title_toolbar($form_id_in = false, $current = 'tdomf_show_form_options_menu') { $form_ids = tdomf_get_form_ids(); $pages = tdomf_get_option_form(TDOMF_OPTION_CREATEDPAGES, $form_id_in); if (tdomf_wp23()) { /* do nothing */ } else { if (tdomf_wp27()) { ?> <ul class="subsubsub"> <li> <a <?php if ($current == 'tdomf_show_form_options_menu') { ?> class="current" <?php } ?> href="admin.php?page=tdomf_show_form_options_menu&form=<?php echo $form_id_in; ?> "><?php printf(__("Options", "tdomf"), $form_id_in); ?> </a> |</li> <li> <a <?php if ($current == 'tdomf_show_form_menu') { ?> class="current" <?php } ?> href="admin.php?page=tdomf_show_form_menu&form=<?php echo $form_id_in; ?> "><?php printf(__("Create", "tdomf"), $form_id_in); ?> </a> |</li> <li> <a <?php if ($current == 'tdomf_show_form_hacker' && !isset($_REQUEST['text'])) { ?> class="current" <?php } ?> href="admin.php?page=tdomf_show_form_hacker&form=<?php echo $form_id_in; ?> "><?php printf(__("Hack", "tdomf"), $form_id_in); ?> </a> |</li> <li> <a <?php if ($current == 'tdomf_show_form_hacker' && isset($_REQUEST['text'])) { ?> class="current" <?php } ?> href="admin.php?page=tdomf_show_form_hacker&text&form=<?php echo $form_id_in; ?> "><?php printf(__("Messages", "tdomf"), $form_id_in); ?> </a> |</li> <li> <a <?php if ($current == 'tdomf_show_form_export_menu') { ?> class="current" <?php } ?> href="admin.php?page=tdomf_show_form_export_menu&form=<?php echo $form_id_in; ?> "><?php printf(__("Export", "tdomf"), $form_id_in); ?> </a> |</li> <?php if ($pages != false && is_array($pages)) { ?> <li><a href="<?php echo get_permalink($pages[0]); ?> " title="<?php echo htmlentities(_e("Live on your blog!", "tdomf"), ENT_QUOTES); ?> " ><?php _e("View Page »", "tdomf"); ?> </a> |</li> <?php } ?> <?php if (tdomf_get_option_form(TDOMF_OPTION_INCLUDED_YOUR_SUBMISSIONS, $form_id_in) && get_option(TDOMF_OPTION_YOUR_SUBMISSIONS)) { ?> <li><a href="users.php?page=tdomf_your_submissions#tdomf_form<?php echo $form_id_in; ?> " title="<?php _e("Included on the 'Your Submissions' page!", 'tdomf'); ?> " > <?php _e("View on 'Your Submissions' »", "tdomf"); ?> </a> |</li> <?php } ?> </ul> <div class="tablenav"> <div class="alignleft"> <a class="button" title="<?php echo htmlentities(__('Create a new form', 'tdomf'), ENT_QUOTES); ?> " href="<?php echo wp_nonce_url("admin.php?page=tdomf_show_form_options_menu&new", 'tdomf-new-form'); ?> "> <?php _e("New", "tdomf"); ?> </a> <a class="button" title="<?php echo htmlentities(__('Delete this form', 'tdomf'), ENT_QUOTES); ?> " href="<?php echo wp_nonce_url("admin.php?page=tdomf_show_form_options_menu&delete={$form_id_in}", 'tdomf-delete-form-' . $form_id_in); ?> "> <?php _e("Delete", "tdomf"); ?> </a> <a class="button" title="<?php echo htmlentities(__('Make a copy of this form', 'tdomf'), ENT_QUOTES); ?> " href="<?php echo wp_nonce_url("admin.php?page=tdomf_show_form_options_menu©={$form_id_in}&form={$form_id_in}", 'tdomf-copy-form-' . $form_id_in); ?> "> <?php _e("Copy", "tdomf"); ?> </a> </div> <!-- alignleft --> <?php if (!empty($form_ids)) { ?> <div class="alignright actions"> <div class="tablenav-pages"><span class="displaying-num"><?php _e("Forms:", 'tdomf'); ?> </span> <?php foreach ($form_ids as $form_id) { ?> <?php if ($form_id->form_id == $form_id_in) { ?> <span class='page-numbers current'><?php printf($form_id_in); ?> </span> <?php } else { $form_name = tdomf_get_option_form(TDOMF_OPTION_NAME, $form_id->form_id); ?> <a class='page-numbers' title='<?php echo htmlentities($form_name, ENT_QUOTES); ?> ' href="admin.php?page=<?php echo $current; ?> &form=<?php echo $form_id->form_id; ?> "> <?php printf($form_id->form_id); ?> </a> <?php } ?> <?php } ?> </div> <!-- alignleft actions --> <?php } ?> </div> <!-- tablenav --> </div> <!-- wrap --> <div class="wrap"> <?php } else { if (tdomf_wp25()) { ?> <ul class="subsubsub"> <?php if (!empty($form_ids)) { foreach ($form_ids as $form_id) { ?> <li><a href="admin.php?page=tdomf_show_form_options_menu&form=<?php echo $form_id->form_id; ?> "<?php if ($form_id->form_id == $form_id_in) { ?> class="current" <?php } ?> > <?php printf(__("Form %d", "tdomf"), $form_id->form_id); ?> </a> |</li> <?php } } ?> <?php if (function_exists('wp_nonce_url')) { ?> <li><a href="<?php echo wp_nonce_url("admin.php?page=tdomf_show_form_options_menu&new", 'tdomf-new-form'); ?> "> <?php _e("New Form »", "tdomf"); ?> </a></li> <?php } else { ?> <li><a href="admin.php?page=tdomf_show_form_options_menu&new"><?php _e("New Form »", "tdomf"); ?> </a></li> <?php } ?> </ul> <ul class="subsubsub"> <?php if (function_exists('wp_nonce_url')) { ?> <li><a href="<?php echo wp_nonce_url("admin.php?page=tdomf_show_form_options_menu&delete={$form_id}", 'tdomf-delete-form-' . $form_id); ?> "> <?php _e("Delete", "tdomf"); ?> </a> |</li> <li><a href="<?php echo wp_nonce_url("admin.php?page=tdomf_show_form_options_menu©={$form_id}&form={$form_id}", 'tdomf-copy-form-' . $form_id); ?> "> <?php _e("Copy", "tdomf"); ?> </a> |</li> <?php } else { ?> <li><a href="admin.php?page=tdomf_show_form_options_menu&delete=<?php echo $form_id; ?> "><?php _e("Delete", "tdomf"); ?> </a> |</li> <li><a href="admin.php?page=tdomf_show_form_options_menu©=<?php echo $form_id; ?> "><?php _e("Copy", "tdomf"); ?> </a> |</li> <?php } ?> <?php if ($pages != false) { ?> <li><a href="<?php echo get_permalink($pages[0]); ?> " title="<?php _e("Live on your blog!", "tdomf"); ?> " ><?php _e("View Page »", "tdomf"); ?> </a> |</li> <?php } ?> <?php if (tdomf_get_option_form(TDOMF_OPTION_INCLUDED_YOUR_SUBMISSIONS, $form_id) && get_option(TDOMF_OPTION_YOUR_SUBMISSIONS)) { ?> <li><a href="users.php?page=tdomf_your_submissions#tdomf_form<?php echo $form_id; ?> " title="<?php _e("Included on the 'Your Submissions' page!", 'tdomf'); ?> " > <?php _e("View on 'Your Submissions' »", "tdomf"); ?> </a> |</li> <?php } ?> <li><a href="admin.php?page=tdomf_show_form_menu&form=<?php echo $form_id; ?> "><?php printf(__("Widgets »", "tdomf"), $form_id); ?> </a> |</li> <li><a href="admin.php?page=tdomf_show_form_hacker&form=<?php echo $form_id; ?> "><?php printf(__("Hack Form »", "tdomf"), $form_id); ?> </a></li> </ul> <?php } } } }