function peopleaggregator_listAds($args) { // global var $path_prefix has been removed - please, use PA::$path static variable require_once "api/Advertisement/Advertisement.php"; // map 'page_type' arg to a page key like PAGE_HOMEPAGE $page_type = $args['page_type']; $page_key = NULL; foreach (Advertisement::get_pages() as $page) { if ($page['api_id'] == $page_type) { $page_key = $page['value']; break; } } if ($page_key === NULL) { throw new PAException(INVALID_ID, "Invalid advertisement page type '{$page_type}'."); } // build orientation map $orientation_map = array(); foreach (Advertisement::get_orientations() as $ori) { $orientation_map[$ori['value']] = $ori['caption']; } $ads_out = array(); foreach (Advertisement::get(NULL, array('page_id' => $page_key, 'is_active' => ACTIVE)) as $ad) { $ad_out = array("id" => "ad:" . $ad->ad_id, "title" => $ad->title, "description" => $ad->description, "orientation" => $ad->orientation); if (!empty($ad->ad_image)) { list($w, $h) = getimagesize(PA::$upload_path . "/" . $ad->ad_image); $ad_out['image'] = array("url" => api_get_url_of_file($ad->ad_image), "width" => $w, "height" => $h); } if (!empty($ad->url)) { $ad_out['url'] = $ad->url; } if (!empty($ad->javascript)) { $ad_out['javascript'] = $ad->javascript; } $ads_out[] = $ad_out; } return array("success" => TRUE, "msg" => "Retrieved " . count($ads_out) . " ad(s)", "ads" => $ads_out); }