/**
  * process any uploads
  *
  * @return void
  * @author Andy Bennett
  */
 public static function upload_listener()
 {
     if (!Event::$data instanceof ORM) {
         throw new Exception('Model not passed to ' . __CLASS__ . '/' . __FUNCTION__);
     }
     $model = Event::$data;
     // do the uploading
     foreach ($_FILES as $file => $file_data) {
         if ($file_data['error'] == 0) {
             $tmp_file = $file_data['tmp_name'];
             $filename = $file_data['name'];
             $udata = fileinfo::get($tmp_file, $filename);
             $udata['file_name'] = filestore::put($file_data, $filename);
             preview::generate($udata);
             $n = str_replace('form_', '', $file);
             $id = (is_object($model->{$n}) and $model->{$n}->id > 0) ? $model->{$n}->id : 0;
             if (isset($udata['image_width']) && empty($udata['image_width'])) {
                 unset($udata['image_width']);
             }
             if (isset($udata['image_height']) && empty($udata['image_height'])) {
                 unset($udata['image_height']);
             }
             // if there is preview data set
             if (is_array($udata['preview'])) {
                 // add the preview data into the upload table
                 $preview = ORM::factory('upload');
                 foreach ($udata['preview'] as $k => $v) {
                     if ($k == 'preview') {
                         continue;
                     }
                     $preview->{$k} = $v;
                 }
                 $preview->parent_model = $model->object_name;
                 $preview->parent_id = $model->id;
                 $preview->save();
                 // and assign the id to the row
                 $udata['preview_id'] = $preview->id;
             }
             unset($udata['preview']);
             $o = ORM::factory('upload', $id);
             if (!$o->loaded) {
                 $o = ORM::factory('upload');
             }
             foreach ($udata as $k => $v) {
                 $o->{$k} = $v;
             }
             $o->parent_model = $model->object_name;
             $o->parent_id = $model->id;
             $o->save();
             // insert the upload into the uploads database
             // $_POST[$file] = $o->id;
             $f = str_replace('form_', '', $file);
             $model->{$f} = $o->id;
             $model->save();
         }
     }
 }
Example #2
0
        $message = $messageRepository->find($messageId);
        if (!$message) {
            header("HTTP/1.0 404 Not Found");
            echo '<h1>404 Not Found</h1>';
            exit;
        }
        $GLOBALS['TL_LANGUAGE'] = $message->getLanguage();
        $event = new \Avisota\Contao\Core\Event\CreateFakeRecipientEvent($message);
        $eventDispatcher->dispatch(\Avisota\Contao\Core\CoreEvents::CREATE_FAKE_RECIPIENT, $event);
        $recipient = $event->getRecipient();
        if ($message->getCategory()->getViewOnlinePage()) {
            // Fixme can rmove this?
            $event = new LoadLanguageFileEvent('avisota_message');
            $eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, $event);
            $url = sprintf($translator->translate('viewOnline', 'avisota_message'), sprintf('%ssystem/modules/avisota-message/web/preview.php?id=%s', \Environment::get('base'), $message->getId()));
        } else {
            $url = false;
        }
        $additionalData = array('view_online_link' => $url);
        /** @var \Avisota\Contao\Message\Core\Renderer\MessageRendererInterface $renderer */
        $renderer = $container['avisota.message.renderer'];
        $messageTemplate = $renderer->renderMessage($message);
        $messagePreview = $messageTemplate->renderPreview($recipient, $additionalData);
        header('Content-Type: ' . $messageTemplate->getContentType() . '; charset=' . $messageTemplate->getContentEncoding());
        header('Content-Disposition: inline; filename="' . $messageTemplate->getContentName() . '"');
        echo $messagePreview;
        exit;
    }
}
$preview = new preview();
$preview->run();
 function preview()
 {
     $this->output->secure();
     $f = $this->input->f;
     $uid = $_SESSION['user']['id'];
     include_once "modules/preview.php";
     $p = new preview();
     $p->zid = $f['id'];
     $tpl = new XTemplate("templates/ads_preview.html");
     $tpl->assign("PREVIEW", $p->display());
     $tpl->assign("ADS_MENU", $this->menu($_REQUEST['f']['id']));
     $tpl->assign('URL', trim($this->default['adrevenue']['hostname'], "/") . "/index.php?section=redir&zid={$p->zid}");
     $tpl->parse("main");
     $this->title = lib_lang("Preview Ad");
     $this->content = $tpl->text("main");
     $this->display();
     $this->printpage();
     exit;
 }
 function _default()
 {
     // Our Duplicate flag
     $this->dup = 1;
     // Get variables
     if (!$this->zone) {
         $this->zone = $_GET['id'];
     }
     if (!$this->affid) {
         $this->affid = $_GET['affid'] ? $_GET['affid'] : 0;
     }
     if (!$this->rows) {
         $this->rows = $_GET['rows'] ? $_GET['rows'] : 0;
     }
     if (!$this->cols) {
         $this->cols = $_GET['cols'] ? $_GET['cols'] : 0;
     }
     if (!$this->ad_sort) {
         $this->ad_sort = $_GET['ad_sort'] ? $_GET['ad_sort'] : "asc";
     }
     if (!$this->format) {
         $this->format = $_GET['output'] ? $_GET['output'] : "html";
     }
     if (!$this->keyword) {
         $this->keyword = $_GET['keyword'];
     }
     $this->keywordid = 0;
     $this->keywordrate = 0.0;
     // Setup default headers
     // P3P: CP="NOI DSP COR PSAo PSDo OUR BUS OTC"
     if (!$this->default['adrevenue']['p3p']) {
         header('P3P: CP="NOI DSP COR PSAo PSDo OUR BUS OTC"');
     } else {
         header('P3P: CP="' . $this->default['adrevenue']['p3p'] . '"');
     }
     header("Cache-Control: no-store, no-cache, must-revalidate");
     header("Pragma: no-cache");
     header("X-Vendor: W3matter LLC | RevSense | http://www.revsense.com");
     // Get the zone
     if (!$this->zone) {
         return "";
     }
     $this->z = lib_cache_get("zone", $this->zone);
     if (!$this->z) {
         $p = $this->db->getsql("SELECT * FROM adrev_zones WHERE id=?", array($this->zone));
         $this->z = $p[0];
         lib_cache_put("zone", $this->zone, $p[0]);
     }
     // Check if this zone is active
     if ($this->z['status'] == 0) {
         return "";
     }
     // Check dayparting
     if ($this->z['daypart_enable'] == 1) {
         $day = date("w");
         $hour = date("G");
         if (!in_array($hour, lib_bit_options($this->z['daypart_hours']))) {
             return "";
         }
         if (!in_array($day, lib_bit_options($this->z['daypart_days']))) {
             return "";
         }
     }
     // Check geotargetting
     // **** This function will be added in a point release **** //
     // Override some zone settings that a user might have passed in
     if ($_GET['rows'] > 0) {
         $this->z['rows'] = $_GET['rows'];
     }
     if ($_GET['cols'] > 0) {
         $this->z['cols'] = $_GET['cols'];
     }
     if ($_GET['max_display_ads'] > 0) {
         $this->z['max_display_ads'] = $_GET['max_display_ads'];
     }
     if ($_GET['ad_sort']) {
         $this->z['ad_sort'] = $_GET['ad_sort'];
     }
     if ($_GET['rows'] && $_GET['cols']) {
         $this->z['max_display_ads'] = $_GET['rows'] * $_GET['cols'];
     }
     if (!$_GET['fuzzy']) {
         $this->z['keywords_fuzzy'] = $this->fuzzy ? $this->fuzzy : $this->z['keywords_fuzzy'];
     }
     // Get ads
     if (!$this->ads()) {
         return "";
     }
     // Update the log and billing info
     $this->impressions();
     include_once "modules/preview.php";
     $x = 0;
     $c = new preview();
     $c->affid = $this->affid;
     $c->keyid = $this->keywordid;
     if ($this->format == "js" || $this->format == "html" || $this->format == "raw") {
         reset($this->adlist);
         if ($this->z['layout_template']) {
             $tpl = new XTemplate("MEM", "<!-- BEGIN: main -->\n" . $this->z['layout_template'] . "\n<!-- END: main -->");
         } else {
             $tpl = new XTemplate("MEM", "<!-- BEGIN: main -->\n" . join("", file("templates/zone_default_layout.html")) . "\n<!-- END: main -->\n");
         }
         foreach ($this->adlist as $rec) {
             $x++;
             $parsed = 0;
             $c->zid = $rec['zid'];
             $oz = $c->format_ad("html");
             $tpl->assign("AD", $oz);
             $tpl->parse("main.row.col");
             if ($x >= $this->z['cols']) {
                 $x = 0;
                 $parsed = 1;
                 $tpl->parse("main.row");
             }
         }
         // Finish up parsing
         if (!$parsed) {
             $tpl->parse("main.row");
         }
         $tpl->parse("main");
         $out = $tpl->text("main");
         if ($this->format == "js") {
             $o1 = str_replace("'", "\\'", $out);
             $o1 = str_ireplace('<script', "<scr'+'ipt", $o1);
             $o1 = str_ireplace('</script>', "</scr'+'ipt>", $o1);
             $o = explode("\n", $o1);
             $oo = array();
             if (count($o) > 0) {
                 foreach ($o as $rec) {
                     if (strlen(trim($rec)) > 0) {
                         $oo[] = trim($rec);
                     }
                 }
             }
             $date = date("r");
             $nocache = md5(uniqid("")) . " | " . $_SERVER['REMOTE_ADDR'] . " | " . iif($this->dup, 'DUP', '');
             $out = "// W3matter.com | RevSense | http://www.w3matter.com\n";
             $out .= "// {$date}\n";
             $out .= "// Ad Code: {$nocache}\n\n";
             $out .= "document.write('" . implode("');\ndocument.write('", $oo) . "');\n";
             header("Content-type: text/javascript");
             echo $out;
             exit;
         }
     } elseif ($this->format == "xml") {
         // XML output
         $out = '<?xml version="1.0" encoding="UTF-16"?>' . "\n";
         reset($this->adlist);
         foreach ($this->adlist as $ad) {
             $c->zid = $ad['zid'];
             $out .= $c->format_ad("xml");
         }
         header("Content-type: text/xml");
     } else {
         // CSV output
         reset($this->adlist);
         foreach ($this->adlist as $ad) {
             $c->zid = $ad['zid'];
             $out .= $c->format_ad("csv");
         }
         header("Content-type: text/csv");
     }
     $net = lib_getmicrotime() - $this->tz;
     header("X-Server-Time: {$net}");
     echo $out;
     return "";
 }
 function zone_format()
 {
     $this->output->admin();
     $f = $this->input->f;
     $field_types = $this->default[field_types];
     // Loadup the zone
     $z = $this->db->getsql("SELECT * FROM adrev_zones WHERE id=?", array($f['id']));
     if (count($f[ad_format]) == 0) {
         $f[ad_format] = unserialize(stripslashes($z[0][ad_format]));
     }
     // Error finding zone
     if (!$z[0][id]) {
         $this->output->redirect(lib_lang("The zone could not be found"), "index.php?section=zone", 3);
         exit;
     }
     // Save the data
     if ($f[submit]) {
         // Cleanup the ad_format array();
         reset($f[ad_format]);
         $n = count($f[ad_format]);
         for ($x = 0; $x <= $n; $x++) {
             if (!$f[ad_format][$x][type]) {
                 unset($f[ad_format][$x]);
             }
         }
         $i = array();
         $i[ad_sort] = iif($z[0][rtype] == 2, "bid", $f[ad_sort]);
         $i[urls_target] = $f[urls_target];
         $i[urls_hide] = $f[urls_hide] ? 1 : 0;
         $i[urls_tracking] = $f[urls_tracking] ? 1 : 0;
         $i[ad_format] = serialize($f[ad_format]);
         $i[template] = trim(stripslashes($f[template]));
         $this->db->update("adrev_zones", "id", $f[id], $i);
         $this->output->redirect(lib_lang("Zone Format options were updated"), "index.php?section=zone&action=zone_format&f[id]={$f['id']}", 1);
         exit;
     }
     // Show the form
     $tpl = new XTemplate("templates/zone_format.html");
     $sortlist = array("asc" => lib_lang("Oldest at top"), "desc" => lib_lang("Newest at Top"), "rand" => lib_lang("Random"), "bid" => lib_lang("By Bid Price"));
     $tpl->assign("AD_SORT", lib_htlist_array($sortlist, $z[0][ad_sort]));
     $target = array("_self" => lib_lang("Open ad in same window"), "_new" => lib_lang("Open ad in new window"));
     $tpl->assign("URLS_TARGET", lib_htlist_array($target, $z[0][urls_target]));
     $tpl->assign("URLS_HIDE", $z[0][urls_hide] ? "CHECKED" : "");
     $tpl->assign("URLS_TRACKING", $z[0][urls_tracking] ? "CHECKED" : "");
     // Show the rows
     $row = 0;
     while (list($key, $val) = each($field_types)) {
         $row++;
         $tpl->assign("NAME", iif($f[ad_format][$row][name], $f[ad_format][$row][name], $val));
         $tpl->assign("TYPE", $key);
         $tpl->assign("ROW", $row);
         $tpl->assign("CHECKED", iif($f[ad_format][$row][type], "CHECKED", ""));
         $tpl->assign("BGCOLOR", iif($f[ad_format][$row][type], "#D2FFC4", "#FFFFFF"));
         // Non Image formats
         if ($key != "IMAGE") {
             $font = iif(!$f[ad_format][$row][font], "Verdana,Arial,Helvetica,sans-serif", $f[ad_format][$row][font]);
             $tpl->assign("FONT", "<input type=text name=\"f[ad_format][{$row}][font]\" value=\"{$font}\" size=10>");
             $size = iif(!$f[ad_format][$row][size], "1", $f[ad_format][$row][size]);
             $tpl->assign("SIZE", "<input type=text name=\"f[ad_format][{$row}][size]\" value=\"{$size}\" size=1>");
             $color = iif(!$f[ad_format][$row][color], "black", $f[ad_format][$row][color]);
             $tpl->assign("COLOR", "<input type=text name=\"f[ad_format][{$row}][color]\" value=\"{$color}\" size=6>");
             $bold = iif(!$f[ad_format][$row][bold], "", "CHECKED");
             $tpl->assign("BOLD", "<input type=checkbox name=\"f[ad_format][{$row}][bold]\" value=\"1\" {$bold}>");
             // Set some better default sizes
             $size = 20;
             if ($key == "TITLE") {
                 $size = 25;
             }
             if ($key == "DESCRIPTION") {
                 $size = 64;
             }
             if ($key == "URL") {
                 $size = 512;
             }
             if ($key == "DISPLAY_URL") {
                 $size = 25;
             }
             if ($key == "EMAIL") {
                 $size = 64;
             }
             if ($key == "PHONE") {
                 $size = 15;
             }
             if ($key == "FAX") {
                 $size = 15;
             }
             if ($key == "CONTENT") {
                 $size = 8192;
             }
             if (preg_match('/CUSTOM/', $key)) {
                 $size = 32;
             }
             $max_length = iif(!$f[ad_format][$row][max_length], $size, $f[ad_format][$row][max_length]);
             $tpl->assign("MAX_LENGTH", "<input type=text name=\"f[ad_format][{$row}][max_length]\" value=\"{$max_length}\" size=5>");
             $tpl->assign("MAX_UPLOAD", "&nbsp;");
             $tpl->assign("HEIGHT", "&nbsp;");
             $tpl->assign("WIDTH", "&nbsp;");
         } else {
             $tpl->assign("BOLD", "&nbsp;");
             $tpl->assign("COLOR", "&nbsp;");
             $tpl->assign("SIZE", "&nbsp;");
             $tpl->assign("FONT", "&nbsp;");
             $tpl->assign("MAX_LENGTH", "&nbsp;");
             $max_upload = iif(!$f[ad_format][$row][max_length], "65536", $f[ad_format][$row][max_length]);
             $tpl->assign("MAX_UPLOAD", "<input type=text name=\"f[ad_format][{$row}][max_length]\" value=\"{$max_upload}\" size=5>");
             $height = iif(!$f[ad_format][$row][height], "60", $f[ad_format][$row][height]);
             $tpl->assign("HEIGHT", "<input type=text name=\"f[ad_format][{$row}][height]\" value=\"{$height}\" size=4>");
             $width = iif(!$f[ad_format][$row][width], "480", $f[ad_format][$row][width]);
             $tpl->assign("WIDTH", "<input type=text name=\"f[ad_format][{$row}][width]\" value=\"{$width}\" size=4>");
         }
         $tpl->parse("main.formatlist");
     }
     // Grab the ad type for this zone
     $style = $z[0][style];
     $s = $this->db->getsql("SELECT * FROM adrev_ad_types WHERE id=?", array($style));
     $tpl->assign("FIELD_TYPES", lib_htlist_array($field_types, '0'));
     $tpl->assign("ID", $f[id]);
     $tpl->assign("ZONE_MENU", $this->zone_menu($f[id]));
     $tpl->assign("TEMPLATE", htmlentities(stripslashes($z[0][template]), ENT_QUOTES));
     // Preview the template
     $ad = $this->db->getsql("SELECT zid FROM adrev_ads WHERE zone=? LIMIT 1", array($f['id']));
     if (!$ad[0][zid]) {
         $tpl->assign("PREVIEW", lib_lang("You need to place at least one ad in this zone for a preview to be generated"));
     } else {
         include_once "modules/preview.php";
         $p = new preview();
         $p->main();
         $p->zid = $ad[0][zid];
         $preview = $p->display();
         $tpl->assign("PREVIEW", $preview);
     }
     $tpl->parse("main");
     $this->title = lib_lang("Manage") . " [" . stripslashes($z[0][name]) . "] : " . lib_lang("Format");
     $this->content = $tpl->text("main");
     $this->display();
     $this->printpage();
     exit;
 }