Unknown Account#i', $html); } /** * parse a category page * @param: string category url * @param: bool parse only sub-categories * @param: bool parse only one level * @return: array category */ function parse_category($url, $path, $cats_only=false, $one_level=false) { $url = str_replace('&page=all', null, $url); $current = array( 'url' => $url, 'path' => null, 'id' => null, ); // id $temp = parse_url($url); $temp = explode('/', $temp['path']); $current['id'] = $temp[ count($temp)-1 ]; $current['path'] = $path.'/'.$current['id']; if ($one_level === 'stop') { return $current; } $current = array_merge($current, array( 'title' => null, 'description' => null, 'pictures' => array(), 'categories' => array(), 'nb_pictures' => 0, 'nb_categories' => 0, )); $url.= '&page=all'; // seriously... (should be ? not &) $html = get_file_cached($url); if ($html == 'file_error') { return $current; } preg_match('#(.*)#is', $html, $matches); $body = $matches[1]; // content // if (preg_match('#
(.*)
#is', $body, $matches) === 0) return 'null1'; if (preg_match_all('#]*)" class="thumbnail">#i', $body, $matches) === 0) return $current; $links = $matches[1]; // title if (preg_match('#

(.*?)

#i', $body, $matches)) { $current['title'] = trim($matches[1]); } else { $current['title'] = $current['id']; } // description if (preg_match('#(.*?)#s', $body, $matches)) { $current['description'] = trim($matches[1]); } // sub-cats and pictures foreach ($links as $link) { if (strpos($link, '/image/') !== false) { if (($image = parse_image($link, $cats_only)) !== null) { $current['pictures'][ $image['id'] ] = $image; } $current['nb_pictures']++; } else { $next_level = ($one_level === true) ? 'stop' : false; if (($category = parse_category($link, $current['path'], $cats_only, $next_level)) !== null) { $current['categories'][ $category['id'] ] = $category; } $current['nb_categories']++; } } return $current; } /** * parse a picture page * @param: string picture url * @param: bool return only url and id * @return: array picture */ function parse_image($url, $light=false) { $url = preg_replace('#/(small|medium|large|original)$#', null, $url); $current = array( 'url' => $url, 'id' => null, ); // id $temp = parse_url($url); $temp = explode('/', $temp['path']); $current['id'] = $temp[ count($temp)-1 ]; if ($light) { return $current; } $current = array_merge($current, array( 'title' => null, 'path' => null, 'description' => null, 'date' => null, 'author' => null, 'keywords' => array(), )); $url.= '/original'; $html = get_file_cached($url); if ($html == 'file_error') { return $current; } preg_match('#(.*)#is', $html, $matches); $body = $matches[1]; // path if (preg_match('#]*)class="display" src="([^">]*)"#i', $body, $matches) ===0) return null; $current['path'] = $matches[2]; // title preg_match('#(.*?)#i', $body, $matches); if (!empty($matches[1])) { $current['title'] = trim($matches[1]); $current['title'] = get_filename_wo_extension($current['title']); } else { $current['title'] = $current['id']; } // description if (preg_match('#

(.*?)

#is', $body, $matches)) { $current['description'] = trim($matches[1]); } // date if (preg_match('#(.*?)#i', $body, $matches)) { $current['date'] = trim($matches[1]); } // author if (preg_match('#(.*?)#i', $body, $matches)) { $current['author'] = trim($matches[1]); } preg_match('#(.*)#is', $html, $matches); $head = $matches[1]; // keywords if (preg_match('#]*)">#i', $head, $matches)) { $words = explode(',', $matches[1]); foreach ($words as $word) { if (!empty($word)) $current['keywords'][] = trim($word); } } return $current; } /** * print categories tree (list or select) * @param: array tree * @param: int level * @param: string tree type (list|select) * @return: string */ function print_tree(&$tree, $level=0, $type='list') { $out = ''; if ($type == 'list') { $out.= '
'; } else if ($type == 'select') { $i=0; foreach ($tree as $item) { $out.= '