| Total Complexity | 207 |
| Total Lines | 1531 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Website often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Website, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 36 | class Website extends CommonObject |
||
| 37 | { |
||
| 38 | /** |
||
| 39 | * @var string Id to identify managed objects |
||
| 40 | */ |
||
| 41 | public $element = 'website'; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var string Name of table without prefix where object is stored |
||
| 45 | */ |
||
| 46 | public $table_element = 'website'; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var array Does website support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe |
||
| 50 | */ |
||
| 51 | public $ismultientitymanaged = 1; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var string String with name of icon for website. Must be the part after the 'object_' into object_myobject.png |
||
| 55 | */ |
||
| 56 | public $picto = 'globe'; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var int Entity |
||
| 60 | */ |
||
| 61 | public $entity; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var string Ref |
||
| 65 | */ |
||
| 66 | public $ref; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @var string description |
||
| 70 | */ |
||
| 71 | public $description; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @var string Main language of web site |
||
| 75 | */ |
||
| 76 | public $lang; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @var string List of languages of web site ('fr', 'es_MX', ...) |
||
| 80 | */ |
||
| 81 | public $otherlang; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @var int Status |
||
| 85 | */ |
||
| 86 | public $status; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @var integer|string date_creation |
||
| 90 | */ |
||
| 91 | public $date_creation; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @var integer|string date_modification |
||
| 95 | */ |
||
| 96 | public $date_modification; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @var integer |
||
| 100 | */ |
||
| 101 | public $fk_default_home; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @var int User Create Id |
||
| 105 | */ |
||
| 106 | public $fk_user_creat; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @var string |
||
| 110 | */ |
||
| 111 | public $virtualhost; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @var int |
||
| 115 | */ |
||
| 116 | public $use_manifest; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @var int |
||
| 120 | */ |
||
| 121 | public $position; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * List of containers |
||
| 125 | * |
||
| 126 | * @var array |
||
| 127 | */ |
||
| 128 | public $lines; |
||
| 129 | |||
| 130 | |||
| 131 | const STATUS_DRAFT = 0; |
||
| 132 | const STATUS_VALIDATED = 1; |
||
| 133 | |||
| 134 | |||
| 135 | /** |
||
| 136 | * Constructor |
||
| 137 | * |
||
| 138 | * @param DoliDb $db Database handler |
||
| 139 | */ |
||
| 140 | public function __construct(DoliDB $db) |
||
| 144 | } |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Create object into database |
||
| 148 | * |
||
| 149 | * @param User $user User that creates |
||
| 150 | * @param bool $notrigger false=launch triggers after, true=disable triggers |
||
| 151 | * |
||
| 152 | * @return int <0 if KO, Id of created object if OK |
||
| 153 | */ |
||
| 154 | public function create(User $user, $notrigger = false) |
||
| 286 | } |
||
| 287 | } |
||
| 288 | |||
| 289 | /** |
||
| 290 | * Load object in memory from the database |
||
| 291 | * |
||
| 292 | * @param int $id Id object |
||
| 293 | * @param string $ref Ref |
||
| 294 | * @return int <0 if KO, 0 if not found, >0 if OK |
||
| 295 | */ |
||
| 296 | public function fetch($id, $ref = null) |
||
| 364 | } |
||
| 365 | } |
||
| 366 | |||
| 367 | /** |
||
| 368 | * Load object lines in memory from the database |
||
| 369 | * |
||
| 370 | * @return int <0 if KO, 0 if not found, >0 if OK |
||
| 371 | */ |
||
| 372 | public function fetchLines() |
||
| 373 | { |
||
| 374 | $this->lines = array(); |
||
| 375 | |||
| 376 | // Load lines with object MyObjectLine |
||
| 377 | |||
| 378 | return count($this->lines) ? 1 : 0; |
||
| 379 | } |
||
| 380 | |||
| 381 | |||
| 382 | /** |
||
| 383 | * Load all object in memory ($this->records) from the database |
||
| 384 | * |
||
| 385 | * @param string $sortorder Sort Order |
||
| 386 | * @param string $sortfield Sort field |
||
| 387 | * @param int $limit offset limit |
||
| 388 | * @param int $offset offset limit |
||
| 389 | * @param array $filter filter array |
||
| 390 | * @param string $filtermode filter mode (AND or OR) |
||
| 391 | * |
||
| 392 | * @return int <0 if KO, >0 if OK |
||
| 393 | */ |
||
| 394 | public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') |
||
| 465 | } |
||
| 466 | } |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Update object into database |
||
| 470 | * |
||
| 471 | * @param User $user User that modifies |
||
| 472 | * @param bool $notrigger false=launch triggers after, true=disable triggers |
||
| 473 | * |
||
| 474 | * @return int <0 if KO, >0 if OK |
||
| 475 | */ |
||
| 476 | public function update(User $user, $notrigger = false) |
||
| 577 | } |
||
| 578 | } |
||
| 579 | |||
| 580 | /** |
||
| 581 | * Delete object in database |
||
| 582 | * |
||
| 583 | * @param User $user User that deletes |
||
| 584 | * @param bool $notrigger false=launch triggers after, true=disable triggers |
||
| 585 | * |
||
| 586 | * @return int <0 if KO, >0 if OK |
||
| 587 | */ |
||
| 588 | public function delete(User $user, $notrigger = false) |
||
| 589 | { |
||
| 590 | global $conf; |
||
| 591 | |||
| 592 | dol_syslog(__METHOD__, LOG_DEBUG); |
||
| 593 | |||
| 594 | $error = 0; |
||
| 595 | |||
| 596 | $this->db->begin(); |
||
| 597 | |||
| 598 | if (!$error) { |
||
| 599 | if (!$notrigger) { |
||
| 600 | // Uncomment this and change WEBSITE to your own tag if you |
||
| 601 | // want this action calls a trigger. |
||
| 602 | |||
| 603 | //// Call triggers |
||
| 604 | //$result=$this->call_trigger('WEBSITE_DELETE',$user); |
||
| 605 | //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} |
||
| 606 | //// End call triggers |
||
| 607 | } |
||
| 608 | } |
||
| 609 | |||
| 610 | if (!$error) { |
||
| 611 | $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element; |
||
| 612 | $sql .= ' WHERE rowid='.((int) $this->id); |
||
| 613 | |||
| 614 | $resql = $this->db->query($sql); |
||
| 615 | if (!$resql) { |
||
| 616 | $error++; |
||
| 617 | $this->errors[] = 'Error '.$this->db->lasterror(); |
||
| 618 | dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR); |
||
| 619 | } |
||
| 620 | } |
||
| 621 | |||
| 622 | if (!$error && !empty($this->ref)) { |
||
| 623 | $pathofwebsite = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$this->ref; |
||
| 624 | |||
| 625 | dol_delete_dir_recursive($pathofwebsite); |
||
| 626 | } |
||
| 627 | |||
| 628 | // Commit or rollback |
||
| 629 | if ($error) { |
||
| 630 | $this->db->rollback(); |
||
| 631 | |||
| 632 | return -1 * $error; |
||
| 633 | } else { |
||
| 634 | $this->db->commit(); |
||
| 635 | |||
| 636 | return 1; |
||
| 637 | } |
||
| 638 | } |
||
| 639 | |||
| 640 | /** |
||
| 641 | * Load a website its id and create a new one in database. |
||
| 642 | * This copy website directories, regenerate all the pages + alias pages and recreate the medias link. |
||
| 643 | * |
||
| 644 | * @param User $user User making the clone |
||
| 645 | * @param int $fromid Id of object to clone |
||
| 646 | * @param string $newref New ref |
||
| 647 | * @param string $newlang New language |
||
| 648 | * @return mixed New object created, <0 if KO |
||
| 649 | */ |
||
| 650 | public function createFromClone($user, $fromid, $newref, $newlang = '') |
||
| 651 | { |
||
| 652 | global $conf, $langs; |
||
| 653 | global $dolibarr_main_data_root; |
||
| 654 | |||
| 655 | $now = dol_now(); |
||
| 656 | $error = 0; |
||
| 657 | |||
| 658 | dol_syslog(__METHOD__, LOG_DEBUG); |
||
| 659 | |||
| 660 | $newref = dol_sanitizeFileName($newref); |
||
| 661 | |||
| 662 | if (empty($newref)) { |
||
| 663 | $this->error = 'ErrorBadParameter'; |
||
| 664 | return -1; |
||
| 665 | } |
||
| 666 | |||
| 667 | $object = new self($this->db); |
||
| 668 | |||
| 669 | // Check no site with ref exists |
||
| 670 | if ($object->fetch(0, $newref) > 0) { |
||
| 671 | $this->error = 'ErrorNewRefIsAlreadyUsed'; |
||
| 672 | return -1; |
||
| 673 | } |
||
| 674 | |||
| 675 | $this->db->begin(); |
||
| 676 | |||
| 677 | // Load source object |
||
| 678 | $object->fetch($fromid); |
||
| 679 | |||
| 680 | $oldidforhome = $object->fk_default_home; |
||
| 681 | $oldref = $object->ref; |
||
| 682 | |||
| 683 | $pathofwebsiteold = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.dol_sanitizeFileName($oldref); |
||
| 684 | $pathofwebsitenew = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.dol_sanitizeFileName($newref); |
||
| 685 | dol_delete_dir_recursive($pathofwebsitenew); |
||
| 686 | |||
| 687 | $fileindex = $pathofwebsitenew.'/index.php'; |
||
| 688 | |||
| 689 | // Reset some properties |
||
| 690 | unset($object->id); |
||
| 691 | unset($object->fk_user_creat); |
||
| 692 | unset($object->import_key); |
||
| 693 | |||
| 694 | // Clear fields |
||
| 695 | $object->ref = $newref; |
||
| 696 | $object->fk_default_home = 0; |
||
| 697 | $object->virtualhost = ''; |
||
| 698 | $object->date_creation = $now; |
||
| 699 | $object->fk_user_creat = $user->id; |
||
| 700 | $object->position = ((int) $object->position) + 1; |
||
| 701 | $object->status = self::STATUS_DRAFT; |
||
| 702 | if (empty($object->lang)) { |
||
| 703 | $object->lang = substr($langs->defaultlang, 0, 2); // Should not happen. Protection for corrupted site with no languages |
||
| 704 | } |
||
| 705 | |||
| 706 | // Create clone |
||
| 707 | $object->context['createfromclone'] = 'createfromclone'; |
||
| 708 | $result = $object->create($user); |
||
| 709 | if ($result < 0) { |
||
| 710 | $error++; |
||
| 711 | $this->error = $object->error; |
||
| 712 | $this->errors = $object->errors; |
||
| 713 | dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR); |
||
| 714 | } |
||
| 715 | |||
| 716 | if (!$error) { |
||
| 717 | dolCopyDir($pathofwebsiteold, $pathofwebsitenew, $conf->global->MAIN_UMASK, 0, null, 2); |
||
| 718 | |||
| 719 | // Check symlink to medias and restore it if ko |
||
| 720 | $pathtomedias = DOL_DATA_ROOT.'/medias'; // Target |
||
| 721 | $pathtomediasinwebsite = $pathofwebsitenew.'/medias'; // Source / Link name |
||
| 722 | if (!is_link(dol_osencode($pathtomediasinwebsite))) { |
||
| 723 | dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite); |
||
| 724 | dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure dir for website exists |
||
| 725 | $result = symlink($pathtomedias, $pathtomediasinwebsite); |
||
| 726 | } |
||
| 727 | |||
| 728 | // Copy images and js dir |
||
| 729 | $pathofmediasjsold = DOL_DATA_ROOT.'/medias/js/'.$oldref; |
||
| 730 | $pathofmediasjsnew = DOL_DATA_ROOT.'/medias/js/'.$newref; |
||
| 731 | dolCopyDir($pathofmediasjsold, $pathofmediasjsnew, $conf->global->MAIN_UMASK, 0); |
||
| 732 | |||
| 733 | $pathofmediasimageold = DOL_DATA_ROOT.'/medias/image/'.$oldref; |
||
| 734 | $pathofmediasimagenew = DOL_DATA_ROOT.'/medias/image/'.$newref; |
||
| 735 | dolCopyDir($pathofmediasimageold, $pathofmediasimagenew, $conf->global->MAIN_UMASK, 0); |
||
| 736 | |||
| 737 | $newidforhome = 0; |
||
| 738 | |||
| 739 | // Duplicate pages |
||
| 740 | $objectpages = new WebsitePage($this->db); |
||
| 741 | $listofpages = $objectpages->fetchAll($fromid); |
||
| 742 | foreach ($listofpages as $pageid => $objectpageold) { |
||
| 743 | // Delete old file |
||
| 744 | $filetplold = $pathofwebsitenew.'/page'.$pageid.'.tpl.php'; |
||
| 745 | dol_delete_file($filetplold); |
||
| 746 | |||
| 747 | // Create new file |
||
| 748 | $objectpagenew = $objectpageold->createFromClone($user, $pageid, $objectpageold->pageurl, '', 0, $object->id, 1); |
||
| 749 | |||
| 750 | //print $pageid.' = '.$objectpageold->pageurl.' -> '.$objectpagenew->id.' = '.$objectpagenew->pageurl.'<br>'; |
||
| 751 | if (is_object($objectpagenew) && $objectpagenew->pageurl) { |
||
| 752 | $filealias = $pathofwebsitenew.'/'.$objectpagenew->pageurl.'.php'; |
||
| 753 | $filetplnew = $pathofwebsitenew.'/page'.$objectpagenew->id.'.tpl.php'; |
||
| 754 | |||
| 755 | // Save page alias |
||
| 756 | $result = dolSavePageAlias($filealias, $object, $objectpagenew); |
||
| 757 | if (!$result) { |
||
| 758 | setEventMessages('Failed to write file '.$filealias, null, 'errors'); |
||
| 759 | } |
||
| 760 | |||
| 761 | $result = dolSavePageContent($filetplnew, $object, $objectpagenew); |
||
| 762 | if (!$result) { |
||
| 763 | setEventMessages('Failed to write file '.$filetplnew, null, 'errors'); |
||
| 764 | } |
||
| 765 | |||
| 766 | if ($pageid == $oldidforhome) { |
||
| 767 | $newidforhome = $objectpagenew->id; |
||
| 768 | } |
||
| 769 | } else { |
||
| 770 | setEventMessages($objectpageold->error, $objectpageold->errors, 'errors'); |
||
| 771 | $error++; |
||
| 772 | } |
||
| 773 | } |
||
| 774 | } |
||
| 775 | |||
| 776 | if (!$error) { |
||
| 777 | // Restore id of home page |
||
| 778 | $object->fk_default_home = $newidforhome; |
||
|
|
|||
| 779 | $res = $object->update($user); |
||
| 780 | if (!($res > 0)) { |
||
| 781 | $error++; |
||
| 782 | setEventMessages($object->error, $object->errors, 'errors'); |
||
| 783 | } |
||
| 784 | |||
| 785 | if (!$error) { |
||
| 786 | $filetpl = $pathofwebsitenew.'/page'.$newidforhome.'.tpl.php'; |
||
| 787 | $filewrapper = $pathofwebsitenew.'/wrapper.php'; |
||
| 788 | |||
| 789 | // Re-generates the index.php page to be the home page, and re-generates the wrapper.php |
||
| 790 | //-------------------------------------------------------------------------------------- |
||
| 791 | $result = dolSaveIndexPage($pathofwebsitenew, $fileindex, $filetpl, $filewrapper); |
||
| 792 | } |
||
| 793 | } |
||
| 794 | |||
| 795 | unset($object->context['createfromclone']); |
||
| 796 | |||
| 797 | // End |
||
| 798 | if (!$error) { |
||
| 799 | $this->db->commit(); |
||
| 800 | |||
| 801 | return $object; |
||
| 802 | } else { |
||
| 803 | $this->db->rollback(); |
||
| 804 | |||
| 805 | return -1; |
||
| 806 | } |
||
| 807 | } |
||
| 808 | |||
| 809 | /** |
||
| 810 | * Return a link to the user card (with optionally the picto) |
||
| 811 | * Use this->id,this->lastname, this->firstname |
||
| 812 | * |
||
| 813 | * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto) |
||
| 814 | * @param string $option On what the link point to |
||
| 815 | * @param integer $notooltip 1=Disable tooltip |
||
| 816 | * @param int $maxlen Max length of visible user name |
||
| 817 | * @param string $morecss Add more css on link |
||
| 818 | * @return string String with URL |
||
| 819 | */ |
||
| 820 | public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '') |
||
| 850 | } |
||
| 851 | |||
| 852 | /** |
||
| 853 | * Retourne le libelle du status d'un user (actif, inactif) |
||
| 854 | * |
||
| 855 | * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto |
||
| 856 | * @return string Label of status |
||
| 857 | */ |
||
| 858 | public function getLibStatut($mode = 0) |
||
| 859 | { |
||
| 860 | return $this->LibStatut($this->status, $mode); |
||
| 861 | } |
||
| 862 | |||
| 863 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 864 | /** |
||
| 865 | * Renvoi le libelle d'un status donne |
||
| 866 | * |
||
| 867 | * @param int $status Id status |
||
| 868 | * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto |
||
| 869 | * @return string Label of status |
||
| 870 | */ |
||
| 871 | public function LibStatut($status, $mode = 0) |
||
| 872 | { |
||
| 873 | // phpcs:enable |
||
| 874 | global $langs; |
||
| 875 | |||
| 876 | if (empty($this->labelStatus) || empty($this->labelStatusShort)) { |
||
| 877 | global $langs; |
||
| 878 | //$langs->load("mymodule"); |
||
| 879 | $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Disabled'); |
||
| 880 | $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled'); |
||
| 881 | $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Disabled'); |
||
| 882 | $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled'); |
||
| 883 | } |
||
| 884 | |||
| 885 | $statusType = 'status5'; |
||
| 886 | if ($status == self::STATUS_VALIDATED) { |
||
| 887 | $statusType = 'status4'; |
||
| 888 | } |
||
| 889 | |||
| 890 | return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); |
||
| 891 | } |
||
| 892 | |||
| 893 | |||
| 894 | /** |
||
| 895 | * Initialise object with example values |
||
| 896 | * Id must be 0 if object instance is a specimen |
||
| 897 | * |
||
| 898 | * @return void |
||
| 899 | */ |
||
| 900 | public function initAsSpecimen() |
||
| 901 | { |
||
| 902 | global $user; |
||
| 903 | |||
| 904 | $this->id = 0; |
||
| 905 | $this->specimen = 1; |
||
| 906 | $this->entity = 1; |
||
| 907 | $this->ref = 'myspecimenwebsite'; |
||
| 908 | $this->description = 'A specimen website'; |
||
| 909 | $this->lang = 'en'; |
||
| 910 | $this->otherlang = 'fr,es'; |
||
| 911 | $this->status = 1; |
||
| 912 | $this->fk_default_home = null; |
||
| 913 | $this->virtualhost = 'http://myvirtualhost'; |
||
| 914 | $this->fk_user_creat = $user->id; |
||
| 915 | $this->fk_user_modif = $user->id; |
||
| 916 | $this->date_creation = dol_now(); |
||
| 917 | $this->tms = dol_now(); |
||
| 918 | } |
||
| 919 | |||
| 920 | |||
| 921 | /** |
||
| 922 | * Generate a zip with all data of web site. |
||
| 923 | * |
||
| 924 | * @return string Path to file with zip or '' if error |
||
| 925 | */ |
||
| 926 | public function exportWebSite() |
||
| 927 | { |
||
| 928 | global $conf, $mysoc; |
||
| 929 | |||
| 930 | $website = $this; |
||
| 931 | |||
| 932 | if (empty($website->id) || empty($website->ref)) { |
||
| 933 | setEventMessages("Website id or ref is not defined", null, 'errors'); |
||
| 934 | return ''; |
||
| 935 | } |
||
| 936 | |||
| 937 | dol_syslog("Create temp dir ".$conf->website->dir_temp); |
||
| 938 | dol_mkdir($conf->website->dir_temp); |
||
| 939 | if (!is_writable($conf->website->dir_temp)) { |
||
| 940 | setEventMessages("Temporary dir ".$conf->website->dir_temp." is not writable", null, 'errors'); |
||
| 941 | return ''; |
||
| 942 | } |
||
| 943 | |||
| 944 | $destdir = $conf->website->dir_temp.'/'.$website->ref; |
||
| 945 | |||
| 946 | dol_syslog("Clear temp dir ".$destdir); |
||
| 947 | $count = 0; $countreallydeleted = 0; |
||
| 948 | $counttodelete = dol_delete_dir_recursive($destdir, $count, 1, 0, $countreallydeleted); |
||
| 949 | if ($counttodelete != $countreallydeleted) { |
||
| 950 | setEventMessages("Failed to clean temp directory ".$destdir, null, 'errors'); |
||
| 951 | return ''; |
||
| 952 | } |
||
| 953 | |||
| 954 | $arrayreplacementinfilename = array(); |
||
| 955 | $arrayreplacementincss = array(); |
||
| 956 | $arrayreplacementincss['file=image/'.$website->ref.'/'] = "file=image/__WEBSITE_KEY__/"; |
||
| 957 | $arrayreplacementincss['file=js/'.$website->ref.'/'] = "file=js/__WEBSITE_KEY__/"; |
||
| 958 | $arrayreplacementincss['medias/image/'.$website->ref.'/'] = "medias/image/__WEBSITE_KEY__/"; |
||
| 959 | $arrayreplacementincss['medias/js/'.$website->ref.'/'] = "medias/js/__WEBSITE_KEY__/"; |
||
| 960 | if ($mysoc->logo_small) { |
||
| 961 | $arrayreplacementincss['file=logos%2Fthumbs%2F'.$mysoc->logo_small] = "file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__"; |
||
| 962 | } |
||
| 963 | if ($mysoc->logo_mini) { |
||
| 964 | $arrayreplacementincss['file=logos%2Fthumbs%2F'.$mysoc->logo_mini] = "file=logos%2Fthumbs%2F__LOGO_MINI_KEY__"; |
||
| 965 | } |
||
| 966 | if ($mysoc->logo) { |
||
| 967 | $arrayreplacementincss['file=logos%2Fthumbs%2F'.$mysoc->logo] = "file=logos%2Fthumbs%2F__LOGO_KEY__"; |
||
| 968 | } |
||
| 969 | |||
| 970 | // Create output directories |
||
| 971 | dol_syslog("Create containers dir"); |
||
| 972 | dol_mkdir($conf->website->dir_temp.'/'.$website->ref.'/containers'); |
||
| 973 | dol_mkdir($conf->website->dir_temp.'/'.$website->ref.'/medias/image/websitekey'); |
||
| 974 | dol_mkdir($conf->website->dir_temp.'/'.$website->ref.'/medias/js/websitekey'); |
||
| 975 | |||
| 976 | // Copy files into 'containers' |
||
| 977 | $srcdir = $conf->website->dir_output.'/'.$website->ref; |
||
| 978 | $destdir = $conf->website->dir_temp.'/'.$website->ref.'/containers'; |
||
| 979 | |||
| 980 | dol_syslog("Copy content from ".$srcdir." into ".$destdir); |
||
| 981 | dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacementinfilename, 2); |
||
| 982 | |||
| 983 | // Copy files into medias/image |
||
| 984 | $srcdir = DOL_DATA_ROOT.'/medias/image/'.$website->ref; |
||
| 985 | $destdir = $conf->website->dir_temp.'/'.$website->ref.'/medias/image/websitekey'; |
||
| 986 | |||
| 987 | dol_syslog("Copy content from ".$srcdir." into ".$destdir); |
||
| 988 | dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacementinfilename); |
||
| 989 | |||
| 990 | // Copy files into medias/js |
||
| 991 | $srcdir = DOL_DATA_ROOT.'/medias/js/'.$website->ref; |
||
| 992 | $destdir = $conf->website->dir_temp.'/'.$website->ref.'/medias/js/websitekey'; |
||
| 993 | |||
| 994 | dol_syslog("Copy content from ".$srcdir." into ".$destdir); |
||
| 995 | dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacementinfilename); |
||
| 996 | |||
| 997 | // Make some replacement into some files |
||
| 998 | $cssindestdir = $conf->website->dir_temp.'/'.$website->ref.'/containers/styles.css.php'; |
||
| 999 | dolReplaceInFile($cssindestdir, $arrayreplacementincss); |
||
| 1000 | |||
| 1001 | $htmldeaderindestdir = $conf->website->dir_temp.'/'.$website->ref.'/containers/htmlheader.html'; |
||
| 1002 | dolReplaceInFile($htmldeaderindestdir, $arrayreplacementincss); |
||
| 1003 | |||
| 1004 | // Build sql file |
||
| 1005 | $filesql = $conf->website->dir_temp.'/'.$website->ref.'/website_pages.sql'; |
||
| 1006 | $fp = fopen($filesql, "w"); |
||
| 1007 | if (empty($fp)) { |
||
| 1008 | setEventMessages("Failed to create file ".$filesql, null, 'errors'); |
||
| 1009 | return ''; |
||
| 1010 | } |
||
| 1011 | |||
| 1012 | $objectpages = new WebsitePage($this->db); |
||
| 1013 | $listofpages = $objectpages->fetchAll($website->id); |
||
| 1014 | |||
| 1015 | // Assign ->newid and ->newfk_page |
||
| 1016 | $i = 1; |
||
| 1017 | foreach ($listofpages as $pageid => $objectpageold) { |
||
| 1018 | $objectpageold->newid = $i; |
||
| 1019 | $i++; |
||
| 1020 | } |
||
| 1021 | $i = 1; |
||
| 1022 | foreach ($listofpages as $pageid => $objectpageold) { |
||
| 1023 | // Search newid |
||
| 1024 | $newfk_page = 0; |
||
| 1025 | foreach ($listofpages as $pageid2 => $objectpageold2) { |
||
| 1026 | if ($pageid2 == $objectpageold->fk_page) { |
||
| 1027 | $newfk_page = $objectpageold2->newid; |
||
| 1028 | break; |
||
| 1029 | } |
||
| 1030 | } |
||
| 1031 | $objectpageold->newfk_page = $newfk_page; |
||
| 1032 | $i++; |
||
| 1033 | } |
||
| 1034 | foreach ($listofpages as $pageid => $objectpageold) { |
||
| 1035 | $allaliases = $objectpageold->pageurl; |
||
| 1036 | $allaliases .= ($objectpageold->aliasalt ? ','.$objectpageold->aliasalt : ''); |
||
| 1037 | |||
| 1038 | $line = '-- Page ID '.$objectpageold->id.' -> '.$objectpageold->newid.'__+MAX_llx_website_page__ - Aliases '.$allaliases.' --;'; // newid start at 1, 2... |
||
| 1039 | $line .= "\n"; |
||
| 1040 | fputs($fp, $line); |
||
| 1041 | |||
| 1042 | // Warning: We must keep llx_ here. It is a generic SQL. |
||
| 1043 | $line = 'INSERT INTO llx_website_page(rowid, fk_page, fk_website, pageurl, aliasalt, title, description, lang, image, keywords, status, date_creation, tms, import_key, grabbed_from, type_container, htmlheader, content, author_alias, allowed_in_frames)'; |
||
| 1044 | |||
| 1045 | $line .= " VALUES("; |
||
| 1046 | $line .= $objectpageold->newid."__+MAX_llx_website_page__, "; |
||
| 1047 | $line .= ($objectpageold->newfk_page ? $this->db->escape($objectpageold->newfk_page)."__+MAX_llx_website_page__" : "null").", "; |
||
| 1048 | $line .= "__WEBSITE_ID__, "; |
||
| 1049 | $line .= "'".$this->db->escape($objectpageold->pageurl)."', "; |
||
| 1050 | $line .= "'".$this->db->escape($objectpageold->aliasalt)."', "; |
||
| 1051 | $line .= "'".$this->db->escape($objectpageold->title)."', "; |
||
| 1052 | $line .= "'".$this->db->escape($objectpageold->description)."', "; |
||
| 1053 | $line .= "'".$this->db->escape($objectpageold->lang)."', "; |
||
| 1054 | $line .= "'".$this->db->escape($objectpageold->image)."', "; |
||
| 1055 | $line .= "'".$this->db->escape($objectpageold->keywords)."', "; |
||
| 1056 | $line .= "'".$this->db->escape($objectpageold->status)."', "; |
||
| 1057 | $line .= "'".$this->db->idate($objectpageold->date_creation)."', "; |
||
| 1058 | $line .= "'".$this->db->idate($objectpageold->date_modification)."', "; |
||
| 1059 | $line .= ($objectpageold->import_key ? "'".$this->db->escape($objectpageold->import_key)."'" : "null").", "; |
||
| 1060 | $line .= "'".$this->db->escape($objectpageold->grabbed_from)."', "; |
||
| 1061 | $line .= "'".$this->db->escape($objectpageold->type_container)."', "; |
||
| 1062 | |||
| 1063 | $stringtoexport = $objectpageold->htmlheader; |
||
| 1064 | $stringtoexport = str_replace(array("\r\n", "\r", "\n"), "__N__", $stringtoexport); |
||
| 1065 | $stringtoexport = str_replace('file=image/'.$website->ref.'/', "file=image/__WEBSITE_KEY__/", $stringtoexport); |
||
| 1066 | $stringtoexport = str_replace('file=js/'.$website->ref.'/', "file=js/__WEBSITE_KEY__/", $stringtoexport); |
||
| 1067 | $stringtoexport = str_replace('medias/image/'.$website->ref.'/', "medias/image/__WEBSITE_KEY__/", $stringtoexport); |
||
| 1068 | $stringtoexport = str_replace('medias/js/'.$website->ref.'/', "medias/js/__WEBSITE_KEY__/", $stringtoexport); |
||
| 1069 | $stringtoexport = str_replace('file=logos%2Fthumbs%2F'.$mysoc->logo_small, "file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__", $stringtoexport); |
||
| 1070 | $stringtoexport = str_replace('file=logos%2Fthumbs%2F'.$mysoc->logo_mini, "file=logos%2Fthumbs%2F__LOGO_MINI_KEY__", $stringtoexport); |
||
| 1071 | $stringtoexport = str_replace('file=logos%2Fthumbs%2F'.$mysoc->logo, "file=logos%2Fthumbs%2F__LOGO_KEY__", $stringtoexport); |
||
| 1072 | $line .= "'".$this->db->escape(str_replace(array("\r\n", "\r", "\n"), "__N__", $stringtoexport))."', "; // Replace \r \n to have record on 1 line |
||
| 1073 | |||
| 1074 | $stringtoexport = $objectpageold->content; |
||
| 1075 | $stringtoexport = str_replace(array("\r\n", "\r", "\n"), "__N__", $stringtoexport); |
||
| 1076 | $stringtoexport = str_replace('file=image/'.$website->ref.'/', "file=image/__WEBSITE_KEY__/", $stringtoexport); |
||
| 1077 | $stringtoexport = str_replace('file=js/'.$website->ref.'/', "file=js/__WEBSITE_KEY__/", $stringtoexport); |
||
| 1078 | $stringtoexport = str_replace('medias/image/'.$website->ref.'/', "medias/image/__WEBSITE_KEY__/", $stringtoexport); |
||
| 1079 | $stringtoexport = str_replace('medias/js/'.$website->ref.'/', "medias/js/__WEBSITE_KEY__/", $stringtoexport); |
||
| 1080 | $stringtoexport = str_replace('file=logos%2Fthumbs%2F'.$mysoc->logo_small, "file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__", $stringtoexport); |
||
| 1081 | $stringtoexport = str_replace('file=logos%2Fthumbs%2F'.$mysoc->logo_mini, "file=logos%2Fthumbs%2F__LOGO_MINI_KEY__", $stringtoexport); |
||
| 1082 | $stringtoexport = str_replace('file=logos%2Fthumbs%2F'.$mysoc->logo, "file=logos%2Fthumbs%2F__LOGO_KEY__", $stringtoexport); |
||
| 1083 | |||
| 1084 | // When we have a link src="image/websiteref/file.png" into html content |
||
| 1085 | $stringtoexport = str_replace('="image/'.$website->ref.'/', '="image/__WEBSITE_KEY__/', $stringtoexport); |
||
| 1086 | |||
| 1087 | $line .= "'".$this->db->escape($stringtoexport)."', "; // Replace \r \n to have record on 1 line |
||
| 1088 | $line .= "'".$this->db->escape($objectpageold->author_alias)."', "; |
||
| 1089 | $line .= "'".$this->db->escape($objectpageold->allowed_in_frames)."'"; |
||
| 1090 | $line .= ");"; |
||
| 1091 | $line .= "\n"; |
||
| 1092 | |||
| 1093 | fputs($fp, $line); |
||
| 1094 | |||
| 1095 | // Add line to update home page id during import |
||
| 1096 | //var_dump($this->fk_default_home.' - '.$objectpageold->id.' - '.$objectpageold->newid);exit; |
||
| 1097 | if ($this->fk_default_home > 0 && ($objectpageold->id == $this->fk_default_home) && ($objectpageold->newid > 0)) { // This is the record with home page |
||
| 1098 | // Warning: We must keep llx_ here. It is a generic SQL. |
||
| 1099 | $line = "UPDATE llx_website SET fk_default_home = ".($objectpageold->newid > 0 ? $this->db->escape($objectpageold->newid)."__+MAX_llx_website_page__" : "null")." WHERE rowid = __WEBSITE_ID__;"; |
||
| 1100 | $line .= "\n"; |
||
| 1101 | fputs($fp, $line); |
||
| 1102 | } |
||
| 1103 | } |
||
| 1104 | |||
| 1105 | $line = "\n-- For Dolibarr v14+ --;\n"; |
||
| 1106 | $line .= "UPDATE llx_website SET lang = '".$this->db->escape($this->fk_default_lang)."' WHERE rowid = __WEBSITE_ID__;\n"; |
||
| 1107 | $line .= "UPDATE llx_website SET otherlang = '".$this->db->escape($this->otherlang)."' WHERE rowid = __WEBSITE_ID__;\n"; |
||
| 1108 | $line .= "\n"; |
||
| 1109 | fputs($fp, $line); |
||
| 1110 | |||
| 1111 | fclose($fp); |
||
| 1112 | if (!empty($conf->global->MAIN_UMASK)) { |
||
| 1113 | @chmod($filesql, octdec($conf->global->MAIN_UMASK)); |
||
| 1114 | } |
||
| 1115 | |||
| 1116 | // Build zip file |
||
| 1117 | $filedir = $conf->website->dir_temp.'/'.$website->ref.'/.'; |
||
| 1118 | $fileglob = $conf->website->dir_temp.'/'.$website->ref.'/website_'.$website->ref.'-*.zip'; |
||
| 1119 | $filename = $conf->website->dir_temp.'/'.$website->ref.'/website_'.$website->ref.'-'.dol_print_date(dol_now(), 'dayhourlog').'-V'.((float) DOL_VERSION).'.zip'; |
||
| 1120 | |||
| 1121 | dol_delete_file($fileglob, 0); |
||
| 1122 | $result = dol_compress_file($filedir, $filename, 'zip'); |
||
| 1123 | |||
| 1124 | if ($result > 0) { |
||
| 1125 | return $filename; |
||
| 1126 | } else { |
||
| 1127 | global $errormsg; |
||
| 1128 | $this->error = $errormsg; |
||
| 1129 | return ''; |
||
| 1130 | } |
||
| 1131 | } |
||
| 1132 | |||
| 1133 | |||
| 1134 | /** |
||
| 1135 | * Open a zip with all data of web site and load it into database. |
||
| 1136 | * |
||
| 1137 | * @param string $pathtofile Path of zip file |
||
| 1138 | * @return int <0 if KO, Id of new website if OK |
||
| 1139 | */ |
||
| 1140 | public function importWebSite($pathtofile) |
||
| 1141 | { |
||
| 1142 | global $conf, $mysoc; |
||
| 1143 | |||
| 1144 | $error = 0; |
||
| 1145 | |||
| 1146 | $object = $this; |
||
| 1147 | if (empty($object->ref)) { |
||
| 1148 | $this->error = 'Function importWebSite called on object not loaded (object->ref is empty)'; |
||
| 1149 | return -1; |
||
| 1150 | } |
||
| 1151 | |||
| 1152 | dol_delete_dir_recursive($conf->website->dir_temp."/".$object->ref); |
||
| 1153 | dol_mkdir($conf->website->dir_temp.'/'.$object->ref); |
||
| 1154 | |||
| 1155 | $filename = basename($pathtofile); |
||
| 1156 | if (!preg_match('/^website_(.*)-(.*)$/', $filename, $reg)) { |
||
| 1157 | $this->errors[] = 'Bad format for filename '.$filename.'. Must be website_XXX-VERSION.'; |
||
| 1158 | return -1; |
||
| 1159 | } |
||
| 1160 | |||
| 1161 | $result = dol_uncompress($pathtofile, $conf->website->dir_temp.'/'.$object->ref); |
||
| 1162 | |||
| 1163 | if (!empty($result['error'])) { |
||
| 1164 | $this->errors[] = 'Failed to unzip file '.$pathtofile.'.'; |
||
| 1165 | return -1; |
||
| 1166 | } |
||
| 1167 | |||
| 1168 | $arrayreplacement = array(); |
||
| 1169 | $arrayreplacement['__WEBSITE_ID__'] = $object->id; |
||
| 1170 | $arrayreplacement['__WEBSITE_KEY__'] = $object->ref; |
||
| 1171 | $arrayreplacement['__N__'] = $this->db->escape("\n"); // Restore \n |
||
| 1172 | $arrayreplacement['__LOGO_SMALL_KEY__'] = $this->db->escape($mysoc->logo_small); |
||
| 1173 | $arrayreplacement['__LOGO_MINI_KEY__'] = $this->db->escape($mysoc->logo_mini); |
||
| 1174 | $arrayreplacement['__LOGO_KEY__'] = $this->db->escape($mysoc->logo); |
||
| 1175 | |||
| 1176 | // Copy containers |
||
| 1177 | dolCopyDir($conf->website->dir_temp.'/'.$object->ref.'/containers', $conf->website->dir_output.'/'.$object->ref, 0, 1); // Overwrite if exists |
||
| 1178 | |||
| 1179 | // Make replacement into css and htmlheader file |
||
| 1180 | $cssindestdir = $conf->website->dir_output.'/'.$object->ref.'/styles.css.php'; |
||
| 1181 | $result = dolReplaceInFile($cssindestdir, $arrayreplacement); |
||
| 1182 | |||
| 1183 | $htmldeaderindestdir = $conf->website->dir_output.'/'.$object->ref.'/htmlheader.html'; |
||
| 1184 | $result = dolReplaceInFile($htmldeaderindestdir, $arrayreplacement); |
||
| 1185 | |||
| 1186 | // Now generate the master.inc.php page |
||
| 1187 | $filemaster = $conf->website->dir_output.'/'.$object->ref.'/master.inc.php'; |
||
| 1188 | $result = dolSaveMasterFile($filemaster); |
||
| 1189 | if (!$result) { |
||
| 1190 | $this->errors[] = 'Failed to write file '.$filemaster; |
||
| 1191 | $error++; |
||
| 1192 | } |
||
| 1193 | |||
| 1194 | dolCopyDir($conf->website->dir_temp.'/'.$object->ref.'/medias/image/websitekey', $conf->website->dir_output.'/'.$object->ref.'/medias/image/'.$object->ref, 0, 1); // Medias can be shared, do not overwrite if exists |
||
| 1195 | dolCopyDir($conf->website->dir_temp.'/'.$object->ref.'/medias/js/websitekey', $conf->website->dir_output.'/'.$object->ref.'/medias/js/'.$object->ref, 0, 1); // Medias can be shared, do not overwrite if exists |
||
| 1196 | |||
| 1197 | $sqlfile = $conf->website->dir_temp."/".$object->ref.'/website_pages.sql'; |
||
| 1198 | |||
| 1199 | $result = dolReplaceInFile($sqlfile, $arrayreplacement); |
||
| 1200 | |||
| 1201 | $this->db->begin(); |
||
| 1202 | |||
| 1203 | // Search the $maxrowid because we need it later |
||
| 1204 | $sqlgetrowid = 'SELECT MAX(rowid) as max from '.MAIN_DB_PREFIX.'website_page'; |
||
| 1205 | $resql = $this->db->query($sqlgetrowid); |
||
| 1206 | if ($resql) { |
||
| 1207 | $obj = $this->db->fetch_object($resql); |
||
| 1208 | $maxrowid = $obj->max; |
||
| 1209 | } |
||
| 1210 | |||
| 1211 | // Load sql record |
||
| 1212 | $runsql = run_sql($sqlfile, 1, '', 0, '', 'none', 0, 1); // The maxrowid of table is searched into this function two |
||
| 1213 | if ($runsql <= 0) { |
||
| 1214 | $this->errors[] = 'Failed to load sql file '.$sqlfile; |
||
| 1215 | $error++; |
||
| 1216 | } |
||
| 1217 | |||
| 1218 | $objectpagestatic = new WebsitePage($this->db); |
||
| 1219 | |||
| 1220 | // Make replacement of IDs |
||
| 1221 | $fp = fopen($sqlfile, "r"); |
||
| 1222 | if ($fp) { |
||
| 1223 | while (!feof($fp)) { |
||
| 1224 | $reg = array(); |
||
| 1225 | |||
| 1226 | // Warning fgets with second parameter that is null or 0 hang. |
||
| 1227 | $buf = fgets($fp, 65000); |
||
| 1228 | if (preg_match('/^-- Page ID (\d+)\s[^\s]+\s(\d+).*Aliases\s(.*)\s--;/i', $buf, $reg)) { |
||
| 1229 | $oldid = $reg[1]; |
||
| 1230 | $newid = ($reg[2] + $maxrowid); |
||
| 1231 | $aliasesarray = explode(',', $reg[3]); |
||
| 1232 | |||
| 1233 | dol_syslog("Found ID ".$oldid." to replace with ID ".$newid." and shortcut aliases to create: ".$reg[3]); |
||
| 1234 | |||
| 1235 | dol_move($conf->website->dir_output.'/'.$object->ref.'/page'.$oldid.'.tpl.php', $conf->website->dir_output.'/'.$object->ref.'/page'.$newid.'.tpl.php', 0, 1, 0, 0); |
||
| 1236 | |||
| 1237 | $objectpagestatic->fetch($newid); |
||
| 1238 | |||
| 1239 | // The move is not enough, so we regenerate page |
||
| 1240 | $filetpl = $conf->website->dir_output.'/'.$object->ref.'/page'.$newid.'.tpl.php'; |
||
| 1241 | $result = dolSavePageContent($filetpl, $object, $objectpagestatic); |
||
| 1242 | if (!$result) { |
||
| 1243 | $this->errors[] = 'Failed to write file '.basename($filetpl); |
||
| 1244 | $error++; |
||
| 1245 | } |
||
| 1246 | |||
| 1247 | // Regenerate alternative aliases pages |
||
| 1248 | if (is_array($aliasesarray)) { |
||
| 1249 | foreach ($aliasesarray as $aliasshortcuttocreate) { |
||
| 1250 | if (trim($aliasshortcuttocreate)) { |
||
| 1251 | $filealias = $conf->website->dir_output.'/'.$object->ref.'/'.trim($aliasshortcuttocreate).'.php'; |
||
| 1252 | $result = dolSavePageAlias($filealias, $object, $objectpagestatic); |
||
| 1253 | if (!$result) { |
||
| 1254 | $this->errors[] = 'Failed to write file '.basename($filealias); |
||
| 1255 | $error++; |
||
| 1256 | } |
||
| 1257 | } |
||
| 1258 | } |
||
| 1259 | } |
||
| 1260 | } |
||
| 1261 | } |
||
| 1262 | } |
||
| 1263 | |||
| 1264 | // Read record of website that has been updated by the run_sql function previously called so we can get the |
||
| 1265 | // value of fk_default_home that is ID of home page |
||
| 1266 | $sql = "SELECT fk_default_home FROM ".MAIN_DB_PREFIX."website WHERE rowid = ".((int) $object->id); |
||
| 1267 | $resql = $this->db->query($sql); |
||
| 1268 | if ($resql) { |
||
| 1269 | $obj = $this->db->fetch_object($resql); |
||
| 1270 | if ($obj) { |
||
| 1271 | $object->fk_default_home = $obj->fk_default_home; |
||
| 1272 | } else { |
||
| 1273 | //$this->errors[] = 'Failed to get the Home page'; |
||
| 1274 | //$error++; |
||
| 1275 | } |
||
| 1276 | } |
||
| 1277 | |||
| 1278 | // Regenerate index page to point to the new index page |
||
| 1279 | $pathofwebsite = $conf->website->dir_output.'/'.$object->ref; |
||
| 1280 | dolSaveIndexPage($pathofwebsite, $pathofwebsite.'/index.php', $pathofwebsite.'/page'.$object->fk_default_home.'.tpl.php', $pathofwebsite.'/wrapper.php'); |
||
| 1281 | |||
| 1282 | if ($error) { |
||
| 1283 | $this->db->rollback(); |
||
| 1284 | return -1; |
||
| 1285 | } else { |
||
| 1286 | $this->db->commit(); |
||
| 1287 | return $object->id; |
||
| 1288 | } |
||
| 1289 | } |
||
| 1290 | |||
| 1291 | /** |
||
| 1292 | * Rebuild all files of a containers of a website. Rebuild also the wrapper.php file. TODO Add other files too. |
||
| 1293 | * Note: Files are already regenerated during importWebSite so this function is useless when importing a website. |
||
| 1294 | * |
||
| 1295 | * @return int <0 if KO, >=0 if OK |
||
| 1296 | */ |
||
| 1297 | public function rebuildWebSiteFiles() |
||
| 1372 | } |
||
| 1373 | } |
||
| 1374 | |||
| 1375 | /** |
||
| 1376 | * Return if web site is a multilanguage web site. Return false if there is only 0 or 1 language. |
||
| 1377 | * |
||
| 1378 | * @return boolean True if web site is a multilanguage web site |
||
| 1379 | */ |
||
| 1380 | public function isMultiLang() |
||
| 1381 | { |
||
| 1382 | return (empty($this->otherlang) ? false : true); |
||
| 1383 | } |
||
| 1384 | |||
| 1385 | /** |
||
| 1386 | * Component to select language inside a container (Full CSS Only) |
||
| 1387 | * |
||
| 1388 | * @param array|string $languagecodes 'auto' to show all languages available for page, or language codes array like array('en','fr','de','es') |
||
| 1389 | * @param Translate $weblangs Language Object |
||
| 1390 | * @param string $morecss More CSS class on component |
||
| 1391 | * @param string $htmlname Suffix for HTML name |
||
| 1392 | * @return string HTML select component |
||
| 1393 | */ |
||
| 1394 | public function componentSelectLang($languagecodes, $weblangs, $morecss = '', $htmlname = '') |
||
| 1567 | } |
||
| 1568 | } |
||
| 1569 |