network_id, $_SESSION['user']['id'] );
if( !$page_access ) {
if( $user_type == DISABLED_MEMBER ) {
$redirect_url = $base_url.'/homepage.php?msg=7003';
}
else if( empty( $user_type ) || $user_type == NETWORK_WAITING_MEMBER) {
$redirect_url = $base_url.'/homepage.php?msg=7002';
} else {
$redirect_url = NULL;
}
if( $redirect_url ) {
header("Location:$redirect_url");
exit;
}
}
}
}//____eof__do_redirect
ob_start();
$time = gmdate('D, d M Y H:i:s').'GMT';
header("Last-Modified: $time");
header("Expires: $time");
header("Pragma: no-cache");
return 1;
}
}
function register_session($login_name,$user_id,$role,$first_name,$last_name,$email,$picture=NULL){
session_start();
$_SESSION['user']['name'] = $login_name;
$_SESSION['user']['id'] = $user_id;
$_SESSION['user']['role'] = $role;
$_SESSION['user']['first_name'] = $first_name;
$_SESSION['user']['last_name'] = $last_name;
$_SESSION['user']['email'] = $email;
$_SESSION['user']['picture'] = $picture;
}
function has_html(& $s) {
return (preg_match('/<[^>]+>/',$s)) ? true : false;
}
function chop_string($string, $length=30, $link = "") {
global $base_url;
if (has_html($string)) {
$san = new InputSanitizer();
$san->passthrough = TRUE; // we want no HTML filtering here
$return = $san->process($string, $length);
} else {
$return = substr($string, 0, $length);
if(strlen($string) > $length) {
$return .= "..";
/*if($length >= DESCRIPTION_LENGTH && !empty($link)) {
$return .= "
read more..";
}*/
}
}
$return = nl2br($return);
return $return;
}
function filter_all_post(&$post_array, $strip_all_tags = FALSE, $allow_tags_everywhere = FALSE) {
$filt = Validation::get_input_filter($strip_all_tags);
if ($allow_tags_everywhere) $filt->htmlAllowedEverywhere = TRUE;
$post_array = $filt->process($post_array);
}
//Function will take the comma separated tags as argument and return the array of these comma seprated tags
function tags_string_to_array($tagstring) {
$tags = array();
if(strlen($tagstring) > 0) {
$tags_array = explode(",",$tagstring);
foreach($tags_array as $value) {
$tags[] = $value;
}
}
return $tags;
}
// Function will take an array as argument and return the delimiter separated string
function tags_array_to_string($tagarray, $delimiter = ',') {
$tagstring = "";
if(count($tagarray) > 0) {
for($counter = 0; $counter < count($tagarray); $counter++) {
$tagstring .= $tagarray[$counter]['name'].$delimiter;
}
$tagstring = substr($tagstring, 0, strlen($tagstring) - 1);
}
return $tagstring;
}
/* This function is used to displat the formatted ouput.Following things will be handled by it
- Will split the String to chunks.
- Will Strip slashes
*/
function display_sanitized($body,$length=CHUNK_LENGTH) {
$body = stripslashes($body);
$body = chunk_split($body, $length);
return $body;
}
//This function checks the mime type of file
//purpose e.g. if we change abc.pdf to abc.gif then it will cause GD crash
//So we can check it actually
if (!function_exists('mime_content_type'))
{
function mime_content_type($f)
{
//$output = system ( trim( 'file -bi ' . escapeshellarg ( $f ) ) ) ;
$output = exec(trim('file -bi ' . escapeshellarg ($f)));
return $output;
}
}
/**
* function used to check permissions for user to do an activity
* @param $params is array of parameters like $params['action'], $param['uid']..
*/
function user_can( $params ) {
global $network_info, $login_uid;
$action = $params['action'];
switch( $action ) {
case 'edit_content':
case 'delete_content':
if( $params['uid'] && $params['cid'] ) {
//super admin can edit/ delete any content
if( $params['uid'] == SUPER_USER_ID ) {
return true;
}
// network owner can edit / delete any content in a network
if( Network::is_admin( $network_info->network_id, $params['uid'] ) ) {
return true;
}
//Loading content
$content_obj = Content::load_content((int)$params['cid'], $params['uid'] );
//author of the content can perform the action
if( $content_obj->author_id == $params['uid'] ) {
return true;
}
if( $content_obj->parent_collection_id != -1 ) { // content is a part of some collection
// Loading collection
$collection_obj = ContentCollection::load_collection((int)$content_obj->parent_collection_id, $params['uid'] );
// owner of collection can also edit the content
if ( $collection_obj->author_id == $params['uid'] ) {
return true;
}
}
}
break;
case 'delete_comment':
//network owner can delete any comment
$comment = $params['comment_info'];//array having the comment details
if ($login_uid == SUPER_USER_ID) { //Super user can delete any comment
return true;
} else if ($network_info->owner_id == $login_uid) {//Network owner can delete the comment
return true;
} else if ($comment['user_id'] == $login_uid) { //Author of comment can delete the comment
return true;
}
$content = Content::load_content((int)$comment['content_id'], $login_uid);
if ($content->author_id == $login_uid) { //Author of the content can delete the comment.
return true;
} else if ($content->parent_collection_id != -1) { // means content belongs to some collection
$collection = ContentCollection::load_collection($content->parent_collection_id, $login_id);
if ($collection->author_id == $login_uid) {//If content on which comment has been posted belongs to some collection then author of that collection can delete the comment
return true;
}
}
return false;// return false in all the other cases
break;
case 'edit_forum':
$perm_array = array($network_info->owner_id, SUPER_USER_ID, $params['group_owner'], $params['forum_owner']);
return in_array($login_uid, $perm_array);
break;
case 'delete_rep': // Delete the Replies of forum
$perm_array = array($network_info->owner_id, SUPER_USER_ID, $params['group_owner'], $params['forum_owner'], $params['rep_owner']);
return in_array($login_uid, $perm_array);
break;
case 'view_group_content':
if ($params['allow_anonymous']) return true;
$perm_array = array ($network_info->owner_id, SUPER_USER_ID, $params['group_owner']);
$member_type = array (MEMBER, MODERATOR, OWNER);
if (in_array($login_uid, $perm_array) || in_array($params['member_type'], $member_type))
return true;
break;
case 'view_abuse_report_form':
if(empty($login_uid)) return false;
$extra = unserialize($network_info->extra);
$pram = $extra['notify_owner']['report_abuse_on_content']['value'];
if (isset($pram) && ($pram > 0) ) return true;
return false;
break;
case 'delete_comment_authorization':
$perm_array = array($network_info->owner_id, SUPER_USER_ID, $params['group_owner'], $params['content_owner'], $params['comment_owner']);
return in_array($login_uid, $perm_array);
break;
}
return false;
}
function group_user_authentication ($group_id) {
global $login_uid, $base_url;
$access_array = array();
$access_array['style'] = "";
if (!empty($login_uid)) {
$user_type = Group::get_user_type($login_uid, $group_id);
$group_var = new Group();
$group_var->load($group_id);
switch (trim($user_type)) {
case NOT_A_MEMBER:
if ($group_var->reg_type == REG_MODERATED) {
$access_array['hyper_link'] = "$base_url/group.php?action=join&gid=$group_id";
$access_array['caption'] = 'Request to join';
$access_array['style'] = "style=\"width:160px;\"";
}
else {
$access_array['hyper_link'] = "$base_url/group.php?action=join&gid=$group_id";
$access_array['caption'] = 'Join';
}
break;
case MEMBER:
$access_array['hyper_link'] = "$base_url/group.php?action=leave&gid=$group_id";
$access_array['caption'] = 'Unjoin';
break;
case OWNER:
$access_array['hyper_link'] = "$base_url/addgroup.php?gid=$group_id";
$access_array['caption'] = 'Edit';
break;
}
}
else {
$access_array['hyper_link'] = "$base_url/group.php?action=join&gid=$group_id";
$access_array['caption'] = 'Join';
}
return $access_array;
}
/**
This function convert object into array
some time we are using this type of variable
'$links[$i]->login_name' convert these type of variable into array
*/
function objtoarray($data) {
$cnt = count($data);
if ($cnt > 0 ) {
$return_array = array();
for ($i = 0; $i < $cnt; $i++) {
if(is_object($data[$i])) {
foreach($data[$i] as $k=>$v) {
$return_array[$i][$k] = $v;
}
}
else {
$return_array[$i] = $data[$i];
}
}
return $return_array;
}
return $data;
}
/**
This function is created for the sorting of array
ie array( 0=> array( 'members'=>2, 'owner' => 'pa'), 1=> array('members'=>1, 'owner' => 'xyz'))
Now we want to sort the array in the basis of owner , then we use this function
*/
function sortByFunc(&$arr, $func, $direc='asc', $change_the_key=NULL) {
$tmpArr = array();
foreach ($arr as $k => &$e) {
$tmpArr[] = array('f' => $func($e), 'k' => $k, 'e' =>&$e);
}
if ($direc == 'desc') {
arsort($tmpArr);
}
else {
sort($tmpArr);
}
$arr = array();
foreach($tmpArr as &$fke) {
if($change_the_key) {
$arr[] = &$fke['e'];
}
else{
$arr[$fke['k']] = &$fke['e'];
}
}
}
/**
* set the variables for the class
* @param $modulename name of module, in which we create a form
*/
/* Function for handling the post data. Call this function on the top of set_up function of web page */
function handle_post ($action_file=null) {
global $global_form_data, $global_form_error;
unset($global_form_data);
unset($global_form_error);
if (!empty($_POST['form_handler'])) {
$msg_handler = new FormHandler();
$msg_handler->block_module_name = $_POST['form_handler'];
$msg_handler->action_file = $action_file;
$msg_handler->manage_post();
}
return;
}
/**
* set the variables for the class
* @param $msg_array takes a array of messages
* @param $on_success set for redirection after success . if you want to change the page
* @param $on_failure set for redirection after failure . if you want to change the page
* @param $query_str while redirection if any Query string exits
*/
/* Call this function at the end of action.php file in the block module */
function set_web_variables ($msg_array, $redirect_url=NULL, $query_str=NULL, $unset_array=NULL) {
$msg_handler = new FormHandler();
$msg_handler->msg = $msg_array;
$msg_handler->redirect_url = $redirect_url;
$msg_handler->query_str = $query_str;
$msg_handler->unset_array = $unset_array;
$msg_handler->handle_post_data();
}
function total_abuse($id, $type) {
$report_abuse_obj = new ReportAbuse();
$report_abuse_obj->parent_type = $type;
$report_abuse_obj->parent_id = $id;
$result = $report_abuse_obj->get_multiples();
return count($result);
}
?>