|
19 | 19 |
|
20 | 20 | // Static pages are treated as sites in themselves. |
21 | 21 | if($type == 'single_page' ){ |
| 22 | + single_page_adder($site_url); |
22 | 23 |
|
23 | | - // The adder cURLs the site to test if the URL can be scanned. |
24 | | - $curled_site = single_page_adder($site_url); |
| 24 | +// WordPress sites are added via their API. |
| 25 | +}elseif($type == 'wordpress'){ |
| 26 | + wordpress_site_adder($site_url); |
25 | 27 |
|
26 | | - // Site URL changes to the curled URL. |
27 | | - $site_url = $curled_site['url']; |
28 | | - |
29 | | - // Single pages are saved with the following pramenters |
30 | | - $type = 'single_page'; |
31 | | - $status = 'active'; |
32 | | - $site = $curled_site['url']; |
33 | | - $is_parent = 1; |
34 | | - DataAccess::add_page($site_url, $type, $status, $site, $is_parent ); |
35 | | - |
36 | | -// WordPress and XML deals with adding pages similarly, |
37 | | -// so their functions are wrapped in one condition. |
38 | | -}elseif($type == 'wordpress' || $type == 'xml' ){ |
39 | | - |
40 | | - // WordPress API is queried to create sites. |
41 | | - if($type == 'wordpress' ) |
42 | | - $curled_site = wordpress_site_adder($site_url); |
43 | | - |
44 | | - // .XML adder can create lots of pages. |
45 | | - if($type == 'xml' ) |
46 | | - $curled_site = xml_site_adder($site_url); |
47 | | - |
48 | | - // Both XML and WP deliver similar content. |
49 | | - $pages = $curled_site['contents']; |
50 | | - $site_url = $curled_site['url']; |
51 | | - |
52 | | - // We're setting the status and adding pages here so we |
53 | | - // do not have to call the db inside "models/adders.php", |
54 | | - // keeping each model focused on distinct functions. |
55 | | - $pages_records = []; |
56 | | - foreach ($pages as &$page): |
57 | | - |
58 | | - // Though these variables were set, we must reset them for |
59 | | - // one page, since we have now generated many pages. |
60 | | - if($site_url == $page['url']){ |
61 | | - $is_parent = 1; |
62 | | - |
63 | | - // This will be used later.. |
64 | | - $has_parent = true; |
65 | | - |
66 | | - }else{ |
67 | | - $is_parent = ''; |
68 | | - } |
69 | | - |
70 | | - // Push each page to pages' records. |
71 | | - array_push( |
72 | | - $pages_records, |
73 | | - array( |
74 | | - 'url' => $page['url'], |
75 | | - 'site' => $site_url, |
76 | | - 'is_parent' => $is_parent, |
77 | | - 'status' => 'active', |
78 | | - 'type' => $type |
79 | | - ) |
80 | | - ); |
81 | | - |
82 | | - endforeach; |
83 | | - |
84 | | - // Some newly created record arrays do not have existing sites |
85 | | - // and do not contain a parent because API/XML records contain |
86 | | - // different URLs than the URL where the API/XML exists. In that |
87 | | - // case, the first record, which is often the homepage, becomes |
88 | | - // the parent. |
89 | | - if(!isset($has_parent) && !isset($existing_site)){ |
90 | | - $first_record = &$pages_records[0]; |
91 | | - $first_record['is_parent'] = 1; |
92 | | - } |
93 | | - |
94 | | - // Finalllly, we can add pages to the DB. |
95 | | - DataAccess::add_pages($pages_records); |
| 28 | +// .XML sites use the latest version of XML standards. |
| 29 | +}elseif($type == 'xml'){ |
| 30 | + xml_site_adder($site_url); |
96 | 31 |
|
97 | 32 | // Since we're passing type through a URL, we have a fallback |
98 | 33 | // in case someone passes an unsupported 'type'. |
99 | 34 | }else{ |
100 | | - die('"'.$type.'" sites are unsupported.'); |
| 35 | + throw new Exception('"'.$type.'" sites are unsupported'); |
101 | 36 | } |
102 | 37 |
|
103 | 38 | // Back home we go. |
|
0 commit comments