Advertisement
Guest User

Untitled

a guest
Apr 14th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.19 KB | None | 0 0
  1. <?php
  2.  
  3. // TODO global.php MUST BE PLACED ONE FILE LEVEL ABOVE TO FUNCTION
  4. include_once '../global.php';
  5.  
  6. // get the identifier for the page we want to load
  7. $action = $_GET['action'];
  8.  
  9. // instantiate a controller and route it
  10. $sc = new Index();
  11. $sc->route($action);
  12.  
  13.  
  14. class Index{
  15.  
  16. // route us to the appropriate class method for this action
  17. public function route($action) {
  18. switch($action) {
  19.  
  20. // home page, login, logout
  21. case 'home':
  22. $this->home();
  23. $this->getTemp('London');
  24. break;
  25. case 'login':
  26. $this->login();
  27. break;
  28. case 'loginSubmit':
  29. $username = $_POST['username'];
  30. $password = $_POST['pw'];
  31. $this -> loginSubmit($username, $password);
  32. break;
  33. case 'logout':
  34. $this -> logout();
  35. break;
  36. case 'register':
  37. $this -> register();
  38. break;
  39. case 'confirm_reg':
  40. $this -> confirm_reg();
  41. break;
  42.  
  43. // add location/people
  44. case 'add_loc':
  45. $this->add_loc();
  46. break;
  47. case 'confirm_loc':
  48. $this->confirm_loc();
  49. break;
  50. case 'add_person':
  51. $this->add_person();
  52. break;
  53. case 'confirm_person':
  54. $this->confirm_person();
  55. break;
  56.  
  57. // display/edit people
  58. case 'view_person':
  59. $name = $_GET['name'];
  60. $this->view_person($name);
  61. break;
  62. case 'edit_person':
  63. $name = $_GET['name'];
  64. $this->edit_person($name);
  65. break;
  66. case 'edit_person_complete':
  67. $name = $_GET['name'];
  68. $this->edit_person_complete($name);
  69. break;
  70. case 'person_article_complete':
  71. $name = $_GET['name'];
  72. $this->person_article_complete($name);
  73. break;
  74. case 'person_delete':
  75. $name = $_GET['name'];
  76. $this->person_delete($name);
  77. break;
  78.  
  79. // display/edit locations
  80. case 'view_loc':
  81. $name = $_GET['name'];
  82. $this->view_loc($name);
  83. break;
  84. case 'edit_loc':
  85. $name = $_GET['name'];
  86. $this->edit_loc($name);
  87. break;
  88. case 'edit_loc_complete':
  89. $name = $_GET['name'];
  90. $this->edit_loc_complete($name);
  91. break;
  92. case 'loc_article_complete':
  93. $name = $_GET['name'];
  94. $this->loc_article_complete($name);
  95. break;
  96. case 'loc_delete':
  97. $name = $_GET['name'];
  98. $this->loc_delete($name);
  99. break;
  100.  
  101. // list view
  102. case 'list_locations':
  103. $this->list_locations();
  104. break;
  105. case 'list_people':
  106. $this->list_people();
  107. break;
  108. case 'list_community':
  109. $this->list_community();
  110. break;
  111.  
  112. // profiles
  113. case 'view_profile':
  114. $name = $_GET['name'];
  115. $this -> view_profile($name);
  116. break;
  117. case 'edit_profile':
  118. $name = $_GET['name'];
  119. $this -> edit_profile($name);
  120. break;
  121. case 'edit_profile_complete':
  122. $name = $_GET['name'];
  123. $this -> edit_profile_complete($name);
  124. break;
  125. case 'follow':
  126. $name = $_GET['name'];
  127. $this -> follow($name);
  128. break;
  129. case 'unfollow':
  130. $name = $_GET['name'];
  131. $this -> unfollow($name);
  132. break;
  133.  
  134. }
  135. }
  136.  
  137. //////////////////////////////////////////////////////////////////////////////////
  138.  
  139. public function home() {
  140. $pageTitle = 'Home';
  141. include_once SYSTEM_PATH.'/view/header.tpl';
  142. $test = $this->getTemp('Aliceville');
  143. include_once SYSTEM_PATH.'/view/home.tpl';
  144. // TODO: AJAX widget?
  145. // echo '<p style="margin-right: 10%; font-size:large;"> Current Weather in Aliceville: '.$test['description'].'</p>';
  146. // TODO: pull data and put into feed
  147. if(!isset($_SESSION['username'])){
  148. // add template here
  149. }
  150. include_once SYSTEM_PATH.'/view/footer.tpl';
  151. }
  152.  
  153. public function login(){
  154. $pageTitle = 'Login';
  155. include_once SYSTEM_PATH.'/view/header.tpl';
  156. include_once SYSTEM_PATH.'/view/login.tpl';
  157. include_once SYSTEM_PATH.'/view/footer.tpl';
  158. }
  159.  
  160. public function loginSubmit($un, $pw){
  161.  
  162. $db = Db::instance(); // create db connection
  163. // build query
  164. $q = sprintf("SELECT * FROM User_Data WHERE username = %d;", $un);
  165. $result = $db->query($q); // execute query
  166.  
  167. // make sure we found something
  168. if($result->num_rows == 0) {
  169. header('Location: '.BASE_URL.'/login');
  170. } else {
  171. $row = $result->fetch_assoc(); // get results as associative array
  172. $correctPassword = $row['password'];
  173. }
  174.  
  175. if($pw == $correctPassword){
  176. $_SESSION['permissions'] = $row['permissions'];
  177. $_SESSION['username'] = $un;
  178.  
  179. //add to activity feed
  180. $this->addActivity('login', 'login');
  181.  
  182. header('Location: '.BASE_URL.'/community/'.$un);
  183. }
  184. else
  185. header('Location: '.BASE_URL.'/login');
  186. }
  187.  
  188. public function logout(){
  189. // end session
  190. $this->addActivity('logout', 'logout');
  191. unset($_SESSION['username']);
  192. session_destroy();
  193. // return to home page
  194. header('Location: '.BASE_URL);
  195. }
  196.  
  197. public function register(){
  198. $pageTitle = 'Register';
  199. include_once SYSTEM_PATH.'/view/header.tpl';
  200. include_once SYSTEM_PATH.'/view/signup.tpl';
  201. include_once SYSTEM_PATH.'/view/footer.tpl';
  202. }
  203.  
  204. public function confirm_reg(){
  205.  
  206. // get POST variables
  207. $username = $_POST['username_in'];
  208. $first_name = $_POST['first_name_in'];
  209. $last_name = $_POST['last_name_in'];
  210. $email = $_POST['email_in'];
  211. $password = $_POST['password_in'];
  212. $gender = $_POST['gender'];
  213. $permissions = 'user';
  214.  
  215. // required fields
  216. if( empty($username) | empty($first_name) | empty($last_name) | empty($email) | empty($password) | empty($gender) ) {
  217. header('Location: '.BASE_URL.'/register/');
  218. }
  219.  
  220. $user = new User();
  221.  
  222. $user->username = $username;
  223. $user->first_name = $first_name;
  224. $user->last_name = $last_name;
  225. $user->email = $email;
  226. $user->password = $password;
  227. $user->gender = $gender;
  228. $user->permissions = $permissions;
  229.  
  230. $memID = $user->u_save();
  231. header('Location: '.BASE_URL.'/login');
  232.  
  233. }
  234. //////////////////////////////////////////////////////////////////////////////////
  235.  
  236. public function add_person(){
  237. // can not add if not logged in
  238. if(!isset($_SESSION['username'])){
  239. header('Location: '.BASE_URL);
  240. }
  241.  
  242. $pageTitle = "Add New Person";
  243. include_once SYSTEM_PATH.'/view/header.tpl';
  244. include_once SYSTEM_PATH.'/view/add_person.tpl';
  245. include_once SYSTEM_PATH.'/view/footer.tpl';
  246. }
  247.  
  248. public function confirm_person(){
  249.  
  250. // can not edit if not logged in
  251. if(!isset($_SESSION['username'])){
  252. header('Location: '.BASE_URL);
  253. }
  254.  
  255. // get POST variables
  256. $first_name = $_POST['first_name_in']; // required
  257. $last_name = $_POST['last_name_in']; // required
  258. $date_captured = $_POST['dc_in'];
  259. $age = $_POST['age_in'];
  260. $profile_image = $_POST['profile_image_in'];
  261. $etc = $_POST['etc_in'];
  262.  
  263. // name is required
  264. if( empty($name)) {
  265. header('Location: '.BASE_URL.'/add_person/');
  266. }
  267.  
  268. $person = new Person();
  269.  
  270. $person->first_name = $first_name;
  271. $person->last_name = $last_name;
  272. $person->date_captured = $date_captured;
  273. $person->age = $age;
  274. $person->profile_image = $profile_image;
  275. $person->etc = $etc;
  276.  
  277. $memID = $person->p_save();
  278. header('Location: '.BASE_URL.'/people/'.$last_name);
  279. }
  280.  
  281. public function add_loc(){
  282. // can not add if not logged in
  283. if(!isset($_SESSION['username'])){
  284. header('Location: '.BASE_URL);
  285. }
  286.  
  287. $pageTitle = "Add New Location";
  288. // TODO post template here
  289. }
  290.  
  291. public function confirm_loc(){
  292.  
  293. // can not edit if not logged in
  294. if(!isset($_SESSION['username'])){
  295. header('Location: '.BASE_URL);
  296. }
  297.  
  298. // get POST variables
  299. $name = $_POST['name_in']; // required
  300. $activities = $_POST['activities_in'];
  301. $staff = $_POST['staff_in'];
  302. $capacity = $_POST['capacity_in'];
  303. $cost = $_POST['cost_in'];
  304. $profile_image = $_POST['profile_image_in'];
  305. $brief_description = $_POST['brief_description'];
  306.  
  307. // name is required
  308. if( empty($name)) {
  309. header('Location: '.BASE_URL.'/add_location/');
  310. }
  311.  
  312. $place = new Location();
  313.  
  314. $place->name = $name;
  315. $place->activities = $activities;
  316. $place->staff = $staff;
  317. $place->capacity = $capacity;
  318. $place->cost = $cost;
  319.  
  320. $memID = $place->l_save();
  321. $name = ucwords(str_replace(" ", "_", $name));
  322. header('Location: '.BASE_URL.'/locations/'.$name);
  323. }
  324.  
  325. //////////////////////////////////////////////////////////////////////////////////
  326.  
  327.  
  328. public function view_person($name){
  329.  
  330. // check if valid, and post
  331. $person = Person::p_loadByID($name);
  332. if($person == null) {
  333. die('Invalid id');
  334. }
  335. $pageTitle = $person->first_name;
  336.  
  337. $list = Article::getByTargetID($person->id, "People");
  338.  
  339. include_once SYSTEM_PATH.'/view/header.tpl';
  340. include_once SYSTEM_PATH.'/view/person.tpl';
  341. include_once SYSTEM_PATH.'/view/footer.tpl';
  342.  
  343. }
  344.  
  345. public function edit_person($name){
  346.  
  347. // can not edit if not logged in
  348. if(!isset($_SESSION['username'])){
  349. header('Location: '.BASE_URL);
  350. }
  351.  
  352. // check if valid, and post
  353. $person = Person::p_loadByID($name);
  354. if($person == null) {
  355. die('Invalid name');
  356. }
  357.  
  358. // title
  359. $pageTitle = "Edit $person->first_name";
  360. $list = Article::getByTargetID($person->id, "People");
  361. //templates
  362. include_once SYSTEM_PATH.'/view/header.tpl';
  363. include_once SYSTEM_PATH.'/view/edit_person.tpl';
  364. include_once SYSTEM_PATH.'/view/footer.tpl';
  365. }
  366.  
  367. public function edit_person_complete($name){
  368.  
  369. // can not edit if not logged in
  370. if(!isset($_SESSION['username'])){
  371. header('Location: '.BASE_URL);
  372. }
  373.  
  374. // get POST variables
  375. $first_name = $_POST['first_name_in'];
  376. $last_name = $_POST['last_name_in'];
  377. $date_captured = $_POST['dc_in'];
  378. $age = $_POST['age_in'];
  379. $profile_image = $_POST['profile_image_in'];
  380. $etc = $_POST['etc_in'];
  381.  
  382.  
  383. $person = Person::p_loadByID($last_name);
  384.  
  385. $person->first_name = $first_name;
  386. $person->date_captured = $date_captured;
  387. $person->age = $age;
  388. $person->profile_image = $profile_image;
  389. $person->etc = $etc;
  390.  
  391. // Add to user's activity
  392. $this->addActivity($name, 'edit');
  393.  
  394.  
  395.  
  396. $memID = $person->p_save();
  397. $name = ucwords(str_replace(" ", "_", $name));
  398. header('Location: '.BASE_URL.'/people/'.$name);
  399. }
  400.  
  401. public function person_article_complete($name){
  402.  
  403. // can not add article if not logged in
  404. if(!isset($_SESSION['username'])){
  405. header('Location: '.BASE_URL);
  406. }
  407.  
  408. // get POST variables
  409. $target_id = $_POST['target_id_in'];
  410. $article_title = $_POST['article_title_in'];
  411. $article_text = $_POST['article_text_in'];
  412. $article_image = $_POST['article_image_in'];
  413.  
  414. $article = new Article();
  415.  
  416. $article->target_id = $target_id;
  417. $article->article_title = $article_title;
  418. $article->article_text = $article_text;
  419. $article->article_image = $article_image;
  420.  
  421. $article->save("People");
  422. $name = ucwords(str_replace(" ", "_", $name));
  423. header('Location: '.BASE_URL.'/people/'.$name);
  424.  
  425. }
  426.  
  427. public function person_delete($name){
  428.  
  429. // can not remove if not logged in
  430. if(!isset($_SESSION['username'])){
  431. header('Location: '.BASE_URL);
  432. }
  433.  
  434. // check if valid
  435. $person = Person::loadByName($name);
  436. if($person == null) {
  437. die('Invalid family member name');
  438. }
  439.  
  440. // remove all data sections
  441. $articles = Article::getByTargetID($person->id, "People");
  442. foreach($articles as $art){
  443. $art->remove();
  444. }
  445.  
  446. // call remove function on member page
  447. $person->remove();
  448.  
  449. $this->addActivity($name, 'delete');
  450.  
  451. header('Location: '.BASE_URL.'/people');
  452. }
  453.  
  454. //////////////////////////////////////////////////////////////////////////////////
  455.  
  456. public function view_loc($name){
  457. // title
  458. $name = ucwords(str_replace("_", " ", $name));
  459. $pageTitle = $name;
  460.  
  461. // check if valid, and post
  462. $place = Location::l_loadByName($name);
  463. if($place == null) {
  464. die('Invalid name');
  465. }
  466.  
  467. include_once SYSTEM_PATH.'/view/header.tpl';
  468. include_once SYSTEM_PATH.'/view/location.tpl';
  469. include_once SYSTEM_PATH.'/view/footer.tpl';
  470. }
  471.  
  472. public function edit_loc($name){
  473.  
  474. // can not edit if not logged in
  475. if(!isset($_SESSION['username'])){
  476. header('Location: '.BASE_URL);
  477. }
  478.  
  479. $name = ucwords(str_replace("_", " ", $name));
  480. $pageTitle = $name;
  481.  
  482. // check if valid, and post
  483. $place = Location::l_loadByName($name);
  484. if($place == null) {
  485. die('Invalid name');
  486. }
  487.  
  488. include_once SYSTEM_PATH.'/view/header.tpl';
  489. include_once SYSTEM_PATH.'/view/edit_location.tpl';
  490. include_once SYSTEM_PATH.'/view/footer.tpl';
  491. }
  492.  
  493. public function edit_loc_complete($name){
  494.  
  495. // can not edit if not logged in
  496. if(!isset($_SESSION['username'])){
  497. header('Location: '.BASE_URL);
  498. }
  499.  
  500. // get POST variables
  501. $name = $_POST['name_in']; // required
  502. $activities = $_POST['activities_in'];
  503. $staff = $_POST['staff_in'];
  504. $capacity = $_POST['capacity_in'];
  505. $cost = $_POST['cost_in'];
  506. $profile_image = $_POST['profile_image_in'];
  507. $brief_description = $_POST['brief_description_in'];
  508.  
  509.  
  510. $name = ucwords(str_replace("_", " ", $name));
  511. $place = Location::l_loadByName($name);
  512.  
  513. $place->name = $name;
  514. $place->activities = $activities;
  515. $place->staff = $staff;
  516. $place->capacity = $capacity;
  517. $place->cost = $cost;
  518. $place->profile_image = $profile_image;
  519. $place->brief_description = $brief_description;
  520.  
  521. $memID = $place->l_save();
  522. $name = ucwords(str_replace(" ", "_", $name));
  523. header('Location: '.BASE_URL.'/locations/'.$name);
  524. }
  525.  
  526. public function loc_article_complete($name){
  527.  
  528. // can not add article if not logged in
  529. if(!isset($_SESSION['username'])){
  530. header('Location: '.BASE_URL);
  531. }
  532.  
  533. // get POST variables
  534. $target_id = $_POST['target_id_in'];
  535. $article_title = $_POST['article_title_in'];
  536. $article_text = $_POST['article_text_in'];
  537. $article_image = $_POST['article_image_in'];
  538.  
  539. $article = new Article();
  540.  
  541. $article->target_id = $target_id;
  542. $article->article_title = $article_title;
  543. $article->article_text = $article_text;
  544. $article->article_image = $article_image;
  545.  
  546. $article->save("Locations");
  547. $name = ucwords(str_replace(" ", "_", $name));
  548. header('Location: '.BASE_URL.'/people/'.$name);
  549.  
  550. }
  551.  
  552. public function loc_delete($name){
  553.  
  554. // can not remove if not logged in
  555. if(!isset($_SESSION['username'])){
  556. header('Location: '.BASE_URL);
  557. }
  558.  
  559. // check if valid
  560. $place = Location::loadByName($name);
  561. if($person == null) {
  562. die('Invalid family member name');
  563. }
  564.  
  565. // remove all data sections
  566. $articles = Article::getByTargetID($person->id, "Locations");
  567. foreach($articles as $art){
  568. $art->remove();
  569. }
  570.  
  571. // call remove function on member page
  572. $place->remove();
  573.  
  574. $this->addActivity($name, 'delete');
  575.  
  576. header('Location: '.BASE_URL.'/locations');
  577. }
  578.  
  579. //////////////////////////////////////////////////////////////////////////////////
  580.  
  581. public function list_people(){
  582. $pageTitle = "People";
  583. // get list of all persons and display
  584. $list = Person::getPeople();
  585. include_once SYSTEM_PATH.'/view/header.tpl';
  586. include_once SYSTEM_PATH.'/view/people.tpl';
  587. include_once SYSTEM_PATH.'/view/footer.tpl';
  588.  
  589. }
  590.  
  591. public function list_locations(){
  592. $pageTitle = "Locations";
  593.  
  594. // get list of all Locations and display
  595. $list = Location::getLocations();
  596. include_once SYSTEM_PATH.'/view/header.tpl';
  597. include_once SYSTEM_PATH.'/view/locations.tpl';
  598. include_once SYSTEM_PATH.'/view/footer.tpl';
  599.  
  600. }
  601.  
  602.  
  603.  
  604.  
  605. public function list_community(){
  606. $pageTitle = "Community";
  607.  
  608. // get list of all persons and display
  609. $list = User::getUsers();
  610.  
  611. include_once SYSTEM_PATH.'/view/header.tpl';
  612. include_once SYSTEM_PATH.'/view/community.tpl';
  613. include_once SYSTEM_PATH.'/view/footer.tpl';
  614.  
  615.  
  616.  
  617. }
  618.  
  619.  
  620.  
  621. //////////////////////////////////////////////////////////////////////////////////
  622.  
  623. public function view_profile($name){
  624.  
  625. // check if valid, and post
  626. $user = User::u_loadByName($name);
  627. $currentUser = $_SESSION['username'];
  628. if($user != null) {
  629. $logged_in = true;
  630. // TODO add content template
  631. } else {
  632. die('Invalid name');
  633. }
  634.  
  635. $list = Follow::getByFollower($currentUser);
  636. $activity_feed = Activity::getActivitiesByUser($name);
  637.  
  638. $following = false;
  639.  
  640. foreach($list as $follow)
  641. {
  642. if ($follow->user_followee == $name)
  643. {
  644. $following = true;
  645. }
  646.  
  647. }
  648.  
  649. $pageTitle = $user->first_name."_".$user->last_name;
  650.  
  651. include_once SYSTEM_PATH.'/view/header.tpl';
  652. include_once SYSTEM_PATH.'/view/profile.tpl';
  653. include_once SYSTEM_PATH.'/view/footer.tpl';
  654. }
  655.  
  656.  
  657. public function edit_profile($name){
  658.  
  659. // check if valid, and post
  660. $user = User::u_loadByName($name);
  661. if($user != null) {
  662. // TODO add content template
  663. } else {
  664. die('Invalid name');
  665. }
  666.  
  667. $pageTitle = "Edit Profile";
  668.  
  669. include_once SYSTEM_PATH.'/view/header.tpl';
  670. include_once SYSTEM_PATH.'/view/edit_profile.tpl';
  671. include_once SYSTEM_PATH.'/view/footer.tpl';
  672.  
  673. }
  674.  
  675. public function edit_profile_complete($name){
  676.  
  677. $user = User::u_loadByName($name);
  678. if($user == null) {
  679. die('Invalid name');
  680. }
  681.  
  682. // TODO admin priviledges
  683. // can not edit if not logged in
  684. if($_SESSION['username'] != $user->username){
  685. header('Location: '.BASE_URL);
  686. }
  687.  
  688. $corr_pw = $user->password;
  689.  
  690. // get POST variables
  691. $old_pw = $_POST['old_pw_in'];
  692. $password = $_POST['new_pw_in'];
  693. $first_name = $_POST['first_name_in'];
  694. $last_name = $_POST['last_name_in'];
  695. $email = $_POST['email_in'];
  696. $gender = $_POST['gender'];
  697.  
  698. echo $old_pw;
  699. echo $password;
  700. echo $first_name;
  701. echo $last_name;
  702. echo $email;
  703. echo $gender;
  704.  
  705.  
  706. if($old_pw != $corr_pw){
  707. header('Location: '.BASE_URL.'/community/'.$name.'/edit_profile');
  708. }
  709.  
  710. if( empty($first_name) | empty($last_name) | empty($email) | empty($password) | empty($gender) ) {
  711. header('Location: '.BASE_URL.'/community/'.$name.'/edit_profile');
  712. }
  713.  
  714. $user->first_name = $first_name;
  715. $user->last_name = $last_name;
  716. $user->email = $email;
  717. $user->password = $password;
  718. $user->gender = $gender;
  719.  
  720. $memID = $user->u_update();
  721. $name = ucwords(str_replace(" ", "_", $name));
  722. $name = strtolower($name);
  723. $this->addActivity($name, 'edit');
  724. header('Location: '.BASE_URL.'/community/'.$name);
  725.  
  726. }
  727.  
  728. public function follow($name){
  729.  
  730. /// get usernames for follower and folowee
  731. $follower = $_SESSION['username'];
  732. $followee = User::u_loadByName($name);
  733.  
  734.  
  735. $follow = new Follow();
  736. $follow->user_follower = $follower;
  737. $follow->user_followee = $followee->username;
  738. $follow->save();
  739.  
  740. //TODO test this method
  741.  
  742. // Add to user's activity
  743. $this->addActivity($name, 'follow');
  744.  
  745. header('Location: '.BASE_URL.'/community/'.$name);
  746.  
  747. }
  748.  
  749. public function unfollow($name){
  750.  
  751. // get usernames for follower and folowee
  752. $follower = $_SESSION['username'];
  753. $followee = User::u_loadByName($name);
  754.  
  755.  
  756. $follow = new Follow();
  757. $follow->user_follower = $follower;
  758. $follow->user_followee = $followee->username;
  759. $follow->remove();
  760.  
  761. //TODO test this method
  762.  
  763.  
  764. // Add to user's activity
  765. $this->addActivity($name, 'unfollow');
  766.  
  767. header('Location: '.BASE_URL.'/community/'.$name);
  768. }
  769.  
  770.  
  771. public function addActivity($page, $activity)
  772. {
  773. $act = new Activity();
  774. $act->user = $_SESSION['username'];
  775. $act->page = $page;
  776. $act->activity_type = $activity;
  777. $act->save();
  778. }
  779.  
  780.  
  781. public static function getTemp($cityName) {
  782. $query = urlencode($cityName);
  783. $endpoint = 'http://api.openweathermap.org/data/2.5/weather?q='.$query.'&APPID=567d44be5ca794937686b4c376c29fec';
  784. $contents = file_get_contents($endpoint);
  785. $json = json_decode($contents);
  786. $results = $json->{'weather'};
  787.  
  788. //shuffle($results);
  789. $info = $results[0];
  790.  
  791. $main = $info->{'main'}; // title of the image
  792. $description = $info->{'description'}; // thumbnail of the img
  793. $icon = $info->{'icon'}; // url to the img's item page
  794.  
  795. $data = array(
  796. 'main' => $main,
  797. 'description' => $description,
  798. 'icon' => $icon
  799. );
  800.  
  801. return $data;
  802. }
  803.  
  804.  
  805. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement