Пример #1
0
 /**
  * Create a thumbnail from an image file.
  *
  * <code>
  * $myFile   = "/tmp/myfile.jpg";
  *
  * $options = array(
  *     "destination" => "image/mypic.jpg",
  *     "width" => 200,
  *     "height" => 200,
  *     "scale" => JImage::SCALE_INSIDE
  * );
  *
  * $file = new PrismFileImage($myFile);
  * $file->createThumbnail($options);
  *
  * </code>
  *
  * @param  array $options Some options used in the process of generating thumbnail.
  *
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  *
  * @return string A location to the new file.
  */
 public function createThumbnail($options)
 {
     $width = ArrayHelper::getValue($options, "width", 100);
     $height = ArrayHelper::getValue($options, "height", 100);
     $scale = ArrayHelper::getValue($options, "scale", \JImage::SCALE_INSIDE);
     $destination = ArrayHelper::getValue($options, "destination");
     if (!$destination) {
         throw new \InvalidArgumentException(\JText::_("LIB_PRISM_ERROR_INVALID_FILE_DESTINATION"));
     }
     // Generate thumbnail.
     $image = new \JImage();
     $image->loadFile($this->file);
     if (!$image->isLoaded()) {
         throw new \RuntimeException(\JText::sprintf('LIB_PRISM_ERROR_FILE_NOT_FOUND', $this->file));
     }
     // Resize the file as a new object
     $thumb = $image->resize($width, $height, true, $scale);
     $fileName = basename($this->file);
     $ext = \JString::strtolower(\JFile::getExt(\JFile::makeSafe($fileName)));
     switch ($ext) {
         case "gif":
             $type = IMAGETYPE_GIF;
             break;
         case "png":
             $type = IMAGETYPE_PNG;
             break;
         case IMAGETYPE_JPEG:
         default:
             $type = IMAGETYPE_JPEG;
     }
     $thumb->toFile($destination, $type);
     return $destination;
 }
Пример #2
0
 /**
  * Load transactions from database.
  *
  * <code>
  * $options = array(
  *     "ids" => array(1,2,3),
  *     "txn_status" => "completed"
  * );
  *
  * $transactions    = new Crowdfunding\Transactions(\JFactory::getDbo());
  * $transactions->load($options);
  *
  * foreach($transactions as $transaction) {
  *   echo $transaction->txn_id;
  *   echo $transaction->txn_amount;
  * }
  *
  * </code>
  *
  * @param array $options
  *
  * @throws \UnexpectedValueException
  */
 public function load($options = array())
 {
     $ids = !isset($options["ids"]) ? null : (array) $options["ids"];
     if (!is_array($ids) or !$ids) {
         return;
     }
     ArrayHelper::toInteger($ids);
     // Load project data
     $query = $this->db->getQuery(true);
     $query->select("a.id, a.txn_date, a.txn_id, a.txn_amount, a.txn_currency, a.txn_status, " . "a.extra_data, a.status_reason, a.project_id, a.reward_id, a.investor_id, " . "a.receiver_id, a.service_provider, a.reward_state")->from($this->db->quoteName("#__crowdf_transactions", "a"))->where("a.id IN ( " . implode(",", $ids) . " )");
     // Filter by status.
     $status = ArrayHelper::getValue($options, "txn_status", null, "cmd");
     if (!empty($status)) {
         $query->where("a.txn_status = " . $this->db->quote($status));
     }
     $this->db->setQuery($query);
     $results = $this->db->loadObjectList();
     // Convert JSON string into an array.
     if (!empty($results)) {
         foreach ($results as $key => $result) {
             if (!empty($result->extra_data)) {
                 $result->extra_data = json_decode($result->extra_data, true);
                 $results[$key] = $result;
             }
         }
     } else {
         $results = array();
     }
     $this->items = $results;
 }
Пример #3
0
 /**
  * Method to get the record form.
  *
  * @param   array    $data      Data for the form.
  * @param   boolean  $loadData  True if the form is to load its own data (default case), false if not.
  *
  * @return  JForm    A JForm object on success, false on failure.
  *
  * @since   1.6
  */
 public function getForm($data = array(), $loadData = true)
 {
     // The folder and element vars are passed when saving the form.
     if (empty($data)) {
         $item = $this->getItem();
         $folder = $item->folder;
         $element = $item->element;
     } else {
         $folder = ArrayHelper::getValue($data, 'folder', '', 'cmd');
         $element = ArrayHelper::getValue($data, 'element', '', 'cmd');
     }
     // Add the default fields directory
     JForm::addFieldPath(JPATH_PLUGINS . '/' . $folder . '/' . $element . '/field');
     // These variables are used to add data from the plugin XML files.
     $this->setState('item.folder', $folder);
     $this->setState('item.element', $element);
     // Get the form.
     $form = $this->loadForm('com_plugins.plugin', 'plugin', array('control' => 'jform', 'load_data' => $loadData));
     if (empty($form)) {
         return false;
     }
     // Modify the form based on access controls.
     if (!$this->canEditState((object) $data)) {
         // Disable fields for display.
         $form->setFieldAttribute('ordering', 'disabled', 'true');
         $form->setFieldAttribute('enabled', 'disabled', 'true');
         // Disable fields while saving.
         // The controller has already verified this is a record you can edit.
         $form->setFieldAttribute('ordering', 'filter', 'unset');
         $form->setFieldAttribute('enabled', 'filter', 'unset');
     }
     return $form;
 }
Пример #4
0
 /**
  * This method prepare a link where the user will be redirected
  * after action he has done.
  *
  * <code>
  * array(
  *        "view",
  *        "layout"
  *        "id",
  *        "url_var",
  *        "force_direction" // This is a link that will be used instead generated by the system.
  * );
  * </code>
  * @param array $options
  *
  * @throws \InvalidArgumentException
  *
  * @return string
  */
 protected function prepareRedirectLink($options)
 {
     $view = ArrayHelper::getValue($options, 'view');
     $task = ArrayHelper::getValue($options, 'task');
     $itemId = ArrayHelper::getValue($options, 'id', 0, 'uint');
     $urlVar = ArrayHelper::getValue($options, 'url_var', 'id');
     // Remove standard parameters
     unset($options['view'], $options['task'], $options['id'], $options['url_var']);
     $link = $this->defaultLink;
     // Redirect to different of common views
     if (null !== $view) {
         $link .= '&view=' . $view;
         if ($itemId > 0) {
             $link .= $this->getRedirectToItemAppend($itemId, $urlVar);
         } else {
             $link .= $this->getRedirectToListAppend();
         }
         return $link;
     }
     // Prepare redirection
     switch ($task) {
         case 'apply':
             $link .= '&view=' . $this->view_item . $this->getRedirectToItemAppend($itemId, $urlVar);
             break;
         case 'save2new':
             $link .= '&view=' . $this->view_item . $this->getRedirectToItemAppend();
             break;
         default:
             $link .= '&view=' . $this->view_list . $this->getRedirectToListAppend();
             break;
     }
     // Generate additional parameters
     $extraParams = $this->prepareExtraParameters($options);
     return $link . $extraParams;
 }
 /**
  * Generate a string of amount based on location.
  * The method uses PHP NumberFormatter ( Internationalization Functions ).
  * If the internationalization library is not loaded, the method generates a simple string ( 100 USD, 500 EUR,... )
  *
  * <code>
  * $options = array(
  *     "intl" => true",
  *     "locale" => "en_GB",
  *     "symbol" => "£",
  *     "position" => 0 // 0 for symbol on the left side, 1 for symbole on the right side.
  * );
  *
  * $amount = Prism\Utilities\StringHelper::getAmount(100, GBP, $options);
  *
  * echo $amount;
  * </code>
  *
  * @param float $amount Amount value.
  * @param string $currency Currency Code ( GBP, USD, EUR,...)
  * @param array $options Options - "intl", "locale", "symbol",...
  *
  * @return string
  */
 public static function getAmount($amount, $currency, array $options = array())
 {
     $useIntl = ArrayHelper::getValue($options, 'intl', false, 'bool');
     $locale = ArrayHelper::getValue($options, 'locale');
     $symbol = ArrayHelper::getValue($options, 'symbol');
     $position = ArrayHelper::getValue($options, 'position', 0, 'int');
     // Use PHP Intl library.
     if ($useIntl and extension_loaded('intl')) {
         // Generate currency string using PHP NumberFormatter ( Internationalization Functions )
         // Get current locale code.
         if (!$locale) {
             $lang = \JFactory::getLanguage();
             $locale = $lang->getName();
         }
         $numberFormat = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
         $result = $numberFormat->formatCurrency($amount, $currency);
     } else {
         // Generate a custom currency string.
         if (\JString::strlen($symbol) > 0) {
             // Symbol
             if (0 === $position) {
                 // Symbol at the beginning.
                 $result = $symbol . $amount;
             } else {
                 // Symbol at end.
                 $result = $amount . $symbol;
             }
         } else {
             // Code
             $result = $amount . $currency;
         }
     }
     return $result;
 }
Пример #6
0
 /**
  * Stick items
  *
  * @return  void
  *
  * @since   1.6
  */
 public function sticky_publish()
 {
     // Check for request forgeries.
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $ids = $this->input->get('cid', array(), 'array');
     $values = array('sticky_publish' => 1, 'sticky_unpublish' => 0);
     $task = $this->getTask();
     $value = ArrayHelper::getValue($values, $task, 0, 'int');
     if (empty($ids)) {
         JError::raiseWarning(500, JText::_('COM_BANNERS_NO_BANNERS_SELECTED'));
     } else {
         // Get the model.
         /** @var BannersModelBanner $model */
         $model = $this->getModel();
         // Change the state of the records.
         if (!$model->stick($ids, $value)) {
             JError::raiseWarning(500, $model->getError());
         } else {
             if ($value == 1) {
                 $ntext = 'COM_BANNERS_N_BANNERS_STUCK';
             } else {
                 $ntext = 'COM_BANNERS_N_BANNERS_UNSTUCK';
             }
             $this->setMessage(JText::plural($ntext, count($ids)));
         }
     }
     $this->setRedirect('index.php?option=com_banners&view=banners');
 }
Пример #7
0
 public function save($key = null, $urlVar = null)
 {
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $app = JFactory::getApplication();
     /** @var $app JApplicationAdministrator */
     $data = $app->input->post->get('jform', array(), 'array');
     $itemId = ArrayHelper::getValue($data, 'id');
     $redirectOptions = array('task' => $this->getTask(), 'id' => $itemId);
     $model = $this->getModel();
     /** @var $model GamificationModelPoint */
     $form = $model->getForm($data, false);
     /** @var $form JForm */
     if (!$form) {
         throw new Exception(JText::_('COM_GAMIFICATION_ERROR_FORM_CANNOT_BE_LOADED'));
     }
     // Validate the form
     $validData = $model->validate($form, $data);
     // Check for errors.
     if ($validData === false) {
         $this->displayNotice($form->getErrors(), $redirectOptions);
         return;
     }
     try {
         $itemId = $model->save($validData);
         $redirectOptions['id'] = $itemId;
     } catch (Exception $e) {
         JLog::add($e->getMessage(), JLog::ERROR, 'com_gamification');
         throw new Exception(JText::_('COM_GAMIFICATION_ERROR_SYSTEM'));
     }
     $this->displayMessage(JText::_('COM_GAMIFICATION_POINTS_SAVED'), $redirectOptions);
 }
 /**
  * Load locations data by ID from database.
  *
  * <code>
  * $options = array(
  *     "ids" => array(1,2,3,4,5), // Load locations by IDs.
  *     "search" => "London" // It is a phrase for searching.
  * );
  *
  * $locations   = new Socialcommunity\Locations(JFactory::getDbo());
  * $locations->load($options);
  *
  * foreach($locations as $location) {
  *   echo $location["name"];
  *   echo $location["country_code"];
  * }
  * </code>
  *
  * @param array $options
  */
 public function load(array $options = array())
 {
     $ids = ArrayHelper::getValue($options, 'ids', array(), 'array');
     $search = ArrayHelper::getValue($options, 'search', '', 'string');
     $countryId = ArrayHelper::getValue($options, 'country_id', 0, 'int');
     ArrayHelper::toInteger($ids);
     $query = $this->db->getQuery(true);
     $query->select('a.id, a.name, a.latitude, a.longitude, a.country_code, a.state_code, a.timezone, a.published')->from($this->db->quoteName('#__itpsc_locations', 'a'));
     if (count($ids) > 0) {
         $query->where('a.id IN ( ' . implode(',', $ids) . ' )');
     }
     // Filter by country ID ( use subquery to get country code ).
     if ($countryId > 0) {
         $subQuery = $this->db->getQuery(true);
         $subQuery->select('sqc.code')->from($this->db->quoteName('#__itpsc_countries', 'sqc'))->where('sqc.id = ' . (int) $countryId);
         $query->where('a.country_code = ( ' . $subQuery . ' )');
     }
     if ($query !== null and $query !== '') {
         $escaped = $this->db->escape($search, true);
         $quoted = $this->db->quote('%' . $escaped . '%', false);
         $query->where('a.name LIKE ' . $quoted);
     }
     $this->db->setQuery($query);
     $this->items = (array) $this->db->loadAssocList('id');
 }
Пример #9
0
 /**
  * Enable/Disable an extension (if supported).
  *
  * @return  void
  *
  * @since   1.6
  */
 public function publish()
 {
     // Check for request forgeries.
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $ids = $this->input->get('cid', array(), 'array');
     $values = array('publish' => 1, 'unpublish' => 0);
     $task = $this->getTask();
     $value = ArrayHelper::getValue($values, $task, 0, 'int');
     if (empty($ids)) {
         JError::raiseWarning(500, JText::_('COM_INSTALLER_ERROR_NO_EXTENSIONS_SELECTED'));
     } else {
         // Get the model.
         $model = $this->getModel('manage');
         // Change the state of the records.
         if (!$model->publish($ids, $value)) {
             JError::raiseWarning(500, implode('<br />', $model->getErrors()));
         } else {
             if ($value == 1) {
                 $ntext = 'COM_INSTALLER_N_EXTENSIONS_PUBLISHED';
             } elseif ($value == 0) {
                 $ntext = 'COM_INSTALLER_N_EXTENSIONS_UNPUBLISHED';
             }
             $this->setMessage(JText::plural($ntext, count($ids)));
         }
     }
     $this->setRedirect(JRoute::_('index.php?option=com_installer&view=manage', false));
 }
Пример #10
0
 public function save($key = null, $urlVar = null)
 {
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $data = $this->input->post->get('jform', array(), 'array');
     $itemId = ArrayHelper::getValue($data, 'id');
     $responseOptions = array('task' => $this->getTask(), 'id' => $itemId);
     $model = $this->getModel();
     /** @var $model EmailTemplatesModelEmail */
     $form = $model->getForm($data, false);
     /** @var $form JForm */
     if (!$form) {
         throw new Exception(JText::_('COM_EMAILTEMPLATES_ERROR_FORM_CANNOT_BE_LOADED'));
     }
     // Validate the form data
     $validData = $model->validate($form, $data);
     // Check for errors
     if ($validData === false) {
         $this->displayNotice($form->getErrors(), $responseOptions);
         return;
     }
     try {
         $itemId = $model->save($validData);
         $responseOptions['id'] = $itemId;
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         throw new Exception(JText::_('COM_EMAILTEMPLATES_ERROR_SYSTEM'));
     }
     $this->displayMessage(JText::_('COM_EMAILTEMPLATES_EMAIL_SAVED_SUCCESSFULLY'), $responseOptions);
 }
Пример #11
0
 public function save($key = null, $urlVar = null)
 {
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $data = $this->input->post->get('jform', array(), 'array');
     $itemId = ArrayHelper::getValue($data, "id");
     $redirectData = array("task" => $this->getTask(), "id" => $itemId);
     $model = $this->getModel();
     /** @var $model GamificationModelRank */
     $form = $model->getForm($data, false);
     /** @var $form JForm */
     if (!$form) {
         throw new Exception(JText::_("COM_GAMIFICATION_ERROR_FORM_CANNOT_BE_LOADED"), 500);
     }
     // Validate the form
     $validData = $model->validate($form, $data);
     // Check for errors
     if ($validData === false) {
         $this->displayNotice($form->getErrors(), $redirectData);
         return;
     }
     try {
         $itemId = $model->save($validData);
         $redirectData["id"] = $itemId;
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         throw new Exception(JText::_('COM_GAMIFICATION_ERROR_SYSTEM'));
     }
     $this->displayMessage(JText::_('COM_GAMIFICATION_LEVEL_SAVED'), $redirectData);
 }
 public function read()
 {
     // Check for request forgeries
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     // Get items to publish from the request.
     $cid = $this->input->get('cid', array(), 'array');
     $data = array('read' => 1, 'notread' => 0);
     $task = $this->getTask();
     $value = ArrayHelper::getValue($data, $task, 0, 'int');
     $redirectOptions = array("view" => "notifications");
     // Make sure the item ids are integers
     ArrayHelper::toInteger($cid);
     if (empty($cid)) {
         $this->displayNotice(JText::_($this->text_prefix . '_NO_ITEM_SELECTED'), $redirectOptions);
         return;
     }
     try {
         $model = $this->getModel();
         $model->read($cid, $value);
     } catch (RuntimeException $e) {
         $this->displayWarning($e->getMessage(), $redirectOptions);
         return;
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         throw new Exception(JText::_('COM_GAMIFICATION_ERROR_SYSTEM'));
     }
     if ($value == 1) {
         $msg = $this->text_prefix . '_N_ITEMS_READ';
     } else {
         $msg = $this->text_prefix . '_N_ITEMS_NOT_READ';
     }
     $this->displayMessage(JText::plural($msg, count($cid)), $redirectOptions);
 }
Пример #13
0
 /**
  * Shows the data formatted for the list view
  *
  * @param   string    $data      Elements data
  * @param   stdClass  &$thisRow  All the data in the lists current row
  * @param   array     $opts      Rendering options
  *
  * @return  string	formatted value
  */
 public function renderListData($data, stdClass &$thisRow, $opts = array())
 {
     $listModel = $this->getListModel();
     $params = $this->getParams();
     $w = (int) $params->get('fb_gm_table_mapwidth');
     $h = (int) $params->get('fb_gm_table_mapheight');
     $z = (int) $params->get('fb_gm_table_zoomlevel');
     $data = FabrikWorker::JSONtoData($data, true);
     foreach ($data as $i => &$d) {
         if ($params->get('fb_gm_staticmap_tableview')) {
             $d = $this->_staticMap($d, $w, $h, $z, $i, true, ArrayHelper::fromObject($thisRow));
         }
         if ($params->get('icon_folder') == '1' && ArrayHelper::getValue($opts, 'icon', 1)) {
             // $$$ rob was returning here but that stopped us being able to use links and icons together
             $d = $this->replaceWithIcons($d, 'list', $listModel->getTmpl());
         } else {
             if (!$params->get('fb_gm_staticmap_tableview')) {
                 $d = $params->get('fb_gm_staticmap_tableview_type_coords', 'num') == 'dms' ? $this->_dmsformat($d) : $this->_microformat($d);
             }
         }
         if (ArrayHelper::getValue($opts, 'rollover', 1)) {
             $d = $this->rollover($d, $thisRow, 'list');
         }
         if (ArrayHelper::getValue($opts, 'link', 1)) {
             $d = $listModel->_addLink($d, $this, $thisRow, $i);
         }
     }
     return $this->renderListDataFinal($data);
 }
Пример #14
0
 /**
  * Method to toggle the featured setting of a list of contacts.
  *
  * @return  void
  *
  * @since   1.6
  */
 public function featured()
 {
     // Check for request forgeries
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $ids = $this->input->get('cid', array(), 'array');
     $values = array('featured' => 1, 'unfeatured' => 0);
     $task = $this->getTask();
     $value = ArrayHelper::getValue($values, $task, 0, 'int');
     // Get the model.
     /** @var ContactModelContact $model */
     $model = $this->getModel();
     // Access checks.
     foreach ($ids as $i => $id) {
         $item = $model->getItem($id);
         if (!JFactory::getUser()->authorise('core.edit.state', 'com_contact.category.' . (int) $item->catid)) {
             // Prune items that you can't change.
             unset($ids[$i]);
             JError::raiseNotice(403, JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'));
         }
     }
     if (empty($ids)) {
         JError::raiseWarning(500, JText::_('COM_CONTACT_NO_ITEM_SELECTED'));
     } else {
         // Publish the items.
         if (!$model->featured($ids, $value)) {
             JError::raiseWarning(500, $model->getError());
         }
     }
     $this->setRedirect('index.php?option=com_contact&view=contacts');
 }
Пример #15
0
 /**
  * Load transactions from database.
  *
  * <code>
  * $options = array(
  *     "ids" => array(1,2,3),
  *     "txn_status" => "completed"
  * );
  *
  * $transactions    = new Crowdfunding\Transactions(\JFactory::getDbo());
  * $transactions->load($options);
  *
  * foreach($transactions as $transaction) {
  *   echo $transaction->txn_id;
  *   echo $transaction->txn_amount;
  * }
  *
  * </code>
  *
  * @param array $options
  *
  * @throws \UnexpectedValueException
  */
 public function load($options = array())
 {
     $ids = !array_key_exists('ids', $options) ? array() : (array) $options['ids'];
     $ids = ArrayHelper::toInteger($ids);
     $results = array();
     if (count($ids) > 0) {
         // Load project data
         $query = $this->db->getQuery(true);
         $query->select('a.id, a.txn_date, a.txn_id, a.txn_amount, a.txn_currency, a.txn_status, ' . 'a.extra_data, a.status_reason, a.project_id, a.reward_id, a.investor_id, ' . 'a.receiver_id, a.service_provider, a.service_alias, a.reward_state')->from($this->db->quoteName('#__crowdf_transactions', 'a'))->where('a.id IN ( ' . implode(',', $ids) . ' )');
         // Filter by status.
         $status = ArrayHelper::getValue($options, 'txn_status', null, 'cmd');
         if ($status !== null) {
             $query->where('a.txn_status = ' . $this->db->quote($status));
         }
         $this->db->setQuery($query);
         $results = (array) $this->db->loadAssocList();
         // Convert JSON string into an array.
         if (count($results) > 0) {
             foreach ($results as $key => &$result) {
                 if (!empty($result['extra_data'])) {
                     $result['extra_data'] = json_decode($result['extra_data'], true);
                 }
             }
             unset($result);
         }
     }
     $this->items = $results;
 }
Пример #16
0
 /**
  * Method to change the block status on a record.
  *
  * @return  void
  *
  * @since   1.6
  */
 public function changeBlock()
 {
     // Check for request forgeries.
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $ids = $this->input->get('cid', array(), 'array');
     $values = array('block' => 1, 'unblock' => 0);
     $task = $this->getTask();
     $value = ArrayHelper::getValue($values, $task, 0, 'int');
     if (empty($ids)) {
         JError::raiseWarning(500, JText::_('COM_USERS_USERS_NO_ITEM_SELECTED'));
     } else {
         // Get the model.
         $model = $this->getModel();
         // Change the state of the records.
         if (!$model->block($ids, $value)) {
             JError::raiseWarning(500, $model->getError());
         } else {
             if ($value == 1) {
                 $this->setMessage(JText::plural('COM_USERS_N_USERS_BLOCKED', count($ids)));
             } elseif ($value == 0) {
                 $this->setMessage(JText::plural('COM_USERS_N_USERS_UNBLOCKED', count($ids)));
             }
         }
     }
     $this->setRedirect('index.php?option=com_users&view=users');
 }
Пример #17
0
 /**
  * Load data about updates from database by project ID.
  *
  * <code>
  * $options = array(
  *     "project_id" => 1, // It can also be an array with IDs.
  *     "period" => 7, // Period in days
  *     "limit" => 10 // Limit the results
  * );
  *
  * $updates   = new Crowdfunding\Updates(\JFactory::getDbo());
  * $updates->load($options);
  *
  * foreach($updates as $item) {
  *      echo $item->title;
  *      echo $item->record_date;
  * }
  * </code>
  *
  * @param array $options
  */
 public function load(array $options = array())
 {
     $query = $this->db->getQuery(true);
     $query->select('a.id, a.title, a.description, a.record_date, a.project_id')->from($this->db->quoteName('#__crowdf_updates', 'a'));
     // Filter by IDs.
     $ids = ArrayHelper::getValue($options, 'ids', array(), 'array');
     if (count($ids) > 0) {
         $query->where('a.ids IN (' . implode(',', $ids) . ')');
     }
     // Filter by project ID.
     $projectId = ArrayHelper::getValue($options, 'project_id', 0, 'int');
     if ($projectId > 0) {
         $query->where('a.project_id = ' . (int) $projectId);
     }
     // Filter by period.
     $period = ArrayHelper::getValue($options, 'period', 0, 'int');
     if ($period > 0) {
         $query->where('a.record_date >= DATE_SUB(NOW(), INTERVAL ' . $period . ' DAY)');
     }
     // Set limit.
     $limit = ArrayHelper::getValue($options, 'limit', 0, 'int');
     if ($limit > 0) {
         $this->db->setQuery($query, 0, $limit);
     } else {
         $this->db->setQuery($query);
     }
     $this->items = (array) $this->db->loadAssocList();
 }
Пример #18
0
 /**
  * Load latest transaction ordering by record date.
  *
  * <code>
  * $limit = 10;
  *
  * $latest = new Crowdfunding\Statistics\Transactions\Latest(JFactory::getDbo());
  * $latest->load(['limit' => $limit]);
  *
  * foreach ($latest as $project) {
  *      echo $project["txn_amount"];
  *      echo $project["txn_currency"];
  *      echo $project["txn_date"];
  * }
  * </code>
  *
  * @param array $options
  */
 public function load(array $options = array())
 {
     $limit = ArrayHelper::getValue($options, 'limit', 5, 'int');
     $query = $this->getQuery();
     $query->order('a.txn_date DESC');
     $this->db->setQuery($query, 0, (int) $limit);
     $this->items = (array) $this->db->loadAssocList();
 }
Пример #19
0
 /**
  * Initialize the object.
  *
  * <code>
  * $options = array(
  *    "view" => "article",
  *    "task" => "...",
  *    "menu_item_id" => 1,
  *    "generate_metadesc" => true, // Generate or not meta description.
  *    "extract_image" => false // Extract image from item content
  * );
  *
  * $extension = new ItpMeta\Extension\Content($options);
  * </code>
  *
  * @param $options
  */
 public function __construct($options)
 {
     $this->view = ArrayHelper::getValue($options, 'view');
     $this->task = ArrayHelper::getValue($options, 'task');
     $this->menuItemId = ArrayHelper::getValue($options, 'menu_item_id');
     $this->genMetaDesc = ArrayHelper::getValue($options, 'generate_metadesc', false, 'bool');
     $this->extractImage = ArrayHelper::getValue($options, 'extract_image', false, 'bool');
 }
Пример #20
0
 /**
  * Creates the associated observer instance and attaches it to the $observableObject
  * $typeAlias can be of the form "{variableName}.type", automatically replacing {variableName} with table-instance variables variableName
  *
  * @param   \JObservableInterface $observableObject The subject object to be observed
  * @param   array                $params           ( 'typeAlias' => $typeAlias )
  *
  * @return  self
  *
  * @since   3.1.2
  */
 public static function createObserver(\JObservableInterface $observableObject, $params = array())
 {
     $observer = new self($observableObject);
     $observer->typeAliasPattern = ArrayHelper::getValue($params, 'typeAlias');
     $observer->sendNotification = ArrayHelper::getValue($params, 'send_notification', false, "bool");
     $observer->storeActivity = ArrayHelper::getValue($params, 'store_activity', false, "bool");
     return $observer;
 }
Пример #21
0
function modChrome_material_card($module, &$params, &$attribs)
{
    if (!empty($module->content)) {
        $extractImage = ArrayHelper::getValue($attribs, 'extractimage', true);
        $titleImage = '';
        if ($extractImage) {
            $doc = new DOMDocument();
            $doc->loadHTML($module->content);
            $images = $doc->getElementsByTagName('img');
            $i = 0;
            foreach ($images as $image) {
                if ($i > 0) {
                    continue;
                }
                $titleImage = $doc->saveHTML($image);
                $image->parentNode->removeChild($image);
                $i++;
            }
            $module->content = $doc->saveHTML();
        }
        ?>
		<div class="col-grow-vertical <?php 
        echo htmlspecialchars($params->get('moduleclass_sfx')) . ' ' . ArrayHelper::getValue($attribs, 'col');
        ?>
">
			<div class="card">
				<?php 
        if ($titleImage !== '') {
            ?>
					<div class="card-image">
						<?php 
            echo $titleImage;
            ?>
					</div>
				<?php 
        }
        ?>
				<div class="card-content">
					<?php 
        if ($module->showtitle != 0) {
            ?>
						<span class="card-title"><?php 
            echo $module->title;
            ?>
</span>
					<?php 
        }
        ?>
					<?php 
        echo $module->content;
        ?>
				</div>
			</div>
		</div>
		<?php 
    }
}
Пример #22
0
 static function toggle($value = 0, $view, $field, $i)
 {
     $states = array(0 => array('icon-remove', JText::_('Toggle'), 'inactive btn-danger'), 1 => array('icon-checkmark', JText::_('Toggle'), 'active btn-success'));
     $state = \Joomla\Utilities\ArrayHelper::getValue($states, (int) $value, $states[0]);
     $text = '<span aria-hidden="true" class="' . $state[0] . '"></span>';
     $html = '<a href="#" class="btn btn-micro ' . $state[2] . '"';
     $html .= 'onclick="return toggleField(\'cb' . $i . '\',\'' . $view . '.toggle\',\'' . $field . '\')" title="' . JText::_($state[1]) . '">' . $text . '</a>';
     return $html;
 }
Пример #23
0
 /**
  * Draws the html form element
  *
  * @param   array $data          to pre-populate element with
  * @param   int   $repeatCounter repeat group counter
  *
  * @return  string    elements html
  */
 public function render($data, $repeatCounter = 0)
 {
     $range = $this->getRange();
     $fullName = $this->getDataElementFullName();
     $data = FArrayHelper::getValue($data, $fullName);
     if (is_array($data)) {
         $data = ArrayHelper::getValue($data, $repeatCounter);
     }
     return $this->_renderListData($data, $range, $repeatCounter);
 }
Пример #24
0
 /**
  * Constructor.
  *
  * @param   array $config An optional associative array of configuration settings.
  *
  * @see     JModelLegacy
  * @since   12.2
  */
 public function __construct($config = array())
 {
     $this->app = ArrayHelper::getValue($config, 'app', JFactory::getApplication());
     $this->user = ArrayHelper::getValue($config, 'user', JFactory::getUser());
     $this->config = ArrayHelper::getValue($config, 'config', JFactory::getConfig());
     $this->session = ArrayHelper::getValue($config, 'session', JFactory::getSession());
     $this->db = ArrayHelper::getValue($config, 'db', JFactory::getDbo());
     $this->pluginManager = ArrayHelper::getValue($config, 'pluginManager', JModelLegacy::getInstance('Pluginmanager', 'FabrikFEModel'));
     parent::__construct($config);
 }
Пример #25
0
 /**
  * Get the HTML code of the state switcher
  *
  * @param   int      $i          Row number
  * @param   int      $value      The state value
  * @param   boolean  $canChange  Can the user change the state?
  *
  * @return  string
  *
  * @since   3.4
  */
 public static function status($i, $value = 0, $canChange = false)
 {
     // Array of image, task, title, action.
     $states = array(-2 => array('trash', 'messages.unpublish', 'JTRASHED', 'COM_MESSAGES_MARK_AS_UNREAD'), 1 => array('publish', 'messages.unpublish', 'COM_MESSAGES_OPTION_READ', 'COM_MESSAGES_MARK_AS_UNREAD'), 0 => array('unpublish', 'messages.publish', 'COM_MESSAGES_OPTION_UNREAD', 'COM_MESSAGES_MARK_AS_READ'));
     $state = ArrayHelper::getValue($states, (int) $value, $states[0]);
     $icon = $state[0];
     if ($canChange) {
         $html = '<a href="#" onclick="return listItemTask(\'cb' . $i . '\',\'' . $state[1] . '\')" class="btn btn-micro hasTooltip' . ($value == 1 ? ' active' : '') . '" title="' . JHtml::tooltipText($state[3]) . '"><span class="icon-' . $icon . '"></span></a>';
     }
     return $html;
 }
Пример #26
0
 /**
  * Constructor
  *
  * @param   array $config A named configuration array for object construction.
  *
  */
 public function __construct($config = array())
 {
     $this->app = ArrayHelper::getValue($config, 'app', JFactory::getApplication());
     $this->user = ArrayHelper::getValue($config, 'user', JFactory::getUser());
     $this->package = $this->app->getUserState('com_fabrik.package', 'fabrik');
     $this->session = ArrayHelper::getValue($config, 'session', JFactory::getSession());
     $this->doc = ArrayHelper::getValue($config, 'doc', JFactory::getDocument());
     $this->db = ArrayHelper::getValue($config, 'db', JFactory::getDbo());
     $this->config = ArrayHelper::getValue($config, 'config', JFactory::getConfig());
     parent::__construct($config);
 }
Пример #27
0
 /**
  * Count user's posts.
  *
  * <code>
  * $options = array(
  *      "user_id"        => 1
  * );
  *
  * $entities = new Socialcommunity\Wall\User\Posts(JFactory::getDbo());
  * echo $entities->getNumber($options);
  * </code>
  *
  * @param array $options  Options that will be used for filtering results.
  *
  * @return int
  */
 public function getNumber(array $options = array())
 {
     $userId = ArrayHelper::getValue($options, 'user_id', 0, 'integer');
     if (!$userId) {
         return count($this->items);
     }
     $query = $this->db->getQuery(true);
     $query->select('COUNT(*)')->from($this->db->quoteName('#__itpsc_userwalls', 'a'))->where('a.user_id = ' . (int) $userId);
     $this->db->setQuery($query, 0, 1);
     return (int) $this->db->loadResult();
 }
 /**
  * Load data about the most funded projects.
  *
  * <code>
  * $mostFunded = new Crowdfunding\Statistics\Projects\MostFunded(\JFactory::getDbo());
  * $mostFunded->load();
  *
  * foreach ($mostFunded as $project) {
  *      echo $project["title"];
  * }
  * </code>
  *
  * @param array $options
  */
 public function load(array $options = array())
 {
     $limit = ArrayHelper::getValue($options, 'limit', 5, 'int');
     // Get current date
     jimport('joomla.date.date');
     $date = new \JDate();
     $today = $date->toSql();
     $query = $this->getQuery();
     $query->where('( a.published = 1 AND a.approved = 1 )')->where('( a.funding_start <= ' . $this->db->quote($today) . ' AND a.funding_end >= ' . $this->db->quote($today) . ' )')->order('a.funded DESC');
     $this->db->setQuery($query, 0, (int) $limit);
     $this->items = (array) $this->db->loadAssocList();
 }
Пример #29
0
 /**
  * Create and initialize the object.
  *
  * <code>
  * $keys = array(
  *       "user_id"  => 1,
  *       "group_id" => 2
  * );
  * $userRank    = Gamification\User\Rank::getInstance(\JFactory::getDbo(), $keys);
  * </code>
  *
  * @param \JDatabaseDriver $db
  * @param  array $keys
  * @param  array $options
  *
  * @return null|self
  */
 public static function getInstance(\JDatabaseDriver $db, array $keys, array $options = array())
 {
     $userId = ArrayHelper::getValue($keys, "user_id");
     $groupId = ArrayHelper::getValue($keys, "group_id");
     $index = md5($userId . ":" . $groupId);
     if (!isset(self::$instances[$index])) {
         $item = new Rank($db, $options);
         $item->load($keys);
         self::$instances[$index] = $item;
     }
     return self::$instances[$index];
 }
Пример #30
0
 /**
  * Make a request to Transifex server.
  *
  * @param string  $path
  * @param array $options
  *
  * @throws \RuntimeException
  *
  * @return null|Response
  */
 protected function request($path, array $options = array())
 {
     if (!function_exists('curl_version')) {
         throw new \RuntimeException('The cURL library is not loaded.');
     }
     $headers = ArrayHelper::getValue($options, 'headers', array(), 'array');
     $method = ArrayHelper::getValue($options, 'method', 'get');
     $postData = ArrayHelper::getValue($options, 'data', array(), 'array');
     $url = $this->url . $path;
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectionTimeout);
     curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     // Prepare headers
     if (count($headers) > 0) {
         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
         curl_setopt($ch, CURLOPT_HEADER, 0);
     }
     if (strcmp($method, 'post') === 0) {
         curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
     }
     if ($this->auth) {
         curl_setopt($ch, CURLOPT_USERPWD, $this->username . ':' . $this->password);
     }
     // Get the data
     $response = curl_exec($ch);
     if (false !== $response) {
         $this->data = json_decode($response, true);
         if (!is_array($this->data)) {
             $message = (string) $response . ' (' . $url . ')';
             throw new \RuntimeException($message);
         }
     }
     // Get info about the request
     $this->info = curl_getinfo($ch);
     // Check for error
     $errorNumber = curl_errno($ch);
     if ($errorNumber > 0) {
         $message = curl_error($ch) . '(' . (int) $errorNumber . ')';
         throw new \RuntimeException($message);
     }
     // Close the request
     curl_close($ch);
     // Create response object
     $response = new Response();
     $response->bind($this->data);
     return $response;
 }