function saveTargetingData($post) { require JPATH_SITE . DS . "administrator" . DS . "components" . DS . "com_socialads" . DS . "config" . DS . "config.php"; $session = JFactory::getSession(); $app = JFactory::getApplication(); //.. do Back End Stuff if ($app->isAdmin()) { $ad_creator_id = $post->get('ad_creator_id'); $user = JFactory::getUser($ad_creator_id); $userid = $user->id; } else { $user = JFactory::getUser(); $userid = $user->id; } if (!$userid) { $userid = 0; return false; } $adData = new stdClass(); $adData->ad_id = ''; $ad_id = $session->get('ad_id'); $tagetId = ''; //Get primary key of table if ($ad_id) { $adData->ad_id = $ad_id; //Get order id // @params $value,$field_name,$tableName $targetAdId = $this->getIdFromAnyFieldValue($adData->ad_id, 'ad_id', '#__ad_geo_target'); if ($targetAdId) { $tagetId = $targetAdId; } } else { $app = JFactory::getApplication(); $app->enqueueMessage('Session Expire', 'error'); return false; } //Added for geo targeting $geo_type = $post->get('geo_type', '', 'STRING'); $geo_fields = $post->get('geo', '', 'Array'); $geo_target = $post->get('geo_targett', '', 'INT'); $social_target = $post->get('social_targett', '', 'INT'); $context_target = $post->get('context_targett', '', 'INT'); //Set geoflag $geoflag = 0; if (isset($geo_fields) || !empty($geo_fields)) { foreach ($geo_fields as $geo) { if (!empty($geo)) { $geoflag = 1; break; } } } $context_target_data = $post->get('context_target_data', '', 'Array'); $context_target_data_keywordtargeting = $context_target_data['keywordtargeting']; //check to decide if ad is non targeted ie guest ad /*if( $geo_target=="1" && !$geoflag && !($social_target=="1") || !($geo_target=="1") && !($social_target=="1") ) { if(($context_target!="1") || ($context_target=="1" &&!($context_target_data_keywordtargeting))) { $adData->ad_guest = 1; } else { $adData->ad_guest = 0; } }*/ //IF any one targeting set then ad is not a guest ad if ($geo_target || $social_target || $context_target) { $adData->ad_guest = 0; } else { $adData->ad_guest = 1; } //Start of geo if ($socialads_config['geo_target'] && $geo_target == "1") { $geo_adfields = $geo_fields; //form field name="geo[country]" name="geo[region]" name="geo[city]" if ($geoflag) { $first_key = array_keys($geo_fields); $type = str_replace("by", "", $geo_type); //name="geo_type" everywhere || city || region $fielddata = new stdClass(); $fielddata->id = ''; //Get tagert table id if ($tagetId) { $fielddata->id = $tagetId; } $fielddata->ad_id = $ad_id; foreach ($geo_fields as $key => $value) { if ($first_key[0] == $key) { // for country $fielddata->{$key} = $value; } else { if ($type == $key) { // for region & city $fielddata->{$key} = $value; } else { if ($geo_type == "everywhere") { break; } } } } if ($fielddata->id) { if (!$this->_db->updateObject('#__ad_geo_target', $fielddata, 'id')) { echo $this->_db->stderr(); return false; } } else { 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 (!$this->_db->execute()) { echo $this->_db->stderr(); return false; } } /*end of geo*/ /*Start of context*/ //Get primary key of table if (!empty($ad_id)) { //Get order id // @params $value,$field_name,$tableName $id = $this->getIdFromAnyFieldValue($ad_id, 'ad_id', '#__ad_contextual_target'); if ($id) { $context_targetId = $id; } } else { $app = JFactory::getApplication(); $app->enqueueMessage('Session Expire', 'error'); return false; } if ($socialads_config['context_target'] && $context_target == "1") { if ($context_target_data_keywordtargeting) { $context_target = new stdClass(); $context_target->id = ''; $context_target->ad_id = $ad_id; if ($context_targetId) { $context_target->id = $context_targetId; } $context_target->keywords = trim(strtolower($context_target_data_keywordtargeting)); if ($context_target->id) { if (!$this->_db->updateObject('#__ad_contextual_target', $context_target, 'id')) { echo $this->_db->stderr(); return false; } } else { if (!$this->_db->insertObject('#__ad_contextual_target', $context_target, 'id')) { echo $this->_db->stderr(); return false; } } } } else { if ($context_targetId) { $query = "DELETE FROM #__ad_contextual_target WHERE id=" . $context_targetId; $this->_db->setQuery($query); if (!$this->_db->execute()) { echo $this->_db->stderr(); } } } //START Save --Social Targeting data-- //$buildadsession->set('ad_fields',$data['mapdata']); //$session_adfields = $buildadsession->get('ad_fields'); //$profile=$buildadsession->get('plg_fields'); $ad_fields = $post->get('mapdata', '', 'Array'); $profile = $post->get('plgdata', '', 'Array'); //Get social target ID // @params $value,$field_name,$tableName if ($ad_id) { $db = JFactory::getDBO(); if ($social_target == "1") { $db = JFactory::getDBO(); $app = JFactory::getApplication(); $dbprefix = $app->getCfg('dbprefix'); $tbexist_query = "SHOW TABLES LIKE '" . $dbprefix . "ad_fields'"; $db->setQuery($tbexist_query); $isTableExist = $db->loadResult(); if ($isTableExist) { $query = "SELECT adfield_id FROM #__ad_fields\n\t\t\t\t\tWHERE adfield_ad_id = " . $ad_id; $db->setQuery($query); $adfield_id = $db->loadResult(); } } } if ((!empty($ad_fields) || !empty($profile)) && $social_target == "1") { //For saving demographic details $fielddata = new stdClass(); $fielddata->adfield_id = ''; if ($adfield_id) { $fielddata->adfield_id = $adfield_id; } $fielddata->adfield_ad_id = $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; if (!empty($ad_fields)) { foreach ($ad_fields 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; } } } } } $socialadshelper = new socialadshelper(); $tableColumns = $socialadshelper->getTableColumns('ad_fields'); JPluginHelper::importPlugin('socialadstargeting'); $dispatcher = JDispatcher::getInstance(); $results = $dispatcher->trigger('onFrontendTargetingSave', array($profile, $tableColumns)); for ($i = 0; $i < count($results); $i++) { if ($results[$i] != "") { foreach ($results[$i] as $key => $value) { $fielddata->{$key} = $value; } } } //insert fields $db = JFactory::getDBO(); $app = JFactory::getApplication(); $dbprefix = $app->getCfg('dbprefix'); $tbexist_query = "SHOW TABLES LIKE '" . $dbprefix . "ad_fields'"; $db->setQuery($tbexist_query); $isTableExist = $db->loadResult(); if ($isTableExist) { if ($fielddata->adfield_id) { if (!$this->_db->updateObject('#__ad_fields', $fielddata, 'adfield_id')) { echo $this->_db->stderr(); return false; } } else { if (!$this->_db->insertObject('#__ad_fields', $fielddata, 'adfield_id')) { echo $this->_db->stderr(); return false; } } } } else { if ($adfield_id) { $this->deleteData('ad_fields', 'adfield_id', $adfield_id); } } //Update ad data table if (!$this->_db->updateObject('#__ad_data', $adData, 'ad_id')) { echo $this->_db->stderr(); return false; } //empty condition checkin ends //END Save --Social Targeting data-- return true; }
/** * Buildad view display method * @return void **/ function display($tpl = null) { $input = JFactory::getApplication()->input; $layout = $input->get('layout', 'default'); $user = JFactory::getUser(); if ($user->id) { //User authorized to view chat history if (!JFactory::getUser($user->id)->authorise('core.create_ad', 'com_socialads')) { $app = JFactory::getApplication(); $app->enqueueMessage(JText::_('COM_SOCIALADS_AUTH_ERROR'), 'warning'); return false; } } $model = $this->getModel('buildad'); //$post=$input->post; if ($input->get('frm', '', 'STRING') != 'editad' && $input->get('frm', '', 'STRING') != 'directad') { $buildadsession = JFactory::getSession(); $buildadsession->clear('ad_data'); $buildadsession->clear('ad_image'); $buildadsession->clear('upimgcopy'); $buildadsession->clear('ad_fields'); $buildadsession->clear('plg_fields'); $buildadsession->clear('upimg'); $buildadsession->clear('datefrom'); $buildadsession->clear('dateto'); $buildadsession->clear('ad_totaldays'); $buildadsession->clear('ad_totaldisplay'); $buildadsession->clear('totalamount'); $buildadsession->clear('ad_chargeoption'); $buildadsession->clear('ad_gateway'); $buildadsession->clear('ad_currency'); $buildadsession->clear('ad_rate'); $buildadsession->clear('guestbutton'); $buildadsession->clear('addatapluginlist'); $buildadsession->clear('pluginimg'); $buildadsession->clear('user_points'); //Added by sagar $buildadsession->clear('arb_flag'); $buildadsession->clear('order_id'); //Added by sagar //added for geo targeting $buildadsession->clear('geo_type'); $buildadsession->clear('geo_fields'); $buildadsession->clear('geo_target'); $buildadsession->clear('social_target'); //added for geo targeting $buildadsession->clear('context_target_data_keywordtargeting'); //$buildadsession->clear('ad_id'); $buildadsession->clear('camp'); $buildadsession->clear('value'); $buildadsession->clear('pricing_opt'); } $model = $this->getModel('buildad'); $fields = $this->get('Fields'); $this->fields = $fields; // url select list $url1 = array(); $url1[] = JHtml::_('select.option', 'http', JText::_("HTTP")); $url1[] = JHtml::_('select.option', 'https', JText::_("HTTPS")); $this->assignRef('url1', $url1); //for payment-info. view $result = $this->get('Payment'); $this->paypal = $result; //session variable for ad-data $buildadsession = JFactory::getSession(); $this->managead_adid = $ad_id = $input->get('adid', 0, 'INT'); $session = JFactory::getSession(); if (!$ad_id) { $ad_id = $session->get('ad_id'); } $session->set('ad_id', $ad_id); $this->ad_id = $ad_id; $this->allowWholeAdEdit = 1; $socialadshelper = new socialadshelper(); $this->Itemid = $socialadshelper->getSocialadsItemid('managead'); if ($ad_id) { $builadModel = $this->getModel(); $this->checkItIsuserAd = $builadModel->checkItIsuserAd($ad_id); if (!$this->checkItIsuserAd) { $session->clear('ad_id'); return false; } require_once JPATH_SITE . DS . 'components' . DS . 'com_socialads' . DS . 'models' . DS . 'managead.php'; $managead_model = new socialadsModelManageAd(); //var_dump($managead_model); die('adasdasd'); $addata_for_adsumary_edit = $managead_model->getData($ad_id); //$this->assignRef( 'ad_socialtarget',$addata[0] ); $this->assignRef('addata_for_adsumary_edit', $addata_for_adsumary_edit[1]); $this->assignRef('social_target', $addata_for_adsumary_edit[0]); $zone = $managead_model->getzone($ad_id); $this->assignRef('zone', $zone[0]); $this->geo_target = $managead_model->getData_geo($ad_id); //$this->assignRef( 'geo_target', $managead_model->getData_geo()); $Data_context_target = $managead_model->getData_context_target($ad_id); $this->assignRef('context_target', $Data_context_target['keywords']); $this->assignRef('context_target_data_keywordtargeting', $Data_context_target['keywords']); $this->pricingData = $builadModel->getpricingData($ad_id); $sa_addCredit = $input->get('sa_addCredit', 0); $this->sa_addCredit = $sa_addCredit; // called from add more credit $this->editableSteps = array(); if (!empty($sa_addCredit)) { $socialadshelper = new socialadshelper(); $user = JFactory::getUser(); $sa_addCredit = $input->get('sa_addCredit'); $this->editableSteps = $socialadshelper->adStateForAddMoreCredit($ad_id, $user->id); } else { $this->allowWholeAdEdit = $builadModel->allowWholeAdEdit($ad_id); } // print_r($this->editableSteps); die; } else { $ad_data = $buildadsession->get('ad_data'); $this->ad_data = $ad_data; //added for geo targeting //session variable for geo_fields $this->geo_target = $buildadsession->get('geo_target'); $this->geo_type = $buildadsession->get('geo_type'); $this->geo_fields = $buildadsession->get('geo_fields'); $this->context_target_data_keywordtargeting = $buildadsession->get('context_target_data_keywordtargeting'); $this->social_target = $buildadsession->get('social_target'); } //for camp edit //$this->assignRef( 'bid_value',$buildadsession->get('bid_value' )); //print_r($this->bid_value); die("im view buildad"); //$this->assignRef( 'ad_data',$ad_data ); //Extra code for zone $defaultzone_show = 1; $Check_default_zone = $this->get('defaultzone'); if (count($Check_default_zone) == 1) { $defaultzone_show = $model->checkdefaultzone($Check_default_zone); } $this->assignRef('Check_default_zone', $Check_default_zone); $this->assignRef('defaultzone_show', $defaultzone_show); //Extra code for zone $camp_dd = $this->get('campaign'); $this->assignRef('camp_dd', $camp_dd); if ($campid = $input->get('campid', 0, 'INT')) { $model = $this->getModel('buildad'); $cname = $model->getcampname($campid); $this->assignRef('cname', $cname); } $this->setLayout($layout); //die('asdasdasdasdasdasd'); // vm: started -------------------------------------- $this->country = $this->get("Country"); // load social ads config params require JPATH_SITE . DS . "administrator" . DS . "components" . DS . "com_socialads" . DS . "config" . DS . "config.php"; $selected_gateways = $socialads_config['gateways']; //getting GETWAYS $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('payment'); //$params->get( 'gateways' ) = array('0' => 'paypal','1'=>'Payu'); if (!is_array($selected_gateways)) { $gateway_param[] = $selected_gateways; } else { $gateway_param = $selected_gateways; } if (!empty($gateway_param)) { $gateways = $dispatcher->trigger('onTP_GetInfo', array($gateway_param)); } $this->ad_gateways = $gateways; $this->userbill = array(); if (!empty($user->id)) { $this->userbill = $model->getbillDetails($user->id); } //Amol: $socialadshelper = new socialadshelper(); $this->adfieldsTableColumn = $socialadshelper->getTableColumns('ad_fields'); // vm: code end parent::display($tpl); }
function getSocialAds($data, $params, $adRetriever) { require JPATH_SITE . DS . "administrator" . DS . "components" . DS . "com_socialads" . DS . "config" . DS . "config.php"; require JPATH_SITE . DS . "components" . DS . "com_socialads" . DS . "defines.php"; $db = JFactory::getDBO(); $fuzzy_fields = array(); $getUserData = ''; $getUserData = $data; if (!empty($getUserData)) { $socialadshelper = new socialadshelper(); $paramlist = $socialadshelper->getTableColumns('ad_fields'); if (empty($paramlist)) { return array(); } //sort 'the exact & fuzzy part foreach ($getUserData as $values) { if (in_array($values->mapping_fieldname, $paramlist)) { if ($values->mapping_match == 0) { /*$fuzzy_fields[] = $values->mapping_fieldname; $fuzzy_data[] = $values->value;*/ if (strlen($values->value) > 4) { $where[] = "( MATCH ({$values->mapping_fieldname}) AGAINST (" . $db->quote($values->value) . " IN BOOLEAN MODE) OR b.{$values->mapping_fieldname} = '')"; } else { $where[] = " ( b.{$values->mapping_fieldname} = '{$values->value}' OR b.{$values->mapping_fieldname} = '' ) "; } } else { switch ($values->mapping_fieldtype) { // switch to add where conditions for field types case 'singleselect': case 'gender': case 'boolean': case 'multiselect': $where[] = "(b.{$values->mapping_fieldname} LIKE " . $db->Quote("%|{$values->value}|%") . " OR b.{$values->mapping_fieldname} = '')"; break; case 'textbox': $where[] = "(b.{$values->mapping_fieldname} LIKE " . $db->Quote("%|{$values->value}|%") . " OR b.{$values->mapping_fieldname} = '')"; break; case 'date': $where[] = "(b.{$values->mapping_fieldname} = " . $db->Quote($values->value) . " OR b.{$values->mapping_fieldname} = '')"; break; case 'daterange': case 'numericrange': $where[] = "(b.{$values->mapping_fieldname}_low <= {$db->Quote($values->value)} AND b.{$values->mapping_fieldname}_high >= \t{$db->Quote($values->value)})"; break; } } } } $where[] = " b.adfield_ad_id = a.ad_id"; /*if(count($fuzzy_fields)) //if there is any fuzzy targeted field { $field_names = implode(',', $fuzzy_fields); $valueswithqoutesinarray = array(); foreach ($fuzzy_data as $fuz_value) { $fuz_value = addslashes($fuz_value); $fuzzy_values[] = "'".htmlspecialchars($fuz_value)."'"; // TODO: Find an alternative for htmlspecialchars } $fuzzy_values = implode(' ', $fuzzy_values); $query_fuz = "MATCH ($field_names) AGAINST ( \"$fuzzy_values\" IN BOOLEAN MODE )"; }*/ /*if ($query_fuz) { //$query_fuz .= ' AS relevance '; $extra ="HAVING relevance >.2 ORDER BY relevance "; } else { $query_fuz = " a.ad_id as relevance "; $extra = "ORDER BY a.ad_id "; }*/ $extra = "ORDER BY a.ad_id "; if ($limit) { $extra .= " LIMIT {$limit}"; } $camp_join = $this->join_camp(); //camp_join if camp enabled in backend // Begin composing the query $query = "SELECT a.ad_id "; /*if ($query_fuz) { $query .= ', ' . $query_fuz . "\n"; }*/ $query .= " FROM " . ($getUserData ? " #__ad_fields as b ," : "") . " #__ad_data as a {$camp_join} \n"; $function_name = "adids"; $common_where = $this->query_common($params, $function_name, $adRetriever); //common query $common_where = implode(' AND ', $common_where); $where[] = !$this->_my->id ? " a.ad_guest = 1" : " a.ad_guest <> 1"; //Start Added by Sheetal if ($this->_my->id && $getUserData) { //added by aniket --to call only those plugin who has the entry in ad_fields table //add this query in separate function so that it can aslo be used while creating ad JPluginHelper::importPlugin('socialadstargeting'); $dispatcher = JDispatcher::getInstance(); $results = $dispatcher->trigger('OnAfterGetAds', array($paramlist)); //Call the plugin and get the result foreach ($results as $value) { foreach ($value as $val) { $where[] = " {$val}"; } } } //End Added by Sheetal $where = count($where) ? ' WHERE ' . implode("\n AND ", $where) : ''; //commpon where imploded... $where = $where . " AND " . $common_where; $query .= "\n " . $where . "\n " . $extra; $db->setQuery($query); $result = $db->loadObjectList(); //print_r($result); die('final'); $ads = $result; } //chk for $getUserData exists if (empty($result)) { return array(); } return $ads; }