Más contenido relacionado La actualidad más candente (20) Similar a Hidden in plain site – joomla! hidden secrets for code monkeys (20) Más de Nicholas Dionysopoulos (11) Hidden in plain site – joomla! hidden secrets for code monkeys7. Date and Time
$dateString = '2015-05-31 12:00:00';
$date = JFactory::getDate($dateString);
$format = JText::_('DATE_FORMAT_LC2');
echo $date->format($format);
11. $http = JHttpFactory::getHttp();
$response = $http->get('http://www.joomla.org/
download.html');
$this->out("HTTP Code: " . $response->code);
$this->out("Headers:n" . print_r($response-
>headers, true));
HTTP Transfers
without the pain of cURL and stream contexts
12. $stream = new JStream();
$stream->open(JPATH_SITE . '/tmp/temp.gz', 'w',
false, null, false, false, true);
$stream->write($buffer);
$stream->chmod();
$stream->close();
Stream file I/O
with transparent GZip / BZip2 support
15. $image = new JImage(__DIR__ . '/image.jpg');
$image->createThumbs([
'640x480', '320x200', '160x100', ‘80x50'
], JImage::SCALE_FILL, __DIR__ . '/thumbs');
Image manipulation
Thumbnails
16. $image = new JImage(__DIR__ . '/image.jpg');
$newImage = $image
->filter('grayscale')
->rotate('10', 0xFFFFFF, true)
->resize(320, 200);
$newImage->toFile(
__DIR__ . ‘/altered.png',
IMAGETYPE_PNG
);
Image manipulation
Alter and convert images
21. $config = [
'dbinstaller_directory' => '/path/to/xml/files',
'option' => 'com_example'
];
$schemaUpdater = new FOFDatabaseInstaller($config);
// Install or update schema
$schemaUpdater->updateSchema();
// Remove the schema
$schemaUpdater->removeSchema();
XML-based schema updates
using FOFDatabaseInstaller
23. $db = JFactory::getDbo();
$importer = $db->getImporter();
$importer->from($xml);
// Bug: mergeStructure is protected. Sad panda :(
// $importer->mergeStructure();
$reflection = new ReflectionObject($importer);
$method = $reflection->getMethod('mergeStructure');
$method->setAccessible(true);
$method->invoke($importer);
Importing the database
Here Be Dragons!
28. // Set up
$plugin = JFactory::getApplication()->getParams()
->get('captcha',
JFactory::getConfig()->get('captcha'));
$captcha = JCaptcha::getInstance($plugin, array(
'namespace' => 'myComponent'
));
// Show
echo $captcha->display('mycaptcha', 'mycaptcha');
// Validate
$code = JFactory::getApplication()->input->get('mycaptcha');
if (!$captcha->checkAnswer($code))
{
throw new RuntimeException('Bots not welcome', 403);
}
CAPTCHA
Keep bots away
29. $less = new JLess();
$less->ccompile($lessFile, $cssFile);
Compile LESS to CSS
Server-side, cached
32. More than a CMS
Custom application types
• JApplicationCLI
• JApplicationWeb
• JApplicationDaemon