Example #1
0
/**
 * Add/edit albums
 */
function mediashare_editapi_addAlbum(&$args)
{
    $dom = ZLanguage::getModuleDomain('mediashare');
    // Check basic access (but don't do fine grained Mediashare access check)
    if (!SecurityUtil::checkPermission('mediashare::', '::', ACCESS_EDIT)) {
        return LogUtil::registerPermissionError();
    }
    // Set defaults
    // FIXME: what if not logged in - how about 'owner' ???
    if (!isset($args['ownerId'])) {
        $args['ownerId'] = pnUserGetVar('uid');
    }
    if (!isset($args['template']) || empty($args['template'])) {
        // Include null test
        $args['template'] = pnModGetVar('mediashare', 'defaultAlbumTemplate', 'Standard');
    }
    // Parse extapp URL and add extapp data
    if (!mediashare_editapi_extappLocateApp($args)) {
        return false;
    }
    Loader::loadClass('RandomUtil');
    $album = array('ownerId' => (int) $args['ownerId'], 'createdDate' => DateUtil::getDatetime(), 'title' => $args['title'], 'keywords' => $args['keywords'], 'summary' => $args['summary'], 'description' => $args['description'], 'template' => $args['template'], 'parentAlbumId' => (int) $args['parentAlbumId'], 'thumbnailSize' => (int) pnModGetVar('mediashare', 'thumbnailSize'), 'viewKey' => RandomUtil::getInteger(100000000, 999999999, true) * 10000 + RandomUtil::getInteger(1, 9999), 'extappURL' => $args['extappURL'], 'extappData' => $args['extappData']);
    $album = DBUtil::insertObject($album, 'mediashare_albums', 'id');
    if ($album === false) {
        return LogUtil::registerError(__f('Error in %1$s: %2$s.', array('editapi.addAlbum', 'Could not add the new album.'), $dom));
    }
    if (!pnModAPIFunc('mediashare', 'edit', 'updateNestedSetValues')) {
        return false;
    }
    if (!pnModAPIFunc('mediashare', 'edit', 'setDefaultAccess', array('albumId' => $album['id']))) {
        return false;
    }
    pnModCallHooks('item', 'create', "album-{$album['id']}", array('module' => 'mediashare', 'albumId' => $album['id']));
    if (!pnModAPIFunc('mediashare', 'edit', 'updateKeywords', array('itemId' => $album['id'], 'type' => 'album', 'keywords' => $args['keywords']))) {
        return false;
    }
    if (!pnModAPIFunc('mediashare', 'edit', 'fetchExternalImages', array('albumId' => $album['id']))) {
        return false;
    }
    return $album['id'];
}
Example #2
0
 /**
  * Create a system-generated password or password-like code, meeting the configured constraints for a password.
  *
  * @return string The generated (unhashed) password-like string.
  */
 public static function generatePassword()
 {
     $minLength = ModUtil::getVar('Users', 'minpass', 5);
     if (!is_numeric($minLength) || (int) $minLength != $minLength || $minLength < 5) {
         $minLength = 5;
     }
     $minLength = min($minLength, 25);
     $maxLength = min($minLength + 3, 25);
     return RandomUtil::getStringForPassword($minLength, $maxLength);
 }
Example #3
0
 /**
  * Hashes the data with a random salt value and returns a string containing the hash method, salt and hash.
  *
  * @param string $unhashedData         The data to be salted and hashed.
  * @param string $hashMethodName       Any value returned by hash_algo().
  * @param array  $hashMethodNameToCode An array indexed by algorithm names (from hash_algos()) used to encode the hashing algorithm
  *                                         name and include it on the salted hash string; optional, if not specified, then the
  *                                         algorithm name is included in the string returned (which could be considered less than secure!).
  * @param int    $saltLength    The number of random characters to use in the salt.
  * @param string $saltDelimeter The delimiter between the salt and the hash, must be a single character.
  *
  * @return string|bool The algorithm name (or code if $hashMethodNameToCode specified), salt and hashed data separated by the salt delimiter;
  *                      false if an error occured.
  */
 public static function getSaltedHash($unhashedData, $hashMethodName, array $hashMethodNameToCode = array(), $saltLength = 5, $saltDelimeter = self::SALT_DELIM)
 {
     $saltedHash = false;
     $saltStr = RandomUtil::getString($saltLength, $saltLength, false, true, true, true, true, true, false, array($saltDelimeter));
     return self::buildSaltedHash($unhashedData, $hashMethodName, $saltStr, $hashMethodNameToCode, $saltDelimeter);
 }
Example #4
0
 private function finalizeParameters()
 {
     \ModUtil::initCoreVars(true);
     // initialize the modvars array (includes ZConfig (System) vars)
     // Set the System Identifier as a unique string.
     if (!\System::getVar('system_identifier')) {
         \System::setVar('system_identifier', str_replace('.', '', uniqid(rand(1000000000, 9999999999), true)));
     }
     // store the recent version in a config var for later usage. This enables us to determine the version we are upgrading from
     \System::setVar('Version_Num', \Zikula_Core::VERSION_NUM);
     \System::setVar('language_i18n', \ZLanguage::getLanguageCode());
     // add new configuration parameters
     $params = $this->yamlManager->getParameters();
     unset($params['username'], $params['password']);
     if (!isset($params['secret']) || $params['secret'] == 'ThisTokenIsNotSoSecretChangeIt') {
         $params['secret'] = \RandomUtil::getRandomString(50);
     }
     if (!isset($params['url_secret'])) {
         $params['url_secret'] = \RandomUtil::getRandomString(10);
     }
     // Configure the Request Context
     // see http://symfony.com/doc/current/cookbook/console/sending_emails.html#configuring-the-request-context-globally
     $params['router.request_context.host'] = isset($params['router.request_context.host']) ? $params['router.request_context.host'] : $this->container->get('request')->getHost();
     $params['router.request_context.scheme'] = isset($params['router.request_context.scheme']) ? $params['router.request_context.scheme'] : 'http';
     $params['router.request_context.base_url'] = isset($params['router.request_context.base_url']) ? $params['router.request_context.base_url'] : $this->container->get('request')->getBasePath();
     $this->yamlManager->setParameters($params);
     return true;
 }
Example #5
0
    public function reinsertPage($args)
    {
        $pageData = $args['page'];

        if ($pageData['parentPageId'] > 0) {
            $sourcePageData = $this->getPage(array('id' => $pageData['parentPageId'], 'checkActive' => false, 'includeContent' => false));
            if ($sourcePageData === false) {
                $pageData['parentPageId'] = 0;
            }
        } else {
            $sourcePageData = null;
        }

        $pageData['language'] = ZLanguage::getLanguageCode();

        // what does this mean?
        if ($pageData['parentPageId'] > 0) {
            $pageData['position'] = $this->contentGetLastSubPagePosition($pageData['parentPageId']) + 1;
            $pageData['level'] = ($sourcePageData == null ? 0 : $sourcePageData['level'] + 1);
        } else {
            $pageData['position'] = $this->contentGetLastPagePosition($pageData['parentPageId']) + 1;
            $pageData['parentPageId'] = ($sourcePageData == null ? 0 : $sourcePageData['parentPageId']);
            $pageData['level'] = ($sourcePageData == null ? 0 : $sourcePageData['level']);
        }

        $ok = $this->isUniqueUrlnameByParentID(array('urlname' => $pageData['urlname'], 'parentId' => $pageData['parentPageId']));
        while (!$ok) {
            $pageData['urlname'] = DataUtil::formatPermalink(RandomUtil::getString(12, 12, false, true, true, false, true, false, true));
            $ok = $this->isUniqueUrlnameByParentID(array('urlname' => $pageData['urlname'], 'parentId' => $pageData['parentPageId']));
        }

        $pageData['setLeft'] = -2;
        $pageData['setRight'] = -1;

        $this->setInitialPageState($pageData);

        $newPage = DBUtil::insertObject($pageData, 'content_page', true);
        Content_Util::contentMainEditExpandSet($pageData['parentPageId'], true);

        $ok = $this->insertPage(array('pageId' => $pageData['id'], 'position' => $pageData['position'], 'parentPageId' => $pageData['parentPageId']));
        if ($ok === false) {
            return false;
        }

        Content_Util::clearCache();
        return array('id' => $pageData['id'], 'urlname' => $pageData['urlname']);
    }
Example #6
0
 private function finalizeParameters()
 {
     \ModUtil::initCoreVars(true);
     // initialize the modvars array (includes ZConfig (System) vars)
     $params = $this->decodeParameters($this->yamlManager->getParameters());
     \System::setVar('language_i18n', $params['locale']);
     // Set the System Identifier as a unique string.
     \System::setVar('system_identifier', str_replace('.', '', uniqid(rand(1000000000, 9999999999.0), true)));
     // add admin email as site email
     \System::setVar('adminmail', $params['email']);
     // regenerate the theme list
     \Zikula\Module\ThemeModule\Util::regenerate();
     // add remaining parameters and remove unneeded ones
     unset($params['username'], $params['password'], $params['email'], $params['dbtabletype']);
     $params['datadir'] = !empty($params['datadir']) ? $params['datadir'] : 'userdir';
     $params['secret'] = \RandomUtil::getRandomString(50);
     $params['url_secret'] = \RandomUtil::getRandomString(10);
     // Configure the Request Context
     // see http://symfony.com/doc/current/cookbook/console/sending_emails.html#configuring-the-request-context-globally
     $params['router.request_context.host'] = isset($params['router.request_context.host']) ? $params['router.request_context.host'] : $this->container->get('request')->getHost();
     $params['router.request_context.scheme'] = isset($params['router.request_context.scheme']) ? $params['router.request_context.scheme'] : 'http';
     $params['router.request_context.base_url'] = isset($params['router.request_context.base_url']) ? $params['router.request_context.base_url'] : $this->container->get('request')->getBasePath();
     $this->yamlManager->setParameters($params);
     // clear the cache
     $this->container->get('zikula.cache_clearer')->clear('symfony.config');
     return true;
 }