/**
  * This function is to support saving bucket config changes
  * via Ajax
  */
 protected function handleAjax()
 {
     $data['success'] = 0;
     $framework = new FrameworkController();
     $site = $framework->getSite();
     if ($GLOBALS['BAC_PAGE_PERMISSIONS']->checkAction('editBucketProperties') > 0) {
         if (isset($this->post['pageurl']) && isset($this->post['propertiesBucketId'])) {
             if (!empty($this->post['pageurl']) && $site->hasBucket($this->post['propertiesBucketId'])) {
                 $bucket = $site->getBucket($this->post['propertiesBucketId']);
                 $bucket->setLiveUrl($this->post['pageurl']);
                 $data['success'] = $bucket->writeConfig();
                 $data['liveUrl'] = $bucket->getLiveUrl();
                 $data['bucketId'] = $bucket->getBucketId();
             }
         }
     } else {
         $data['success'] = 0;
     }
     if ($GLOBALS['BAC_PAGE_PERMISSIONS']->checkAction('createBlock') > 0) {
         if (isset($this->post['newblockid']) && isset($this->post['addBlockBucketId'])) {
             if (!empty($this->post['newblockid']) && $site->hasBucket($this->post['addBlockBucketId'])) {
                 $bucket = $site->getBucket($this->post['addBlockBucketId']);
                 $newblockConfig = array("type" => BlockTypes::Text, "blockid" => $this->post['newblockid'], "bucketid" => $bucket->getBucketId());
                 $factory = new BlockFactory();
                 $newblock = $factory->build($newblockConfig);
                 $data['success'] = $bucket->addBlock($newblock);
             }
         }
     } else {
         $data['success'] = 0;
     }
     if ($GLOBALS['BAC_PAGE_PERMISSIONS']->checkAction('deleteBlock') > 0) {
         if (isset($this->post['deleteBlock']) && isset($this->post['deleteBlockBlockId']) && isset($this->post['deleteBlockBucketId'])) {
             if (!empty($this->post['deleteBlockBlockId']) && $site->hasBucket($this->post['deleteBlockBucketId'])) {
                 $bucket = $site->getBucket($this->post['deleteBlockBucketId']);
                 if ($bucket->hasBlock($this->post['deleteBlockBlockId'])) {
                     if ($bucket->removeBlock($this->post['deleteBlockBlockId'])) {
                         $data['success'] = 1;
                     } else {
                         $data['success'] = 0;
                     }
                 }
             }
         }
     } else {
         $data['success'] = 0;
     }
     $ret['ajax'] = true;
     $ret['data'] = $data;
     return $ret;
 }
    /**
     * @return eZINI
     */
    static public function iniMerck()
    {
        if(is_null(self::$_iniMerck))
            self::$_iniMerck = eZINI::instance('merck.ini');

        return self::$_iniMerck;
    }
Esempio n. 3
0
function render_result($data)
{
    if ($data !== null) {
        if (is_array($data)) {
            if (isset($data[Block::MARKER_KEY])) {
                $block_name = $data[Block::MARKER_KEY];
                $block = BlockFactory::create($block_name, $data);
                return $block->__toString();
            }
            if (isset($data[Layout::MARKER_KEY])) {
                $layout_name = $data[Layout::MARKER_KEY];
                //il layout ha bisogno della vista dell'albero ma forse la posso passare anche così
                $layout = LayoutFactory::create($layout_name, $data);
                return $layout->__toString();
            }
            $collected = "";
            foreach ($data as $k => $v) {
                $collected .= render_result($v);
            }
            return $collected;
        }
        //nel caso in cui non sia un blocco e non sia un layout stampo quello che trovo :)
        return $data;
    }
}
Esempio n. 4
0
 function testFindBlocks()
 {
     BlockFactory::clear();
     $this->assertFalse(BlockFactory::can_create("documenti/visualizza"), "Può creare il blocco documenti/visualizza");
     $this->assertFalse(BlockFactory::can_create("documenti/altro"), "Può creare il blocco documenti/visualizza");
     BlockFactory::add_directory("/" . FRAMEWORK_CORE_PATH . "tests/base/blocks/");
     $this->assertTrue(BlockFactory::can_create("documenti/visualizza"), "Non puo' creare il blocco documenti/visualizza");
     $this->assertFalse(BlockFactory::can_create("documenti/altro"), "Può creare il blocco documenti/altro");
 }
Esempio n. 5
0
 public static function create($name, $data)
 {
     $loader = LayoutLoader::instance();
     if ($loader->has_found_layout($name)) {
         $layout_path = $loader->get_layout_path_by_name($name);
         $layout = new Layout();
         $layout->__setup($layout_path, $name, new Tree($data));
         return $layout;
     } else {
         return BlockFactory::create("errors/layout_not_found", array("layout_name" => $name));
     }
 }
Esempio n. 6
0
 public static function create($name, $parent_context)
 {
     $loader = PageLoader::instance();
     if ($loader->has_found_page($name)) {
         $page_path = $loader->get_page_path_by_name($name);
         $page = new Page();
         $page->__setup($page_path, $name);
         self::$pages[$name] = $page;
     } else {
         $page = BlockFactory::create("errors/page_not_found", $parent_context);
     }
     //ritorno la pagina
     return $page;
 }
Esempio n. 7
0
<div style="max-width:60%; width:60%; border-color: black; border-style: solid; border-width: 1px;">
    <img src="/framework/core/immagini/simboli/blocco_non_trovato.png" alt="blocco non trovato" />
        Il blocco <?php 
echo $name;
?>
 non &egrave; stato trovato.
        <br />
        Percorsi di ricerca : <br />
        <ul>
        <?php 
foreach (BlockFactory::get_search_dirs() as $d) {
    ?>
        <li><?php 
    echo $d;
    ?>
</li>
        <?php 
}
?>
        </ul>
        
        Blocchi disponibili :
        <ul>
            <?php 
foreach (BlockFactory::get_available_blocks() as $bk) {
    echo "<li>{$bk}</li>";
}
?>
        </ul>
</div>
Esempio n. 8
0
<?php

BlockFactory::add_directory("/" . FRAMEWORK_CORE_PATH . "/blocks/");
BlockFactory::add_directory("/blocks/");
<?php

/* @type $Params string[] */

if ( in_array( 'register-with-facebook', $Params['Parameters'] ) || in_array( 'social-register-confirmation', $Params['Parameters'] ) )
{
    header('X-Frame-Options:');
}

$outputType = 'html';
$controller = BlockFactory::factory ( $Params, $outputType );

try
{
    $controller->buildResult ();

    $Result = $controller->getResult();
}
catch ( Exception $e )
{
    $Result         = $controller->getResult();
    $statusReason   = HttpTool::$statusReason[$Result['error_status']];

    header("{$_SERVER['SERVER_PROTOCOL']} {$Result['error_status']} {$statusReason}");
}

SessionTool::flush();

    /**
     * Fetches an application by its url
     * @param string $uri
     * @param string $outputType
     * @return ApplicationDefault
     */
    static public function fetchByUri( $uri, $outputType = 'html' )
    {
        // We keep $currentApplication to avoid loosing it during the process
        $currentApplication = ApplicationDefault::instance();
        $realServerURi      = $_SERVER['REQUEST_URI'];
        $uri                = trim($uri, '/ ');
        $uriparams          = explode('/', $uri);
        $applicationName    = $uriparams[0];

        $functions = array(
            'html'     => 'main_view',
            'json'     => 'json',
            'ajax'     => 'ajax'
        );

        array_unshift($uriparams, 'app_content');

        $_SERVER['REQUEST_URI'] = '/esibuild/'.$functions[$outputType].'/app_content/'.$uri;

        $params = array(
            self::paramBlockKey()               => 'app_content',
            'ModuleName'                        => 'esibuild',
            'FunctionName'                      => $functions[$outputType],
            self::paramCurrentApplicationKey()  => $applicationName,
            'Parameters'                        => $uriparams
        );

        $application            = BlockFactory::factory( $params, $outputType );
        $_SERVER['REQUEST_URI'] = $realServerURi;

        // We set $currentApplication again
        ApplicationDefault::setInstance($currentApplication);

        return $application;
    }
 protected function handlePost()
 {
     /**
      * This section updates the administration password to the user supplied value
      */
     $ret['message'] = 'Settings saved';
     $ret['settingsSaved'] = 'true';
     $passwordDefined = true;
     if ($this->adminExists()) {
         $firstTime = false;
         $ret['redirectToLogin'] = '******';
     } else {
         $firstTime = true;
         $ret['redirectToLogin'] = '******';
     }
     //HANDLE ADMIN ACCOUNT
     if (isset($this->post['adminPassword']) && !empty($this->post['adminPassword'])) {
         if (isset($this->post['adminPasswordConfirm']) && $this->post['adminPassword'] == $this->post['adminPasswordConfirm']) {
             $newpass = sha1($this->post['adminPassword']);
             $newuser = '******';
             $usertype = UserTypes::Admin;
             //Create default permissions
             $pagePermissions = array();
             $bucketsPermissions = new PagePermissions(array(PagePermissions::c_pagename => 'buckets', PagePermissions::c_actionPermissions => array('all' => ActionPermissions::Allowed)));
             $pagePermissions['buckets'] = $bucketsPermissions;
             $setupPermissions = new PagePermissions(array(PagePermissions::c_pagename => 'settings', PagePermissions::c_actionPermissions => array('all' => ActionPermissions::Allowed)));
             $pagePermissions['settings'] = $setupPermissions;
             //create new user
             $userCreated = $this->createUser($newuser, $newpass, $usertype, $pagePermissions);
             if (!$userCreated) {
                 $ret['message'] = "Settings could not be saved";
                 $ret['settingsSaved'] = 'false';
                 $ret['redirectToLogin'] = '******';
                 $passwordDefined = false;
             }
         } else {
             //return 'error, passwords don't match' message
             $ret['message'] = "Admin passwords do not match";
             $ret['settingsSaved'] = 'false';
             $ret['redirectToLogin'] = '******';
             $passwordDefined = false;
         }
     } else {
         //Error, user didn't define a password
         if ($firstTime) {
             $ret['message'] = "A password must be specified";
             $ret['settingsSaved'] = 'false';
             $ret['redirectToLogin'] = '******';
             $passwordDefined = false;
         }
     }
     //HANDLE AUTHOR ACCOUNT
     if (isset($this->post['authorPassword']) && !empty($this->post['authorPassword'])) {
         if (isset($this->post['authorPasswordConfirm']) && $this->post['authorPassword'] == $this->post['authorPasswordConfirm']) {
             $newpass = sha1($this->post['authorPassword']);
             $newuser = '******';
             $usertype = UserTypes::Author;
             //Create default permissions
             //TODO: Why are we resetting permissions on a password change?
             //This should only happen if it is a new user (i.e. the user doesn't
             //exist). Change this when permissions are modifiable.
             $pagePermissions = array();
             $bucketsPermissions = new PagePermissions(array(PagePermissions::c_pagename => 'buckets', PagePermissions::c_actionPermissions => array('createBucket' => ActionPermissions::Denied, 'deleteBucket' => ActionPermissions::Denied, 'createBlock' => ActionPermissions::Denied, 'deleteBlock' => ActionPermissions::Denied, 'createBlogBlock' => ActionPermissions::Allowed, 'deleteBlogBlock' => ActionPermissions::Allowed, 'editBlock' => ActionPermissions::Allowed)));
             $pagePermissions['buckets'] = $bucketsPermissions;
             $setupPermissions = new PagePermissions(array(PagePermissions::c_pagename => 'settings', PagePermissions::c_actionPermissions => array('createBucket' => ActionPermissions::Denied, 'deleteBucket' => ActionPermissions::Denied, 'createBlock' => ActionPermissions::Denied, 'deleteBlock' => ActionPermissions::Denied, 'changeAdminPassword' => ActionPermissions::Denied, 'changeAuthorPassword' => ActionPermissions::Allowed)));
             $pagePermissions['settings'] = $setupPermissions;
             //Create new user
             $userCreated = $this->createUser($newuser, $newpass, $usertype, $pagePermissions);
             if (!$userCreated) {
                 $ret['message'] = "Settings could not be saved";
                 $ret['settingsSaved'] = 'false';
                 $ret['redirectToLogin'] = '******';
                 $passwordDefined = false;
             }
         } else {
             //return 'error, passwords don't match' message
             $ret['message'] = "Author passwords do not match";
             $ret['settingsSaved'] = 'false';
             $ret['redirectToLogin'] = '******';
             $passwordDefined = false;
         }
     }
     /*
      * This section creates the directories and files for the buckets
      */
     if (isset($this->post['sitemap']) && $passwordDefined) {
         //Get the existing site for comparison
         $framework = new FrameworkController();
         $site = $framework->getSite();
         $bucketlist = $site->getAllBuckets();
         $blockarray = array();
         $bucketarray = array();
         //This loop marks every block and bucket for deletion
         foreach ($bucketlist as $bucket) {
             if ($bucket->hasBlocks()) {
                 $blocklist = $bucket->getAllBlocks();
                 foreach ($blocklist as $block) {
                     $blockarray[$bucket->getBucketId()][$block->getBlockId()] = false;
                 }
             }
             $bucketarray[$bucket->getBucketId()] = false;
         }
         //The string looks like:
         //page1:container1,container2,container3|page2:container1,container2,container3
         $sitemap_string = $this->post['sitemap'];
         $bucketsArray = explode("|", $sitemap_string);
         $bucketsdir = Constants::GET_PAGES_DIRECTORY();
         for ($i = 0; $i < count($bucketsArray); $i++) {
             if (strlen($bucketsArray[$i]) <= 1) {
                 continue;
             }
             //Get the bucket and block list from the bucket string
             $bucketstring = explode(":", $bucketsArray[$i]);
             $bucketname = $bucketstring[0];
             $blockstring = $bucketstring[1];
             $blockNameArray = explode(",", $blockstring);
             //If we have no bucket name, then there's nothing to
             //do here (no bucket page names)
             if ($bucketname == null || $bucketname == "") {
                 continue;
             }
             //If the directory exists, we don't want to overwrite it
             //This adds the page
             $bucketarray[$bucketname] = true;
             $result = $site->addBucket($bucketname);
             $blocktext = "";
             for ($j = 0; $j < count($blockNameArray); $j++) {
                 $blockname = $blockNameArray[$j];
                 //If the block name is blank do nothing (no blank bucket names)
                 if ($blockname == null || $blockname == "") {
                     continue;
                 }
                 //Don't delete this block!
                 if (isset($blockarray[$bucketname][$blockname])) {
                     $blockarray[$bucketname][$blockname] = true;
                 }
                 //TODO: this needs to be refactored, we aren't creating a new block every time, only loading
                 //blocks that exist.
                 $bucket = $site->getBucket($bucketname);
                 if (!$bucket->hasBlock($blockname)) {
                     $newblockConfig = array("type" => BlockTypes::Text, "blockid" => $blockname, "bucketid" => $bucketname);
                     $factory = new BlockFactory();
                     $newblock = $factory->build($newblockConfig);
                     $bucket->addBlock($newblock);
                 }
             }
         }
         //Now delete all the blocks that are still in the array as false
         foreach ($blockarray as $bucketname => $blocklist) {
             foreach ($blocklist as $blockname => $exists) {
                 if (!$exists) {
                     $currentbucket = $site->getBucket($bucketname);
                     $result = $currentbucket->removeBlock($blockname);
                 }
             }
         }
         //Now delete the bucket
         foreach ($bucketarray as $bucketname => $exists) {
             $path = $bucketsdir . "/" . $bucketname;
             if (!$exists) {
                 $deleted = $site->removeBucket($bucketname);
             }
         }
     } else {
         //No site map
     }
     return $ret;
 }