Example #1
0
 public function changeLogo($iId, $aImage, $bResize = false)
 {
     $aStyle = $this->database()->select('ts.style_id, ts.folder, t.folder AS theme_folder, ts.logo_image')->from($this->_sTable, 'ts')->join(Phpfox::getT('theme'), 't', 't.theme_id = ts.theme_id')->where('ts.style_id = ' . (int) $iId)->execute('getRow');
     if (!isset($aStyle['style_id'])) {
         return Phpfox_Error::set(Phpfox::getPhrase('theme.not_a_valid_style'));
     }
     $aInfo = getimagesize($aImage['tmp_name']);
     switch ($aInfo['mime']) {
         case 'image/png':
             $sExt = 'png';
             break;
         case 'image/gif':
             $sExt = 'gif';
             break;
         case 'image/jpg':
         case 'image/jpeg':
             $sExt = 'jpg';
             break;
         default:
             return Phpfox_Error::set(Phpfox::getPhrase('theme.not_a_valid_file_extension'));
             break;
     }
     $this->database()->delete(Phpfox::getT('theme_style_logo'), 'style_id = ' . $aStyle['style_id']);
     $iLogoId = $this->database()->insert(Phpfox::getT('theme_style_logo'), array('style_id' => $aStyle['style_id'], 'logo' => base64_encode(file_get_contents($aImage['tmp_name'])), 'file_ext' => $sExt));
     $this->cache()->remove(array('theme', 'theme_logo_' . $aStyle['theme_folder'] . '_' . $aStyle['folder']));
     $sLogoFile = PHPFOX_DIR_FILE . 'static' . PHPFOX_DS . md5($aStyle['theme_folder'] . $aStyle['folder']) . '.' . $sExt;
     if (file_exists($sLogoFile)) {
         Phpfox_File::instance()->unlink($sLogoFile);
     }
     if (@move_uploaded_file($aImage['tmp_name'], $sLogoFile)) {
         Phpfox_Image::instance()->createThumbnail($sLogoFile, $sLogoFile, 100, 100, false);
         return true;
     }
     return Phpfox_Error::set(Phpfox::getPhrase('theme.unable_to_upload_image'));
 }
Example #2
0
 /**
  * Class constructor. We load the image library the admin decided to use on their site.
  *
  */
 public function __construct()
 {
     if (!self::$_oObject) {
         $sDriver = 'phpfox.image.library.gd';
         self::$_oObject = Phpfox::getLib($sDriver);
     }
 }
Example #3
0
 public function add()
 {
     /*
     @title
     @info Create a page. On success it will return information about the new page.
     @method POST
     @extra title=#{Title of the page|string|yes}&info=#{Information about the page|string|yes}&type_id=#{Parent category ID#. Use [action]page.categories[/action]|int|yes}&category_id=#{Sub-category ID#. Use [action]page.categories[/action]|int|yes}&image=#{Default avatar/logo for the page. Must be an HTTP path to an image|string|no}
     @return page_id=#{Page ID#|int}&profile_user_id=#{This is the profile user ID# for the page|int}&title=#{Title of the page|string}&likes=#{Total number of likes|int}&permalink=#{Link to the page|string}&info=#{Information about the page|string}&created_by=#{Person who created the page|string}&created_by_url=#{Profile link of the person who created the page|string}&photo_100px=#{Photo of the page. 100px|string}&photo_100px_square=#{Square photo of the page. 100px|string}
     */
     if ($this->_oApi->isAllowed('pages.add_page') == false) {
         return $this->_oApi->error('pages.add_page', 'Unable to create a page for this user.');
     }
     $aInsert = array('title' => $this->_oApi->get('title'), 'info' => $this->_oApi->get('info'), 'type_id' => $this->_oApi->get('type_id'), 'category_id' => $this->_oApi->get('category_id'));
     $iId = Phpfox::getService('pages.process')->add($aInsert);
     if (!$iId) {
         return $this->_oApi->error('pages.unable_to_add_page', implode('', Phpfox_Error::get()));
     }
     $aPages = $this->get($iId);
     if ($this->_oApi->get('image') != '') {
         $sType = $this->_oApi->get('image_type');
         $sImageContent = file_get_contents($this->_oApi->get('image'));
         $sImagePath = Phpfox::getParam('pages.dir_image') . $aPages[0]['page_id'] . '.' . $sType;
         $hFile = fopen($sImagePath, 'w');
         fwrite($hFile, $sImageContent);
         fclose($hFile);
         $_FILES['photo']['error'] = '';
         $_FILES['photo']['tmp_name'] = $sImagePath;
         $_FILES['photo']['name'] = $this->_oApi->get('photo_name');
         $oFile = Phpfox_File::instance();
         $oImage = Phpfox_Image::instance();
         $aImage = $oFile->load('photo', array('jpg', 'gif', 'png'), Phpfox::getUserParam('pages.max_upload_size_pages') === 0 ? null : Phpfox::getUserParam('pages.max_upload_size_pages') / 1024);
         $sFileName = $oFile->upload('photo', Phpfox::getParam('pages.dir_image'), $iId);
         $sPath = Phpfox::getParam('pages.dir_image');
         $iFileSizes = filesize(Phpfox::getParam('pages.dir_image') . sprintf($sFileName, ''));
         $aUpdate['image_path'] = $sFileName;
         $aUpdate['image_server_id'] = Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID');
         $iSize = 50;
         $oImage->createThumbnail(Phpfox::getParam('pages.dir_image') . sprintf($sFileName, ''), Phpfox::getParam('pages.dir_image') . sprintf($sFileName, '_' . $iSize), $iSize, $iSize);
         $iFileSizes += filesize(Phpfox::getParam('pages.dir_image') . sprintf($sFileName, '_' . $iSize));
         $iSize = 120;
         $oImage->createThumbnail(Phpfox::getParam('pages.dir_image') . sprintf($sFileName, ''), Phpfox::getParam('pages.dir_image') . sprintf($sFileName, '_' . $iSize), $iSize, $iSize);
         $iFileSizes += filesize(Phpfox::getParam('pages.dir_image') . sprintf($sFileName, '_' . $iSize));
         $iSize = 200;
         $oImage->createThumbnail(Phpfox::getParam('pages.dir_image') . sprintf($sFileName, ''), Phpfox::getParam('pages.dir_image') . sprintf($sFileName, '_' . $iSize), $iSize, $iSize);
         $iFileSizes += filesize(Phpfox::getParam('pages.dir_image') . sprintf($sFileName, '_' . $iSize));
         define('PHPFOX_PAGES_IS_IN_UPDATE', true);
         Phpfox::getService('user.process')->uploadImage($aPages[0]['profile_user_id'], true, Phpfox::getParam('pages.dir_image') . sprintf($sFileName, ''));
         // Update user space usage
         Phpfox::getService('user.space')->update(Phpfox::getUserId(), 'pages', $iFileSizes);
         $this->database()->update($this->_sTable, $aUpdate, 'page_id = ' . (int) $iId);
         $aPages = $this->get($iId);
     }
     return $aPages[0];
 }
Example #4
0
 public function add($aVals, $iUpdateId = null)
 {
     $aForms = array('title' => array('message' => Phpfox::getPhrase('subscribe.provide_a_message_for_the_package'), 'type' => array('string:required')), 'description' => array('message' => Phpfox::getPhrase('subscribe.provide_a_description_for_the_package'), 'type' => 'string:required'), 'user_group_id' => array('message' => Phpfox::getPhrase('subscribe.provide_a_user_group_on_success'), 'type' => 'int:required'), 'fail_user_group' => array('message' => Phpfox::getPhrase('subscribe.provide_a_user_group_on_cancellation'), 'type' => 'int:required'), 'is_registration' => array('message' => Phpfox::getPhrase('subscribe.provide_if_the_package_should_be_added_to_the_registration_form'), 'type' => 'int:required'), 'is_active' => array('message' => Phpfox::getPhrase('subscribe.select_if_the_package_is_active_or_not'), 'type' => 'int:required'), 'cost' => array('message' => Phpfox::getPhrase('subscribe.provide_a_price_for_the_package'), 'type' => 'currency:required'), 'show_price' => array('type' => 'int:required'), 'background_color' => array('type' => 'string'));
     $bIsRecurring = false;
     if (isset($aVals['is_recurring']) && $aVals['is_recurring']) {
         $aForms['recurring_cost'] = array('message' => Phpfox::getPhrase('subscribe.provide_a_recurring_cost'), 'type' => 'currency:required');
         $aForms['recurring_period'] = array('message' => Phpfox::getPhrase('subscribe.provide_a_recurring_period'), 'type' => 'int:required');
         $bIsRecurring = true;
     }
     if ($iUpdateId !== null) {
         if (isset($aVals['is_recurring']) && !$aVals['is_recurring']) {
             $aCacheForm = $aVals;
         }
     }
     $aVals = $this->validator()->process($aForms, $aVals);
     if (!Phpfox_Error::isPassed()) {
         return false;
     }
     if ($iUpdateId !== null) {
         if (isset($aCacheForm['is_recurring']) && !$aCacheForm['is_recurring']) {
             $aVals['recurring_period'] = 0;
             $aVals['recurring_cost'] = null;
         }
     }
     $aVals['cost'] = serialize($aVals['cost']);
     if ($bIsRecurring) {
         $aVals['recurring_cost'] = serialize($aVals['recurring_cost']);
     }
     if (!empty($_FILES['image']['name'])) {
         $aImage = Phpfox_File::instance()->load('image', array('jpg', 'gif', 'png'));
         if ($aImage === false) {
             return false;
         }
     }
     $aVals['title'] = $this->preParse()->convert($aVals['title']);
     $aVals['description'] = $this->preParse()->convert($aVals['description']);
     $aVals['background_color'] = Phpfox::getLib('parse.input')->clean($aVals['background_color']);
     if ($iUpdateId !== null) {
         $iId = $iUpdateId;
         $this->database()->update($this->_sTable, $aVals, 'package_id = ' . (int) $iUpdateId);
     } else {
         $iLastOrderId = $this->database()->select('ordering')->from($this->_sTable)->order('ordering DESC')->execute('getSlaveField');
         $aVals['ordering'] = $iLastOrderId + 1;
         $iId = $this->database()->insert($this->_sTable, $aVals);
     }
     if (!empty($_FILES['image']['name']) && ($sFileName = Phpfox_File::instance()->upload('image', Phpfox::getParam('subscribe.dir_image'), $iId))) {
         $this->database()->update($this->_sTable, array('image_path' => $sFileName, 'server_id' => Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID')), 'package_id = ' . (int) $iId);
         Phpfox_Image::instance()->createThumbnail(Phpfox::getParam('subscribe.dir_image') . sprintf($sFileName, ''), Phpfox::getParam('subscribe.dir_image') . sprintf($sFileName, '_120'), 120, 120);
         unlink(Phpfox::getParam('subscribe.dir_image') . sprintf($sFileName, ''));
     }
     return $iId;
 }
Example #5
0
 public function add()
 {
     /*
     @title
     @info 
     @method POST
     @extra title=#{Title of the listing|string|yes}&currency_id=#{Currency ID. Use [action]core.getCurrencies[/action] to get a list of valid currencies|string|yes}&price=#{Price|decimal|no}&country_iso=#{Country ISO ID. Use [action]core.getCurrencies[/action]|string|no}&country_child_id=#{State/Province ID#. Use [action]core.getCurrencies[/action]|int|no}&postal_code=#{Postal code|string|no}&city=#{City|string|no}&mini_description=#{Mini description|string|yes}&description=#{Description|string|yes}&category=#{Comma separated category ID#'s. Use [action]marketplace.categories[/action]|string|yes}&images=#{Comma separated URL to images|string|no}  
     @return id=#{Item ID#|int}&title=#{Title of the item|string}&description=#{Description of the item|string}&likes=#{Total number of likes|int}&permalink=#{Link to the item|string}&mini_description=#{Mini description of the listing|string}&currency_id=#{Currency ID|string}&price=#{Price|decimal}&country_iso=#{Country ISO|string}&postal_code=#{Postal code|string}&city=#{City|string}&images=#{Array of images|array}
     */
     $aCategories = array();
     if ($this->_oApi->get('category')) {
         $aCategories = explode(',', $this->_oApi->get('category'));
     }
     $aVals = array('title' => $this->_oApi->get('title'), 'currency_id' => $this->_oApi->get('currency_id'), 'price' => $this->_oApi->get('price'), 'country_iso' => $this->_oApi->get('country_iso'), 'country_child_id' => $this->_oApi->get('country_child_id'), 'postal_code' => $this->_oApi->get('postal_code'), 'city' => $this->_oApi->get('city'), 'mini_description' => $this->_oApi->get('mini_description'), 'description' => $this->_oApi->get('description'), 'category' => (array) $aCategories);
     if (($iId = Phpfox::getService('marketplace.process')->add($aVals)) !== false) {
         if ($this->_oApi->get('images') != '') {
             $oImage = Phpfox_Image::instance();
             $oFile = Phpfox_File::instance();
             $aSizes = array(50, 120, 200, 400);
             $iFileSizes = 0;
             foreach (explode(',', $this->_oApi->get('images')) as $sImage) {
                 $sType = $oFile->getFileExt($sImage);
                 $sImageContent = file_get_contents($sImage);
                 $sImagePath = Phpfox::getParam('marketplace.dir_image') . $iId . '.' . $sType;
                 $hFile = fopen($sImagePath, 'w');
                 fwrite($hFile, $sImageContent);
                 fclose($hFile);
                 $_FILES['photo']['error'] = '';
                 $_FILES['photo']['tmp_name'] = $sImagePath;
                 $_FILES['photo']['name'] = basename($sImagePath);
                 if ($aImage = $oFile->load('photo', array('jpg', 'gif', 'png'), Phpfox::getUserParam('marketplace.max_upload_size_listing') === 0 ? null : Phpfox::getUserParam('marketplace.max_upload_size_listing') / 1024)) {
                     $sFileName = Phpfox_File::instance()->upload('photo', Phpfox::getParam('marketplace.dir_image'), $iId);
                     $iFileSizes += filesize(Phpfox::getParam('marketplace.dir_image') . sprintf($sFileName, ''));
                     $this->database()->insert(Phpfox::getT('marketplace_image'), array('listing_id' => $iId, 'image_path' => $sFileName, 'server_id' => Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID')));
                     foreach ($aSizes as $iSize) {
                         $oImage->createThumbnail(Phpfox::getParam('marketplace.dir_image') . sprintf($sFileName, ''), Phpfox::getParam('marketplace.dir_image') . sprintf($sFileName, '_' . $iSize), $iSize, $iSize);
                         $oImage->createThumbnail(Phpfox::getParam('marketplace.dir_image') . sprintf($sFileName, ''), Phpfox::getParam('marketplace.dir_image') . sprintf($sFileName, '_' . $iSize . '_square'), $iSize, $iSize, false);
                         $iFileSizes += filesize(Phpfox::getParam('marketplace.dir_image') . sprintf($sFileName, '_' . $iSize));
                     }
                 }
             }
             if ($iFileSizes === 0) {
                 return false;
             }
             $this->database()->update($this->_sTable, array('image_path' => $sFileName, 'server_id' => Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID')), 'listing_id = ' . $iId);
             Phpfox::getService('user.space')->update(Phpfox::getUserId(), 'marketplace', $iFileSizes);
         }
         $aReturn = $this->get($iId);
         return $aReturn[0];
     }
 }
Example #6
0
 /**
  * Uploads an emoticon and inserts it in the package it belongs to, it also updates an emoticon's title and replace.
  * @param array $aVals
  */
 public function addEmoticon($aVals, $sFileName = null)
 {
     // check completeness of the array
     $aForm = array('title' => array('message' => Phpfox::getPhrase('emoticon.select_a_module'), 'type' => 'string:required'), 'text' => array('message' => Phpfox::getPhrase('emoticon.provide_a_emoticon_symbol'), 'type' => 'string:required'), 'package_path' => array('message' => Phpfox::getPhrase('emoticon.define_a_path_for_the_package'), 'type' => 'string:required'));
     $this->validator()->process($aForm, $aVals);
     if (!Phpfox_Error::isPassed()) {
         return false;
     }
     // check that there is not another replace for the same package
     $bExists = $this->database()->select('*')->from($this->_sTable)->where('text = \'' . $aVals['text'] . '\'')->execute('getSlaveRow');
     // if is not updating and the one in the DB matches in text and package_PATH then throw an error
     if (!isset($aVals['emoticon_id']) && isset($bExists['emoticon_id']) && $bExists['emoticon_id'] > 0) {
         return Phpfox_Error::set(Phpfox::getPhrase('emoticon.symbol_already_exists'));
     }
     // if is updating then update all the fields except the image field right away
     if (isset($aVals['emoticon_id']) && $aVals['emoticon_id'] > 0) {
         $aUpdate = array('title' => Phpfox::getLib('parse.input')->clean($aVals['title']), 'text' => Phpfox::getLib('parse.input')->clean($aVals['text']), 'package_path' => Phpfox::getLib('parse.input')->clean($aVals['package_path']));
         $this->database()->update($this->_sTable, $aUpdate, 'emoticon_id = ' . (int) $aVals['emoticon_id']);
     }
     // Upload image
     if (!empty($aVals['file']['tmp_name'])) {
         if ($sFileName === null) {
             $oFile = Phpfox_File::instance();
             $oImage = Phpfox_Image::instance();
             $aImage = $oFile->load('file', array('png', 'jpg', 'gif'));
             if ($aImage === false) {
                 return false;
             }
             $sFileName = Phpfox::getLib('parse.input')->cleanFileName(preg_replace("/^(.*?)\\.(jpg|jpeg|gif|png)\$/i", "\$1", $aVals['file']['name']));
             $sDirectory = $this->database()->select('package_path')->from(Phpfox::getT('emoticon_package'))->where('package_path =\'' . $this->database()->escape(Phpfox::getLib('parse.input')->clean($aVals['package_path'])) . '\'')->execute('getSlaveField');
             $sDirectory = Phpfox::getParam('core.dir_emoticon') . $sDirectory . PHPFOX_DS;
             if (!($sFileName = $oFile->upload('file', $sDirectory, $sFileName, false, 0644, false))) {
                 return Phpfox_Error::set(Phpfox::getPhrase('emoticon.image_could_not_be_uploaded'));
             }
         }
     }
     if (isset($aVals['emoticon_id']) && is_numeric($aVals['emoticon_id'])) {
         // Update the image field
         $this->database()->update($this->_sTable, array('title' => $this->preParse()->clean($aVals['title']), 'text' => $this->preParse()->clean($aVals['text'])), 'emoticon_id = ' . (int) $aVals['emoticon_id']);
     } else {
         // insert in the database
         $aInsert = array('title' => $this->preParse()->clean($aVals['title']), 'text' => $this->preParse()->clean($aVals['text']), 'image' => str_replace('%s', '', $sFileName), 'package_path' => Phpfox::getLib('parse.input')->clean($aVals['package_path']));
         $this->database()->insert($this->_sTable, $aInsert);
     }
     // remove cache
     $this->cache()->remove('emoticon');
     $this->cache()->remove('emoticon_parse');
     return true;
 }
Example #7
0
 /**
  * Controller
  */
 public function process()
 {
     if (!Phpfox::isUser()) {
         exit;
     }
     $aImage = Phpfox_File::instance()->load('image', array('jpg', 'gif', 'png'));
     if ($aImage === false) {
         return j('#js_image_error')->show();
     }
     $aParts = explode('x', $this->request()->get('ad_size'));
     if ($sFileName = Phpfox_File::instance()->upload('image', Phpfox::getParam('ad.dir_image'), Phpfox::getUserId() . uniqid())) {
         Phpfox_Image::instance()->createThumbnail(Phpfox::getParam('ad.dir_image') . sprintf($sFileName, ''), Phpfox::getParam('ad.dir_image') . sprintf($sFileName, '_thumb'), Phpfox::getParam('ad.multi_ad') ? 100 : $aParts[0] / 3, Phpfox::getParam('ad.multi_ad') ? 72 : $aParts[1] - 20);
         Phpfox_File::instance()->unlink(Phpfox::getParam('ad.dir_image') . sprintf($sFileName, ''));
         rename(Phpfox::getParam('ad.dir_image') . sprintf($sFileName, '_thumb'), Phpfox::getParam('ad.dir_image') . sprintf($sFileName, ''));
         // http://www.phpfox.com/tracker/view/14922/ -> If CDN, the unlink function above deletes the image!!
         if (Phpfox::getParam('core.allow_cdn')) {
             Phpfox::getLib('cdn')->put(Phpfox::getParam('ad.dir_image') . sprintf($sFileName, ''));
         }
         return ['run' => '$(\'.js_ad_image\').html(\'<a href="#ad-link"><img src="' . Phpfox::getParam('ad.url_image') . sprintf($sFileName, '') . '" alt="" /></a>\').show(); window.parent.$(\'#js_image_holder_message\').hide(); window.parent.$(\'#js_image_holder_link\').show(); window.parent.$(\'#js_image_id\').val(\'' . sprintf($sFileName, '') . '\');'];
     }
     exit;
 }
Example #8
0
 public function cropPhoto($aVals)
 {
     if (isset($aVals['skip_croping'])) {
         return true;
     }
     // http://www.phpfox.com/tracker/view/14516/
     $sFile = Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), '');
     if (!file_exists($sFile)) {
         if (Phpfox::getParam('core.allow_cdn')) {
             $sMainFile = $sFile;
             $sActualFile = Phpfox::getLib('image.helper')->display(array('server_id' => Phpfox::getUserBy('server_id'), 'path' => 'core.url_user', 'file' => Phpfox::getUserBy('user_image'), 'suffix' => (!isset($iSize) ? '' : '_') . $iSize, 'return_url' => true));
             copy($sActualFile, $sFile);
         }
     }
     Phpfox_Image::instance()->createThumbnail(Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), ''), Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), '') . '_temp', $aVals['image_width'], $aVals['image_height'], false);
     if (empty($aVals['w'])) {
         return Phpfox_Error::set(Phpfox::getPhrase('photo.select_an_area_on_your_photo_to_crop'));
     }
     Phpfox_Image::instance()->cropImage(Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), '') . '_temp', Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), '_50_square'), $aVals['w'], $aVals['h'], $aVals['x1'], $aVals['y1'], 75);
     Phpfox_Image::instance()->cropImage(Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), '') . '_temp', Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), '') . '_temp', $aVals['w'], $aVals['h'], $aVals['x1'], $aVals['y1'], $aVals['w']);
     foreach (Phpfox::getParam('user.user_pic_sizes') as $iSize) {
         if ($iSize >= 75) {
             // continue;
         }
         if (Phpfox::getParam('core.keep_non_square_images')) {
             Phpfox_Image::instance()->createThumbnail(Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), '') . '_temp', Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), '_' . $iSize), $iSize, $iSize);
         }
         Phpfox_Image::instance()->createThumbnail(Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), '') . '_temp', Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), '_' . $iSize . '_square'), $iSize, $iSize, false);
         if (defined('PHPFOX_IS_HOSTED_SCRIPT')) {
             unlink(Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), '_' . $iSize));
             unlink(Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), '_' . $iSize . '_square'));
         }
     }
     unlink(Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), '') . '_temp');
     // http://www.phpfox.com/tracker/view/14516/
     if (Phpfox::isModule('photo') && Phpfox::getParam('photo.delete_original_after_resize')) {
         if (file_exists(Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), '') . '_temp')) {
             unlink(Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), '') . '_temp');
         }
         if (Phpfox::getParam('core.allow_cdn')) {
             Phpfox::getLib('cdn')->remove(sprintf(sprintf(Phpfox::getUserBy('user_image'), '')));
         }
     }
     return true;
 }
Example #9
0
    /**
     * Controller
     */
    public function process()
    {
        if (!isset($_FILES['file']) && isset($_FILES['Filedata'])) {
            $_FILES['file'] = array();
            $_FILES['file']['error']['file'] = UPLOAD_ERR_OK;
            $_FILES['file']['name']['file'] = $_FILES['Filedata']['name'];
            $_FILES['file']['type']['file'] = $_FILES['Filedata']['type'];
            $_FILES['file']['tmp_name']['file'] = $_FILES['Filedata']['tmp_name'];
            $_FILES['file']['size']['file'] = $_FILES['Filedata']['size'];
        } elseif (!isset($_FILES['file'])) {
            exit;
        }
        $oFile = Phpfox_File::instance();
        $oImage = Phpfox_Image::instance();
        $oAttachment = Phpfox::getService('attachment.process');
        $sIds = '';
        $sStr = '';
        $iUploaded = 0;
        $iFileSizes = 0;
        foreach ($_FILES['file']['error'] as $iKey => $sError) {
            if ($sError == UPLOAD_ERR_OK) {
                $aValid = array('gif', 'png', 'jpg');
                if ($this->request()->get('custom_attachment') == 'photo') {
                    $aValid = array('gif', 'png', 'jpg');
                } elseif ($this->request()->get('custom_attachment') == 'video') {
                    $aValid = Phpfox::getService('video')->getFileExt();
                }
                if ($this->request()->get('input') == '' && $this->request()->get('custom_attachment') == '') {
                    $aValid = Phpfox::getService('attachment.type')->getTypes();
                }
                $iMaxSize = null;
                if (Phpfox::getUserParam('attachment.item_max_upload_size') !== 0) {
                    $iMaxSize = Phpfox::getUserParam('attachment.item_max_upload_size') / 1024;
                }
                $aImage = $oFile->load('file[' . $iKey . ']', $aValid, $iMaxSize);
                if ($aImage !== false) {
                    if (!Phpfox::getService('attachment')->isAllowed()) {
                        echo '<script type="text/javascript">window.parent.$(\'#' . $this->request()->get('upload_id') . '\').parents(\'.js_upload_attachment_parent_holder\').html(\'<div class="error_message">' . Phpfox::getPhrase('attachment.failed_limit_reached') . '</div>\');</script>';
                        continue;
                    }
                    $iUploaded++;
                    $bIsImage = in_array($aImage['ext'], Phpfox::getParam('attachment.attachment_valid_images'));
                    $iId = $oAttachment->add(array('category' => $this->request()->get('category_name'), 'file_name' => $_FILES['file']['name'][$iKey], 'extension' => $aImage['ext'], 'is_image' => $bIsImage));
                    $sIds .= $iId . ',';
                    $sFileName = $oFile->upload('file[' . $iKey . ']', Phpfox::getParam('core.dir_attachment'), $iId);
                    $sFileSize = filesize(Phpfox::getParam('core.dir_attachment') . sprintf($sFileName, ''));
                    $iFileSizes += $sFileSize;
                    $oAttachment->update(array('file_size' => $sFileSize, 'destination' => $sFileName, 'server_id' => Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID')), $iId);
                    if ($bIsImage) {
                        $sThumbnail = Phpfox::getParam('core.dir_attachment') . sprintf($sFileName, '_thumb');
                        $sViewImage = Phpfox::getParam('core.dir_attachment') . sprintf($sFileName, '_view');
                        $oImage->createThumbnail(Phpfox::getParam('core.dir_attachment') . sprintf($sFileName, ''), $sThumbnail, Phpfox::getParam('attachment.attachment_max_thumbnail'), Phpfox::getParam('attachment.attachment_max_thumbnail'));
                        $oImage->createThumbnail(Phpfox::getParam('core.dir_attachment') . sprintf($sFileName, ''), $sViewImage, Phpfox::getParam('attachment.attachment_max_medium'), Phpfox::getParam('attachment.attachment_max_medium'));
                        $iFileSizes += filesize($sThumbnail) + filesize($sThumbnail);
                    }
                    if ($this->request()->get('custom_attachment') == 'video') {
                        Phpfox::getService('user.space')->update(Phpfox::getUserId(), 'attachment', $iFileSizes);
                        echo '<script type="text/javascript">window.parent.$(\'#' . $this->request()->get('upload_id') . '\').find(\'.js_upload_form_image_holder:first\').html(\'<div class="js_upload_form_image_holder_image">' . Phpfox::getLib('image.helper')->display(array('theme' => 'ajax/add.gif')) . '</div>' . Phpfox::getPhrase('attachment.converting') . ' ' . strip_tags($_FILES['file']['name'][$iKey]) . '...\'); window.parent.$.ajaxCall(\'video.convert\', \'attachment_id=' . $iId . '&attachment_inline=' . ($this->request()->get('attachment_inline') ? '1' : '0') . '&attachment_obj_id=' . $this->request()->get('attachment_obj_id') . '\');</script>';
                        exit;
                    } else {
                        echo '<script type="text/javascript">window.parent.$(\'#' . $this->request()->get('upload_id') . '\').find(\'.js_upload_form_image_holder:first\').html(\'<div class="js_upload_form_image_holder_image">' . Phpfox::getLib('image.helper')->display(array('theme' => 'misc/accept.png')) . '</div>Completed ' . strip_tags($_FILES['file']['name'][$iKey]) . '\');</script>';
                    }
                } else {
                    echo '<script type="text/javascript">window.parent.$(\'#' . $this->request()->get('upload_id') . '\').find(\'.js_upload_form_image_holder:first\').html(\'<div class="js_upload_form_image_holder_image">' . Phpfox::getLib('image.helper')->display(array('theme' => 'misc/delete.png')) . '</div>Failed ' . strip_tags($_FILES['file']['name'][$iKey]) . ' <br /> <div class="error_message">' . implode(' ', Phpfox_Error::get()) . '</div>\');</script>';
                }
            }
        }
        if (!$iUploaded) {
            exit;
        }
        if ($this->request()->get('custom_attachment') == 'photo' || $this->request()->get('custom_attachment') == 'video') {
            $aAttachment = Phpfox_Database::instance()->select('*')->from(Phpfox::getT('attachment'))->where('attachment_id = ' . (int) $iId)->execute('getSlaveRow');
            if ($this->request()->get('custom_attachment') == 'photo') {
                $sImagePath = Phpfox::getLib('image.helper')->display(array('server_id' => $aAttachment['server_id'], 'path' => 'core.url_attachment', 'file' => $aAttachment['destination'], 'suffix' => '_view', 'max_width' => 'attachment.attachment_max_medium', 'max_height' => 'attachment.attachment_max_medium', 'return_url' => true));
                echo '
				<script type="text/javascript">
					window.parent.Editor.insert({is_image: true, name: \'\', id: \'' . $iId . ':view\', type: \'image\', path: \'' . $sImagePath . '\'});
				</script>
				';
            } else {
                echo '
				<script type="text/javascript">
					window.parent.Editor.insert({is_image: true, name: \'\', id: \'' . $iId . '\', type: \'video\'});
				</script>
				';
            }
        } else {
            ob_start();
            Phpfox::getBlock('attachment.list', array('sIds' => $sIds, 'bCanUseInline' => true, 'attachment_no_header' => true, 'attachment_edit' => true, 'sAttachmentInput' => $this->request()->get('input')));
            $sContent = ob_get_contents();
            ob_clean();
            $sAttachmentObject = $this->request()->get('attachment_obj_id');
            if (!empty($sAttachmentObject)) {
                echo '
				<script type="text/javascript">
					var $oParent = window.parent.$(\'#' . $this->request()->get('attachment_obj_id') . '\');
					$oParent.find(\'.js_attachment:first\').val($oParent.find(\'.js_attachment:first\').val() + \'' . $sIds . '\');
					$oParent.find(\'.js_attachment_list:first\').show();
					$oParent.find(\'.js_attachment_list_holder:first\').prepend(\'' . str_replace("'", "\\'", str_replace(array("\n", "\t", "\r"), '', $sContent)) . '\');
					window.parent.$Core.loadInit();
				</script>
				';
            }
            if ($this->request()->get('category_name') == 'theme') {
                echo '
				<script type="text/javascript">
					var $oParent = window.parent.$(\'#' . $this->request()->get('input') . '\');
					$oParent.val(\'' . Phpfox::getParam('core.url_attachment') . sprintf($sFileName, '') . '\');
					// window.parent.on_change_image($oParent);
					$oParent.focus();
					$oParent.blur();
					window.parent.tb_remove();
				</script>
				';
            }
        }
        // Update user space usage
        Phpfox::getService('user.space')->update(Phpfox::getUserId(), 'attachment', $iFileSizes);
        if ($this->request()->get('attachment_inline')) {
            echo '<script type="text/javascript">window.parent.$Core.updateInlineBox();</script>';
        }
        exit;
    }
Example #10
0
 /**
  * Adds a photo to an album of the name of the application.
  * If such album does not exist it creates it.
  */
 public function addPhoto()
 {
     // Check permission
     if ($this->_oApi->isAllowed('photo.add_photo') == false) {
         return $this->_oApi->error('photo.add_photo', 'User did not allow to upload photos on their behalf.');
     }
     $oFile = Phpfox_File::instance();
     $oImage = Phpfox_Image::instance();
     if (isset($_FILES['photo'])) {
         $sType = 'png';
         switch ($_FILES['photo']['type']) {
             case 'image/jpeg':
             case 'image/jpg':
                 $sType = 'jpg';
                 break;
             case 'image/gif':
                 $sType = 'gif';
                 break;
         }
     }
     $bIsUrlImage = false;
     if (empty($_FILES['photo'])) {
         $sImage = $this->_oApi->get('url');
         $sType = $oFile->getFileExt($sImage);
         $sImageContent = file_get_contents($sImage);
         $bIsUrlImage = true;
     }
     $sImagePath = Phpfox::getParam('photo.dir_photo') . uniqid() . '.' . $sType;
     if ($bIsUrlImage) {
         $hFile = fopen($sImagePath, 'w');
         fwrite($hFile, $sImageContent);
         fclose($hFile);
         $_FILES['photo']['error'] = '';
         $_FILES['photo']['name'] = basename($sImagePath);
         $_FILES['photo']['size'] = filesize($sImagePath);
         $_FILES['photo']['type'] = $sType;
     } else {
         move_uploaded_file($_FILES['photo']['tmp_name'], $sImagePath);
         $_FILES['photo']['name'] = $this->_oApi->get('photo_name');
     }
     $_FILES['photo']['tmp_name'] = $sImagePath;
     $aImage = $oFile->load('photo', array('jpg', 'gif', 'png'), Phpfox::getUserParam('photo.photo_max_upload_size') === 0 ? null : Phpfox::getUserParam('photo.photo_max_upload_size') / 1024);
     $aImage['type_id'] = 1;
     $aImage['description'] = $this->_oApi->get('description');
     $aErrors = Phpfox_Error::get();
     if (!empty($aErrors)) {
         return $this->_oApi->error('photo.photo_add_photo_load', array_pop($aErrors));
     }
     $aReturnPhotos = array();
     if ($iId = Phpfox::getService('photo.process')->add(PHPFOX_APP_USER_ID, $aImage)) {
         $sFileName = $oFile->upload('photo', Phpfox::getParam('photo.dir_photo'), $iId);
         $sPath = Phpfox::getParam('photo.dir_photo');
         $aErrors = Phpfox_Error::get();
         if (!empty($aErrors)) {
             return $this->_oApi->error('photo.photo_add_photo_upload', array_pop($aErrors));
         }
         $sPhotoTitle = $this->_oApi->get('photo_name');
         if (empty($sPhotoTitle)) {
             $sPhotoTitle = $this->_oApi->getAppName() . ' ' . rand(100, 999);
         }
         // Update the image with the full path to where it is located.
         $aSize = getimagesize(Phpfox::getParam('photo.dir_photo') . sprintf($sFileName, ''));
         Phpfox::getService('photo.process')->update(Phpfox::getUserId(), $iId, array('destination' => $sFileName, 'title' => $sPhotoTitle, 'width' => $aSize[0], 'height' => $aSize[1], 'server_id' => Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID')));
         $aReturnPhotos['original'] = Phpfox::getParam('photo.url_photo') . sprintf($sFileName, '');
         foreach (Phpfox::getParam('photo.photo_pic_sizes') as $iSize) {
             if ($oImage->createThumbnail($sPath . sprintf($sFileName, ''), $sPath . sprintf($sFileName, '_' . $iSize), $iSize, $iSize) === false) {
                 continue;
             }
             $aReturnPhotos[$iSize . 'px'] = Phpfox::getParam('photo.url_photo') . sprintf($sFileName, '_' . $iSize);
             if (Phpfox::getParam('photo.enabled_watermark_on_photos')) {
                 $oImage->addMark($sPath . sprintf($sFileName, '_' . $iSize));
             }
         }
         if (Phpfox::getParam('photo.enabled_watermark_on_photos')) {
             $oImage->addMark($sPath . sprintf($sFileName, ''));
         }
         if (Phpfox::isModule('feed')) {
             $iPrivacy = null;
             $iPrivacyComment = null;
             $iFeedId = Phpfox::getService('feed.process')->add('photo', $iId, $iPrivacy, $iPrivacyComment, 0);
         }
         return $this->getPhotos($iId);
     }
     return $this->_oApi->error('photo.add_photo_process', 'Could not add photo to process');
 }
Example #11
0
 public function rotate($iId, $sCmd)
 {
     $aPhoto = $this->database()->select('user_id, title, photo_id, destination, server_id')->from($this->_sTable)->where('photo_id = ' . (int) $iId)->execute('getSlaveRow');
     if (!isset($aPhoto['photo_id'])) {
         return Phpfox_Error::set(Phpfox::getPhrase('photo.unable_to_find_the_photo_you_plan_to_edit'));
     }
     if ($aPhoto['user_id'] == Phpfox::getUserId() && Phpfox::getUserParam('photo.can_edit_own_photo') || Phpfox::getUserParam('photo.can_edit_other_photo')) {
         if (!Phpfox::getParam('photo.delete_original_after_resize')) {
             $aSizes = array_merge(array(''), Phpfox::getParam('photo.photo_pic_sizes'));
         } else {
             $aSizes = Phpfox::getParam('photo.photo_pic_sizes');
         }
         $aParts = explode('/', $aPhoto['destination']);
         $sParts = '';
         if (is_array($aParts)) {
             foreach ($aParts as $sPart) {
                 if (!empty($sPart)) {
                     if (!preg_match('/jpg|gif|png/i', $sPart)) {
                         $sParts .= $sPart . '/';
                     }
                 }
             }
         }
         foreach ($aSizes as $iSize) {
             $sFile = Phpfox::getParam('photo.dir_photo') . sprintf($aPhoto['destination'], (empty($iSize) ? '' : '_') . $iSize);
             if (file_exists($sFile) || Phpfox::getParam('core.allow_cdn')) {
                 if (Phpfox::getParam('core.allow_cdn') && $aPhoto['server_id'] > 0) {
                     $sMainFile = $sFile;
                     $sActualFile = Phpfox::getLib('image.helper')->display(array('server_id' => $aPhoto['server_id'], 'path' => 'photo.url_photo', 'file' => $aPhoto['destination'], 'suffix' => (empty($iSize) ? '' : '_') . $iSize, 'return_url' => true));
                     $aExts = preg_split("/[\\/\\.]/", $sActualFile);
                     $iCnt = count($aExts) - 1;
                     $sExt = strtolower($aExts[$iCnt]);
                     $sFile = Phpfox::getParam('photo.dir_photo') . $sParts . md5($aPhoto['destination']) . (empty($iSize) ? '' : '_') . $iSize . '.' . $sExt;
                     copy($sActualFile, $sFile);
                     //p($sFile);
                 }
                 Phpfox_Image::instance()->rotate($sFile, $sCmd);
             }
             if (Phpfox::getParam('core.allow_cdn') && $aPhoto['server_id'] > 0) {
                 $this->database()->update(Phpfox::getT('photo'), array('destination' => $sParts . md5($aPhoto['destination']) . '%s.' . $sExt), 'photo_id = ' . (int) $aPhoto['photo_id']);
             }
         }
         return $aPhoto;
     }
     return false;
 }
Example #12
0
 /**
  * @todo Security checks. Users perms.
  *
  * @param unknown_type $iId
  * @param unknown_type $aVals
  * @return unknown
  */
 public function update($iId, $aVals)
 {
     $aAlbum = $this->database()->select('*')->from($this->_sTable)->where('album_id = ' . (int) $iId)->execute('getSlaveRow');
     if (!isset($aAlbum['album_id'])) {
         return Phpfox_Error::set(Phpfox::getPhrase('music.unable_to_find_the_album_you_want_to_edit'));
     }
     Phpfox::getService('ban')->checkAutomaticBan($aVals['name'] . ' ' . $aVals['text']);
     if ($aAlbum['user_id'] == Phpfox::getUserId() && Phpfox::getUserParam('music.can_edit_own_albums') || Phpfox::getUserParam('music.can_edit_other_music_albums')) {
         if (empty($aVals['privacy'])) {
             $aVals['privacy'] = 0;
         }
         if (empty($aVals['privacy_comment'])) {
             $aVals['privacy_comment'] = 0;
         }
         $this->database()->update($this->_sTable, array('privacy' => isset($aVals['privacy']) ? $aVals['privacy'] : '0', 'privacy_comment' => isset($aVals['privacy_comment']) ? $aVals['privacy_comment'] : '0', 'name' => $this->preParse()->clean($aVals['name'], 255), 'year' => $aVals['year']), 'album_id = ' . $aAlbum['album_id']);
         $this->database()->update(Phpfox::getT('music_album_text'), array('text' => empty($aVals['text']) ? null : $this->preParse()->clean($aVals['text']), 'text_parsed' => empty($aVals['text']) ? null : $this->preParse()->prepare($aVals['text'])), 'album_id = ' . $aAlbum['album_id']);
         $aSongs = $this->database()->select('song_id, user_id')->from(Phpfox::getT('music_song'))->where('album_id = ' . (int) $aAlbum['album_id'])->execute('getSlaveRows');
         if (count($aSongs)) {
             foreach ($aSongs as $aSong) {
                 $this->database()->update(Phpfox::getT('music_song'), array('privacy' => isset($aVals['privacy']) ? $aVals['privacy'] : '0', 'privacy_comment' => isset($aVals['privacy_comment']) ? $aVals['privacy_comment'] : '0'), 'song_id = ' . $aSong['song_id']);
                 Phpfox::isModule('feed') ? Phpfox::getService('feed.process')->update('music_album', $aSong['song_id'], $aVals['privacy'], $aVals['privacy_comment'], 0, $aSong['user_id']) : null;
                 if (Phpfox::isModule('privacy')) {
                     if ($aVals['privacy'] == '4') {
                         Phpfox::getService('privacy.process')->update('music_song', $aSong['song_id'], isset($aVals['privacy_list']) ? $aVals['privacy_list'] : array());
                     } else {
                         Phpfox::getService('privacy.process')->delete('music_song', $aSong['song_id']);
                     }
                 }
             }
         }
         if (Phpfox::isModule('privacy')) {
             if ($aVals['privacy'] == '4') {
                 Phpfox::getService('privacy.process')->update('music_album', $iId, isset($aVals['privacy_list']) ? $aVals['privacy_list'] : array());
             } else {
                 Phpfox::getService('privacy.process')->delete('music_album', $iId);
             }
         }
         if (!empty($_FILES['image']['name'])) {
             $aImage = Phpfox_File::instance()->load('image', array('jpg', 'gif', 'png'));
             if ($aImage === false) {
                 return false;
             }
             $oImage = Phpfox_Image::instance();
             $oFile = Phpfox_File::instance();
             $sFileName = Phpfox_File::instance()->upload('image', Phpfox::getParam('music.dir_image'), $iId);
             $iFileSizes = filesize(Phpfox::getParam('music.dir_image') . sprintf($sFileName, ''));
             foreach ($this->_aPhotoSizes as $iSize) {
                 $oImage->createThumbnail(Phpfox::getParam('music.dir_image') . sprintf($sFileName, ''), Phpfox::getParam('music.dir_image') . sprintf($sFileName, '_' . $iSize), $iSize, $iSize);
                 $oImage->createThumbnail(Phpfox::getParam('music.dir_image') . sprintf($sFileName, ''), Phpfox::getParam('music.dir_image') . sprintf($sFileName, '_' . $iSize . '_square'), $iSize, $iSize, false);
                 $iFileSizes += filesize(Phpfox::getParam('music.dir_image') . sprintf($sFileName, '_' . $iSize));
             }
             $this->database()->update($this->_sTable, array('image_path' => $sFileName, 'server_id' => Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID')), 'album_id = ' . $iId);
             // Update user space usage
             Phpfox::getService('user.space')->update($aAlbum['user_id'], 'music_image', $iFileSizes);
         }
         if (!empty($_FILES['mp3']['name'])) {
             if (empty($aVals['title'])) {
                 return Phpfox_Error::set(Phpfox::getPhrase('music.provide_a_title_for_this_track'));
             }
             if (!Music_Service_Process::instance()->upload($aVals, $aAlbum['album_id'])) {
                 return false;
             }
         }
         ($sPlugin = Phpfox_Plugin::get('music.service_album_process_update__1')) ? eval($sPlugin) : false;
         return true;
     }
     return Phpfox_Error::set(Phpfox::getPhrase('music.unable_to_edit_this_album'));
 }
Example #13
0
 public function updateCounter($iId, $iPage, $iPageLimit)
 {
     if ($iId == 'photo-profile') {
         $iCnt = $this->database()->select('COUNT(*)')->from(Phpfox::getT('photo'), 'p')->join(Phpfox::getT('photo_album'), 'pa', 'pa.album_id = p.album_id AND pa.profile_id > 0')->execute('getSlaveField');
         $aRows = $this->database()->select('p.photo_id')->from(Phpfox::getT('photo'), 'p')->join(Phpfox::getT('photo_album'), 'pa', 'pa.album_id = p.album_id AND pa.profile_id > 0')->limit($iPage, $iPageLimit, $iCnt)->execute('getSlaveRows');
         foreach ($aRows as $aRow) {
             $this->database()->update(Phpfox::getT('photo'), array('is_profile_photo' => '1'), 'photo_id = ' . $aRow['photo_id']);
         }
         return $iCnt;
     } elseif ($iId == 'photo-tag-update') {
         $iCnt = $this->database()->select('COUNT(*)')->from(Phpfox::getT('tag'))->where('category_id = \'photo\'')->execute('getSlaveField');
         $aRows = $this->database()->select('m.tag_id, oc.photo_id AS tag_item_id')->from(Phpfox::getT('tag'), 'm')->where('m.category_id = \'photo\'')->leftJoin(Phpfox::getT('photo'), 'oc', 'oc.photo_id = m.item_id')->limit($iPage, $iPageLimit, $iCnt)->execute('getSlaveRows');
         foreach ($aRows as $aRow) {
             if (empty($aRow['tag_item_id'])) {
                 $this->database()->delete(Phpfox::getT('tag'), 'tag_id = ' . $aRow['tag_id']);
             }
         }
         return $iCnt;
     } elseif ($iId == 'photo-thumbnail') {
         @ini_set('memory_limit', '100M');
         $iCnt = $this->database()->select('COUNT(*)')->from(Phpfox::getT('photo'))->where($this->database()->isNotNull('destination'))->execute('getSlaveField');
         $aRows = $this->database()->select('photo_id, destination')->from(Phpfox::getT('photo'))->where($this->database()->isNotNull('destination'))->limit($iPage, $iPageLimit, $iCnt)->execute('getSlaveRows');
         $oImage = Phpfox_Image::instance();
         foreach ($aRows as $aRow) {
             if (preg_match("/\\{file\\/pic\\/(.*)\\/(.*)\\.jpg\\}/i", $aRow['destination'], $aMatches)) {
                 $sPath = PHPFOX_DIR;
                 $sFileName = str_replace(array('{', '.jpg}'), array('', '%s.jpg'), $aRow['destination']);
             } else {
                 $sPath = Phpfox::getParam('photo.dir_photo');
                 $sFileName = $aRow['destination'];
             }
             if (file_exists($sPath . sprintf($sFileName, ''))) {
                 foreach (Phpfox::getParam('photo.photo_pic_sizes') as $iSize) {
                     if ($oImage->createThumbnail($sPath . sprintf($sFileName, ''), $sPath . sprintf($sFileName, '_' . $iSize), $iSize, $iSize) === false) {
                         continue;
                     }
                     if (Phpfox::getParam('photo.enabled_watermark_on_photos')) {
                         $oImage->addMark($sPath . sprintf($sFileName, '_' . $iSize));
                     }
                 }
                 if (Phpfox::getParam('photo.enabled_watermark_on_photos')) {
                     $oImage->addMark($sPath . sprintf($sFileName, ''));
                 }
             }
         }
         return $iCnt;
     } elseif ($iId == 'photo-count') {
         $iCnt = $this->database()->select('COUNT(*)')->from(Phpfox::getT('user'))->execute('getSlaveField');
         $aRows = $this->database()->select('u.user_id')->from(Phpfox::getT('user'), 'u')->limit($iPage, $iPageLimit, $iCnt)->group('u.user_id')->execute('getSlaveRows');
         foreach ($aRows as $aRow) {
             $iTotalPhotos = $this->database()->select('COUNT(f.photo_id)')->from(Phpfox::getT('photo'), 'f')->where('f.view_id = 0 AND f.group_id = 0 AND f.type_id = 0 AND f.privacy = 0 AND f.user_id = ' . $aRow['user_id'])->execute('getSlaveField');
             $this->database()->update(Phpfox::getT('user_field'), array('total_photo' => $iTotalPhotos), 'user_id = ' . $aRow['user_id']);
         }
     }
     $iCnt = $this->database()->select('COUNT(*)')->from(Phpfox::getT('photo_album'))->execute('getSlaveField');
     $aRows = $this->database()->select('g.album_id, COUNT(gi.photo_id) AS total_items')->from(Phpfox::getT('photo_album'), 'g')->leftJoin(Phpfox::getT('photo'), 'gi', 'gi.album_id = g.album_id')->group('g.album_id')->limit($iPage, $iPageLimit, $iCnt)->execute('getSlaveRows');
     foreach ($aRows as $aRow) {
         $this->database()->update(Phpfox::getT('photo_album'), array('total_photo' => $aRow['total_items']), 'album_id = ' . (int) $aRow['album_id']);
     }
     return $iCnt;
 }
Example #14
0
 /**
  * Method is named "upload", however due to how PHP works the file has already been
  * uploaded and this simply moves the uploaded file to the final location
  * since it passed all the tests done by the load() method.
  *
  * @param string $sFormItem Name of the <input> used when submitting the form.
  * @param string $sDestination Full path to where the final location of the file will be
  * @param string $sFileName File name of the uploaded file once we have moved it to its final destination
  * @param bool $bModifyFileName By default we modify the actual file name with a unique MD5 hash to make it harder to find, however setting this to FALSE will keep the original name of the file.
  * @param int $iPerm UNIX file permissions on the file. Default is 0644 (read only).
  * @param bool $buildDir We place files in folders based on the current month/year by default. Set this to FALSE to not create such directories and place it in the specificed destination folder.
  * @param bool $bCdn If CDN support is enabled we will copy the file to the CDN server. Set this to FALSE to force the script to not copy the file to CDN even if support is enabled for CDN.
  * @return mixed Returns a FALSE if we cannot move the file or a STRING on the full path of where the file is located as well as the files new name and extension.
  */
 public function upload($sFormItem, $sDestination, $sFileName, $bModifyFileName = true, $iPerm = 0644, $buildDir = true, $bCdn = true)
 {
     ($sPlugin = Phpfox_Plugin::get('file_upload_start')) ? eval($sPlugin) : false;
     if ($buildDir) {
         $this->_buildDir($sDestination);
     } else {
         $this->_sDestination = $sDestination;
     }
     if ($sPlugin = Phpfox_Plugin::get('library_phpfox_file_file_upload_1')) {
         eval($sPlugin);
         if (isset($mReturnFromPlugin)) {
             return $mReturnFromPlugin;
         }
     }
     if ($bModifyFileName === true) {
         $sFileName = md5($sFileName . PHPFOX_TIME . uniqid());
     }
     if (Phpfox::getParam(array('balancer', 'enabled'))) {
         if (Phpfox_Image::instance()->isImageExtension($this->_aFile['ext'])) {
             list($iWidth, $iHeight) = getimagesize($this->_aFile['tmp_name']);
             $sFileName = $iWidth . '-' . $iHeight . '-' . Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID') . '_' . $sFileName;
         } else {
             $sFileName = Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID') . '_' . $sFileName;
         }
     }
     $sDest = $this->_sDestination . $sFileName . '.' . $this->_sExt;
     if ($sPlugin = Phpfox_Plugin::get('library_phpfox_file_file_upload_2')) {
         eval($sPlugin);
         if (isset($mReturnFromPlugin)) {
             return $mReturnFromPlugin;
         }
     }
     if (defined('PHPFOX_APP_USER_ID') || defined('PHPFOX_HTML5_PHOTO_UPLOAD')) {
         @copy($this->_aFile['tmp_name'], $sDest);
         @unlink($this->_aFile['tmp_name']);
     } else {
         if (!@move_uploaded_file($this->_aFile['tmp_name'], $sDest)) {
             return Phpfox_Error::set(Phpfox::getPhrase('core.unable_to_move_the_file'));
         }
     }
     if ($sPlugin = Phpfox_Plugin::get('library_phpfox_file_file_upload_3')) {
         eval($sPlugin);
         if (isset($mReturnFromPlugin)) {
             return $mReturnFromPlugin;
         }
     }
     // Windows permission problem???
     if (stristr(PHP_OS, "win")) {
         @copy($sDest, $sDest . '.cache');
         @unlink($sDest);
         @copy($sDest . '.cache', $sDest);
         @unlink($sDest . '.cache');
     } else {
         @chmod($sDest, $iPerm);
     }
     if (Phpfox::getParam('core.allow_cdn') && $bCdn === true) {
         $bReturn = Phpfox::getLib('cdn')->put($sDestination . str_replace('\\', '/', str_replace($sDestination, '', $this->_sDestination) . $sFileName . '.' . $this->_sExt));
         if ($bReturn === false) {
             return false;
         }
     }
     return str_replace('\\', '/', str_replace($sDestination, '', $this->_sDestination) . $sFileName . ($bModifyFileName === true || is_array($bModifyFileName) ? '%s.' : '.') . $this->_sExt);
 }
Example #15
0
 public function update($iId, $aVals, $aEventPost = null)
 {
     if (!$this->_verify($aVals, true)) {
         return false;
     }
     if (isset($aEventPost) && isset($aEventPost['is_featured']) && $aEventPost['is_featured']) {
         $this->cache()->remove('event_featured', 'substr');
     }
     if (!isset($aVals['privacy'])) {
         $aVals['privacy'] = 0;
     }
     if (!isset($aVals['privacy_comment'])) {
         $aVals['privacy_comment'] = 0;
     }
     $oParseInput = Phpfox::getLib('parse.input');
     Phpfox::getService('ban')->checkAutomaticBan($aVals['title'] . ' ' . $aVals['description']);
     $iStartTime = Phpfox::getLib('date')->mktime($aVals['start_hour'], $aVals['start_minute'], 0, $aVals['start_month'], $aVals['start_day'], $aVals['start_year']);
     $iEndTime = Phpfox::getLib('date')->mktime($aVals['end_hour'], $aVals['end_minute'], 0, $aVals['end_month'], $aVals['end_day'], $aVals['end_year']);
     if ($iStartTime > $iEndTime) {
         $iEndTime = $iStartTime;
     }
     $aSql = array('privacy' => isset($aVals['privacy']) ? $aVals['privacy'] : '0', 'privacy_comment' => isset($aVals['privacy_comment']) ? $aVals['privacy_comment'] : '0', 'title' => $oParseInput->clean($aVals['title'], 255), 'location' => $oParseInput->clean($aVals['location'], 255), 'country_iso' => $aVals['country_iso'], 'country_child_id' => isset($aVals['country_child_id']) ? Phpfox::getService('core.country')->getValidChildId($aVals['country_iso'], (int) $aVals['country_child_id']) : 0, 'city' => empty($aVals['city']) ? null : $oParseInput->clean($aVals['city'], 255), 'postal_code' => empty($aVals['postal_code']) ? null : Phpfox::getLib('parse.input')->clean($aVals['postal_code'], 20), 'start_time' => Phpfox::getLib('date')->convertToGmt($iStartTime), 'end_time' => Phpfox::getLib('date')->convertToGmt($iEndTime), 'start_gmt_offset' => Phpfox::getLib('date')->getGmtOffset($iStartTime), 'end_gmt_offset' => Phpfox::getLib('date')->getGmtOffset($iEndTime), 'address' => empty($aVals['address']) ? null : Phpfox::getLib('parse.input')->clean($aVals['address']));
     if (Phpfox::getUserParam('event.can_add_gmap') && isset($aVals['gmap']) && is_array($aVals['gmap']) && isset($aVals['gmap']['latitude']) && isset($aVals['gmap']['longitude'])) {
         $aSql['gmap'] = serialize($aVals['gmap']);
     }
     if ($this->_bHasImage) {
         $oImage = Phpfox_Image::instance();
         $sFileName = Phpfox_File::instance()->upload('image', Phpfox::getParam('event.dir_image'), $iId);
         $iFileSizes = filesize(Phpfox::getParam('event.dir_image') . sprintf($sFileName, ''));
         $aSql['image_path'] = $sFileName;
         $aSql['server_id'] = Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID');
         /*
         $iSize = 50;			
         $oImage->createThumbnail(Phpfox::getParam('event.dir_image') . sprintf($sFileName, ''), Phpfox::getParam('event.dir_image') . sprintf($sFileName, '_' . $iSize), $iSize, $iSize);			
         $iFileSizes += filesize(Phpfox::getParam('event.dir_image') . sprintf($sFileName, '_' . $iSize));			
         
         $iSize = 120;			
         $oImage->createThumbnail(Phpfox::getParam('event.dir_image') . sprintf($sFileName, ''), Phpfox::getParam('event.dir_image') . sprintf($sFileName, '_' . $iSize), $iSize, $iSize);			
         $iFileSizes += filesize(Phpfox::getParam('event.dir_image') . sprintf($sFileName, '_' . $iSize));
         
         $iSize = 200;			
         $oImage->createThumbnail(Phpfox::getParam('event.dir_image') . sprintf($sFileName, ''), Phpfox::getParam('event.dir_image') . sprintf($sFileName, '_' . $iSize), $iSize, $iSize);			
         $iFileSizes += filesize(Phpfox::getParam('event.dir_image') . sprintf($sFileName, '_' . $iSize));
         */
         $oImage->createThumbnail(Phpfox::getParam('event.dir_image') . sprintf($sFileName, ''), Phpfox::getParam('event.dir_image') . sprintf($sFileName, ''), 600, 400);
         // Update user space usage
         Phpfox::getService('user.space')->update(Phpfox::getUserId(), 'event', $iFileSizes);
     }
     if ($sPlugin = Phpfox_Plugin::get('event.service_process_update__start')) {
         return eval($sPlugin);
     }
     $this->database()->update($this->_sTable, $aSql, 'event_id = ' . (int) $iId);
     $this->database()->update(Phpfox::getT('event_text'), array('description' => empty($aVals['description']) ? null : $oParseInput->clean($aVals['description']), 'description_parsed' => empty($aVals['description']) ? null : $oParseInput->prepare($aVals['description'])), 'event_id = ' . (int) $iId);
     $aEvent = $this->database()->select('event_id, user_id, title, module_id')->from($this->_sTable)->where('event_id = ' . (int) $iId)->execute('getSlaveRow');
     if (isset($aVals['emails']) || isset($aVals['invite'])) {
         $aInvites = $this->database()->select('invited_user_id, invited_email')->from(Phpfox::getT('event_invite'))->where('event_id = ' . (int) $iId)->execute('getRows');
         $aInvited = array();
         foreach ($aInvites as $aInvite) {
             $aInvited[empty($aInvite['invited_email']) ? 'user' : 'email'][empty($aInvite['invited_email']) ? $aInvite['invited_user_id'] : $aInvite['invited_email']] = true;
         }
     }
     if (isset($aVals['emails'])) {
         $aEmails = explode(',', $aVals['emails']);
         $aCachedEmails = array();
         foreach ($aEmails as $sEmail) {
             $sEmail = trim($sEmail);
             if (!Phpfox::getLib('mail')->checkEmail($sEmail)) {
                 continue;
             }
             if (isset($aInvited['email'][$sEmail])) {
                 continue;
             }
             $sLink = Phpfox_Url::instance()->permalink('event', $aEvent['event_id'], $aEvent['title']);
             $sMessage = Phpfox::getPhrase('event.full_name_invited_you_to_the_title', array('full_name' => Phpfox::getUserBy('full_name'), 'title' => $oParseInput->clean($aVals['title'], 255), 'link' => $sLink));
             if (!empty($aVals['personal_message'])) {
                 $sMessage .= Phpfox::getPhrase('event.full_name_added_the_following_personal_message', array('full_name' => Phpfox::getUserBy('full_name'))) . "\n";
                 $sMessage .= $aVals['personal_message'];
             }
             $oMail = Phpfox::getLib('mail');
             if (isset($aVals['invite_from']) && $aVals['invite_from'] == 1) {
                 $oMail->fromEmail(Phpfox::getUserBy('email'))->fromName(Phpfox::getUserBy('full_name'));
             }
             $bSent = $oMail->to($sEmail)->subject(array('event.full_name_invited_you_to_the_event_title', array('full_name' => Phpfox::getUserBy('full_name'), 'title' => $oParseInput->clean($aVals['title'], 255))))->message($sMessage)->send();
             if ($bSent) {
                 $this->_aInvited[] = array('email' => $sEmail);
                 $aCachedEmails[$sEmail] = true;
                 $this->database()->insert(Phpfox::getT('event_invite'), array('event_id' => $iId, 'type_id' => 1, 'user_id' => Phpfox::getUserId(), 'invited_email' => $sEmail, 'time_stamp' => PHPFOX_TIME));
             }
         }
     }
     if (isset($aVals['invite']) && is_array($aVals['invite'])) {
         $sUserIds = '';
         foreach ($aVals['invite'] as $iUserId) {
             if (!is_numeric($iUserId)) {
                 continue;
             }
             $sUserIds .= $iUserId . ',';
         }
         $sUserIds = rtrim($sUserIds, ',');
         $aUsers = $this->database()->select('user_id, email, language_id, full_name')->from(Phpfox::getT('user'))->where('user_id IN(' . $sUserIds . ')')->execute('getSlaveRows');
         foreach ($aUsers as $aUser) {
             if (isset($aCachedEmails[$aUser['email']])) {
                 continue;
             }
             if (isset($aInvited['user'][$aUser['user_id']])) {
                 continue;
             }
             $sLink = Phpfox_Url::instance()->permalink('event', $aEvent['event_id'], $aEvent['title']);
             $sMessage = Phpfox::getPhrase('event.full_name_invited_you_to_the_title', array('full_name' => Phpfox::getUserBy('full_name'), 'title' => $oParseInput->clean($aVals['title'], 255), 'link' => $sLink), false, null, $aUser['language_id']);
             if (!empty($aVals['personal_message'])) {
                 $sMessage .= Phpfox::getPhrase('event.full_name_added_the_following_personal_message', array('full_name' => Phpfox::getUserBy('full_name')), false, null, $aUser['language_id']) . ":\n" . $aVals['personal_message'];
             }
             $bSent = Phpfox::getLib('mail')->to($aUser['user_id'])->subject(array('event.full_name_invited_you_to_the_event_title', array('full_name' => Phpfox::getUserBy('full_name'), 'title' => $oParseInput->clean($aVals['title'], 255))))->message($sMessage)->notification('event.invite_to_event')->send();
             if ($bSent) {
                 $this->_aInvited[] = array('user' => $aUser['full_name']);
                 $iInviteId = $this->database()->insert(Phpfox::getT('event_invite'), array('event_id' => $iId, 'user_id' => Phpfox::getUserId(), 'invited_user_id' => $aUser['user_id'], 'time_stamp' => PHPFOX_TIME));
                 Phpfox::isModule('request') ? Phpfox::getService('request.process')->add('event_invite', $iId, $aUser['user_id']) : null;
             }
         }
     }
     $this->database()->delete(Phpfox::getT('event_category_data'), 'event_id = ' . (int) $iId);
     foreach ($this->_aCategories as $iCategoryId) {
         $this->database()->insert(Phpfox::getT('event_category_data'), array('event_id' => $iId, 'category_id' => $iCategoryId));
     }
     if (empty($aEvent['module_id'])) {
         Phpfox::isModule('feed') ? Phpfox::getService('feed.process')->update('event', $iId, $aVals['privacy'], $aVals['privacy_comment'], 0, $aEvent['user_id']) : null;
     }
     Phpfox::getService('feed.process')->clearCache('event', $iId);
     ($sPlugin = Phpfox_Plugin::get('event.service_process_update__end')) ? eval($sPlugin) : false;
     if (Phpfox::getParam('event.cache_events_per_user')) {
         $sCacheId = $this->cache()->set(array('events_by_user', $aEvent['user_id']));
         $this->cache()->remove($sCacheId);
     }
     if (Phpfox::isModule('tag') && Phpfox::getParam('tag.enable_hashtag_support')) {
         Phpfox::getService('tag.process')->update('event', $aEvent['event_id'], $aEvent['user_id'], $aVals['description'], true);
     }
     return true;
 }
Example #16
0
 public function update($iId, $aVals, $aPage)
 {
     if (!$this->_verify($aVals, true)) {
         return false;
     }
     if ($sPlugin = Phpfox_Plugin::get('pages.service_process_update_0')) {
         eval($sPlugin);
         if (isset($mReturnFromPlugin)) {
             return $mReturnFromPlugin;
         }
     }
     $aUser = $this->database()->select('user_id')->from(Phpfox::getT('user'))->where('profile_page_id = ' . (int) $iId)->execute('getSlaveRow');
     $aUpdate = array('type_id' => isset($aVals['type_id']) ? (int) $aVals['type_id'] : '0', 'category_id' => isset($aVals['category_id']) ? (int) $aVals['category_id'] : 0, 'reg_method' => isset($aVals['reg_method']) ? (int) $aVals['reg_method'] : 0, 'privacy' => isset($aVals['privacy']) ? (int) $aVals['privacy'] : 0);
     if (isset($aVals['use_timeline'])) {
         $aUpdate['use_timeline'] = (int) $aVals['use_timeline'];
     }
     /* Only store the location if the admin has set a google key or ipinfodb key. This input is not always available */
     if ((Phpfox::getParam('core.ip_infodb_api_key') != '' || Phpfox::getParam('core.google_api_key')) && isset($aVals['location'])) {
         if (isset($aVals['location']['name'])) {
             $aUpdate['location_name'] = $this->preParse()->clean($aVals['location']['name']);
         }
         if (isset($aVals['location']['latlng'])) {
             $aMatch = explode(',', $aVals['location']['latlng']);
             if (isset($aMatch[1])) {
                 $aUpdate['location_latitude'] = $aMatch[0];
                 $aUpdate['location_longitude'] = $aMatch[1];
             }
         }
     }
     if (isset($aVals['landing_page'])) {
         $aUpdate['landing_page'] = $aVals['landing_page'];
     }
     if (!empty($aVals['title'])) {
         $aUpdate['title'] = $this->preParse()->clean($aVals['title']);
     }
     if ($this->_bHasImage) {
         if (!empty($aPage['image_path'])) {
             $this->deleteImage($aPage);
         }
         $oImage = Phpfox_Image::instance();
         $sFileName = Phpfox_File::instance()->upload('image', Phpfox::getParam('pages.dir_image'), $iId);
         $iFileSizes = filesize(Phpfox::getParam('pages.dir_image') . sprintf($sFileName, ''));
         $aUpdate['image_path'] = $sFileName;
         $aUpdate['image_server_id'] = Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID');
         $iSize = 50;
         $oImage->createThumbnail(Phpfox::getParam('pages.dir_image') . sprintf($sFileName, ''), Phpfox::getParam('pages.dir_image') . sprintf($sFileName, '_' . $iSize), $iSize, $iSize, false);
         $iFileSizes += filesize(Phpfox::getParam('pages.dir_image') . sprintf($sFileName, '_' . $iSize));
         $iSize = 120;
         $oImage->createThumbnail(Phpfox::getParam('pages.dir_image') . sprintf($sFileName, ''), Phpfox::getParam('pages.dir_image') . sprintf($sFileName, '_' . $iSize), $iSize, $iSize, false);
         $iFileSizes += filesize(Phpfox::getParam('pages.dir_image') . sprintf($sFileName, '_' . $iSize));
         $iSize = 200;
         $oImage->createThumbnail(Phpfox::getParam('pages.dir_image') . sprintf($sFileName, ''), Phpfox::getParam('pages.dir_image') . sprintf($sFileName, '_' . $iSize), $iSize, $iSize, false);
         $iFileSizes += filesize(Phpfox::getParam('pages.dir_image') . sprintf($sFileName, '_' . $iSize));
         define('PHPFOX_PAGES_IS_IN_UPDATE', true);
         Phpfox::getService('user.process')->uploadImage($aUser['user_id'], true, Phpfox::getParam('pages.dir_image') . sprintf($sFileName, ''));
         // Update user space usage
         Phpfox::getService('user.space')->update(Phpfox::getUserId(), 'pages', $iFileSizes);
     }
     $this->database()->update($this->_sTable, $aUpdate, 'page_id = ' . (int) $iId);
     $this->database()->update(Phpfox::getT('pages_text'), array('text' => $this->preParse()->clean($aVals['text']), 'text_parsed' => $this->preParse()->prepare($aVals["text"])), 'page_id = ' . (int) $iId);
     if ($sPlugin = Phpfox_Plugin::get('pages.service_process_update_1')) {
         eval($sPlugin);
         if (isset($mReturnFromPlugin)) {
             return $mReturnFromPlugin;
         }
     }
     if (isset($aVals['invite']) && is_array($aVals['invite'])) {
         $aNewPage = Phpfox::getService('pages')->getForEdit($aPage['page_id']);
         $sUserIds = '';
         foreach ($aVals['invite'] as $iUserId) {
             if (!is_numeric($iUserId)) {
                 continue;
             }
             $sUserIds .= $iUserId . ',';
         }
         $sUserIds = rtrim($sUserIds, ',');
         $aUsers = $this->database()->select('user_id, email, language_id, full_name')->from(Phpfox::getT('user'))->where('user_id IN(' . $sUserIds . ')')->execute('getSlaveRows');
         $bSent = false;
         $sLink = Phpfox::getService('pages')->getUrl($aNewPage['page_id'], $aNewPage['title'], $aNewPage['vanity_url']);
         foreach ($aUsers as $aUser) {
             if (isset($aCachedEmails[$aUser['email']])) {
                 continue;
             }
             if (isset($aInvited['user'][$aUser['user_id']])) {
                 continue;
             }
             $sMessage = Phpfox::getPhrase('pages.full_name_invited_you_to_the_page_title', array('full_name' => Phpfox::getUserBy('full_name'), 'title' => $aNewPage['title']));
             $sMessage .= "\n" . Phpfox::getPhrase('pages.to_view_this_page_click_the_link_below_a_href_link_link_a', array('link' => $sLink)) . "\n";
             $bSent = Phpfox::getLib('mail')->to($aUser['user_id'])->subject(array('pages.full_name_sent_you_a_page_invitation', array('full_name' => Phpfox::getUserBy('full_name'))))->message($sMessage)->send();
             if ($bSent) {
                 $iInviteId = $this->database()->insert(Phpfox::getT('pages_invite'), array('page_id' => $iId, 'user_id' => Phpfox::getUserId(), 'invited_user_id' => $aUser['user_id'], 'time_stamp' => PHPFOX_TIME));
                 Phpfox::isModule('request') ? Phpfox::getService('request.process')->add('pages_invite', $iId, $aUser['user_id']) : null;
             }
         }
         if ($bSent == true) {
             Phpfox::addMessage(Phpfox::getPhrase('pages.invitations_sent_out'));
         }
     }
     $aUserCache = array();
     $this->database()->delete(Phpfox::getT('pages_admin'), 'page_id = ' . (int) $iId);
     $aAdmins = Phpfox_Request::instance()->getArray('admins');
     if (count($aAdmins)) {
         foreach ($aAdmins as $iAdmin) {
             if (isset($aUserCache[$iAdmin])) {
                 continue;
             }
             $aUserCache[$iAdmin] = true;
             $this->database()->insert(Phpfox::getT('pages_admin'), array('page_id' => $iId, 'user_id' => $iAdmin));
             $this->cache()->remove(array('user', 'pages_' . $iAdmin));
             $this->cache()->remove(array('pages', $iAdmin));
         }
     }
     if (isset($aVals['perms'])) {
         $this->database()->delete(Phpfox::getT('pages_perm'), 'page_id = ' . (int) $iId);
         foreach ($aVals['perms'] as $sPermId => $iPermValue) {
             $this->database()->insert(Phpfox::getT('pages_perm'), array('page_id' => (int) $iId, 'var_name' => $sPermId, 'var_value' => (int) $iPermValue));
         }
     }
     $this->database()->update(Phpfox::getT('user'), array('full_name' => Phpfox::getLib('parse.input')->clean($aVals['title'], 255)), 'profile_page_id = ' . (int) $iId);
     return true;
 }
Example #17
0
 public function attachToItem()
 {
     Phpfox::isUser(true);
     $iFileSizes = 0;
     $oAttachment = Phpfox::getService('attachment.process');
     $oFile = Phpfox_File::instance();
     $oImage = Phpfox_Image::instance();
     $aPhoto = Phpfox::getService('photo')->getPhoto($this->get('photo-id'));
     if (!isset($aPhoto['photo_id'])) {
         $this->alert(Phpfox::getPhrase('photo.unable_to_find_the_photo_you_are_looking_for'));
         return;
     }
     if ($aPhoto['user_id'] != Phpfox::getUserId()) {
         $this->alert(Phpfox::getPhrase('photo.unable_to_import_this_photo'));
         return;
     }
     $iId = $oAttachment->add(array('category' => $this->get('category'), 'file_name' => $aPhoto['file_name'], 'extension' => $aPhoto['extension'], 'is_image' => true));
     $sIds = $iId . ',';
     $sFileName = md5($iId . PHPFOX_TIME . uniqid()) . '%s.' . $aPhoto['extension'];
     $sFileToCopy = Phpfox::getParam('photo.dir_photo') . sprintf($aPhoto['original_destination'], '');
     if (!file_exists($sFileToCopy)) {
         $sFileToCopy = Phpfox::getParam('photo.dir_photo') . sprintf($aPhoto['original_destination'], '_500');
     }
     $oFile->copy($sFileToCopy, Phpfox::getParam('core.dir_attachment') . sprintf($sFileName, ''));
     $sFileSize = $aPhoto['file_size'];
     $iFileSizes += $sFileSize;
     $oAttachment->update(array('file_size' => $sFileSize, 'destination' => $sFileName, 'server_id' => Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID')), $iId);
     $sThumbnail = Phpfox::getParam('core.dir_attachment') . sprintf($sFileName, '_thumb');
     $sViewImage = Phpfox::getParam('core.dir_attachment') . sprintf($sFileName, '_view');
     $oImage->createThumbnail(Phpfox::getParam('core.dir_attachment') . sprintf($sFileName, ''), $sThumbnail, Phpfox::getParam('attachment.attachment_max_thumbnail'), Phpfox::getParam('attachment.attachment_max_thumbnail'));
     $oImage->createThumbnail(Phpfox::getParam('core.dir_attachment') . sprintf($sFileName, ''), $sViewImage, Phpfox::getParam('attachment.attachment_max_medium'), Phpfox::getParam('attachment.attachment_max_medium'));
     $iFileSizes += filesize($sThumbnail) + filesize($sThumbnail);
     Phpfox::getService('user.space')->update(Phpfox::getUserId(), 'attachment', $iFileSizes);
     /*
     ob_start();
     
     Phpfox::getBlock('attachment.list', array('sIds' => $sIds, 'bCanUseInline' => true, 'attachment_no_header' => true, 'attachment_edit' => true, 'sAttachmentInput' => $this->get('input')));
     
     $sContent = ob_get_contents();
     
     ob_clean();
     
     $this->call('var $oParent = $(\'#' . $this->get('obj-id') . '\'); $oParent.find(\'.js_attachment:first\').val($oParent.find(\'.js_attachment:first\').val() + \'' . $sIds . '\'); $oParent.find(\'.js_attachment_list:first\').show(); $oParent.find(\'.js_attachment_list_holder:first\').prepend(\'' . str_replace("'", "\'", str_replace(array("\n", "\t", "\r"), '', $sContent)) . '\'); $Core.loadInit();');
     */
     $aAttachment = Phpfox_Database::instance()->select('*')->from(Phpfox::getT('attachment'))->where('attachment_id = ' . (int) $iId)->execute('getSlaveRow');
     $sImagePath = Phpfox::getLib('image.helper')->display(array('server_id' => $aAttachment['server_id'], 'path' => 'core.url_attachment', 'file' => $aAttachment['destination'], 'suffix' => '_view', 'max_width' => 'attachment.attachment_max_medium', 'max_height' => 'attachment.attachment_max_medium', 'return_url' => true));
     $this->call('Editor.insert({is_image: true, name: \'\', id: \'' . $iId . ':view\', type: \'image\', path: \'' . $sImagePath . '\'});');
     if ($this->get('attachment-inline')) {
         $this->call('$Core.clearInlineBox();');
     } else {
         $this->call('tb_remove();');
     }
 }
Example #18
0
 public function update($iId, $aVals)
 {
     if (!$this->_verify($aVals)) {
         return false;
     }
     $oParseInput = Phpfox::getLib('parse.input');
     Phpfox::getService('ban')->checkAutomaticBan($aVals['title'] . ' ' . $aVals['description']);
     if (empty($aVals['privacy'])) {
         $aVals['privacy'] = 0;
     }
     if (empty($aVals['privacy_comment'])) {
         $aVals['privacy_comment'] = 0;
     }
     $aSql = array('privacy' => isset($aVals['privacy']) ? $aVals['privacy'] : '0', 'privacy_comment' => isset($aVals['privacy_comment']) ? $aVals['privacy_comment'] : '0', 'title' => $oParseInput->clean($aVals['title'], 255), 'currency_id' => $aVals['currency_id'], 'price' => $this->_price($aVals['price']), 'country_iso' => $aVals['country_iso'], 'country_child_id' => isset($aVals['country_child_id']) ? (int) $aVals['country_child_id'] : 0, 'postal_code' => empty($aVals['postal_code']) ? null : Phpfox::getLib('parse.input')->clean($aVals['postal_code'], 20), 'city' => empty($aVals['city']) ? null : $oParseInput->clean($aVals['city'], 255), 'is_sell' => isset($aVals['is_sell']) ? (int) $aVals['is_sell'] : 0, 'auto_sell' => isset($aVals['auto_sell']) ? (int) $aVals['auto_sell'] : 0, 'mini_description' => empty($aVals['mini_description']) ? null : $oParseInput->clean($aVals['mini_description'], 255));
     if (isset($aVals['view_id']) && ($aVals['view_id'] == '0' || $aVals['view_id'] == '2')) {
         $aSql['view_id'] = $aVals['view_id'];
     }
     $this->database()->update($this->_sTable, $aSql, 'listing_id = ' . (int) $iId);
     if (Phpfox::isModule('input')) {
         $bAdded = Phpfox::getService('input.process')->addValue(array('item_id' => $iId, 'module' => 'marketplace', 'action' => 'add-listing', 'aVals' => $aVals));
     }
     $this->database()->update(Phpfox::getT('marketplace_text'), array('description' => empty($aVals['description']) ? null : $oParseInput->clean($aVals['description']), 'description_parsed' => empty($aVals['description']) ? null : $oParseInput->prepare($aVals['description'])), 'listing_id = ' . (int) $iId);
     ($sPlugin = Phpfox_Plugin::get('marketplace.service_process_update')) ? eval($sPlugin) : false;
     $this->database()->delete(Phpfox::getT('marketplace_category_data'), 'listing_id = ' . (int) $iId);
     foreach ($this->_aCategories as $iCategoryId) {
         $this->database()->insert(Phpfox::getT('marketplace_category_data'), array('listing_id' => $iId, 'category_id' => $iCategoryId));
     }
     $aListing = $this->database()->select('*')->from($this->_sTable)->where('listing_id = ' . (int) $iId)->execute('getSlaveRow');
     if ($this->_bHasImage) {
         $oImage = Phpfox_Image::instance();
         $oFile = Phpfox_File::instance();
         $aSizes = array(50, 120, 200, 400);
         $iFileSizes = 0;
         foreach ($_FILES['image']['error'] as $iKey => $sError) {
             if ($sError == UPLOAD_ERR_OK) {
                 if ($aImage = $oFile->load('image[' . $iKey . ']', array('jpg', 'gif', 'png'), Phpfox::getUserParam('marketplace.max_upload_size_listing') === 0 ? null : Phpfox::getUserParam('marketplace.max_upload_size_listing') / 1024)) {
                     $sFileName = Phpfox_File::instance()->upload('image[' . $iKey . ']', Phpfox::getParam('marketplace.dir_image'), $iId);
                     $iFileSizes += filesize(Phpfox::getParam('marketplace.dir_image') . sprintf($sFileName, ''));
                     $this->database()->insert(Phpfox::getT('marketplace_image'), array('listing_id' => $iId, 'image_path' => $sFileName, 'server_id' => Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID')));
                     foreach ($aSizes as $iSize) {
                         $oImage->createThumbnail(Phpfox::getParam('marketplace.dir_image') . sprintf($sFileName, ''), Phpfox::getParam('marketplace.dir_image') . sprintf($sFileName, '_' . $iSize), $iSize, $iSize);
                         $oImage->createThumbnail(Phpfox::getParam('marketplace.dir_image') . sprintf($sFileName, ''), Phpfox::getParam('marketplace.dir_image') . sprintf($sFileName, '_' . $iSize . '_square'), $iSize, $iSize, false);
                         $iFileSizes += filesize(Phpfox::getParam('marketplace.dir_image') . sprintf($sFileName, '_' . $iSize));
                     }
                 }
             }
         }
         if ($iFileSizes === 0) {
             return false;
         }
         $this->database()->update($this->_sTable, array('image_path' => $sFileName, 'server_id' => Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID')), 'listing_id = ' . $iId);
         ($sPlugin = Phpfox_Plugin::get('marketplace.service_process_update__1')) ? eval($sPlugin) : false;
         // Update user space usage
         Phpfox::getService('user.space')->update(Phpfox::getUserId(), 'marketplace', $iFileSizes);
     }
     if (isset($aVals['emails']) || isset($aVals['invite'])) {
         $aInvites = $this->database()->select('invited_user_id, invited_email')->from(Phpfox::getT('marketplace_invite'))->where('listing_id = ' . (int) $iId)->execute('getRows');
         $aInvited = array();
         foreach ($aInvites as $aInvite) {
             $aInvited[empty($aInvite['invited_email']) ? 'user' : 'email'][empty($aInvite['invited_email']) ? $aInvite['invited_user_id'] : $aInvite['invited_email']] = true;
         }
     }
     if (isset($aVals['emails'])) {
         $aEmails = explode(',', $aVals['emails']);
         $aCachedEmails = array();
         foreach ($aEmails as $sEmail) {
             $sEmail = trim($sEmail);
             if (!Phpfox::getLib('mail')->checkEmail($sEmail)) {
                 continue;
             }
             if (isset($aInvited['email'][$sEmail])) {
                 continue;
             }
             $sLink = Phpfox_Url::instance()->permalink('marketplace', $aListing['listing_id'], $aListing['title']);
             $sMessage = Phpfox::getPhrase('marketplace.full_name_invited_you_to_view_the_marketplace_listing_title', array('full_name' => Phpfox::getUserBy('full_name'), 'title' => $oParseInput->clean($aVals['title'], 255), 'link' => $sLink));
             if (!empty($aVals['personal_message'])) {
                 $sMessage .= "\n\n" . Phpfox::getPhrase('marketplace.full_name_added_the_following_personal_message', array('full_name' => Phpfox::getUserBy('full_name'))) . ":\n";
                 $sMessage .= $aVals['personal_message'];
             }
             $oMail = Phpfox::getLib('mail');
             if (isset($aVals['invite_from']) && $aVals['invite_from'] == 1) {
                 $oMail->fromEmail(Phpfox::getUserBy('email'))->fromName(Phpfox::getUserBy('full_name'));
             }
             $bSent = $oMail->to($sEmail)->subject(array('marketplace.full_name_invited_you_to_view_the_listing_title', array('full_name' => Phpfox::getUserBy('full_name'), 'title' => $oParseInput->clean($aVals['title'], 255))))->message($sMessage)->send();
             if ($bSent) {
                 $this->_aInvited[] = array('email' => $sEmail);
                 $aCachedEmails[$sEmail] = true;
                 $this->database()->insert(Phpfox::getT('marketplace_invite'), array('listing_id' => $iId, 'type_id' => 1, 'user_id' => Phpfox::getUserId(), 'invited_email' => $sEmail, 'time_stamp' => PHPFOX_TIME));
             }
         }
     }
     if (isset($aVals['invite']) && is_array($aVals['invite'])) {
         $sUserIds = '';
         foreach ($aVals['invite'] as $iUserId) {
             if (!is_numeric($iUserId)) {
                 continue;
             }
             $sUserIds .= $iUserId . ',';
         }
         $sUserIds = rtrim($sUserIds, ',');
         $aUsers = $this->database()->select('user_id, email, language_id, full_name')->from(Phpfox::getT('user'))->where('user_id IN(' . $sUserIds . ')')->execute('getSlaveRows');
         foreach ($aUsers as $aUser) {
             if (isset($aCachedEmails[$aUser['email']])) {
                 continue;
             }
             if (isset($aInvited['user'][$aUser['user_id']])) {
                 continue;
             }
             $sLink = Phpfox_Url::instance()->permalink('marketplace', $aListing['listing_id'], $aListing['title']);
             $sMessage = Phpfox::getPhrase('marketplace.full_name_invited_you_to_view_the_marketplace_listing_title', array('full_name' => Phpfox::getUserBy('full_name'), 'title' => $oParseInput->clean($aVals['title'], 255), 'link' => $sLink), false, null, $aUser['language_id']);
             if (!empty($aVals['personal_message'])) {
                 $sMessage .= "\n\n" . Phpfox::getPhrase('marketplace.full_name_added_the_following_personal_message', array('full_name' => Phpfox::getUserBy('full_name')), false, null, $aUser['language_id']);
                 $sMessage .= $aVals['personal_message'];
             }
             $bSent = Phpfox::getLib('mail')->to($aUser['user_id'])->subject(array('marketplace.full_name_invited_you_to_view_the_listing_title', array('full_name' => Phpfox::getUserBy('full_name'), 'title' => $oParseInput->clean($aVals['title'], 255))))->message($sMessage)->notification('marketplace.new_invite')->send();
             if ($bSent) {
                 $this->_aInvited[] = array('user' => $aUser['full_name']);
                 $this->database()->insert(Phpfox::getT('marketplace_invite'), array('listing_id' => $iId, 'user_id' => Phpfox::getUserId(), 'invited_user_id' => $aUser['user_id'], 'time_stamp' => PHPFOX_TIME));
                 Phpfox::isModule('request') ? Phpfox::getService('request.process')->add('marketplace_invite', $iId, $aUser['user_id']) : null;
             }
         }
     }
     Phpfox::isModule('feed') ? Phpfox::getService('feed.process')->update('marketplace', $iId, $aVals['privacy'], $aVals['privacy_comment'], 0, $aListing['user_id']) : null;
     if (Phpfox::isModule('privacy')) {
         if ($aVals['privacy'] == '4') {
             Phpfox::getService('privacy.process')->update('marketplace', $iId, isset($aVals['privacy_list']) ? $aVals['privacy_list'] : array());
         } else {
             Phpfox::getService('privacy.process')->delete('marketplace', $iId);
         }
     }
     if (Phpfox::isModule('tag') && Phpfox::getParam('tag.enable_hashtag_support')) {
         Phpfox::getService('tag.process')->update('marketplace', $iId, Phpfox::getUserId(), $aVals['description'], true);
     }
     return true;
 }
Example #19
0
 public function getForProfileView($iProfileId, $bForceCreation = false)
 {
     $aAlbum = $this->getForView($iProfileId, true);
     if (!isset($aAlbum['album_id']) || $bForceCreation === true) {
         $aUser = $this->database()->select(Phpfox::getUserField())->from(Phpfox::getT('user'), 'u')->where('u.user_id = ' . (int) $iProfileId)->execute('getSlaveRow');
         if (!isset($aUser['user_id'])) {
             return false;
         }
         if (!isset($aAlbum['album_id'])) {
             $iId = $this->database()->insert(Phpfox::getT('photo_album'), array('privacy' => '0', 'privacy_comment' => '0', 'user_id' => $aUser['user_id'], 'name' => "{phrase var='photo.profile_pictures'}", 'time_stamp' => PHPFOX_TIME, 'profile_id' => $aUser['user_id']));
             $this->database()->insert(Phpfox::getT('photo_album_info'), array('album_id' => $iId));
         } else {
             $iId = $aAlbum['album_id'];
         }
         if (!empty($aUser['user_image']) && file_exists(Phpfox::getParam('core.dir_user') . sprintf($aUser['user_image'], ''))) {
             $aImage = getimagesize(Phpfox::getParam('core.dir_user') . sprintf($aUser['user_image'], ''));
             $iFileSize = filesize(Phpfox::getParam('core.dir_user') . sprintf($aUser['user_image'], ''));
             $aInsert = array('album_id' => $iId, 'title' => date('F j, Y'), 'user_id' => $aUser['user_id'], 'server_id' => $aUser['user_server_id'], 'time_stamp' => PHPFOX_TIME, 'is_cover' => '1', 'is_profile_photo' => '1');
             if (defined('PHPFOX_FORCE_PHOTO_VERIFY_EMAIL')) {
                 $aInsert['view_id'] = 3;
             }
             $this->database()->update(Phpfox::getT('photo'), array('is_cover' => '0'), 'album_id = ' . (int) $iId);
             $iPhotoInsert = $this->database()->insert(Phpfox::getT('photo'), $aInsert);
             $sFilename = strtolower(sprintf($aUser['user_image'], ''));
             $aExts = preg_split("/[\\/\\.]/", sprintf($aUser['user_image'], ''));
             $iCnt = count($aExts) - 1;
             $sExt = strtolower($aExts[$iCnt]);
             $this->database()->insert(Phpfox::getT('photo_info'), array('photo_id' => $iPhotoInsert, 'file_name' => sprintf($aUser['user_image'], ''), 'mime_type' => $aImage['mime'], 'extension' => $sExt, 'width' => $aImage[0], 'height' => $aImage[1], 'file_size' => $iFileSize));
             $sFileName = md5($iPhotoInsert) . '%s.' . $sExt;
             $this->database()->update(Phpfox::getT('photo'), array('destination' => $sFileName), 'photo_id = ' . (int) $iPhotoInsert);
             copy(Phpfox::getParam('core.dir_user') . sprintf($aUser['user_image'], ''), Phpfox::getParam('photo.dir_photo') . sprintf($sFileName, ''));
             $oImage = Phpfox_Image::instance();
             foreach (Phpfox::getParam('photo.photo_pic_sizes') as $iSize) {
                 // Create the thumbnail
                 if ($oImage->createThumbnail(Phpfox::getParam('photo.dir_photo') . sprintf($sFileName, ''), Phpfox::getParam('photo.dir_photo') . sprintf($sFileName, '_' . $iSize), $iSize, $iSize, true, Phpfox::getParam('photo.enabled_watermark_on_photos') && Phpfox::getParam('core.watermark_option') != 'none' ? Phpfox::getParam('core.watermark_option') == 'image' ? 'force_skip' : true : false) === false) {
                     continue;
                 }
                 if (Phpfox::getParam('photo.enabled_watermark_on_photos')) {
                     $oImage->addMark(Phpfox::getParam('photo.dir_photo') . sprintf($sFileName, '_' . $iSize));
                 }
             }
             if (Phpfox::getParam('photo.enabled_watermark_on_photos')) {
                 $oImage->addMark(Phpfox::getParam('photo.dir_photo') . sprintf($sFileName, ''));
             }
             Phpfox::getService('user.activity')->update($aUser['user_id'], 'photo');
         }
         $aAlbum = $this->getForView($iProfileId, true);
     }
     if ($bForceCreation) {
         $aAlbum['photo_id'] = $iPhotoInsert;
     }
     return $aAlbum;
 }
Example #20
0
         }
         if (!defined('PHPFOX_IS_FB_USER')) {
             define('PHPFOX_IS_FB_USER', true);
         }
         $iUserId = Phpfox::getService('user.process')->add($aVals);
         if ($iUserId === false) {
             Phpfox_Url::instance()->send('facebook.account', array('type' => 'no-account', 'error' => serialize(Phpfox_Error::get())));
         } else {
             Phpfox::getService('facebook.process')->addUser($iUserId, $aUserInfo['id']);
             $sImage = 'https://graph.facebook.com/me/picture?type=large&access_token=' . Phpfox::getService('facebook')->getToken();
             Phpfox_File::instance()->writeToCache('fb_' . $iUserId . '_' . md5($sImage), file_get_contents($sImage));
             $sNewImage = 'fb_' . $iUserId . '_' . md5($sImage) . '%s.jpg';
             copy(PHPFOX_DIR_CACHE . 'fb_' . $iUserId . '_' . md5($sImage), Phpfox::getParam('core.dir_user') . sprintf($sNewImage, ''));
             foreach (Phpfox::getParam('user.user_pic_sizes') as $iSize) {
                 Phpfox_Image::instance()->createThumbnail(Phpfox::getParam('core.dir_user') . sprintf($sNewImage, ''), Phpfox::getParam('core.dir_user') . sprintf($sNewImage, '_' . $iSize), $iSize, $iSize);
                 Phpfox_Image::instance()->createThumbnail(Phpfox::getParam('core.dir_user') . sprintf($sNewImage, ''), Phpfox::getParam('core.dir_user') . sprintf($sNewImage, '_' . $iSize . '_square'), $iSize, $iSize, false);
             }
             unlink(PHPFOX_DIR_CACHE . 'fb_' . $iUserId . '_' . md5($sImage));
             $iServerId = 0;
             if (Phpfox::getParam('core.allow_cdn')) {
                 $iServerId = Phpfox::getLib('cdn')->getServerId();
             }
             Phpfox_Database::instance()->update(Phpfox::getT('user'), array('user_image' => $sNewImage, 'server_id' => $iServerId), 'user_id = ' . (int) $iUserId);
             if (Phpfox::getService('user.auth')->login($aVals['user_name'], null, false, 'user_name', true)) {
                 Phpfox_Url::instance()->send('');
             } else {
                 Phpfox_Url::instance()->send('facebook.account', array('type' => 'no-login'));
             }
         }
     }
 }
Example #21
0
 public function cropPhoto()
 {
     $aPostVals = $this->get('val');
     if (empty($aPostVals['w']) && !isset($aPostVals['skip_croping'])) {
         $this->show('#js_photo_preview_ajax')->html('#js_photo_preview_ajax', '');
         return Phpfox_Error::set(Phpfox::getPhrase('photo.select_an_area_on_your_photo_to_crop'));
     }
     if ($this->get('in_process')) {
         $oImage = Phpfox_Image::instance();
         $sFileName = $this->get('in_process');
         $aImages = array();
         if ($sPhotos = $this->get('photos')) {
             $aImages = unserialize(base64_decode(urldecode($this->get('photos'))));
         }
         $iNotCompleted = 0;
         foreach (Phpfox::getParam('user.user_pic_sizes') as $iSize) {
             if (isset($aImages[sprintf($sFileName, '_' . $iSize)])) {
                 continue;
             }
             if (Phpfox::getParam('core.keep_non_square_images')) {
                 $oImage->createThumbnail(Phpfox::getParam('core.dir_user') . sprintf($sFileName, ''), Phpfox::getParam('core.dir_user') . sprintf($sFileName, '_' . $iSize), $iSize, $iSize);
             }
             $oImage->createThumbnail(Phpfox::getParam('core.dir_user') . sprintf($sFileName, ''), Phpfox::getParam('core.dir_user') . sprintf($sFileName, '_' . $iSize . '_square'), $iSize, $iSize, false);
             $aImages[sprintf($sFileName, '_' . $iSize)] = true;
             $iNotCompleted++;
             $this->call('p(\'Processing photo: ' . sprintf($sFileName, '_' . $iSize) . '\');');
             break;
         }
         $sValues = '';
         foreach ($this->get('val') as $sKey => $mValue) {
             $sValues .= '&val[' . $sKey . ']=' . urlencode($mValue);
         }
         if ($iNotCompleted) {
             $this->call('$.ajaxCall(\'user.cropPhoto\', \'js_disable_ajax_restart=true&photos=' . urlencode(base64_encode(serialize($aImages))) . '&in_process=' . $this->get('in_process') . '&file=' . $this->get('in_process') . '' . $sValues . '\');');
         } else {
             $oFile = Phpfox_File::instance();
             $iServerId = Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID');
             $this->call('p(\'Completed resizing photos.\');');
             if (Phpfox::getUserBy('user_image') != '') {
                 if (file_exists(Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), ''))) {
                     $oFile->unlink(Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), ''));
                     foreach (Phpfox::getParam('user.user_pic_sizes') as $iSize) {
                         if (file_exists(Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), '_' . $iSize))) {
                             $oFile->unlink(Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), '_' . $iSize));
                         }
                         if (file_exists(Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), '_' . $iSize . '_square'))) {
                             $oFile->unlink(Phpfox::getParam('core.dir_user') . sprintf(Phpfox::getUserBy('user_image'), '_' . $iSize . '_square'));
                         }
                     }
                 }
             }
             $sFileName = $this->get('file');
             Phpfox_Database::instance()->update(Phpfox::getT('user'), array('user_image' => $sFileName, 'server_id' => $iServerId), 'user_id = ' . Phpfox::getUserId());
             Phpfox::isModule('feed') ? Phpfox::getService('feed.process')->delete('user_photo', Phpfox::getUserId()) : null;
             Phpfox::isModule('feed') ? Phpfox::getService('feed.process')->add('user_photo', Phpfox::getUserId(), serialize(array('destination' => $sFileName, 'server_id' => $iServerId))) : null;
             $this->call('$.ajaxCall(\'user.cropPhoto\', \'crop=true&js_disable_ajax_restart=true' . $sValues . '\');');
             if (Phpfox::isModule('photo')) {
                 Phpfox::getService('photo.album')->getForProfileView(Phpfox::getUserId(), true);
             }
         }
         return;
     }
     $aVals = $this->get('val');
     if (isset($aVals['skip_croping']) || !isset($aVals['skip_croping'])) {
         $this->call('p(\'Cropping photo.\');');
         if (Phpfox::getService('user.process')->cropPhoto($this->get('val'))) {
             /*
             				if ($this->get('crop'))
             				{
             * 
             */
             Phpfox::addMessage(Phpfox::getPhrase('user.profile_photo_successfully_updated'));
             Phpfox::setCookie('recache_image', 'yes', PHPFOX_TIME + 600);
             $this->call('window.location.href = \'' . Phpfox_Url::instance()->makeUrl('profile') . '\';');
             /*
             				}
             				else 
             				{
             					$this->show('#js_photo_preview_ajax')->html('#js_photo_preview_ajax', '<span class="valid_message">' . Phpfox::getPhrase('user.done') . '</span>', '.fadeOut(5000)');
             					$sImageAvatar = Phpfox::getLib('image.helper')->display(array(
             							'server_id' => Phpfox::getUserBy('server_id'),
             							'title' => Phpfox::getUserBy('full_name'),
             							'path' => 'core.url_user',
             							'file' => Phpfox::getUserBy('user_image'),
             							'suffix' => '_75_square',
             							'max_width' => 75,
             							'max_height' => 75,
             							'no_default' => true,
             							'time_stamp' => true,
             							'class' => 'border'		
             						)
             					);
             					$this->html('#js_user_avatar', $sImageAvatar);	
             				}			
             * 
             */
         } else {
             $this->show('#js_photo_preview_ajax')->html('#js_photo_preview_ajax', '');
         }
     }
 }
Example #22
0
 /**
  * Adds a gift
  * @param array $aVals
  * @return bool
  * @todo more checks on the incoming values before insert
  */
 public function addGift($aVals)
 {
     $iSize = 120;
     $oFile = Phpfox_File::instance();
     $mLoaded = null;
     $oImage = Phpfox_Image::instance();
     $bIsEdit = isset($aVals['egift_id']) && $aVals['egift_id'] > 0;
     $aVals['category'] = isset($aVals['category']) ? (int) $aVals['category'] : 0;
     $aSQL = array('category_id' => (int) $aVals['category'], 'user_id' => Phpfox::getUserId(), 'time_stamp' => PHPFOX_TIME, 'title' => Phpfox::getLib('parse.input')->clean($aVals['title']), 'price' => serialize($aVals['currency']));
     if (isset($_FILES['file']['name']) && !empty($_FILES['file']['name'])) {
         if (!$oFile->load('file', array('jpg', 'gif', 'png'))) {
             return Phpfox_Error::set('Could not load file');
         }
         $aSQL['file_path'] = $oFile->upload('file', Phpfox::getParam('egift.dir_egift'), '');
         if ($aSQL['file_path'] == false) {
             return Phpfox_Error::set('Could not upload files');
         }
         $oImage->createThumbnail(Phpfox::getParam('egift.dir_egift') . sprintf($aSQL['file_path'], ''), Phpfox::getParam('egift.dir_egift') . sprintf($aSQL['file_path'], '_' . $iSize), $iSize, $iSize);
         $oImage->createThumbnail(Phpfox::getParam('egift.dir_egift') . sprintf($aSQL['file_path'], ''), Phpfox::getParam('egift.dir_egift') . sprintf($aSQL['file_path'], '_75_square'), 75, 75, false);
     }
     if ($bIsEdit) {
         /* Make sure we delete the old image */
         if (isset($aSQL['file_path'])) {
             $sOldFile = $this->database()->select('file_path')->from(Phpfox::getT('egift'))->where('egift_id = ' . (int) $aVals['egift_id'])->execute('getSlaveField');
             foreach (Phpfox::getService('egift')->_aSizes as $iSize) {
                 if (empty($sOldFile)) {
                     continue;
                 }
                 if (file_exists(Phpfox::getParam('egift.dir_egift') . sprintf($sOldFile, $iSize))) {
                     $oFile->unlink(Phpfox::getParam('egift.dir_egift') . sprintf($sOldFile, $iSize));
                 }
             }
             if (!empty($sOldFile) && file_exists(Phpfox::getParam('egift.dir_egift') . sprintf($sOldFile, ''))) {
                 $oFile->unlink(Phpfox::getParam('egift.dir_egift') . sprintf($sOldFile, ''));
             }
         }
         $this->database()->update(Phpfox::getT('egift'), $aSQL, 'egift_id = ' . (int) $aVals['egift_id']);
     } else {
         $this->database()->insert(Phpfox::getT('egift'), $aSQL);
     }
     $this->cache()->remove('egift', 'substr');
     return true;
 }
Example #23
0
 /**
  *	Adds a new Quiz
  * @param array $aVals
  * @param int $iUser
  * @return boolean
  */
 public function add(&$aVals, $iUser)
 {
     // case where user had JS disabled
     if (!isset($aVals['q'])) {
         return false;
     }
     /* check for banned words */
     foreach ($aVals['q'] as $aQuestions) {
         Phpfox::getService('ban')->checkAutomaticBan($aQuestions['question']);
         foreach ($aQuestions['answers'] as $aAnswer) {
             Phpfox::getService('ban')->checkAutomaticBan($aAnswer['answer']);
         }
     }
     Phpfox::getService('ban')->checkAutomaticBan($aVals['title'] . ' ' . $aVals['description']);
     if (empty($aVals['privacy'])) {
         $aVals['privacy'] = 0;
     }
     if (empty($aVals['privacy_comment'])) {
         $aVals['privacy_comment'] = 0;
     }
     // insert to the quiz table:
     $iQuizId = $this->database()->insert($this->_sTable, array('view_id' => $aVals['view_id'] = Phpfox::getUserParam('quiz.new_quizzes_need_moderation') ? 1 : 0, 'privacy' => isset($aVals['privacy']) ? $aVals['privacy'] : '0', 'privacy_comment' => isset($aVals['privacy_comment']) ? $aVals['privacy_comment'] : '0', 'user_id' => (int) $iUser, 'title' => Phpfox::getLib('parse.input')->clean($aVals['title']), 'description' => Phpfox::getLib('parse.input')->clean($aVals['description'], 255), 'time_stamp' => PHPFOX_TIME));
     // now we insert the questions and the answers
     foreach ($aVals['q'] as $aQuestions) {
         // first we need to insert the question to get its ID
         $iQuestionId = $this->database()->insert(Phpfox::getT('quiz_question'), array('quiz_id' => $iQuizId, 'question' => Phpfox::getLib('parse.input')->clean($aQuestions['question'])));
         foreach ($aQuestions['answers'] as $aAnswer) {
             $this->database()->insert(Phpfox::getT('quiz_answer'), array('question_id' => $iQuestionId, 'answer' => Phpfox::getLib('parse.input')->clean($aAnswer['answer']), 'is_correct' => (int) $aAnswer['is_correct']));
         }
     }
     // Picture upload
     if (Phpfox::getUserParam('quiz.can_upload_picture') && isset($_FILES['image']['name']) && $_FILES['image']['name'] != '') {
         $oFile = Phpfox_File::instance();
         $oImage = Phpfox_Image::instance();
         $aImage = $oFile->load('image', array('jpg', 'gif', 'png'));
         if ($aImage !== false) {
             $sFileName = $oFile->upload('image', Phpfox::getParam('quiz.dir_image'), $iQuizId);
             // update the poll
             $this->database()->update($this->_sTable, array('image_path' => $sFileName, 'server_id' => Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID')), 'quiz_id = ' . $iQuizId);
             // now the thumbnails
             $iSize = Phpfox::getParam('quiz.quiz_max_image_pic_size');
             $oImage->createThumbnail(Phpfox::getParam('quiz.dir_image') . sprintf($sFileName, ''), Phpfox::getParam('quiz.dir_image') . sprintf($sFileName, '_' . $iSize), $iSize, $iSize);
             // Update user space usage
             Phpfox::getService('user.space')->update(Phpfox::getUserId(), 'quiz', filesize(Phpfox::getParam('quiz.dir_image') . sprintf($sFileName, '')) + filesize(Phpfox::getParam('quiz.dir_image') . sprintf($sFileName, '_' . $iSize)));
         }
     }
     if (!Phpfox::getUserParam('quiz.new_quizzes_need_moderation')) {
         if (Phpfox::isModule('feed')) {
             Phpfox::isModule('feed') ? Phpfox::getService('feed.process')->add('quiz', $iQuizId, $aVals['privacy'], isset($aVals['privacy_comment']) ? (int) $aVals['privacy_comment'] : 0) : null;
         }
         // Update user activity
         Phpfox::getService('user.activity')->update(Phpfox::getUserId(), 'quiz');
     }
     if ($aVals['privacy'] == '4') {
         Phpfox::getService('privacy.process')->add('quiz', $iQuizId, isset($aVals['privacy_list']) ? $aVals['privacy_list'] : array());
     }
     // Plugin call
     if ($sPlugin = Phpfox_Plugin::get('quiz.service_process_add__end')) {
         eval($sPlugin);
     }
     return $iQuizId;
 }
Example #24
0
 public function updateCounter($iId, $iPage, $iPageLimit)
 {
     @ini_set('memory_limit', '100M');
     $iCnt = $this->database()->select('COUNT(*)')->from(Phpfox::getT('user'))->where($this->database()->isNotNull('user_image'))->execute('getSlaveField');
     $aRows = $this->database()->select('user_id, user_image')->from(Phpfox::getT('user'))->where($this->database()->isNotNull('user_image'))->limit($iPage, $iPageLimit, $iCnt)->execute('getSlaveRows');
     foreach ($aRows as $aRow) {
         if (preg_match("/\\{file\\/pic\\/(.*)\\/(.*)\\.jpg\\}/i", $aRow['user_image'], $aMatches)) {
             $sPath = PHPFOX_DIR;
             $sImagePath = str_replace(array('{', '}'), '', $aRow['user_image']);
         } else {
             $sPath = Phpfox::getParam('core.dir_user');
             $sImagePath = $aRow['user_image'];
         }
         if (file_exists($sPath . sprintf($sImagePath, ''))) {
             foreach (Phpfox::getParam('user.user_pic_sizes') as $iSize) {
                 if (!file_exists($sPath . sprintf($sImagePath, '_' . $iSize))) {
                     Phpfox_Image::instance()->createThumbnail($sPath . sprintf($sImagePath, ''), $sPath . sprintf($sImagePath, '_' . $iSize), $iSize, $iSize);
                 }
                 if (!file_exists($sPath . sprintf($sImagePath, '_' . $iSize . '_square'))) {
                     Phpfox_Image::instance()->createThumbnail($sPath . sprintf($sImagePath, ''), $sPath . sprintf($sImagePath, '_' . $iSize . '_square'), $iSize, $iSize, true);
                 }
             }
         } else {
         }
     }
     return $iCnt;
 }
Example #25
0
 /**
  * Controller
  */
 public function process()
 {
     // We only allow users the ability to upload images.
     if (!Phpfox::isUser()) {
         exit;
     }
     if (isset($_REQUEST['picup'])) {
         $_FILES['Filedata'] = $_FILES['image'];
         unset($_FILES['image']);
     }
     if (isset($_FILES['Filedata']) && !isset($_FILES['image'])) {
         $_FILES['image'] = array();
         //$_FILES['Filedata'];
         $_FILES['image']['error']['image'] = UPLOAD_ERR_OK;
         $_FILES['image']['name']['image'] = $_FILES['Filedata']['name'];
         $_FILES['image']['type']['image'] = $_FILES['Filedata']['type'];
         $_FILES['image']['tmp_name']['image'] = $_FILES['Filedata']['tmp_name'];
         $_FILES['image']['size']['image'] = $_FILES['Filedata']['size'];
     }
     $fn = isset($_SERVER['HTTP_X_FILENAME']) ? $_SERVER['HTTP_X_FILENAME'] : false;
     if ($fn) {
         define('PHPFOX_HTML5_PHOTO_UPLOAD', true);
         if (isset($_FILES['ajax_upload'])) {
             $_FILES['image'] = [];
             // $_FILES['image'][] = $_FILES['ajax_upload'];
             foreach ($_FILES['ajax_upload'] as $key => $value) {
                 $_FILES['image'][$key][0] = $value;
             }
         } else {
             $sHTML5TempFile = PHPFOX_DIR_CACHE . 'image_' . md5(PHPFOX_DIR_CACHE . $fn . uniqid());
             file_put_contents($sHTML5TempFile, file_get_contents('php://input'));
             $_FILES['image'] = array('name' => array($fn), 'type' => array('image/jpeg'), 'tmp_name' => array($sHTML5TempFile), 'error' => array(0), 'size' => array(filesize($sHTML5TempFile)));
         }
     }
     // If no images were uploaded lets get out of here.
     if (!isset($_FILES['image'])) {
         exit;
     }
     // Make sure the user group is actually allowed to upload an image
     if (!Phpfox::getUserParam('photo.can_upload_photos')) {
         exit;
     }
     if (($iFlood = Phpfox::getUserParam('photo.flood_control_photos')) !== 0) {
         $aFlood = array('action' => 'last_post', 'params' => array('field' => 'time_stamp', 'table' => Phpfox::getT('photo'), 'condition' => 'user_id = ' . Phpfox::getUserId(), 'time_stamp' => $iFlood * 60));
         // actually check if flooding
         if (Phpfox::getLib('spam')->check($aFlood)) {
             Phpfox_Error::set(Phpfox::getPhrase('photo.uploading_photos_a_little_too_soon') . ' ' . Phpfox::getLib('spam')->getWaitTime());
         }
         if (!Phpfox_Error::isPassed()) {
             // Output JavaScript
             echo '<script type="text/javascript">';
             if (!isset($bIsInline)) {
                 echo 'window.parent.document.getElementById(\'js_progress_cache_holder\').style.display = \'none\';';
                 echo 'window.parent.document.getElementById(\'js_photo_form_holder\').style.display = \'block\';';
                 echo 'window.parent.document.getElementById(\'js_upload_error_message\').innerHTML = \'<div class="error_message">' . implode('', Phpfox_Error::get()) . '</div>\';';
             } else {
                 if (isset($aVals['is_cover_photo'])) {
                     echo 'window.parent.$(\'#js_cover_photo_iframe_loader_error\').html(\'<div class="error_message">' . implode('', Phpfox_Error::get()) . '</div>\').show();';
                 } else {
                     echo 'window.parent.$Core.resetActivityFeedError(\'' . implode('', Phpfox_Error::get()) . '\');';
                 }
             }
             echo '</script>';
             exit;
         }
     }
     $oFile = Phpfox_File::instance();
     $oImage = Phpfox_Image::instance();
     $aVals = $this->request()->get('val');
     if (defined('PHPFOX_HTML5_PHOTO_UPLOAD')) {
         $aParts = explode('&', $_SERVER['HTTP_X_POST_FORM']);
         foreach ($aParts as $sPart) {
             $aReq = explode('=', $sPart);
             if (substr($aReq[0], 0, 3) == 'val') {
                 $aVals[preg_replace('/val\\[(.*?)\\]/i', '\\1', $aReq[0])] = isset($aReq[1]) ? $aReq[1] : '';
             }
         }
     }
     if (!is_array($aVals)) {
         $aVals = array();
     }
     $bIsInline = false;
     if (isset($aVals['action']) && $aVals['action'] == 'upload_photo_via_share') {
         $bIsInline = true;
     }
     $oServicePhotoProcess = Phpfox::getService('photo.process');
     $aImages = array();
     $aFeed = array();
     $iFileSizes = 0;
     $iCnt = 0;
     ($sPlugin = Phpfox_Plugin::get('photo.component_controller_frame_start')) ? eval($sPlugin) : false;
     if (!empty($aVals['album_id'])) {
         $aAlbum = Phpfox::getService('photo.album')->getAlbum(Phpfox::getUserId(), $aVals['album_id'], true);
     }
     if (isset($_REQUEST['status_info']) && !empty($_REQUEST['status_info'])) {
         $aVals['description'] = $_REQUEST['status_info'];
     }
     foreach ($_FILES['image']['error'] as $iKey => $sError) {
         if ($sError == UPLOAD_ERR_OK) {
             if ($aImage = $oFile->load('image[' . $iKey . ']', array('jpg', 'gif', 'png'), Phpfox::getUserParam('photo.photo_max_upload_size') === 0 ? null : Phpfox::getUserParam('photo.photo_max_upload_size') / 1024)) {
                 if (isset($aVals['action']) && $aVals['action'] == 'upload_photo_via_share') {
                     $aVals['description'] = isset($aVals['is_cover_photo']) ? null : $aVals['status_info'];
                     $aVals['type_id'] = isset($aVals['is_cover_photo']) ? '2' : '1';
                 }
                 if ($iId = $oServicePhotoProcess->add(Phpfox::getUserId(), array_merge($aVals, $aImage))) {
                     $iCnt++;
                     $aPhoto = Phpfox::getService('photo')->getForProcess($iId);
                     // Move the uploaded image and return the full path to that image.
                     $sFileName = $oFile->upload('image[' . $iKey . ']', Phpfox::getParam('photo.dir_photo'), Phpfox::getParam('photo.rename_uploaded_photo_names') ? Phpfox::getUserBy('user_name') . '-' . preg_replace('/&#/i', 'u', $aPhoto['title']) : $iId, Phpfox::getParam('photo.rename_uploaded_photo_names') ? array() : true);
                     if (!$sFileName) {
                         exit('failed: ' . implode('', Phpfox_Error::get()));
                     }
                     // Get the original image file size.
                     $iFileSizes += filesize(Phpfox::getParam('photo.dir_photo') . sprintf($sFileName, ''));
                     // Get the current image width/height
                     $aSize = getimagesize(Phpfox::getParam('photo.dir_photo') . sprintf($sFileName, ''));
                     // Update the image with the full path to where it is located.
                     $aUpdate = array('destination' => $sFileName, 'width' => $aSize[0], 'height' => $aSize[1], 'server_id' => Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID'), 'allow_rate' => empty($aVals['album_id']) ? '1' : '0', 'description' => empty($aVals['description']) ? null : $aVals['description']);
                     // Solves bug, when categories are left empty and setting "photo.allow_photo_category_selection" is enabled:
                     if (isset($aVals['category_id'])) {
                         $aUpdate['category_id'] = $aVals['category_id'];
                     } elseif (isset($aVals['category_id[]'])) {
                         $aUpdate['category_id'] = $aVals['category_id[]'];
                     }
                     $oServicePhotoProcess->update(Phpfox::getUserId(), $iId, $aUpdate);
                     // Assign vars for the template.
                     $aImages[] = array('photo_id' => $iId, 'server_id' => Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID'), 'destination' => $sFileName, 'name' => $aImage['name'], 'ext' => $aImage['ext'], 'size' => $aImage['size'], 'width' => $aSize[0], 'height' => $aSize[1], 'completed' => 'false');
                     ($sPlugin = Phpfox_Plugin::get('photo.component_controller_frame_process_photo')) ? eval($sPlugin) : false;
                 }
             } else {
             }
         }
     }
     $iFeedId = 0;
     // Make sure we were able to upload some images
     if (count($aImages)) {
         if (defined('PHPFOX_IS_HOSTED_SCRIPT')) {
             unlink(Phpfox::getParam('photo.dir_photo') . sprintf($sFileName, ''));
         }
         $aCallback = !empty($aVals['callback_module']) ? Phpfox::callback($aVals['callback_module'] . '.addPhoto', $aVals['callback_item_id']) : null;
         $sAction = isset($aVals['action']) ? $aVals['action'] : 'view_photo';
         // Have we posted an album for these set of photos?
         if (isset($aVals['album_id']) && !empty($aVals['album_id'])) {
             $aAlbum = Phpfox::getService('photo.album')->getAlbum(Phpfox::getUserId(), $aVals['album_id'], true);
             // Set the album privacy
             Phpfox::getService('photo.album.process')->setPrivacy($aVals['album_id']);
             // Check if we already have an album cover
             if (!Phpfox::getService('photo.album.process')->hasCover($aVals['album_id'])) {
                 // Set the album cover
                 Phpfox::getService('photo.album.process')->setCover($aVals['album_id'], $iId);
             }
             // Update the album photo count
             if (!Phpfox::getUserParam('photo.photo_must_be_approved')) {
                 Phpfox::getService('photo.album.process')->updateCounter($aVals['album_id'], 'total_photo', false, count($aImages));
             }
             if (!defined('PHPFOX_SKIP_FEED_ENTRY') && !Phpfox::getUserParam('photo.photo_must_be_approved')) {
                 // (Phpfox::isModule('feed') ? $iFeedId = Phpfox::getService('feed.process')->callback($aCallback)->delete('photo_album', $aVals['album_id'], Phpfox::getUserId()) : null);
                 // (Phpfox::isModule('feed') ? $iFeedId = Phpfox::getService('feed.process')->callback($aCallback)->add('photo_album', $aVals['album_id'], $aAlbum['privacy'], $aAlbum['privacy_comment'], (isset($aVals['parent_user_id']) ? (int) $aVals['parent_user_id'] : 0)) : null);
             }
             $sAction = 'view_album';
         } else {
             if (!defined('PHPFOX_SKIP_FEED_ENTRY') && !Phpfox::getUserParam('photo.photo_must_be_approved')) {
                 // (Phpfox::isModule('feed') ? $iFeedId = Phpfox::getService('feed.process')->callback($aCallback)->add('photo', $iId, (isset($aVals['privacy']) ? (int) $aVals['privacy'] : 0), (isset($aVals['privacy_comment']) ? (int) $aVals['privacy_comment'] : 0), (isset($aVals['parent_user_id']) ? (int) $aVals['parent_user_id'] : 0)) : null);
             }
         }
         //die('temp:' . __LINE__ . ' count: ' . count($aImages) . 'isset: ' . (print_r(isset($aVals['album_id']), true)));
         // Update the user space usage
         Phpfox::getService('user.space')->update(Phpfox::getUserId(), 'photo', $iFileSizes);
         ($sPlugin = Phpfox_Plugin::get('photo.component_controller_frame_process_photos_done')) ? eval($sPlugin) : false;
         if (isset($aVals['page_id']) && $aVals['page_id'] > 0) {
             if (Phpfox::getService('pages.process')->setCoverPhoto($aVals['page_id'], $iId, true)) {
                 //echo '<script type="text/javascript">parent.window.location.href = "' . Phpfox::permalink('pages', $aVals['page_id'], '') . '";</script>';
                 $aVals['is_cover_photo'] = 1;
             } else {
                 echo '<script type="text/javascript">alert("Something went wrong: ' . implode(Phpfox_Error::get()) . '");</script>';
             }
         }
         if (isset($_REQUEST['picup'])) {
             //exit();
         } else {
             if (isset($aVals['method']) && $aVals['method'] == 'massuploader') {
                 //echo 'window.aImagesUrl.push("' . urlencode(base64_encode(serialize($aImages))) . '");';
                 echo 'window.aImagesUrl.push(' . json_encode($aImages) . ');';
             } else {
                 $sExtra = '';
                 if (!empty($aVals['start_year']) && !empty($aVals['start_month']) && !empty($aVals['start_day'])) {
                     $sExtra .= '&start_year= ' . $aVals['start_year'] . '&start_month= ' . $aVals['start_month'] . '&start_day= ' . $aVals['start_day'] . '';
                 }
                 if (!defined('PHPFOX_HTML5_PHOTO_UPLOAD')) {
                     echo '<script type="text/javascript">';
                 }
                 if ($bIsInline && Phpfox::isModule('video') && Phpfox::getParam('video.convert_servers_enable')) {
                     echo 'document.domain = "' . Phpfox::getParam('video.convert_js_parent') . '";';
                 }
                 if (!defined('PHPFOX_HTML5_PHOTO_UPLOAD')) {
                     echo 'window.parent.';
                 }
                 $out = http_build_query((new Core\Request())->all());
                 echo '$.ajaxCall(\'photo.process\', \'' . $out . '&' . (isset($aVals['page_id']) && !empty($aVals['page_id']) ? 'is_page=1&' : '') . 'js_disable_ajax_restart=true' . $sExtra . '&twitter_connection=' . (isset($aVals['connection']) && isset($aVals['connection']['twitter']) ? $aVals['connection']['twitter'] : '0') . '&facebook_connection=' . (isset($aVals['connection']['facebook']) ? $aVals['connection']['facebook'] : '0') . '&custom_pages_post_as_page=' . $this->request()->get('custom_pages_post_as_page') . '&photos=' . urlencode(json_encode($aImages)) . '&action=' . $sAction . '' . (isset($iFeedId) ? '&feed_id=' . $iFeedId : '') . '' . ($aCallback !== null ? '&callback_module=' . $aCallback['module'] . '&callback_item_id=' . $aCallback['item_id'] : '') . '&parent_user_id=' . (isset($aVals['parent_user_id']) ? (int) $aVals['parent_user_id'] : 0) . '&is_cover_photo=' . (isset($aVals['is_cover_photo']) ? '1' : '0') . (isset($aVals['page_id']) && $aVals['page_id'] > 0 ? '&page_id=' . $aVals['page_id'] : '') . '\');';
                 if (!defined('PHPFOX_HTML5_PHOTO_UPLOAD')) {
                     echo '</script>';
                 }
             }
         }
         ($sPlugin = Phpfox_Plugin::get('photo.component_controller_frame_process_photos_done_javascript')) ? eval($sPlugin) : false;
     } else {
         // Output JavaScript
         if (!defined('PHPFOX_HTML5_PHOTO_UPLOAD')) {
             echo '<script type="text/javascript">';
         } else {
             if (isset($sHTML5TempFile) && file_exists($sHTML5TempFile)) {
                 unlink($sHTML5TempFile);
             }
             header('HTTP/1.1 500 Internal Server Error');
             echo 'hasErrors++;';
         }
         if (!$bIsInline) {
             // echo 'window.parent.$(\'#js_progress_cache_holder\').hide();';
             // echo 'window.parent.document.getElementById(\'js_photo_form_holder\').style.display = \'block\';';
             // echo 'window.parent.document.getElementById(\'js_upload_error_message\').innerHTML = \'<div class="error_message">' . implode('', Phpfox_Error::get()) . '</div>\';';
         } else {
             if (Phpfox::isModule('video') && Phpfox::getParam('video.convert_servers_enable')) {
                 echo 'document.domain = "' . Phpfox::getParam('video.convert_js_parent') . '";';
             }
             if (isset($aVals['is_cover_photo'])) {
                 echo 'window.parent.$(\'#js_cover_photo_iframe_loader_upload\').hide();';
                 echo 'window.parent.$(\'#js_activity_feed_form\').show();';
                 echo 'window.parent.$(\'#js_cover_photo_iframe_loader_error\').html(\'<div class="error_message">' . implode('', Phpfox_Error::get()) . '</div>\').show();';
             } else {
                 echo 'window.parent.$Core.resetActivityFeedError(\'' . implode('', Phpfox_Error::get()) . '\');';
             }
         }
         if (!defined('PHPFOX_HTML5_PHOTO_UPLOAD')) {
             echo '</script>';
         }
     }
     exit;
 }
Example #26
0
 /**
  * Adds a poll
  *
  * @param array $aVals input from the form after validated
  * @param integer $iUser user_id of the owner of the poll
  */
 public function add($iUser, $aVals, $bIsUpdate = false)
 {
     ($sPlugin = Phpfox_Plugin::get('poll.service_process_add_start')) ? eval($sPlugin) : false;
     $sAnswers = '';
     if (isset($aVals['answer']) && is_array($aVals['answer'])) {
         foreach ($aVals['answer'] as $aAnswer) {
             $sAnswers .= $aAnswer['answer'] . ' ';
         }
     }
     Phpfox::getService('ban')->checkAutomaticBan($aVals['question'] . ' ' . $sAnswers);
     if (!isset($aVals['randomize'])) {
         $aVals['randomize'] = 0;
     }
     if (!isset($aVals['hide_vote'])) {
         $aVals['hide_vote'] = 0;
     }
     if (!isset($aVals['privacy'])) {
         $aVals['privacy'] = 0;
     }
     $oImage = Phpfox_Image::instance();
     $oFile = Phpfox_File::instance();
     $bHasImage = false;
     $bIsCustom = !empty($aVals['module_id']) ? true : false;
     if ($bIsCustom) {
         $aVals['randomize'] = '0';
     }
     // upload the image uploaded if allowed
     if (Phpfox::getUserParam('poll.poll_can_upload_image') && isset($_FILES['image']['name']) && $_FILES['image']['name'] != '') {
         $aImage = $oFile->load('image', array('jpg', 'gif', 'png'));
         if ($aImage === false) {
             return false;
         }
         $bHasImage = true;
     }
     $aInsert = array('question' => Phpfox::getLib('parse.input')->clean($aVals['question']), 'privacy' => isset($aVals['privacy']) ? $aVals['privacy'] : '0', 'privacy_comment' => isset($aVals['privacy_comment']) ? $aVals['privacy_comment'] : '0', 'view_id' => (!$bIsCustom && Phpfox::getUserParam('poll.poll_requires_admin_moderation')) === true ? 1 : 0, 'randomize' => isset($aVals['randomize']) ? (int) $aVals['randomize'] : '1', 'server_id' => Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID'), 'hide_vote' => isset($aVals['hide_vote']) ? (int) $aVals['hide_vote'] : '0');
     //(($sPlugin = Phpfox_Plugin::get('poll.service_process_add_ainsert')) ? eval($sPlugin) : false);
     //if its an update then delete the older answers
     if ($bIsUpdate) {
         $iId = $aVals['poll_id'];
         $this->database()->update($this->_sTable, $aInsert, 'poll_id = ' . (int) $aVals['poll_id']);
         $aInsert = $this->database()->select('poll_id, question, view_id, image_path')->from($this->_sTable)->where('poll_id = ' . (int) $aVals['poll_id'])->execute('getSlaveRow');
         // get the file size of the old image
         $iSize = Phpfox::getParam('poll.poll_max_image_pic_size');
         if ($bHasImage && isset($aInsert['image_path']) && $aInsert['image_path'] != '' && file_exists(Phpfox::getParam('poll.dir_image') . sprintf($aInsert['image_path'], '')) && file_exists(Phpfox::getParam('poll.dir_image') . sprintf($aInsert['image_path'], '_' . $iSize))) {
             $iOldPictureSpaceUsed = filesize(Phpfox::getParam('poll.dir_image') . sprintf($aInsert['image_path'], '')) + filesize(Phpfox::getParam('poll.dir_image') . sprintf($aInsert['image_path'], '_' . $iSize));
             // update the space used
             Phpfox::getService('user.space')->update((int) $iUser, 'quiz', $iOldPictureSpaceUsed, '-');
             // and delete the old picture
             Phpfox_File::instance()->unlink(Phpfox::getParam('poll.dir_image') . sprintf($aInsert['image_path'], ''));
             Phpfox_File::instance()->unlink(Phpfox::getParam('poll.dir_image') . sprintf($aInsert['image_path'], '_' . $iSize));
         }
         $aTotalVotes = $this->database()->select('pa.answer_id, pa.total_votes')->from(Phpfox::getT('poll_answer'), 'pa')->where('pa.poll_id = ' . (int) $aVals['poll_id'])->execute('getSlaveRows');
         $this->database()->delete(Phpfox::getT('poll_answer'), 'poll_id = ' . $aVals['poll_id']);
         if (Phpfox::isModule('feed')) {
             Phpfox::isModule('feed') ? Phpfox::getService('feed.process')->update('poll', $iId, $aVals['privacy'], isset($aVals['privacy_comment']) ? (int) $aVals['privacy_comment'] : 0) : null;
         }
         if (Phpfox::isModule('privacy')) {
             if ($aVals['privacy'] == '4') {
                 Phpfox::getService('privacy.process')->update('poll', $iId, isset($aVals['privacy_list']) ? $aVals['privacy_list'] : array());
             } else {
                 Phpfox::getService('privacy.process')->delete('poll', $iId);
             }
         }
         if (Phpfox::getParam('feed.cache_each_feed_entry')) {
             $this->cache()->remove(array('feeds', 'poll_' . $iId));
         }
     } else {
         $aInsert['user_id'] = $iUser;
         $aInsert['time_stamp'] = PHPFOX_TIME;
         if ($bIsCustom) {
             $aInsert['module_id'] = $aVals['module_id'];
         }
         $iId = $this->database()->insert($this->_sTable, $aInsert);
         if (!Phpfox::getUserParam('poll.poll_requires_admin_moderation') && !$bIsCustom) {
             Phpfox::isModule('feed') ? Phpfox::getService('feed.process')->add('poll', $iId, $aVals['privacy'], isset($aVals['privacy_comment']) ? (int) $aVals['privacy_comment'] : 0) : null;
             // Update user activity
             Phpfox::getService('user.activity')->update(Phpfox::getUserId(), 'poll');
         }
         if (isset($aVals['privacy']) && $aVals['privacy'] == '4') {
             Phpfox::getService('privacy.process')->add('poll', $iId, isset($aVals['privacy_list']) ? $aVals['privacy_list'] : array());
         }
     }
     // at this point there should only be valid answers ( != 'Answer number 1...', 'Answer number 2...')
     $iOrdering = 1;
     foreach ($aVals['answer'] as $aAnswer) {
         if (Phpfox::getLib('parse.format')->isEmpty($aAnswer['answer'])) {
             continue;
         }
         $aAnswerInsert = array('poll_id' => $bIsUpdate ? $aVals['poll_id'] : (int) $iId, 'answer' => Phpfox::getLib('parse.input')->clean($aAnswer['answer'], 255), 'ordering' => $iOrdering);
         // (($sPlugin = Phpfox_Plugin::get('poll.service_process_add_insert_answer')) ? eval($sPlugin) : false);
         if (isset($aAnswer['answer_id'])) {
             $aAnswerInsert['answer_id'] = $aAnswer['answer_id'];
             foreach ($aTotalVotes as $aVotes) {
                 if ($aAnswer['answer_id'] == $aVotes['answer_id']) {
                     $aAnswerInsert['total_votes'] = $aVotes['total_votes'];
                 }
             }
         }
         $this->database()->insert(Phpfox::getT('poll_answer'), $aAnswerInsert);
         ++$iOrdering;
     }
     if ($bHasImage) {
         if (is_bool($iId)) {
             $iId = (int) $aVals['poll_id'];
         }
         $sFileName = $oFile->upload('image', Phpfox::getParam('poll.dir_image'), $iId);
         // update the poll
         $this->database()->update($this->_sTable, array('image_path' => $sFileName), 'poll_id = ' . $iId);
         // now the thumbnails
         // $iSize = Phpfox::getParam('poll.poll_max_image_pic_size');
         $oImage->createThumbnail(Phpfox::getParam('poll.dir_image') . sprintf($sFileName, ''), Phpfox::getParam('poll.dir_image') . sprintf($sFileName, ''), 600, 400);
         // Update user space usage
         Phpfox::getService('user.space')->update(Phpfox::getUserId(), 'poll', filesize(Phpfox::getParam('poll.dir_image') . sprintf($sFileName, '')));
         $this->database()->update($this->_sTable, array('server_id' => Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID')), 'poll_id = ' . (int) $iId);
     }
     if (!$bIsCustom) {
         if ($bIsUpdate) {
             // sync the results
             $aResults = $this->database()->select('pr.*')->from(Phpfox::getT('poll_result'), 'pr')->join(Phpfox::getT('poll_answer'), 'pa', 'pa.answer_id = pr.answer_id')->where('pr.poll_id = ' . (int) $aVals['poll_id'])->execute('getSlaveRows');
             $this->database()->delete(Phpfox::getT('poll_result'), 'poll_id = ' . $aVals['poll_id']);
             foreach ($aResults as $aResult) {
                 $this->database()->insert(Phpfox::getT('poll_result'), $aResult);
             }
         }
     }
     ($sPlugin = Phpfox_Plugin::get('poll.service_process_add_end')) ? eval($sPlugin) : false;
     return array($iId, $aInsert);
 }