function addMonial()
 {
     jimport('joomla.filesystem.file');
     jimport('joomla.utilities.utility');
     JRequest::checkToken() or jexit('Invalid Token');
     $app = JFactory::getApplication();
     $db =& JFactory::getDBO();
     $document =& JFactory::getDocument();
     require_once JPATH_COMPONENT . DS . 'assets' . DS . '3rdparty' . DS . 'SimpleImage.php';
     $myparams =& JComponentHelper::getParams('com_eztestimonial');
     $imageSubFolder = $myparams->getValue('data.params.imagefolder');
     $autoApprove = $myparams->getValue('data.params.autoapprove', 0);
     $uploadSize = $myparams->getValue('data.params.imagesize', 400);
     $spamfilter = $myparams->getValue('data.params.spamfilter');
     $sendemailtouser = $myparams->getValue('data.params.sendemailtouser', 0);
     $sendemailtoadmin = $myparams->getValue('data.params.sendemailtoadmin', 0);
     $summerytxtlength = $myparams->getValue('data.params.summerytxtlength', 100);
     $ImgUrl = JRoute::_(JURI::base() . 'images/' . $imageSubFolder . '/');
     $returnUrl = JRoute::_("index.php?option=com_eztestimonial&view=testimonials");
     $valid = true;
     $fullname = strip_tags(JRequest::getVar('iname'));
     $useremail = strip_tags(JRequest::getVar('iemail'));
     $location = strip_tags(JRequest::getVar('iaddress'));
     $website = strip_tags(JRequest::getVar('iwebsite'));
     $message = strip_tags(JRequest::getVar('imessage'));
     $aboutme = strip_tags(JRequest::getVar('iboutme'));
     $rating = JRequest::getVar('rating');
     $file = JRequest::getVar('iimage', null, 'files', 'array');
     $filename = JFile::makeSafe($file['name']);
     $src = $file['tmp_name'];
     $extension_of_image = testimonialController::get_extension(strtolower($filename));
     //get the extension of image
     $FileSize = filesize($file['tmp_name']);
     $AllowedSize = $uploadSize * 1048576;
     if ($spamfilter == 1) {
         $privatekey = $myparams->getValue('data.params.reprivatekey');
         require_once JPATH_COMPONENT . DS . 'assets' . DS . '3rdparty' . DS . 'recaptchalib.php';
         $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
         if (!$resp->is_valid) {
             $app->enqueueMessage(JText::_('COM_TESTIMONIALS_WRONGRECAPTCHA'), 'error');
             $valid = false;
         }
     } elseif ($spamfilter == 2) {
         $akismetKey = $myparams->getValue('data.params.akismetKey');
         require_once JPATH_COMPONENT . DS . 'assets' . DS . '3rdparty' . DS . 'Akismet.class.php';
         $MyURL = JURI::base();
         $akismet = new Akismet($MyURL, $akismetKey);
         $akismet->setCommentAuthor($fullname);
         $akismet->setCommentAuthorEmail($email);
         $akismet->setCommentAuthorURL($website);
         $akismet->setCommentContent($message);
         $akismet->setPermalink(JURI::current());
         if ($akismet->isCommentSpam()) {
             die("spam alert!");
             $valid = false;
         }
     }
     if ($FileSize > $AllowedSize) {
         $exceededtxt = JText::sprintf(JText::_('COM_TESTIMONIALS_IMAGESIZETOOBIG'), testimonialController::format_bytes($AllowedSize), testimonialController::format_bytes($FileSize));
         $app->enqueueMessage($exceededtxt, 'error');
         $valid = false;
     }
     if (strlen($FileSize) <= 1 && strlen($filename) > 1) {
         $app->enqueueMessage(JText::_('COM_TESTIMONIALS_ERRUPLOADING'), 'error');
         $valid = false;
     }
     if ($FileSize > 1 && $valid == true) {
         // Import image
         switch ($extension_of_image) {
             case 'jpg':
             case 'jpeg':
             case 'png':
             case 'gif':
                 break;
             default:
                 // Unsupported format
                 $app->enqueueMessage(JText::_('COM_TESTIMONIALS_FILENOTSUPPORTED'), 'error');
                 $valid = false;
                 break;
         }
     }
     if ($FileSize > 1 && $valid == true) {
         $random_str = testimonialController::random_str();
         $photo_name = strtolower(str_replace(" ", "-", htmlspecialchars($fullname))) . "-" . $random_str . ".";
         // cleaned photo name with random charactor
         $newPhotoname = $photo_name . $extension_of_image;
         $newPhotoPath = JPATH_BASE . DS . "images" . DS . $imageSubFolder . DS;
         $thumb_dest = $newPhotoPath . 'thumb_' . $newPhotoname;
         $thumb_dest50 = $newPhotoPath . 'thumb50_' . $newPhotoname;
         $dest = $newPhotoPath . $newPhotoname;
         $image = new SimpleImage();
         $image->square_crop($file['tmp_name'], $thumb_dest, $thumb_size = 200, $jpg_quality = 90);
         $image->square_crop($file['tmp_name'], $thumb_dest50, $thumb_size = 50, $jpg_quality = 90);
         $image->load($file['tmp_name']);
         //$image->resizeToWidth(600);
         $image->save($dest);
     } else {
         $newPhotoname = '';
     }
     if (strlen($fullname) < 2) {
         $app->enqueueMessage(JText::_('COM_TESTIMONIALS_EMPTYNAME'), 'error');
         $valid = false;
     }
     if (strlen($useremail) < 2) {
         $app->enqueueMessage(JText::_('COM_TESTIMONIALS_EMPTYEMAIL'), 'error');
         $valid = false;
     }
     if (strlen($location) < 2) {
         $app->enqueueMessage(JText::_('COM_TESTIMONIALS_EMPTYLOCATION'), 'error');
         $valid = false;
     }
     if (strlen($message) < 2) {
         $app->enqueueMessage(JText::_('COM_TESTIMONIALS_EMPTYMSSG'), 'error');
         $valid = false;
     }
     if ($valid) {
         $approved = $autoApprove == 1 ? 1 : 0;
         $postdata = array('fullName' => $fullname, 'email' => $useremail, 'location' => $location, 'aboutauthor' => $aboutme, 'website' => $website, 'message_summary' => testimonialController::truncate($message, $summerytxtlength), 'message_long' => $message, 'image_name' => $newPhotoname, 'added_date' => date("Y-m-d H:i:s"), 'rating' => $rating, 'approved' => $approved);
         $row =& $this->getTable();
         if (!$row->bind($postdata)) {
             $app->enqueueMessage($row->getError(), 'error');
         }
         if (!$row->store()) {
             $app->enqueueMessage($row->getError(), 'error');
         } else {
             //send email to user
             $sitename = $app->getCfg('sitename');
             if ($sendemailtouser == 1) {
                 $useremailfromnametxt = $myparams->getValue('data.params.useremailfromnametxt', 'From A Company');
                 $useremailaddress = $myparams->getValue('data.params.useremailfromtxt', '*****@*****.**');
                 $useremailsubject = $myparams->getValue('data.params.useremailsubjecttxt', 'Email Subject');
                 $useremailbody = $myparams->getValue('data.params.useremailtxt', 'Email Body');
                 $useremailbody = JText::sprintf($useremailbody, $fullname);
                 $prasearray = array('{b}' => '<b>', '{/b}' => '</b>', '{br}' => '<br />', '{sitename}' => $sitename, '{siteurl}' => JURI::base(), '{name}' => $fullname);
                 $useremailbody = testimonialController::mail_body_phraser($useremailbody, $prasearray);
                 $SendUserEmail = JUtility::sendMail($useremailaddress, $useremailfromnametxt, $useremail, $useremailsubject, $useremailbody, true);
                 if (!$SendUserEmail) {
                     $app->enqueueMessage(JText::_('COM_TESTIMONIALS_EMAILFAILDUSER'), 'error');
                 }
             }
             $adminemails = explode(",", $myparams->getValue('data.params.adminemails', '*****@*****.**'));
             $adminmailtxt = $myparams->getValue('data.params.adminmailtxt');
             $prasearray = array('{b}' => '<b>', '{/b}' => '</b>', '{br}' => '<br />', '{sitename}' => $sitename, '{siteurl}' => JURI::base());
             $adminmailtxt = testimonialController::mail_body_phraser($adminmailtxt, $prasearray);
             // send mail to all administrators
             foreach ($adminemails as $adminemail) {
                 $adminmailtxt = JText::sprintf($adminmailtxt, $row->iname);
                 $SendAdminEmail = JUtility::sendMail($mailfrom, $fromname, $adminemail, $adminmailsubjecttxt, $adminmailtxt, true);
                 $app->enqueueMessage($adminemailstosend, 'error');
                 if (!$SendAdminEmail) {
                     $app->enqueueMessage(JText::_('COM_TESTIMONIALS_EMAILFAILDADMIN'), 'error');
                 }
             }
             //display message accordingly
             if ($autoApprove == 0) {
                 $app->enqueueMessage(JText::_('COM_TESTIMONIALS_WAITINGAPPROVAL'), 'message');
                 $app->redirect($returnUrl);
             } else {
                 $app->enqueueMessage(JText::_('COM_TESTIMONIALS_PUBLISHEDMSG'), 'message');
                 $app->redirect($returnUrl);
             }
         }
     }
 }
/**
 * Move temp images from temp directory.
 *
 * @param mixed $image
 */
function moveTradeTmpImages($images)
{
    $imageList = explode('|', $images);
    $tmpStrPath = str_replace(DIR_FS_TRADE_IMG, '/', DIR_FS_TRADE_IMG_TMP);
    $userID = buckys_is_logged_in();
    if (count($imageList) > 0 && $userID) {
        $rootPath = rtrim(DIR_FS_ROOT, '/');
        if (!is_dir(DIR_FS_TRADE_IMG . $userID)) {
            $createSuccessFlag = mkdir(DIR_FS_TRADE_IMG . $userID, 0777);
            //Create Index.html to prevent directory listing issue
            $fp = fopen(DIR_FS_TRADE_IMG . $userID . "/index.html", "w");
            fclose($fp);
            if ($createSuccessFlag === false) {
                return $createSuccessFlag;
            }
        }
        foreach ($imageList as $imgFile) {
            if (strpos($imgFile, $tmpStrPath) !== false) {
                $newFilePath = str_replace($tmpStrPath, '/' . $userID . '/', $imgFile);
                @copy($rootPath . $imgFile, $rootPath . $newFilePath);
                @unlink($rootPath . $imgFile);
                $thumbPathInfo = pathinfo($rootPath . $newFilePath);
                $thumbFileName = $thumbPathInfo['dirname'] . "/" . $thumbPathInfo['filename'] . TRADE_ITEM_IMAGE_THUMB_SUFFIX . "." . $thumbPathInfo['extension'];
                unset($resizeImageIns);
                $resizeImageIns = new SimpleImage($rootPath . $newFilePath);
                $resizeImageIns->square_crop(150);
                $resizeImageIns->save($thumbFileName);
            }
        }
        $images = str_replace($tmpStrPath, '/' . $userID . '/', $images);
        return $images;
    } else {
        return '';
    }
}
Exemple #3
0
    $file = '';
}
if (empty($file) || !file_exists($root . $file)) {
    $file = '/noimage.jpg';
}
echo $file;
exit;
$fileRes = '/resize/' . $height . '/' . $width . '/' . $type . $file;
$file = $root . $file;
$fileRes = $root . $fileRes;
if (!file_exists($fileRes)) {
    require_once $root . '/SimpleImage.php';
    $simpleImage = new SimpleImage();
    $simpleImage->load($file);
    switch ($type) {
        case 'no':
            $simpleImage->square_crop($height, $width);
            break;
        case 'w':
            $simpleImage->fit_to_width($width);
            break;
        case 'h':
            $simpleImage->fit_to_height($height);
            break;
        case 's':
            $simpleImage->resize($height, $width);
            break;
    }
    createFolders($fileRes);
    $simpleImage->save($fileRes);
}