def init_g(): # argumentos de busqueda por defecto g.args = {} g.active_types = {} g.active_srcs = {} # caracteristicas del cliente g.full_browser=is_full_browser() g.search_bot=is_search_bot() # peticiones en modo preproduccion g.beta_request = request.url_root[request.url_root.index("//")+2:].startswith("beta.") # prefijo para los contenidos estáticos if g.beta_request: app_static_prefix = current_app.static_url_path else: app_static_prefix = current_app.config["STATIC_PREFIX"] or current_app.static_url_path g.static_prefix = app_static_prefix current_app.assets.url = app_static_prefix + "/" g.autocomplete_disabled = "false" if current_app.config["SERVICE_TAMING_ACTIVE"] else "true" # dominio de la web g.domain = "foofind.is" if request.url_root.rstrip("/").endswith(".is") else "foofind.com" # informacion de la página por defecto g.title = g.domain g.keywords = set() g.page_description = g.title g.full_lang = current_app.config["ALL_LANGS_COMPLETE"][g.lang]
def init_g(): g.accept_cookies = None # argumentos de busqueda por defecto g.args = {} g.active_types = {} g.active_srcs = {} # caracteristicas del cliente g.full_browser=is_full_browser() g.search_bot=is_search_bot() # peticiones en modo preproduccion g.beta_request = request.url_root[request.url_root.index("//")+2:].startswith("beta.") # prefijo para los contenidos estáticos if g.beta_request: app_static_prefix = current_app.static_url_path else: app_static_prefix = current_app.config["STATIC_PREFIX"] or current_app.static_url_path g.static_prefix = app_static_prefix current_app.assets.url = app_static_prefix + "/" g.autocomplete_disabled = "false" if current_app.config["SERVICE_TAMING_ACTIVE"] else "true" # dominio de la web g.domain = "foofind.is" if request.url_root.rstrip("/").endswith(".is") else "foofind.com" # informacion de la página por defecto g.title = g.domain g.keywords = set() g.page_description = g.title g.full_lang = current_app.config["ALL_LANGS_COMPLETE"][g.lang] # downloader links g.downloader = current_app.config["DOWNLOADER"] g.downloader_properties = local_cache["downloader_properties"] g.user_build = current_app.config["DOWNLOADER_DEFAULT_BUILD"] # Find the best active build for the user for build, info in g.downloader_properties.iteritems(): try: if build != "common" and info["active"] and info["length"] and info.get("check_user_agent", lambda x:False)(request.user_agent): g.user_build = build except BaseException as e: logging.exception(e) accept_cookies = request.cookies.get("ck", "0") if accept_cookies=="0": if not (any(lang_code in request.accept_languages.values() for lang_code in current_app.config["SPANISH_LANG_CODES"]) or request.remote_addr in spanish_ips): accept_cookies = "2" g.accept_cookies = accept_cookies
def init_g(app): # cache por defecto g.must_cache = 7200 # caracteristicas del cliente g.full_browser=is_full_browser() g.search_bot=is_search_bot() # idioma ingles g.lang = "en" # peticiones en modo preproduccion g.beta_request = request.url_root[request.url_root.index("//")+2:].startswith("beta.") # prefijo para los contenidos estáticos if g.beta_request: app_static_prefix = app.static_url_path else: app_static_prefix = app.config["STATIC_PREFIX"] or app.static_url_path g.static_prefix = app.assets.url = app_static_prefix # permite sobreescribir practicamente todo el <head> si es necesario g.override_header = False # alerts system g.alert = {} g.keywords = {'torrents', 'download', 'files', 'search', 'audio', 'video', 'image', 'document', 'software'} g.show_blacklisted_content = app.config["SHOW_BLACKLISTED_CONTENT"] # informacion de categorias g.categories = categories_cache.categories g.categories_by_url = categories_cache.categories_by_url g.categories_results = None g.featured = [] # pagina actual g.page_type = None # busqueda actual g.track = False g.query = g.clean_query = None g.category = None # cookie control g.must_accept_cookies = app.config["MUST_ACCEPT_COOKIES"] # images server g.images_server = app.config["IMAGES_SERVER"] g.is_adult_content = False # permite ofrecer el downloader en enlaces de descarga g.offer_downloader = False # dominio de la web g.domain = None g.domains_family = app.config["ALLOWED_DOMAINS"] for domain in g.domains_family: if domain in request.url_root: g.domain = domain break else: return g.domain_cookies = [url_for('index.cookies', _domain=domain) for domain in g.domains_family if domain!=g.domain] g.section = "torrents" if g.domain=="torrents.fm" else "downloader" if g.domain=="torrents.ms" else "news" g.domain_capitalized = g.domain.capitalize() # RUM if "RUM_CODES" in app.config: rum_codes = app.config["RUM_CODES"] g.RUM_code = rum_codes[g.domain] if g.domain in rum_codes else rum_codes["torrents.com"] else: g.RUM_code = None # título de la página por defecto g.title = [g.domain_capitalized] # Patrón de URL de busqueda, para evitar demasiadas llamadas a url_for g.url_search_base = url_for("files.search", query="___") g.url_adult_search_base = url_for("files.category", category="p**n", query="___") # downloader links g.downloader_properties = local_cache["downloader_properties"]
def init_g(app): # secure? g.secure_request = request.headers.get("X-SSL-Active", "No")=="Yes" request.environ['wsgi.url_scheme'] = "https" if g.secure_request else "http" # cache por defecto g.must_cache = 7200 # caracteristicas del cliente g.full_browser=is_full_browser() g.search_bot=is_search_bot() # peticiones en modo preproduccion g.beta_request = request.url_root[request.url_root.index("//")+2:].startswith("beta.") # prefijo para los contenidos estáticos if g.beta_request: app_static_prefix = app.static_url_path else: app_static_prefix = app.config["STATIC_PREFIX"] or app.static_url_path g.static_prefix = app.assets.url = app_static_prefix # permite sobreescribir practicamente todo el <head> si es necesario g.override_header = False # alerts system g.alert = {} g.keywords = {'torrents', 'download', 'files', 'search', 'audio', 'video', 'image', 'document', 'software'} g.show_blacklisted_content = app.config["SHOW_BLACKLISTED_CONTENT"] # informacion de categorias g.categories = categories_cache.categories g.categories_by_url = categories_cache.categories_by_url g.categories_results = None g.featured = [] # pagina actual g.page_type = None # busqueda actual g.track = False g.query = g.clean_query = None g.category = None # cookie control g.must_accept_cookies = app.config["MUST_ACCEPT_COOKIES"] # images server g.images_server = app.config["IMAGES_SERVER"] g.is_adult_content = False # dominio de la web g.domain = None g.domains_family = app.config["ALLOWED_DOMAINS"] for domain in g.domains_family: if domain in request.url_root: g.domain = domain break else: return g.section = "torrents" if g.domain=="torrents.fm" else "downloader" if g.domain=="torrents.ms" else "news" g.domain_capitalized = g.domain.capitalize() # language selector g.langs = langs = app.config["LANGS"] g.translate_domains = app.config["TRANSLATE_DOMAINS"] g.lang = "".join(lang for lang in langs[1:] if lang+"."+g.domain in request.url_root) or langs[0] g.langs_switch = app.config["LANGS_SWITCH"] # IMPORTANT: DON'T USE URL_FOR BEFORE THIS POINT IN THIS FUNCTION! # RUM if "RUM_CODES" in app.config: rum_codes = app.config["RUM_CODES"] g.RUM_code = rum_codes[g.domain] if g.domain in rum_codes else rum_codes["torrents.com"] else: g.RUM_code = None # título de la página por defecto g.title = [g.domain_capitalized] # cookies g.domain_cookies = [url_for('index.cookies', _domain=domain) for domain in g.domains_family if domain!=g.domain] # Patrón de URL de busqueda, para evitar demasiadas llamadas a url_for g.url_search_base = url_for("files.search", query="___") g.url_adult_search_base = url_for("files.category", category="p**n", query="___") # permite ofrecer el downloader en enlaces de descarga g.offer_downloader = True # downloader links g.downloader_properties = local_cache["downloader_properties"] g.user_build = current_app.config["DOWNLOADER_DEFAULT_BUILD"] # Find the best active build for the user for build, info in g.downloader_properties.iteritems(): try: if build != "common" and info["active"] and info["length"] and info.get("check_user_agent", lambda x:False)(request.user_agent): g.user_build = build except BaseException as e: logging.exception(e) # banners g.banners = app.config["BANNERS"]