Wednesday, October 12, 2011

Tips 14: Modifying List of File Gallery



Just as the list submission, file gallery list on TikiWiki is also not designed in a certain manner so that only certain users are able to view a list of files gallery. The understanding is like this, suppose you have an image file that you upload to the file gallery, then the image file will be visible through the gallery file lists by all users who have access to the file's gallery. Basically, as long as you upload a file to the file gallery, that file will be visible for anyone to see it. The difference, in TikiWiki, because it is collaborative, then the file can be shared to anyone, even possibly be edited by anyone as well.
This post will provide guidance, how to create a file that is uploaded in the gallery file that can only be viewed by the user who has the right to view it. The principle works are the same as in submission list. In the end, the file is public, but file management is carried out by the competent authority. The trick is as follows:
  1. Open file /lib//filegals/filegallib.php and find "function get_files_info".
  2. Right before the script $return = false;, insert the script as follows:
    //additional procedure to control user, begin
    global $tiki_p_admin_file_galleries;

    if ($tiki_p_admin_file_galleries !='y') {
    if ( $where != '' ) {
    $where .= ' AND ';
    $bindvars = array_merge($bindvars, (array)$user);
    } else {
    $where = ' WHERE ';
    $bindvars = (array)$user;
    }
    $where .= ' `user`' . ( is_array($user) ? $this->bindvars_to_sql_in($user, true, true) : '=?' );
    }
    //additional procedure to control user,  end
  3. Save and close file /lib//filegals/filegallib.php.
  4. Open file /lib//tikilib.php and find "function get_files".
  5. Right before the script if( !empty($filter['categId']) ) {, insert the script as follows:
    //additional procedure to control user, begin
    if ($tiki_p_admin_file_galleries !='y') {
      $f_where .= " AND tf.`user` = '$user' ";
    }
    //additional procedure to control user,  end
  6. Save and close file /lib//tikilib.php. Finish.
Explanation: the above procedures stated that if a user who is currently logging on has the right (given the right) to become admin file galleries ($tiki_p_admin_file_galleries), then the user ($user) is allowed to load and display all files uploaded by many users. If a user who is currently logging on does not have the right to do that, then the user is only able to load display the list of file galleries that he or she uploaded only (stated with the command AND `user` = $ user). Doing this way will maintain users' security and privacy.

No comments:

Post a Comment