function get_links()
 {
     $this->Paging["count"] = Advertisement::get($param = array('cnt' => TRUE), NULL);
     $params = array('cnt' => FALSE, 'show' => $this->Paging["show"], 'page' => $this->Paging["page"], 'sort_by' => 'changed', 'direction' => 'DESC');
     $ads_data = Advertisement::get($params, NULL);
     return $ads_data;
 }
 function get_links()
 {
     $condition = array();
     if ($this->mode == 'textpad') {
         $condition['type'] = 'textpad';
     } else {
         $condition['type'] = 'ad';
         if (!empty($_REQUEST['gid'])) {
             $condition['group_id'] = (int) $_REQUEST['gid'];
         } else {
             $condition['group_id'] = NULL;
         }
     }
     $this->Paging["count"] = Advertisement::get(array('cnt' => TRUE), $condition);
     $params = array('cnt' => FALSE, 'show' => $this->Paging["show"], 'page' => $this->Paging["page"], 'sort_by' => 'changed', 'direction' => 'DESC');
     $ads_data = Advertisement::get($params, $condition);
     return $ads_data;
 }
 private function initNew($cb, $default_mode, $default_block_type, $setting_data)
 {
     global $page_uid, $uid;
     // render all modules
     foreach ($this->modules_array as $module) {
         // standard column-specific initialization
         switch ($module->column) {
             case 'left':
             case 'right':
                 if ($default_mode) {
                     $module->mode = $default_mode;
                 }
                 // some modules don't like to be set as PRI/HOMEPAGE
                 switch ($module->module_name) {
                     case 'LogoModule':
                     case 'AdsByGoogleModule':
                     case 'GroupAccessModule':
                     case 'GroupStatsModule':
                         break;
                     default:
                         if ($default_block_type) {
                             $module->block_type = $default_block_type;
                         }
                 }
                 break;
             case 'middle':
                 break;
         }
         // now call the page callback and see if we need to skip
         // displaying this module
         $skipped = $module->skipped;
         if ($cb && !$skipped) {
             switch ($cb($module->column, $module->module_name, $module, $this)) {
                 case 'skip':
                     $skipped = TRUE;
                     break;
             }
         }
         // now render for display
         $render_time = NULL;
         if (!$skipped) {
             $start_time = microtime(TRUE);
             $html = $module->render();
             if (!$module->do_skip) {
                 //add the module to list if it is not being skipped from within the module.
                 $render_time = microtime(TRUE) - $start_time;
                 $this->module_arrays[$module->column][] = $html;
             }
         }
         if ($this->debugging) {
             $dhtml = "← {$module->module_name} ({$module->block_type}; {$module->mode}; " . sprintf("%.3f s", $render_time) . ")";
             if ($skipped) {
                 $dhtml .= " SKIPPED";
             }
             $dhtml .= "<br>";
             $this->module_arrays[$module->column][] = $dhtml;
         }
     }
     /*
         $pages = Advertisement::get_pages(); // get pages where ads is to be displayed
         $display_ad = FALSE;
         foreach ($pages as $page) {
           if (PA::$config->page_type == $page['value']) {
             $display_ad = TRUE;
             break;
           }
         }
     */
     // the following code does exactly the same as
     // the above commented, only much more efficient
     // because it'snot loading ALL pages
     $display_ad = false;
     if (preg_match("/(network|group)/", $this->setting_data['page_type'])) {
         $display_ad = true;
     }
     if ($display_ad) {
         // get all ads
         $netw_ads = array();
         try {
             $netw_ads = Advertisement::get(array('direction' => 'ASC', 'sort_by' => 'orientation'), array('page_id' => PA::$config->page_type, 'is_active' => ACTIVE, 'group_id' => NULL));
         } catch (PAException $e) {
             Logger::log(__FILE__ . " " . $e->getMessage(), 32);
         }
         $group_ads = array();
         if (!empty($_REQUEST['gid'])) {
             try {
                 $group_ads = Advertisement::get(array('direction' => 'ASC', 'sort_by' => 'orientation'), array('page_id' => PA::$config->page_type, 'is_active' => ACTIVE, 'group_id' => (int) $_REQUEST['gid']));
             } catch (PAException $e) {
                 Logger::log(__FILE__ . " " . $e->getMessage(), 32);
             }
         }
         $all_ads = array();
         foreach ($group_ads as $ad) {
             $all_ads[] = $ad;
         }
         foreach ($netw_ads as $ad) {
             $all_ads[] = $ad;
         }
         if (!empty($all_ads)) {
             foreach ($all_ads as $ad) {
                 $pos = $ad->orientation;
                 $pos = explode(',', $ad->orientation);
                 $x_loc = $pos[0];
                 //y_loc was not originally designed so for already created ads
                 //FIX for already created ads
                 if (array_key_exists(1, $pos)) {
                     $y_loc = $pos[1];
                 } else {
                     $y_loc = 1;
                     //Ads created before this logic implementation should come on top
                 }
                 //horizontal and vertical position should not be empty
                 if (!empty($x_loc) && !empty($y_loc)) {
                     $array_of_data = array('links' => $ad);
                     $inner_html = $this->add_block_module('AdvertisementModule', $array_of_data);
                     $this->add_module_xy($x_loc, $y_loc, $inner_html);
                 }
             }
         }
         //end of if all_ads
     }
     //end of display_ad
 }
示例#4
0
<?php

$login_required = FALSE;
global $path_prefix;
include "includes/page.php";
require_once "{$path_prefix}/api/Advertisement/Advertisement.php";
if (!empty($_GET['ad_id'])) {
    $condition = array('ad_id' => $_GET['ad_id']);
    $res = Advertisement::get($params = NULL, $condition);
    $hit_count = $res[0]->hit_count;
    $hit_count++;
    $update_fields = array('hit_count' => $hit_count);
    Advertisement::update($update_fields, $condition);
}
     $advertisement->created = $_POST['created'];
     $msg_id = 19014;
 } else {
     $msg_id = 19015;
     $advertisement->created = time();
 }
 $advertisement->user_id = $login_uid;
 $advertisement->title = $form_data['ad_title'] = $_POST['ad_title'];
 if (strlen($advertisement->title) > 30) {
     $error = TRUE;
     $_GET['msg_id'] = 19020;
 }
 $advertisement->description = $form_data['ad_description'] = $_POST['ad_description'];
 $advertisement->page_id = $form_data['page_id'] = $_POST['page_id'];
 $advertisement->orientation = $form_data['orientation'] = $_POST['x_loc'] . ',' . $_POST['y_loc'];
 $ad_data = Advertisement::get(NULL, array('orientation' => $advertisement->orientation, 'is_active' => TRUE));
 if (!empty($ad_data) && !empty($advertisement->ad_id) && $advertisement->orientation != '0,0') {
     $ad_data = $ad_data[0];
     if ($advertisement->ad_id != $ad_data->ad_id) {
         $error = TRUE;
         $message = ucfirst($ad_data->type) . __(' is already enabled at specified orientation');
     }
 }
 $advertisement->changed = time();
 $advertisement->is_active = ACTIVE;
 $advertisement->type = 'textpad';
 if (!$error) {
     try {
         $advertisement->save();
         $form_data = array();
         header("Location: " . PA::$url . '/' . FILE_MANAGE_TEXTPADS . "?msg_id={$msg_id}");
示例#6
0
 function __construct($cb, $page_type, $title, $page_template = "homepage_pa.tpl", $header_template = "header.tpl", $default_mode = PRI, $default_block_type = HOMEPAGE, $network_info_ = NULL, $onload = NULL, $setting_data = NULL)
 {
     global $login_uid, $page_uid, $uid, $path_prefix, $current_theme_path, $current_theme_rel_path, $base_url, $network_info, $current_blockmodule_path;
     $this->debugging = isset($_GET['debug']);
     $this->page_template = $page_template;
     $this->top_navigation_template = 'top_navigation_bar.tpl';
     //TO DO: Remove this hardcoded text afterwards
     $this->header_template = $header_template;
     //settings for current network
     $this->network_info = $network_info_ ? $network_info_ : $network_info;
     //FIXME: does this have to be a parameter?  can't we just always use the global $network_info?
     // the function hide_message_window is added here
     // so whenever html page is loaded the message window's ok button gets focus
     // here if previouly some function is defined as
     // onload = "ajax_call_method(ajax_titles, $uid, ajax_urls);"
     // now it will look like
     // onload = "ajax_call_method(ajax_titles, $uid, ajax_urls); hide_message_window();"
     $this->onload = "{$onload} hide_message_window('confirm_btn');";
     $this->page_title = $title;
     $this->html_body_attributes = "";
     // default settings for the tiers
     $this->main_tier = @$_GET['tier_one'];
     $this->second_tier = @$_GET['tier_two'];
     $this->third_tier = @$_GET['tier_three'];
     $navigation = new Navigation();
     $navigation_links = $navigation->get_links();
     $message_count = null;
     if ($login_uid) {
         $message_count = Message::get_new_msg_count($login_uid);
     }
     // load all templates
     $this->page =& new Template(CURRENT_THEME_FSPATH . "/" . $this->page_template);
     $this->page->set('current_theme_path', $current_theme_path);
     $this->page->set('current_theme_rel_path', $current_theme_rel_path);
     $this->page->set('base_url', $base_url);
     // Loading the templates variables for the Outer templates files
     $this->page->set('outer_class', get_class_name($page_type));
     $this->top_navigation_bar =& new Template(CURRENT_THEME_FSPATH . "/" . $this->top_navigation_template);
     $this->top_navigation_bar->set('current_theme_path', $current_theme_path);
     $this->top_navigation_bar->set('current_theme_rel_path', $current_theme_rel_path);
     $this->top_navigation_bar->set('navigation_links', $navigation_links);
     $this->header =& new Template(CURRENT_THEME_FSPATH . "/" . $this->header_template);
     $this->header->set('current_theme_path', $current_theme_path);
     $this->header->set('current_theme_rel_path', $current_theme_rel_path);
     $this->header->set('base_url', $base_url);
     $this->header->set_object('network_info', $this->network_info);
     $this->header->set('message_count', $message_count['unread_msg']);
     $this->header->set('navigation_links', $navigation_links);
     $this->footer =& new Template(CURRENT_THEME_FSPATH . "/footer.tpl");
     $this->footer->set('current_theme_path', $current_theme_path);
     $this->footer->set('page_name', $title);
     // load module settings
     // if we want to change the Module's arrangement then we give the setting_data to this function or we want to change the Ordering of the Modules ...
     if ($setting_data) {
         $this->setting_data = $setting_data;
     } else {
         $this->setting_data = !$page_type ? NULL : ModuleSetting::load_setting($page_type, $uid);
     }
     // render all modules
     $this->module_arrays = array();
     foreach (array("left", "middle", "right") as $module_column) {
         $modulesFromDB = !$page_type ? NULL : @$this->setting_data[$module_column];
         $array_modules = array();
         // render all modules
         if ($modulesFromDB) {
             foreach ($modulesFromDB as $moduleName) {
                 if (!$moduleName) {
                     continue;
                 }
                 $file = "{$current_blockmodule_path}/{$moduleName}/{$moduleName}.php";
                 try {
                     require_once $file;
                 } catch (Exception $e) {
                     echo "<p>Failed to require_once {$file}.</p>";
                     throw $e;
                 }
                 $obj = new $moduleName();
                 $obj->login_uid = (int) $login_uid;
                 // uid of logged in user
                 $obj->page_uid = (int) $page_uid;
                 // uid specified in URL
                 // standard column-specific initialization
                 switch ($module_column) {
                     case 'left':
                     case 'right':
                         if ($default_mode) {
                             $obj->mode = $default_mode;
                         }
                         // some modules don't like to be set as PRI/HOMEPAGE
                         switch ($moduleName) {
                             case 'LogoModule':
                             case 'AdsByGoogleModule':
                             case 'GroupAccessModule':
                             case 'GroupStatsModule':
                                 break;
                             default:
                                 if ($default_block_type) {
                                     $obj->block_type = $default_block_type;
                                 }
                         }
                         break;
                     case 'middle':
                         break;
                 }
                 // now call the page callback and see if we need to skip
                 // displaying this module
                 $skipped = FALSE;
                 if ($cb) {
                     switch ($cb($module_column, $moduleName, $obj)) {
                         case 'skip':
                             $skipped = TRUE;
                             break;
                     }
                 }
                 // now render for display
                 if (!$skipped) {
                     $start_time = microtime(TRUE);
                     $html = $obj->render();
                     $render_time = microtime(TRUE) - $start_time;
                     $array_modules[] = $html;
                 }
                 if ($this->debugging) {
                     $dhtml = "&larr; {$moduleName} ({$obj->block_type}; {$obj->mode}; " . sprintf("%.3f s", $render_time) . ")";
                     if ($skipped) {
                         $dhtml .= " SKIPPED";
                     }
                     $dhtml .= "<br>";
                     $array_modules[] = $dhtml;
                 }
             }
         }
         $this->module_arrays[$module_column] = $array_modules;
     }
     $pages = Advertisement::get_pages();
     // get pages where ads is to be displayed
     $display_ad = FALSE;
     foreach ($pages as $page) {
         if ($page_type == $page['value']) {
             $display_ad = TRUE;
             break;
         }
     }
     if ($display_ad) {
         // get all ads
         $all_ads = Advertisement::get(array('direction' => 'ASC', 'sort_by' => 'orientation'), array('page_id' => $page_type, 'is_active' => ACTIVE));
         if (!empty($all_ads)) {
             foreach ($all_ads as $ad) {
                 $pos = $ad->orientation;
                 $pos = explode(',', $ad->orientation);
                 $x_loc = $pos[0];
                 //y_loc was not originally designed so for already created ads
                 //FIX for already created ads
                 if (array_key_exists(1, $pos)) {
                     $y_loc = $pos[1];
                 } else {
                     $y_loc = 1;
                     //Ads created before this logic implementation should come on top
                 }
                 //horizontal and vertical position should not be empty
                 if (!empty($x_loc) && !empty($y_loc)) {
                     $array_of_data = array('links' => $ad);
                     $inner_html = $this->add_block_module('AdvertisementModule', $array_of_data);
                     $this->add_module_xy($x_loc, $y_loc, $inner_html);
                 }
             }
         }
         //end of if all_ads
     }
     //end of display_ad
 }
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);
}
 public function findAd($name)
 {
     $ad = Advertisement::get()->filter('Title', $name)->first();
     return $ad;
 }
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`";
     if ($this->classHasAdvertisements($this->owner->ClassName)) {
         $objects = array(0 => 0);
         $images = array(0 => 0);
         $dos1 = $this->advertisementsToShow();
         if ($dos1) {
             foreach ($dos1 as $obj) {
                 $images[$obj->ID] = $obj->AdvertisementImageID;
                 $objects[$obj->ID] = $obj->ID;
             }
         }
         //check for non-existing images and delete advertisements associated with it
         foreach ($images as $objectID => $imageID) {
             if (!Image::get()->byID($imageID)) {
                 $obj = Advertisement::get()->byID($objectID);
                 if ($obj) {
                     $obj->delete();
                     $obj->destroy();
                     unset($objects[$objectID]);
                 }
             }
         }
         //check if a folder has been set and create objects
         if ($this->owner->AdvertisementsFolderID) {
             $dos2 = Image::get()->where("\"File\".\"ParentID\" = " . $this->owner->AdvertisementsFolderID . " AND \"Advertisement\".\"AdvertisementImageID\" IS NULL ")->leftJoin("Advertisement", "\"Advertisement\".\"AdvertisementImageID\" = \"File\".\"ID\" ");
             if ($dos2->count()) {
                 $advertisementsToAdd = array();
                 foreach ($dos2 as $image) {
                     $newAdvertisement = new Advertisement();
                     $newAdvertisement->AdvertisementImageID = $image->ID;
                     $newAdvertisement->Title = $image->Title;
                     $newAdvertisement->AutoAdded = true;
                     $newAdvertisement->write();
                     $objects[$newAdvertisement->ID] = $newAdvertisement->ID;
                 }
                 $this->owner->Advertisements()->addMany($objects);
             }
         }
         if ($this->owner->AdvertisementStyleID) {
             if (!AdvertisementStyle::get()->byID($this->owner->AdvertisementStyleID)) {
                 $this->owner->AdvertisementStyleID = 0;
             }
         }
         //remove advdertisements if parent is being used...
         if ($this->owner->UseParentAdvertisements) {
             if ($this->advertisementParent()) {
                 $combos = $this->owner->Advertisements();
                 if ($combos) {
                     $combos->removeAll();
                 }
             } else {
                 $this->owner->UseParentAdvertisements = false;
             }
         }
     }
 }
    $advertisement->changed = time();
    $advertisement->is_active = ACTIVE;
    if (!$error) {
        try {
            $advertisement->save();
            $form_data = array();
            header("location: manage_ad_center.php?msg_id={$msg_id}");
            exit;
        } catch (PAException $e) {
            $msg[] = $e->message;
        }
    }
} else {
    if (!empty($_GET['do']) && $_GET['do'] == 'edit' && !empty($_GET['ad_id'])) {
        $edit = TRUE;
        $res = Advertisement::get($params = NULL, $condition = array('ad_id' => (int) $_GET['ad_id']));
        if (!empty($res)) {
            $form_data['ad_id'] = $res[0]->ad_id;
            $form_data['ad_image'] = $res[0]->ad_image;
            $form_data['ad_script'] = $res[0]->ad_script;
            $form_data['ad_url'] = $res[0]->url;
            $form_data['ad_title'] = $res[0]->title;
            $form_data['ad_description'] = $res[0]->description;
            $form_data['page_id'] = $res[0]->page_id;
            $form_data['orientation'] = $res[0]->orientation;
            $form_data['created'] = $res[0]->created;
        }
    } else {
        if (!empty($_GET['action']) && $_GET['action'] == 'delete' && !empty($_GET['ad_id'])) {
            if (!empty($_GET['ad_id'])) {
                try {