Exemplo n.º 1
0
function api_nested_cats()
{
    $args = ['taxonomy' => 'arc', 'hide_empty' => false];
    $terms = get_categories($args);
    $cats_tree = get_cat_tree(0, $terms);
    $resp_obj = ['status' => 'ok', 'message' => 'Arcs returned successfully.', 'data' => []];
    if (empty($cats_tree)) {
        $resp_obj['status'] = 'fail';
        $resp_obj['message'] = 'Failed to retrieve any arcs!';
    } else {
        foreach ($cats_tree as $ind => $cat) {
            $add = [];
            $add['arc_image'] = get_field('arc_image', 'arc_' . $cat->cat_ID);
            $add['display_order'] = get_field('display_order', 'arc_' . $cat->cat_ID);
            $cats_tree[$ind] = array_merge((array) $cat, (array) $add);
        }
        $resp_obj['data'] = $cats_tree;
    }
    return $resp_obj;
}
Exemplo n.º 2
0
function stage_fill_album()
{
    $cats = get_cat_tree();
    $big = array();
    foreach ($cats as $cat) {
        // iterate top level only
        $p = new Page(G::$base . $cat['link']);
        $p->go_line('"maintable');
        $curcatlink = '';
        $curcat = $cat;
        do {
            if ($p->curr_line()->contain('class="catlink"')) {
                $matches = $p->curr_line()->regex_match('/class="catlink"><a href="([^"]+)"/');
                $curcatlink = $matches[1];
                $curcat = G::$db->from('category')->where('link', $curcatlink)->doFetchRow();
            } else {
                if ($p->curr_line()->contain('class="alblink')) {
                    $info = array('category_id' => $curcat['id']);
                    // do {
                    // get info of 1 album
                    // <span class="alblink"><a href="thumbnails.php?album=233">T-ara</a></span>
                    $m = $p->curr_line()->regex_match('/href="([^"]+)">([^<]+)</');
                    $info['link'] = $m[1];
                    $info['name'] = $m[2];
                    $p->go_line('class="albums');
                    // <a href="thumbnails.php?album=233" class="albums"><img src="albums/userpics/10001/thumb_T-ara97.jpg" class="image" width="128" height="78" border="0" alt="T-ara97.jpg" /><br /></a>
                    $m = $p->curr_line()->regex_match('/src="([^"]+)"/');
                    $info['thumbnail'] = $m[1];
                    $p->go_line('class="album_stat');
                    // <p class="album_stat">133 files, last one added on Dec 28, 2010<br />Album viewed 310 times</p>
                    $m = $p->curr_line()->regex_match('/>(.*)<\\/p>/');
                    $info['desc'] = $m[1];
                    // } while (!$p->next_line()->contain('</table>'));
                    $big[$curcat['id']][] = $info;
                }
            }
        } while (!$p->next_line()->contain('var gaJsHost'));
    }
    // we have all albums
    file_put_contents('redflava.albums.export', var_export($big, true));
    // insert to database
    foreach ($big as $cat_id => $albums) {
        foreach ($albums as $album) {
            G::$db->set($album)->from('album')->doInsert();
        }
    }
}