Example #1
0
function mediashare_mediahandlerapi_scanMediaHandlers()
{
    // Check access
    if (!SecurityUtil::checkPermission('mediashare::', '::', ACCESS_ADMIN)) {
        return LogUtil::registerPermissionError();
    }
    $dom = ZLanguage::getModuleDomain('mediashare');
    // Clear existing handler table
    if (!DBUtil::truncateTable('mediashare_mediahandlers')) {
        return LogUtil::registerError(__f('Error in %1$s: %2$s.', array('mediahandlerapi.scanMediaHandlers', __f("Could not clear the '%s' table.", 'mediahandlers', $dom)), $dom));
    }
    // Scan for handlers APIs
    $files = FileUtil::getFiles('modules/mediashare', false, true, 'php', 'f');
    foreach ($files as $file) {
        if (preg_match('/^pnmedia_([-a-zA-Z0-9_]+)api.php$/', $file, $matches)) {
            $handlerName = $matches[1];
            $handlerApi = "media_{$handlerName}";
            // Force load - it is used during pninit
            pnModAPILoad('mediashare', $handlerApi, true);
            if (!($handler = pnModAPIFunc('mediashare', $handlerApi, 'buildHandler'))) {
                return false;
            }
            $fileTypes = $handler->getMediaTypes();
            foreach ($fileTypes as $fileType) {
                $fileType['handler'] = $handlerName;
                $fileType['title'] = $handler->getTitle();
                if (!pnModAPIFunc('mediashare', 'mediahandler', 'addMediaHandler', $fileType)) {
                    return false;
                }
            }
        }
    }
    return true;
}
Example #2
0
function mediashare_sourcesapi_scanSources()
{
    // Check access
    if (!SecurityUtil::checkPermission('mediashare::', '::', ACCESS_ADMIN)) {
        return LogUtil::registerPermissionError();
    }
    $dom = ZLanguage::getModuleDomain('mediashare');
    // Clear existing sources table
    if (!DBUtil::truncateTable('mediashare_sources')) {
        return LogUtil::registerError(__f('Error in %1$s: %2$s.', array('sourcesapi.scanSources', __f("Could not clear the '%s' table.", 'sources', $dom)), $dom));
    }
    // Scan for sources APIs
    $files = FileUtil::getFiles('modules/mediashare', false, true, 'php', 'f');
    foreach ($files as $file) {
        if (preg_match('/^pnsource_([-a-zA-Z0-9_]+)api.php$/', $file, $matches)) {
            $sourceName = $matches[1];
            $sourceApi = "source_{$sourceName}";
            // Force load - it is used during pninit
            pnModAPILoad('mediashare', $sourceApi, true);
            if (!($title = pnModAPIFunc('mediashare', $sourceApi, 'getTitle'))) {
                return false;
            }
            if (!pnModAPIFunc('mediashare', 'sources', 'addSource', array('title' => $title, 'name' => $sourceName))) {
                return false;
            }
        }
    }
    return true;
}
Example #3
0
 /**
  * Purge IDS Log.
  *
  * @param none
  *
  * @return bool true if successful, false otherwise.
  */
 public function purgeidslog($args)
 {
     if (!SecurityUtil::checkPermission('SecurityCenter::', '::', ACCESS_DELETE)) {
         return false;
     }
     if (!DBUtil::truncateTable('sc_intrusion')) {
         return false;
     }
     return true;
 }
Example #4
0
 public function upgrade_MigrateLanguageCodes()
 {
     $objArray = DBUtil::selectObjectArray('categories_category');
     DBUtil::truncateTable('categories_category');
     $newObjArray = array();
     foreach ($objArray as $category) {
         // translate display_name l3 -> l2
         $data = unserialize($category['display_name']);
         if (is_array($data)) {
             $array = array();
             foreach ($data as $l3 => $v) {
                 $l2 = ZLanguage::translateLegacyCode($l3);
                 if ($l2) {
                     $array[$l2] = $v;
                 }
             }
             $category['display_name'] = serialize($array);
         }
         // translate display_desc l3 -> l2
         $data = unserialize($category['display_desc']);
         if (is_array($data)) {
             $array = array();
             foreach ($data as $l3 => $v) {
                 $l2 = ZLanguage::translateLegacyCode($l3);
                 if ($l2) {
                     $array[$l2] = $v;
                 }
             }
             $category['display_desc'] = serialize($array);
         }
         // commit
         DBUtil::insertObject($category, 'categories_category', 'id', true);
     }
     return;
 }
Example #5
0
 public function resetPermissions()
 {
     // Delete all current permission entries.
     if (!DBUtil::truncateTable('group_perms')) {
         $this->setError(__('Error! Permission not deleted'));
         return false;
     }
     // Array of permission objects to insert.
     $perms = array();
     $perms[] = array('pid' => 1, 'gid' => 2, 'sequence' => 1, 'realm' => 0, 'component' => '.*', 'instance' => '.*', 'level' => 800, 'bond' => 0);
     $perms[] = array('pid' => 2, 'gid' => -1, 'sequence' => 2, 'realm' => 0, 'component' => 'ExtendedMenublock::', 'instance' => '1:2:', 'level' => 0, 'bond' => 0);
     $perms[] = array('pid' => 3, 'gid' => 1, 'sequence' => 3, 'realm' => 0, 'component' => '.*', 'instance' => '.*', 'level' => 300, 'bond' => 0);
     $perms[] = array('pid' => 4, 'gid' => 0, 'sequence' => 4, 'realm' => 0, 'component' => 'ExtendedMenublock::', 'instance' => '1:(1|3):', 'level' => 0, 'bond' => 0);
     $perms[] = array('pid' => 5, 'gid' => 0, 'sequence' => 5, 'realm' => 0, 'component' => '.*', 'instance' => '.*', 'level' => 200, 'bond' => 0);
     // Insert default permissions or fail.
     if (!DBUtil::insertObjectArray($perms, 'group_perms', 'pid')) {
         $this->setError(__('Error inserting permission'));
         return false;
     }
     // Success.
     return true;
 }
Example #6
0
 /**
  * Add default block data for new installs
  * This is called after a complete pn installation since the blocks
  * need to be populated with module id's which are only available
  * once the install has been completed
  */
 public function defaultdata()
 {
     // create the default block positions - left, right and center for the traditional 3 column layout
     ModUtil::loadApi('Blocks', 'admin', true);
     // sanity check - truncate existing tables to ensure a clean blocks setup
     DBUtil::truncateTable('blocks');
     DBUtil::truncateTable('block_positions');
     DBUtil::truncateTable('block_placements');
     $left = ModUtil::apiFunc('Blocks', 'admin', 'createposition', array('name' => 'left', 'description' => $this->__('Left blocks')));
     $right = ModUtil::apiFunc('Blocks', 'admin', 'createposition', array('name' => 'right', 'description' => $this->__('Right blocks')));
     $center = ModUtil::apiFunc('Blocks', 'admin', 'createposition', array('name' => 'center', 'description' => $this->__('Center blocks')));
     $search = ModUtil::apiFunc('Blocks', 'admin', 'createposition', array('name' => 'search', 'description' => $this->__('Search block')));
     $header = ModUtil::apiFunc('Blocks', 'admin', 'createposition', array('name' => 'header', 'description' => $this->__('Header block')));
     $footer = ModUtil::apiFunc('Blocks', 'admin', 'createposition', array('name' => 'footer', 'description' => $this->__('Footer block')));
     $topnav = ModUtil::apiFunc('Blocks', 'admin', 'createposition', array('name' => 'topnav', 'description' => $this->__('Top navigation block')));
     $bottomnav = ModUtil::apiFunc('Blocks', 'admin', 'createposition', array('name' => 'bottomnav', 'description' => $this->__('Bottom navigation block')));
     // define an array of the default blocks
     $blocks = array();
     // build the menu content
     $languages = ZLanguage::getInstalledLanguages();
     $saveLanguage = ZLanguage::getLanguageCode();
     $menucontent = array();
     $topnavcontent = array();
     foreach ($languages as $lang) {
         ZLanguage::setLocale($lang);
         ZLanguage::bindCoreDomain();
         $menucontent['displaymodules'] = '0';
         $menucontent['stylesheet'] = 'extmenu.css';
         $menucontent['template'] = 'blocks_block_extmenu.tpl';
         $menucontent['blocktitles'][$lang] = $this->__('Main menu');
         // insert the links
         $menucontent['links'][$lang][] = array('name' => $this->__('Home'), 'url' => '{homepage}', 'title' => $this->__("Go to the home page"), 'level' => 0, 'parentid' => null, 'image' => '', 'active' => '1');
         $menucontent['links'][$lang][] = array('name' => $this->__('Administration'), 'url' => '{Admin:admin:adminpanel}', 'title' => $this->__('Go to the site administration'), 'level' => 0, 'parentid' => null, 'image' => '', 'active' => '1');
         $menucontent['links'][$lang][] = array('name' => $this->__('My Account'), 'url' => '{Users}', 'title' => $this->__('Go to your account panel'), 'level' => 0, 'parentid' => null, 'image' => '', 'active' => '1');
         $menucontent['links'][$lang][] = array('name' => $this->__('Log out'), 'url' => '{Users:user:logout}', 'title' => $this->__('Log out of this site'), 'level' => 0, 'parentid' => null, 'image' => '', 'active' => '1');
         $menucontent['links'][$lang][] = array('name' => $this->__('Site search'), 'url' => '{Search}', 'title' => $this->__('Search this site'), 'level' => 0, 'parentid' => null, 'image' => '', 'active' => '1');
         $topnavcontent['displaymodules'] = '0';
         $topnavcontent['stylesheet'] = 'extmenu.css';
         $topnavcontent['template'] = 'blocks_block_extmenu_topnav.tpl';
         $topnavcontent['blocktitles'][$lang] = $this->__('Top navigation');
         // insert the links
         $topnavcontent['links'][$lang][] = array('name' => $this->__('Home'), 'url' => '{homepage}', 'title' => $this->__("Go to the site's home page"), 'level' => 0, 'parentid' => null, 'image' => '', 'active' => '1');
         $topnavcontent['links'][$lang][] = array('name' => $this->__('My Account'), 'url' => '{Users}', 'title' => $this->__('Go to your account panel'), 'level' => 0, 'parentid' => null, 'image' => '', 'active' => '1');
         $topnavcontent['links'][$lang][] = array('name' => $this->__('Site search'), 'url' => '{Search}', 'title' => $this->__('Search this site'), 'level' => 0, 'parentid' => null, 'image' => '', 'active' => '1');
     }
     ZLanguage::setLocale($saveLanguage);
     $menucontent = serialize($menucontent);
     $topnavcontent = serialize($topnavcontent);
     $searchcontent = array('displaySearchBtn' => 1, 'active' => array('Users' => 1));
     $searchcontent = serialize($searchcontent);
     $hellomessage = $this->__('<p><a href="http://zikula.org/">Zikula</a> is a content management system (CMS) and application framework. It is secure and stable, and is a good choice for sites with a large volume of traffic.</p><p>With Zikula:</p><ul><li>you can customise all aspects of the site\'s appearance through themes, with support for CSS style sheets, JavaScript, Flash and all other modern web development technologies;</li><li>you can mark content as being suitable for either a single language or for all languages, and can control all aspects of localisation and internationalisation of your site;</li><li>you can be sure that your pages will display properly in all browsers, thanks to Zikula\'s full compliance with W3C HTML standards;</li><li>you get a standard application-programming interface (API) that lets you easily augment your site\'s functionality through modules, blocks and other extensions;</li><li>you can get help and support from the Zikula community of webmasters and developers at <a href="http://www.zikula.org">zikula.org</a>.</li></ul><p>Enjoy using Zikula!</p><p><strong>The Zikula team</strong></p><p><em>Note: Zikula is Free Open Source Software (FOSS) licensed under the GNU General Public License.</em></p>');
     $blocks[] = array('bkey' => 'Extmenu', 'collapsable' => 1, 'defaultstate' => 1, 'language' => '', 'mid' => ModUtil::getIdFromName('Blocks'), 'title' => $this->__('Main menu'), 'description' => $this->__('Main menu'), 'content' => $menucontent, 'positions' => array($left));
     $blocks[] = array('bkey' => 'Search', 'collapsable' => 1, 'defaultstate' => 1, 'language' => '', 'mid' => ModUtil::getIdFromName('Search'), 'title' => $this->__('Search box'), 'description' => $this->__('Search block'), 'content' => $searchcontent, 'positions' => array($search));
     $blocks[] = array('bkey' => 'Html', 'collapsable' => 1, 'defaultstate' => 1, 'language' => '', 'mid' => ModUtil::getIdFromName('Blocks'), 'title' => $this->__("This site is powered by Zikula!"), 'description' => $this->__('HTML block'), 'content' => $hellomessage, 'positions' => array($center));
     $blocks[] = array('bkey' => 'Login', 'collapsable' => 1, 'defaultstate' => 1, 'language' => '', 'mid' => ModUtil::getIdFromName('Users'), 'title' => $this->__('User log-in'), 'description' => $this->__('Login block'), 'positions' => array($right));
     //$blocks[] = array('bkey' => 'Online', 'collapsable' => 1, 'defaultstate' => 1, 'language' => '', 'mid' => ModUtil::getIdFromName('Users'), 'title' => $this->__('Who\'s on-line'), 'description' => $this->__('Online block'), 'positions' => array($right));
     $blocks[] = array('bkey' => 'Extmenu', 'collapsable' => 1, 'defaultstate' => 1, 'language' => '', 'mid' => ModUtil::getIdFromName('Blocks'), 'title' => $this->__('Top navigation'), 'description' => $this->__('Theme navigation'), 'content' => $topnavcontent, 'positions' => array($topnav));
     // create each block and then update the block
     // the create creates the initial block record, the update sets the block placement
     foreach ($blocks as $position => $block) {
         $block['bid'] = ModUtil::apiFunc('Blocks', 'admin', 'create', $block);
         ModUtil::apiFunc('Blocks', 'admin', 'update', $block);
     }
     return;
 }
Example #7
0
 /**
  * Regenerate modules list.
  *
  * @param array $args All parameters passed to this function.
  *                      array $args['filemodules'] An array of modules in the filesystem, as would be returned by
  *                                                  {@link getfilemodules()}; optional, defaults to the results of
  *                                                  $this->getfilemodules().
  *
  * @return boolean True on success, false on failure.
  */
 public function regenerate($args)
 {
     // Security check
     if (!System::isInstalling()) {
         if (!SecurityUtil::checkPermission('Extensions::', '::', ACCESS_ADMIN)) {
             return LogUtil::registerPermissionError();
         }
     }
     // Argument check
     if (!isset($args['filemodules']) || !is_array($args['filemodules'])) {
         return LogUtil::registerArgsError();
     }
     // default action
     $filemodules = $args['filemodules'];
     $defaults = isset($args['defaults']) ? $args['defaults'] : false;
     // Get all modules in DB
     $dbmodules = DBUtil::selectObjectArray('modules', '', '', -1, -1, 'name');
     if (!$dbmodules) {
         return LogUtil::registerError($this->__('Error! Could not load data.'));
     }
     // build a list of found modules and dependencies
     $module_names = array();
     $moddependencies = array();
     foreach ($filemodules as $modinfo) {
         $module_names[] = $modinfo['name'];
         if (isset($modinfo['dependencies']) && !empty($modinfo['dependencies'])) {
             $moddependencies[$modinfo['name']] = unserialize($modinfo['dependencies']);
         }
     }
     // see if any modules have changed name since last generation
     foreach ($filemodules as $name => $modinfo) {
         if (isset($modinfo['oldnames']) || !empty($modinfo['oldnames'])) {
             $tables = DBUtil::getTables();
             foreach ($dbmodules as $dbname => $dbmodinfo) {
                 if (in_array($dbmodinfo['name'], (array) $modinfo['oldnames'])) {
                     // migrate its modvars
                     $cols = $tables['module_vars_column'];
                     $save = array('modname' => $modinfo['name']);
                     DBUtil::updateObject($save, 'module_vars', "{$cols['modname']} = '{$dbname}'");
                     // rename the module register
                     $save = $dbmodules[$dbname];
                     $save['name'] = $modinfo['name'];
                     unset($dbmodules[$dbname]);
                     $dbname = $modinfo['name'];
                     $dbmodules[$dbname] = $save;
                     DBUtil::updateObject($dbmodules[$dbname], 'modules');
                     // rename hooks in the hooks table.
                     $hooksColumns = $tables['hooks_column'];
                     $hooks = DBUtil::selectObjectArray('hooks', "{$hooksColumns['smodule']} = '{$save['name']}'");
                     if ($hooks) {
                         foreach ($hooks as $hook) {
                             $hook['smodule'] = $dbmodinfo['name'];
                             DBUtil::updateObject($hook, 'hooks');
                         }
                     }
                     $hooks = DBUtil::selectObjectArray('hooks', "{$hooksColumns['tmodule']} = '{$save['name']}'");
                     if ($hooks) {
                         foreach ($hooks as $hook) {
                             $hook['tmodule'] = $dbmodinfo['name'];
                             DBUtil::updateObject($hook, 'hooks');
                         }
                     }
                     DBUtil::deleteObjectByID('hooks', $modinfo['name'], 'tmodule');
                 }
             }
             unset($tables);
         }
         if (isset($dbmodules[$name]) && $dbmodules[$name]['state'] > 10) {
             $dbmodules[$name]['state'] = $dbmodules[$name]['state'] - 20;
             $this->setState(array('id' => $dbmodules[$name]['id'], 'state' => $dbmodules[$name]['state']));
         }
         if (isset($dbmodules[$name]['id'])) {
             $modinfo['id'] = $dbmodules[$name]['id'];
             if ($dbmodules[$name]['state'] != ModUtil::STATE_UNINITIALISED && $dbmodules[$name]['state'] != ModUtil::STATE_INVALID) {
                 unset($modinfo['version']);
             }
             if (!$defaults) {
                 unset($modinfo['displayname']);
                 unset($modinfo['description']);
                 unset($modinfo['url']);
             }
             DBUtil::updateObject($modinfo, 'modules');
         }
         // check core version is compatible with current
         $minok = 0;
         $maxok = 0;
         // strip any -dev, -rcN etc from version number
         $coreVersion = preg_replace('#(\\d+\\.\\d+\\.\\d+).*#', '$1', Zikula_Core::VERSION_NUM);
         if (!empty($filemodules[$name]['core_min'])) {
             $minok = version_compare($coreVersion, $filemodules[$name]['core_min']);
         }
         if (!empty($filemodules[$name]['core_max'])) {
             $maxok = version_compare($filemodules[$name]['core_max'], $coreVersion);
         }
         if ($minok == -1 || $maxok == -1) {
             $dbmodules[$name]['state'] = $dbmodules[$name]['state'] + 20;
             $this->setState(array('id' => $dbmodules[$name]['id'], 'state' => $dbmodules[$name]['state']));
         }
         if (isset($dbmodules[$name]['state'])) {
             $filemodules[$name]['state'] = $dbmodules[$name]['state'];
         }
     }
     // See if we have lost any modules since last generation
     foreach ($dbmodules as $name => $modinfo) {
         if (!in_array($name, $module_names)) {
             $result = DBUtil::selectObjectByID('modules', $name, 'name');
             if ($result === false) {
                 return LogUtil::registerError($this->__('Error! Could not load data.'));
             }
             if (empty($result)) {
                 die($this->__('Error! Could not retrieve module ID.'));
             }
             if ($dbmodules[$name]['state'] == ModUtil::STATE_INVALID) {
                 // module was invalid and now it was removed, delete it
                 $this->remove(array('id' => $dbmodules[$name]['id']));
             } elseif ($dbmodules[$name]['state'] == ModUtil::STATE_UNINITIALISED) {
                 // module was uninitialised and subsequently removed, delete it
                 $this->remove(array('id' => $dbmodules[$name]['id']));
             } else {
                 // Set state of module to 'missing'
                 $this->setState(array('id' => $result['id'], 'state' => ModUtil::STATE_MISSING));
             }
             unset($dbmodules[$name]);
         }
     }
     // See if we have gained any modules since last generation,
     // or if any current modules have been upgraded
     foreach ($filemodules as $name => $modinfo) {
         if (empty($dbmodules[$name])) {
             // New module
             // RNG: set state to invalid if we can't determine an ID
             $modinfo['state'] = ModUtil::STATE_UNINITIALISED;
             if (!$modinfo['version']) {
                 $modinfo['state'] = ModUtil::STATE_INVALID;
             }
             if ($this->serviceManager['multisites.enabled'] == 1) {
                 // only the main site can regenerate the modules list
                 if ($this->serviceManager['multisites.mainsiteurl'] == FormUtil::getPassedValue('sitedns', null, 'GET') && $this->serviceManager['multisites.based_on_domains'] == 0 || $this->serviceManager['multisites.mainsiteurl'] == $_SERVER['HTTP_HOST'] && $this->serviceManager['multisites.based_on_domains'] == 1) {
                     DBUtil::insertObject($modinfo, 'modules');
                 }
             } else {
                 DBUtil::insertObject($modinfo, 'modules');
             }
         } else {
             // module is in the db already
             if ($dbmodules[$name]['state'] == ModUtil::STATE_MISSING) {
                 // module was lost, now it is here again
                 $this->setState(array('id' => $dbmodules[$name]['id'], 'state' => ModUtil::STATE_INACTIVE));
             } elseif ($dbmodules[$name]['state'] == ModUtil::STATE_INVALID && $modinfo['version']) {
                 // module was invalid, now it is valid
                 $modinfo = array_merge($modinfo, array('id' => $dbmodules[$name]['id'], 'state' => ModUtil::STATE_UNINITIALISED));
                 DBUtil::updateObject($modinfo, 'modules');
             }
             if ($dbmodules[$name]['version'] != $modinfo['version']) {
                 if ($dbmodules[$name]['state'] != ModUtil::STATE_UNINITIALISED && $dbmodules[$name]['state'] != ModUtil::STATE_INVALID) {
                     $this->setState(array('id' => $dbmodules[$name]['id'], 'state' => ModUtil::STATE_UPGRADED));
                 }
             }
         }
     }
     // now clear re-load the dependencies table with all current dependencies
     DBUtil::truncateTable('module_deps');
     // loop round dependences adding the module id - we do this now rather than
     // earlier since we won't have the id's for new modules at that stage
     $dependencies = array();
     ModUtil::flushCache();
     foreach ($moddependencies as $modname => $moddependency) {
         $modid = ModUtil::getIdFromName($modname);
         // each module may have multiple dependencies
         foreach ($moddependency as $dependency) {
             $dependency['modid'] = $modid;
             $dependencies[] = $dependency;
         }
     }
     DBUtil::insertObjectArray($dependencies, 'module_deps');
     return true;
 }