Example #1
0
    function getFieldHTML($field, $required)
    {
        $html = '';
        $pID = $field->value;
        $class = $required == 1 ? ' required' : '';
        $disabled = '';
        if ($this->_view === 'register') {
            // get pType from registration session OR defaultPType
            $pID = XiptFactory::getPluginHandler()->getRegistrationPType();
            $html = '<input type="hidden"
							id="field' . $field->id . '"
							name="field' . $field->id . '"
							value="' . $pID . '" />';
            $pName = XiptLibProfiletypes::getProfiletypeName($pID);
            $html .= $pName;
            return $html;
        }
        // it might be some other user (in case of admin is editing profile)
        $user = JFactory::getUser();
        $userid = $user->id;
        if (!(int) $pID) {
            $pID = XiptLibProfiletypes::getUserData($userid, 'PROFILETYPE');
            XiptError::assert($pID, XiptText::_("USERID {$pID} DOES_NOT_EXIST"), XiptError::ERROR);
        }
        $visiblePT = XiptLibProfiletypes::getProfiletypeArray(array('visible' => 1));
        $allowToChangePType = $this->_params->get('allow_user_to_change_ptype_after_reg', 0);
        $allowToChangePType = $allowToChangePType && array_key_exists($pID, $visiblePT) || XiptHelperUtils::isAdmin($user->id);
        //if not allowed then show disabled view of ptype
        if ($allowToChangePType == false) {
            $pName = XiptLibProfiletypes::getProfileTypeName($pID);
            $pName = $pName;
            $html = '<input type="hidden"
							id="field' . $field->id . '"
							name="field' . $field->id . '"
							value="' . $pID . '" />';
            return $html . $pName;
        }
        $mainframe = JFactory::getApplication();
        if ($mainframe->isAdmin() == true || XiptHelperUtils::isAdmin($user->id)) {
            $filter = array('published' => 1);
        } else {
            $filter = array('published' => 1, 'visible' => 1);
        }
        // user can change profiletype, add information
        $pTypes = XiptLibProfiletypes::getProfiletypeArray($filter);
        $html = '<select id="field' . $field->id . '" name="field' . $field->id . '" ' . $disabled . ' class="hasTip select' . $class . ' inputbox" title="' . $field->name . '::' . htmlentities($field->tips) . '">';
        $selectedElement = 0;
        if (!empty($pTypes)) {
            foreach ($pTypes as $pType) {
                $selected = $pType->id == $pID ? ' selected="selected"' : '';
                if (!empty($selected)) {
                    $selectedElement++;
                }
                $html .= '<option value="' . $pType->id . '"' . $selected . '>' . $pType->name . '</option>';
            }
        }
        $html .= '</select>';
        $html .= '<span id="errfield' . $field->id . 'msg" style="display:none;">&nbsp;</span>';
        return $html;
    }
Example #2
0
 function getSettings($paramName = '', $defaultValue = 0)
 {
     $sModel = XiptFactory::getInstance('settings', 'model');
     $params = $sModel->getParams();
     if (!$params) {
         XiptError::raiseWarning('XIPT-SYSTEM-ERROR', 'JSPT PARAMS ARE NULL');
     }
     if (empty($paramName)) {
         return $params;
     }
     if ($paramName == 'aec_integrate') {
         $aec_integrate = $params->get('aec_integrate', 'aec');
         if ($aec_integrate == 'aec') {
             return $params->get('subscription_integrate', $defaultValue);
         } else {
             return $aec_integrate;
         }
     }
     if ($paramName == 'aec_message') {
         $aec_message = $params->get('aec_message', 'aec');
         if ($aec_message == 'aec') {
             return $params->get('subscription_message', $defaultValue);
         } else {
             return $aec_message;
         }
     }
     return $params->get($paramName, $defaultValue);
 }
Example #3
0
 function createCustomField($what)
 {
     // Load the JTable Object.
     JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_community' . DS . 'tables');
     $row = JTable::getInstance('profiles', 'CommunityTable');
     $row->load(0);
     switch ($what) {
         case PROFILETYPE_CUSTOM_FIELD_CODE:
             $data['type'] = PROFILETYPE_FIELD_TYPE_NAME;
             $data['name'] = 'Profiletype';
             $data['tips'] = 'Profiletype Of User';
             break;
         case TEMPLATE_CUSTOM_FIELD_CODE:
             $data['type'] = TEMPLATE_FIELD_TYPE_NAME;
             $data['name'] = 'Template';
             $data['tips'] = 'Template Of User';
             break;
         default:
             XiptError::assert(0);
             break;
     }
     $data['published'] = 1;
     $data['fieldcode'] = $what;
     return $row->bind($data) && $row->store();
 }
Example #4
0
 function save($post = null)
 {
     if ($post === null) {
         $post = JRequest::get('post', JREQUEST_ALLOWRAW);
     }
     $save = $this->getModel()->saveParams($post['settings'], 'settings', 'params');
     XiptError::assert($save, XiptText::_('ERROR_IN_SAVING_SETTINGS'), XiptError::WARNING);
     $msg = XiptText::_('SETTINGS_SAVED');
     $this->setRedirect("index.php?option=com_xipt&view=settings", $msg);
     return true;
 }
Example #5
0
 public static function getInstance()
 {
     $suffix = JString::stristr(XiptHelperJomsocial::get_js_version(), 2.0) ? "Js20" : "Js18";
     $classname = "XiptFieldsTemplates" . JString::ucfirst($suffix);
     if (class_exists($classname, true) === false) {
         XiptError::raiseError(__CLASS__ . '.' . __LINE__, XiptText::_("{$className} : CLASS_NOT_FOUND"));
         return false;
     }
     $instance = new $classname();
     return $instance;
 }
Example #6
0
 function getProfileTypeArray($menuid)
 {
     XiptError::assert($menuid, XiptText::_("MENU_ID_CANNOT_BE_NULL"), XiptError::ERROR);
     $results = XiptFactory::getInstance('jstoolbar', 'model')->getProfileTypes($menuid);
     if (empty($results)) {
         return array(XIPT_PROFILETYPE_ALL);
     }
     $allTypes = XiptHelperProfiletypes::getProfileTypeArray();
     // array_values is user to arrange the array from index 0,
     //array_diff uses index starting from 1
     return array_values(array_diff($allTypes, $results));
 }
Example #7
0
 function getName()
 {
     $name = $this->_name;
     if (empty($name)) {
         $r = null;
         if (!preg_match('/View(.*)/i', get_class($this), $r)) {
             XiptError::raiseError(__CLASS__ . '.' . __LINE__, "Can't get or parse class name.");
         }
         $name = strtolower($r[1]);
     }
     return $name;
 }
Example #8
0
 function getProfileTypeArray($fid, $for)
 {
     XiptError::assert($fid, XiptText::_("PROFILEFIELD_ID_CAN_NOT_BE_NULL"), XiptError::ERROR);
     //Load all profiletypes for the field
     $results = XiptFactory::getInstance('profilefields', 'model')->getProfileTypes($fid, $for);
     if (empty($results)) {
         return array(XIPT_PROFILETYPE_ALL);
     }
     $allTypes = XiptHelperProfiletypes::getProfileTypeArray();
     // array_values is user to arrange the array from index 0,
     //array_diff uses index starting from 1
     return array_values(array_diff($allTypes, $results));
 }
Example #9
0
 function unCopyXIPTFilesFromJomSocial()
 {
     $COMMUNITY_PATH_FRNTEND = JPATH_ROOT . DS . 'components' . DS . 'com_community';
     $targetFile = $COMMUNITY_PATH_FRNTEND . DS . 'libraries' . DS . 'fields' . DS . 'profiletypes.php';
     if (JFile::exists($targetFile)) {
         JFile::delete($targetFile) || XiptError::raiseError('XIPT-UNINSTALL-ERROR', 'Not able to restore backup:' . __LINE__);
     }
     $targetFile = $COMMUNITY_PATH_FRNTEND . DS . 'libraries' . DS . 'fields' . DS . 'templates.php';
     if (JFile::exists($targetFile)) {
         JFile::delete($targetFile) || XiptError::raiseError('XIPT-UNINSTALL-ERROR', 'Not able to restore backup : ' . __LINE__);
     }
     return;
 }
Example #10
0
 function getFieldData($value = 0)
 {
     $pID = $value;
     if (!$pID) {
         //get value from profiletype field from xipt_users table
         //not required to get data from getUser() fn b'coz we call this fn in
         //getViewableprofile only.
         $userid = JRequest::getVar('userid', 0);
         XiptError::assert($userid, XiptText::_("USERID {$userid} DOES_NOT_EXIST"), XiptError::ERROR);
         $pID = XiptLibProfiletypes::getUserData($userid, 'PROFILETYPE');
     }
     $pName = XiptLibProfiletypes::getProfiletypeName($pID);
     return $pName;
 }
Example #11
0
 function getFieldsForProfiletype(&$fields, $selectedProfiletypeID, $from, $notSelectedFields = null)
 {
     XiptError::assert($selectedProfiletypeID, XiptText::_("SELECTED_PROFILETYPE_DOES_NOT_EXIST"), XiptError::ERROR);
     $task = JRequest::getVar('task', '');
     if ($notSelectedFields === null) {
         $categories = XiptHelperProfilefields::getProfileFieldCategories();
         foreach ($categories as $catIndex => $catInfo) {
             $catName = $catInfo['name'];
             $notSelectedFields[$catName] = $this->getNotSelectedFieldForProfiletype($selectedProfiletypeID, $catIndex);
         }
     }
     $count = count($fields);
     for ($i = 0; $i < $count; $i++) {
         $field =& $fields[$i];
         if (is_object($field)) {
             $fieldId = $field->id;
         } else {
             $fieldId = $field['id'];
         }
         if (in_array($fieldId, $notSelectedFields['ALLOWED'])) {
             unset($fields[$i]);
             continue;
         }
         if (in_array($fieldId, $notSelectedFields['REQUIRED'])) {
             if (is_object($field)) {
                 $field->required = 0;
             } else {
                 $field['required'] = 0;
             }
         }
         if (in_array($fieldId, $notSelectedFields['VISIBLE']) && $from === 'getViewableProfile') {
             unset($fields[$i]);
             continue;
         }
         if (in_array($fieldId, $notSelectedFields['EDITABLE_AFTER_REG']) && $from === 'getEditableProfile' && JFactory::getApplication()->isAdmin() == false) {
             unset($fields[$i]);
             continue;
         }
         if (in_array($fieldId, $notSelectedFields['EDITABLE_DURING_REG']) && $from != 'getViewableProfile' && $from != 'getEditableProfile' && $task != 'advancesearch') {
             unset($fields[$i]);
             continue;
         }
         if (in_array($fieldId, $notSelectedFields['ADVANCE_SEARCHABLE']) && $from === '_loadAllFields' && $task === 'advancesearch') {
             unset($fields[$i]);
         }
     }
     $fields = array_values($fields);
     return true;
 }
Example #12
0
 function reset($id = 0)
 {
     //XITODO : what to do if invalid id comes
     $id = JRequest::getVar('profileId', $id);
     $pModel = $this->getModel();
     // Try to save configurations
     $save = $pModel->save(array('params' => ''), $id);
     if (XiptError::assert($save, XiptText::_('UNABLE_TO_RESET_PROFILETYPE_INTO_DATABASE_PLEASE_ENSURE_THAT_THE_TABLE_JOS_XIPT_PROFILETYPES_EXISTS'), XiptError::WARNING) == false) {
         return false;
     }
     $link = XiptRoute::_('index.php?option=com_xipt&view=configuration', false);
     $msg = XiptText::_('PROFILETYPE_HAS_BEEN_RESET');
     $this->setRedirect($link, $msg);
     return true;
 }
Example #13
0
 public function getAclObject($aclName)
 {
     $path = dirname(__FILE__) . DS . $aclName . DS . $aclName . '.php';
     if (!JFile::exists($path)) {
         XiptError::raiseError(__CLASS__ . '.' . __LINE__, sprintf(XiptText::_("INVALID_ACL_FILE"), $aclName));
         return false;
     }
     require_once $path;
     //$instance will comtain all addon object according to rule
     //Every rule will have different object
     static $instance = array();
     if (isset($instance[$aclName])) {
         return $instance[$aclName];
     }
     $instance[$aclName] = new $aclName();
     return $instance[$aclName];
 }
Example #14
0
 function edit($id = 0, $acl = 0)
 {
     $id = JRequest::getVar('id', $id);
     $acl = JRequest::getVar('acl', $acl);
     $view = $this->getView();
     XiptError::assert($acl || $id, XiptText::_("NOT_DEFINED {$id} or {$acl}"), XiptError::ERROR);
     if ($acl) {
         $aclObject = XiptAclFactory::getAclObject($acl);
     } else {
         $aclObject = XiptAclFactory::getAclObjectFromId($id);
     }
     XiptError::assert(isset($aclObject), XiptText::_("NOT_ABLE_TO_CREATE_ACL_OBJECT"), XiptError::ERROR);
     $aclObject->load($id);
     $data = $aclObject->getObjectInfoArray();
     $data['id'] = $id;
     return $view->edit($data);
 }
Example #15
0
 function save($data, $pk = null)
 {
     if (isset($data) === false || count($data) <= 0) {
         XiptError::raiseError(__CLASS__ . '.' . __LINE__, XiptText::_("NO_DATA_TO_SAVE_IN_USER_TABLE_KINDLY_RE-LOGIN_AND_RETRY_TO_SAVE_DATA"));
         return false;
     }
     //load the table row
     $table = $this->getTable();
     if (!$table) {
         XiptError::raiseError(__CLASS__ . '.' . __LINE__, sprintf(XiptText::_("TABLE_DOES_NOT_EXIST"), $table));
         return false;
     }
     $table->load($pk);
     //to clean cached data, reset record list
     $this->_recordlist = array();
     //bind, and then save
     if ($table->bind($data) && $table->store()) {
         return true;
     }
     //some error occured
     XiptError::raiseError(__CLASS__ . '.' . __LINE__, sprintf(XiptText::_("NOT_ABLE_TO_SAVE_DATA_IN_TABLE_PLEASE_RE-TRY"), $table));
     return false;
 }
Example #16
0
 function _addUserToGroup($userId, $groupIds)
 {
     if (empty($groupIds)) {
         return false;
     }
     $groupIds = explode(',', $groupIds);
     $groupModel = CFactory::getModel('groups');
     //if user has selected "none" just exit
     if (is_array($groupIds) == false || in_array(NONE, $groupIds)) {
         return false;
     }
     foreach ($groupIds as $k => $gid) {
         if ($groupModel->isMember($userId, $gid)) {
             continue;
         }
         $group = JTable::getInstance('Group', 'CTable');
         $member = JTable::getInstance('GroupMembers', 'CTable');
         $group->load($gid);
         // Set the properties for the members table
         $member->groupid = $group->id;
         $member->memberid = $userId;
         // @rule: If approvals is required, set the approved status accordingly.
         $member->approved = 1;
         // SHOULD BE always 1  by SHYAM//( $group->approvals ) ? '0' : 1;
         //@todo: need to set the privileges
         $member->permissions = '0';
         $store = $member->store();
         // Assert if storing fails
         XiptError::assert($store, XiptText::_("DATA_IS_NOT_STORED"), XiptError::ERROR);
         if ($member->approved) {
             self::addWallCount($gid);
         }
     }
     return true;
 }
Example #17
0
 function multidobool($task = 'enable', $cids = array(0))
 {
     $task = JRequest::getVar('task', $task);
     $offpattern = '/^switchOff/';
     $onpattern = '/^switchOn/';
     if (preg_match($onpattern, $task)) {
         $switch = false;
         //$columninfo = str_split($task,strlen('switchOn'));
         $columninfo = explode('switchOn', $task);
         $column = array_key_exists(1, $columninfo) ? $columninfo[1] : '';
         $value = 1;
     } else {
         if (preg_match($offpattern, $task)) {
             $switch = false;
             //$columninfo = str_split($task,strlen('switchOff'));
             $columninfo = explode('switchOff', $task);
             $column = array_key_exists(1, $columninfo) ? $columninfo[1] : '';
             $value = 0;
         } else {
             XiptError::assert(0);
         }
     }
     $cids = JRequest::getVar('cid', $cids, 'post', 'array');
     foreach ($cids as $cid) {
         if (!$this->_doBool($column, $value, $cid)) {
             XiptError::raiseError(__CLASS__ . '.' . __LINE__, XiptText::_("ERROR_IN_REORDERING_ITEMS"));
         }
     }
     //redirect now
     $this->setRedirect(XiptRoute::_("index.php?option=com_" . JString::strtolower($this->getPrefix()) . "&view={$this->getName()}"), sprintf(XiptText::_($task . '.MSG'), $cids));
     return false;
 }
Example #18
0
 function loadParams($id, $what = '')
 {
     $record = $this->loadRecords(0);
     $xmlPath = XIPT_FRONT_PATH_ASSETS . DS . 'xml' . DS . JString::strtolower($this->getName() . ".{$what}.xml");
     $iniPath = XIPT_FRONT_PATH_ASSETS . DS . 'ini' . DS . JString::strtolower($this->getName() . ".{$what}.ini");
     $iniData = JFile::read($iniPath);
     XiptError::assert(JFile::exists($xmlPath), sprintf(XiptText::_("FILE_DOES_NOT_EXIST"), $xmlPath), XiptError::ERROR);
     $config = new XiptParameter($iniData, $xmlPath);
     if (isset($record[$id])) {
         $config->bind($record[$id]->{$what});
     }
     return $config;
 }
Example #19
0
 function copyLibraryFiles()
 {
     $XIPT_PATH_ADMIN = JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_xipt';
     $COMMUNITY_PATH_FRNTEND = JPATH_ROOT . DS . 'components' . DS . 'com_community';
     $sourceFile = $XIPT_PATH_ADMIN . DS . 'hacks' . DS . 'front_libraries_fields_profiletypes.php';
     $targetFile = $COMMUNITY_PATH_FRNTEND . DS . 'libraries' . DS . 'fields' . DS . 'profiletypes.php';
     JFile::copy($sourceFile, $targetFile) || XiptError::raiseError('INSTERR', "Not able to copy file " . $sourceFile . " to " . $targetFile);
     $sourceFile = $XIPT_PATH_ADMIN . DS . 'hacks' . DS . 'front_libraries_fields_templates.php';
     $targetFile = $COMMUNITY_PATH_FRNTEND . DS . 'libraries' . DS . 'fields' . DS . 'templates.php';
     JFile::copy($sourceFile, $targetFile) || XiptError::raiseError('INSTERR', "Not able to copy file " . $sourceFile . " to " . $targetFile);
     return;
 }
Example #20
0
define('DEFAULT_IMAGEWATERMRK', 'components' . DS . 'com_xipt' . DS . 'assets' . DS . 'images' . DS . 'demo_watermrk.png');
define('DEFAULT_IMAGEWATERMRK_THUMB', 'components' . DS . 'com_xipt' . DS . 'assets' . DS . 'images' . DS . 'demo_watermrk_thumb.png');
define('DEFAULT_DEMOAVATAR', 'components' . DS . 'com_xipt' . DS . 'assets' . DS . 'images' . DS . 'default_avatar.png');
define('DEFAULT_DEMOAVATAR_THUMB', 'components' . DS . 'com_xipt' . DS . 'assets' . DS . 'images' . DS . 'default_thumb.png');
//where to store profiletype avatars
define('PROFILETYPE_AVATAR_STORAGE_REFERENCE_PATH', 'images' . DS . 'profiletype');
define('PROFILETYPE_AVATAR_STORAGE_PATH', JPATH_ROOT . DS . PROFILETYPE_AVATAR_STORAGE_REFERENCE_PATH);
define('USER_AVATAR_BACKUP', JPATH_ROOT . DS . PROFILETYPE_AVATAR_STORAGE_REFERENCE_PATH . DS . 'useravatar');
if (JFolder::exists(PROFILETYPE_AVATAR_STORAGE_PATH) == false && JFolder::create(PROFILETYPE_AVATAR_STORAGE_PATH) === false) {
    XiptError::raiseError("XIPT-ERROR", "Folder [" . PROFILETYPE_AVATAR_STORAGE_PATH . "] does not exist. Even we are not able to create it. Please check file permission.");
    return false;
}
//if(JFolder::exists(PROFILETYPE_AVATAR_STORAGE_PATH))
//	chmod(PROFILETYPE_AVATAR_STORAGE_PATH, 0755);
if (JFolder::exists(USER_AVATAR_BACKUP) == false && JFolder::create(USER_AVATAR_BACKUP) === false) {
    XiptError::raiseError("XIPT-ERROR", "Folder [" . USER_AVATAR_BACKUP . "] does not exist. Even we are not able to create it. Please check file permission.");
    return false;
}
//if(JFolder::exists(USER_AVATAR_BACKUP))
//	chmod(USER_AVATAR_BACKUP, 0755);
// define constants for category of Profile Fields
define('PROFILE_FIELD_CATEGORY_ALLOWED', 0);
define('PROFILE_FIELD_CATEGORY_REQUIRED', 1);
define('PROFILE_FIELD_CATEGORY_VISIBLE', 2);
define('PROFILE_FIELD_CATEGORY_EDITABLE_AFTER_REG', 3);
define('PROFILE_FIELD_CATEGORY_EDITABLE_DURING_REG', 4);
define('PROFILE_FIELD_CATEGORY_ADVANCE_SEARCHABLE', 5);
//define constants for blocking display application according to owner,visitor and both
define('BLOCK_DISPLAY_APP_OF_OWNER', 0);
define('BLOCK_DISPLAY_APP_OF_VISITOR', 1);
define('BLOCK_DISPLAY_APP_OF_BOTH', 2);
Example #21
0
 /**
  * Get structure of table from db table
  */
 public function getColumns()
 {
     if (isset($this->_columns)) {
         return $this->_columns;
     }
     $tableName = $this->getTableName();
     if (XiptHelperTable::isTableExist($tableName) === FALSE) {
         return XiptError::raiseError(__CLASS__ . '.' . __LINE__, XiptText::_("Table {$this->_tbl} DOES_NOT_EXIST"));
     }
     $fields = $this->_db->getTableFields($tableName);
     $this->_columns = $fields[$tableName];
     return $this->_columns;
 }
Example #22
0
 function getUserData($userid, $what = 'PROFILETYPE')
 {
     $results = array();
     switch ($what) {
         case 'PROFILETYPE':
             if ($userid == 0) {
                 return XiptFactory::getSettings('guestProfiletypeID', XiptFactory::getSettings('defaultProfiletypeID', 0));
             }
             $getMe = PROFILETYPE_FIELD_IN_USER_TABLE;
             $defaultValue = XiptLibProfiletypes::getDefaultProfiletype();
             break;
         case 'TEMPLATE':
             $getMe = TEMPLATE_FIELD_IN_USER_TABLE;
             $allTemplates = XiptHelperJomsocial::getTemplatesList();
             $pID = XiptLibProfiletypes::getUserData($userid, 'PROFILETYPE');
             $defaultValue = XiptLibProfiletypes::getProfileTypeData($pID, 'template');
             //else get system template
             if (in_array($defaultValue, $allTemplates) === false) {
                 $defaultValue = XiptLibProfiletypes::getDefaultTemplate();
             }
             break;
         default:
             XiptError::raiseError('XIPT-SYSTEM-ERROR', 'XIPT System Error');
     }
     $results = XiptFactory::getInstance('users', 'model')->loadRecords(0);
     // not a valid result OR value not set
     if (!$results || isset($results[$userid]) == false) {
         return $defaultValue;
     }
     $what = strtolower($what);
     return $results[$userid]->{$what};
 }
Example #23
0
 function getPTPrivacyValue($privacy)
 {
     $value = PRIVACY_PUBLIC;
     switch ($privacy) {
         case "friends":
             $value = PRIVACY_FRIENDS;
             break;
         case "members":
             $value = PRIVACY_MEMBERS;
             break;
         case "public":
             $value = PRIVACY_PUBLIC;
             break;
         default:
             XiptError::assert(0);
     }
     return $value;
 }
Example #24
0
 function uploadAndSetImage($file, $id, $what)
 {
     $mainframe =& JFactory::getApplication();
     CFactory::load('helpers', 'image');
     $config = CFactory::getConfig();
     $uploadLimit = (double) $config->get('maxuploadsize');
     $uploadLimit = $uploadLimit * 1024 * 1024;
     // @rule: Limit image size based on the maximum upload allowed.
     if (filesize($file['tmp_name']) > $uploadLimit) {
         $mainframe->enqueueMessage(XiptText::_('IMAGE_FILE_SIZE_EXCEEDED'), 'error');
         $mainframe->redirect(CRoute::_('index.php?option=com_xipt&view=profiletypes&task=edit&id=' . $id, false));
     }
     if (!cValidImage($file['tmp_name'])) {
         $mainframe->enqueueMessage(XiptText::_('IMAGE_FILE_NOT_SUPPORTED'), 'error');
     } else {
         switch ($what) {
             case 'avatar':
                 $imageMaxWidth = AVATAR_WIDTH;
                 $thumbWidth = AVATAR_WIDTH_THUMB;
                 $thumbHeight = AVATAR_HEIGHT_THUMB;
                 $imgPrefix = 'avatar_';
                 break;
             case 'watermark':
                 $imageMaxWidth = WATERMARK_WIDTH;
                 $thumbWidth = WATERMARK_WIDTH_THUMB;
                 $thumbHeight = WATERMARK_HEIGHT_THUMB;
                 $imgPrefix = 'watermark_';
                 break;
         }
         $storage = PROFILETYPE_AVATAR_STORAGE_PATH;
         $storageImage = $storage . DS . $imgPrefix . $id . cImageTypeToExt($file['type']);
         $storageThumbnail = $storage . DS . $imgPrefix . $id . '_thumb' . cImageTypeToExt($file['type']);
         $image = PROFILETYPE_AVATAR_STORAGE_REFERENCE_PATH . DS . $imgPrefix . $id . cImageTypeToExt($file['type']);
         //$thumbnail			= PROFILETYPE_AVATAR_STORAGE_REFERENCE_PATH . $imgPrefix . $id.'_thumb' . cImageTypeToExt( $file['type'] );
         //here check if folder exist or not. if not then create it.
         if (JFolder::exists($storage) == false) {
             JFolder::create($storage);
         }
         // Only resize when the width exceeds the max.
         if (!cImageResizePropotional($file['tmp_name'], $storageImage, $file['type'], $imageMaxWidth)) {
             $mainframe->enqueueMessage(XiptText::sprintf('COM_XIPT_ERROR_MOVING_UPLOADED_FILE', $storageImage), 'error');
         }
         // Generate thumbnail
         if (!cImageCreateThumb($file['tmp_name'], $storageThumbnail, $file['type'], $thumbWidth, $thumbHeight)) {
             $mainframe->enqueueMessage(XiptText::sprintf('COM_XIPT_ERROR_MOVING_UPLOADED_FILE', $storageThumbnail), 'error');
         }
         $oldFile = XiptLibProfiletypes::getProfiletypeData($id, $what);
         // If old file is default_thumb or default, we should not remove it.
         if (!Jstring::stristr($oldFile, DEFAULT_AVATAR) && !Jstring::stristr($oldFile, DEFAULT_AVATAR_THUMB) && $oldFile != $image && $oldFile != '') {
             // File exists, try to remove old files first.
             $oldFile = JString::str_ireplace('/', DS, $oldFile);
             //only delete when required
             if (JFile::exists($oldFile)) {
                 JFile::delete($oldFile);
             }
         }
         //here due to extension mismatch we can break the functionality of avatar
         if ($what === 'avatar') {
             /* No need to update thumb here , script will update both avatar and thumb */
             //$newThumb   = XiptHelperImage::getThumbAvatarFromFull($newAvatar);
             $oldAvatar = XiptLibProfiletypes::getProfiletypeData($id, 'avatar');
             $allUsers = XiptLibProfiletypes::getAllUsers($id);
             if ($allUsers) {
                 $filter[] = 'avatar';
                 $newData['avatar'] = $image;
                 $oldData['avatar'] = $oldAvatar;
                 foreach ($allUsers as $userid) {
                     XiptLibProfiletypes::updateUserProfiletypeFilteredData($userid, $filter, $oldData, $newData);
                 }
             }
         }
         //now update profiletype with new avatar or watermark
         if (!XiptFactory::getInstance('profiletypes', 'model')->save(array($what => XiptHelperUtils::getUrlpathFromFilePath($image)), $id)) {
             XiptError::raiseError(__CLASS__ . '.' . __LINE__, XiptText::_("ERROR_IN_DATABASE"));
         }
     }
 }
Example #25
0
 function generateThumbnail($imageName, $filename, $storage, $newData, $config)
 {
     require_once JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'helpers' . DS . 'image.php';
     $fileExt = JFile::getExt($filename);
     $thumbnailName = 'watermark_' . $newData->id . '_thumb.' . $fileExt;
     $storageThumbnail = $storage . DS . $thumbnailName;
     $watermarkPath = $storage . DS . $imageName . '.' . $fileExt;
     $watermarkThumbWidth = $config->get('xiThumbWidth', 80);
     $watermarkThumbHeight = $config->get('xiThumbHeight', 20);
     // create a transparent blank image
     // if type of watermark is text call ImageCreateTrueColor else
     //else call imageCreateTransparent
     if ($config->get('typeofwatermark', '0') == '0') {
         $dstimg = ImageCreateTrueColor($watermarkThumbWidth, $watermarkThumbHeight);
     } else {
         $dstimg = XiptLibImage::imageCreateTransparent($watermarkThumbWidth, $watermarkThumbHeight);
     }
     $watermarkType = XiptHelperImage::getImageType($watermarkPath);
     $srcimg = cImageOpen($watermarkPath, $watermarkType);
     //XITODO : also support other formats
     if (imagecopyresampled($dstimg, $srcimg, 0, 0, 0, 0, $watermarkThumbWidth, $watermarkThumbHeight, $config->get('xiWidth', 64), $config->get('xiHeight', 64))) {
         //fix for permissions
         imagepng($dstimg, $storageThumbnail);
         chmod($storageThumbnail, 0744);
     } else {
         XiptError::raiseWarning('XIPT_THUMB_WAR', 'THUMBNAIL NOT SUPPORTED');
     }
     /*if(!cImageCreateThumb( $watermarkPath , $storageThumbnail , XiptHelperImage::getImageType($watermarkPath),$config->get(xiWidth,64)/2,$config->get(xiHeight,64)/2));
     		$info['msg'] .= sprintf(JText::_('ERROR MOVING UPLOADED FILE') , $storageThumbnail);*/
     return;
 }
Example #26
0
 function load($imgname)
 {
     if (!$imgname) {
         return false;
     }
     $filename1 = stripslashes($this->imgname);
     //XiTODO:: Use php fun rather than manually
     $extension = $this->getExtension($filename1);
     $extension = strtolower($extension);
     if ($extension != "png") {
         XiptError::raiseWarning('XIPT_THUMB_WAR', 'EXTENSION NOT SUPPORTED');
     } else {
         $uploadedfile = $this->imgpath;
         $src = imagecreatefrompng($uploadedfile);
     }
     return $src;
 }
Example #27
0
 function resetUserAvatar($pid, $newavatar, $oldavatar, $newavatarthumb)
 {
     //get all users for profiletype
     $users = XiptLibProfiletypes::getAllUsers($pid);
     //Change all avatar and thumb path in url formate
     $newavatar = XiptHelperUtils::getUrlpathFromFilePath($newavatar);
     $newavatarthumb = XiptHelperUtils::getUrlpathFromFilePath($newavatarthumb);
     $cnt = count($users);
     for ($i = 0; $i < $cnt; $i++) {
         //if user is admin unset value
         if (XiptHelperUtils::isAdmin($users[$i])) {
             unset($users[$i]);
         }
     }
     $users = array_values($users);
     $cnt = count($users);
     if ($cnt > 0) {
         // XITODO : Change IN query to sub query
         //update user avatar and thumb of all users who doesn't have custom avatar
         $query = new XiptQuery();
         $result = $query->update('#__community_users')->set(" avatar = '{$newavatar}' ")->set(" thumb = '{$newavatarthumb}' ")->where(" avatar = '{$oldavatar}' ")->where(" userid  IN (" . implode(",", $users) . ") ")->dbLoadQuery()->query();
         if (!$result) {
             return XiptError::raiseWarning(500, XiptText::_("ERROR_IN_DATABASE_WHEN_SAVING_AVATAR_IN_COMMUNITY_USER_TABLE"));
         }
         return true;
     }
 }
Example #28
0
/**
* @Copyright Ready Bytes Software Labs Pvt. Ltd. (C) 2010- author-Team Joomlaxi
* @license GNU/GPL http://www.gnu.org/copyleft/gpl.html
*@TODO : Include all helper files or other files in one common file and include that file
**/
// no direct access
if (!defined('_JEXEC')) {
    die('Restricted access');
}
// add include files
require_once JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_xipt' . DS . 'includes.php';
// check for jom social supported version and show message
if (!XiptHelperJomsocial::isSupportedJS()) {
    $msg = "ERROR : The JomSocial Current Version used by you is not supported for ProfileTypes.";
    JFactory::getApplication()->enqueueMessage($msg);
}
$controller = JRequest::getCmd('view', 'cpanel');
$controller = JString::strtolower($controller);
$class = 'XiptController' . JString::ucfirst($controller);
// Test if the object really exists in the current context
if (!class_exists($class, true)) {
    XiptError::raiseError(__CLASS__ . '.' . __LINE__, sprintf(XiptText_("INVALID_CONTROLLER_OBJECT_CLASS_DEFINITION_DOES_NOT_EXISTS_IN_THIS_CONTEXT"), $class));
}
$controller = new $class();
// Perform the Request task
$task = JRequest::getCmd('task', 'display');
// Task's are methods of the controller. Perform the Request task
$controller->execute($task);
// Redirect if set by the controller
$controller->redirect();
Example #29
0
 function showWatermarkOverImage($imagePath, $watermarkPath, $newImageName = "tmp", $position = 'bl')
 {
     XiptError::assert(JFile::exists($imagePath) && JFile::exists($watermarkPath), XiptText::_("FILE {$imagePath} AND {$watermarkPath} DOES NOT EXIST"), XiptError::ERROR);
     //original image
     $destinationType = self::getImageType($imagePath);
     $watermarkType = self::getImageType($watermarkPath);
     // Load image helper library as it is needed.
     require_once JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'helpers' . DS . 'image.php';
     $watermarkImage = cImageOpen($watermarkPath, $watermarkType);
     /*if(JFolder::exists(PROFILETYPE_AVATAR_STORAGE_REFERENCE_PATH)==false)
     			JFolder::create(PROFILETYPE_AVATAR_STORAGE_REFERENCE_PATH);
     			
     		JFile::copy($imagePath,$newImagePath);*/
     $imageImage = cImageOpen($imagePath, $destinationType);
     /*calculate watermark height and width from watermark image */
     $watermarkWidth = imagesx($watermarkImage);
     $watermarkHeight = imagesy($watermarkImage);
     /*get original image size */
     $size = getimagesize($imagePath);
     $dest_x = 0;
     //$size[0] - $watermarkWidth - 5;
     $dest_y = 0;
     //$size[1] - $watermarkHeight - 5;
     $xy = array();
     $xy[0] =& $dest_x;
     $xy[1] =& $dest_y;
     $watermarkSize = array();
     $watermarkSize[0] = $watermarkWidth;
     $watermarkSize[1] = $watermarkHeight;
     self::setPosotion($size, $watermarkSize, $watermarkImage, $position, $xy);
     imagecopymerge($imageImage, $watermarkImage, $dest_x, $dest_y, 0, 0, $watermarkSize[0], $watermarkSize[1], 100);
     /*first copy the image to tmp location , b'coz we don't want to destroy original image */
     $newImagePath = PROFILETYPE_AVATAR_STORAGE_PATH . DS . $newImageName . '.' . JFile::getExt($imagePath);
     $newImageRefPath = PROFILETYPE_AVATAR_STORAGE_REFERENCE_PATH . DS . $newImageName . '.' . JFile::getExt($imagePath);
     imagesavealpha($imageImage, true);
     ob_start();
     // Test if type is png
     if ($destinationType == 'image/png' || $destinationType == 'image/x-png') {
         imagepng($imageImage);
     } elseif ($destinationType == 'image/gif') {
         imagegif($imageImage);
     } else {
         // We default to use jpeg
         imagejpeg($imageImage, null, 100);
     }
     $output = ob_get_contents();
     ob_end_clean();
     JFile::write($newImagePath, $output);
     // Free any memory from the existing image resources
     imagedestroy($imageImage);
     imagedestroy($watermarkImage);
     return $output ? $newImageRefPath : false;
 }
Example #30
0
 function bind($data)
 {
     if (is_object($data)) {
         $this->aclparams->bind($data->aclparams);
         $this->coreparams->bind($data->coreparams);
         $this->rulename = $data->rulename;
         $this->published = $data->published;
         $this->id = $data->id;
         return $this;
     }
     if (is_array($data)) {
         //XiTODO:: need to test for Joomla 1.5
         $aclParam = $data['aclparams']->toArray();
         $coreParams = $data['coreparams']->toArray();
         $this->aclparams->bind($aclParam);
         $this->coreparams->bind($coreParams);
         //$this->aclparams->bind($data['aclparams']);
         //$this->coreparams->bind($data['coreparams']);
         $this->rulename = $data['rulename'];
         $this->published = $data['published'];
         $this->id = $data['id'];
         return $this;
     }
     //Any issue
     XiptError::assert(0);
 }