| Conditions | 7 |
| Paths | 40 |
| Total Lines | 104 |
| Code Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 81 | public function emailArticle() { |
||
| 82 | |||
| 83 | $ids = explode(",", $_REQUEST['param']); |
||
| 84 | $ids_qmarks = arr_qmarks($ids); |
||
| 85 | |||
| 86 | print_hidden("op", "pluginhandler"); |
||
| 87 | print_hidden("plugin", "mail"); |
||
| 88 | print_hidden("method", "sendEmail"); |
||
| 89 | |||
| 90 | $sth = $this->pdo->prepare("SELECT email, full_name FROM ttrss_users WHERE |
||
| 91 | id = ?"); |
||
| 92 | $sth->execute([$_SESSION['uid']]); |
||
| 93 | |||
| 94 | if ($row = $sth->fetch()) { |
||
| 95 | $user_email = htmlspecialchars($row['email']); |
||
| 96 | $user_name = htmlspecialchars($row['full_name']); |
||
| 97 | } |
||
| 98 | |||
| 99 | if (!$user_name) { |
||
|
|
|||
| 100 | $user_name = $_SESSION['name']; |
||
| 101 | } |
||
| 102 | |||
| 103 | print_hidden("from_email", "$user_email"); |
||
| 104 | print_hidden("from_name", "$user_name"); |
||
| 105 | |||
| 106 | require_once "lib/MiniTemplator.class.php"; |
||
| 107 | |||
| 108 | $tpl = new MiniTemplator; |
||
| 109 | |||
| 110 | $tpl->readTemplateFromFile("templates/email_article_template.txt"); |
||
| 111 | |||
| 112 | $tpl->setVariable('USER_NAME', $_SESSION["name"], true); |
||
| 113 | $tpl->setVariable('USER_EMAIL', $user_email, true); |
||
| 114 | $tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"], true); |
||
| 115 | |||
| 116 | $sth = $this->pdo->prepare("SELECT DISTINCT link, content, title, note |
||
| 117 | FROM ttrss_user_entries, ttrss_entries WHERE id = ref_id AND |
||
| 118 | id IN ($ids_qmarks) AND owner_uid = ?"); |
||
| 119 | $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
||
| 120 | |||
| 121 | if (count($ids) > 1) { |
||
| 122 | $subject = __("[Forwarded]")." ".__("Multiple articles"); |
||
| 123 | } |
||
| 124 | |||
| 125 | while ($line = $sth->fetch()) { |
||
| 126 | |||
| 127 | if (!$subject) { |
||
| 128 | $subject = __("[Forwarded]")." ".htmlspecialchars($line["title"]); |
||
| 129 | } |
||
| 130 | |||
| 131 | $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"])); |
||
| 132 | $tnote = strip_tags($line["note"]); |
||
| 133 | if ($tnote != '') { |
||
| 134 | $tpl->setVariable('ARTICLE_NOTE', $tnote, true); |
||
| 135 | $tpl->addBlock('note'); |
||
| 136 | } |
||
| 137 | $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"])); |
||
| 138 | |||
| 139 | $tpl->addBlock('article'); |
||
| 140 | } |
||
| 141 | |||
| 142 | $tpl->addBlock('email'); |
||
| 143 | |||
| 144 | $content = ""; |
||
| 145 | $tpl->generateOutputToString($content); |
||
| 146 | |||
| 147 | print "<table width='100%'><tr><td>"; |
||
| 148 | |||
| 149 | $addresslist = explode(",", $this->host->get($this, "addresslist")); |
||
| 150 | |||
| 151 | print __('To:'); |
||
| 152 | |||
| 153 | print "</td><td>"; |
||
| 154 | |||
| 155 | /* print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\" |
||
| 156 | style=\"width : 30em;\" |
||
| 157 | name=\"destination\" id=\"emailArticleDlg_destination\">"; */ |
||
| 158 | |||
| 159 | print_select("destination", "", $addresslist, 'style="width: 30em" dojoType="dijit.form.ComboBox"'); |
||
| 160 | |||
| 161 | /* print "<div class=\"autocomplete\" id=\"emailArticleDlg_dst_choices\" |
||
| 162 | style=\"z-index: 30; display : none\"></div>"; */ |
||
| 163 | |||
| 164 | print "</td></tr><tr><td>"; |
||
| 165 | |||
| 166 | print __('Subject:'); |
||
| 167 | |||
| 168 | print "</td><td>"; |
||
| 169 | |||
| 170 | print "<input dojoType='dijit.form.ValidationTextBox' required='true' |
||
| 171 | style='width : 30em;' name='subject' value=\"$subject\" id='subject'>"; |
||
| 172 | |||
| 173 | print "</td></tr>"; |
||
| 174 | |||
| 175 | print "<tr><td colspan='2'><textarea dojoType='dijit.form.SimpleTextarea' |
||
| 176 | style='height : 200px; font-size : 12px; width : 98%' rows=\"20\" |
||
| 177 | name='content'>$content</textarea>"; |
||
| 178 | |||
| 179 | print "</td></tr></table>"; |
||
| 180 | |||
| 181 | print "<footer>"; |
||
| 182 | print "<button dojoType='dijit.form.Button' onclick=\"dijit.byId('emailArticleDlg').execute()\">".__('Send e-mail')."</button> "; |
||
| 183 | print "<button dojoType='dijit.form.Button' onclick=\"dijit.byId('emailArticleDlg').hide()\">".__('Cancel')."</button>"; |
||
| 184 | print "</footer>"; |
||
| 185 | |||
| 246 |