Radomizing Image Filenames

From Littledamien Wiki
Revision as of 14:20, 12 March 2012 by Video8 (talk | contribs) (moved Radomizing Image Names to Radomizing Image Filenames)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Setting image upload randomization

  • In the PHP parent record class, set the image object's randomize property value.
  • Make sure that the value is not overwritten by fill_from_input() unless it's truly intended.
class ParentContent extends db_content_class
{
	function __construct()
	{
		parent::__construct();
		$this->image = new image_upload_class($this->SECTION_ID(), $this->id->value);
		$this->image->randomize->value = self::RANDOMIZE_IMAGE_FILENAME; /* <<< set randomization here (TRUE or FALSE) */
	}

	public function fill_from_input()
	{
		parent::fill_from_input();
		$this->image->randomize->value = self::RANDOMIZE_IMAGE_FILENAME; /* <<< make sure the value is not overridden ever */
	}
}

JavaScript/AJAX

HTML thumbnail container attributes

  • .gallery-tn-container assigned "click" handler which displays edit and delete buttons.
    • "click" assignment: LITTLED.Gallery.bindImageOverlayHandlers()
    • .gallery-tn-container template file: [COMMON_LIB]_templates/forms/images/image_upload_link.php
  • .gallery-tn-container attributes:
    • data-id image link record id
    • data-pid parent record id
    • data-tid content type id of the parent record
    • data-op operation, e.g. "upload", "edit", or "delete"
    • data-rand randomization flag
      • Randomization attribute value is assigned by the PHP image_upload_class passed to the thumbnail template

How the randomization flag value is passed to the AJAX script

  • .gallery-tn-container onClick handler copies its attributes to the edit and delete buttons.
  • upload/edit button (#edit-galltn-btn) has onClick handler LITTLED.Gallery.selectThumbnail()
    • randomization flag value is retrieved from the edit button's attributes
    • randomization flag value is passed to the AJAX script

Upload script

  • Image upload AJAX script: [COMMON_LIB]ajax/images/upload_image.php
  • parameter ilrf determines randomization, e.g.:
/ajax/images/upload_image.php?ilrf=[true|false]

PHP code

  • image_upload_class->randomize holds value used as switch to randomize image filenames
  • image_upload_class->randomize set in either image_upload_class::fill_from_input() or image_upload_class::fill_inline_input()
  • image_upload_class inherits its save() routine from image_link_class::save($saveKeywords=false, $randomizeFilename=false)