Esempio n. 1
0
/**
 * This function calculates the resized width and resized heigt according to the source and target widths
 * and heights, height so that no distortions occur
 * parameters
 * $image = the absolute path to the image
 * $target_width = how large do you want your resized image
 * $target_height = how large do you want your resized image
 * $slideshow (default=0) = indicates weither we are generating images for a slideshow or not, t
 *							this overrides the $_SESSION["image_resizing"] a bit so that a thumbnail
 *							view is also possible when you choose not to resize the source images
 */
function resize_image($image, $target_width, $target_height, $slideshow = 0)
{
    // Modifications by Ivan Tcholakov, 04-MAY-2009.
    $result = array();
    if (isset($_SESSION['image_resizing']) && $_SESSION['image_resizing'] == 'resizing' or $slideshow == 1) {
        $new_sizes = api_resize_image($image, $target_width, $target_height);
        $result[] = $new_sizes['height'];
        $result[] = $new_sizes['width'];
    } else {
        $size = api_getimagesize($image);
        $result[] = $size['height'];
        $result[] = $size['width'];
    }
    return $result;
}
    public function make_lp($files = array())
    {
        global $_course;
        $previous = 0;
        $i = 0;

        if (!is_dir($this->base_work_dir.$this->created_dir))
            return false;

        foreach ($files as $file) {
            /* '||' is used as separator between fields:
                slide name (with accents) || file name (without accents) || all slide text (to be indexed).
            */
            list($slide_name, $file_name, $slide_body) = explode('||', $file);

            // Filename is utf8 encoded, but when we decode, some chars are not translated (like quote ’).
            // so we remove these chars by translating it in htmlentities and the reconvert it in want charset.
            $slide_name = api_htmlentities($slide_name, ENT_COMPAT, $this->original_charset);
            $slide_name = str_replace('’', '\'', $slide_name);
            $slide_name = api_convert_encoding($slide_name, api_get_system_encoding(), $this->original_charset);
            $slide_name = api_html_entity_decode($slide_name, ENT_COMPAT, api_get_system_encoding());

            if ($this->take_slide_name === true) {
                $slide_name = str_replace('_', ' ', $slide_name);
                $slide_name = api_ucfirst($slide_name);
            } else {
                $slide_name = 'slide'.str_repeat('0', 2 - strlen($i)).$i;
            }

            $i++;
            // Add the png to documents.
            $document_id = add_document(
                $_course,
                $this->created_dir.'/'.urlencode($file_name),
                'file',
                filesize($this->base_work_dir.$this->created_dir.'/'.$file_name),
                $slide_name
            );

            api_item_property_update(
                $_course,
                TOOL_DOCUMENT,
                $document_id,
                'DocumentAdded',
                api_get_user_id(),
                0,
                0,
                null,
                null,
                api_get_session_id()
            );

            // Generating the thumbnail.
            $image = $this->base_work_dir.$this->created_dir .'/'. $file_name;

            $pattern = '/(\w+)\.png$/';
            $replacement = '${1}_thumb.png';
            $thumb_name = preg_replace($pattern, $replacement, $file_name);

            // Calculate thumbnail size.
            $image_size = api_getimagesize($image);
            $width  = $image_size['width'];
            $height = $image_size['height'];

            $thumb_width = 300;
            $thumb_height = floor($height * ($thumb_width / $width));

            $my_new_image = new Image($image);
            $my_new_image->resize($thumb_width, $thumb_height);
            $my_new_image->send_image($this->base_work_dir.$this->created_dir .'/'. $thumb_name, -1, 'png');

            // Adding the thumbnail to documents.
            $document_id_thumb = add_document(
                $_course,
                $this->created_dir.'/'.urlencode($thumb_name),
                'file',
                filesize($this->base_work_dir.$this->created_dir.'/'.$thumb_name),
                $slide_name
            );

            api_item_property_update($_course, TOOL_THUMBNAIL, $document_id_thumb, 'DocumentAdded', api_get_user_id(), 0, 0);

            // Create an html file.
            $html_file = $file_name.'.html';
            $fp = fopen($this->base_work_dir.$this->created_dir.'/'.$html_file, 'w+');

            $slide_src = api_get_path(REL_COURSE_PATH).$_course['path'].'/document/'.$this->created_dir.'/'.utf8_encode($file_name);
            $slide_src = str_replace('//', '/', $slide_src);
            fwrite($fp,
'<html>
    <head>
    </head>
    <body>
        <img src="'.$slide_src.'" />
    </body>
</html>');  // This indentation is to make the generated html files to look well.

            fclose($fp);
            $document_id = add_document(
                $_course,
                $this->created_dir.'/'.urlencode($html_file),
                'file',
                filesize($this->base_work_dir.$this->created_dir.'/'.$html_file),
                $slide_name
            );

            if ($document_id) {

                // Put the document in item_property update.
                api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(), 0, 0, null, null, api_get_session_id());

                $previous = $this->add_item(0, $previous, 'document', $document_id, $slide_name, '');
                if ($this->first_item == 0) {
                    $this->first_item = $previous;
                }
            }
            // Code for text indexing.
            if (api_get_setting('search_enabled') == 'true') {

                if (isset($_POST['index_document']) && $_POST['index_document']) {
                    $di = new ChamiloIndexer();
                    isset($_POST['language']) ? $lang = Database::escape_string($_POST['language']) : $lang = 'english';
                    $di->connectDb(NULL, NULL, $lang);
                    $ic_slide = new IndexableChunk();
                    $ic_slide->addValue('title', $slide_name);
                    $specific_fields = get_specific_field_list();
                    $all_specific_terms = '';
                    foreach ($specific_fields as $specific_field) {
                        if (isset($_REQUEST[$specific_field['code']])) {
                            $sterms = trim($_REQUEST[$specific_field['code']]);
                            $all_specific_terms .= ' '. $sterms;
                            if (!empty($sterms)) {
                                $sterms = explode(',', $sterms);
                                foreach ($sterms as $sterm) {
                                    $ic_slide->addTerm(trim($sterm), $specific_field['code']);
                                }
                            }
                        }
                    }
                    $slide_body = $all_specific_terms .' '. $slide_body;
                    $ic_slide->addValue('content', $slide_body);
                    /* FIXME:  cidReq:lp_id:doc_id al indexar  */
                    // Add a comment to say terms separated by commas.
                    $courseid = api_get_course_id();
                    $ic_slide->addCourseId($courseid);
                    $ic_slide->addToolId(TOOL_LEARNPATH);
                    $lp_id = $this->lp_id;
                    $xapian_data = array(
                        SE_COURSE_ID => $courseid,
                        SE_TOOL_ID => TOOL_LEARNPATH,
                        SE_DATA => array('lp_id' => $lp_id, 'lp_item' => $previous, 'document_id' => $document_id),
                        SE_USER => (int)api_get_user_id(),
                    );
                    $ic_slide->xapian_data = serialize($xapian_data);
                    $di->addChunk($ic_slide);
                    // Index and return search engine document id.
                    $did = $di->index();
                    if ($did) {
                        // Save it to db.
                        $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
                        $sql = 'INSERT INTO %s (id, course_code, tool_id, ref_id_high_level, ref_id_second_level, search_did)
                            VALUES (NULL , \'%s\', \'%s\', %s, %s, %s)';
                        $sql = sprintf($sql, $tbl_se_ref, api_get_course_id(), TOOL_LEARNPATH, $lp_id, $previous, $did);
                        Database::query($sql);
                    }
                }
            }
        }
    }
Esempio n. 3
0
 /**
  * Gets the current group image
  * @param string group id
  * @param string picture group name
  * @param string height
  * @param string picture size it can be small_,  medium_  or  big_
  * @param string style css
  * @return array with the file and the style of an image i.e $array['file'] $array['style']
  */
 public function get_picture_group($id, $picture_file, $height, $size_picture = GROUP_IMAGE_SIZE_MEDIUM, $style = '')
 {
     $picture = array();
     $picture['style'] = $style;
     if ($picture_file == 'unknown.jpg') {
         $picture['file'] = api_get_path(WEB_IMG_PATH) . $picture_file;
         return $picture;
     }
     switch ($size_picture) {
         case GROUP_IMAGE_SIZE_ORIGINAL:
             $size_picture = '';
             break;
         case GROUP_IMAGE_SIZE_BIG:
             $size_picture = 'big_';
             break;
         case GROUP_IMAGE_SIZE_MEDIUM:
             $size_picture = 'medium_';
             break;
         case GROUP_IMAGE_SIZE_SMALL:
             $size_picture = 'small_';
             break;
         default:
             $size_picture = 'medium_';
     }
     $image_array_sys = $this->get_group_picture_path_by_id($id, 'system', false, true);
     $image_array = $this->get_group_picture_path_by_id($id, 'web', false, true);
     $file = $image_array_sys['dir'] . $size_picture . $picture_file;
     if (file_exists($file)) {
         $picture['file'] = $image_array['dir'] . $size_picture . $picture_file;
         $picture['style'] = '';
         if ($height > 0) {
             $dimension = api_getimagesize($picture['file']);
             $margin = ($height - $dimension['width']) / 2;
             //@ todo the padding-top should not be here
             $picture['style'] = ' style="padding-top:' . $margin . 'px; width:' . $dimension['width'] . 'px; height:' . $dimension['height'] . ';" ';
         }
     } else {
         $file = $image_array_sys['dir'] . $picture_file;
         if (file_exists($file) && !is_dir($file)) {
             $picture['file'] = $image_array['dir'] . $picture_file;
         } else {
             $picture['file'] = api_get_path(WEB_IMG_PATH) . 'unknown_group.png';
         }
     }
     return $picture;
 }
 /**
  * Formats a page content by reorganising the HTML code a little
  * @param	string	Page header
  * @param	string	Page content
  * @return	string	Formatted page content
  */
 function format_page_content($header, $content)
 {
     // Limit the width of the doc.
     list($max_width, $max_height) = explode('x', api_get_setting('service_ppt2lp', 'size'));
     $content = preg_replace("|<body[^>]*>|i", "\\0\r\n<div style=\"width:" . $max_width . "\">", $content, -1, $count);
     if ($count < 1) {
         $content = '<body><div style="width:' . $max_width . '">' . $content;
     }
     $content = preg_replace('|</body>|i', '</div>\\0', $content, -1, $count);
     if ($count < 1) {
         $content = $content . '</div></body>';
     }
     // Add the headers.
     $content = $header . $content;
     // Resize all the picture to the max_width-10
     preg_match_all("|<img[^src]*src=\"([^\"]*)\"[^>]*>|i", $content, $images);
     foreach ($images[1] as $key => $image) {
         // Check if the <img tag soon has a width attribute.
         $defined_width = preg_match("|width=([^\\s]*)|i", $images[0][$key], $img_width);
         $img_width = $img_width[1];
         if (!$defined_width) {
             $image_size = api_getimagesize($this->base_work_dir . $this->created_dir . '/' . $image);
             $img_width = $image_size['width'];
             $img_height = $image_size['height'];
             $new_width = $max_width - 10;
             if ($img_width > $new_width) {
                 $picture_resized = str_ireplace('<img', '<img width="' . $new_width . '" ', $images[0][$key]);
                 $content = str_replace($images[0][$key], $picture_resized, $content);
             }
         } elseif ($img_width > $max_width - 10) {
             $picture_resized = str_ireplace('width=' . $img_width, 'width="' . ($max_width - 10) . '"', $images[0][$key]);
             $content = str_replace($images[0][$key], $picture_resized, $content);
         }
     }
     return $content;
 }
Esempio n. 5
0
         $show_forum = true;
     } else {
         $show_forum = GroupManager::user_has_access($user_id, $forum['forum_of_group'], GroupManager::GROUP_TOOL_FORUM);
     }
 }
 if ($show_forum) {
     $form_count++;
     $mywhatsnew_post_info = isset($whatsnew_post_info[$forum['forum_id']]) ? $whatsnew_post_info[$forum['forum_id']] : null;
     $html = '<div class="panel panel-default forum">';
     $html .= '<div class="panel-body">';
     $forum_image = '';
     $imgForum = '';
     // Showing the image
     if (!empty($forum['forum_image'])) {
         $image_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/upload/forum/images/' . $forum['forum_image'];
         $image_size = api_getimagesize($image_path);
         $img_attributes = '';
         if (!empty($image_size)) {
             //limit display width and height to 100px
             $img_attributes = ' style="width:80px" height="80px"';
             $imgForum = "<img src=\"{$image_path}\" {$img_attributes}>";
         } else {
             $imgForum = '';
         }
         $forum_image = $imgForum;
     } else {
         if ($forum['forum_of_group'] == '0') {
             $forum_image = Display::return_icon('forum_group.png', get_lang('GroupForum'), null, ICON_SIZE_LARGE);
         } else {
             $forum_image = Display::return_icon('forum.png', get_lang('Forum'), null, ICON_SIZE_LARGE);
         }
Esempio n. 6
0
    $message = Display::return_message($err_msg, 'error');
}
// USER PICTURE
$image_path = UserManager::get_user_picture_path_by_id($user_id, 'web');
$image_dir = $image_path['dir'];
$image = $image_path['file'];
$image_file = $image != '' ? $image_dir . $image : api_get_path(WEB_CODE_PATH) . 'img/unknown.jpg';
$image_size = api_getimagesize($image_file);
$img_attributes = 'src="' . $image_file . '?rand=' . time() . '" ' . 'alt="' . api_get_person_name($user_data['firstname'], $user_data['lastname']) . '" ' . 'style="float:' . ($text_dir == 'rtl' ? 'left' : 'right') . '; padding:5px;" ';
if ($image_size['width'] > 300) {
    //limit display width to 300px
    $img_attributes .= 'width="300" ';
}
// get the path,width and height from original picture
$big_image = $image_dir . 'big_' . $image;
$big_image_size = api_getimagesize($big_image);
$big_image_width = $big_image_size['width'];
$big_image_height = $big_image_size['height'];
$url_big_image = $big_image . '?rnd=' . time();
$content = null;
if ($image == '') {
    $content .= '<img ' . $img_attributes . ' />';
} else {
    $content .= '<input type="image" ' . $img_attributes . ' onclick="javascript: return show_image(\'' . $url_big_image . '\',\'' . $big_image_width . '\',\'' . $big_image_height . '\');"/>';
}
// Display form
$content .= $form->return_form();
$tpl = new Template($tool_name);
$tpl->assign('message', $message);
$tpl->assign('content', $content);
$tpl->display_one_col_template();
Esempio n. 7
0
     @mkdir($directory_thumbnails, api_get_permissions_for_new_directories());
 }
 // check files and thumbnails
 if (is_array($image_files_only)) {
     foreach ($image_files_only as $one_image_file) {
         $image = $sys_course_path . $_course['path'] . '/document' . $folder . $one_image_file;
         $image_thumbnail = $directory_thumbnails . '.' . $one_image_file;
         if (file_exists($image)) {
             //check thumbnail
             $imagetype = explode(".", $image);
             //or check $imagetype = image_type_to_extension(exif_imagetype($image), false);
             $imagetype = strtolower($imagetype[count($imagetype) - 1]);
             if (in_array($imagetype, $allowed_thumbnail_types)) {
                 if (!file_exists($image_thumbnail)) {
                     //run each once we view thumbnails is too heavy, then need move into  !file_exists($image_thumbnail, and only run when haven't the thumbnail
                     $original_image_size = api_getimagesize($image);
                     switch ($imagetype) {
                         case 'gif':
                             $source_img = imagecreatefromgif($image);
                             break;
                         case 'jpg':
                             $source_img = imagecreatefromjpeg($image);
                             break;
                         case 'jpeg':
                             $source_img = imagecreatefromjpeg($image);
                             break;
                         case 'png':
                             $source_img = imagecreatefrompng($image);
                             break;
                     }
                     $new_thumbnail_size = api_calculate_image_size($original_image_size['width'], $original_image_size['height'], $max_thumbnail_width, $max_thumbnail_height);
/**
 * This function displays the form that is used to add a forum category.
 *
 * @param array $inputvalues
 * @param int $lp_id
 * @return void HTML
 *
 * @author Patrick Cool <*****@*****.**>, Ghent University
 * @author Juan Carlos Raña Trabado (return to lp_id)
 *
 * @version may 2011, Chamilo 1.8.8
 */
function show_add_forum_form($inputvalues = array(), $lp_id)
{
    $_course = api_get_course_info();
    // Initialize the object.
    $form = new FormValidator('forumcategory', 'post', 'index.php?' . api_get_cidreq());
    // The header for the form
    if (!empty($inputvalues)) {
        $form_title = get_lang('EditForum');
    } else {
        $form_title = get_lang('AddForum');
    }
    $session_header = Session::read('session_name');
    $form->addElement('header', $form_title . $session_header);
    // We have a hidden field if we are editing.
    if (!empty($inputvalues) && is_array($inputvalues)) {
        $my_forum_id = isset($inputvalues['forum_id']) ? $inputvalues['forum_id'] : null;
        $form->addElement('hidden', 'forum_id', $my_forum_id);
    }
    $lp_id = intval($lp_id);
    // hidden field if from learning path
    $form->addElement('hidden', 'lp_id', $lp_id);
    // The title of the forum
    $form->addElement('text', 'forum_title', get_lang('Title'), array('autofocus'));
    // The comment of the forum.
    $form->addHtmlEditor('forum_comment', get_lang('Description'), null, null, array('ToolbarSet' => 'Forum', 'Width' => '98%', 'Height' => '200'));
    // Dropdown list: Forum categories
    $forum_categories = get_forum_categories();
    foreach ($forum_categories as $key => $value) {
        $forum_categories_titles[$value['cat_id']] = $value['cat_title'];
    }
    $form->addElement('select', 'forum_category', get_lang('InForumCategory'), $forum_categories_titles);
    $form->applyFilter('forum_category', 'html_filter');
    if ($_course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD) {
        // This is for horizontal
        $group = array();
        $group[] = $form->createElement('radio', 'allow_anonymous', null, get_lang('Yes'), 1);
        $group[] = $form->createElement('radio', 'allow_anonymous', null, get_lang('No'), 0);
        $form->addGroup($group, 'allow_anonymous_group', get_lang('AllowAnonymousPosts'), ' ');
    }
    $form->addButtonAdvancedSettings('advanced_params');
    $form->addElement('html', '<div id="advanced_params_options" style="display:none">');
    $group = array();
    $group[] = $form->createElement('radio', 'students_can_edit', null, get_lang('Yes'), 1);
    $group[] = $form->createElement('radio', 'students_can_edit', null, get_lang('No'), 0);
    $form->addGroup($group, 'students_can_edit_group', get_lang('StudentsCanEdit'), ' ');
    $group = array();
    $group[] = $form->createElement('radio', 'approval_direct', null, get_lang('Approval'), 1);
    $group[] = $form->createElement('radio', 'approval_direct', null, get_lang('Direct'), 0);
    $group = array();
    $group[] = $form->createElement('radio', 'allow_attachments', null, get_lang('Yes'), 1);
    $group[] = $form->createElement('radio', 'allow_attachments', null, get_lang('No'), 0);
    $group = array();
    $group[] = $form->createElement('radio', 'allow_new_threads', null, get_lang('Yes'), 1);
    $group[] = $form->createElement('radio', 'allow_new_threads', null, get_lang('No'), 0);
    $form->addGroup($group, 'allow_new_threads_group', get_lang('AllowNewThreads'), ' ');
    $group = array();
    $group[] = $form->createElement('radio', 'default_view_type', null, get_lang('Flat'), 'flat');
    $group[] = $form->createElement('radio', 'default_view_type', null, get_lang('Threaded'), 'threaded');
    $group[] = $form->createElement('radio', 'default_view_type', null, get_lang('Nested'), 'nested');
    $form->addGroup($group, 'default_view_type_group', get_lang('DefaultViewType'), ' ');
    // Drop down list: Groups
    $groups = GroupManager::get_group_list();
    $groups_titles[0] = get_lang('NotAGroupForum');
    foreach ($groups as $key => $value) {
        $groups_titles[$value['id']] = $value['name'];
    }
    $form->addElement('select', 'group_forum', get_lang('ForGroup'), $groups_titles);
    // Public or private group forum
    $group = array();
    $group[] = $form->createElement('radio', 'public_private_group_forum', null, get_lang('Public'), 'public');
    $group[] = $form->createElement('radio', 'public_private_group_forum', null, get_lang('Private'), 'private');
    $form->addGroup($group, 'public_private_group_forum_group', get_lang('PublicPrivateGroupForum'), '');
    // Forum image
    $form->add_progress_bar();
    if (isset($inputvalues['forum_image']) && strlen($inputvalues['forum_image']) > 0) {
        $image_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/upload/forum/images/' . $inputvalues['forum_image'];
        $image_size = api_getimagesize($image_path);
        $img_attributes = '';
        if (!empty($image_size)) {
            if ($image_size['width'] > 100 || $image_size['height'] > 100) {
                //limit display width and height to 100px
                $img_attributes = 'width="100" height="100"';
            }
            $show_preview_image = '<img src="' . $image_path . '" ' . $img_attributes . '>';
            $form->addElement('label', get_lang('PreviewImage'), $show_preview_image);
            $form->addElement('checkbox', 'remove_picture', null, get_lang('DelImage'));
        }
    }
    $forum_image = isset($inputvalues['forum_image']) ? $inputvalues['forum_image'] : '';
    $form->addElement('file', 'picture', $forum_image != '' ? get_lang('UpdateImage') : get_lang('AddImage'));
    $form->addRule('picture', get_lang('OnlyImagesAllowed'), 'filetype', array('jpg', 'jpeg', 'png', 'gif'));
    $form->addElement('html', '</div>');
    // The OK button
    if (isset($_GET['id']) && $_GET['action'] == 'edit') {
        $form->addButtonUpdate(get_lang('ModifyForum'), 'SubmitForum');
    } else {
        $form->addButtonCreate(get_lang('CreateForum'), 'SubmitForum');
    }
    // setting the rules
    $form->addRule('forum_title', get_lang('ThisFieldIsRequired'), 'required');
    $form->addRule('forum_category', get_lang('ThisFieldIsRequired'), 'required');
    $defaultSettingAllowNewThreads = api_get_default_tool_setting('forum', 'allow_new_threads', 0);
    // Settings the defaults
    if (empty($inputvalues) || !is_array($inputvalues)) {
        $defaults['allow_anonymous_group']['allow_anonymous'] = 0;
        $defaults['students_can_edit_group']['students_can_edit'] = 0;
        $defaults['approval_direct_group']['approval_direct'] = 0;
        $defaults['allow_attachments_group']['allow_attachments'] = 1;
        $defaults['allow_new_threads_group']['allow_new_threads'] = $defaultSettingAllowNewThreads;
        $defaults['default_view_type_group']['default_view_type'] = api_get_setting('forum.default_forum_view');
        $defaults['public_private_group_forum_group']['public_private_group_forum'] = 'public';
        if (isset($_GET['forumcategory'])) {
            $defaults['forum_category'] = Security::remove_XSS($_GET['forumcategory']);
        }
    } else {
        // the default values when editing = the data in the table
        $defaults['forum_id'] = isset($inputvalues['forum_id']) ? $inputvalues['forum_id'] : null;
        $defaults['forum_title'] = prepare4display(isset($inputvalues['forum_title']) ? $inputvalues['forum_title'] : null);
        $defaults['forum_comment'] = prepare4display(isset($inputvalues['forum_comment']) ? $inputvalues['forum_comment'] : null);
        $defaults['forum_category'] = isset($inputvalues['forum_category']) ? $inputvalues['forum_category'] : null;
        $defaults['allow_anonymous_group']['allow_anonymous'] = isset($inputvalues['allow_anonymous']) ? $inputvalues['allow_anonymous'] : null;
        $defaults['students_can_edit_group']['students_can_edit'] = isset($inputvalues['allow_edit']) ? $inputvalues['allow_edit'] : null;
        $defaults['approval_direct_group']['approval_direct'] = isset($inputvalues['approval_direct_post']) ? $inputvalues['approval_direct_post'] : null;
        $defaults['allow_attachments_group']['allow_attachments'] = isset($inputvalues['allow_attachments']) ? $inputvalues['allow_attachments'] : null;
        $defaults['allow_new_threads_group']['allow_new_threads'] = isset($inputvalues['allow_new_threads']) ? $inputvalues['allow_new_threads'] : $defaultSettingAllowNewThreads;
        $defaults['default_view_type_group']['default_view_type'] = isset($inputvalues['default_view']) ? $inputvalues['default_view'] : null;
        $defaults['public_private_group_forum_group']['public_private_group_forum'] = isset($inputvalues['forum_group_public_private']) ? $inputvalues['forum_group_public_private'] : null;
        $defaults['group_forum'] = isset($inputvalues['forum_of_group']) ? $inputvalues['forum_of_group'] : null;
    }
    $form->setDefaults($defaults);
    // Validation or display
    if ($form->validate()) {
        $check = Security::check_token('post');
        if ($check) {
            $values = $form->exportValues();
            $return_message = store_forum($values);
            Display::display_confirmation_message($return_message);
        }
        Security::clear_token();
    } else {
        $token = Security::get_token();
        $form->addElement('hidden', 'sec_token');
        $form->setConstants(array('sec_token' => $token));
        $form->display();
    }
}
Esempio n. 9
0
/**
 * This function resizes an image, with preserving its proportions (or aspect ratio).
 * @author Ivan Tcholakov, MAY-2009.
 * @param int $image            System path or URL of the image
 * @param int $target_width     Targeted width
 * @param int $target_height    Targeted height
 * @return array                Calculated new width and height
 */
function api_resize_image($image, $target_width, $target_height)
{
    $image_properties = api_getimagesize($image);
    return api_calculate_image_size($image_properties['width'], $image_properties['height'], $target_width, $target_height);
}
Esempio n. 10
0
 /**
  * Displays the information of an individual user
  * @param int $user_id
  */
 public static function display_individual_user($user_id, $returnContent = false)
 {
     global $interbreadcrumb;
     $safe_user_id = intval($user_id);
     $curretUserId = api_get_user_id();
     $user_table = Database::get_main_table(TABLE_MAIN_USER);
     $sql = "SELECT * FROM {$user_table} WHERE user_id = " . $safe_user_id;
     $result = Database::query($sql);
     $userInfo = api_get_user_info($user_id);
     $content = null;
     if (Database::num_rows($result) == 1) {
         $user_object = Database::fetch_object($result);
         $alt = $userInfo['complete_name'] . ($curretUserId == $user_id ? '&nbsp;(' . get_lang('Me') . ')' : '');
         $status = api_get_status_from_code($user_object->status);
         $interbreadcrumb[] = array('url' => SocialManager::getUserOnlineLink(), 'name' => get_lang('UsersOnLineList'));
         if ($returnContent == false) {
             Display::display_header($alt, null, $alt);
         }
         $content = '<div class ="thumbnail">';
         if (strlen(trim($user_object->picture_uri)) > 0) {
             $sysdir_array = UserManager::get_user_picture_path_by_id($safe_user_id, 'system');
             $sysdir = $sysdir_array['dir'];
             $webdir_array = UserManager::get_user_picture_path_by_id($safe_user_id, 'web');
             $webdir = $webdir_array['dir'];
             $fullurl = $webdir . $user_object->picture_uri;
             $system_image_path = $sysdir . $user_object->picture_uri;
             list($width, $height, $type, $attr) = @getimagesize($system_image_path);
             $height += 30;
             $width += 30;
             // get the path,width and height from original picture
             $big_image = $webdir . 'big_' . $user_object->picture_uri;
             $big_image_size = api_getimagesize($big_image);
             $big_image_width = $big_image_size['width'];
             $big_image_height = $big_image_size['height'];
             $url_big_image = $big_image . '?rnd=' . time();
             //echo '<a href="javascript:void()" onclick="javascript: return show_image(\''.$url_big_image.'\',\''.$big_image_width.'\',\''.$big_image_height.'\');" >';
             $content .= '<img src="' . $fullurl . '" alt="' . $alt . '" />';
         } else {
             $content .= Display::return_icon('unknown.jpg', get_lang('Unknown'));
         }
         if (!empty($status)) {
             $content .= '<div class="caption">' . $status . '</div>';
         }
         $content .= '</div>';
         if (api_get_setting('show_email_addresses') == 'true') {
             $content .= Display::encrypted_mailto_link($user_object->email, $user_object->email) . '<br />';
         }
         if ($user_object->competences) {
             $content .= Display::page_subheader(get_lang('MyCompetences'));
             $content .= '<p>' . $user_object->competences . '</p>';
         }
         if ($user_object->diplomas) {
             $content .= Display::page_subheader(get_lang('MyDiplomas'));
             $content .= '<p>' . $user_object->diplomas . '</p>';
         }
         if ($user_object->teach) {
             $content .= Display::page_subheader(get_lang('MyTeach'));
             $content .= '<p>' . $user_object->teach . '</p>';
         }
         $content .= SocialManager::display_productions($user_object->user_id);
         if ($user_object->openarea) {
             $content .= Display::page_subheader(get_lang('MyPersonalOpenArea'));
             $content .= '<p>' . $user_object->openarea . '</p>';
         }
     } else {
         if ($returnContent == false) {
             Display::display_header(get_lang('UsersOnLineList'));
         }
         $content .= '<div class="actions-title">';
         $content .= get_lang('UsersOnLineList');
         $content .= '</div>';
     }
     if ($returnContent) {
         return $content;
     } else {
         echo $content;
     }
 }
 /**
  * Gets the current user image
  * @param string user id
  * @param string picture user name
  * @param string height
  * @param string picture size it can be USER_IMAGE_SIZE_SMALL,  USER_IMAGE_SIZE_MEDIUM, USER_IMAGE_SIZE_BIG or  USER_IMAGE_SIZE_ORIGINAL
  * @param string style css
  * @return array with the file and the style of an image i.e $array['file'] $array['style']
  */
 public static function get_picture_user($user_id, $picture_file, $height, $size_picture = USER_IMAGE_SIZE_MEDIUM, $style = '')
 {
     $picture = array();
     $picture['style'] = $style;
     if ($picture_file == 'unknown.jpg') {
         $picture['file'] = api_get_path(WEB_CODE_PATH) . 'img/' . $picture_file;
         return $picture;
     }
     switch ($size_picture) {
         case USER_IMAGE_SIZE_ORIGINAL:
             $size_picture = '';
             break;
         case USER_IMAGE_SIZE_BIG:
             $size_picture = 'big_';
             break;
         case USER_IMAGE_SIZE_MEDIUM:
             $size_picture = 'medium_';
             break;
         case USER_IMAGE_SIZE_SMALL:
             $size_picture = 'small_';
             break;
         default:
             $size_picture = 'medium_';
     }
     $image_array_sys = self::get_user_picture_path_by_id($user_id, 'system', false, true);
     $image_array = self::get_user_picture_path_by_id($user_id, 'web', false, true);
     $file = $image_array_sys['dir'] . $size_picture . $picture_file;
     if (file_exists($file)) {
         $picture['file'] = $image_array['dir'] . $size_picture . $picture_file;
         $picture['style'] = '';
         if ($height > 0) {
             $dimension = api_getimagesize($picture['file']);
             $margin = ($height - $dimension['width']) / 2;
             //@ todo the padding-top should not be here
             $picture['style'] = ' style="padding-top:' . $margin . 'px; width:' . $dimension['width'] . 'px; height:' . $dimension['height'] . 'px;" ';
             $picture['original_height'] = $dimension['width'];
             $picture['original_width'] = $dimension['height'];
         }
     } else {
         $file = $image_array_sys['dir'] . $picture_file;
         if (file_exists($file) && !is_dir($file)) {
             $picture['file'] = $image_array['dir'] . $picture_file;
         } else {
             switch ($size_picture) {
                 case 'big_':
                     $picture['file'] = api_get_path(WEB_CODE_PATH) . 'img/unknown.jpg';
                     break;
                 case 'medium_':
                     $picture['file'] = api_get_path(WEB_CODE_PATH) . 'img/unknown_50_50.jpg';
                     break;
                 case 'small_':
                     $picture['file'] = api_get_path(WEB_CODE_PATH) . 'img/unknown.jpg';
                     break;
                 default:
                     $picture['file'] = api_get_path(WEB_CODE_PATH) . 'img/unknown.jpg';
                     break;
             }
         }
     }
     return $picture;
 }