wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.InternalLink.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: class.InternalLink.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/lib/persistence/class.PersistenceFacade.php");
20 
21 /**
22  * @class InternalLink
23  * @ingroup Presentation
24  * @brief InternalLink contains static methods for handling internal application links.
25  * These links are useful in an scenario, where an object represents a page and
26  * several subobjects represent page elements.
27  *
28  * @author ingo herwig <ingo@wemove.com>
29  */
31 {
32  /**
33  * Make an internal link to an object
34  * @param oid The id of the object to link to
35  * @return The link
36  */
37  function makeLink($oid)
38  {
39  return "javascript:doDisplay('".$oid."'); submitAction('')";
40  }
41  /**
42  * Make an internal link to an object
43  * @param oid The object id of the object to link to
44  * @param anchorOID The object id of the subobject to link to
45  * @param anchorName The name inside the subobject to link to (null, if the object itself should be linked), [default: null]
46  * @return The link
47  */
48  function makeAnchorLink($oid, $anchorOID, $anchorName=null)
49  {
50  $str = "javascript:doDisplay('".$oid."'); setVariable('anchor', '".$anchorOID;
51  if ($anchorName != null)
52  $str .= "#".$anchorName;
53  $str .= "'); submitAction('')";
54  return $str;
55  }
56  /**
57  * Test if a link is an internal link
58  * @param link The link to test
59  * @return True/False wether the link is an internal link or not
60  */
61  function isLink($link)
62  {
63  return strpos($link, "javascript:doDisplay") === 0;
64  }
65  /**
66  * Get the oid of the referenced object
67  * @param link The link to process
68  * @return The oid or null if no valid oid is referenced
69  */
70  function getReferencedOID($link)
71  {
72  preg_match_all("/.*?[\']([A-Za-z0-9]+:[0-9]+)[\'].*?/", $link, $matches);
73  if (sizeof($matches) > 0)
74  {
75  $oid = $matches[1][0];
77  return $oid;
78  }
79  return null;
80  }
81  /**
82  * Get the oid of the referenced subobject if any
83  * @param link The link to process
84  * @return The oid or null if no anchor is defined
85  */
86  function getAnchorOID($link)
87  {
88  preg_match_all("/.*?[\']([A-Za-z0-9]+:[0-9]+)[\'].*?/", $link, $matches);
89  if (sizeof($matches) > 0 && sizeof($matches[1]) > 0)
90  {
91  $oid = $matches[1][1];
93  return $oid;
94  }
95  return null;
96  }
97  /**
98  * Get the name of the anchor inside the referenced subobject if any
99  * @param link The link to process
100  * @return The name or null if no anchor name is defined
101  */
102  function getAnchorName($link)
103  {
104  preg_match_all("/.*?[\'][A-Za-z0-9]+:[0-9]+#(.+?)[\'].*?/", $link, $matches);
105  if (sizeof($matches) > 0 && sizeof($matches[1]) > 0)
106  {
107  $name = $matches[1][1];
108  return $name;
109  }
110  return null;
111  }
112 }
113 ?>