示例#1
0
/**
 * Parser post's content with function reference pieces.
 */
function the_content()
{
    static $post_types = array('wp-parser-class', 'wp-parser-method', 'wp-parser-function', 'wp-parser-hook');
    $post = get_post();
    $content = get_the_content();
    if (!in_array($post->post_type, $post_types, true)) {
        return $content;
    }
    $before_content = 'wp-parser-hook' === $post->post_type ? get_hook_prototype() : get_prototype();
    $before_content .= '<p class="wp-parser-description">' . get_the_excerpt() . '</p>';
    $before_content .= '<div class="wp-parser-longdesc">';
    $after_content = '</div>';
    $after_content .= '<div class="wp-parser-arguments"><h3>Arguments</h3>';
    $args = 'wp-parser-hook' === $post->post_type ? get_hook_arguments() : get_arguments();
    foreach ($args as $arg) {
        $after_content .= '<div class="wp-parser-arg">';
        $after_content .= '<h4><code><span class="type">' . implode('|', $arg['types']) . '</span> <span class="variable">' . $arg['name'] . '</span></code></h4>';
        $after_content .= empty($arg['desc']) ? '' : wpautop($arg['desc'], false);
        $after_content .= '</div>';
    }
    $after_content .= '</div>';
    $source = get_source_link();
    if ($source) {
        $after_content .= '<a href="' . $source . '">Source</a>';
    }
    $before_content = apply_filters('wp_parser_before_content', $before_content);
    $after_content = apply_filters('wp_parser_after_content', $after_content);
    echo $before_content . $content . $after_content;
}
/**
 * Retrieves the results from the Multilingüe API server given a word + language
 *
 * @return json response
 */
function sc_multilingue_search()
{
    if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], $_POST["action"])) {
        $result = 'S\'ha produït un error en contactar amb el servidor. Proveu de nou.';
    } else {
        $paraula = sanitize_text_field($_POST["paraula"]);
        $lang = sanitize_text_field($_POST["lang"]);
        $url_api = get_option('api_diccionari_multilingue');
        $url = $url_api . 'search/' . $paraula . '?lang=' . $lang;
        $api_call = do_json_api_call($url);
        if (is_array($api_call)) {
            throw_error('404', 'No Results For This Search');
            $result = 'Sembla que la paraula que esteu cercant no es troba al diccionari. Heu seleccionat la llengua correcta?';
        } else {
            if ($api_call && $api_call != 'error') {
                $api_response = json_decode($api_call);
                if (isset($api_response[0])) {
                    $resultat_string = count($api_response) > 1 ? 'resultats' : 'resultat';
                    $result = 'Resultats de la cerca per: <strong>' . $paraula . '</strong> (' . count($api_response) . ' ' . $resultat_string . ') <hr class="clara"/>';
                    foreach ($api_response as $single_entry) {
                        $response['paraula'] = $paraula;
                        $response['source'] = get_source_link($single_entry);
                        //Unset main source/other sources
                        $refs = (array) $single_entry->references;
                        unset($refs[$single_entry->source]);
                        $single_entry->references = $refs;
                        $response['result'] = $single_entry;
                        $result .= Timber::fetch('ajax/multilingue-paraula.twig', array('response' => $response));
                    }
                } else {
                    throw_error('404', 'No Results For This Search');
                    $result = 'Sembla que la paraula que esteu cercant no es troba al diccionari. Heu seleccionat la llengua correcta?';
                }
            } else {
                throw_error('500', 'Error connecting to API server');
                $result = 'S\'ha produït un error en contactar amb el servidor. Proveu de nou.';
            }
        }
    }
    echo json_encode($result);
    die;
}
         $result = 'Resultats de la cerca per: <strong>' . $paraula . '</strong> (' . count($api_response) . ' ' . $resultat_string . ') <hr class="clara"/>';
         $title = 'Diccionari multilingüe: ' . $paraula . '. Definició i traducció al català, anglès, alemany, francès, italià i espanyol | Softcatalà';
         $content_title = 'Diccionari multilingüe: «' . $paraula . '»';
         if (isset($llengua)) {
             $canonical = '/diccionari-multilingue/paraula/' . $api_response[0]->word_ca . '/';
         } else {
             $canonical = '/diccionari-multilingue/paraula/' . $paraula . '/';
         }
         if (property_exists($api_response[0], 'definition_ca')) {
             $description = 'Definició de «' . $paraula . '»: ' . $api_response[0]->definition_ca . '. Traduccions al català, anglès, alemany, francès, italià i espanyol';
         } else {
             $description = 'Definició de la paraula «' . $paraula . '» i traduccions al català, anglès, alemany, francès, italià i espanyol';
         }
         foreach ($api_response as $single_entry) {
             $response['paraula'] = $paraula;
             $response['source'] = get_source_link($single_entry);
             //Unset main source/other sources
             $refs = (array) $single_entry->references;
             unset($refs[$single_entry->source]);
             $single_entry->references = $refs;
             $response['result'] = $single_entry;
             $result .= Timber::fetch('ajax/multilingue-paraula.twig', array('response' => $response));
         }
     } else {
         throw_error('404', 'No Results For This Search');
         $context_holder['cerca_result'] = 'Sembla que la paraula que esteu cercant no es troba al diccionari. Heu seleccionat la llengua correcta?';
     }
     $context_holder['cerca_result'] = $result;
 } 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.';