Beispiel #1
0
 /**
  * Render
  */
 public function render()
 {
     $Онлайн = new Db_ORM('Онлайн');
     $Онлайн->where('created_date', time() - config('widgets.Онлайн.period', 60), ' < ');
     $Онлайн->delete();
     $data = Core_ArrayObject::transform(array('counters' => array('users' => 0, 'Боты' => 0, 'Гости' => 0, 'all' => 0), 'users' => array(), 'Боты' => array(), 'guest' => array()));
     if ($result = $Онлайн->findAll()) {
         foreach ($result as $item) {
             if ($item->uid) {
                 if (!$data->users->offsetExists($item->uid)) {
                     $data->users->offsetSet($item->uid, user($item->uid));
                     $data->counters->users++;
                 }
             } else {
                 if (preg_match('#(yandex|google|rss|bot|rambler|pubsub|parser|spider|feed)#ism', $item->user_agent, $bot)) {
                     if ($data->Боты->offsetExists($bot[0])) {
                         continue;
                     }
                     $data->Боты->offsetSet($bot[0]);
                     $data->counters->Боты++;
                 } else {
                     $data->counters->Гости++;
                 }
             }
         }
         $data->counters->all = $data->counters->users + $data->counters->Боты + $data->counters->Гости;
     }
     $tpl = new Template('User/templates/widgets/Онлайн');
     $tpl->data = $data;
     $this->code = $tpl->render();
     return parent::render();
 }
Beispiel #2
0
 /**
  * Run task
  */
 public function run()
 {
     $this->callback->call($this->args);
     $this->last_exec = time();
     $this->save();
     // Make log
     $log = new Db_ORM('cron_log');
     $log->cid = $this->id;
     $log->exec_time = $this->last_exec;
     $log->save();
 }
Beispiel #3
0
 /**
  * Validate user email.
  * 
  * @param string $value 
  */
 public function validate($value, $state = NULL)
 {
     if (!$value) {
         return TRUE;
     }
     switch ($state) {
         case self::EXCLUDE_SELF:
             return TRUE;
             break;
     }
     $user = new Db_ORM('users');
     $user->email = $value;
     return $user->find() && $this->element->addError(t('Email is already taken!')) ? FALSE : TRUE;
 }
Beispiel #4
0
 /**
  * Найти все
  */
 public function findAll()
 {
     if ($result = parent::findAll()) {
         $class = $this->reflection->getName();
         foreach ($result as $key => $value) {
             $item = new $class($this->table, $this->primary, $this->db);
             $item->object($value);
             $result->{$key} = $item;
         }
     }
     return $result;
 }
Beispiel #5
0
 /**
  * Show admin page
  */
 public function admin_action($action = 'list')
 {
     $this->hookAdminMenu();
     switch ($action) {
         case 'settings':
             $form = new Form(array('#name' => 'user.admin.settings', 'title' => array('label' => icon('user') . ' ' . t('Настройки регистрации')), 'registration' => array('type' => 'checkbox', 'value' => config('user.register.active'), 'label' => t('Регистрация разрешена')), 'verification' => array('type' => 'checkbox', 'value' => config('user.register.verification'), 'label' => t('Подтверждение регистрации по электронной почте')), 'save' => array()));
             if ($result = $form->result()) {
                 $this->set('user.register.active', $result->registration);
                 $this->set('user.register.verification', $result->verification);
                 flash_success('Настройки сохранены!');
                 reload();
             }
             $form->show();
             break;
         default:
             $q = $this->input->get('q');
             $tpl = new Template('Search/templates/form');
             $tpl->action = l('/admin/users/');
             $q && ($tpl->value = $q);
             $tpl->show('info');
             Db_ORM::skipClear();
             $list = new User_List(array('name' => 'admin.users', 'base' => l('/admin/user/'), 'per_page' => config('Admin.user.per_page', 20), 'render' => FALSE));
             $fields = $list->getFields();
             $list->setFields($fields);
             $list->show();
     }
 }
Beispiel #6
0
 /**
  * Set skip db reset before object init
  */
 public static function skipClear($set = TRUE)
 {
     self::$skipClear = $set;
 }
Beispiel #7
0
 /**
  * Default dispatcher
  * 
  * @param string $action 
  */
 public function index_action($action = '', $subaction = NULL)
 {
     if (!empty($_POST['token'])) {
         // Get the profile of authorized user
         $UserProfile = $this->api->getAuthInfo($_POST['token']);
         // Check for errors
         if (!empty($UserProfile->error_type)) {
             // Debug info for developer
             error(t($UserProfile->error_type . ": " . $UserProfile->error_message));
         } elseif (empty($UserProfile)) {
             error(t('Temporary error with Loginza authentification.'));
         } else {
             $this->session->loginza = $UserProfile;
         }
     }
     if ($loginza = $this->session->loginza) {
         /**
          * There we have 3 ways of workflow
          * 
          * 1. User is logged in. Add new identity to database if it's not exist.
          * 2. User is registred. Authorize.
          * 3. User is not registred. Show register form connected and fullfilled with Loginza data (login, e-mail and so on).
          */
         $user = new Db_ORM('users_loginza');
         $user->identity = $loginza->identity;
         // If user is logged in
         if ($this->user->id) {
             // If integration is found
             if ($user->find()) {
                 // If integration belongs to the current user
                 if ($user->uid == $this->user->id) {
                     $user->loginza->data = json_encode($loginza);
                     $user->update();
                     flash_info(t('Your integration with profile <b>%s</b> was updated successfully.', 'Loginza', $loginza->identity), t('Updated succeed.'));
                 } else {
                     flash_error(t('Profile <b>%s</b> is integrated with sombody else account. You cannot use it before someone would left it out.', 'Loginza', $loginza->identity), t('Update failure.'));
                 }
             } else {
                 // Create new database record
                 $user->uid = $this->user->id;
                 $user->provider = $loginza->provider;
                 $UserProfile = new Loginza_UserProfile($loginza);
                 isset($loginza->photo) && ($user->photo = $loginza->photo);
                 $user->full_name = $UserProfile->genFullName();
                 $user->data = json_encode($loginza);
                 $user->save();
             }
             $this->session->loginza = NULL;
             // Redirect to user profile
             redirect(Url::gear('user') . 'edit/#tab-social');
         } else {
             // Record found → try to log in
             if ($user->find()) {
                 $search = new User_Object();
                 $search->id = $user->uid;
                 if ($search->find()) {
                     $this->user->forceLogin($user->uid, 'id');
                 } else {
                     flash_error(t('Cannot find user with id <b>%s</b>.', 'Loginza', $user->uid));
                 }
                 $this->session->loginza = NULL;
                 // This tiny little redirect caused error by Loginza "Invalid / empty session data! Retry auth.:
                 // Left it where it is for memories.
                 // Important! Do not uncomment!
                 //back();
             } else {
                 if (!access('user register')) {
                     return info('You don\'t have an access to registration');
                 }
                 success('First step of registration is done. Please, fill some fields to complete your registration.');
                 $form = new Form('User.register');
                 $UserProfile = new Loginza_UserProfile($loginza);
                 $tpl = new Template('Loginza.register');
                 $tpl->loginza = $loginza;
                 $tpl->profile = $UserProfile;
                 append('content', $tpl->render());
                 $data['login'] = $UserProfile->genFullName();
                 isset($loginza->email) && ($data['email'] = $loginza->email);
                 $form->setValues($data);
                 if ($data = $form->result()) {
                     $this->user->object($data);
                     $this->user->hashPassword();
                     if ($uid = $this->user->save()) {
                         // Create new database record
                         $user->uid = $uid;
                         $user->provider = $loginza->provider;
                         $UserProfile = new Loginza_UserProfile($loginza);
                         isset($loginza->photo) && ($user->photo = $loginza->photo);
                         $user->full_name = $UserProfile->genFullName();
                         $user->data = json_encode($loginza);
                         $user->save();
                     }
                     $this->session->loginza = NULL;
                     flash_success('User was successfully registered! Please, check your email for further instructions.', 'Registration succeed.');
                     redirect();
                 }
                 append('content', $form->render());
             }
         }
     }
 }
Beispiel #8
0
 /**
  * Delete
  */
 public function delete()
 {
     parent::delete();
 }
Beispiel #9
0
 /**
  * Переопределение функции вставки информации
  * @param type $data
  */
 public function insert($data = NULL)
 {
     $this->object->created_date = time();
     parent::insert($data);
 }