Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Hidden in plain site – joomla! hidden secrets for code monkeys

1,538 views

Published on

How well do you know the API tools Joomla! 3 has to offer to developers? Take the guided tour with an experienced Joomla! developer and long-time contributor.

Published in: Technology

Hidden in plain site – joomla! hidden secrets for code monkeys

  1. 1. Hidden in plain site Joomla! hidden secrets for code monkeys
  2. 2. Junior Dev Stuff
  3. 3. Input $app = JFactory::getApplication();
 $option = $app->input ->getCmd(‘option’);
  4. 4. File uploads with security check $app = JFactory::getApplication();
 $option = $app->input->files
 ->get('file', array());
  5. 5. File uploads without security check $app = JFactory::getApplication();
 $option = $app->input->files
 ->get('file', array(), 'raw');
  6. 6. Date and Time $dateString = '2015-05-31 12:00:00';
 $date = JFactory::getDate($dateString);
 $format = JText::_('DATE_FORMAT_LC2');
 echo $date->format($format);
  7. 7. URI manipulation $uri = JUri::getInstance();
 $uri->setVar('joomla', 'rocks');
 echo $uri->toString();
  8. 8. Serious low-level stuff
  9. 9. $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
  10. 10. $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
  11. 11. JArchive::extract($archiveName, $targetFolder); Extract archives
 zip, tar, tar.gz / tgz, tar.bz2 / tbz
  12. 12. JStringPunycode::emailToPunycode('üser@êxαmpłe.com' );
 // üser@xn--xmpe-fpa54cg0l.com
 
 JStringPunycode::urlToPunycode('http:// www.παράδειγμα.com');
 // http://www.xn--hxajbheg2az3al.com
 
 JStringPunycode::fromPunycode('http://www.xn-- hxajbheg2az3al.com');
 // http://www.παράδειγμα.com UTF-8 Domains
 a.k.a. “Punycode” or IDNA conversion
  13. 13. $image = new JImage(__DIR__ . '/image.jpg');
 $image->createThumbs([ '640x480', '320x200', '160x100', ‘80x50' ], JImage::SCALE_FILL, __DIR__ . '/thumbs'); Image manipulation
 Thumbnails
  14. 14. $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
  15. 15. Files and databases
  16. 16. GitHub integration
 JGithub
  17. 17. $patcher = JFilesystemPatcher::getInstance();
 $patcher
 ->reset()
 ->addFile( __DIR__ . ‘/file1.patch', JPATH_BASE, 1 );
 $patcher->apply(); Apply patch files
 JFilesystemPatcher
  18. 18. $schemaUpdater = JSchemaChangeset::getInstance( $db, '/path/to/sql/files' );
 $errors = $schemaUpdater->check();
 $schemaUpdater->fix(); Update the schema
 or get a list of errors (changes not applied)
  19. 19. $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
  20. 20. $db = JFactory::getDbo();
 $exporter = $db->getExporter();
 $xml = $exporter->asXml(); Exporting the database
 Here Be Dragons!
  21. 21. $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!
  22. 22. Dial the awesome to eleven!
  23. 23. Services Lots of!
  24. 24. JFacebook JLinkedin JGoogle JTwitter JMediawiki JOpenstreetmapJOauth1Client JOauth2Client Services Lots of!
  25. 25. Cryptography
 JKeychain & JCrypt • 3DES • Blowfish • Rijndael256 (AES) • Simple (don’t use) • mcrypt
  26. 26. // 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
  27. 27. $less = new JLess();
 $less->ccompile($lessFile, $cssFile); Compile LESS to CSS
 Server-side, cached
  28. 28. $pathway = JFactory::getApplication() ->getPathway();
 $pathway->addItem('MyItem', $url); Manipulate breadcrumbs
 Custom, in-component pathways
  29. 29. Microdata
 Schema.org support https://docs.joomla.org/Microdata
  30. 30. More than a CMS
 Custom application types • JApplicationCLI • JApplicationWeb • JApplicationDaemon
  31. 31. Photos by Smithsonian Institution, National Museum of American History
  32. 32. May the Core be with you
  33. 33. The End

×