Exemplo n.º 1
0
 /**
  * Open, parse, and return the template file.
  *
  * @param $file string the template file name
  */
 public function fetch($file = null)
 {
     $template = new CTemplateHelper();
     $tmpFile = $file;
     if (empty($file)) {
         $file = $this->file;
     }
     if ($this->mobileTemplate()) {
         $file = $template->getMobileTemplateFile($file);
     } else {
         $file = $template->getTemplateFile($file);
     }
     // Template variable: $my;
     $my = CFactory::getUser();
     $this->setRef('my', $my);
     // Template variable: $config;
     if (!isset($this->vars['config']) && empty($this->vars['config'])) {
         $this->vars['config'] = CFactory::getConfig();
     }
     // Template variable: the rest.
     if ($this->vars) {
         extract($this->vars, EXTR_REFS);
     }
     if (!JFile::exists($file)) {
         $mainframe =& JFactory::getApplication();
         $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_TEMPLATE_FILE_NOT_FOUND', $tmpFile . '.php'), 'error');
         return;
     }
     ob_start();
     // Start output buffering
     require $file;
     // Include the file
     $contents = ob_get_contents();
     // Get the contents of the buffer
     ob_end_clean();
     // End buffering and discard
     // Replace all _QQQ_ to "
     // Language file now uses new _QQQ_ to maintain Joomla 1.6 compatibility
     $contents = CTemplate::quote($contents);
     return $contents;
     // Return the contents
 }
Exemplo n.º 2
0
 /**
  * Open, parse, and return the template file.
  *
  * @param $file string the template file name
  * @param $folder if exists, like the file to view
  * @return type
  */
 public function fetch($file = null)
 {
     if (empty($file)) {
         $file = $this->file;
     }
     $tplFile = $this->_getTemplateFile('layouts/' . $file);
     if ($tplFile) {
         // Template variable: $my;
         $my = CFactory::getUser();
         $this->setRef('my', $my);
         // set Up admin var
         $this->set('isCommunityAdmin', COwnerHelper::isCommunityAdmin());
         // Template variable: $config;
         if (!isset($this->_vars['config']) && empty($this->vars['config'])) {
             $this->_vars['config'] = CFactory::getConfig();
         }
         // Template variable: the rest.
         if ($this->_vars) {
             extract($this->_vars, EXTR_REFS);
         }
         ob_start();
         // Start output buffering
         require $tplFile;
         // Include the file
         $contents = ob_get_contents();
         // Get the contents of the buffer
         ob_end_clean();
         // End buffering and discard
         // Replace all _QQQ_ to "
         // Language file now uses new _QQQ_ to maintain Joomla 1.6 compatibility
         $contents = CTemplate::quote($contents);
         return $contents;
         // Return the contents
     }
     return '';
 }
Exemplo n.º 3
0
 /**
  * Perform necessary formatting on the title for display in the stream
  * @param type $row 
  */
 private function _formatTitle($row)
 {
     // We will need to replace _QQQ_ here since
     // CKses will reformat the link
     $row->title = CTemplate::quote($row->title);
     // If the title start with actor's name, and it is a normal status, remove them!
     // Otherwise, leave it as the old style
     if (strpos($row->title, '<a class="actor-link"') !== false && isset($row->actor) && $row->app == 'profile') {
         $pattern = '/(<a class="actor-link".*?' . '>.*?<\\/a>)/';
         $row->title = preg_replace($pattern, '', $row->title);
     }
     return CKses::kses($row->title, CKses::allowed());
 }
Exemplo n.º 4
0
 /**
  * Saves a user's profile
  *
  * @access	private
  * @param	none
  */
 private function _saveProfile()
 {
     $model = $this->getModel('profile');
     $usermodel = $this->getModel('user');
     $document = JFactory::getDocument();
     $my = CFactory::getUser();
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     $input = CFactory::getInput();
     if ($my->id == 0) {
         return $this->blockUnregister();
     }
     $appsLib = CAppPlugins::getInstance();
     $saveSuccess = $appsLib->triggerEvent('onFormSave', array('jsform-profile-edit'));
     if (empty($saveSuccess) || !in_array(false, $saveSuccess)) {
         $values = array();
         $profiles = $model->getEditableProfile($my->id, $my->getProfileType());
         foreach ($profiles['fields'] as $group => $fields) {
             foreach ($fields as $data) {
                 $fieldValue = new stdClass();
                 // Get value from posted data and map it to the field.
                 // Here we need to prepend the 'field' before the id because in the form, the 'field' is prepended to the id.
                 // Grab raw, unfiltered data
                 $postData = $input->post->get('field' . $data['id'], '', 'RAW');
                 //
                 // Retrieve the privacy data for this particular field.
                 $fieldValue->access = JRequest::getInt('privacy' . $data['id'], 0, 'POST');
                 $fieldValue->value = CProfileLibrary::formatData($data['type'], $postData);
                 if (get_magic_quotes_gpc()) {
                     $fieldValue->value = stripslashes($fieldValue->value);
                 }
                 $values[$data['id']] = $fieldValue;
                 // @rule: Validate custom profile if necessary
                 if (!CProfileLibrary::validateField($data['id'], $data['type'], $values[$data['id']]->value, $data['required'], $data['visible'])) {
                     // If there are errors on the form, display to the user.
                     // If it is a drop down selection, use a different message
                     $message = '';
                     switch ($data['type']) {
                         case 'select':
                             $message = JText::sprintf('COM_COMMUNITY_FIELD_SELECT_EMPTY', $data['name']);
                             break;
                         case 'url':
                             $message = JText::sprintf('COM_COMMUNITY_FIELD_INVALID_URL', $data['name']);
                             break;
                         default:
                             $data['value'] = $values[$data['id']]->value;
                             $message = CProfileLibrary::getErrorMessage($data);
                     }
                     $mainframe->enqueueMessage(CTemplate::quote($message), 'error');
                     return false;
                 }
             }
         }
         // Rebuild new $values with field code
         $valuesCode = array();
         foreach ($values as $key => $val) {
             $fieldCode = $model->getFieldCode($key);
             if ($fieldCode) {
                 // For backward compatibility, we can't pass in an object. We need it to behave
                 // like 1.8.x where we only pass values.
                 $valuesCode[$fieldCode] = $val->value;
             }
         }
         $saveSuccess = false;
         $appsLib = CAppPlugins::getInstance();
         $appsLib->loadApplications();
         // Trigger before onBeforeUserProfileUpdate
         $args = array();
         $args[] = $my->id;
         $args[] = $valuesCode;
         $result = $appsLib->triggerEvent('onBeforeProfileUpdate', $args);
         $optionList = $model->getAllList();
         foreach ($optionList as $list) {
             // $optionList return all the list, even if the field is disabled
             // So, need to check if we're using it or not first
             if (isset($values[$list['id']]) && is_array($list['options'])) {
                 $option = $values[$list['id']]->value;
                 $option = str_replace('&amp;', '&', $option);
                 if (JString::strlen(JString::trim($option)) != 0 && !in_array($option, $list['options'])) {
                     if (!in_array($option, CProfile::getCountryList())) {
                         $result[] = false;
                     }
                 }
             }
         }
         // make sure none of the $result is false
         if (!$result || !in_array(false, $result)) {
             $saveSuccess = true;
             $model->saveProfile($my->id, $values);
         }
     }
     // Trigger before onAfterUserProfileUpdate
     $args = array();
     $args[] = $my->id;
     $args[] = $saveSuccess;
     $result = $appsLib->triggerEvent('onAfterProfileUpdate', $args);
     if ($saveSuccess) {
         CUserPoints::assignPoint('profile.save');
         return true;
     } else {
         $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_PROFILE_NOT_SAVED'), 'error');
         return false;
     }
 }
Exemplo n.º 5
0
 /**
  * Saves a user's profile	
  * 	 	
  * @access	private
  * @param	none 
  */
 private function _saveProfile()
 {
     $model =& $this->getModel('profile');
     $usermodel =& $this->getModel('user');
     $document = JFactory::getDocument();
     $my = CFactory::getUser();
     $mainframe =& JFactory::getApplication();
     if ($my->id == 0) {
         return $this->blockUnregister();
     }
     CFactory::load('libraries', 'apps');
     $appsLib =& CAppPlugins::getInstance();
     $saveSuccess = $appsLib->triggerEvent('onFormSave', array('jsform-profile-edit'));
     if (empty($saveSuccess) || !in_array(false, $saveSuccess)) {
         $values = array();
         $profiles = $model->getEditableProfile($my->id, $my->getProfileType());
         CFactory::load('libraries', 'profile');
         foreach ($profiles['fields'] as $group => $fields) {
             foreach ($fields as $data) {
                 $fieldValue = new stdClass();
                 // Get value from posted data and map it to the field.
                 // Here we need to prepend the 'field' before the id because in the form, the 'field' is prepended to the id.
                 $postData = JRequest::getVar('field' . $data['id'], '', 'POST');
                 // Retrieve the privacy data for this particular field.
                 $fieldValue->access = JRequest::getInt('privacy' . $data['id'], 0, 'POST');
                 $fieldValue->value = CProfileLibrary::formatData($data['type'], $postData);
                 $values[$data['id']] = $fieldValue;
                 // @rule: Validate custom profile if necessary
                 if (!CProfileLibrary::validateField($data['id'], $data['type'], $values[$data['id']]->value, $data['required'])) {
                     // If there are errors on the form, display to the user.
                     $message = JText::sprintf('COM_COMMUNITY_FIELD_CONTAIN_IMPROPER_VALUES', $data['name']);
                     $mainframe->enqueueMessage(CTemplate::quote($message), 'error');
                     return;
                 }
             }
         }
         // Rebuild new $values with field code
         $valuesCode = array();
         foreach ($values as $key => $val) {
             $fieldCode = $model->getFieldCode($key);
             if ($fieldCode) {
                 // For backward compatibility, we can't pass in an object. We need it to behave
                 // like 1.8.x where we only pass values.
                 $valuesCode[$fieldCode] = $val->value;
             }
         }
         $saveSuccess = false;
         $appsLib =& CAppPlugins::getInstance();
         $appsLib->loadApplications();
         // Trigger before onBeforeUserProfileUpdate
         $args = array();
         $args[] = $my->id;
         $args[] = $valuesCode;
         $result = $appsLib->triggerEvent('onBeforeProfileUpdate', $args);
         // make sure none of the $result is false
         if (!$result || !in_array(false, $result)) {
             $saveSuccess = true;
             $model->saveProfile($my->id, $values);
         }
     }
     // Trigger before onAfterUserProfileUpdate
     $args = array();
     $args[] = $my->id;
     $args[] = $saveSuccess;
     $result = $appsLib->triggerEvent('onAfterProfileUpdate', $args);
     if ($saveSuccess) {
         CFactory::load('libraries', 'userpoints');
         CUserPoints::assignPoint('profile.save');
         $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_PROFILE_SAVED'));
     } else {
         $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_PROFILE_NOT_SAVED'), 'error');
     }
 }