Exemplo n.º 1
0
 function query($atts)
 {
     $default = array('limit' => -1, 'pagination' => true);
     $atts = wp_parse_args($atts, $default);
     if (!empty($atts['cat'])) {
         $atts['tax_query']['relation'] = 'OR';
         if (!empty($atts['cat'])) {
             $atts['tax_query'][] = array('taxonomy' => 'category', 'field' => 'slug', 'terms' => $atts['cat']);
             unset($atts['cat']);
         }
     }
     if ($atts['limit']) {
         $atts['posts_per_page'] = $atts['limit'];
         unset($atts['limit']);
         if ($atts['pagination']) {
             $atts['paged'] = get_page_query();
         }
     }
     return $atts;
 }
function read_alphabetic_list($dom)
{
    #  $first_id = $last_id = -1;
    list($first_id, $last_id) = get_page_query($dom);
    #  echo "\nfirst = $first_id_str; last = $last_id_str";
    # 3) get search result div list
    # <div class="searchResultBox"> <div>
    #     <!-- <p>select_url: <span tal:content="python:request.get('page_settings').get('select_url')" /></p> -->
    #     <a href="http://rdnet.dk/ddo/ordbog?aselect=opstoppertud&amp;query=ord&amp;first_id=59964&amp;last_id=60003">
    #       opstoppertud
    #     </a> sb.
    #   </div> </div>
    $searchResultBox = $dom->find("div.searchResultBox");
    if (count($searchResultBox) == 3) {
        #  echo "\nsearchResultBox: " . $searchResultBox[0]->outertext; # testing
        #  echo "\nsearchResultBox: " . $searchResultBox[1]->outertext; # testing
        #  echo "\nsearchResultBox: " . $searchResultBox[2]->outertext; # testing
        $id = $first_id;
        foreach ($searchResultBox[2]->find("div") as $data) {
            $children = $data->children();
            $children[0]->outertext = "\n";
            $href = trim($children[1]->href);
            $word = trim($children[1]->innertext);
            $children[1]->outertext = "\n";
            $type = trim($data->innertext);
            # 3b) save to db
            echo "\nid={$id}\n";
            $data = array("id" => $id++, "word" => $word, "type" => $type, "href" => $href);
            $table_name = "word_list";
            $verbose = 2;
            $message = scraperwiki::save_sqlite(array("id"), $data, $table_name, $verbose);
            print_r($message);
            #test
            #      echo json_encode($data);
            if ($id == 3) {
                break;
            }
        }
    }
}
Exemplo n.º 3
0
/**
 * Query Generator
 * Generate query and loop through it, with column logic enabled.
 */
function spyropress_query_generator($atts, $content = null)
{
    // default setting
    $default = array('callback' => '', 'row' => 1, 'row_container' => 'div', 'row_class' => get_row_class(true), 'column_class' => '', 'columns' => 1, 'pagination' => false);
    $atts = wp_parse_args($atts, $default);
    $output = '';
    $counter = $column_counter = 0;
    $columns = $atts['columns'];
    $callback = $atts['callback'];
    $close = false;
    // Add Pagination
    if ($atts['limit']) {
        $atts['posts_per_page'] = $atts['limit'];
        unset($atts['limit']);
        if ($atts['pagination']) {
            $atts['paged'] = get_page_query();
        }
    }
    // set column cssClass
    $colclass = array();
    $colclass[] = get_column_class($columns);
    $colclass[] = $atts['column_class'];
    // if is archive merge wp_query
    if (is_archive() || is_search()) {
        global $wp_query;
        if (!empty($wp_query->query)) {
            $atts = array_merge($wp_query->query, $atts);
        }
    }
    // init wp_query
    $posts = new WP_Query($atts);
    if ($posts->have_posts()) {
        while ($posts->have_posts()) {
            $posts->the_post();
            $counter++;
            // if has column defined
            if ($columns) {
                $column_counter++;
                $colclass_fl = array();
                if ($column_counter == 1) {
                    if ($atts['row']) {
                        $output .= '<' . $atts['row_container'] . ' class="' . $atts['row_class'] . '">';
                        $close = true;
                    }
                    $colclass_fl[] = get_first_column_class();
                }
                if ($column_counter == $columns) {
                    $colclass_fl[] = get_last_column_class();
                }
                $atts['column_class'] = spyropress_clean_cssclass(array_merge($colclass, $colclass_fl));
                // get the item using the defined callback function
                if ($callback) {
                    $output .= call_user_func_array($callback, array(get_the_ID(), $atts, $counter, $column_counter));
                }
                if ($column_counter == $columns) {
                    $column_counter = 0;
                    if ($atts['row']) {
                        $output .= '</' . $atts['row_container'] . '>';
                        $close = false;
                    }
                }
            } else {
                if ($callback) {
                    $output .= call_user_func_array($callback, array(get_the_ID(), $atts, $counter, $column_counter));
                }
            }
        }
        // close last unclosed row
        if (isset($atts['row']) && $atts['row'] && $close) {
            $output .= '</' . $atts['row_container'] . '>';
        }
        wp_reset_query();
        // get pagination for query if enabled
        $pagination = '';
        if ($atts['pagination']) {
            $pagination = wp_pagenavi(array('query' => $posts, 'echo' => false));
        }
        return array('content' => $output, 'pagination' => $pagination);
    } else {
        wp_reset_query();
        return;
    }
}