HomeHelpTrac

source: tags/6.1/uploadPhoto.php @ 10374

Revision 10374, 13.6 KB checked in by Andrey Prikaznov, 3 years ago (diff)
Line 
1<?php
2
3/***************************************************************************
4*                            Dolphin Smart Community Builder
5*                              -----------------
6*     begin                : Mon Mar 23 2006
7*     copyright            : (C) 2006 BoonEx Group
8*     website              : http://www.boonex.com/
9* This file is part of Dolphin - Smart Community Builder
10*
11* Dolphin is free software. This work is licensed under a Creative Commons Attribution 3.0 License.
12* http://creativecommons.org/licenses/by/3.0/
13*
14* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16* See the Creative Commons Attribution 3.0 License for more details.
17* You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin,
18* see license.txt file; if not, write to marketing@boonex.com
19***************************************************************************/
20
21require_once( BX_DIRECTORY_PATH_CLASSES . 'BxDolMedia.php');
22
23
24class UploadPhoto extends BxDolMedia
25{
26    function UploadPhoto( $iProfileID )
27    {
28        $this -> sMediaType = 'photo';
29        $this -> iProfileID = $iProfileID;
30        parent::BxDolMedia();
31       
32        $aMember = getProfileInfo( $this -> iProfileID );
33        $sSex = $aMember['Sex'];
34       
35        //$sSex = db_value( "SELECT `Sex` FROM `Profiles` WHERE `ID` = '{$this -> iProfileID}'" );
36       
37        if( $sSex == 'male' or $sSex == 'Male' )
38        {
39            $this -> sSexIcon = 'man_small.gif';
40            $this -> sSexPic = 'man_big.gif';
41        }
42        elseif( $sSex == 'female' or $sSex == 'Female' )
43        {
44            $this -> sSexIcon = 'woman_small.gif';
45            $this -> sSexPic = 'woman_big.gif';
46        }
47        else
48        {
49            $this -> sSexIcon = 'visitor_small.gif';
50            $this -> sSexPic = 'visitor_big.gif';
51        }
52    }
53
54
55    function getMediaPage( $iMediaID = '' )
56    {
57
58
59        //print_r( $this -> aMedia);
60
61        $ret = '';
62        //$ret .= print_r($_POST, true);
63
64        $bShowMenu = false;
65        $bWithoutJS = false;
66
67
68        if( 0 < $this -> iMediaCount )
69        {
70            $iMediaID = ( 0 < $iMediaID ) ? $iMediaID : $this -> aMedia['0']['PrimPhoto'];
71
72            $aCurPhoto = $this -> getElementArrayByID($iMediaID);
73            if( empty( $aCurPhoto ) )
74            {
75                $sPhotoUrl = getTemplateIcon( $this -> sSexPic );
76                $bShowMenu = false;
77                $bWithoutJS = true;
78            }
79            else
80            {
81                $ret .= '<div class="mediaTitle" id="sTitleDiv">';
82                    $ret .= htmlspecialchars_adv( $aCurPhoto['med_title'] );
83                $ret .= '</div>';
84                $sPhotoUrl = $this -> sMediaUrl . 'photo_' . $aCurPhoto['med_file'];
85                $iPhotoRating = $this -> getRating( $aCurPhoto['med_rating_sum'], $aCurPhoto['med_rating_count'] );
86                $bShowMenu = true;
87            }
88
89        }
90        else
91        {
92            $sPhotoUrl = getTemplateIcon( $this -> sSexPic );
93            $bShowMenu = false;
94        }
95
96        $ret .= $this -> getJSCode( $aCurPhoto );
97
98        $ret .= '<div class="ratingParentBlock">';
99            $ret .= '<div class="ratingBlock" style="height:' . $this -> aMediaConfig['size']['photoHeight'] . 'px; width:10px;">';
100                $ret .= '<div class="ratingInner" id="sPhotoRatingDiv" style="height:' . $iPhotoRating . '%;">';
101                    $ret .= '<div class="ratingTextBlock">';
102                        $ret .= '<div id="sRatingTextDiv" style="height:0%;">';
103                            $iPhotoRatingSum = ( 0 < $aCurPhoto['med_rating_sum'] ) ? $aCurPhoto['med_rating_sum'] : 0 ;
104                            $iPhotoRatingCount = ( 0 < $aCurPhoto['med_rating_count'] ) ? $aCurPhoto['med_rating_count'] : 0;
105                            $ret .= _t('_votes') . '&nbsp;' . $iPhotoRatingCount . '<br>';
106                            $ret .= _t('_ratio') . '&nbsp;' . $iPhotoRatingSum;
107                        $ret .= '</div>' . "\n";
108                    $ret .= '</div>' . "\n";
109                $ret .= '</div>' . "\n";
110            $ret .= '</div>' . "\n";
111        $ret .= '</div>' . "\n";
112
113        $ret .= '<div class="photoBlock" id="photoKeeper">';
114            $ret .= '<img src="' . getTemplateIcon('spacer.gif') . '" style="width:' . $this -> aMediaConfig['size']['photoWidth'] . 'px; height:' . $this -> aMediaConfig['size']['photoHeight'] . 'px; background-image:url(' . $sPhotoUrl . ');" class="photo" id="temPhotoID" alt="" />';
115        $ret .= '</div>';
116
117        if( $bShowMenu )
118        {
119            $ret .= '<div class="photoMenu">';
120                $ret .= '<form action="' . $_SERVER['PHP_SELF'] . '" method="post" name="actionForm">';
121
122                    $ret .= '<input type="submit" name="deletePhoto" value="' . _t( '_Delete' ) . '" onclick="return confirm(\'' . _t('_are you sure?') . '\');" />';
123                    $ret .= '<input type="submit" name="makePrim" value="' . _t('_Make Primary') . '" />';
124                    $aMember = getProfileInfo( $this -> iProfileID );
125                    $ret .= ($aMember['Couple']>0) ? '<input type="submit" name="makePrimCouple" value="' . _t('_Make Primary') . ' to Couple" />' : '';
126                    $ret .= '<input type="hidden" id="photoID" name="photoID" value="' . $aCurPhoto['med_id'] . '" />';
127
128                    $sRatable = ($aCurPhoto['rate_able']=='1') ? _t('_disable able to rate') : _t('_enable able to rate');
129                    $ret .= '<input type="submit" id="makeRable" name="makeRable" value="' . $sRatable . '" />';
130
131                $ret .= '</form>';
132            $ret .= '</div>';
133        }
134        $ret .= '<div class="clear_both"></div>';
135        $ret .= '<div class="iconBlock">';
136            if( $bWithoutJS )
137            {
138                $ret .= $this -> getIconsList();
139            }
140            else
141            {
142                $ret .= $this -> _getIconsList();
143            }
144        $ret .= '</div>';
145
146        return $ret;
147    }
148
149    function getJSCode( $aCurPhoto )
150    {
151        $ret = '';
152
153        $ret .= '<script type="text/javascript">
154            function setImage()
155            {
156                var imgCode;
157                var oOldImg = document.getElementById("temPhotoID");
158                oOldImg.style.backgroundImage = "url(' . $this -> sMediaUrl . 'photo_' . $aCurPhoto['med_file'] . ')";
159                return false;
160            }
161
162            function changePhoto( sFile, iMediaID, sTitle, iRate, rateSum, rateCount, bRable )
163            {
164                var oOldImg = document.getElementById("temPhotoID");
165                oOldImg.style.backgroundImage = "url(' . $this -> sMediaUrl . 'photo_"+sFile+")";
166                changeTitle( sTitle );
167                changeRate( iRate, rateSum, rateCount );
168                changeMediaID( iMediaID );
169                changeRable( bRable );
170                return false;
171            }
172
173            function changeTitle( sTitle )
174            {
175                var oTitleDiv = document.getElementById("sTitleDiv");
176                oTitleDiv.innerHTML = stripSlashes(sTitle);
177            }
178
179            function changeRate( iRate, rateSum, rateCount )
180            {
181                var oRateDiv = document.getElementById("sPhotoRatingDiv");
182                var oRateTextDiv = document.getElementById("sRatingTextDiv");
183
184                oRateDiv.style.position = "relative";
185                oRateDiv.style.height = iRate + "%";
186                oRateDiv.style.top =  100 - iRate + "%";
187
188                oRateTextDiv.innerHTML = "' . _t('_votes') . ' "+rateCount+"<br>' . _t('_ratio') . ' "+rateSum;
189            }
190
191            function changeMediaID( iMediaID )
192            {
193                var oPhotoID = document.getElementById("photoID");
194                oPhotoID.value = iMediaID;
195            }
196
197            function changeRable( iChecked )
198            {
199                var oRable = document.getElementById("makeRable");
200                var sRableCapt = (iChecked == 1) ? "'._t('_disable able to rate').'" : "'._t('_enable able to rate').'";
201                oRable.value = sRableCapt;
202            }
203
204        </script>';
205
206        return $ret;
207    }
208
209
210    function _getIconsList()
211    {
212        for( $i = 0; $i < $this -> aMediaConfig['max']['photo']; $i++ )
213        {
214            $sIconSrc = $this -> sMediaDir . 'icon_' . $this -> aMedia[$i]['med_file'];
215            if( extFileExists( $sIconSrc ) )
216            {
217                $iPhotoRatingSum = ( 0 < $this -> aMedia[$i]['med_rating_sum'] ) ? $this -> aMedia[$i]['med_rating_sum'] : 0 ;
218                $iPhotoRatingCount = ( 0 < $this -> aMedia[$i]['med_rating_count'] ) ? $this -> aMedia[$i]['med_rating_count'] : 0 ;
219                $iPhotoRating = $this -> getRating( $iPhotoRatingSum, $iPhotoRatingCount );
220                $sIconUrl = $this -> sMediaUrl . 'icon_' . $this -> aMedia[$i]['med_file'];
221
222                //function changePhoto( sFile, imgDiv, sTitle, titleDiv, iRate, rateDiv)
223                $sRableVal = ($this -> aMedia[$i]['rate_able']=='1') ? '1' : '0';
224
225                $atrib =
226                    "'{$this -> aMedia[$i]['med_file']}', " .
227                    "'{$this -> aMedia[$i]['med_id']}', " .
228                    "'" . addslashes( htmlspecialchars( htmlspecialchars($this -> aMedia[$i]['med_title'] ) ) ) . "'," .
229                    "$iPhotoRating, " .
230                    "$iPhotoRatingSum, " .
231                    "$iPhotoRatingCount, " .
232                    "'$sRableVal'";
233               
234                $ret .= '
235                    <img src="' . getTemplateIcon('spacer.gif') . '"
236                      style="width:' . $this -> aMediaConfig['size']['iconWidth'] . 'px; height:' .
237                        $this -> aMediaConfig['size']['iconHeight'] . 'px; background-image:url(' . $sIconUrl . '); cursor:pointer;"
238                      alt="" class="icons" onmouseover="this.className=\'iconsHover\'" onmouseout="this.className=\'icons\'"
239                      onclick="return changePhoto(' . $atrib . ');" />';
240            }
241            else
242            {
243                $sIconUrl = getTemplateIcon( $this -> sSexIcon );
244                $ret .= '<img src="' . getTemplateIcon('spacer.gif') . '" style="width:' . $this -> aMediaConfig['size']['iconWidth'] . 'px; height:' . $this -> aMediaConfig['size']['iconHeight'] . 'px; background-image:url(' . $sIconUrl . ');" alt="" class="icons" />';
245            }
246        }
247        return $ret;
248    }
249
250    function getIconsList()
251    {
252        $ret = '';
253
254        for( $i = 0; $i < $this -> aMediaConfig['max']['photo']; $i++ )
255        {
256            $sIconSrc = $this -> sMediaDir . 'icon_' . $this -> aMedia[$i]['med_file'];
257            if( extFileExists( $sIconSrc ) )
258            {
259                $sIconUrl = $this -> sMediaUrl . 'icon_' . $this -> aMedia[$i]['med_file'];
260                $ret .= '<a href="' . $this -> aMediaConfig['url']['media'] . '?photoID=' . $this -> aMedia[$i]['med_id'] . '">';
261                    $ret .= '<img src="' . getTemplateIcon('spacer.gif') . '" style="width:' . $this -> aMediaConfig['size']['iconWidth'] . 'px; height:' . $this -> aMediaConfig['size']['iconHeight'] . 'px; background-image:url(' . $sIconUrl . '); cursor:pointer;"  alt="" class="icons" onmouseover="this.className=\'iconsHover\'" onmouseout="this.className=\'icons\'" />';
262                $ret .= '</a>';
263            }
264            else
265            {
266                $sIconUrl = getTemplateIcon( $this -> sSexIcon );
267                $ret .= '<img src="' . getTemplateIcon('spacer.gif') . '" style="width:' . $this -> aMediaConfig['size']['iconWidth'] . 'px; height:' . $this -> aMediaConfig['size']['iconHeight'] . 'px; background-image:url(' . $sIconUrl . ');" alt="" class="icons" />';
268            }
269        }
270        return $ret;
271    }
272
273    function validateMediaArray( $aMedia )
274    {
275        foreach( $aMedia as $iKey => $aValue )
276        {
277            $sIconSrc = $this -> sMediaDir . 'icon_' . $aValue['med_file'];
278            $sThumbSrc = $this -> sMediaDir . 'thumb_' . $aValue['med_file'];
279            $sPhotoSrc = $this -> sMediaDir . 'photo_' . $aValue['med_file'];
280
281            if( !extFileExists( $sIconSrc ) || !extFileExists( $sThumbSrc ) || !extFileExists( $sPhotoSrc ) )
282            {
283                if( $aValue['med_id'] == $aValue['PrimPhoto'] )
284                {
285                    $this -> oMediaQuery -> resetPrimPhoto( $this -> iProfileID );
286                }
287                unset( $aMedia[$iKey]);
288            }
289
290        }
291
292        return array_values( $aMedia );
293    }
294
295    function uploadMedia()
296    {
297        global $dir;
298        $sMediaDir = $this -> getProfileMediaDir();
299
300        if( !$sMediaDir )
301        {
302            return false;
303        }
304        $sFileName = time();
305
306        $ext = moveUploadedImage( $_FILES, 'photo', $sMediaDir . $sFileName, $this -> aMediaConfig['max']['photoFile'], false );
307       
308        if( ( 0 == $_FILES[$this -> sMediaType]['error'] ) )
309        {
310            if ( getParam( 'enable_watermark' ) == 'on' )
311            {
312                $iTransparent = getParam( 'transparent1' );
313                $sWaterMark = $dir['profileImage'] . getParam( 'Water_Mark' );
314                                       
315                if (  strlen(getParam( 'Water_Mark' )) && file_exists($sWaterMark) )
316                {
317                    $sFile = $sMediaDir . $sFileName . $ext;           
318                    applyWatermark( $sFile, $sFile, $sWaterMark, $iTransparent );
319                }
320            }
321           
322            if( strlen( $ext ) && !(int)$ext )
323            {
324                imageResize( $sMediaDir . $sFileName . $ext, $sMediaDir . 'icon_' . $sFileName . $ext, $this -> aMediaConfig['size']['iconWidth'], $this -> aMediaConfig['size']['iconHeight'], true );
325                imageResize( $sMediaDir . $sFileName . $ext, $sMediaDir . 'thumb_' . $sFileName . $ext, $this -> aMediaConfig['size']['thumbWidth'], $this -> aMediaConfig['size']['thumbHeight'], true );
326                imageResize( $sMediaDir . $sFileName . $ext, $sMediaDir . 'photo_' . $sFileName . $ext, $this -> aMediaConfig['size']['photoWidth'], $this -> aMediaConfig['size']['photoHeight'], true );
327               
328                chmod( $sMediaDir . 'icon_'  . $sFileName . $ext, 0644 );
329                chmod( $sMediaDir . 'thumb_' . $sFileName . $ext, 0644 );
330                chmod( $sMediaDir . 'photo_' . $sFileName . $ext, 0644 );
331               
332                $this -> insertMediaToDb( $sFileName . $ext );
333                if( 0 == $this -> iMediaCount || $this -> aMedia['0']['PrimPhoto'] == 0  )
334                {
335                    $iLastID = mysql_insert_id($GLOBALS['MySQL']->link);
336                    $this -> oMediaQuery -> setPrimaryPhoto( $this -> iProfileID, $iLastID );
337                }
338   
339   
340                @unlink( $sMediaDir . $sFileName . $ext );
341            }
342        }
343    }
344
345    function deleteMedia( $iPhotoID )
346    {
347        $aPhotos = $this -> getElementArrayByID( $iPhotoID );
348        $sIconSrc = $this -> sMediaDir . 'icon_' . $aPhotos['med_file'];
349        $sThumbSrc = $this -> sMediaDir . 'thumb_' . $aPhotos['med_file'];
350        $sPhotoSrc = $this -> sMediaDir . 'photo_' . $aPhotos['med_file'];
351
352        $this -> oMediaQuery -> deleteMedia( $this -> iProfileID, $iPhotoID, $this -> sMediaType );
353        if( $aPhotos['med_id'] == $aPhotos['PrimPhoto'] )
354        {
355            $this -> oMediaQuery -> resetPrimPhoto( $this -> iProfileID );
356        }
357
358        @unlink( $sIconSrc );
359        @unlink( $sThumbSrc );
360        @unlink( $sPhotoSrc );
361    }
362
363    function makePrimPhoto( $iPhotoID, $bCouple = false )
364    {
365        if ($bCouple>0) {
366            $aMember = getProfileInfo( $this -> iProfileID );
367            $sDestID = $aMember['Couple'];
368        } else {
369            $sDestID = $this->iProfileID;
370        }
371        if ($sDestID>0)
372            $this -> oMediaQuery -> setPrimaryPhoto( $sDestID, $iPhotoID );
373        createUserDataFile( $sDestID );
374    }
375
376    function makeRablePhoto( $iPhotoID ) {
377        $this->oMediaQuery->setRablePhoto($iPhotoID);
378    }
379
380}
381
382?>
Note: See TracBrowser for help on using the repository browser.