/** * Internal method to get a JavaScript object notation string from an array * * @param array $array The array to convert to JavaScript object notation * @return string JavaScript object notation representation of the array * @since 1.5 */ function _getJSObject($array = array()) { // Initialize variables $object = '{'; // Iterate over array to build objects foreach ((array) $array as $k => $v) { if (is_null($v)) { continue; } if (!is_array($v) && !is_object($v)) { $object .= ' ' . $k . ': '; $object .= is_numeric($v) || strpos($v, '\\') === 0 ? is_numeric($v) ? $v : substr($v, 1) : "'" . $v . "'"; $object .= ','; } else { $object .= ' ' . $k . ': ' . JHTMLBehavior::_getJSObject($v) . ','; } } if (substr($object, -1) == ',') { $object = substr($object, 0, -1); } $object .= '}'; return $object; }
function uploader($id = 'file-upload', $params = array()) { $path = 'administrator/components/com_phocagallery/assets/upload/'; JHTML::script('swf.js', $path, false); // mootools are loaded yet JHTML::script('uploader.js', $path, false); // mootools are loaded yet static $uploaders; if (!isset($uploaders)) { $uploaders = array(); } if (isset($uploaders[$id]) && $uploaders[$id]) { return; } // Setup options object $opt['url'] = isset($params['targetURL']) ? $params['targetURL'] : null; $opt['swf'] = isset($params['swf']) ? $params['swf'] : JURI::root(true) . '/media/system/swf/uploader.swf'; $opt['multiple'] = isset($params['multiple']) && !$params['multiple'] ? '\\false' : '\\true'; $opt['queued'] = isset($params['queued']) && !$params['queued'] ? '\\false' : '\\true'; $opt['queueList'] = isset($params['queueList']) ? $params['queueList'] : 'upload-queue'; $opt['instantStart'] = isset($params['instantStart']) && $params['instantStart'] ? '\\true' : '\\false'; $opt['allowDuplicates'] = isset($params['allowDuplicates']) && !$params['allowDuplicates'] ? '\\false' : '\\true'; $opt['limitSize'] = isset($params['limitSize']) && $params['limitSize'] ? (int) $params['limitSize'] : null; $opt['limitFiles'] = isset($params['limitFiles']) && $params['limitFiles'] ? (int) $params['limitFiles'] : null; $opt['optionFxDuration'] = isset($params['optionFxDuration']) ? (int) $params['optionFxDuration'] : null; $opt['container'] = isset($params['container']) ? '\\$(' . $params['container'] . ')' : '\\$(\'' . $id . '\').getParent()'; $opt['types'] = isset($params['types']) ? '\\' . $params['types'] : '\\{\'All Files (*.*)\': \'*.*\'}'; // Optional functions $opt['createReplacement'] = isset($params['createReplacement']) ? '\\' . $params['createReplacement'] : null; $opt['onComplete'] = isset($params['onComplete']) ? '\\' . $params['onComplete'] : null; $opt['onAllComplete'] = isset($params['onAllComplete']) ? '\\' . $params['onAllComplete'] : null; /* types: Object with (description: extension) pairs, default: Images (*.jpg; *.jpeg; *.gif; *.png) */ $options = JHTMLBehavior::_getJSObject($opt); // Attach tooltips to document $document =& JFactory::getDocument(); $uploaderInit = 'sBrowseCaption=\'' . JText::_('Browse Files', true) . '\'; sRemoveToolTip=\'' . JText::_('Remove from queue', true) . '\'; window.addEvent(\'load\', function(){ var Uploader = new FancyUpload($(\'' . $id . '\'), ' . $options . '); $(\'upload-clear\').adopt(new Element(\'input\', { type: \'button\', events: { click: Uploader.clearList.bind(Uploader, [false])}, value: \'' . JText::_('Clear Completed') . '\' })); });'; $document->addScriptDeclaration($uploaderInit); // Set static array $uploaders[$id] = true; return; }
public static function tooltip($selector = '.hasTip', $params = array()) { static $tips; if (!isset($tips)) { $tips = array(); } // Include mootools framework JHtml::_('behavior.framework', true); $sig = md5(serialize(array($selector, $params))); if (isset($tips[$sig]) && $tips[$sig]) { return; } // Setup options object $opt['maxTitleChars'] = isset($params['maxTitleChars']) && $params['maxTitleChars'] ? (int) $params['maxTitleChars'] : 50; // offsets needs an array in the format: array('x'=>20, 'y'=>30) $opt['offsets'] = isset($params['offsets']) && is_array($params['offsets']) ? $params['offsets'] : null; $opt['showDelay'] = isset($params['showDelay']) ? (int) $params['showDelay'] : null; $opt['hideDelay'] = isset($params['hideDelay']) ? (int) $params['hideDelay'] : null; $opt['className'] = isset($params['className']) ? $params['className'] : null; $opt['fixed'] = isset($params['fixed']) && $params['fixed'] ? '\\true' : '\\false'; $opt['onShow'] = isset($params['onShow']) ? '\\' . $params['onShow'] : null; $opt['onHide'] = isset($params['onHide']) ? '\\' . $params['onHide'] : null; $options = JHTMLBehavior::_getJSObject($opt); // Attach tooltips to document $document =& JFactory::getDocument(); $document->addScriptDeclaration("\n\t\twindow.addEvent('domready', function() {\n\t\t\t\$\$('{$selector}').each(function(el) {\n\t\t\t\tvar title = el.get('title');\n\t\t\t\tif (title) {\n\t\t\t\t\tvar parts = title.split('::', 2);\n\t\t\t\t\tel.store('tip:title', parts[0]);\n\t\t\t\t\tel.store('tip:text', parts[1]);\n\t\t\t\t}\n\t\t\t});\n\t\t\tvar JTooltips = new Tips(\$\$('{$selector}'), {$options});\n\t\t});"); // Set static array $tips[$sig] = true; return; }
function jdGetDirectory($callback, $folder, $getFiles = false, $filter = '*') { jimport('joomla.filesystem.file'); jimport('joomla.filesystem.file'); $folder = JPath::clean(JPATH_ROOT . DS . $folder); JPath::check($folder); $response = new XajaxResponse(); if (!is_dir($folder)) { return $response; } $result = array(); $dirs = JFolder::folders($folder, '', false, true); foreach ($dirs as $dir) { $dirData = array(); $dirData['permission'] = substr(sprintf("%o", fileperms($dir)), -3); if ($getFiles) { $fileData = array(); $files = glob($folder . DS . $filter); foreach ($files as $f) { $fileData[$f]['permission'] = substr(sprintf("%o", fileperms($f)), -3); } } $result[$dir]['info'] = $dirData; $result[$dir]['files'] = $fileData; } $response->script($callback . '(' . JHTMLBehavior::_getJSObject($result) . ')'); return $response; }