Exemplo n.º 1
0
 public function add($attributes)
 {
     if (empty($attributes['ids'])) {
         return;
     }
     $context['gallery'] = array_map(function ($item) {
         return new \TimberImage($item->ID);
     }, get_posts(['include' => $attributes['ids'], 'post_mime_type' => 'image', 'post_status' => 'inherit', 'post_type' => 'attachment', 'order' => 'ASC', 'orderby' => 'post__in']));
     return \Timber::fetch('partials/gallery.twig', $context);
 }
Exemplo n.º 2
0
 /**
  * This functions enables the new user fields on backend
  *
  * @param WP_User $user User to get information from.
  */
 function extra_user_profile_fields($user)
 {
     $admin_template = get_stylesheet_directory() . '/templates/admin/sc-user.twig';
     foreach ($this->custom_user_fields as $user_field) {
         $options['name'] = $user_field['name'];
         $options['available_values'] = $this->get_info_for_select($user_field['post_type']);
         $options['stored_values'] = get_user_meta($user->ID, $user_field['name'], true);
     }
     $section_html_content = Timber::fetch($admin_template, array('options' => $options));
     echo $section_html_content;
 }
            throw_error('500', 'Error connecting to API server');
            $context_holder['cerca_result'] = 'S\'ha produït un error en contactar amb el servidor. Proveu de nou.';
        }
    }
} else {
    if (!empty($lletra)) {
        if (strlen($lletra) == '1') {
            $url = $url_api . 'index/' . $lletra;
            $api_response = json_decode(do_json_api_call($url));
            if ($api_response) {
                $response['lletra'] = $lletra;
                $response['result'] = $api_response;
                $title = 'Diccionari multilingüe: paraules que comencen per ' . $lletra;
                $content_title = 'Diccionari multilingüe. Lletra «' . $lletra . '»';
                $canonical = '/diccionari-multilingue/lletra/' . $lletra . '/';
                $context_holder['cerca_result'] = Timber::fetch('ajax/multilingue-lletra.twig', array('response' => $response));
            } else {
                throw_error('500', 'Error connecting to API server');
                $context_holder['cerca_result'] = 'S\'ha produït un error en contactar amb el servidor. Proveu de nou.';
            }
        } else {
            throw_error('404', 'No Results For This Search');
            $context_holder['cerca_result'] = 'Esteu utilitzant la cerca per lletra. Heu cercat <strong>' . $context['lletra'] . '</strong>. La cerca només pot contenir una lletra';
        }
    }
}
$context_filterer = new SC_ContextFilterer($context_holder);
$context_overrides = array('title' => $title, 'description' => $description, 'canonical' => $canonical);
$context = $context_filterer->get_filtered_context($context_overrides, false);
$context['post'] = $post;
$context['paraula'] = $paraula;
Exemplo n.º 4
0
 /**
  * Renders the Softcatalà dashboard settings page
  */
 function softcatala_dash_page()
 {
     wp_enqueue_script('sc-js-dash', get_template_directory_uri() . '/static/js/sc-admin.js', array('jquery'), WP_SOFTCATALA_VERSION, true);
     $admin_template = dirname(__FILE__) . '/templates/admin/sc-dash.twig';
     $sections = $this->get_email_sections();
     $section_html_content = Timber::fetch($admin_template, array('sections' => $sections));
     echo $section_html_content;
 }
Exemplo n.º 5
0
 /**
  * Renders the dashboard page
  */
 function scimporter_dash_page()
 {
     $admin_template = dirname(__FILE__) . '/templates/admin/sc-importer.twig';
     $section_html_content = Timber::fetch($admin_template);
     echo $section_html_content;
 }
Exemplo n.º 6
0
/**
 * Function to look up a program with a title similar to the title from the search on the add program form
 *
 * @return json response
 */
function sc_search_program()
{
    if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], $_POST["action"])) {
        $result['text'] = "S'ha produït un error en cercar el programa. Podeu continuar igualment.";
    } else {
        check_is_ajax_call();
        $nom_programa = sanitize_text_field($_POST["nom_programa"]);
        $result = array();
        if (!empty($nom_programa)) {
            $query['s'] = $nom_programa;
            $args = get_post_query_args('programa', SearchQueryType::Programa, $query);
            $result_full = query_posts($args);
        }
        $programs = array_map('generate_post_url_link', $result_full);
        if (count($programs) > 0) {
            $result['programs'] = Timber::fetch('ajax/programs-list.twig', array('programs' => $programs));
            $result['text'] = "El programa que proposeu és algun dels que es mostren a continuació?";
        } else {
            $result['text'] = "El programa no està a la nostra base de dades. Podeu continuar!";
        }
    }
    $response = json_encode($result);
    die($response);
}
Exemplo n.º 7
0
//Ads
$context_holder['ads_container'] = generate_ads_html(array('13', '17'));
$paraula = sanitize_text_field(urldecode(get_query_var('paraula')));
$content_title = 'Diccionari de sinònims';
if (!empty($paraula)) {
    $url = $url_sinonims_server . urlencode($paraula);
    try {
        $sinonims_server = json_decode(do_json_api_call($url));
        if ($sinonims_server != 'error' && count($sinonims_server->synsets) > 0) {
            $sinonims['paraula'] = $paraula;
            $sinonims['response'] = $sinonims_server->synsets;
            $content_title = 'Diccionari de sinònims: «' . $paraula . '»';
            $title = 'Diccionari de sinònims en català: «' . $paraula . '»';
            $prefix_description = 'Sinònims de «' . $paraula . '» en català.';
            $canonical = get_current_url();
            $context_holder['sinonims_result'] = Timber::fetch('ajax/sinonims-list.twig', array('sinonims' => $sinonims));
        } else {
            if ($sinonims_server == 'error') {
                throw_service_error($content_title);
            } else {
                throw_error('404', 'No Results For This Search');
                $context_holder['sinonims_result'] = 'La paraula que esteu cercant no es troba al diccionari.';
            }
        }
    } catch (Exception $e) {
        throw_service_error($content_title);
    }
}
$context_overrides = array('title' => $title, 'prefix_description' => $prefix_description, 'canonical' => $canonical);
$context_filterer = new SC_ContextFilterer($context_holder);
$context = $context_filterer->get_filtered_context($context_overrides, false);