Ejemplo n.º 1
0
 function storeUnlimiteAd()
 {
     require JPATH_SITE . DS . "administrator" . DS . "components" . DS . "com_socialads" . DS . "config" . DS . "config.php";
     $data = JRequest::get('post');
     $data = $this->dataSanitize($data);
     $user = JFactory::getUser();
     $img = str_replace(JUri::base(), '', $data['upimgcopy']);
     if ($img == '') {
         $img = str_replace(JUri::base(), '', $data['upimg']);
     }
     $build = new stdClass();
     $build->ad_id = '';
     $build->ad_creator = $user->id;
     foreach ($data['addata'] as $addata) {
         foreach ($addata as $k => $ad) {
             $build->{$k} = $ad;
         }
     }
     //ANIKET
     $buildadsession = JFactory::getSession();
     if (empty($data['camp_name'])) {
         $buildadsession->set('camp', $data['camp']);
     } else {
         $buildadsession->set('camp', $data['camp_name']);
         $buildadsession->set('value', $data['camp_amount']);
     }
     $buildadsession->set('pricing_opt', $data['pricing_opt']);
     if ($socialads_config['select_campaign'] == 1) {
         $db = JFactory::getDBO();
         $query = "SELECT campaign FROM #__ad_campaign WHERE campaign ='" . $buildadsession->get('camp') . "'";
         $db->setQuery($query);
         $campaign = $db->loadResult();
         if (empty($campaign)) {
             $query = "INSERT INTO #__ad_campaign (campaign,user_id,daily_budget,camp_published) VALUES ('" . $buildadsession->get('camp') . "'," . $user->id . "," . $buildadsession->get('value') . ",1)";
             $db->setQuery($query);
             $db->execute();
         }
         $query = "SELECT camp_id FROM #__ad_campaign WHERE campaign ='" . $buildadsession->get('camp') . "'";
         $db->setQuery($query);
         $camp_id = $db->loadResult();
         $build->camp_id = $camp_id;
         //$build->ad_payment_type	 =	$buildadsession->get('pricing_opt');
     }
     $build->ad_image = $img;
     $build->ad_created_date = date('Y-m-d H:i:s');
     $build->ad_published = 1;
     $build->ad_approved = 1;
     $build->ad_noexpiry = 1;
     if (isset($data['guestbutton'])) {
         $buildadsession->set('guestbutton', $data['guestbutton']);
         $guest = $buildadsession->get('guestbutton');
     }
     $geoflag = 0;
     if (isset($data['geo']) || !empty($data['geo'])) {
         foreach ($data['geo'] as $geo) {
             if (!empty($geo)) {
                 $geoflag = 1;
                 break;
             }
         }
     }
     if (isset($data['geo_target']) && !$geoflag && !isset($data['social_target']) || !isset($data['geo_target']) && !isset($data['social_target'])) {
         if ($data['context_target'] != "on" || $data['context_target'] == "on" && !$data['context_target_data_keywordtargeting']) {
             $build->ad_guest = 1;
         }
     }
     //Extra Code For Zone
     $adzone = '';
     if ($data['ad_zone_id'] != '') {
         $adzone = $data['ad_zone_id'];
     } else {
         $adzone = $data['adzone'];
     }
     $build->ad_zone = $adzone;
     $build->layout = $data['layout'];
     //Extra Code For Zone
     //insert fields
     if (!$this->_db->insertObject('#__ad_data', $build, 'ad_id')) {
         echo $this->_db->stderr();
         return false;
     }
     /*start of geo*/
     if ($socialads_config['geo_target'] && isset($data['geo_target'])) {
         if ($geoflag) {
             $first_key = array_keys($data['geo']);
             $type = str_replace("by", "", $data['geo_type']);
             $fielddata = new stdClass();
             $fielddata->ad_id = $build->ad_id;
             foreach ($data['geo'] as $key => $value) {
                 if ($first_key[0] == $key) {
                     $fielddata->{$key} = $value;
                 } else {
                     if ($type == $key) {
                         $fielddata->{$key} = $value;
                     } else {
                         if ($data['geo_type'] == "everywhere") {
                             break;
                         }
                     }
                 }
             }
             if (!$this->_db->insertObject('#__ad_geo_target', $fielddata, 'id')) {
                 echo $this->_db->stderr();
                 return false;
             }
         }
     }
     /*end of geo*/
     $var = new socialadshelper();
     $adfields = $var->chkadfields();
     if (!empty($adfields) && isset($data['social_target'])) {
         //For saving demographic details
         $fielddata = new stdClass();
         $fielddata->adfield_id = '';
         $fielddata->adfield_ad_id = $this->_db->insertid();
         $date_low = date('Y-m-d 00:00:00', mktime(0, 0, 0, 01, 1, 1910));
         $date_high = date('Y-m-d 00:00:00', mktime(0, 0, 0, 01, 1, 2030));
         $grad_low = 0;
         $grad_high = 2030;
         foreach ($data['mapdata'] as $mapdata) {
             foreach ($mapdata as $m => $map) {
                 if ($m) {
                     if (strstr($m, ',')) {
                         $selcheck = explode(',', $m);
                         $var = isset($fielddata->{$selcheck}[0]);
                     } else {
                         $var = isset($fielddata->{$m});
                     }
                     if (!$var) {
                         if (strstr($m, '|')) {
                             $rangecheck = explode('|', $m);
                             if ($rangecheck[2] == 0) {
                                 if ($map) {
                                     if ($rangecheck[1] == 'daterange') {
                                         $date_low = $map;
                                     } elseif ($rangecheck[1] == 'numericrange') {
                                         $grad_low = $map;
                                     }
                                 }
                                 if ($rangecheck[1] == 'daterange') {
                                     $fielddata->{$rangecheck}[0] = $date_low;
                                 } elseif ($rangecheck[1] == 'numericrange') {
                                     $fielddata->{$rangecheck}[0] = $grad_low;
                                 }
                                 //0
                             } elseif ($rangecheck[2] == 1) {
                                 if ($map) {
                                     if ($rangecheck[1] == 'daterange') {
                                         $date_high = $map;
                                     } elseif ($rangecheck[1] == 'numericrange') {
                                         $grad_high = $map;
                                     }
                                 }
                                 if ($rangecheck[1] == 'daterange') {
                                     $fielddata->{$rangecheck}[0] = $date_high;
                                 } elseif ($rangecheck[1] == 'numericrange') {
                                     $fielddata->{$rangecheck}[0] = $grad_high;
                                 }
                                 //2030
                             }
                         } elseif (strstr($m, ',')) {
                             $selcheck = explode(',', $m);
                             if ($selcheck[1] == 'select') {
                                 if ($map) {
                                     $fielddata->{$selcheck}[0] = '|' . $map . '|';
                                 } else {
                                     $fielddata->{$selcheck}[0] = $map;
                                 }
                             }
                         } else {
                             $fielddata->{$m} = $map;
                         }
                     } else {
                         if (strstr($m, ',')) {
                             $selcheck = explode(',', $m);
                             if ($selcheck[1] == 'select') {
                                 $fielddata->{$selcheck}[0] .= '|' . $map . '|';
                             }
                         } else {
                             $fielddata->{$m} .= '|' . $map . '|';
                         }
                         //$fielddata->$m .= ','.$map;
                     }
                 }
             }
         }
         JPluginHelper::importPlugin('socialadstargeting');
         $dispatcher = JDispatcher::getInstance();
         $results = $dispatcher->trigger('onFrontendTargetingSave', array($profile));
         for ($i = 0; $i < count($results); $i++) {
             if ($results[$i] != "") {
                 foreach ($results[$i] as $key => $value) {
                     $fielddata->{$key} = $value;
                 }
             }
         }
         //insert fields
         if (!$this->_db->insertObject('#__ad_fields', $fielddata, 'adfield_id')) {
             echo $this->_db->stderr();
             return false;
         }
     }
     //chk empty ad_fields
     $ad_id = $build->ad_id;
     /*start of context*/
     if ($socialads_config['context_target'] && $data['context_target'] == "on") {
         $context_adfields = $data['context_target_data_keywordtargeting'];
         if ($context_adfields) {
             $fielddata = new stdClass();
             $fielddata->id = '';
             $fielddata->ad_id = $build->ad_id;
             $fielddata->keywords = trim(strtolower($context_adfields));
             /*$keyarr=explode(',',$fielddata->keywords);
             			foreach($keyarr as $keyword)
             			{
             						if(strlen($keyword)<=3)
             						{
             							$no_of_chars=3-strlen($keyword);
             							for($i=0;$i<$no_of_chars;$i++)
             							{
             							$keyword=$keyword.'8';
             							}
             
             						}
             						$newkeyarr[]=$keyword;
             
             			}
             
             			$keystr=implode(',',$newkeyarr);
             
             			$fielddata->keywords=$keystr;*/
             if (!$this->_db->insertObject('#__ad_contextual_target', $fielddata, 'id')) {
                 echo $this->_db->stderr();
                 return false;
             }
         }
     }
     /*end of context*/
     return $build->ad_id;
 }
Ejemplo n.º 2
0
 function store()
 {
     require JPATH_SITE . DS . "administrator" . DS . "components" . DS . "com_socialads" . DS . "config" . DS . "config.php";
     global $mainframe;
     $mainframe = JFactory::getApplication();
     $input = JFactory::getApplication()->input;
     //for getting adfield_id from DB
     $db = JFactory::getDBO();
     $user = JFactory::getUser();
     $data = JRequest::get('post');
     $data = $this->dataSanitize($data);
     $user = JFactory::getUser();
     $build = new stdClass();
     $ad_id = $input->get('adid', 0, 'INT');
     $build->ad_id = $ad_id;
     $imgname = str_replace(JUri::base(), '', $data['upimg']);
     foreach ($data['addata'] as $addata) {
         foreach ($addata as $k => $ad) {
             $build->{$k} = $ad;
         }
     }
     //code for guest
     $geoflag = 0;
     if (isset($data['geo']) || !empty($data['geo'])) {
         foreach ($data['geo'] as $geo) {
             if (!empty($geo)) {
                 $geoflag = 1;
                 break;
             }
         }
     }
     if (isset($data['geo_target']) && !$geoflag && !isset($data['social_target']) || !isset($data['geo_target']) && !isset($data['social_target'])) {
         if ($data['context_target'] == "on" && !$data['context_target_data_keywordtargeting'] || $data['context_target'] != "on") {
             $build->ad_guest = 1;
         } else {
             $build->ad_guest = 0;
         }
     } else {
         $build->ad_guest = 0;
     }
     //code for guest
     $build->ad_image = $imgname;
     $build->layout = $data['layout'];
     //update fields
     if (!$this->_db->updateObject('#__ad_data', $build, 'ad_id')) {
         echo $this->_db->stderr();
         return false;
     }
     //For saving demographic details
     /*start of geo*/
     $fielddata = new stdClass();
     $fielddata->ad_id = $build->ad_id;
     if ($socialads_config['geo_target'] && !empty($data['geo_target'])) {
         $geo_adfields = $data['geo'];
         if ($geoflag) {
             $first_key = array_keys($data['geo']);
             $type = str_replace("by", "", $data['geo_type']);
             foreach ($data['geo'] as $key => $value) {
                 if ($first_key[0] == $key) {
                     $fielddata->{$key} = $value;
                 } else {
                     if ($data['geo_type'] == "everywhere") {
                         $fielddata->{$key} = "";
                     } else {
                         if ($type == $key) {
                             $fielddata->{$key} = $value;
                         }
                     }
                 }
             }
             $query = "SELECT  a.id FROM #__ad_geo_target AS a, #__ad_data AS b WHERE a.ad_id=" . $ad_id . " AND a.ad_id=b.ad_id AND  b.ad_creator=" . $user->id . "";
             $db->setQuery($query);
             $adfieldid = $db->loadResult();
             $query = "DELETE FROM #__ad_geo_target WHERE ad_id=" . $ad_id;
             $this->_db->setQuery($query);
             if (!$db->execute()) {
                 echo $this->_db->stderr();
             }
             $fielddata->id = '';
             if (!$this->_db->insertObject('#__ad_geo_target', $fielddata, 'id')) {
                 echo $this->_db->stderr();
                 //return false;
             }
         }
     } else {
         $query = "DELETE FROM #__ad_geo_target WHERE ad_id=" . $ad_id;
         $this->_db->setQuery($query);
         if (!$db->execute()) {
             echo $this->_db->stderr();
         }
     }
     /*end of geo*/
     /*start of context*/
     $fielddata = new stdClass();
     $fielddata->id = '';
     $fielddata->ad_id = $build->ad_id;
     $fielddata->keywords = strtolower(trim($context_adfields));
     $query = "SELECT  id FROM #__ad_contextual_target AS a, #__ad_data AS b WHERE a.ad_id=" . $ad_id . " AND a.ad_id=b.ad_id ";
     $db->setQuery($query);
     $adfieldid = $db->loadResult();
     if ($socialads_config['context_target']) {
         if ($data['context_target'] == "on") {
             $context_adfields = trim($data['context_target_data_keywordtargeting']);
             if ($context_adfields) {
                 $fielddata->keywords = strtolower(trim($context_adfields));
                 if ($adfieldid) {
                     $fielddata->id = $adfieldid;
                     if (!$this->_db->updateObject('#__ad_contextual_target', $fielddata, 'id')) {
                     }
                 } else {
                     if (!$this->_db->insertObject('#__ad_contextual_target', $fielddata, 'id')) {
                         echo $this->_db->stderr();
                         return false;
                     }
                 }
             }
         } else {
             if ($adfieldid) {
                 $fielddata->id = $adfieldid;
                 $query = 'DELETE FROM #__ad_contextual_target' . ' WHERE id= ' . $fielddata->id;
                 $db->setQuery($query);
                 if (!$db->execute()) {
                 }
             }
         }
     } else {
         if ($adfieldid) {
             //echo "HERE4";
             $fielddata->id = $adfieldid;
             $query = 'DELETE FROM #__ad_contextual_target' . ' WHERE id= ' . $fielddata->id;
             $db->setQuery($query);
             if (!$db->execute()) {
             }
         }
     }
     /*end of context*/
     $fielddata = new stdClass();
     $ad_id = $input->get('adid', 0, 'INT');
     $socialadshelper = new socialadshelper();
     $adfields = $socialadshelper->chkadfields();
     if (!empty($adfields)) {
         $query = "SELECT distinct adfield_id\n\t\t\tFROM #__ad_fields AS a, #__ad_data AS b\n\t\t\tWHERE a.adfield_ad_id=" . $ad_id . " AND b.ad_creator=" . $user->id . "";
         $db->setQuery($query);
         $adfieldid = $db->loadResult();
         $fieldsas = $db->getTableColumns("#__ad_fields");
         if ($data['social_target'] == "on" && !empty($fieldsas)) {
             //chk empty
             $query = "SELECT COUNT(*) FROM #__ad_fields AS f WHERE f.adfield_ad_id=" . $build->ad_id;
             $db->setQuery($query);
             $count = $db->loadResult();
             $fielddata->adfield_id = $adfieldid;
             $fielddata->adfield_ad_id = $build->ad_id;
             $date_low = date('Y-m-d 00:00:00', mktime(0, 0, 0, 01, 1, 1910));
             $date_high = date('Y-m-d 00:00:00', mktime(0, 0, 0, 01, 1, 2030));
             $grad_low = 0;
             $grad_high = 2030;
             foreach ($data['mapdata'] as $mapdata) {
                 foreach ($mapdata as $m => $map) {
                     if ($m) {
                         if (strstr($m, ',')) {
                             $selcheck = explode(',', $m);
                             $var = isset($fielddata->{$selcheck}[0]);
                         } else {
                             $var = isset($fielddata->{$m});
                         }
                         if (!$var) {
                             if (strstr($m, '|')) {
                                 $rangecheck = explode('|', $m);
                                 if ($rangecheck[2] == 0) {
                                     if ($map) {
                                         if ($rangecheck[1] == 'daterange') {
                                             $date_low = $map;
                                         } elseif ($rangecheck[1] == 'numericrange') {
                                             $grad_low = $map;
                                         }
                                     }
                                     if ($rangecheck[1] == 'daterange') {
                                         $fielddata->{$rangecheck}[0] = $date_low;
                                     } elseif ($rangecheck[1] == 'numericrange') {
                                         $fielddata->{$rangecheck}[0] = $grad_low;
                                     }
                                     //0
                                 } elseif ($rangecheck[2] == 1) {
                                     if ($map) {
                                         if ($rangecheck[1] == 'daterange') {
                                             $date_high = $map;
                                         } elseif ($rangecheck[1] == 'numericrange') {
                                             $grad_high = $map;
                                         }
                                     }
                                     if ($rangecheck[1] == 'daterange') {
                                         $fielddata->{$rangecheck}[0] = $date_high;
                                     } elseif ($rangecheck[1] == 'numericrange') {
                                         $fielddata->{$rangecheck}[0] = $grad_high;
                                     }
                                     //2030
                                 }
                             } elseif (strstr($m, ',')) {
                                 $selcheck = explode(',', $m);
                                 if ($selcheck[1] == 'select') {
                                     if ($map) {
                                         $fielddata->{$selcheck}[0] = '|' . $map . '|';
                                     } else {
                                         $fielddata->{$selcheck}[0] = $map;
                                     }
                                 }
                             } else {
                                 $fielddata->{$m} = $map;
                             }
                         } else {
                             if (strstr($m, ',')) {
                                 $selcheck = explode(',', $m);
                                 if ($selcheck[1] == 'select') {
                                     $fielddata->{$selcheck}[0] .= '|' . $map . '|';
                                 }
                             } else {
                                 $fielddata->{$m} .= '|' . $map . '|';
                             }
                             //$fielddata->$m .= ','.$map;
                         }
                     }
                 }
             }
             JPluginHelper::importPlugin('socialadstargeting');
             $dispatcher = JDispatcher::getInstance();
             $results = $dispatcher->trigger('onFrontendTargetingSave', array($data['plgdata']));
             //		$res = new stdClass();
             for ($j = 0; $j < count($results); $j++) {
                 if ($results[$j] != "") {
                     foreach ($results[$j] as $key => $value) {
                         $fielddata->{$key} = $value;
                     }
                 }
             }
             if ($count > 0) {
                 //if multiselect box is empty then field name should be post blank value
                 $db = JFactory::getDBO();
                 $query = "SELECT mapping_fieldname FROM #__ad_fields_mapping WHERE mapping_fieldtype='multiselect'";
                 $db->setQuery($query);
                 $mulfields = $db->loadResultarray();
                 foreach ($fielddata as $k => $v) {
                     $fields[] = $k;
                 }
                 for ($i = 0; $i < count($mulfields); $i++) {
                     if (!in_array($mulfields[$i], $fields)) {
                         $fielddata->{$mulfields}[$i] = '';
                     }
                 }
                 //update fields
                 if (!$this->_db->updateObject('#__ad_fields', $fielddata, 'adfield_id')) {
                     echo $this->_db->stderr();
                     return false;
                 }
             } else {
                 $fielddata->adfield_id = null;
                 //insert fields
                 if (!$this->_db->insertObject('#__ad_fields', $fielddata, 'adfield_id')) {
                     echo $this->_db->stderr();
                     return false;
                 }
             }
         } else {
             if ($data['social_target'] != "on" && $adfieldid) {
                 //echo "HERE4";
                 $fielddata->id = $adfieldid;
                 $query = 'DELETE FROM #__ad_fields' . ' WHERE adfield_id= ' . $adfieldid;
                 $db->setQuery($query);
                 if (!$db->execute()) {
                 }
             }
         }
     }
     //chk empty
     if ($socialads_config['all_approval'] == 1 && $socialads_config['approval'] == 1) {
         $build = new stdClass();
         $build->ad_id = $ad_id;
         $build->ad_approved = '0';
         //update fields
         if (!$this->_db->updateObject('#__ad_data', $build, 'ad_id')) {
             echo $this->_db->stderr();
             return false;
         }
     }
     //mail function after upadting an Ad
     $query = "SELECT a.ad_title,  u.username FROM #__ad_data as a, #__users as u\n\t\t\t\t\t\tWHERE a.ad_creator=u.id\n\t\t\t\t\t\tAND a.ad_id=" . $ad_id;
     $this->_db->setQuery($query);
     $result = $this->_db->loadObject();
     //print_r($result);
     $body = JText::_('UPDATE_MAIL_BODY');
     $body = str_replace('{username}', $result->username, $body);
     $ad_title = $result->ad_title != '' ? JText::_("PERIDIC_STATS_ADTIT") . ' <b>"' . $result->ad_title . '"</b>' : JText::_("PERIDIC_STATS_ADID") . ' : <b>' . $ad_id . '</b>';
     $body = str_replace('{title}', $ad_title, $body);
     $body = str_replace('{link}', JUri::base() . 'administrator/index.php?option=com_socialads&view=approveads', $body);
     $from = $mainframe->getCfg('mailfrom');
     $fromname = $mainframe->getCfg('fromname');
     $recipient = $mainframe->getCfg('mailfrom');
     $user = JFactory::getUser();
     $subject = JText::_('MAIL_UPDATE_SUB');
     $body = nl2br($body);
     $mode = 1;
     $cc = null;
     $bcc = null;
     $bcc = null;
     $attachment = null;
     $replyto = null;
     $replytoname = null;
     JFactory::getMailer()->sendMail($from, $fromname, $recipient, $subject, $body, $mode, $cc, $bcc, $attachment, $replyto, $replytoname);
     return true;
 }