Ejemplo n.º 1
0
    function imageupload()
    {
        require JPATH_SITE . DS . "administrator" . DS . "components" . DS . "com_socialads" . DS . "config" . DS . "config.php";
        $data = JRequest::get('post');
        //create object of media helper class
        $media = new sa_mediaHelper();
        //get uploaded media details
        $file_field = strip_tags($_REQUEST['filename']);
        $file_name = $_FILES[$file_field]['name'];
        //orginal file name
        $file_name = strtolower($_FILES[$file_field]['name']);
        //convert name to lowercase
        $file_name = preg_replace('/\\s/', '_', $file_name);
        //replace "spaces" with "_" in filename
        $file_type = $_FILES[$file_field]['type'];
        $file_tmp_name = $_FILES[$file_field]['tmp_name'];
        $file_size = $_FILES[$file_field]['size'];
        $file_error = $_FILES[$file_field]['error'];
        //set error flag, if any error occurs set this to 1
        $error_flag = 0;
        //check for max media size allowed for upload
        $max_size_exceed = $media->check_max_size($file_size);
        if ($max_size_exceed) {
            $errorList[] = JText::_('FILE_BIG') . " " . $socialads_config['image_size'] . "KB<br>";
            $error_flag = 1;
        }
        if (!$error_flag) {
            //detect file type
            //& detect media group type image/video/flash
            $media_type_group = $media->check_media_type_group($file_type);
            if (!$media_type_group['allowed']) {
                $errorList[] = JText::_('FILE_ALLOW');
                $error_flag = 1;
            }
            if (!$error_flag) {
                $media_extension = $media->get_media_extension($file_name);
                //determine if resizing is needed for images
                //get max height and width for selected zone
                $adzone = '';
                if ($data['ad_zone_id'] != '') {
                    $adzone = $data['ad_zone_id'];
                } else {
                    $adzone = $data['adzone'];
                }
                $adzone_media_dimnesions = $media->get_adzone_media_dimensions($adzone);
                //@TODO get video frame height n width
                $max_zone_width = $adzone_media_dimnesions->img_width;
                $max_zone_height = $adzone_media_dimnesions->img_height;
                //if($media_type_group['media_type_group']!="video" )// skip resizing for video
                if ($media_type_group['media_type_group'] == "image") {
                    //get uploaded image dimensions
                    $media_size_info = $media->check_media_resizing_needed($adzone_media_dimnesions, $file_tmp_name);
                    $resizing = 0;
                    if ($media_size_info['resize']) {
                        $resizing = 1;
                    }
                    switch ($resizing) {
                        case 0:
                            $new_media_width = $media_size_info['width_img'];
                            $new_media_height = $media_size_info['height_img'];
                            $top_offset = 0;
                            //@TODO not sure abt this
                            $blank_height = $new_media_height;
                            //@TODO not sure abt this
                            break;
                        case 1:
                            $new_dimensions = $media->get_new_dimensions($max_zone_width, $max_zone_height, 'auto');
                            $new_media_width = $new_dimensions['new_calculated_width'];
                            $new_media_height = $new_dimensions['new_calculated_height'];
                            $top_offset = $new_dimensions['top_offset'];
                            $blank_height = $new_dimensions['blank_height'];
                            break;
                    }
                } else {
                    $new_media_width = $adzone_media_dimnesions->img_width;
                    $new_media_height = $adzone_media_dimnesions->img_height;
                    $top_offset = 0;
                    //@TODO not sure abt this
                    $blank_height = $new_media_height;
                }
                $fullPath = JUri::root() . 'images/socialads/';
                $relPath = 'images/socialads/';
                $colorR = 255;
                $colorG = 255;
                $colorB = 255;
                $file_name_without_extension = $media->get_media_file_name_without_extension($file_name);
                $upload_image = $media->uploadImage($file_field, $max_zone_width, $max_zone_height, $fullPath, $relPath, $colorR, $colorG, $colorB, $new_media_width, $new_media_height, $blank_height, $top_offset, $media_extension, $file_name_without_extension);
            }
        }
        if ($error_flag) {
            echo '<img src="' . JUri::root() . 'components/com_socialads/images/error.gif" width="16" height="16px" border="0" style="margin-bottom: -3px;" /> Error(s) Found: ';
            foreach ($errorList as $value) {
                echo $value . ', ';
            }
            jexit();
        }
        if (isset($data['upimgcopy'])) {
            $img = str_replace(JUri::base(), '', $data['upimgcopy']);
            jimport('joomla.filesystem.file');
            /*if(JFile::exists(JPATH_ROOT.DS.$img))
            		JFile::delete(JPATH_ROOT.DS.$img);*/
        }
        if (is_array($upload_image)) {
            foreach ($upload_image as $key => $value) {
                if ($value == "-ERROR-") {
                    unset($upload_image[$key]);
                }
            }
            $document = array_values($upload_image);
            for ($x = 0; $x < sizeof($document); $x++) {
                $errorList[] = $document[$x];
            }
            $imgUploaded = false;
        } else {
            $imgUploaded = true;
        }
        if ($imgUploaded) {
            switch ($media->media_type_group) {
                case "flash":
                    //FLOWPLAYER METHOD
                    echo '<div><input type="hidden" name="upimg" value="' . $upload_image . '"></div>';
                    echo '<script src="' . JUri::root() . 'components/com_socialads/js/flowplayer-3.2.9.min.js" type="text/javascript"></script>';
                    echo '<div class="vid_ad_preview"
					href="' . $upload_image . '"
					style="background:url(' . JUri::root() . '/components/com_socialads/images/black.png);width:' . $new_media_width . 'px;height:' . $new_media_height . 'px;
					">
					</div>';
                    //configure flowplayer	//disable all controls //hide play button
                    echo '
					<script type="text/javascript">
						flowplayer("div.vid_ad_preview",
						{
							src:"' . JUri::root() . 'components' . DS . 'com_socialads' . DS . 'js' . DS . 'flowplayer-3.2.10.swf",
							wmode:"opaque"
						},
						{
							canvas: {
								backgroundColor:"#000000",
								width:' . $new_media_width . ',
								height:' . $new_media_height . '
							},

							//default settings for the play button
							play: {
								opacity: 0.0,
							 	label: null,
							 	replayLabel: null,
							 	fadeSpeed: 500,
							 	rotateSpeed: 50
							},

							plugins:{
								controls: null
							}
						});
					</script>';
                    jexit();
                    break;
                case "video":
                    //FLOWPLAYER METHOD
                    echo '<div><input type="hidden" name="upimg" value="' . $upload_image . '"></div>';
                    echo '<script src="' . JUri::root() . 'components/com_socialads/js/flowplayer-3.2.9.min.js" type="text/javascript"></script>';
                    echo '<div class="vid_ad_preview"
					href="' . $upload_image . '"
					style="background:url(' . JUri::root() . '/components/com_socialads/images/black.png);width:' . $new_media_width . 'px;height:' . $new_media_height . 'px;
					">
					</div>';
                    //configure flowplayer	//disable all controls //hide play button
                    echo '
					<script type="text/javascript">
						flowplayer("div.vid_ad_preview",
						{
							src:"' . JUri::root() . 'components' . DS . 'com_socialads' . DS . 'js' . DS . 'flowplayer-3.2.10.swf",
							wmode:"opaque"
						},
						{
							canvas: {
								backgroundColor:"#000000",
								width:' . $new_media_width . ',
								height:' . $new_media_height . '
							},

							//default settings for the play button
							play: {
								opacity: 0.0,
							 	label: null,
							 	replayLabel: null,
							 	fadeSpeed: 500,
							 	rotateSpeed: 50
							},

							plugins:{

								controls: {
									url:"' . JUri::root() . 'components' . DS . 'com_socialads' . DS . 'js' . DS . 'flowplayer.controls-3.2.10.swf",
									height:25,
									timeColor: "#980118",
									all: false,
									play: true,
									scrubber: true,
									volume: true,
									time: false,
									mute: true,
									progressColor: "#FF0000",
									bufferColor: "#669900",
									volumeColor: "#FF0000"
								}

							}
						});
					</script>';
                    jexit();
                    break;
            }
            if ($max_zone_width == $media_size_info['width_img'] && $max_zone_height == $media_size_info['height_img']) {
                echo '<img src="' . $upload_image . '" border="0" />';
            } else {
                if ($max_zone_width != $media_size_info['width_img'] || $max_zone_height != $media_size_info['height_img']) {
                    //  $msg  = JText::sprintf('UPLOAD_NEWMSG', $media_size_info['width_img'],$media_size_info['height_img'],$max_zone_width,$max_zone_height);
                    $msg = JText::_('IMAGE_RESIZE_1') . $max_zone_width . " x " . $max_zone_height . JText::_('IMAGE_RESIZE_2') . $media_size_info['width_img'] . " x " . $media_size_info['height_img'] . JText::_('IMAGE_RESIZE_3');
                    echo '<img src="' . $upload_image . '" border="0" />';
                    echo '<script>alert("' . $msg . '")</script>';
                }
            }
            echo '<div><input type="hidden" name="upimg" value="' . $upload_image . '"></div>';
            jexit();
        } else {
            echo '<img src="' . JUri::root() . 'components/com_socialads/images/error.gif" width="16" height="16px" border="0" style="margin-bottom: -3px;" /> Error(s) Found: ';
            foreach ($errorList as $value) {
                echo $value . ', ';
            }
            jexit();
        }
    }
Ejemplo n.º 2
0
    function getAdHTMLByMedia($upload_area, $ad_image, $ad_body, $ad_link, $ad_layout, $track = 0, $adzone, $ad_id = '')
    {
        $adHtmlTyped = '';
        if ($ad_layout == 'layout2' || $ad_layout == 'layout4' || $ad_layout == 'layout6') {
            $ad_type = 'text';
            $adHtmlTyped .= $ad_body;
        } else {
            require_once JPATH_SITE . DS . 'components' . DS . 'com_socialads' . DS . 'helpers' . DS . 'media.php';
            require JPATH_SITE . DS . "administrator" . DS . "components" . DS . "com_socialads" . DS . "config" . DS . "config.php";
            $media = new sa_mediaHelper();
            $fpath = JUri::root() . $ad_image;
            $fextension = JFile::getExt($fpath);
            $ad_type = $media->get_ad_type($fextension);
            $socialadshelper = new socialadshelper();
            /*
            //@TODO use image/zone dimensions here?
            $media_d=$media->check_media_resizing_needed($zone_d,$fpath);
            $opti_d=$media->get_new_dimensions($zone_d->img_width, $zone_d->img_height, 'auto');
            */
            switch ($ad_type) {
                case "image":
                    //@TODO use resized image dimensions here
                    $adHtmlTyped = '<img class="' . $ad_layout . '_ad_prev_img" alt="" src="' . JUri::root() . $ad_image . '" style="border:0px;" />';
                    break;
                case "flash":
                    if ($track) {
                        $zone_d = $media->get_adzone_media_dimensions($adzone);
                        //include flowplayer javascript
                        $socialadshelper->loadScriptOnce(JUri::root() . 'components' . DS . 'com_socialads' . DS . 'js' . DS . 'flowplayer-3.2.9.min.js');
                        $adHtmlTyped = '';
                        //@TODO use image?zone dimensions here?
                        //$ht_wd='width:'.$media_d['width_img'].'px;height:'.$media_d['height_img'].'px';
                        //$ht_wd='width:'.$opti_d['new_calculated_width'].'px;height:'.$opti_d['new_calculated_height'].'px';
                        $ht_wd = 'width:' . $zone_d->img_width . 'px;height:' . $zone_d->img_height . 'px';
                        //create uniquq tag for each ad for video ads
                        $adHtmlTyped .= '<div
							href="' . JUri::root() . $ad_image . '"
							style="display:block;' . $ht_wd . '"
							id="vid_player_' . $ad_id . '">
							</div>';
                        //flow player js, configured as required
                        $adHtmlTyped .= '
						<script>
							flowplayer("vid_player_' . $ad_id . '",
							{
								src:"' . JUri::root() . 'components' . DS . 'com_socialads' . DS . 'js' . DS . 'flowplayer-3.2.10.swf",
								wmode:"opaque"
							},
							{
								/*
								canvas: {
									backgroundColor:"#000000",
									width:' . $zone_d->img_width . ',
									height:' . $zone_d->img_height . '
								},
								*/

								clip : {
									scaling: "scale",
									autoPlay: true
								},

								//default settings for the play button
								play: {
									opacity: 0.0,
									label: null,
									replayLabel: null,
									fadeSpeed: 500,
									rotateSpeed: 50
								},

								plugins:{
									controls: null,

									content: {
										url:"' . JUri::root() . 'components' . DS . 'com_socialads' . DS . 'js' . DS . 'flowplayer.content-3.2.8.swf",
										width:' . $zone_d->img_width . ',
										height:' . $zone_d->img_height . ',
										backgroundColor: "#112233",
										opacity: 0.0,
										onClick: function() {
										window.open("' . $ad_link . '","_blank");/*opens in new tab*/
										}
									}
								}
							});
						</script>';
                    } else {
                        //FLOWPLAYER
                        $zone_d = $media->get_adzone_media_dimensions($adzone);
                        $adHtmlTyped = '';
                        $adHtmlTyped .= '
						<div class="vid_ad_preview"
						href="' . JUri::root() . $ad_image . '"
						style="background:url(' . JUri::root() . '/components/com_socialads/images/black.png);width:' . $zone_d->img_width . 'px;height:' . $zone_d->img_height . 'px;
						">
						</div>
						';
                        //this is needed for ad preview from backend
                        $adHtmlTyped .= '<script type="text/javascript">
						flowplayer("div.vid_ad_preview",
						{
							src:"' . JUri::root() . 'components' . DS . 'com_socialads' . DS . 'js' . DS . 'flowplayer-3.2.10.swf",
							wmode:"opaque"
						},
						{
							canvas: {
								backgroundColor:"#000000",
								width:' . $zone_d->img_width . ',
								height:' . $zone_d->img_height . '
							},

							//default settings for the play button
							play: {
								opacity: 0.0,
							 	label: null,
							 	replayLabel: null,
							 	fadeSpeed: 500,
							 	rotateSpeed: 50
							},

							plugins:{
								controls: null
							}
						});
						</script>';
                    }
                    break;
                case "video":
                    if ($track) {
                        $zone_d = $media->get_adzone_media_dimensions($adzone);
                        //include flowplayer javascript
                        $socialadshelper->loadScriptOnce(JUri::root() . 'components' . DS . 'com_socialads' . DS . 'js' . DS . 'flowplayer-3.2.9.min.js');
                        $adHtmlTyped = '';
                        /*
                        //@TODO use image?zone dimensions here?
                        $ht_wd='width:'.$media_d['width_img'].'px;height:'.$media_d['height_img'].'px';
                        $ht_wd='width:'.$opti_d['new_calculated_width'].'px;height:'.$opti_d['new_calculated_height'].'px';
                        */
                        $ht_wd = 'width:' . $zone_d->img_width . 'px;height:' . $zone_d->img_height . 'px';
                        //calculate top margin for play button icon
                        $top_margin = $zone_d->img_height / 2 - 48;
                        //calculate overlay div height
                        $div_height = $zone_d->img_height - 25;
                        //create uniquq tag for each ad for video ads
                        $adHtmlTyped .= '<div
							href="' . JUri::root() . $ad_image . '"
							style="display:block;' . $ht_wd . '"
							id="vid_player_' . $ad_id . '">
							</div>';
                        //flow player js, configured as required
                        $adHtmlTyped .= '
						<script>
							flowplayer("vid_player_' . $ad_id . '",
							{
								src:"' . JUri::root() . 'components' . DS . 'com_socialads' . DS . 'js' . DS . 'flowplayer-3.2.10.swf",
								wmode:"opaque"
							},
							{
								canvas: {
									backgroundColor:"#000000",
									width:' . $zone_d->img_width . ',
									height:' . $zone_d->img_height . '
								},

								//default settings for the play button
								play: {
									opacity: 0.0,
								 	label: null,
								 	replayLabel: null,
								 	fadeSpeed: 500,
								 	rotateSpeed: 50
								},
							';
                        if ($socialads_config["allow_vid_ads_autoplay"] == 0) {
                            //added by aniket for stop auto play
                            $adHtmlTyped .= '	clip: {
									// these two settings will make the first frame visible
									autoPlay: false,
									autoBuffering: true,
									duration: 0,
									// locate a good looking first frame with the start parameter
									start: 62,
									},
							';
                        }
                        $adHtmlTyped .= '	plugins:{
									controls: {
										url:"' . JUri::root() . 'components' . DS . 'com_socialads' . DS . 'js' . DS . 'flowplayer.controls-3.2.10.swf",
										height:25,
										timeColor: "#980118",
										all: false,
										play: true,
										scrubber: true,
										volume: true,
										time: false,
										mute: true,
										progressColor: "#FF0000",
										bufferColor: "#669900",
										volumeColor: "#FF0000"
									},

									content: {
										url:"' . JUri::root() . 'components' . DS . 'com_socialads' . DS . 'js' . DS . 'flowplayer.content-3.2.8.swf",
										width:' . $zone_d->img_width . ',
										height:' . $div_height . ',
										backgroundColor: "#112233",
										opacity: 0.0,
										onClick: function() {
										window.open("' . $ad_link . '","_blank");/*opens in new tab*/
										}
									}
								}
							});
						</script>';
                    } else {
                        //FLOWPLAYER
                        $zone_d = $media->get_adzone_media_dimensions($adzone);
                        $adHtmlTyped = '';
                        $adHtmlTyped .= '
						<div class="vid_ad_preview"
						href="' . JUri::root() . $ad_image . '"
						style="background:url(' . JUri::root() . '/components/com_socialads/images/black.png);width:' . $zone_d->img_width . 'px;height:' . $zone_d->img_height . 'px;
						">
						</div>
						';
                        //this is needed for ad preview from backend
                        $adHtmlTyped .= '<script type="text/javascript">
						flowplayer("div.vid_ad_preview",
						{
							src:"' . JUri::root() . 'components' . DS . 'com_socialads' . DS . 'js' . DS . 'flowplayer-3.2.10.swf",
							wmode:"opaque"
						},
						{
							canvas: {
								backgroundColor:"#000000",
								width:' . $zone_d->img_width . ',
								height:' . $zone_d->img_height . '
							},

							//default settings for the play button
							play: {
							opacity: 0.0,
								label: null,
								replayLabel: null,
								fadeSpeed: 500,
								rotateSpeed: 50
							},

							plugins:{
								controls: {
										url:"' . JUri::root() . 'components' . DS . 'com_socialads' . DS . 'js' . DS . 'flowplayer.controls-3.2.10.swf",
										height:25,
										timeColor: "#980118",
										all: false,
										play: true,
										scrubber: true,
										volume: true,
										time: false,
										mute: true,
										progressColor: "#FF0000",
										bufferColor: "#669900",
										volumeColor: "#FF0000"
									}
							}
						});
						</script>';
                    }
                    break;
            }
            //end switch case
        }
        //end else (media ads)
        $adHtmlTypedwithad_type = "<div class='adtype' adtype='" . $ad_type . "'>" . $adHtmlTyped . "</div>";
        return $adHtmlTypedwithad_type;
    }