コード例 #1
0
 /**
  * called via ajax to perform viz ajax task (defined by plugintask method)
  */
 public function display()
 {
     $document = JFactory::getDocument();
     $id = JRequest::getInt('visualizationid');
     $viz = FabTable::getInstance('Visualization', 'FabrikTable');
     $viz->load($id);
     $modelpaths = JModel::addIncludePath(JPATH_SITE . '/plugins/fabrik_visualization/' . $viz->plugin . '/models');
     $model = $this->getModel($viz->plugin);
     $model->setId($id);
     $pluginTask = JRequest::getVar('plugintask', '', 'request');
     if ($pluginTask !== '') {
         echo $model->{$pluginTask}();
     } else {
         $task = JRequest::getVar('task');
         $path = JPATH_SITE . '/plugins/fabrik_visualization/' . $viz->plugin . '/controllers/' . $viz->plugin . '.php';
         if (file_exists($path)) {
             require_once $path;
         } else {
             JError::raiseNotice(400, 'could not load viz:' . $viz->plugin);
             return;
         }
         $controllerName = 'FabrikControllerVisualization' . $viz->plugin;
         $controller = new $controllerName();
         $controller->addViewPath(JPATH_SITE . '/plugins/fabrik_visualization/' . $viz->plugin . '/views');
         $controller->addViewPath(COM_FABRIK_FRONTEND . '/views');
         //add the model path
         $modelpaths = JModel::addIncludePath(JPATH_SITE . '/plugins/fabrik_visualization/' . $viz->plugin . '/models');
         $modelpaths = JModel::addIncludePath(COM_FABRIK_FRONTEND . '/models');
         $origId = JRequest::getInt('visualizationid');
         JRequest::setVar('visualizationid', $id);
         $controller->{$task}();
     }
 }
コード例 #2
0
 /**
  * Called via ajax to perform viz ajax task (defined by plugintask method)
  *
  * @param   boolean  $cachable   If true, the view output will be cached
  * @param   array    $urlparams  An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
  *
  * @return  JController  A JController object to support chaining.
  */
 public function display($cachable = false, $urlparams = false)
 {
     $document = JFactory::getDocument();
     $app = JFactory::getApplication();
     $input = $app->input;
     $id = $input->getInt('visualizationid');
     $viz = FabTable::getInstance('Visualization', 'FabrikTable');
     $viz->load($id);
     $modelpaths = JModelLegacy::addIncludePath(JPATH_SITE . '/plugins/fabrik_visualization/' . $viz->plugin . '/models');
     $model = $this->getModel($viz->plugin);
     $model->setId($id);
     $pluginTask = $input->get('plugintask', '', 'request');
     if ($pluginTask !== '') {
         echo $model->{$pluginTask}();
     } else {
         $task = $input->get('task');
         $path = JPATH_SITE . '/plugins/fabrik_visualization/' . $viz->plugin . '/controllers/' . $viz->plugin . '.php';
         if (file_exists($path)) {
             require_once $path;
         } else {
             throw new RuntimeException('Could not load visualization: ' . $viz->plugin);
         }
         $controllerName = 'FabrikControllerVisualization' . $viz->plugin;
         $controller = new $controllerName();
         $controller->addViewPath(JPATH_SITE . '/plugins/fabrik_visualization/' . $viz->plugin . '/views');
         $controller->addViewPath(COM_FABRIK_FRONTEND . '/views');
         // Add the model path
         $modelpaths = JModelLegacy::addIncludePath(JPATH_SITE . '/plugins/fabrik_visualization/' . $viz->plugin . '/models');
         $modelpaths = JModelLegacy::addIncludePath(COM_FABRIK_FRONTEND . '/models');
         $origId = $input->getInt('visualizationid');
         $input->set('visualizationid', $id);
         $controller->{$task}();
     }
     return $this;
 }
コード例 #3
0
ファイル: plugin.php プロジェクト: rogeriocc/fabrik
 /**
  * Get the plugins data to bind to the form
  *
  * @return  array
  */
 protected function getData()
 {
     $type = $this->getState('type');
     if ($type === 'validationrule') {
         $item = FabTable::getInstance('Element', 'FabrikTable');
         $item->load($this->getState('id'));
     } else {
         $feModel = $this->getPluginModel();
         $item = $feModel->getTable();
     }
     $data = (array) json_decode($item->params);
     $data['plugin'] = $this->getState('plugin');
     $data['params'] = (array) JArrayHelper::getValue($data, 'params', array());
     $data['params']['plugins'] = $this->getState('plugin');
     $data['validationrule']['plugin'] = $this->getState('plugin');
     $c = $this->getState('c') + 1;
     // Add plugin published state, locations and events
     $state = (array) JArrayHelper::getValue($data, 'plugin_state');
     $locations = (array) JArrayHelper::getValue($data, 'plugin_locations');
     $events = (array) JArrayHelper::getValue($data, 'plugin_events');
     $data['params']['plugin_state'] = JArrayHelper::getValue($state, $c, 1);
     $data['plugin_locations'] = JArrayHelper::getValue($locations, $c);
     $data['plugin_events'] = JArrayHelper::getValue($events, $c);
     return $data;
 }
コード例 #4
0
ファイル: connection.php プロジェクト: juliano-hallac/fabrik
 /**
  * Returns a reference to the a Table object, always creating it.
  *
  * @param	type	The table type to instantiate
  * @param	string	A prefix for the table class name. Optional.
  * @param	array	Configuration array for model. Optional.
  * @return	JTable	A database object
  * @since	1.6
  */
 public function getTable($type = 'Connection', $prefix = 'FabrikTable', $config = array())
 {
     // not sure if we should be loading JTable or FabTable here
     // issue with using Fabtable is that it will always load the cached verion of the cnn
     // which might cause issues when migrating from test to live sites???
     $config['dbo'] = FabriKWorker::getDbo(true);
     return FabTable::getInstance($type, $prefix, $config);
 }
コード例 #5
0
 function getVisualization()
 {
     if (!isset($this->_row)) {
         $this->_row = FabTable::getInstance('Visualization', 'FabrikTable');
         $this->_row->load($this->getState('id'));
     }
     return $this->_row;
 }
コード例 #6
0
ファイル: visualization.php プロジェクト: rhotog/fabrik
 /**
  * if loading via id then we want to get the view name and add the plugin view and model paths
  * @return string view name
  */
 protected function getViewName()
 {
     $viz = FabTable::getInstance('Visualization', 'FabrikTable');
     $viz->load(JRequest::getInt('id'));
     $viewName = $viz->plugin;
     $this->addViewPath(JPATH_SITE . DS . 'plugins' . DS . 'fabrik_visualization' . DS . $viewName . DS . 'views');
     JModel::addIncludePath(JPATH_SITE . DS . 'plugins' . DS . 'fabrik_visualization' . DS . $viewName . DS . 'models');
     return $viewName;
 }
コード例 #7
0
ファイル: visualization.php プロジェクト: glauberm/cinevi
 /**
  * If loading via id then we want to get the view name and add the plugin view and model paths
  *
  * @return   string  view name
  */
 protected function getViewName()
 {
     $viz = FabTable::getInstance('Visualization', 'FabrikTable');
     $viz->load($this->input->getInt('id'));
     $viewName = $viz->plugin;
     $this->addViewPath(JPATH_SITE . '/plugins/fabrik_visualization/' . $viewName . '/views');
     JModelLegacy::addIncludePath(JPATH_SITE . '/plugins/fabrik_visualization/' . $viewName . '/models');
     return $viewName;
 }
コード例 #8
0
ファイル: join.php プロジェクト: nickbunyan/fabrik
 /**
  * load the model from the element id
  * $param string $key
  * @param int $id
  */
 function getJoinFromKey($key, $id)
 {
     if (!isset($this->_join)) {
         $db =& JFactory::getDbo();
         $this->_join = FabTable::getInstance('join', 'FabrikTable');
         $this->_join->load(array($key => $id));
     }
     return $this->_join;
 }
コード例 #9
0
ファイル: import.php プロジェクト: LGBGit/tierno
 /**
  * Returns a reference to the a Table object, always creating it.
  *
  * @param   string $type   The table type to instantiate
  * @param   string $prefix A prefix for the table class name. Optional.
  * @param   array  $config Configuration array for model. Optional.
  *
  * @return  JTable    A database object
  */
 public function getTable($type = 'List', $prefix = 'FabrikTable', $config = array())
 {
     $sig = $type . $prefix . implode('.', $config);
     if (!array_key_exists($sig, $this->tables)) {
         $config['dbo'] = FabrikWorker::getDbo(true);
         $this->tables[$sig] = FabTable::getInstance($type, $prefix, $config);
     }
     return $this->tables[$sig];
 }
コード例 #10
0
ファイル: plugin-cron.php プロジェクト: rogeriocc/fabrik
 /**
  * Get the db row
  *
  * @param   bool  $force  force reload
  *
  * @return  object
  */
 public function &getTable($force = false)
 {
     if (!$this->row || $force) {
         JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_fabrik/tables');
         $row = FabTable::getInstance('Cron', 'FabrikTable');
         $row->load($this->row);
         $this->row = $row;
     }
     return $this->row;
 }
コード例 #11
0
ファイル: fabrik.php プロジェクト: LGBGit/tierno
 /**
  * Method to load and return a model object.
  *
  * @param   string  $name    The name of the view
  * @param   string  $prefix  The class prefix. Optional.
  * @param   array   $config  configuration
  *
  * @return	mixed	Model object or boolean false if failed
  */
 protected function _createTable($name, $prefix = 'Table', $config = array())
 {
     // Clean the model name
     $name = preg_replace('/[^A-Z0-9_]/i', '', $name);
     $prefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix);
     // Make sure we are returning a DBO object
     if (!array_key_exists('dbo', $config)) {
         $config['dbo'] = $this->getDbo();
     }
     return FabTable::getInstance($name, $prefix, $config);
 }
コード例 #12
0
ファイル: cron.php プロジェクト: rogeriocc/fabrik
 /**
  * If loading via id then we want to get the view name and add the plugin view and model paths
  *
  * @return   string  view name
  */
 protected function getViewName()
 {
     if (!isset($this->viewName)) {
         $item = FabTable::getInstance('Cron', 'FabrikTable');
         $item->load(JRequest::getInt('id'));
         $this->viewName = $item->plugin;
         $this->addViewPath(JPATH_SITE . '/plugins/fabrik_cron/' . $this->viewName . '/views');
         $this->addModelPath(JPATH_SITE . '/plugins/fabrik_cron/' . $this->viewName . '/models');
         JModel::addIncludePath(JPATH_SITE . '/plugins/fabrik_cron/' . $this->viewName . '/models');
     }
     return $this->viewName;
 }
コード例 #13
0
ファイル: crons.php プロジェクト: juliano-hallac/fabrik
 public function run()
 {
     $db = FabrikWorker::getDbo(true);
     $cid = JRequest::getVar('cid', array(0), 'method', 'array');
     JArrayHelper::toInteger($cid);
     $cid = implode(',', $cid);
     $query = $db->getQuery(true);
     $query->select('*')->from('#__{package}_cron')->where('id IN (' . $cid . ')');
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     $adminListModel = JModel::getInstance('List', 'FabrikModel');
     //JModel::addIncludePath(JPATH_SITE.DS.'components'.DS.'com_fabrik'.DS.'models');
     $pluginManager = JModel::getInstance('Pluginmanager', 'FabrikFEModel');
     $listModel = JModel::getInstance('list', 'FabrikFEModel');
     $c = 0;
     $log = FabTable::getInstance('Log', 'FabrikTable');
     foreach ($rows as $row) {
         //load in the plugin
         $rowParams = json_decode($row->params);
         $log->message = '';
         $log->id = null;
         $log->referring_url = '';
         $log->message_type = 'plg.cron.' . $row->plugin;
         $plugin =& $pluginManager->getPlugIn($row->plugin, 'cron');
         $table = FabTable::getInstance('cron', 'FabrikTable');
         $table->load($row->id);
         $plugin->setRow($table);
         $params =& $plugin->getParams();
         $thisListModel = clone $listModel;
         $thisAdminListModel = clone $adminListModel;
         $tid = (int) $rowParams->table;
         if ($tid !== 0) {
             $thisListModel->setId($tid);
             $log->message .= "\n\n{$row->plugin}\n listid = " . $thisListModel->getId();
             //. var_export($table);
             if ($plugin->requiresTableData()) {
                 $table =& $listModel->getTable();
                 $data = $thisListModel->getData();
                 $log->message .= "\n" . $thisListModel->_buildQuery();
             }
         } else {
             $data = array();
         }
         // $$$ hugh - added table model param, in case plugin wants to do further table processing
         $c = $c + $plugin->process($data, $thisListModel, $thisAdminListModel);
         if ($plugin->getParams()->get('log', 0) == 1) {
             $log->message = $plugin->getLog() . "\n\n" . $log->message;
             $log->store();
         }
     }
     $this->setRedirect('index.php?option=com_fabrik&view=crons', $c . " records updated");
 }
コード例 #14
0
 /**
  * called via ajax to perform viz ajax task (defined by plugintask method)
  */
 public function display()
 {
     $document = JFactory::getDocument();
     $id = JRequest::getInt('visualizationid');
     $viz = FabTable::getInstance('Visualization', 'FabrikTable');
     $viz->load($id);
     $modelpaths = JModel::addIncludePath(JPATH_SITE . DS . 'plugins' . DS . 'fabrik_visualization' . DS . $viz->plugin . DS . 'models');
     $model = $this->getModel($viz->plugin);
     $model->setId($id);
     $pluginTask = JRequest::getVar('plugintask', '', 'request');
     if ($pluginTask !== '') {
         echo $model->{$pluginTask}();
     }
 }
コード例 #15
0
ファイル: visualization.php プロジェクト: Jobar87/fabrik
	/**
	 * Display the view
	 */

	function display()
	{
		$document = JFactory::getDocument();

		$viewName = str_replace('FabrikControllerVisualization', '', get_class($this));
		if ($viewName == '') {
			// if we are using a url like http://localhost/fabrik3.0.x/index.php?option=com_fabrik&view=visualization&id=6
			// then we need to ascertain which viz to use
			$id = JRequest::getInt('id');
			$viz = FabTable::getInstance('Visualization', 'FabrikTable');

			$viz->load(JRequest::getInt('id'));
			$viewName = $viz->plugin;
			$this->addViewPath(JPATH_SITE.DS.'plugins'.DS.'fabrik_visualization'.DS.$viewName.DS.'views');
			//add the model path
			$modelpaths = JModel::addIncludePath(JPATH_SITE.DS.'plugins'.DS.'fabrik_visualization'.DS.$viewName.DS.'models');
		}
		$viewType	= $document->getType();

		// Set the default view name from the Request
		$view = $this->getView($viewName, $viewType);

		// Push a model into the view

		$model = $this->getModel($viewName);
		if (!JError::isError($model)) {
			$view->setModel($model, true);
		}
		// Display the view
		$view->assign('error', $this->getError());

		// f3 cache with raw view gives error
		if (in_array(JRequest::getCmd('format'), array('raw', 'csv'))) {
			$view->display();
		} else {
			$post = JRequest::get('post');
			//build unique cache id on url, post and user id
			$user = JFactory::getUser();
			$cacheid = serialize(array(JRequest::getURI(), $post, $user->get('id'), get_class($view), 'display', $this->cacheId));
			$cache = JFactory::getCache('com_fabrik', 'view');
			$cache->get($view, 'display', $cacheid);
		}
	}
コード例 #16
0
ファイル: plugin.php プロジェクト: glauberm/cinevi
 /**
  * Get the plugins data to bind to the form
  *
  * @return  array
  */
 protected function getData()
 {
     $type = $this->getState('type');
     $data = array();
     if ($type === 'validationrule') {
         $item = FabTable::getInstance('Element', 'FabrikTable');
         $item->load($this->getState('id'));
     } elseif ($type === 'elementjavascript') {
         $item = FabTable::getInstance('Jsaction', 'FabrikTable');
         $item->load($this->getState('id'));
         $data = $item->getProperties();
     } else {
         $feModel = $this->getPluginModel();
         $item = $feModel->getTable();
     }
     $data = $data + (array) json_decode($item->params);
     $data['plugin'] = $this->getState('plugin');
     $data['params'] = (array) FArrayHelper::getValue($data, 'params', array());
     $data['params']['plugins'] = $this->getState('plugin');
     $data['validationrule']['plugin'] = $this->getState('plugin');
     $data['validationrule']['plugin_published'] = $this->getState('plugin_published');
     $data['validationrule']['show_icon'] = $this->getState('show_icon');
     $data['validationrule']['must_validate'] = $this->getState('must_validate');
     $data['validationrule']['validate_in'] = $this->getState('validate_in');
     $data['validationrule']['validation_on'] = $this->getState('validation_on');
     $c = $this->getState('c') + 1;
     // Add plugin published state, locations, descriptions and events
     $state = (array) FArrayHelper::getValue($data, 'plugin_state');
     $locations = (array) FArrayHelper::getValue($data, 'plugin_locations');
     $events = (array) FArrayHelper::getValue($data, 'plugin_events');
     $descriptions = (array) FArrayHelper::getValue($data, 'plugin_description');
     $data['params']['plugin_state'] = FArrayHelper::getValue($state, $c, 1);
     $data['plugin_locations'] = FArrayHelper::getValue($locations, $c);
     $data['plugin_events'] = FArrayHelper::getValue($events, $c);
     $data['plugin_description'] = FArrayHelper::getValue($descriptions, $c);
     // For list plugins view
     $data['params']['plugin_description'] = FArrayHelper::getValue($descriptions, $c);
     return $data;
 }
コード例 #17
0
ファイル: groups.php プロジェクト: LGBGit/tierno
 /**
  * Returns a reference to the a Table object, always creating it.
  *
  * @param   type    $type    The table type to instantiate
  * @param   string  $prefix  A prefix for the table class name. Optional.
  * @param   array   $config  Configuration array for model. Optional.
  *
  * @return  JTable	A database object
  */
 public function getTable($type = 'Group', $prefix = 'FabrikTable', $config = array())
 {
     $config['dbo'] = FabrikWorker::getDbo();
     return FabTable::getInstance($type, $prefix, $config);
 }
コード例 #18
0
ファイル: visualization.php プロジェクト: ankaau/GathBandhan
 /**
  * Get the item
  *
  * @return  FabrikTableVisualization
  */
 public function getVisualization()
 {
     if (!isset($this->row)) {
         $this->row = FabTable::getInstance('Visualization', 'FabrikTable');
         $this->row->load($this->getState('id'));
         $this->setListIds();
         // Needed to load the language file!
         $pluginManager = FabrikWorker::getPluginManager();
         $plugin = $pluginManager->getPlugIn($this->_row->plugin, 'visualization');
     }
     return $this->row;
 }
コード例 #19
0
ファイル: parent.php プロジェクト: romuland/khparts
 /**
  * log  to table jos_fabrik_logs
  * @param string $type e.g. 'fabrik.fileupload.download'
  * @param mixed $msg array/object/string
  * @param bool $jsonEncode
  */
 public function log($type, $msg, $jsonEncode = true)
 {
     if ($jsonEncode) {
         $msg = json_encode($msg);
     }
     $log = FabTable::getInstance('log', 'FabrikTable');
     $log->message_type = $type;
     $log->message = $msg;
     $log->store();
 }
コード例 #20
0
ファイル: connection.php プロジェクト: rogeriocc/fabrik
 /**
  * Load the default connection
  *
  * @return  object  default connection
  */
 function &loadDefaultConnection()
 {
     if (!$this->_defaultConnection) {
         // $$$ rob connections are pooled for all packages - each package should use
         // jos_fabrik_connections and not jos_{package}_connections
         $row = FabTable::getInstance('Connection', 'FabrikTable');
         $row->load(array('default' => 1));
         $this->_defaultConnection = $row;
     }
     $this->_connection = $this->_defaultConnection;
     return $this->_defaultConnection;
 }
コード例 #21
0
ファイル: package.php プロジェクト: ppantilla/bbninja
 /**
  * create the SQL install file
  *
  * @param   object  $row  package
  *
  * @return  string  path
  */
 protected function makeInstallSQL($row)
 {
     $sql = '';
     $config = JFactory::getConfig();
     $db = FabrikWorker::getDbo(true);
     // Create the sql for the cloned fabrik meta data tables
     foreach ($this->tables as $table) {
         $db->setQuery('SHOW CREATE TABLE ' . $table);
         $tbl = $db->loadRow();
         $tbl = str_replace('_fabrik_', '_' . $row->component_name . '_', $tbl[1]);
         $tbl = str_replace($config->get('dbprefix'), '#__', $tbl);
         $sql .= str_replace('CREATE TABLE', 'CREATE TABLE IF NOT EXISTS', $tbl) . ";\n\n";
         $table = str_replace(array('_fabrik_', '{package}'), array('_' . $row->component_name . '_', $row->component_name), $table);
         $sql .= 'TRUNCATE TABLE ' . $table . ";\n\n";
     }
     foreach ($row->blocks as $block => $ids) {
         $key = FabrikString::rtrimword($block, 's');
     }
     // Create the sql to build the db tables that store the data.
     $formModel = JModelLegacy::getInstance('form', 'FabrikFEModel');
     $lookups = $this->getInstallItems($row);
     $lids = $lookups->list;
     JArrayHelper::toInteger($lids);
     $plugins = array();
     foreach ($lids as $lid) {
         $listModel = JModelLegacy::getInstance('list', 'FabrikFEModel');
         $listModel->setId($lid);
         $sql .= "\n\n" . $listModel->getCreateTableSQL(true);
     }
     foreach ($lookups->form as $fid) {
         $formModel->setId($fid);
         if (!in_array($fid, $lookups->list)) {
             $lookups->list[] = $fid;
         }
         // @FIXME get sql to create tables for dbjoin/cdd elements (need to do if not exists)
         $dbs = $formModel->getElementOptions(false, 'name', true, true, array());
     }
     $sql .= "\n\n";
     if (isset($lookups->visualization)) {
         $vrow = FabTable::getInstance('Visualization', 'FabrikTable');
         $vrow->load($vid);
         $visModel = JModelLegacy::getInstance($vrow->plugin, 'fabrikModel');
         $visModel->setId($vid);
         $listModels = $visModel->getlistModels();
         foreach ($listModels as $lmodel) {
             $vrow = FabTable::getInstance('Visualization', 'FabrikTable');
             $vrow->load($vid);
             $visModel = JModel::getInstance($vrow->plugin, 'fabrikModel');
             $visModel->setId($vid);
             $listModels = $visModel->getlistModels();
             foreach ($listModels as $lmodel) {
                 $sql .= $lmodel->getCreateTableSQL(true);
                 // Add the table ids to the $lookups->list
                 if (!in_array($lmodel->getId(), $lookups->list)) {
                     $lookups->list[] = $lmodel->getId();
                 }
             }
         }
     }
     $path = $this->outputPath . 'admin/sql/install.mysql.uft8.sql';
     JFile::write($path, $sql);
     return $path;
 }
コード例 #22
0
ファイル: fabrikcron.php プロジェクト: rogeriocc/fabrik
 /**
  * Run all active cron jobs
  *
  * @return void
  */
 protected function doCron()
 {
     $app = JFactory::getApplication();
     if ($app->isAdmin() || JRequest::getVar('option') == 'com_acymailing') {
         return;
     }
     // $$$ hugh - don't want to run on things like AJAX calls
     if (JRequest::getVar('format', '') == 'raw') {
         return;
     }
     // Get all active tasks
     $db = FabrikWorker::getDbo(true);
     $now = JRequest::getVar('fabrikcron_run', false);
     $log = FabTable::getInstance('Log', 'FabrikTable');
     if (!$now) {
         /* $$$ hugh - changed from using NOW() to JFactory::getDate(), to avoid time zone issues, see:
          * http://fabrikar.com/forums/showthread.php?p=102245#post102245
          * .. which seems reasonable, as we use getDate() to set 'lastrun' to at the end of this func
          */
         $nextrun = "CASE " . "WHEN unit = 'second' THEN DATE_ADD( lastrun, INTERVAL frequency SECOND )\n" . "WHEN unit = 'minute' THEN DATE_ADD( lastrun, INTERVAL frequency MINUTE )\n" . "WHEN unit = 'hour' THEN DATE_ADD( lastrun, INTERVAL frequency HOUR )\n" . "WHEN unit = 'day' THEN DATE_ADD( lastrun, INTERVAL frequency DAY )\n" . "WHEN unit = 'week' THEN DATE_ADD( lastrun, INTERVAL frequency WEEK )\n" . "WHEN unit = 'month' THEN DATE_ADD( lastrun, INTERVAL frequency MONTH )\n" . "WHEN unit = 'year' THEN DATE_ADD( lastrun, INTERVAL frequency YEAR ) END";
         $query = "SELECT id, plugin, lastrun, unit, frequency, {$nextrun} AS nextrun FROM #__{package}_cron\n";
         $query .= "WHERE published = '1' ";
         $query .= "AND {$nextrun} < '" . JFactory::getDate()->toSql() . "'";
     } else {
         $query = "SELECT id, plugin FROM #__{package}_cron WHERE published = '1'";
     }
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     if (empty($rows)) {
         return;
     }
     $log->message = '';
     /* $$$ hugh - set 'state' to 2 for selected rows, so we don't end up running
      * multiple copies, if this code is run again before selected plugins have
      * finished running, see:
      * http://fabrikar.com/forums/showthread.php?p=114008#post114008
      */
     $ids = array();
     foreach ($rows as $row) {
         $ids[] = (int) $row->id;
     }
     $query = $db->getQuery(true);
     $query->update('#__{package}_cron')->set('published = 2')->where('id IN (' . implode(',', $ids) . ')');
     $db->setQuery($query);
     $db->query();
     JModel::addIncludePath(JPATH_SITE . '/components/com_fabrik/models');
     $pluginManager = JModel::getInstance('Pluginmanager', 'FabrikFEModel');
     $listModel = JModel::getInstance('list', 'FabrikFEModel');
     foreach ($rows as $row) {
         $log->message = '';
         $log->id = null;
         $log->referring_url = '';
         // Load in the plugin
         $plugin = $pluginManager->getPluginFromId($row->id, 'Cron');
         $log->message_type = 'plg.cron.' . $row->plugin;
         if (!$plugin->queryStringActivated()) {
             // $$$ hugh - don't forget to make it runnable again before continuing
             $query->clear();
             $query->update('#__{package}_cron')->set('published = 1')->where('id = ' . $row->id);
             $db->setQuery($query);
             $db->query();
             continue;
         }
         $tid = (int) $plugin->getParams()->get('table');
         $thisListModel = clone $listModel;
         if ($tid !== 0) {
             $thisListModel->setId($tid);
             $log->message .= "\n\n{$row->plugin}\n listid = " . $thisListModel->getId();
             if ($plugin->requiresTableData()) {
                 $table = $thisListModel->getTable();
                 $total = $thisListModel->getTotalRecords();
                 $nav = $thisListModel->getPagination($total, 0, $total);
                 $data = $thisListModel->getData();
                 $log->message .= "\n" . $thisListModel->_buildQuery();
             }
         } else {
             $data = array();
         }
         $res = $plugin->process($data, $thisListModel);
         $log->message = $plugin->getLog() . "\n\n" . $log->message;
         $now = JFactory::getDate();
         $now = $now->toUnix();
         $new = JFactory::getDate($row->nextrun);
         $tmp = $new->toUnix();
         switch ($row->unit) {
             case 'second':
                 $inc = 1;
                 break;
             case 'minute':
                 $inc = 60;
                 break;
             case 'hour':
                 $inc = 60 * 60;
                 break;
             default:
             case 'day':
                 $inc = 60 * 60 * 24;
                 break;
         }
         /* Don't use NOW() as the last run date as this could mean that the cron
          * jobs aren't run as frequently as specified
          * if the lastrun date was set in admin to ages ago, then incrementally increase the
          * last run date until it is less than now
          */
         while ($tmp + $inc * $row->frequency < $now) {
             $tmp = $tmp + $inc * $row->frequency;
         }
         // Mark them as being run
         // $$$ hugh - and make it runnable again by setting 'state' back to 1
         $nextrun = JFactory::getDate($tmp);
         $query->clear();
         $query->update('#__{package}_cron')->set('published = 1, lastrun = ' . $db->quote($nextrun->toSql()))->where('id = ' . $row->id);
         $db->setQuery($query);
         $db->query();
         // Log if asked for
         if ($plugin->getParams()->get('log', 0) == 1) {
             $log->store();
         }
     }
 }
コード例 #23
0
ファイル: fabsubs.php プロジェクト: rogeriocc/fabrik
        }
        $res = JUtility::sendMail($mailfrom, $fromname, $row->email, $mail->subject, $mail->body, true);
    }
}
//send email reminders to active subs in old acctexpt table:
//last date this should be used from is 09/03/2011
$db->setQuery("SELECT s.id AS subid, email, name, `type` AS subscription, username,\ndatediff(expiration, now()) AS daysleft, expiration as renew_date\nFROM `#__acctexp_subscr` as s\nleft join #__users as u on s.userid = u.id\nwhere status = 'Active' and plan != 2 and plan !=3\n");
$res = $db->loadObjectList();
foreach ($res as $row) {
    if (array_key_exists($row->daysleft, $expiration_mails)) {
        $mail = clone $expiration_mails[$row->daysleft];
        foreach ($row as $k => $v) {
            $mail->subject = str_replace('{' . $k . '}', $v, $mail->subject);
            $mail->body = str_replace('{' . $k . '}', $v, $mail->body);
        }
        $res = JUtility::sendMail($mailfrom, $fromname, $row->email, $mail->subject, $mail->body, true);
    }
}
//expire non recurring subs that have expired. Create fall back plan if required
$db->setQuery("SELECT s.id AS subid\nFROM `fabsubs_subscriptions` AS s\nINNER JOIN fabsubs_plans AS p ON p.id = s.plan\n WHERE status = 'Active' AND lifetime = 0 AND recurring = 0 AND CASE\n\tWHEN p.period_unit = 'Y' THEN datediff(date_add(lastpay_date , interval p.duration year), now())\n\tWHEN p.period_unit = 'M' THEN datediff(date_add(lastpay_date , interval p.duration month), now())\n\tWHEN p.period_unit = 'W' THEN datediff(date_add(lastpay_date , interval p.duration week), now())\n\tWHEN p.period_unit = 'D' THEN datediff(date_add(lastpay_date , interval p.duration day), now())\n  END <= 0\n\n  OR ( expiration != '0000-00-00 00:00:00' AND\n  CASE\n\tWHEN p.period_unit = 'Y' THEN datediff(date_add(expiration , interval p.duration year), now())\n\tWHEN p.period_unit = 'M' THEN datediff(date_add(expiration , interval p.duration month), now())\n\tWHEN p.period_unit = 'W' THEN datediff(date_add(expiration , interval p.duration week), now())\n\tWHEN p.period_unit = 'D' THEN datediff(date_add(expiration , interval p.duration day), now())\n  END <= 0\n  )\n ");
$ipn = new fabrikPayPalIPN();
$rows = $db->loadObjectList();
$now = JFactory::getDate()->toSql();
$sub = FabTable::getInstance('Subscriptions', 'FabrikTable');
foreach ($rows as $row) {
    $sub->load($row->subid);
    $sub->status = 'Expired';
    $sub->eot_date = $now;
    $sub->store();
    $ipn->fallbackPlan($sub);
}
コード例 #24
0
ファイル: element.php プロジェクト: rhotog/fabrik
 /**
  * Returns a reference to the a Table object, always creating it.
  *
  * @param	type	The table type to instantiate
  * @param	string	A prefix for the table class name. Optional.
  * @param	array	Configuration array for model. Optional.
  * @return	JTable	A database object
  * @since	1.6
  */
 public function getTable($type = 'Element', $prefix = 'FabrikTable', $config = array())
 {
     $config['dbo'] = FabriKWorker::getDbo(true);
     return FabTable::getInstance($type, $prefix, $config);
 }
コード例 #25
0
 function &getValidationRule()
 {
     if (!$this->_rule) {
         JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_fabrik' . DS . 'tables');
         $row = FabTable::getInstance('Validationrule', 'FabrikTable');
         $row->load($this->_id);
         $this->_rule = $row;
     }
     return $this->_rule;
 }
コード例 #26
0
ファイル: article.php プロジェクト: juliano-hallac/fabrik
 function saveArticle()
 {
     // Initialize variables
     $db =& FabrikWorker::getDbo();
     $user =& JFactory::getUser();
     $dispatcher =& JDispatcher::getInstance();
     JPluginHelper::importPlugin('content');
     $this->_postFabrikDataAsArticleData();
     $details = JRequest::getVar('details', array(), 'post', 'array');
     $option = JRequest::getCmd('option');
     $sectionid = JRequest::getVar('sectionid', 0, '', 'int');
     $nullDate = $db->getNullDate();
     $row =& FabTable::getInstance('content');
     if (!$row->bind(JRequest::get('post'))) {
         JError::raiseError(500, $db->stderr());
         return false;
     }
     $row->bind($details);
     // sanitise id field
     $row->id = (int) $row->id;
     $this->_isNew = true;
     // Are we saving from an item edit?
     if ($row->id) {
         $this->_isNew = false;
         $datenow = JFactory::getDate();
         $row->modified = $datenow->toMySQL();
         $row->modified_by = $user->get('id');
     }
     $row->created_by = $row->created_by ? $row->created_by : $user->get('id');
     if ($row->created && strlen(trim($row->created)) <= 10) {
         $row->created .= ' 00:00:00';
     }
     $config =& JFactory::getConfig();
     $tzoffset = $config->getValue('config.offset');
     $date =& JFactory::getDate($row->created, $tzoffset);
     $row->created = $date->toMySQL();
     // Append time if not added to publish date
     if (strlen(trim($row->publish_up)) <= 10) {
         $row->publish_up .= ' 00:00:00';
     }
     $date =& JFactory::getDate($row->publish_up, $tzoffset);
     $row->publish_up = $date->toMySQL();
     // Handle never unpublish date
     if (trim($row->publish_down) == JText::_('Never') || trim($row->publish_down) == '') {
         $row->publish_down = $nullDate;
     } else {
         if (strlen(trim($row->publish_down)) <= 10) {
             $row->publish_down .= ' 00:00:00';
         }
         $date =& JFactory::getDate($row->publish_down, $tzoffset);
         $row->publish_down = $date->toMySQL();
     }
     // Get a state and parameter variables from the request
     // should probably punt this logic into the controller, but for now ...
     $articlePublishElementName = $this->_elementBaseName($this->_articlePublishElement);
     $row->state = $this->_formModel->_formData[$articlePublishElementName];
     // probably an array, i.e. coming from a yes/no radio or dropdown
     if (is_array($row->state)) {
         $row->state = $row->state[0];
     }
     $params = JRequest::getVar('params', null, 'post', 'array');
     $row->params = json_encode($params);
     // Get metadata string
     $metadata = JRequest::getVar('meta', null, 'post', 'array');
     if (is_array($metadata)) {
         $txt = array();
         foreach ($metadata as $k => $v) {
             if ($k == 'description') {
                 $row->metadesc = $v;
             } elseif ($k == 'keywords') {
                 $row->metakey = $v;
             } else {
                 $txt[] = "{$k}={$v}";
             }
         }
         $row->metadata = implode("\n", $txt);
     }
     // Prepare the content for saving to the database
     ContentHelper::saveContentPrep($row);
     // Make sure the data is valid
     if (!$row->check()) {
         JError::raiseError(500, $db->stderr());
         return false;
     }
     // Increment the content version number
     $row->version++;
     $result = $dispatcher->trigger('onBeforeContentSave', array(&$row, $this->_isNew));
     if (in_array(false, $result, true)) {
         JError::raiseError(500, $row->getError());
         return false;
     }
     // Store the content to the database
     if (!$row->store()) {
         JError::raiseError(500, $db->stderr());
         return false;
     }
     $this->_articleId = $row->id;
     // Check the article and update item order
     $row->checkin();
     $row->reorder('catid = ' . (int) $row->catid . ' AND state >= 0');
     //		*
     //		 * We need to update frontpage status for the article.
     //		 *
     //		 * First we include the frontpage table and instantiate an instance of it.
     //		 *
     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_frontpage' . DS . 'tables' . DS . 'frontpage.php';
     $fp = new TableFrontPage($db);
     // Is the article viewable on the frontpage?
     if (JRequest::getVar('frontpage', 0, '', 'int')) {
         // Is the item already viewable on the frontpage?
         if (!$fp->load($row->id)) {
             // Insert the new entry
             $query = 'INSERT INTO #__content_frontpage' . ' VALUES ( ' . (int) $row->id . ', 1 )';
             $db->setQuery($query);
             if (!$db->query()) {
                 JError::raiseError(500, $db->stderr());
                 return false;
             }
             $fp->ordering = 1;
         }
     } else {
         // Delete the item from frontpage if it exists
         if (!$fp->delete($row->id)) {
             $msg .= $fp->stderr();
         }
         $fp->ordering = 0;
     }
     $fp->reorder();
     $cache =& JFactory::getCache('com_content');
     $cache->clean();
     $dispatcher->trigger('onAfterContentSave', array(&$row, $this->_isNew));
 }
コード例 #27
0
ファイル: paypal.php プロジェクト: rogeriocc/fabrik
 /**
  * Called from paypal at the end of the transaction
  *
  * @return  void
  */
 public function onIpn()
 {
     $config = JFactory::getConfig();
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_fabrik/tables');
     $log = FabTable::getInstance('log', 'FabrikTable');
     $log->referring_url = $_SERVER['REQUEST_URI'];
     $log->message_type = 'fabrik.ipn.start';
     $log->message = json_encode($_REQUEST);
     $log->store();
     // Lets try to load in the custom returned value so we can load up the form and its parameters
     $custom = JRequest::getVar('custom');
     list($formid, $rowid, $ipn_value) = explode(":", $custom);
     // Pretty sure they are added but double add
     JModel::addIncludePath(COM_FABRIK_FRONTEND . '/models');
     $formModel = JModel::getInstance('Form', 'FabrikFEModel');
     $formModel->setId($formid);
     $listModel = $formModel->getlistModel();
     $params = $formModel->getParams();
     $table = $listModel->getTable();
     $db = $listModel->getDb();
     $query = $db->getQuery(true);
     /* $$$ hugh
      * @TODO shortColName won't handle joined data, need to fix this to use safeColName
      * (don't forget to change quoteName stuff later on as well)
      */
     $renderOrder = JRequest::getInt('renderOrder');
     $ipn_txn_field = (array) $params->get('paypal_ipn_txn_id_element', array());
     $ipn_txn_field = FabrikString::shortColName($ipn_txn_field[$renderOrder]);
     $ipn_payment_field = (array) $params->get('paypal_ipn_payment_element', array());
     $ipn_payment_field = FabrikString::shortColName($ipn_payment_field[$renderOrder]);
     $ipn_field = (array) $params->get('paypal_ipn_element', array());
     $ipn_field = FabrikString::shortColName($ipn_field[$renderOrder]);
     $ipn_status_field = (array) $params->get('paypal_ipn_status_element', array());
     $ipn_status_field = FabrikString::shortColName($ipn_status_field[$renderOrder]);
     $ipn_address_field = (array) $params->get('paypal_ipn_address_element', array());
     $ipn_address_field = FabrikString::shortColName($ipn_address_field[$renderOrder]);
     $w = new FabrikWorker();
     $ipn_value = str_replace('[', '{', $ipn_value);
     $ipn_value = str_replace(']', '}', $ipn_value);
     $ipn_value = $w->parseMessageForPlaceHolder($ipn_value, $_POST);
     $email_from = $admin_email = $config->get('mailfrom');
     // Read the post from PayPal system and add 'cmd'
     $req = 'cmd=_notify-validate';
     foreach ($_POST as $key => $value) {
         $value = urlencode(stripslashes($value));
         $req .= "&{$key}={$value}";
     }
     // Post back to PayPal system to validate
     $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
     $header .= "Host: www.paypal.com:443\r\n";
     $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
     $header .= "Content-Length: " . JString::strlen($req) . "\r\n\r\n";
     if ($_POST['test_ipn'] == 1) {
         $paypalurl = 'ssl://www.sandbox.paypal.com';
     } else {
         $paypalurl = 'ssl://www.paypal.com';
     }
     // Assign posted variables to local variables
     $item_name = JRequest::getVar('item_name');
     $item_number = JRequest::getVar('item_number');
     $payment_status = JRequest::getVar('payment_status');
     $payment_amount = JRequest::getVar('mc_gross');
     $payment_currency = JRequest::getVar('mc_currency');
     $txn_id = JRequest::getVar('txn_id');
     $txn_type = JRequest::getVar('txn_type');
     $receiver_email = JRequest::getVar('receiver_email');
     $payer_email = JRequest::getVar('payer_email');
     $buyer_address = JRequest::getVar('address_status') . ' - ' . JRequest::getVar('address_street') . ' ' . JRequest::getVar('address_zip') . ' ' . JRequest::getVar('address_state') . ' ' . JRequest::getVar('address_city') . ' ' . JRequest::getVar('address_country_code');
     $status = 'ok';
     $err_msg = '';
     if (empty($formid) || empty($rowid)) {
         $status = 'form.paypal.ipnfailure.custom_error';
         $err_msg = "formid or rowid empty in custom: {$custom}";
     } else {
         // @TODO implement a curl alternative as fsockopen is not always available
         $fp = fsockopen($paypalurl, 443, $errno, $errstr, 30);
         if (!$fp) {
             $status = 'form.paypal.ipnfailure.fsock_error';
             $err_msg = "fsock error: {$errno};{$errstr}";
         } else {
             fputs($fp, $header . $req);
             while (!feof($fp)) {
                 $res = fgets($fp, 1024);
                 /* paypal steps (from their docs):
                  * check the payment_status is Completed
                  * check that txn_id has not been previously processed
                  * check that receiver_email is your Primary PayPal email
                  * check that payment_amount/payment_currency are correct
                  * process payment
                  */
                 if (JString::strcmp($res, "VERIFIED") == 0) {
                     // $$tom This block Paypal from updating the IPN field if the payment status evolves (e.g. from Pending to Completed)
                     // $$$ hugh - added check of status, so only barf if there is a status field, and it is Completed for this txn_id
                     if (!empty($ipn_txn_field) && !empty($ipn_status_field)) {
                         $query->clear();
                         $query->select($ipn_status_field)->from($table->db_table_name)->where($db->quoteName($ipn_txn_field) . ' = ' . $db->quote($txn_id));
                         $db->setQuery($query);
                         $txn_result = $db->loadResult();
                         if (!empty($txn_result)) {
                             if ($txn_result == 'Completed') {
                                 if ($payment_status != 'Reversed' && $payment_status != 'Refunded') {
                                     $status = 'form.paypal.ipnfailure.txn_seen';
                                     $err_msg = "transaction id already seen as Completed, new payment status makes no sense: {$txn_id}, {$payment_status}";
                                 }
                             } elseif ($txn_result == 'Reversed') {
                                 if ($payment_status != 'Canceled_Reversal') {
                                     $status = 'form.paypal.ipnfailure.txn_seen';
                                     $err_msg = "transaction id already seen as Reversed, new payment status makes no sense: {$txn_id}, {$payment_status}";
                                 }
                             }
                         }
                     }
                     if ($status == 'ok') {
                         $set_list = array();
                         if (!empty($ipn_field)) {
                             if (empty($ipn_value)) {
                                 $ipn_value = $txn_id;
                             }
                             $set_list[$ipn_field] = $ipn_value;
                         }
                         if (!empty($ipn_txn_field)) {
                             $set_list[$ipn_txn_field] = $txn_id;
                         }
                         if (!empty($ipn_payment_field)) {
                             $set_list[$ipn_payment_field] = $payment_amount;
                         }
                         if (!empty($ipn_status_field)) {
                             $set_list[$ipn_status_field] = $payment_status;
                         }
                         if (!empty($ipn_address_field)) {
                             $set_list[$ipn_address_field] = $buyer_address;
                         }
                         $ipn = $this->getIPNHandler($params, $renderOrder);
                         if ($ipn !== false) {
                             $request = $_REQUEST;
                             $ipn_function = 'payment_status_' . $payment_status;
                             if (method_exists($ipn, $ipn_function)) {
                                 $status = $ipn->{$ipn_function}($listModel, $request, $set_list, $err_msg);
                                 if ($status != 'ok') {
                                     break;
                                 }
                             }
                             $txn_type_function = "txn_type_" . $txn_type;
                             if (method_exists($ipn, $txn_type_function)) {
                                 $status = $ipn->{$txn_type_function}($listModel, $request, $set_list, $err_msg);
                                 if ($status != 'ok') {
                                     break;
                                 }
                             }
                         }
                         if (!empty($set_list)) {
                             $set_array = array();
                             foreach ($set_list as $set_field => $set_value) {
                                 $set_value = $db->quote($set_value);
                                 $set_field = $db->quoteName($set_field);
                                 $set_array[] = "{$set_field} = {$set_value}";
                             }
                             $query->clear();
                             $query->update($table->db_table_name)->set(implode(',', $set_array))->where($table->db_primary_key . ' = ' . $db->quote($rowid));
                             $db->setQuery($query);
                             if (!$db->query()) {
                                 $status = 'form.paypal.ipnfailure.query_error';
                                 $err_msg = 'sql query error: ' . $db->getErrorMsg();
                             }
                         }
                     }
                 } elseif (JString::strcmp($res, "INVALID") == 0) {
                     $status = 'form.paypal.ipnfailure.invalid';
                     $err_msg = 'paypal postback failed with INVALID';
                 }
             }
             fclose($fp);
         }
     }
     $receive_debug_emails = (array) $params->get('paypal_receive_debug_emails');
     $receive_debug_emails = $receive_debug_emails[$renderOrder];
     $send_default_email = (array) $params->get('paypal_send_default_email');
     $send_default_email = $send_default_email[$renderOrder];
     if ($status != 'ok') {
         foreach ($_POST as $key => $value) {
             $emailtext .= $key . " = " . $value . "\n\n";
         }
         if ($receive_debug_emails == '1') {
             $subject = $config->get('sitename') . ": Error with PayPal IPN from Fabrik";
             JUtility::sendMail($email_from, $email_from, $admin_email, $subject, $emailtext, false);
         }
         $log->message_type = $status;
         $log->message = $emailtext . "\n//////////////\n" . $res . "\n//////////////\n" . $req . "\n//////////////\n" . $err_msg;
         if ($send_default_email == '1') {
             $payer_emailtext = "There was an error processing your PayPal payment.  The administrator of this site has been informed.";
             JUtility::sendMail($email_from, $email_from, $payer_email, $subject, $payer_emailtext, false);
         }
     } else {
         foreach ($_POST as $key => $value) {
             $emailtext .= $key . " = " . $value . "\n\n";
         }
         if ($receive_debug_emails == '1') {
             $subject = $config->get('sitename') . ': IPN ' . $payment_status;
             JUtility::sendMail($email_from, $email_from, $admin_email, $subject, $emailtext, false);
         }
         $log->message_type = 'form.paypal.ipn.' . $payment_status;
         $query = $db->getQuery();
         $log->message = $emailtext . "\n//////////////\n" . $res . "\n//////////////\n" . $req . "\n//////////////\n" . $query;
         if ($send_default_email == '1') {
             $payer_subject = "PayPal success";
             $payer_emailtext = "Your PayPal payment was succesfully processed.  The PayPal transaction id was {$txn_id}";
             JUtility::sendMail($email_from, $email_from, $payer_email, $payer_subject, $payer_emailtext, false);
         }
     }
     $log->message .= "\n IPN custom function = {$ipn_function}";
     $log->message .= "\n IPN custom transaction function = {$txn_type_function}";
     $log->store();
     jexit();
 }
コード例 #28
0
ファイル: crons.php プロジェクト: LGBGit/tierno
 /**
  * Run the selected cron plugins
  *
  * @return  void
  */
 public function run()
 {
     $mailer = JFactory::getMailer();
     $config = JFactory::getConfig();
     $db = FabrikWorker::getDbo(true);
     $app = JFactory::getApplication();
     $input = $app->input;
     $cid = $input->get('cid', array(), 'array');
     JArrayHelper::toInteger($cid);
     $cid = implode(',', $cid);
     $query = $db->getQuery(true);
     $query->select('*')->from('#__{package}_cron')->where('id IN (' . $cid . ')');
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     $adminListModel = JModelLegacy::getInstance('List', 'FabrikAdminModel');
     $pluginManager = JModelLegacy::getInstance('Pluginmanager', 'FabrikFEModel');
     $listModel = JModelLegacy::getInstance('list', 'FabrikFEModel');
     $c = 0;
     $this->log = FabTable::getInstance('Log', 'FabrikTable');
     register_shutdown_function(array($this, 'shutdownHandler'));
     foreach ($rows as $row) {
         // Load in the plugin
         $rowParams = json_decode($row->params);
         $this->log->message = '';
         $this->log->id = null;
         $this->log->referring_url = '';
         $this->log->message_type = 'plg.cron.' . $row->plugin;
         $plugin = $pluginManager->getPlugIn($row->plugin, 'cron');
         $table = FabTable::getInstance('cron', 'FabrikTable');
         $table->load($row->id);
         $plugin->setRow($table);
         $plugin->getParams();
         $thisListModel = clone $listModel;
         $thisAdminListModel = clone $adminListModel;
         $tid = (int) $rowParams->table;
         if ($tid !== 0) {
             $thisListModel->setId($tid);
             $this->log->message .= "\n\n{$row->plugin}\n listid = " . $thisListModel->getId();
             if ($plugin->requiresTableData()) {
                 $thisListModel->setLimits(0, 0);
                 $thisListModel->getPagination(0, 0, 0);
                 $data = $thisListModel->getData();
             }
         } else {
             $data = array();
         }
         $this->runningId = $row->id;
         // $$$ hugh - added table model param, in case plugin wants to do further table processing
         $c = $c + $plugin->process($data, $thisListModel, $thisAdminListModel);
         $this->log->message = $plugin->getLog() . "\n\n" . $this->log->message;
         if ($plugin->getParams()->get('log', 0) == 1) {
             $this->log->store();
         }
         // Email log message
         $recipient = $plugin->getParams()->get('log_email', '');
         if ($recipient != '') {
             $recipient = explode(',', $recipient);
             $subject = $config->get('sitename') . ': ' . $row->plugin . ' scheduled task';
             $mailer->sendMail($config->get('mailfrom'), $config->get('fromname'), $recipient, $subject, $this->log->message, true);
         }
     }
     $this->setRedirect('index.php?option=com_fabrik&view=crons', $c . ' records updated');
 }
コード例 #29
0
ファイル: list.php プロジェクト: jfquestiaux/fabrik
 /**
  * Alter the forms' data collection table when the forms' groups and/or
  * elements are altered
  *
  * @return void|JError
  */
 public function ammendTable()
 {
     $db = FabrikWorker::getDbo(true);
     $input = $this->app->input;
     $query = $db->getQuery(true);
     $table = $this->table;
     $amend = false;
     $tableName = $table->db_table_name;
     $fabrikDb = $this->getDb();
     $columns = $fabrikDb->getTableColumns($tableName);
     $existingFields = array_keys($columns);
     $existingFields = array_map('strtolower', $existingFields);
     $lastField = empty($existingFields) ? '' : $existingFields[count($existingFields) - 1];
     $sql = 'ALTER TABLE ' . $db->qn($tableName) . ' ';
     $sqlAdd = array();
     // $$$ hugh - looks like this is now an array in jform
     $jForm = $input->get('jform', array(), 'array');
     $arGroups = FArrayHelper::getValue($jForm, 'current_groups', array(), 'array');
     if (empty($arGroups)) {
         // Get a list of groups used by the form
         $query->select('group_id')->from('#__{package}_formgroup')->where('form_id = ' . (int) $this->getFormModel()->getId());
         $db->setQuery($query);
         $groups = $db->loadObjectList();
         $arGroups = array();
         foreach ($groups as $g) {
             $arGroups[] = $g->group_id;
         }
     }
     $arAddedObj = array();
     foreach ($arGroups as $group_id) {
         $group = FabTable::getInstance('Group', 'FabrikTable');
         $group->load($group_id);
         if ($group->is_join == '0') {
             $query->clear();
             $query->select('*')->from('#__{package}_elements')->where('group_id = ' . (int) $group_id);
             $db->setQuery($query);
             $elements = $db->loadObjectList();
             foreach ($elements as $obj) {
                 $objName = $obj->name;
                 /*
                  * Do the check in lowercase (we already strtowlower()'ed $existingFields up there ^^,
                  * because MySQL field names are case insensitive, so if the element is called 'foo' and there
                  * is a column called 'Foo', and we try and create 'foo' on the table ... it'll blow up.
                  *
                  * However, leave the $objName unchanged, so if we do create a column for it, it uses the case
                  * they specific in the element name - it's not up to us to force their column naming to all lower,
                  * we just need to avoid clashes.
                  *
                  * @TODO We might consider detecting and raising a warning about case inconsistencies?
                  */
                 if (!in_array(strtolower($objName), $existingFields)) {
                     // Make sure that the object is not already in the table
                     if (!in_array($objName, $arAddedObj)) {
                         // Any elements that are names the same (eg radio buttons) can not be entered twice into the database
                         $arAddedObj[] = $objName;
                         $pluginClassName = $obj->plugin;
                         $plugin = $this->pluginManager->getPlugIn($pluginClassName, 'element');
                         if (is_object($plugin)) {
                             $plugin->setId($obj->id);
                             $objType = $plugin->getFieldDescription();
                         } else {
                             $objType = 'VARCHAR(255)';
                         }
                         if ($objName != '' && !is_null($objType)) {
                             $amend = true;
                             $add = 'ADD COLUMN ' . $db->qn($objName) . ' ' . $objType . ' null';
                             if ($lastField !== '') {
                                 $add .= ' AFTER ' . $db->qn($lastField);
                             }
                             $sqlAdd[] = $add;
                         }
                     }
                 }
             }
         }
     }
     if ($amend) {
         $sql .= implode(', ', $sqlAdd);
         $fabrikDb->setQuery($sql);
         try {
             $fabrikDb->execute();
         } catch (Exception $e) {
             JError::raiseWarning(500, 'amend table: ' . $e->getMessage());
         }
     }
 }
コード例 #30
0
ファイル: form.php プロジェクト: Jobar87/fabrik
/**
 *  delete form and form groups
 * @param array $cids to delete
 */

public function delete($cids)
{
	$res = parent::delete($cids);
	if ($res) {
		foreach ($cids as $cid) {
			$item = FabTable::getInstance('FormGroup', 'FabrikTable');
			$item->load(array('form_id'=> $cid));
			$item->delete();
		}
	}
	return $res;
}