示例#1
0
 function insert($autoLinkMatchingZones = true)
 {
     $this->_rebuildCache();
     $id = parent::insert();
     if ($id) {
         // add default zone
         $aVariables = array('ad_id' => $id, 'zone_id' => 0);
         Admin_DA::addAdZone($aVariables);
         if ($autoLinkMatchingZones) {
             MAX_addDefaultPlacementZones($id, $this->campaignid);
         }
     }
     return $id;
 }
示例#2
0
function processForm($bannerid, $form, &$oComponent, $formDisabled = false)
{
    $aFields = $form->exportValues();
    $doBanners = OA_Dal::factoryDO('banners');
    // Get the existing banner details (if it is not a new banner)
    if (!empty($bannerid)) {
        if ($doBanners->get($bannerid)) {
            $aBanner = $doBanners->toArray();
        }
    }
    $aVariables = array();
    $aVariables['campaignid'] = $aFields['campaignid'];
    $aVariables['target'] = isset($aFields['target']) ? $aFields['target'] : '';
    $aVariables['height'] = isset($aFields['height']) ? $aFields['height'] : 0;
    $aVariables['width'] = isset($aFields['width']) ? $aFields['width'] : 0;
    $aVariables['weight'] = !empty($aFields['weight']) ? $aFields['weight'] : 0;
    $aVariables['adserver'] = !empty($aFields['adserver']) ? $aFields['adserver'] : '';
    $aVariables['alt'] = !empty($aFields['alt']) ? $aFields['alt'] : '';
    $aVariables['bannertext'] = !empty($aFields['bannertext']) ? $aFields['bannertext'] : '';
    $aVariables['htmltemplate'] = !empty($aFields['htmltemplate']) ? $aFields['htmltemplate'] : '';
    $aVariables['description'] = !empty($aFields['description']) ? $aFields['description'] : '';
    $aVariables['imageurl'] = !empty($aFields['imageurl']) && $aFields['imageurl'] != 'http://' ? $aFields['imageurl'] : '';
    $aVariables['url'] = !empty($aFields['url']) && $aFields['url'] != 'http://' ? $aFields['url'] : '';
    $aVariables['status'] = $aFields['status'] != '' ? $aFields['status'] : '';
    $aVariables['statustext'] = !empty($aFields['statustext']) ? $aFields['statustext'] : '';
    $aVariables['storagetype'] = $aFields['type'];
    $aVariables['ext_bannertype'] = $aFields['ext_bannertype'];
    $aVariables['comments'] = $aFields['comments'];
    $aVariables['filename'] = !empty($aBanner['filename']) ? $aBanner['filename'] : '';
    $aVariables['contenttype'] = !empty($aBanner['contenttype']) ? $aBanner['contenttype'] : '';
    if ($aFields['type'] == 'url') {
        $aVariables['contenttype'] = OA_Creative_File::staticGetContentTypeByExtension($aVariables['imageurl']);
        if (empty($aVariables['contenttype'])) {
            // Assume dynamic urls (i.e. http://www.example.com/foo?bar) are "gif"
            $aVariables['contenttype'] = 'gif';
        }
    } elseif ($aFields['type'] == 'txt') {
        // Text banners should always have a "txt" content type
        $aVariables['contenttype'] = 'txt';
    }
    $aVariables['alt_filename'] = !empty($aBanner['alt_filename']) ? $aBanner['alt_filename'] : '';
    $aVariables['alt_contenttype'] = !empty($aBanner['alt_contenttype']) ? $aBanner['alt_contenttype'] : '';
    $aVariables['alt_imageurl'] = !empty($aFields['alt_imageurl']) ? $aFields['alt_imageurl'] : '';
    if (isset($aFields['keyword']) && $aFields['keyword'] != '') {
        $keywordArray = split('[ ,]+', $aFields['keyword']);
        $aVariables['keyword'] = implode(' ', $keywordArray);
    } else {
        $aVariables['keyword'] = '';
    }
    $editSwf = false;
    // Deal with any files that are uploaded.
    if (!empty($_FILES['upload']) && $aFields['replaceimage'] == 't') {
        //TODO refactor upload to be a valid quickform elem
        $oFile = OA_Creative_File::factoryUploadedFile('upload');
        checkForErrorFileUploaded($oFile);
        $oFile->store($aFields['type']);
        $aFile = $oFile->getFileDetails();
        if (!empty($aFile)) {
            $aVariables['filename'] = $aFile['filename'];
            $aVariables['contenttype'] = $aFile['contenttype'];
            $aVariables['width'] = $aFile['width'];
            $aVariables['height'] = $aFile['height'];
            $aVariables['pluginversion'] = $aFile['pluginversion'];
            $editSwf = $aFile['editswf'];
        }
        // Delete the old file for this banner
        if (!empty($aBanner['filename']) && $aBanner['filename'] != $aFile['filename'] && ($aBanner['storagetype'] == 'web' || $aBanner['storagetype'] == 'sql')) {
            DataObjects_Banners::deleteBannerFile($aBanner['storagetype'], $aBanner['filename']);
        }
    }
    if (!empty($_FILES['uploadalt']) && $_FILES['uploadalt']['size'] > 0 && $aFields['replacealtimage'] == 't') {
        //TODO: Check image only? - Wasn't enforced before
        $oFile = OA_Creative_File::factoryUploadedFile('uploadalt');
        checkForErrorFileUploaded($oFile);
        $oFile->store($aFields['type']);
        $aFile = $oFile->getFileDetails();
        if (!empty($aFile)) {
            $aVariables['alt_filename'] = $aFile['filename'];
            $aVariables['alt_contenttype'] = $aFile['contenttype'];
        }
    }
    // Handle SWF transparency
    if ($aVariables['contenttype'] == 'swf') {
        $aVariables['transparent'] = isset($aFields['transparent']) && $aFields['transparent'] ? 1 : 0;
    }
    // Update existing hard-coded links if new file has not been uploaded
    if ($aVariables['contenttype'] == 'swf' && empty($_FILES['upload']['tmp_name']) && isset($aFields['alink']) && is_array($aFields['alink']) && count($aFields['alink'])) {
        // Prepare the parameters
        $parameters_complete = array();
        // Prepare targets
        if (!isset($aFields['atar']) || !is_array($aFields['atar'])) {
            $aFields['atar'] = array();
        }
        foreach ($aFields['alink'] as $key => $val) {
            if (substr($val, 0, 7) == 'http://' && strlen($val) > 7) {
                if (!isset($aFields['atar'][$key])) {
                    $aFields['atar'][$key] = '';
                }
                if (isset($aFields['alink_chosen']) && $aFields['alink_chosen'] == $key) {
                    $aVariables['url'] = $val;
                    $aVariables['target'] = $aFields['atar'][$key];
                }
                /*
                                if (isset($aFields['asource'][$key]) && $aFields['asource'][$key] != '') {
                                    $val .= '|source:'.$aFields['asource'][$key];
                                }
                */
                $parameters_complete[$key] = array('link' => $val, 'tar' => $aFields['atar'][$key]);
            }
        }
        $parameters = array('swf' => $parameters_complete);
    } else {
        $parameters = null;
    }
    $aVariables['parameters'] = serialize($parameters);
    //TODO: deleting images is not viable because they could still be in use in the delivery cache
    //    // Delete any old banners...
    //    if (!empty($aBanner['filename']) && $aBanner['filename'] != $aVariables['filename']) {
    //        phpAds_ImageDelete($aBanner['storagetype'], $aBanner['filename']);
    //    }
    //    if (!empty($aBanner['alt_filename']) && $aBanner['alt_filename'] != $aVariables['alt_filename']) {
    //        phpAds_ImageDelete($aBanner['storagetype'], $aBanner['alt_filename']);
    //    }
    // Clients are only allowed to modify certain fields, ensure that other fields are unchanged
    if (OA_Permission::isAccount(OA_ACCOUNT_ADVERTISER)) {
        $aVariables['weight'] = $aBanner['weight'];
        $aVariables['description'] = $aBanner['name'];
        $aVariables['comments'] = $aBanner['comments'];
    }
    $insert = empty($bannerid) ? true : false;
    if ($oComponent) {
        $result = $oComponent->preprocessForm($insert, $bannerid, $aFields, $aVariables);
        if ($result === false) {
            // handle error
            return false;
        }
    }
    // File the data
    $doBanners->setFrom($aVariables);
    if ($insert) {
        $bannerid = $doBanners->insert();
        // Run the Maintenance Priority Engine process
        OA_Maintenance_Priority::scheduleRun();
    } else {
        $doBanners->update();
        // check if size has changed
        if ($aVariables['width'] != $aBanner['width'] || $aVariables['height'] != $aBanner['height']) {
            MAX_adjustAdZones($bannerid);
            MAX_addDefaultPlacementZones($bannerid, $aVariables['campaignid']);
        }
    }
    if ($oComponent) {
        $result = $oComponent->processForm($insert, $bannerid, $aFields, $aVariables);
        if ($result === false) {
            // handle error
            // remove rec from banners table?
            return false;
        }
    }
    $translation = new OX_Translation();
    if ($insert) {
        // Queue confirmation message
        $translated_message = $translation->translate($GLOBALS['strBannerHasBeenAdded'], array(MAX::constructURL(MAX_URL_ADMIN, 'banner-edit.php?clientid=' . $aFields['clientid'] . '&campaignid=' . $aFields['campaignid'] . '&bannerid=' . $bannerid), htmlspecialchars($aFields['description'])));
        OA_Admin_UI::queueMessage($translated_message, 'local', 'confirm', 0);
        // Determine what the next page is
        if ($editSwf) {
            $nextPage = "banner-swf.php?clientid=" . $aFields['clientid'] . "&campaignid=" . $aFields['campaignid'] . "&bannerid={$bannerid}&insert=true";
        } else {
            $nextPage = "campaign-banners.php?clientid=" . $aFields['clientid'] . "&campaignid=" . $aFields['campaignid'];
        }
    } else {
        // Determine what the next page is
        if ($editSwf) {
            $nextPage = "banner-swf.php?clientid=" . $aFields['clientid'] . "&campaignid=" . $aFields['campaignid'] . "&bannerid={$bannerid}";
        } else {
            $translated_message = $translation->translate($GLOBALS['strBannerHasBeenUpdated'], array(MAX::constructURL(MAX_URL_ADMIN, 'banner-edit.php?clientid=' . $aFields['clientid'] . '&campaignid=' . $aFields['campaignid'] . '&bannerid=' . $aFields['bannerid']), htmlspecialchars($aFields['description'])));
            OA_Admin_UI::queueMessage($translated_message, 'local', 'confirm', 0);
            $nextPage = "banner-edit.php?clientid=" . $aFields['clientid'] . "&campaignid=" . $aFields['campaignid'] . "&bannerid={$bannerid}";
        }
    }
    // Go to the next page
    Header("Location: {$nextPage}");
    exit;
}
function processForm($bannerid, $form, &$oComponent, $formDisabled = false)
{
    $aFields = $form->exportValues();
    $doBanners = OA_Dal::factoryDO('banners');
    if (!empty($bannerid)) {
        if ($doBanners->get($bannerid)) {
            $aBanner = $doBanners->toArray();
        }
    }
    $aVariables = array();
    $aVariables['campaignid'] = $aFields['campaignid'];
    $aVariables['target'] = isset($aFields['target']) ? $aFields['target'] : '';
    $aVariables['height'] = isset($aFields['height']) ? $aFields['height'] : 0;
    $aVariables['width'] = isset($aFields['width']) ? $aFields['width'] : 0;
    $aVariables['weight'] = !empty($aFields['weight']) ? $aFields['weight'] : 0;
    $aVariables['adserver'] = !empty($aFields['adserver']) ? $aFields['adserver'] : '';
    $aVariables['alt'] = !empty($aFields['alt']) ? $aFields['alt'] : '';
    $aVariables['bannertext'] = !empty($aFields['bannertext']) ? $aFields['bannertext'] : '';
    $aVariables['htmltemplate'] = !empty($aFields['htmltemplate']) ? $aFields['htmltemplate'] : '';
    $aVariables['description'] = !empty($aFields['description']) ? $aFields['description'] : '';
    $aVariables['imageurl'] = !empty($aFields['imageurl']) && $aFields['imageurl'] != 'http://' ? $aFields['imageurl'] : '';
    $aVariables['url'] = !empty($aFields['url']) && $aFields['url'] != 'http://' ? $aFields['url'] : '';
    $aVariables['status'] = $aFields['status'] != '' ? $aFields['status'] : '';
    $aVariables['storagetype'] = $aFields['type'];
    $aVariables['ext_bannertype'] = 'bannerTypeText:oxMarkedText:oxMarkedTextComponent';
    $aVariables['comments'] = $aFields['comments'];
    $aVariables['contenttype'] = 'txt';
    if (isset($aFields['keyword']) && $aFields['keyword'] != '') {
        $keywordArray = split('[ ,]+', $aFields['keyword']);
        $aVariables['keyword'] = implode(' ', $keywordArray);
    } else {
        $aVariables['keyword'] = '';
    }
    $editSwf = false;
    $parameters = null;
    $aVariables['parameters'] = serialize($parameters);
    $insert = empty($bannerid) ? true : false;
    $doBanners->setFrom($aVariables);
    if ($insert) {
        $bannerid = $doBanners->insert();
        OA_Maintenance_Priority::scheduleRun();
    } else {
        $doBanners->update();
        if ($aVariables['width'] != $aBanner['width'] || $aVariables['height'] != $aBanner['height']) {
            MAX_adjustAdZones($bannerid);
            MAX_addDefaultPlacementZones($bannerid, $aVariables['campaignid']);
        }
    }
    $translation = new OX_Translation();
    if ($insert) {
        $translated_message = $translation->translate($GLOBALS['strBannerHasBeenAdded'], array(MAX::constructURL(MAX_URL_ADMIN, 'banner-edit.php?clientid=' . $aFields['clientid'] . '&campaignid=' . $aFields['campaignid'] . '&bannerid=' . $bannerid), htmlspecialchars($aFields['description'])));
        OA_Admin_UI::queueMessage($translated_message, 'local', 'confirm', 0);
        $nextPage = "oxMarkedTextAdvertiser-index.php?clientid=" . $aFields['clientid'] . "&campaignid=" . $aFields['campaignid'];
    } else {
        $translated_message = $translation->translate($GLOBALS['strBannerHasBeenUpdated'], array(MAX::constructURL(MAX_URL_ADMIN, 'banner-edit.php?clientid=' . $aFields['clientid'] . '&campaignid=' . $aFields['campaignid'] . '&bannerid=' . $aFields['bannerid']), htmlspecialchars($aFields['description'])));
        OA_Admin_UI::queueMessage($translated_message, 'local', 'confirm', 0);
        $nextPage = "banner-edit.php?clientid=" . $aFields['clientid'] . "&campaignid=" . $aFields['campaignid'] . "&bannerid={$bannerid}";
    }
    Header("Location: {$nextPage}");
    exit;
}
function save_ajax_request($banner_id, $campaign_id, $client_id, $image_id, $template_id, $banner_description, $banner_storagetype)
{
    $file = fopen('http://zetaprints.com/preview/' . $image_id, 'rb');
    $data = fread($file, 1024);
    while (!feof($file)) {
        $data .= fread($file, 1024);
    }
    fclose($file);
    $banner = OA_Dal::factoryDO('banners');
    // Get the existing banner details (if it is not a new banner)
    if (!empty($banner_id)) {
        $result = $banner->get($banner_id);
    }
    if (!$result) {
        OA::debug('here');
        $banner->bannerid = '';
        $banner->campaignid = $campaign_id;
        $banner->clientid = $client_id;
        $banner->url = '';
        $banner->imageurl = '';
        $banner->weight = $pref['default_banner_weight'];
        $banner->description = $banner_description;
        $banner->storagetype = $banner_storagetype;
    }
    require_once MAX_PATH . '/lib/OA/Creative/File.php';
    $file = OA_Creative_File::factoryString($image_id, $data);
    $file->store($banner->storagetype);
    if (!empty($banner->filename) && ($banner->storagetype == 'web' || $banner->storagetype == 'sql')) {
        DataObjects_Banners::deleteBannerFile($banner->storagetype, $banner->filename);
    }
    $file_detailes = $file->getFileDetails();
    $new_banner = empty($banner_id) ? true : false;
    if ($new_banner) {
        $size_changed = $file_detailes['width'] != $banner->width || $file_detailes['height'] != $banner->height;
    }
    $banner->filename = $file_detailes['filename'];
    $banner->contenttype = $file_detailes['contenttype'];
    $banner->width = $file_detailes['width'];
    $banner->height = $file_detailes['height'];
    $banner->pluginversion = $file_detailes['pluginversion'];
    if ($new_banner) {
        $banner->insert();
        require_once MAX_PATH . '/lib/OA/Maintenance/Priority.php';
        OA_Maintenance_Priority::scheduleRun();
        $banner_id = $banner->bannerid;
    } else {
        $banner->update();
        // if size has changed
        if (size_changes) {
            MAX_adjustAdZones($banner_id);
            MAX_addDefaultPlacementZones($banner_id, $campaign_id);
        }
    }
    $zp_banners = OA_Dal::factoryDO('Zpbanners');
    $zp_banners->set_zp_banner_id($banner_id, $template_id);
    return "banner-edit.php?clientid={$client_id}&campaignid={$campaign_id}&bannerid={$banner_id}";
}