function awpcp_new_media_manager()
{
    static $instance = null;
    if (is_null($instance)) {
        $instance = new AWPCP_NewMediaManager(awpcp_media_api(), awpcp_uploaded_file_logic_factory(), awpcp()->settings);
    }
    return $instance;
}
function awpcp_update_file_status_ajax_handler()
{
    return new AWPCP_UpdateFileStatusAjaxHandler(awpcp_media_api(), awpcp_files_collection(), awpcp_listings_collection(), awpcp_request(), awpcp_ajax_response());
}
Example #3
0
 public function upload_images_form($ad, $params = array())
 {
     $show_preview = (bool) get_awpcp_option('show-ad-preview-before-payment');
     $pay_first = (bool) get_awpcp_option('pay-before-place-ad');
     extract($params);
     if ($images_uploaded > 0 && $pay_first) {
         $next = __('Finish', 'AWPCP');
     } else {
         if ($images_uploaded == 0 && false == $pay_first && $show_preview) {
             $next = __('Preview Ad', 'AWPCP');
         } else {
             if ($images_uploaded == 0) {
                 $next = __('Place Ad', 'AWPCP');
             } else {
                 if ($show_preview) {
                     $next = __('Preview Ad', 'AWPCP');
                 } else {
                     $next = __('Checkout', 'AWPCP');
                 }
             }
         }
     }
     $params = array_merge($params, array('listing' => $ad, 'files' => awpcp_media_api()->find_by_ad_id($ad->ad_id), 'messages' => $this->messages, 'next' => $next));
     $template = AWPCP_DIR . '/frontend/templates/page-place-ad-upload-images-step.tpl.php';
     return $this->render($template, $params);
 }
Example #4
0
/**
 * Upload and associates the given files with the specified Ad.
 *
 * @param $files    An array of elements of $_FILES.
 * @since 3.0.2
 * @deprecated 3.4
 */
function awpcp_upload_files($ad, $files, &$errors = array())
{
    $media = awpcp_media_api();
    $constraints = awpcp_get_upload_file_constraints();
    $image_mime_types = awpcp_get_image_mime_types();
    $uploaded = array();
    foreach ($files as $name => $info) {
        $can_upload = awpcp_can_upload_file_to_ad($info, $ad);
        if ($can_upload !== true) {
            if ($can_upload !== false) {
                $errors[$name] = $can_upload;
            } else {
                $message = _x('An error occurred trying to upload the file %s.', 'upload files', 'AWPCP');
                $errors[$name] = sprintf($message, '<strong>' . $info['name'] . '</strong>');
            }
            continue;
        }
        if ($result = awpcp_upload_file($info, $constraints, $error)) {
            $file = $media->create(array('ad_id' => $ad->ad_id, 'name' => $result['filename'], 'path' => $result['path'], 'mime_type' => $result['mime_type'], 'is_primary' => in_array($info['type'], $image_mime_types) && awpcp_array_data('is_primary', false, $info)));
            if (!is_null($file)) {
                if ($file->is_image() && $file->is_primary()) {
                    $media->set_ad_primary_image($ad, $file);
                }
                $uploaded[] = $file;
            } else {
                $message = _x('The file %s was properly uploaded but there was a problem trying to save the information to the database.', 'upload files', 'AWPCP');
                $errors[$name] = sprintf($message, '<strong>' . $result['original'] . '</strong>');
            }
        } else {
            $errors[$name] = $error;
        }
    }
    return $uploaded;
}
 private function get_files($ad)
 {
     $allowed_mime_types = awpcp_get_allowed_mime_types();
     $image_mime_types = awpcp_get_image_mime_types();
     $files = awpcp_media_api()->find_by_ad_id($ad->ad_id, array('order' => array('mime_type ASC', 'id ASC')));
     $groups = array();
     foreach ($files as $file) {
         $extension = strtolower(awpcp_get_file_extension($file->name));
         $mime_type = $file->mime_type;
         if (!in_array($mime_type, $allowed_mime_types)) {
             continue;
         } else {
             if (in_array($mime_type, $image_mime_types)) {
                 $groups['images'][] = $file;
             } else {
                 $groups[$extension][] = $file;
             }
         }
     }
     return $groups;
 }
 public function manage_images($listing)
 {
     $allowed_files = awpcp_listing_upload_limits()->get_listing_upload_limits($listing);
     $params = array('listing' => $listing, 'files' => awpcp_media_api()->find_by_ad_id($listing->ad_id), 'media_manager_configuration' => array('nonce' => wp_create_nonce('awpcp-manage-listing-media-' . $listing->ad_id), 'allowed_files' => $allowed_files, 'show_admin_actions' => awpcp_current_user_is_moderator()), 'media_uploader_configuration' => array('listing_id' => $listing->ad_id, 'nonce' => wp_create_nonce('awpcp-upload-media-for-listing-' . $listing->ad_id), 'allowed_files' => $allowed_files), 'urls' => array('view-listing' => $this->url(array('action' => 'view', 'id' => $listing->ad_id)), 'listings' => $this->url(array('id' => null))));
     echo $this->render(AWPCP_DIR . '/templates/admin/listings-media-center.tpl.php', $params);
 }
Example #7
0
 public function enable($approve_images = true, $trigger_actions = true)
 {
     $listing_enabled = $this->set_disabled_status(false);
     if ($listing_enabled) {
         if ($approve_images) {
             $images = awpcp_media_api()->find_images_awaiting_approval_by_ad_id($this->ad_id);
             foreach ($images as $image) {
                 awpcp_media_api()->approve($image);
             }
         }
         if ($trigger_actions) {
             do_action('awpcp_approve_ad', $this);
         }
     }
     return $listing_enabled;
 }
function awpcp_upload_generated_thumbnail_ajax_handler()
{
    return new AWPCP_UploadGeneratedThumbnailAjaxHandler(awpcp_image_resizer(), awpcp_media_api(), awpcp_listings_collection(), awpcp()->settings, awpcp_request(), awpcp_ajax_response());
}
Example #9
0
/**
 * @since 3.0
 */
function awpcp_do_placeholder_images($ad, $placeholder)
{
    global $wpdb;
    global $awpcp_imagesurl;
    static $replacements = array();
    if (isset($replacements[$ad->ad_id])) {
        return $replacements[$ad->ad_id][$placeholder];
    }
    $placeholders = array('featureimg' => '', 'awpcpshowadotherimages' => '', 'images' => '', 'awpcp_image_name_srccode' => '');
    $url = awpcp_listing_renderer()->get_view_listing_url($ad);
    $thumbnail_width = get_awpcp_option('displayadthumbwidth');
    if (awpcp_are_images_allowed()) {
        $images_uploaded = $ad->count_image_files();
        $primary_image = awpcp_media_api()->get_ad_primary_image($ad);
        $gallery_name = 'awpcp-gallery-' . $ad->ad_id;
        if ($primary_image) {
            $large_image = $primary_image->get_large_image_url('large');
            $thumbnail = $primary_image->get_primary_thumbnail_url('primary');
            if (get_awpcp_option('show-click-to-enlarge-link', 1)) {
                $link = '<a class="thickbox enlarge" href="%s">%s</a>';
                $link = sprintf($link, $large_image, __('Click to enlarge image.', 'AWPCP'));
            } else {
                $link = '';
            }
            // single ad
            $content = '<div class="awpcp-ad-primary-image">';
            $content .= '<a class="awpcp-listing-primary-image-thickbox-link thickbox thumbnail" href="%s" rel="%s">';
            $content .= '<img class="thumbshow" src="%s"/>';
            $content .= '</a>%s';
            $content .= '</div>';
            $placeholders['featureimg'] = sprintf($content, esc_attr($large_image), $gallery_name, esc_attr($thumbnail), $link);
            // listings
            $content = '<a class="awpcp-listing-primary-image-listing-link" href="%s"><img src="%s" width="%spx" border="0" alt="%s" /></a>';
            $content = sprintf($content, $url, $thumbnail, $thumbnail_width, awpcp_esc_attr($ad->ad_title));
            $placeholders['awpcp_image_name_srccode'] = $content;
        }
        if ($images_uploaded >= 1) {
            $results = awpcp_media_api()->find_public_images_by_ad_id($ad->ad_id);
            $columns = get_awpcp_option('display-thumbnails-in-columns', 0);
            $rows = $columns > 0 ? ceil(count($results) / $columns) : 0;
            $shown = 0;
            $images = array();
            foreach ($results as $image) {
                $large_image = $image->get_url('large');
                $thumbnail = $image->get_url('thumbnail');
                if ($columns > 0) {
                    $css = join(' ', awpcp_get_grid_item_css_class(array(), $shown, $columns, $rows));
                } else {
                    $css = '';
                }
                $content = '<li class="%s">';
                $content .= '<a class="thickbox" href="%s" rel="%s">';
                $content .= '<img class="thumbshow" src="%s" />';
                $content .= '</a>';
                $content .= '</li>';
                $images[] = sprintf($content, esc_attr($css), esc_attr($large_image), esc_attr($gallery_name), esc_attr($thumbnail));
                $shown = $shown + 1;
            }
            $placeholders['awpcpshowadotherimages'] = join('', $images);
            $content = '<ul class="awpcp-single-ad-images">%s</ul>';
            $placeholders['images'] = sprintf($content, $placeholders['awpcpshowadotherimages']);
        }
    }
    // fallback thumbnail
    if (awpcp_are_images_allowed() && empty($placeholders['awpcp_image_name_srccode'])) {
        $thumbnail = sprintf('%s/adhasnoimage.png', $awpcp_imagesurl);
        $content = '<a class="awpcp-listing-primary-image-listing-link" href="%s"><img src="%s" width="%spx" border="0" alt="%s" /></a>';
        $content = sprintf($content, $url, $thumbnail, $thumbnail_width, awpcp_esc_attr($ad->ad_title));
        $placeholders['awpcp_image_name_srccode'] = $content;
    }
    $placeholders['featureimg'] = apply_filters('awpcp-featured-image-placeholder', $placeholders['featureimg'], 'single', $ad);
    $placeholders['awpcp_image_name_srccode'] = apply_filters('awpcp-featured-image-placeholder', $placeholders['awpcp_image_name_srccode'], 'listings', $ad);
    $placeholders['featured_image'] = $placeholders['featureimg'];
    $placeholders['imgblockwidth'] = "{$thumbnail_width}px";
    $placeholders['thumbnail_width'] = "{$thumbnail_width}px";
    $replacements[$ad->ad_id] = apply_filters('awpcp-placeholders-image', $placeholders, $ad);
    return $replacements[$ad->ad_id][$placeholder];
}
Example #10
0
 public function get($file_id)
 {
     $file = awpcp_media_api()->find_by_id($file_id);
     if (is_null($file)) {
         $message = __('No file was found with id: %d', 'AWPCP');
         throw new AWPCP_Exception(sprintf($message, $file_id));
     }
     return $file;
 }
Example #11
0
 public function upload_images_form($ad, $params = array())
 {
     $params = array_merge($params, array('listing' => $ad, 'files' => awpcp_media_api()->find_by_ad_id($ad->ad_id), 'hidden' => array('ad_id' => $ad->ad_id, 'edit-hash' => $this->get_edit_hash($ad)), 'messages' => $this->messages, 'next' => __('Finish', 'AWPCP')));
     $template = AWPCP_DIR . '/frontend/templates/page-place-ad-upload-images-step.tpl.php';
     return $this->render($template, $params);
 }
Example #12
0
 private function save_images($entries, $adid, $row, &$errors)
 {
     global $wpdb;
     $test_import = $this->options['test-import'];
     $media_api = awpcp_media_api();
     foreach ($entries as $entry) {
         $extension = awpcp_get_file_extension($entry['filename']);
         $mime_type = sprintf('image/%s', $extension);
         $data = array('ad_id' => $adid, 'name' => $entry['filename'], 'path' => $entry['filename'], 'mime_type' => $mime_type, 'enabled' => true, 'is_primary' => false);
         $result = $test_import || $media_api->create($data);
         if ($result === false) {
             $msg = __("Could not save the information to the database for %s in row %d", 'AWPCP');
             $errors[] = sprintf($msg, $entry['original'], $row);
         }
     }
 }
function awpcp_send_to_facebook_helper()
{
    return new AWPCP_SendToFacebookHelper(AWPCP_Facebook::instance(), awpcp_listings_metadata(), awpcp_media_api());
}
function awpcp_fix_empty_media_mime_type_upgrade_routine()
{
    return new AWPCP_FixEmptyMediaMimeTypeUpgradeRoutine(awpcp_media_api(), awpcp()->settings, $GLOBALS['wpdb']);
}
Example #15
0
function awpcp_get_ad_share_info($id)
{
    global $wpdb;
    $ad = AWPCP_Ad::find_by_id($id);
    $info = array();
    if (is_null($ad)) {
        return null;
    }
    $info['url'] = url_showad($id);
    $info['title'] = stripslashes($ad->ad_title);
    $info['description'] = strip_tags(stripslashes($ad->ad_details));
    $info['description'] = str_replace("\n", " ", $info['description']);
    if (awpcp_utf8_strlen($info['description']) > 300) {
        $info['description'] = awpcp_utf8_substr($info['description'], 0, 300) . '...';
    }
    $info['images'] = array();
    $info['published-time'] = awpcp_datetime('Y-m-d', $ad->ad_postdate);
    $info['modified-time'] = awpcp_datetime('Y-m-d', $ad->ad_last_updated);
    $images = awpcp_media_api()->find_by_ad_id($ad->ad_id, array('enabled' => true));
    foreach ($images as $image) {
        $info['images'][] = $image->get_url('large');
    }
    return $info;
}
Example #16
0
 protected function render_item_image($item, $instance)
 {
     global $awpcp_imagesurl;
     $show_images = $instance['show-images'] && awpcp_are_images_allowed();
     $image = awpcp_media_api()->get_ad_primary_image($item);
     if (!is_null($image) && $show_images) {
         $image_url = $image->get_url();
     } else {
         if ($instance['show-blank'] && $show_images) {
             $image_url = "{$awpcp_imagesurl}/adhasnoimage.png";
         } else {
             $image_url = '';
         }
     }
     if (empty($image_url)) {
         $html_image = '';
     } else {
         $html_image = sprintf('<a class="awpcp-listings-widget-item-listing-link self" href="%1$s"><img src="%2$s" alt="%3$s" /></a>', url_showad($item->ad_id), $image_url, esc_attr($item->ad_title));
     }
     return apply_filters('awpcp-listings-widget-listing-thumbnail', $html_image, $item);
 }