Пример #1
0
 /**
  * getPreview
  *
  * @param   object  &$feed  Params
  *
  * @return	object
  */
 public function getPreview(&$feed)
 {
     if (isset($feed->params)) {
         $feed->xtform = EForm::paramsToRegistry($feed);
     }
     $import_limit = $feed->xtform->get('import_limit');
     $feed->xtform->set('import_limit', 3);
     $check_existing = $feed->xtform->get('check_existing');
     $feed->xtform->set('check_existing', 0);
     $loadResult = null;
     try {
         $start_time = time();
         $feedImporterHelper = new FeedImporterHelper();
         $feedProcessorHelper = new FeedProcessorHelper();
         $feedGeneratorHelper = new FeedGeneratorHelper();
         $loadResult = $feedImporterHelper->import($feed);
         $contents = $feedProcessorHelper->process($feed, $loadResult);
         $feedGeneratorHelper->execute($contents, $feed->xtform, true);
         $loadResult->processed_time = time() - $start_time;
         $loadResult->preview = $contents;
     } catch (Exception $e) {
         ELog::showMessage($e->getMessage(), JLog::ERROR);
     }
     $feed->xtform->set('import_limit', $import_limit);
     $feed->xtform->set('check_existing', $check_existing);
     return $loadResult;
 }
Пример #2
0
 /**
  * Method to get a form object.
  *
  * @param	string		$xml		The form data. Can be XML string if file flag is set to false.
  * @param	array		$options	Optional array of parameters.
  * @param	boolean		$clear		Optional argument to force load a new form.
  * @return	mixed		JForm object on success, False on error.
  */
 public function &getForm($xml = null, $name = 'form', $options = array(), $clear = false)
 {
     if ($xml === null) {
         $xml = strtolower($this->getName());
     }
     // Handle the optional arguments.
     $options['array'] = array_key_exists('array', $options) ? $options['array'] : 'jform';
     $options['file'] = array_key_exists('file', $options) ? $options['file'] : true;
     $options['event'] = array_key_exists('event', $options) ? $options['event'] : null;
     $options['group'] = array_key_exists('group', $options) ? $options['group'] : null;
     // Create a signature hash.
     $hash = md5($xml . serialize($options));
     // Check if we can use a previously loaded form.
     if (isset($this->_forms[$hash]) && !$clear) {
         return $this->_forms[$hash];
     }
     // Get the form.
     EForm::addFormPath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'forms');
     EForm::addFieldPath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'fields');
     EFormValidator::addRulePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'rules');
     $app = JFactory::getApplication();
     if ($app->isSite()) {
         EForm::addFormPath(JPATH_COMPONENT_SITE . DS . 'models' . DS . 'forms');
         EForm::addFieldPath(JPATH_COMPONENT_SITE . DS . 'models' . DS . 'fields');
         EFormValidator::addRulePath(JPATH_COMPONENT_SITE . DS . 'models' . DS . 'rules');
     }
     $form =& EForm::getInstance($xml, $name, $options['file'], $options);
     // Check for an error.
     if (JError::isError($form)) {
         $this->setError($form->getMessage());
         $false = false;
         return $form;
     }
     // Look for an event to fire.
     if ($options['event'] !== null) {
         // Get the dispatcher.
         $dispatcher =& JDispatcher::getInstance();
         // Load an optional plugin group.
         if ($options['group'] !== null) {
             JPluginHelper::importPlugin($options['group']);
         }
         // Trigger the form preparation event.
         $results = $dispatcher->trigger($options['event'], array($form->getName(), $form));
         // Check for errors encountered while preparing the form.
         if (count($results) && in_array(false, $results, true)) {
             // Get the last error.
             $error = $dispatcher->getError();
             // Convert to a JException if necessary.
             if (!JError::isError($error)) {
                 $error = new JException($error, 500);
             }
             return $error;
         }
     }
     // Store the form for later.
     $this->_forms[$hash] = $form;
     return $form;
 }
Пример #3
0
 public function getForm()
 {
     $form = new EForm(require Yii::getPathOfAlias('application.views.site.bookingForm') . '.php', $this);
     $elements = $form->getElements();
     $subForm = new EForm(array('elements' => array()), new AviaPassportForm(), $form);
     // Sub-form to act as a container for the parameter forms.
     $subForm->visible = true;
     $subForm->title = 'Passports';
     // Title to make it a fieldset
     $subFormElements = $subForm->getElements();
     if ($this->passports) {
         foreach ($this->passports as $parameterId => $parameter) {
             //VarDumper::dump($parameter->getForm($subForm));
             $subFormElements->add($parameterId, $parameter->getForm($subForm));
         }
     }
     $elements->add('passports', $subForm);
     return $form;
 }
Пример #4
0
 /**
  * import
  *
  * @param   object  &$feed  Params
  *
  * @return	void
  */
 public function import(&$feed)
 {
     if (isset($feed->params)) {
         $feed->xtform = EForm::paramsToRegistry($feed);
     }
     $import_frequency = $feed->xtform->get('import_frequency', self::ALWAYS_EXPRESSION);
     if ($import_frequency != self::ALWAYS_EXPRESSION) {
         $automators = F0FModel::getTmpInstance('Automators', 'AutoTweetModel');
         $key = 'feed-' . $feed->id;
         $lastexec = $automators->lastRun($key);
         if ($lastexec->toUnix() < JFactory::getDate()->toUnix()) {
             $lastexec = 'now';
         }
         $next = TextUtil::nextScheduledDate($import_frequency, $lastexec);
         $logger = AutotweetLogger::getInstance();
         $logger->log(JLog::INFO, "Feed import: lastRunCheck {$lastexec} ({$key}, 0, {$next})");
         if (!$automators->lastRunCheck($key, 0, $next)) {
             $logger->log(JLog::INFO, "Feed import: lastRunCheck skipped!");
             return;
         }
     }
     $result = new StdClass();
     $result->added_items = 0;
     $simplePie = $this->_createSimplePie($feed);
     if ($simplePie->get_type() & SIMPLEPIE_TYPE_NONE) {
         throw new Exception(JText::sprintf('COM_AUTOTWEET_FEED_UNABLE_TO_PROCESS', $feed->xtform->get('title') . ' (' . $feed->xtform->get('feed') . ')'));
     } elseif ($simplePie->error) {
         throw new Exception("SimplePie error (ID={$feed->id}): " . $simplePie->error . ' for ' . $feed->xtform->get('title') . ' (' . $feed->xtform->get('feed') . ')');
     }
     $title = $simplePie->get_title();
     $c = (int) $feed->xtform->get('import_limit');
     $items = $simplePie->get_items(0, $c);
     $result->title = $title;
     $result->items = $items;
     $simplePie->__destruct();
     unset($items, $simplePie);
     // End SimplePie processing
     return $result;
 }
Пример #5
0
 /**
  * getXingValidation.
  *
  * @return	void
  */
 public function getXingValidation()
 {
     @ob_end_clean();
     header('Content-type: text/plain');
     // No JInputJSON in J2.5
     $raw = file_get_contents('php://input');
     $data = json_decode($raw, true);
     $safeHtmlFilter = JFilterInput::getInstance();
     $token = $data['token'];
     $token = $safeHtmlFilter->clean($token, 'ALNUM');
     $this->input->set($token, 1);
     // CSRF prevention
     if ($this->csrfProtection) {
         $this->_csrfProtection();
     }
     $channel_id = $data['channel_id'];
     $channel_id = $safeHtmlFilter->clean($channel_id, 'ALNUM');
     $channel = F0FTable::getAnInstance('Channel', 'AutoTweetTable');
     $result = $channel->load($channel_id);
     $channel->xtform = EForm::paramsToRegistry($channel);
     $status = false;
     $error_message = 'Unknown';
     $user = null;
     $userId = null;
     $url = null;
     $icon = null;
     try {
         $xingChannelHelper = new XingChannelHelper($channel);
         $isAuth = $xingChannelHelper->isAuth();
         if ($isAuth && isset($isAuth->users) && count($isAuth->users) == 1) {
             $users = $isAuth->users;
             $user = $users[0];
             $status = true;
             $error_message = 'Ok';
             $url = $xingChannelHelper->getSocialUrl($user);
             $userId = $user->id;
             $icon = F0FModel::getTmpInstance('Channeltypes', 'AutoTweetModel')->getIcon(AutoTweetModelChanneltypes::TYPE_XING_CHANNEL);
         } else {
             $error_message = 'Xing Login Failed!';
         }
     } catch (Exception $e) {
         $error_message = $e->getMessage();
     }
     $message = json_encode(array('status' => $status, 'error_message' => $error_message, 'user' => $userId, 'icon' => $icon, 'url' => $url));
     echo EJSON_START . $message . EJSON_END;
     flush();
     JFactory::getApplication()->close();
 }
Пример #6
0
 /**
  * This method runs after an item has been gotten from the database in a read
  * operation. You can modify it before it's returned to the MVC triad for
  * further processing.
  *
  * @param   JTable  &$record  Param
  *
  * @return bool
  */
 protected function onAfterGetItem(&$record)
 {
     jimport('extly.form.eform');
     $record->xtform = EForm::paramsToRegistry($record);
     return parent::onAfterGetItem($record);
 }
Пример #7
0
 /**
  * This method runs after an item has been gotten from the database in a read
  * operation. You can modify it before it's returned to the MVC triad for
  * further processing.
  *
  * @param   JTable  &$record  Param
  *
  * @return bool
  */
 protected function onAfterGetItem(&$record)
 {
     $record->xtform = EForm::paramsToRegistry($record);
     return parent::onAfterGetItem($record);
 }
Пример #8
0
 /**
  * applyAjaxOwnAction
  *
  * @return	void
  */
 public function applyAjaxOwnAction()
 {
     try {
         // CSRF prevention
         if ($this->csrfProtection) {
             $this->_csrfProtection();
         }
         $data = $this->_getAjaxData();
         // On Before Save
         $data['params'] = EForm::paramsToString($data);
         if (array_key_exists('publish_up', $data)) {
             $data['publish_up'] = EParameter::convertLocalUTC($data['publish_up']);
         } else {
             $data['publish_up'] = JFactory::getDate()->toSql();
         }
         // Cleaning annoying spaces
         $data = array_map('trim', $data);
         // Ready to Save
         require_once JPATH_PLUGINS . '/autotweet/autotweetpost/autotweetpost.php';
         $plugin = JPluginHelper::getPlugin('autotweet', 'autotweetpost');
         $className = 'plgAutotweet' . $plugin->name;
         if (!class_exists($className)) {
             throw new Exception(JText::_('COM_AUTOTWEET_COMPOSER_DISABLED_ERROR'));
         }
         $dispatcher = JDispatcher::getInstance();
         $plugin = new $className($dispatcher, (array) $plugin);
         $status = $plugin->postArticle($data);
         $id = null;
         if ($status !== false) {
             $id = $status;
             $status = true;
         }
         $message = json_encode(array('status' => $status, 'request_id' => $id, 'message' => $status ? JText::_('COM_AUTOTWEET_COMPOSER_MESSAGE_SAVED') : 'Unable to addAjaxAction.', 'messageType' => $status ? 'success' : 'error', 'hash' => AutotweetBaseHelper::getHash()));
     } catch (Exception $e) {
         $message = json_encode(array('status' => false, 'message' => $e->getMessage(), 'messageType' => 'error', 'hash' => AutotweetBaseHelper::getHash()));
     }
     echo EJSON_START . $message . EJSON_END;
 }
Пример #9
0
 /**
  * _getContentData
  *
  * @param   array  &$request  Param
  *
  * @return	data
  */
 public function _getContentData(&$request)
 {
     $this->logger->log(JLog::INFO, '_getContentData', $request);
     // Get source plugin for message
     // Gets the plugin that has triggered the message
     $pluginsModel = F0FModel::getTmpInstance('Plugins', 'AutoTweetModel');
     $plugin = $pluginsModel->createPlugin($request->plugin);
     if (empty($plugin)) {
         $this->logger->log(JLog::WARNING, 'publishRequest: unknown plugin. Source: ' . $request->plugin);
         $post = $request;
     } else {
         $plugin->setMessage($request->description);
         $request->xtform = EForm::paramsToRegistry($request);
         $plugin->setHashtags($request->xtform->get('hashtags', ''));
         // Get data from plugin
         if (method_exists($plugin, 'getExtendedData')) {
             if (!isset($request->native_object) && isset($request->params)) {
                 $request->native_object = $request->params;
             }
             $data = $plugin->getExtendedData($request->ref_id, $request->typeinfo, $request->native_object);
         } else {
             $data = $plugin->getData($request->ref_id, $request->typeinfo);
         }
     }
     // Check if post is valid to avoid spam; if not remove post from queue
     if (empty($data) || !array_key_exists('is_valid', $data) || !$data['is_valid']) {
         $this->logger->log(JLog::ERROR, 'publishRequest: message not valid (spam or technical problem - old plugin?), queue id = ' . $request->id);
         RequestHelp::saveError($request->id, 'COM_AUTOTWEET_ERROR_PUBLISHREQUEST');
         return null;
     }
     $data['autopublish'] = $plugin->isAutopublish();
     $data['show_url'] = $plugin->getShowUrlMode();
     return $data;
 }
Пример #10
0
 /**
  * setExtensionParam.
  *
  * @param   string  $folder   Params
  * @param   string  $element  Params
  * @param   string  $key      Params
  * @param   string  $value    Params
  *
  * @return	string.
  */
 public static function setExtensionParam($folder, $element, $key, $value)
 {
     $extensionsModel = F0FModel::getTmpInstance('Extensions', 'ExtlyModel');
     $extensionsModel->set('folder', $folder);
     $extensionsModel->set('element', $element);
     $extensionsModel->set('limit', 1);
     $extensions = $extensionsModel->getItemList();
     if (count($extensions) == 1) {
         $extension = $extensions[0];
         if (isset($extension->{$key})) {
             $extension->{$key} = $value;
             return $extensionsModel->save($extension);
         }
         $extension->xtform = EForm::paramsToRegistry($extension);
         $extension->xtform->set($key, $value);
         return $extensionsModel->save($extension);
     }
     return false;
 }
Пример #11
0
								<td colspan="20"><?php 
EHtml::renderPagination($this);
?>
								</td>
							</tr>
						</tfoot>
						<tbody>
							<?php 
if ($count = count($this->items)) {
    ?>
							<?php 
    $i = 0;
    $m = 1;
    foreach ($this->items as $item) {
        $m = 1 - $m;
        $item->xtform = EForm::paramsToRegistry($item);
        $checkedout = $item->checked_out != 0;
        ?>
							<tr class="row<?php 
        echo $m;
        ?>
">
								<?php 
        if ($hasAjaxOrderingSupport !== false) {
            ?>
								<td class="order nowrap center hidden-phone"><?php 
            if ($this->perms->editstate) {
                $disableClassName = '';
                $disabledLabel = '';
                if (!$hasAjaxOrderingSupport['saveOrder']) {
                    $disabledLabel = JText::_('JORDERINGDISABLED');
Пример #12
0
 /**
  * loadRequest.
  *
  * @param   int  $req_id  Param.
  *
  * @return	void
  *
  * @deprecated
  */
 protected function loadRequest($req_id)
 {
     $articles = F0FModel::getTmpInstance('Requests', 'AutoTweetModel');
     $articles->set('ref_id', $req_id);
     $article = $articles->getFirstItem();
     $article->xtform = EForm::paramsToRegistry($article);
     return $article;
 }
Пример #13
0
 /**
  * publishCronjobPosts
  *
  * @param   int  $limit  Param
  *
  * @return	boolean
  */
 public static function publishCronjobPosts($limit)
 {
     $postsModel = F0FModel::getTmpInstance('Posts', 'AutoTweetModel');
     $postsModel->set('pubstate', AutotweetPostHelper::POST_CRONJOB);
     $postsModel->set('filter_order', 'postdate');
     $postsModel->set('filter_order_Dir', 'ASC');
     $postsModel->set('limit', $limit);
     $posts = $postsModel->getItemList();
     $sharingHelper = SharingHelper::getInstance();
     $logger = AutotweetLogger::getInstance();
     $logger->log(JLog::INFO, 'publishCronjobPosts Posts: ' . count($posts));
     foreach ($posts as $post) {
         $logger->log(JLog::INFO, 'Sending Post ID: ' . $post->id . ' Channel: ' . $post->channel_id . ' Plugin: ' . $post->plugin);
         $post->xtform = EForm::paramsToRegistry($post);
         $sharingHelper->publishPost($post);
     }
 }
Пример #14
0
 /**
  * This method runs before the $data is saved to the $table. Return false to
  * stop saving.
  *
  * @param   array   &$data   Param
  * @param   JTable  &$table  Param
  *
  * @return bool
  */
 protected function onBeforeSave(&$data, &$table)
 {
     EForm::onBeforeSaveWithParams($data);
     return parent::onBeforeSave($data, $table);
 }
Пример #15
0
 /**
  * Method to load a form field object.
  *
  * @param	string		$type		The field type.
  * @param	boolean		$new		Flag to toggle whether we should get a new instance of the object.
  * @return	mixed		Field object on success, false otherwise.
  * @since	1.6
  */
 public function &loadFieldType($type, $new = true)
 {
     $false = false;
     $key = md5($type);
     $class = 'JFormField' . ucfirst($type);
     // Return the field object if it already exists and we don't need a new one.
     if (isset($this->_fieldTypes[$key]) && $new === false) {
         return $this->_fieldTypes[$key];
     }
     if (!class_exists('JFormFieldList')) {
         require_once dirname(__FILE__) . DS . 'fields' . DS . 'list.php';
     }
     if (!class_exists('JFormFieldText')) {
         require_once dirname(__FILE__) . DS . 'fields' . DS . 'text.php';
     }
     if (!class_exists($class)) {
         $paths = EForm::addFieldPath();
         // If the type is complex, add the base type to the paths.
         if ($pos = strpos($type, '_')) {
             // Add the complex type prefix to the paths.
             for ($i = 0, $n = count($paths); $i < $n; $i++) {
                 // Derive the new path.
                 $path = $paths[$i] . DS . strtolower(substr($type, 0, $pos));
                 // If the path does not exist, add it.
                 if (!in_array($path, $paths)) {
                     array_unshift($paths, $path);
                 }
             }
             // Break off the end of the complex type.
             $type = substr($type, $pos + 1);
         }
         // Try to find the field file.
         jimport('joomla.filesystem.path');
         if ($file = JPath::find($paths, strtolower($type) . '.php')) {
             require_once $file;
         } else {
             return $false;
         }
         // Check once and for all if the class exists.
         if (!class_exists($class)) {
             return $false;
         }
     }
     // Instantiate a new field object.
     $this->_fieldTypes[$key] = new $class($this);
     return $this->_fieldTypes[$key];
 }