Advertisement
Guest User

overide neofrag

a guest
Mar 30th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.20 KB | None | 0 0
  1. <?php if (!defined('NEOFRAG_CMS')) exit;
  2. /**************************************************************************
  3. Copyright © 2015 Michaël BILCOT & Jérémy VALENTIN
  4.  
  5. This file is part of NeoFrag.
  6.  
  7. NeoFrag is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU Lesser General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11.  
  12. NeoFrag is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU Lesser General Public License for more details.
  16.  
  17. You should have received a copy of the GNU Lesser General Public License
  18. along with NeoFrag. If not, see <http://www.gnu.org/licenses/>.
  19. **************************************************************************/
  20.  
  21. class o_m_members_c_admin extends Controller_Module
  22. {
  23.     public function index($members)
  24.     {
  25.         $table_groups = $this
  26.             ->load->library('table')
  27.             ->add_columns(array(
  28.                 array(
  29.                     'content' => function($data){
  30.                         return NeoFrag::loader()->groups->display($data['data_id']);
  31.                     },
  32.                     'search'  => function($data){
  33.                         return NeoFrag::loader()->groups->display($data['data_id'], FALSE, FALSE);
  34.                     },
  35.                     'sort'    => function($data){
  36.                         return NeoFrag::loader()->groups->display($data['data_id'], FALSE, FALSE);
  37.                     }
  38.                 ),
  39.                 array(
  40.                     'content' => array(
  41.                         function($data){
  42.                             return button_edit('admin/members/groups/edit/'.$data['url'].'.html');
  43.                         },
  44.                         function($data){
  45.                             if (!$data['auto'])
  46.                             {
  47.                                 return button_delete('admin/members/groups/delete/'.$data['url'].'.html');
  48.                             }
  49.                         }
  50.                     )
  51.                 )
  52.             ))
  53.             ->data($this->groups())
  54.             ->pagination(FALSE)
  55.             ->save();
  56.  
  57.         $table_users = $this
  58.             ->table
  59.             ->add_columns(array(
  60.                 array(
  61.                     'title'   => $this('member'),
  62.                     'content' => function($data){
  63.                         return NeoFrag::loader()->user->link($data['user_id'], $data['username']);
  64.                     },
  65.                     'sort'    => function($data){
  66.                         return $data['username'];
  67.                     },
  68.                     'search'  => function($data){
  69.                         return $data['username'];
  70.                     }
  71.                 ),
  72.                 array(
  73.                     'title'   => $this('email'),
  74.                     'content' => function($data){
  75.                         return '<a href="mailto:'.$data['email'].'">'.$data['email'].'</a>';
  76.                     },
  77.                     'sort'    => function($data){
  78.                         return $data['email'];
  79.                     },
  80.                     'search'  => function($data){
  81.                         return $data['email'];
  82.                     }
  83.                 ),
  84.                 array(
  85.                     'title'   => $this('groups'),
  86.                     'content' => function($data){
  87.                         return NeoFrag::loader()->groups->user_groups($data['user_id']);
  88.                     },
  89.                     'sort'    => function($data){
  90.                         return NeoFrag::loader()->groups->user_groups($data['user_id'], FALSE);
  91.                     },
  92.                     'search'  => function($data){
  93.                         return NeoFrag::loader()->groups->user_groups($data['user_id'], FALSE);
  94.                     }
  95.                 ),
  96.                 array(
  97.                     'title'   => $this('registration_date'),
  98.                     'content' => function($data){
  99.                         return '<span data-toggle="tooltip" title="'.timetostr(NeoFrag::loader()->lang('date_time_long'), $data['registration_date']).'">'.time_span($data['registration_date']).'</span>';
  100.                     },
  101.                     'sort'    => function($data){
  102.                         return $data['registration_date'];
  103.                     }
  104.                 ),
  105.                 array(
  106.                     'title'   => $this('last_activity'),
  107.                     'content' => function($data){
  108.                         return '<span data-toggle="tooltip" title="'.timetostr(NeoFrag::loader()->lang('date_time_long'), $data['last_activity_date']).'">'.time_span($data['last_activity_date']).'</span>';
  109.                     },
  110.                     'sort'    => function($data){
  111.                         return $data['last_activity_date'];
  112.                     }
  113.                 ),
  114.                 array(
  115.                     'content' => array(
  116.                         function($data, $loader){
  117.                             return button('admin/members/ban/'.$data['user_id'].'/'.url_title($data['username']).'.html', 'fa-ban', $loader->lang('ban'), 'warning');
  118.                         },
  119.                         function($data){
  120.                             return button_edit('admin/members/'.$data['user_id'].'/'.url_title($data['username']).'.html');
  121.                         },
  122.                         function($data){
  123.                             return button_delete('admin/members/delete/'.$data['user_id'].'/'.url_title($data['username']).'.html');
  124.                         }
  125.                     )
  126.                 )
  127.             ))
  128.             ->data($members)
  129.             ->save();
  130.        
  131.         return new Row(
  132.             new Col(
  133.                 new Panel(array(
  134.                     'title'   => $this('groups'),
  135.                     'icon'    => 'fa-users',
  136.                     'content' => $table_groups->display(),
  137.                     'footer'  => button_add('admin/members/groups/add.html', $this('add_group')),
  138.                     'size'    => 'col-md-12 col-lg-3'
  139.                 ))
  140.             ),
  141.             new Col(
  142.                 new Panel(array(
  143.                     'title'   => $this('members'),
  144.                     'icon'    => 'fa-users',
  145.                     'content' => $table_users->display(),
  146.                     'size'    => 'col-md-12 col-lg-9'
  147.                 ))
  148.             )
  149.         );
  150.     }
  151.  
  152.     public function _edit($member_id, $username, $email, $groups, $first_name, $last_name, $avatar, $signature, $date_of_birth, $sex, $location, $website, $quote)
  153.     {
  154.         $form_member = $this
  155.             ->title($this('edit_member'))
  156.             ->subtitle($username)
  157.             ->css('groups')
  158.             ->load->library('form')
  159.             ->add_rules('members', array(
  160.                 'username'      => $username,
  161.                 'email'         => $email,
  162.                 'first_name'    => $first_name,
  163.                 'last_name'     => $last_name,
  164.                 'avatar'        => $avatar,
  165.                 'signature'     => $signature,
  166.                 'date_of_birth' => $date_of_birth,
  167.                 'sex'           => $sex,
  168.                 'location'      => $location,
  169.                 'website'       => $website,
  170.                 'quote'         => $quote
  171.             ))
  172.             ->add_submit($this('edit'))
  173.             ->add_back('admin/members.html')
  174.             ->save();
  175.            
  176.         $form_groups = $this
  177.             ->form
  178.             ->add_rules(array(
  179.                 'groups' => array(
  180.                     'type'   => 'checkbox',
  181.                     'values' => array_filter($this->groups(), function($group){
  182.                         return !$group['auto'] || $group['auto'] == 'neofrag' || !is_null($group['users']);
  183.                     }),
  184.                     'rules'  => 'required'
  185.                 )
  186.             ))
  187.             ->save();
  188.            
  189.         $activities = '';
  190.            
  191.         $sessions = $this
  192.             ->load->library('table')
  193.             ->add_columns(array(
  194.                 array(
  195.                     'content' => function($data){
  196.                         return '<div style="text-align: center;">'.user_agent($data['user_agent']).'</div>';
  197.                     },
  198.                     'size'    => '56px'
  199.                 ),
  200.                 array(
  201.                     'title'   => $this('ip_address'),
  202.                     'content' => function($data){
  203.                         return geolocalisation($data['ip_address']).'<span data-toggle="tooltip" data-original-title="'.$data['host_name'].'">'.$data['ip_address'].'</span>';
  204.                     }
  205.                 ),
  206.                 array(
  207.                     'title'   => $this('referer'),
  208.                     'content' => function($data, $loader){
  209.                         return $data['referer'] ? urltolink($data['referer']) : $loader->lang('none');
  210.                     }
  211.                 ),
  212.                 array(
  213.                     'title'   => $this('arrival_date'),
  214.                     'content' => function($data){
  215.                         return '<span data-toggle="tooltip" title="'.timetostr(NeoFrag::loader()->lang('date_time_long'), $data['date']).'">'.time_span($data['date']).'</span>';
  216.                     }
  217.                 ),
  218.                 array(
  219.                     'title'   => $this('last_activity'),
  220.                     'content' => function($data){
  221.                         return '<span data-toggle="tooltip" title="'.timetostr(NeoFrag::loader()->lang('date_time_long'), $data['last_activity']).'">'.time_span($data['last_activity']).'</span>';
  222.                     }
  223.                 ),
  224.                 array(
  225.                     'content' => array(
  226.                         function($data){
  227.                             return button_delete('admin/members/sessions/delete/'.$data['session_id'].'.html');
  228.                         }
  229.                     )
  230.                 )
  231.             ))
  232.             ->data($this->user->get_sessions($member_id))
  233.             ->no_data($this('no_session'))
  234.             ->display();
  235.        
  236.         if ($form_member->is_valid($post))
  237.         {
  238.             $this->model()->edit_member(
  239.                 $member_id,
  240.                 $post['username'],
  241.                 $post['email'],
  242.                 $post['first_name'],
  243.                 $post['last_name'],
  244.                 $post['avatar'],
  245.                 $post['date_of_birth'],
  246.                 $post['sex'],
  247.                 $post['location'],
  248.                 $post['website'],
  249.                 $post['quote'],
  250.                 $post['signature']
  251.             );
  252.            
  253.             //add_alert('succes', 'membre édité');
  254.  
  255.             redirect_back('admin/members.html');
  256.         }
  257.         else if ($form_groups->is_valid($post))
  258.         {
  259.             $this->model()->edit_groups(
  260.                 $member_id,
  261.                 $post['groups']
  262.             );
  263.  
  264.             //add_alert('succes', 'groupes du membre édités');
  265.  
  266.             redirect_back('admin/members.html');
  267.         }
  268.        
  269.         return new Row(
  270.             new Col(
  271.                 new Panel(array(
  272.                     'title'   => $this('edit_member'),
  273.                     'icon'    => 'fa-user',
  274.                     'content' => $form_member->display(),
  275.                     'size'    => 'col-md-12 col-lg-7'
  276.                 ))
  277.             ),
  278.             new Col(
  279.                 new Panel(array(
  280.                     'title'   => $this('groups'),
  281.                     'icon'    => 'fa-users',
  282.                     'content' => $this->load->view('groups', array(
  283.                         'user_id' => $member_id,
  284.                         'form_id' => $form_groups->id
  285.                     )),
  286.                     'footer'  => '<button class="btn btn-outline btn-primary">'.icon('fa-check').' '.$this('save').'</button>',
  287.                     'form'    => TRUE,
  288.                     'size'    => 'col-md-12 col-lg-5'
  289.                 )),
  290.                 /*new Panel(array(
  291.                     'title'   => 'Dernières activités',
  292.                     'icon'    => 'fa-history',
  293.                     'content' => $activities,
  294.                     'size'    => 'col-md-12 col-lg-5'
  295.                 )),*/
  296.                 new Panel(array(
  297.                     'title'   => $this('active_sessions'),
  298.                     'icon'    => 'fa-globe',
  299.                     'content' => $sessions,
  300.                     'size'    => 'col-md-12 col-lg-5'
  301.                 ))
  302.             )
  303.         );
  304.     }
  305.  
  306.     public function delete($user_id, $username)
  307.     {
  308.         $this   ->title($this('delete_confirmation'))
  309.                 ->load->library('form')
  310.                 ->confirm_deletion($this('delete_confirmation'), $this('user_delete_message', $username));
  311.  
  312.         if ($this->form->is_valid())
  313.         {
  314.             $this->db   ->where('user_id', $user_id)
  315.                         ->update('nf_users', array('username'  => 'old-'.$username,
  316.                                                    'password'  => '99a30df0f2488360cdd46b4b88e5f5f0',
  317.                                                    'email'     => $user_id.'@neofrag.fr',
  318.                                                    'admin'     => FALSE));
  319.  
  320.  
  321.             $this->db   ->where('user_id', $user_id)
  322.                         ->delete('nf_users_groups');
  323.  
  324.             $this->db->insert('nf_users_groups', array(
  325.                     'user_id'  => $user_id,
  326.                     'group_id' => "4"
  327.                 ));
  328.  
  329.             $this->db   ->where('user_id', $user_id)
  330.                         ->delete('nf_sessions');
  331.  
  332.             return 'OK';
  333.         }
  334.  
  335.         echo $this->form->display();
  336.     }
  337.    
  338.     public function _ban($member_id = 0, $username = '')
  339.     {
  340.         $this   ->title($this('ban_title'))
  341.                 ->icon('fa-bomb');
  342.        
  343.         return new Panel(array(
  344.             'title'   => $this('ban_title'),
  345.             'icon'    => 'fa-bomb',
  346.             'style'   => 'panel-info',
  347.             'content' => $this('unavailable_feature'),
  348.             'size'    => 'col-md-12'
  349.         ));
  350.     }
  351.    
  352.     public function _groups_add()
  353.     {
  354.         $this   ->title($this('groups'))
  355.                 ->subtitle($this('add'))
  356.                 ->load->library('form')
  357.                 ->add_rules('groups')
  358.                 ->add_back('admin/members.html')
  359.                 ->add_submit($this('add'));
  360.  
  361.         if ($this->form->is_valid($post))
  362.         {
  363.             $this->model('groups')->add_group(
  364.                 $post['title'],
  365.                 $post['color'],
  366.                 $post['icon'],
  367.                 $this->config->lang
  368.             );
  369.  
  370.             //add_alert('success', $this('group_added'));
  371.  
  372.             redirect_back('admin/members.html');
  373.         }
  374.  
  375.         return new Panel(array(
  376.             'title'   => $this('add_group'),
  377.             'icon'    => 'fa-users',
  378.             'content' => $this->form->display(),
  379.             'size'    => 'col-md-12'
  380.         ));
  381.     }
  382.    
  383.     public function _groups_edit($group_id, $name, $title, $color, $icon, $auto)
  384.     {
  385.         $this   ->title($this('groups'))
  386.                 ->subtitle($this('edit'))
  387.                 ->load->library('form')
  388.                 ->add_rules('groups', array(
  389.                     'title' => $title,
  390.                     'color' => $color,
  391.                     'icon'  => $icon,
  392.                     'auto'  => $auto
  393.                 ))
  394.                 ->add_back('admin/members.html')
  395.                 ->add_submit($this('edit'));
  396.  
  397.         if ($this->form->is_valid($post))
  398.         {
  399.             if ($group_id)
  400.             {
  401.                 $this->model('groups')->edit_group(
  402.                     $group_id,
  403.                     $post['title'],
  404.                     $post['color'],
  405.                     $post['icon'],
  406.                     $this->config->lang,
  407.                     $auto
  408.                 );
  409.             }
  410.             else
  411.             {
  412.                 $this->db->insert('nf_groups', array(
  413.                     'name'  => $name,
  414.                     'color' => $post['color'],
  415.                     'icon'  => $post['icon'],
  416.                     'auto'  => TRUE
  417.                 ));
  418.             }
  419.  
  420.             //add_alert('success', $this('group_edited'));
  421.  
  422.             redirect_back('admin/members.html');
  423.         }
  424.  
  425.         return new Panel(array(
  426.             'title'   => $this('edit_group_title'),
  427.             'icon'    => 'fa-users',
  428.             'content' => $this->form->display(),
  429.             'size'    => 'col-md-12'
  430.         ));
  431.     }
  432.  
  433.     public function _groups_delete($group_id, $title)
  434.     {
  435.         $this   ->title($this('delete_confirmation'))
  436.                 ->load->library('form')
  437.                 ->confirm_deletion($this('delete_confirmation'), $this('group_delete_message', $title));
  438.  
  439.         if ($this->form->is_valid())
  440.         {
  441.             $this->db   ->where('group_id', $group_id)
  442.                         ->delete('nf_groups');
  443.  
  444.             $this->access->revoke($group_id);
  445.  
  446.             return 'OK';
  447.         }
  448.  
  449.         echo $this->form->display();
  450.     }
  451.    
  452.     public function _sessions($sessions)
  453.     {
  454.         $this   ->title($this('sessions'))
  455.                 ->subtitle($this('list_active_sessions'))
  456.                 ->icon('fa-globe')
  457.                 ->load->library('table')
  458.                 ->preprocessing(function($row){
  459.                     $user_data = unserialize($row['user_data']);
  460.                    
  461.                     $row['date']       = $user_data['session']['date'];
  462.                     $row['history']    = array_reverse($user_data['session']['history']);
  463.                     $row['user_agent'] = $user_data['session']['user_agent'];
  464.                     $row['referer']    = $user_data['session']['referer'];
  465.                
  466.                     unset($row['user_data']);
  467.                    
  468.                     return $row;
  469.                 })
  470.                 ->add_columns(array(
  471.                     array(
  472.                         'content' => function($data){
  473.                             return $data['remember_me'] ? '<i class="fa fa-toggle-on text-green" data-toggle="tooltip" title="Connexion persistante"></i>' : '<i class="fa fa-toggle-off text-grey" data-toggle="tooltip" title="Connexion non persistante"></i>';
  474.                         },
  475.                         'size'    => TRUE,
  476.                         'align'   => 'center'
  477.                     ),
  478.                     array(
  479.                         'title'   => $this('user'),
  480.                         'content' => function($data, $loader){
  481.                             return $data['user_id'] ? NeoFrag::loader()->user->link($data['user_id'], $data['username']) : '<i>'.$loader->lang('guest').'</i>';
  482.                         },
  483.                         'search'  => function($data, $loader){
  484.                             return $data['user_id'] ? $data['username'] : $loader->lang('guest');
  485.                         },
  486.                         'sort'  => function($data, $loader){
  487.                             return $data['user_id'] ? $data['username'] : $loader->lang('guest');
  488.                         }
  489.                     ),
  490.                     array(
  491.                         'content' => function($data){
  492.                             return user_agent($data['user_agent']);
  493.                         },
  494.                         'size'    => TRUE,
  495.                         'align'   => 'center',
  496.                         'search'  => function($data){
  497.                             return $data['user_agent'];
  498.                         },
  499.                         'sort'    => function($data){
  500.                             return $data['user_agent'];
  501.                         }
  502.                     ),
  503.                     array(
  504.                         'title'   => $this('ip_address'),
  505.                         'content' => function($data){
  506.                             return geolocalisation($data['ip_address']).'<span data-toggle="tooltip" data-original-title="'.$data['host_name'].'">'.$data['ip_address'].'</span>';
  507.                         },
  508.                         'search'  => function($data){
  509.                             return $data['ip_address'];
  510.                         },
  511.                         'sort'    => function($data){
  512.                             return $data['ip_address'];
  513.                         }
  514.                     ),
  515.                     array(
  516.                         'title'   => $this('referer'),
  517.                         'content' => function($data, $loader){
  518.                             return $data['referer'] ? urltolink($data['referer']) : $loader->lang('none');
  519.                         },
  520.                         'search'  => function($data){
  521.                             return $data['user_agent'];
  522.                         },
  523.                         'sort'    => function($data){
  524.                             return $data['user_agent'];
  525.                         }
  526.                     ),
  527.                     array(
  528.                         'title'   => $this('arrival_date'),
  529.                         'content' => function($data){
  530.                             return '<span data-toggle="tooltip" title="'.timetostr(NeoFrag::loader()->lang('date_time_long'), $data['date']).'">'.time_span($data['date']).'</span>';
  531.                         },
  532.                         'sort'    => function($data){
  533.                             return $data['date'];
  534.                         }
  535.                     ),
  536.                     array(
  537.                         'title'   => $this('last_activity'),
  538.                         'content' => function($data){
  539.                             return '<span data-toggle="tooltip" title="'.timetostr(NeoFrag::loader()->lang('date_time_long'), $data['last_activity']).'">'.time_span($data['last_activity']).'</span>';
  540.                         },
  541.                         'sort'    => function($data){
  542.                             return $data['last_activity'];
  543.                         }
  544.                     ),
  545.                     array(
  546.                         'title'   => $this('history'),
  547.                         'content' => function($data, $loader){
  548.                             $links = implode('<br />', array_map(function($a){
  549.                                 return '<a href="'.url($a).'">'.$a.'</a>';
  550.                             }, $data['history']));
  551.  
  552.                             return '<span data-toggle="popover" title="'.$loader->lang('last_pages_visited').'" data-content="'.utf8_htmlentities($links).'" data-placement="auto" data-html="1">'.icon('fa-history').' '.reset($data['history']).'</span>';
  553.                         }
  554.                     ),
  555.                     array(
  556.                         'content' => array(function($data){
  557.                             if ($data['user_id'] && $data['session_id'] != NeoFrag::loader()->session('session_id'))
  558.                             {
  559.                                 return button_delete('admin/members/sessions/delete/'.$data['session_id'].'.html');
  560.                             }
  561.                         })
  562.                     )
  563.                 ))
  564.                 ->data($sessions);
  565.        
  566.         return new Panel(array(
  567.             'title'   => $this('sessions'),
  568.             'icon'    => 'fa-globe',
  569.             'content' => $this->table->display()
  570.         ));
  571.     }
  572.    
  573.     public function _sessions_delete($session_id, $username)
  574.     {
  575.         $this   ->title($this('delete_confirmation'))
  576.                 ->load->library('form')
  577.                 ->confirm_deletion($this('delete_confirmation'), $this('session_delete_message', $username));
  578.  
  579.         if ($this->form->is_valid())
  580.         {
  581.             $this->db   ->where('session_id', $session_id)
  582.                         ->delete('nf_sessions');
  583.  
  584.             return 'OK';
  585.         }
  586.  
  587.         echo $this->form->display();
  588.     }
  589. }
  590.  
  591. /*
  592. NeoFrag Alpha 0.1.3
  593. ./neofrag/modules/members/controllers/admin.php
  594. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement