/** * Controller */ public function process() { Phpfox::isUser(true); $sView = $this->request()->get('view'); $aCond = array(); switch ($sView) { case 'pending': $aCond[] = 'AND s.is_custom = 2'; // pending approval break; case 'payment': $aCond[] = 'AND s.is_custom = 0'; break; case 'denied': $aCond[] = 'AND s.is_custom = 4'; break; default: $aCond[] = 'AND s.is_custom = 3'; break; } $aCond[] = 'AND s.user_id = ' . Phpfox::getUserId(); Ad_Service_Ad::instance()->getSectionMenu(); $aAds = Ad_Service_Ad::instance()->getSponsorForUser($aCond); $this->template()->setTitle(Phpfox::getPhrase('ad.ad_management'))->setFullSite()->setBreadcrumb(Phpfox::getPhrase('ad.advertise'), $this->url()->makeUrl('ad'))->setBreadcrumb(Phpfox::getPhrase('ad.sponsorships'), $this->url()->makeUrl('ad.manage-sponsor'), true)->setHeader(array('table.css' => 'style_css', 'manage.js' => 'module_ad'))->assign(array('aAds' => $aAds, 'sView' => $sView)); }
/** * Controller */ public function process() { if ($iId = $this->request()->getInt('delete')) { if (Phpfox::getService('ad.process')->deleteInvoice($iId)) { $this->url()->send('admincp.ad.invoice', null, Phpfox::getPhrase('ad.invoice_successfully_deleted')); } } $iPage = $this->request()->getInt('page'); $aPages = array(5, 10, 15, 20); $aDisplays = array(); foreach ($aPages as $iPageCnt) { $aDisplays[$iPageCnt] = Phpfox::getPhrase('core.per_page', array('total' => $iPageCnt)); } $aSorts = array('time_stamp' => Phpfox::getPhrase('ad.recently_added')); $aFilters = array('status' => array('type' => 'select', 'options' => array('1' => Phpfox::getPhrase('ad.paid'), '2' => Phpfox::getPhrase('ad.pending_payment'), '3' => Phpfox::getPhrase('ad.cancelled')), 'add_any' => true), 'display' => array('type' => 'select', 'options' => $aDisplays, 'default' => '10'), 'sort' => array('type' => 'select', 'options' => $aSorts, 'default' => 'ad_id'), 'sort_by' => array('type' => 'select', 'options' => array('DESC' => Phpfox::getPhrase('core.descending'), 'ASC' => Phpfox::getPhrase('core.ascending')), 'default' => 'DESC')); $oSearch = Phpfox_Search::instance()->set(array('type' => 'invoices', 'filters' => $aFilters, 'search' => 'search')); $sStatus = $oSearch->get('status'); switch ($sStatus) { case '1': $oSearch->setCondition('ai.status = \'completed\''); break; case '2': $oSearch->setCondition('(ai.status = \'pending\' OR ' . Phpfox_Database::instance()->isNull('ai.status') . ')'); break; case '3': $oSearch->setCondition('ai.status = \'cancel\''); break; default: break; } $iLimit = $oSearch->getDisplay(); list($iCnt, $aInvoices) = Ad_Service_Ad::instance()->getInvoices($oSearch->getConditions(), $oSearch->getSort(), $oSearch->getPage(), $iLimit); $this->template()->setTitle(Phpfox::getPhrase('ad.ad_invoices'))->setBreadcrumb(Phpfox::getPhrase('ad.invoices'))->assign(array('aInvoices' => $aInvoices)); }
/** * Controller */ public function process() { if (($iDelete = $this->request()->getInt('delete')) && Phpfox::getService('ad.process')->deletePlacement($iDelete)) { $this->url()->send('admincp.ad.placement', null, Phpfox::getPhrase('ad.ad_placement_successfully_deleted')); } $this->template()->setTitle(Phpfox::getPhrase('ad.manage_ad_placements'))->setBreadcrumb(Phpfox::getPhrase('ad.manage_ad_placements'), $this->url()->makeUrl('ad.placement'))->setActionMenu(['New Placement' => ['url' => $this->url()->makeUrl('admincp.ad.placement.add'), 'class' => 'popup']])->assign(array('aPlacements' => Ad_Service_Ad::instance()->getPlacements())); }
/** * Controller */ public function process() { Phpfox::isUser(true); $sView = $this->request()->get('view'); $aCond = array(); switch ($sView) { case 'pending': $aCond[] = 'AND a.is_custom = 2'; break; case 'payment': $aCond[] = 'AND a.is_custom = 1'; break; case 'denied': $aCond[] = 'AND a.is_custom = 4'; break; default: $aCond[] = 'AND a.is_custom = 3'; break; } $aCond[] = 'AND a.user_id = ' . Phpfox::getUserId(); if (Phpfox::getParam('ad.multi_ad')) { $aCond[] = ' AND a.location = 50'; } $aAds = Ad_Service_Ad::instance()->getForUser($aCond); Ad_Service_Ad::instance()->getSectionMenu(); $this->template()->setTitle(Phpfox::getPhrase('ad.ad_management'))->setFullSite()->setBreadcrumb(Phpfox::getPhrase('ad.advertise'), $this->url()->makeUrl('ad'))->setBreadcrumb(Phpfox::getPhrase('ad.advertise'), $this->url()->makeUrl('ad.manage'), true)->setHeader(array('table.css' => 'style_css', 'manage.js' => 'module_ad'))->assign(array('aAllAds' => $aAds, 'sView' => $sView, 'bNewPurchase' => $this->request()->get('payment'))); }
/** * Controller */ public function process() { $bIsEdit = false; if (($iId = $this->request()->getInt('id')) && ($aPlacement = Ad_Service_Ad::instance()->getPlacement($iId))) { $bIsEdit = true; $this->setParam('currency_value_val[cost]', unserialize($aPlacement['cost'])); $this->template()->assign(array('aForms' => $aPlacement)); } if ($aVals = $this->request()->getArray('val')) { if ($bIsEdit) { if (Phpfox::getService('ad.process')->updatePlacement($aPlacement['plan_id'], $aVals)) { $this->url()->send('admincp.ad.placement.add', array('id' => $aPlacement['plan_id']), Phpfox::getPhrase('ad.ad_placement_successfully_updated')); } } else { if (Phpfox::getService('ad.process')->addPlacement($aVals)) { $this->url()->send('admincp.ad.placement', null, Phpfox::getPhrase('ad.ad_placement_successfully_added')); } } } $aPlans = Ad_Service_Ad::instance()->getPlans(true); $aCount = array(); for ($i = 1; $i <= 12; $i++) { if (isset($aPlans[$i])) { //continue; } $aCount[$i] = $i; } if ($bIsEdit) { $aCount[$aPlacement['block_id']] = $aPlacement['block_id']; } $this->template()->setTitle(Phpfox::getPhrase('ad.add_ad_placement'))->setBreadcrumb(Phpfox::getPhrase('ad.manage_placements'), $this->url()->makeUrl('admincp.ad.placement'))->setBreadcrumb($bIsEdit ? 'Edit Ad Placement' : 'New Placement', $this->url()->current(), true)->assign(array('bIsEdit' => $bIsEdit, 'aPlanBlocks' => $aCount)); }
/** * Controller */ public function process() { ($sPlugin = Phpfox_Plugin::get('ad.component_controller_admincp_process__start')) ? eval($sPlugin) : false; $iPage = $this->request()->getInt('page'); if ($iId = $this->request()->getInt('approve')) { if (Phpfox::getService('ad.process')->approve($iId)) { $this->url()->send('admincp.ad', null, Phpfox::getPhrase('ad.ad_successfully_approved')); } } if ($iId = $this->request()->getInt('deny')) { if (Phpfox::getService('ad.process')->deny($iId)) { $this->url()->send('admincp.ad', null, Phpfox::getPhrase('ad.ad_successfully_denied')); } } if ($iId = $this->request()->getInt('delete')) { if (Phpfox::getService('ad.process')->delete($iId)) { $this->url()->send('admincp.ad', null, Phpfox::getPhrase('ad.ad_successfully_deleted')); } } if ($aVals = $this->request()->getArray('val')) { if (Phpfox::getService('ad.process')->updateActivity($aVals)) { $this->url()->send('admincp.ad', null, Phpfox::getPhrase('ad.ad_s_successfully_updated')); } } $aPages = array(5, 10, 15, 20); $aDisplays = array(); foreach ($aPages as $iPageCnt) { $aDisplays[$iPageCnt] = Phpfox::getPhrase('core.per_page', array('total' => $iPageCnt)); } $aSorts = array('ad_id' => Phpfox::getPhrase('ad.recently_added')); $aFilters = array('status' => array('type' => 'select', 'options' => array('1' => Phpfox::getPhrase('ad.pending_approval'), '2' => Phpfox::getPhrase('ad.pending_payment'), '4' => Phpfox::getPhrase('ad.denied')), 'add_any' => true), 'display' => array('type' => 'select', 'options' => $aDisplays, 'default' => '10'), 'sort' => array('type' => 'select', 'options' => $aSorts, 'default' => 'ad_id'), 'sort_by' => array('type' => 'select', 'options' => array('DESC' => Phpfox::getPhrase('core.descending'), 'ASC' => Phpfox::getPhrase('core.ascending')), 'default' => 'DESC')); $oSearch = Phpfox_Search::instance()->set(array('type' => 'campaigns', 'filters' => $aFilters, 'search' => 'search')); $sStatus = $oSearch->get('status'); $sView = $this->request()->get('view'); $iLocation = $this->request()->getInt('location'); if ($sStatus == '1') { $oSearch->setCondition('is_custom = 2'); } elseif ($sStatus == '2') { $oSearch->setCondition('is_custom = 1'); } elseif ($sStatus == '4') { $oSearch->setCondition('is_custom = 4'); } else { switch ($sView) { case 'pending': $oSearch->setCondition('is_custom = 2'); break; default: // $oSearch->setCondition('is_custom IN(0,2,3)'); break; } } if ($iLocation > 0) { $oSearch->setCondition('AND location = ' . (int) $iLocation); } $iLimit = $oSearch->getDisplay(); list($iCnt, $aAds) = Ad_Service_Ad::instance()->get($oSearch->getConditions(), $oSearch->getSort(), $oSearch->getPage(), $iLimit); Phpfox_Pager::instance()->set(array('page' => $iPage, 'size' => $iLimit, 'count' => $oSearch->getSearchTotal($iCnt))); $this->template()->setTitle(Phpfox::getPhrase('ad.manage_ad_campaigns'))->setBreadcrumb(Phpfox::getPhrase('ad.manage_ad_campaigns'), $this->url()->makeUrl('admincp.ad'))->assign(array('aAds' => $aAds, 'iPendingCount' => (int) Ad_Service_Ad::instance()->getPendingCount(), 'sPendingLink' => Phpfox_Url::instance()->makeUrl('admincp.ad', array('view' => 'pending')), 'bIsSearch' => $this->request()->get('search-id') ? true : false, 'sView' => $sView)); ($sPlugin = Phpfox_Plugin::get('ad.component_controller_admincp_process__end')) ? eval($sPlugin) : false; }
/** * Controller */ public function process() { $aPlans = Ad_Service_Ad::instance()->getPlans(); //($this->getParam('block_id')); $iBlockId = $this->getParam('block_id'); foreach ($aPlans as $iKey => $aPlan) { if ($aPlan['is_active'] != 1 || $aPlan['block_id'] != $this->getParam('block_id')) { unset($aPlans[$iKey]); continue; } if (!empty($aPlan['cost']) && Phpfox::getLib('parse.format')->isSerialized($aPlan['cost'])) { $aCosts = unserialize($aPlan['cost']); $iLastCost = 0; $iLastCurrency = null; foreach ($aCosts as $sKey => $iCost) { if (strtolower(Phpfox::getService('core.currency')->getDefault()) == strtolower($sKey)) { $aPlans[$iKey]['default_cost'] = $aPlan['default_cost'] = $iCost; $aPlans[$iKey]['default_currency_id'] = $aPlan['default_curency'] = $sKey; } } } $aPlan = array('block_id' => $iBlockId, 'default_cost' => $aPlan['default_cost'], 'd_width' => $aPlan['d_width'], 'd_height' => $aPlan['d_height'], 'is_cpm' => $aPlan['is_cpm'], 'plan_id' => $aPlan['plan_id']); $aPlans[$iKey]['sSizes'] = '<a href="#" onclick="window.parent.$Core.Ad.setPlan(' . $this->getParam('block_id') . ', ' . $aPlan['plan_id'] . ',' . $aPlan['default_cost'] . ',' . $aPlan['d_width'] . ',' . $aPlan['d_height'] . ',' . $aPlan['is_cpm'] . ');">' . $aPlan['d_width'] . 'x' . $aPlan['d_height'] . '</a>'; //$(\'#location\').val(' . $iBlockId . '); window.parent.$Core.Ad.oPlan.default_cost = ' . $aPlan['default_cost'] .';window.parent.$Core.Ad.blockPlacementCallback(\'' . $aPlan['d_width'] . '\', \'' . $aPlan['d_height'] . '\',\'' . $iBlockId . '\',\''. $aPlan['is_cpm'].'\'); window.parent.tb_remove(); } if (empty($aPlans)) { return false; } $this->template()->assign(array('aPlans' => $aPlans, 'sBlockLocation' => $this->getParam('block_id'))); }
/** * Handles API callback for payment gateways. * * @param array $aParams ARRAY of params passed from the payment gateway after a payment has been made. * @return bool|null FALSE if payment is not valid|Nothing returned if everything went well. */ public function paymentApiCallback($aParams) { Phpfox::log('Module callback recieved: ' . var_export($aParams, true)); Phpfox::log('Attempting to retrieve purchase from the database'); define('PHPFOX_API_CALLBACK', true); // used to override security checks in the processes if (preg_match('/sponsor/i', $aParams['item_number'])) { // we get the sponsored ad $iId = preg_replace("/[^0-9]/", '', $aParams['item_number']); Phpfox::log('Ad is sponsored'); $aInvoice = $this->database()->select('*')->from(Phpfox::getT('ad_invoice'))->where('invoice_id = ' . $iId . ' AND is_sponsor = 1')->execute('getSlaveRow'); $aAd = Ad_Service_Ad::instance()->getSponsor($aInvoice['ad_id']); } else { $aAd = Ad_Service_Ad::instance()->getForEdit($aParams['item_number']); $aInvoice = Ad_Service_Ad::instance()->getInvoice($aAd['ad_id']); } if (empty($aAd) || $aAd === false) { Phpfox::log('Purchase is not valid'); return false; } if (empty($aInvoice) || $aInvoice === false) { Phpfox::log('Not a valid invoice'); return false; } Phpfox::log('Purchase is valid: ' . var_export($aInvoice, true)); if ($aParams['status'] == 'completed') { if ($aParams['total_paid'] == $aInvoice['price']) { Phpfox::log('Paid correct price'); } else { Phpfox::log('Paid incorrect price'); return false; } } else { Phpfox::log('Payment is not marked as "completed".'); return false; } Phpfox::log('Handling purchase'); $this->database()->update(Phpfox::getT('ad_invoice'), array('status' => $aParams['status'], 'time_stamp_paid' => PHPFOX_TIME), 'invoice_id = ' . $aInvoice['invoice_id']); if (isset($aAd['auto_publish'])) { // its a sponsor ad $this->database()->update(Phpfox::getT('ad_sponsor'), array('is_custom' => $aAd['auto_publish'] == 1 ? '3' : '2', 'is_active' => $aAd['auto_publish'] == 1 ? '1' : '0'), 'sponsor_id = ' . $aAd['sponsor_id']); if ($aAd['auto_publish'] == 1) { $sModule = $aAd['module_id']; $sSection = ''; if (strpos($sModule, '-') !== false) { $aModule = explode('-', $sModule); $sModule = $aModule[0]; $sSection = $aModule[1]; } Phpfox::callback($sModule . '.enableSponsor', array('item_id' => $aAd['item_id'], 'section' => $sSection)); } } else { $this->database()->update(Phpfox::getT('ad'), array('is_custom' => '2'), 'ad_id = ' . $aAd['ad_id']); } $this->cache()->remove('ad', 'substr'); Phpfox::log('Handling complete'); }
/** * Controller */ public function process() { Phpfox::isUser(true); if (($sId = $this->request()->get('item_number')) != '') { define('PHPFOX_SKIP_POST_PROTECTION', true); $this->url()->send('ad.invoice', null, 'Payment Completed'); } $aCond = array(); $aCond[] = 'ai.user_id = ' . Phpfox::getUserId(); list($iCnt, $aInvoices) = Ad_Service_Ad::instance()->getInvoices($aCond); Ad_Service_Ad::instance()->getSectionMenu(); $this->template()->setTitle(Phpfox::getPhrase('ad.ad_invoices'))->setFullSite()->setBreadcrumb(Phpfox::getPhrase('ad.advertise'), $this->url()->makeUrl('ad'))->setBreadcrumb(Phpfox::getPhrase('ad.invoices'), $this->url()->makeUrl('ad.invoice'), true)->setHeader('cache', array('table.css' => 'style_css'))->assign(array('aInvoices' => $aInvoices)); }
/** * Controller */ public function process() { ($sPlugin = Phpfox_Plugin::get('ad.component_controller_process__start')) ? eval($sPlugin) : false; if ($iAd = $this->request()->getInt('id')) { if ($sUrl = Ad_Service_Ad::instance()->getAdRedirect($iAd)) { $this->url()->forward($sUrl); } } $this->url()->send('ad.manage'); Ad_Service_Ad::instance()->getSectionMenu(); $this->template()->setTitle(Phpfox::getPhrase('ad.advertise'))->setBreadcrumb(Phpfox::getPhrase('ad.advertise'), $this->url()->makeUrl('ad'))->assign(array()); ($sPlugin = Phpfox_Plugin::get('ad.component_controller_process__start')) ? eval($sPlugin) : false; }
public function loadProfileBlock() { exit; $sProfileUrl = str_replace('profile_', '', $this->get('url')); if ($this->get('url') == 'profile_info') { $sProfileUrl = 'profile'; } if (!Phpfox::isModule($sProfileUrl)) { Phpfox_Error::set('Trying to load an invalid module.'); } else { if (!Phpfox::hasCallback($sProfileUrl, 'getAjaxProfileController')) { Phpfox_Error::set('Unable to load the section you are looking for.'); } } if (Phpfox_Error::isPassed()) { $oModule = Phpfox_Module::instance(); $oTpl = Phpfox_Template::instance(); $oTpl->assign(array('bIsAjaxLoader' => true)); $aStyleInUse = $oTpl->getStyleInUse(); $oModule->loadBlocks(); $aUrlParams = array($this->get('user_name')); if ($this->get('url') != 'profile') { $aUrlParams[] = str_replace('profile_', '', $this->get('url')); } Phpfox_Url::instance()->setParam($aUrlParams); $oModule->setController(Phpfox::callback($sProfileUrl . '.getAjaxProfileController')); if ($aStyleInUse['total_column'] == '3') { $oTpl->assign(array('aBlocks1' => $oTpl->bIsSample ? true : Phpfox_Module::instance()->getModuleBlocks(1), 'aBlocks3' => $oTpl->bIsSample ? true : Phpfox_Module::instance()->getModuleBlocks(3), 'aAdBlocks1' => $oTpl->bIsSample ? true : (Phpfox::isModule('ad') ? Ad_Service_Ad::instance()->getForBlock(1) : null), 'aAdBlocks3' => $oTpl->bIsSample ? true : (Phpfox::isModule('ad') ? Ad_Service_Ad::instance()->getForBlock(3) : null))); } else { $oTpl->assign(array('aBlocks1' => array(), 'aBlocks3' => array(), 'aAdBlocks1' => array(), 'aAdBlocks3' => array())); } $oTpl->assign(array('sPublicMessage' => Phpfox::getMessage(), 'aErrors' => Phpfox_Error::getDisplay() ? Phpfox_Error::get() : array(), 'aStyleInUse' => $aStyleInUse)); list($aBreadCrumbs, $aBreadCrumbTitle) = $oTpl->getBreadCrumb(); $this->remove('#js_temp_breadcrumb'); if (count($aBreadCrumbs)) { foreach ($aBreadCrumbs as $sLink => $sPhrase) { $this->append('h1', '<span id="js_temp_breadcrumb"><span class="profile_breadcrumb">»</span><a href="' . $sLink . '">' . $sPhrase . '</a></span>'); break; } } $oTpl->getLayout($oTpl->sDisplayLayout); $this->html($aStyleInUse['total_column'] == '3' ? '#content_load_data' : '#content', $this->getContent(false)); if ($this->get('url') == 'profile_info') { $this->call('$Core.loadProfileInfo();'); } } else { $this->html('#js_profile_block_view_data_' . $this->get('url'), implode('', Phpfox_Error::get())); } $this->call('$Core.loadInit();'); }
public function recalculate() { if ((int) $this->get('total') < 1000 && $this->get('isCPM')) { $this->alert(Phpfox::getPhrase('ad.there_is_minimum_of_1000_impressions')); } else { $iBlockId = $this->get('block_id'); // http://www.phpfox.com/tracker/view/15439/ // solves conflict with http://www.phpfox.com/tracker/view/14192/ if ($aPlan = Ad_Service_Ad::instance()->getPlan($iBlockId, $iBlockId == 50 ? true : false)) { $iTotal = $this->get('isCPM') ? $this->get('total') / 1000 * $aPlan['default_cost'] : $this->get('total') * $aPlan['default_cost']; $this->html('#js_ad_cost', Phpfox::getService('core.currency')->getCurrency($iTotal))->hide('#js_ad_cost_recalculate')->show('#js_ad_cost'); } } }
/** * Controller * This block shows an ad inside another block */ public function process() { ($sPlugin = Phpfox_Plugin::get('ad.component_block_inner_process__start')) ? eval($sPlugin) : false; if (!Phpfox::getParam('ad.enable_ads')) { return false; } if ($this->getParam('sClass', '') == '') { return false; } $aAd = Ad_Service_Ad::instance()->getForLocation($this->getParam('sClass')); if (!is_array($aAd)) { return false; } if (is_array($aAd) && empty($aAd)) { return false; } $this->template()->assign(array('aAd' => $aAd)); ($sPlugin = Phpfox_Plugin::get('ad.component_block_inner_process__end')) ? eval($sPlugin) : false; }
/** * Add a custom ad, which are created by the end-users. * * @param array $aVals ARRAY of $_POST form values. * @return bool|int FALSE if ad was not created.|Ad ID# if ad was successfully created. */ public function addCustom($aVals) { Phpfox::isUser(true); if ((int) $aVals['total_view'] < 1000 && $aVals['is_cpm']) { return Phpfox_Error::set(Phpfox::getPhrase('ad.there_is_minimum_of_1000_impressions')); } if (Phpfox::getParam('ad.multi_ad')) { $aVals['type_id'] == 2; } // total_click does not exist at this point because it is one single input for the user. $fPrice = $aVals['is_cpm'] ? $aVals['default_cost'] * $aVals['total_view'] / 1000 : $aVals['default_cost'] * $aVals['total_view']; if (isset($aVals['country_iso_custom']) && is_array($aVals['country_iso_custom']) && !empty($aVals['country_iso_custom'])) { foreach ($aVals['country_iso_custom'] as $iKey => $sCountry) { if (empty($sCountry)) { unset($aVals['country_iso_custom'][$iKey]); } } if (count($aVals['country_iso_custom']) == 1) { $aVals['country_iso'] = reset($aVals['country_iso_custom']); } else { $aVals['country_iso'] = null; } } $aSize = explode('x', $aVals['ad_size']); if ($aVals['type_id'] == '1') { $aImage = Phpfox_File::instance()->load('image', array('jpg', 'gif', 'png')); if ($aImage === false) { return false; } list($iWidth, $iHeight) = getimagesize($aImage['tmp_name']); if ($iWidth > $aSize[0] || $iHeight > $aSize[1]) { return Phpfox_Error::set(Phpfox::getPhrase('ad.the_file_dimensions_are_too_big')); } } $iStartTime = Phpfox::getLib('date')->convertToGmt(Phpfox::getLib('date')->mktime($aVals['start_hour'], $aVals['start_minute'], 0, $aVals['start_month'], $aVals['start_day'], $aVals['start_year'])); /* * The field is_custom tells the state of the ad as follows: 1: Pending Payment 2: Pending Approval 3: Approved? 4: Denied */ $aInsert = array('is_custom' => $fPrice == 0 ? '3' : '1', 'user_id' => Phpfox::getUserId(), 'type_id' => $aVals['type_id'], 'name' => $this->preParse()->clean($aVals['name']), 'url_link' => $aVals['url_link'], 'start_date' => $iStartTime, 'end_date' => 0, 'total_view' => isset($aVals['total_view']) ? (int) $aVals['total_view'] : 0, 'total_click' => (int) $aVals['is_cpm'] == 1 ? '0' : (isset($aVals['total_view']) ? (int) $aVals['total_view'] : 0), 'is_active' => $fPrice == 0 ? '1' : '0', 'location' => $aVals['location'], 'country_iso' => empty($aVals['country_iso']) ? null : $aVals['country_iso'], 'gender' => empty($aVals['gender']) ? 0 : (int) $aVals['gender'], 'age_from' => empty($aVals['age_from']) ? 0 : (int) $aVals['age_from'], 'age_to' => empty($aVals['age_from']) ? 0 : (int) $aVals['age_to'], 'gmt_offset' => $iStartTime > 0 ? Phpfox::getLib('date')->getGmtOffset($iStartTime) : null, 'image_path' => $aVals['image_path'], 'server_id' => Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID'), 'is_cpm' => (int) $aVals['is_cpm']); //if ($sPlugin = Phpfox_Plugin::get('ad.service_process_addcustom_before_insert_ad')){eval($sPlugin);} if (Phpfox::getParam('ad.advanced_ad_filters')) { $oParse = Phpfox::getLib('parse.input'); $aInsert['postal_code'] = explode(',', $oParse->clean($aVals['postal_code'])); $aInsert['postal_code'] = json_encode($aInsert['postal_code']); $aInsert['city_location'] = explode(',', $oParse->clean($aVals['city_location'])); $aInsert['city_location'] = json_encode($aInsert['city_location']); } $aVals['html_code'] = str_replace(Phpfox::getPhrase('ad.image_placement'), '', $aVals['html_code'], $iCount); if (Phpfox::getParam('ad.multi_ad') && isset($aVals['body_text']) && !empty($aVals['body_text']) && isset($aVals['title']) && !empty($aVals['title'])) { $aInsert['html_code'] = json_encode(array('body' => Phpfox::getLib('parse.input')->clean($aVals['body_text']), 'title' => Phpfox::getLib('parse.input')->clean($aVals['title']))); } $iId = $this->database()->insert(Phpfox::getT('ad'), $aInsert); // Insert countries $this->_adCountries($aVals, $iId); if ($aVals['type_id'] == '1') { if ($sFileName = Phpfox_File::instance()->upload('image', Phpfox::getParam('ad.dir_image'), $iId)) { $this->database()->update($this->_sTable, array('image_path' => $sFileName, 'server_id' => Phpfox_Request::instance()->getServer('PHPFOX_SERVER_ID')), 'ad_id = ' . (int) $iId); } } else { if (Phpfox::getParam('ad.multi_ad') != true) { /* $aVals['html_code'] = '<div style="width:' . $aSize[0] . 'px; height:' . $aSize[1] . 'px; background:#' . $aVals['color_bg'] . '; border:1px #' . $aVals['color_border'] . ' solid;">' . $aVals['html_code'] . '</div>'; if (preg_match('/js_image_place_holder/i', $aVals['html_code'])) { $aVals['html_code'] = preg_replace('/<div class=\"js_ad_image\"(.*?)>(.*?)<\/div>/is', '', $aVals['html_code']); $aVals['html_code'] = str_replace('margin-left: 130px;', '', $aVals['html_code']); $aVals['html_code'] = str_replace('margin-left:130px;', '', $aVals['html_code']); } */ $aVals['html_code'] = str_replace('#ad-link"', Phpfox_Url::instance()->makeUrl('ad', array('id' => $iId)) . '" target="_blank"', $aVals['html_code']); $aVals['html_code'] = preg_replace('/id="js_sample_ad_form_(.*)_(.*)" class="js_ad_holder"/i', '', $aVals['html_code']); $this->database()->update(Phpfox::getT('ad'), array('html_code' => $aVals['html_code']), 'ad_id = ' . (int) $iId); } } //if ($sPlugin = Phpfox_Plugin::get('ad.service_process_addcustom_before_insert_invoice')){eval($sPlugin);} $aPlan = Ad_Service_Ad::instance()->getPlan($aVals['location'], true); $this->database()->insert(Phpfox::getT('ad_invoice'), array('ad_id' => $iId, 'user_id' => Phpfox::getUserId(), 'currency_id' => $aPlan['default_currency_id'], 'price' => $fPrice, 'time_stamp' => PHPFOX_TIME, 'time_stamp_paid' => $fPrice == 0 ? PHPFOX_TIME : '0', 'is_sponsor' => 0)); $this->cache()->remove('ad', 'substr'); return $iId; }
/** * Controller */ public function process() { ($sPlugin = Phpfox_Plugin::get('ad.component_block_display_process__start')) ? eval($sPlugin) : false; if (!Phpfox::getParam('ad.enable_ads')) { return false; } /* if (Phpfox::getParam('ad.multi_ad') && $this->getParam('block_id') != 3 && $this->getParam('block_id') != 50 && $this->getParam('bIsIframe') != true) { return false; } */ $this->setParam('block_id', 50); /* if ($this->getParam('bIsIframe') == true && Phpfox::getParam('ad.multi_ad') == true) { $this->setParam('block_id', 50); } */ if (Phpfox::getParam('ad.multi_ad') != true && $this->getParam('adId') !== null && is_numeric($this->getParam('adId')) && $this->getParam('adId') > 0) { $aAds = Ad_Service_Ad::instance()->get(array('ad_id = ' . (int) $this->getParam('adId'))); } else { $aAds = Ad_Service_Ad::instance()->getForBlock($this->getParam('block_id'), true); } if (!is_array($aAds)) { $aAds = array(); } if ($this->getParam('bIsIframe') === true && is_array($aAds) && count($aAds) > 1) { // http://www.phpfox.com/tracker/view/14740/ foreach ($aAds as $iKey => $aAd) { if (!is_array($aAd)) { unset($aAds[$iKey]); } } $aAds = $aAds[array_rand($aAds)]; } if (!is_array($aAds)) { $aAds = array(); } foreach ($aAds as $iKey => $aAd) { if (!is_array($aAd)) { $aAds = array($aAds); break; } } $bBlockIdForAds = false; foreach ($aAds as $iKey => $aAd) { if (!empty($aAd['disallow_controller'])) { $sControllerName = Phpfox_Module::instance()->getFullControllerName(); $aParts = explode(',', $aAd['disallow_controller']); foreach ($aParts as $sPart) { $sPart = trim($sPart); // str_replace for marketplace.invoice/index // str_replace for music.browse/album if ($sControllerName == $sPart || str_replace('/index', '', $sControllerName) == $sPart || str_replace('/', '.', $sControllerName) == $sPart) { unset($aAds[$iKey]); //return false; } } } if (!empty($aAd[$iKey]['html_code'])) { $aAds[$iKey]['html_code'] = str_replace('target="_blank"', 'target="_blank" class="no_ajax_link"', $aAd['html_code']); } if (PHPFOX_IS_AJAX && $this->getParam('block_id') == 'photo_theater' && ($aGetRequest = $this->request()->get('core')) && isset($aGetRequest['call']) && $aGetRequest['call'] == 'photo.view') { $bBlockIdForAds = true; } if ($aAd['is_active'] != 1) { unset($aAds[$iKey]); } } if (!count($aAds)) { return false; } $iBlockId = Phpfox::getParam('ad.multi_ad') ? 50 : $this->getParam('block_id'); $this->template()->assign(array('aBlockAds' => $aAds, 'bBlockIdForAds' => $bBlockIdForAds, 'iBlockId' => $iBlockId)); if (Phpfox::getParam('ad.multi_ad')) { if (!$this->getParam('bNoTitle')) { $this->template()->assign('sHeader', Phpfox::getPhrase('ad.sponsored')); $this->template()->assign(['aFooter' => ['Create an Ad' => $this->url()->makeUrl('ad.add')]]); } return 'block'; } ($sPlugin = Phpfox_Plugin::get('ad.component_block_display_process__end')) ? eval($sPlugin) : false; }
public function getRandomSponsored() { $sCacheId = $this->cache()->set('photo_sponsored'); if (!($aPhotos = $this->cache()->get($sCacheId))) { $aPhotos = $this->database()->select('s.*, pi.width, pi.height, u.user_name, p.total_view, p.time_stamp, pi.file_size, p.photo_id, p.destination, p.server_id, p.title, p.album_id, p.total_view')->from($this->_sTable, 'p')->join(Phpfox::getT('user'), 'u', 'u.user_id = p.user_id')->join(Phpfox::getT('photo_info'), 'pi', 'pi.photo_id = p.photo_id')->join(Phpfox::getT('ad_sponsor'), 's', 's.item_id = p.photo_id')->leftJoin(Phpfox::getT('photo_album'), 'pa', 'pa.album_id = p.album_id')->where('p.view_id = 0 AND p.group_id = 0 AND p.privacy = 0 AND p.is_sponsor = 1 AND s.module_id = "photo"')->execute('getRows'); $this->cache()->save($sCacheId, $aPhotos); } if (Phpfox::isModule('ad')) { $aPhotos = Ad_Service_Ad::instance()->filterSponsor($aPhotos); } if ($aPhotos === true || is_array($aPhotos) && !count($aPhotos)) { return false; } // Randomize to get a photo return $aPhotos[mt_rand(0, count($aPhotos) - 1)]; }
/** * Controller */ public function process() { ($sPlugin = Phpfox_Plugin::get('ad.component_controller_admincp_add_process__start')) ? eval($sPlugin) : false; $bIsEdit = false; $aVals = $this->request()->getArray('val'); $aAllCountries = Phpfox::getService('core.country')->getCountriesAndChildren(); $this->template()->setHeader(array('add.js' => 'module_ad', '<script type="text/javascript">$Behavior.loadAdJs = function() { $Core.Ad.isEdit = true; $Core.Ad.setCountries(\'' . json_encode($aAllCountries) . '\'); }</script>'))->assign(array('aAllCountries' => $aAllCountries)); if ($iId = $this->request()->getInt('id')) { if ($aAd = Ad_Service_Ad::instance()->getForEdit($iId)) { $bIsEdit = true; if ($aAd['location'] == 50) { $aCustomAd = json_decode($aAd['html_code'], true); $aAd['c_ad_title'] = $aCustomAd['title']; $aAd['c_ad_body'] = $aCustomAd['body']; } $this->template()->assign('aForms', $aAd); $this->template()->assign('aAccess', $aAd['user_group']); if (isset($aAd['countries_list']) && !empty($aAd['countries_list'])) { $sCountries = implode('_', $aAd['countries_list']); $aProvinces = array(); if (isset($aAd['province']) && !empty($aAd['province'])) { foreach ($aAd['province'] as $sProvince) { $aProvinces[$sProvince] = true; } } $this->template()->setHeader(array('<script type="text/javascript"> $Behavior.toggleSelected = function(){$Core.Ad.toggleSelectedCountries("' . $sCountries . '");$Core.Ad.toggleSelectedProvinces(' . json_encode($aProvinces) . ');}; </script>')); } else { $this->template()->setHeader(array('<script type="text/javascript"> $Behavior.toggleSelectedCountries = function(){ $("#country_iso option:eq(0)").attr("selected", "selected"); }; </script>')); } } } $aValidation = array('type_id' => array('title' => Phpfox::getPhrase('ad.select_a_banner_type'), 'def' => 'int'), 'name' => Phpfox::getPhrase('ad.provide_a_name_for_this_campaign')); if (is_array($aVals) && count($aVals) > 0) { if (isset($aVals['type_id'])) { if ($aVals['type_id'] == 1) { $aValidation['url_link'] = Phpfox::getPhrase('ad.provide_a_link_for_your_banner'); } } } $oValidator = Phpfox_Validator::instance()->set(array('sFormName' => 'js_form', 'aParams' => $aValidation)); if (is_array($aVals) && count($aVals) > 0) { if ($aVals['type_id'] == 2 && empty($aVals['html_code'])) { Phpfox_Error::set(Phpfox::getPhrase('ad.provide_html_for_your_banner')); } if ($oValidator->isValid($aVals)) { if ($bIsEdit) { if (Ad_Service_Process::instance()->update($aAd['ad_id'], $aVals)) { $this->url()->send('admincp.ad.add', array('id' => $aAd['ad_id']), Phpfox::getPhrase('ad.ad_successfully_updated')); } } else { if (Phpfox::getService('ad.process')->add($aVals)) { $this->url()->send('admincp.ad.add', null, Phpfox::getPhrase('ad.ad_successfully_added')); } } } if (isset($aVals['user_group'])) { $this->template()->assign('aAccess', $aVals['user_group']); } $this->template()->assign('aForms', $aVals); } $aAge = array(); $iAgeEnd = date('Y') - Phpfox::getParam('user.date_of_birth_start'); $iAgeStart = date('Y') - Phpfox::getParam('user.date_of_birth_end'); for ($iAgeStart; $iAgeStart <= $iAgeEnd; $iAgeStart++) { $aAge[$iAgeStart] = $iAgeStart; } $this->template()->setTitle(Phpfox::getPhrase('ad.create_new_campaign'))->setBreadcrumb(Phpfox::getPhrase('ad.create_new_campaign'))->setPhrase(array('ad.min_age_cannot_be_higher_than_max_age'))->setHeader('cache', array('ad.js' => 'module_ad'))->assign(array('aUserGroups' => Phpfox::getService('user.group')->get(), 'aAge' => $aAge, 'bIsEdit' => $bIsEdit, 'sCreateJs' => $oValidator->createJS(), 'sGetJsForm' => $oValidator->getJsForm(), 'aComponents' => Phpfox::getService('admincp.component')->get())); ($sPlugin = Phpfox_Plugin::get('ad.component_controller_admincp_add_process__end')) ? eval($sPlugin) : false; }
/** * Controller * when getInt(view) it updates the click count for the item, redirects right after * when getInt(module) and getInt(id) it shows the Create Sponsor Ad * when getInt(add) the user is reviewing a campagin -> dont show the submit * when getInt(pay) the user is shown the payment options and nothing else */ public function process() { // Updating clicks and redirecting. No page is shown because its a redirect if (($iView = $this->request()->getInt('view')) != 0) { $aUrl = Ad_Service_Ad::instance()->getSponsor($iView); // split the module if theres a subsection $sModule = $aUrl['module_id']; $sSection = ''; if (strpos($aUrl['module_id'], '-') !== false) { $aModule = explode('-', $aUrl['module_id']); $sModule = $aModule[0]; $sSection = $aModule[1]; } if (Phpfox::isModule($sModule)) { $sLink = Phpfox::callback($sModule . '.getLink', array('item_id' => $aUrl['item_id'], 'section' => $sSection)); // Update the counter of views (do we need the track table here?) // do not log clicks if its an Admin or the creator of the sponsor ad if (!Phpfox::isAdmin()) { Phpfox_Database::instance()->update(Phpfox::getT('ad_sponsor'), array('total_click' => $aUrl['total_click'] + 1), 'sponsor_id = ' . $aUrl['sponsor_id'] . ' AND user_id != ' . Phpfox::getUserId()); } $this->url()->send($sLink); } } // Check its a user Phpfox::isUser(true); // define default values $sModule = $this->request()->get('section'); $sFunction = 'getToSponsorInfo'; $sStatus = $this->request()->get('status'); $iSponsorId = $this->request()->get('req3'); $aAge = array(); $iAgeDiff = date('Y') - Phpfox::getParam('user.date_of_birth_start'); for ($i = 0; $i <= Phpfox::getParam('user.date_of_birth_end') - Phpfox::getParam('user.date_of_birth_start'); $i++) { $aAge[Phpfox::getParam('user.date_of_birth_end') + $i] = $iAgeDiff - $i; } asort($aAge); // is the user trying to view a campaign? if ($iId = $this->request()->get('add')) { $aVals = Ad_Service_Ad::instance()->getSponsor($iId); $sModule = $aVals['module_id']; $iSponsorId = $iId; $this->template()->assign(array('isView' => true)); } // final fixing if (strpos($sModule, '-') !== false) { $aModule = explode('-', $sModule); $sModule = $aModule[0]; $sFunction = 'getToSponsor' . ucwords($aModule[1]) . 'Info'; } // Sponsoring posts in the feed $aVals = $this->request()->getArray('val'); if ($this->request()->get('where') == 'feed') { // http://www.phpfox.com/tracker/view/15061/ $this->template()->assign(array('sFormerModule' => $this->request()->get('section'))); // get "feed" item_id instead of original "module name" item_id $aNewItemId = Feed_Service_Feed::instance()->getForItem($this->request()->get('section'), $this->request()->getInt('item')); if (!empty($aNewItemId)) { // correct "feed" item_id $aVals['item_id'] = $aNewItemId['feed_id']; } $aVals['module'] = 'feed'; // assign feed as module instead of original // Can sponsor without paying? (note that param is not plural) if (Phpfox::getUserParam('feed.can_sponsor_feed')) { // Payment completed: no payment required $sStatus = 'completed'; // Flag for template to skip payment form $this->template()->assign(array('bWithoutPay' => true)); // add the sponsor $iSponsorId = Phpfox::getService('ad.process')->addSponsor($aVals); } // END $sFunction = 'getSponsorPostInfo'; $sModule = 'feed'; // Easier to get all from one single module $iSponsorId = array('iItemId' => $this->request()->getInt('item'), 'sModule' => $this->request()->get('section')); } if (Phpfox::hasCallback($sModule, $sFunction)) { $aItem = Phpfox::callback($sModule . '.' . $sFunction, $iSponsorId); if (empty($aItem)) { return Phpfox_Error::display(Phpfox::getPhrase('core.module_is_not_a_valid_module', array('module' => $sModule))); } /* aItem must be in the format: * array( * 'title' => 'item title', <-- required * 'link' => 'makeUrl()'ed link', <-- required * 'paypal_msg' => 'message for paypal' <-- required * 'item_id' => int <-- required * 'user_id' => owner's user id <-- required * 'error' => 'phrase if item doesnt exit' <-- optional * 'extra' => 'description' <-- optional * 'image' => 'path to an image', <-- optional * 'image_dir' => 'photo.url_photo|... <-- optional (required if image) * ) */ if (isset($aItem['error']) && !empty($aItem['error'])) { return Phpfox_Error::display($aItem['error']); } // check that the user viewing is either the owner of the item or an admin if ($aItem['user_id'] != Phpfox::getUserId() && !Phpfox::isAdmin()) { return Phpfox_Error::display(Phpfox::getPhrase('ad.sponsor_error_owner')); } $aPrices = Phpfox::getUserParam($sModule . '.' . $sModule . (isset($aModule[1]) ? '_' . $aModule[1] : '') . '_sponsor_price'); if (Phpfox::getLib('parse.format')->isSerialized($aPrices)) { $aPrices = unserialize($aPrices); if (!isset($aPrices[Phpfox::getService('core.currency')->getDefault()])) { return Phpfox_Error::display(Phpfox::getPhrase('ad.the_default_currency_has_no_price')); } $aItem['default_cost'] = $aPrices[Phpfox::getService('core.currency')->getDefault()]; $aItem['ad_cost'] = $aItem['default_cost']; } else { return Phpfox_Error::display(Phpfox::getPhrase('ad.the_currency_for_your_membership_has_no_price')); } if (!isset($aItem['title'])) { return Phpfox_Error::display($aItem['error']); } $aItem['name'] = $aItem['title']; if (isset($aVals) && !empty($aVals)) { $aItem = array_merge($aItem, $aVals); $aItem['default_cost'] = isset($aItem['cpm']) ? $aItem['cpm'] : $aItem['ad_cost']; } if (($sWhere = $this->request()->get('where')) != '') { $aItem['where'] = $sWhere; } if (($iItemId = $this->request()->get('item')) != '') { $aItem['item_id'] = $iItemId; } $this->template()->assign(array('aForms' => $aItem)); } elseif ($this->request()->get('add', '') == '' && $this->request()->get('pay', '') == '') { return Phpfox_Error::display(Phpfox::getPhrase('core.module_is_not_a_valid_module', array('module' => $sModule))); } $this->template()->assign(array('aAge' => $aAge)); $iSponsorId = $this->request()->getInt('pay'); // defaults to 0 if (($aVals = $this->request()->getArray('val')) || $iSponsorId > 0) { if ($iSponsorId > 0) { $aVals = Ad_Service_Ad::instance()->getSponsor($iSponsorId, Phpfox::getUserId()); $fTotalCost = $aVals['price']; $aVals['name'] = $aVals['campaign_name']; $aItem = array('item_id' => $aVals['item_id'], 'paypal_msg' => $aVals['paypal_msg']); } if (!isset($aVals['total_view']) || $aVals['total_view'] != 0 && $aVals['total_view'] < 1000) { Phpfox_Error::set(Phpfox::getPhrase('ad.impressions_cant_be_less_than_a_thousand')); } if (!isset($aVals['name']) || empty($aVals['name'])) { Phpfox_Error::set(Phpfox::getPhrase('ad.provide_a_campaign_name')); } if (!isset($fTotalCost)) { $fTotalCost = round($aVals['total_view'] * $aItem['default_cost'] / 1000 * 100) / 100; } if (Phpfox_Error::isPassed()) { // validator $aVals['module'] = $sModule; if (isset($aModule[1])) { $aVals['section'] = $aModule[1]; } $aVals['item_id'] = $aItem['item_id']; if ($iSponsorId < 1) { // http://www.phpfox.com/tracker/view/15061/ // if sponsor in feeds if ($this->request()->get('where') == 'feed') { // get "feed" item_id instead of original "module name" item_id if (!empty($aNewItemId)) { // correct "feed" item_id $aVals['item_id'] = $aNewItemId['feed_id']; } } //END $iSponsorId = Phpfox::getService('ad.process')->addSponsor($aVals); } $this->template()->assign(array('iInvoice' => $iSponsorId)); $this->setParam('gateway_data', array('item_number' => 'ad|' . $iSponsorId . '-sponsor', 'currency_code' => Phpfox::getService('core.currency')->getDefault(), 'amount' => $fTotalCost, 'item_name' => $aItem['paypal_msg'], 'return' => $this->url()->makeUrl('ad.invoice'), 'recurring' => 0, 'recurring_cost' => '', 'alternative_cost' => 0, 'alternative_recurring_cost' => 0)); } } elseif ($this->request()->get('status') == '') { $this->template()->setHeader(array('sponsor.js' => 'module_ad', '<script type="text/javascript">$Behavior.loadSponsorInfo = function(){$Core.Ad.setPrice(' . $aItem['default_cost'] . ');}</script>')); } $iId = $this->request()->get('req3'); if (empty($iId)) { $iId = null; } $this->template()->setTitle(Phpfox::getPhrase('ad.creating_an_ad'))->setBreadcrumb(Phpfox::getPhrase('ad.advertise'), $this->url()->makeUrl('ad'))->setPhrase(array('ad.for_currency_total_cost', 'ad.impressions_cant_be_less_than_a_thousand', 'ad.the_currency_for_your_membership_has_no_price'))->assign(array('sStatus' => $sStatus, 'sModule' => $sModule . (isset($aModule[1]) ? '-' . $aModule[1] : ''), 'iId' => $iId)); }
public function get($iUserid = null, $iFeedId = null, $iPage = 0, $bForceReturn = false) { $params = []; if (is_array($iUserid)) { $params = $iUserid; $iUserid = null; if (isset($params['id'])) { $iFeedId = $params['id']; } if (isset($params['page'])) { $iPage = $params['page']; } } $oUrl = Phpfox_Url::instance(); $oReq = Phpfox_Request::instance(); $oParseOutput = Phpfox::getLib('parse.output'); $bIsCheckForUpdate = defined('PHPFOX_CHECK_FOR_UPDATE_FEED') ? 1 : 0; $iLastFeedId = defined('PHPFOX_CHECK_FOR_UPDATE_FEED_ID') ? PHPFOX_CHECK_FOR_UPDATE_FEED_ID : 0; if ($oReq->get('get-new')) { // $bForceReturn = true; } if ($iCommentId = $oReq->getInt('comment-id')) { if (isset($this->_aCallback['feed_comment'])) { $aCustomCondition = array('feed.type_id = \'' . $this->_aCallback['feed_comment'] . '\' AND feed.item_id = ' . (int) $iCommentId . ' AND feed.parent_user_id = ' . (int) $this->_aCallback['item_id']); } else { $aCustomCondition = array('feed.type_id IN(\'feed_comment\', \'feed_egift\') AND feed.item_id = ' . (int) $iCommentId . ' AND feed.parent_user_id = ' . (int) $iUserid); } $iFeedId = true; } elseif ($iStatusId = $oReq->getInt('status-id')) { $aCustomCondition = array('feed.type_id = \'user_status\' AND feed.item_id = ' . (int) $iStatusId . ' AND feed.user_id = ' . (int) $iUserid); $iFeedId = true; } elseif ($iLinkId = $oReq->getInt('link-id')) { $aCustomCondition = array('feed.type_id = \'link\' AND feed.item_id = ' . (int) $iLinkId . ' AND feed.user_id = ' . (int) $iUserid); $iFeedId = true; } elseif ($iLinkId = $oReq->getInt('plink-id')) { $aCustomCondition = array('feed.type_id = \'link\' AND feed.item_id = ' . (int) $iLinkId . ' AND feed.parent_user_id = ' . (int) $iUserid); $iFeedId = true; } elseif ($iPokeId = $oReq->getInt('poke-id')) { $aCustomCondition = array('feed.type_id = \'poke\' AND feed.item_id = ' . (int) $iPokeId . ' AND feed.user_id = ' . (int) $iUserid); $iFeedId = true; } $iTotalFeeds = (int) Phpfox::getComponentSetting($iUserid === null ? Phpfox::getUserId() : $iUserid, 'feed.feed_display_limit_' . ($iUserid !== null ? 'profile' : 'dashboard'), Phpfox::getParam('feed.feed_display_limit')); if (isset($params['limit'])) { $iTotalFeeds = $params['limit']; } $iOffset = $iPage * $iTotalFeeds; $extra = ''; ($sPlugin = Phpfox_Plugin::get('feed.service_feed_get_start')) ? eval($sPlugin) : false; if (isset($params['type_id'])) { $extra .= ' AND type_id ' . (is_array($params['type_id']) ? 'IN(' . implode(',', array_map(function ($value) { return "'{$value}'"; }, $params['type_id'])) . ')' : '= \'' . $params['type_id'] . '\'') . ''; // d($extra); exit; } $sOrder = 'feed.time_update DESC'; if (Phpfox::getUserBy('feed_sort') || defined('PHPFOX_IS_USER_PROFILE')) { $sOrder = 'feed.time_stamp DESC'; } $aCond = array(); if (isset($this->_aCallback['module'])) { $aNewCond = array(); if ($iCommentId = $oReq->getInt('comment-id')) { if (!isset($this->_aCallback['feed_comment'])) { $aCustomCondition = array('feed.type_id = \'' . $this->_aCallback['module'] . '_comment\' AND feed.item_id = ' . (int) $iCommentId . ''); } } $aNewCond[] = 'AND feed.parent_user_id = ' . (int) $this->_aCallback['item_id']; if ($iUserid !== null && $iFeedId !== null) { $aNewCond[] = 'AND feed.feed_id = ' . (int) $iFeedId . ' AND feed.user_id = ' . (int) $iUserid; } if ($iUserid === null && $iFeedId !== null) { $aNewCond = []; $aNewCond[] = 'AND feed.feed_id = ' . (int) $iFeedId; } $aRows = $this->database()->select('feed.*, ' . Phpfox::getUserField() . ', u.view_id')->from(Phpfox::getT($this->_aCallback['table_prefix'] . 'feed'), 'feed')->join(Phpfox::getT('user'), 'u', 'u.user_id = feed.user_id')->where(isset($aCustomCondition) ? $aCustomCondition : $aNewCond)->order($sOrder)->limit($iOffset, $iTotalFeeds, null, false, true)->execute('getSlaveRows'); // Fixes missing page_user_id, required to create the proper feed target if ($this->_aCallback['module'] == 'pages') { foreach ($aRows as $iKey => $aValue) { $aRows[$iKey]['page_user_id'] = $iUserid; } } } elseif ($sIds = $oReq->get('ids')) { $aParts = explode(',', $oReq->get('ids')); $sNewIds = ''; foreach ($aParts as $sPart) { $sNewIds .= (int) $sPart . ','; } $sNewIds = rtrim($sNewIds, ','); $aRows = $this->database()->select('feed.*, ' . Phpfox::getUserField() . ', u.view_id')->from($this->_sTable, 'feed')->join(Phpfox::getT('user'), 'u', 'u.user_id = feed.user_id')->where('feed.feed_id IN(' . $sNewIds . ')')->order('feed.time_stamp DESC')->execute('getSlaveRows'); } elseif ($iUserid === null && $iFeedId !== null) { $aRows = $this->database()->select('feed.*, ' . Phpfox::getUserField() . ', u.view_id')->from($this->_sTable, 'feed')->join(Phpfox::getT('user'), 'u', 'u.user_id = feed.user_id')->where('feed.feed_id = ' . (int) $iFeedId)->order('feed.time_stamp DESC')->execute('getSlaveRows'); } elseif ($iUserid !== null && $iFeedId !== null) { $aRows = $this->database()->select('feed.*, ' . Phpfox::getUserField() . ', u.view_id')->from($this->_sTable, 'feed')->join(Phpfox::getT('user'), 'u', 'u.user_id = feed.user_id')->where(isset($aCustomCondition) ? $aCustomCondition : 'feed.feed_id = ' . (int) $iFeedId . ' AND feed.user_id = ' . (int) $iUserid . '')->order('feed.time_stamp DESC')->limit(1)->execute('getSlaveRows'); } elseif ($iUserid !== null) { if ($iUserid == Phpfox::getUserId()) { $aCond[] = 'AND feed.privacy IN(0,1,2,3,4)'; } else { if (Phpfox::getService('user')->getUserObject($iUserid)->is_friend) { $aCond[] = 'AND feed.privacy IN(0,1,2)'; } else { if (Phpfox::getService('user')->getUserObject($iUserid)->is_friend_of_friend) { $aCond[] = 'AND feed.privacy IN(0,2)'; } else { $aCond[] = 'AND feed.privacy IN(0)'; } } } // There is no reciprocal feed when you add someone as friend $this->database()->select('feed.*')->from($this->_sTable, 'feed')->where('feed.type_id = \'friend\' AND feed.user_id = ' . (int) $iUserid)->union(); ($sPlugin = Phpfox_Plugin::get('feed.service_feed_get_userprofile')) ? eval($sPlugin) : ''; $iTimelineYear = 0; if (($iTimelineYear = Phpfox_Request::instance()->get('year')) && !empty($iTimelineYear)) { $iMonth = 12; $iDay = 31; if (($iTimelineMonth = Phpfox_Request::instance()->get('month')) && !empty($iTimelineMonth)) { $iMonth = $iTimelineMonth; $iDay = Phpfox::getLib('date')->lastDayOfMonth($iMonth, $iTimelineYear); } $aCond[] = 'AND feed.time_stamp <= \'' . mktime(0, 0, 0, $iMonth, $iDay, $iTimelineYear) . '\''; } $this->database()->select('feed.*')->from($this->_sTable, 'feed')->where(array_merge($aCond, array('AND type_id = \'feed_comment\' AND feed.user_id = ' . (int) $iUserid . '')))->union(); $this->database()->select('feed.*')->from($this->_sTable, 'feed')->where(array_merge($aCond, array('AND feed.user_id = ' . (int) $iUserid . ' AND feed.feed_reference = 0 AND feed.parent_user_id = 0')))->union(); if (Phpfox::isUser()) { if (Phpfox::isModule('privacy')) { $this->database()->join(Phpfox::getT('privacy'), 'p', 'p.module_id = feed.type_id AND p.item_id = feed.item_id')->join(Phpfox::getT('friend_list_data'), 'fld', 'fld.list_id = p.friend_list_id AND fld.friend_user_id = ' . Phpfox::getUserId() . ''); } $this->database()->select('feed.*')->from($this->_sTable, 'feed')->where('feed.privacy IN(4) AND feed.user_id = ' . (int) $iUserid . ' AND feed.feed_reference = 0')->union(); } $this->database()->select('feed.*')->from($this->_sTable, 'feed')->where(array_merge($aCond, array('AND feed.parent_user_id = ' . (int) $iUserid)))->union(); $aRows = $this->database()->select('feed.*, ' . Phpfox::getUserField())->unionFrom('feed')->join(Phpfox::getT('user'), 'u', 'u.user_id = feed.user_id')->order('feed.time_stamp DESC')->group('feed.feed_id')->limit($iOffset, $iTotalFeeds, null, false, true)->execute('getSlaveRows'); } else { // Users must be active within 7 days or we skip their activity feed $iLastActiveTimeStamp = (int) Phpfox::getParam('feed.feed_limit_days') <= 0 ? 0 : PHPFOX_TIME - 86400 * Phpfox::getParam('feed.feed_limit_days'); if (Phpfox::isModule('privacy') && Phpfox::getUserParam('privacy.can_view_all_items') && $oReq->get('view-all')) { $this->_hashSearch(); $sSelect = 'feed.*, ' . Phpfox::getUserField(); if (Phpfox::isModule('friend')) { $sSelect .= ', f.friend_id AS is_friend'; $this->database()->leftJoin(Phpfox::getT('friend'), 'f', 'f.user_id = feed.user_id AND f.friend_user_id = ' . Phpfox::getUserId()); } $sWhere = 'feed.time_stamp > \'' . $iLastActiveTimeStamp . '\' ' . $extra . ' AND feed.feed_reference = 0'; if ($bIsCheckForUpdate) { $sWhere .= ' AND feed.feed_id>' . intval($iLastFeedId); } $aRows = $this->database()->select($sSelect)->from(Phpfox::getT('feed'), 'feed')->join(Phpfox::getT('user'), 'u', 'u.user_id = feed.user_id')->order($sOrder)->group('feed.feed_id')->limit($iOffset, $iTotalFeeds)->where($sWhere)->execute('getSlaveRows'); } else { if (Phpfox::getParam('feed.feed_only_friends') && !isset($params['is_api']) && $oReq->segment(1) != 'hashtag') { if (Phpfox::isModule('friend')) { // Get my friends feeds $this->database()->select('feed.*')->from($this->_sTable, 'feed')->join(Phpfox::getT('friend'), 'f', 'f.user_id = feed.user_id AND f.friend_user_id = ' . Phpfox::getUserId())->where('feed.privacy IN(0,1,2) ' . $extra . ' AND feed.time_stamp > \'' . $iLastActiveTimeStamp . '\' AND feed.feed_reference = 0')->union(); // Get my feeds $this->database()->select('feed.*')->from($this->_sTable, 'feed')->where('feed.privacy IN(0,1,2,3,4) ' . $extra . ' AND feed.user_id = ' . Phpfox::getUserId() . ' AND feed.time_stamp > \'' . $iLastActiveTimeStamp . '\' AND feed.feed_reference = 0')->union(); } } else { $sMyFeeds = '1,2,3,4'; ($sPlugin = Phpfox_Plugin::get('feed.service_feed_get_buildquery')) ? eval($sPlugin) : ''; if (Phpfox::isModule('friend')) { // Get my friends feeds $this->database()->select('feed.*')->from($this->_sTable, 'feed')->join(Phpfox::getT('friend'), 'f', 'f.user_id = feed.user_id AND f.friend_user_id = ' . Phpfox::getUserId())->where('feed.privacy IN(1,2) ' . $extra . ' AND feed.time_stamp > \'' . $iLastActiveTimeStamp . '\' AND feed.feed_reference = 0')->limit($iTotalFeeds)->union(); // Get my friends of friends feeds $this->database()->select('feed.*')->from($this->_sTable, 'feed')->join(Phpfox::getT('friend'), 'f1', 'f1.user_id = feed.user_id')->join(Phpfox::getT('friend'), 'f2', 'f2.user_id = ' . Phpfox::getUserId() . ' AND f2.friend_user_id = f1.friend_user_id')->where('feed.privacy IN(2) ' . $extra . ' AND feed.time_stamp > \'' . $iLastActiveTimeStamp . '\' AND feed.feed_reference = 0')->limit($iTotalFeeds)->union(); } // Get my feeds $this->database()->select('feed.*')->from($this->_sTable, 'feed')->where('feed.privacy IN(' . $sMyFeeds . ') ' . $extra . ' AND feed.user_id = ' . Phpfox::getUserId() . ' AND feed.time_stamp > \'' . $iLastActiveTimeStamp . '\' AND feed.feed_reference = 0')->union(); // Get public feeds $this->database()->select('feed.*')->from($this->_sTable, 'feed')->where('feed.privacy IN(0) ' . $extra . ' AND feed.time_stamp > \'' . $iLastActiveTimeStamp . '\' AND feed.feed_reference = 0')->union(); if (Phpfox::isModule('privacy')) { $this->database()->join(Phpfox::getT('privacy'), 'p', 'p.module_id = feed.type_id AND p.item_id = feed.item_id')->join(Phpfox::getT('friend_list_data'), 'fld', 'fld.list_id = p.friend_list_id AND fld.friend_user_id = ' . Phpfox::getUserId() . ''); } // Get feeds based on custom friends lists $this->database()->select('feed.*')->from($this->_sTable, 'feed')->where('feed.privacy IN(4) ' . $extra . ' AND feed.time_stamp > \'' . $iLastActiveTimeStamp . '\' AND feed.feed_reference = 0')->union(); } $this->_hashSearch(); $sSelect = 'feed.*, u.view_id, ' . Phpfox::getUserField(); if (Phpfox::isModule('friend')) { $sSelect .= ', f.friend_id AS is_friend'; $this->database()->leftJoin(Phpfox::getT('friend'), 'f', 'f.user_id = feed.user_id AND f.friend_user_id = ' . Phpfox::getUserId()); } $sWhere = ' 1 '; if ($bIsCheckForUpdate) { $sWhere .= ' AND feed.feed_id > ' . intval($iLastFeedId); } $aRows = $this->database()->select($sSelect)->unionFrom('feed')->join(Phpfox::getT('user'), 'u', 'u.user_id = feed.user_id')->where($sWhere)->order($sOrder)->group('feed.feed_id')->limit($iOffset, $iTotalFeeds, null, false, true)->execute('getSlaveRows'); } } if ($bForceReturn === true) { return $aRows; } $bFirstCheckOnComments = false; if (Phpfox::getParam('feed.allow_comments_on_feeds') && Phpfox::isUser() && Phpfox::isModule('comment')) { $bFirstCheckOnComments = true; } $aFeeds = array(); $aParentFeeds = array(); foreach ($aRows as $sKey => $aRow) { $aRow['feed_time_stamp'] = $aRow['time_stamp']; if ($aReturn = $this->_processFeed($aRow, $sKey, $iUserid, $bFirstCheckOnComments)) { if (isset($aReturn['force_user'])) { $aReturn['user_name'] = $aReturn['force_user']['user_name']; $aReturn['full_name'] = $aReturn['force_user']['full_name']; $aReturn['user_image'] = $aReturn['force_user']['user_image']; $aReturn['server_id'] = $aReturn['force_user']['server_id']; } $aReturn['feed_month_year'] = date('m_Y', $aRow['feed_time_stamp']); $aReturn['feed_time_stamp'] = $aRow['feed_time_stamp']; /* Lets figure out the phrases for like.display right here */ //if (Phpfox::getParam('like.allow_dislike')) if (Phpfox::isModule('like')) { $this->getPhraseForLikes($aReturn); } if (Phpfox::getParam('feed.cache_each_feed_entry') && !empty($aReturn['like_type_id']) && Phpfox::isUser() && isset($aReturn['likes']) && count($aReturn['likes'])) { $iUserLiked = isset($aReturn['likes_history'][Phpfox::getUserId()]) ? true : false; $aReturn['feed_is_liked'] = $iUserLiked; $aReturn['is_liked'] = $iUserLiked; } if (Phpfox::getParam('feed.cache_each_feed_entry') && isset($aReturn['comments']) && count($aReturn['comments'])) { foreach ($aReturn['comments'] as $iCommentKey => $aCommentValue) { $aReturn['comments'][$iCommentKey]['is_liked'] = isset($aCommentValue['liked_history'][Phpfox::getUserId()]) ? true : false; } } $aFeeds[] = $aReturn; } // Show the feed properly. If user A posted on page 1, then feed will say "user A > page 1 posted ..." if (isset($this->_aCallback['module']) && $this->_aCallback['module'] == 'pages') { // If defined parent user, and the parent user is not the same page (logged in as a page) if (isset($aRow['page_user_id']) && $aReturn['page_user_id'] != $aReturn['user_id']) { $aParentFeeds[$aReturn['feed_id']] = $aRow['page_user_id']; } } elseif (isset($this->_aCallback['module']) && $this->_aCallback['module'] == 'event') { // Keep it empty $aParentFeeds = array(); } elseif (isset($aRow['parent_user_id']) && !isset($aRow['parent_user']) && $aRow['type_id'] != 'friend') { $aParentFeeds[$aRow['feed_id']] = $aRow['parent_user_id']; } if (empty($aFeeds) && defined('PHPFOX_IS_USER_PROFILE')) { return $this->get($iUserid, $iFeedId, ++$iPage, $bForceReturn); } } // Get the parents for the feeds so it displays arrow.png if (!empty($aParentFeeds)) { $aParentUsers = $this->database()->select(Phpfox::getUserField())->from(Phpfox::getT('user'), 'u')->where('user_id IN (' . implode(',', array_values($aParentFeeds)) . ')')->execute('getSlaveRows'); $aFeedsWithParents = array_keys($aParentFeeds); foreach ($aFeeds as $sKey => $aRow) { if (in_array($aRow['feed_id'], $aFeedsWithParents) && $aRow['type_id'] != 'photo_tag') { foreach ($aParentUsers as $aUser) { if ($aUser['user_id'] == $aRow['parent_user_id']) { $aTempUser = array(); foreach ($aUser as $sField => $sVal) { $aTempUser['parent_' . $sField] = $sVal; } $aFeeds[$sKey]['parent_user'] = $aTempUser; } } } } } $oReq = Phpfox_Request::instance(); if (($oReq->getInt('status-id') || $oReq->getInt('comment-id') || $oReq->getInt('link-id') || $oReq->getInt('poke-id')) && isset($aFeeds[0])) { $aFeeds[0]['feed_view_comment'] = true; // $this->setParam('aFeed', array_merge(array('feed_display' => 'view', 'total_like' => $aRows[0]['feed_total_like']), $aRows[0])); } if ($oReq->getInt('page') == 0 && Phpfox::isModule('ad') && Phpfox::getParam('ad.multi_ad') && $iFeedId == null && ($iAd = Ad_Service_Ad::instance()->getSponsoredFeed()) != false) { $aFeeds = array_splice($aFeeds, 0, count($aFeeds) - 1); $aSponsored = $this->get(null, $iAd); if (isset($aSponsored[0])) { $aSponsored[0]['sponsored_feed'] = true; $aFeeds = array_merge($aSponsored, $aFeeds); } } // d($aFeeds); exit; return $aFeeds; }
/** * Controller */ public function process() { Phpfox::isUser(true); Phpfox::getUserParam('ad.can_create_ad_campaigns', true); // $aAllCountries = Phpfox::getService('core.country')->get(); $aAllCountries = Phpfox::getService('core.country')->getCountriesAndChildren(); $bIsEdit = false; $bCompleted = $this->request()->get('req3') == 'completed' ? true : false; if (($iId = $this->request()->getInt('id')) && ($aAd = Ad_Service_Ad::instance()->getForEdit($iId))) { if ($aAd['user_id'] != Phpfox::getUserId()) { return Phpfox_Error::display(Phpfox::getPhrase('ad.unable_to_edit_purchase_this_ad')); } if (!$bCompleted) { $bIsEdit = true; } $aAd['country_iso_custom'] = $aAd['country_iso']; $this->template()->assign(array('aForms' => $aAd, 'aAllCountries' => $aAllCountries)); $this->template()->setHeader(array('add.js' => 'module_ad', '<script type="text/javascript">$Behavior.loadAdJs = function() { $Core.Ad.isEdit = true; $Core.Ad.setCountries(\'' . json_encode($aAllCountries) . '\'); }</script>')); } if ($bIsEdit) { $aValidation = array(); } else { $aValidation = array('url_link' => array('def' => 'url')); } $aValidation['name'] = Phpfox::getPhrase('ad.provide_a_campaign_name'); if (!$bIsEdit) { $aValidation['total_view'] = Phpfox::getPhrase('ad.define_how_many_impressions_for_this_ad'); } $oValidator = Phpfox_Validator::instance()->set(array('sFormName' => 'js_form', 'aParams' => $aValidation)); if ($aVals = $this->request()->getArray('val')) { if ($oValidator->isValid($aVals)) { if (isset($aVals['location'])) { if (Phpfox::getParam('ad.multi_ad')) { $aPlan = Ad_Service_Ad::instance()->getPlan(50, true); } else { $aPlan = Ad_Service_Ad::instance()->getPlan($aVals['block_id'], false); } $aVals = array_merge($aPlan, $aVals); } if ($bIsEdit) { if ($iId = Phpfox::getService('ad.process')->updateCustom($aAd['ad_id'], $aVals)) { $this->url()->send('ad.manage', null, Phpfox::getPhrase('ad.ad_successfully_updated')); } } else { if ($iId = Phpfox::getService('ad.process')->addCustom($aVals)) { $this->url()->send('ad.add.completed', array('id' => $iId)); } } } } $aAge = array(); $iAgeEnd = date('Y') - Phpfox::getParam('user.date_of_birth_start'); $iAgeStart = date('Y') - Phpfox::getParam('user.date_of_birth_end'); for ($iAgeStart; $iAgeStart <= $iAgeEnd; $iAgeStart++) { $aAge[$iAgeStart] = $iAgeStart; } $iPlacementCount = count((array) Ad_Service_Ad::instance()->getPlacements()); if (!$bCompleted && !$bIsEdit) { if ($iPlacementCount) { $this->template()->setHeader(array('add.js' => 'module_ad', '<script type="text/javascript">$Behavior.loadAdJs = function() { $Core.Ad.setCountries(\'' . json_encode($aAllCountries) . '\'); };</script>')); } } else { $aPlan = Ad_Service_Ad::instance()->getPlan($aAd['location'], true); if (!isset($aPlan['plan_id'])) { return Phpfox_Error::display(Phpfox::getPhrase('ad.not_a_valid_ad_plan')); } // is it free? $aCosts = unserialize($aPlan['cost']); $bIsFree = true; foreach ($aCosts as $sCurrency => $fCost) { if ($fCost > 0) { $bIsFree = false; break; } } $this->template()->assign(array('bIsFree' => $bIsFree)); $this->setParam('gateway_data', array('item_number' => 'ad|' . $aAd['ad_id'], 'currency_code' => $aPlan['default_currency_id'], 'amount' => $aPlan['is_cpm'] ? $aPlan['default_cost'] * $aAd['total_view'] / 1000 : $aPlan['default_cost'] * $aAd['total_view'], 'item_name' => $aPlan['title'], 'return' => $this->url()->makeUrl('ad.manage', array('view' => 'pending', 'payment' => 'done')), 'recurring' => '', 'recurring_cost' => '', 'alternative_cost' => '', 'alternative_recurring_cost' => '')); } $this->template()->setTitle($bIsEdit ? Phpfox::getPhrase('ad.updating_an_ad') : Phpfox::getPhrase('ad.creating_an_ad'))->setBreadcrumb(Phpfox::getPhrase('ad.advertise'), $this->url()->makeUrl('ad'))->setBreadcrumb($bIsEdit ? Phpfox::getPhrase('ad.updating_an_ad') : Phpfox::getPhrase('ad.creating_an_ad'), $this->url()->makeUrl('ad.add'), true)->setPhrase(array('ad.select_an_ad_placement', 'ad.there_is_minimum_of_1000_impressions'))->assign(array('aAge' => $aAge, 'bIsEdit' => $bIsEdit, 'sCreateJs' => $oValidator->createJS(), 'sGetJsForm' => $oValidator->getJsForm(), 'bCompleted' => $bCompleted, 'bIsEdit' => $bIsEdit, 'iPlacementCount' => $iPlacementCount, 'aAllCountries' => $aAllCountries))->setPhrase(array('core.you_cannot_write_more_then_limit_characters', 'core.you_have_limit_character_s_left', 'ad.amount_currency_per_1000_impressions', 'ad.amount_currency_per_click'))->setHeader('cache', array('jquery/plugin/jquery.limitTextarea.js' => 'static_script', 'add.css' => 'module_ad', '<script type="text/javascript">$Behavior.setMulti = function(){ oParams[\'ad.multi_ad\'] = ' . (Phpfox::getParam('ad.multi_ad') ? 'true' : 'false') . ';};</script>'))->setFullSite(); }