background image

Κεφάλαιο 3 - Ανάπτυξη και Υλοποίηση της Εφαρμογής 
 

 

 

52 

 

1. 

function

 extract_file

(

$file

,

 

$directory

,

 

$project_id

){

 

2. 

  $zip

 

=

 

new

 ZipArchive

;

 

3. 

  $db

 

=

 

new

 Database

;

 

4.  
5. 

  if

 

(

$zip

->

open

(

$file

)

 

===

 

true

)

 

{

 

6. 

    for

(

$i

 

=

 

0

;

 

$i

 

<

 

$zip

->

numFiles

;

 

$i

++)

 

{

 

7. 

      $filearray

 

=

 

$zip

->

getNameIndex

(

$i

);

 

8. 

      $fileinfo

 

=

 

pathinfo

(

$filearray

);

 

9. 

      $absolute_dir

 

=

 

$directory

;

 

10.  
11. 

     if

(

 

isset

(

 

$fileinfo

[

'extension'

]

 

)

 

){

 

12. 

       if

(

 

$db

->

add_file

(

$fileinfo

[

'basename'

],

 

$project_id

)

 

>

0

 

){

 

13. 

         copy

(

"zip://"

.

$file

.

"#"

.

$filearray

,

 

$absolute_dir

.

"/"

.

$fileinfo

[

'basename'

]);

 

14. 

       }

else

{

 

15. 

         return

 

false

;

 

16. 

       }

 

17. 

     }

 

18. 

   }

                   

 

19. 

   $zip

->

close

();

 

20. 

   return

 

true

;

 

21. 

 }

 

22. 

 return

 

false

;

 

23. 

}

 

24. 

 [...]

 

25. 

// Send Email 

 

26. 

function

 send_email

(

$message

,

 

$subject

,

 

$mail

){

 

27. 

 $headers

 

=

 

'From: noreply@spam.vlsi.gr'

.

"\r\n"

.

'Reply-To: nore-

ply@spam.vlsi.gr'

.

"\r\n"

.

'X-Mailer: PHP/'

.

phpversion

();

 

28. 

 return

 

mail

(

$mail

,

 

$subject

,

 

$message

,

 

$headers

);

 

29. 

}

 

 

Κώδικας 17: General.php - Οι μέθοδοι extract_file και send_email 

 

1. 

// Return the shortcode of a string

 

2. 

function

 create_short_code

(

$string

){

 

3. 

  $replace_pairs

 

=

 

array

(

 

4. 

    " "

 

=>

 

"-"

,

 

5. 

    "α"

 

=>

 

"a"

,

 

6. 

    "β"

 

=>

 

"b"

,

 

7. 

    

[...]

 

8. 

  

);

 

9. 

  

$string

 

=

 

trim

(

$string

,

" "

);

 

10. 

 $string

 

=

 

strtr

(

$string

,

 

$replace_pairs

);

 

11. 

 $string

 

=

 

strtolower

(

$string

);

 

12. 

 $string

 

=

 

preg_replace

(

"/[^a-z0-9\-\.]/"

,

""

,

$string

);

 

13. 

 $string

 

=

 

preg_replace

(

"/-+/"

,

"-"

,

$string

);

 

14. 

 return

 

$string

;

 

15. 

}

 

 

Κώδικας 18: General.php - Η μέθοδος create_short_code