function __construct() { $this->context = APP_EXTENSION . "_payments."; $this->tablename = '#__' . APP_PREFIX . '_payment_log'; JTheFactoryHelper::tableIncludePath('payments'); parent::__construct(); }
function save($data) { // Get the previous configuration. if (is_object($data)) { $data = JArrayHelper::fromObject($data); } $prev = JTheFactoryHelper::getConfig(); $prev = JArrayHelper::fromObject($prev); $data = array_merge($prev, $data); $configfile = JTheFactoryAdminHelper::getConfigFile(); $config = new JRegistry('config'); $config->loadArray($data); jimport('joomla.filesystem.path'); jimport('joomla.filesystem.file'); jimport('joomla.client.helper'); // Get the new FTP credentials. $ftp = JClientHelper::getCredentials('ftp', true); // Attempt to make the file writeable if using FTP. if (!$ftp['enabled'] && JPath::isOwner($configfile) && !JPath::setPermissions($configfile, '0644')) { JError::raiseNotice(101, JText::_('FACTORY_SETTINGS_FILE_IS_NOT_WRITABLE')); } // Attempt to write the configuration file as a PHP class named JConfig. $configString = $config->toString('PHP', array('class' => ucfirst(APP_PREFIX) . "Config", 'closingtag' => false)); if (!JFile::write($configfile, $configString)) { JError::raiseWarning(101, JText::_('FACTORY_SETTINGS_FILE_WRITE_FAILED')); return false; } // Attempt to make the file unwriteable if using FTP. if (!$ftp['enabled'] && JPath::isOwner($configfile) && !JPath::setPermissions($configfile, '0444')) { JError::raiseNotice(101, JText::_('FACTORY_SETTINGS_FILE_IS_NOT_WRITABLE')); } return true; }
function __construct($config=array()) { $MyApp= JTheFactoryApplication::getInstance(); $lang= JFactory::getLanguage(); $lang->load('thefactory.payments'); $config['view_path']=$MyApp->app_path_front.'payments'.DS."views"; parent::__construct($config); JTheFactoryHelper::modelIncludePath('payments'); JTheFactoryHelper::tableIncludePath('payments'); }
function Listing() { $app = JFactory::getApplication(); $filter_username = $app->getUserStateFromRequest(APP_EXTENSION . "_payments." . 'filter_username', 'filter_username', '', 'string'); $cfg = JTheFactoryHelper::getConfig(); $model = JModel::getInstance('Orders', 'JTheFactoryModel'); $rows = $model->getOrdersList($filter_username); $view = $this->getView('orders'); $view->assign('orders', $rows); $view->assign('filter_username', $filter_username); $view->assign('pagination', $model->get('pagination')); $view->assign('cfg', $cfg); $view->display('list'); }
function display() { jimport('joomla.form.form'); $form = JForm::getInstance('config', $this->formxml); $cfg = JTheFactoryHelper::getConfig(); $data = JArrayHelper::fromObject($cfg); $form->bind($data); $groups = JTheFactoryConfigHelper::getFieldGroups($this->formxml); JTheFactoryEventsHelper::triggerEvent('onDisplaySettings', array($form, $groups, $data)); $view = $this->getView('settings'); $view->assignRef('groups', $groups); $view->assignRef('form', $form); $view->assignRef('formxml', $this->formxml); $view->display(); }
function getGoogleCurrency($currency_from, $currency_to) { $url = "http://www.google.com/ig/calculator?hl=en&q=1+{$currency_from}=?{$currency_to}"; $res = JTheFactoryHelper::remote_read_url($url); $matches = array(); if (preg_match('/lhs:\\s*"([^"]*)"\\s*,rhs:\\s*"([^"]*)"\\s*,error:\\s*"([^"]*)"/', $res, $matches)) { $error = $matches[3]; $rate = $matches[2]; if ($error) { return false; } return floatval(substr($rate, 0, strpos($rate, " "))); } else { return false; } }
/** * Field related Tasks / Admin Section */ function Main() { $MyApp = JTheFactoryApplication::getInstance(); $filename = $MyApp->getIniValue('version_root') . '/' . APP_EXTENSION . ".xml"; $doc = JTheFactoryHelper::remote_read_url($filename); $xml = JFactory::getXML($doc, false); $view = $this->getView('main'); if (version_compare(COMPONENT_VERSION, (string) $xml->latestversion) >= 0) { $view->assign('isnew_version', false); } else { $view->assign('isnew_version', true); } $view->assign('latestversion', (string) $xml->latestversion); $view->assign('versionhistory', (string) $xml->versionhistory); $view->assign('downloadlink', (string) $xml->downloadlink); $view->assign('aboutfactory', html_entity_decode((string) $xml->aboutfactory)); $view->assign('otherproducts', html_entity_decode((string) $xml->otherproducts)); $view->assign('build', (string) $xml->build); $view->display(); }
function display($tpl = null) { $db = JFactory::getDBO(); $db->setQuery("select * from #__bid_paysystems where enabled=1"); $gateways = $db->loadObjectList(); $db->setQuery("select * from #__bid_pricing where enabled=1"); $items = $db->loadObjectList(); $db->setQuery("select * from #__bid_cronlog where event='cron' order by logtime desc limit 1"); $log = $db->loadObject(); $cfg = JTheFactoryHelper::getConfig(); $this->assignref('gateways', $gateways); $this->assignref('items', $items); if ($log) { $this->assignref('latest_cron_time', $log->logtime); } else { $this->assign('latest_cron_time', JText::_('COM_BIDS_NEVER')); } $this->assignref('cfg', $cfg); parent::display($tpl); }
function __construct($modulename = null) { $this->modulename = $modulename; if (!$modulename) { $this->modulename = $this->name; } $MyApp = JTheFactoryApplication::getInstance(); $this->basepath = $MyApp->app_path_admin . strtolower($this->modulename); $config = array('view_path' => $this->basepath . DS . "views"); parent::__construct($config); $this->loadLanguage(); $this->registerClass('toolbar'); $this->registerClass('helper'); $this->registerClass('submenu'); if (file_exists($this->basepath . DS . "models")) { JTheFactoryHelper::modelIncludePath($this->modulename); } if (file_exists($this->basepath . DS . "tables")) { JTheFactoryHelper::tableIncludePath($this->modulename); } }
function getBalance() { JTheFactoryHelper::modelIncludePath('payments'); $balance = JModelLegacy::getInstance('balance','JTheFactoryModel'); return $balance->getUserBalance(); }
function getModel($model) { jimport('joomla.application.component.model'); JTheFactoryHelper::modelIncludePath('payments'); return JModel::getInstance($model, 'JTheFactoryModel'); }
public function Cronjob_Info() { $cfg = JTheFactoryHelper::getConfig(); $db = JFactory::getDBO(); $db->setQuery("select * from #__bid_cronlog where event='cron' order by logtime desc limit 1"); $log = $db->loadObject(); $view = $this->getView('settingspanel'); $view->assignref('cfg', $cfg); $view->assignref('cronlog', $log); $view->display('cronsettings'); }
function setCurrentTheme($theme) { $MyApp = JTheFactoryApplication::getInstance(); $cfg = JTheFactoryHelper::getConfig(); $cfg->theme = $theme; JTheFactoryHelper::modelIncludePath('config'); $formxml = JPATH_ROOT . DS . "administrator" . DS . "components" . DS . APP_EXTENSION . DS . $MyApp->getIniValue('configxml'); $model = JModel::getInstance('Config', 'JTheFactoryModel', array('formxml' => $formxml)); $model->save($cfg); }
/** * JTheFactoryApplication::Initialize() * loads some "magic" files like defines.php,loads the main helper file (APP_PREFIX.php) * loads other helpers (through helper::loadHelperclasses) * loads the needed Controller * adds htmlelements and formelements to path (admin) * adds tables to paths * * @return void */ function Initialize($task = null) { jimport('joomla.application.component.controller'); if (!$this->frontpage) { JFormHelper::addFieldPath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'formelements'); } JHtml::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'htmlelements'); JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables'); if (file_exists(JPATH_COMPONENT_SITE . DS . 'defines.php')) { require_once JPATH_COMPONENT_SITE . DS . 'defines.php'; } if (file_exists(JPATH_COMPONENT_SITE . DS . 'helpers' . DS . strtolower($this->appname) . '.php')) { require_once JPATH_COMPONENT_SITE . DS . 'helpers' . DS . strtolower($this->appname) . '.php'; } $class_name = ucfirst($this->appname) . 'Helper'; call_user_func(array($class_name, 'loadHelperClasses')); JTheFactoryEventsHelper::triggerEvent('onBeforeExecuteTask', array(&$this->_stopexecution)); if ($this->_stopexecution) { return; } if (!$task) { $task = JRequest::getCmd('task'); } $this->_controller = JTheFactoryHelper::loadController($task); //Try to load Framework controllers if (!$this->_controller) { $controllerClass = JRequest::getWord('controller'); if (!$controllerClass && strpos($task, '.') !== FALSE) { $task = explode('.', $task); $controllerClass = $task[0]; } if ($controllerClass) { $path = JPATH_COMPONENT . DS . 'controllers' . DS . basename($controllerClass) . '.php'; file_exists($path) ? require_once $path : JError::raiseError(500, JText::_('ERROR_CONTROLLER_NOT_FOUND')); $controllerClass = 'J' . ucfirst($this->appname) . ($this->frontpage ? "" : "Admin") . 'Controller' . $controllerClass; $this->_controller = new $controllerClass(); } else { $this->_controller = JControllerLegacy::getInstance('J' . ucfirst($this->appname) . ($this->frontpage ? "" : "Admin")); } } }
function smarty_positions($params, &$smarty) { if(!isset($params['position']) || empty($params['position'])) return null; if(!isset($params['item']) || empty($params['item'])) return null; $item=$params['item']; $page=(isset($params['page']))?$params['page']:""; $catfield=null; if (is_callable(array($item,'getCategoryField'))) $catfield=$item->getCategoryField(); //make sure proper object is passed if (is_object($item)) $item=get_object_vars($item); $position=$params['position']; $template_file=$smarty->get_template_vars('template_file'); JTheFactoryHelper::modelIncludePath('positions'); $model= JModelLegacy::getInstance('Positions','JTheFactoryModel'); $fields=$model->getFieldsForPosition($template_file,$position); $result=""; $fieldObj= JTable::getInstance('FieldsTable','JTheFactory'); JTheFactoryHelper::modelIncludePath('fields'); $fieldsmodel= JModelLegacy::getInstance('Fields','JTheFactoryModel'); foreach($fields as $field) if (isset($item[$field->db_name])&&$page==$field->page) { $fieldObj->bind($field); if ($catfield && $fieldObj->categoryfilter && !$fieldsmodel->hasAssignedCat($fieldObj,$item->$catfield)) continue; $ftype= CustomFieldsFactory::getFieldType($field->ftype); $field_label=$field->name; $field_html=$ftype->getTemplateHTML($fieldObj,$item[$field->db_name]); $result.="<div id='{$field->db_name}'><label class='custom_field'>{$field_label}</label>: {$field_html}</div>"; } return $result; }
function sendNotificationMail($user) { $config = JFactory::getConfig(); $mail_from = $config->getValue("mailfrom"); $sitename = $config->getValue("sitename"); JTheFactoryHelper::modelIncludePath('payments'); $balancemodel = JModel::getInstance('Balance', 'JTheFactoryModel'); $balance = $balancemodel->getUserBalance($user->id); $r = $this->loadPricingObject(); $params = new JParameter($r->params); $email_text = base64_decode($params->get('email_text')); $link = JURI::root() . '/index.php?option=' . APP_EXTENSION . '&task=paycomission'; $email_text = str_replace('%USERNAME%', $user->username, $email_text); $email_text = str_replace('%NAME%', $user->name, $email_text); $email_text = str_replace('%BALANCE%', $balance->balance . " " . $balance->currency, $email_text); $email_text = str_replace('%LINK%', $link, $email_text); JUTility::sendMail($mail_from, $sitename, $user->email, JText::_("COM_BIDS_COMISION_PAYMENT_NOTIFICATION"), $email_text, true); }
function notices() { JTheFactoryHelper::modelIncludePath('payments'); $balancemodel = JModel::getInstance('Balance', 'JTheFactoryModel'); $balancemodel->set('filters', 'p.balance<0'); $rows = $balancemodel->getBalancesList(); $viewMenu = $this->getView('menu'); $viewMenu->display(); $view = $this->getView('Notices'); $view->assign('userbalances', $rows); $view->assign('pagination', $balancemodel->get('pagination')); $view->display(); }
function cron() { /* cron script Pass and authentication*/ $cfg=BidsHelperTools::getConfig(); $config =JFactory::getConfig(); $pass=JRequest::getVar('pass'); $debug= JRequest::getVar('debug',0); $date=new JDate(); $nowMysql=$date->toMySQL(false); $database = JFactory::getDbo(); JTheFactoryHelper::modelIncludePath('payments'); JTheFactoryHelper::tableIncludePath('payments'); $log= JTable::getInstance('bidcronlog'); $log->priority='log'; $log->event='cron'; $log->logtime=$nowMysql; $logtext=""; if ($cfg->bid_opt_cron_password!==$pass) { //Bad Password, log and exit; $log->log=JText::_("COM_BIDS_BAD_PASSWORD_USED")." > $pass"; $log->store(); die(JText::_("COM_BIDS_ACCESS_DENIED")); } @set_time_limit(0); @ignore_user_abort(true); // reminder for due to expire suggestions $database->setQuery(" SELECT s.auction_id,a.userid FROM #__bid_suggestions AS s LEFT JOIN #__bid_auctions AS a ON s.auction_id = a.id WHERE s.status=2 AND UTC_TIMESTAMP() > DATE_ADD( s.modified, INTERVAL 24 HOUR) AND a.published=1 AND a.close_offer=0 AND a.close_by_admin=0 AND UTC_TIMESTAMP() < a.end_date GROUP BY s.auction_id"); $curs = $database->loadObjectList(); if(count($curs)>0) { $auction = JTable::getInstance('auction'); $userIds = array(); foreach($curs as $k=>$val) { $userIds[] = $val->userid; } $database->setQuery('SELECT u.* FROM #__users AS u WHERE u.id IN ( '.implode(',',$userIds).' )'); $mails = $database->loadObjectList(); $auction->SendMails($mails,'suggest_reminder'); //Notyfy Sellers abour pending suggestions } // reject expired suggestions $database->setQuery(" SELECT a.id AS suggestionId,a.auction_id,b.userid FROM #__bid_suggestions AS a LEFT JOIN #__bid_auctions AS b ON a.auction_id = b.id WHERE UTC_TIMESTAMP() > DATE_ADD( a.modified, INTERVAL 48 HOUR) AND a.status=2"); $curs = $database->loadObjectList(); if(count($curs)>0) { $auction = JTable::getInstance('auction'); $userIds = array(); $suggestionIds = array(); foreach($curs as $k=>$val) { $suggestionIds[] = $val->suggestionId; $userIds[] = $val->userid; } $database->setQuery('UPDATE #__bid_suggestions SET status=0 WHERE id IN ('.implode(',',$suggestionIds).')'); $database->query();// reject the suggestions $database->setQuery('SELECT u.* FROM #__users AS u WHERE u.id IN ( '.implode(',',$userIds).' )'); $mails = $database->loadObjectList(); $auction->SendMails($mails,'suggest_rejected'); //Notyfy Bidders abour rejected suggestion } //CLOSE auctions $query = "SELECT a.*, a.id as auctionId, GROUP_CONCAT(b.userid) AS bidderIds, GROUP_CONCAT(w.userid) AS watcherIds FROM #__bid_auctions AS a LEFT JOIN #__bids AS b ON a.id=b.auction_id LEFT JOIN #__bid_watchlist AS w ON a.id=w.auction_id WHERE UTC_TIMESTAMP() >= a.end_date AND a.close_offer = 0 AND a.published = 1 AND a.close_by_admin=0 GROUP BY a.id"; $database->setQuery($query); $rows = $database->loadObjectList('auctionId'); $extendedAuctions = array(); if($cfg->bid_opt_auto_extent && $cfg->bid_opt_auto_extent_nobids) { //these auctions have no bids and will be extended foreach($rows as $id=>$r) { if(!$r->bidderIds) { $extendedAuctions[] = $id; } } } if(count($rows)>0) { $auction = JTable::getInstance('auction'); //exclude auctions that are going to be extended $closeAuctions = array_diff(array_keys($rows),$extendedAuctions); if(count($closeAuctions)) { $database->setQuery('UPDATE #__bid_auctions SET close_offer=1, closed_date=UTC_TIMESTAMP() WHERE id IN ('.implode(',', $closeAuctions).')'); $database->query(); } foreach ($rows as $r) { //Notify bidders $auction->bind($r); //extend auctions with no bids if($cfg->bid_opt_auto_extent && $cfg->bid_opt_auto_extent_nobids>0 && !$r->bidderIds) { $extendedPeriodSeconds = $cfg->bid_opt_auto_extent_nobids * BidsHelperDateTime::translateAutoextendPeriod($cfg->bid_opt_auto_extent_nobids_type); $endTime = BidsHelperDateTime::getTimeStamp($auction->end_date); $newEndTime = $endTime + $extendedPeriodSeconds; $auction->end_date = gmdate('Y-m-d H:i:s',$newEndTime); $auction->store(); continue; } jimport('joomla.application.component.model'); JModelLegacy::addIncludePath(JPATH_COMPONENT_SITE.DS.'models'); $auctionmodel = JModelLegacy::getInstance('auction','bidsModel'); $auctionmodel->load($r->auctionId); $seller = JTable::getInstance('user'); $seller->load($r->userid); if($r->automatic) { $a = $auctionmodel->get('auction'); $highestBid = $a->highestBid; $nrHighestBids = 1; if( AUCTION_TYPE_PRIVATE == $a->auction_type ) { if($highestBid) { $query = 'SELECT COUNT(1) AS nrHighestBids FROM #__bids WHERE auction_id='.$r->auctionId.' AND bid_price='.$highestBid->bid_price; $database->setQuery($query); $nrHighestBids = $database->loadResult(); } else { $nrHighestBids = 0; } } if($highestBid) { if ($nrHighestBids>1) { //mark auction as NOT automatic and alert owner that 2 or more bids are the same $database->setQuery('UPDATE #__bid_auctions SET automatic=0 WHERE id='.$a->id); $database->query(); $auctionmodel->SendMails(array($seller),'bid_choose_winner'); } else { if ($cfg->bid_opt_global_enable_reserve_price && $a->reserve_price>0 && $a->reserve_price>=$highestBid->bid_price) { //reserve price not met! $auctionmodel->SendMails(array($seller),'bid_reserve_not_met');//reserve price not met } else { $bid = JTable::getInstance('bid'); $bid->bind($highestBid); $auctionmodel->close($bid); } } } else { $auctionmodel->SendMails(array($seller),'bid_offer_no_winner_to_owner'); } } else { // Notify owner to choose winner OR that his auction has no winner $auctionmodel->SendMails(array($seller), $r->bidderIds ? 'bid_choose_winner' : 'bid_offer_no_winner_to_owner'); } if($r->bidderIds) { $database->setQuery('SELECT u.* FROM #__users AS u WHERE u.id IN ('.$r->bidderIds.')'); $mails = $database->loadObjectList(); $auctionmodel->SendMails($mails,'bid_closed'); //Notyfy Bidders abour closed Auction $database->setQuery('DELETE FROM #__bid_watchlist WHERE auction_id='.$r->id.' AND userid IN ('.$r->bidderIds.')'); $database->query();//delete bidders from watchlist, to avoid double notification } //Notify Watchlist, Clean Watchlist if($r->watcherIds) { $database->setQuery('SELECT u.* FROM #__users AS u WHERE u.id IN ('.$r->watcherIds.')'); $mails = $database->loadObjectList(); $auctionmodel->SendMails($mails,'bid_watchlist_closed'); //Notify Watchlist $database->setQuery('DELETE FROM #__bid_watchlist WHERE auction_id='.$r->id); $database->query(); } } } // END EXPIRED AUCTION //Daily Jobs (things that should run once a day ) $daily= JRequest::getVar('daily',''); if ($daily){ //Notify upcoming expirations $query = "SELECT a.* from #__bid_auctions AS a WHERE UTC_TIMESTAMP() >= DATE_ADD(end_date,INTERVAL -1 DAY) AND a.close_offer != 1 AND published = 1 AND a.close_by_admin!=1"; $database->setQuery($query); $rows = $database->loadObjectList(); $auction = JTable::getInstance('auction'); $logtext.=sprintf("Soon to expire: %d auctions\r\n",count($rows)); foreach ($rows as $row){ $auction->load($row->id); $usr=JFactory::getUser($row->userid); $auction->SendMails(array($usr),'bid_your_will_expire'); // Notify Owner that his auction will soon expire $query = "SELECT u.* FROM #__users u left join #__bid_watchlist w on u.id = w.userid where w.auction_id = ".$row->id; $database->setQuery($query); $watchlist_mails = $database->loadObjectList(); $auction->SendMails($watchlist_mails,'bid_watchlist_will_expire'); //Notify Users in watchlist that an auction will expire } //Close all auctions without a parent user (deleted users?)s $query = "UPDATE #__bid_auctions AS a LEFT JOIN #__users AS b ON a.userid=b.id SET close_by_admin=1, closed_date=UTC_TIMESTAMP() WHERE b.id IS NULL"; $database->setQuery($query); $database->query(); //delete Very old auctions (past Archived time) $interval = intval($bidCfg->bid_opt_archive); $d_opt = ( $bidCfg->bid_opt_archive_type!='') ? $bidCfg->bid_opt_archive_type : 'month'; $d_opt_sql = strtoupper($d_opt); if ($interval>0){ $query = "SELECT id FROM #__bid_auctions WHERE UTC_TIMESTAMP() > DATE_ADD( closed_date, INTERVAL $interval {$d_opt_sql} ) AND (close_offer =1 or close_by_admin=1)"; $database->setQuery($query); $idx = $database->loadResultArray(); //select auctions that have to be purged $row = JTable::getInstance('auction'); if (count($idx)) { foreach ($idx as $id){ $row->delete($id); } } } $model= JModelLegacy::getInstance('Currency','JTheFactoryModel'); $currtable= JTable::getInstance('CurrencyTable','JTheFactory'); $currencies=$model->getCurrencyList(); $default_currency=$model->getDefault(); $results=array(); foreach($currencies as $currency){ if ($currency->name==$default_currency){ $currtable->load($currency->id); $currtable->convert=1; $currtable->store(); $results[]=$currency->name." ---> ".$default_currency." = 1"; continue; } $conversion=$model->getGoogleCurrency($currency->name,$default_currency); if ($conversion===false){ $results[]=JText::_("COM_BIDS_ERROR_CONVERTING")." {$currency->name} --> $default_currency"; continue; } $currtable->load($currency->id); $currtable->convert=$conversion; $currtable->store(); $results[]=$currency->name." ---> ".$default_currency." = $conversion "; } $logtext.=implode("\r\n",$results); $logtext.="\r\n"; //some cleanup } $log->log=$logtext; $log->store(); if ($debug) return; ob_clean(); exit(); }