示例#1
0
 /**
  * Record migration in migrations table
  *
  * @param   string  $file       The path to file being recorded
  * @param   string  $scope      The folder of migration
  * @param   string  $hash       The hash of file
  * @param   string  $direction  Up or down
  * @param   string  $status     The status of the run
  * @return  bool
  **/
 public function recordMigration($file, $scope, $hash, $direction, $status = 'success')
 {
     // Catch instances where we don't have a status field yet
     // and mimic prior behavior where these runs were not logged
     if (!$this->db->tableHasField($this->get('tbl_name'), 'status') && $status != 'success') {
         return true;
     }
     // Try inserting a migration record into the database
     try {
         $date = new \Hubzero\Utility\Date();
         // Craete our object to insert
         $obj = (object) array('file' => $file, 'hash' => $hash, 'direction' => $direction, 'date' => $date->toSql(), 'action_by' => php_sapi_name() == 'cli' ? exec("whoami") : \User::get('id'));
         if ($this->db->tableHasField($this->get('tbl_name'), 'scope')) {
             $obj->scope = $scope;
         }
         if ($this->db->tableHasField($this->get('tbl_name'), 'status')) {
             $obj->status = $status;
         }
         $this->db->insertObject($this->get('tbl_name'), $obj);
     } catch (\Hubzero\Database\Exception\QueryFailedException $e) {
         $this->log("Failed inserting migration record: {$e->getMessage()}", 'error');
         return false;
     }
 }
示例#2
0
 /**
  * Record migration in migrations table
  *
  * @param   string  $file       the path to file being recorded
  * @param   string  $scope      the folder of migration
  * @param   string  $hash       the hash of file
  * @param   string  $direction  up or down
  * @return  bool
  **/
 public function recordMigration($file, $scope, $hash, $direction)
 {
     // Try inserting a migration record into the database
     try {
         $date = new \Hubzero\Utility\Date();
         // Craete our object to insert
         $obj = (object) array('file' => $file, 'hash' => $hash, 'direction' => $direction, 'date' => $date->toSql(), 'action_by' => php_sapi_name() == 'cli' ? exec("whoami") : \User::get('id'));
         if ($this->db->tableHasField($this->get('tbl_name'), 'scope')) {
             $obj->scope = $scope;
         }
         $this->db->insertObject($this->get('tbl_name'), $obj);
     } catch (\PDOException $e) {
         $this->log("Failed inserting migration record: {$e}", 'error');
         return false;
     }
 }
示例#3
0
            echo $result['title'];
            ?>
</a></h3>

								<div class="result-extras">
									<!-- Cateogory : mandatory -->
									<span class="result-category"><?php 
            echo ucfirst($result['hubtype']);
            ?>
</span>

									<?php 
            if (isset($result['date'])) {
                ?>
										<?php 
                $date = new \Hubzero\Utility\Date($result['date']);
                ?>
										<span class="result-timestamp"><time datetime="<?php 
                echo $result['date'];
                ?>
"><?php 
                echo $date->toLocal('Y-m-d h:mA');
                ?>
</time></span>
									<?php 
            }
            ?>

									<!-- Authors -->
									<?php 
            if (isset($result['author'])) {
示例#4
0
 public function onUserAfterSave($data, $isNew, $result, $error)
 {
     $userId = \Hubzero\Utility\Arr::getValue($data, 'id', 0, 'int');
     if ($userId && $result && isset($data['profile']) && count($data['profile'])) {
         try {
             //Sanitize the date
             if (!empty($data['profile']['dob'])) {
                 $date = new \Hubzero\Utility\Date($data['profile']['dob']);
                 $data['profile']['dob'] = $date->format('Y-m-d');
             }
             $db = App::get('db');
             $db->setQuery('DELETE FROM #__user_profiles WHERE user_id = ' . $userId . " AND profile_key LIKE 'profile.%'");
             if (!$db->query()) {
                 throw new Exception($db->getErrorMsg());
             }
             $tuples = array();
             $order = 1;
             foreach ($data['profile'] as $k => $v) {
                 $tuples[] = '(' . $userId . ', ' . $db->quote('profile.' . $k) . ', ' . $db->quote(json_encode($v)) . ', ' . $order++ . ')';
             }
             $db->setQuery('INSERT INTO `#__user_profiles` VALUES ' . implode(', ', $tuples));
             if (!$db->query()) {
                 throw new Exception($db->getErrorMsg());
             }
         } catch (Exception $e) {
             $this->_subject->setError($e->getMessage());
             return false;
         }
     }
     return true;
 }
示例#5
0
 /**
  * Generates automatic date value
  *
  * @param   array   $data  the data being saved
  * @return  string
  */
 public function automaticDate($data)
 {
     if (!isset($data['date'])) {
         $dt = new \Hubzero\Utility\Date('now');
         $data['date'] = $dt->toSql();
     }
     return $data['date'];
 }
示例#6
0
 /**
  * Set processed timestamp
  *
  * @param   array   $data  the data being saved
  * @return  string
  */
 public function automaticProcessed($data)
 {
     $dt = new \Hubzero\Utility\Date();
     return $dt->toSql();
 }
示例#7
0
 /**
  * Method to save the form data.
  *
  * @param	array		The form data.
  * @return	mixed		The user id on success, false on failure.
  * @since	1.6
  */
 public function register($temp)
 {
     $db = $this->getDbo();
     $params = Component::params('com_users');
     // Initialise the table with JUser.
     $user = new JUser();
     $data = (array) $this->getData();
     // Merge in the registration data.
     foreach ($temp as $k => $v) {
         $data[$k] = $v;
     }
     // Prepare the data for the user object.
     $data['email'] = $data['email1'];
     $data['password'] = $data['password1'];
     $useractivation = $params->get('useractivation');
     $sendpassword = $params->get('sendpassword', 1);
     // Check if the user needs to activate their account.
     if ($useractivation == 1 || $useractivation == 2) {
         $data['activation'] = App::hash(JUserHelper::genRandomPassword());
         $data['block'] = 1;
     }
     // Bind the data.
     if (!$user->bind($data)) {
         $this->setError(Lang::txt('COM_USERS_REGISTRATION_BIND_FAILED', $user->getError()));
         return false;
     }
     // Load the users plugin group.
     Plugin::import('user');
     // Store the data.
     if (!$user->save()) {
         $this->setError(Lang::txt('COM_USERS_REGISTRATION_SAVE_FAILED', $user->getError()));
         return false;
     }
     // Compile the notification mail values.
     $data = $user->getProperties();
     $data['fromname'] = Config::get('fromname');
     $data['mailfrom'] = Config::get('mailfrom');
     $data['sitename'] = Config::get('sitename');
     $data['siteurl'] = Request::root();
     // Handle account activation/confirmation emails.
     if ($useractivation == 2) {
         // Set the link to confirm the user email.
         $uri = JURI::getInstance();
         $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
         $data['activate'] = $base . Route::url('index.php?option=com_users&task=registration.activate&token=' . $data['activation'], false);
         $emailSubject = Lang::txt('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']);
         if ($sendpassword) {
             $emailBody = Lang::txt('COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY', $data['name'], $data['sitename'], $data['activate'], $data['siteurl'], $data['username'], $data['password_clear']);
         } else {
             $emailBody = Lang::txt('COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY_NOPW', $data['name'], $data['sitename'], $data['activate'], $data['siteurl'], $data['username']);
         }
     } elseif ($useractivation == 1) {
         // Set the link to activate the user account.
         $uri = JURI::getInstance();
         $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
         $data['activate'] = $base . Route::url('index.php?option=com_users&task=registration.activate&token=' . $data['activation'], false);
         $emailSubject = Lang::txt('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']);
         if ($sendpassword) {
             $emailBody = Lang::txt('COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY', $data['name'], $data['sitename'], $data['activate'], $data['siteurl'], $data['username'], $data['password_clear']);
         } else {
             $emailBody = Lang::txt('COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY_NOPW', $data['name'], $data['sitename'], $data['activate'], $data['siteurl'], $data['username']);
         }
     } else {
         $emailSubject = Lang::txt('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']);
         $emailBody = Lang::txt('COM_USERS_EMAIL_REGISTERED_BODY', $data['name'], $data['sitename'], $data['siteurl']);
     }
     // Send the registration email.
     $return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody);
     //Send Notification mail to administrators
     if ($params->get('useractivation') < 2 && $params->get('mail_to_admin') == 1) {
         $emailSubject = Lang::txt('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']);
         $emailBodyAdmin = Lang::txt('COM_USERS_EMAIL_REGISTERED_NOTIFICATION_TO_ADMIN_BODY', $data['name'], $data['username'], $data['siteurl']);
         // get all admin users
         $query = 'SELECT name, email, sendEmail' . ' FROM #__users' . ' WHERE sendEmail=1';
         $db->setQuery($query);
         $rows = $db->loadObjectList();
         // Send mail to all superadministrators id
         foreach ($rows as $row) {
             $return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $row->email, $emailSubject, $emailBodyAdmin);
             // Check for an error.
             if ($return !== true) {
                 $this->setError(Lang::txt('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'));
                 return false;
             }
         }
     }
     // Check for an error.
     if ($return !== true) {
         $this->setError(Lang::txt('COM_USERS_REGISTRATION_SEND_MAIL_FAILED'));
         // Send a system message to administrators receiving system mails
         $db = App::get('db');
         $q = "SELECT id\n\t\t\t\tFROM #__users\n\t\t\t\tWHERE block = 0\n\t\t\t\tAND sendEmail = 1";
         $db->setQuery($q);
         $sendEmail = $db->loadColumn();
         if (count($sendEmail) > 0) {
             $jdate = new \Hubzero\Utility\Date();
             // Build the query to add the messages
             $q = "INSERT INTO " . $db->quoteName('#__messages') . " (" . $db->quoteName('user_id_from') . ", " . $db->quoteName('user_id_to') . ", " . $db->quoteName('date_time') . ", " . $db->quoteName('subject') . ", " . $db->quoteName('message') . ") VALUES ";
             $messages = array();
             foreach ($sendEmail as $userid) {
                 $messages[] = "(" . $userid . ", " . $userid . ", '" . $jdate->toSql() . "', '" . Lang::txt('COM_USERS_MAIL_SEND_FAILURE_SUBJECT') . "', '" . Lang::txt('COM_USERS_MAIL_SEND_FAILURE_BODY', $return, $data['username']) . "')";
             }
             $q .= implode(',', $messages);
             $db->setQuery($q);
             $db->query();
         }
         return false;
     }
     if ($useractivation == 1) {
         return "useractivate";
     } elseif ($useractivation == 2) {
         return "adminactivate";
     } else {
         return $user->id;
     }
 }