Пример #1
0
    /**
     * Writes $auditName with $auditAttributes as content
     * to file name that will be fetched from ini settings by auditNameSettings() for logging.
     *
     * @param string $auditName
     * @param array $auditAttributes
     * @return bool
     */
    static function writeAudit( $auditName, $auditAttributes = array() )
    {
        $enabled = eZAudit::isAuditEnabled();
        if ( !$enabled )
            return false;

        $auditNameSettings = eZAudit::auditNameSettings();

        if ( !isset( $auditNameSettings[$auditName] ) )
            return false;

        $ip = eZSys::clientIP();
        if ( !$ip )
            $ip = eZSys::serverVariable( 'HOSTNAME', true );

        $user = eZUser::currentUser();
        $userID = $user->attribute( 'contentobject_id' );
        $userLogin = $user->attribute( 'login' );

        $message = "[$ip] [$userLogin:$userID]\n";

        foreach ( array_keys( $auditAttributes ) as $attributeKey )
        {
            $attributeValue = $auditAttributes[$attributeKey];
            $message .= "$attributeKey: $attributeValue\n";
        }

        $logName = $auditNameSettings[$auditName]['file_name'];
        $dir = $auditNameSettings[$auditName]['dir'];
        eZLog::write( $message, $logName, $dir );

        return true;
    }
 /**
  * Unhide a subtree
  *
  * Unhide algorithm:
  * if ( parent node is visible )
  * {
  *     1) Mark root node as not hidden and visible.
  *     2) Recursively mark child nodes as visible (except for nodes previosly marked as hidden, and all their children).
  * }
  * else
  * {
  *     Mark root node as not hidden.
  * }
  *
  * Transaction unsafe. If you call several transaction unsafe methods you must enclose
  * the calls within a db transaction; thus within db->begin and db->commit.
  *
  * @param eZContentObjectTreeNode $node Root node of the subtree
  * @param bool $modifyRootNode Whether to modify the root node (true/false)
  */
 static function unhideSubTree(eZContentObjectTreeNode $node, $modifyRootNode = true)
 {
     $nodeID = $node->attribute('node_id');
     $nodePath = $node->attribute('path_string');
     $nodeInvisible = $node->attribute('is_invisible');
     $parentNode = $node->attribute('parent');
     if (!$parentNode instanceof eZContentObjectTreeNode) {
         eZDebug::writeError("Parent of Node #{$nodeID} doesn't exist or inaccesible.", __METHOD__);
         return;
     }
     $time = time();
     if (eZAudit::isAuditEnabled()) {
         // Set audit params.
         $objectID = $node->attribute('contentobject_id');
         $objectName = $node->attribute('name');
         eZAudit::writeAudit('content-hide', array('Node ID' => $nodeID, 'Object ID' => $objectID, 'Content Name' => $objectName, 'Time' => $time, 'Comment' => 'Node has been unhidden: eZContentObjectTreeNode::unhideSubTree()'));
     }
     $db = eZDB::instance();
     $db->begin();
     if (!$parentNode->attribute('is_invisible')) {
         // 1) Mark root node as not hidden and visible.
         if ($modifyRootNode) {
             $db->query("UPDATE ezcontentobject_tree SET is_invisible=0, is_hidden=0, modified_subnode={$time} WHERE node_id={$nodeID}");
         }
         // 2) Recursively mark child nodes as visible (except for nodes previosly marked as hidden, and all their children).
         // 2.1) $hiddenChildren = Fetch all hidden children for the root node
         $hiddenChildren = $db->arrayQuery("SELECT path_string FROM ezcontentobject_tree " . "WHERE node_id <> {$nodeID} AND is_hidden=1 AND path_string LIKE '{$nodePath}%'");
         $skipSubtreesString = '';
         foreach ($hiddenChildren as $i) {
             $skipSubtreesString .= " AND path_string NOT LIKE '" . $i['path_string'] . "%'";
         }
         // 2.2) Mark those children as visible which are not under nodes in $hiddenChildren
         $db->query("UPDATE ezcontentobject_tree SET is_invisible=0, modified_subnode={$time} WHERE path_string LIKE '{$nodePath}%' {$skipSubtreesString}");
     } else {
         // Mark root node as not hidden.
         if ($modifyRootNode) {
             $db->query("UPDATE ezcontentobject_tree SET is_hidden=0, modified_subnode={$time} WHERE node_id={$nodeID}");
         }
     }
     $node->updateAndStoreModified();
     $db->commit();
     eZContentObjectTreeNode::clearViewCacheForSubtree($node, $modifyRootNode);
 }
Пример #3
0
 function removeThis()
 {
     $ini = eZINI::instance();
     $object = $this->object();
     $nodeID = $this->attribute('node_id');
     if (eZAudit::isAuditEnabled()) {
         // Set audit params.
         $objectID = $object->attribute('id');
         $objectName = $object->attribute('name');
         eZAudit::writeAudit('content-delete', array('Node ID' => $nodeID, 'Object ID' => $objectID, 'Content Name' => $objectName, 'Comment' => 'Removed the current node: eZContentObjectTreeNode::removeNode()'));
     }
     $db = eZDB::instance();
     $db->begin();
     $nodePath = $this->attribute('path_string');
     $childrensPath = $nodePath;
     $pathString = " path_string like '{$childrensPath}%' ";
     $urlAlias = $this->attribute('url_alias');
     // Remove static cache
     if ($ini->variable('ContentSettings', 'StaticCache') == 'enabled') {
         $staticCache = new eZStaticCache();
         $staticCache->removeURL("/" . $urlAlias);
         $staticCache->generateAlwaysUpdatedCache();
         $parent = $this->fetchParent();
     }
     $db->query("DELETE FROM ezcontentobject_tree\n                            WHERE {$pathString} OR\n                            path_string = '{$nodePath}'");
     // Re-cache parent node
     if ($ini->variable('ContentSettings', 'StaticCache') == 'enabled') {
         if ($parent) {
             $staticCache->cacheURL("/" . $parent->urlAlias());
         }
     }
     // Clean up URL alias entries
     eZURLAliasML::removeByAction('eznode', $nodeID);
     // Clean up content cache
     eZContentCacheManager::clearContentCacheIfNeeded($this->attribute('contentobject_id'));
     // clean up user cache
     if (in_array($object->attribute('contentclass_id'), eZUser::contentClassIDs())) {
         eZUser::removeSessionData($object->attribute('id'));
         eZUser::purgeUserCacheByUserId($object->attribute('id'));
     }
     $parentNode = $this->attribute('parent');
     if (is_object($parentNode)) {
         eZContentCacheManager::clearContentCacheIfNeeded($parentNode->attribute('contentobject_id'));
         $parentNode->updateAndStoreModified();
     }
     // Clean up policies and limitations
     eZRole::cleanupByNode($this);
     // Clean up recent items
     eZContentBrowseRecent::removeRecentByNodeID($nodeID);
     // Clean up bookmarks
     eZContentBrowseBookmark::removeByNodeID($nodeID);
     // Clean up tip-a-friend counter
     eZTipafriendCounter::removeForNode($nodeID);
     // Clean up view counter
     eZViewCounter::removeCounter($nodeID);
     $db->commit();
 }