Import() public method

Import a write panel given the file path.
public Import ( string $panelFilePath, string $writePanelName = false, boolean $overwrite = false ) : the
$panelFilePath string the full path of the panel file
$writePanelName string the write panel name, if this value if false, the function will use the pnl filename as the write panel name. The default value is false
$overwrite boolean whether to overwrite existing panels with the same name
return the panel id, or false in case of error.
function install()
{
    require_once dirname(__FILE__) . '/../magic-fields/RCCWP_CustomWritePanel.php';
    // Create default write pages
    $existing_write_panels = array();
    foreach (RCCWP_CustomWritePanel::GetCustomWritePanels() as $panel) {
        array_push($existing_write_panels, $panel->name);
    }
    $panels_dir_name = dirname(__FILE__) . '/panels/';
    $panels_dir = opendir($panels_dir_name);
    $panels = array();
    while (false !== ($panel_file = readdir($panels_dir))) {
        $panel_name = basename($panel_file, ".pnl");
        if (!is_dir($panel_file) && $panel_name && $panel_name != $panel_file && !in_array($panel_name, $existing_write_panels)) {
            // If this file isn't a directory, ends with .pnl, and isn't already an existing panel, create and store it for import.
            // $panel_id = RCCWP_CustomWritePanel::Create($panel_name, '', array(), array(), 1, "post", false);
            RCCWP_CustomWritePanel::Import($panels_dir_name . $panel_file);
            $panels[$panel_name] = $panel_file;
        }
    }
    foreach ($panels as $panel_name => $panel_file) {
        RCCWP_CustomWritePanel::Import($panels_dir_name . $panel_file, $panel_name, true);
    }
}
Exemplo n.º 2
0
 /**
  * Import a module given the zip file path. Importing a module means inserting it in
  * the database and copying its folder to modules folder. If a module with the same
  * name already exists, the function will append a number to the module name. You must 
  * have either php ZipArchive extension or unzip program installed.
  *
  * @param string $zipFilePath the full path of the zip file
  * @param string $moduleName the module name, if this value if false, the function will
  * 							use the zip filename as the module name. The default value is false
  * @return the module id, or false in case of error.
  */
 function Import($zipFilePath, $moduleName = false)
 {
     include_once 'RCCWP_CustomGroup.php';
     include_once 'RCCWP_CustomField.php';
     include_once 'RCCWP_CustomWritePanel.php';
     include_once 'RCCWP_Application.php';
     include_once 'RCCWP_CustomWritePanel.php';
     global $flutter_domain;
     if (!strpos($zipFilePath, ".zip")) {
         return false;
     }
     if (!$moduleName) {
         //use zip filename
         $moduleName = basename($zipFilePath, ".zip");
     }
     if ($moduleName == '') {
         return false;
     }
     // Append a number if the module already exists,
     $i = 1;
     $newModuleName = $moduleName;
     while (file_exists(FLUTTER_MODULES_DIR . $newModuleName)) {
         $newModuleName = $moduleName . "_" . $i++;
     }
     $moduleName = $newModuleName;
     mkdir(FLUTTER_MODULES_DIR . $moduleName);
     chmod(FLUTTER_MODULES_DIR . $moduleName, 0777);
     $destPath = FLUTTER_MODULES_DIR . $moduleName . DIRECTORY_SEPARATOR;
     if (class_exists('ZipArchive')) {
         $zip = new ZipArchive();
         // open archive
         if ($zip->open($zipFilePath) !== TRUE) {
             die(__('Could not open archive', $flutter_domain));
         }
         // extract contents to destination directory
         $zip->extractTo($destPath);
         // close archive
         $zip->close();
     } else {
         if (RCCWP_Application::CheckDecompressionProgramUnzip()) {
             $command = "unzip {$zipFilePath} -d " . $destPath;
         } else {
             die(__('Cannot find unzip program!', $flutter_domain));
         }
         exec($command, $out, $err);
     }
     $moduleInfo_imported_data = unserialize(file_get_contents($destPath . 'module_info.exp'));
     //Import module
     $moduleID = RCCWP_CustomWriteModule::Create($moduleName, $moduleInfo_imported_data['moduleinfo']->description, false);
     //Import any panels
     if ($handle = @opendir($destPath)) {
         while (false !== ($file = readdir($handle))) {
             if (substr($file, 0, 1) == "_") {
                 $panelName = basename(substr($file, 1), ".pnl");
                 RCCWP_CustomWritePanel::Import($destPath . $file, $panelName);
             }
         }
     }
     //Create Duplicates
     foreach ($moduleInfo_imported_data['duplicates'] as $moduleDuplicate) {
         RCCWP_ModuleDuplicate::Create($moduleID, $moduleDuplicate->duplicate_name);
     }
     return $moduleID;
 }
 function Import()
 {
     global $mf_domain;
     include_once 'RCCWP_CustomWritePanel.php';
     if (isset($_FILES['import-write-panel-file']) && !empty($_FILES['import-write-panel-file']['tmp_name'])) {
         $filePath = $_FILES['import-write-panel-file']['tmp_name'];
     } else {
         die(__('Error uploading file!', $mf_domain));
     }
     $writePanelName = basename($_FILES['import-write-panel-file']['name'], ".pnl");
     $panelID = RCCWP_CustomWritePanel::Import($filePath, $writePanelName);
     unlink($filePath);
     echo "<div class='wrap'><h3>" . __("The Write Panel was imported successfuly.", $mf_domain) . "</h3>";
     echo '<p><a href="' . RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('view-custom-write-panel', $panelID) . '">' . __('Click here', $mf_domain) . ' </a> ' . __('to edit the write panel.', $mf_domain) . '</p>';
     echo "</div>";
 }
Exemplo n.º 4
0
 /**
  * Import default modules/panels in the theme if it is the first time to 
  * activate the theme and add the theme settings to the database.
  *
  */
 function ImportNewTheme($themeName)
 {
     // -- Add/update theme settings to the database
     FlutterLayoutBlock::UpdateModuleSettings(get_template_directory() . '/configure.xml', -1, '-', get_option('template'));
     FlutterLayoutBlock::UpdateAllModulesSettings();
     // -- Import modules and panels
     if (RCCWP_Application::IsWordpressMu()) {
         if (get_site_option('Flutter_theme_ft_' . $themeName) == '1') {
             return;
         }
         update_site_option('Flutter_theme_ft_' . $themeName, '1');
     } else {
         if (get_option('Flutter_theme_ft_' . $themeName) == '1') {
             return;
         }
         update_option('Flutter_theme_ft_' . $themeName, '1');
     }
     $modulesFolder = get_template_directory() . '/Flutter_modules/';
     $panelsFolder = get_template_directory() . '/Flutter_panels/';
     // Import modules
     if ($handle = @opendir($modulesFolder)) {
         while (false !== ($file = readdir($handle))) {
             $filePath = $modulesFolder . $file;
             RCCWP_CustomWriteModule::Import($filePath);
         }
     }
     // Import panels
     if ($handle = @opendir($panelsFolder)) {
         while (false !== ($file = readdir($handle))) {
             $filePath = $panelsFolder . $file;
             RCCWP_CustomWritePanel::Import($filePath);
         }
     }
 }