/** * Get the input * * @return string */ protected function getInput() { $iframeid = $this->id . '_iframe'; $app = JFactory::getApplication(); $input = $app->input; $cid = $input->get('id', array(0), 'array'); $cid = FArrayHelper::getValue($cid, 0); // $$$ hugh - when creating a new form, no 'cid' ... not sure what to do, so just set it to 0. Should // prolly just return something like 'available after save' ? $c = isset($this->form->repeatCounter) ? (int) $this->form->repeatCounter : 0; $href = COM_FABRIK_LIVESITE . 'index.php?option=com_fabrik&task=plugin.pluginAjax&plugin=twitter'; $href .= '&g=form&method=authenticateAdmin&tmpl=component&formid=' . $cid . '&repeatCounter=' . $c; $clearjs = '$(\'jform_params_twitter_oauth_token-' . $c . '\').value = \'\';'; $clearjs .= '$(\'jform_params_twitter_oauth_token_secret-' . $c . '\').value = \'\';'; $clearjs .= '$(\'jform_params_twitter_oauth_user-' . $c . '\').value = \'\';'; $clearjs .= "return false;"; $src = COM_FABRIK_LIVESITE . 'components/com_fabrik/libs/abraham-twitteroauth/images/lighter.png'; $winOpts = 'width=800,height=460,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes'; $js = "window.open('{$href}', 'twitterwins', '" . $winOpts . "');return false;"; $parsedUrl = parse_url(JUri::root()); $origin = $parsedUrl['scheme'] . '://' . $parsedUrl['host']; $str = "\n<script type='text/javascript'>\nwindow.addEventListener('message', function(event) {\n\tif (~event.origin.indexOf('" . $origin . "')) {\n\t\tjQuery(event.data).each(function (i, k) {\n\t\t\tjQuery(k[0]).val(k[1]);\n\t\t});\n\t} else {\n\t\treturn;\n\t}\n});\n</script>\n"; $str .= '<a href="#" onclick="' . $js . '">'; $str .= '<img src="' . $src . '" alt="Sign in with Twitter"/></a>'; $str .= " | <button class=\"button btn\" href=\"#\" onclick=\"{$clearjs}\">"; $str .= FText::_('PLG_FORM_TWITTER_CLEAR_CREDENTIALS') . "</button><br/>"; $str .= "<br /><input type=\"hidden\" readonly=\"readonly\" name=\"" . $this->name . "\" id=\"" . $this->id . "\" value=\"" . $this->value . "\" />"; return $str; }
/** * Method to set the home property for a list of items * * @since 1.6 * * @return null */ public function setDefault() { // Check for request forgeries JSession::checkToken() or die(FText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); $input = $app->input; // Get items to publish from the request. $cid = $input->get('cid', array(), 'array'); $data = array('setDefault' => 1, 'unsetDefault' => 0); $task = $this->getTask(); $value = FArrayHelper::getValue($data, $task, 0, 'int'); if ($value == 0) { $this->setMessage(FText::_('COM_FABRIK_CONNECTION_CANT_UNSET_DEFAULT')); } if (empty($cid)) { JError::raiseWarning(500, FText::_($this->text_prefix . '_NO_ITEM_SELECTED')); } else { if ($value != 0) { $cid = $cid[0]; // Get the model. $model = $this->getModel(); // Publish the items. if (!$model->setDefault($cid, $value)) { JError::raiseWarning(500, $model->getError()); } else { $this->setMessage(FText::_('COM_FABRIK_CONNECTION_SET_DEFAULT')); } } } $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false)); }
/** * Display * * @param string $tpl Template * * @return void */ public function display($tpl = null) { FabrikHelperHTML::framework(); $input = $this->app->input; $item = $this->get('Item'); $srcs = array('media/com_fabrik/js/icons.js', 'media/com_fabrik/js/icongen.js', 'media/com_fabrik/js/canvas.js', 'media/com_fabrik/js/history.js', 'media/com_fabrik/js/keynav.js', 'media/com_fabrik/js/tabs.js', 'media/com_fabrik/js/pages.js', 'media/com_fabrik/js/frontpackage.js'); FabrikHelperHTML::script($srcs); FabrikHelperHTML::stylesheet('media/com_fabrik/css/package.css'); $canvas = $item->params->get('canvas'); // $$$ rob 08/11/2011 test if component name set but still rendering // in option=com_fabrik then we should use fabrik as the package if ($input->get('option') === 'com_fabrik') { $item->component_name = 'fabrik'; } $tabs = FArrayHelper::getValue($canvas, 'tabs', array('Page 1')); $tabs = json_encode($tabs); $d = new stdClass(); $layout = json_encode(FArrayHelper::getValue($canvas, 'layout', $d)); $id = $this->get('State')->get('package.id'); $script = "window.addEvent('fabrik.loaded', function() {\n\t\t\tnew FrontPackage({\n\t\ttabs : {$tabs},\n\t\ttabelement : 'packagemenu',\n\t\tpagecontainer : 'packagepages',\n\t\tlayout: {$layout},\n\t\t'packageId': {$id},\n\t\t'package':'{$item->component_name}'\n\t});\n\t\t});"; FabrikHelperHTML::addScriptDeclaration($script); // Force front end templates $this->_basePath = COM_FABRIK_FRONTEND . '/views'; $tmpl = !isset($item->template) ? 'default' : $item->template; $this->addTemplatePath($this->_basePath . '/' . $this->_name . '/tmpl/' . $tmpl); $text = $this->loadTemplate(); FabrikHelperHTML::runContentPlugins($text); echo $text; }
/** * Set selected elements to be shown/not shown in list * * @return null */ public function toggleInList() { // Check for request forgeries JSession::checkToken() or die(FText::_('JINVALID_TOKEN')); // Get items to publish from the request. $app = JFactory::getApplication(); $input = $app->input; $cid = $input->get('cid', array(), 'array'); $data = array('showInListView' => 1, 'hideFromListView' => 0); $task = $this->getTask(); $value = FArrayHelper::getValue($data, $task, 0, 'int'); if (empty($cid)) { JError::raiseWarning(500, FText::_($this->text_prefix . '_NO_ITEM_SELECTED')); } else { // Get the model. $model = $this->getModel(); // Make sure the item ids are integers JArrayHelper::toInteger($cid); // Publish the items. if (!$model->addToListView($cid, $value)) { JError::raiseWarning(500, $model->getError()); } else { if ($value == 1) { $nText = $this->text_prefix . '_N_ITEMS_ADDED_TO_LIST_VIEW'; } else { $nText = $this->text_prefix . '_N_ITEMS_REMOVED_FROM_LIST_VIEW'; } $this->setMessage(JText::plural($nText, count($cid))); } } $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false)); }
/** * Return the javascript to create an instance of the class defined in formJavascriptClass * * @param array $args Array [0] => string table's form id to contain plugin * * @return bool */ public function onLoadJavascriptInstance($args) { if (!$this->canUse()) { return; } /** @var FabrikFEModelList $model */ $model = $this->getModel(); $params = $this->getParams(); $orderEl = $model->getFormModel()->getElement($params->get('order_element'), true); $opts = $this->getElementJSOptions(); $orderElName = FabrikString::safeColNameToArrayKey(FArrayHelper::getValue($model->orderEls, 0, '')); $opts->enabled = $orderElName == FabrikString::safeColNameToArrayKey($orderEl->getOrderByName()) ? true : false; $opts->listid = $model->getId(); $opts->orderElementId = $params->get('order_element'); $opts->handle = $params->get('order_element_as_handle', 1) == 1 ? '.' . $orderEl->getOrderByName() : false; $opts->direction = $opts->enabled ? $model->orderDirs[0] : ''; $opts->transition = ''; $opts->duration = ''; $opts->constrain = ''; $opts->clone = ''; $opts->revert = ''; $opts = json_encode($opts); $this->jsInstance = "new FbListOrder({$opts})"; return true; }
/** * Get the list's active/selected plug-ins * * @return array */ public function getPlugins() { $item = $this->getItem(); // Load up the active plug-ins $plugins = FArrayHelper::getValue($item->params, 'plugins', array()); return $plugins; }
/** * Get the foreign keys value. * * @return mixed string|int */ protected function fkData() { if (!isset($this->fkData)) { /** @var FabrikFEModelForm $formModel */ $formModel = $this->getModel(); $params = $this->getParams(); $this->fkData = array(); // Get the foreign key element $fkElement = $this->fkElement(); if ($fkElement) { $fkElementKey = $fkElement->getFullName(); $this->fkData = json_decode(FArrayHelper::getValue($formModel->formData, $fkElementKey)); if (is_object($this->fkData)) { $this->fkData = ArrayHelper::fromObject($this->fkData); } $fkEval = $params->get('foreign_key_eval', ''); if ($fkEval !== '') { $fkData = $this->fkData; $eval = eval($fkEval); if ($eval !== false) { $this->fkData = $eval; } } } } return $this->fkData; }
/** * Render uploaded image * * @param object &$model Element model * @param object &$params Element params * @param string $file Row data for this element * @param object $thisRow All row's data * * @return void */ public function render(&$model, &$params, $file, $thisRow = null) { /* * $$$ hugh - added this hack to let people use elementname__title as a title element * for the image, to show in the lightbox popup. * So we have to work out if we're being called from a table or form */ $formModel = $model->getFormModel(); $title = basename($file); if ($params->get('fu_title_element') == '') { $title_name = $model->getFullName(true, false) . '__title'; } else { $title_name = str_replace('.', '___', $params->get('fu_title_element')); } if ($this->inTableView) { if (array_key_exists($title_name, $thisRow)) { $title = $thisRow->{$title_name}; } } else { if (is_object($formModel)) { if (is_array($formModel->data)) { $title = FArrayHelper::getValue($formModel->data, $title_name, ''); } } } $bits = FabrikWorker::JSONtoData($title, true); $title = FArrayHelper::getValue($bits, $model->_repeatGroupCounter, $title); $title = htmlspecialchars(strip_tags($title, ENT_NOQUOTES)); $file = $model->getStorage()->getFileUrl($file); $fullSize = $file; if (!$this->fullImageInRecord($params)) { if ($params->get('fileupload_crop')) { $file = $model->getStorage()->_getCropped($fullSize); } else { $file = $model->getStorage()->_getThumb($file); } } list($width, $height) = $this->imageDimensions($params); $file = $model->storage->preRenderPath($file); $n = $this->inTableView ? '' : $model->getElement()->name; if ($params->get('restrict_lightbox', 1) == 0) { $n = ''; } $layout = $model->getLayout('image'); $displayData = new stdClass(); $displayData->lightboxAttrs = FabrikHelperHTML::getLightboxAttributes($title, $n); $displayData->fullSize = $model->storage->preRenderPath($fullSize); $displayData->file = $file; $displayData->makeLink = $params->get('make_link', true) && !$this->fullImageInRecord($params); $displayData->title = $title; $displayData->isJoin = $model->isJoin(); $displayData->width = $width; $displayData->showImage = $params->get('fu_show_image'); $displayData->inListView = $this->inTableView; $displayData->height = $height; $displayData->isSlideShow = $this->inTableView && $params->get('fu_show_image_in_table', '0') == '2' || !$this->inTableView && !$formModel->isEditable() && $params->get('fu_show_image', '0') == '3'; $this->output = $layout->render($displayData); }
/** * Prep the button. Show it if in heading (top of list) but not in rows * * @param array &$args Arguments * * @return bool; */ public function button(&$args) { $opts = FArrayHelper::getValue($args, 0, array()); $model = $this->getModel(); $this->buttonAction = $model->actionMethod(); $this->context = $model->getRenderContext(); $heading = (bool) FArrayHelper::getValue($opts, 'heading', false); return $heading; }
/** * Internally render the plugin, and add required script declarations * to the document * * @return void */ public function render() { $params = $this->getParams(); $document = JFactory::getDocument(); $document->addScript("http://api.simile-widgets.org/runway/1.0/runway-api.js"); $c = 0; $images = (array) $params->get('coverflow_image'); $titles = (array) $params->get('coverflow_title'); $subtitles = (array) $params->get('coverflow_subtitle'); $listIds = (array) $params->get('coverflow_table'); $eventData = array(); foreach ($listIds as $listId) { $listModel = JModelLegacy::getInstance('List', 'FabrikFEModel'); $listModel->setId($listId); $list = $listModel->getTable(); $listModel->getPagination(0, 0, 0); $image = $images[$c]; $title = $titles[$c]; $subtitle = $subtitles[$c]; $data = $listModel->getData(); if ($listModel->canView() || $listModel->canEdit()) { $elements = $listModel->getElements(); $imageElement = FArrayHelper::getValue($elements, FabrikString::safeColName($image)); foreach ($data as $group) { if (is_array($group)) { foreach ($group as $row) { $event = new stdClass(); if (!method_exists($imageElement, 'getStorage')) { switch (get_class($imageElement)) { case 'FabrikModelFabrikImage': $rootFolder = $imageElement->getParams()->get('selectImage_root_folder'); $rootFolder = JString::ltrim($rootFolder, '/'); $rootFolder = JString::rtrim($rootFolder, '/'); $event->image = COM_FABRIK_LIVESITE . 'images/stories/' . $rootFolder . '/' . $row->{$image . '_raw'}; break; default: $event->image = isset($row->{$image . '_raw'}) ? $row->{$image . '_raw'} : ''; break; } } else { $event->image = $imageElement->getStorage()->pathToURL($row->{$image . '_raw'}); } $event->title = $title === '' ? '' : (string) strip_tags($row->{$title}); $event->subtitle = $subtitle === '' ? '' : (string) strip_tags($row->{$subtitle}); $eventData[] = $event; } } } } $c++; } $json = json_encode($eventData); $str = "var coverflow = new FbVisCoverflow({$json});"; $srcs = FabrikHelperHTML::framework(); $srcs['Coverflow'] = $this->srcBase . 'coverflow/coverflow.js'; FabrikHelperHTML::script($srcs, $str); }
/** * Validate the elements data against the rule * * @param string $data To check * @param int $repeatCounter Repeat group counter * * @return bool true if validation passes, false if fails */ public function validate($data, $repeatCounter) { $params = $this->getParams(); $elementModel = $this->elementModel; // As ornot is a radio button it gets json encoded/decoded as an object $orNot = $params->get('userexists_or_not', 'fail_if_exists'); jimport('joomla.user.helper'); $result = JUserHelper::getUserId($data); if ($this->user->get('guest')) { if (!$result) { if ($orNot == 'fail_if_exists') { return true; } } else { if ($orNot == 'fail_if_not_exists') { return true; } } return false; } else { if (!$result) { if ($orNot == 'fail_if_exists') { return true; } } else { $userField = $params->get('userexists_user_field'); $userId = 0; if ((int) $userField !== 0) { $userElementModel = FabrikWorker::getPluginManager()->getElementPlugin($userField); $userFullName = $userElementModel->getFullName(true, false); $userField = $userElementModel->getFullName(false, false); } if (!empty($userField)) { // $$$ the array thing needs fixing, for now just grab 0 $formData = $elementModel->getForm()->formData; $userId = FArrayHelper::getValue($formData, $userFullName . '_raw', FArrayHelper::getValue($formData, $userFullName, '')); if (is_array($userId)) { $userId = FArrayHelper::getValue($userId, 0, ''); } } if ($userId != 0) { if ($result == $userId) { return $orNot == 'fail_if_exists' ? true : false; } return false; } else { // The connected user is editing his own data if ($result == $this->user->get('id')) { return $orNot == 'fail_if_exists' ? true : false; } return false; } } return false; } }
/** * 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); }
/** * Send SMS * * @param string $message sms message * @param array $opts Options * * @return void */ public function process($message, $opts) { $username = FArrayHelper::getValue($opts, 'sms-username'); $password = FArrayHelper::getValue($opts, 'sms-password'); $smsfrom = FArrayHelper::getValue($opts, 'sms-from'); $smsto = FArrayHelper::getValue($opts, 'sms-to'); $url = sprintf($this->url, $username, $smsto, $smsfrom, urlencode($message)); $response = FabrikSMS::doRequest('GET', $url, ''); return strstr($response, 'api_') !== false; }
/** * Send SMS * * @param string $message sms message * @param array $opts Options * * @return void */ public function process($message, $opts) { $username = FArrayHelper::getValue($opts, 'sms-username'); $password = FArrayHelper::getValue($opts, 'sms-password'); $smsfrom = FArrayHelper::getValue($opts, 'sms-from'); $smsto = FArrayHelper::getValue($opts, 'sms-to'); $smstos = explode(',', $smsto); foreach ($smstos as $smsto) { $url = sprintf($this->url, $username, $password, $smsto, $message); FabrikSMS::doRequest('GET', $url, ''); } }
/** * Exif to number * * @param string $value Value * @param string $format Format * * @return string */ protected function exifToNumber($value, $format) { $spos = JString::strpos($value, '/'); if ($spos === false) { return sprintf($format, $value); } else { $bits = explode('/', $value, 2); $base = FArrayHelper::getValue($bits, 0); $divider = FArrayHelper::getValue($bits, 1); return $divider == 0 ? sprintf($format, 0) : sprintf($format, $base / $divider); } }
/** * Create the SQL select 'name AS alias' segment for list/form queries * * @param array &$aFields array of element names * @param array &$aAsFields array of 'name AS alias' fields * @param array $opts options * * @return void */ public function getAsField_html(&$aFields, &$aAsFields, $opts = array()) { $dbTable = $this->actualTableName(); $db = FabrikWorker::getDbo(); if ($this->app->input->get('c') != 'form') { $params = $this->getParams(); $fullElName = FArrayHelper::getValue($opts, 'alias', $db->qn($dbTable . '___' . $this->getElement()->name)); $r = 'COUNT(' . $params->get('count_field', '*') . ')'; $aFields[] = $r . ' AS ' . $fullElName; $aAsFields[] = $fullElName; $aAsFields[] = $db->qn($dbTable . '___' . $this->getElement()->name . '_raw'); } }
/** * Prep the button if needed * * @param array &$args Arguments * * @return bool; */ public function button(&$args) { parent::button($args); $heading = false; if (!empty($args)) { $heading = FArrayHelper::getValue($args[0], 'heading'); } if ($heading) { return true; } $params = $this->getParams(); return (bool) $params->get('button_in_row', true); }
/** * Short cut for getting the element's filter value * * @param int $elementId Element id * * @since 3.0.7 * * @return string */ public static function filterValue($elementId) { $app = JFactory::getApplication(); $pluginManager = FabrikWorker::getPluginManager(); $model = $pluginManager->getElementPlugin($elementId); $listModel = $model->getListModel(); $listid = $listModel->getId(); $key = 'com_fabrik.list' . $listid . '_com_fabrik_' . $listid . '.filter'; $filters = JArrayHelper::fromObject($app->getUserState($key)); $elementIds = (array) FArrayHelper::getValue($filters, 'elementid', array()); $index = array_search($elementId, $elementIds); $value = $filters['value'][$index]; return $value; }
/** * Validate the elements data against the rule * * @param string $data To check * @param int $repeatCounter Repeat group counter * * @return bool true if validation passes, false if fails */ public function validate($data, $repeatCounter) { $input = $this->app->input; $elementModel = $this->elementModel; // Could be a dropdown with multivalues if (is_array($data)) { $data = implode('', $data); } $params = $this->getParams(); $otherField = $params->get('areuniquevalues-otherfield', ''); $listModel = $elementModel->getlistModel(); $table = $listModel->getTable(); if ((int) $otherField !== 0) { $otherElementModel = $this->getOtherElement(); $otherFullName = $otherElementModel->getFullName(true, false); $otherField = $otherElementModel->getFullName(false, false); } else { // Old fabrik 2.x params stored element name as a string $otherFullName = $table->db_table_name . '___' . $otherField; } $db = $listModel->getDb(); $lookupTable = $db->qn($table->db_table_name); $data = $db->q($data); $query = $db->getQuery(true); $query->select('COUNT(*)')->from($lookupTable)->where($db->qn($elementModel->getFullName(false, false)) . ' = ' . $data); $listModel->buildQueryJoin($query); if (!empty($otherField)) { // $$$ the array thing needs fixing, for now just grab 0 $formData = $elementModel->getForm()->formData; $v = FArrayHelper::getValue($formData, $otherFullName . '_raw', FArrayHelper::getValue($formData, $otherFullName, '')); if (is_array($v)) { $v = FArrayHelper::getValue($v, 0, ''); } $query->where($db->qn($otherField) . ' = ' . $db->quote($v)); } /* $$$ hugh - need to check to see if we're editing a record, otherwise * will fail 'cos it finds the original record (assuming this element hasn't changed) * @TODO - is there a better way getting the rowid? What if this is form a joined table? */ $rowId = $input->get('rowid'); if (!empty($rowId)) { $query->where($table->db_primary_key . ' != ' . $db->q($rowId)); } $db->setQuery($query); $c = $db->loadResult(); return $c == 0 ? true : false; }
/** * process the plugin, called after form is submitted * * @return bool */ public function onAfterProcess() { $params = $this->getParams(); $w = new FabrikWorker(); $formModel = $this->getModel(); // @FIXME to use selected connection $upsertDb = $this->getDb(); $query = $upsertDb->getQuery(true); $this->data = $this->getProcessData(); if (!$this->shouldProcess('upsert_conditon', null, $params)) { return; } $table = $this->getTableName(); $pk = FabrikString::safeColName($params->get('primary_key')); $rowId = $params->get('row_value', ''); // Used for updating previously added records. Need previous pk val to ensure new records are still created. $origData = $formModel->getOrigData(); $origData = FArrayHelper::getValue($origData, 0, new stdClass()); if (isset($origData->__pk_val)) { $this->data['origid'] = $origData->__pk_val; } $rowId = $w->parseMessageForPlaceholder($rowId, $this->data, false); $upsertRowExists = $this->upsertRowExists($table, $pk, $rowId); /** * If row exists and "insert only", or row doesn't exist and "update only", bail out */ if ($upsertRowExists && $params->get('upsert_insert_only', '0') === '1' || !$upsertRowExists && $params->get('upsert_insert_only', '0') === '2') { return true; } $fields = $this->upsertData($upsertRowExists); $query->set($fields); if ($rowId === '') { $query->insert($table); } else { if ($upsertRowExists) { $query->update($table)->where($pk . ' = ' . $upsertDb->quote($rowId)); } else { $query->insert($table); } } $upsertDb->setQuery($query); $upsertDb->execute(); return true; }
/** * Assign module settings to the list model * * @param JRegistry $params Module parameters * @param JModelLegacy &$model List model * * @return $model */ public static function applyParams($params, &$model) { $app = JFactory::getApplication(); $input = $app->input; $useajax = $params->get('useajax', ''); $showTitle = $params->get('show-title', ''); $limit = (int) $params->get('limit', 0); $listParams = $model->getParams(); $listParams->set('show-table-picker', false); $random = intval($params->get('radomizerecords', 0)); if ($limit !== 0) { $app->setUserState('com_fabrik.list' . $model->getRenderContext() . '.limitlength', $limit); $input->set('limit', $limit); } if ($useajax !== '') { $model->set('ajax', $useajax); } if ($params->get('ajax_links') !== '') { $listParams->set('list_ajax_links', $params->get('ajax_links')); } $links = array('addurl', 'editurl', 'detailurl'); foreach ($links as $link) { if ($params->get($link, '') !== '') { $listParams->set($link, $params->get($link)); } } if ($showTitle !== '') { $listParams->set('show-title', $showTitle); } $model->randomRecords = $random; // Set up prefilters - will overwrite ones defined in the list! $prefilters = JArrayHelper::fromObject(json_decode($params->get('prefilters'))); $conditions = (array) $prefilters['filter-conditions']; if (!empty($conditions)) { $joins = FArrayHelper::getValue($prefilters, 'filter-join', array()); $listParams->set('filter-join', $joins); $listParams->set('filter-fields', $prefilters['filter-fields']); $listParams->set('filter-conditions', $prefilters['filter-conditions']); $listParams->set('filter-value', $prefilters['filter-value']); $listParams->set('filter-access', $prefilters['filter-access']); $listParams->set('filter-eval', FArrayHelper::getValue($prefilters, 'filter-eval')); } return $model; }
/** * Set the google map style * * @param object $params Element/vis parameters (contains gmap_styles property as json string) * * @since 3.0.7 * * @return array Styles */ public static function styleJs($params) { $optStyles = array(); $styles = json_decode($params->get('gmap_styles')); if (!$styles) { return array(); } // Map Feature type to style $features = $styles->style_feature; // What exactly to style in the feature type (road, fill, border etc) $elements = $styles->style_element; $styleKeys = $styles->style_styler_key; $styleValues = $styles->style_styler_value; // First merge any identical feature styles $stylers = array(); for ($i = 0; $i < count($features); $i++) { $feature = FArrayHelper::getValue($features, $i); $element = FArrayHelper::getValue($elements, $i); $key = $feature . '|' . $element; if (!array_key_exists($key, $stylers)) { $stylers[$key] = array(); } $aStyle = new stdClass(); $styleKey = FArrayHelper::getValue($styleKeys, $i); $styleValue = FArrayHelper::getValue($styleValues, $i); if ($styleKey && $styleValue) { $aStyle->{$styleKey} = $styleValue; $stylers[$key][] = $aStyle; } } $return = array(); foreach ($stylers as $styleKey => $styler) { $o = new stdClass(); $bits = explode('|', $styleKey); if ($bits[0] !== 'all') { $o->featureType = $bits[0]; $o->elementType = $bits[1]; } $o->stylers = $styler; $return[] = $o; } return $return; }
/** * Trigger called when a row is stored. * If we are creating a new record, and the element was set to readonly * then insert the users data into the record to be stored * * @param array &$data Data to store * @param int $repeatCounter Repeat group index * * @return bool If false, data should not be added. */ public function onStoreRow(&$data, $repeatCounter = 0) { if (!parent::onStoreRow($data, $repeatCounter)) { return false; } $element = $this->getElement(); $formModel = $this->getFormModel(); $formData = $formModel->formData; if (FArrayHelper::getValue($formData, 'rowid', 0) == 0 && !in_array($element->name, $data)) { $data[$element->name] = $_SERVER['REMOTE_ADDR']; } else { $params = $this->getParams(); if ($params->get('ip_update_on_edit', 0)) { $data[$element->name] = FabrikString::filteredIp(); $data[$element->name . '_raw'] = FabrikString::filteredIp(); } } return true; }
/** * Method to publish a list of items * * @return null */ public function publish() { $app = JFactory::getApplication(); $input = $app->input; $cid = $input->get('cid', array(), 'array'); $data = array('publish' => 1, 'unpublish' => 0, 'archive' => 2, 'trash' => -2, 'report' => -3); $task = $this->getTask(); $value = FArrayHelper::getValue($data, $task, 0, 'int'); if (empty($cid)) { JError::raiseWarning(500, FText::_($this->text_prefix . '_NO_ITEM_SELECTED')); } else { // Make sure the item ids are integers JArrayHelper::toInteger($cid); $model = $this->getModel('Form', 'FabrikAdminModel'); $formIds = $model->swapListToFormIds($cid); // Publish the items. if (!$model->publish($formIds, $value)) { JError::raiseWarning(500, $model->getError()); } else { // Publish the groups $groupModel = $this->getModel('Group'); if (is_object($groupModel)) { $groupIds = $groupModel->swapFormToGroupIds($formIds); if (!empty($groupIds)) { if ($groupModel->publish($groupIds, $value) === false) { JError::raiseWarning(500, $groupModel->getError()); } else { // Publish the elements $elementModel = $this->getModel('Element'); $elementIds = $elementModel->swapGroupToElementIds($groupIds); if (!$elementModel->publish($elementIds, $value)) { JError::raiseWarning(500, $elementModel->getError()); } } } } // Finally publish the list parent::publish(); } } $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false)); }
/** * 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) { $name = $this->getHTMLName($repeatCounter); $params = $this->getParams(); $formModel = $this->getFormModel(); $userEl = $formModel->getElement($params->get('user_element'), true); $thisUser = false; if ($userEl) { $data = $formModel->getData(); $userId = FArrayHelper::getValue($data, $userEl->getFullName(true, false) . '_raw', 0); // Failed validation if (is_array($userId)) { $userId = FArrayHelper::getValue($userId, 0); } $thisUser = !empty($userId) ? JFactory::getUser($userId) : false; } $selected = $this->getValue($data, $repeatCounter); if (is_string($selected)) { $selected = json_decode($selected); } if (!$this->isEditable()) { if (!empty($thisUser)) { $selected = $thisUser->groups; } // Get the titles for the user groups. //if (count($selected) > 0) if (!FArrayHelper::emptyish($selected)) { $query = $this->_db->getQuery(true); $query->select($this->_db->qn('title')); $query->from($this->_db->qn('#__usergroups')); $query->where($this->_db->qn('id') . ' IN ( ' . implode(' , ', $selected) . ')'); $this->_db->setQuery($query); $selected = $this->_db->loadColumn(); } } $layout = $this->getLayout('form'); $layoutData = new stdClass(); $layoutData->isEditable = $this->isEditable(); $layoutData->input = JHtml::_('access.usergroups', $name, $selected, true); $layoutData->selected = is_array($selected) ? implode(', ', $selected) : ''; return $layout->render($layoutData); }
/** * Send SMS * * @param string $message sms message * @param array $opts options * * @return void */ public function process($message = '', $opts) { jimport('vendor.twilio.sdk.Services.Twilio'); $username = FArrayHelper::getValue($opts, 'sms-username'); $token = FArrayHelper::getValue($opts, 'sms-password'); $smsto = FArrayHelper::getValue($opts, 'sms-to'); // From a valid Twilio number $smsfrom = FArrayHelper::getValue($opts, 'sms-from'); $smstos = explode(",", $smsto); $client = new Services_Twilio($username, $token); foreach ($smstos as $smsto) { try { $call = $client->account->messages->create(array('From' => $smsfrom, 'To' => $smsto, 'Body' => $message)); } catch (Services_Twilio_RestException $e) { //echo $e->getMessage(); return false; } } return true; }
/** * Send SMS * * @param string $message sms message * @param array $opts Options * * @return void */ public function process($message, $opts) { $username = FArrayHelper::getValue($opts, 'sms-username'); $password = FArrayHelper::getValue($opts, 'sms-password'); $smsfrom = FArrayHelper::getValue($opts, 'sms-from'); $smsto = FArrayHelper::getValue($opts, 'sms-to'); $smstos = explode(",", $smsto); $message = urlencode($message); foreach ($smstos as $smsto) { if (substr($smsto, 0, 1) == '+' && JString::substr($smsto, 1, 2) != '44') { // Global sms $route = 8; } else { // UK (itagg) $route = 7; } $smsto = urlencode($smsto); $url = $this->url; $vars = 'usr='******'&pwd=' . $password . '&from=rob&to=' . $smsto . '&type=text&route=' . $route . '&txt=' . $message; $itaggapi = "https://secure.itagg.com/smsg/sms.mes"; /* $params="usr=XXX&pwd=YYY&from=steve&to=07712345678,447912345678,3912345678&type=text&rout e=7&txt=hello+via+POST"; */ $ch = curl_init(); if (!$ch) { throw new RuntimeException("cant ini curl session", 500); exit; } curl_setopt($ch, CURLOPT_URL, $itaggapi); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $vars); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $returned = curl_exec($ch); curl_close($ch); // This will be the OK / error message if ($returned === true) { echo "sent ok"; } $res = FabrikSMS::doRequest('POST', $url, $vars); } }
/** * 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) { $values = $this->getSubOptionValues(); $labels = $this->getSubOptionLabels(); $selected = (array) $this->getValue($data, $repeatCounter); $i = 0; $to = array(); $from = array(); foreach ($values as $v) { if (!in_array($v, $selected)) { $from[$v] = $labels[$i]; } $i++; } $i = 0; $lookup = array_flip($values); foreach ($selected as $v) { if ($v == '' || $v == '-' || $v == '[""]') { continue; } $k = FArrayHelper::getValue($lookup, $v); $tmpTxt = addslashes(htmlspecialchars(FArrayHelper::getValue($labels, $k))); $to[$v] = $tmpTxt; $i++; } if (!$this->isEditable()) { return implode(', ', $to); } FabrikHelperHTML::stylesheet(COM_FABRIK_LIVESITE . 'plugins/fabrik_element/picklist/picklist.css'); $layout = $this->getLayout('form'); $layoutData = new stdClass(); $layoutData->id = $this->getHTMLId($repeatCounter); $layoutData->errorCSS = $this->elementError != '' ? ' elementErrorHighlight' : ''; $layoutData->from = $from; $layoutData->to = $to; $layoutData->name = $this->getHTMLName($repeatCounter); $layoutData->value = json_encode($selected); $layoutData->addOptionsUi = $this->getAddOptionFields($repeatCounter); return $layout->render($layoutData); }
/** * Display the view * * @param string $tpl Template * * @return void */ public function display($tpl = null) { // Initialise variables. JHtml::_('behavior.modal', 'a.modal'); $model = $this->getModel(); $this->form = $this->get('Form'); $this->item = $this->get('Item'); $this->state = $this->get('State'); $this->listform = $this->get('PackageListForm'); // Check for errors. if (count($errors = $this->get('Errors'))) { throw new RuntimeException(implode("\n", $errors), 500); } $this->addToolbar(); $canvas = FArrayHelper::getValue($this->item->params, 'canvas', array()); $blocks = new stdClass(); $b = FArrayHelper::getValue($canvas, 'blocks', array()); $blocks->form = FArrayHelper::getValue($b, 'form', array()); $blocks->list = FArrayHelper::getValue($b, 'list', array()); $blocks->visualization = FArrayHelper::getValue($b, 'visualization', array()); $opts = JArrayHelper::getvalue($canvas, 'options', array()); $d = new stdClass(); $layout = FArrayHelper::getValue($canvas, 'layout', $d); $document = JFactory::getDocument(); $opts = new stdClass(); $opts->blocks = $blocks; $opts->layout = $layout; $opts = json_encode($opts); $this->js = "PackageCanvas = new AdminPackage({$opts});"; $srcs[] = 'administrator/components/com_fabrik/views/package/adminpackage.js'; FabrikHelperHTML::iniRequireJS(); FabrikHelperHTML::script($srcs, $this->js); // Simple layout $this->listOpts = $model->getListOpts(); $this->formOpts = $model->getFormOpts(); $this->selFormOpts = $model->getSelFormOpts(); $this->selListOpts = $model->getSelListOpts(); FabrikAdminHelper::setViewLayout($this); parent::display($tpl); }
/** * 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; }