function bread_crumb($id) { global $Bread_crumb; $Bread_crumb->add(LangLoader::get_message('module_title', 'common', 'media'), MediaUrlBuilder::home()); $categories = array_reverse(MediaService::get_categories_manager()->get_parents($id, true)); foreach ($categories as $category) { if ($category->get_id() != Category::ROOT_CATEGORY) { $Bread_crumb->add($category->get_name(), url('media.php?cat=' . $category->get_id(), 'media-0-' . $category->get_id() . '+' . $category->get_rewrited_name() . '.php')); } } }
function get_feed_data_struct($idcat = 0, $name = '') { if (MediaService::get_categories_manager()->get_categories_cache()->category_exists($idcat)) { require_once PATH_TO_ROOT . '/media/media_constant.php'; $category = MediaService::get_categories_manager()->get_categories_cache()->get_category($idcat); $site_name = GeneralConfig::load()->get_site_name(); $site_name = $idcat != Category::ROOT_CATEGORY ? $site_name . ' : ' . $category->get_name() : $site_name; $feed_module_name = LangLoader::get_message('module_title', 'common', 'media'); $data = new FeedData(); $data->set_title($feed_module_name . ' - ' . $site_name); $data->set_date(new Date()); $data->set_link(SyndicationUrlBuilder::rss('media', $idcat)); $data->set_host(HOST); $data->set_desc($feed_module_name . ' - ' . $site_name); $data->set_lang(LangLoader::get_message('xml_lang', 'main')); $data->set_auth_bit(Category::READ_AUTHORIZATIONS); $categories = MediaService::get_categories_manager()->get_childrens($idcat, new SearchCategoryChildrensOptions(), true); $ids_categories = array_keys($categories); $results = PersistenceContext::get_querier()->select('SELECT media.*, cat.image FROM ' . MediaSetup::$media_table . ' media LEFT JOIN ' . MediaSetup::$media_cats_table . ' cat ON cat.id = media.idcat WHERE media.idcat IN :ids_categories AND infos = :status_approved ORDER BY timestamp DESC', array('ids_categories' => $ids_categories, 'status_approved' => MEDIA_STATUS_APROBED)); foreach ($results as $row) { // Rewriting $link = new Url('/media/media' . url('.php?id=' . $row['id'], '-' . $row['id'] . '+' . Url::encode_rewrite($row['name']) . '.php')); $item = new FeedItem(); $item->set_title($row['name']); $item->set_link($link); $item->set_guid($link); $item->set_desc(FormatingHelper::second_parse($row['contents'])); $item->set_date(new Date($row['timestamp'], Timezone::SERVER_TIMEZONE)); $item->set_image_url($row['image']); $item->set_auth(MediaService::get_categories_manager()->get_heritated_authorizations($row['idcat'], Category::READ_AUTHORIZATIONS, Authorizations::AUTH_PARENT_PRIORITY)); $enclosure = new FeedItemEnclosure(); $enclosure->set_lenght(@filesize($row['url'])); $enclosure->set_type($row['mime_type']); $enclosure->set_url($row['url']); $item->set_enclosure($enclosure); $data->add_item($item); } $results->dispose(); return $data; } }
private function is_authorized($bit, $mode = Authorizations::AUTH_CHILD_PRIORITY) { $auth = MediaService::get_categories_manager()->get_heritated_authorizations($this->id_category, $bit, $mode); return AppContext::get_current_user()->check_auth($auth, $bit); }
public function __construct() { parent::__construct(MediaService::get_categories_manager()); }
protected function get_categories_manager() { return MediaService::get_categories_manager(); }
Feed::clear_cache('media'); AppContext::get_response()->redirect('media' . url('.php?id=' . $media['idedit'])); } elseif (!$media['idedit'] && (($auth_write = MediaAuthorizationsService::check_authorizations($media['idcat'])->write()) || MediaAuthorizationsService::check_authorizations($media['idcat'])->contribution())) { $result = PersistenceContext::get_querier()->insert(PREFIX . "media", array('idcat' => $media['idcat'], 'iduser' => AppContext::get_current_user()->get_id(), 'timestamp' => time(), 'name' => $media['name'], 'contents' => FormatingHelper::strparse($media['contents']), 'url' => $media['url'], 'mime_type' => $media['mime_type'], 'infos' => MediaAuthorizationsService::check_authorizations($media['idcat'])->write() ? MEDIA_STATUS_APROBED : 0, 'width' => $media['width'], 'height' => $media['height'])); $new_id_media = $result->get_last_inserted_id(); // Feeds Regeneration Feed::clear_cache('media'); if (!$auth_write) { $media_contribution = new Contribution(); $media_contribution->set_id_in_module($new_id_media); $media_contribution->set_description(stripslashes($media['counterpart'])); $media_contribution->set_entitled($media['name']); $media_contribution->set_fixing_url('/media/media_action.php?edit=' . $new_id_media); $media_contribution->set_poster_id(AppContext::get_current_user()->get_id()); $media_contribution->set_module('media'); $media_contribution->set_auth(Authorizations::capture_and_shift_bit_auth(MediaService::get_categories_manager()->get_heritated_authorizations($media['idcat'], Category::MODERATION_AUTHORIZATIONS, Authorizations::AUTH_CHILD_PRIORITY), Category::MODERATION_AUTHORIZATIONS, Contribution::CONTRIBUTION_AUTH_BIT)); ContributionService::save_contribution($media_contribution); DispatchManager::redirect(new UserContributionSuccessController()); } else { AppContext::get_response()->redirect('media' . url('.php?id=' . $new_id_media)); } } else { $error_controller = PHPBoostErrors::user_not_authorized(); DispatchManager::redirect($error_controller); } } else { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } $tpl->display(); require_once '../kernel/footer.php';
private function generate_response() { $response = new SiteDisplayResponse($this->tpl); $graphical_environment = $response->get_graphical_environment(); $graphical_environment->set_page_title($this->get_category()->get_name(), $this->lang['module_title']); $graphical_environment->get_seo_meta_data()->set_description($this->get_category()->get_description()); $graphical_environment->get_seo_meta_data()->set_canonical_url(MediaUrlBuilder::display_category($this->get_category()->get_id(), $this->get_category()->get_rewrited_name(), AppContext::get_request()->get_getint('page', 1))); $breadcrumb = $graphical_environment->get_breadcrumb(); $breadcrumb->add($this->lang['module_title'], MediaUrlBuilder::home()); $categories = array_reverse(MediaService::get_categories_manager()->get_parents($this->get_category()->get_id(), true)); foreach ($categories as $id => $category) { if ($category->get_id() != Category::ROOT_CATEGORY) { $breadcrumb->add($category->get_name(), MediaUrlBuilder::display_category($category->get_id(), $category->get_rewrited_name())); } } return $response; }
} else { $db_where = null; } } else { $cat = 0; $db_where = null; $sub_cats = true; } $nbr_media = PersistenceContext::get_querier()->count(PREFIX . "media", 'WHERE ' . ($sub_cats && !empty($authorized_categories) ? 'idcat IN :authorized_categories' : 'idcat = :idcat') . (is_null($db_where) ? '' : ' AND infos = :infos'), array('authorized_categories' => $authorized_categories, 'idcat' => !empty($cat) ? $cat : 0, 'infos' => $db_where)); $categories_cache = MediaService::get_categories_manager()->get_categories_cache(); //On crée une pagination si le nombre de fichier est trop important. $page = AppContext::get_request()->get_getint('p', 1); $pagination = new ModulePagination($page, $nbr_media, $NUMBER_ELEMENTS_PER_PAGE); $pagination->set_url(new Url('/media/moderation_media.php?p=%d')); if ($pagination->current_page_is_empty() && $page > 1) { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } $result = PersistenceContext::get_querier()->select("SELECT media.*, media_cats.name AS cat_name\n\t\tFROM " . MediaSetup::$media_table . " media\n\t\tLEFT JOIN " . MediaSetup::$media_cats_table . " media_cats ON media_cats.id = media.idcat\n\t\tWHERE " . ($sub_cats && !empty($authorized_categories) ? 'idcat IN :authorized_categories' : 'idcat = :idcat') . (is_null($db_where) ? '' : ' AND infos = :infos') . "\n\t\tORDER BY infos ASC, timestamp DESC\n\t\tLIMIT :number_items_per_page OFFSET :display_from", array('authorized_categories' => $authorized_categories, 'idcat' => !empty($cat) ? $cat : 0, 'infos' => $db_where, 'number_items_per_page' => $pagination->get_number_items_per_page(), 'display_from' => $pagination->get_display_from())); while ($row = $result->fetch()) { $js_array[] = $row['id']; $tpl->assign_block_vars('files', array('ID' => $row['id'], 'NAME' => $row['name'], 'U_FILE' => url('media.php?id=' . $row['id'], 'media-' . $row['id'] . '-' . $row['idcat'] . '+' . Url::encode_rewrite($row['name']) . '.php'), 'U_EDIT' => url('media_action.php?edit=' . $row['id']), 'CAT' => $categories_cache->category_exists($row['idcat']) ? $row['cat_name'] : $LANG['unknown'], 'U_CAT' => url('media.php?cat=' . $row['idcat']), 'COLOR' => $row['infos'] == MEDIA_STATUS_UNVISIBLE ? '#FFEE99' : ($row['infos'] == MEDIA_STATUS_APROBED ? '#CCFFCC' : '#FFCCCC'), 'SHOW' => $row['infos'] == MEDIA_STATUS_APROBED ? ' checked="checked"' : '', 'HIDE' => $row['infos'] == MEDIA_STATUS_UNVISIBLE ? ' checked="checked"' : '', 'UNAPROBED' => $row['infos'] == MEDIA_STATUS_UNAPROBED ? ' checked="checked"' : '')); } $result->dispose(); $search_category_children_options = new SearchCategoryChildrensOptions(); $search_category_children_options->add_authorizations_bits(Category::READ_AUTHORIZATIONS); $search_category_children_options->add_authorizations_bits(Category::CONTRIBUTION_AUTHORIZATIONS); $tpl->put_all(array('C_DISPLAY' => true, 'C_PAGINATION' => $pagination->has_several_pages(), 'L_FILTER' => $MEDIA_LANG['filter'], 'L_DISPLAY_FILE' => $MEDIA_LANG['display_file'], 'L_ALL' => $MEDIA_LANG['all_file'], 'SELECTED_ALL' => is_null($db_where) ? ' selected="selected"' : '', 'L_FVISIBLE' => $MEDIA_LANG['visible'], 'SELECTED_VISIBLE' => $db_where === MEDIA_STATUS_APROBED ? ' selected="selected"' : '', 'L_FUNVISIBLE' => $MEDIA_LANG['unvisible'], 'SELECTED_UNVISIBLE' => $db_where === MEDIA_STATUS_UNVISIBLE ? ' selected="selected"' : '', 'L_FUNAPROBED' => $MEDIA_LANG['unaprobed'], 'SELECTED_UNAPROBED' => $db_where === MEDIA_STATUS_UNAPROBED ? ' selected="selected"' : '', 'L_CATEGORIES' => $MEDIA_LANG['from_cats'], 'CATEGORIES_TREE' => MediaService::get_categories_manager()->get_select_categories_form_field('idcat', LangLoader::get_message('form.category', 'common'), $cat, $search_category_children_options)->display()->render(), 'L_INCLUDE_SUB_CATS' => $MEDIA_LANG['include_sub_cats'], 'SUB_CATS' => is_null($sub_cats) ? ' checked="checked"' : ($sub_cats ? ' checked="checked"' : ''), 'L_MODO_PANEL' => $LANG['modo_panel'], 'L_NAME' => $LANG['name'], 'L_VISIBLE' => $MEDIA_LANG['show_media_short'], 'L_UNVISIBLE' => $MEDIA_LANG['hide_media_short'], 'L_UNAPROBED' => $MEDIA_LANG['unaprobed_media_short'], 'C_NO_MODERATION' => $nbr_media > 0 ? 0 : 1, 'L_NO_MODERATION' => $MEDIA_LANG['no_media_moderate'], 'L_CONFIRM_DELETE_ALL' => str_replace('\'', '\\\'', $MEDIA_LANG['confirm_delete_media_all']), 'L_LEGEND' => $MEDIA_LANG['legend'], 'L_FILE_UNAPROBED' => $MEDIA_LANG['file_unaprobed'], 'L_FILE_UNVISIBLE' => $MEDIA_LANG['file_unvisible'], 'L_FILE_VISIBLE' => $MEDIA_LANG['file_visible'], 'PAGINATION' => $pagination->display(), 'L_SUBMIT' => $LANG['submit'], 'L_RESET' => $LANG['reset'], 'JS_ARRAY' => '"' . implode('", "', $js_array) . '"')); } $tpl->display(); require_once '../kernel/footer.php';
bread_crumb($media['idcat']); $Bread_crumb->add($media['name'], url('media.php?id=' . $id_media, 'media-' . $id_media . '-' . $media['idcat'] . '+' . Url::encode_rewrite($media['name']) . '.php')); define('TITLE', $media['name']); require_once '../kernel/header.php'; //MAJ du compteur. PersistenceContext::get_querier()->inject("UPDATE " . PREFIX . "media SET counter = counter + 1 WHERE id = :id", array('id' => $id_media)); $notation = new Notation(); $notation->set_module_name('media'); $notation->set_notation_scale($config->get_notation_scale()); $notation->set_id_in_module($id_media); $notation->set_number_notes($media['number_notes']); $notation->set_average_notes($media['average_notes']); $notation->set_user_already_noted(!empty($media['note'])); $nbr_notes = $media['number_notes']; $group_color = User::get_group_color($media['groups'], $media['level']); $tpl->put_all(array('ID' => $id_media, 'C_DISPLAY_MEDIA' => true, 'C_ROOT_CATEGORY' => $media['idcat'] == Category::ROOT_CATEGORY, 'C_MODO' => MediaAuthorizationsService::check_authorizations($media['idcat'])->moderation(), 'C_DISPLAY_NOTATION' => $config->is_notation_enabled(), 'C_DISPLAY_COMMENTS' => $config->are_comments_enabled(), 'ID_MEDIA' => $id_media, 'NAME' => $media['name'], 'CONTENTS' => stripslashes(FormatingHelper::second_parse($media['contents'])), 'COUNT' => $media['counter'], 'KERNEL_NOTATION' => NotationService::display_active_image($notation), 'HITS' => (int) $media['counter'] + 1 > 1 ? sprintf($MEDIA_LANG['n_times'], (int) $media['counter'] + 1) : sprintf($MEDIA_LANG['n_time'], (int) $media['counter'] + 1), 'U_COM' => PATH_TO_ROOT . '/media/media' . url('.php?id=' . $id_media . '&com=0', '-' . $id_media . '-' . $media['idcat'] . '+' . Url::encode_rewrite($media['name']) . '.php?com=0') . '#comments-list', 'L_COM' => CommentsService::get_number_and_lang_comments('media', $id_media), 'L_DATE' => LangLoader::get_message('date', 'date-common'), 'L_SIZE' => $LANG['size'], 'L_MEDIA_INFOS' => $MEDIA_LANG['media_infos'], 'DATE' => Date::to_format($media['timestamp'], Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE), 'L_MODO_PANEL' => $LANG['modo_panel'], 'L_UNAPROBED' => $MEDIA_LANG['unaprobed_media_short'], 'HEIGHT_P' => $media['height'] + 50, 'L_VIEWED' => $LANG['view'], 'L_BY' => $LANG['by'], 'BY' => !empty($media['display_name']) ? '<a href="' . UserUrlBuilder::profile($media['iduser'])->rel() . '" class="' . UserService::get_level_class($media['level']) . '"' . (!empty($group_color) ? ' style="color:' . $group_color . '"' : '') . '>' . $media['display_name'] . '</a>' : $LANG['guest'], 'U_UNVISIBLE_MEDIA' => url('media_action.php?unvisible=' . $id_media . '&token=' . AppContext::get_session()->get_token()), 'U_EDIT_MEDIA' => url('media_action.php?edit=' . $id_media), 'U_DELETE_MEDIA' => url('media_action.php?del=' . $id_media . '&token=' . AppContext::get_session()->get_token()), 'U_POPUP_MEDIA' => url('media_popup.php?id=' . $id_media), 'CATEGORY_NAME' => $media['idcat'] == Category::ROOT_CATEGORY ? LangLoader::get_message('module_title', 'common', 'media') : MediaService::get_categories_manager()->get_categories_cache()->get_category($media['idcat'])->get_name(), 'U_EDIT_CATEGORY' => $media['idcat'] == Category::ROOT_CATEGORY ? MediaUrlBuilder::configuration()->rel() : MediaUrlBuilder::edit_category($media['idcat'])->rel())); if (empty($mime_type_tpl[$media['mime_type']])) { $media_tpl = new FileTemplate('media/format/media_other.tpl'); } else { $media_tpl = new FileTemplate('media/' . $mime_type_tpl[$media['mime_type']]); } $media_tpl->put_all(array('URL' => $media['url'], 'MIME' => $media['mime_type'], 'WIDTH' => $media['width'], 'HEIGHT' => $media['height'])); $tpl->put('media_format', $media_tpl); //Affichage commentaires. if (AppContext::get_request()->get_getint('com', 0) == 0) { $comments_topic = new MediaCommentsTopic(); $comments_topic->set_id_in_module($id_media); $comments_topic->set_url(new Url('/media/media.php?id=' . $id_media . '&com=0')); $tpl->put_all(array('COMMENTS' => CommentsService::display($comments_topic)->render())); } $tpl->display();
private function save() { $this->config->set_items_number_per_page($this->form->get_value('items_number_per_page')); $this->config->set_categories_number_per_page($this->form->get_value('categories_number_per_page')); $this->config->set_columns_number_per_line($this->form->get_value('columns_number_per_line')); if ($this->form->get_value('author_displayed')) { $this->config->display_author(); } else { $this->config->hide_author(); } if ($this->form->get_value('comments_enabled')) { $this->config->enable_comments(); } else { $this->config->disable_comments(); } if ($this->form->get_value('notation_enabled')) { $this->config->enable_notation(); $this->config->set_notation_scale($this->form->get_value('notation_scale')); if ($this->form->get_value('notation_scale') != $this->config->get_notation_scale()) { NotationService::update_notation_scale('media', $this->config->get_notation_scale(), $this->form->get_value('notation_scale')); } } else { $this->config->disable_notation(); } $this->config->set_max_video_width($this->form->get_value('max_video_width')); $this->config->set_max_video_height($this->form->get_value('max_video_height')); $this->config->set_root_category_description($this->form->get_value('root_category_description')); $this->config->set_root_category_content_type($this->form->get_value('root_category_content_type')->get_raw_value()); $this->config->set_authorizations($this->form->get_value('authorizations')->build_auth_array()); MediaConfig::save(); MediaService::get_categories_manager()->regenerate_cache(); }