edit-icon-license-list.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?
  2. $src = '../LICENSE-ICONS-3RD-PARTY.json';
  3. // check for ajax request
  4. if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
  5. return file_put_contents($src, json_encode($_POST['list'], JSON_PRETTY_PRINT));
  6. exit();
  7. }
  8. ?>
  9. <!doctype html>
  10. <title>Zammad Icons</title>
  11. <style>
  12. html {
  13. padding: 0 14px 14px 0;
  14. }
  15. body {
  16. margin: 28px 28px 14px 14px;
  17. background: hsl(210,14%,97%);
  18. font-family: sans-serif;
  19. font-size: 13px;
  20. }
  21. .controls {
  22. border: 1px solid hsl(167,72%,60%);
  23. border-radius: 5px;
  24. margin: 0 0 28px 14px;
  25. display: table;
  26. box-shadow: 0 1px hsl(199,44%,96%);
  27. }
  28. .controls label {
  29. padding: 7px 10px;
  30. float: left;
  31. cursor: pointer;
  32. }
  33. .controls label:not(:last-child) {
  34. border-right: 1px solid hsl(167,72%,60%);
  35. }
  36. .controls input {
  37. display: none;
  38. }
  39. .controls input:checked + label {
  40. background: hsl(167,72%,60%);
  41. color: white;
  42. }
  43. .icons {
  44. display: flex;
  45. flex-wrap: wrap;
  46. }
  47. .icon-holder {
  48. border: 1px solid hsl(199,44%,93%);
  49. background: white;
  50. box-shadow: 0 2px hsl(210,7%,96%);
  51. margin: 0 0 14px 14px;
  52. display: flex;
  53. flex-direction: column;
  54. align-items: center;
  55. justify-content: center;
  56. flex: 1;
  57. }
  58. .icon-holder.is-filtered {
  59. display: none;
  60. }
  61. .icon {
  62. position: relative;
  63. padding: 14px;
  64. width: 100%;
  65. box-sizing: border-box;
  66. display: flex;
  67. justify-content: center;
  68. background: hsl(210,14%,98%);
  69. }
  70. .icon.is-light {
  71. background: hsl(210,14%,88%);
  72. }
  73. .icon svg {
  74. width: 128px;
  75. height: 128px;
  76. position: relative;
  77. }
  78. .icon-body {
  79. padding: 14px 14px 10px;
  80. display: flex;
  81. flex-direction: column;
  82. justify-content: center;
  83. }
  84. .icon-name {
  85. margin: 0 0 7px;
  86. white-space: nowrap;
  87. }
  88. input:not([type=radio]) {
  89. margin: 0 0 4px;
  90. font: inherit;
  91. border: 1px solid #ddd;
  92. padding: 3px 5px;
  93. }
  94. input:not([type=radio]):focus {
  95. outline: none;
  96. border-color: hsl(205,74%,61%);
  97. }
  98. /*.icon:before {
  99. content: "";
  100. position: absolute;
  101. left: 0;
  102. top: 0;
  103. width: 100%;
  104. height: 100%;
  105. background-image:
  106. linear-gradient(45deg, black 25%, transparent 25%, transparent 75%, black 75%, black),
  107. linear-gradient(45deg, black 25%, transparent 25%, transparent 75%, black 75%, black);
  108. background-size: 20px 20px;
  109. background-position: 10px 10px, 40px 40px;
  110. opacity: 0.3;
  111. }*/
  112. </style>
  113. <div class="controls">
  114. <input type="radio" value="off" name="filter" checked id="off"><label for="off">No Filter</label>
  115. <input type="radio" value="empty_author" name="filter" id="author"><label for="author">No Author</label>
  116. <input type="radio" value="empty_license" name="filter" id="license"><label for="license">No License</label>
  117. </div>
  118. <div class="icons">
  119. <?
  120. # Path to image folder
  121. $imageFolder = '../public/assets/images/icons/';
  122. # Show only these file types from the image folder
  123. $imageTypes = '{*.svg}';
  124. # Set to true if you prefer sorting images by name
  125. # If set to false, images will be sorted by date
  126. $sortByImageName = false;
  127. # Set to false if you want the oldest images to appear first
  128. # This is only used if images are sorted by date (see above)
  129. $newestImagesFirst = true;
  130. # The rest of the code is technical
  131. # Add images to array
  132. $images = glob($imageFolder . $imageTypes, GLOB_BRACE);
  133. $author_data = json_decode(file_get_contents($src), true);
  134. # Sort images
  135. if ($sortByImageName) {
  136. $sortedImages = $images;
  137. natsort($sortedImages);
  138. } else {
  139. # Sort the images based on its 'last modified' time stamp
  140. $sortedImages = array();
  141. $count = count($images);
  142. for ($i = 0; $i < $count; $i++) {
  143. $sortedImages[date('YmdHis', filemtime($images[$i])) . $i] = $images[$i];
  144. }
  145. # Sort images in array
  146. if ($newestImagesFirst) {
  147. krsort($sortedImages);
  148. } else {
  149. ksort($sortedImages);
  150. }
  151. }
  152. ?>
  153. <? foreach ($sortedImages as $image): ?>
  154. <?
  155. # Get the name of the image, stripped from image folder path and file type extension
  156. $filename = basename($image);
  157. $name = preg_replace('/\\.[^.\\s]{3,4}$/', '', $filename);
  158. # Begin adding
  159. ?>
  160. <div class="icon-holder">
  161. <div class="icon">
  162. <?= file_get_contents($image) ?>
  163. </div>
  164. <form class="icon-body" data-filename="<?= $filename ?>">
  165. <div class="icon-name"><?= $name ?></div>
  166. <input name="author" value="<?= $author_data[$filename]['author'] ?>" placeholder="Author">
  167. <input type="url" name="url" value="<?= $author_data[$filename]['url'] ?>" placeholder="URL">
  168. <input name="license" value="<?= $author_data[$filename]['license'] ?>" placeholder="License">
  169. </form>
  170. </div>
  171. <? endforeach ?>
  172. </div>
  173. <script src="../app/assets/javascripts/app/lib/core/jquery-2.1.4.js"></script>
  174. <script>
  175. var self = "<?= basename($_SERVER["SCRIPT_FILENAME"]) ?>"
  176. var filter = "off"
  177. var filterTimeout
  178. $('input').on({
  179. input: storeAuthors,
  180. blur: onBlur,
  181. focus: onFocus
  182. })
  183. function onBlur(){
  184. filterTimeout = setTimeout(applyFilter, 500)
  185. }
  186. function onFocus(){
  187. clearTimeout(filterTimeout)
  188. }
  189. function storeAuthors(){
  190. var iconList = {}
  191. $('.icon-holder form').each(function(){
  192. iconList[$(this).attr('data-filename')] = {
  193. author: this.elements.author.value,
  194. url: this.elements.url.value,
  195. license: this.elements.license.value
  196. }
  197. })
  198. $.post(self, { list: iconList }, function(data){ console.log(data) })
  199. }
  200. $('[name="filter"]').change(function(){
  201. filter = this.value
  202. applyFilter()
  203. })
  204. function applyFilter(){
  205. $('.icon-holder').removeClass('is-filtered').each(function(){
  206. var holder = $(this)
  207. switch(filter){
  208. case "empty_author":
  209. if(holder.find("[name='author']").val())
  210. holder.addClass('is-filtered')
  211. break;
  212. case "empty_license":
  213. if(holder.find("[name='license']").val())
  214. holder.addClass('is-filtered')
  215. break;
  216. }
  217. });
  218. }
  219. $('svg').each(function(i, svg){
  220. var areas = []
  221. var svgBoundingBox = svg.getBoundingClientRect()
  222. var svgArea = svgBoundingBox.width * svgBoundingBox.height
  223. $(svg).find('*').each(function(i, el){
  224. var fill = $(el).attr('fill')
  225. if(fill && fill != 'none'){
  226. var childBoundingBox = el.getBoundingClientRect()
  227. areas.push({
  228. luminance: getLuminance(fill),
  229. areaPercentage: (childBoundingBox.width * childBoundingBox.height)/svgArea
  230. })
  231. }
  232. })
  233. if(!areas.length)
  234. return
  235. var averageLuminance = areas.reduce(function(previousValue, currentValue, index, array){
  236. if(array.length == 1)
  237. return currentValue.luminance
  238. else
  239. return previousValue + currentValue.luminance * currentValue.areaPercentage
  240. }, 0)
  241. if(averageLuminance > 220){
  242. $(svg).parent().addClass('is-light')
  243. }
  244. })
  245. //
  246. // from http://stackoverflow.com/questions/12043187/how-to-check-if-hex-color-is-too-black
  247. //
  248. function getLuminance(hex){
  249. var c = hex.substring(1); // strip #
  250. var rgb = parseInt(c, 16); // convert rrggbb to decimal
  251. var r = (rgb >> 16) & 0xff; // extract red
  252. var g = (rgb >> 8) & 0xff; // extract green
  253. var b = (rgb >> 0) & 0xff; // extract blue
  254. return 0.2126 * r + 0.7152 * g + 0.0722 * b; // per ITU-R BT.709
  255. }
  256. </script>