PageRenderTime 122ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/OX/Extension/deliveryLimitations/DeliveryLimitations.php

https://github.com/orchestra-io/sample-openx
PHP | 336 lines | 149 code | 31 blank | 156 comment | 16 complexity | f2ee4243058c2ac06fb6b87f746d9dba MD5 | raw file
  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v${RELEASE_MAJOR_MINOR} |
  5. | =======${RELEASE_MAJOR_MINOR_DOUBLE_UNDERLINE} |
  6. | |
  7. | Copyright (c) 2003-2009 OpenX Limited |
  8. | For contact details, see: http://www.openx.org/ |
  9. | |
  10. | This program is free software; you can redistribute it and/or modify |
  11. | it under the terms of the GNU General Public License as published by |
  12. | the Free Software Foundation; either version 2 of the License, or |
  13. | (at your option) any later version. |
  14. | |
  15. | This program is distributed in the hope that it will be useful, |
  16. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  17. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  18. | GNU General Public License for more details. |
  19. | |
  20. | You should have received a copy of the GNU General Public License |
  21. | along with this program; if not, write to the Free Software |
  22. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  23. +---------------------------------------------------------------------------+
  24. $Id: DeliveryLimitations.php 44411 2009-10-07 14:59:11Z david.keen $
  25. */
  26. require_once MAX_PATH . '/lib/max/Plugin/Common.php';
  27. require_once MAX_PATH . '/lib/max/Plugin/Translation.php';
  28. require_once MAX_PATH . '/lib/max/Delivery/limitations.delivery.php';
  29. require_once MAX_PATH . '/lib/OA/Maintenance/Priority/DeliveryLimitation/Empty.php';
  30. require_once LIB_PATH . '/Plugin/Component.php';
  31. /**
  32. * Plugins_DeliveryLimitations is an abstract class for every Delivery limitation plugin. Note that
  33. * subclasses of this plugin need to build an 'evaluation' function, which is named of the form:
  34. * 'MAX_check{Type}_{Plugin}.
  35. *
  36. * {Type} is the group which the plugin belongs to (e.g. Time, Geo, etc.), and is also the subfolder
  37. * under 'deliveryLimitations' where the plugin lives.
  38. *
  39. * {Plugin} is the actual name of the plugin. The plugin file name is also called {Plugin}.plugin.php.
  40. *
  41. * @abstract
  42. * @package OpenXPlugin
  43. * @subpackage DeliveryLimitations
  44. * @author Chris Nutting <chris@m3.net>
  45. */
  46. class Plugins_DeliveryLimitations extends OX_Component
  47. {
  48. var $ad_id;
  49. var $logical;
  50. var $type;
  51. var $comparison;
  52. var $data = '';
  53. var $executionorder;
  54. var $count;
  55. var $res;
  56. var $columnName = '';
  57. var $nameEnglish = '';
  58. var $defaultComparison = '==';
  59. /**
  60. * An array list of operations available for this type of plugin.
  61. *
  62. * @var array
  63. */
  64. var $aOperations;
  65. function Plugins_DeliveryLimitations()
  66. {
  67. $this->aOperations = MAX_limitationsGetAOperationsForString($this);
  68. }
  69. /**
  70. * Initialise this plugin
  71. */
  72. function init($data)
  73. {
  74. if (!is_null($data)) {
  75. foreach ($data as $name => $value) {
  76. $this->$name = $value;
  77. }
  78. }
  79. $this->displayName = $this->getName();
  80. $this->res = $this->_getRes();
  81. }
  82. function _getRes()
  83. {
  84. $file = MAX_PATH.$GLOBALS['_MAX']['CONF']['pluginPaths']['plugins']."/deliveryLimitations/{$this->group}/{$this->component}.res.inc.php";
  85. if (is_readable($file)) {
  86. // Use include here, not require_once, so that the $res array will be created every time,
  87. // even if the plugin is initialised more than once
  88. include $file;
  89. return $res;
  90. }
  91. return array();
  92. }
  93. /**
  94. * Returns the localized name of the plugin. The method is based
  95. * on the data stored in nameEnglish member variable.
  96. *
  97. * @return string Localized name of the plugin.
  98. */
  99. function getName()
  100. {
  101. return MAX_Plugin_Translation::translate(
  102. $this->nameEnglish, $this->extension, $this->group);
  103. }
  104. /**
  105. * Evaluates whether the person or agency can use this plugin (e.g. if they have the right permissions)
  106. *
  107. * @abstract
  108. * @return boolean
  109. */
  110. function isAllowed($page = false)
  111. {
  112. return true;
  113. }
  114. /**
  115. * Method to check input data
  116. *
  117. * @param array $data Most important to check is $data['data'] field
  118. * @return bool|string true or error message
  119. */
  120. function checkInputData($data)
  121. {
  122. // if (!($data['data'] && !is_array($data['data']) && trim($data['data'] != ''))) {
  123. // return MAX_Plugin_Translation::translate($this->group.' - '.$this->getName().': Please provide a non-empty limitation parameters', $this->extension, $this->group);
  124. // }
  125. return true;
  126. }
  127. /**
  128. * Echos the HTML to display this limitation
  129. *
  130. * @return void
  131. */
  132. function display()
  133. {
  134. global $tabindex;
  135. if ($this->executionorder > 0) {
  136. echo "<tr><td colspan='4'><img src='" . OX::assetPath() . "/images/break-el.gif' width='100%' height='1'></td></tr>";
  137. }
  138. $bgcolor = $this->executionorder % 2 == 0 ? "#E6E6E6" : "#FFFFFF";
  139. echo "<tr height='35' bgcolor='$bgcolor'>";
  140. echo "<td width='100'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  141. if ($this->executionorder == 0) {
  142. echo "<input type='hidden' name='acl[{$this->executionorder}][logical]' value='and'>&nbsp;";
  143. } else {
  144. echo "<select name='acl[{$this->executionorder}][logical]' tabindex='".($tabindex++)."'>";
  145. echo "<option value='or' " . (($this->logical == 'or') ? 'selected' : '') . ">{$GLOBALS['strOR']}</option>";
  146. echo "<option value='and' " . (($this->logical == 'and') ? 'selected' : '') . ">{$GLOBALS['strAND']}</option>";
  147. echo "</select>";
  148. }
  149. echo "</td><td width='130'>";
  150. echo "<table cellpadding='2'><tr><td><img src='" . OX::assetPath() . "/images/icon-acl.gif' align='absmiddle'>&nbsp;</td><td>{$this->displayName}</td></tr></table>";
  151. echo "<input type='hidden' name='acl[{$this->executionorder}][type]' value='{$this->type}'>";
  152. echo "<input type='hidden' name='acl[{$this->executionorder}][executionorder]' value='{$this->executionorder}'>";
  153. echo "</td><td >";
  154. $this->displayComparison();
  155. echo "</td>";
  156. // Show buttons
  157. echo "<td align='{$GLOBALS['phpAds_TextAlignRight']}'>";
  158. echo "<input type='image' name='action[del][{$this->executionorder}]' value='{$this->executionorder}' src='" . OX::assetPath() . "/images/icon-recycle.gif' border='0' align='absmiddle' alt='{$GLOBALS['strDelete']}'>";
  159. echo "&nbsp;&nbsp;";
  160. echo "<img src='" . OX::assetPath() . "/images/break-el.gif' width='1' height='35'>";
  161. echo "&nbsp;&nbsp;";
  162. if ($this->executionorder && $this->executionorder < $this->count)
  163. echo "<input type='image' name='action[up][{$this->executionorder}]' src='" . OX::assetPath() . "/images/triangle-u.gif' border='0' alt='{$GLOBALS['strUp']}' align='absmiddle'>";
  164. else
  165. echo "<img src='" . OX::assetPath() . "/images/triangle-u-d.gif' alt='{$GLOBALS['strUp']}' align='absmiddle'>";
  166. if ($this->executionorder < $this->count - 1) {
  167. echo "<input type='image' name='action[down][{$this->executionorder}]' src='" . OX::assetPath() . "/images/triangle-d.gif' border='0' alt='{$GLOBALS['strDown']}' align='absmiddle'>";
  168. } else {
  169. echo "<img src='" . OX::assetPath() . "/images/triangle-d-d.gif' alt='{$GLOBALS['strDown']}' align='absmiddle'>";
  170. }
  171. echo "&nbsp;&nbsp;</td></tr>";
  172. echo "<tr bgcolor='$bgcolor'><td>&nbsp;</td><td>&nbsp;</td><td colspan='2'>";
  173. $this->displayData();
  174. echo "<br /><br /></td></tr>";
  175. //if (!isset($acl[$key]['type']) || $acl[$key]['type'] != $previous_type && $previous_type != '')
  176. //echo "<tr><td height='1' colspan='4' bgcolor='#888888'><img src='" . OX::assetPath() . "/images/break.gif' height='1' width='100%'></td></tr>";
  177. }
  178. /**
  179. * Echos the HTML to display the comparison operator for this limitation
  180. *
  181. * @return void
  182. */
  183. function displayComparison()
  184. {
  185. global $tabindex;
  186. echo "<select name='acl[{$this->executionorder}][comparison]' tabindex='".($tabindex++)."'>";
  187. foreach($this->aOperations as $sOperator => $sDescription) {
  188. echo "<option value='$sOperator' " . (($this->comparison == $sOperator) ? 'selected' : '') . ">$sDescription</option>";
  189. }
  190. echo "</select>";
  191. }
  192. /**
  193. * Echos the HTML to display the data on the 'delivery limitations' screen for this limitation
  194. *
  195. * @return void
  196. */
  197. function displayData()
  198. {
  199. global $tabindex;
  200. echo "<input type='text' size='40' name='acl[{$this->executionorder}][data]' value=\"".htmlspecialchars(isset($this->data) ? $this->data : "")."\" tabindex='".($tabindex++)."'>";
  201. }
  202. /**
  203. * A private method to "flatten" a delivery limitation into the string format that is
  204. * saved to the database (either in the acls, acls_channel or banners table, when part
  205. * of a compiled limitation string).
  206. *
  207. * By default, simply returns the data exactly as is, as the default plugin data format
  208. * is a string itself.
  209. *
  210. * Should be overridden in any delivery limitation plugin where data is input from or
  211. * displayed in the UI in anything other than string format, or where the string data
  212. * needs to be interpreted in any way to be usable in the delivery limitation.
  213. *
  214. * @access private
  215. * @param mixed $data An optional, expanded form delivery limitation.
  216. * @return string The delivery limitation in flattened format.
  217. */
  218. function _flattenData($data = null)
  219. {
  220. if (is_null($data)) {
  221. $data = $this->data;
  222. }
  223. return $data;
  224. }
  225. /**
  226. * A private method to "expand" a delivery limitation from the string format that
  227. * is saved in the database (ie. in the acls or acls_channel table) into its
  228. * "expanded" form.
  229. *
  230. * By default, simply returns the data exactly as is, as the default plugin data format
  231. * is a string itself.
  232. *
  233. * Should be overridden in any delivery limitation plugin where data is input from or
  234. * displayed in the UI in anything other than string format, or where the string data
  235. * needs to be interpreted in any way to be useable in the delivery limitation.
  236. *
  237. * @access private
  238. * @param string $data An optional, flat form delivery limitation data string.
  239. * @return mixed The delivery limitation data in expanded format.
  240. */
  241. function _expandData($data = null)
  242. {
  243. if (is_null($data)) {
  244. $data = $this->data;
  245. }
  246. return $data;
  247. }
  248. /**
  249. * A private method to pre-compile limitaions.
  250. *
  251. * Will generally be overridden by delivery limitations with special requirements (eg. converting
  252. * the data stored in the database for the limitation from "as entered" data into lowercase, etc.).
  253. *
  254. * @access private
  255. * @param string $sData An internal representation of the limitation data
  256. * for this plugin as a string.
  257. * @return string The delivery limitation in pre-compiled form, with any changes to the format
  258. * of the data stored in the database having been made, ready to be used for
  259. * either compiling the limitation into final form, or converting the limitation
  260. * into SQL form.
  261. */
  262. function _preCompile($sData) {
  263. return MAX_limitationsGetPreprocessedString($sData);
  264. }
  265. /**
  266. * Returns the compiledlimitation string for this limitation. The compiledlimitation variable is
  267. * then used for functions which need to evaluate whether the banner can be shown without the need
  268. * to loop through every single limitation.
  269. *
  270. * @return string The delivery limitation in compiled form.
  271. */
  272. function compile()
  273. {
  274. return $this->compileData($this->data);
  275. }
  276. /**
  277. * The same as compile(), but works on arbitrary data.
  278. *
  279. * @param string $data
  280. */
  281. function compileData($data)
  282. {
  283. $result = 'MAX_check' . ucfirst($this->group) . '_' . $this->component . "('{$data}', '{$this->comparison}')";
  284. return MAX_limitationsGetQuotedString($result);
  285. }
  286. /**
  287. * Returns a data in its basic form, so it can be saved to the database.
  288. *
  289. * @return string The data.
  290. */
  291. function getData()
  292. {
  293. return $this->data;
  294. }
  295. /**
  296. * A method to return an instance to be used by the MPE
  297. *
  298. * @param unknown_type $aDeliveryLimitation
  299. */
  300. function getMpeClassInstance($aDeliveryLimitation)
  301. {
  302. return new OA_Maintenance_Priority_DeliveryLimitation_Empty($aDeliveryLimitation);
  303. }
  304. }
  305. ?>