PageRenderTime 65ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/siggen/inc/functions.inc

http://wowroster-addons.googlecode.com/
Pascal | 1084 lines | 395 code | 102 blank | 587 comment | 35 complexity | 95ccbf9987ee0d7aab3fc43af3999dd9 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /**
  3. * Project: SigGen - Signature and Avatar Generator for WoWRoster
  4. * File: /inc/functions.inc
  5. *
  6. * @link http://www.wowroster.net
  7. * @license http://www.gnu.org/licenses/gpl.html Licensed under the GNU General Public License v3.
  8. * @author Joshua Clark
  9. * @version $Id: functions.inc 542 2011-11-26 20:37:05Z c.treyce@gmail.com $
  10. * @copyright 2005-2011 Joshua Clark
  11. * @package SigGen
  12. * @filesource
  13. */
  14. if ( !defined('IN_ROSTER') )
  15. {
  16. exit('Detected invalid access to this file!');
  17. }
  18. /**
  19. * Common SigConfig Functions Class
  20. * @package SigGen
  21. */
  22. class SigConfigClass
  23. {
  24. var $message;
  25. var $sql_debug;
  26. /**
  27. * Check directory status
  28. *
  29. * @param string $dir | directory to check
  30. * @param bool $writeable | check writable
  31. * @param bool $chmod | chmod directory
  32. * @return bool | ( true{dir exists} | false{dir does not exist} )
  33. */
  34. function checkDir( $dir , $writeable=0 , $chmod=0 )
  35. {
  36. // See if it exists
  37. if( file_exists($dir) )
  38. {
  39. if( $writeable )
  40. {
  41. if( !is_writable($dir) )
  42. {
  43. if( $chmod )
  44. {
  45. return @chmod( $dir,0777 );
  46. }
  47. else
  48. {
  49. return false;
  50. }
  51. }
  52. }
  53. return true;
  54. }
  55. else
  56. {
  57. return false;
  58. }
  59. }
  60. /**
  61. * Create a directory
  62. *
  63. * @param string $dir | name of the directory to create
  64. * @return bool | ( true{created} | false{not created} )
  65. */
  66. function makeDir( $dir )
  67. {
  68. return @mkdir($dir);
  69. }
  70. /**
  71. * Set the SigGen Config Messages
  72. *
  73. * @param string $message | add string to the messages
  74. */
  75. function setMessage( $message )
  76. {
  77. $this->message .= $message . '[|]';
  78. }
  79. /**
  80. * Get the Messages
  81. *
  82. * @return string | Full HTML table with messages
  83. */
  84. function getMessage()
  85. {
  86. global $roster;
  87. $message = $this->message;
  88. if( !empty($message) )
  89. {
  90. // Replace newline feeds with <br />
  91. $messageArr = explode("[|]",$message);
  92. $output = '';
  93. $row=0;
  94. foreach( $messageArr as $line )
  95. {
  96. if( $line != '' )
  97. {
  98. $output .= $line . '<br />';
  99. }
  100. }
  101. return $output;
  102. }
  103. else
  104. {
  105. return '';
  106. }
  107. }
  108. /**
  109. * Create an HTML option list
  110. *
  111. * @param array $values array ($name => $value)
  112. * @param string $selected what will be selected
  113. * @param string $id what to match selected with
  114. * @param string $type What value goes into
  115. * 0- name
  116. * 1- member_id
  117. * @param string $param additional crap for <select> field
  118. * @return string an html option list
  119. */
  120. function createMemberList( $values , $selected , $id , $type=0 , $param='' )
  121. {
  122. if( $selected != '' )
  123. {
  124. $select_one = true;
  125. }
  126. $option_list = "\n\t<select id=\"{$id}\" name=\"{$id}\" $param>\n\t\t<option value=\"\" style=\"color:grey;\">--None--</option>\n";
  127. foreach( $values as $value )
  128. {
  129. $array[$value['server']][$value['member_id']] = $value['name'];
  130. }
  131. foreach( $array as $server => $data )
  132. {
  133. $option_list .= "\t\t<optgroup label=\"{$server}\">\n";
  134. foreach( $data as $member_id => $name )
  135. {
  136. $value = ($type ? $member_id : "$name@$server");
  137. if( $selected == $value && $select_one )
  138. {
  139. $option_list .= "\t\t\t<option value=\"{$value}\" selected=\"selected\">{$name}</option>\n";
  140. $select_one = false;
  141. }
  142. else
  143. {
  144. $option_list .= "\t\t\t<option value=\"{$value}\">{$name}</option>\n";
  145. }
  146. }
  147. $option_list .= "\t\t</optgroup>\n";
  148. }
  149. $option_list .= "\t</select>";
  150. return $option_list;
  151. }
  152. /**
  153. * Create an HTML option list
  154. *
  155. * @param array $values array ($name => $value)
  156. * @param string $selected what will be selected
  157. * @param string $id what to match selected with
  158. * @param string $type how to arrange the value/label
  159. * 0- name value (LIST)
  160. * 1- value name (LISTREV)
  161. * 2- name name (NAME)
  162. * 3- value value (VALUE)
  163. * @param string $param additional crap for <select> field
  164. * @return string an html option list
  165. */
  166. function createOptionList( $values , $selected , $id , $type='' , $param='' , $none=true )
  167. {
  168. if( $selected != '' )
  169. {
  170. $select_one = true;
  171. }
  172. $option_list = "\n\t<select id=\"{$id}\" name=\"{$id}\" $param>\n";
  173. $option_list .= ($none ? "\t\t<option value=\"\" style=\"color:grey;\">--None--</option>\n" : '');
  174. foreach( $values as $Aname => $Avalue )
  175. {
  176. switch ($type)
  177. {
  178. case 0: // name value
  179. case 'list':
  180. $value = $Avalue;
  181. $name = $Aname;
  182. break;
  183. case 1: // value name
  184. case 'rev':
  185. $value = $Aname;
  186. $name = $Avalue;
  187. break;
  188. case 2: // name name
  189. case 'name':
  190. $value = $Aname;
  191. $name = $Aname;
  192. break;
  193. case 3: // value value
  194. case 'value':
  195. $value = $Avalue;
  196. $name = $Avalue;
  197. break;
  198. default:
  199. $value = $Avalue;
  200. $name = $Aname;
  201. break;
  202. }
  203. if( $selected == $value && $select_one )
  204. {
  205. $option_list .= "\t\t<option value=\"{$value}\" selected=\"selected\">{$name}</option>\n";
  206. $select_one = false;
  207. }
  208. else
  209. {
  210. $option_list .= "\t\t<option value=\"{$value}\">{$name}</option>\n";
  211. }
  212. }
  213. $option_list .= "\t</select>";
  214. return $option_list;
  215. }
  216. /**
  217. * Create an HTML radio set
  218. *
  219. * @param array $values array ($name => $value)
  220. * @param string $id what to match selected with
  221. * @param string $checked what will be checked
  222. * @param string $param additional crap for <select> field
  223. * @return string an html option list
  224. */
  225. function createRadioSet( $values , $id , $checked , $param='' )
  226. {
  227. if( $checked != '' )
  228. {
  229. $select_one = true;
  230. }
  231. $radio_set = "\n\t<div class=\"radioset\" $param>\n";
  232. foreach( $values as $name => $value )
  233. {
  234. if( $checked == $value && $select_one )
  235. {
  236. $radio_set .= "\t\t<input type=\"radio\" id=\"rd-{$id}-{$value}\" name=\"{$id}\" value=\"{$value}\" checked=\"checked\" /><label for=\"rd-{$id}-{$value}\">{$name}</label>\n";
  237. $select_one = false;
  238. }
  239. else
  240. {
  241. $radio_set .= "\t\t<input type=\"radio\" id=\"rd-{$id}-{$value}\" name=\"{$id}\" value=\"{$value}\" /><label for=\"rd-{$id}-{$value}\">{$name}</label>\n";
  242. }
  243. }
  244. $radio_set .= "\t</div>";
  245. return $radio_set;
  246. }
  247. /**
  248. * Create a color picker input field
  249. *
  250. * @param string $id html name of field
  251. * @param array $value value of field
  252. * @return string color picker html
  253. */
  254. function createColorPicker( $name , $value )
  255. {
  256. global $roster;
  257. // Check for Roster version to determine which color picker to use
  258. if (version_compare(ROSTER_VERSION, '2.1.9', '<')) {
  259. $color = '<input type="text" maxlength="7" size="10" class="colorinput" style="background-color:' . $value . ';" value="' . $value . '" name="' . $name . '" id="' . $name . '" />'
  260. . '<img src="' . $roster->config['theme_path'] . '/images/color/select_arrow.gif" style="cursor:pointer;vertical-align:middle;margin-bottom:2px;" onclick="showColorPicker(this,document.getElementById(\'' . $name . '\'))" alt="" />';
  261. }
  262. else
  263. {
  264. $color = '<input type="text" maxlength="7" size="8" class="color-picker" value="' . $value . '" name="' . $name . '" id="' . $name . '" />'
  265. . '<div class="color-display" style="background-color:' . $value . ';"></div>' . "\n";
  266. }
  267. return $color;
  268. }
  269. /**
  270. * Get a list of files from a directory
  271. *
  272. * @param string $dir | directory to get list of files
  273. * @param mixed $ext | get files with this extention can be an array
  274. * @return array | $file => $name
  275. */
  276. function listFiles( $dir , $ext )
  277. {
  278. $arrFiles = array();
  279. // Open the directory
  280. $tmp_dir = @opendir( $dir );
  281. if( !empty($tmp_dir) )
  282. {
  283. // Read the files
  284. while( $file = readdir($tmp_dir) )
  285. {
  286. $pfad_info = pathinfo($file);
  287. if( is_array($ext) )
  288. {
  289. if( in_array(strtolower($pfad_info['extension']),$ext))
  290. {
  291. $name = str_replace('.' . $pfad_info['extension'],'',$file);
  292. $arrFiles += array($file => $name);
  293. }
  294. }
  295. else
  296. {
  297. if( strtolower($pfad_info['extension']) == strtolower($ext) )
  298. {
  299. $name = str_replace('.' . $pfad_info['extension'],'',$file);
  300. $arrFiles += array($file => $name);
  301. }
  302. }
  303. }
  304. // close the directory
  305. closedir($tmp_dir);
  306. //sort the list
  307. asort($arrFiles);
  308. }
  309. return $arrFiles;
  310. }
  311. /**
  312. * Get a list of directories from a directory
  313. *
  314. * @param string $dir | directory to get list of directories
  315. * @return array | $file => $name
  316. */
  317. function listDir( $dir )
  318. {
  319. $arrFiles = array();
  320. // Open the directory
  321. $tmp_dir = @opendir( $dir );
  322. if( !empty($tmp_dir) )
  323. {
  324. // Read the files
  325. while( $file = readdir($tmp_dir) )
  326. {
  327. if( is_dir($dir . $file) && $file != '.' && $file != '..' )
  328. {
  329. $arrFiles += array($file => $file);
  330. }
  331. }
  332. // close the directory
  333. closedir($tmp_dir);
  334. //sort the list
  335. asort($arrFiles);
  336. }
  337. return $arrFiles;
  338. }
  339. /**
  340. * Check if a table exists
  341. *
  342. * @param string $table | db table to check
  343. * @return array ( $name => $value )
  344. */
  345. function checkDb( $table )
  346. {
  347. global $roster;
  348. $sql_str = "SHOW TABLES LIKE '$table';";
  349. $result = $roster->db->query($sql_str);
  350. $r = $roster->db->fetch($result, SQL_ASSOC);
  351. if( empty($r) )
  352. {
  353. return false;
  354. }
  355. else
  356. {
  357. return true;
  358. }
  359. }
  360. /**
  361. * Get Data from the database
  362. *
  363. * @param string $table | table to get data from
  364. * @param string $field | field to get data from ( default *{all} )
  365. * @param string $where | where statement ( default ''{blank} )
  366. * @param string $order | order by statement ( default ''{blank} )
  367. * @return array ( $name => $value )
  368. */
  369. function getDbData( $table , $field , $where='', $order='' )
  370. {
  371. global $roster;
  372. if( !empty($table) )
  373. {
  374. if( !empty($where) )
  375. {
  376. $where = ' WHERE ' . $where;
  377. }
  378. if( !empty($order) )
  379. {
  380. $order = ' ORDER BY ' . $order;
  381. }
  382. if( empty($field) )
  383. {
  384. $field = '*';
  385. }
  386. // SQL String
  387. $sql_str = "SELECT $field FROM `$table`$where$order;";
  388. $result = $roster->db->query($sql_str);
  389. if ( $result )
  390. {
  391. if( $roster->db->num_rows() > 1 )
  392. {
  393. $data = array();
  394. for( $i=0; $i<$roster->db->num_rows(); $i++)
  395. {
  396. $row = $roster->db->fetch($result, SQL_ASSOC);
  397. $data[] = $row;
  398. }
  399. return $data;
  400. }
  401. else
  402. {
  403. $data = $roster->db->fetch($result, SQL_ASSOC);
  404. return $data;
  405. }
  406. }
  407. }
  408. }
  409. /**
  410. * Get list of a field from the database
  411. *
  412. * @param string $table | table to get data from
  413. * @param string $field | field to get data from ( default *{all} )
  414. * @param string $where | where statement ( default ''{blank} )
  415. * @param string $order | order by statement ( default ''{blank} )
  416. * @return array ( $name => $value )
  417. */
  418. function getDbList( $table , $field , $where='', $order='' )
  419. {
  420. global $roster;
  421. if( !empty($table) )
  422. {
  423. if( !empty($where) )
  424. {
  425. $where = ' WHERE ' . $where;
  426. }
  427. if( !empty($order) )
  428. {
  429. $order = ' ORDER BY ' . $order;
  430. }
  431. if( empty($field) )
  432. {
  433. $field = '*';
  434. }
  435. else
  436. {
  437. $field = "`$field`";
  438. }
  439. // SQL String
  440. $sql_str = "SELECT $field FROM `$table`$where$order;";
  441. $result = $roster->db->query($sql_str);
  442. while( $r = $roster->db->fetch($result, SQL_ASSOC) )
  443. {
  444. $list[] = $r[trim($field,'`')];
  445. }
  446. return $list;
  447. }
  448. }
  449. /**
  450. * Get a list of tables from a database
  451. *
  452. * @param string $table | name of db table
  453. * @return array ( $name => $value )
  454. */
  455. function getDbColumns( $table )
  456. {
  457. global $roster;
  458. if( !empty($table) )
  459. {
  460. // SQL String
  461. $sql_str = "SHOW COLUMNS FROM `$table`";
  462. $result = $roster->db->query($sql_str);
  463. while( $row = $roster->db->fetch($result,SQL_NUM) )
  464. {
  465. $col_names[] = $row[0];
  466. }
  467. return $col_names;
  468. }
  469. }
  470. /**
  471. * Upload Images to a folder
  472. *
  473. * @param string $dir | directory to upload image to
  474. * @param string $filename | filename of final uploaded image
  475. * @return bool
  476. */
  477. function uploadImage( $dir , $filename )
  478. {
  479. global $roster;
  480. $accepted_files = array('png','gif','jpg','jpeg');
  481. $uploaded_filename = $_FILES['userfile']['name'];
  482. $uploaded_fileext = strtolower(ltrim(strrchr($uploaded_filename,'.'),'.'));
  483. $userfile_name = ( isset($_FILES['userfile']['name']) ? $filename . '.' . $uploaded_fileext : '' );
  484. if( isset($_FILES['userfile']) )
  485. {
  486. if( empty($_FILES['userfile']['name']) )
  487. {
  488. $this->setMessage($roster->locale->act['select_image_upload']);
  489. return false;
  490. }
  491. elseif( empty( $filename ) )
  492. {
  493. $this->setMessage($roster->locale->act['select_name_upload']);
  494. return false;
  495. }
  496. else
  497. {
  498. $userfile_name = $_POST['image_type'] . $userfile_name;
  499. if( !in_array( $uploaded_fileext,$accepted_files ) )
  500. {
  501. $this->setMessage($roster->locale->act['image_mustbe_right']);
  502. return false;
  503. }
  504. if( file_exists($dir . $userfile_name) )
  505. {
  506. if( md5_file($dir . $userfile_name) == md5_file($_FILES['userfile']['tmp_name']) )
  507. {
  508. $this->setMessage($roster->locale->act['image_a_copy']);
  509. return false;
  510. }
  511. }
  512. if( !move_uploaded_file( $_FILES['userfile']['tmp_name'],$dir . $userfile_name ) || !chmod( $dir . $userfile_name,0777 ) )
  513. {
  514. $this->setMessage(sprintf($roster->locale->act['image_upload_failed'],$userfile_name,str_replace( '\\','/',$dir )));
  515. return false;
  516. }
  517. else
  518. {
  519. $this->setMessage(sprintf($roster->locale->act['image_upload_success'],$userfile_name,str_replace( '\\','/',$dir )));
  520. return true;
  521. }
  522. }
  523. }
  524. else
  525. {
  526. return false;
  527. }
  528. }
  529. /**
  530. * Delete an image from a folder
  531. *
  532. * @param string $dir | directory to delete image from
  533. * @param string $filename | filename of image to delete
  534. * @return bool
  535. */
  536. function deleteImage( $dir , $filename )
  537. {
  538. global $roster;
  539. if( empty($filename) )
  540. {
  541. $this->setMessage($roster->locale->act['select_image_delete']);
  542. return false;
  543. }
  544. else
  545. {
  546. if( file_exists($dir . $filename) )
  547. {
  548. if( unlink($dir . $filename) )
  549. {
  550. $this->setMessage(sprintf($roster->locale->act['image_deleted'],str_replace( '\\','/',$dir ) . $filename));
  551. return true;
  552. }
  553. else
  554. {
  555. $this->setMessage(sprintf($roster->locale->act['image_delete_failed'],str_replace( '\\','/',$dir ) . $filename));
  556. return false;
  557. }
  558. }
  559. }
  560. }
  561. /**
  562. * Process Data for entry to the database
  563. *
  564. * @param array $post | $_POST array
  565. * @param string $config_name | db id to process
  566. */
  567. function processData( $post , $config_name, $data )
  568. {
  569. global $roster;
  570. $configData = $data;
  571. // Array for color fixing
  572. $color_fix = array(
  573. 'backg_fill_color',
  574. 'expbar_color_border',
  575. 'expbar_color_inside',
  576. 'expbar_color_bar',
  577. 'expbar_color_maxbar',
  578. 'expbar_font_color',
  579. 'expbar_text_shadow',
  580. 'lvl_font_color',
  581. 'lvl_text_shadow',
  582. 'skills_font_color',
  583. 'skills_shadow',
  584. 'text_name_font_color',
  585. 'text_name_shadow',
  586. 'text_class_font_color',
  587. 'text_class_shadow',
  588. 'text_honor_font_color',
  589. 'text_honor_shadow',
  590. 'text_guildname_font_color',
  591. 'text_guildname_shadow',
  592. 'text_guildtitle_font_color',
  593. 'text_guildtitle_shadow',
  594. 'text_servername_font_color',
  595. 'text_servername_shadow',
  596. 'text_sitename_font_color',
  597. 'text_sitename_shadow',
  598. 'text_talpoints_font_color',
  599. 'text_talpoints_shadow',
  600. 'text_custom_font_color',
  601. 'text_custom_shadow',
  602. );
  603. // Update only the changed fields
  604. $sqlarray = array();
  605. foreach( $post as $settingName => $settingValue )
  606. {
  607. // Fix colors
  608. if( in_array($settingName,$color_fix) && $settingValue != '' )
  609. {
  610. if( substr($settingValue, 0, 1) != '#' )
  611. {
  612. $settingValue = '#' . strtoupper($settingValue);
  613. }
  614. else
  615. {
  616. $settingValue = strtoupper($settingValue);
  617. }
  618. }
  619. // Fix directories
  620. if( substr($settingName, -4, 4) == '_dir' )
  621. {
  622. // Replace slashes
  623. $settingValue = str_replace( '\\\\','/',$settingValue );
  624. $settingValue = str_replace( '\\','/',$settingValue );
  625. // Check for directories defined with no '/' at the end
  626. // and with a '/' at the beginning
  627. if( substr($settingValue, -1, 1) != '/' )
  628. {
  629. $settingValue .= '/';
  630. }
  631. if( substr($settingValue, 0, 1) == '/' && $settingName != 'save_images_dir' )
  632. {
  633. $settingValue = substr($settingValue, 1);
  634. }
  635. }
  636. if( $settingName != 'sc_op' && $settingValue != $configData[$settingName] )
  637. {
  638. $sqlarray += array($settingName => $settingValue);
  639. }
  640. }
  641. // Update DataBase
  642. if( count($sqlarray) > 0 )
  643. {
  644. $update_sql = 'UPDATE `' . ROSTER_SIGCONFIGTABLE . "` SET " . $roster->db->build_query('UPDATE',$sqlarray) . " WHERE `config_id` = '" . $config_name . "'";
  645. $roster->db->query($update_sql) or errorMode( 'processData: ' . $roster->db->error() );
  646. $this->setMessage( $roster->locale->act['settings_changed'] );
  647. }
  648. }
  649. /**
  650. * Resets the config to defaults
  651. *
  652. * @param bool $confirm | Confirmation to reset
  653. * @param sting $config_id | db id to process
  654. */
  655. function resetDefaults( $confirm , $config_id )
  656. {
  657. global $roster;
  658. $sql_file = SIGGEN_DIR . 'inc/sql.inc';
  659. if( $confirm )
  660. {
  661. if( file_exists($sql_file) )
  662. {
  663. include_once( $sql_file );
  664. if( in_array($config_id,array('avatar','signature')) )
  665. {
  666. $sql = $create_sql['reset'][$config_id];
  667. }
  668. else
  669. {
  670. $sql = sprintf($create_sql['reset']['default'],$config_id);
  671. }
  672. $roster->db->query($sql) or errorMode( 'resetDefaults: ' . $roster->db->error() );
  673. $this->setMessage($roster->locale->act['settings_reset']);
  674. }
  675. else
  676. {
  677. $this->setMessage(sprintf($roster->locale->act['cannot_find_file'],$sql_file));
  678. }
  679. }
  680. else
  681. {
  682. $this->setMessage($roster->locale->act['reset_checkbox']);
  683. }
  684. }
  685. /**
  686. * Creates a new config mode
  687. *
  688. * @param string Config ID
  689. * @return bool Success or not
  690. */
  691. function new_config( $name )
  692. {
  693. global $roster;
  694. $exists = $this->getDbData(ROSTER_SIGCONFIGTABLE , '`config_id`' , "`config_id` = '$name'");
  695. if( $exists == '' )
  696. {
  697. if( preg_match('/[^a-z0-9_-]/', $name) )
  698. {
  699. $this->setMessage($roster->locale->act['config_invalid']);
  700. return false;
  701. }
  702. else
  703. {
  704. $sql_file = SIGGEN_DIR . 'inc/sql.inc';
  705. if( file_exists($sql_file) )
  706. {
  707. include_once( $sql_file );
  708. $sql = sprintf($create_sql['reset']['default'],$name);
  709. $roster->db->query($sql) or errorMode( 'new_config: ' . $roster->db->error() );
  710. $this->setMessage(sprintf($roster->locale->act['config_created'],$name));
  711. return true;
  712. }
  713. else
  714. {
  715. $this->setMessage(sprintf($roster->locale->act['cannot_find_file'],$sql_file));
  716. return false;
  717. }
  718. }
  719. }
  720. else
  721. {
  722. $this->setMessage(sprintf($roster->locale->act['config_exists'],$name));
  723. return false;
  724. }
  725. }
  726. /**
  727. * Deletes a config mode
  728. *
  729. * @param string Config ID
  730. * @return bool Success or not
  731. */
  732. function delete_config( $name )
  733. {
  734. global $roster;
  735. if( in_array($name,array('avatar','signature')) )
  736. {
  737. $this->setMessage($roster->locale->act['config_cannot_delete_default']);
  738. return false;
  739. }
  740. else
  741. {
  742. $exists = $this->getDbData(ROSTER_SIGCONFIGTABLE , '`config_id`' , "`config_id` = '$name'");
  743. if( $exists != '' )
  744. {
  745. $sql = "DELETE FROM `" . ROSTER_SIGCONFIGTABLE . "` WHERE `config_id` = '$name';";
  746. $roster->db->query($sql) or errorMode( 'delete_config: ' . $roster->db->error() );
  747. $this->setMessage(sprintf($roster->locale->act['config_deleted'],$name));
  748. return true;
  749. }
  750. else
  751. {
  752. $this->setMessage(sprintf($roster->locale->act['config_cannot_delete'],$name));
  753. return false;
  754. }
  755. }
  756. }
  757. /**
  758. * Grabs settings from a file, exported from SigGen
  759. *
  760. * @param string Config ID to import
  761. * @return bool Success or not
  762. */
  763. function importSettings( $checkData , $config_id )
  764. {
  765. global $roster, $sc_db_ver;
  766. $accepted_file = "siggen_$config_id.txt";
  767. $uploaded_filename = $_FILES['userfile']['name'];
  768. $temp_file = $_FILES['userfile']['tmp_name'];
  769. $ignore = array('config_id','db_ver');
  770. if( isset($_FILES['userfile']) )
  771. {
  772. if( empty($_FILES['userfile']['name']) )
  773. {
  774. $this->setMessage(sprintf($roster->locale->act['select_import_file'],$accepted_file));
  775. return false;
  776. }
  777. else
  778. {
  779. if( $accepted_file != $uploaded_filename )
  780. {
  781. $this->setMessage($roster->locale->act['import_mustbe_right']);
  782. return false;
  783. }
  784. if( file_exists($temp_file) && is_readable($temp_file) )
  785. {
  786. $file_as_array = file($temp_file);
  787. $firstline = true;
  788. $settingsArray = array();
  789. foreach( $file_as_array as $file_line )
  790. {
  791. $file_line = trim($file_line);
  792. list($value,$setting) = explode('|',$file_line);
  793. if( $firstline )
  794. {
  795. if( version_compare($sc_db_ver, $value, '<') )
  796. {
  797. $this->setMessage(sprintf($roster->locale->act['import_upload_failed_ver'],$value,$sc_db_ver));
  798. return false;
  799. }
  800. $firstline = false;
  801. }
  802. elseif( !in_array($value,$ignore) )
  803. {
  804. $settingsArray[$value] = $setting;
  805. }
  806. }
  807. $this->processData($settingsArray,$config_id,$checkData);
  808. $this->setMessage($roster->locale->act['import_upload_success']);
  809. return true;
  810. }
  811. else
  812. {
  813. $this->setMessage($roster->locale->act['import_upload_failed']);
  814. return false;
  815. }
  816. }
  817. }
  818. else
  819. {
  820. return false;
  821. }
  822. }
  823. /**
  824. * Grabs settings from SigGen, exports them to a file
  825. *
  826. * @param array $checkData SigGen Data
  827. * @param string $config_id Current config
  828. */
  829. function exportSettings( $checkData , $config_id )
  830. {
  831. global $sc_db_ver;
  832. $file = "$sc_db_ver|$config_id\n";
  833. foreach( $checkData as $name => $value )
  834. {
  835. $file .= "$name|$value\n";
  836. }
  837. header('Content-Type: text/x-delimtext; name="siggen_' . $config_id . '.txt"');
  838. header('Content-disposition: attachment; filename="siggen_' . $config_id . '.txt"');
  839. // We need to stripslashes no matter what the setting of magic_quotes_gpc is
  840. echo stripslashes($file);
  841. exit;
  842. }
  843. /**
  844. * Create a tooltip
  845. *
  846. * @param string $content | Content in tooltip
  847. * @param string $caption | Text in the caption
  848. * @return string ( Overlib styled tooltip )
  849. */
  850. function createTip( $content , $caption )
  851. {
  852. $tipsettings = ",WRAP";
  853. if( !empty($caption) )
  854. {
  855. $caption2 = ",CAPTION,'$caption'";
  856. }
  857. $tip = "<span class=\"ui-icon ui-icon-help\" style=\"cursor:help;\" onmouseover=\"overlib('$content'$caption2$tipsettings);\" onmouseout=\"return nd();\"></span>$caption";
  858. return $tip;
  859. }
  860. /**
  861. * Create a tooltip icon
  862. *
  863. * @param string $content | Content in tooltip
  864. * @param string $caption | Text in the caption
  865. * @return string ( Overlib styled tooltip )
  866. */
  867. function createTipIcon( $content , $caption )
  868. {
  869. $tipsettings = ",WRAP";
  870. if( !empty($caption) )
  871. {
  872. $caption2 = ",CAPTION,'$caption'";
  873. }
  874. $tip = "<span class=\"ui-icon ui-icon-help\" style=\"cursor:help;\" onmouseover=\"overlib('$content'$caption2$tipsettings);\" onmouseout=\"return nd();\"></span>";
  875. return $tip;
  876. }
  877. /**
  878. * Creates a table for viewing image packs
  879. *
  880. * @param string $dir
  881. */
  882. function imagePreview($dir)
  883. {
  884. global $roster, $addon;
  885. $return = '<table cellpadding="0" cellspacing="0" style="font-size:10px;">';
  886. $dirname = '.';
  887. $pattern = "(\\.png$)"; // valid image extensions
  888. $columns = 2;
  889. $drawIndex = 0;
  890. if($handle = opendir($dirname))
  891. {
  892. while(false !== ($file = readdir($handle)))
  893. {
  894. if(eregi($pattern, $file)) //if this file is a valid image
  895. {
  896. if($drawIndex == 0)
  897. {
  898. $return .= '<tr>';
  899. }
  900. $return .= '<td align="center"><img src="' . $addon['url_path'] . 'img/' . $file . '" style="border:0;"><br />' . $file . '</td>';
  901. $drawIndex++;
  902. if($drawIndex == $columns)
  903. {
  904. $return .= '</tr>';
  905. $drawIndex = 0;
  906. }
  907. }
  908. }
  909. if($drawIndex !== 0)
  910. {
  911. $finishDraw = $columns - $drawIndex;
  912. while($finishDraw !== 0)
  913. {
  914. $return .= '<td>&nbsp;</td>';
  915. $finishDraw--;
  916. }
  917. $return .= '</tr>';
  918. }
  919. }
  920. closedir($handle);
  921. $return .= '</table>';
  922. }
  923. }