├── .gitattributes ├── .gitignore ├── Cpviz.class.php ├── LICENSE ├── Makefile ├── README.md ├── assets ├── css │ └── cpviz.css └── js │ ├── full.render.js │ ├── html2canvas.min.js │ ├── panzoom.min.js │ └── viz.min.js ├── functions.inc.php ├── graphviz ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTORS.md ├── LICENCE ├── README.md ├── composer.json ├── phpunit.xml.dist ├── samples │ ├── 00-readme.php │ ├── 01-basic.php │ └── 02-table.php ├── src │ └── Alom │ │ └── Graphviz │ │ ├── Assign.php │ │ ├── AttributeBag.php │ │ ├── AttributeSet.php │ │ ├── BaseInstruction.php │ │ ├── Digraph.php │ │ ├── DirectedEdge.php │ │ ├── Edge.php │ │ ├── Graph.php │ │ ├── InstructionInterface.php │ │ ├── Node.php │ │ ├── RawText.php │ │ └── Subgraph.php └── tests │ └── Alom │ └── Graphviz │ └── Tests │ ├── AssignTest.php │ ├── AttributeBagTest.php │ ├── AttributeSetTest.php │ ├── DigraphTest.php │ ├── DirectedEdgeTest.php │ ├── NodeTest.php │ └── SubgraphTest.php ├── i18n └── extensionsettings.pot ├── install.php ├── module.sig ├── module.xml ├── page.cpviz.php └── views ├── options.php └── rnav.php /.gitattributes: -------------------------------------------------------------------------------- 1 | amp_conf/htdocs/admin/assets/js/pbxlib.js merge=ours 2 | module.xml merge=ours 3 | *.po merge=merge-gettext-po 4 | *.pot merge=merge-gettext-po 5 | *.mo merge=ours 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | notes.txt 2 | -------------------------------------------------------------------------------- /Cpviz.class.php: -------------------------------------------------------------------------------- 1 | freepbx = $freepbx; 15 | $this->db = $this->freepbx->Database; 16 | } 17 | 18 | public function install() { 19 | // Required by BMO, but can remain empty 20 | } 21 | 22 | public function uninstall() { 23 | // Required by BMO, but can remain empty 24 | } 25 | 26 | public function getOptions() { 27 | $sql = "SELECT panzoom, horizontal, datetime, destination, scale, dynmembers FROM cpviz"; 28 | $sth = $this->db->prepare($sql); 29 | $sth->execute(); 30 | return $sth->fetchAll(\PDO::FETCH_ASSOC); 31 | } 32 | 33 | public function editCpviz($panzoom, $horizontal, $datetime, $destination, $scale, $dynmembers) { 34 | $sql = "UPDATE cpviz SET 35 | `panzoom` = :panzoom, 36 | `horizontal` = :horizontal, 37 | `datetime` = :datetime, 38 | `destination` = :destination, 39 | `scale` = :scale, 40 | `dynmembers` = :dynmembers 41 | WHERE `id` = 1"; 42 | $insert = [ 43 | ':panzoom' => $panzoom, 44 | ':horizontal' => $horizontal, 45 | ':datetime' => $datetime, 46 | ':destination' => $destination, 47 | ':scale' => $scale, 48 | ':dynmembers' => $dynmembers 49 | ]; 50 | $stmt = $this->db->prepare($sql); 51 | return $stmt->execute($insert); 52 | } 53 | 54 | public function doConfigPageInit($page) { 55 | $request = $_REQUEST; 56 | $action = isset($request['action']) ? $request['action'] : ''; 57 | $panzoom = isset($request['panzoom']) ? $request['panzoom'] : ''; 58 | $horizontal = isset($request['horizontal']) ? $request['horizontal'] : ''; 59 | $datetime = isset($request['datetime']) ? $request['datetime'] : ''; 60 | $destination = isset($request['destination']) ? $request['destination'] : ''; 61 | $scale = isset($request['scale']) ? $request['scale'] : ''; 62 | $dynmembers = isset($request['dynmembers']) ? $request['dynmembers'] : ''; 63 | 64 | switch ($action) { 65 | case 'edit': 66 | $this->editCpviz($panzoom, $horizontal, $datetime, $destination, $scale, $dynmembers); 67 | break; 68 | default: 69 | break; 70 | } 71 | } 72 | public function getRightNav($request) { 73 | return load_view(__DIR__."/views/rnav.php",[]); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for packing up the cpviz module 3 | # 4 | TARBALL = ~/cpviz.tar.gz 5 | 6 | all: sign pack 7 | 8 | sign: 9 | sign cpviz 10 | 11 | pack: $(TARBALL) 12 | 13 | $(TARBALL): 14 | (cd .. ; tar cvzf $(TARBALL) --exclude=cpviz/.git --exclude=$(TARBALL) cpviz) 15 | 16 | clean: 17 | rm -f $(TARBALL) 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ⚠️ This repository has been deprecated and is no longer maintained. 2 | Please visit [dpviz](https://github.com/madgen78/dpviz) for the latest version and updates.⚠️ 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ``` 11 | Dial Plan Visualizer - see a graph of the call flow for 12 | any Inbound Route. 13 | ``` 14 | ### What? 15 | cpviz 16 | This is a module for [FreePBX©](http://www.freepbx.org/ "FreePBX Home Page"), an open source graphical user interface to control and manage [Asterisk(http://www.asterisk.org/ "Asterisk Home Page") phone systems. FreePBX is licensed under GPL. 17 | The cpviz module shows you a graph of the call flow for any Inbound Route. End-user PBX support often involves making changes to the flow for inbound calls, or simply asking questions about it (e.g. "Whose phones ring when someone calls X? When we get a call on Y does it go directly to the IVR or are there Time Conditions applied first?"). 18 | 19 | ### Installing the module 20 | * If upgrading- uninstall the current version first. 21 | 22 | * Command line... 23 | Uninstall: 24 | ``` 25 | fwconsole ma uninstall cpviz 26 | ``` 27 | 28 | Install: 29 | ``` 30 | fwconsole ma downloadinstall https://github.com/madgen78/cpviz/archive/refs/heads/1.0.13.zip 31 | ``` 32 | 33 | --or-- 34 | 35 | ### Installing the Module 36 | 37 | 1. **Log into FreePBX**, then navigate to **Admin > Module Admin**. 38 | 2. Click **Upload Modules**. 39 | 3. **Download the module** from the following link: [Download cpviz 1.0.14](https://github.com/madgen78/cpviz/archive/refs/heads/1.0.14.zip). 40 | 41 | #### Upload the Module: 42 | 4. Set the upload type to **"Upload (From Hard Disk)"**. 43 | 5. Click **Choose File** to select the downloaded file, then click **Upload (From Hard Disk)**. 44 | 6. After the upload, click the **"Local Module Administration"** link. 45 | 46 | #### Install the Module: 47 | 7. Scroll down to **Dial Plan Visualizer** under the **Reports** section and click it. 48 | 8. Click the **Install** action. 49 | 9. Finally, click the **Process** button at the bottom of the page. 50 | 51 | 52 | ### How to Use the Module 53 | 1. **Log in to your PBX** and navigate to **Reports > Dial Plan Visualizer**. 54 | 2. **Select or search for an inbound route** using the side menu. 55 | 56 | #### Highlighting Paths: 57 | - Click **Highlight Paths**, then click on a node or edge to highlight it (links are inactive). 58 | - **Exported images** will include the highlighted paths. 59 | - When you're done, click **Remove Highlights** to clear the highlights. 60 | 61 | #### Navigation: 62 | - **Pan** by holding down the left mouse button. 63 | - **Zoom** using the mouse wheel. 64 | 65 | #### Additional Features: 66 | - **Hover** over a path to highlight the entire path from start to end. 67 | - **Click** on a destination to open it in a new tab. 68 | - **Click** on a "Match: (timegroup)" to open it in a new tab. 69 | - To export, click the **"Export as ... .png"** button. 70 | 71 | ### License 72 | [This modules code is licensed as GPLv3+](http://www.gnu.org/licenses/gpl-3.0.txt) 73 | 74 | ### Issues 75 | * No known issues at this time. 76 | 77 | 78 | -------------------------------------------------------------------------------- /assets/css/cpviz.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | height: 100%; 3 | margin: 0; 4 | padding: 0; 5 | } 6 | #vizContainer { 7 | width: 100%; 8 | height: 100%; 9 | max-width: 100%; 10 | max-height: 100%; 11 | /*overflow: hidden; 12 | /*border: 1px solid black; /* Just for visualization */ 13 | } 14 | #set_table tr:nth-child(even){background-color: #EEEEEE;} 15 | /* the lines within the edges */ 16 | .edge:active path, 17 | .edge:hover path { 18 | cursor: pointer; 19 | stroke: fuchsia; 20 | stroke-width: 3; 21 | stroke-opacity: 1; 22 | } 23 | /* arrows are typically drawn with a polygon */ 24 | .edge:active polygon, 25 | .edge:hover polygon { 26 | cursor: pointer; 27 | stroke: fuchsia; 28 | stroke-width: 3; 29 | fill: fuchsia; 30 | stroke-opacity: 1; 31 | fill-opacity: 1; 32 | } 33 | /* If you happen to have text and want to color that as well... */ 34 | .edge:active text, 35 | .edge:hover text { 36 | cursor: pointer; 37 | fill: fuchsia; 38 | } 39 | svg { 40 | max-width: 100%; 41 | max-height: 100%; 42 | display: block; 43 | /*margin: auto; /* Center the SVG horizontally */ 44 | } 45 | #graph0 { 46 | border: none; 47 | } 48 | 49 | .selected ellipse { 50 | fill: #ff0000 !important; 51 | } 52 | .highlighted-edge path { 53 | stroke: #ff0000 !important; 54 | stroke-width: 3px !important; 55 | } 56 | .highlighted-edge polygon { 57 | fill: #ff0000 !important; 58 | } -------------------------------------------------------------------------------- /assets/js/panzoom.min.js: -------------------------------------------------------------------------------- 1 | !function(e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).panzoom=e()}(function(){return function o(r,i,a){function c(n,e){if(!i[n]){if(!r[n]){var t="function"==typeof require&&require;if(!e&&t)return t(n,!0);if(u)return u(n,!0);throw(t=new Error("Cannot find module '"+n+"'")).code="MODULE_NOT_FOUND",t}t=i[n]={exports:{}},r[n][0].call(t.exports,function(e){return c(r[n][1][e]||e)},t,t.exports,o,r,i,a)}return i[n].exports}for(var u="function"==typeof require&&require,e=0;e element. Use its child instead (e.g. ). As of March 2016 only FireFox supported transform on the root element");e.disableKeyboardInteraction||o.setAttribute("tabindex",0);return{getBBox:function(){var e=t.getBBox();return{left:e.x,top:e.y,width:e.width,height:e.height}},getScreenCTM:function(){var e=o.getCTM();return e||o.getScreenCTM()},getOwner:function(){return o},applyTransform:function(e){t.setAttribute("transform","matrix("+e.scale+" 0 0 "+e.scale+" "+e.x+" "+e.y+")")},initTransform:function(e){var n=t.getCTM();e.x=n.e,e.y=n.f,e.scale=n.a,o.removeAttributeNS(null,"viewBox")}}}},{}],6:[function(e,n,t){n.exports=function(){this.x=0,this.y=0,this.scale=1}},{}],7:[function(e,n,t){var e=e("bezier-easing"),p={ease:e(.25,.1,.25,1),easeIn:e(.42,0,1,1),easeOut:e(0,0,.58,1),easeInOut:e(.42,0,.58,1),linear:e(0,0,1,1)};function h(){}function o(){var n=new Set,t=new Set,o=0;return{next:e,cancel:e,clearAll:function(){n.clear(),t.clear(),cancelAnimationFrame(o),o=0}};function e(e){t.add(e),o=o||requestAnimationFrame(r)}function r(){o=0;var e=t;t=n,(n=e).forEach(function(e){e()}),n.clear()}}n.exports=function(t,n,e){var o=Object.create(null),r=Object.create(null),i="function"==typeof(e=e||{}).easing?e.easing:p[e.easing];i||(e.easing&&console.warn("Unknown easing function in amator: "+e.easing),i=p.ease);var a="function"==typeof e.step?e.step:h,c="function"==typeof e.done?e.done:h,u=function(e){if(!e)return"undefined"!=typeof window&&window.requestAnimationFrame?{next:window.requestAnimationFrame.bind(window),cancel:window.cancelAnimationFrame.bind(window)}:{next:function(e){return setTimeout(e,1e3/60)},cancel:function(e){return clearTimeout(e)}};if("function"!=typeof e.next)throw new Error("Scheduler is supposed to have next(cb) function");if("function"!=typeof e.cancel)throw new Error("Scheduler is supposed to have cancel(handle) function");return e}(e.scheduler),f=Object.keys(n);f.forEach(function(e){o[e]=t[e],r[e]=n[e]-t[e]});var s,e="number"==typeof e.duration?e.duration:400,l=Math.max(1,.06*e),m=0;return s=u.next(function e(){var n=i(m/l);m+=1;d(n);m<=l?(s=u.next(e),a(t)):(s=0,setTimeout(function(){c(t)},0))}),{cancel:function(){u.cancel(s),s=0}};function d(n){f.forEach(function(e){t[e]=r[e]*n+o[e]})}},n.exports.makeAggregateRaf=o,n.exports.sharedScheduler=o()},{"bezier-easing":8}],8:[function(e,n,t){var u=4,f=1e-7,s=10,r="function"==typeof Float32Array;function o(e,n){return 1-3*n+3*e}function l(e,n,t){return((o(n,t)*e+(3*t-6*n))*e+3*n)*e}function m(e,n,t){return 3*o(n,t)*e*e+2*(3*t-6*n)*e+3*n}function d(e){return e}n.exports=function(i,n,a,t){if(!(0<=i&&i<=1&&0<=a&&a<=1))throw new Error("bezier x values must be in [0, 1] range");if(i===n&&a===t)return d;for(var c=new(r?Float32Array:Array)(11),e=0;e<11;++e)c[e]=l(.1*e,i,a);function o(e){for(var n=0,t=1;10!==t&&c[t]<=e;++t)n+=.1;var o=n+.1*((e-c[--t])/(c[t+1]-c[t])),r=m(o,i,a);return.001<=r?function(e,n,t,o){for(var r=0;rf&&++c\n\n'});return this.wrapper.render(e,{format:t,engine:n,files:o,images:a,yInvert:r})}},{key:"renderSVGElement",value:function(e){var r=1getAll($sql, DB_FETCHMODE_ASSOC); 33 | if (DB::IsError($results)) { 34 | die_freepbx($results->getMessage()."

Error selecting from incoming"); 35 | } 36 | 37 | // Store the routes in a hash indexed by the inbound number 38 | foreach($results as $route) { 39 | $num = $route['extension']; 40 | $cid = $route['cidnum']; 41 | $routes[$num.$cid] = $route; 42 | } 43 | return $routes; 44 | } 45 | 46 | function dp_find_route($routes, $num) { 47 | 48 | $match = array(); 49 | $pattern = '/[^_xX+0-9]/'; # remove all non-digits 50 | $num = preg_replace($pattern, '', $num); 51 | 52 | // "extension" is the key for the routes hash 53 | foreach ($routes as $ext => $route) { 54 | if ($ext == $num) { 55 | $match = $routes[$num]; 56 | } 57 | } 58 | return $match; 59 | } 60 | 61 | # 62 | # This is a recursive function. It digs through various nodes 63 | # (ring groups, ivrs, time conditions, extensions, etc.) to find 64 | # the path a call takes. It creates a graph of the path through 65 | # the dial plan, stored in the $route object. 66 | # 67 | # 68 | function dp_follow_destinations (&$route, $destination) { 69 | global $db; 70 | global $pastels; 71 | global $neons; 72 | global $direction; 73 | 74 | if (! isset ($route['dpgraph'])) { 75 | $route['dpgraph'] = new Alom\Graphviz\Digraph('"'.$route['extension'].'"'); 76 | $route['dpgraph']->attr('graph',array('rankdir'=>$direction)); 77 | } 78 | $dpgraph = $route['dpgraph']; 79 | dplog(9, "destination='$destination' route[extension]: " . print_r($route['extension'], true)); 80 | 81 | # This only happens on the first call. Every recursive call includes 82 | # a destination to look at. For the first one, we get the destination from 83 | # the route object. 84 | if ($destination == '') { 85 | if (empty($route['extension'])){$didLabel='ANY';}else{$didLabel=formatPhoneNumber($route['extension']);} 86 | $didLink=$route['extension'].'/'; 87 | if (!empty($route['cidnum'])){ 88 | $didLabel.=' / '.formatPhoneNumber($route['cidnum']); 89 | $didLink.=$route['cidnum']; 90 | } 91 | 92 | $dpgraph->node($route['extension'], 93 | array( 94 | 'label' => sanitizeLabel($didLabel), 95 | 'shape' => 'cds', 96 | 'style' => 'filled', 97 | 'URL' => htmlentities('/admin/config.php?display=did&view=form&extdisplay='.urlencode($didLink)), 98 | 'target'=>'_blank', 99 | 'fillcolor' => 'darkseagreen') 100 | ); 101 | // $graph->node() returns the graph, not the node, so we always 102 | // have to get() the node after adding to the graph if we want 103 | // to save it for something. 104 | // UPDATE: beginNode() creates a node and returns it instead of 105 | // returning the graph. Similarly for edge() and beginEdge(). 106 | $route['parent_node'] = $dpgraph->get($route['extension']); 107 | $route['parent_edge_label'] = ' Always'; 108 | 109 | # One of thse should work to set the root node, but neither does. 110 | # See: https://rt.cpan.org/Public/Bug/Display.html?id=101437 111 | #$route->{parent_node}->set_attribute('root', 'true'); 112 | #$dpgraph->set_attribute('root' => $route->{extension}); 113 | 114 | // If an inbound route has no destination, we want to bail, otherwise recurse. 115 | if ($route['destination'] != '') { 116 | dp_follow_destinations($route, $route['destination']); 117 | } 118 | return; 119 | } 120 | 121 | dplog(9, "Inspecting destination $destination"); 122 | 123 | // We use get() to see if the node exists before creating it. get() throws 124 | // an exception if the node does not exist so we have to catch it. 125 | try { 126 | $node = $dpgraph->get($destination); 127 | } catch (Exception $e) { 128 | dplog(7, "Adding node: $destination"); 129 | $node = $dpgraph->beginNode($destination); 130 | } 131 | 132 | // Add an edge from our parent to this node, if there is not already one. 133 | // We do this even if the node already existed because this node might 134 | // have several paths to reach it. 135 | $ptxt = $route['parent_node']->getAttribute('label', ''); 136 | $ntxt = $node->getAttribute('label', ''); 137 | dplog(9, "Found it: ntxt = $ntxt"); 138 | if ($ntxt == '' ) { $ntxt = "(new node: $destination)"; } 139 | if ($dpgraph->hasEdge(array($route['parent_node'], $node))) { 140 | dplog(9, "NOT making an edge from $ptxt -> $ntxt"); 141 | $edge= $dpgraph->beginEdge(array($route['parent_node'], $node)); 142 | $edge->attribute('label', sanitizeLabel($route['parent_edge_label'])); 143 | } else { 144 | dplog(9, "Making an edge from $ptxt -> $ntxt"); 145 | $edge= $dpgraph->beginEdge(array($route['parent_node'], $node)); 146 | $edge->attribute('label', sanitizeLabel($route['parent_edge_label'])); 147 | if (preg_match("/^(Match:)./", $route['parent_edge_label'])){ 148 | $edge->attribute('URL', $route['parent_edge_url']); 149 | $edge->attribute('target', $route['parent_edge_target']); 150 | } 151 | } 152 | 153 | dplog(9, "The Graph: " . print_r($dpgraph, true)); 154 | 155 | // Now bail if we have already recursed on this destination before. 156 | if ($node->getAttribute('label', 'NONE') != 'NONE') { 157 | return; 158 | } 159 | 160 | # Now look at the destination and figure out where to dig deeper. 161 | 162 | # 163 | # Announcements 164 | # 165 | if (preg_match("/^app-announcement-(\d+),s,(\d+)/", $destination, $matches)) { 166 | $annum = $matches[1]; 167 | $another = $matches[2]; 168 | 169 | $an = $route['announcements'][$annum]; 170 | $recID=$an['recording_id']; 171 | 172 | $announcement = isset($route['recordings'][$recID]) ? $route['recordings'][$recID]['displayname'] : 'None'; 173 | #feature code exist? 174 | if ( isset($route['featurecodes']['*29'.$recID]) ){ 175 | #custom feature code? 176 | if ($route['featurecodes']['*29'.$an['recording_id']]['customcode']!=''){$featurenum=$route['featurecodes']['*29'.$an['recording_id']]['customcode'];}else{$featurenum=$route['featurecodes']['*29'.$an['recording_id']]['defaultcode'];} 177 | #is it enabled? 178 | if ( ($route['recordings'][$recID]['fcode']== '1') && ($route['featurecodes']['*29'.$recID]['enabled']=='1') ){$rec='\\nRecord(yes): '.$featurenum;}else{$rec='\\nRecord(no): '.$featurenum;} 179 | }else{ 180 | $rec='\\nRecord(no): disabled'; 181 | } 182 | 183 | $node->attribute('label', 'Announcements: '.sanitizeLabel($an['description']).'\\nRecording: '.sanitizeLabel($announcement).$rec); 184 | $node->attribute('URL', htmlentities('/admin/config.php?display=announcement&view=form&extdisplay='.$annum)); 185 | $node->attribute('target', '_blank'); 186 | $node->attribute('shape', 'note'); 187 | $node->attribute('fillcolor', 'oldlace'); 188 | $node->attribute('style', 'filled'); 189 | 190 | # The destinations we need to follow are the no-answer destination 191 | # (postdest) and the members of the group. 192 | 193 | if ($an['post_dest'] != '') { 194 | $route['parent_edge_label'] = ' Continue'; 195 | $route['parent_node'] = $node; 196 | dp_follow_destinations($route, $an['post_dest']); 197 | } 198 | # end of announcements 199 | 200 | # 201 | # Blackhole 202 | # 203 | } elseif (preg_match("/^app-blackhole,(hangup|congestion|busy|zapateller|musiconhold|ring|no-service),(\d+)/", $destination, $matches)) { 204 | $blackholetype = str_replace('musiconhold','Music On Hold',$matches[1]); 205 | $blackholeother = $matches[2]; 206 | 207 | $node->attribute('label', 'Terminate Call: '.ucwords($blackholetype,'-')); 208 | $node->attribute('shape', 'invhouse'); 209 | $node->attribute('fillcolor', 'orangered'); 210 | $node->attribute('style', 'filled'); 211 | #end of Blackhole 212 | 213 | # 214 | # Call Flow Control (daynight) 215 | # 216 | } elseif (preg_match("/^app-daynight,(\d+),(\d+)/", $destination, $matches)) { 217 | $daynightnum = $matches[1]; 218 | $daynightother = $matches[2]; 219 | $daynight = $route['daynight'][$daynightnum]; 220 | 221 | #feature code exist? 222 | if ( isset($route['featurecodes']['*28'.$daynightnum]) ){ 223 | #custom feature code? 224 | if ($route['featurecodes']['*28'.$daynightnum]['customcode']!=''){$featurenum=$route['featurecodes']['*28'.$daynightnum]['customcode'];}else{$featurenum=$route['featurecodes']['*28'.$daynightnum]['defaultcode'];} 225 | #is it enabled? 226 | if ($route['featurecodes']['*28'.$daynightnum]['enabled']=='1'){$code='\\nToggle (enabled): '.$featurenum;}else{$code='\\nToggle (disabled): '.$featurenum;} 227 | }else{ 228 | $code=''; 229 | } 230 | 231 | #check current status and set path to active 232 | $C = '/usr/sbin/asterisk -rx "database show DAYNIGHT/C'.$daynightnum.'" | cut -d \':\' -f2 | tr -d \' \' | head -1'; 233 | exec($C, $current_daynight); 234 | $dactive = $nactive = ""; 235 | if ($current_daynight[0]=='DAY'){$dactive="(Active)";}else{$nactive="(Active)";} 236 | 237 | foreach ($daynight as $d){ 238 | if ($d['dmode']=='day'){ 239 | $route['parent_edge_label'] = ' Day Mode '.$dactive; 240 | $route['parent_node'] = $node; 241 | dp_follow_destinations($route, $d['dest']); 242 | }elseif ($d['dmode']=='night'){ 243 | $route['parent_edge_label'] = ' Night Mode '.$nactive; 244 | $route['parent_node'] = $node; 245 | dp_follow_destinations($route, $d['dest']); 246 | }elseif ($d['dmode']=="fc_description"){ 247 | $node->attribute('label', "Call Flow: ".sanitizeLabel($d['dest']) .$code); 248 | } 249 | } 250 | $daynight = $route['daynight'][$daynightnum]; 251 | $node->attribute('URL', htmlentities('/admin/config.php?display=daynight&view=form&itemid='.$daynightnum.'&extdisplay='.$daynightnum)); 252 | $node->attribute('target', '_blank'); 253 | $node->attribute('fillcolor', $pastels[14]); 254 | $node->attribute('style', 'filled'); 255 | #end of Call Flow Control (daynight) 256 | 257 | # 258 | # Conferences (meetme) 259 | # 260 | } elseif (preg_match("/^ext-meetme,(\d+),(\d+)/", $destination, $matches)) { 261 | $meetmenum = $matches[1]; 262 | $meetmeother = $matches[2]; 263 | $meetme = $route['meetme'][$meetmenum]; 264 | 265 | $node->attribute('label', 'Conferences: '.$meetme['exten'].' '.sanitizeLabel($meetme['description'])); 266 | $node->attribute('URL', htmlentities('/admin/config.php?display=conferences&view=form&extdisplay='.$meetmenum)); 267 | $node->attribute('target', '_blank'); 268 | $node->attribute('fillcolor', 'burlywood'); 269 | $node->attribute('style', 'filled'); 270 | #end of Conferences (meetme) 271 | 272 | # 273 | # Directory 274 | # 275 | } elseif (preg_match("/^directory,(\d+),(\d+)/", $destination, $matches)) { 276 | $directorynum = $matches[1]; 277 | $directoryother = $matches[2]; 278 | $directory = $route['directory'][$directorynum]; 279 | 280 | $node->attribute('label', 'Directory: '.sanitizeLabel($directory['dirname'])); 281 | $node->attribute('URL', htmlentities('/admin/config.php?display=directory&view=form&id='.$directorynum)); 282 | $node->attribute('target', '_blank'); 283 | $node->attribute('fillcolor', $pastels[9]); 284 | $node->attribute('style', 'filled'); 285 | #end of Directory 286 | 287 | # 288 | # DISA 289 | # 290 | } elseif (preg_match("/^disa,(\d+),(\d+)/", $destination, $matches)) { 291 | $disanum = $matches[1]; 292 | $disaother = $matches[2]; 293 | $disa = $route['disa'][$disanum]; 294 | 295 | $node->attribute('label', 'DISA: '.sanitizeLabel($disa['displayname'])); 296 | $node->attribute('URL', htmlentities('/admin/config.php?display=disa&view=form&itemid='.$disanum)); 297 | $node->attribute('target', '_blank'); 298 | $node->attribute('fillcolor', $pastels[10]); 299 | $node->attribute('style', 'filled'); 300 | #end of DISA 301 | 302 | # 303 | # Dynamic Routes 304 | # 305 | } elseif (preg_match("/^dynroute-(\d+)/", $destination, $matches)) { 306 | $dynnum = $matches[1]; 307 | $dynrt = $route['dynroute'][$dynnum]; 308 | 309 | $recID=$dynrt['announcement_id']; 310 | 311 | $announcement = isset($route['recordings'][$recID]) ? $route['recordings'][$recID]['displayname'] : 'None'; 312 | $node->attribute('label', 'DYN: '.sanitizeLabel($dynrt['name']).'\\nAnnouncement: '.sanitizeLabel($announcement)); 313 | $node->attribute('URL', htmlentities('/admin/config.php?display=dynroute&action=edit&id='.$dynnum)); 314 | $node->attribute('target', '_blank'); 315 | $node->attribute('shape', 'component'); 316 | $node->attribute('fillcolor', $pastels[12]); 317 | $node->attribute('style', 'filled'); 318 | 319 | //are the invalid and timeout destinations the same? 320 | if ($dynrt['invalid_dest']==$dynrt['default_dest']){ 321 | $route['parent_edge_label']= ' Invalid Input, Default ('.$dynrt['timeout'].' secs)'; 322 | $route['parent_node'] = $node; 323 | dp_follow_destinations($route, $dynrt['invalid_dest']); 324 | }else{ 325 | if ($dynrt['invalid_dest'] != '') { 326 | $route['parent_edge_label']= ' Invalid Input'; 327 | $route['parent_node'] = $node; 328 | dp_follow_destinations($route, $dynrt['invalid_dest']); 329 | } 330 | if ($dynrt['default_dest'] != '') { 331 | $route['parent_edge_label']= ' Default ('.$dynrt['timeout'].' secs)'; 332 | $route['parent_node'] = $node; 333 | dp_follow_destinations($route, $dynrt['default_dest']); 334 | } 335 | } 336 | 337 | if (!empty($dynrt['routes'])){ 338 | ksort($dynrt['routes']); 339 | foreach ($dynrt['routes'] as $selid => $ent) { 340 | 341 | $route['parent_edge_label']= ' Match: '.sanitizeLabel($ent['selection']).'\\n'.sanitizeLabel($ent['description']); 342 | $route['parent_node'] = $node; 343 | dp_follow_destinations($route, $ent['dest']); 344 | } 345 | } 346 | #end of Dynamic Routes 347 | 348 | # 349 | # Extension (from-did-direct) 350 | # 351 | } elseif (preg_match("/^from-did-direct,(\d+),(\d+)/", $destination, $matches)) { 352 | $extnum = $matches[1]; 353 | $extother = $matches[2]; 354 | $extname= $route['extensions'][$extnum]['name']; 355 | $extemail= $route['extensions'][$extnum]['email']; 356 | $extemail= str_replace("|",",\\n",$extemail); 357 | 358 | $node->attribute('label', 'Extension: '.$extnum.' '.sanitizeLabel($extname).'\\n'.sanitizeLabel($extemail)); 359 | $node->attribute('URL', htmlentities('/admin/config.php?display=extensions&extdisplay='.$extnum)); 360 | $node->attribute('target', '_blank'); 361 | $node->attribute('shape', 'house'); 362 | $node->attribute('fillcolor', $pastels[15]); 363 | $node->attribute('style', 'filled'); 364 | #end of Extension (from-did-direct) 365 | 366 | # 367 | # Feature Codes 368 | # 369 | } elseif (preg_match("/^ext-featurecodes,(\*?\d+),(\d+)/", $destination, $matches)) { 370 | $featurenum = $matches[1]; 371 | $featureother = $matches[2]; 372 | $feature = $route['featurecodes'][$featurenum]; 373 | 374 | if ($feature['customcode']!=''){$featurenum=$feature['customcode'];} 375 | $node->attribute('label', 'Feature Code: '.sanitizeLabel($feature['description']).' \\<'.$featurenum.'\\>'); 376 | $node->attribute('URL', htmlentities('/admin/config.php?display=featurecodeadmin')); 377 | $node->attribute('target', '_blank'); 378 | $node->attribute('shape', 'folder'); 379 | $node->attribute('fillcolor', 'gainsboro'); 380 | $node->attribute('style', 'filled'); 381 | #end of Feature Codes 382 | 383 | # 384 | # Inbound Routes 385 | # 386 | } elseif (preg_match("/^from-trunk,([^,]*),(\d+)/", $destination, $matches)) { 387 | 388 | $num = $matches[1]; 389 | $numother = $matches[2]; 390 | 391 | $incoming = $route['incoming'][$num]; 392 | 393 | $didLabel = ($num == '') ? 'ANY' : formatPhoneNumber($num); 394 | $didLabel.="\n".$incoming['description']; 395 | $didLink=$num.'/'; 396 | 397 | $node->attribute('label', sanitizeLabel($didLabel)); 398 | $node->attribute('URL', htmlentities('/admin/config.php?display=did&view=form&extdisplay='.urlencode($didLink))); 399 | $node->attribute('target', '_blank'); 400 | $node->attribute('shape', 'cds'); 401 | $node->attribute('fillcolor', 'darkseagreen'); 402 | $node->attribute('style', 'filled'); 403 | 404 | $route['parent_edge_label']= ' Continue'; 405 | $route['parent_node'] = $node; 406 | dp_follow_destinations($route, $incoming['destination']); 407 | 408 | #end of Inbound Routes 409 | 410 | # 411 | # IVRs 412 | # 413 | } elseif (preg_match("/^ivr-(\d+),([a-z]+),(\d+)/", $destination, $matches)) { 414 | $inum = $matches[1]; 415 | $iflag = $matches[2]; 416 | $iother = $matches[3]; 417 | 418 | $ivr = $route['ivrs'][$inum]; 419 | $recID= $ivr['announcement']; 420 | $ivrRecName = isset($route['recordings'][$recID]) ? $route['recordings'][$recID]['displayname'] : 'None'; 421 | 422 | #feature code exist? 423 | if ( isset($route['featurecodes']['*29'.$ivr['announcement']]) ){ 424 | #custom feature code? 425 | if ($route['featurecodes']['*29'.$ivr['announcement']]['customcode']!=''){$featurenum=$route['featurecodes']['*29'.$ivr['announcement']]['customcode'];}else{$featurenum=$route['featurecodes']['*29'.$ivr['announcement']]['defaultcode'];} 426 | #is it enabled? 427 | if ( ($route['recordings'][$recID]['fcode']== '1') && ($route['featurecodes']['*29'.$recID]['enabled']=='1') ){$rec='(yes): '.$featurenum;}else{$rec='(no): '.$featurenum;} 428 | }else{ 429 | $rec='(no): disabled'; 430 | } 431 | 432 | $node->attribute('label', "IVR: ".sanitizeLabel($ivr['name'])."\\nAnnouncement: ".sanitizeLabel($ivrRecName)."\\lRecord ".$rec."\\l"); 433 | $node->attribute('URL', htmlentities('/admin/config.php?display=ivr&action=edit&id='.$inum)); 434 | $node->attribute('target', '_blank'); 435 | $node->attribute('shape', 'component'); 436 | $node->attribute('fillcolor', 'gold'); 437 | $node->attribute('style', 'filled'); 438 | 439 | # The destinations we need to follow are the invalid_destination, 440 | # timeout_destination, and the selection targets 441 | 442 | 443 | #are the invalid and timeout destinations the same? 444 | if ($ivr['invalid_destination']==$ivr['timeout_destination']){ 445 | $route['parent_edge_label']= " Invalid Input, Timeout ($ivr[timeout_time] secs)"; 446 | $route['parent_node'] = $node; 447 | dp_follow_destinations($route, $ivr['invalid_destination']); 448 | }else{ 449 | if ($ivr['invalid_destination'] != '') { 450 | $route['parent_edge_label']= ' Invalid Input'; 451 | $route['parent_node'] = $node; 452 | dp_follow_destinations($route, $ivr['invalid_destination']); 453 | } 454 | if ($ivr['timeout_destination'] != '') { 455 | $route['parent_edge_label']= ' Timeout ('.$ivr['timeout_time'].' secs)'; 456 | $route['parent_node'] = $node; 457 | dp_follow_destinations($route, $ivr['timeout_destination']); 458 | } 459 | } 460 | 461 | #now go through the selections 462 | if (!empty($ivr['entries'])){ 463 | ksort($ivr['entries']); 464 | foreach ($ivr['entries'] as $selid => $ent) { 465 | 466 | $route['parent_edge_label']= ' Selection '.sanitizeLabel($ent['selection']); 467 | $route['parent_node'] = $node; 468 | dp_follow_destinations($route, $ent['dest']); 469 | } 470 | } 471 | # end of IVRs 472 | 473 | # 474 | # Languages 475 | # 476 | } elseif (preg_match("/^app-languages,(\d+),(\d+)/", $destination, $matches)) { 477 | $langnum = $matches[1]; 478 | $langother = $matches[2]; 479 | 480 | $lang = $route['languages'][$langnum]; 481 | $node->attribute('label', 'Languages: '.sanitizeLabel($lang['description'])); 482 | $node->attribute('URL', htmlentities('/admin/config.php?display=languages&view=form&extdisplay='.$langnum)); 483 | $node->attribute('target', '_blank'); 484 | $node->attribute('shape', 'note'); 485 | $node->attribute('fillcolor', $pastels[6]); 486 | $node->attribute('style', 'filled'); 487 | 488 | if ($lang['dest'] != '') { 489 | $route['parent_edge_label'] = ' Continue'; 490 | $route['parent_node'] = $node; 491 | dp_follow_destinations($route, $lang['dest']); 492 | } 493 | #end of Languages 494 | 495 | # 496 | # MISC Destinations 497 | # 498 | } elseif (preg_match("/^ext-miscdests,(\d+),(\d+)/", $destination, $matches)) { 499 | $miscdestnum = $matches[1]; 500 | $miscdestother = $matches[2]; 501 | 502 | $miscdest = $route['miscdest'][$miscdestnum]; 503 | $node->attribute('label', 'Misc Dest: '.sanitizeLabel($miscdest['description']).' ('.$miscdest['destdial'].')'); 504 | $node->attribute('URL', htmlentities('/admin/config.php?display=miscdests&view=form&extdisplay='.$miscdestnum)); 505 | $node->attribute('target', '_blank'); 506 | $node->attribute('shape', 'rpromoter'); 507 | $node->attribute('fillcolor', 'coral'); 508 | $node->attribute('style', 'filled'); 509 | #end of MISC Destinations 510 | 511 | # 512 | # Play Recording 513 | # 514 | } elseif (preg_match("/^play-system-recording,(\d+),(\d+)/", $destination, $matches)) { 515 | $recID = $matches[1]; 516 | $recIDOther = $matches[2]; 517 | $playName = isset($route['recordings'][$recID]) ? $route['recordings'][$recID]['displayname'] : 'None'; 518 | $node->attribute('label', 'Play Recording: '.sanitizeLabel($playName)); 519 | $node->attribute('URL', htmlentities('/admin/config.php?display=recordings&action=edit&id='.$recID)); 520 | $node->attribute('target', '_blank'); 521 | $node->attribute('shape', 'rect'); 522 | $node->attribute('fillcolor', $pastels['16']); 523 | $node->attribute('style', 'filled'); 524 | #end of Play Recording 525 | 526 | # 527 | # Queues 528 | # 529 | } elseif (preg_match("/^ext-queues,(\d+),(\d+)/", $destination, $matches)) { 530 | $qnum = $matches[1]; 531 | $qother = $matches[2]; 532 | 533 | $q = $route['queues'][$qnum]; 534 | if ($q['maxwait'] == 0 || $q['maxwait'] == '' || !is_numeric($q['maxwait'])) { 535 | $maxwait = 'Unlimited'; 536 | } else { 537 | $maxwait = secondsToTime($q['maxwait']); 538 | } 539 | $node->attribute('label', 'Queue '.$qnum.': '.sanitizeLabel($q['descr'])); 540 | $node->attribute('URL', htmlentities('/admin/config.php?display=queues&view=form&extdisplay='.$qnum)); 541 | $node->attribute('target', '_blank'); 542 | $node->attribute('shape', 'hexagon'); 543 | $node->attribute('fillcolor', 'mediumaquamarine'); 544 | $node->attribute('style', 'filled'); 545 | 546 | # The destinations we need to follow are the queue members (extensions) 547 | # and the no-answer destination. 548 | if ($q['dest'] != '') { 549 | $route['parent_edge_label'] = ' No Answer ('.$maxwait.')'; 550 | $route['parent_node'] = $node; 551 | dp_follow_destinations($route, $q['dest']); 552 | } 553 | 554 | foreach ($q['members'] as $types=>$type) { 555 | foreach ($type as $members){ 556 | $route['parent_node'] = $node; 557 | $route['parent_edge_label'] = ($types == 'static') ? ' Static' : ' Dynamic'; 558 | dp_follow_destinations($route, 'qmember'.$members); 559 | } 560 | } 561 | #end of Queues 562 | 563 | # 564 | # Queue members (static and dynamic) 565 | # 566 | } elseif (preg_match("/^qmember(\d+)/", $destination, $matches)) { 567 | $qextension=$matches[1]; 568 | $qlabel = isset($route['extensions'][$qextension]['name']) ? $route['extensions'][$qextension]['name'] : ''; 569 | $node->attribute('label', 'Ext '.$qextension.'\\n'.sanitizeLabel($qlabel)); 570 | 571 | if ($route['parent_edge_label'] == ' Static') { 572 | $node->attribute('fillcolor', $pastels[20]); 573 | }else{ 574 | $node->attribute('fillcolor', $pastels[8]); 575 | } 576 | $node->attribute('style', 'filled'); 577 | 578 | #end of Queue members (static and dynamic) 579 | 580 | # 581 | # Ring Groups 582 | # 583 | } elseif (preg_match("/^ext-group,(\d+),(\d+)/", $destination, $matches)) { 584 | $rgnum = $matches[1]; 585 | $rgother = $matches[2]; 586 | 587 | $rg = $route['ringgroups'][$rgnum]; 588 | $node->attribute('label', 'Ring Groups: '.$rgnum.' '.sanitizeLabel($rg['description'])); 589 | $node->attribute('URL', htmlentities('/admin/config.php?display=ringgroups&view=form&extdisplay='.$rgnum)); 590 | $node->attribute('target', '_blank'); 591 | $node->attribute('fillcolor', $pastels[12]); 592 | $node->attribute('style', 'filled'); 593 | 594 | # The destinations we need to follow are the no-answer destination 595 | # (postdest) and the members of the group. 596 | if ($rg['postdest'] != '') { 597 | $route['parent_edge_label'] = ' No Answer ('.secondsToTime($rg['grptime']).')'; 598 | $route['parent_node'] = $node; 599 | dp_follow_destinations($route, $rg['postdest']); 600 | } 601 | 602 | $grplist = preg_split("/-/", $rg['grplist']); 603 | 604 | foreach ($grplist as $member) { 605 | $route['parent_node'] = $node; 606 | $route['parent_edge_label'] = ''; 607 | dp_follow_destinations($route, "rg$member"); 608 | } 609 | # End of Ring Groups 610 | 611 | # 612 | # Ring Group Members 613 | # 614 | } elseif (preg_match("/^rg(\d+)/", $destination, $matches)) { 615 | $rgext = $matches[1]; 616 | $rglabel = isset($route['extensions'][$rgext]) ? 'Ext '.$rgext.'\\n'.$route['extensions'][$rgext]['name'] : $rgext; 617 | 618 | $node->attribute('label', sanitizeLabel($rglabel)); 619 | $node->attribute('fillcolor', $pastels[2]); 620 | $node->attribute('style', 'filled'); 621 | # end of ring group members 622 | 623 | # 624 | # Set CID 625 | # 626 | } elseif (preg_match("/^app-setcid,(\d+),(\d+)/", $destination, $matches)) { 627 | $cidnum = $matches[1]; 628 | $cidother = $matches[2]; 629 | 630 | $cid = $route['setcid'][$cidnum]; 631 | $node->attribute('label', 'Set CID\\nName= '.preg_replace('/\${CALLERID\(name\)}/i', '$cid_name', $cid['cid_name']).'\\nNumber= '.preg_replace('/\${CALLERID\(num\)}/i', '$cid_number', $cid['cid_num'])); 632 | $node->attribute('URL', htmlentities('/admin/config.php?display=setcid&view=form&id='.$cidnum)); 633 | $node->attribute('target', '_blank'); 634 | $node->attribute('shape', 'note'); 635 | $node->attribute('fillcolor', $pastels[6]); 636 | $node->attribute('style', 'filled'); 637 | 638 | if ($cid['dest'] != '') { 639 | $route['parent_edge_label'] = ' Continue'; 640 | $route['parent_node'] = $node; 641 | dp_follow_destinations($route, $cid['dest']); 642 | } 643 | #end of Set CID 644 | 645 | # 646 | # Time Conditions 647 | # 648 | } elseif (preg_match("/^timeconditions,(\d+),(\d+)/", $destination, $matches)) { 649 | $tcnum = $matches[1]; 650 | $tcother = $matches[2]; 651 | 652 | $tc = $route['timeconditions'][$tcnum]; 653 | $node->attribute('label', "TC: ".sanitizeLabel($tc['displayname'])); 654 | $node->attribute('URL', htmlentities('/admin/config.php?display=timeconditions&view=form&itemid='.$tcnum)); 655 | $node->attribute('target', '_blank'); 656 | $node->attribute('shape', 'invhouse'); 657 | $node->attribute('fillcolor', 'dodgerblue'); 658 | $node->attribute('style', 'filled'); 659 | 660 | 661 | # Not going to use the time group info for right now. Maybe put it in the edge text? 662 | $tgname = $route['timegroups'][$tc['time']]['description']; 663 | $tgtime = $route['timegroups'][$tc['time']]['time']; 664 | $tgnum = $route['timegroups'][$tc['time']]['id']; 665 | 666 | # Now set the current node to be the parent and recurse on both the true and false branches 667 | $route['parent_edge_label'] = 'Match:\\n'.sanitizeLabel($tgname).'\\n'.$tgtime; 668 | $route['parent_edge_url'] = htmlentities('/admin/config.php?display=timegroups&view=form&extdisplay='.$tgnum); 669 | $route['parent_edge_target'] = '_blank'; 670 | 671 | $route['parent_node'] = $node; 672 | dp_follow_destinations($route, $tc['truegoto']); 673 | 674 | 675 | $route['parent_edge_label'] = ' NoMatch'; 676 | $route['parent_edge_url'] =''; 677 | $route['parent_edge_target'] = ''; 678 | $route['parent_node'] = $node; 679 | dp_follow_destinations($route, $tc['falsegoto']); 680 | #end of Time Conditions 681 | 682 | # 683 | # Voicemail 684 | # 685 | } elseif (preg_match("/^ext-local,vm([b,i,s,u])(\d+),(\d+)/", $destination, $matches)) { 686 | $vmtype= $matches[1]; 687 | $vmnum = $matches[2]; 688 | $vmother = $matches[3]; 689 | 690 | $vm_array=array('b'=>'(Busy Message)','i'=>'(Instructions Only)','s'=>'(No Message)','u'=>'(Unavailable Message)' ); 691 | $vmname= $route['extensions'][$vmnum]['name']; 692 | $vmemail= $route['extensions'][$vmnum]['email']; 693 | $vmemail= str_replace("|",",\\n",$vmemail); 694 | 695 | $node->attribute('label', 'Voicemail: '.$vmnum.' '.sanitizeLabel($vmname).' '.$vm_array[$vmtype].'\\n'.$vmemail); 696 | $node->attribute('URL', htmlentities('/admin/config.php?display=extensions&extdisplay='.$vmnum)); 697 | $node->attribute('target', '_blank'); 698 | $node->attribute('shape', 'house'); 699 | $node->attribute('fillcolor', $pastels[11]); 700 | $node->attribute('style', 'filled'); 701 | #end of Voicemail 702 | 703 | # 704 | # VM Blast 705 | # 706 | } elseif (preg_match("/^vmblast\-grp,(\d+),(\d+)/", $destination, $matches)) { 707 | $vmblastnum = $matches[1]; 708 | $vmblastother = $matches[2]; 709 | $vmblast = $route['vmblasts'][$vmblastnum]; 710 | 711 | $node->attribute('label', 'VM Blast: '.$vmblastnum.' '.sanitizeLabel($vmblast['description'])); 712 | $node->attribute('URL', htmlentities('/admin/config.php?display=vmblast&view=form&extdisplay='.$vmblastnum)); 713 | $node->attribute('target', '_blank'); 714 | $node->attribute('shape', 'folder'); 715 | $node->attribute('fillcolor', 'gainsboro'); 716 | $node->attribute('style', 'filled'); 717 | 718 | if (!empty($vmblast['members'])){ 719 | foreach ($vmblast['members'] as $member) { 720 | 721 | $route['parent_edge_label']= ''; 722 | $route['parent_node'] = $node; 723 | dp_follow_destinations($route, 'vmblast-mem,'.$member); 724 | 725 | } 726 | } 727 | #end of VM Blast 728 | 729 | #VM Blast members 730 | } elseif (preg_match("/^vmblast\-mem,(\d+)/", $destination, $matches)) { 731 | $member=$matches[1]; 732 | $vmblastname=$route['extensions'][$member]['name']; 733 | $vmblastemail=$route['extensions'][$member]['email']; 734 | $vmblastemail= str_replace("|",",\\n",$vmblastemail); 735 | $node->attribute('label', 'Ext '.$member.' '.sanitizeLabel($vmblastname).'\\n'.sanitizeLabel($vmblastemail)); 736 | $node->attribute('target', '_blank'); 737 | $node->attribute('shape', 'rect'); 738 | $node->attribute('fillcolor', $pastels['16']); 739 | $node->attribute('style', 'filled'); 740 | 741 | #preg_match not found 742 | }else { 743 | dplog(1, "Unknown destination type: $destination"); 744 | $node->attribute('fillcolor', $pastels[12]); 745 | $node->attribute('label', sanitizeLabel($destination)); 746 | $node->attribute('style', 'filled'); 747 | 748 | } 749 | 750 | } 751 | 752 | 753 | # load gobs of data. Save it in hashrefs indexed by ints 754 | function dp_load_tables(&$dproute) { 755 | global $db; 756 | global $dynmembers; 757 | # Time Conditions 758 | $query = "select * from timeconditions"; 759 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 760 | if (DB::IsError($results)) { 761 | die_freepbx($results->getMessage()."

Error selecting from timeconditions"); 762 | } 763 | foreach($results as $tc) { 764 | $id = $tc['timeconditions_id']; 765 | $dproute['timeconditions'][$id] = $tc; 766 | } 767 | 768 | # Time Groups 769 | $query = "select * from timegroups_groups"; 770 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 771 | if (DB::IsError($results)) { 772 | die_freepbx($results->getMessage()."

Error selecting from timegroups_groups"); 773 | } 774 | foreach($results as $tg) { 775 | $id = $tg['id']; 776 | $dproute['timegroups'][$id] = $tg; 777 | } 778 | 779 | # Time Groups Details 780 | $query = "select * from timegroups_details"; 781 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 782 | if (DB::IsError($results)) { 783 | die_freepbx($results->getMessage()."

Error selecting from timegroups_details"); 784 | } 785 | foreach($results as $tgd) { 786 | $id = $tgd['timegroupid']; 787 | if (! isset($dproute['timegroups'][$id])) { 788 | dplog(1, "timegroups_details id found for unknown timegroup, id=$id"); 789 | } else { 790 | if (!isset($dproute['timegroups'][$id]['time'])){$dproute['timegroups'][$id]['time']='';} 791 | $exploded=explode("|",$tgd['time']); 792 | if ($exploded[0]!=='*'){$time=$exploded[0];}else{$time='';} 793 | if ($exploded[1]!=='*'){$dow=ucwords($exploded[1],'-').', ';}else{$dow='';} 794 | if ($exploded[2]!=='*'){$date=$exploded[2].' ';}else{$date='';} 795 | if ($exploded[3]!=='*'){$month=ucfirst($exploded[3]).' ';}else{$month='';} 796 | 797 | $dproute['timegroups'][$id]['time'] .=$dow . $month . $date . $time."\\l"; 798 | //$dproute['timegroups'][$id]['time'] .= "\n"; 799 | } 800 | } 801 | 802 | # Users 803 | $query = "select * from users"; 804 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 805 | if (DB::IsError($results)) { 806 | die_freepbx($results->getMessage()."

Error selecting from users"); 807 | } 808 | 809 | foreach($results as $users) { 810 | $Qresult=array(); 811 | $id = $users['extension']; 812 | $u[$id]= $users; 813 | $dproute['extensions'][$id]= $users; 814 | 815 | $Q='grep -E \'^'.$id.'[[:space:]]*[=>]+\' /etc/asterisk/voicemail.conf | cut -d \',\' -f3'; 816 | exec($Q, $Qresult); 817 | if (!empty($Qresult[0])){ 818 | $dproute['extensions'][$id]['email'] =$Qresult[0]; 819 | }else{ 820 | $dproute['extensions'][$id]['email'] ='unassigned'; 821 | } 822 | } 823 | 824 | # Queues 825 | $query = "select * from queues_config"; 826 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 827 | if (DB::IsError($results)) { 828 | die_freepbx($results->getMessage()."

Error selecting from timegroups_details"); 829 | } 830 | foreach($results as $q) { 831 | $id = $q['extension']; 832 | $dproute['queues'][$id] = $q; 833 | $dproute['queues'][$id]['members']['static']=array(); 834 | $dproute['queues'][$id]['members']['dynamic']=array(); 835 | } 836 | 837 | # Queue members (static) 838 | $query = "select * from queues_details"; 839 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 840 | if (DB::IsError($results)) { 841 | die_freepbx($results->getMessage()."

Error selecting from queues_details"); 842 | } 843 | 844 | foreach($results as $qd) { 845 | $id = $qd['id']; 846 | if ($qd['keyword'] == 'member') { 847 | $member = $qd['data']; 848 | if (preg_match("/Local\/(\d+)/", $member, $matches)) { 849 | $enum = $matches[1]; 850 | $dproute['queues'][$id]['members']['static'][]=$enum; 851 | } 852 | } 853 | } 854 | 855 | # Queue members (dynamic) //options 856 | if ($dynmembers){ 857 | foreach ($dproute['queues'] as $id=>$details){ 858 | $dynmem=array(); 859 | $D='/usr/sbin/asterisk -rx "database show QPENALTY '.$id.'" | grep \'/agents/\' | cut -d\'/\' -f5 | cut -d\':\' -f1'; 860 | exec($D, $dynmem); 861 | 862 | foreach ($dynmem as $enum){ 863 | $dproute['queues'][$id]['members']['dynamic'][]=$enum; 864 | } 865 | } 866 | } 867 | 868 | # Inbound Routes 869 | $query = "select * from incoming"; 870 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 871 | if (DB::IsError($results)) { 872 | die_freepbx($results->getMessage()."

Error selecting from incoming"); 873 | } 874 | foreach($results as $incoming) { 875 | $id = $incoming['extension']; 876 | $dproute['incoming'][$id] = $incoming; 877 | } 878 | 879 | # IVRs 880 | $query = "select * from ivr_details"; 881 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 882 | if (DB::IsError($results)) { 883 | die_freepbx($results->getMessage()."

Error selecting from ivr_details"); 884 | } 885 | foreach($results as $ivr) { 886 | $id = $ivr['id']; 887 | $dproute['ivrs'][$id] = $ivr; 888 | } 889 | 890 | # IVR entries 891 | $query = "select * from ivr_entries"; 892 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 893 | if (DB::IsError($results)) { 894 | die_freepbx($results->getMessage()."

Error selecting from ivr_entries"); 895 | } 896 | foreach($results as $ent) { 897 | $id = $ent['ivr_id']; 898 | $selid = $ent['selection']; 899 | dplog(9, "entry: ivr=$id selid=$selid"); 900 | $dproute['ivrs'][$id]['entries'][$selid] = $ent; 901 | } 902 | 903 | # Ring Groups 904 | $query = "select * from ringgroups"; 905 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 906 | if (DB::IsError($results)) { 907 | die_freepbx($results->getMessage()."

Error selecting from ringgroups"); 908 | } 909 | foreach($results as $rg) { 910 | $id = $rg['grpnum']; 911 | $dproute['ringgroups'][$id] = $rg; 912 | } 913 | 914 | # Announcements 915 | $query = "select * from announcement"; 916 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 917 | if (DB::IsError($results)) { 918 | die_freepbx($results->getMessage()."

Error selecting from announcement"); 919 | } 920 | foreach($results as $an) { 921 | $id = $an['announcement_id']; 922 | $dproute['announcements'][$id] = $an; 923 | $dest = $an['post_dest']; 924 | dplog(9, "announcement dest: an=$id dest=$dest"); 925 | $dproute['announcements'][$id]['dest'] = $dest; 926 | } 927 | 928 | # Set Caller ID 929 | $query = "select * from setcid"; 930 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 931 | if (DB::IsError($results)) { 932 | die_freepbx($results->getMessage()."

Error selecting from setcid"); 933 | } 934 | foreach($results as $cid) { 935 | $id = $cid['cid_id']; 936 | $dproute['setcid'][$id] = $cid; 937 | } 938 | 939 | # Misc Destinations 940 | $query = "select * from miscdests"; 941 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 942 | if (DB::IsError($results)) { 943 | die_freepbx($results->getMessage()."

Error selecting from misc destinations"); 944 | } 945 | foreach($results as $miscdest) { 946 | $id = $miscdest['id']; 947 | $dproute['miscdest'][$id] = $miscdest; 948 | dplog(9, "miscdest dest: $id"); 949 | } 950 | 951 | # Conferences (meetme) 952 | $query = "select * from meetme"; 953 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 954 | if (DB::IsError($results)) { 955 | die_freepbx($results->getMessage()."

Error selecting from meetme (conferences)"); 956 | } 957 | foreach($results as $meetme) { 958 | $id = $meetme['exten']; 959 | $dproute['meetme'][$id] = $meetme; 960 | dplog(9, "meetme dest: conf=$id"); 961 | } 962 | 963 | # Directory 964 | $query = "select * from directory_details"; 965 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 966 | if (DB::IsError($results)) { 967 | die_freepbx($results->getMessage()."

Error selecting from directory"); 968 | } 969 | foreach($results as $directory) { 970 | $id = $directory['id']; 971 | $dproute['directory'][$id] = $directory; 972 | dplog(9, "directory=$id"); 973 | } 974 | 975 | # DISA 976 | $query = "select * from disa"; 977 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 978 | if (DB::IsError($results)) { 979 | die_freepbx($results->getMessage()."

Error selecting from disa"); 980 | } 981 | foreach($results as $disa) { 982 | $id = $disa['disa_id']; 983 | $dproute['disa'][$id] = $disa; 984 | dplog(9, "disa=$id"); 985 | } 986 | 987 | # Call Flow Control (day/night) 988 | $query = "select * from daynight"; 989 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 990 | if (DB::IsError($results)) { 991 | die_freepbx($results->getMessage()."

Error selecting from daynight"); 992 | } 993 | foreach($results as $daynight) { 994 | $id = $daynight['ext']; 995 | $dproute['daynight'][$id][] = $daynight; 996 | dplog(9, "daynight=$id"); 997 | } 998 | 999 | # Feature Codes 1000 | $query = "select * from featurecodes"; 1001 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 1002 | if (DB::IsError($results)) { 1003 | die_freepbx($results->getMessage()."

Error selecting from featurecodes"); 1004 | } 1005 | foreach($results as $featurecodes) { 1006 | $id=$featurecodes['defaultcode']; 1007 | $dproute['featurecodes'][$id] = $featurecodes; 1008 | dplog(9, "featurecodes=$id"); 1009 | } 1010 | 1011 | # Recordings 1012 | $query = "select * from recordings"; 1013 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 1014 | if (DB::IsError($results)) { 1015 | die_freepbx($results->getMessage()."

Error selecting from featurecodes"); 1016 | } 1017 | foreach($results as $recordings) { 1018 | $id=$recordings['id']; 1019 | $dproute['recordings'][$id] = $recordings; 1020 | dplog(9, "recordings=$id"); 1021 | } 1022 | 1023 | # Voicemail Blasting 1024 | $query = "select * from vmblast"; 1025 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 1026 | if (DB::IsError($results)) { 1027 | die_freepbx($results->getMessage()."

Error selecting from Voicemail Blasting"); 1028 | } 1029 | foreach($results as $vmblasts) { 1030 | $id = $vmblasts['grpnum']; 1031 | dplog(9, "vmblast: vmblast=$id"); 1032 | $dproute['vmblasts'][$id] = $vmblasts; 1033 | } 1034 | 1035 | # Voicemail Blasting Groups 1036 | $query = "select * from vmblast_groups"; 1037 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 1038 | if (DB::IsError($results)) { 1039 | die_freepbx($results->getMessage()."

Error selecting from Voicemail Blasting Groups"); 1040 | } 1041 | foreach($results as $vmblastsGrp) { 1042 | $id = $vmblastsGrp['grpnum']; 1043 | dplog(9, "vmblast: vmblast=$id"); 1044 | $dproute['vmblasts'][$id]['members'][] = $vmblastsGrp['ext']; 1045 | } 1046 | 1047 | // Array of table names to check 1048 | $tables = ['dynroute', 'dynroute_dests', 'languages']; 1049 | 1050 | foreach ($tables as $table) { 1051 | // Check if the table exists 1052 | $tableExists = $db->getOne("SHOW TABLES LIKE '$table'"); 1053 | 1054 | if (!$tableExists) { 1055 | // Skip to the next table if the current table does not exist 1056 | continue; 1057 | } 1058 | 1059 | $query = "SELECT * FROM $table"; 1060 | $results = $db->getAll($query, DB_FETCHMODE_ASSOC); 1061 | 1062 | if (DB::IsError($results)) { 1063 | // Log the error but continue to check the other tables 1064 | dplog(9, "Error selecting from $table: " . $results->getMessage()); 1065 | continue; // Skip to the next table 1066 | } 1067 | 1068 | if ($table == 'dynroute') { 1069 | foreach ($results as $dynroute) { 1070 | $id = $dynroute['id']; 1071 | $dproute['dynroute'][$id] = $dynroute; 1072 | dplog(9, "dynroute=$id"); 1073 | } 1074 | } elseif ($table == 'dynroute_dests') { 1075 | foreach ($results as $dynroute_dests) { 1076 | $id = $dynroute_dests['dynroute_id']; 1077 | $selid = $dynroute_dests['selection']; 1078 | dplog(9, "dynroute_dests: dynroute=$id match=$selid"); 1079 | $dproute['dynroute'][$id]['routes'][$selid] = $dynroute_dests; 1080 | } 1081 | } elseif ($table == 'languages') { 1082 | foreach($results as $languages) { 1083 | $id=$languages['language_id']; 1084 | $dproute['languages'][$id] = $languages; 1085 | dplog(9, "languages=$id"); 1086 | } 1087 | } 1088 | 1089 | } 1090 | } 1091 | # END load gobs of data. 1092 | 1093 | function sanitizeLabel($text) { 1094 | if ($text === null) { 1095 | $text = ''; 1096 | } 1097 | return htmlentities($text, ENT_QUOTES, 'UTF-8'); 1098 | } 1099 | 1100 | function dplog($level, $msg) { 1101 | global $dp_log_level; 1102 | 1103 | if (!isset($dp_log_level) || $dp_log_level < $level) { 1104 | return; 1105 | } 1106 | 1107 | $ts = date('m-d-Y H:i:s'); 1108 | $logFile = "/var/log/asterisk/cpviz.log"; 1109 | 1110 | $fd = fopen($logFile, "a"); 1111 | if (!$fd) { 1112 | error_log("Couldn't open log file: $logFile"); 1113 | return; 1114 | } 1115 | 1116 | fwrite($fd, "[$ts] [Level $level] $msg\n"); 1117 | fclose($fd); 1118 | } 1119 | 1120 | function secondsToTime($seconds) { 1121 | $seconds = (int) round($seconds); // Ensure whole number input 1122 | 1123 | $hours = (int) ($seconds / 3600); 1124 | $minutes = (int) (($seconds % 3600) / 60); 1125 | $seconds = $seconds % 60; 1126 | 1127 | return $hours > 0 ? "$hours hrs, $minutes mins" : 1128 | ($minutes > 0 ? "$minutes mins, $seconds secs" : "$seconds secs"); 1129 | } 1130 | 1131 | function formatPhoneNumber($phoneNumber) { 1132 | $phoneNumber = preg_replace('/[^0-9]/','',$phoneNumber); 1133 | 1134 | if(strlen($phoneNumber) > 10) { 1135 | $countryCode = substr($phoneNumber, 0, strlen($phoneNumber)-10); 1136 | $areaCode = substr($phoneNumber, -10, 3); 1137 | $nextThree = substr($phoneNumber, -7, 3); 1138 | $lastFour = substr($phoneNumber, -4, 4); 1139 | 1140 | $phoneNumber = '+'.$countryCode.' ('.$areaCode.') '.$nextThree.'-'.$lastFour; 1141 | } 1142 | else if(strlen($phoneNumber) == 10) { 1143 | $areaCode = substr($phoneNumber, 0, 3); 1144 | $nextThree = substr($phoneNumber, 3, 3); 1145 | $lastFour = substr($phoneNumber, 6, 4); 1146 | 1147 | $phoneNumber = '('.$areaCode.') '.$nextThree.'-'.$lastFour; 1148 | } 1149 | 1150 | return $phoneNumber; 1151 | } 1152 | 1153 | function options_get() { 1154 | $row = \FreePBX::Cpviz()->getOptions(); 1155 | $i = 0; 1156 | if(!empty($row) && is_array($row)) { 1157 | foreach ($row as $item) { 1158 | $row[$i] = $item; 1159 | $i++; 1160 | } 1161 | return $row; 1162 | } else { 1163 | return []; 1164 | } 1165 | } 1166 | 1167 | 1168 | ?> 1169 | -------------------------------------------------------------------------------- /graphviz/.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.lock 3 | -------------------------------------------------------------------------------- /graphviz/.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.3 5 | - 5.4 6 | - 5.5 7 | - 5.6 8 | - 7.0 9 | - hhvm 10 | 11 | before_script: 12 | - composer install 13 | -------------------------------------------------------------------------------- /graphviz/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGLOG 2 | 3 | ## 1.1.0 (12/07/2016) 4 | 5 | * [feature] Add methods hasEdge/getEdge on graph (Alexandre Salomé) 6 | * [feature] Add methods getAttribute on node and edge (Alexandre Salomé) 7 | * [feature] Add method get($id) on graph to get a subgraph or a node (Alexandre Salomé) 8 | * [feature] Disable label escaping (Alexandre Salomé) 9 | 10 | ## 1.0.1 (21/05/2014) 11 | 12 | * [bug] Remove semicolon at the end of output (Clemens Tolboom) 13 | 14 | ## 1.0.0 (10/05/2013) 15 | 16 | * [feature] Initial release (Alexandre Salomé) 17 | * [bug] Enable escaping for hyphens (Aurélien Fredouelle) 18 | * [bug] Coding standards and tests (George Petsagourakis) 19 | -------------------------------------------------------------------------------- /graphviz/CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | # Contributors 2 | 3 | ## By order of appearance 4 | 5 | * Alexandre Salomé 6 | * George Petsagourakis 7 | * Aurélien Fredouelle 8 | * Olivier Dolbeau 9 | * Clemens Tolboom 10 | * Oskar Stark 11 | 12 | ## Command used to generate: 13 | 14 | ``` 15 | git log --reverse --format="%aN" \ 16 | | sed "s/alexandresalome/Alexandre Salomé/g" \ 17 | | perl -ne 'if (!defined $x{$_}) { print $_; $x{$_} = 1; }' 18 | ``` 19 | -------------------------------------------------------------------------------- /graphviz/LICENCE: -------------------------------------------------------------------------------- 1 | Copyright (c) Alexandre Salomé 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /graphviz/README.md: -------------------------------------------------------------------------------- 1 | # Graphviz 2 | 3 | ![Build status](https://travis-ci.org/alexandresalome/graphviz.png?branch=master) [![Latest Stable Version](https://poser.pugx.org/alom/graphviz/v/stable)](https://packagist.org/packages/alom/graphviz) [![Total Downloads](https://poser.pugx.org/alom/graphviz/downloads)](https://packagist.org/packages/alom/graphviz) [![License](https://poser.pugx.org/alom/graphviz/license)](https://packagist.org/packages/alom/graphviz) [![Monthly Downloads](https://poser.pugx.org/alom/graphviz/d/monthly)](https://packagist.org/packages/alom/graphviz) [![Daily Downloads](https://poser.pugx.org/alom/graphviz/d/daily)](https://packagist.org/packages/alom/graphviz) 4 | 5 | Graphviz generation for PHP 6 | 7 | * [View CHANGELOG](CHANGELOG.md) 8 | * [View CONTRIBUTORS](CONTRIBUTORS.md) 9 | 10 | [![Build Status](https://secure.travis-ci.org/alexandresalome/graphviz.png?branch=master)](http://travis-ci.org/alexandresalome/graphviz) 11 | 12 | ## Installation 13 | 14 | Install the latest version with: 15 | 16 | ```bash 17 | composer require alom/graphviz 18 | ``` 19 | 20 | ## Usage 21 | 22 | This library allow you to create Dot Graph with a PHP fluid interface: 23 | 24 | ```php 25 | $graph = new Alom\Graphviz\Digraph('G'); 26 | $graph 27 | ->subgraph('cluster_1') 28 | ->attr('node', array('style' => 'filled', 'fillcolor' => 'blue')) 29 | ->node('A') 30 | ->node('B') 31 | ->edge(array('b0', 'b1', 'b2', 'b3')) 32 | ->end() 33 | ->edge(array('A', 'B', 'C')) 34 | ; 35 | echo $graph->render(); 36 | ``` 37 | 38 | ### Escaping of labels 39 | 40 | By default, labels will be escaped, so that your PHP string is represented "as it is" in the graph. If you don't want the label to be escaped, add set the special **_escaped** attribute to false: 41 | 42 | ```php 43 | $graph = new Alom\Graphviz\Digraph('G'); 44 | $graph 45 | ->node('my_table', array( 46 | 'label' => '<...
>', 47 | '_escaped' => false 48 | )) 49 | ``` 50 | 51 | ### Browsing the graph 52 | 53 | When you have created lot of subgraphs and nodes, it might be useful to be able to browse it using identifiers. For example, if you have the following graph: 54 | 55 | ```php 56 | $graph = new Alom\Graphviz\Digraph('G'); 57 | $graph 58 | ->subgraph('cluster_1') 59 | ->node('A') 60 | ->node('B') 61 | ->end() 62 | ->subgraph('cluster_2') 63 | ->node('C') 64 | ->node('D') 65 | ->end() 66 | ->edge(array('C', 'D')) 67 | ; 68 | ``` 69 | 70 | You can do the following to access the nodes in the existing graph: 71 | 72 | ```php 73 | $cluster = $graph->get('cluster_1'); 74 | $node = $graph->get('cluster_2')->get('D'); 75 | ``` 76 | 77 | When you have a node or an edge, you can manipulate its attributes: 78 | 79 | ```php 80 | # read a value 81 | echo $node->getAttribute('label', 'no label'); # second argument is default value 82 | 83 | # write a value 84 | $node->attribute('label', 'new label'); 85 | ``` 86 | 87 | On a graph, you can access or verify edge existence: 88 | 89 | ``` 90 | $graph->hasEdge(array('A', 'B')); 91 | $graph->getEdge(array('C', 'D')); 92 | ``` 93 | 94 | ### Using cluster and record IDs 95 | 96 | If you create an edge from/to an ID inside a record, use an array instead of a string: 97 | 98 | ```php 99 | $graph = new Alom\Graphviz\Digraph('G'); 100 | $graph 101 | ->node('A', array('shape' => 'record', 'label' => '{ <1> Part 1 | <2> Part 2}')) 102 | ->node('B') 103 | ->edge(array('B', array('A', '1'))) 104 | ; 105 | ``` 106 | 107 | As you can see in the example above, the edge is composed of two parts: 108 | 109 | * ``'B'``: a regular node 110 | * ``array('A', '1')``: targets the cell "1" inside the A node 111 | 112 | This method also work for **getEdge**, **hasEdge** and every edge-related method. 113 | 114 | ## Samples 115 | 116 | Take a look at examples located in **samples** folder: 117 | 118 | * [00-readme.php](samples/00-readme.php): Example from graphviz README 119 | * [01-basic.php](samples/01-basic.php): Basic styling of nodes 120 | * [02-table.php](samples/02-table.php): An example for HTML table escaping 121 | 122 | You can generate any of those graph by using the following commands: 123 | 124 | ```bash 125 | php samples/00-readme.php | dot -Tpdf -oout.pdf 126 | xdg-open out.pdf 127 | ``` 128 | -------------------------------------------------------------------------------- /graphviz/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "alom/graphviz", 3 | "description": "Graphviz generation for PHP", 4 | "keywords": ["dot", "graphviz"], 5 | "homepage": "http://github.com/alexandresalome/graphviz", 6 | "type": "library", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Alexandre Salomé", 11 | "email": "alexandre.salome@gmail.com", 12 | "homepage": "http://alexandre-salome.fr" 13 | } 14 | ], 15 | "require": { 16 | "php": ">=5.3.0" 17 | }, 18 | "require-dev": { 19 | "phpunit/phpunit": "3.7.*" 20 | }, 21 | "autoload": { 22 | "psr-0": { 23 | "Alom": "src/" 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /graphviz/phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 14 | 15 | 16 | 17 | tests 18 | 19 | 20 | 21 | 22 | 23 | src 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /graphviz/samples/00-readme.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | require_once __DIR__ . '/../../vendor/autoload.php'; 11 | 12 | $graph = new Alom\Graphviz\Digraph('G'); 13 | 14 | $graph 15 | ->subgraph('cluster_1') 16 | ->attr('node', array('style' => 'filled', 'fillcolor' => 'blue')) 17 | ->node('A') 18 | ->node('B') 19 | ->end() 20 | ->edge(array('A', 'B', 'C')) 21 | ; 22 | 23 | echo $graph->render(); 24 | -------------------------------------------------------------------------------- /graphviz/samples/01-basic.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | require_once __DIR__ . '/../../vendor/autoload.php'; 11 | 12 | $graph = new Alom\Graphviz\Digraph('G'); 13 | $graph 14 | ->subgraph('cluster_0') 15 | ->set('style', 'filled') 16 | ->set('color', 'lightgrey') 17 | ->attr('node', array('style' => 'filled', 'color' => 'white')) 18 | ->edge(array('a0', 'a1', 'a2', 'a3')) 19 | ->set('label', 'process #1') 20 | ->end() 21 | ->subgraph('cluster_1') 22 | ->attr('node', array('style' => 'filled')) 23 | ->edge(array('b0', 'b1', 'b2', 'b3')) 24 | ->set('label', 'process #2') 25 | ->set('color', 'blue') 26 | ->end() 27 | ->edge(array('start', 'a0')) 28 | ->edge(array('start', 'b0')) 29 | ->edge(array('a1', 'b3')) 30 | ->edge(array('b2', 'a3')) 31 | ->edge(array('a3', 'a0')) 32 | ->edge(array('a3', 'end')) 33 | ->edge(array('b3', 'end')) 34 | ; 35 | 36 | echo $graph->render(); 37 | -------------------------------------------------------------------------------- /graphviz/samples/02-table.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | require_once __DIR__ . '/../vendor/autoload.php'; 11 | 12 | $graph = new Alom\Graphviz\Digraph('G'); 13 | $graph 14 | ->node('escaped', array( 15 | 'label' => '<
Should be escaped
>', 16 | )) 17 | ->node('unescaped', array( 18 | 'label' => '<
Should not be escaped
>', 19 | '_escaped' => false, 20 | )) 21 | ->edge(array('escaped', 'unescaped'), array( 22 | 'label' => '<
label
>', 23 | '_escaped' => false, 24 | )) 25 | ; 26 | 27 | echo $graph->render(); 28 | -------------------------------------------------------------------------------- /graphviz/src/Alom/Graphviz/Assign.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | namespace Alom\Graphviz; 11 | 12 | /** 13 | * Graph attribute assignment. 14 | * 15 | * @author Alexandre Salomé 16 | */ 17 | class Assign extends BaseInstruction 18 | { 19 | /** @var string Name of the attribute */ 20 | protected $name; 21 | 22 | /** @var string Value of the assignment */ 23 | protected $value; 24 | 25 | /** 26 | * Creates a new assignment 27 | * 28 | * @param string $name Name of the attribute to set 29 | * @param string $value Value of the attribute 30 | */ 31 | public function __construct($name, $value = NULL) 32 | { 33 | $this->name = $name; 34 | $this->value = $value; 35 | } 36 | 37 | /** 38 | * Returns the name of assignment. 39 | * 40 | * @return string The assignment name 41 | */ 42 | public function getName() 43 | { 44 | return $this->name; 45 | } 46 | 47 | /** 48 | * Returns the value of assignment. 49 | * 50 | * @return string the assignment value 51 | */ 52 | public function getValue() 53 | { 54 | return $this->value; 55 | } 56 | 57 | /** 58 | * Changes the value of assignment. 59 | * 60 | * @param string $value The new value to set 61 | * 62 | * @return Assign Fluid interface 63 | */ 64 | public function setValue($value) 65 | { 66 | $this->value = $value; 67 | 68 | return $this; 69 | } 70 | 71 | /** 72 | * @inheritdoc 73 | */ 74 | public function render($indent = 0, $spaces = self::DEFAULT_INDENT) 75 | { 76 | return str_repeat($spaces, $indent) . $this->renderInlineAssignment($this->name, $this->value) . ";\n"; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /graphviz/src/Alom/Graphviz/AttributeBag.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | namespace Alom\Graphviz; 11 | 12 | /** 13 | * Attribute holder for nodes and edges. 14 | * 15 | * @author Alexandre Salomé 16 | */ 17 | class AttributeBag extends BaseInstruction 18 | { 19 | /** @var array Associative array of attributes. The key is the name. */ 20 | protected $attributes; 21 | 22 | /** 23 | * Creates a new attribute bag. 24 | * 25 | * @param array $attributes An associative array of attributes values 26 | */ 27 | public function __construct(array $attributes = array()) 28 | { 29 | if (isset($attributes['_escaped'])) { 30 | $escaped = $attributes['_escaped']; 31 | unset($attributes['_escaped']); 32 | } else { 33 | $escaped = true; 34 | } 35 | 36 | if (!$escaped && isset($attributes['label'])) { 37 | $attributes['label'] = new RawText($attributes['label']); 38 | } 39 | 40 | $this->attributes = $attributes; 41 | } 42 | 43 | /** 44 | * Changes the value of an attribute. 45 | * 46 | * @param string $name The name for the attribute 47 | * @param string $value Value to set 48 | * 49 | * @return AttributeBag Fluid interface 50 | */ 51 | public function set($name, $value) 52 | { 53 | $this->attributes[$name] = $value; 54 | 55 | return $this; 56 | } 57 | 58 | /** 59 | * Returns the value of an attribute. 60 | * 61 | * @param string $name The name for the attribute 62 | * @param string $default Default value if attribute is not set. 63 | * 64 | * @return string|mixed The attribute value 65 | */ 66 | public function get($name, $default = null) 67 | { 68 | return isset($this->attributes[$name]) ? $this->attributes[$name] : $default; 69 | } 70 | 71 | /** 72 | * Tests if the bag has an attribute. 73 | * 74 | * @param string $name The attribute name to check 75 | * 76 | * @return boolean Result of the test 77 | */ 78 | public function has($name) 79 | { 80 | return isset($this->attributes[$name]); 81 | } 82 | 83 | /** 84 | * @inheritdoc 85 | */ 86 | public function render($indent = 0, $spaces = self::DEFAULT_INDENT) 87 | { 88 | if (0 == count($this->attributes)) { 89 | return ''; 90 | } 91 | 92 | $exp = array(); 93 | foreach ($this->attributes as $name => $value) { 94 | $exp[] = $this->renderInlineAssignment($name, $value); 95 | } 96 | 97 | return '[' . implode(', ', $exp) . ']'; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /graphviz/src/Alom/Graphviz/AttributeSet.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | namespace Alom\Graphviz; 11 | 12 | /** 13 | * Attributes bag for node/edge/graph 14 | * 15 | * @author Alexandre Salomé 16 | */ 17 | class AttributeSet extends BaseInstruction 18 | { 19 | /** @var string Name of shape to set attributes */ 20 | protected $name; 21 | 22 | /** @var AttributeBag Attribute bag */ 23 | protected $attributes; 24 | 25 | /** 26 | * Creates a new attribute set 27 | * 28 | * @param string $name Name of the attribute set 29 | * @param array $attributes 30 | * 31 | * @throws \InvalidArgumentException 32 | */ 33 | public function __construct($name, array $attributes = array()) 34 | { 35 | if (!in_array($name, array('node', 'edge', 'graph'))) { 36 | throw new \InvalidArgumentException(sprintf('Name invalid for attribute set : %s', $name)); 37 | } 38 | 39 | $this->name = $name; 40 | $this->attributes = new AttributeBag($attributes); 41 | } 42 | 43 | /** 44 | * @return string 45 | */ 46 | public function getName() 47 | { 48 | return $this->name; 49 | } 50 | 51 | /** 52 | * @return AttributeBag 53 | */ 54 | public function getAttributes() 55 | { 56 | return $this->attributes; 57 | } 58 | 59 | /** 60 | * @inheritdoc 61 | */ 62 | public function render($indent = 0, $spaces = self::DEFAULT_INDENT) 63 | { 64 | return str_repeat($spaces, $indent) . $this->name . ' ' . $this->attributes->render() . ";\n"; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /graphviz/src/Alom/Graphviz/BaseInstruction.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | namespace Alom\Graphviz; 11 | 12 | /** 13 | * Base class for Graphviz instructions. 14 | * 15 | * @author Alexandre Salomé 16 | */ 17 | abstract class BaseInstruction implements InstructionInterface 18 | { 19 | /** 20 | * Renders an inline assignment (without indent or end return line). 21 | * 22 | * It will handle escaping, according to the value. 23 | * 24 | * @param string $name A name 25 | * @param string $value A value 26 | * 27 | * @return string 28 | */ 29 | protected function renderInlineAssignment($name, $value) 30 | { 31 | if ($value instanceof RawText) { 32 | $value = $value->getText(); 33 | } else { 34 | $value = $this->escape($value); 35 | } 36 | 37 | return $this->escape($name).'='.$value; 38 | } 39 | 40 | /** 41 | * Escapes a value if needed. 42 | * 43 | * @param string $value The value to set 44 | * 45 | * @return string The escaped string 46 | */ 47 | protected function escape($value) 48 | { 49 | dplog(5, "in escape: value: $value"); 50 | dplog(5, "in escape: print_r(value): " . print_r($value,true)); 51 | $x = ($this->needsEscaping($value)) ? '"' . str_replace('"', '""', str_replace('\\', '\\\\', $value)) . '"' : $value; 52 | dplog(5, "in escape: value2: $x"); 53 | return ($this->needsEscaping($value)) ? '"' . str_replace('"', '""', str_replace('\\', '\\\\', $value)) . '"' : $value; 54 | } 55 | 56 | protected function escapePath(array $path) 57 | { 58 | dplog(9, "in escapePath: value: zzzzz"); 59 | $list = array(); 60 | foreach ($path as $element) { 61 | $list[] = $this->escape($element); 62 | } 63 | 64 | return implode(':', $list); 65 | } 66 | 67 | /** 68 | * Tests if a string needs escaping. 69 | * 70 | * @param string $value 71 | * 72 | * @return boolean Result of test 73 | */ 74 | protected function needsEscaping($value) 75 | { 76 | return preg_match('/[{} "#-:\\\\\\/\\.,]/', $value) || in_array($value, array('graph', 'node', 'edge')) || empty($value); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /graphviz/src/Alom/Graphviz/Digraph.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | namespace Alom\Graphviz; 11 | 12 | /** 13 | * Directed graph 14 | * 15 | * @author Alexandre Salomé 16 | */ 17 | class Digraph extends Graph 18 | { 19 | /** 20 | * @inheritdoc 21 | */ 22 | protected function createEdge($list, array $attributes = array(), BaseInstruction $parent = null) 23 | { 24 | return new DirectedEdge($list, $attributes, $parent); 25 | } 26 | 27 | /** 28 | * @inheritdoc 29 | */ 30 | protected function getHeader($id) 31 | { 32 | return 'digraph ' . $id; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /graphviz/src/Alom/Graphviz/DirectedEdge.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | namespace Alom\Graphviz; 11 | 12 | /** 13 | * Directed edge 14 | * 15 | * @author Alexandre Salomé 16 | */ 17 | class DirectedEdge extends Edge 18 | { 19 | /** 20 | * @inheritdoc 21 | */ 22 | protected function getOperator() 23 | { 24 | return ' -> '; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /graphviz/src/Alom/Graphviz/Edge.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | namespace Alom\Graphviz; 11 | 12 | /** 13 | * Base edge class 14 | * 15 | * @author Alexandre Salomé 16 | */ 17 | abstract class Edge extends BaseInstruction 18 | { 19 | /** @var array List of elements */ 20 | protected $list; 21 | 22 | /** @var AttributeBag Attributes of the edge */ 23 | protected $attributes; 24 | 25 | /** @var BaseInstruction Parent instruction */ 26 | protected $parent; 27 | 28 | /** 29 | * Returns operator for associating elements 30 | * 31 | * @return string The operator 32 | */ 33 | abstract protected function getOperator(); 34 | 35 | /** 36 | * Creates an edge. 37 | * 38 | * @param array $list List of edges 39 | * @param array $attributes Associative array of attributes 40 | * @param BaseInstruction $parent Parent instruction 41 | */ 42 | public function __construct(array $list, array $attributes = array(), BaseInstruction $parent = NULL) 43 | { 44 | $this->list = $list; 45 | $this->attributes = new AttributeBag($attributes); 46 | $this->parent = $parent; 47 | } 48 | 49 | /** 50 | * Returns list of elements composing the edge. 51 | * 52 | * @return array 53 | */ 54 | public function getList() 55 | { 56 | return $this->list; 57 | } 58 | 59 | /** 60 | * Returns the value of an attribute of the edge. 61 | * 62 | * @param string $name name of the attribute 63 | * @param mixed $default default value if the attribute does not exist 64 | */ 65 | public function getAttribute($name, $default = null) 66 | { 67 | return $this->attributes->get($name, $default); 68 | } 69 | 70 | /** 71 | * Sets an attribute. 72 | * 73 | * @param string $name Name of the attribute to set 74 | * @param string $value Value of the attribute to set 75 | * 76 | * @return Edge Fluid-interface 77 | */ 78 | public function attribute($name, $value) 79 | { 80 | $this->attributes->set($name, $value); 81 | 82 | return $this; 83 | } 84 | 85 | /** 86 | * Returns list of attributes. 87 | * 88 | * @return AttributeBag 89 | */ 90 | public function getAttributes() 91 | { 92 | return $this->attributes; 93 | } 94 | 95 | /** 96 | * @inheritdoc 97 | */ 98 | public function render($indent = 0, $spaces = self::DEFAULT_INDENT) 99 | { 100 | $edges = array(); 101 | foreach ($this->list as $edge) { 102 | // Each element of the list should be a node, right? So why are we 103 | // calling them edges, for a start? And why are we sending objects to 104 | // a function that escapes strings. Either this is really brain damaged 105 | // or there is something i fundamentally do not understand here. 106 | // 107 | // I'm commenting out the code that was here and replacing it with node->getId() 108 | // cheeks 8/4/18 109 | $edges[] = $this->escape($edge->getId()); 110 | 111 | /* 112 | if (is_array($edge)) { 113 | $edges[] = $this->escapePath($edge); 114 | } else { 115 | $edges[] = $this->escape($edge); 116 | } 117 | */ 118 | } 119 | 120 | $edge = implode($this->getOperator(), $edges); 121 | 122 | $attributes = $this->attributes->render($indent + 1); 123 | return str_repeat($spaces, $indent) . $edge . ($attributes ? ' ' . $attributes : $attributes) . ";\n"; 124 | } 125 | 126 | /** 127 | * End function for fluid-interface. 128 | * 129 | * @return BaseInstruction|null The parent or null 130 | */ 131 | public function end() 132 | { 133 | return $this->parent; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /graphviz/src/Alom/Graphviz/Graph.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | namespace Alom\Graphviz; 11 | 12 | /** 13 | * Base graph instruction. 14 | * 15 | * @author Alexandre Salomé 16 | */ 17 | abstract class Graph extends BaseInstruction 18 | { 19 | /** @var BaseInstruction Parent node */ 20 | protected $parent; 21 | 22 | /** @var string Graph identifier */ 23 | protected $id; 24 | 25 | /** @var string Name of the graph */ 26 | protected $name; 27 | 28 | /** @var BaseInstruction[] Instructions list */ 29 | protected $instructions = array(); 30 | 31 | /** 32 | * Creates a new edge for the graph. 33 | * 34 | * @param array $list List of elements of the edge 35 | * @param array $attributes Associative array of attributes 36 | * @param BaseInstruction $parent Parent element 37 | * 38 | * @return Edge The created edge 39 | */ 40 | abstract protected function createEdge($list, array $attributes = array(), BaseInstruction $parent = null); 41 | 42 | /** 43 | * Returns the graph header (digraph G as example). 44 | * 45 | * @param string $id Identifier of graph 46 | * 47 | * @return string The graph header 48 | */ 49 | abstract protected function getHeader($id); 50 | 51 | /** 52 | * Creates a new graph. 53 | * 54 | * @param string $id Identifier of the graph 55 | * @param BaseInstruction $parent Parent element 56 | */ 57 | public function __construct($id, $parent = null) 58 | { 59 | $this->parent = $parent; 60 | $this->id = $id; 61 | } 62 | 63 | /** 64 | * Returns identifier of graph. 65 | * 66 | * @return string 67 | */ 68 | public function getId() 69 | { 70 | return $this->id; 71 | } 72 | 73 | /** 74 | * Adds a new instruction to graph. 75 | * 76 | * @param InstructionInterface $instruction Instruction to add 77 | * 78 | * @return Graph Fluid-interface 79 | */ 80 | public function append(InstructionInterface $instruction) 81 | { 82 | $this->instructions[] = $instruction; 83 | 84 | return $this; 85 | } 86 | 87 | /** 88 | * Returns list of instructions. 89 | * 90 | * @return array 91 | */ 92 | public function getInstructions() 93 | { 94 | return $this->instructions; 95 | } 96 | 97 | /** 98 | * Returns a node or a subgraph, given his id. 99 | * 100 | * @param string $id the identifier of the node/graph to fetch 101 | * 102 | * @return Node|Graph 103 | * 104 | * @throws InvalidArgumentException node or graph not found 105 | */ 106 | public function get($id) 107 | { 108 | foreach ($this->instructions as $instruction) { 109 | if (!$instruction instanceof Node && !$instruction instanceof Subgraph) { 110 | continue; 111 | } 112 | 113 | if ($instruction->getId() == $id) { 114 | return $instruction; 115 | } 116 | } 117 | 118 | throw new \InvalidArgumentException(sprintf('Found no node or graph with id "%s" in "%s".', $id, $this->id)); 119 | } 120 | 121 | /** 122 | * Tests if the graph has an edge. 123 | * 124 | * @param (string|string[])[] a path 125 | * 126 | * @return boolean 127 | */ 128 | public function hasEdge(array $edge) 129 | { 130 | try { 131 | $this->getEdge($edge); 132 | 133 | return true; 134 | } catch (\InvalidArgumentException $e) { 135 | return false; 136 | } 137 | } 138 | 139 | /** 140 | * Returns an edge by its path. 141 | * 142 | * @param (string|string[])[] a path 143 | * 144 | * @return Edge 145 | * 146 | * @throws InvalidArgumentException path not found 147 | */ 148 | public function getEdge(array $edge) 149 | { 150 | foreach ($this->instructions as $instruction) { 151 | if (!$instruction instanceof Edge) { 152 | continue; 153 | } 154 | 155 | if ($instruction->getList() == $edge) { 156 | return $instruction; 157 | } 158 | } 159 | 160 | $label = implode(' -> ', array_map(function ($edge) { 161 | if (is_string($edge)) { 162 | return $edge; 163 | } 164 | 165 | /* added this because the latest FreePBX with PHP 5.6.40 was throwing 166 | an exception if edge was not an array. When I print_r($edge) 167 | in that case, it's an Edge object. cheeks@swcp.com 9/18/19 */ 168 | if (is_array($edge)) { 169 | return implode(':', $edge); 170 | } 171 | }, $edge)); 172 | 173 | throw new \InvalidArgumentException(sprintf('Found no edge "%s".', $label)); 174 | } 175 | 176 | /** 177 | * Adds an assignment instruction. 178 | * 179 | * @param string $name Name of the value to assign 180 | * @param string $value Value to assign 181 | * 182 | * @throws \InvalidArgumentException 183 | * @return Graph Fluid-interface 184 | */ 185 | public function set($name, $value) 186 | { 187 | if (in_array($name, array('graph', 'node', 'edge'))) { 188 | throw new \InvalidArgumentException(sprintf('Use method attr for setting %s', $name)); 189 | } 190 | 191 | $this->instructions[] = new Assign($name, $value); 192 | 193 | return $this; 194 | } 195 | 196 | /** 197 | * Define attributes for node/edge/graph. 198 | * 199 | * @param string $name Name of type 200 | * @param array $attributes Attributes of the type 201 | * 202 | * @return \Alom\Graphviz\Graph 203 | */ 204 | public function attr($name, array $attributes) 205 | { 206 | $this->instructions[] = new AttributeSet($name, $attributes); 207 | 208 | return $this; 209 | } 210 | 211 | /** 212 | * Starts a subgraph. 213 | * 214 | * @param string $id Identifier of subgraph 215 | * 216 | * @return Subgraph 217 | */ 218 | public function subgraph($id) 219 | { 220 | return $this->instructions[] = new Subgraph($id, $this); 221 | } 222 | 223 | /** 224 | * Created a new node on graph. 225 | * 226 | * @param string $id Identifier of node 227 | * @param array $attributes Attributes to set on node 228 | * 229 | * @return Graph Fluid-interface 230 | */ 231 | public function node($id, array $attributes = array()) 232 | { 233 | $this->instructions[] = new Node($id, $attributes, $this); 234 | 235 | return $this; 236 | } 237 | 238 | /** 239 | * Created a new node on graph. 240 | * 241 | * @param string $id Identifier of node 242 | * @param array $attributes Attributes to set on node 243 | * 244 | * @return Node 245 | */ 246 | public function beginNode($id, array $attributes = array()) 247 | { 248 | return $this->instructions[] = new Node($id, $attributes, $this); 249 | } 250 | 251 | /** 252 | * Created a new edge on graph. 253 | * 254 | * @param array $list List of edges 255 | * @param array $attributes Attributes to set on edge 256 | * 257 | * @return Graph Fluid-interface 258 | */ 259 | public function edge($list, array $attributes = array()) 260 | { 261 | $this->instructions[] = $this->createEdge($list, $attributes, $this); 262 | 263 | return $this; 264 | } 265 | 266 | /** 267 | * Created a new edge on graph. 268 | * 269 | * @param array $list List of edges 270 | * @param array $attributes Attributes to set on edge 271 | * 272 | * @return Edge 273 | */ 274 | public function beginEdge($list, array $attributes = array()) 275 | { 276 | return $this->instructions[] = $this->createEdge($list, $attributes, $this); 277 | } 278 | 279 | /** 280 | * Fluid-interface to access parent. 281 | * 282 | * @return Graph 283 | */ 284 | public function end() 285 | { 286 | return $this->parent; 287 | } 288 | 289 | /** 290 | * @inheritdoc 291 | */ 292 | public function render($indent = 0, $spaces = self::DEFAULT_INDENT) 293 | { 294 | $margin = str_repeat($spaces, $indent); 295 | $result = $margin . $this->getHeader($this->id) . ' {' . "\n"; 296 | foreach ($this->instructions as $instruction) { 297 | $result .= $instruction->render($indent + 1, $spaces); 298 | } 299 | $result .= $margin . '}' . "\n"; 300 | 301 | return $result; 302 | } 303 | } 304 | -------------------------------------------------------------------------------- /graphviz/src/Alom/Graphviz/InstructionInterface.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | namespace Alom\Graphviz; 11 | 12 | /** 13 | * Interface of Graphviz instructions. 14 | * 15 | * @author Alexandre Salomé 16 | */ 17 | interface InstructionInterface 18 | { 19 | const DEFAULT_INDENT = ' '; 20 | 21 | /** 22 | * Renders the assign statement. 23 | * 24 | * @param int $indent Current level of indentation 25 | * @param string $spaces 26 | * 27 | * @return string The rendered line 28 | */ 29 | function render($indent = 0, $spaces = self::DEFAULT_INDENT); 30 | } 31 | -------------------------------------------------------------------------------- /graphviz/src/Alom/Graphviz/Node.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | namespace Alom\Graphviz; 11 | 12 | /** 13 | * Node instruction. 14 | * 15 | * @author Alexandre Salomé 16 | */ 17 | class Node extends BaseInstruction 18 | { 19 | /** @var Graph Parent instruction. */ 20 | protected $parent; 21 | 22 | /** @var string Identifier of the node. */ 23 | protected $id; 24 | 25 | /** @var AttributeBag Attributes of the node. */ 26 | protected $attributes; 27 | 28 | /** 29 | * Creates a new node. 30 | * 31 | * @param string $id Identifier of the node 32 | * @param array $attributes Attributes to set on node 33 | * @param Graph $parent Parent instruction 34 | */ 35 | public function __construct($id, array $attributes = array(), $parent = null) 36 | { 37 | $this->parent = $parent; 38 | $this->id = $id; 39 | $this->attributes = new AttributeBag($attributes); 40 | } 41 | 42 | /** 43 | * Returns identifier of the node. 44 | * 45 | * @return string Identifier of the node 46 | */ 47 | public function getId() 48 | { 49 | return $this->id; 50 | } 51 | 52 | /** 53 | * Returns attributes of the graph. 54 | * 55 | * @return AttributeBag 56 | */ 57 | public function getAttributes() 58 | { 59 | return $this->attributes; 60 | } 61 | 62 | /** 63 | * Returns the value of an attribute of the node. 64 | * 65 | * @param string $name name of the attribute 66 | * @param mixed $default default value if the attribute does not exist 67 | */ 68 | public function getAttribute($name, $default = null) 69 | { 70 | return $this->attributes->get($name, $default); 71 | } 72 | 73 | /** 74 | * Sets an attribute of node. 75 | * 76 | * @param string $name Name of the attribute to set 77 | * @param string $value Value to set 78 | * 79 | * @return \Alom\Graphviz\Node 80 | */ 81 | public function attribute($name, $value) 82 | { 83 | $this->attributes->set($name, $value); 84 | 85 | return $this; 86 | } 87 | 88 | /** 89 | * Fluid interface method. 90 | * 91 | * @return Graph 92 | */ 93 | public function end() 94 | { 95 | return $this->parent; 96 | } 97 | 98 | /** 99 | * @inheritdoc 100 | */ 101 | public function render($indent = 0, $spaces = self::DEFAULT_INDENT) 102 | { 103 | $attributes = $this->attributes->render($indent + 1, $spaces); 104 | 105 | return str_repeat($spaces, $indent) . $this->escape($this->id) . ($attributes ? ' ' . $attributes : '') . ";\n"; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /graphviz/src/Alom/Graphviz/RawText.php: -------------------------------------------------------------------------------- 1 | text = $text; 12 | } 13 | 14 | public function getText() 15 | { 16 | return $this->text; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /graphviz/src/Alom/Graphviz/Subgraph.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | namespace Alom\Graphviz; 11 | 12 | /** 13 | * Subgraph 14 | * 15 | * @author Alexandre Salomé 16 | */ 17 | class Subgraph extends Graph 18 | { 19 | /** 20 | * @inheritdoc 21 | */ 22 | protected function createEdge($list, array $attributes = array(), BaseInstruction $parent = null) 23 | { 24 | $currentParent = $parent; 25 | while ($currentParent !== null) { 26 | if ($currentParent instanceof Digraph) { 27 | return new DirectedEdge($list, $attributes, $parent); 28 | } 29 | 30 | $currentParent = $parent->end(); 31 | } 32 | 33 | throw new \LogicException('Unable to find edge type'); 34 | } 35 | 36 | /** 37 | * @inheritdoc 38 | */ 39 | protected function getHeader($id) 40 | { 41 | return 'subgraph ' . $id; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /graphviz/tests/Alom/Graphviz/Tests/AssignTest.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | namespace Alom\Graphviz\Tests; 11 | 12 | use Alom\Graphviz\Assign; 13 | 14 | class AssignTest extends \PHPUnit_Framework_TestCase 15 | { 16 | public function testValue() 17 | { 18 | 19 | $assign = new Assign('foo'); 20 | $this->assertEquals(null, $assign->getValue(), "Default value"); 21 | 22 | $return = $assign->setValue('bar'); 23 | $this->assertEquals('bar', $assign->getValue(), "Value getter is correct"); 24 | $this->assertSame($return, $assign); 25 | } 26 | 27 | public function testName() 28 | { 29 | $assign = new Assign('foo'); 30 | $this->assertEquals('foo', $assign->getName(), "name getter"); 31 | } 32 | 33 | public function testRender() 34 | { 35 | $assign = new Assign('foo', ''); 36 | $this->assertEquals("foo=\"\";\n", $assign->render(), "Empty string"); 37 | 38 | $assign = new Assign('foo', '#bar'); 39 | $this->assertEquals("foo=\"#bar\";\n", $assign->render(), "Escaping"); 40 | 41 | $assign = new Assign('foo', 'a-b'); 42 | $this->assertEquals("foo=\"a-b\";\n", $assign->render(), "Escaping hyphens"); 43 | 44 | $assign = new Assign('foo', 'bar'); 45 | $this->assertEquals("foo=bar;\n", $assign->render(), "Render method with simple strings"); 46 | $this->assertEquals(" foo=bar;\n", $assign->render(1), "Render method with indent"); 47 | $this->assertEquals(" foo=bar;\n", $assign->render(1, " "), "Render method with indent and spaces"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /graphviz/tests/Alom/Graphviz/Tests/AttributeBagTest.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | namespace Alom\Graphviz\Tests; 11 | 12 | use Alom\Graphviz\AttributeBag; 13 | 14 | class AttributeBagTest extends \PHPUnit_Framework_TestCase 15 | { 16 | public function testGetterSetterHasser() 17 | { 18 | $bag = new AttributeBag(array('foo' => 'bar', 'bar' => 'baz')); 19 | 20 | $this->assertEquals('bar', $bag->get('foo'), "Get existing"); 21 | $this->assertTrue($bag->has('foo'), "has() with existing"); 22 | 23 | $this->assertFalse($bag->has('baz'), "has() with inexisting"); 24 | $this->assertNull($bag->get('baz'), "Inexisting"); 25 | $this->assertFalse($bag->get('baz', false), "Default value"); 26 | 27 | $bag->set('name', 'alice'); 28 | $this->assertEquals('alice', $bag->get('name')); 29 | } 30 | 31 | public function testRender() 32 | { 33 | $bag = new AttributeBag(); 34 | $this->assertEquals('', $bag->render(), "Empty attribute bag"); 35 | 36 | $bag->set('foo', 'bar'); 37 | $this->assertEquals('[foo=bar]', $bag->render(), "Render with one simple string"); 38 | 39 | $bag->set('bar', 'foo bar'); 40 | $this->assertEquals('[foo=bar, bar="foo bar"]', $bag->render(), "Render with multiple attributes"); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /graphviz/tests/Alom/Graphviz/Tests/AttributeSetTest.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | namespace Alom\Graphviz\Tests; 11 | 12 | use Alom\Graphviz\AttributeSet; 13 | 14 | class AttributeSetTest extends \PHPUnit_Framework_TestCase 15 | { 16 | public function testGetters() 17 | { 18 | $set = new AttributeSet('node', array('foo' => 'bar')); 19 | 20 | $this->assertEquals('node', $set->getName(), "getName"); 21 | $this->assertEquals('bar', $set->getAttributes()->get('foo'), "Attributes"); 22 | } 23 | 24 | public function testRender() 25 | { 26 | $set = new AttributeSet('node', array('foo' => 'bar')); 27 | 28 | $this->assertEquals("node [foo=bar];\n", $set->render(), "Simple render"); 29 | $this->assertEquals(" node [foo=bar];\n", $set->render(1), "Render with indent"); 30 | $this->assertEquals(" node [foo=bar];\n", $set->render(1, " "), "Render with indent and spaces"); 31 | } 32 | 33 | /** 34 | * @dataProvider provideIncorrectElement 35 | */ 36 | public function testElement($element, $isCorrect) 37 | { 38 | if (!$isCorrect) { 39 | $this->setExpectedException('InvalidArgumentException'); 40 | } 41 | $set = new AttributeSet($element); 42 | } 43 | 44 | public function provideIncorrectElement() 45 | { 46 | return array( 47 | array('node', true), 48 | array('edge', true), 49 | array('graph', true), 50 | array('foo', false) 51 | ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /graphviz/tests/Alom/Graphviz/Tests/DigraphTest.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | namespace Alom\Graphviz\Tests; 11 | 12 | use Alom\Graphviz\Assign; 13 | use Alom\Graphviz\AttributeSet; 14 | use Alom\Graphviz\Digraph; 15 | use Alom\Graphviz\DirectedEdge; 16 | use Alom\Graphviz\Node; 17 | use Alom\Graphviz\Subgraph; 18 | 19 | class DigraphTest extends \PHPUnit_Framework_TestCase 20 | { 21 | public function testGet() 22 | { 23 | $graph = new Digraph('G'); 24 | $graph->subgraph('foo') 25 | ->node('bar', array('label' => 'baz')) 26 | ; 27 | 28 | $this->assertEquals('baz', $graph->get('foo')->get('bar')->getAttribute('label')); 29 | } 30 | 31 | public function testGet_NotExisting() 32 | { 33 | $graph = new Digraph('G'); 34 | $graph->node('foo'); 35 | 36 | try { 37 | $graph->get('bar'); 38 | $this->fail(); 39 | } catch (\InvalidArgumentException $e) { 40 | // ok 41 | } 42 | } 43 | 44 | public function testGetEdge() 45 | { 46 | $graph = new Digraph('G'); 47 | $graph->edge(array('A', 'B')); 48 | $graph->edge(array('B', array('C', '1'))); 49 | 50 | $edge = $graph->getEdge(array('A', 'B')); 51 | $this->assertEquals(array('A', 'B'), $edge->getList()); 52 | 53 | $edge = $graph->getEdge(array('B', array('C', '1'))); 54 | $this->assertEquals(array('B', array('C', 1)), $edge->getList()); 55 | } 56 | 57 | public function testGetEdge_notExisting() 58 | { 59 | $graph = new Digraph('G'); 60 | $graph->edge(array('A', 'B')); 61 | $graph->edge(array('B', array('C', '1'))); 62 | 63 | try { 64 | $edge = $graph->getEdge(array('A', 'C')); 65 | $this->fail(); 66 | } catch (\InvalidArgumentException $e) { 67 | $this->assertEquals('Found no edge "A -> C".', $e->getMessage()); 68 | } 69 | 70 | try { 71 | $edge = $graph->getEdge(array('A', array('C', '2'))); 72 | $this->fail(); 73 | } catch (\InvalidArgumentException $e) { 74 | $this->assertEquals('Found no edge "A -> C:2".', $e->getMessage()); 75 | } 76 | } 77 | 78 | public function testRawText() 79 | { 80 | $graph = new Digraph('G'); 81 | $node = $graph->beginNode('foo', array( 82 | 'label' => 'baz>', 83 | '_escaped' => false 84 | )); 85 | 86 | $this->assertInstanceOf('Alom\Graphviz\RawText', $node->getAttributes()->get('label')); 87 | $this->assertEquals("digraph G {\n foo [label=baz>];\n}\n", $graph->render()); 88 | } 89 | 90 | public function testRender() 91 | { 92 | $graph = new Digraph('G'); 93 | 94 | $this->assertEquals("digraph G {\n}\n", $graph->render(), "Render empty graph"); 95 | $this->assertEquals(" digraph G {\n }\n", $graph->render(1), "Render empty graph with indent"); 96 | $this->assertEquals(" digraph G {\n }\n", $graph->render(1, " "), "Render empty graph with indent and spaces"); 97 | 98 | $mock = $this->getMock('Alom\Graphviz\InstructionInterface', array('render')); 99 | 100 | $mock 101 | ->expects($this->once()) 102 | ->method('render') 103 | ->with(2, " ") 104 | ->will($this->returnValue(" foobarbaz;\n")) 105 | ; 106 | 107 | $graph->append($mock); 108 | 109 | $this->assertEquals(" digraph G {\n foobarbaz;\n }\n", $graph->render(1, " "), "Render with statements"); 110 | } 111 | 112 | public function testFluidInterfaceShort() 113 | { 114 | $graph = new Digraph('G'); 115 | 116 | $graph 117 | ->set('rankdir', 'LR') 118 | ->node('A') 119 | ->node('B') 120 | ->edge(array('A', 'B')) 121 | ; 122 | 123 | $this->assertCount(4, $instructions = $graph->getInstructions(), "3 instructions"); 124 | 125 | $this->assertTrue($instructions[0] instanceof Assign, "First instruction is assignment"); 126 | $this->assertEquals('rankdir', $instructions[0]->getName(), "First instruction name"); 127 | $this->assertEquals('LR', $instructions[0]->getValue(), "First instruction value"); 128 | 129 | $this->assertTrue($instructions[1] instanceof Node, "Second instruction is a node"); 130 | $this->assertEquals("A", $instructions[1]->getId(), "Id of first node"); 131 | 132 | $this->assertTrue($instructions[2] instanceof Node, "Third instruction is a node"); 133 | $this->assertEquals("B", $instructions[2]->getId(), "Id of second node"); 134 | 135 | $this->assertTrue($instructions[3] instanceof DirectedEdge, "Fourth instruction is an edge"); 136 | } 137 | 138 | public function testFluidInterfaceVerbose() 139 | { 140 | $graph = new Digraph('G'); 141 | 142 | $graph 143 | ->beginNode('A') 144 | ->attribute('color', 'red') 145 | ->end() 146 | ->beginEdge(array('A', 'B')) 147 | ->attribute('color', 'blue') 148 | ->end() 149 | ; 150 | 151 | $this->assertCount(2, $instructions = $graph->getInstructions(), "2 instructions"); 152 | 153 | $this->assertTrue($instructions[0] instanceof Node, "First instructions is a node"); 154 | $this->assertEquals('A', $instructions[0]->getId(), "Node identifier"); 155 | $this->assertEquals('red', $instructions[0]->getAttributes()->get('color'), "Node attribute"); 156 | 157 | $this->assertTrue($instructions[1] instanceof DirectedEdge, "Second instructions is a node"); 158 | $this->assertEquals('blue', $instructions[1]->getAttributes()->get('color'), "Edge attribute"); 159 | } 160 | 161 | public function testAttr() 162 | { 163 | $graph = new Digraph('G'); 164 | $graph->attr('node', array('color' => 'blue')); 165 | 166 | $this->assertCount(1, $instructions = $graph->getInstructions(), "Instruction count"); 167 | $this->assertTrue($instructions[0] instanceof AttributeSet, "Instruction is an attribute set"); 168 | $this->assertEquals("node", $instructions[0]->getName(), "Name is correct"); 169 | $this->assertEquals("blue", $instructions[0]->getAttributes()->get('color'), "Attribute is correct"); 170 | } 171 | 172 | /** 173 | * @expectedException InvalidArgumentException 174 | * @dataProvider provideIncorrectSetUsage 175 | */ 176 | public function testIncorrectSetUsage($name) 177 | { 178 | $graph = new Digraph('G'); 179 | $graph->set($name, 'foo'); 180 | } 181 | 182 | public function provideIncorrectSetUsage() 183 | { 184 | return array( 185 | array('graph'), 186 | array('edge'), 187 | array('node'), 188 | ); 189 | } 190 | 191 | public function testSubGraph() 192 | { 193 | $graph = new Digraph('G'); 194 | $subgraph = $graph->subgraph('foo'); 195 | $subgraph->edge(array('A', 'B')); 196 | 197 | $this->assertCount(1, $graph->getInstructions(), "Count of instructions"); 198 | $this->assertTrue($subgraph instanceof Subgraph, "Subgraph return"); 199 | $this->assertSame('foo', $subgraph->getId(), "Subgraph identifier"); 200 | $this->assertSame($graph, $subgraph->end(), "Subgraph end"); 201 | 202 | $this->assertEquals("subgraph foo {\n A -> B;\n}\n", $subgraph->render(), "Subgraph rendering"); 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /graphviz/tests/Alom/Graphviz/Tests/DirectedEdgeTest.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | namespace Alom\Graphviz\Tests; 11 | 12 | use Alom\Graphviz\DirectedEdge; 13 | 14 | class DirectedEdgeTest extends \PHPUnit_Framework_TestCase 15 | { 16 | public function testStructure() 17 | { 18 | $mock = $this->getMock('Alom\Graphviz\BaseInstruction'); 19 | $edge = new DirectedEdge(array('A', 'B'), array(), $mock); 20 | 21 | $this->assertCount(2, $edge->getList(), "2 elements in the edge"); 22 | $edge->attribute('foo', 'bar'); 23 | $this->assertEquals('bar', $edge->getAttributes()->get('foo'), "Value of attribute is correct"); 24 | $this->assertSame($mock, $edge->end(), "End returns parent"); 25 | } 26 | 27 | public function testRender() 28 | { 29 | $edge = new DirectedEdge(array('A', 'B')); 30 | 31 | $this->assertEquals("A -> B;\n", $edge->render()); 32 | } 33 | 34 | public function testAttributes() 35 | { 36 | $edge = new DirectedEdge(array('A', 'B'), array('foo' => 'bar')); 37 | 38 | $this->assertEquals('bar', $edge->getAttribute('foo')); 39 | $this->assertEquals('foo', $edge->getAttribute('not-existing', 'foo')); 40 | 41 | $edge->attribute('bar', 'baz'); 42 | 43 | $this->assertEquals('baz', $edge->getAttribute('bar')); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /graphviz/tests/Alom/Graphviz/Tests/NodeTest.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | namespace Alom\Graphviz\Tests; 11 | 12 | use Alom\Graphviz\Node; 13 | 14 | class NodeTest extends \PHPUnit_Framework_TestCase 15 | { 16 | public function testRender() 17 | { 18 | $node = new Node('A'); 19 | 20 | $this->assertEquals("A;\n", $node->render(), "Render basic"); 21 | } 22 | 23 | public function testAttributes() 24 | { 25 | $node = new Node('A', array('foo' => 'bar')); 26 | 27 | $this->assertEquals('bar', $node->getAttribute('foo')); 28 | $this->assertEquals('foo', $node->getAttribute('not-existing', 'foo')); 29 | 30 | $node->attribute('bar', 'baz'); 31 | 32 | $this->assertEquals('baz', $node->getAttribute('bar')); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /graphviz/tests/Alom/Graphviz/Tests/SubgraphTest.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | namespace Alom\Graphviz\Tests; 11 | 12 | use Alom\Graphviz\Subgraph; 13 | 14 | class SubgraphTest extends \PHPUnit_Framework_TestCase 15 | { 16 | /** 17 | * @expectedException LogicException 18 | */ 19 | public function testUnknownParent() 20 | { 21 | $subgraph = new Subgraph('S'); 22 | $subgraph->edge(array('A', 'B', 'C')); 23 | 24 | $subgraph->render(); 25 | 26 | $this->markTestIncomplete('This test has not been fully implemented yet.'); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /i18n/extensionsettings.pot: -------------------------------------------------------------------------------- 1 | # This file is part of FreePBX. 2 | # 3 | # For licensing information, please see the file named LICENSE located in the module directory 4 | # 5 | # FreePBX language template for extensionsettings 6 | # Copyright (C) 2008-2016 Sangoma, Inc. 7 | # 8 | msgid "" 9 | msgstr "" 10 | "Project-Id-Version: PACKAGE VERSION\n" 11 | "Report-Msgid-Bugs-To: \n" 12 | "POT-Creation-Date: 2016-03-01 11:33-0800\n" 13 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 | "Last-Translator: FULL NAME \n" 15 | "Language-Team: LANGUAGE \n" 16 | "MIME-Version: 1.0\n" 17 | "Content-Type: text/plain; charset=utf-8\n" 18 | "Content-Transfer-Encoding: 8bit\n" 19 | 20 | #: page.extensionsettings.php:12 21 | msgid "Call status" 22 | msgstr "" 23 | 24 | #: extensionsettings.i18n.php:8 25 | msgid "" 26 | "Creates a list of all extensions and their current settings for CW, CF, CFB, " 27 | "CFU, VMXB and VMXU" 28 | msgstr "" 29 | 30 | #: page.extensionsettings.php:9 31 | msgid "Extension" 32 | msgstr "" 33 | 34 | #: extensionsettings.i18n.php:4 35 | #: extensionsettings.i18n.php:10 36 | msgid "Extension Settings" 37 | msgstr "" 38 | 39 | #: page.extensionsettings.php:11 40 | msgid "Follow-Me" 41 | msgstr "" 42 | 43 | #: page.extensionsettings.php:21 44 | msgid "FreePBX Extension Settings" 45 | msgstr "" 46 | 47 | #: extensionsettings.i18n.php:6 48 | #: extensionsettings.i18n.php:12 49 | msgid "Settings" 50 | msgstr "" 51 | 52 | #: page.extensionsettings.php:13 53 | msgid "Status" 54 | msgstr "" 55 | 56 | #: page.extensionsettings.php:10 57 | msgid "VmX Locator" 58 | msgstr "" 59 | -------------------------------------------------------------------------------- /install.php: -------------------------------------------------------------------------------- 1 | query($sql); 7 | 8 | if (DB::isError($result)) { 9 | die("Error inserting data: " . $result->getMessage()); 10 | } 11 | -------------------------------------------------------------------------------- /module.sig: -------------------------------------------------------------------------------- 1 | -----BEGIN PGP SIGNED MESSAGE----- 2 | Hash: SHA1 3 | 4 | ;################################################ 5 | ;# FreePBX Module Signature File # 6 | ;################################################ 7 | ;# Do not alter the contents of this file! If # 8 | ;# this file is tampered with, the module will # 9 | ;# fail validation and be marked as invalid! # 10 | ;################################################ 11 | 12 | [config] 13 | version=2 14 | hash=sha256 15 | signedwith=AB9EB095 16 | signedby=sign.php 17 | repo=manual 18 | type=public 19 | [hashes] 20 | Cpviz.class.php = b99a2484a020984afc4a9747f9e13dbd7978b643257a5775210fb75c47e07864 21 | LICENSE = 8ceb4b9ee5adedde47b31e975c1d90c73ad27b6b165a1dcd80c7c545eb65b903 22 | Makefile = 8f4a0594c1ee7b3e296bf72eb4ed55cbbdf2ec7a283a51dba59ba53786e38b77 23 | README.md = 1cd715f8b844c00dc983477179dcc0b60be78bf00d695086b606799f4ef5459f 24 | assets/css/cpviz.css = 4a2e01d9c6117686b42e213d16f29f4c03d8c0acdd2986ac128ff2cf4b6466aa 25 | assets/js/full.render.js = c4be40289cf118a32f12c92878905b7b4a555b543e48429a595ef917a174c484 26 | assets/js/html2canvas.min.js = b8222eb2d315b38e2c4d2c0435ef8814c7cee1bbf1bb9af26b549df02a586508 27 | assets/js/panzoom.min.js = c393dc9cd71a195d28f44b1788b234df779966c5f5465d638698542848a89c74 28 | assets/js/viz.min.js = f37126c05edf3e31b0ff8db7c12c74e15948c6426800e63b0b82266b400700b6 29 | functions.inc.php = 857af43b78ab7c2a5326136fa509823a831374c12843afda849d835d90459182 30 | graphviz/CHANGELOG.md = b97070be805eb91e5ed5d2c5da12b10eb42904ef657171437df20a2165696e93 31 | graphviz/CONTRIBUTORS.md = cc2300aae7c466bace95f3c929f24b80834f6517c975184c2e3fff03e54cccb7 32 | graphviz/LICENCE = 58ebc1c069f6c1a11786d2590b245636bd2f8a18e7f9c88000c02049408291f8 33 | graphviz/README.md = 6c793811bee1b20d990b0d2dcb58e39e07a5d3e9f4213ae8a11d673d3f28ccd6 34 | graphviz/composer.json = 42207b195ca0074985ec9ccb8394553b57f9623c64afa8ae7ad96ab4a2a9f65e 35 | graphviz/phpunit.xml.dist = 331354e64d9f9ee23b1eb1b024d23aa01583e311abc42f0b18b87d3ec352473b 36 | graphviz/samples/00-readme.php = 40865546200c521d0cba877364fbfc805e3038417e4c36929cc6deb1870b0372 37 | graphviz/samples/01-basic.php = e0c8602c1a3539923b83e8f99800f3973de4874e48d884e85f7bd9b93be33c7d 38 | graphviz/samples/02-table.php = d10d30c263e195425d3c5e1b450294cc40c3b64efb18f15fe7b19bc54683ad44 39 | graphviz/src/Alom/Graphviz/Assign.php = 08818de20f467d3337bf6ae97e3a15720eeec593fc056544cf7aae6d0e9efbf8 40 | graphviz/src/Alom/Graphviz/AttributeBag.php = 8286e655801bc7e4996faf236e0510dab0d1f8d8ce59ff0f8072a1b24fcc6d8e 41 | graphviz/src/Alom/Graphviz/AttributeSet.php = 58ed8d24033ad8e7004a557233bc67eea66fae516e98d9f2cfe121386cf0ba00 42 | graphviz/src/Alom/Graphviz/BaseInstruction.php = 27edf6a71bd59685484c7ab6ed094278c350f613329e22e40bea09b1f1e36c19 43 | graphviz/src/Alom/Graphviz/Digraph.php = 2e1f0cd85931d3b59bc0bb04b7c446ba229586f8ff6171b0cfdd2796376bbcb5 44 | graphviz/src/Alom/Graphviz/DirectedEdge.php = aeea046b27b2c873e0e54a49ebfd8662c64d5086e56be835f0a8e332407377e1 45 | graphviz/src/Alom/Graphviz/Edge.php = 8c003d3eba2e642a2c649fb2c40297c208ee34b09ac144f790084bbbcacda3aa 46 | graphviz/src/Alom/Graphviz/Graph.php = 21d8654bd33d189ce0a9a8612a939e0f7d089ad0b92466d4bb5325320ec80201 47 | graphviz/src/Alom/Graphviz/InstructionInterface.php = a1e74cb1f9bdc3455156c04cf8dcc08f5c43088427f795c7b2d624212b63d3ec 48 | graphviz/src/Alom/Graphviz/Node.php = 0776d2cb751a4f8dd157fd45883e14112c78a242758cbbb43c87e4d1981ac676 49 | graphviz/src/Alom/Graphviz/RawText.php = caa02adb3b5f36fb505ef4dfc1d35b180b4071629653c523b88021f2ca8d4236 50 | graphviz/src/Alom/Graphviz/Subgraph.php = 0b8095bd6796df0b01942b272c2d1deb053f3b15092b72062482af6916370fff 51 | graphviz/tests/Alom/Graphviz/Tests/AssignTest.php = 1051db88ebbd363b17576435858c62855ab88e57b0b119600f4aa87465a6ea8d 52 | graphviz/tests/Alom/Graphviz/Tests/AttributeBagTest.php = 9936b1f293884062e11212b4472adfcc68c19bfa85bc83fb554862950f82d79c 53 | graphviz/tests/Alom/Graphviz/Tests/AttributeSetTest.php = dcc20e5c77c8def4ad9eb11a31609af2800fb231f726db83f77c9eba4a88c6df 54 | graphviz/tests/Alom/Graphviz/Tests/DigraphTest.php = 80585fc7293036ce75e5f334bea2d7203243e6a2950829d4ce76971d543c91c4 55 | graphviz/tests/Alom/Graphviz/Tests/DirectedEdgeTest.php = d936597010e42c8cafadf44548dedbe8c900a1f63c9b9d8eac1e6d690cc33ba1 56 | graphviz/tests/Alom/Graphviz/Tests/NodeTest.php = e7efd8cfe481c229df26c57851ec84fa1eed504a3fc050f2f568511a980769be 57 | graphviz/tests/Alom/Graphviz/Tests/SubgraphTest.php = f313f35d426381b1bcf044a1fbbdd79f0ff41b05e705fb0c1837959902ec5078 58 | i18n/extensionsettings.pot = c1e41bcb1fb5d068b64d00d88fb1660152356efd034967d649a2654a8b698ff8 59 | install.php = 783871ca7d44cab2db2f1414651d782275f55f4e4611125e842c08ee898d486c 60 | module.xml = 918a4b5ab887bbd1ca5643848f6b01282f156f3f67c972d0d83e821306709b34 61 | page.cpviz.php = 753283c13d2b5eb4e562670af9bcd5384153f300ab408162042577130572ec93 62 | views/options.php = d305dec04d64edac3212053f52017abd112ac1adf31f6e21958b14ef6365c77e 63 | views/rnav.php = 9a25da1a3113d539bdc58009a773f24b04a110ae2850f5462cfa7173e60e2e93 64 | ;# End 65 | -----BEGIN PGP SIGNATURE----- 66 | Version: GnuPG v2.0.22 (GNU/Linux) 67 | 68 | iQIcBAEBAgAGBQJn4ybVAAoJEFjoDUb+1cDjd8wQALKJ4vLMI/W8Afg7qqpvqjH4 69 | 3f6pGkgMHJFSPQ0R8icmDTld+a2096Zq59NTvdeJKcm4GWl352YYejebRlvsp8Jr 70 | 3V66B5F2O+qC9dz7Cx9xCou3rXS2cxbGmChm9MPm/RkOOAz/zZJFOXTfxCoItVqA 71 | ooN6kNIYvIvvwaKlDgiuKCYd6Kq++LLDczjSDPFgAwo2Rx4JqrhTAPIETevQHh/Y 72 | Qp3rVMj+R3CezavpfdKFrafi1gz5LksEeGkjHYxY8iyRL83ZkoREMw16cY7Bqeso 73 | g5TQzJZf2CtBDknkJGiA3fGzCgYk1YLlI+NKw1PFwdUFR0hUN5MqFXgD7ImDMmih 74 | 505IiX4vwNDhSNhnVgOuzc8lSSFsZewc+vin5j7kMN7bGX3q/jTYFHaFWsyemaZi 75 | 9LglBrkm8TuW+zRKhZleBcdaA15I2/RqfEC2wYr386n7tEnlv+hL84TcZBNCpcnV 76 | gSyqta7L1qRDweNMT/0ThbPrGn6Z6KBdGPddRde5aA4qjNBM6kBCqiugR52ELU7q 77 | bUZbGh7+8qKIwchmdQvm+Vw5rW5Y1NoXLxG5ViBoJMq1+0t+nkHKuN9E/sh5jioO 78 | NQgmUZ1+1BHMiJGMb1+1U60THMnlBNKn4J3lc6q8ZOjjiidvn4yyeOTHUlaGKOUb 79 | 0oQZjS+m/o8YJLnK9noM 80 | =ogGN 81 | -----END PGP SIGNATURE----- 82 | -------------------------------------------------------------------------------- /module.xml: -------------------------------------------------------------------------------- 1 | 2 | cpviz 3 | unsupported 4 | Dial Plan Visualizer 5 | 1.0.14 6 | ZTelco 7 | GPLv3+ 8 | http://www.gnu.org/licenses/gpl-3.0.txt 9 | Reports 10 | Graphical display of the dial plan for any Inbound Route 11 | 12 | Dial Plan Visualizer 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 | 26 | *1.0.14* Updated for ANY route. Updated for E.164 format. Added Highlighting. 27 | *1.0.13* Formatted module. Added Dynamic Routes. Big overhaul of code. 28 | *1.0.12* Added panzoom 29 | *1.0.11* Updated name and email for Voicemail 30 | *1.0.10* AdamV expanded on initial 31 | *1.0.8* First fully working release 32 | *1.0.0* First release, testing module creation 33 | 34 | https://www.ztelco.com/ 35 | c62830a311338fa38b1aa0e9f9284fc3 36 | 37 | 12.0 38 | 39 |
40 | -------------------------------------------------------------------------------- /page.cpviz.php: -------------------------------------------------------------------------------- 1 | 36 |
37 |
38 |

39 |
40 | " . "FreePBX config data:\n" . print_r($inroutes, true) . "
"; 44 | 45 | if (isset($_GET['extdisplay'])) { 46 | $dproute = dp_find_route($inroutes, $iroute); 47 | 48 | if (empty($dproute)) { 49 | echo "

Error: Could not find inbound route for '$iroute'

"; 50 | } else { 51 | $filename = ($iroute == '') ? 'ANY.png' : $iroute.'.png'; 52 | echo '

'; 53 | dp_load_tables($dproute); # adds data for time conditions, IVRs, etc. 54 | //echo "
" . "FreePBX config data:\n" . print_r($dproute, true) . "

"; 55 | 56 | 57 | dplog(5, "Doing follow dest ..."); 58 | dp_follow_destinations($dproute, ''); 59 | dplog(5, "Finished follow dest ..."); 60 | 61 | $gtext = $dproute['dpgraph']->render(); 62 | 63 | dplog(5, "Dial Plan Graph for $extdisplay $cid:\n$gtext"); 64 | 65 | $gtext = str_replace(["\n","+"], ["\\n","\\+"], $gtext); // ugh, apparently viz chokes on newlines, wtf? 66 | 67 | ?> 68 |
69 |
70 |

Dial Plan For Inbound Route

71 | ".date('Y-m-d H:i:s')."";} ?> 72 |
73 |
74 | 75 | 76 | 77 | 370 | 372 | 373 | 381 | 385 |
-------------------------------------------------------------------------------- /views/options.php: -------------------------------------------------------------------------------- 1 |
2 | 5 |
6 |
7 |
8 |
9 |
10 | 11 |
12 |
13 |
14 |
15 |
16 |
17 | 18 | 19 |
20 |
21 | > 22 | 23 | > 24 | 25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | 33 |
34 |
35 |
36 | 37 | 38 |
39 |
40 |
41 |
42 |
43 |
44 | 45 | 46 |
47 |
48 | > 49 | 50 | > 51 | 52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 | 60 |
61 |
62 |
63 | 64 | 65 |
66 |
67 |
68 |
69 |
70 |
71 | 72 | 73 |
74 |
75 | > 76 | 77 | > 78 | 79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 | 87 |
88 |
89 |
90 | 91 | 92 |
93 |
94 |
95 |
96 |
97 |
98 | 99 | 100 |
101 |
102 | > 103 | 104 | > 105 | 106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 | 114 |
115 |
116 |
117 | 118 | 119 |
120 |
121 |
122 |
123 |
124 |
125 | 126 | 127 |
128 |
129 | > 130 | 131 | > 132 | 133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 | 141 |
142 |
143 |
144 | 145 | 146 |
147 |
148 |
149 |
150 |
151 |
152 | 153 | 154 |
155 |
156 | > 157 | 158 | > 159 | 160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 | 168 |
169 |
170 |
171 | 172 | 173 |
174 |
175 | 176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
-------------------------------------------------------------------------------- /views/rnav.php: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 40 | 41 | 42 | 70 | --------------------------------------------------------------------------------